/soc/2012/sanket/statscollector-2.x.y: d5fb331f50cc: Load Accoun...

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


Changeset: d5fb331f50ccbf5ca66913a9d70761bbcd723532
Author:	 Sanket Agarwal <sanket at soc.pidgin.im>
Date:	 2012-05-12 18:20 +0000
Branch:	 soc.2012.statscollector
URL: http://hg.pidgin.im/soc/2012/sanket/statscollector-2.x.y/rev/d5fb331f50cc

Description:

Load Account info in a hash-table

It is required to store information initially in a Hash table to
facilitate further updates to stats. Though this seems initally
harsh as too much coding, in the long run it's a better practice.

Once the scheme for accounts is established we can move to more
stats such as plugins or CPU info etc.

diffstat:

 pidgin/plugins/statscollector.c |  51 ++++++++++++++++++++++++++++++++++++++--
 1 files changed, 48 insertions(+), 3 deletions(-)

diffs (90 lines):

diff --git a/pidgin/plugins/statscollector.c b/pidgin/plugins/statscollector.c
--- a/pidgin/plugins/statscollector.c
+++ b/pidgin/plugins/statscollector.c
@@ -15,6 +15,7 @@
 #define STATS_MINOR_VERSION 0
 
 xmlnode *root_stats;
+GHashTable *stats_acc_ht, *stats_plugins_ht;
 
 static void
 sign_on_event(PurpleAccount *account){
@@ -25,7 +26,17 @@
    * 1.1 If no, then add the account to the list of accounts used
    */
 
-  xmlnode *fetch;
+  char *username, *protocol;
+
+  username = purple_account_get_username(account);
+  protocol = purple_account_get_protocol_id(account);
+
+  /* check if the account already exist in our XML file */
+
+  if(g_hash_table_lookup(stats_acc_ht, username))
+    purple_debug_info("STATS", "Account already exists!");
+  else g_hash_table_insert(stats_acc_ht, username, protocol);
+
 
   purple_debug_info("XX-STATS",
       "Logged into a account %s with protocol %s",
@@ -45,6 +56,8 @@
 
   /* Load the xml */
   char *data;
+  xmlnode *stats_acc_xml, *stats_plugins_xml;
+  xmlnode *start, *u_node, *p_node;
   xmlnode *root = purple_util_read_xml_from_file("stats.xml",
       "stats-collection");
 
@@ -55,8 +68,8 @@
     /* Create an empty structure for the XML */
     root = xmlnode_new("stats");
 
+    xmlnode_new_child(root, "cpuinfo");
     xmlnode_new_child(root, "accounts");
-    xmlnode_new_child(root, "cpuinfo");
     xmlnode_new_child(root, "plugins");
 
     /* Write the structure back (init) */
@@ -65,7 +78,39 @@
 
   }
 
-  /* Check if the XML format version is compatible with current XML */
+  else{
+
+    /* Populate the hash tables with account and plugin information */
+
+    stats_acc_ht = g_hash_table_new(g_str_hash, g_str_equal);
+    stats_plugins_ht = g_hash_table_new(g_str_hash, g_str_equal);
+
+    stats_acc_xml = xmlnode_get_child(root, "accounts");
+    stats_plugins_xml = xmlnode_get_child(root, "plugins");
+
+    purple_debug_info("STATS", "Accounts: %s", xmlnode_to_formatted_str(stats_acc_xml, NULL));
+
+    start = xmlnode_get_child(stats_acc_xml, "account");
+
+    for(;start;start = xmlnode_get_next_twin(start)){
+
+      u_node = xmlnode_get_child(start, "username");
+      p_node = xmlnode_get_child(start, "protocol");
+
+      g_hash_table_insert(stats_acc_ht, (char *)xmlnode_get_data(u_node),
+          (char *)xmlnode_get_data(p_node));
+
+    }
+
+    start = xmlnode_get_child(stats_acc_xml, "plugins");
+
+    for(;start;start = xmlnode_get_next_twin(start)){
+
+      /* Logic to be still filled up */
+
+     }
+
+  }
 
   /* Return the structure for modification */
   return root;



More information about the Commits mailing list