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);
263 int aim_parse_bosrights(struct aim_session_t *sess,
264 struct command_rx_struct *command, ...)
266 rxcallback_t userfunc = NULL;
268 struct aim_tlvlist_t *tlvlist;
269 struct aim_tlv_t *tlv;
270 unsigned short maxpermits = 0, maxdenies = 0;
275 if (!(tlvlist = aim_readtlvchain(command->data+10, command->commandlen-10)))
279 * TLV type 0x0001: Maximum number of buddies on permit list.
281 if ((tlv = aim_gettlv(tlvlist, 0x0001, 1))) {
282 maxpermits = aimutil_get16(tlv->value);
286 * TLV type 0x0002: Maximum number of buddies on deny list.
289 if ((tlv = aim_gettlv(tlvlist, 0x0002, 1))) {
290 maxdenies = aimutil_get16(tlv->value);
293 userfunc = aim_callhandler(command->conn, 0x0009, 0x0003);
295 ret = userfunc(sess, command, maxpermits, maxdenies);
297 aim_freetlvchain(&tlvlist);
303 * aim_bos_clientready()
310 u_long aim_bos_clientready(struct aim_session_t *sess,
311 struct aim_conn_t *conn)
313 u_char command_2[] = {
314 /* placeholders for dynamic data */
315 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
361 int command_2_len = 0x52;
362 struct command_tx_struct *newpacket;
364 if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, command_2_len)))
369 memcpy(newpacket->data, command_2, command_2_len);
371 /* This write over the dynamic parts of the byte block */
372 aim_putsnac(newpacket->data, 0x0001, 0x0002, 0x0000, sess->snac_nextid);
374 aim_tx_enqueue(sess, newpacket);
376 return (sess->snac_nextid++);
380 * Request Rate Information.
383 u_long aim_bos_reqrate(struct aim_session_t *sess,
384 struct aim_conn_t *conn)
386 return aim_genericreq_n(sess, conn, 0x0001, 0x0006);
390 * Rate Information Response Acknowledge.
393 u_long aim_bos_ackrateresp(struct aim_session_t *sess,
394 struct aim_conn_t *conn)
396 struct command_tx_struct *newpacket;
397 int packlen = 20, i=0;
399 if(!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, packlen)))
400 return (sess->snac_nextid);
404 i = aim_putsnac(newpacket->data, 0x0001, 0x0008, 0x0000, 0);
405 i += aimutil_put16(newpacket->data+i, 0x0001);
406 i += aimutil_put16(newpacket->data+i, 0x0002);
407 i += aimutil_put16(newpacket->data+i, 0x0003);
408 i += aimutil_put16(newpacket->data+i, 0x0004);
409 i += aimutil_put16(newpacket->data+i, 0x0005);
411 aim_tx_enqueue(sess, newpacket);
413 return (sess->snac_nextid);
417 * aim_bos_setprivacyflags()
419 * Sets privacy flags. Normally 0x03.
421 * Bit 1: Allows other AIM users to see how long you've been idle.
422 * Bit 2: Allows other AIM users to see how long you've been a member.
425 u_long aim_bos_setprivacyflags(struct aim_session_t *sess,
426 struct aim_conn_t *conn,
429 return aim_genericreq_l(sess, conn, 0x0001, 0x0014, &flags);
433 * aim_bos_reqpersonalinfo()
435 * Requests the current user's information. Can't go generic on this one
436 * because aparently it uses SNAC flags.
439 u_long aim_bos_reqpersonalinfo(struct aim_session_t *sess,
440 struct aim_conn_t *conn)
442 return aim_genericreq_n(sess, conn, 0x0001, 0x000e);
445 u_long aim_setversions(struct aim_session_t *sess,
446 struct aim_conn_t *conn)
448 struct command_tx_struct *newpacket;
451 if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10 + (4*12))))
456 i = aim_putsnac(newpacket->data, 0x0001, 0x0017, 0x0000, sess->snac_nextid);
458 i += aimutil_put16(newpacket->data+i, 0x0001);
459 i += aimutil_put16(newpacket->data+i, 0x0003);
461 i += aimutil_put16(newpacket->data+i, 0x0002);
462 i += aimutil_put16(newpacket->data+i, 0x0001);
464 i += aimutil_put16(newpacket->data+i, 0x0003);
465 i += aimutil_put16(newpacket->data+i, 0x0001);
467 i += aimutil_put16(newpacket->data+i, 0x0004);
468 i += aimutil_put16(newpacket->data+i, 0x0001);
470 i += aimutil_put16(newpacket->data+i, 0x0006);
471 i += aimutil_put16(newpacket->data+i, 0x0001);
473 i += aimutil_put16(newpacket->data+i, 0x0008);
474 i += aimutil_put16(newpacket->data+i, 0x0001);
476 i += aimutil_put16(newpacket->data+i, 0x0009);
477 i += aimutil_put16(newpacket->data+i, 0x0001);
479 i += aimutil_put16(newpacket->data+i, 0x000a);
480 i += aimutil_put16(newpacket->data+i, 0x0001);
482 i += aimutil_put16(newpacket->data+i, 0x000b);
483 i += aimutil_put16(newpacket->data+i, 0x0002);
485 i += aimutil_put16(newpacket->data+i, 0x000c);
486 i += aimutil_put16(newpacket->data+i, 0x0001);
488 i += aimutil_put16(newpacket->data+i, 0x0013);
489 i += aimutil_put16(newpacket->data+i, 0x0001);
491 i += aimutil_put16(newpacket->data+i, 0x0015);
492 i += aimutil_put16(newpacket->data+i, 0x0001);
495 for (j = 0; j < 0x10; j++) {
496 i += aimutil_put16(newpacket->data+i, j); /* family */
497 i += aimutil_put16(newpacket->data+i, 0x0003); /* version */
501 aim_tx_enqueue(sess, newpacket);
503 return (sess->snac_nextid++);
508 * aim_bos_reqservice(serviceid)
513 u_long aim_bos_reqservice(struct aim_session_t *sess,
514 struct aim_conn_t *conn,
517 return aim_genericreq_s(sess, conn, 0x0001, 0x0004, &serviceid);
523 * No-op. WinAIM sends these every 4min or so to keep
524 * the connection alive. Its not real necessary.
527 u_long aim_bos_nop(struct aim_session_t *sess,
528 struct aim_conn_t *conn)
530 return aim_genericreq_n(sess, conn, 0x0001, 0x0016);
534 * aim_bos_reqrights()
536 * Request BOS rights.
539 u_long aim_bos_reqrights(struct aim_session_t *sess,
540 struct aim_conn_t *conn)
542 return aim_genericreq_n(sess, conn, 0x0009, 0x0002);
546 * aim_bos_reqbuddyrights()
548 * Request Buddy List rights.
551 u_long aim_bos_reqbuddyrights(struct aim_session_t *sess,
552 struct aim_conn_t *conn)
554 return aim_genericreq_n(sess, conn, 0x0003, 0x0002);
558 * aim_send_warning(struct aim_session_t *sess,
559 * struct aim_conn_t *conn, char *destsn, int anon)
560 * send a warning to destsn.
561 * anon is anonymous or not;
562 * AIM_WARN_ANON anonymous
564 * returns -1 on error (couldn't alloc packet), next snacid on success.
567 int aim_send_warning(struct aim_session_t *sess, struct aim_conn_t *conn, char *destsn, int anon)
569 struct command_tx_struct *newpacket;
572 if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, strlen(destsn)+13)))
578 curbyte += aim_putsnac(newpacket->data+curbyte,
579 0x0004, 0x0008, 0x0000, sess->snac_nextid);
581 curbyte += aimutil_put16(newpacket->data+curbyte, (anon & AIM_WARN_ANON)?1:0);
583 curbyte += aimutil_put8(newpacket->data+curbyte, strlen(destsn));
585 curbyte += aimutil_putstr(newpacket->data+curbyte, destsn, strlen(destsn));
587 newpacket->commandlen = curbyte;
590 aim_tx_enqueue(sess, newpacket);
592 return (sess->snac_nextid++);
598 * aim_debugconn_sendconnect()
600 * For aimdebugd. If you don't know what it is, you don't want to.
602 u_long aim_debugconn_sendconnect(struct aim_session_t *sess,
603 struct aim_conn_t *conn)
605 return aim_genericreq_n(sess, conn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_DEBUGCONN_CONNECT);
609 * Generic routine for sending commands.
612 * I know I can do this in a smarter way...but I'm not thinking straight
615 * I had one big function that handled all three cases, but then it broke
616 * and I split it up into three. But then I fixed it. I just never went
617 * back to the single. I don't see any advantage to doing it either way.
620 u_long aim_genericreq_n(struct aim_session_t *sess,
621 struct aim_conn_t *conn,
622 u_short family, u_short subtype)
624 struct command_tx_struct *newpacket;
626 if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10)))
631 aim_putsnac(newpacket->data, family, subtype, 0x0000, sess->snac_nextid);
633 aim_tx_enqueue(sess, newpacket);
634 return (sess->snac_nextid++);
641 u_long aim_genericreq_l(struct aim_session_t *sess,
642 struct aim_conn_t *conn,
643 u_short family, u_short subtype, u_long *longdata)
645 struct command_tx_struct *newpacket;
648 /* If we don't have data, there's no reason to use this function */
650 return aim_genericreq_n(sess, conn, family, subtype);
652 if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+sizeof(u_long))))
657 aim_putsnac(newpacket->data, family, subtype, 0x0000, sess->snac_nextid);
660 newlong = htonl(*longdata);
661 memcpy(&(newpacket->data[10]), &newlong, sizeof(u_long));
663 aim_tx_enqueue(sess, newpacket);
664 return (sess->snac_nextid++);
667 u_long aim_genericreq_s(struct aim_session_t *sess,
668 struct aim_conn_t *conn,
669 u_short family, u_short subtype, u_short *shortdata)
671 struct command_tx_struct *newpacket;
674 /* If we don't have data, there's no reason to use this function */
676 return aim_genericreq_n(sess, conn, family, subtype);
678 if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+sizeof(u_short))))
683 aim_putsnac(newpacket->data, family, subtype, 0x0000, sess->snac_nextid);
686 newshort = htons(*shortdata);
687 memcpy(&(newpacket->data[10]), &newshort, sizeof(u_short));
689 aim_tx_enqueue(sess, newpacket);
690 return (sess->snac_nextid++);
694 * aim_bos_reqlocaterights()
696 * Request Location services rights.
699 u_long aim_bos_reqlocaterights(struct aim_session_t *sess,
700 struct aim_conn_t *conn)
702 return aim_genericreq_n(sess, conn, 0x0002, 0x0002);
706 * aim_bos_reqicbmparaminfo()
708 * Request ICBM parameter information.
711 u_long aim_bos_reqicbmparaminfo(struct aim_session_t *sess,
712 struct aim_conn_t *conn)
714 return aim_genericreq_n(sess, conn, 0x0004, 0x0004);
718 * Add ICBM parameter? Huh?
720 unsigned long aim_addicbmparam(struct aim_session_t *sess,
721 struct aim_conn_t *conn)
723 struct command_tx_struct *newpacket;
724 int packlen = 10+16, i=0;
726 if(!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, packlen)))
727 return (sess->snac_nextid);
731 i = aim_putsnac(newpacket->data, 0x0004, 0x0002, 0x0000, sess->snac_nextid);
732 i += aimutil_put16(newpacket->data+i, 0x0000);
733 i += aimutil_put16(newpacket->data+i, 0x0000);
734 i += aimutil_put16(newpacket->data+i, 0x0003);
735 i += aimutil_put16(newpacket->data+i, 0x1f40);
736 i += aimutil_put16(newpacket->data+i, 0x03e7);
737 i += aimutil_put16(newpacket->data+i, 0x03e7);
738 i += aimutil_put16(newpacket->data+i, 0x0000);
739 i += aimutil_put16(newpacket->data+i, 0x0000);
741 aim_tx_enqueue(sess, newpacket);
743 return (sess->snac_nextid);