soc.2012.statscollector: 4332203b: Add support for plugins

sanket at sanketagarwal.com sanket at sanketagarwal.com
Mon May 14 13:27:53 EDT 2012


----------------------------------------------------------------------
Revision: 4332203bdc21ec17e5fbfbfdf6f5d0e58b490599
Parent:   30e972b5e1592eae1c327f437183594ee2be3c87
Author:   sanket at sanketagarwal.com
Date:     05/13/12 11:09:46
Branch:   im.pidgin.soc.2012.statscollector
URL: http://d.pidgin.im/viewmtn/revision/info/4332203bdc21ec17e5fbfbfdf6f5d0e58b490599

Changelog: 

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.

Changes against parent 30e972b5e1592eae1c327f437183594ee2be3c87

  patched  pidgin/plugins/statscollector.c

-------------- next part --------------
============================================================
--- pidgin/plugins/statscollector.c	74e877dcf2f5088e1d28361f14e7d80781ce20ba
+++ pidgin/plugins/statscollector.c	48cd2ea5fb7fb10bf30eba8bdb32c1050bc2d0e6
@@ -47,6 +47,15 @@ save_xml(){
 
   // 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 @@ sign_on_event(PurpleAccount *account){
 
 }
 
+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 @@ init_stats(){
    * 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,14 +210,28 @@ init_stats(){
     }
 
 
-    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);
+
+
+
   }
 
   /* Return the structure for modification */
@@ -182,12 +249,17 @@ plugin_load(PurplePlugin *plugin) {
 
   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 @@ static PurplePluginInfo info =
 	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