]>
Commit | Line | Data |
---|---|---|
9de3ca7e | 1 | |
37ee990e | 2 | #define FAIM_INTERNAL |
dd60ff8b | 3 | #include <aim.h> |
9de3ca7e | 4 | |
9f1a4013 | 5 | /* |
6 | * Oncoming Buddy notifications contain a subset of the | |
7 | * user information structure. Its close enough to run | |
8 | * through aim_extractuserinfo() however. | |
9 | * | |
69e7980c | 10 | * Although the offgoing notification contains no information, |
11 | * it is still in a format parsable by extractuserinfo. | |
12 | * | |
9f1a4013 | 13 | */ |
d410cf58 | 14 | static int buddychange(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
9f1a4013 | 15 | { |
7b0bc7f2 | 16 | aim_userinfo_t userinfo; |
d410cf58 | 17 | aim_rxcallback_t userfunc; |
9f1a4013 | 18 | |
d410cf58 | 19 | aim_extractuserinfo(sess, bs, &userinfo); |
9f1a4013 | 20 | |
d410cf58 | 21 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
22 | return userfunc(sess, rx, &userinfo); | |
9f1a4013 | 23 | |
d410cf58 | 24 | return 0; |
9f1a4013 | 25 | } |
26 | ||
d410cf58 | 27 | static int rights(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
9f1a4013 | 28 | { |
d410cf58 | 29 | aim_rxcallback_t userfunc; |
30 | aim_tlvlist_t *tlvlist; | |
31 | fu16_t maxbuddies = 0, maxwatchers = 0; | |
32 | int ret = 0; | |
33 | ||
34 | /* | |
35 | * TLVs follow | |
36 | */ | |
37 | tlvlist = aim_readtlvchain(bs); | |
38 | ||
39 | /* | |
40 | * TLV type 0x0001: Maximum number of buddies. | |
41 | */ | |
42 | if (aim_gettlv(tlvlist, 0x0001, 1)) | |
43 | maxbuddies = aim_gettlv16(tlvlist, 0x0001, 1); | |
44 | ||
45 | /* | |
46 | * TLV type 0x0002: Maximum number of watchers. | |
47 | * | |
48 | * Watchers are other users who have you on their buddy | |
49 | * list. (This is called the "reverse list" by a certain | |
50 | * other IM protocol.) | |
51 | * | |
52 | */ | |
53 | if (aim_gettlv(tlvlist, 0x0002, 1)) | |
54 | maxwatchers = aim_gettlv16(tlvlist, 0x0002, 1); | |
55 | ||
56 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
57 | ret = userfunc(sess, rx, maxbuddies, maxwatchers); | |
58 | ||
59 | aim_freetlvchain(&tlvlist); | |
60 | ||
61 | return ret; | |
9f1a4013 | 62 | } |
63 | ||
d410cf58 | 64 | static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
9f1a4013 | 65 | { |
66 | ||
d410cf58 | 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); | |
9f1a4013 | 71 | |
d410cf58 | 72 | return 0; |
9f1a4013 | 73 | } |
74 | ||
d410cf58 | 75 | faim_internal int buddylist_modfirst(aim_session_t *sess, aim_module_t *mod) |
9f1a4013 | 76 | { |
77 | ||
d410cf58 | 78 | mod->family = 0x0003; |
79 | mod->version = 0x0000; | |
80 | mod->flags = 0; | |
81 | strncpy(mod->name, "buddylist", sizeof(mod->name)); | |
82 | mod->snachandler = snachandler; | |
9f1a4013 | 83 | |
d410cf58 | 84 | return 0; |
9f1a4013 | 85 | } |
86 | ||
9de3ca7e | 87 | /* |
88 | * aim_add_buddy() | |
89 | * | |
90 | * Adds a single buddy to your buddy list after login. | |
91 | * | |
37ee990e | 92 | * XXX this should just be an extension of setbuddylist() |
93 | * | |
9de3ca7e | 94 | */ |
d410cf58 | 95 | faim_export int aim_add_buddy(aim_session_t *sess, aim_conn_t *conn, const char *sn) |
9de3ca7e | 96 | { |
d410cf58 | 97 | aim_frame_t *fr; |
98 | aim_snacid_t snacid; | |
9de3ca7e | 99 | |
d410cf58 | 100 | if (!sn || !strlen(sn)) |
101 | return -EINVAL; | |
9de3ca7e | 102 | |
d410cf58 | 103 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn)))) |
104 | return -ENOMEM; | |
9de3ca7e | 105 | |
d410cf58 | 106 | snacid = aim_cachesnac(sess, 0x0003, 0x0004, 0x0000, sn, strlen(sn)+1); |
107 | aim_putsnac(&fr->data, 0x0003, 0x0004, 0x0000, snacid); | |
9de3ca7e | 108 | |
d410cf58 | 109 | aimbs_put8(&fr->data, strlen(sn)); |
110 | aimbs_putraw(&fr->data, sn, strlen(sn)); | |
9de3ca7e | 111 | |
d410cf58 | 112 | aim_tx_enqueue(sess, fr); |
9de3ca7e | 113 | |
d410cf58 | 114 | return 0; |
9de3ca7e | 115 | } |
116 | ||
37ee990e | 117 | /* |
118 | * XXX generalise to support removing multiple buddies (basically, its | |
119 | * the same as setbuddylist() but with a different snac subtype). | |
120 | * | |
121 | */ | |
d410cf58 | 122 | faim_export int aim_remove_buddy(aim_session_t *sess, aim_conn_t *conn, const char *sn) |
9de3ca7e | 123 | { |
d410cf58 | 124 | aim_frame_t *fr; |
125 | aim_snacid_t snacid; | |
9de3ca7e | 126 | |
d410cf58 | 127 | if (!sn || !strlen(sn)) |
128 | return -EINVAL; | |
9de3ca7e | 129 | |
25aaf30e | 130 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn)))) |
d410cf58 | 131 | return -ENOMEM; |
9de3ca7e | 132 | |
d410cf58 | 133 | snacid = aim_cachesnac(sess, 0x0003, 0x0005, 0x0000, sn, strlen(sn)+1); |
134 | aim_putsnac(&fr->data, 0x0003, 0x0005, 0x0000, snacid); | |
9de3ca7e | 135 | |
d410cf58 | 136 | aimbs_put8(&fr->data, strlen(sn)); |
137 | aimbs_putraw(&fr->data, sn, strlen(sn)); | |
9de3ca7e | 138 | |
d410cf58 | 139 | aim_tx_enqueue(sess, fr); |
9de3ca7e | 140 | |
d410cf58 | 141 | return 0; |
9de3ca7e | 142 | } |
143 |