/soc/2015/nakulgulati/main: 61b708195547: hangouts: chat init pa...
Nakul at rock.pidgin.im
Nakul at rock.pidgin.im
Sat Aug 8 22:14:52 EDT 2015
Changeset: 61b708195547bf444aeef10b3225830aa31b3499
Author: Nakul Gulati
Date: 2015-08-09 10:13 +0800
Branch: hangouts
URL: https://hg.pidgin.im/soc/2015/nakulgulati/main/rev/61b708195547
Description:
hangouts: chat init parser, fixed empty values
diffstat:
libpurple/protocols/hangouts/api.c | 15 +----------
libpurple/protocols/hangouts/util.c | 48 ++++++++++++++++++++++++++++++++++--
libpurple/protocols/hangouts/util.h | 3 ++
3 files changed, 49 insertions(+), 17 deletions(-)
diffs (119 lines):
diff --git a/libpurple/protocols/hangouts/api.c b/libpurple/protocols/hangouts/api.c
--- a/libpurple/protocols/hangouts/api.c
+++ b/libpurple/protocols/hangouts/api.c
@@ -447,28 +447,15 @@ hangouts_api_get_chat_init_cb (PurpleHtt
{
const gchar *raw_res;
GHashTable *chat_init_tab;
- JsonNode *root, *result;
- JsonPath *path;
- JsonArray *array;
+ JsonNode *root;
raw_res = purple_http_response_get_data (response, NULL);
chat_init_tab = hangouts_util_parse (raw_res);
root = hangouts_util_construct_json_dictionary (chat_init_tab);
- path = json_path_new ();
- json_path_compile (path, "$.ds:7[0][2]", NULL);
-
- result = json_path_match (path, root);
- array = json_node_dup_array (result);
- gchar *str = json_array_get_string_element (array, 0);
-
- purple_debug_misc ("chat_init", "Results: %s\n", str);
-
g_hash_table_destroy (chat_init_tab);
- g_object_unref (path);
json_node_free (root);
- json_node_free (result);
}
void
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
@@ -74,6 +74,45 @@ hangouts_util_parse (gchar *raw_data)
return chat_init_data;
}
+gchar *
+hangouts_util_add_null_values (gchar *string)
+{
+ gchar *dob_comma="";
+ gchar *brac_comma="";
+ gchar *start;
+ gchar *temp;
+
+ while (TRUE)
+ {
+ if (dob_comma == NULL && brac_comma == NULL)
+ {
+ break;
+ }
+ brac_comma = strstr (string, "[,");
+
+ if (brac_comma != NULL)
+ {
+ start = g_strndup (string, ++brac_comma - string);
+ temp = g_strdup_printf ("%snull%s", start, brac_comma);
+ string = temp;
+ }
+
+ dob_comma = strstr (string, ",,");
+ if (dob_comma != NULL)
+ {
+ start = g_strndup (string, ++dob_comma - string);
+ temp = g_strdup_printf ("%snull%s", start, dob_comma);
+ string = temp;
+ }
+ }
+
+ g_free (start);
+ g_free (brac_comma);
+ g_free (dob_comma);
+
+ return string;
+}
+
void
hangouts_util_add_node (gpointer key, gpointer value, gpointer data)
{
@@ -81,17 +120,20 @@ hangouts_util_add_node (gpointer key, gp
JsonParser *parser;
JsonNode *node;
gboolean parse_success;
+ gchar *string;
builder = data;
parser = json_parser_new ();
+ string = g_strcompress (value);
- parse_success = json_parser_load_from_data (parser, g_strcompress (value), -1,
+ parse_success = json_parser_load_from_data (parser, string, -1,
NULL);
if (!parse_success)
{
- //TODO add null values to string where missing for valid json
- return;
+ string = hangouts_util_add_null_values (string);
+ json_parser_load_from_data (parser, string, -1,
+ NULL);
}
node = json_parser_get_root (parser);
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
@@ -33,6 +33,9 @@ hangouts_util_escape_string (gchar *stri
GHashTable *
hangouts_util_parse (gchar *raw_data);
+gchar *
+hangouts_util_add_null_values(gchar *string);
+
void
hangouts_util_add_node (gpointer key, gpointer value, gpointer data);
More information about the Commits
mailing list