soc.2012.statscollector: 30e972b5: Sign-on signal handled
sanket at sanketagarwal.com
sanket at sanketagarwal.com
Mon May 14 13:27:51 EDT 2012
----------------------------------------------------------------------
Revision: 30e972b5e1592eae1c327f437183594ee2be3c87
Parent: 4d612f4b1c83ea1c7268d5f840a05b6279017e32
Author: sanket at sanketagarwal.com
Date: 05/12/12 15:23:16
Branch: im.pidgin.soc.2012.statscollector
URL: http://d.pidgin.im/viewmtn/revision/info/30e972b5e1592eae1c327f437183594ee2be3c87
Changelog:
Sign-on signal handled
The functionality is as: each sign-on will either trigger adding
an extra account in stats.xml OR it will leave it unchanged.
There are some strucutural differences in the code in terms of
handling of the Hash Table efficiently.
Changes against parent 4d612f4b1c83ea1c7268d5f840a05b6279017e32
patched pidgin/plugins/statscollector.c
-------------- next part --------------
============================================================
--- pidgin/plugins/statscollector.c 8fb4b55bd8f469bbfc34208e8d6c3dbe2471f5e4
+++ pidgin/plugins/statscollector.c 74e877dcf2f5088e1d28361f14e7d80781ce20ba
@@ -18,6 +18,41 @@ static void
GHashTable *stats_acc_ht, *stats_plugins_ht;
static void
+save_xml(){
+
+ /* Uses the Hash tables and other XML nodes
+ * that have been saved/modified and create
+ * final modified XML out of it to be flushed
+ */
+
+ GHashTableIter iter;
+ gpointer key, value;
+ xmlnode *nroot, *nacc, *nplugins, *node, *node1, *node2;
+ char *data;
+
+ nroot = xmlnode_new("stats");
+ nacc = xmlnode_new_child(nroot, "accounts");
+ nplugins = xmlnode_new_child(nroot, "plugins");
+
+ /* Use the hash tables to populate acc and plugins */
+
+ g_hash_table_iter_init(&iter, stats_acc_ht);
+
+ while(g_hash_table_iter_next(&iter, &key, &value)){
+
+ node = xmlnode_from_str(value, -1);
+ xmlnode_insert_child(nacc, node);
+
+ }
+
+ // purple_debug_info("STATS", "SAVE %s", xmlnode_to_formatted_str(nroot, NULL));
+
+ data = xmlnode_to_formatted_str(nroot, NULL);
+ purple_util_write_data_to_file("stats.xml", data, -1);
+
+}
+
+static void
sign_on_event(PurpleAccount *account){
/* Store information about logging on of an account. The following
@@ -26,8 +61,9 @@ sign_on_event(PurpleAccount *account){
* 1.1 If no, then add the account to the list of accounts used
*/
- char *username, *protocol;
+ char *username, *protocol, *data;
+ xmlnode *acc, *u_node, *p_node;
username = purple_account_get_username(account);
protocol = purple_account_get_protocol_id(account);
@@ -35,14 +71,24 @@ sign_on_event(PurpleAccount *account){
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);
+ else{
+ acc = xmlnode_new("account");
- purple_debug_info("XX-STATS",
- "Logged into a account %s with protocol %s",
- purple_account_get_username(account),
- purple_account_get_protocol_id(account));
+ u_node = xmlnode_new_child(acc, "username");
+ xmlnode_insert_data(u_node, username, -1);
+ 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, username, data);
+
+ }
+
+ save_xml();
+
}
static xmlnode *
@@ -55,6 +101,8 @@ init_stats(){
*/
/* Load the xml */
+ GHashTableIter *iter;
+ char *key, *value;
char *data;
xmlnode *stats_acc_xml, *stats_plugins_xml;
xmlnode *start, *u_node, *p_node;
@@ -68,7 +116,6 @@ init_stats(){
/* 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, "plugins");
@@ -95,13 +142,21 @@ init_stats(){
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));
+ (char *)xmlnode_to_formatted_str(start, NULL));
}
+ g_hash_table_iter_init(&iter, stats_acc_ht);
+
+ while(g_hash_table_iter_next(&iter, &key, &value)){
+
+ purple_debug_info("STATS", "HASH %s\n", value);
+
+ }
+
+
start = xmlnode_get_child(stats_acc_xml, "plugins");
for(;start;start = xmlnode_get_next_twin(start)){
@@ -127,13 +182,10 @@ plugin_load(PurplePlugin *plugin) {
root_stats = init_stats();
- /* Spit the current stats */
- purple_debug_info("STATS", "%s",xmlnode_to_formatted_str(root_stats, NULL));
-
/* Register the account signals for sign-on/off */
- /* purple_signal_connect(purple_accounts_get_handle(), "account-signed-on", */
- /* plugin, PURPLE_CALLBACK(sign_on_event), NULL); */
+ purple_signal_connect(purple_accounts_get_handle(), "account-signed-on",
+ plugin, PURPLE_CALLBACK(sign_on_event), NULL);
return TRUE;
}
More information about the Commits
mailing list