/soc/2012/sanket/statscollector-2.x.y: 5ba70471aa4a: Extend the ...

Sanket Agarwal sanket at soc.pidgin.im
Tue Jul 10 00:36:22 EDT 2012


Changeset: 5ba70471aa4a4da9931218c5151afbb36d7eb60a
Author:	 Sanket Agarwal <sanket at soc.pidgin.im>
Date:	 2012-05-14 10:55 +0000
Branch:	 soc.2012.statscollector
URL: http://hg.pidgin.im/soc/2012/sanket/statscollector-2.x.y/rev/5ba70471aa4a

Description:

Extend the key for accounts; use attribute style xml

Currently for account only "username" was being used. It is possible to have
same username on different IM services. So we use username-prpl_id as our
key.

Secondly it's better to use <account id=".."> and <plugin id=".."> and then
save element level information.

diffstat:

 pidgin/plugins/statscollector.c |  50 +++++++++++++++++++++++++++++-----------
 1 files changed, 36 insertions(+), 14 deletions(-)

diffs (131 lines):

diff --git a/pidgin/plugins/statscollector.c b/pidgin/plugins/statscollector.c
--- a/pidgin/plugins/statscollector.c
+++ b/pidgin/plugins/statscollector.c
@@ -52,7 +52,6 @@
 
   }
 
-  // purple_debug_info("STATS", "SAVE %s", xmlnode_to_formatted_str(nroot, NULL));
 
   g_hash_table_iter_init(&iter, stats_plugins_ht);
 
@@ -140,9 +139,25 @@
 
 }
 
+static gchar *
+get_acc_id(char *username, char *prpl_id){
+
+  /* Generates a id from username and prpl_id */
+
+  char *id = (char *)malloc(500*sizeof(char));
+
+  id[0] = '\0';
+  strcat(id, username);
+  strcat(id, "-");
+  strcat(id, prpl_id);
+
+  return id;
+
+}
+
 
 static void
-sign_on_event(PurpleAccount *account){
+acc_sign_on_event(PurpleAccount *account){
 
   /* Store information about logging on of an account. The following
    * measures should be taken:
@@ -151,28 +166,33 @@
    */
 
   const char *username, *protocol, *data;
+  char *id;
 
   xmlnode *acc, *u_node, *p_node;
   username = purple_account_get_username(account);
   protocol = purple_account_get_protocol_id(account);
 
+  id = get_acc_id(username, protocol);
+
   /* check if the account already exist in our XML file */
 
-  if(g_hash_table_lookup(stats_acc_ht, username))
+  if(g_hash_table_lookup(stats_acc_ht, id))
     purple_debug_info("STATS", "Account already exists!");
   else{
 
     acc = xmlnode_new("account");
 
-    u_node = xmlnode_new_child(acc, "username");
-    xmlnode_insert_data(u_node, username, -1);
+    /* u_node = xmlnode_new_child(acc, "username"); */
+    /* xmlnode_insert_data(u_node, username, -1); */
+
+    xmlnode_set_attrib(acc, "id", id);
 
     p_node = xmlnode_new_child(acc, "protocol");
     xmlnode_insert_data(p_node, protocol, -1);
 
     data = xmlnode_to_str(acc, NULL);
 
-    g_hash_table_insert(stats_acc_ht, (void *)username, (void *)data);
+    g_hash_table_insert(stats_acc_ht, (void *)id, (void *)data);
 
   }
 
@@ -213,8 +233,10 @@
 
     plugin_xml = xmlnode_new("plugin");
 
-    p_id = xmlnode_new_child(plugin_xml, "id");
-    xmlnode_insert_data(p_id, plugin_id, -1);
+    xmlnode_set_attrib(plugin_xml, "id", plugin_id);
+
+    /* p_id = xmlnode_new_child(plugin_xml, "id"); */
+    /* xmlnode_insert_data(p_id, plugin_id, -1); */
 
     data = xmlnode_to_str(plugin_xml, NULL);
 
@@ -241,7 +263,7 @@
   /* GHashTableIter *iter; */
   GList *loaded_plugins;
   xmlnode *stats_acc_xml, *stats_plugins_xml;
-  xmlnode *start, *u_node;
+  xmlnode *start, *id_node;
 
   /* Load the xml */
   xmlnode *root = purple_util_read_xml_from_file("stats.xml",
@@ -275,9 +297,9 @@
 
     for(;start;start = xmlnode_get_next_twin(start)){
 
-      u_node = xmlnode_get_child(start, "username");
+      id_node = xmlnode_get_attrib(start, "id");
 
-      g_hash_table_insert(stats_acc_ht, (char *)xmlnode_get_data(u_node),
+      g_hash_table_insert(stats_acc_ht, (char *)id_node,
           (char *)xmlnode_to_formatted_str(start, NULL));
 
     }
@@ -295,9 +317,9 @@
 
     for(;start;start = xmlnode_get_next_twin(start)){
 
-      u_node = xmlnode_get_child(start, "id");
+      id_node = xmlnode_get_attrib(start, "id");
 
-      g_hash_table_insert(stats_plugins_ht, (char *)xmlnode_get_data(u_node),
+      g_hash_table_insert(stats_plugins_ht, (char *)(id_node),
           (char *)xmlnode_to_formatted_str(start, NULL));
 
     }
@@ -334,7 +356,7 @@
   /* Register the account signals for sign-on */
 
   purple_signal_connect(purple_accounts_get_handle(), "account-signed-on",
-                      plugin, PURPLE_CALLBACK(sign_on_event), NULL);
+                      plugin, PURPLE_CALLBACK(acc_sign_on_event), NULL);
 
    /* Register the plugin signals for sign-on */
 



More information about the Commits mailing list