/soc/2012/sanket/statscollector-2.x.y: 30274be76c14: Add support...

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


Changeset: 30274be76c1498d575406e7ac6a7b8e85f38074d
Author:	 Sanket Agarwal <sanket at soc.pidgin.im>
Date:	 2012-05-13 15:09 +0000
Branch:	 soc.2012.statscollector
URL: http://hg.pidgin.im/soc/2012/sanket/statscollector-2.x.y/rev/30274be76c14

Description:

Add support for plugins

Now the plugins which are loaded unloaded can be recorded in the stats file.
This way we can detect various plugin usages as well. There are a host of TODO's
as of now.
* Handle case of corrupt XML files
* Some of the plugins reported are not required in the report, namely
"core-ssl", "prpl-*" etc. Though I have some hacks for prpl-* BUT we need
a better distinction for plugins to be recorded.

diffstat:

 pidgin/plugins/statscollector.c |  86 +++++++++++++++++++++++++++++++++++++---
 1 files changed, 79 insertions(+), 7 deletions(-)

diffs (144 lines):

diff --git a/pidgin/plugins/statscollector.c b/pidgin/plugins/statscollector.c
--- a/pidgin/plugins/statscollector.c
+++ b/pidgin/plugins/statscollector.c
@@ -47,6 +47,15 @@
 
   // purple_debug_info("STATS", "SAVE %s", xmlnode_to_formatted_str(nroot, NULL));
 
+  g_hash_table_iter_init(&iter, stats_plugins_ht);
+
+  while(g_hash_table_iter_next(&iter, &key, &value)){
+
+    node = xmlnode_from_str(value, -1);
+    xmlnode_insert_child(nplugins, node);
+
+  }
+
   data = xmlnode_to_formatted_str(nroot, NULL);
   purple_util_write_data_to_file("stats.xml", data, -1);
 
@@ -91,6 +100,48 @@
 
 }
 
+static void
+plugin_load_event(PurplePlugin *plugin){
+
+  /* Store information about logging on of an account. The following
+   * measures should be taken:
+   * 1. Check if we already have such an account in our database
+   * 1.1 If no, then add the account to the list of accounts used
+   */
+
+  char *plugin_id, *data;
+  xmlnode *plugin_xml, *p_id;
+
+  plugin_id = purple_plugin_get_id(plugin);
+
+  /* check if the account already exist in our XML file */
+
+  if(g_hash_table_lookup(stats_plugins_ht, plugin_id))
+    purple_debug_info("STATS", "Plugin %s already exists!", plugin_id);
+
+  else if(g_str_has_prefix(plugin_id, "prpl"))
+    /* We don't need no prpl plugins */
+    purple_debug_info("STATS", "Plugin %s is a prpl plugin\n", plugin_id);
+
+  else{
+
+    plugin_xml = xmlnode_new("plugin");
+
+    p_id = xmlnode_new_child(plugin_xml, "id");
+    xmlnode_insert_data(p_id, plugin_id, -1);
+
+    data = xmlnode_to_str(plugin_xml, NULL);
+
+    /* purple_debug_info("STATS", "PLGN %s %s\\n", */
+    /*     plugin_id, data); */
+
+    g_hash_table_insert(stats_plugins_ht, plugin_id, data);
+
+  }
+
+  save_xml();
+
+}
 static xmlnode *
 init_stats(){
 
@@ -100,12 +151,14 @@
    * 2. In case plugin versions change the XML format, handle that
    */
 
-  /* Load the xml */
   GHashTableIter *iter;
+  GList *loaded_plugins;
   char *key, *value;
   char *data;
   xmlnode *stats_acc_xml, *stats_plugins_xml;
   xmlnode *start, *u_node, *p_node;
+
+  /* Load the xml */
   xmlnode *root = purple_util_read_xml_from_file("stats.xml",
       "stats-collection");
 
@@ -157,13 +210,27 @@
     }
 
 
-    start = xmlnode_get_child(stats_acc_xml, "plugins");
+    start = xmlnode_get_child(stats_acc_xml, "plugin");
 
     for(;start;start = xmlnode_get_next_twin(start)){
 
-      /* Logic to be still filled up */
+      u_node = xmlnode_get_child(start, "id");
 
-     }
+      g_hash_table_insert(stats_plugins_ht, (char *)xmlnode_get_data(u_node),
+          (char *)xmlnode_to_formatted_str(start, NULL));
+
+    }
+
+    /* It's a good idea to get all loaded plugins and insert them
+     * since, we might miss a few if users are already using them
+     * and then enable our plugin
+     */
+
+    loaded_plugins = purple_plugins_get_loaded();
+
+    g_list_foreach(loaded_plugins, plugin_load_event, NULL);
+
+
 
   }
 
@@ -182,12 +249,17 @@
 
   root_stats = init_stats();
 
-  /* Register the account signals for sign-on/off */
+  /* Register the account signals for sign-on */
 
   purple_signal_connect(purple_accounts_get_handle(), "account-signed-on",
                       plugin, PURPLE_CALLBACK(sign_on_event), NULL);
 
-  return TRUE;
+   /* Register the plugin signals for sign-on */
+
+  purple_signal_connect(purple_plugins_get_handle(), "plugin-load",
+                      plugin, PURPLE_CALLBACK(plugin_load_event), NULL);
+
+ return TRUE;
 }
 
 static PurplePluginInfo info =
@@ -200,7 +272,7 @@
 	0,                                              /**< flags */
 	NULL,                                           /**< dependencies */
 	PURPLE_PRIORITY_DEFAULT,                        /**< priority */
-	"statscollector",                               /**< id */
+	"gtk-statscollector",                               /**< id */
 	N_("Statistics collection"),                    /**< name */
 	DISPLAY_VERSION,                                /**< version */
 	N_("Automated collection of statistics for "



More information about the Commits mailing list