comparison util.c @ 331:b4c846870b3c

improved handling of RT string
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Tue, 13 Oct 2009 02:45:03 +0900
parents cc41ee1f5d3a
children 227852ee649c
comparison
equal deleted inserted replaced
330:cc41ee1f5d3a 331:b4c846870b3c
483 idstr = g_hash_table_lookup(params, "id"); 483 idstr = g_hash_table_lookup(params, "id");
484 fav_with_api(strtoull(idstr, NULL, 10)); 484 fav_with_api(strtoull(idstr, NULL, 10));
485 return TRUE; 485 return TRUE;
486 } 486 }
487 else if(strstr(cmd, "retweet-twitter")) { 487 else if(strstr(cmd, "retweet-twitter")) {
488 gchar *msg0;
488 sender = g_hash_table_lookup(params, "user"); 489 sender = g_hash_table_lookup(params, "user");
489 idstr = g_hash_table_lookup(params, "id"); 490 idstr = g_hash_table_lookup(params, "id");
490 msg = g_hash_table_lookup(params, "msg"); 491 msg0 = g_hash_table_lookup(params, "msg");
492 msg = g_uri_unescape_string(msg0, NULL);
493
491 if(idstr) 494 if(idstr)
492 msgid = strtoull(idstr, NULL, 10); 495 msgid = strtoull(idstr, NULL, 10);
493 496
494 /* find conv */ 497 /* find conv */
495 conv = purple_find_conversation_with_account( 498 conv = purple_find_conversation_with_account(
499 gtkconv = PIDGIN_CONVERSATION(conv); 502 gtkconv = PIDGIN_CONVERSATION(conv);
500 503
501 twitter_debug("sender = %s, id = %llu\n", sender, (unsigned long long)msgid); 504 twitter_debug("sender = %s, id = %llu\n", sender, (unsigned long long)msgid);
502 505
503 recipient = g_strdup_printf("RT @%s: %s", sender, msg); 506 recipient = g_strdup_printf("RT @%s: %s", sender, msg);
507 g_free(msg);
504 gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer, 508 gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer,
505 recipient, -1); 509 recipient, -1);
506 510
507 GtkTextIter iter; 511 GtkTextIter iter;
508 gtk_text_buffer_get_start_iter(gtkconv->entry_buffer, &iter); 512 gtk_text_buffer_get_start_iter(gtkconv->entry_buffer, &iter);
514 return TRUE; 518 return TRUE;
515 } 519 }
516 return FALSE; 520 return FALSE;
517 } 521 }
518 522
519 void 523 gchar *
520 twitter_add_links(gchar **str) 524 twitter_make_link_string(gchar **str)
521 { 525 {
522 GMatchInfo *match_info = NULL; 526 GMatchInfo *match_info = NULL;
523 gchar *tmpstr0 = NULL, *tmpstr = NULL; 527 gchar *boddy0 = NULL, *boddy = NULL;
524 gchar *newstr = NULL, *match = NULL; 528 gchar *newstr = NULL, *match = NULL;
525 gchar *linkstr = NULL; 529 gchar *linkstr = NULL;
526 gchar *user = NULL; 530 gchar *user = NULL;
527 531
528 twitter_debug("called\n"); 532 twitter_debug("called\n");
529 533
530 /* buffer without ptmsgid=123 */ 534 /* buffer without ptmsgid=123 */
531 tmpstr0 = g_regex_replace(regp[SENDER], *str, -1, 0, "", 0, NULL); 535 boddy0 = g_regex_replace(regp[SENDER], *str, -1, 0, "", 0, NULL);
532 tmpstr = g_regex_replace(regp[MESSAGE_ID], tmpstr0, -1, 0, "", 0, NULL); 536 boddy = g_regex_replace(regp[MESSAGE_ID], boddy0, -1, 0, "", 0, NULL);
533 g_free(tmpstr0); 537 g_free(boddy0);
534 tmpstr0 = NULL; 538 boddy0 = NULL;
535 twitter_debug("tmpstr = %s\n", tmpstr); 539 twitter_debug("boddy = %s\n", boddy);
540
541 boddy0 = g_uri_escape_string(boddy, " !$()*,;:@/?#[]", TRUE);
542 g_free(boddy);
543 boddy = boddy0;
536 544
537 /* sender */ 545 /* sender */
538 g_regex_match(regp[SENDER], *str, 0, &match_info); 546 g_regex_match(regp[SENDER], *str, 0, &match_info);
539 if(g_match_info_matches(match_info)) { 547 if(g_match_info_matches(match_info)) {
540 user = g_match_info_fetch(match_info, 2); 548 user = g_match_info_fetch(match_info, 2);
548 if(match_info) { 556 if(match_info) {
549 match = g_match_info_fetch(match_info, 1); 557 match = g_match_info_fetch(match_info, 1);
550 linkstr = g_strdup_printf(LINK_FORMAT_TWITTER, 558 linkstr = g_strdup_printf(LINK_FORMAT_TWITTER,
551 match, user, /* Reply */ 559 match, user, /* Reply */
552 match, /* Favorite */ 560 match, /* Favorite */
553 match, user, tmpstr); /* Retweet */ 561 match, user, boddy); /* Retweet */
554 562
555 twitter_debug("linkstr = %s\n", linkstr); 563 twitter_debug("linkstr = %s\n", linkstr);
556 564
557 newstr = g_regex_replace(regp[MESSAGE_ID], *str, -1, 0, 565 newstr = g_regex_replace(regp[MESSAGE_ID], *str, -1, 0,
558 linkstr, 566 "",
559 0, NULL); 567 0, NULL);
560 568
561 twitter_debug("newstr = %s\n", newstr); 569 twitter_debug("newstr = %s\n", newstr);
562 570
563 g_free(*str); 571 g_free(*str);
564 *str = newstr; 572 *str = newstr;
565 573
566 g_free(linkstr);
567
568 g_free(match); 574 g_free(match);
569 match = NULL; 575 match = NULL;
570 576
571 g_match_info_free(match_info); 577 g_match_info_free(match_info);
572 match_info = NULL; 578 match_info = NULL;
573 } 579 }
574 580
575 g_free(user); 581 g_free(user);
576 g_free(tmpstr); 582 g_free(boddy);
577 } 583
584 return linkstr;
585 }