Mercurial > pidgin
annotate libfaim/misc.c @ 2082:3937f5eb6d75
[gaim-migrate @ 2092]
fix solaris stuffs.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Tue, 24 Jul 2001 22:23:23 +0000 |
parents | 4bf0163563ca |
children |
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, | |
2026
4bf0163563ca
[gaim-migrate @ 2036]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1959
diff
changeset
|
207 const char *profile, |
4bf0163563ca
[gaim-migrate @ 2036]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1959
diff
changeset
|
208 const char *awaymsg, |
1535 | 209 unsigned short caps) |
210 { | |
211 struct command_tx_struct *newpacket; | |
212 int i = 0, tmp, caplen; | |
2026
4bf0163563ca
[gaim-migrate @ 2036]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1959
diff
changeset
|
213 static const char defencoding[] = {"text/aolrtf; charset=\"us-ascii\""}; |
1535 | 214 |
2026
4bf0163563ca
[gaim-migrate @ 2036]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1959
diff
changeset
|
215 i = 10; |
4bf0163563ca
[gaim-migrate @ 2036]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1959
diff
changeset
|
216 if (profile) |
4bf0163563ca
[gaim-migrate @ 2036]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1959
diff
changeset
|
217 i += 4+strlen(defencoding)+4+strlen(profile); |
4bf0163563ca
[gaim-migrate @ 2036]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1959
diff
changeset
|
218 if (awaymsg) |
4bf0163563ca
[gaim-migrate @ 2036]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1959
diff
changeset
|
219 i += 4+strlen(defencoding)+4+strlen(awaymsg); |
4bf0163563ca
[gaim-migrate @ 2036]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1959
diff
changeset
|
220 i += 4+512; /* for capabilities */ |
4bf0163563ca
[gaim-migrate @ 2036]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1959
diff
changeset
|
221 |
4bf0163563ca
[gaim-migrate @ 2036]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1959
diff
changeset
|
222 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, i))) |
1535 | 223 return -1; |
224 | |
2026
4bf0163563ca
[gaim-migrate @ 2036]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1959
diff
changeset
|
225 i = aim_putsnac(newpacket->data, 0x0002, 0x004, 0x0000, sess->snac_nextid); |
4bf0163563ca
[gaim-migrate @ 2036]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1959
diff
changeset
|
226 |
4bf0163563ca
[gaim-migrate @ 2036]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1959
diff
changeset
|
227 if (profile) { |
4bf0163563ca
[gaim-migrate @ 2036]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1959
diff
changeset
|
228 i += aim_puttlv_str(newpacket->data+i, 0x0001, strlen(defencoding), defencoding); |
4bf0163563ca
[gaim-migrate @ 2036]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1959
diff
changeset
|
229 i += aim_puttlv_str(newpacket->data+i, 0x0002, strlen(profile), profile); |
4bf0163563ca
[gaim-migrate @ 2036]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1959
diff
changeset
|
230 } |
4bf0163563ca
[gaim-migrate @ 2036]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1959
diff
changeset
|
231 |
4bf0163563ca
[gaim-migrate @ 2036]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1959
diff
changeset
|
232 if (awaymsg) { |
4bf0163563ca
[gaim-migrate @ 2036]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1959
diff
changeset
|
233 i += aim_puttlv_str(newpacket->data+i, 0x0003, strlen(defencoding), defencoding); |
1535 | 234 i += aim_puttlv_str(newpacket->data+i, 0x0004, strlen(awaymsg), awaymsg); |
2026
4bf0163563ca
[gaim-migrate @ 2036]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1959
diff
changeset
|
235 } |
1535 | 236 |
237 /* Capability information. */ | |
238 | |
239 tmp = (i += aimutil_put16(newpacket->data+i, 0x0005)); | |
240 i += aimutil_put16(newpacket->data+i, 0x0000); /* rewritten later */ | |
241 i += (caplen = aim_putcap(newpacket->data+i, 512, caps)); | |
242 aimutil_put16(newpacket->data+tmp, caplen); /* rewrite TLV size */ | |
243 | |
244 newpacket->commandlen = i; | |
245 aim_tx_enqueue(sess, newpacket); | |
246 | |
247 return (sess->snac_nextid++); | |
248 } | |
249 | |
250 /* | |
251 * aim_bos_clientready() | |
252 * | |
253 * Send Client Ready. | |
254 * | |
255 */ | |
256 faim_export unsigned long aim_bos_clientready(struct aim_session_t *sess, | |
257 struct aim_conn_t *conn) | |
258 { | |
259 struct aim_tool_version tools[] = { | |
260 {0x0001, 0x0003, AIM_TOOL_WIN32, 0x0686}, | |
261 {0x0002, 0x0001, AIM_TOOL_WIN32, 0x0001}, | |
262 {0x0003, 0x0001, AIM_TOOL_WIN32, 0x0001}, | |
263 {0x0004, 0x0001, AIM_TOOL_WIN32, 0x0001}, | |
264 {0x0006, 0x0001, AIM_TOOL_WIN32, 0x0001}, | |
265 {0x0008, 0x0001, AIM_TOOL_WIN32, 0x0001}, | |
266 {0x0009, 0x0001, AIM_TOOL_WIN32, 0x0001}, | |
267 {0x000a, 0x0001, AIM_TOOL_WIN32, 0x0001}, | |
268 {0x000b, 0x0001, AIM_TOOL_WIN32, 0x0001} | |
269 }; | |
270 int i,j; | |
271 struct command_tx_struct *newpacket; | |
272 int toolcount = sizeof(tools)/sizeof(struct aim_tool_version); | |
273 | |
274 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 1152))) | |
275 return -1; | |
276 | |
277 newpacket->lock = 1; | |
278 | |
279 i = aim_putsnac(newpacket->data, 0x0001, 0x0002, 0x0000, sess->snac_nextid); | |
280 aim_cachesnac(sess, 0x0001, 0x0002, 0x0000, NULL, 0); | |
281 | |
282 for (j = 0; j < toolcount; j++) { | |
283 i += aimutil_put16(newpacket->data+i, tools[j].group); | |
284 i += aimutil_put16(newpacket->data+i, tools[j].version); | |
285 i += aimutil_put16(newpacket->data+i, tools[j].tool); | |
286 i += aimutil_put16(newpacket->data+i, tools[j].toolversion); | |
287 } | |
288 | |
289 newpacket->commandlen = i; | |
290 newpacket->lock = 0; | |
291 | |
292 aim_tx_enqueue(sess, newpacket); | |
293 | |
294 return sess->snac_nextid; | |
295 } | |
296 | |
297 /* | |
298 * Request Rate Information. | |
299 * | |
300 */ | |
301 faim_export unsigned long aim_bos_reqrate(struct aim_session_t *sess, | |
302 struct aim_conn_t *conn) | |
303 { | |
304 return aim_genericreq_n(sess, conn, 0x0001, 0x0006); | |
305 } | |
306 | |
307 /* | |
308 * Rate Information Response Acknowledge. | |
309 * | |
310 */ | |
311 faim_export unsigned long aim_bos_ackrateresp(struct aim_session_t *sess, | |
312 struct aim_conn_t *conn) | |
313 { | |
314 struct command_tx_struct *newpacket; | |
315 int packlen = 20, i=0; | |
316 | |
317 if(!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, packlen))) | |
318 return (sess->snac_nextid); | |
319 | |
320 newpacket->lock = 1; | |
321 | |
322 i = aim_putsnac(newpacket->data, 0x0001, 0x0008, 0x0000, 0); | |
323 i += aimutil_put16(newpacket->data+i, 0x0001); | |
324 i += aimutil_put16(newpacket->data+i, 0x0002); | |
325 i += aimutil_put16(newpacket->data+i, 0x0003); | |
326 i += aimutil_put16(newpacket->data+i, 0x0004); | |
327 i += aimutil_put16(newpacket->data+i, 0x0005); | |
328 | |
329 newpacket->commandlen = i; | |
330 newpacket->lock = 0; | |
331 | |
332 aim_tx_enqueue(sess, newpacket); | |
333 | |
334 return (sess->snac_nextid); | |
335 } | |
336 | |
337 /* | |
338 * aim_bos_setprivacyflags() | |
339 * | |
340 * Sets privacy flags. Normally 0x03. | |
341 * | |
342 * Bit 1: Allows other AIM users to see how long you've been idle. | |
343 * Bit 2: Allows other AIM users to see how long you've been a member. | |
344 * | |
345 */ | |
346 faim_export unsigned long aim_bos_setprivacyflags(struct aim_session_t *sess, | |
347 struct aim_conn_t *conn, | |
348 u_long flags) | |
349 { | |
350 return aim_genericreq_l(sess, conn, 0x0001, 0x0014, &flags); | |
351 } | |
352 | |
353 /* | |
354 * aim_bos_reqpersonalinfo() | |
355 * | |
356 * Requests the current user's information. Can't go generic on this one | |
357 * because aparently it uses SNAC flags. | |
358 * | |
359 */ | |
360 faim_export unsigned long aim_bos_reqpersonalinfo(struct aim_session_t *sess, | |
361 struct aim_conn_t *conn) | |
362 { | |
363 return aim_genericreq_n(sess, conn, 0x0001, 0x000e); | |
364 } | |
365 | |
366 faim_export unsigned long aim_setversions(struct aim_session_t *sess, | |
367 struct aim_conn_t *conn) | |
368 { | |
369 struct command_tx_struct *newpacket; | |
370 int i; | |
371 | |
1649 | 372 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10 + (4*16)))) |
1535 | 373 return -1; |
374 | |
375 newpacket->lock = 1; | |
376 | |
377 i = aim_putsnac(newpacket->data, 0x0001, 0x0017, 0x0000, sess->snac_nextid); | |
378 aim_cachesnac(sess, 0x0001, 0x0017, 0x0000, NULL, 0); | |
379 | |
380 i += aimutil_put16(newpacket->data+i, 0x0001); | |
381 i += aimutil_put16(newpacket->data+i, 0x0003); | |
382 | |
383 i += aimutil_put16(newpacket->data+i, 0x0002); | |
384 i += aimutil_put16(newpacket->data+i, 0x0001); | |
385 | |
386 i += aimutil_put16(newpacket->data+i, 0x0003); | |
387 i += aimutil_put16(newpacket->data+i, 0x0001); | |
388 | |
389 i += aimutil_put16(newpacket->data+i, 0x0004); | |
390 i += aimutil_put16(newpacket->data+i, 0x0001); | |
391 | |
392 i += aimutil_put16(newpacket->data+i, 0x0006); | |
393 i += aimutil_put16(newpacket->data+i, 0x0001); | |
394 | |
395 i += aimutil_put16(newpacket->data+i, 0x0008); | |
396 i += aimutil_put16(newpacket->data+i, 0x0001); | |
397 | |
398 i += aimutil_put16(newpacket->data+i, 0x0009); | |
399 i += aimutil_put16(newpacket->data+i, 0x0001); | |
400 | |
401 i += aimutil_put16(newpacket->data+i, 0x000a); | |
402 i += aimutil_put16(newpacket->data+i, 0x0001); | |
403 | |
404 i += aimutil_put16(newpacket->data+i, 0x000b); | |
1649 | 405 i += aimutil_put16(newpacket->data+i, 0x0002); |
406 | |
407 i += aimutil_put16(newpacket->data+i, 0x000c); | |
1535 | 408 i += aimutil_put16(newpacket->data+i, 0x0001); |
409 | |
1649 | 410 i += aimutil_put16(newpacket->data+i, 0x0013); |
411 i += aimutil_put16(newpacket->data+i, 0x0001); | |
412 | |
413 i += aimutil_put16(newpacket->data+i, 0x0015); | |
1535 | 414 i += aimutil_put16(newpacket->data+i, 0x0001); |
415 | |
416 newpacket->commandlen = i; | |
417 newpacket->lock = 0; | |
418 aim_tx_enqueue(sess, newpacket); | |
419 | |
420 return sess->snac_nextid; | |
421 } | |
422 | |
423 | |
424 /* | |
425 * aim_bos_reqservice(serviceid) | |
426 * | |
427 * Service request. | |
428 * | |
429 */ | |
430 faim_export unsigned long aim_bos_reqservice(struct aim_session_t *sess, | |
431 struct aim_conn_t *conn, | |
432 u_short serviceid) | |
433 { | |
434 return aim_genericreq_s(sess, conn, 0x0001, 0x0004, &serviceid); | |
435 } | |
436 | |
437 /* | |
438 * aim_bos_nop() | |
439 * | |
440 * No-op. WinAIM sends these every 4min or so to keep | |
441 * the connection alive. Its not real necessary. | |
442 * | |
443 */ | |
444 faim_export unsigned long aim_bos_nop(struct aim_session_t *sess, | |
445 struct aim_conn_t *conn) | |
446 { | |
447 return aim_genericreq_n(sess, conn, 0x0001, 0x0016); | |
448 } | |
449 | |
450 /* | |
451 * aim_flap_nop() | |
452 * | |
453 * No-op. WinAIM 4.x sends these _every minute_ to keep | |
454 * the connection alive. | |
455 */ | |
456 faim_export unsigned long aim_flap_nop(struct aim_session_t *sess, | |
457 struct aim_conn_t *conn) | |
458 { | |
459 struct command_tx_struct *newpacket; | |
460 | |
461 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0005, 0))) | |
462 return sess->snac_nextid; | |
463 | |
464 newpacket->lock = 1; | |
465 newpacket->commandlen = 0; | |
466 newpacket->lock = 0; | |
467 | |
468 aim_tx_enqueue(sess, newpacket); | |
469 | |
470 return (sess->snac_nextid); | |
471 } | |
472 | |
473 /* | |
474 * aim_bos_reqrights() | |
475 * | |
476 * Request BOS rights. | |
477 * | |
478 */ | |
479 faim_export unsigned long aim_bos_reqrights(struct aim_session_t *sess, | |
480 struct aim_conn_t *conn) | |
481 { | |
482 return aim_genericreq_n(sess, conn, 0x0009, 0x0002); | |
483 } | |
484 | |
485 /* | |
486 * aim_bos_reqbuddyrights() | |
487 * | |
488 * Request Buddy List rights. | |
489 * | |
490 */ | |
491 faim_export unsigned long aim_bos_reqbuddyrights(struct aim_session_t *sess, | |
492 struct aim_conn_t *conn) | |
493 { | |
494 return aim_genericreq_n(sess, conn, 0x0003, 0x0002); | |
495 } | |
496 | |
497 /* | |
498 * aim_send_warning(struct aim_session_t *sess, | |
499 * struct aim_conn_t *conn, char *destsn, int anon) | |
500 * send a warning to destsn. | |
501 * anon is anonymous or not; | |
502 * AIM_WARN_ANON anonymous | |
503 * | |
504 * returns -1 on error (couldn't alloc packet), next snacid on success. | |
505 * | |
506 */ | |
507 faim_export int aim_send_warning(struct aim_session_t *sess, struct aim_conn_t *conn, char *destsn, int anon) | |
508 { | |
509 struct command_tx_struct *newpacket; | |
510 int curbyte; | |
511 | |
512 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, strlen(destsn)+13))) | |
513 return -1; | |
514 | |
515 newpacket->lock = 1; | |
516 | |
517 curbyte = 0; | |
518 curbyte += aim_putsnac(newpacket->data+curbyte, | |
519 0x0004, 0x0008, 0x0000, sess->snac_nextid); | |
520 | |
521 curbyte += aimutil_put16(newpacket->data+curbyte, (anon & AIM_WARN_ANON)?1:0); | |
522 | |
523 curbyte += aimutil_put8(newpacket->data+curbyte, strlen(destsn)); | |
524 | |
525 curbyte += aimutil_putstr(newpacket->data+curbyte, destsn, strlen(destsn)); | |
526 | |
527 newpacket->commandlen = curbyte; | |
528 newpacket->lock = 0; | |
529 | |
530 aim_tx_enqueue(sess, newpacket); | |
531 | |
532 return (sess->snac_nextid++); | |
533 } | |
534 | |
535 /* | |
536 * aim_debugconn_sendconnect() | |
537 * | |
538 * For aimdebugd. If you don't know what it is, you don't want to. | |
539 */ | |
540 faim_export unsigned long aim_debugconn_sendconnect(struct aim_session_t *sess, | |
541 struct aim_conn_t *conn) | |
542 { | |
543 return aim_genericreq_n(sess, conn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_DEBUGCONN_CONNECT); | |
544 } | |
545 | |
546 /* | |
547 * Generic routine for sending commands. | |
548 * | |
549 * | |
550 * I know I can do this in a smarter way...but I'm not thinking straight | |
551 * right now... | |
552 * | |
553 * I had one big function that handled all three cases, but then it broke | |
554 * and I split it up into three. But then I fixed it. I just never went | |
555 * back to the single. I don't see any advantage to doing it either way. | |
556 * | |
557 */ | |
558 faim_internal unsigned long aim_genericreq_n(struct aim_session_t *sess, | |
559 struct aim_conn_t *conn, | |
560 u_short family, u_short subtype) | |
561 { | |
562 struct command_tx_struct *newpacket; | |
563 | |
564 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10))) | |
565 return 0; | |
566 | |
567 newpacket->lock = 1; | |
568 | |
1959
741842331ceb
[gaim-migrate @ 1969]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1839
diff
changeset
|
569 aim_putsnac(newpacket->data, family, subtype, 0x0000, 0x00000000); |
741842331ceb
[gaim-migrate @ 1969]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1839
diff
changeset
|
570 |
741842331ceb
[gaim-migrate @ 1969]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1839
diff
changeset
|
571 aim_tx_enqueue(sess, newpacket); |
741842331ceb
[gaim-migrate @ 1969]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1839
diff
changeset
|
572 |
741842331ceb
[gaim-migrate @ 1969]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1839
diff
changeset
|
573 return sess->snac_nextid; |
741842331ceb
[gaim-migrate @ 1969]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1839
diff
changeset
|
574 } |
741842331ceb
[gaim-migrate @ 1969]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1839
diff
changeset
|
575 |
741842331ceb
[gaim-migrate @ 1969]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1839
diff
changeset
|
576 faim_internal unsigned long aim_genericreq_n_snacid(struct aim_session_t *sess, |
741842331ceb
[gaim-migrate @ 1969]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1839
diff
changeset
|
577 struct aim_conn_t *conn, |
741842331ceb
[gaim-migrate @ 1969]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1839
diff
changeset
|
578 unsigned short family, |
741842331ceb
[gaim-migrate @ 1969]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1839
diff
changeset
|
579 unsigned short subtype) |
741842331ceb
[gaim-migrate @ 1969]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1839
diff
changeset
|
580 { |
741842331ceb
[gaim-migrate @ 1969]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1839
diff
changeset
|
581 struct command_tx_struct *newpacket; |
741842331ceb
[gaim-migrate @ 1969]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1839
diff
changeset
|
582 |
741842331ceb
[gaim-migrate @ 1969]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1839
diff
changeset
|
583 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10))) |
741842331ceb
[gaim-migrate @ 1969]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1839
diff
changeset
|
584 return 0; |
741842331ceb
[gaim-migrate @ 1969]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1839
diff
changeset
|
585 |
741842331ceb
[gaim-migrate @ 1969]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1839
diff
changeset
|
586 newpacket->lock = 1; |
741842331ceb
[gaim-migrate @ 1969]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1839
diff
changeset
|
587 |
1535 | 588 aim_putsnac(newpacket->data, family, subtype, 0x0000, sess->snac_nextid); |
589 aim_cachesnac(sess, family, subtype, 0x0000, NULL, 0); | |
590 | |
591 aim_tx_enqueue(sess, newpacket); | |
1959
741842331ceb
[gaim-migrate @ 1969]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1839
diff
changeset
|
592 |
741842331ceb
[gaim-migrate @ 1969]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1839
diff
changeset
|
593 return sess->snac_nextid++; |
1535 | 594 } |
595 | |
596 /* | |
597 * | |
598 * | |
599 */ | |
600 faim_internal unsigned long aim_genericreq_l(struct aim_session_t *sess, | |
601 struct aim_conn_t *conn, | |
602 u_short family, u_short subtype, | |
603 u_long *longdata) | |
604 { | |
605 struct command_tx_struct *newpacket; | |
606 u_long newlong; | |
607 | |
608 /* If we don't have data, there's no reason to use this function */ | |
609 if (!longdata) | |
610 return aim_genericreq_n(sess, conn, family, subtype); | |
611 | |
612 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+sizeof(u_long)))) | |
613 return -1; | |
614 | |
615 newpacket->lock = 1; | |
616 | |
1959
741842331ceb
[gaim-migrate @ 1969]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1839
diff
changeset
|
617 aim_putsnac(newpacket->data, family, subtype, 0x0000, 0x00000000); |
1535 | 618 |
619 /* copy in data */ | |
620 newlong = htonl(*longdata); | |
621 memcpy(&(newpacket->data[10]), &newlong, sizeof(u_long)); | |
622 | |
623 aim_tx_enqueue(sess, newpacket); | |
1959
741842331ceb
[gaim-migrate @ 1969]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1839
diff
changeset
|
624 |
1535 | 625 return sess->snac_nextid; |
626 } | |
627 | |
628 faim_internal unsigned long aim_genericreq_s(struct aim_session_t *sess, | |
629 struct aim_conn_t *conn, | |
630 u_short family, u_short subtype, | |
631 u_short *shortdata) | |
632 { | |
633 struct command_tx_struct *newpacket; | |
634 u_short newshort; | |
635 | |
636 /* If we don't have data, there's no reason to use this function */ | |
637 if (!shortdata) | |
638 return aim_genericreq_n(sess, conn, family, subtype); | |
639 | |
640 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+sizeof(u_short)))) | |
641 return -1; | |
642 | |
643 newpacket->lock = 1; | |
644 | |
1959
741842331ceb
[gaim-migrate @ 1969]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1839
diff
changeset
|
645 aim_putsnac(newpacket->data, family, subtype, 0x0000, 0x00000000); |
1535 | 646 |
647 /* copy in data */ | |
648 newshort = htons(*shortdata); | |
649 memcpy(&(newpacket->data[10]), &newshort, sizeof(u_short)); | |
650 | |
651 aim_tx_enqueue(sess, newpacket); | |
1959
741842331ceb
[gaim-migrate @ 1969]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1839
diff
changeset
|
652 |
1535 | 653 return sess->snac_nextid; |
654 } | |
655 | |
656 /* | |
657 * aim_bos_reqlocaterights() | |
658 * | |
659 * Request Location services rights. | |
660 * | |
661 */ | |
662 faim_export unsigned long aim_bos_reqlocaterights(struct aim_session_t *sess, | |
663 struct aim_conn_t *conn) | |
664 { | |
665 return aim_genericreq_n(sess, conn, 0x0002, 0x0002); | |
666 } | |
667 | |
668 /* | |
669 * aim_bos_reqicbmparaminfo() | |
670 * | |
671 * Request ICBM parameter information. | |
672 * | |
673 */ | |
674 faim_export unsigned long aim_bos_reqicbmparaminfo(struct aim_session_t *sess, | |
675 struct aim_conn_t *conn) | |
676 { | |
677 return aim_genericreq_n(sess, conn, 0x0004, 0x0004); | |
678 } | |
679 | |
680 /* | |
681 * Add ICBM parameter? Huh? | |
682 */ | |
683 faim_export unsigned long aim_addicbmparam(struct aim_session_t *sess, | |
684 struct aim_conn_t *conn) | |
685 { | |
686 struct command_tx_struct *newpacket; | |
687 int packlen = 10+16, i=0; | |
688 | |
689 if(!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, packlen))) | |
690 return (sess->snac_nextid); | |
691 | |
692 newpacket->lock = 1; | |
693 | |
1959
741842331ceb
[gaim-migrate @ 1969]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1839
diff
changeset
|
694 i = aim_putsnac(newpacket->data, 0x0004, 0x0002, 0x0000, 0x00000000); |
1535 | 695 |
696 i += aimutil_put16(newpacket->data+i, 0x0000); | |
697 i += aimutil_put16(newpacket->data+i, 0x0000); | |
698 i += aimutil_put16(newpacket->data+i, 0x0003); | |
699 i += aimutil_put16(newpacket->data+i, 0x1f40); | |
700 i += aimutil_put16(newpacket->data+i, 0x03e7); | |
701 i += aimutil_put16(newpacket->data+i, 0x03e7); | |
702 i += aimutil_put16(newpacket->data+i, 0x0000); | |
703 i += aimutil_put16(newpacket->data+i, 0x0000); | |
704 | |
705 aim_tx_enqueue(sess, newpacket); | |
706 | |
707 return sess->snac_nextid; | |
708 } | |
709 | |
710 /* | |
711 * Set directory profile data (not the same as aim_bos_setprofile!) | |
712 */ | |
713 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) | |
714 { | |
715 struct command_tx_struct *newpacket; | |
716 int packlen = 0, i = 0; | |
717 | |
718 packlen += 2+2+2; | |
719 | |
720 if(first) /* TLV 0001 */ | |
721 packlen += (strlen(first) + 4); | |
722 if(middle) | |
723 packlen += (strlen(middle) + 4); | |
724 if(last) | |
725 packlen += (strlen(last) + 4); | |
726 if(maiden) | |
727 packlen += (strlen(maiden) + 4); | |
728 if(nickname) | |
729 packlen += (strlen(nickname) + 4); | |
730 if(street) | |
731 packlen += (strlen(street) + 4); | |
732 if(state) | |
733 packlen += (strlen(state) + 4); | |
734 if(city) | |
735 packlen += (strlen(city) + 4); | |
736 if(zip) | |
737 packlen += (strlen(zip) + 4); | |
738 | |
739 if(!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, packlen+10))) | |
740 return -1; | |
741 | |
742 newpacket->lock = 1; | |
743 | |
744 i = aim_putsnac(newpacket->data, 0x0002, 0x0009, 0x0000, 0); | |
745 | |
746 /* 000a/0002: privacy: 1 to allow search/disp, 0 to disallow */ | |
747 i += aim_puttlv_16(newpacket->data+i, 0x000a, privacy); | |
748 | |
749 | |
750 if (first) | |
751 i += aim_puttlv_str(newpacket->data+i, 0x0001, strlen(first), first); | |
752 if (middle) | |
753 i += aim_puttlv_str(newpacket->data+i, 0x0003, strlen(middle), middle); | |
754 if (last) | |
755 i += aim_puttlv_str(newpacket->data+i, 0x0002, strlen(last), last); | |
756 if (maiden) | |
757 i += aim_puttlv_str(newpacket->data+i, 0x0004, strlen(maiden), maiden); | |
758 if (nickname) | |
759 i += aim_puttlv_str(newpacket->data+i, 0x000c, strlen(nickname), nickname); | |
760 if (street) | |
761 i += aim_puttlv_str(newpacket->data+i, 0x0021, strlen(street), street); | |
762 if (city) | |
763 i += aim_puttlv_str(newpacket->data+i, 0x0008, strlen(city), city); | |
764 if (state) | |
765 i += aim_puttlv_str(newpacket->data+i, 0x0007, strlen(state), state); | |
766 if (zip) | |
767 i += aim_puttlv_str(newpacket->data+i, 0x000d, strlen(zip), zip); | |
768 | |
769 newpacket->commandlen = i; | |
770 newpacket->lock = 0; | |
771 | |
772 aim_tx_enqueue(sess, newpacket); | |
773 | |
774 return(sess->snac_nextid); | |
775 } | |
776 | |
777 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) | |
778 { | |
779 struct command_tx_struct *newpacket; | |
780 int packlen = 0, i = 0; | |
781 | |
782 packlen += 2+2+2; | |
783 | |
784 if(interest1) | |
785 packlen += (strlen(interest1) + 4); | |
786 if(interest2) | |
787 packlen += (strlen(interest2) + 4); | |
788 if(interest3) | |
789 packlen += (strlen(interest3) + 4); | |
790 if(interest4) | |
791 packlen += (strlen(interest4) + 4); | |
792 if(interest5) | |
793 packlen += (strlen(interest5) + 4) ; | |
794 | |
795 | |
796 if(!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, packlen+10))) | |
797 return -1; | |
798 | |
799 newpacket->lock = 1; | |
800 | |
801 i = aim_putsnac(newpacket->data, 0x0002, 0x000f, 0x0000, 0); | |
802 | |
803 /* 000a/0002: 0000 ?? ?privacy? */ | |
804 i += aim_puttlv_16(newpacket->data+i, 0x000a, privacy); | |
805 | |
806 if(interest1) | |
807 i += aim_puttlv_str(newpacket->data+i, 0x000b, strlen(interest1), interest1); | |
808 if(interest2) | |
809 i += aim_puttlv_str(newpacket->data+i, 0x000b, strlen(interest2), interest2); | |
810 if(interest3) | |
811 i += aim_puttlv_str(newpacket->data+i, 0x000b, strlen(interest3), interest3); | |
812 if(interest4) | |
813 i += aim_puttlv_str(newpacket->data+i, 0x000b, strlen(interest4), interest4); | |
814 if(interest5) | |
815 i += aim_puttlv_str(newpacket->data+i, 0x000b, strlen(interest1), interest5); | |
816 | |
817 newpacket->commandlen = i; | |
818 newpacket->lock = 0; | |
819 | |
820 aim_tx_enqueue(sess, newpacket); | |
821 | |
822 return(sess->snac_nextid); | |
823 } | |
824 | |
825 faim_export unsigned long aim_icq_setstatus(struct aim_session_t *sess, | |
826 struct aim_conn_t *conn, | |
827 unsigned long status) | |
828 { | |
829 struct command_tx_struct *newpacket; | |
830 int i; | |
831 unsigned long data; | |
832 | |
833 data = 0x00030000 | status; /* yay for error checking ;^) */ | |
834 | |
835 if(!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10 + 4))) | |
836 return -1; | |
837 | |
838 newpacket->lock = 1; | |
839 | |
840 i = aim_putsnac(newpacket->data, 0x0001, 0x001e, 0x0000, 0x0000001e); | |
841 i += aim_puttlv_32(newpacket->data+i, 0x0006, data); | |
842 | |
843 newpacket->commandlen = i; | |
844 newpacket->lock = 0; | |
845 | |
846 aim_tx_enqueue(sess, newpacket); | |
847 | |
848 return(sess->snac_nextid); | |
849 } | |
1649 | 850 |
851 /* | |
852 * Should be generic enough to handle the errors for all families... | |
853 * | |
854 */ | |
855 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) | |
856 { | |
857 int ret = 0; | |
858 int error = 0; | |
1839
109cacf1ff97
[gaim-migrate @ 1849]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1649
diff
changeset
|
859 aim_rxcallback_t userfunc; |
1649 | 860 struct aim_snac_t *snac2; |
861 | |
862 snac2 = aim_remsnac(sess, snac->id); | |
863 | |
864 if (datalen) | |
865 error = aimutil_get16(data); | |
866 | |
867 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
868 ret = userfunc(sess, rx, error, snac2?snac2->data:NULL); | |
869 | |
870 if (snac2) | |
871 free(snac2->data); | |
872 free(snac2); | |
873 | |
874 return ret; | |
875 } | |
876 | |
877 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) | |
878 { | |
879 | |
880 if (snac->subtype == 0x0001) | |
881 return generror(sess, mod, rx, snac, data, datalen); | |
882 else if ((snac->family == 0xffff) && (snac->subtype == 0xffff)) { | |
1839
109cacf1ff97
[gaim-migrate @ 1849]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1649
diff
changeset
|
883 aim_rxcallback_t userfunc; |
1649 | 884 |
885 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
886 return userfunc(sess, rx); | |
887 } | |
888 | |
889 return 0; | |
890 } | |
891 | |
892 faim_internal int misc_modfirst(struct aim_session_t *sess, aim_module_t *mod) | |
893 { | |
894 | |
895 mod->family = 0xffff; | |
896 mod->version = 0x0000; | |
897 mod->flags = AIM_MODFLAG_MULTIFAMILY; | |
898 strncpy(mod->name, "misc", sizeof(mod->name)); | |
899 mod->snachandler = snachandler; | |
900 | |
901 return 0; | |
902 } |