5 * TODO: Seperate a lot of this into an aim_bos.c.
19 * Should set your current idle time in seconds. Idealy, OSCAR should
20 * do this for us. But, it doesn't. The client must call this to set idle
24 u_long aim_bos_setidle(struct aim_session_t *sess,
25 struct aim_conn_t *conn,
28 return aim_genericreq_l(sess, conn, 0x0001, 0x0011, &idletime);
33 * aim_bos_changevisibility(conn, changtype, namelist)
35 * Changes your visibility depending on changetype:
37 * AIM_VISIBILITYCHANGE_PERMITADD: Lets provided list of names see you
38 * AIM_VISIBILITYCHANGE_PERMIDREMOVE: Removes listed names from permit list
39 * AIM_VISIBILITYCHANGE_DENYADD: Hides you from provided list of names
40 * AIM_VISIBILITYCHANGE_DENYREMOVE: Lets list see you again
42 * list should be a list of
43 * screen names in the form "Screen Name One&ScreenNameTwo&" etc.
45 * Equivelents to options in WinAIM:
46 * - Allow all users to contact me: Send an AIM_VISIBILITYCHANGE_DENYADD
47 * with only your name on it.
48 * - Allow only users on my Buddy List: Send an
49 * AIM_VISIBILITYCHANGE_PERMITADD with the list the same as your
51 * - Allow only the uesrs below: Send an AIM_VISIBILITYCHANGE_PERMITADD
52 * with everyone listed that you want to see you.
53 * - Block all users: Send an AIM_VISIBILITYCHANGE_PERMITADD with only
54 * yourself in the list
55 * - Block the users below: Send an AIM_VISIBILITYCHANGE_DENYADD with
56 * the list of users to be blocked
60 u_long aim_bos_changevisibility(struct aim_session_t *sess,
61 struct aim_conn_t *conn,
62 int changetype, char *denylist)
64 struct command_tx_struct *newpacket;
68 char *localcpy = NULL;
76 localcpy = (char *) malloc(strlen(denylist)+1);
77 memcpy(localcpy, denylist, strlen(denylist)+1);
79 listcount = aimutil_itemcnt(localcpy, '&');
80 packlen = aimutil_tokslen(localcpy, 99, '&') + listcount + 9;
82 if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, packlen)))
89 case AIM_VISIBILITYCHANGE_PERMITADD: subtype = 0x05; break;
90 case AIM_VISIBILITYCHANGE_PERMITREMOVE: subtype = 0x06; break;
91 case AIM_VISIBILITYCHANGE_DENYADD: subtype = 0x07; break;
92 case AIM_VISIBILITYCHANGE_DENYREMOVE: subtype = 0x08; break;
94 free(newpacket->data);
99 /* We actually DO NOT send a SNAC ID with this one! */
100 aim_putsnac(newpacket->data, 0x0009, subtype, 0x00, 0);
102 j = 10; /* the next byte */
104 for (i=0; (i < (listcount - 1)) && (i < 99); i++)
106 tmpptr = aimutil_itemidx(localcpy, i, '&');
108 newpacket->data[j] = strlen(tmpptr);
109 memcpy(&(newpacket->data[j+1]), tmpptr, strlen(tmpptr));
110 j += strlen(tmpptr)+1;
117 aim_tx_enqueue(sess, newpacket);
119 return (sess->snac_nextid); /* dont increment */
126 * aim_bos_setbuddylist(buddylist)
128 * This just builds the "set buddy list" command then queues it.
130 * buddy_list = "Screen Name One&ScreenNameTwo&";
132 * TODO: Clean this up.
134 * XXX: I can't stress the TODO enough.
137 u_long aim_bos_setbuddylist(struct aim_session_t *sess,
138 struct aim_conn_t *conn,
143 struct command_tx_struct *newpacket;
147 char *localcpy = NULL;
150 len = 10; /* 10B SNAC headers */
152 if (!buddy_list || !(localcpy = (char *) malloc(strlen(buddy_list)+1)))
154 strncpy(localcpy, buddy_list, strlen(buddy_list)+1);
157 tmpptr = strtok(localcpy, "&");
158 while ((tmpptr != NULL) && (i < 150)) {
160 printf("---adding %d: %s (%d)\n", i, tmpptr, strlen(tmpptr));
162 len += 1+strlen(tmpptr);
164 tmpptr = strtok(NULL, "&");
167 printf("*** send buddy list len: %d (%x)\n", len, len);
170 if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, len)))
175 aim_putsnac(newpacket->data, 0x0003, 0x0004, 0x0000, 0);
177 j = 10; /* the next byte */
179 strncpy(localcpy, buddy_list, strlen(buddy_list)+1);
181 tmpptr = strtok(localcpy, "&");
182 while ((tmpptr != NULL) & (i < 150)) {
184 printf("---adding %d: %s (%d)\n", i, tmpptr, strlen(tmpptr));
186 newpacket->data[j] = strlen(tmpptr);
187 memcpy(&(newpacket->data[j+1]), tmpptr, strlen(tmpptr));
188 j += 1+strlen(tmpptr);
190 tmpptr = strtok(NULL, "&");
195 aim_tx_enqueue(sess, newpacket);
199 return (sess->snac_nextid);
203 * aim_bos_setprofile(profile)
205 * Gives BOS your profile.
209 u_long aim_bos_setprofile(struct aim_session_t *sess,
210 struct aim_conn_t *conn,
215 struct command_tx_struct *newpacket;
216 int i = 0, tmp, caplen;
218 if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 1152+strlen(profile)+1+(awaymsg?strlen(awaymsg):0))))
221 i += aim_putsnac(newpacket->data, 0x0002, 0x004, 0x0000, sess->snac_nextid);
222 i += aim_puttlv_str(newpacket->data+i, 0x0001, strlen("text/x-aolrtf; charset=\"us-ascii\""), "text/x-aolrtf; charset=\"us-ascii\"");
223 i += aim_puttlv_str(newpacket->data+i, 0x0002, strlen(profile), profile);
224 /* why do we send this twice? */
225 i += aim_puttlv_str(newpacket->data+i, 0x0003, strlen("text/x-aolrtf; charset=\"us-ascii\""), "text/x-aolrtf; charset=\"us-ascii\"");
227 /* Away message -- we send this no matter what, even if its blank */
229 i += aim_puttlv_str(newpacket->data+i, 0x0004, strlen(awaymsg), awaymsg);
231 i += aim_puttlv_str(newpacket->data+i, 0x0004, 0x0000, NULL);
233 /* Capability information. */
235 tmp = (i += aimutil_put16(newpacket->data+i, 0x0005));
236 i += aimutil_put16(newpacket->data+i, 0x0000); /* rewritten later */
237 i += (caplen = aim_putcap(newpacket->data+i, 512, caps));
238 aimutil_put16(newpacket->data+tmp, caplen); /* rewrite TLV size */
240 newpacket->commandlen = i;
241 aim_tx_enqueue(sess, newpacket);
243 return (sess->snac_nextid++);
247 * aim_bos_setgroupperm(mask)
249 * Set group permisson mask. Normally 0x1f (all classes).
251 * The group permission mask allows you to keep users of a certain
252 * class or classes from talking to you. The mask should be
253 * a bitwise OR of all the user classes you want to see you.
256 u_long aim_bos_setgroupperm(struct aim_session_t *sess,
257 struct aim_conn_t *conn,
260 return aim_genericreq_l(sess, conn, 0x0009, 0x0004, &mask);
264 * aim_bos_clientready()
271 u_long aim_bos_clientready(struct aim_session_t *sess,
272 struct aim_conn_t *conn)
274 u_char command_2[] = {
275 /* placeholders for dynamic data */
276 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
322 int command_2_len = 0x52;
323 struct command_tx_struct *newpacket;
325 if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, command_2_len)))
330 memcpy(newpacket->data, command_2, command_2_len);
332 /* This write over the dynamic parts of the byte block */
333 aim_putsnac(newpacket->data, 0x0001, 0x0002, 0x0000, sess->snac_nextid);
335 aim_tx_enqueue(sess, newpacket);
337 return (sess->snac_nextid++);
341 * Request Rate Information.
344 u_long aim_bos_reqrate(struct aim_session_t *sess,
345 struct aim_conn_t *conn)
347 return aim_genericreq_n(sess, conn, 0x0001, 0x0006);
351 * Rate Information Response Acknowledge.
354 u_long aim_bos_ackrateresp(struct aim_session_t *sess,
355 struct aim_conn_t *conn)
357 struct command_tx_struct *newpacket;
358 int packlen = 20, i=0;
360 if(!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, packlen)))
361 return (sess->snac_nextid);
365 i = aim_putsnac(newpacket->data, 0x0001, 0x0008, 0x0000, 0);
366 i += aimutil_put16(newpacket->data+i, 0x0001);
367 i += aimutil_put16(newpacket->data+i, 0x0002);
368 i += aimutil_put16(newpacket->data+i, 0x0003);
369 i += aimutil_put16(newpacket->data+i, 0x0004);
370 i += aimutil_put16(newpacket->data+i, 0x0005);
372 aim_tx_enqueue(sess, newpacket);
374 return (sess->snac_nextid);
378 * aim_bos_setprivacyflags()
380 * Sets privacy flags. Normally 0x03.
382 * Bit 1: Allows other AIM users to see how long you've been idle.
383 * Bit 2: Allows other AIM users to see how long you've been a member.
386 u_long aim_bos_setprivacyflags(struct aim_session_t *sess,
387 struct aim_conn_t *conn,
390 return aim_genericreq_l(sess, conn, 0x0001, 0x0014, &flags);
394 * aim_bos_reqpersonalinfo()
396 * Requests the current user's information. Can't go generic on this one
397 * because aparently it uses SNAC flags.
400 u_long aim_bos_reqpersonalinfo(struct aim_session_t *sess,
401 struct aim_conn_t *conn)
403 return aim_genericreq_n(sess, conn, 0x0001, 0x000e);
406 u_long aim_setversions(struct aim_session_t *sess,
407 struct aim_conn_t *conn)
409 struct command_tx_struct *newpacket;
412 if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10 + (4*12))))
417 i = aim_putsnac(newpacket->data, 0x0001, 0x0017, 0x0000, sess->snac_nextid);
419 i += aimutil_put16(newpacket->data+i, 0x0001);
420 i += aimutil_put16(newpacket->data+i, 0x0003);
422 i += aimutil_put16(newpacket->data+i, 0x0002);
423 i += aimutil_put16(newpacket->data+i, 0x0001);
425 i += aimutil_put16(newpacket->data+i, 0x0003);
426 i += aimutil_put16(newpacket->data+i, 0x0001);
428 i += aimutil_put16(newpacket->data+i, 0x0004);
429 i += aimutil_put16(newpacket->data+i, 0x0001);
431 i += aimutil_put16(newpacket->data+i, 0x0006);
432 i += aimutil_put16(newpacket->data+i, 0x0001);
434 i += aimutil_put16(newpacket->data+i, 0x0008);
435 i += aimutil_put16(newpacket->data+i, 0x0001);
437 i += aimutil_put16(newpacket->data+i, 0x0009);
438 i += aimutil_put16(newpacket->data+i, 0x0001);
440 i += aimutil_put16(newpacket->data+i, 0x000a);
441 i += aimutil_put16(newpacket->data+i, 0x0001);
443 i += aimutil_put16(newpacket->data+i, 0x000b);
444 i += aimutil_put16(newpacket->data+i, 0x0002);
446 i += aimutil_put16(newpacket->data+i, 0x000c);
447 i += aimutil_put16(newpacket->data+i, 0x0001);
449 i += aimutil_put16(newpacket->data+i, 0x0013);
450 i += aimutil_put16(newpacket->data+i, 0x0001);
452 i += aimutil_put16(newpacket->data+i, 0x0015);
453 i += aimutil_put16(newpacket->data+i, 0x0001);
456 for (j = 0; j < 0x10; j++) {
457 i += aimutil_put16(newpacket->data+i, j); /* family */
458 i += aimutil_put16(newpacket->data+i, 0x0003); /* version */
462 aim_tx_enqueue(sess, newpacket);
464 return (sess->snac_nextid++);
469 * aim_bos_reqservice(serviceid)
474 u_long aim_bos_reqservice(struct aim_session_t *sess,
475 struct aim_conn_t *conn,
478 return aim_genericreq_s(sess, conn, 0x0001, 0x0004, &serviceid);
484 * No-op. WinAIM sends these every 4min or so to keep
485 * the connection alive. Its not real necessary.
488 u_long aim_bos_nop(struct aim_session_t *sess,
489 struct aim_conn_t *conn)
491 return aim_genericreq_n(sess, conn, 0x0001, 0x0016);
495 * aim_bos_reqrights()
497 * Request BOS rights.
500 u_long aim_bos_reqrights(struct aim_session_t *sess,
501 struct aim_conn_t *conn)
503 return aim_genericreq_n(sess, conn, 0x0009, 0x0002);
507 * aim_bos_reqbuddyrights()
509 * Request Buddy List rights.
512 u_long aim_bos_reqbuddyrights(struct aim_session_t *sess,
513 struct aim_conn_t *conn)
515 return aim_genericreq_n(sess, conn, 0x0003, 0x0002);
519 * aim_send_warning(struct aim_session_t *sess,
520 * struct aim_conn_t *conn, char *destsn, int anon)
521 * send a warning to destsn.
522 * anon is anonymous or not;
523 * AIM_WARN_ANON anonymous
525 * returns -1 on error (couldn't alloc packet), next snacid on success.
528 int aim_send_warning(struct aim_session_t *sess, struct aim_conn_t *conn, char *destsn, int anon)
530 struct command_tx_struct *newpacket;
533 if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, strlen(destsn)+13)))
539 curbyte += aim_putsnac(newpacket->data+curbyte,
540 0x0004, 0x0008, 0x0000, sess->snac_nextid);
542 curbyte += aimutil_put16(newpacket->data+curbyte, (anon & AIM_WARN_ANON)?1:0);
544 curbyte += aimutil_put8(newpacket->data+curbyte, strlen(destsn));
546 curbyte += aimutil_putstr(newpacket->data+curbyte, destsn, strlen(destsn));
548 newpacket->commandlen = curbyte;
551 aim_tx_enqueue(sess, newpacket);
553 return (sess->snac_nextid++);
559 * aim_debugconn_sendconnect()
561 * For aimdebugd. If you don't know what it is, you don't want to.
563 u_long aim_debugconn_sendconnect(struct aim_session_t *sess,
564 struct aim_conn_t *conn)
566 return aim_genericreq_n(sess, conn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_DEBUGCONN_CONNECT);
570 * Generic routine for sending commands.
573 * I know I can do this in a smarter way...but I'm not thinking straight
576 * I had one big function that handled all three cases, but then it broke
577 * and I split it up into three. But then I fixed it. I just never went
578 * back to the single. I don't see any advantage to doing it either way.
581 u_long aim_genericreq_n(struct aim_session_t *sess,
582 struct aim_conn_t *conn,
583 u_short family, u_short subtype)
585 struct command_tx_struct *newpacket;
587 if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10)))
592 aim_putsnac(newpacket->data, family, subtype, 0x0000, sess->snac_nextid);
594 aim_tx_enqueue(sess, newpacket);
595 return (sess->snac_nextid++);
602 u_long aim_genericreq_l(struct aim_session_t *sess,
603 struct aim_conn_t *conn,
604 u_short family, u_short subtype, u_long *longdata)
606 struct command_tx_struct *newpacket;
609 /* If we don't have data, there's no reason to use this function */
611 return aim_genericreq_n(sess, conn, family, subtype);
613 if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+sizeof(u_long))))
618 aim_putsnac(newpacket->data, family, subtype, 0x0000, sess->snac_nextid);
621 newlong = htonl(*longdata);
622 memcpy(&(newpacket->data[10]), &newlong, sizeof(u_long));
624 aim_tx_enqueue(sess, newpacket);
625 return (sess->snac_nextid++);
628 u_long aim_genericreq_s(struct aim_session_t *sess,
629 struct aim_conn_t *conn,
630 u_short family, u_short subtype, u_short *shortdata)
632 struct command_tx_struct *newpacket;
635 /* If we don't have data, there's no reason to use this function */
637 return aim_genericreq_n(sess, conn, family, subtype);
639 if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+sizeof(u_short))))
644 aim_putsnac(newpacket->data, family, subtype, 0x0000, sess->snac_nextid);
647 newshort = htons(*shortdata);
648 memcpy(&(newpacket->data[10]), &newshort, sizeof(u_short));
650 aim_tx_enqueue(sess, newpacket);
651 return (sess->snac_nextid++);
655 * aim_bos_reqlocaterights()
657 * Request Location services rights.
660 u_long aim_bos_reqlocaterights(struct aim_session_t *sess,
661 struct aim_conn_t *conn)
663 return aim_genericreq_n(sess, conn, 0x0002, 0x0002);
667 * aim_bos_reqicbmparaminfo()
669 * Request ICBM parameter information.
672 u_long aim_bos_reqicbmparaminfo(struct aim_session_t *sess,
673 struct aim_conn_t *conn)
675 return aim_genericreq_n(sess, conn, 0x0004, 0x0004);
679 * Add ICBM parameter? Huh?
681 unsigned long aim_addicbmparam(struct aim_session_t *sess,
682 struct aim_conn_t *conn)
684 struct command_tx_struct *newpacket;
685 int packlen = 10+16, i=0;
687 if(!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, packlen)))
688 return (sess->snac_nextid);
692 i = aim_putsnac(newpacket->data, 0x0004, 0x0002, 0x0000, sess->snac_nextid);
693 i += aimutil_put16(newpacket->data+i, 0x0000);
694 i += aimutil_put16(newpacket->data+i, 0x0000);
695 i += aimutil_put16(newpacket->data+i, 0x0003);
696 i += aimutil_put16(newpacket->data+i, 0x1f40);
697 i += aimutil_put16(newpacket->data+i, 0x03e7);
698 i += aimutil_put16(newpacket->data+i, 0x03e7);
699 i += aimutil_put16(newpacket->data+i, 0x0000);
700 i += aimutil_put16(newpacket->data+i, 0x0000);
702 aim_tx_enqueue(sess, newpacket);
704 return (sess->snac_nextid);