Mercurial > pidgin
annotate src/protocols/oscar/buddylist.c @ 8900:7a67c459ab8f
[gaim-migrate @ 9669]
Move the preference renameing/removing stuff to prefs.c...
It's pretty ugly... but it was ugly before...
So now we remove the eradicated prefs. I think.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Fri, 07 May 2004 03:25:00 +0000 |
parents | a50eea7628cb |
children | 096197a628bf |
rev | line source |
---|---|
3952 | 1 /* |
2 * Family 0x0003 - Old-style Buddylist Management (non-SSI). | |
3 * | |
4 */ | |
2086 | 5 |
6 #define FAIM_INTERNAL | |
7 #include <aim.h> | |
8 | |
5927 | 9 #include <string.h> |
10 | |
2086 | 11 /* |
3952 | 12 * Subtype 0x0002 - Request rights. |
2086 | 13 * |
3952 | 14 * Request Buddy List rights. |
2086 | 15 * |
16 */ | |
7285 | 17 faim_export int aim_buddylist_reqrights(aim_session_t *sess, aim_conn_t *conn) |
2086 | 18 { |
7282 | 19 return aim_genericreq_n_snacid(sess, conn, 0x0003, 0x0002); |
2086 | 20 } |
21 | |
3952 | 22 /* |
23 * Subtype 0x0003 - Rights. | |
24 * | |
25 */ | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
26 static int rights(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
2086 | 27 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
28 aim_rxcallback_t userfunc; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
29 aim_tlvlist_t *tlvlist; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
30 fu16_t maxbuddies = 0, maxwatchers = 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
31 int ret = 0; |
2086 | 32 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
33 /* |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
34 * TLVs follow |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
35 */ |
7167 | 36 tlvlist = aim_tlvlist_read(bs); |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
37 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
38 /* |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
39 * TLV type 0x0001: Maximum number of buddies. |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
40 */ |
7167 | 41 if (aim_tlv_gettlv(tlvlist, 0x0001, 1)) |
42 maxbuddies = aim_tlv_get16(tlvlist, 0x0001, 1); | |
2086 | 43 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
44 /* |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
45 * TLV type 0x0002: Maximum number of watchers. |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
46 * |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
47 * Watchers are other users who have you on their buddy |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
48 * list. (This is called the "reverse list" by a certain |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
49 * other IM protocol.) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
50 * |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
51 */ |
7167 | 52 if (aim_tlv_gettlv(tlvlist, 0x0002, 1)) |
53 maxwatchers = aim_tlv_get16(tlvlist, 0x0002, 1); | |
2086 | 54 |
3213 | 55 /* |
56 * TLV type 0x0003: Unknown. | |
57 * | |
58 * ICQ only? | |
59 */ | |
60 | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
61 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
62 ret = userfunc(sess, rx, maxbuddies, maxwatchers); |
2086 | 63 |
7167 | 64 aim_tlvlist_free(&tlvlist); |
2086 | 65 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
66 return ret; |
2086 | 67 } |
68 | |
69 /* | |
3952 | 70 * Subtype 0x0004 - Add buddy to list. |
2086 | 71 * |
72 * Adds a single buddy to your buddy list after login. | |
3952 | 73 * XXX This should just be an extension of setbuddylist() |
2086 | 74 * |
75 */ | |
7285 | 76 faim_export int aim_buddylist_addbuddy(aim_session_t *sess, aim_conn_t *conn, const char *sn) |
2086 | 77 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
78 aim_frame_t *fr; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
79 aim_snacid_t snacid; |
2086 | 80 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
81 if (!sn || !strlen(sn)) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
82 return -EINVAL; |
2086 | 83 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
84 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn)))) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
85 return -ENOMEM; |
2086 | 86 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
87 snacid = aim_cachesnac(sess, 0x0003, 0x0004, 0x0000, sn, strlen(sn)+1); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
88 aim_putsnac(&fr->data, 0x0003, 0x0004, 0x0000, snacid); |
2086 | 89 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
90 aimbs_put8(&fr->data, strlen(sn)); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
91 aimbs_putraw(&fr->data, sn, strlen(sn)); |
2086 | 92 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
93 aim_tx_enqueue(sess, fr); |
2086 | 94 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
95 return 0; |
2086 | 96 } |
97 | |
98 /* | |
3952 | 99 * Subtype 0x0004 - Add multiple buddies to your buddy list. |
100 * | |
101 * This just builds the "set buddy list" command then queues it. | |
102 * | |
103 * buddy_list = "Screen Name One&ScreenNameTwo&"; | |
104 * | |
105 * XXX Clean this up. | |
106 * | |
107 */ | |
7285 | 108 faim_export int aim_buddylist_set(aim_session_t *sess, aim_conn_t *conn, const char *buddy_list) |
3952 | 109 { |
110 aim_frame_t *fr; | |
111 aim_snacid_t snacid; | |
112 int len = 0; | |
113 char *localcpy = NULL; | |
114 char *tmpptr = NULL; | |
115 | |
116 if (!buddy_list || !(localcpy = strdup(buddy_list))) | |
117 return -EINVAL; | |
118 | |
119 for (tmpptr = strtok(localcpy, "&"); tmpptr; ) { | |
120 faimdprintf(sess, 2, "---adding: %s (%d)\n", tmpptr, strlen(tmpptr)); | |
121 len += 1 + strlen(tmpptr); | |
122 tmpptr = strtok(NULL, "&"); | |
123 } | |
124 | |
125 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+len))) | |
126 return -ENOMEM; | |
127 | |
128 snacid = aim_cachesnac(sess, 0x0003, 0x0004, 0x0000, NULL, 0); | |
129 aim_putsnac(&fr->data, 0x0003, 0x0004, 0x0000, snacid); | |
130 | |
131 strncpy(localcpy, buddy_list, strlen(buddy_list) + 1); | |
132 | |
133 for (tmpptr = strtok(localcpy, "&"); tmpptr; ) { | |
134 | |
135 faimdprintf(sess, 2, "---adding: %s (%d)\n", tmpptr, strlen(tmpptr)); | |
136 | |
137 aimbs_put8(&fr->data, strlen(tmpptr)); | |
138 aimbs_putraw(&fr->data, tmpptr, strlen(tmpptr)); | |
139 tmpptr = strtok(NULL, "&"); | |
140 } | |
141 | |
142 aim_tx_enqueue(sess, fr); | |
143 | |
144 free(localcpy); | |
145 | |
146 return 0; | |
147 } | |
148 | |
149 /* | |
150 * Subtype 0x0005 - Remove buddy from list. | |
151 * | |
2086 | 152 * XXX generalise to support removing multiple buddies (basically, its |
153 * the same as setbuddylist() but with a different snac subtype). | |
154 * | |
155 */ | |
7285 | 156 faim_export int aim_buddylist_removebuddy(aim_session_t *sess, aim_conn_t *conn, const char *sn) |
2086 | 157 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
158 aim_frame_t *fr; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
159 aim_snacid_t snacid; |
2086 | 160 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
161 if (!sn || !strlen(sn)) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
162 return -EINVAL; |
2086 | 163 |
2315
7ec21662ffc2
[gaim-migrate @ 2325]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
164 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn)))) |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
165 return -ENOMEM; |
2086 | 166 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
167 snacid = aim_cachesnac(sess, 0x0003, 0x0005, 0x0000, sn, strlen(sn)+1); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
168 aim_putsnac(&fr->data, 0x0003, 0x0005, 0x0000, snacid); |
2086 | 169 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
170 aimbs_put8(&fr->data, strlen(sn)); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
171 aimbs_putraw(&fr->data, sn, strlen(sn)); |
2086 | 172 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
173 aim_tx_enqueue(sess, fr); |
2086 | 174 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
175 return 0; |
2086 | 176 } |
177 | |
3952 | 178 /* |
179 * Subtype 0x000b | |
180 * | |
181 * XXX Why would we send this? | |
182 * | |
183 */ | |
7285 | 184 faim_export int aim_buddylist_oncoming(aim_session_t *sess, aim_conn_t *conn, aim_userinfo_t *info) |
3952 | 185 { |
186 aim_frame_t *fr; | |
187 aim_snacid_t snacid; | |
188 | |
189 if (!sess || !conn || !info) | |
190 return -EINVAL; | |
191 | |
192 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152))) | |
193 return -ENOMEM; | |
194 | |
195 snacid = aim_cachesnac(sess, 0x0003, 0x000b, 0x0000, NULL, 0); | |
196 | |
197 aim_putsnac(&fr->data, 0x0003, 0x000b, 0x0000, snacid); | |
198 aim_putuserinfo(&fr->data, info); | |
199 | |
200 aim_tx_enqueue(sess, fr); | |
201 | |
202 return 0; | |
203 } | |
204 | |
205 /* | |
206 * Subtype 0x000c | |
207 * | |
208 * XXX Why would we send this? | |
209 * | |
210 */ | |
7285 | 211 faim_export int aim_buddylist_offgoing(aim_session_t *sess, aim_conn_t *conn, const char *sn) |
3952 | 212 { |
213 aim_frame_t *fr; | |
214 aim_snacid_t snacid; | |
215 | |
216 if (!sess || !conn || !sn) | |
217 return -EINVAL; | |
218 | |
219 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn)))) | |
220 return -ENOMEM; | |
221 | |
222 snacid = aim_cachesnac(sess, 0x0003, 0x000c, 0x0000, NULL, 0); | |
223 | |
224 aim_putsnac(&fr->data, 0x0003, 0x000c, 0x0000, snacid); | |
225 aimbs_put8(&fr->data, strlen(sn)); | |
226 aimbs_putraw(&fr->data, sn, strlen(sn)); | |
227 | |
228 aim_tx_enqueue(sess, fr); | |
229 | |
230 return 0; | |
231 } | |
232 | |
233 /* | |
234 * Subtypes 0x000b and 0x000c - Change in buddy status | |
235 * | |
236 * Oncoming Buddy notifications contain a subset of the | |
5836 | 237 * user information structure. It's close enough to run |
238 * through aim_info_extract() however. | |
3952 | 239 * |
240 * Although the offgoing notification contains no information, | |
5836 | 241 * it is still in a format parsable by aim_info_extract(). |
3952 | 242 * |
243 */ | |
244 static int buddychange(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) | |
245 { | |
4871 | 246 int ret = 0; |
3952 | 247 aim_userinfo_t userinfo; |
248 aim_rxcallback_t userfunc; | |
249 | |
5836 | 250 aim_info_extract(sess, bs, &userinfo); |
3952 | 251 |
252 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
4871 | 253 ret = userfunc(sess, rx, &userinfo); |
3952 | 254 |
7011 | 255 if (snac->subtype == 0x000b) |
256 aim_locate_requestuserinfo(sess, userinfo.sn); | |
5836 | 257 aim_info_free(&userinfo); |
258 | |
4871 | 259 return ret; |
3952 | 260 } |
261 | |
262 static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) | |
263 { | |
264 | |
265 if (snac->subtype == 0x0003) | |
266 return rights(sess, mod, rx, snac, bs); | |
267 else if ((snac->subtype == 0x000b) || (snac->subtype == 0x000c)) | |
268 return buddychange(sess, mod, rx, snac, bs); | |
269 | |
270 return 0; | |
271 } | |
272 | |
273 faim_internal int buddylist_modfirst(aim_session_t *sess, aim_module_t *mod) | |
274 { | |
275 | |
276 mod->family = 0x0003; | |
277 mod->version = 0x0001; | |
278 mod->toolid = 0x0110; | |
4071 | 279 mod->toolversion = 0x0629; |
3952 | 280 mod->flags = 0; |
281 strncpy(mod->name, "buddylist", sizeof(mod->name)); | |
282 mod->snachandler = snachandler; | |
283 | |
284 return 0; | |
285 } |