comparison libgaim/protocols/oscar/family_icbm.c @ 15088:25c3a33c6485

[gaim-migrate @ 17874] Add a flap_connection_send_snac() helper function that makes it a little easier/cleaner to send a SNAC-based FLAP command. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sat, 02 Dec 2006 09:44:53 +0000
parents 60b1bc8dbf37
children 033e1604cf63
comparison
equal deleted inserted replaced
15087:337dfc40a538 15088:25c3a33c6485
267 * 267 *
268 */ 268 */
269 int aim_im_sendch1_ext(OscarData *od, struct aim_sendimext_args *args) 269 int aim_im_sendch1_ext(OscarData *od, struct aim_sendimext_args *args)
270 { 270 {
271 FlapConnection *conn; 271 FlapConnection *conn;
272 FlapFrame *frame;
273 aim_snacid_t snacid; 272 aim_snacid_t snacid;
273 ByteStream data;
274 guchar cookie[8]; 274 guchar cookie[8];
275 int msgtlvlen; 275 int msgtlvlen;
276 static const guint8 deffeatures[] = { 0x01, 0x01, 0x01, 0x02 }; 276 static const guint8 deffeatures[] = { 0x01, 0x01, 0x01, 0x02 };
277 277
278 if (!od || !(conn = flap_connection_findbygroup(od, 0x0004))) 278 if (!od || !(conn = flap_connection_findbygroup(od, 0x0004)))
311 } else { 311 } else {
312 msgtlvlen += 2 /* 0101 */ + 2 /* block len */; 312 msgtlvlen += 2 /* 0101 */ + 2 /* block len */;
313 msgtlvlen += 4 /* charset */ + args->msglen; 313 msgtlvlen += 4 /* charset */ + args->msglen;
314 } 314 }
315 315
316 frame = flap_frame_new(od, 0x02, msgtlvlen+128); 316 byte_stream_init(&data, g_malloc(msgtlvlen + 128), msgtlvlen + 128);
317
318 /* XXX - should be optional */
319 snacid = aim_cachesnac(od, 0x0004, 0x0006, 0x0000, args->destsn, strlen(args->destsn)+1);
320 aim_putsnac(&frame->data, 0x0004, 0x0006, 0x0000, snacid);
321 317
322 /* Generate an ICBM cookie */ 318 /* Generate an ICBM cookie */
323 aim_icbm_makecookie(cookie); 319 aim_icbm_makecookie(cookie);
324 320
325 /* ICBM header */ 321 /* ICBM header */
326 aim_im_puticbm(&frame->data, cookie, 0x0001, args->destsn); 322 aim_im_puticbm(&data, cookie, 0x0001, args->destsn);
327 323
328 /* Message TLV (type 0x0002) */ 324 /* Message TLV (type 0x0002) */
329 byte_stream_put16(&frame->data, 0x0002); 325 byte_stream_put16(&data, 0x0002);
330 byte_stream_put16(&frame->data, msgtlvlen); 326 byte_stream_put16(&data, msgtlvlen);
331 327
332 /* Features TLV (type 0x0501) */ 328 /* Features TLV (type 0x0501) */
333 byte_stream_put16(&frame->data, 0x0501); 329 byte_stream_put16(&data, 0x0501);
334 if (args->flags & AIM_IMFLAGS_CUSTOMFEATURES) { 330 if (args->flags & AIM_IMFLAGS_CUSTOMFEATURES) {
335 byte_stream_put16(&frame->data, args->featureslen); 331 byte_stream_put16(&data, args->featureslen);
336 byte_stream_putraw(&frame->data, args->features, args->featureslen); 332 byte_stream_putraw(&data, args->features, args->featureslen);
337 } else { 333 } else {
338 byte_stream_put16(&frame->data, sizeof(deffeatures)); 334 byte_stream_put16(&data, sizeof(deffeatures));
339 byte_stream_putraw(&frame->data, deffeatures, sizeof(deffeatures)); 335 byte_stream_putraw(&data, deffeatures, sizeof(deffeatures));
340 } 336 }
341 337
342 if (args->flags & AIM_IMFLAGS_MULTIPART) { 338 if (args->flags & AIM_IMFLAGS_MULTIPART) {
343 aim_mpmsg_section_t *sec; 339 aim_mpmsg_section_t *sec;
344 340
345 /* Insert each message part in a TLV (type 0x0101) */ 341 /* Insert each message part in a TLV (type 0x0101) */
346 for (sec = args->mpmsg->parts; sec; sec = sec->next) { 342 for (sec = args->mpmsg->parts; sec; sec = sec->next) {
347 byte_stream_put16(&frame->data, 0x0101); 343 byte_stream_put16(&data, 0x0101);
348 byte_stream_put16(&frame->data, sec->datalen + 4); 344 byte_stream_put16(&data, sec->datalen + 4);
349 byte_stream_put16(&frame->data, sec->charset); 345 byte_stream_put16(&data, sec->charset);
350 byte_stream_put16(&frame->data, sec->charsubset); 346 byte_stream_put16(&data, sec->charsubset);
351 byte_stream_putraw(&frame->data, (guchar *)sec->data, sec->datalen); 347 byte_stream_putraw(&data, (guchar *)sec->data, sec->datalen);
352 } 348 }
353 349
354 } else { 350 } else {
355 351
356 /* Insert message text in a TLV (type 0x0101) */ 352 /* Insert message text in a TLV (type 0x0101) */
357 byte_stream_put16(&frame->data, 0x0101); 353 byte_stream_put16(&data, 0x0101);
358 354
359 /* Message block length */ 355 /* Message block length */
360 byte_stream_put16(&frame->data, args->msglen + 0x04); 356 byte_stream_put16(&data, args->msglen + 0x04);
361 357
362 /* Character set */ 358 /* Character set */
363 byte_stream_put16(&frame->data, args->charset); 359 byte_stream_put16(&data, args->charset);
364 byte_stream_put16(&frame->data, args->charsubset); 360 byte_stream_put16(&data, args->charsubset);
365 361
366 /* Message. Not terminated */ 362 /* Message. Not terminated */
367 byte_stream_putraw(&frame->data, (guchar *)args->msg, args->msglen); 363 byte_stream_putraw(&data, (guchar *)args->msg, args->msglen);
368 } 364 }
369 365
370 /* Set the Autoresponse flag */ 366 /* Set the Autoresponse flag */
371 if (args->flags & AIM_IMFLAGS_AWAY) { 367 if (args->flags & AIM_IMFLAGS_AWAY) {
372 byte_stream_put16(&frame->data, 0x0004); 368 byte_stream_put16(&data, 0x0004);
373 byte_stream_put16(&frame->data, 0x0000); 369 byte_stream_put16(&data, 0x0000);
374 } else if (args->flags & AIM_IMFLAGS_ACK) { 370 } else if (args->flags & AIM_IMFLAGS_ACK) {
375 /* Set the Request Acknowledge flag */ 371 /* Set the Request Acknowledge flag */
376 byte_stream_put16(&frame->data, 0x0003); 372 byte_stream_put16(&data, 0x0003);
377 byte_stream_put16(&frame->data, 0x0000); 373 byte_stream_put16(&data, 0x0000);
378 } 374 }
379 375
380 if (args->flags & AIM_IMFLAGS_OFFLINE) { 376 if (args->flags & AIM_IMFLAGS_OFFLINE) {
381 byte_stream_put16(&frame->data, 0x0006); 377 byte_stream_put16(&data, 0x0006);
382 byte_stream_put16(&frame->data, 0x0000); 378 byte_stream_put16(&data, 0x0000);
383 } 379 }
384 380
385 /* 381 /*
386 * Set the I HAVE A REALLY PURTY ICON flag. 382 * Set the I HAVE A REALLY PURTY ICON flag.
387 * XXX - This should really only be sent on initial 383 * XXX - This should really only be sent on initial
388 * IMs and when you change your icon. 384 * IMs and when you change your icon.
389 */ 385 */
390 if (args->flags & AIM_IMFLAGS_HASICON) { 386 if (args->flags & AIM_IMFLAGS_HASICON) {
391 byte_stream_put16(&frame->data, 0x0008); 387 byte_stream_put16(&data, 0x0008);
392 byte_stream_put16(&frame->data, 0x000c); 388 byte_stream_put16(&data, 0x000c);
393 byte_stream_put32(&frame->data, args->iconlen); 389 byte_stream_put32(&data, args->iconlen);
394 byte_stream_put16(&frame->data, 0x0001); 390 byte_stream_put16(&data, 0x0001);
395 byte_stream_put16(&frame->data, args->iconsum); 391 byte_stream_put16(&data, args->iconsum);
396 byte_stream_put32(&frame->data, args->iconstamp); 392 byte_stream_put32(&data, args->iconstamp);
397 } 393 }
398 394
399 /* 395 /*
400 * Set the Buddy Icon Requested flag. 396 * Set the Buddy Icon Requested flag.
401 * XXX - Every time? Surely not... 397 * XXX - Every time? Surely not...
402 */ 398 */
403 if (args->flags & AIM_IMFLAGS_BUDDYREQ) { 399 if (args->flags & AIM_IMFLAGS_BUDDYREQ) {
404 byte_stream_put16(&frame->data, 0x0009); 400 byte_stream_put16(&data, 0x0009);
405 byte_stream_put16(&frame->data, 0x0000); 401 byte_stream_put16(&data, 0x0000);
406 } 402 }
407 403
408 flap_connection_send(conn, frame); 404 /* XXX - should be optional */
405 snacid = aim_cachesnac(od, 0x0004, 0x0006, 0x0000, args->destsn, strlen(args->destsn)+1);
406
407 flap_connection_send_snac(od, conn, 0x0004, 0x0006, 0x0000, snacid, &data);
408 g_free(data.data);
409 409
410 /* clean out SNACs over 60sec old */ 410 /* clean out SNACs over 60sec old */
411 aim_cleansnacs(od, 60); 411 aim_cleansnacs(od, 60);
412 412
413 return 0; 413 return 0;