6 * Oncoming Buddy notifications contain a subset of the
7 * user information structure. Its close enough to run
8 * through aim_extractuserinfo() however.
10 * Although the offgoing notification contains no information,
11 * it is still in a format parsable by extractuserinfo.
14 static int buddychange(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
16 aim_userinfo_t userinfo;
17 aim_rxcallback_t userfunc;
19 aim_extractuserinfo(sess, bs, &userinfo);
21 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
22 return userfunc(sess, rx, &userinfo);
27 static int rights(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
29 aim_rxcallback_t userfunc;
30 aim_tlvlist_t *tlvlist;
31 fu16_t maxbuddies = 0, maxwatchers = 0;
37 tlvlist = aim_readtlvchain(bs);
40 * TLV type 0x0001: Maximum number of buddies.
42 if (aim_gettlv(tlvlist, 0x0001, 1))
43 maxbuddies = aim_gettlv16(tlvlist, 0x0001, 1);
46 * TLV type 0x0002: Maximum number of watchers.
48 * Watchers are other users who have you on their buddy
49 * list. (This is called the "reverse list" by a certain
53 if (aim_gettlv(tlvlist, 0x0002, 1))
54 maxwatchers = aim_gettlv16(tlvlist, 0x0002, 1);
56 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
57 ret = userfunc(sess, rx, maxbuddies, maxwatchers);
59 aim_freetlvchain(&tlvlist);
64 static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
67 if (snac->subtype == 0x0003)
68 return rights(sess, mod, rx, snac, bs);
69 else if ((snac->subtype == 0x000b) || (snac->subtype == 0x000c))
70 return buddychange(sess, mod, rx, snac, bs);
75 faim_internal int buddylist_modfirst(aim_session_t *sess, aim_module_t *mod)
79 mod->version = 0x0000;
81 strncpy(mod->name, "buddylist", sizeof(mod->name));
82 mod->snachandler = snachandler;
90 * Adds a single buddy to your buddy list after login.
92 * XXX this should just be an extension of setbuddylist()
95 faim_export int aim_add_buddy(aim_session_t *sess, aim_conn_t *conn, const char *sn)
100 if (!sn || !strlen(sn))
103 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn))))
106 snacid = aim_cachesnac(sess, 0x0003, 0x0004, 0x0000, sn, strlen(sn)+1);
107 aim_putsnac(&fr->data, 0x0003, 0x0004, 0x0000, snacid);
109 aimbs_put8(&fr->data, strlen(sn));
110 aimbs_putraw(&fr->data, sn, strlen(sn));
112 aim_tx_enqueue(sess, fr);
118 * XXX generalise to support removing multiple buddies (basically, its
119 * the same as setbuddylist() but with a different snac subtype).
122 faim_export int aim_remove_buddy(aim_session_t *sess, aim_conn_t *conn, const char *sn)
127 if (!sn || !strlen(sn))
130 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn))))
133 snacid = aim_cachesnac(sess, 0x0003, 0x0005, 0x0000, sn, strlen(sn)+1);
134 aim_putsnac(&fr->data, 0x0003, 0x0005, 0x0000, snacid);
136 aimbs_put8(&fr->data, strlen(sn));
137 aimbs_putraw(&fr->data, sn, strlen(sn));
139 aim_tx_enqueue(sess, fr);