1 | |
---|
2 | #define FAIM_INTERNAL |
---|
3 | #include <aim.h> |
---|
4 | |
---|
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 | * |
---|
10 | * Although the offgoing notification contains no information, |
---|
11 | * it is still in a format parsable by extractuserinfo. |
---|
12 | * |
---|
13 | */ |
---|
14 | static int buddychange(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
---|
15 | { |
---|
16 | aim_userinfo_t userinfo; |
---|
17 | aim_rxcallback_t userfunc; |
---|
18 | |
---|
19 | aim_extractuserinfo(sess, bs, &userinfo); |
---|
20 | |
---|
21 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
---|
22 | return userfunc(sess, rx, &userinfo); |
---|
23 | |
---|
24 | return 0; |
---|
25 | } |
---|
26 | |
---|
27 | static int rights(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
---|
28 | { |
---|
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; |
---|
62 | } |
---|
63 | |
---|
64 | static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
---|
65 | { |
---|
66 | |
---|
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); |
---|
71 | |
---|
72 | return 0; |
---|
73 | } |
---|
74 | |
---|
75 | faim_internal int buddylist_modfirst(aim_session_t *sess, aim_module_t *mod) |
---|
76 | { |
---|
77 | |
---|
78 | mod->family = 0x0003; |
---|
79 | mod->version = 0x0001; |
---|
80 | mod->toolid = 0x0110; |
---|
81 | mod->toolversion = 0x047b; |
---|
82 | mod->flags = 0; |
---|
83 | strncpy(mod->name, "buddylist", sizeof(mod->name)); |
---|
84 | mod->snachandler = snachandler; |
---|
85 | |
---|
86 | return 0; |
---|
87 | } |
---|
88 | |
---|
89 | /* |
---|
90 | * aim_add_buddy() |
---|
91 | * |
---|
92 | * Adds a single buddy to your buddy list after login. |
---|
93 | * |
---|
94 | * XXX this should just be an extension of setbuddylist() |
---|
95 | * |
---|
96 | */ |
---|
97 | faim_export int aim_add_buddy(aim_session_t *sess, aim_conn_t *conn, const char *sn) |
---|
98 | { |
---|
99 | aim_frame_t *fr; |
---|
100 | aim_snacid_t snacid; |
---|
101 | |
---|
102 | if (!sn || !strlen(sn)) |
---|
103 | return -EINVAL; |
---|
104 | |
---|
105 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn)))) |
---|
106 | return -ENOMEM; |
---|
107 | |
---|
108 | snacid = aim_cachesnac(sess, 0x0003, 0x0004, 0x0000, sn, strlen(sn)+1); |
---|
109 | aim_putsnac(&fr->data, 0x0003, 0x0004, 0x0000, snacid); |
---|
110 | |
---|
111 | aimbs_put8(&fr->data, strlen(sn)); |
---|
112 | aimbs_putraw(&fr->data, sn, strlen(sn)); |
---|
113 | |
---|
114 | aim_tx_enqueue(sess, fr); |
---|
115 | |
---|
116 | return 0; |
---|
117 | } |
---|
118 | |
---|
119 | /* |
---|
120 | * XXX generalise to support removing multiple buddies (basically, its |
---|
121 | * the same as setbuddylist() but with a different snac subtype). |
---|
122 | * |
---|
123 | */ |
---|
124 | faim_export int aim_remove_buddy(aim_session_t *sess, aim_conn_t *conn, const char *sn) |
---|
125 | { |
---|
126 | aim_frame_t *fr; |
---|
127 | aim_snacid_t snacid; |
---|
128 | |
---|
129 | if (!sn || !strlen(sn)) |
---|
130 | return -EINVAL; |
---|
131 | |
---|
132 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn)))) |
---|
133 | return -ENOMEM; |
---|
134 | |
---|
135 | snacid = aim_cachesnac(sess, 0x0003, 0x0005, 0x0000, sn, strlen(sn)+1); |
---|
136 | aim_putsnac(&fr->data, 0x0003, 0x0005, 0x0000, snacid); |
---|
137 | |
---|
138 | aimbs_put8(&fr->data, strlen(sn)); |
---|
139 | aimbs_putraw(&fr->data, sn, strlen(sn)); |
---|
140 | |
---|
141 | aim_tx_enqueue(sess, fr); |
---|
142 | |
---|
143 | return 0; |
---|
144 | } |
---|
145 | |
---|