Mercurial > pidgin
comparison src/protocols/msn/switchboard.c @ 8646:1e211dde3cae
[gaim-migrate @ 9398]
Added a patch by shx to clean up the message-handling code and split the
command stuff from it, among a few other things. Also, I fixed a crash in
message parsing, which I think may close a couple bug reports.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Tue, 13 Apr 2004 04:08:22 +0000 |
parents | fc27237783ee |
children | 17ef51dc609c |
comparison
equal
deleted
inserted
replaced
8645:47f647dd2ac3 | 8646:1e211dde3cae |
---|---|
258 } | 258 } |
259 | 259 |
260 return send_clientcaps(swboard); | 260 return send_clientcaps(swboard); |
261 } | 261 } |
262 | 262 |
263 static void | |
264 msg_cmd_post(MsnServConn *servconn, char *payload, size_t len) | |
265 { | |
266 MsnMessage *msg = msn_message_new(); | |
267 | |
268 msg->passport = servconn->msg_passport; | |
269 | |
270 msn_message_parse_payload(msg, payload, len); | |
271 | |
272 msn_servconn_process_message(servconn, msg); | |
273 | |
274 msn_message_destroy(msg); | |
275 } | |
276 | |
263 static gboolean | 277 static gboolean |
264 msg_cmd(MsnServConn *servconn, const char *command, const char **params, | 278 msg_cmd(MsnServConn *servconn, const char *command, const char **params, |
265 size_t param_count) | 279 size_t param_count) |
266 { | 280 { |
267 gaim_debug(GAIM_DEBUG_INFO, "msn", "Found message. Parsing.\n"); | 281 gaim_debug(GAIM_DEBUG_INFO, "msn", "Found message. Parsing.\n"); |
268 | 282 |
269 servconn->parsing_multiline = TRUE; | 283 servconn->payload_cb = msg_cmd_post; |
270 servconn->multiline_type = MSN_MULTILINE_MSG; | 284 servconn->payload_len = atoi(params[2]); |
271 servconn->multiline_len = atoi(params[2]); | |
272 | 285 |
273 servconn->msg_passport = g_strdup(params[0]); | 286 servconn->msg_passport = g_strdup(params[0]); |
274 servconn->msg_friendly = g_strdup(params[1]); | |
275 | 287 |
276 return TRUE; | 288 return TRUE; |
277 } | 289 } |
278 | 290 |
279 static gboolean | 291 static gboolean |
336 char *body; | 348 char *body; |
337 const char *value; | 349 const char *value; |
338 | 350 |
339 body = gaim_escape_html(msn_message_get_body(msg)); | 351 body = gaim_escape_html(msn_message_get_body(msg)); |
340 | 352 |
341 if (!strcmp(servconn->msg_passport, "messenger@microsoft.com") && | 353 if (!strcmp(msg->passport, "messenger@microsoft.com") && |
342 strstr(body, "immediate security update")) | 354 strstr(body, "immediate security update")) |
343 { | 355 { |
344 g_free(body); | 356 g_free(body); |
345 | 357 |
346 return TRUE; | 358 return TRUE; |
347 } | 359 } |
348 | 360 |
361 #if 0 | |
349 gaim_debug(GAIM_DEBUG_INFO, "msn", "Checking User-Agent...\n"); | 362 gaim_debug(GAIM_DEBUG_INFO, "msn", "Checking User-Agent...\n"); |
350 | 363 |
351 if ((value = msn_message_get_attr(msg, "User-Agent")) != NULL) { | 364 if ((value = msn_message_get_attr(msg, "User-Agent")) != NULL) { |
352 gaim_debug(GAIM_DEBUG_MISC, "msn", "value = '%s'\n", value); | 365 gaim_debug(GAIM_DEBUG_MISC, "msn", "value = '%s'\n", value); |
353 } | 366 } |
367 #endif | |
354 | 368 |
355 if ((value = msn_message_get_attr(msg, "X-MMS-IM-Format")) != NULL) { | 369 if ((value = msn_message_get_attr(msg, "X-MMS-IM-Format")) != NULL) { |
356 char *pre_format, *post_format; | 370 char *pre_format, *post_format; |
357 | 371 |
358 msn_parse_format(value, &pre_format, &post_format); | 372 msn_parse_format(value, &pre_format, &post_format); |
365 | 379 |
366 if (swboard->chat != NULL) | 380 if (swboard->chat != NULL) |
367 { | 381 { |
368 serv_got_chat_in(gc, | 382 serv_got_chat_in(gc, |
369 gaim_conv_chat_get_id(GAIM_CONV_CHAT(swboard->chat)), | 383 gaim_conv_chat_get_id(GAIM_CONV_CHAT(swboard->chat)), |
370 servconn->msg_passport, 0, body, time(NULL)); | 384 msg->passport, 0, body, time(NULL)); |
371 } | 385 } |
372 else | 386 else |
373 serv_got_im(gc, servconn->msg_passport, body, 0, time(NULL)); | 387 serv_got_im(gc, msg->passport, body, 0, time(NULL)); |
374 | 388 |
375 g_free(body); | 389 g_free(body); |
376 | 390 |
377 return TRUE; | 391 return TRUE; |
378 } | 392 } |
385 const char *value; | 399 const char *value; |
386 | 400 |
387 if (swboard->chat == NULL && | 401 if (swboard->chat == NULL && |
388 (value = msn_message_get_attr(msg, "TypingUser")) != NULL) { | 402 (value = msn_message_get_attr(msg, "TypingUser")) != NULL) { |
389 | 403 |
390 serv_got_typing(gc, servconn->msg_passport, MSN_TYPING_RECV_TIMEOUT, | 404 serv_got_typing(gc, msg->passport, MSN_TYPING_RECV_TIMEOUT, |
391 GAIM_TYPING); | 405 GAIM_TYPING); |
392 } | 406 } |
393 | 407 |
394 return TRUE; | 408 return TRUE; |
395 } | 409 } |
402 MsnSwitchBoard *swboard = servconn->data; | 416 MsnSwitchBoard *swboard = servconn->data; |
403 MsnUser *user; | 417 MsnUser *user; |
404 GHashTable *clientcaps; | 418 GHashTable *clientcaps; |
405 const char *value; | 419 const char *value; |
406 | 420 |
407 user = msn_user_new(session, servconn->msg_passport, NULL); | 421 user = msn_user_new(session, msg->passport, NULL); |
408 | 422 |
409 clientcaps = msn_message_get_hashtable_from_body(msg); | 423 clientcaps = msn_message_get_hashtable_from_body(msg); |
410 #endif | 424 #endif |
411 | 425 |
412 return TRUE; | 426 return TRUE; |
498 msn_servconn_register_command(servconn, "_unknown_",unknown_cmd); | 512 msn_servconn_register_command(servconn, "_unknown_",unknown_cmd); |
499 | 513 |
500 /* Register the message type callbacks. */ | 514 /* Register the message type callbacks. */ |
501 msn_servconn_register_msg_type(servconn, "text/plain",plain_msg); | 515 msn_servconn_register_msg_type(servconn, "text/plain",plain_msg); |
502 msn_servconn_register_msg_type(servconn, "text/x-msmsgscontrol", | 516 msn_servconn_register_msg_type(servconn, "text/x-msmsgscontrol", |
503 control_msg); | 517 control_msg); |
504 msn_servconn_register_msg_type(servconn, "text/x-clientcaps", | 518 msn_servconn_register_msg_type(servconn, "text/x-clientcaps", |
505 clientcaps_msg); | 519 clientcaps_msg); |
506 msn_servconn_register_msg_type(servconn, "text/x-clientinfo", | 520 msn_servconn_register_msg_type(servconn, "text/x-clientinfo", |
507 clientcaps_msg); | 521 clientcaps_msg); |
508 #if 0 | 522 #if 0 |
509 msn_servconn_register_msg_type(servconn, "application/x-msnmsgrp2p", | 523 msn_servconn_register_msg_type(servconn, "application/x-msnmsgrp2p", |
510 msn_p2p_msg); | 524 msn_p2p_msg); |
511 #endif | 525 #endif |
512 | 526 |
650 | 664 |
651 gboolean | 665 gboolean |
652 msn_switchboard_send_msg(MsnSwitchBoard *swboard, MsnMessage *msg) | 666 msn_switchboard_send_msg(MsnSwitchBoard *swboard, MsnMessage *msg) |
653 { | 667 { |
654 char *buf; | 668 char *buf; |
669 char *payload; | |
655 size_t len; | 670 size_t len; |
671 size_t payload_len; | |
656 int ret; | 672 int ret; |
657 #if 0 | 673 #if 0 |
658 FILE *fp; | 674 FILE *fp; |
659 #endif | 675 #endif |
660 | 676 |
661 g_return_val_if_fail(swboard != NULL, FALSE); | 677 g_return_val_if_fail(swboard != NULL, FALSE); |
662 g_return_val_if_fail(msg != NULL, FALSE); | 678 g_return_val_if_fail(msg != NULL, FALSE); |
663 | 679 |
664 msn_message_set_transaction_id(msg, ++swboard->trId); | 680 buf = g_strdup_printf("MSG %d %c %d\r\n", ++swboard->trId, |
665 buf = msn_message_to_string(msg, &len); | 681 msn_message_get_flag(msg), (int)msg->size); |
666 | 682 |
667 g_return_val_if_fail(buf != NULL, FALSE); | 683 len = strlen(buf); |
668 | 684 |
669 if (swboard->servconn->txqueue != NULL || !swboard->in_use) { | 685 payload = msn_message_gen_payload(msg, &payload_len); |
686 | |
687 if (payload != NULL) | |
688 { | |
689 buf = g_realloc(buf, len + payload_len + 1); | |
690 memcpy(buf + len, payload, payload_len); | |
691 len += payload_len; | |
692 buf[len] = 0; | |
693 } | |
694 | |
695 if (swboard->servconn->txqueue != NULL || !swboard->in_use) | |
696 { | |
670 gaim_debug(GAIM_DEBUG_INFO, "msn", "Appending message to queue.\n"); | 697 gaim_debug(GAIM_DEBUG_INFO, "msn", "Appending message to queue.\n"); |
671 | 698 |
672 swboard->servconn->txqueue = | 699 swboard->servconn->txqueue = |
673 g_slist_append(swboard->servconn->txqueue, buf); | 700 g_slist_append(swboard->servconn->txqueue, buf); |
674 | 701 |