/soc/2015/nakulgulati/main: 5a053435beb8: hangouts: json wrappers
Nakul at rock.pidgin.im
Nakul at rock.pidgin.im
Wed Aug 12 12:42:04 EDT 2015
Changeset: 5a053435beb89f301cd2e103b7a7a56e45c26fc2
Author: Nakul Gulati
Date: 2015-08-13 00:41 +0800
Branch: hangouts
URL: https://hg.pidgin.im/soc/2015/nakulgulati/main/rev/5a053435beb8
Description:
hangouts: json wrappers
diffstat:
libpurple/protocols/hangouts/json.c | 85 +++++++++++++++++++++++++++++++++++++
libpurple/protocols/hangouts/json.h | 37 ++++++++++++++++
2 files changed, 122 insertions(+), 0 deletions(-)
diffs (132 lines):
diff --git a/libpurple/protocols/hangouts/json.c b/libpurple/protocols/hangouts/json.c
new file mode 100644
--- /dev/null
+++ b/libpurple/protocols/hangouts/json.c
@@ -0,0 +1,85 @@
+/* purple
+ *
+ * Purple is the legal property of its developers, whose names are too numerous
+ * to list here. Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ */
+
+#include "debug.h"
+
+#include "json.h"
+
+JsonNode *
+hangouts_json_node_new (gchar *data, gssize length, gboolean empty_values)
+{
+ JsonNode *root;
+ JsonParser *parser;
+
+ parser = json_parser_new ();
+
+ if (!json_parser_load_from_data (parser, data, length, NULL))
+ {
+ g_object_unref (parser);
+ return NULL;
+ }
+
+ root = json_parser_get_root (parser);
+ root = json_node_copy (root);
+
+ return root;
+}
+
+JsonNode *
+hangouts_json_node_get (JsonNode *root, const gchar *expr, GError **error)
+{
+ JsonNode *ret;
+ JsonNode *node;
+ JsonArray *result;
+
+ node = json_path_query (expr, root, &error);
+
+ if (error != NULL)
+ {
+ json_node_free (node);
+ return NULL;
+ }
+
+ result = json_node_get_array (node);
+
+ ret = json_array_dup_element (result, 0);
+ json_node_free (node);
+ return ret;
+
+}
+
+gchar *
+hangouts_json_node_get_str (JsonNode *root, const gchar *expr, GError **error)
+{
+ gchar *ret;
+ JsonNode *rslt;
+
+ rslt = hangouts_json_node_get (root, expr, error);
+
+ if (rslt == NULL)
+ {
+ return NULL;
+ }
+
+ ret = json_node_dup_string (rslt);
+ json_node_free (rslt);
+ return ret;
+}
diff --git a/libpurple/protocols/hangouts/json.h b/libpurple/protocols/hangouts/json.h
new file mode 100644
--- /dev/null
+++ b/libpurple/protocols/hangouts/json.h
@@ -0,0 +1,37 @@
+/* purple
+ *
+ * Purple is the legal property of its developers, whose names are too numerous
+ * to list here. Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ */
+
+#ifndef _HANGOUTS_JSON_H_
+#define _HANGOUTS_JSON_H_
+
+#include <glib.h>
+#include <json-glib/json-glib.h>
+
+JsonNode *
+hangouts_json_node_new (gchar *data, gssize length, gboolean empty_values);
+
+JsonNode *
+hangouts_json_node_get (JsonNode *root, const gchar *expr, GError **error);
+
+gchar *
+hangouts_json_node_get_str (JsonNode *root, const gchar *expr, GError **error);
+
+#endif /* _HANGOUTS_JSON_H */
More information about the Commits
mailing list