Mercurial > pidgin
annotate libfaim/misc.c @ 1861:7ec37e31e5eb
[gaim-migrate @ 1871]
this is not an "official" fix
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Sat, 19 May 2001 17:57:49 +0000 |
parents | 109cacf1ff97 |
children | 741842331ceb |
rev | line source |
---|---|
1535 | 1 |
2 /* | |
3 * aim_misc.c | |
4 * | |
5 * TODO: Seperate a lot of this into an aim_bos.c. | |
6 * | |
7 * Other things... | |
8 * | |
9 * - Idle setting | |
10 * | |
11 * | |
12 */ | |
13 | |
14 #define FAIM_INTERNAL | |
15 #include <aim.h> | |
16 | |
17 /* | |
18 * aim_bos_setidle() | |
19 * | |
20 * Should set your current idle time in seconds. Idealy, OSCAR should | |
21 * do this for us. But, it doesn't. The client must call this to set idle | |
22 * time. | |
23 * | |
24 */ | |
25 faim_export unsigned long aim_bos_setidle(struct aim_session_t *sess, | |
26 struct aim_conn_t *conn, | |
27 u_long idletime) | |
28 { | |
29 return aim_genericreq_l(sess, conn, 0x0001, 0x0011, &idletime); | |
30 } | |
31 | |
32 | |
33 /* | |
34 * aim_bos_changevisibility(conn, changtype, namelist) | |
35 * | |
36 * Changes your visibility depending on changetype: | |
37 * | |
38 * AIM_VISIBILITYCHANGE_PERMITADD: Lets provided list of names see you | |
39 * AIM_VISIBILITYCHANGE_PERMIDREMOVE: Removes listed names from permit list | |
40 * AIM_VISIBILITYCHANGE_DENYADD: Hides you from provided list of names | |
41 * AIM_VISIBILITYCHANGE_DENYREMOVE: Lets list see you again | |
42 * | |
43 * list should be a list of | |
44 * screen names in the form "Screen Name One&ScreenNameTwo&" etc. | |
45 * | |
46 * Equivelents to options in WinAIM: | |
47 * - Allow all users to contact me: Send an AIM_VISIBILITYCHANGE_DENYADD | |
48 * with only your name on it. | |
49 * - Allow only users on my Buddy List: Send an | |
50 * AIM_VISIBILITYCHANGE_PERMITADD with the list the same as your | |
51 * buddy list | |
52 * - Allow only the uesrs below: Send an AIM_VISIBILITYCHANGE_PERMITADD | |
53 * with everyone listed that you want to see you. | |
54 * - Block all users: Send an AIM_VISIBILITYCHANGE_PERMITADD with only | |
55 * yourself in the list | |
56 * - Block the users below: Send an AIM_VISIBILITYCHANGE_DENYADD with | |
57 * the list of users to be blocked | |
58 * | |
59 * | |
60 */ | |
61 faim_export unsigned long aim_bos_changevisibility(struct aim_session_t *sess, | |
62 struct aim_conn_t *conn, | |
63 int changetype, | |
64 char *denylist) | |
65 { | |
66 struct command_tx_struct *newpacket; | |
67 int packlen = 0; | |
68 u_short subtype; | |
69 | |
70 char *localcpy = NULL; | |
71 char *tmpptr = NULL; | |
72 int i,j; | |
73 int listcount; | |
74 | |
75 if (!denylist) | |
76 return 0; | |
77 | |
78 localcpy = (char *) malloc(strlen(denylist)+1); | |
79 memcpy(localcpy, denylist, strlen(denylist)+1); | |
80 | |
81 listcount = aimutil_itemcnt(localcpy, '&'); | |
82 packlen = aimutil_tokslen(localcpy, 99, '&') + listcount + 9; | |
83 | |
84 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, packlen))) | |
85 return -1; | |
86 | |
87 newpacket->lock = 1; | |
88 | |
89 switch(changetype) | |
90 { | |
91 case AIM_VISIBILITYCHANGE_PERMITADD: subtype = 0x05; break; | |
92 case AIM_VISIBILITYCHANGE_PERMITREMOVE: subtype = 0x06; break; | |
93 case AIM_VISIBILITYCHANGE_DENYADD: subtype = 0x07; break; | |
94 case AIM_VISIBILITYCHANGE_DENYREMOVE: subtype = 0x08; break; | |
95 default: | |
96 free(newpacket->data); | |
97 free(newpacket); | |
98 return 0; | |
99 } | |
100 | |
101 /* We actually DO NOT send a SNAC ID with this one! */ | |
102 aim_putsnac(newpacket->data, 0x0009, subtype, 0x00, 0); | |
103 | |
104 j = 10; /* the next byte */ | |
105 | |
106 for (i=0; (i < (listcount - 1)) && (i < 99); i++) | |
107 { | |
108 tmpptr = aimutil_itemidx(localcpy, i, '&'); | |
109 | |
110 newpacket->data[j] = strlen(tmpptr); | |
111 memcpy(&(newpacket->data[j+1]), tmpptr, strlen(tmpptr)); | |
112 j += strlen(tmpptr)+1; | |
113 free(tmpptr); | |
114 } | |
115 free(localcpy); | |
116 | |
117 newpacket->lock = 0; | |
118 | |
119 aim_tx_enqueue(sess, newpacket); | |
120 | |
121 return (sess->snac_nextid); /* dont increment */ | |
122 | |
123 } | |
124 | |
125 | |
126 | |
127 /* | |
128 * aim_bos_setbuddylist(buddylist) | |
129 * | |
130 * This just builds the "set buddy list" command then queues it. | |
131 * | |
132 * buddy_list = "Screen Name One&ScreenNameTwo&"; | |
133 * | |
134 * TODO: Clean this up. | |
135 * | |
136 * XXX: I can't stress the TODO enough. | |
137 * | |
138 */ | |
139 faim_export unsigned long aim_bos_setbuddylist(struct aim_session_t *sess, | |
140 struct aim_conn_t *conn, | |
141 char *buddy_list) | |
142 { | |
143 int i, j; | |
144 | |
145 struct command_tx_struct *newpacket; | |
146 | |
147 int len = 0; | |
148 | |
149 char *localcpy = NULL; | |
150 char *tmpptr = NULL; | |
151 | |
152 len = 10; /* 10B SNAC headers */ | |
153 | |
154 if (!buddy_list || !(localcpy = (char *) malloc(strlen(buddy_list)+1))) | |
155 return -1; | |
156 strncpy(localcpy, buddy_list, strlen(buddy_list)+1); | |
157 | |
158 i = 0; | |
159 tmpptr = strtok(localcpy, "&"); | |
160 while ((tmpptr != NULL) && (i < 150)) { | |
161 faimdprintf(sess, 2, "---adding %d: %s (%d)\n", i, tmpptr, strlen(tmpptr)); | |
162 len += 1+strlen(tmpptr); | |
163 i++; | |
164 tmpptr = strtok(NULL, "&"); | |
165 } | |
166 faimdprintf(sess, 2, "*** send buddy list len: %d (%x)\n", len, len); | |
167 | |
168 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, len))) | |
169 return -1; | |
170 | |
171 newpacket->lock = 1; | |
172 | |
173 aim_putsnac(newpacket->data, 0x0003, 0x0004, 0x0000, 0); | |
174 | |
175 j = 10; /* the next byte */ | |
176 | |
177 strncpy(localcpy, buddy_list, strlen(buddy_list)+1); | |
178 i = 0; | |
179 tmpptr = strtok(localcpy, "&"); | |
180 while ((tmpptr != NULL) & (i < 150)) { | |
181 faimdprintf(sess, 2, "---adding %d: %s (%d)\n", i, tmpptr, strlen(tmpptr)); | |
182 newpacket->data[j] = strlen(tmpptr); | |
183 memcpy(&(newpacket->data[j+1]), tmpptr, strlen(tmpptr)); | |
184 j += 1+strlen(tmpptr); | |
185 i++; | |
186 tmpptr = strtok(NULL, "&"); | |
187 } | |
188 | |
189 newpacket->lock = 0; | |
190 | |
191 aim_tx_enqueue(sess, newpacket); | |
192 | |
193 free(localcpy); | |
194 | |
195 return (sess->snac_nextid); | |
196 } | |
197 | |
198 /* | |
199 * aim_bos_setprofile(profile) | |
200 * | |
201 * Gives BOS your profile. | |
202 * | |
203 * | |
204 */ | |
205 faim_export unsigned long aim_bos_setprofile(struct aim_session_t *sess, | |
206 struct aim_conn_t *conn, | |
207 char *profile, | |
208 char *awaymsg, | |
209 unsigned short caps) | |
210 { | |
211 struct command_tx_struct *newpacket; | |
212 int i = 0, tmp, caplen; | |
213 | |
214 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 1152+strlen(profile)+1+(awaymsg?strlen(awaymsg):0)))) | |
215 return -1; | |
216 | |
217 i += aim_putsnac(newpacket->data, 0x0002, 0x004, 0x0000, sess->snac_nextid); | |
1649 | 218 i += aim_puttlv_str(newpacket->data+i, 0x0001, strlen("text/aolrtf; charset=\"us-ascii\""), "text/x-aolrtf; charset=\"us-ascii\""); |
1535 | 219 i += aim_puttlv_str(newpacket->data+i, 0x0002, strlen(profile), profile); |
220 /* why do we send this twice? */ | |
1649 | 221 i += aim_puttlv_str(newpacket->data+i, 0x0003, strlen("text/aolrtf; charset=\"us-ascii\""), "text/x-aolrtf; charset=\"us-ascii\""); |
1535 | 222 |
223 /* Away message -- we send this no matter what, even if its blank */ | |
224 if (awaymsg) | |
225 i += aim_puttlv_str(newpacket->data+i, 0x0004, strlen(awaymsg), awaymsg); | |
226 else | |
227 i += aim_puttlv_str(newpacket->data+i, 0x0004, 0x0000, NULL); | |
228 | |
229 /* Capability information. */ | |
230 | |
231 tmp = (i += aimutil_put16(newpacket->data+i, 0x0005)); | |
232 i += aimutil_put16(newpacket->data+i, 0x0000); /* rewritten later */ | |
233 i += (caplen = aim_putcap(newpacket->data+i, 512, caps)); | |
234 aimutil_put16(newpacket->data+tmp, caplen); /* rewrite TLV size */ | |
235 | |
236 newpacket->commandlen = i; | |
237 aim_tx_enqueue(sess, newpacket); | |
238 | |
239 return (sess->snac_nextid++); | |
240 } | |
241 | |
242 /* | |
243 * aim_bos_clientready() | |
244 * | |
245 * Send Client Ready. | |
246 * | |
247 */ | |
248 faim_export unsigned long aim_bos_clientready(struct aim_session_t *sess, | |
249 struct aim_conn_t *conn) | |
250 { | |
251 struct aim_tool_version tools[] = { | |
252 {0x0001, 0x0003, AIM_TOOL_WIN32, 0x0686}, | |
253 {0x0002, 0x0001, AIM_TOOL_WIN32, 0x0001}, | |
254 {0x0003, 0x0001, AIM_TOOL_WIN32, 0x0001}, | |
255 {0x0004, 0x0001, AIM_TOOL_WIN32, 0x0001}, | |
256 {0x0006, 0x0001, AIM_TOOL_WIN32, 0x0001}, | |
257 {0x0008, 0x0001, AIM_TOOL_WIN32, 0x0001}, | |
258 {0x0009, 0x0001, AIM_TOOL_WIN32, 0x0001}, | |
259 {0x000a, 0x0001, AIM_TOOL_WIN32, 0x0001}, | |
260 {0x000b, 0x0001, AIM_TOOL_WIN32, 0x0001} | |
261 }; | |
262 int i,j; | |
263 struct command_tx_struct *newpacket; | |
264 int toolcount = sizeof(tools)/sizeof(struct aim_tool_version); | |
265 | |
266 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 1152))) | |
267 return -1; | |
268 | |
269 newpacket->lock = 1; | |
270 | |
271 i = aim_putsnac(newpacket->data, 0x0001, 0x0002, 0x0000, sess->snac_nextid); | |
272 aim_cachesnac(sess, 0x0001, 0x0002, 0x0000, NULL, 0); | |
273 | |
274 for (j = 0; j < toolcount; j++) { | |
275 i += aimutil_put16(newpacket->data+i, tools[j].group); | |
276 i += aimutil_put16(newpacket->data+i, tools[j].version); | |
277 i += aimutil_put16(newpacket->data+i, tools[j].tool); | |
278 i += aimutil_put16(newpacket->data+i, tools[j].toolversion); | |
279 } | |
280 | |
281 newpacket->commandlen = i; | |
282 newpacket->lock = 0; | |
283 | |
284 aim_tx_enqueue(sess, newpacket); | |
285 | |
286 return sess->snac_nextid; | |
287 } | |
288 | |
289 /* | |
290 * Request Rate Information. | |
291 * | |
292 */ | |
293 faim_export unsigned long aim_bos_reqrate(struct aim_session_t *sess, | |
294 struct aim_conn_t *conn) | |
295 { | |
296 return aim_genericreq_n(sess, conn, 0x0001, 0x0006); | |
297 } | |
298 | |
299 /* | |
300 * Rate Information Response Acknowledge. | |
301 * | |
302 */ | |
303 faim_export unsigned long aim_bos_ackrateresp(struct aim_session_t *sess, | |
304 struct aim_conn_t *conn) | |
305 { | |
306 struct command_tx_struct *newpacket; | |
307 int packlen = 20, i=0; | |
308 | |
309 if(!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, packlen))) | |
310 return (sess->snac_nextid); | |
311 | |
312 newpacket->lock = 1; | |
313 | |
314 i = aim_putsnac(newpacket->data, 0x0001, 0x0008, 0x0000, 0); | |
315 i += aimutil_put16(newpacket->data+i, 0x0001); | |
316 i += aimutil_put16(newpacket->data+i, 0x0002); | |
317 i += aimutil_put16(newpacket->data+i, 0x0003); | |
318 i += aimutil_put16(newpacket->data+i, 0x0004); | |
319 i += aimutil_put16(newpacket->data+i, 0x0005); | |
320 | |
321 newpacket->commandlen = i; | |
322 newpacket->lock = 0; | |
323 | |
324 aim_tx_enqueue(sess, newpacket); | |
325 | |
326 return (sess->snac_nextid); | |
327 } | |
328 | |
329 /* | |
330 * aim_bos_setprivacyflags() | |
331 * | |
332 * Sets privacy flags. Normally 0x03. | |
333 * | |
334 * Bit 1: Allows other AIM users to see how long you've been idle. | |
335 * Bit 2: Allows other AIM users to see how long you've been a member. | |
336 * | |
337 */ | |
338 faim_export unsigned long aim_bos_setprivacyflags(struct aim_session_t *sess, | |
339 struct aim_conn_t *conn, | |
340 u_long flags) | |
341 { | |
342 return aim_genericreq_l(sess, conn, 0x0001, 0x0014, &flags); | |
343 } | |
344 | |
345 /* | |
346 * aim_bos_reqpersonalinfo() | |
347 * | |
348 * Requests the current user's information. Can't go generic on this one | |
349 * because aparently it uses SNAC flags. | |
350 * | |
351 */ | |
352 faim_export unsigned long aim_bos_reqpersonalinfo(struct aim_session_t *sess, | |
353 struct aim_conn_t *conn) | |
354 { | |
355 return aim_genericreq_n(sess, conn, 0x0001, 0x000e); | |
356 } | |
357 | |
358 faim_export unsigned long aim_setversions(struct aim_session_t *sess, | |
359 struct aim_conn_t *conn) | |
360 { | |
361 struct command_tx_struct *newpacket; | |
362 int i; | |
363 | |
1649 | 364 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10 + (4*16)))) |
1535 | 365 return -1; |
366 | |
367 newpacket->lock = 1; | |
368 | |
369 i = aim_putsnac(newpacket->data, 0x0001, 0x0017, 0x0000, sess->snac_nextid); | |
370 aim_cachesnac(sess, 0x0001, 0x0017, 0x0000, NULL, 0); | |
371 | |
372 i += aimutil_put16(newpacket->data+i, 0x0001); | |
373 i += aimutil_put16(newpacket->data+i, 0x0003); | |
374 | |
375 i += aimutil_put16(newpacket->data+i, 0x0002); | |
376 i += aimutil_put16(newpacket->data+i, 0x0001); | |
377 | |
378 i += aimutil_put16(newpacket->data+i, 0x0003); | |
379 i += aimutil_put16(newpacket->data+i, 0x0001); | |
380 | |
381 i += aimutil_put16(newpacket->data+i, 0x0004); | |
382 i += aimutil_put16(newpacket->data+i, 0x0001); | |
383 | |
384 i += aimutil_put16(newpacket->data+i, 0x0006); | |
385 i += aimutil_put16(newpacket->data+i, 0x0001); | |
386 | |
387 i += aimutil_put16(newpacket->data+i, 0x0008); | |
388 i += aimutil_put16(newpacket->data+i, 0x0001); | |
389 | |
390 i += aimutil_put16(newpacket->data+i, 0x0009); | |
391 i += aimutil_put16(newpacket->data+i, 0x0001); | |
392 | |
393 i += aimutil_put16(newpacket->data+i, 0x000a); | |
394 i += aimutil_put16(newpacket->data+i, 0x0001); | |
395 | |
396 i += aimutil_put16(newpacket->data+i, 0x000b); | |
1649 | 397 i += aimutil_put16(newpacket->data+i, 0x0002); |
398 | |
399 i += aimutil_put16(newpacket->data+i, 0x000c); | |
1535 | 400 i += aimutil_put16(newpacket->data+i, 0x0001); |
401 | |
1649 | 402 i += aimutil_put16(newpacket->data+i, 0x0013); |
403 i += aimutil_put16(newpacket->data+i, 0x0001); | |
404 | |
405 i += aimutil_put16(newpacket->data+i, 0x0015); | |
1535 | 406 i += aimutil_put16(newpacket->data+i, 0x0001); |
407 | |
408 newpacket->commandlen = i; | |
409 newpacket->lock = 0; | |
410 aim_tx_enqueue(sess, newpacket); | |
411 | |
412 return sess->snac_nextid; | |
413 } | |
414 | |
415 | |
416 /* | |
417 * aim_bos_reqservice(serviceid) | |
418 * | |
419 * Service request. | |
420 * | |
421 */ | |
422 faim_export unsigned long aim_bos_reqservice(struct aim_session_t *sess, | |
423 struct aim_conn_t *conn, | |
424 u_short serviceid) | |
425 { | |
426 return aim_genericreq_s(sess, conn, 0x0001, 0x0004, &serviceid); | |
427 } | |
428 | |
429 /* | |
430 * aim_bos_nop() | |
431 * | |
432 * No-op. WinAIM sends these every 4min or so to keep | |
433 * the connection alive. Its not real necessary. | |
434 * | |
435 */ | |
436 faim_export unsigned long aim_bos_nop(struct aim_session_t *sess, | |
437 struct aim_conn_t *conn) | |
438 { | |
439 return aim_genericreq_n(sess, conn, 0x0001, 0x0016); | |
440 } | |
441 | |
442 /* | |
443 * aim_flap_nop() | |
444 * | |
445 * No-op. WinAIM 4.x sends these _every minute_ to keep | |
446 * the connection alive. | |
447 */ | |
448 faim_export unsigned long aim_flap_nop(struct aim_session_t *sess, | |
449 struct aim_conn_t *conn) | |
450 { | |
451 struct command_tx_struct *newpacket; | |
452 | |
453 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0005, 0))) | |
454 return sess->snac_nextid; | |
455 | |
456 newpacket->lock = 1; | |
457 newpacket->commandlen = 0; | |
458 newpacket->lock = 0; | |
459 | |
460 aim_tx_enqueue(sess, newpacket); | |
461 | |
462 return (sess->snac_nextid); | |
463 } | |
464 | |
465 /* | |
466 * aim_bos_reqrights() | |
467 * | |
468 * Request BOS rights. | |
469 * | |
470 */ | |
471 faim_export unsigned long aim_bos_reqrights(struct aim_session_t *sess, | |
472 struct aim_conn_t *conn) | |
473 { | |
474 return aim_genericreq_n(sess, conn, 0x0009, 0x0002); | |
475 } | |
476 | |
477 /* | |
478 * aim_bos_reqbuddyrights() | |
479 * | |
480 * Request Buddy List rights. | |
481 * | |
482 */ | |
483 faim_export unsigned long aim_bos_reqbuddyrights(struct aim_session_t *sess, | |
484 struct aim_conn_t *conn) | |
485 { | |
486 return aim_genericreq_n(sess, conn, 0x0003, 0x0002); | |
487 } | |
488 | |
489 /* | |
490 * aim_send_warning(struct aim_session_t *sess, | |
491 * struct aim_conn_t *conn, char *destsn, int anon) | |
492 * send a warning to destsn. | |
493 * anon is anonymous or not; | |
494 * AIM_WARN_ANON anonymous | |
495 * | |
496 * returns -1 on error (couldn't alloc packet), next snacid on success. | |
497 * | |
498 */ | |
499 faim_export int aim_send_warning(struct aim_session_t *sess, struct aim_conn_t *conn, char *destsn, int anon) | |
500 { | |
501 struct command_tx_struct *newpacket; | |
502 int curbyte; | |
503 | |
504 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, strlen(destsn)+13))) | |
505 return -1; | |
506 | |
507 newpacket->lock = 1; | |
508 | |
509 curbyte = 0; | |
510 curbyte += aim_putsnac(newpacket->data+curbyte, | |
511 0x0004, 0x0008, 0x0000, sess->snac_nextid); | |
512 | |
513 curbyte += aimutil_put16(newpacket->data+curbyte, (anon & AIM_WARN_ANON)?1:0); | |
514 | |
515 curbyte += aimutil_put8(newpacket->data+curbyte, strlen(destsn)); | |
516 | |
517 curbyte += aimutil_putstr(newpacket->data+curbyte, destsn, strlen(destsn)); | |
518 | |
519 newpacket->commandlen = curbyte; | |
520 newpacket->lock = 0; | |
521 | |
522 aim_tx_enqueue(sess, newpacket); | |
523 | |
524 return (sess->snac_nextid++); | |
525 } | |
526 | |
527 /* | |
528 * aim_debugconn_sendconnect() | |
529 * | |
530 * For aimdebugd. If you don't know what it is, you don't want to. | |
531 */ | |
532 faim_export unsigned long aim_debugconn_sendconnect(struct aim_session_t *sess, | |
533 struct aim_conn_t *conn) | |
534 { | |
535 return aim_genericreq_n(sess, conn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_DEBUGCONN_CONNECT); | |
536 } | |
537 | |
538 /* | |
539 * Generic routine for sending commands. | |
540 * | |
541 * | |
542 * I know I can do this in a smarter way...but I'm not thinking straight | |
543 * right now... | |
544 * | |
545 * I had one big function that handled all three cases, but then it broke | |
546 * and I split it up into three. But then I fixed it. I just never went | |
547 * back to the single. I don't see any advantage to doing it either way. | |
548 * | |
549 */ | |
550 faim_internal unsigned long aim_genericreq_n(struct aim_session_t *sess, | |
551 struct aim_conn_t *conn, | |
552 u_short family, u_short subtype) | |
553 { | |
554 struct command_tx_struct *newpacket; | |
555 | |
556 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10))) | |
557 return 0; | |
558 | |
559 newpacket->lock = 1; | |
560 | |
561 aim_putsnac(newpacket->data, family, subtype, 0x0000, sess->snac_nextid); | |
562 | |
563 aim_cachesnac(sess, family, subtype, 0x0000, NULL, 0); | |
564 | |
565 aim_tx_enqueue(sess, newpacket); | |
566 return sess->snac_nextid; | |
567 } | |
568 | |
569 /* | |
570 * | |
571 * | |
572 */ | |
573 faim_internal unsigned long aim_genericreq_l(struct aim_session_t *sess, | |
574 struct aim_conn_t *conn, | |
575 u_short family, u_short subtype, | |
576 u_long *longdata) | |
577 { | |
578 struct command_tx_struct *newpacket; | |
579 u_long newlong; | |
580 | |
581 /* If we don't have data, there's no reason to use this function */ | |
582 if (!longdata) | |
583 return aim_genericreq_n(sess, conn, family, subtype); | |
584 | |
585 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+sizeof(u_long)))) | |
586 return -1; | |
587 | |
588 newpacket->lock = 1; | |
589 | |
590 aim_putsnac(newpacket->data, family, subtype, 0x0000, sess->snac_nextid); | |
591 aim_cachesnac(sess, family, subtype, 0x0000, NULL, 0); | |
592 | |
593 /* copy in data */ | |
594 newlong = htonl(*longdata); | |
595 memcpy(&(newpacket->data[10]), &newlong, sizeof(u_long)); | |
596 | |
597 aim_tx_enqueue(sess, newpacket); | |
598 return sess->snac_nextid; | |
599 } | |
600 | |
601 faim_internal unsigned long aim_genericreq_s(struct aim_session_t *sess, | |
602 struct aim_conn_t *conn, | |
603 u_short family, u_short subtype, | |
604 u_short *shortdata) | |
605 { | |
606 struct command_tx_struct *newpacket; | |
607 u_short newshort; | |
608 | |
609 /* If we don't have data, there's no reason to use this function */ | |
610 if (!shortdata) | |
611 return aim_genericreq_n(sess, conn, family, subtype); | |
612 | |
613 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+sizeof(u_short)))) | |
614 return -1; | |
615 | |
616 newpacket->lock = 1; | |
617 | |
618 aim_putsnac(newpacket->data, family, subtype, 0x0000, sess->snac_nextid); | |
619 aim_cachesnac(sess, family, subtype, 0x0000, NULL, 0); | |
620 | |
621 /* copy in data */ | |
622 newshort = htons(*shortdata); | |
623 memcpy(&(newpacket->data[10]), &newshort, sizeof(u_short)); | |
624 | |
625 aim_tx_enqueue(sess, newpacket); | |
626 return sess->snac_nextid; | |
627 } | |
628 | |
629 /* | |
630 * aim_bos_reqlocaterights() | |
631 * | |
632 * Request Location services rights. | |
633 * | |
634 */ | |
635 faim_export unsigned long aim_bos_reqlocaterights(struct aim_session_t *sess, | |
636 struct aim_conn_t *conn) | |
637 { | |
638 return aim_genericreq_n(sess, conn, 0x0002, 0x0002); | |
639 } | |
640 | |
641 /* | |
642 * aim_bos_reqicbmparaminfo() | |
643 * | |
644 * Request ICBM parameter information. | |
645 * | |
646 */ | |
647 faim_export unsigned long aim_bos_reqicbmparaminfo(struct aim_session_t *sess, | |
648 struct aim_conn_t *conn) | |
649 { | |
650 return aim_genericreq_n(sess, conn, 0x0004, 0x0004); | |
651 } | |
652 | |
653 /* | |
654 * Add ICBM parameter? Huh? | |
655 */ | |
656 faim_export unsigned long aim_addicbmparam(struct aim_session_t *sess, | |
657 struct aim_conn_t *conn) | |
658 { | |
659 struct command_tx_struct *newpacket; | |
660 int packlen = 10+16, i=0; | |
661 | |
662 if(!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, packlen))) | |
663 return (sess->snac_nextid); | |
664 | |
665 newpacket->lock = 1; | |
666 | |
667 i = aim_putsnac(newpacket->data, 0x0004, 0x0002, 0x0000, sess->snac_nextid); | |
668 aim_cachesnac(sess, 0x0004, 0x0002, 0x0000, NULL, 0); | |
669 | |
670 i += aimutil_put16(newpacket->data+i, 0x0000); | |
671 i += aimutil_put16(newpacket->data+i, 0x0000); | |
672 i += aimutil_put16(newpacket->data+i, 0x0003); | |
673 i += aimutil_put16(newpacket->data+i, 0x1f40); | |
674 i += aimutil_put16(newpacket->data+i, 0x03e7); | |
675 i += aimutil_put16(newpacket->data+i, 0x03e7); | |
676 i += aimutil_put16(newpacket->data+i, 0x0000); | |
677 i += aimutil_put16(newpacket->data+i, 0x0000); | |
678 | |
679 aim_tx_enqueue(sess, newpacket); | |
680 | |
681 return sess->snac_nextid; | |
682 } | |
683 | |
684 /* | |
685 * Set directory profile data (not the same as aim_bos_setprofile!) | |
686 */ | |
687 faim_export unsigned long aim_setdirectoryinfo(struct aim_session_t *sess, struct aim_conn_t *conn, char *first, char *middle, char *last, char *maiden, char *nickname, char *street, char *city, char *state, char *zip, int country, unsigned short privacy) | |
688 { | |
689 struct command_tx_struct *newpacket; | |
690 int packlen = 0, i = 0; | |
691 | |
692 packlen += 2+2+2; | |
693 | |
694 if(first) /* TLV 0001 */ | |
695 packlen += (strlen(first) + 4); | |
696 if(middle) | |
697 packlen += (strlen(middle) + 4); | |
698 if(last) | |
699 packlen += (strlen(last) + 4); | |
700 if(maiden) | |
701 packlen += (strlen(maiden) + 4); | |
702 if(nickname) | |
703 packlen += (strlen(nickname) + 4); | |
704 if(street) | |
705 packlen += (strlen(street) + 4); | |
706 if(state) | |
707 packlen += (strlen(state) + 4); | |
708 if(city) | |
709 packlen += (strlen(city) + 4); | |
710 if(zip) | |
711 packlen += (strlen(zip) + 4); | |
712 | |
713 if(!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, packlen+10))) | |
714 return -1; | |
715 | |
716 newpacket->lock = 1; | |
717 | |
718 i = aim_putsnac(newpacket->data, 0x0002, 0x0009, 0x0000, 0); | |
719 | |
720 /* 000a/0002: privacy: 1 to allow search/disp, 0 to disallow */ | |
721 i += aim_puttlv_16(newpacket->data+i, 0x000a, privacy); | |
722 | |
723 | |
724 if (first) | |
725 i += aim_puttlv_str(newpacket->data+i, 0x0001, strlen(first), first); | |
726 if (middle) | |
727 i += aim_puttlv_str(newpacket->data+i, 0x0003, strlen(middle), middle); | |
728 if (last) | |
729 i += aim_puttlv_str(newpacket->data+i, 0x0002, strlen(last), last); | |
730 if (maiden) | |
731 i += aim_puttlv_str(newpacket->data+i, 0x0004, strlen(maiden), maiden); | |
732 if (nickname) | |
733 i += aim_puttlv_str(newpacket->data+i, 0x000c, strlen(nickname), nickname); | |
734 if (street) | |
735 i += aim_puttlv_str(newpacket->data+i, 0x0021, strlen(street), street); | |
736 if (city) | |
737 i += aim_puttlv_str(newpacket->data+i, 0x0008, strlen(city), city); | |
738 if (state) | |
739 i += aim_puttlv_str(newpacket->data+i, 0x0007, strlen(state), state); | |
740 if (zip) | |
741 i += aim_puttlv_str(newpacket->data+i, 0x000d, strlen(zip), zip); | |
742 | |
743 newpacket->commandlen = i; | |
744 newpacket->lock = 0; | |
745 | |
746 aim_tx_enqueue(sess, newpacket); | |
747 | |
748 return(sess->snac_nextid); | |
749 } | |
750 | |
751 faim_export unsigned long aim_setuserinterests(struct aim_session_t *sess, struct aim_conn_t *conn, char *interest1, char *interest2, char *interest3, char *interest4, char *interest5, unsigned short privacy) | |
752 { | |
753 struct command_tx_struct *newpacket; | |
754 int packlen = 0, i = 0; | |
755 | |
756 packlen += 2+2+2; | |
757 | |
758 if(interest1) | |
759 packlen += (strlen(interest1) + 4); | |
760 if(interest2) | |
761 packlen += (strlen(interest2) + 4); | |
762 if(interest3) | |
763 packlen += (strlen(interest3) + 4); | |
764 if(interest4) | |
765 packlen += (strlen(interest4) + 4); | |
766 if(interest5) | |
767 packlen += (strlen(interest5) + 4) ; | |
768 | |
769 | |
770 if(!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, packlen+10))) | |
771 return -1; | |
772 | |
773 newpacket->lock = 1; | |
774 | |
775 i = aim_putsnac(newpacket->data, 0x0002, 0x000f, 0x0000, 0); | |
776 | |
777 /* 000a/0002: 0000 ?? ?privacy? */ | |
778 i += aim_puttlv_16(newpacket->data+i, 0x000a, privacy); | |
779 | |
780 if(interest1) | |
781 i += aim_puttlv_str(newpacket->data+i, 0x000b, strlen(interest1), interest1); | |
782 if(interest2) | |
783 i += aim_puttlv_str(newpacket->data+i, 0x000b, strlen(interest2), interest2); | |
784 if(interest3) | |
785 i += aim_puttlv_str(newpacket->data+i, 0x000b, strlen(interest3), interest3); | |
786 if(interest4) | |
787 i += aim_puttlv_str(newpacket->data+i, 0x000b, strlen(interest4), interest4); | |
788 if(interest5) | |
789 i += aim_puttlv_str(newpacket->data+i, 0x000b, strlen(interest1), interest5); | |
790 | |
791 newpacket->commandlen = i; | |
792 newpacket->lock = 0; | |
793 | |
794 aim_tx_enqueue(sess, newpacket); | |
795 | |
796 return(sess->snac_nextid); | |
797 } | |
798 | |
799 faim_export unsigned long aim_icq_setstatus(struct aim_session_t *sess, | |
800 struct aim_conn_t *conn, | |
801 unsigned long status) | |
802 { | |
803 struct command_tx_struct *newpacket; | |
804 int i; | |
805 unsigned long data; | |
806 | |
807 data = 0x00030000 | status; /* yay for error checking ;^) */ | |
808 | |
809 if(!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10 + 4))) | |
810 return -1; | |
811 | |
812 newpacket->lock = 1; | |
813 | |
814 i = aim_putsnac(newpacket->data, 0x0001, 0x001e, 0x0000, 0x0000001e); | |
815 i += aim_puttlv_32(newpacket->data+i, 0x0006, data); | |
816 | |
817 newpacket->commandlen = i; | |
818 newpacket->lock = 0; | |
819 | |
820 aim_tx_enqueue(sess, newpacket); | |
821 | |
822 return(sess->snac_nextid); | |
823 } | |
1649 | 824 |
825 /* | |
826 * Should be generic enough to handle the errors for all families... | |
827 * | |
828 */ | |
829 static int generror(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen) | |
830 { | |
831 int ret = 0; | |
832 int error = 0; | |
1839
109cacf1ff97
[gaim-migrate @ 1849]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1649
diff
changeset
|
833 aim_rxcallback_t userfunc; |
1649 | 834 struct aim_snac_t *snac2; |
835 | |
836 snac2 = aim_remsnac(sess, snac->id); | |
837 | |
838 if (datalen) | |
839 error = aimutil_get16(data); | |
840 | |
841 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
842 ret = userfunc(sess, rx, error, snac2?snac2->data:NULL); | |
843 | |
844 if (snac2) | |
845 free(snac2->data); | |
846 free(snac2); | |
847 | |
848 return ret; | |
849 } | |
850 | |
851 static int snachandler(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen) | |
852 { | |
853 | |
854 if (snac->subtype == 0x0001) | |
855 return generror(sess, mod, rx, snac, data, datalen); | |
856 else if ((snac->family == 0xffff) && (snac->subtype == 0xffff)) { | |
1839
109cacf1ff97
[gaim-migrate @ 1849]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1649
diff
changeset
|
857 aim_rxcallback_t userfunc; |
1649 | 858 |
859 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
860 return userfunc(sess, rx); | |
861 } | |
862 | |
863 return 0; | |
864 } | |
865 | |
866 faim_internal int misc_modfirst(struct aim_session_t *sess, aim_module_t *mod) | |
867 { | |
868 | |
869 mod->family = 0xffff; | |
870 mod->version = 0x0000; | |
871 mod->flags = AIM_MODFLAG_MULTIFAMILY; | |
872 strncpy(mod->name, "misc", sizeof(mod->name)); | |
873 mod->snachandler = snachandler; | |
874 | |
875 return 0; | |
876 } |