soc.2012.statscollector: 018cfa65: Add ``user_splits'' information for acco...

sanket at soc.pidgin.im sanket at soc.pidgin.im
Thu Jun 7 09:17:45 EDT 2012


----------------------------------------------------------------------
Revision: 018cfa65160d7d678c4d9a3f655558585d981de6
Parent:   40203f3815406470eeb9cf929110145988887f66
Author:   sanket at soc.pidgin.im
Date:     06/06/12 15:42:18
Branch:   im.pidgin.soc.2012.statscollector
URL: http://d.pidgin.im/viewmtn/revision/info/018cfa65160d7d678c4d9a3f655558585d981de6

Changelog: 

Add ``user_splits'' information for accounts

A typical jabber account can split to username at domain/resource and IRC account
to username at domain but to do such splits in general (for example prpl-yahoo does
not have any splits) we need to use user_splits which tells us which parts mean
what. This way we can use non-sensitive data to be sent along-with other stats
and classify the accounts further on basis of Facebook or Gtalk.

There's a additional bit of information in the form of ``connect-server'' which
is valid only for XMPP accounts and I have added that too as domains are not
authoritative in classifying the XMPP/Jabber service provider for the domain.

Finally, there are some warning-fixes but I felt too lazy to get them in
another patch, so they are attached inline.

Changes against parent 40203f3815406470eeb9cf929110145988887f66

  patched  libpurple/plugins/statscollector.c

-------------- next part --------------
============================================================
--- libpurple/plugins/statscollector.c	5d94dc5ae6a12d2cbbb35a766e96c8d4e1c04303
+++ libpurple/plugins/statscollector.c	c0e83fa342cbcbd86b4343623b85fbe1374a0b24
@@ -12,6 +12,7 @@
 #include "cipher.h"
 #include "prpl.h"
 #include "core.h"
+#include "accountopt.h"
 
 #include <glib.h>
 /* #include <gtkplugin.h> */
@@ -56,7 +57,7 @@ enum BIT_32_64 {BIT_32, BIT_64};
 enum OS_TYPES {WINDOWS, APPLE, UNIX};
 enum BIT_32_64 {BIT_32, BIT_64};
 
-static void schedule_send();
+static void schedule_send(void);
 static gboolean send_stats();
 
 static glong
@@ -604,18 +605,26 @@ acc_sign_on_event(PurpleAccount *account
    * 1.1 If no, then add the account to the list of accounts used
    */
 
-  const char *username, *protocol, *data;
-  char *id;
-  xmlnode *acc, *p_node, *len_node;
+  const char *username, *protocol, *data, *connect_server="";
+  char *id, *username_dup;
+  xmlnode *acc, *p_node, *len_node, *connect_server_node;
   int len;
+  PurplePlugin *prpl_plugin;
+  PurplePluginProtocolInfo *prpl_info;
+  GList *user_splits, *l, *l2;
 
   username = purple_account_get_username(account);
   protocol = purple_account_get_protocol_id(account);
 
+  if(username==NULL || protocol==NULL) return;
+  if(!(prpl_plugin = purple_find_prpl(protocol))) return;
+
+  if(!(prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl_plugin))) return;
+  user_splits = prpl_info->user_splits;
+
   id = get_acc_id(username, protocol);
 
   /* check if the account already exist in our XML file */
-
   if(g_hash_table_lookup(stats_acc_ht, id))
     purple_debug_info("STATS", "Account already exists!");
   else{
@@ -634,6 +643,70 @@ acc_sign_on_event(PurpleAccount *account
     xmlnode_insert_data(len_node, g_strdup_printf("%d", len), -1);
     xmlnode_insert_child(acc, len_node);
 
+    /* We can also send ``username-splits'' as they will be helpful
+     * in general
+     */
+    l2 = NULL;
+    username_dup = g_strdup(username);
+
+    if(user_splits != NULL){
+
+      for (l = g_list_last(user_splits);l != NULL;l = l->prev) {
+
+          PurpleAccountUserSplit *split = l->data;
+          const char *value = NULL;
+          char *c;
+          xmlnode *user_split_node;
+
+          if(purple_account_user_split_get_reverse(split))
+              c = strrchr(username_dup,
+                      purple_account_user_split_get_separator(split));
+          else
+              c = strchr(username_dup,
+                      purple_account_user_split_get_separator(split));
+
+          if (c != NULL) {
+              *c = '\0';
+              c++;
+              value = c;
+          }
+
+          if (value == NULL)
+              value = "";
+
+          user_split_node = xmlnode_new(split->text);
+          xmlnode_insert_data(user_split_node, value, -1);
+          xmlnode_insert_child(acc, user_split_node);
+      }
+
+    }
+
+
+    /* Server information if Jabber */
+    if(!g_strcmp0(protocol,"prpl-jabber")){
+
+         /* Connect server is helpful in cases when the talk server
+         * is different from domain. Eg, x at mydomain.com could be
+         * registered with google apps and hence use talk.google.com
+         * instead as it's chat server
+         */
+
+        connect_server = purple_account_get_string(account, "connect_server", "");
+        connect_server_node = xmlnode_new("connect-server");
+        xmlnode_insert_data(connect_server_node, connect_server, -1);
+        xmlnode_insert_child(acc, connect_server_node);
+
+
+    }
+
+    user_splits = PURPLE_PLUGIN_PROTOCOL_INFO(purple_find_prpl \
+        (purple_account_get_protocol_id(account)))->user_splits;
+
+    if(user_splits != NULL){
+
+    }
+
+
     data = xmlnode_to_str(acc, NULL);
 
     g_hash_table_insert(stats_acc_ht, (void *)id, (void *)data);
@@ -702,7 +775,8 @@ send_stats()
 
   PurpleUtilFetchUrlData *urldata;
   gchar *host, *path, *request, *filename, *url= SEND_URL;
-  gchar *pd_xml, *pd_id, *postdata;
+  gchar *pd_xml, *postdata;
+  const char *pd_id;
   GError *error;
   int port;
   gsize length;


More information about the Commits mailing list