/soc/2012/sanket/statscollector-2.x.y: 9a6347a3b3d0: Ask Allow/D...

sanket sanket at soc.pidgin.im
Wed Aug 1 08:49:12 EDT 2012


Changeset: 9a6347a3b3d080161f26b50c11dbb6a4cab75cdb
Author:	 sanket <sanket at soc.pidgin.im>
Date:	 2012-08-01 05:48 +0530
Branch:	 soc.2012.statscollector
URL: http://hg.pidgin.im/soc/2012/sanket/statscollector-2.x.y/rev/9a6347a3b3d0

Description:

Ask Allow/Deny/Later authorization box

The plugin (on plugin_load) event, asks the user if he wishes
to send data anonymously. It has three fields, for Allow - Deny
 - Later. Where Later is simply a no-op (on next load it should
 ask).

 ISSUE: I cannot get it to work when pidgin loads the plugin itself.
 That is, when pidgin loads, and the plugin is already in the list of
 enabled plugins, this authorization box should fire, though it does not.

 But still this POC works, and I'll work out the other dirty details
 later.

diffstat:

 pidgin/plugins/statscollector.c |  728 ++++++++++++++++++++++++++++++++++++---
 1 files changed, 660 insertions(+), 68 deletions(-)

diffs (truncated from 1030 to 300 lines):

diff --git a/pidgin/plugins/statscollector.c b/pidgin/plugins/statscollector.c
--- a/pidgin/plugins/statscollector.c
+++ b/pidgin/plugins/statscollector.c
@@ -12,25 +12,101 @@
 #include "cipher.h"
 #include "prpl.h"
 #include "core.h"
+#include "accountopt.h"
+#include "pidginstock.h"
 
 #include <glib.h>
-#include <gtkplugin.h>
+/* #include <gtkplugin.h> */
+#include<gtkutils.h>
+#include "gtkblist.h"
 
 #ifdef _WIN32
 #include<windows.h>
 #endif
 
-#define STATS_MAJOR_VERSION 1
-#define STATS_MINOR_VERSION 0
+#ifdef __APPLE__
+#include<CoreServices/CoreServices.h>
+#include<sys/types.h>
+#include<sys/sysctl.h>
+#endif
 
-xmlnode *root_stats, *cpuinfo_xml;
-GHashTable *stats_acc_ht, *stats_plugins_ht;
-int save_timer = 0;
+/* Allow/Deny Constants */
+#define ALLOW 0
+#define DENY 1
+#define ASK 2
+/* Timeout */
+#define RESEND_SEC (24*3600)
+
+/* Sending URL */
+#define SEND_URL "http://localhost:8000/collectstats/collect/"
+
+/* Version of XML this plugin supports writing */
+
+#define STATS_XML_MAJOR_V "1"
+#define STATS_XML_MINOR_V "0"
+
+/* 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
+ */
+
+#ifdef _POSIX_VERSION
+# include <sys/utsname.h>
+# include <dlfcn.h>
+#endif
+
+PurplePlugin *plugin_g;
+xmlnode *root_stats, *cpuinfo_xml, *ui_info;
+GHashTable *stats_acc_ht, *stats_plugins_ht, *stats_uis_ht;
+int save_timer = 0, send_handle = 0;
 
 /* Types of Operating Systems */
 enum OS_TYPES {WINDOWS, APPLE, UNIX};
 enum BIT_32_64 {BIT_32, BIT_64};
 
