/soc/2012/sanket/statscollector-2.x.y: 17fb474f9b0f: Fix lint er...
Sanket Agarwal
sanket at soc.pidgin.im
Sun Mar 31 23:04:18 EDT 2013
Changeset: 17fb474f9b0f253e16125539b539b02a83194769
Author: Sanket Agarwal <sanket at soc.pidgin.im>
Date: 2013-03-31 19:04 +0530
Branch: soc.2012.statscollector
URL: https://hg.pidgin.im/soc/2012/sanket/statscollector-2.x.y/rev/17fb474f9b0f
Description:
Fix lint errors and Valgrind memory leaks.
diffstat:
libpurple/plugins/statscollector.c | 1994 ++++++++++++++++++-----------------
1 files changed, 1003 insertions(+), 991 deletions(-)
diffs (truncated from 2248 to 300 lines):
diff --git a/libpurple/plugins/statscollector.c b/libpurple/plugins/statscollector.c
--- a/libpurple/plugins/statscollector.c
+++ b/libpurple/plugins/statscollector.c
@@ -33,9 +33,9 @@
/* Allow/Deny Constants */
enum
{
- ALLOW,
- DENY,
- ASK
+ ALLOW,
+ DENY,
+ ASK
} AllowSettings;
/* Timeout */
@@ -50,14 +50,9 @@ enum
#define STATS_XML_V "0.2" /* 0 -- Dev purposes */
-/* POSIX compliance is an issue that I have looked into some detail now
- * It seems like presence of unistd.h and _POSIX_VERSION being defined
- * confirms the presence of POSIX compliance. For this ofcourse we need
- * to ensure that unistd.h is defined. As it is *already* a part of
- * internal.h, we could directly go ahead with the testing if the
- * system is POSIX or not
+/* POSIX compliance may be checked by POSIX_VERSION being defined. This macro is
+ * present in unistd.h and unistd.h is already included in internal.h.
*/
-
#ifdef _POSIX_VERSION
# include <sys/utsname.h>
# include <dlfcn.h>
@@ -81,296 +76,312 @@ static gboolean plugin_unload(PurplePlug
static gboolean refresh_public_server_cache(gpointer data);
static xmlnode *init_stats();
static void acc_sign_on_event(PurpleAccount *account);
-
+static void url_callback(PurpleUtilFetchUrlData *url_data, gpointer user_data,
+ const gchar *url_text, gsize len, const gchar *error_message);
+static void pref_allow_cb(const char *name, PurplePrefType type,
+ gconstpointer val, gpointer data);
static void
-confirm_allow(){
- /* Set the allow variable in prefs to ALLOW */
- purple_prefs_set_int("/plugins/core/statscollector/allow", ALLOW);
+confirm_allow()
+{
+ /* Set the allow variable in prefs to ALLOW */
+ purple_prefs_set_int("/plugins/core/statscollector/allow", ALLOW);
}
static void
-confirm_deny(){
- /* Set the allow variable in prefs to ALLOW */
- purple_prefs_set_int("/plugins/core/statscollector/allow", DENY);
+confirm_deny()
+{
+ /* Set the allow variable in prefs to ALLOW */
+ purple_prefs_set_int("/plugins/core/statscollector/allow", DENY);
}
static void
-confirm_later(){
- /* No-op right now, but can contain logic wherein we have
- * a timeout before the next callout for authorize/deny
- */
+confirm_later()
+{
+ /* No-op right now, but can contain logic wherein we have
+ * a timeout before the next callout for authorize/deny
+ */
}
static glong
-get_time_sec(){
- /* Gets current time in seconds */
- GTimeVal res;
- g_get_current_time(&res);
- return res.tv_sec;
+get_time_sec()
+{
+ /* Gets current time in seconds */
+ GTimeVal res;
+ g_get_current_time(&res);
+ return res.tv_sec;
}
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, *nuis;
- char *data, *version;
+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, *nuis;
+ char *data, *version;
- nroot = xmlnode_new("stats");
+ nroot = xmlnode_new("stats");
- /* Set the string information */
- version = g_strdup_printf("%s", STATS_XML_V);
- xmlnode_set_attrib(nroot, "version", version);
+ /* Set the string information */
+ version = g_strdup_printf("%s", STATS_XML_V);
+ xmlnode_set_attrib(nroot, "version", version);
- /* Load CPUinfo strucutre */
- xmlnode_insert_child(nroot, xmlnode_copy(cpuinfo_xml));
+ /* Load CPUinfo strucutre */
+ xmlnode_insert_child(nroot, xmlnode_copy(cpuinfo_xml));
- /* Load UI info */
- xmlnode_insert_child(nroot, xmlnode_copy(ui_info));
+ /* Load UI info */
+ xmlnode_insert_child(nroot, xmlnode_copy(ui_info));
- nacc = xmlnode_new_child(nroot, "accounts");
- nplugins = xmlnode_new_child(nroot, "plugins");
- nuis = xmlnode_new_child(nroot, "uis");
+ nacc = xmlnode_new_child(nroot, "accounts");
+ nplugins = xmlnode_new_child(nroot, "plugins");
+ nuis = xmlnode_new_child(nroot, "uis");
- /* 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)){
- xmlnode_insert_child(nacc, xmlnode_copy((xmlnode *)value));
- }
- g_hash_table_iter_init(&iter, stats_plugins_ht);
- while(g_hash_table_iter_next(&iter, &key, &value)){
- xmlnode_insert_child(nplugins, xmlnode_copy((xmlnode *)value));
- }
- g_hash_table_iter_init(&iter, stats_uis_ht);
- while(g_hash_table_iter_next(&iter, &key, &value)){
- xmlnode_insert_child(nuis, xmlnode_copy((xmlnode *)value));
- }
+ /* 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)) {
+ xmlnode_insert_child(nacc, xmlnode_copy((xmlnode *)value));
+ }
+ g_hash_table_iter_init(&iter, stats_plugins_ht);
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
+ xmlnode_insert_child(nplugins, xmlnode_copy((xmlnode *)value));
+ }
+ g_hash_table_iter_init(&iter, stats_uis_ht);
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
+ xmlnode_insert_child(nuis, xmlnode_copy((xmlnode *)value));
+ }
- data = xmlnode_to_formatted_str(nroot, NULL);
- purple_util_write_data_to_file("stats.xml", data, -1);
- xmlnode_free(nroot);
- g_free(data);
+ data = xmlnode_to_formatted_str(nroot, NULL);
+ purple_util_write_data_to_file("stats.xml", data, -1);
+ xmlnode_free(nroot);
+
+ g_free(data);
}
static gboolean
-save_cb(gpointer data){
- save_xml();
- save_timer = 0;
- return FALSE;
+save_cb(gpointer data)
+{
+ save_xml();
+ save_timer = 0;
+ return FALSE;
}
static void
-schedule_stats_save(void){
- if(save_timer == 0)
- save_timer = purple_timeout_add_seconds(5, save_cb, NULL);
+schedule_stats_save(void)
+{
+ if (save_timer == 0) {
+ save_timer = purple_timeout_add_seconds(5, save_cb, NULL);
+ }
}
-static void
-refresh_accounts(){
- /* Scan through each of the currently available accounts,
- * and refresh them if we get more info
- */
- GList *loaded_accounts;
- loaded_accounts = purple_accounts_get_all_active();
- g_list_foreach(loaded_accounts, (GFunc)acc_sign_on_event, NULL);
-}
-
-/*
- * Check if the header has HTTP/1.1 200 ...
- * I am assuming that the first few characters will always follow
- * the following format:
- * HTTP/1.x xyz reason
+/* Fetch information about servers (domains) which our stats server thinks are
+ * public. This information can then be used to record the domain field of a
+ * username. In general we do not store the domain due to security reasons.
*/
static void
refresh_public_server_cache_cb(PurpleUtilFetchUrlData *url_data,
- gpointer user_data, const gchar *url_text, gsize len,
- const gchar *error_message)
+ gpointer user_data, const gchar *url_text, gsize len,
+ const gchar *error_message)
{
- int code = -1;
- char *header = g_strdup_printf("%s", url_text);
- char *data_loc=NULL;
- const char *hash_id;
- xmlnode *public_server_hash_root, *start;
+ int code = -1;
+ char *header = g_strdup_printf("%s", url_text);
+ char *data_loc=NULL;
+ const char *hash_id;
+ xmlnode *public_server_hash_root, *start;
+ GList *loaded_accounts;
- if(header && strlen(header) >= 14)
- {
- header += 9;
- header[3] = '\0';
- code = atoi(header);
- }
+ /* Check if the header has HTTP/1.1 200 ...
+ * I am assuming that the first few characters will always follow
+ * the following format:
+ * HTTP/1.x xyz reason
+ */
+ if (header && strlen(header) >= 14) {
+ header += 9;
+ header[3] = '\0';
+ code = atoi(header);
+ }
- purple_debug_info("STATS", "Code returned: %d\n", code);
- if(code == 200)
- {
- /* Extract the data to be converted to XML => GList */
- data_loc = strstr(url_text, "\r\n\r\n");
- public_server_hash_root = xmlnode_from_str(data_loc, -1);
- if(public_server_hash_root != NULL){
- /* Now load a Hash Table of accepted Hashes, currently they won't
- * contain any data, but this is to keep space for any extra info
- * that the server might give away!
- */
- start = xmlnode_get_child(public_server_hash_root, "hash");
- for(;start;start = xmlnode_get_next_twin(start))
- {
- hash_id = xmlnode_get_attrib(start, "id");
- g_hash_table_insert(public_server_cache_ht, (void *)hash_id, NULL);
- }
- public_server_handle = purple_timeout_add_seconds(PUBLIC_SERVER_CACHE_REFRESH, refresh_public_server_cache, NULL);
+ purple_debug_info("STATS", "Code returned: %d\n", code);
+ if (code == 200) {
+ /* Extract the data to be converted to XML => GList */
+ data_loc = strstr(url_text, "\r\n\r\n");
+ public_server_hash_root = xmlnode_from_str(data_loc, -1);
+ if (public_server_hash_root != NULL) {
+ /* Now load a Hash Table of accepted Hashes, currently they won't
+ * contain any data, but this is to keep space for any extra info
+ * that the server might give away!
+ */
+ start = xmlnode_get_child(
+ public_server_hash_root, "hash");
+ for (; start; start = xmlnode_get_next_twin(start)) {
+ hash_id = xmlnode_get_attrib(start, "id");
+ g_hash_table_insert(
+ public_server_cache_ht,
+ (void *)hash_id,
+ NULL);
+ }
+ public_server_handle = purple_timeout_add_seconds(
+ PUBLIC_SERVER_CACHE_REFRESH,
+ refresh_public_server_cache,
+ NULL);
- /* Check all account split hashes */
- refresh_accounts();
-
- }
- } else {
- public_server_handle = purple_timeout_add_seconds(10, refresh_public_server_cache, NULL);
More information about the Commits
mailing list