changeset 220:1ebef23bbccb

- made parrot buffers lists so that delayed echo back message can be properly blocked. - reduced the frequency of scanning lists.
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Sun, 31 Aug 2008 15:01:02 +0900
parents 739ed7a4426c
children b5fa0c295ff5
files pidgin-twitter.c
diffstat 1 files changed, 106 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin-twitter.c	Fri Aug 29 01:11:16 2008 +0900
+++ b/pidgin-twitter.c	Sun Aug 31 15:01:02 2008 +0900
@@ -32,8 +32,8 @@
 static GHashTable *conv_hash = NULL;
 static GList *statuseslist = NULL;
 static GList *postedlist = NULL;
-static gchar *wassr_post = NULL;
-static gchar *identica_post = NULL;
+static GList *wassr_parrot_list = NULL;
+static GList *identica_parrot_list = NULL;
 #ifdef _WIN32
 static gboolean blink_state = FALSE;
 static gboolean blink_modified = FALSE;
@@ -453,11 +453,15 @@
 static gboolean
 is_posted_message(status_t *status, guint lastid)
 {
-    GList *pp;
+    GList *pp = g_list_first(postedlist);
     gboolean rv = FALSE;
 
-    for(pp = postedlist; pp; pp=pp->next) {
+    while(pp) {
+        GList *next;
         status_t *posted = (status_t *)pp->data;
+
+        next = g_list_next(pp);
+
         if(posted->id == status->id) {
             rv = TRUE;
         }
@@ -465,12 +469,12 @@
         if(posted->id <= lastid) {
             free_status(posted);
             g_free(pp->data);
-            pp->data = NULL;
+            postedlist = g_list_delete_link(postedlist, pp);
         }
+
+        pp = next;
     }
 
-    postedlist = g_list_remove_all(postedlist, NULL);
-
     return rv;
 }
 
@@ -530,9 +534,13 @@
      xmlCleanupParser();
 
      /* process statuseslist */
-     for(stp = statuseslist; stp; stp=stp->next) {
+     stp = g_list_first(statuseslist);
+     while(stp) {
+         GList *next;
          status_t *st = (status_t *)stp->data;
 
+         next = g_list_next(stp);
+
          if(st->id > lastid && !is_posted_message(st, lastid)) {
              gchar *msg = NULL;
              gchar *sender = NULL;
@@ -561,10 +569,10 @@
 
          free_status(st);
          g_free(stp->data);
-         stp->data = NULL;
+         statuseslist = g_list_delete_link(statuseslist, stp);
+
+         stp = next;
      }
-
-     statuseslist = g_list_remove_all(statuseslist, NULL);
 }
 
 /* status fetching function. it will be called periodically. */
@@ -613,9 +621,9 @@
     return TRUE;
 }
 
-/***************************/
-/* API base post functions */
-/***************************/
+/****************************/
+/* API based post functions */
+/****************************/
 static void
 post_status_with_api_cb(PurpleUtilFetchUrlData *url_data, gpointer user_data,
                         const gchar *url_text, size_t len,
@@ -829,12 +837,14 @@
 
         if(wassr_ac) {
             /* store sending message to address parrot problem */
-            g_utf8_strncpy(wassr_post, plain, WASSR_POST_LEN);
+            wassr_parrot_list =
+                g_list_prepend(wassr_parrot_list, g_strdup(plain));
             twitter_debug("wassr parrot pushed:%s\n", plain);
         }
         else if(identica_ac) {
             /* store sending message to address parrot problem */
-            g_utf8_strncpy(identica_post, plain, IDENTICA_POST_LEN);
+            identica_parrot_list =
+                g_list_prepend(identica_parrot_list, g_strdup(plain));
             twitter_debug("identica parrot pushed:%s\n", plain);
         }
 
@@ -1248,11 +1258,14 @@
         mark_list = data->request_list;
 
     /* remove the marks in its GtkTextBuffers */
-    for(current = g_list_first(mark_list); current;
-        current = g_list_next(current)) {
+    current = g_list_first(mark_list);
+    while(current) {
         GtkTextMark *current_mark = current->data;
-        GtkTextBuffer *current_text_buffer = gtk_text_mark_get_buffer(
-            current_mark);
+        GtkTextBuffer *current_text_buffer =
+            gtk_text_mark_get_buffer(current_mark);
+        GList *next;
+
+        next = g_list_next(current);
 
         if(!current_text_buffer)
             continue;
@@ -1263,15 +1276,18 @@
                 gtk_text_buffer_delete_mark(current_text_buffer,
                                             current_mark);
                 current->data = NULL;
+                mark_list = g_list_delete_link(mark_list, current);
             }
         }
         else {
             gtk_text_buffer_delete_mark(current_text_buffer, current_mark);
             current->data = NULL;
+            mark_list = g_list_delete_link(mark_list, current);
         }
-    } /* end of for */
-
-    mark_list = g_list_remove_all(mark_list, NULL);
+
+        current = next;
+    }
+
     data->request_list = mark_list;
 }
 
