aboutsummaryrefslogtreecommitdiff
path: root/src/gns/plugin_rest_gns.c
diff options
context:
space:
mode:
authorPhil <phil.buschmann@tum.de>2018-07-26 02:31:30 +0200
committerPhil <phil.buschmann@tum.de>2018-07-26 02:31:30 +0200
commitf7ca27a73e69a8c224d65768be3416ff1388c1d7 (patch)
tree7530a6def74a55885780285162b18b4c2b353380 /src/gns/plugin_rest_gns.c
parentcc577a227d6a5ae8ef75e0fa91ef98ced2d2b743 (diff)
downloadgnunet-f7ca27a73e69a8c224d65768be3416ff1388c1d7.tar.gz
gnunet-f7ca27a73e69a8c224d65768be3416ff1388c1d7.zip
change namestore, json handling; fix identity, gns
Diffstat (limited to 'src/gns/plugin_rest_gns.c')
-rw-r--r--src/gns/plugin_rest_gns.c81
1 files changed, 41 insertions, 40 deletions
diff --git a/src/gns/plugin_rest_gns.c b/src/gns/plugin_rest_gns.c
index 22c908275..aae14153d 100644
--- a/src/gns/plugin_rest_gns.c
+++ b/src/gns/plugin_rest_gns.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2012-2015 GNUnet e.V. 3 Copyright (C) 2012-2015 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software: you can redistribute it and/or modify it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19 */ 17 */
20/** 18/**
21 * @author Philippe Buschmann 19 * @author Philippe Buschmann
@@ -36,6 +34,7 @@
36#define GNUNET_REST_PARAMETER_GNS_NAME "name" 34#define GNUNET_REST_PARAMETER_GNS_NAME "name"
37 35
38#define GNUNET_REST_PARAMETER_GNS_RECORD_TYPE "record_type" 36#define GNUNET_REST_PARAMETER_GNS_RECORD_TYPE "record_type"
37#define GNUNET_REST_GNS_ERROR_UNKNOWN "Unknown Error"
39 38
40/** 39/**
41 * The configuration handle 40 * The configuration handle
@@ -128,8 +127,9 @@ struct RequestHandle
128 * @param handle Handle to clean up 127 * @param handle Handle to clean up
129 */ 128 */
130static void 129static void
131cleanup_handle (struct RequestHandle *handle) 130cleanup_handle (void *cls)
132{ 131{
132 struct RequestHandle *handle = cls;
133 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 133 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
134 "Cleaning up\n"); 134 "Cleaning up\n");
135 135
@@ -170,20 +170,22 @@ do_error (void *cls)
170{ 170{
171 struct RequestHandle *handle = cls; 171 struct RequestHandle *handle = cls;
172 struct MHD_Response *resp; 172 struct MHD_Response *resp;
173 char *json_error; 173 json_t *json_error = json_object();
174 char *response;
174 175
175 if (NULL == handle->emsg) 176 if (NULL == handle->emsg)
176 handle->emsg = GNUNET_strdup("Unknown Error"); 177 handle->emsg = GNUNET_strdup(GNUNET_REST_GNS_ERROR_UNKNOWN);
178
179 json_object_set_new(json_error,"error", json_string(handle->emsg));
177 180
178 GNUNET_asprintf (&json_error, "{\"error\": \"%s\"}", handle->emsg);
179
180 if (0 == handle->response_code) 181 if (0 == handle->response_code)
181 handle->response_code = MHD_HTTP_OK; 182 handle->response_code = MHD_HTTP_OK;
182 183 response = json_dumps (json_error, 0);
183 resp = GNUNET_REST_create_response (json_error); 184 resp = GNUNET_REST_create_response (response);
184 handle->proc (handle->proc_cls, resp, handle->response_code); 185 handle->proc (handle->proc_cls, resp, handle->response_code);
185 cleanup_handle (handle); 186 json_decref(json_error);
186 GNUNET_free(json_error); 187 GNUNET_free(response);
188 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
187} 189}
188 190
189 191
@@ -201,6 +203,7 @@ handle_gns_response (void *cls,
201 uint32_t rd_count, 203 uint32_t rd_count,
202 const struct GNUNET_GNSRECORD_Data *rd) 204 const struct GNUNET_GNSRECORD_Data *rd)
203{ 205{
206 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "TEST4\n");
204 struct RequestHandle *handle = cls; 207 struct RequestHandle *handle = cls;
205 struct MHD_Response *resp; 208 struct MHD_Response *resp;
206 json_t *result_array; 209 json_t *result_array;
@@ -216,12 +219,6 @@ handle_gns_response (void *cls,
216 GNUNET_SCHEDULER_add_now (&do_error, handle); 219 GNUNET_SCHEDULER_add_now (&do_error, handle);
217 return; 220 return;
218 } 221 }
219 if (0 == rd_count)
220 {
221 handle->emsg = GNUNET_strdup("No result found");
222 GNUNET_SCHEDULER_add_now (&do_error, handle);
223 return;
224 }
225 222
226 result_array = json_array(); 223 result_array = json_array();
227 for (uint32_t i=0;i<rd_count;i++) 224 for (uint32_t i=0;i<rd_count;i++)
@@ -246,7 +243,7 @@ handle_gns_response (void *cls,
246 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 243 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
247 GNUNET_free (result); 244 GNUNET_free (result);
248 json_decref (result_array); 245 json_decref (result_array);
249 cleanup_handle (handle); 246 GNUNET_SCHEDULER_add_now(&cleanup_handle, handle);
250} 247}
251 248
252 249
@@ -264,7 +261,8 @@ get_gns_cont (struct GNUNET_REST_RequestHandle *con_handle,
264{ 261{
265 struct RequestHandle *handle = cls; 262 struct RequestHandle *handle = cls;
266 struct GNUNET_HashCode key; 263 struct GNUNET_HashCode key;
267 int conversion_state; 264 char *record_type;
265 char *name;
268 266
269 GNUNET_CRYPTO_hash (GNUNET_REST_PARAMETER_GNS_NAME, 267 GNUNET_CRYPTO_hash (GNUNET_REST_PARAMETER_GNS_NAME,
270 strlen (GNUNET_REST_PARAMETER_GNS_NAME), 268 strlen (GNUNET_REST_PARAMETER_GNS_NAME),
@@ -277,8 +275,14 @@ get_gns_cont (struct GNUNET_REST_RequestHandle *con_handle,
277 GNUNET_SCHEDULER_add_now (&do_error, handle); 275 GNUNET_SCHEDULER_add_now (&do_error, handle);
278 return; 276 return;
279 } 277 }
280 handle->name = GNUNET_strdup( 278 name = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map,&key);
281 GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map,&key)); 279 if(0 >= strlen (name))
280 {
281 handle->emsg = GNUNET_strdup("Length of parameter name is zero");
282 GNUNET_SCHEDULER_add_now (&do_error, handle);
283 return;
284 }
285 handle->name = GNUNET_strdup(name);
282 286
283 GNUNET_CRYPTO_hash (GNUNET_REST_PARAMETER_GNS_RECORD_TYPE, 287 GNUNET_CRYPTO_hash (GNUNET_REST_PARAMETER_GNS_RECORD_TYPE,
284 strlen (GNUNET_REST_PARAMETER_GNS_RECORD_TYPE), 288 strlen (GNUNET_REST_PARAMETER_GNS_RECORD_TYPE),
@@ -291,11 +295,13 @@ get_gns_cont (struct GNUNET_REST_RequestHandle *con_handle,
291 GNUNET_SCHEDULER_add_now (&do_error, handle); 295 GNUNET_SCHEDULER_add_now (&do_error, handle);
292 return; 296 return;
293 } 297 }
294 conversion_state = sscanf (
295 GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, &key),"%u",
296 &(handle->record_type));
297 298
298 if((EOF == conversion_state) || (0 == conversion_state)) 299
300 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "TEST1\n");
301
302 record_type = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, &key);
303 handle->record_type = GNUNET_GNSRECORD_typename_to_number(record_type);
304 if(UINT32_MAX == handle->record_type)
299 { 305 {
300 handle->record_type = GNUNET_GNSRECORD_TYPE_ANY; 306 handle->record_type = GNUNET_GNSRECORD_TYPE_ANY;
301 } 307 }
@@ -307,6 +313,7 @@ get_gns_cont (struct GNUNET_REST_RequestHandle *con_handle,
307 GNUNET_SCHEDULER_add_now (&do_error, handle); 313 GNUNET_SCHEDULER_add_now (&do_error, handle);
308 return; 314 return;
309 } 315 }
316 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "TEST2\n");
310 317
311 handle->gns_lookup = GNUNET_GNS_lookup_with_tld (handle->gns, 318 handle->gns_lookup = GNUNET_GNS_lookup_with_tld (handle->gns,
312 handle->name, 319 handle->name,
@@ -314,13 +321,7 @@ get_gns_cont (struct GNUNET_REST_RequestHandle *con_handle,
314 GNUNET_NO, 321 GNUNET_NO,
315 &handle_gns_response, 322 &handle_gns_response,
316 handle); 323 handle);
317 324 return;
318 if (NULL == handle->gns_lookup)
319 {
320 handle->emsg = GNUNET_strdup("GNS lookup failed");
321 GNUNET_SCHEDULER_add_now (&do_error, handle);
322 return;
323 }
324} 325}
325 326
326 327
@@ -346,7 +347,7 @@ options_cont (struct GNUNET_REST_RequestHandle *con_handle,
346 "Access-Control-Allow-Methods", 347 "Access-Control-Allow-Methods",
347 allow_methods); 348 allow_methods);
348 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 349 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
349 cleanup_handle (handle); 350 GNUNET_SCHEDULER_add_now(&cleanup_handle, handle);
350 return; 351 return;
351} 352}
352 353