/soc/2015/nakulgulati/main: e61b3db0b0d9: hangouts: util parse c...

Nakul at rock.pidgin.im Nakul at rock.pidgin.im
Wed Jul 15 03:09:36 EDT 2015


Changeset: e61b3db0b0d94fe7b739564253f973cc2dc998dd
Author:	 Nakul Gulati
Date:	 2015-07-14 15:07 +0800
Branch:	 hangouts
URL: https://hg.pidgin.im/soc/2015/nakulgulati/main/rev/e61b3db0b0d9

Description:

hangouts: util parse chat init data

diffstat:

 libpurple/protocols/hangouts/util.c |  32 ++++++++++++++++++++++++++++++++
 libpurple/protocols/hangouts/util.h |   5 ++++-
 2 files changed, 36 insertions(+), 1 deletions(-)

diffs (55 lines):

diff --git a/libpurple/protocols/hangouts/util.c b/libpurple/protocols/hangouts/util.c
--- a/libpurple/protocols/hangouts/util.c
+++ b/libpurple/protocols/hangouts/util.c
@@ -22,4 +22,36 @@
 #include "util.h"
 #include <glib.h>
 
+gchar *
+hangouts_util_escape_string(gchar *string){
+	return g_strescape(string,NULL);
+}
 
+void
+hangouts_util_parse(gchar *raw_data)
+{
+	GRegex *regex_script_data,*regex_key_data;
+	GMatchInfo *match_info;
+	gchar *escaped_data;
+
+	escaped_data = hangouts_util_escape_string(raw_data);
+
+	regex_script_data = g_regex_new(HANGOUTS_CHAT_INIT_REGEX, G_REGEX_OPTIMIZE, 0, NULL);
+	regex_key_data = g_regex_new(HANGOUTS_CHAT_KEY_DATA_REGEX, G_REGEX_OPTIMIZE, 0, NULL);
+
+	g_regex_match (regex_script_data, escaped_data, 0, &match_info);
+
+	while (g_match_info_matches (match_info)){
+		gchar *script_data = g_match_info_fetch (match_info, 0);
+		gchar **key_data = g_regex_split(regex_key_data, script_data, 0);
+
+		/*key_data[1] - key
+		key_data[2] - data*/
+
+		g_match_info_next (match_info, NULL);
+		g_free(script_data);
+		g_free(key_data);
+	}
+
+}
+
diff --git a/libpurple/protocols/hangouts/util.h b/libpurple/protocols/hangouts/util.h
--- a/libpurple/protocols/hangouts/util.h
+++ b/libpurple/protocols/hangouts/util.h
@@ -22,7 +22,10 @@
 #ifndef _UTIL_H
 #define _UTIL_H
 
-#define CHAT_INIT_REGEX "(?:<script>AF_initDataCallback\((.*?)\);<\/script>)"
+static const gchar *HANGOUTS_CHAT_INIT_REGEX = "(?:<script>AF_initDataCallback\((.*?)\);<\/script>)";
+static const gchar *HANGOUTS_CHAT_KEY_DATA_REGEX = "(?:key: \'(ds:.{1,2})\')(?:.*?)(?:data:function..{return (.*?)}}.;<\/script>)";
 
+gchar *hangouts_util_escape_string(gchar *string);
+void hangouts_util_parse(gchar *raw_data);
 
 #endif _UTIL_H



More information about the Commits mailing list