Mercurial > pidgin-twitter
comparison util.c @ 347:33d2551727ba
embed "in reply to foo" link to each reply message
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Mon, 14 Dec 2009 20:14:31 +0900 |
parents | dbebabe99035 |
children | 059e962ee26a |
comparison
equal
deleted
inserted
replaced
346:dbebabe99035 | 347:33d2551727ba |
---|---|
527 | 527 |
528 gchar * | 528 gchar * |
529 twitter_rip_link_string(gchar **str) | 529 twitter_rip_link_string(gchar **str) |
530 { | 530 { |
531 GMatchInfo *match_info = NULL; | 531 GMatchInfo *match_info = NULL; |
532 gchar *boddy0 = NULL, *boddy = NULL; | 532 gchar *body0 = NULL, *body = NULL; |
533 gchar *newstr = NULL, *linkstr = NULL; | 533 gchar *newstr = NULL, *linkstr = NULL; |
534 gchar *match = NULL; | 534 gchar *user = NULL; |
535 gchar *idstr = NULL, *user = NULL; | |
536 | 535 |
537 twitter_debug("called\n"); | 536 twitter_debug("called\n"); |
538 | 537 |
539 /* buffer without ptmsgid=123 */ | 538 /* buffer without pttag= */ |
540 boddy0 = g_regex_replace(regp[SENDER], *str, -1, 0, "", 0, NULL); | 539 body0 = g_regex_replace(regp[SENDER], *str, -1, 0, "", 0, NULL); |
541 boddy = g_regex_replace(regp[MESSAGE_ID], boddy0, -1, 0, "", 0, NULL); | 540 body = g_regex_replace(regp[PTTAG_TWITTER], body0, -1, 0, "", 0, NULL); |
542 g_free(boddy0); | 541 g_free(body0); |
543 boddy0 = NULL; | 542 body0 = NULL; |
544 twitter_debug("boddy = %s\n", boddy); | 543 twitter_debug("body = %s\n", body); |
545 | 544 |
546 boddy0 = g_uri_escape_string(boddy, " !$()*,;:@/?#[]", TRUE); | 545 body0 = g_uri_escape_string(body, " !$()*,;:@/?#[]", TRUE); |
547 g_free(boddy); | 546 g_free(body); |
548 boddy = boddy0; | 547 body = body0; |
549 | 548 |
550 /* sender */ | 549 /* sender */ |
551 g_regex_match(regp[SENDER], *str, 0, &match_info); | 550 g_regex_match(regp[SENDER], *str, 0, &match_info); |
552 if(g_match_info_matches(match_info)) { | 551 if(g_match_info_matches(match_info)) { |
553 user = g_match_info_fetch(match_info, 2); | 552 user = g_match_info_fetch(match_info, 2); |
555 g_match_info_free(match_info); | 554 g_match_info_free(match_info); |
556 match_info = NULL; | 555 match_info = NULL; |
557 } | 556 } |
558 | 557 |
559 /* link string */ | 558 /* link string */ |
560 g_regex_match(regp[MESSAGE_ID], *str, 0, &match_info); | 559 g_regex_match(regp[PTTAG_TWITTER], *str, 0, &match_info); |
561 if(match_info) { | 560 if(match_info) { |
562 match = g_match_info_fetch(match_info, 1); | 561 gchar *msg_id_str = NULL; |
563 idstr = match ? match : "0"; | 562 gchar *in_reply_to_status_id_str = NULL; |
564 linkstr = g_strdup_printf(LINK_FORMAT_TWITTER, | 563 long long unsigned int in_reply_to_status_id = 0; |
565 idstr, user, /* Reply */ | 564 |
566 idstr, /* Favorite */ | 565 msg_id_str = g_match_info_fetch(match_info, 1); |
567 idstr, /* Retweet */ | 566 in_reply_to_status_id_str = g_match_info_fetch(match_info, 2); |
568 idstr, user, boddy); /* Quotetweet */ | 567 in_reply_to_status_id = strtoull(in_reply_to_status_id_str, NULL, 10); |
568 g_free(in_reply_to_status_id_str); | |
569 in_reply_to_status_id_str = NULL; | |
570 | |
571 if(in_reply_to_status_id) { | |
572 gchar *in_reply_to_screen_name; | |
573 | |
574 in_reply_to_screen_name = g_match_info_fetch(match_info, 3); | |
575 linkstr = g_strdup_printf(IN_REPLY_TO_FORMAT_TWITTER LINK_FORMAT_TWITTER, | |
576 in_reply_to_screen_name, | |
577 in_reply_to_status_id, | |
578 in_reply_to_screen_name, | |
579 msg_id_str, user, /* Reply */ | |
580 msg_id_str, /* Favorite */ | |
581 msg_id_str, /* Retweet */ | |
582 msg_id_str, user, body); /* Quotetweet */ | |
583 | |
584 g_free(in_reply_to_screen_name); | |
585 in_reply_to_screen_name = NULL; | |
586 } | |
587 else { | |
588 linkstr = g_strdup_printf(LINK_FORMAT_TWITTER, | |
589 msg_id_str, user, /* Reply */ | |
590 msg_id_str, /* Favorite */ | |
591 msg_id_str, /* Retweet */ | |
592 msg_id_str, user, body); /* Quotetweet */ | |
593 } | |
569 | 594 |
570 twitter_debug("linkstr = %s\n", linkstr); | 595 twitter_debug("linkstr = %s\n", linkstr); |
571 | 596 |
572 newstr = g_regex_replace(regp[MESSAGE_ID], *str, -1, 0, | 597 newstr = g_regex_replace(regp[PTTAG_TWITTER], *str, -1, 0, "", 0, NULL); |
573 "", | |
574 0, NULL); | |
575 | 598 |
576 twitter_debug("newstr = %s\n", newstr); | 599 twitter_debug("newstr = %s\n", newstr); |
577 | 600 |
578 g_free(*str); | 601 g_free(*str); |
579 *str = newstr; | 602 *str = newstr; |
580 | 603 |
581 g_free(match); | 604 g_free(msg_id_str); |
582 match = NULL; | 605 msg_id_str = NULL; |
583 | 606 |
584 g_match_info_free(match_info); | 607 g_match_info_free(match_info); |
585 match_info = NULL; | 608 match_info = NULL; |
586 } | 609 } |
587 | 610 |
588 g_free(user); | 611 g_free(user); |
589 g_free(boddy); | 612 g_free(body); |
590 | 613 |
591 return linkstr; | 614 return linkstr; |
592 } | 615 } |