+static void schedule_send(void);
+static gboolean send_stats();
+static gboolean plugin_load(PurplePlugin *);
+
+static void
+confirm_allow(){
+
+  /* Set the allow variable in prefs to ALLOW */
+  purple_prefs_set_int("/plugins/core/statscollector/allow", ALLOW);
+  plugin_load(plugin_g);
+
+}
+
+static void
+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
+   */
+
+}
+
+static glong
+get_time_sec(){
+
+  /* Gets current time in seconds */
+  GTimeVal res;
+  g_get_current_time(&res);
+  return res.tv_sec;
+
+}
+
 static void
 save_xml(){
 
@@ -41,16 +117,25 @@ save_xml(){
 
   GHashTableIter iter;
   gpointer key, value;
-  xmlnode *nroot, *nacc, *nplugins, *node;
-  char *data;
+  xmlnode *nroot, *nacc, *nplugins, *nuis, *node;
+  char *data, *version;
 
   nroot = xmlnode_new("stats");
 
+  /* Set the string information */
+  version = g_strdup_printf("%s.%s", STATS_XML_MAJOR_V,\
+      STATS_XML_MINOR_V);
+  xmlnode_set_attrib(nroot, "version", version);
+
   /* Load CPUinfo strucutre */
   xmlnode_insert_child(nroot, cpuinfo_xml);
 
+  /* Load UI info */
+  xmlnode_insert_child(nroot, ui_info);
+
   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 */
 
@@ -73,6 +158,15 @@ save_xml(){
 
   }
 
+  g_hash_table_iter_init(&iter, stats_uis_ht);
+
+  while(g_hash_table_iter_next(&iter, &key, &value)){
+
+    node = xmlnode_from_str(value, -1);
+    xmlnode_insert_child(nuis, node);
+
+  }
+
   data = xmlnode_to_formatted_str(nroot, NULL);
   purple_util_write_data_to_file("stats.xml", data, -1);
 
@@ -96,12 +190,12 @@ get_app_32_64(){
 
   /* Determines if the application is running in 32 or 64 bit mode */
   int pt_size;
-  xmlnode *bit_size;
+  xmlnode *bit_size_xml;
 
-  pt_size = sizeof(int)*8;
-  bit_size = xmlnode_new("app-bit");
-  xmlnode_insert_data(bit_size, g_strdup_printf("%d",pt_size), -1);
-  return bit_size;
+  pt_size = sizeof(int *)*8;
+  bit_size_xml = xmlnode_new("app-bit");
+  xmlnode_insert_data(bit_size_xml, g_strdup_printf("%d",pt_size), -1);
+  return bit_size_xml;
 
 }
 
@@ -112,20 +206,26 @@ get_os_32_64(){
   int bit_size=-1;
   xmlnode *bit_size_xml;
 #ifdef _WIN32
+
   BOOL bIsWow64;
   typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
   LPFN_ISWOW64PROCESS fnIsWow64Process;
-#elif defined __USE_POSIX
+
+#elif defined _POSIX_VERSION
+
   struct utsname os_utsname;
   char *m_name;
+
 #endif
 
   bit_size_xml = xmlnode_new("os-bit");
 
 #ifdef _WIN64
+
   bit_size = 64;
 
 #elif defined _WIN32
+
   /* Check if we are running as wow64 process */
   bIsWow64 = FALSE;
   fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress( \
@@ -141,13 +241,21 @@ get_os_32_64(){
   if(bIsWow64) bit_size= 64;
   else bit_size = 32;
 
-#elif defined __USE_POSIX
+#elif _POSIX_VERSION
+
   /* Use uname to find kernel architecture and infer bit-size */
   uname(&os_utsname);
   m_name = os_utsname.machine;
 
-  if(!g_strcmp0(m_name, "x86_64")) bit_size = 64;
+  /* Identifying 64 bit OS is tricky. We use the following identifiers
+   * on basis of experience with uname(2) call.
+   */
+
+  if(!g_strcmp0(m_name, "x86_64") || !g_strcmp0(m_name, "ia64") \
+      || !g_strcmp0(m_name, "amd64") || !g_strcmp0(m_name, "ppc64")) \
+    bit_size = 64;
   else bit_size = 32;
+
 #endif
 
   xmlnode_insert_data(bit_size_xml, g_strdup_printf("%d", bit_size), -1);
@@ -163,23 +271,20 @@ get_arch(){
 
   xmlnode *arch_xml;
   char *arch_str;
-#ifdef __linux__
-  struct utsname os_utsname;
-#elif defined _WIN32
+
+#ifdef _WIN32
   SYSTEM_INFO sys_info;
   typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);
   typedef BOOL (WINAPI *PGPI)(DWORD, DWORD, DWORD, DWORD, PDWORD);
   PGNSI pGNSI;
+#elif defined _POSIX_VERSION
+  struct utsname os_utsname;
 #endif
 
   arch_xml = xmlnode_new("arch");
 
 
-#ifdef __linux__
-  uname(&os_utsname);
-  arch_str = os_utsname.machine;
-#elif defined _WIN32
-
+#ifdef _WIN32
   pGNSI = (PGNSI) GetProcAddress(
     GetModuleHandle(TEXT("kernel32.dll")), "GetNativeSystemInfo");
 
@@ -190,17 +295,20 @@ get_arch(){
   switch(sys_info.wProcessorArchitecture){
 
     case 9:
-      arch_str = "AMD64";
+      arch_str = "amd64"; // same as x86_64 in windows
       break;
     case 6:
-      arch_str = "IA64";
+      arch_str = "ia64";
       break;
     case 0:
-      arch_str = "INTEL";
+      arch_str = "x86";
       break;
     default:
       arch_str = "UNKNOWN";
   }
+#elif defined _POSIX_VERSION
+  uname(&os_utsname);
+  arch_str = os_utsname.machine;
 #endif
 
   xmlnode_set_attrib(arch_xml, "id", arch_str);
@@ -218,23 +326,53 @@ get_os_name(){
 
   xmlnode *os_name_xml;
   char *name_attrib;
+
 #ifdef _WIN32
+
   xmlnode *major_version, *minor_version;
   OSVERSIONINFO osvi;
-#elif defined __USE_POSIX
+
+#elif defined __APPLE__
+
+  int mib[2];
+  size_t length;
+  SInt32 major_version,minor_version,bug_fix_version;
+
+  char sys_ver_file[] = "/System/Library/CoreServices/SystemVersion.plist";
+  char *sys_ver_contents, *key_str, *value_str;
+
+  GHashTable *sys_ver_ht;
+  GError *err;



More information about the Commits mailing list