@@ -1663,12 +1679,25 @@
             g_free(*buffer); *buffer = NULL;
         }
         /* discard parrot message */
-        else if(wassr_post &&
-                strlen(wassr_post) &&
-                strstr(stripped, wassr_post)) {
-            twitter_debug("parrot clearing: buf = %s post = %s\n", *buffer, wassr_post);
-            g_free(*sender); *sender = NULL;
-            g_free(*buffer); *buffer = NULL;
+        else {
+            GList *current = g_list_first(wassr_parrot_list);
+            while(current) {
+                GList *next = g_list_next(current);
+
+                if(strstr(stripped, current->data)) {
+                    twitter_debug("parrot clearing: buf = %s post = %s\n",
+                                  *buffer, (char *)current->data);
+                    g_free(*sender); *sender = NULL;
+                    g_free(*buffer); *buffer = NULL;
+                    g_free(current->data);
+                    current->data = NULL;
+                    wassr_parrot_list =
+                        g_list_delete_link(wassr_parrot_list, current);
+                    break;
+                }
+
+                current = next;
+            }
         }
         g_free(stripped);
     }
@@ -1676,13 +1705,23 @@
     if(service == identica_service) {
         /* discard parrot message */
         gchar *stripped = strip_html_markup(*buffer);
-        if(identica_post &&
-           strlen(identica_post) &&
-           strstr(stripped, identica_post)) {
-            twitter_debug("identica parrot clearing: buf = %s post = %s\n",
-                          *buffer, identica_post);
-            g_free(*sender); *sender = NULL;
-            g_free(*buffer); *buffer = NULL;
+        GList *current = g_list_first(identica_parrot_list);
+        while(current) {
+            GList *next = g_list_next(current);
+
+            if(strstr(stripped, current->data)) {
+                twitter_debug("identica parrot clearing: buf = %s post = %s\n",
+                              *buffer, (char *)current->data);
+                g_free(*sender); *sender = NULL;
+                g_free(*buffer); *buffer = NULL;
+                g_free(current->data);
+                current->data = NULL;
+                identica_parrot_list =
+                    g_list_delete_link(identica_parrot_list, current);
+                break;
+            }
+
+            current = next;
         }
         g_free(stripped);
     }
@@ -2327,7 +2366,7 @@
         g_hash_table_insert(hash, g_strdup(user_name), data);
     }
 
-    data->request_list = g_list_append(data->request_list, mark);
+    data->request_list = g_list_prepend(data->request_list, mark);
 }
 
 static gboolean
@@ -2577,12 +2616,6 @@
         attach_to_window();
     }
 
-    /* allocate wassr_post */
-    wassr_post = g_new0(gchar, 4 * WASSR_POST_LEN + 1);
-
-    /* allocate identica_post */
-    identica_post = g_new0(gchar, 4 * IDENTICA_POST_LEN + 1);
-
     return TRUE;
 }
 
@@ -2615,6 +2648,7 @@
 unload_plugin(PurplePlugin *plugin)
 {
     int i;
+    GList *current;
 
     twitter_debug("called\n");
 
@@ -2664,13 +2698,35 @@
     /* detach from twitter window */
     detach_from_window();
 
-    /* free wassr_post */
-    g_free(wassr_post);
-    wassr_post = NULL;
-
-    /* free identica_post */
-    g_free(identica_post);
-    identica_post = NULL;
+    /* free wassr_parrot_list */
+    current = g_list_first(wassr_parrot_list);
+    while(current) {
+        GList *next;
+
+        next = g_list_next(current);
+        g_free(current->data);
+        wassr_parrot_list =
+            g_list_delete_link(wassr_parrot_list, current);
+
+        current = next;
+    }
+    g_list_free(wassr_parrot_list);
+    wassr_parrot_list = NULL;
+
+    /* free identica_parot_list */
+    current = g_list_first(identica_parrot_list);
+    while(current) {
+        GList *next;
+
+        next = g_list_next(current);
+        g_free(current->data);
+        identica_parrot_list =
+            g_list_delete_link(identica_parrot_list, current);
+
+        current = next;
+    }
+    g_list_free(identica_parrot_list);
+    identica_parrot_list = NULL;
 
     return TRUE;
 }