diff options
author | Richard van der Hoff <richard@matrix.org> | 2015-10-16 12:46:28 +0100 |
---|---|---|
committer | Richard van der Hoff <richard@matrix.org> | 2015-10-16 12:46:28 +0100 |
commit | f329642569a47e273e92671aee3e3cf88118d079 (patch) | |
tree | 8c5fba8eb6815f98c2a4a93d47af9bfbce50219a /matrix-json.c | |
parent | 80af6b59c5cc7dbf927abab8a52b185590653918 (diff) | |
download | purple-matrix-f329642569a47e273e92671aee3e3cf88118d079.tar.gz |
Initial attempts at displaying a room in pidgin
Not quite sure if this is the right approach yet - in particular, purple
distinguishes between active 'conversations', as opposed to 'chats' in the
buddy list. Which should our chats be?
Diffstat (limited to 'matrix-json.c')
-rw-r--r-- | matrix-json.c | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/matrix-json.c b/matrix-json.c new file mode 100644 index 0000000..3cf6d0c --- /dev/null +++ b/matrix-json.c @@ -0,0 +1,111 @@ +/* + * matrix-json.c + * + * Convenience wrappers for libglib-json + * + * 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 "matrix-json.h" + +/* node */ + +const gchar *matrix_json_node_get_string(JsonNode *node) +{ + if(node == NULL) + return NULL; + if(JSON_NODE_TYPE(node) != JSON_NODE_VALUE) + return NULL; + return json_node_get_string(node); +} + +JsonObject *matrix_json_node_get_object (JsonNode *node) +{ + if(node == NULL) + return NULL; + if(JSON_NODE_TYPE(node) != JSON_NODE_OBJECT) + return NULL; + return json_node_get_object(node); +} + +JsonArray *matrix_json_node_get_array(JsonNode *node) +{ + if(node == NULL) + return NULL; + if(JSON_NODE_TYPE(node) != JSON_NODE_ARRAY) + return NULL; + return json_node_get_array(node); +} + + + +/* object */ + +JsonNode *matrix_json_object_get_member (JsonObject *object, + const gchar *member_name) +{ + g_assert(member_name != NULL); + + if(object == NULL) + return NULL; + + return json_object_get_member(object, member_name); +} + +const gchar *matrix_json_object_get_string_member(JsonObject *object, + const gchar *member_name) +{ + JsonNode *member; + member = matrix_json_object_get_member(object, member_name); + return matrix_json_node_get_string(member); +} + +JsonObject *matrix_json_object_get_object_member(JsonObject *object, + const gchar *member_name) +{ + JsonNode *member; + member = matrix_json_object_get_member(object, member_name); + return matrix_json_node_get_object(member); +} + + +JsonArray *matrix_json_object_get_array_member(JsonObject *object, + const gchar *member_name) +{ + JsonNode *member; + member = matrix_json_object_get_member(object, member_name); + return matrix_json_node_get_array(member); +} + + + +/* array */ +JsonNode *matrix_json_array_get_element(JsonArray *array, + guint index) +{ + if(array == NULL) + return NULL; + if(json_array_get_length(array) <= index) + return NULL; + return json_array_get_element(array, index); +} + +const gchar *matrix_json_array_get_string_element(JsonArray *array, + guint index) +{ + JsonNode *element; + element = matrix_json_array_get_element(array, index); + return matrix_json_node_get_string(element); +} |