diff 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
line wrap: on
line diff
--- a/util.c	Mon Oct 12 21:51:13 2009 +0900
+++ b/util.c	Tue Oct 13 02:45:03 2009 +0900
@@ -485,9 +485,12 @@
         return TRUE;
     }
     else if(strstr(cmd, "retweet-twitter")) {
+        gchar *msg0;
         sender = g_hash_table_lookup(params, "user");
         idstr = g_hash_table_lookup(params, "id");
-        msg = g_hash_table_lookup(params, "msg");
+        msg0 = g_hash_table_lookup(params, "msg");
+        msg = g_uri_unescape_string(msg0, NULL);
+
         if(idstr)
             msgid = strtoull(idstr, NULL, 10);
 
@@ -501,6 +504,7 @@
         twitter_debug("sender = %s, id = %llu\n", sender, (unsigned long long)msgid);
 
         recipient = g_strdup_printf("RT @%s: %s", sender, msg);
+        g_free(msg);
         gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer,
                                          recipient, -1);
 
@@ -516,11 +520,11 @@
     return FALSE;
 }
 
-void
-twitter_add_links(gchar **str)
+gchar *
+twitter_make_link_string(gchar **str)
 {
     GMatchInfo *match_info = NULL;
-    gchar *tmpstr0 = NULL, *tmpstr = NULL;
+    gchar *boddy0 = NULL, *boddy = NULL;
     gchar *newstr = NULL, *match = NULL;
     gchar *linkstr = NULL;
     gchar *user = NULL;
@@ -528,11 +532,15 @@
     twitter_debug("called\n");
 
     /* buffer without ptmsgid=123 */
-    tmpstr0 = g_regex_replace(regp[SENDER], *str, -1, 0, "", 0, NULL);
-    tmpstr = g_regex_replace(regp[MESSAGE_ID], tmpstr0, -1, 0, "", 0, NULL);
-    g_free(tmpstr0);
-    tmpstr0 = NULL;
-    twitter_debug("tmpstr = %s\n", tmpstr);
+    boddy0 = g_regex_replace(regp[SENDER], *str, -1, 0, "", 0, NULL);
+    boddy = g_regex_replace(regp[MESSAGE_ID], boddy0, -1, 0, "", 0, NULL);
+    g_free(boddy0);
+    boddy0 = NULL;
+    twitter_debug("boddy = %s\n", boddy);
+
+    boddy0 = g_uri_escape_string(boddy, " !$()*,;:@/?#[]", TRUE);
+    g_free(boddy);
+    boddy = boddy0;
 
     /* sender */
     g_regex_match(regp[SENDER], *str, 0, &match_info);
@@ -550,12 +558,12 @@
         linkstr = g_strdup_printf(LINK_FORMAT_TWITTER,
                                  match, user,          /* Reply */
                                  match,                /* Favorite */
-                                 match, user, tmpstr); /* Retweet */
+                                 match, user, boddy);  /* Retweet */
 
         twitter_debug("linkstr = %s\n", linkstr);
 
         newstr = g_regex_replace(regp[MESSAGE_ID], *str, -1, 0,
-                                 linkstr,
+                                 "",
                                  0, NULL);
 
         twitter_debug("newstr = %s\n", newstr);
@@ -563,8 +571,6 @@
         g_free(*str);
         *str = newstr;
 
-        g_free(linkstr);
-
         g_free(match);
         match = NULL;
 
@@ -573,5 +579,7 @@
     }
 
     g_free(user);
-    g_free(tmpstr);
+    g_free(boddy);
+
+    return linkstr;
 }