aboutsummaryrefslogtreecommitdiff
path: root/src/json
diff options
context:
space:
mode:
authorPhil <phil.buschmann@tum.de>2018-07-25 21:57:49 +0200
committerPhil <phil.buschmann@tum.de>2018-07-25 21:57:49 +0200
commitcc577a227d6a5ae8ef75e0fa91ef98ced2d2b743 (patch)
tree07084e1aa8a37dc0dc4d15fe0724801d7867157a /src/json
parent4992eacc10bedaa0edfa03b401253408c6267798 (diff)
downloadgnunet-cc577a227d6a5ae8ef75e0fa91ef98ced2d2b743.tar.gz
gnunet-cc577a227d6a5ae8ef75e0fa91ef98ced2d2b743.zip
-wip namestore api, changed adding gnsrecord
Diffstat (limited to 'src/json')
-rw-r--r--src/json/Makefile.am3
-rw-r--r--src/json/json_parser.c169
2 files changed, 1 insertions, 171 deletions
diff --git a/src/json/Makefile.am b/src/json/Makefile.am
index 5aac23654..16c0450d9 100644
--- a/src/json/Makefile.am
+++ b/src/json/Makefile.am
@@ -16,8 +16,7 @@ libgnunetjson_la_SOURCES = \
16 json.c \ 16 json.c \
17 json_mhd.c \ 17 json_mhd.c \
18 json_generator.c \ 18 json_generator.c \
19 json_helper.c \ 19 json_helper.c
20 json_parser.c
21libgnunetjson_la_LIBADD = \ 20libgnunetjson_la_LIBADD = \
22 $(top_builddir)/src/util/libgnunetutil.la \ 21 $(top_builddir)/src/util/libgnunetutil.la \
23 -ljansson \ 22 -ljansson \
diff --git a/src/json/json_parser.c b/src/json/json_parser.c
deleted file mode 100644
index cfe553b34..000000000
--- a/src/json/json_parser.c
+++ /dev/null
@@ -1,169 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2014, 2015, 2016 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18/**
19 * @file json/json_helper.c
20 * @brief functions for REST JSON parsing
21 * @author Philippe Buschmann
22 */
23
24#include "platform.h"
25#include "gnunet_util_lib.h"
26#include "gnunet_json_lib.h"
27
28#define GNUNET_REST_JSON_PUBKEY_ENTRY "pubkey"
29#define GNUNET_REST_JSON_NAME_ENTRY "name"
30#define GNUNET_REST_JSON_NICKNAME_ENTRY "nickname"
31#define GNUNET_REST_JSON_NEWNAME_ENTRY "newname"
32#define GNUNET_REST_JSON_SUBSYSTEM_ENTRY "subsystem"
33#define GNUNET_REST_JSON_IS_PUBLIC_ENTRY "is_public"
34#define GNUNET_REST_JSON_EXPIRATION_DATE_ENTRY "expiration_time"
35#define GNUNET_REST_JSON_TYPE_ENTRY "type"
36#define GNUNET_REST_JSON_VALUE_ENTRY "value"
37#define GNUNET_REST_JSON_ZONE_ENTRY "zone"
38
39
40int
41GNUNET_REST_JSON_parse (struct GNUNET_REST_JSON_Data** output_data ,json_t *json_data)
42{
43 struct GNUNET_REST_JSON_Data *rest_json_data;
44 json_t *cache;
45
46 rest_json_data = GNUNET_malloc(sizeof(struct GNUNET_REST_JSON_Data));
47
48 cache = json_object_get (json_data, GNUNET_REST_JSON_EXPIRATION_DATE_ENTRY);
49 rest_json_data->expiration_time = NULL;
50 if (NULL != cache)
51 {
52 if (json_is_string(cache))
53 {
54 rest_json_data->expiration_time = GNUNET_strdup(json_string_value(cache));
55 }
56 }
57 cache = json_object_get (json_data, GNUNET_REST_JSON_NAME_ENTRY);
58 rest_json_data->name = NULL;
59 if (NULL != cache)
60 {
61 if (json_is_string(cache))
62 {
63 rest_json_data->name = GNUNET_strdup(json_string_value(cache));
64 }
65 }
66 cache = json_object_get (json_data, GNUNET_REST_JSON_NEWNAME_ENTRY);
67 rest_json_data->new_name = NULL;
68 if (NULL != cache)
69 {
70 if (json_is_string(cache))
71 {
72 rest_json_data->new_name = GNUNET_strdup(json_string_value(cache));
73 }
74 }
75 cache = json_object_get (json_data, GNUNET_REST_JSON_NICKNAME_ENTRY);
76 rest_json_data->nickname = NULL;
77 if (NULL != cache)
78 {
79 if (json_is_string(cache))
80 {
81 rest_json_data->nickname = GNUNET_strdup(json_string_value(cache));
82 }
83 }
84 cache = json_object_get (json_data, GNUNET_REST_JSON_PUBKEY_ENTRY);
85 rest_json_data->pubkey = NULL;
86 if (NULL != cache)
87 {
88 if (json_is_string(cache))
89 {
90 rest_json_data->pubkey = GNUNET_strdup(json_string_value(cache));
91 }
92 }
93 cache = json_object_get (json_data, GNUNET_REST_JSON_SUBSYSTEM_ENTRY);
94 rest_json_data->subsystem = NULL;
95 if (NULL != cache)
96 {
97 if (json_is_string(cache))
98 {
99 rest_json_data->subsystem = GNUNET_strdup(json_string_value(cache));
100 }
101 }
102 cache = json_object_get (json_data, GNUNET_REST_JSON_TYPE_ENTRY);
103 rest_json_data->type = NULL;
104 if (NULL != cache)
105 {
106 if (json_is_string(cache))
107 {
108 rest_json_data->type = GNUNET_strdup(json_string_value(cache));
109 }
110 }
111 cache = json_object_get (json_data, GNUNET_REST_JSON_VALUE_ENTRY);
112 rest_json_data->value = NULL;
113 if (NULL != cache)
114 {
115 if (json_is_string(cache))
116 {
117 rest_json_data->value = GNUNET_strdup(json_string_value(cache));
118 }
119 }
120 cache = json_object_get (json_data, GNUNET_REST_JSON_ZONE_ENTRY);
121 rest_json_data->zone = NULL;
122 if (NULL != cache)
123 {
124 if (json_is_string(cache))
125 {
126 rest_json_data->zone = GNUNET_strdup(json_string_value(cache));
127 }
128 }
129 cache = json_object_get (json_data, GNUNET_REST_JSON_IS_PUBLIC_ENTRY);
130 if (NULL != cache)
131 {
132 if (json_is_integer(cache))
133 {
134 rest_json_data->is_public = json_integer_value(cache);
135 }
136 }
137 *output_data = rest_json_data;
138 return GNUNET_OK;
139}
140
141
142
143int
144GNUNET_REST_JSON_free (struct GNUNET_REST_JSON_Data* rest_json_data)
145{
146 if (rest_json_data != NULL)
147 {
148 GNUNET_free_non_null(rest_json_data->expiration_time);
149 GNUNET_free_non_null(rest_json_data->name);
150 GNUNET_free_non_null(rest_json_data->new_name);
151 GNUNET_free_non_null(rest_json_data->nickname);
152 GNUNET_free_non_null(rest_json_data->pubkey);
153 GNUNET_free_non_null(rest_json_data->subsystem);
154 GNUNET_free_non_null(rest_json_data->type);
155 GNUNET_free_non_null(rest_json_data->value);
156 GNUNET_free_non_null(rest_json_data->zone);
157 }
158 GNUNET_free_non_null(rest_json_data);
159 return GNUNET_OK;
160}
161
162
163
164
165
166
167
168
169