]>
Commit | Line | Data |
---|---|---|
9de3ca7e | 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 | ||
37ee990e | 14 | #define FAIM_INTERNAL |
dd60ff8b | 15 | #include <aim.h> |
9de3ca7e | 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 | */ | |
5ac21963 | 25 | faim_export unsigned long aim_bos_setidle(struct aim_session_t *sess, |
26 | struct aim_conn_t *conn, | |
27 | u_long idletime) | |
9de3ca7e | 28 | { |
a25832e6 | 29 | return aim_genericreq_l(sess, conn, 0x0001, 0x0011, &idletime); |
9de3ca7e | 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 | */ | |
5ac21963 | 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) | |
9de3ca7e | 65 | { |
5b79dc93 | 66 | struct command_tx_struct *newpacket; |
67 | int packlen = 0; | |
9de3ca7e | 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 | ||
9de3ca7e | 78 | localcpy = (char *) malloc(strlen(denylist)+1); |
79 | memcpy(localcpy, denylist, strlen(denylist)+1); | |
80 | ||
81 | listcount = aimutil_itemcnt(localcpy, '&'); | |
5b79dc93 | 82 | packlen = aimutil_tokslen(localcpy, 99, '&') + listcount + 9; |
9de3ca7e | 83 | |
646c6b52 | 84 | if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, packlen))) |
5b79dc93 | 85 | return -1; |
9de3ca7e | 86 | |
5b79dc93 | 87 | newpacket->lock = 1; |
9de3ca7e | 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: | |
5b79dc93 | 96 | free(newpacket->data); |
97 | free(newpacket); | |
9de3ca7e | 98 | return 0; |
99 | } | |
100 | ||
101 | /* We actually DO NOT send a SNAC ID with this one! */ | |
5b79dc93 | 102 | aim_putsnac(newpacket->data, 0x0009, subtype, 0x00, 0); |
9de3ca7e | 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 | ||
5b79dc93 | 110 | newpacket->data[j] = strlen(tmpptr); |
111 | memcpy(&(newpacket->data[j+1]), tmpptr, strlen(tmpptr)); | |
9de3ca7e | 112 | j += strlen(tmpptr)+1; |
113 | free(tmpptr); | |
114 | } | |
115 | free(localcpy); | |
116 | ||
5b79dc93 | 117 | newpacket->lock = 0; |
9de3ca7e | 118 | |
5b79dc93 | 119 | aim_tx_enqueue(sess, newpacket); |
9de3ca7e | 120 | |
a25832e6 | 121 | return (sess->snac_nextid); /* dont increment */ |
9de3ca7e | 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 | * | |
5b79dc93 | 134 | * TODO: Clean this up. |
135 | * | |
136 | * XXX: I can't stress the TODO enough. | |
9de3ca7e | 137 | * |
138 | */ | |
5ac21963 | 139 | faim_export unsigned long aim_bos_setbuddylist(struct aim_session_t *sess, |
140 | struct aim_conn_t *conn, | |
141 | char *buddy_list) | |
9de3ca7e | 142 | { |
143 | int i, j; | |
144 | ||
5b79dc93 | 145 | struct command_tx_struct *newpacket; |
9de3ca7e | 146 | |
c78446b5 | 147 | int len = 0; |
9de3ca7e | 148 | |
149 | char *localcpy = NULL; | |
150 | char *tmpptr = NULL; | |
151 | ||
c78446b5 | 152 | len = 10; /* 10B SNAC headers */ |
9de3ca7e | 153 | |
c78446b5 | 154 | if (!buddy_list || !(localcpy = (char *) malloc(strlen(buddy_list)+1))) |
5b79dc93 | 155 | return -1; |
c78446b5 | 156 | strncpy(localcpy, buddy_list, strlen(buddy_list)+1); |
9de3ca7e | 157 | |
158 | i = 0; | |
159 | tmpptr = strtok(localcpy, "&"); | |
c78446b5 | 160 | while ((tmpptr != NULL) && (i < 150)) { |
646c6b52 | 161 | faimdprintf(sess, 2, "---adding %d: %s (%d)\n", i, tmpptr, strlen(tmpptr)); |
c78446b5 | 162 | len += 1+strlen(tmpptr); |
163 | i++; | |
164 | tmpptr = strtok(NULL, "&"); | |
165 | } | |
646c6b52 | 166 | faimdprintf(sess, 2, "*** send buddy list len: %d (%x)\n", len, len); |
9de3ca7e | 167 | |
646c6b52 | 168 | if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, len))) |
5b79dc93 | 169 | return -1; |
9de3ca7e | 170 | |
5b79dc93 | 171 | newpacket->lock = 1; |
172 | ||
c78446b5 | 173 | aim_putsnac(newpacket->data, 0x0003, 0x0004, 0x0000, 0); |
9de3ca7e | 174 | |
175 | j = 10; /* the next byte */ | |
176 | ||
c78446b5 | 177 | strncpy(localcpy, buddy_list, strlen(buddy_list)+1); |
9de3ca7e | 178 | i = 0; |
c78446b5 | 179 | tmpptr = strtok(localcpy, "&"); |
180 | while ((tmpptr != NULL) & (i < 150)) { | |
646c6b52 | 181 | faimdprintf(sess, 2, "---adding %d: %s (%d)\n", i, tmpptr, strlen(tmpptr)); |
c78446b5 | 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 | } | |
9de3ca7e | 188 | |
5b79dc93 | 189 | newpacket->lock = 0; |
9de3ca7e | 190 | |
5b79dc93 | 191 | aim_tx_enqueue(sess, newpacket); |
9de3ca7e | 192 | |
c78446b5 | 193 | free(localcpy); |
194 | ||
195 | return (sess->snac_nextid); | |
9de3ca7e | 196 | } |
197 | ||
198 | /* | |
199 | * aim_bos_setprofile(profile) | |
200 | * | |
201 | * Gives BOS your profile. | |
202 | * | |
26af6789 | 203 | * |
9de3ca7e | 204 | */ |
5ac21963 | 205 | faim_export unsigned long aim_bos_setprofile(struct aim_session_t *sess, |
206 | struct aim_conn_t *conn, | |
b309471d | 207 | const char *profile, |
208 | const char *awaymsg, | |
5ac21963 | 209 | unsigned short caps) |
9de3ca7e | 210 | { |
5b79dc93 | 211 | struct command_tx_struct *newpacket; |
b69540e3 | 212 | int i = 0, tmp, caplen; |
b309471d | 213 | static const char defencoding[] = {"text/aolrtf; charset=\"us-ascii\""}; |
0c20631f | 214 | |
b309471d | 215 | i = 10; |
216 | if (profile) | |
217 | i += 4+strlen(defencoding)+4+strlen(profile); | |
218 | if (awaymsg) | |
219 | i += 4+strlen(defencoding)+4+strlen(awaymsg); | |
220 | i += 4+512; /* for capabilities */ | |
221 | ||
222 | if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, i))) | |
5b79dc93 | 223 | return -1; |
9de3ca7e | 224 | |
b309471d | 225 | i = aim_putsnac(newpacket->data, 0x0002, 0x004, 0x0000, sess->snac_nextid); |
226 | ||
227 | if (profile) { | |
228 | i += aim_puttlv_str(newpacket->data+i, 0x0001, strlen(defencoding), defencoding); | |
229 | i += aim_puttlv_str(newpacket->data+i, 0x0002, strlen(profile), profile); | |
230 | } | |
231 | ||
232 | if (awaymsg) { | |
233 | i += aim_puttlv_str(newpacket->data+i, 0x0003, strlen(defencoding), defencoding); | |
5b79dc93 | 234 | i += aim_puttlv_str(newpacket->data+i, 0x0004, strlen(awaymsg), awaymsg); |
b309471d | 235 | } |
26af6789 | 236 | |
237 | /* Capability information. */ | |
b69540e3 | 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 | ||
5b79dc93 | 244 | newpacket->commandlen = i; |
245 | aim_tx_enqueue(sess, newpacket); | |
9de3ca7e | 246 | |
a25832e6 | 247 | return (sess->snac_nextid++); |
9de3ca7e | 248 | } |
249 | ||
9de3ca7e | 250 | /* |
251 | * aim_bos_clientready() | |
252 | * | |
253 | * Send Client Ready. | |
254 | * | |
9de3ca7e | 255 | */ |
5ac21963 | 256 | faim_export unsigned long aim_bos_clientready(struct aim_session_t *sess, |
257 | struct aim_conn_t *conn) | |
9de3ca7e | 258 | { |
64c78745 | 259 | struct aim_tool_version tools[] = { |
d6c9fcf0 | 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} | |
9de3ca7e | 269 | }; |
d6c9fcf0 | 270 | int i,j; |
5b79dc93 | 271 | struct command_tx_struct *newpacket; |
d6c9fcf0 | 272 | int toolcount = sizeof(tools)/sizeof(struct aim_tool_version); |
273 | ||
646c6b52 | 274 | if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 1152))) |
5b79dc93 | 275 | return -1; |
276 | ||
277 | newpacket->lock = 1; | |
278 | ||
d6c9fcf0 | 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; | |
9de3ca7e | 291 | |
5b79dc93 | 292 | aim_tx_enqueue(sess, newpacket); |
9de3ca7e | 293 | |
d6c9fcf0 | 294 | return sess->snac_nextid; |
9de3ca7e | 295 | } |
296 | ||
297 | /* | |
9de3ca7e | 298 | * Request Rate Information. |
299 | * | |
9de3ca7e | 300 | */ |
5ac21963 | 301 | faim_export unsigned long aim_bos_reqrate(struct aim_session_t *sess, |
302 | struct aim_conn_t *conn) | |
9de3ca7e | 303 | { |
a25832e6 | 304 | return aim_genericreq_n(sess, conn, 0x0001, 0x0006); |
9de3ca7e | 305 | } |
306 | ||
307 | /* | |
9de3ca7e | 308 | * Rate Information Response Acknowledge. |
309 | * | |
310 | */ | |
5ac21963 | 311 | faim_export unsigned long aim_bos_ackrateresp(struct aim_session_t *sess, |
312 | struct aim_conn_t *conn) | |
9de3ca7e | 313 | { |
5b79dc93 | 314 | struct command_tx_struct *newpacket; |
c78446b5 | 315 | int packlen = 20, i=0; |
9de3ca7e | 316 | |
646c6b52 | 317 | if(!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, packlen))) |
c78446b5 | 318 | return (sess->snac_nextid); |
5b79dc93 | 319 | |
320 | newpacket->lock = 1; | |
9de3ca7e | 321 | |
c78446b5 | 322 | i = aim_putsnac(newpacket->data, 0x0001, 0x0008, 0x0000, 0); |
5b79dc93 | 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); | |
c78446b5 | 327 | i += aimutil_put16(newpacket->data+i, 0x0005); |
5925849b | 328 | |
329 | newpacket->commandlen = i; | |
330 | newpacket->lock = 0; | |
331 | ||
5b79dc93 | 332 | aim_tx_enqueue(sess, newpacket); |
9de3ca7e | 333 | |
c78446b5 | 334 | return (sess->snac_nextid); |
9de3ca7e | 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. | |
98c88242 | 343 | * Bit 2: Allows other AIM users to see how long you've been a member. |
9de3ca7e | 344 | * |
345 | */ | |
5ac21963 | 346 | faim_export unsigned long aim_bos_setprivacyflags(struct aim_session_t *sess, |
347 | struct aim_conn_t *conn, | |
348 | u_long flags) | |
9de3ca7e | 349 | { |
a25832e6 | 350 | return aim_genericreq_l(sess, conn, 0x0001, 0x0014, &flags); |
9de3ca7e | 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 | */ | |
5ac21963 | 360 | faim_export unsigned long aim_bos_reqpersonalinfo(struct aim_session_t *sess, |
361 | struct aim_conn_t *conn) | |
9de3ca7e | 362 | { |
c78446b5 | 363 | return aim_genericreq_n(sess, conn, 0x0001, 0x000e); |
9de3ca7e | 364 | } |
365 | ||
5ac21963 | 366 | faim_export unsigned long aim_setversions(struct aim_session_t *sess, |
367 | struct aim_conn_t *conn) | |
01b59e1e | 368 | { |
5b79dc93 | 369 | struct command_tx_struct *newpacket; |
0c20631f | 370 | int i; |
01b59e1e | 371 | |
e80a0fa9 | 372 | if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10 + (4*16)))) |
5b79dc93 | 373 | return -1; |
374 | ||
375 | newpacket->lock = 1; | |
01b59e1e | 376 | |
5b79dc93 | 377 | i = aim_putsnac(newpacket->data, 0x0001, 0x0017, 0x0000, sess->snac_nextid); |
ee49b735 | 378 | aim_cachesnac(sess, 0x0001, 0x0017, 0x0000, NULL, 0); |
01b59e1e | 379 | |
5b79dc93 | 380 | i += aimutil_put16(newpacket->data+i, 0x0001); |
381 | i += aimutil_put16(newpacket->data+i, 0x0003); | |
26af6789 | 382 | |
5b79dc93 | 383 | i += aimutil_put16(newpacket->data+i, 0x0002); |
384 | i += aimutil_put16(newpacket->data+i, 0x0001); | |
26af6789 | 385 | |
5b79dc93 | 386 | i += aimutil_put16(newpacket->data+i, 0x0003); |
387 | i += aimutil_put16(newpacket->data+i, 0x0001); | |
26af6789 | 388 | |
5b79dc93 | 389 | i += aimutil_put16(newpacket->data+i, 0x0004); |
390 | i += aimutil_put16(newpacket->data+i, 0x0001); | |
26af6789 | 391 | |
5b79dc93 | 392 | i += aimutil_put16(newpacket->data+i, 0x0006); |
393 | i += aimutil_put16(newpacket->data+i, 0x0001); | |
26af6789 | 394 | |
5b79dc93 | 395 | i += aimutil_put16(newpacket->data+i, 0x0008); |
396 | i += aimutil_put16(newpacket->data+i, 0x0001); | |
26af6789 | 397 | |
5b79dc93 | 398 | i += aimutil_put16(newpacket->data+i, 0x0009); |
399 | i += aimutil_put16(newpacket->data+i, 0x0001); | |
26af6789 | 400 | |
5b79dc93 | 401 | i += aimutil_put16(newpacket->data+i, 0x000a); |
402 | i += aimutil_put16(newpacket->data+i, 0x0001); | |
26af6789 | 403 | |
5b79dc93 | 404 | i += aimutil_put16(newpacket->data+i, 0x000b); |
e80a0fa9 | 405 | i += aimutil_put16(newpacket->data+i, 0x0002); |
26af6789 | 406 | |
ee49b735 | 407 | i += aimutil_put16(newpacket->data+i, 0x000c); |
5b79dc93 | 408 | i += aimutil_put16(newpacket->data+i, 0x0001); |
01b59e1e | 409 | |
e80a0fa9 | 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); | |
414 | i += aimutil_put16(newpacket->data+i, 0x0001); | |
415 | ||
5925849b | 416 | newpacket->commandlen = i; |
5b79dc93 | 417 | newpacket->lock = 0; |
418 | aim_tx_enqueue(sess, newpacket); | |
01b59e1e | 419 | |
ee49b735 | 420 | return sess->snac_nextid; |
01b59e1e | 421 | } |
422 | ||
423 | ||
9de3ca7e | 424 | /* |
425 | * aim_bos_reqservice(serviceid) | |
426 | * | |
427 | * Service request. | |
428 | * | |
429 | */ | |
5ac21963 | 430 | faim_export unsigned long aim_bos_reqservice(struct aim_session_t *sess, |
a25832e6 | 431 | struct aim_conn_t *conn, |
432 | u_short serviceid) | |
9de3ca7e | 433 | { |
a25832e6 | 434 | return aim_genericreq_s(sess, conn, 0x0001, 0x0004, &serviceid); |
9de3ca7e | 435 | } |
436 | ||
f0a7908e | 437 | /* |
438 | * aim_bos_nop() | |
439 | * | |
440 | * No-op. WinAIM sends these every 4min or so to keep | |
98c88242 | 441 | * the connection alive. Its not real necessary. |
f0a7908e | 442 | * |
443 | */ | |
5ac21963 | 444 | faim_export unsigned long aim_bos_nop(struct aim_session_t *sess, |
445 | struct aim_conn_t *conn) | |
f0a7908e | 446 | { |
447 | return aim_genericreq_n(sess, conn, 0x0001, 0x0016); | |
448 | } | |
449 | ||
44d6f2dc | 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 | ||
646c6b52 | 461 | if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0005, 0))) |
44d6f2dc | 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 | ||
9de3ca7e | 473 | /* |
474 | * aim_bos_reqrights() | |
475 | * | |
476 | * Request BOS rights. | |
477 | * | |
478 | */ | |
5ac21963 | 479 | faim_export unsigned long aim_bos_reqrights(struct aim_session_t *sess, |
480 | struct aim_conn_t *conn) | |
9de3ca7e | 481 | { |
a25832e6 | 482 | return aim_genericreq_n(sess, conn, 0x0009, 0x0002); |
9de3ca7e | 483 | } |
484 | ||
485 | /* | |
486 | * aim_bos_reqbuddyrights() | |
487 | * | |
488 | * Request Buddy List rights. | |
489 | * | |
490 | */ | |
5ac21963 | 491 | faim_export unsigned long aim_bos_reqbuddyrights(struct aim_session_t *sess, |
492 | struct aim_conn_t *conn) | |
9de3ca7e | 493 | { |
a25832e6 | 494 | return aim_genericreq_n(sess, conn, 0x0003, 0x0002); |
9de3ca7e | 495 | } |
496 | ||
98c88242 | 497 | /* |
3b065cb0 | 498 | * Send a warning to destsn. |
499 | * | |
500 | * Flags: | |
501 | * AIM_WARN_ANON Send as an anonymous (doesn't count as much) | |
98c88242 | 502 | * |
3b065cb0 | 503 | * returns -1 on error (couldn't alloc packet), 0 on success. |
98c88242 | 504 | * |
505 | */ | |
3b065cb0 | 506 | faim_export int aim_send_warning(struct aim_session_t *sess, struct aim_conn_t *conn, const char *destsn, unsigned long flags) |
98c88242 | 507 | { |
3b065cb0 | 508 | struct command_tx_struct *newpacket; |
509 | int curbyte; | |
510 | unsigned short outflags = 0x0000; | |
98c88242 | 511 | |
3b065cb0 | 512 | if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, |
513 | strlen(destsn)+13))) | |
514 | return -1; | |
98c88242 | 515 | |
3b065cb0 | 516 | newpacket->lock = 1; |
98c88242 | 517 | |
3b065cb0 | 518 | curbyte = 0; |
519 | curbyte += aim_putsnac(newpacket->data+curbyte, | |
520 | 0x0004, 0x0008, 0x0000, sess->snac_nextid); | |
98c88242 | 521 | |
3b065cb0 | 522 | if (flags & AIM_WARN_ANON) |
523 | outflags |= 0x0001; | |
98c88242 | 524 | |
3b065cb0 | 525 | curbyte += aimutil_put16(newpacket->data+curbyte, outflags); |
526 | curbyte += aimutil_put8(newpacket->data+curbyte, strlen(destsn)); | |
527 | curbyte += aimutil_putstr(newpacket->data+curbyte, destsn, strlen(destsn)); | |
98c88242 | 528 | |
3b065cb0 | 529 | newpacket->commandlen = curbyte; |
530 | newpacket->lock = 0; | |
98c88242 | 531 | |
3b065cb0 | 532 | aim_tx_enqueue(sess, newpacket); |
98c88242 | 533 | |
3b065cb0 | 534 | aim_cachesnac(sess, 0x0004, 0x0008, 0x0000, destsn, strlen(destsn)+1); |
98c88242 | 535 | |
3b065cb0 | 536 | return 0; |
98c88242 | 537 | } |
538 | ||
e5012450 | 539 | /* |
540 | * aim_debugconn_sendconnect() | |
541 | * | |
542 | * For aimdebugd. If you don't know what it is, you don't want to. | |
543 | */ | |
5ac21963 | 544 | faim_export unsigned long aim_debugconn_sendconnect(struct aim_session_t *sess, |
545 | struct aim_conn_t *conn) | |
e5012450 | 546 | { |
547 | return aim_genericreq_n(sess, conn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_DEBUGCONN_CONNECT); | |
548 | } | |
549 | ||
9de3ca7e | 550 | /* |
551 | * Generic routine for sending commands. | |
552 | * | |
553 | * | |
554 | * I know I can do this in a smarter way...but I'm not thinking straight | |
555 | * right now... | |
556 | * | |
557 | * I had one big function that handled all three cases, but then it broke | |
558 | * and I split it up into three. But then I fixed it. I just never went | |
559 | * back to the single. I don't see any advantage to doing it either way. | |
560 | * | |
561 | */ | |
5ac21963 | 562 | faim_internal unsigned long aim_genericreq_n(struct aim_session_t *sess, |
563 | struct aim_conn_t *conn, | |
564 | u_short family, u_short subtype) | |
9de3ca7e | 565 | { |
5b79dc93 | 566 | struct command_tx_struct *newpacket; |
9de3ca7e | 567 | |
646c6b52 | 568 | if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10))) |
5b79dc93 | 569 | return 0; |
9de3ca7e | 570 | |
5b79dc93 | 571 | newpacket->lock = 1; |
9de3ca7e | 572 | |
f6686b7e | 573 | aim_putsnac(newpacket->data, family, subtype, 0x0000, 0x00000000); |
ee49b735 | 574 | |
5b79dc93 | 575 | aim_tx_enqueue(sess, newpacket); |
f6686b7e | 576 | |
ee49b735 | 577 | return sess->snac_nextid; |
9de3ca7e | 578 | } |
579 | ||
79e0a001 | 580 | faim_internal unsigned long aim_genericreq_n_snacid(struct aim_session_t *sess, |
581 | struct aim_conn_t *conn, | |
582 | unsigned short family, | |
583 | unsigned short subtype) | |
584 | { | |
585 | struct command_tx_struct *newpacket; | |
586 | ||
587 | if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10))) | |
588 | return 0; | |
589 | ||
590 | newpacket->lock = 1; | |
591 | ||
592 | aim_putsnac(newpacket->data, family, subtype, 0x0000, sess->snac_nextid); | |
593 | aim_cachesnac(sess, family, subtype, 0x0000, NULL, 0); | |
594 | ||
595 | aim_tx_enqueue(sess, newpacket); | |
596 | ||
597 | return sess->snac_nextid++; | |
598 | } | |
599 | ||
9de3ca7e | 600 | /* |
601 | * | |
602 | * | |
603 | */ | |
5ac21963 | 604 | faim_internal unsigned long aim_genericreq_l(struct aim_session_t *sess, |
605 | struct aim_conn_t *conn, | |
606 | u_short family, u_short subtype, | |
607 | u_long *longdata) | |
9de3ca7e | 608 | { |
5b79dc93 | 609 | struct command_tx_struct *newpacket; |
9de3ca7e | 610 | u_long newlong; |
611 | ||
612 | /* If we don't have data, there's no reason to use this function */ | |
613 | if (!longdata) | |
a25832e6 | 614 | return aim_genericreq_n(sess, conn, family, subtype); |
9de3ca7e | 615 | |
646c6b52 | 616 | if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+sizeof(u_long)))) |
5b79dc93 | 617 | return -1; |
9de3ca7e | 618 | |
5b79dc93 | 619 | newpacket->lock = 1; |
9de3ca7e | 620 | |
f6686b7e | 621 | aim_putsnac(newpacket->data, family, subtype, 0x0000, 0x00000000); |
9de3ca7e | 622 | |
623 | /* copy in data */ | |
624 | newlong = htonl(*longdata); | |
5b79dc93 | 625 | memcpy(&(newpacket->data[10]), &newlong, sizeof(u_long)); |
9de3ca7e | 626 | |
5b79dc93 | 627 | aim_tx_enqueue(sess, newpacket); |
f6686b7e | 628 | |
ee49b735 | 629 | return sess->snac_nextid; |
9de3ca7e | 630 | } |
631 | ||
5ac21963 | 632 | faim_internal unsigned long aim_genericreq_s(struct aim_session_t *sess, |
633 | struct aim_conn_t *conn, | |
634 | u_short family, u_short subtype, | |
635 | u_short *shortdata) | |
9de3ca7e | 636 | { |
5b79dc93 | 637 | struct command_tx_struct *newpacket; |
9de3ca7e | 638 | u_short newshort; |
639 | ||
640 | /* If we don't have data, there's no reason to use this function */ | |
641 | if (!shortdata) | |
a25832e6 | 642 | return aim_genericreq_n(sess, conn, family, subtype); |
9de3ca7e | 643 | |
646c6b52 | 644 | if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+sizeof(u_short)))) |
5b79dc93 | 645 | return -1; |
9de3ca7e | 646 | |
5b79dc93 | 647 | newpacket->lock = 1; |
9de3ca7e | 648 | |
f6686b7e | 649 | aim_putsnac(newpacket->data, family, subtype, 0x0000, 0x00000000); |
9de3ca7e | 650 | |
651 | /* copy in data */ | |
652 | newshort = htons(*shortdata); | |
5b79dc93 | 653 | memcpy(&(newpacket->data[10]), &newshort, sizeof(u_short)); |
9de3ca7e | 654 | |
5b79dc93 | 655 | aim_tx_enqueue(sess, newpacket); |
f6686b7e | 656 | |
ee49b735 | 657 | return sess->snac_nextid; |
9de3ca7e | 658 | } |
659 | ||
660 | /* | |
661 | * aim_bos_reqlocaterights() | |
662 | * | |
663 | * Request Location services rights. | |
664 | * | |
665 | */ | |
5ac21963 | 666 | faim_export unsigned long aim_bos_reqlocaterights(struct aim_session_t *sess, |
667 | struct aim_conn_t *conn) | |
9de3ca7e | 668 | { |
a25832e6 | 669 | return aim_genericreq_n(sess, conn, 0x0002, 0x0002); |
9de3ca7e | 670 | } |
671 | ||
672 | /* | |
e88ba395 | 673 | * aim_bos_reqicbmparaminfo() |
9de3ca7e | 674 | * |
675 | * Request ICBM parameter information. | |
676 | * | |
677 | */ | |
5ac21963 | 678 | faim_export unsigned long aim_bos_reqicbmparaminfo(struct aim_session_t *sess, |
679 | struct aim_conn_t *conn) | |
9de3ca7e | 680 | { |
a25832e6 | 681 | return aim_genericreq_n(sess, conn, 0x0004, 0x0004); |
9de3ca7e | 682 | } |
e88ba395 | 683 | |
c78446b5 | 684 | /* |
685 | * Add ICBM parameter? Huh? | |
686 | */ | |
5ac21963 | 687 | faim_export unsigned long aim_addicbmparam(struct aim_session_t *sess, |
688 | struct aim_conn_t *conn) | |
c78446b5 | 689 | { |
690 | struct command_tx_struct *newpacket; | |
691 | int packlen = 10+16, i=0; | |
692 | ||
646c6b52 | 693 | if(!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, packlen))) |
c78446b5 | 694 | return (sess->snac_nextid); |
695 | ||
696 | newpacket->lock = 1; | |
697 | ||
f6686b7e | 698 | i = aim_putsnac(newpacket->data, 0x0004, 0x0002, 0x0000, 0x00000000); |
ee49b735 | 699 | |
c78446b5 | 700 | i += aimutil_put16(newpacket->data+i, 0x0000); |
701 | i += aimutil_put16(newpacket->data+i, 0x0000); | |
702 | i += aimutil_put16(newpacket->data+i, 0x0003); | |
703 | i += aimutil_put16(newpacket->data+i, 0x1f40); | |
704 | i += aimutil_put16(newpacket->data+i, 0x03e7); | |
705 | i += aimutil_put16(newpacket->data+i, 0x03e7); | |
706 | i += aimutil_put16(newpacket->data+i, 0x0000); | |
707 | i += aimutil_put16(newpacket->data+i, 0x0000); | |
708 | ||
709 | aim_tx_enqueue(sess, newpacket); | |
710 | ||
ee49b735 | 711 | return sess->snac_nextid; |
c78446b5 | 712 | } |
f2d214f9 | 713 | |
714 | /* | |
715 | * Set directory profile data (not the same as aim_bos_setprofile!) | |
716 | */ | |
717 | 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) | |
718 | { | |
719 | struct command_tx_struct *newpacket; | |
720 | int packlen = 0, i = 0; | |
721 | ||
722 | packlen += 2+2+2; | |
723 | ||
724 | if(first) /* TLV 0001 */ | |
725 | packlen += (strlen(first) + 4); | |
726 | if(middle) | |
727 | packlen += (strlen(middle) + 4); | |
728 | if(last) | |
729 | packlen += (strlen(last) + 4); | |
730 | if(maiden) | |
731 | packlen += (strlen(maiden) + 4); | |
732 | if(nickname) | |
733 | packlen += (strlen(nickname) + 4); | |
734 | if(street) | |
735 | packlen += (strlen(street) + 4); | |
736 | if(state) | |
737 | packlen += (strlen(state) + 4); | |
738 | if(city) | |
739 | packlen += (strlen(city) + 4); | |
740 | if(zip) | |
741 | packlen += (strlen(zip) + 4); | |
742 | ||
646c6b52 | 743 | if(!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, packlen+10))) |
f2d214f9 | 744 | return -1; |
745 | ||
746 | newpacket->lock = 1; | |
747 | ||
748 | i = aim_putsnac(newpacket->data, 0x0002, 0x0009, 0x0000, 0); | |
749 | ||
750 | /* 000a/0002: privacy: 1 to allow search/disp, 0 to disallow */ | |
751 | i += aim_puttlv_16(newpacket->data+i, 0x000a, privacy); | |
752 | ||
753 | ||
754 | if (first) | |
755 | i += aim_puttlv_str(newpacket->data+i, 0x0001, strlen(first), first); | |
756 | if (middle) | |
757 | i += aim_puttlv_str(newpacket->data+i, 0x0003, strlen(middle), middle); | |
758 | if (last) | |
759 | i += aim_puttlv_str(newpacket->data+i, 0x0002, strlen(last), last); | |
760 | if (maiden) | |
761 | i += aim_puttlv_str(newpacket->data+i, 0x0004, strlen(maiden), maiden); | |
762 | if (nickname) | |
763 | i += aim_puttlv_str(newpacket->data+i, 0x000c, strlen(nickname), nickname); | |
764 | if (street) | |
765 | i += aim_puttlv_str(newpacket->data+i, 0x0021, strlen(street), street); | |
766 | if (city) | |
767 | i += aim_puttlv_str(newpacket->data+i, 0x0008, strlen(city), city); | |
768 | if (state) | |
769 | i += aim_puttlv_str(newpacket->data+i, 0x0007, strlen(state), state); | |
770 | if (zip) | |
771 | i += aim_puttlv_str(newpacket->data+i, 0x000d, strlen(zip), zip); | |
772 | ||
773 | newpacket->commandlen = i; | |
774 | newpacket->lock = 0; | |
775 | ||
776 | aim_tx_enqueue(sess, newpacket); | |
777 | ||
778 | return(sess->snac_nextid); | |
779 | } | |
780 | ||
781 | 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) | |
782 | { | |
783 | struct command_tx_struct *newpacket; | |
784 | int packlen = 0, i = 0; | |
785 | ||
786 | packlen += 2+2+2; | |
787 | ||
788 | if(interest1) | |
789 | packlen += (strlen(interest1) + 4); | |
790 | if(interest2) | |
791 | packlen += (strlen(interest2) + 4); | |
792 | if(interest3) | |
793 | packlen += (strlen(interest3) + 4); | |
794 | if(interest4) | |
795 | packlen += (strlen(interest4) + 4); | |
796 | if(interest5) | |
797 | packlen += (strlen(interest5) + 4) ; | |
798 | ||
799 | ||
646c6b52 | 800 | if(!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, packlen+10))) |
f2d214f9 | 801 | return -1; |
802 | ||
803 | newpacket->lock = 1; | |
804 | ||
805 | i = aim_putsnac(newpacket->data, 0x0002, 0x000f, 0x0000, 0); | |
806 | ||
807 | /* 000a/0002: 0000 ?? ?privacy? */ | |
808 | i += aim_puttlv_16(newpacket->data+i, 0x000a, privacy); | |
809 | ||
810 | if(interest1) | |
811 | i += aim_puttlv_str(newpacket->data+i, 0x000b, strlen(interest1), interest1); | |
812 | if(interest2) | |
813 | i += aim_puttlv_str(newpacket->data+i, 0x000b, strlen(interest2), interest2); | |
814 | if(interest3) | |
815 | i += aim_puttlv_str(newpacket->data+i, 0x000b, strlen(interest3), interest3); | |
816 | if(interest4) | |
817 | i += aim_puttlv_str(newpacket->data+i, 0x000b, strlen(interest4), interest4); | |
818 | if(interest5) | |
819 | i += aim_puttlv_str(newpacket->data+i, 0x000b, strlen(interest1), interest5); | |
820 | ||
821 | newpacket->commandlen = i; | |
822 | newpacket->lock = 0; | |
823 | ||
824 | aim_tx_enqueue(sess, newpacket); | |
825 | ||
826 | return(sess->snac_nextid); | |
827 | } | |
ec6b8da8 | 828 | |
829 | faim_export unsigned long aim_icq_setstatus(struct aim_session_t *sess, | |
830 | struct aim_conn_t *conn, | |
831 | unsigned long status) | |
832 | { | |
833 | struct command_tx_struct *newpacket; | |
834 | int i; | |
835 | unsigned long data; | |
836 | ||
837 | data = 0x00030000 | status; /* yay for error checking ;^) */ | |
838 | ||
646c6b52 | 839 | if(!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10 + 4))) |
ec6b8da8 | 840 | return -1; |
841 | ||
842 | newpacket->lock = 1; | |
843 | ||
844 | i = aim_putsnac(newpacket->data, 0x0001, 0x001e, 0x0000, 0x0000001e); | |
845 | i += aim_puttlv_32(newpacket->data+i, 0x0006, data); | |
846 | ||
847 | newpacket->commandlen = i; | |
848 | newpacket->lock = 0; | |
849 | ||
850 | aim_tx_enqueue(sess, newpacket); | |
851 | ||
852 | return(sess->snac_nextid); | |
853 | } | |
00ef5271 | 854 | |
855 | /* | |
856 | * Should be generic enough to handle the errors for all families... | |
857 | * | |
858 | */ | |
859 | 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) | |
860 | { | |
861 | int ret = 0; | |
862 | int error = 0; | |
e677fc43 | 863 | aim_rxcallback_t userfunc; |
00ef5271 | 864 | struct aim_snac_t *snac2; |
865 | ||
866 | snac2 = aim_remsnac(sess, snac->id); | |
867 | ||
868 | if (datalen) | |
869 | error = aimutil_get16(data); | |
870 | ||
871 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
872 | ret = userfunc(sess, rx, error, snac2?snac2->data:NULL); | |
873 | ||
874 | if (snac2) | |
875 | free(snac2->data); | |
876 | free(snac2); | |
877 | ||
878 | return ret; | |
879 | } | |
880 | ||
881 | 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) | |
882 | { | |
883 | ||
884 | if (snac->subtype == 0x0001) | |
885 | return generror(sess, mod, rx, snac, data, datalen); | |
886 | else if ((snac->family == 0xffff) && (snac->subtype == 0xffff)) { | |
e677fc43 | 887 | aim_rxcallback_t userfunc; |
00ef5271 | 888 | |
889 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
890 | return userfunc(sess, rx); | |
891 | } | |
892 | ||
893 | return 0; | |
894 | } | |
895 | ||
896 | faim_internal int misc_modfirst(struct aim_session_t *sess, aim_module_t *mod) | |
897 | { | |
898 | ||
899 | mod->family = 0xffff; | |
900 | mod->version = 0x0000; | |
901 | mod->flags = AIM_MODFLAG_MULTIFAMILY; | |
902 | strncpy(mod->name, "misc", sizeof(mod->name)); | |
903 | mod->snachandler = snachandler; | |
904 | ||
905 | return 0; | |
906 | } |