Mercurial > pidgin
comparison src/protocols/msn/msg.c @ 6868:ab80de7a74d1
[gaim-migrate @ 7414]
Commitinating the current MSNSLP code. It's not working.. I don't know why.
No clients will respond to my messages, even though they appear very valid.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Wed, 17 Sep 2003 02:10:37 +0000 |
parents | bd433a45a463 |
children | 4c29ee932d67 |
comparison
equal
deleted
inserted
replaced
6867:1c4e4c725e0d | 6868:ab80de7a74d1 |
---|---|
96 msn_message_set_attr(msg, "User-Agent", NULL); | 96 msn_message_set_attr(msg, "User-Agent", NULL); |
97 | 97 |
98 msg->msnslp_message = TRUE; | 98 msg->msnslp_message = TRUE; |
99 msg->size += 52; | 99 msg->size += 52; |
100 | 100 |
101 msn_message_set_flag(msg, 'D'); | |
102 msn_message_set_content_type(msg, "application/x-msnmsgrp2p"); | |
103 msn_message_set_charset(msg, NULL); | |
104 | |
105 return msg; | |
106 } | |
107 | |
108 MsnMessage * | |
109 msn_message_new_msnslp_ack(MsnMessage *acked_msg) | |
110 { | |
111 MsnMessage *msg; | |
112 | |
113 g_return_val_if_fail(acked_msg != NULL, NULL); | |
114 g_return_val_if_fail(acked_msg->msnslp_message, NULL); | |
115 | |
116 msg = msn_message_new_msnslp(); | |
117 | |
118 msg->msnslp_ack_message = TRUE; | |
119 msg->acked_msg = msn_message_ref(acked_msg); | |
120 | |
121 msg->msnslp_header.session_id = acked_msg->msnslp_header.session_id; | |
122 msg->msnslp_header.total_size_1 = acked_msg->msnslp_header.total_size_1; | |
123 msg->msnslp_header.total_size_2 = acked_msg->msnslp_header.total_size_2; | |
124 msg->msnslp_header.flags = 0x02; | |
125 msg->msnslp_header.ack_session_id = acked_msg->msnslp_header.session_id; | |
126 msg->msnslp_header.ack_unique_id = acked_msg->msnslp_header.ack_session_id; | |
127 msg->msnslp_header.ack_length_1 = acked_msg->msnslp_header.total_size_1; | |
128 msg->msnslp_header.ack_length_2 = acked_msg->msnslp_header.total_size_2; | |
129 | |
101 return msg; | 130 return msg; |
102 } | 131 } |
103 | 132 |
104 MsnMessage * | 133 MsnMessage * |
105 msn_message_new_from_str(MsnSession *session, const char *str) | 134 msn_message_new_from_str(MsnSession *session, const char *str) |
217 memcpy(footer, tmp, 4); | 246 memcpy(footer, tmp, 4); |
218 | 247 |
219 /* Import the header. */ | 248 /* Import the header. */ |
220 msg->msnslp_header.session_id = msn_get32(tmp); tmp += 4; | 249 msg->msnslp_header.session_id = msn_get32(tmp); tmp += 4; |
221 msg->msnslp_header.id = msn_get32(tmp); tmp += 4; | 250 msg->msnslp_header.id = msn_get32(tmp); tmp += 4; |
222 msg->msnslp_header.offset = msn_get32(tmp); tmp += 8; | 251 msg->msnslp_header.offset_1 = msn_get32(tmp); tmp += 4; |
223 msg->msnslp_header.total_size = msn_get32(tmp); tmp += 8; | 252 msg->msnslp_header.offset_2 = msn_get32(tmp); tmp += 4; |
253 msg->msnslp_header.total_size_1 = msn_get32(tmp); tmp += 4; | |
254 msg->msnslp_header.total_size_2 = msn_get32(tmp); tmp += 4; | |
224 msg->msnslp_header.length = msn_get32(tmp); tmp += 4; | 255 msg->msnslp_header.length = msn_get32(tmp); tmp += 4; |
225 msg->msnslp_header.flags = msn_get32(tmp); tmp += 4; | 256 msg->msnslp_header.flags = msn_get32(tmp); tmp += 4; |
226 msg->msnslp_header.ack_session_id = msn_get32(tmp); tmp += 4; | 257 msg->msnslp_header.ack_session_id = msn_get32(tmp); tmp += 4; |
227 msg->msnslp_header.ack_unique_id = msn_get32(tmp); tmp += 4; | 258 msg->msnslp_header.ack_unique_id = msn_get32(tmp); tmp += 4; |
228 msg->msnslp_header.ack_length = msn_get32(tmp); tmp += 8; | 259 msg->msnslp_header.ack_length_1 = msn_get32(tmp); tmp += 4; |
260 msg->msnslp_header.ack_length_2 = msn_get32(tmp); tmp += 4; | |
229 | 261 |
230 /* Convert to the right endianness */ | 262 /* Convert to the right endianness */ |
231 msg->msnslp_header.session_id = ntohl(msg->msnslp_header.session_id); | 263 msg->msnslp_header.session_id = ntohl(msg->msnslp_header.session_id); |
232 msg->msnslp_header.id = ntohl(msg->msnslp_header.id); | 264 msg->msnslp_header.id = ntohl(msg->msnslp_header.id); |
233 msg->msnslp_header.length = ntohl(msg->msnslp_header.length); | 265 msg->msnslp_header.length = ntohl(msg->msnslp_header.length); |
234 msg->msnslp_header.flags = ntohl(msg->msnslp_header.flags); | 266 msg->msnslp_header.flags = ntohl(msg->msnslp_header.flags); |
235 msg->msnslp_header.ack_length = ntohl(msg->msnslp_header.ack_length); | 267 msg->msnslp_header.ack_length_1 = |
268 ntohl(msg->msnslp_header.ack_length_1); | |
269 msg->msnslp_header.ack_length_2 = | |
270 ntohl(msg->msnslp_header.ack_length_2); | |
236 msg->msnslp_header.ack_session_id = | 271 msg->msnslp_header.ack_session_id = |
237 ntohl(msg->msnslp_header.ack_session_id); | 272 ntohl(msg->msnslp_header.ack_session_id); |
238 msg->msnslp_header.ack_unique_id = | 273 msg->msnslp_header.ack_unique_id = |
239 ntohl(msg->msnslp_header.ack_unique_id); | 274 ntohl(msg->msnslp_header.ack_unique_id); |
240 | 275 |
280 g_free(msg->charset); | 315 g_free(msg->charset); |
281 | 316 |
282 g_hash_table_destroy(msg->attr_table); | 317 g_hash_table_destroy(msg->attr_table); |
283 g_list_free(msg->attr_list); | 318 g_list_free(msg->attr_list); |
284 | 319 |
320 if (msg->msnslp_ack_message) | |
321 msn_message_unref(msg->acked_msg); | |
322 | |
285 gaim_debug(GAIM_DEBUG_INFO, "msn", "Destroying message\n"); | 323 gaim_debug(GAIM_DEBUG_INFO, "msn", "Destroying message\n"); |
286 g_free(msg); | 324 g_free(msg); |
287 } | 325 } |
288 | 326 |
289 MsnMessage * | 327 MsnMessage * |
317 | 355 |
318 char * | 356 char * |
319 msn_message_to_string(const MsnMessage *msg, size_t *ret_size) | 357 msn_message_to_string(const MsnMessage *msg, size_t *ret_size) |
320 { | 358 { |
321 GList *l; | 359 GList *l; |
322 const char *body; | |
323 char *msg_start; | 360 char *msg_start; |
324 char *str; | 361 char *str; |
325 char buf[MSN_BUF_LEN]; | 362 char buf[MSN_BUF_LEN]; |
326 int len; | 363 int len; |
327 | 364 |
334 * | 371 * |
335 * -- ChipX86 | 372 * -- ChipX86 |
336 */ | 373 */ |
337 g_return_val_if_fail(msg != NULL, NULL); | 374 g_return_val_if_fail(msg != NULL, NULL); |
338 | 375 |
339 body = msn_message_get_body(msg); | |
340 | |
341 if (msn_message_is_incoming(msg)) { | 376 if (msn_message_is_incoming(msg)) { |
342 MsnUser *sender = msn_message_get_sender(msg); | 377 MsnUser *sender = msn_message_get_sender(msg); |
343 | 378 |
344 g_snprintf(buf, sizeof(buf), "MSG %s %s %d\r\n", | 379 g_snprintf(buf, sizeof(buf), "MSG %s %s %d\r\n", |
345 msn_user_get_passport(sender), msn_user_get_name(sender), | 380 msn_user_get_passport(sender), msn_user_get_name(sender), |
389 g_strlcat(str, "\r\n", len); | 424 g_strlcat(str, "\r\n", len); |
390 | 425 |
391 if (msg->msnslp_message) | 426 if (msg->msnslp_message) |
392 { | 427 { |
393 char *c; | 428 char *c; |
394 long session_id, id, offset, total_size, length, flags; | 429 long session_id, id, offset_1, offset_2, total_size_1, total_size_2; |
395 long ack_session_id, ack_unique_id, ack_length; | 430 long length, flags; |
431 long ack_session_id, ack_unique_id, ack_length_1, ack_length_2; | |
396 | 432 |
397 c = str + strlen(str); | 433 c = str + strlen(str); |
398 | 434 |
399 session_id = htonl(msg->msnslp_header.session_id); | 435 session_id = htonl(msg->msnslp_header.session_id); |
400 id = htonl(msg->msnslp_header.id); | 436 id = htonl(msg->msnslp_header.id); |
401 offset = htonl(msg->msnslp_header.offset); | 437 offset_1 = htonl(msg->msnslp_header.offset_1); |
402 total_size = htonl(msg->msnslp_header.total_size); | 438 offset_2 = htonl(msg->msnslp_header.offset_2); |
439 total_size_1 = htonl(msg->msnslp_header.total_size_1); | |
440 total_size_2 = htonl(msg->msnslp_header.total_size_2); | |
403 length = htonl(msg->msnslp_header.length); | 441 length = htonl(msg->msnslp_header.length); |
404 flags = htonl(msg->msnslp_header.flags); | 442 flags = htonl(msg->msnslp_header.flags); |
405 ack_session_id = htonl(msg->msnslp_header.ack_session_id); | 443 ack_session_id = htonl(msg->msnslp_header.ack_session_id); |
406 ack_unique_id = htonl(msg->msnslp_header.ack_unique_id); | 444 ack_unique_id = htonl(msg->msnslp_header.ack_unique_id); |
407 ack_length = htonl(msg->msnslp_header.ack_length); | 445 ack_length_1 = htonl(msg->msnslp_header.ack_length_1); |
446 ack_length_2 = htonl(msg->msnslp_header.ack_length_2); | |
408 | 447 |
409 c += msn_put32(c, session_id); | 448 c += msn_put32(c, session_id); |
410 c += msn_put32(c, id); | 449 c += msn_put32(c, id); |
411 c += msn_put32(c, offset); | 450 c += msn_put32(c, offset_1); |
412 c += msn_put32(c, 0); | 451 c += msn_put32(c, offset_2); |
413 c += msn_put32(c, total_size); | 452 c += msn_put32(c, total_size_1); |
414 c += msn_put32(c, 0); | 453 c += msn_put32(c, total_size_2); |
415 c += msn_put32(c, length); | 454 c += msn_put32(c, length); |
416 c += msn_put32(c, flags); | 455 c += msn_put32(c, flags); |
417 c += msn_put32(c, ack_session_id); | 456 c += msn_put32(c, ack_session_id); |
418 c += msn_put32(c, ack_unique_id); | 457 c += msn_put32(c, ack_unique_id); |
419 c += msn_put32(c, ack_length); | 458 c += msn_put32(c, ack_length_1); |
420 c += msn_put32(c, 0); | 459 c += msn_put32(c, ack_length_2); |
421 | 460 |
422 if (body != NULL) | 461 if (msg->bin_content) |
423 { | 462 { |
424 g_strlcpy(c, body, msg->size - (c - msg_start)); | 463 size_t bin_len; |
425 | 464 const void *body = msn_message_get_bin_data(msg, &bin_len); |
426 c += strlen(body); | 465 |
427 | 466 if (body != NULL) |
428 if (strlen(body) > 0) | 467 { |
429 *c++ = '\0'; | 468 memcpy(c, body, msg->size - (c - msg_start)); |
469 | |
470 c += bin_len; | |
471 } | |
472 } | |
473 else | |
474 { | |
475 const char *body = msn_message_get_body(msg); | |
476 | |
477 if (body != NULL) | |
478 { | |
479 g_strlcpy(c, body, msg->size - (c - msg_start)); | |
480 | |
481 c += strlen(body); | |
482 | |
483 if (strlen(body) > 0) | |
484 *c++ = '\0'; | |
485 } | |
430 } | 486 } |
431 | 487 |
432 c += msn_put32(c, msg->msnslp_footer.app_id); | 488 c += msn_put32(c, msg->msnslp_footer.app_id); |
433 | 489 |
434 if (msg->size != (c - msg_start)) | 490 if (msg->size != (c - msg_start)) |
438 "do not match!\n", msg->size, (c - msg_start)); | 494 "do not match!\n", msg->size, (c - msg_start)); |
439 } | 495 } |
440 } | 496 } |
441 else | 497 else |
442 { | 498 { |
499 const char *body = msn_message_get_body(msg); | |
500 | |
443 g_strlcat(str, body, len); | 501 g_strlcat(str, body, len); |
444 | 502 |
445 if (msg->size != strlen(msg_start)) { | 503 if (msg->size != strlen(msg_start)) { |
446 gaim_debug(GAIM_DEBUG_ERROR, "msn", | 504 gaim_debug(GAIM_DEBUG_ERROR, "msn", |
447 "Outgoing message size (%d) and string length (%d) " | 505 "Outgoing message size (%d) and string length (%d) " |
496 g_return_if_fail(msg != NULL); | 554 g_return_if_fail(msg != NULL); |
497 g_return_if_fail(user != NULL); | 555 g_return_if_fail(user != NULL); |
498 | 556 |
499 msg->receiver = user; | 557 msg->receiver = user; |
500 | 558 |
559 if (msg->msnslp_message) | |
560 msn_message_set_attr(msg, "P2P-Dest", msn_user_get_passport(user)); | |
561 | |
501 msn_user_ref(msg->receiver); | 562 msn_user_ref(msg->receiver); |
502 } | 563 } |
503 | 564 |
504 MsnUser * | 565 MsnUser * |
505 msn_message_get_receiver(const MsnMessage *msg) | 566 msn_message_get_receiver(const MsnMessage *msg) |
550 char *buf, *d; | 611 char *buf, *d; |
551 int newline_count = 0; | 612 int newline_count = 0; |
552 size_t new_len; | 613 size_t new_len; |
553 | 614 |
554 g_return_if_fail(msg != NULL); | 615 g_return_if_fail(msg != NULL); |
555 g_return_if_fail(body != NULL); | 616 |
617 if (msg->bin_content) | |
618 msn_message_set_bin_data(msg, NULL, 0); | |
556 | 619 |
557 if (msg->body != NULL) { | 620 if (msg->body != NULL) { |
558 msg->size -= strlen(msg->body); | 621 msg->size -= strlen(msg->body); |
559 g_free(msg->body); | 622 g_free(msg->body); |
560 | 623 |
561 if (msg->msnslp_message) | 624 if (msg->msnslp_message) |
562 msg->size--; | 625 msg->size--; |
563 } | 626 } |
564 | 627 |
565 for (c = body; *c != '\0'; c++) { | 628 if (body != NULL) |
566 if (*c == '\n' && (c == body || *(c - 1) != '\r')) | 629 { |
567 newline_count++; | 630 for (c = body; *c != '\0'; c++) |
568 } | 631 { |
569 | 632 if (*c == '\n' && (c == body || *(c - 1) != '\r')) |
570 new_len = strlen(body) + newline_count; | 633 newline_count++; |
571 | 634 } |
572 buf = g_new0(char, new_len + 1); | 635 |
573 | 636 new_len = strlen(body) + newline_count; |
574 for (c = body, d = buf; *c != '\0'; c++) { | 637 |
575 if (*c == '\n' && (c == body || *(c - 1) != '\r')) { | 638 buf = g_new0(char, new_len + 1); |
576 *d++ = '\r'; | 639 |
577 *d++ = '\n'; | 640 for (c = body, d = buf; *c != '\0'; c++) { |
578 } | 641 if (*c == '\n' && (c == body || *(c - 1) != '\r')) { |
579 else | 642 *d++ = '\r'; |
580 *d++ = *c; | 643 *d++ = '\n'; |
581 } | 644 } |
582 | 645 else |
583 msg->body = buf; | 646 *d++ = *c; |
584 | 647 } |
585 msg->size += new_len; | 648 |
586 | 649 msg->body = buf; |
587 if (msg->msnslp_message) | 650 msg->size += new_len; |
588 msg->size++; | 651 |
652 msg->bin_content = FALSE; | |
653 | |
654 if (msg->msnslp_message) | |
655 msg->size++; | |
656 } | |
657 else | |
658 msg->body = NULL; | |
589 } | 659 } |
590 | 660 |
591 const char * | 661 const char * |
592 msn_message_get_body(const MsnMessage *msg) | 662 msn_message_get_body(const MsnMessage *msg) |
593 { | 663 { |
594 g_return_val_if_fail(msg != NULL, NULL); | 664 g_return_val_if_fail(msg != NULL, NULL); |
665 g_return_val_if_fail(!msg->bin_content, NULL); | |
666 | |
667 return msg->body; | |
668 } | |
669 | |
670 void | |
671 msn_message_set_bin_data(MsnMessage *msg, const void *data, size_t len) | |
672 { | |
673 g_return_if_fail(msg != NULL); | |
674 | |
675 if (!msg->bin_content) | |
676 msn_message_set_body(msg, NULL); | |
677 | |
678 msg->bin_content = TRUE; | |
679 | |
680 if (msg->body != NULL) | |
681 { | |
682 msg->size -= msg->bin_len; | |
683 g_free(msg->body); | |
684 } | |
685 | |
686 if (data != NULL && len > 0) | |
687 { | |
688 msg->body = g_memdup(data, len); | |
689 msg->bin_len = len; | |
690 | |
691 msg->size += len; | |
692 } | |
693 else | |
694 { | |
695 msg->body = NULL; | |
696 msg->bin_len = 0; | |
697 } | |
698 } | |
699 | |
700 const void * | |
701 msn_message_get_bin_data(const MsnMessage *msg, size_t *len) | |
702 { | |
703 g_return_val_if_fail(msg != NULL, NULL); | |
704 g_return_val_if_fail(len != NULL, NULL); | |
705 g_return_val_if_fail(msg->bin_content, NULL); | |
706 | |
707 *len = msg->bin_len; | |
595 | 708 |
596 return msg->body; | 709 return msg->body; |
597 } | 710 } |
598 | 711 |
599 void | 712 void |