soc.2012.statscollector: 77e39db6: Extend the key for accounts; use attribu...
sanket at sanketagarwal.com
sanket at sanketagarwal.com
Mon May 14 13:28:03 EDT 2012
----------------------------------------------------------------------
Revision: 77e39db6e4cb203716ab6f1becb0e1bd15ed195e
Parent: bd9e77e0c505ebe47b1d674f12832c6d331fa664
Author: sanket at sanketagarwal.com
Date: 05/14/12 06:55:49
Branch: im.pidgin.soc.2012.statscollector
URL: http://d.pidgin.im/viewmtn/revision/info/77e39db6e4cb203716ab6f1becb0e1bd15ed195e
Changelog:
Extend the key for accounts; use attribute style xml
Currently for account only "username" was being used. It is possible to have
same username on different IM services. So we use username-prpl_id as our
key.
Secondly it's better to use <account id=".."> and <plugin id=".."> and then
save element level information.
Changes against parent bd9e77e0c505ebe47b1d674f12832c6d331fa664
patched pidgin/plugins/statscollector.c
-------------- next part --------------
============================================================
--- pidgin/plugins/statscollector.c 954d16f205b9ddb7d00a72f49cef7f48ecae3b55
+++ pidgin/plugins/statscollector.c d62a7552cf3655b1265e07cb116356a87baaee82
@@ -52,7 +52,6 @@ save_xml(){
}
- // purple_debug_info("STATS", "SAVE %s", xmlnode_to_formatted_str(nroot, NULL));
g_hash_table_iter_init(&iter, stats_plugins_ht);
@@ -140,9 +139,25 @@ get_cpuinfo_xml(){
}
+static gchar *
+get_acc_id(char *username, char *prpl_id){
+ /* Generates a id from username and prpl_id */
+
+ char *id = (char *)malloc(500*sizeof(char));
+
+ id[0] = '\0';
+ strcat(id, username);
+ strcat(id, "-");
+ strcat(id, prpl_id);
+
+ return id;
+
+}
+
+
static void
-sign_on_event(PurpleAccount *account){
+acc_sign_on_event(PurpleAccount *account){
/* Store information about logging on of an account. The following
* measures should be taken:
@@ -151,28 +166,33 @@ sign_on_event(PurpleAccount *account){
*/
const char *username, *protocol, *data;
+ char *id;
xmlnode *acc, *u_node, *p_node;
username = purple_account_get_username(account);
protocol = purple_account_get_protocol_id(account);
+ id = get_acc_id(username, protocol);
+
/* check if the account already exist in our XML file */
- if(g_hash_table_lookup(stats_acc_ht, username))
+ if(g_hash_table_lookup(stats_acc_ht, id))
purple_debug_info("STATS", "Account already exists!");
else{
acc = xmlnode_new("account");
- u_node = xmlnode_new_child(acc, "username");
- xmlnode_insert_data(u_node, username, -1);
+ /* u_node = xmlnode_new_child(acc, "username"); */
+ /* xmlnode_insert_data(u_node, username, -1); */
+ xmlnode_set_attrib(acc, "id", id);
+
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, (void *)username, (void *)data);
+ g_hash_table_insert(stats_acc_ht, (void *)id, (void *)data);
}
@@ -213,9 +233,11 @@ plugin_load_event(PurplePlugin *plugin){
plugin_xml = xmlnode_new("plugin");
- p_id = xmlnode_new_child(plugin_xml, "id");
- xmlnode_insert_data(p_id, plugin_id, -1);
+ xmlnode_set_attrib(plugin_xml, "id", plugin_id);
+ /* 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", */
@@ -241,7 +263,7 @@ init_stats(){
/* GHashTableIter *iter; */
GList *loaded_plugins;
xmlnode *stats_acc_xml, *stats_plugins_xml;
- xmlnode *start, *u_node;
+ xmlnode *start, *id_node;
/* Load the xml */
xmlnode *root = purple_util_read_xml_from_file("stats.xml",
@@ -275,9 +297,9 @@ init_stats(){
for(;start;start = xmlnode_get_next_twin(start)){
- u_node = xmlnode_get_child(start, "username");
+ id_node = xmlnode_get_attrib(start, "id");
- g_hash_table_insert(stats_acc_ht, (char *)xmlnode_get_data(u_node),
+ g_hash_table_insert(stats_acc_ht, (char *)id_node,
(char *)xmlnode_to_formatted_str(start, NULL));
}
@@ -295,9 +317,9 @@ init_stats(){
for(;start;start = xmlnode_get_next_twin(start)){
- u_node = xmlnode_get_child(start, "id");
+ id_node = xmlnode_get_attrib(start, "id");
- g_hash_table_insert(stats_plugins_ht, (char *)xmlnode_get_data(u_node),
+ g_hash_table_insert(stats_plugins_ht, (char *)(id_node),
(char *)xmlnode_to_formatted_str(start, NULL));
}
@@ -334,7 +356,7 @@ plugin_load(PurplePlugin *plugin) {
/* Register the account signals for sign-on */
purple_signal_connect(purple_accounts_get_handle(), "account-signed-on",
- plugin, PURPLE_CALLBACK(sign_on_event), NULL);
+ plugin, PURPLE_CALLBACK(acc_sign_on_event), NULL);
/* Register the plugin signals for sign-on */
More information about the Commits
mailing list