diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2015-03-11 17:39:32 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2015-03-11 17:39:32 +0000 |
commit | b5cb8ce9b34d0f8cf2eb19cf82680aca365d157f (patch) | |
tree | 7db300f694ca75a5fcd5fc81bc59db30f67fb641 /src/gns | |
parent | 86882d3e761fe639e833446ccfef8d31e0e42998 (diff) | |
download | gnunet-b5cb8ce9b34d0f8cf2eb19cf82680aca365d157f.tar.gz gnunet-b5cb8ce9b34d0f8cf2eb19cf82680aca365d157f.zip |
- fixes, intendation
Diffstat (limited to 'src/gns')
-rw-r--r-- | src/gns/plugin_rest_gns.c | 648 |
1 files changed, 334 insertions, 314 deletions
diff --git a/src/gns/plugin_rest_gns.c b/src/gns/plugin_rest_gns.c index bd28c23f3..d5d6788c8 100644 --- a/src/gns/plugin_rest_gns.c +++ b/src/gns/plugin_rest_gns.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2012-2015 Christian Grothoff (and other contributing authors) | 3 | Copyright (C) 2012-2015 Christian Grothoff (and other contributing authors) |
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 |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU 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, or (at your |
8 | option) any later version. | 8 | 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 | 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 General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with GNUnet; see the file COPYING. If not, write to the |
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @author Martin Schanzenbach | 21 | * @author Martin Schanzenbach |
22 | * @file gns/plugin_rest_gns.c | 22 | * @file gns/plugin_rest_gns.c |
@@ -47,103 +47,145 @@ const struct GNUNET_CONFIGURATION_Handle *cfg; | |||
47 | 47 | ||
48 | struct LookupHandle | 48 | struct LookupHandle |
49 | { | 49 | { |
50 | /** | 50 | /** |
51 | * Handle to GNS service. | 51 | * Handle to GNS service. |
52 | */ | 52 | */ |
53 | struct GNUNET_GNS_Handle *gns; | 53 | struct GNUNET_GNS_Handle *gns; |
54 | 54 | ||
55 | /** | 55 | /** |
56 | * Desired timeout for the lookup (default is no timeout). | 56 | * Desired timeout for the lookup (default is no timeout). |
57 | */ | 57 | */ |
58 | struct GNUNET_TIME_Relative timeout; | 58 | struct GNUNET_TIME_Relative timeout; |
59 | 59 | ||
60 | /** | 60 | /** |
61 | * Handle to lookup request | 61 | * Handle to lookup request |
62 | */ | 62 | */ |
63 | struct GNUNET_GNS_LookupRequest *lookup_request; | 63 | struct GNUNET_GNS_LookupRequest *lookup_request; |
64 | 64 | ||
65 | /** | 65 | /** |
66 | * Lookup an ego with the identity service. | 66 | * Lookup an ego with the identity service. |
67 | */ | 67 | */ |
68 | struct GNUNET_IDENTITY_EgoLookup *el; | 68 | struct GNUNET_IDENTITY_EgoLookup *el; |
69 | 69 | ||
70 | /** | 70 | /** |
71 | * Handle for identity service. | 71 | * Handle for identity service. |
72 | */ | 72 | */ |
73 | struct GNUNET_IDENTITY_Handle *identity; | 73 | struct GNUNET_IDENTITY_Handle *identity; |
74 | 74 | ||
75 | /** | 75 | /** |
76 | * Active operation on identity service. | 76 | * Active operation on identity service. |
77 | */ | 77 | */ |
78 | struct GNUNET_IDENTITY_Operation *id_op; | 78 | struct GNUNET_IDENTITY_Operation *id_op; |
79 | /** | 79 | |
80 | * ID of a task associated with the resolution process. | 80 | /** |
81 | */ | 81 | * ID of a task associated with the resolution process. |
82 | struct GNUNET_SCHEDULER_Task * timeout_task; | 82 | */ |
83 | 83 | struct GNUNET_SCHEDULER_Task * timeout_task; | |
84 | json_t *json_root; | 84 | |
85 | 85 | /** | |
86 | GNUNET_REST_ResultProcessor proc; | 86 | * The root of the received JSON or NULL |
87 | 87 | */ | |
88 | char *name; | 88 | json_t *json_root; |
89 | 89 | ||
90 | const char *ego_str; | 90 | /** |
91 | 91 | * The plugin result processor | |
92 | const char *pkey_str; | 92 | */ |
93 | 93 | GNUNET_REST_ResultProcessor proc; | |
94 | int type; | 94 | |
95 | 95 | /** | |
96 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; | 96 | * The closure of the result processor |
97 | 97 | */ | |
98 | struct GNUNET_CRYPTO_EcdsaPublicKey pkeym; | 98 | void *proc_cls; |
99 | 99 | ||
100 | enum GNUNET_GNS_LocalOptions options; | 100 | /** |
101 | 101 | * The name to look up | |
102 | struct GNUNET_CRYPTO_EcdsaPrivateKey shorten_key; | 102 | */ |
103 | void *proc_cls; | 103 | char *name; |
104 | |||
105 | /** | ||
106 | * The ego to use | ||
107 | * In string representation from JSON | ||
108 | */ | ||
109 | const char *ego_str; | ||
110 | |||
111 | /** | ||
112 | * The Pkey to use | ||
113 | * In stirng representation from JSON | ||
114 | */ | ||
115 | const char *pkey_str; | ||
116 | |||
117 | /** | ||
118 | * The record type to look up | ||
119 | */ | ||
120 | int type; | ||
121 | |||
122 | /** | ||
123 | * The public key of to use for lookup | ||
124 | */ | ||
125 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; | ||
126 | |||
127 | /** | ||
128 | * The public key to use for lookup | ||
129 | */ | ||
130 | struct GNUNET_CRYPTO_EcdsaPublicKey pkeym; | ||
131 | |||
132 | /** | ||
133 | * The resolver options | ||
134 | */ | ||
135 | enum GNUNET_GNS_LocalOptions options; | ||
136 | |||
137 | /** | ||
138 | * the shorten key | ||
139 | */ | ||
140 | struct GNUNET_CRYPTO_EcdsaPrivateKey shorten_key; | ||
141 | |||
104 | }; | 142 | }; |
105 | 143 | ||
144 | /** | ||
145 | * Cleanup lookup handle | ||
146 | * @praram handle Handle to clean up | ||
147 | */ | ||
106 | void | 148 | void |
107 | cleanup_handle (struct LookupHandle *handle) | 149 | cleanup_handle (struct LookupHandle *handle) |
108 | { | 150 | { |
109 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 151 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
110 | "Cleaning up\n"); | 152 | "Cleaning up\n"); |
111 | if (NULL != handle->json_root) | 153 | if (NULL != handle->json_root) |
112 | json_decref (handle->json_root); | 154 | json_decref (handle->json_root); |
113 | 155 | ||
114 | if (NULL != handle->name) | 156 | if (NULL != handle->name) |
115 | GNUNET_free (handle->name); | 157 | GNUNET_free (handle->name); |
116 | if (NULL != handle->el) | 158 | if (NULL != handle->el) |
117 | { | 159 | { |
118 | GNUNET_IDENTITY_ego_lookup_cancel (handle->el); | 160 | GNUNET_IDENTITY_ego_lookup_cancel (handle->el); |
119 | handle->el = NULL; | 161 | handle->el = NULL; |
120 | } | 162 | } |
121 | if (NULL != handle->id_op) | 163 | if (NULL != handle->id_op) |
122 | { | 164 | { |
123 | GNUNET_IDENTITY_cancel (handle->id_op); | 165 | GNUNET_IDENTITY_cancel (handle->id_op); |
124 | handle->id_op = NULL; | 166 | handle->id_op = NULL; |
125 | } | 167 | } |
126 | if (NULL != handle->lookup_request) | 168 | if (NULL != handle->lookup_request) |
127 | { | 169 | { |
128 | GNUNET_GNS_lookup_cancel (handle->lookup_request); | 170 | GNUNET_GNS_lookup_cancel (handle->lookup_request); |
129 | handle->lookup_request = NULL; | 171 | handle->lookup_request = NULL; |
130 | } | 172 | } |
131 | if (NULL != handle->identity) | 173 | if (NULL != handle->identity) |
132 | { | 174 | { |
133 | GNUNET_IDENTITY_disconnect (handle->identity); | 175 | GNUNET_IDENTITY_disconnect (handle->identity); |
134 | handle->identity = NULL; | 176 | handle->identity = NULL; |
135 | } | 177 | } |
136 | if (NULL != handle->gns) | 178 | if (NULL != handle->gns) |
137 | { | 179 | { |
138 | GNUNET_GNS_disconnect (handle->gns); | 180 | GNUNET_GNS_disconnect (handle->gns); |
139 | handle->gns = NULL; | 181 | handle->gns = NULL; |
140 | } | 182 | } |
141 | 183 | ||
142 | if (NULL != handle->timeout_task) | 184 | if (NULL != handle->timeout_task) |
143 | { | 185 | { |
144 | GNUNET_SCHEDULER_cancel (handle->timeout_task); | 186 | GNUNET_SCHEDULER_cancel (handle->timeout_task); |
145 | } | 187 | } |
146 | GNUNET_free (handle); | 188 | GNUNET_free (handle); |
147 | } | 189 | } |
148 | 190 | ||
149 | 191 | ||
@@ -155,12 +197,11 @@ cleanup_handle (struct LookupHandle *handle) | |||
155 | */ | 197 | */ |
156 | static void | 198 | static void |
157 | do_error (void *cls, | 199 | do_error (void *cls, |
158 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 200 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
159 | { | 201 | { |
160 | struct LookupHandle *handle = cls; | 202 | struct LookupHandle *handle = cls; |
161 | |||
162 | cleanup_handle (handle); | ||
163 | handle->proc (handle->proc_cls, NULL, 0, GNUNET_SYSERR); | 203 | handle->proc (handle->proc_cls, NULL, 0, GNUNET_SYSERR); |
204 | cleanup_handle (handle); | ||
164 | } | 205 | } |
165 | 206 | ||
166 | /** | 207 | /** |
@@ -172,10 +213,8 @@ do_error (void *cls, | |||
172 | */ | 213 | */ |
173 | static void | 214 | static void |
174 | process_lookup_result (void *cls, uint32_t rd_count, | 215 | process_lookup_result (void *cls, uint32_t rd_count, |
175 | const struct GNUNET_GNSRECORD_Data *rd) | 216 | const struct GNUNET_GNSRECORD_Data *rd) |
176 | { | 217 | { |
177 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
178 | "result \n"); | ||
179 | struct LookupHandle *handle = cls; | 218 | struct LookupHandle *handle = cls; |
180 | uint32_t i; | 219 | uint32_t i; |
181 | const char *typename; | 220 | const char *typename; |
@@ -186,30 +225,28 @@ process_lookup_result (void *cls, uint32_t rd_count, | |||
186 | json_t *result_array; | 225 | json_t *result_array; |
187 | json_t *record_obj; | 226 | json_t *record_obj; |
188 | 227 | ||
189 | |||
190 | result_root = json_object(); | 228 | result_root = json_object(); |
191 | result_name = json_string (handle->name); | 229 | result_name = json_string (handle->name); |
192 | result_array = json_array(); | 230 | result_array = json_array(); |
193 | json_object_set (result_root, "name", result_name); | 231 | json_object_set (result_root, "name", result_name); |
194 | json_decref (result_name); | 232 | json_decref (result_name); |
195 | |||
196 | handle->lookup_request = NULL; | 233 | handle->lookup_request = NULL; |
197 | 234 | ||
198 | for (i=0; i<rd_count; i++) | 235 | for (i=0; i<rd_count; i++) |
199 | { | 236 | { |
200 | if ( (rd[i].record_type != handle->type) && | 237 | if ( (rd[i].record_type != handle->type) && |
201 | (GNUNET_GNSRECORD_TYPE_ANY != handle->type) ) | 238 | (GNUNET_GNSRECORD_TYPE_ANY != handle->type) ) |
202 | continue; | 239 | continue; |
203 | typename = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type); | 240 | typename = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type); |
204 | string_val = GNUNET_GNSRECORD_value_to_string (rd[i].record_type, | 241 | string_val = GNUNET_GNSRECORD_value_to_string (rd[i].record_type, |
205 | rd[i].data, | 242 | rd[i].data, |
206 | rd[i].data_size); | 243 | rd[i].data_size); |
207 | if (NULL == string_val) | 244 | if (NULL == string_val) |
208 | { | 245 | { |
209 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 246 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
210 | "Record %u of type %d malformed, skipping\n", | 247 | "Record %u of type %d malformed, skipping\n", |
211 | (unsigned int) i, | 248 | (unsigned int) i, |
212 | (int) rd[i].record_type); | 249 | (int) rd[i].record_type); |
213 | continue; | 250 | continue; |
214 | } | 251 | } |
215 | else | 252 | else |
@@ -242,30 +279,27 @@ process_lookup_result (void *cls, uint32_t rd_count, | |||
242 | static void | 279 | static void |
243 | lookup_with_keys (struct LookupHandle *handle, const struct GNUNET_CRYPTO_EcdsaPrivateKey *shorten_key) | 280 | lookup_with_keys (struct LookupHandle *handle, const struct GNUNET_CRYPTO_EcdsaPrivateKey *shorten_key) |
244 | { | 281 | { |
245 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
246 | "Lookup w/ keys \n"); | ||
247 | if (UINT32_MAX == handle->type) | 282 | if (UINT32_MAX == handle->type) |
248 | { | 283 | { |
249 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 284 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
250 | _("Invalid typename specified, assuming `ANY'\n")); | 285 | _("Invalid typename specified, assuming `ANY'\n")); |
251 | handle->type = GNUNET_GNSRECORD_TYPE_ANY; | 286 | handle->type = GNUNET_GNSRECORD_TYPE_ANY; |
252 | } | 287 | } |
253 | |||
254 | if (NULL != handle->name) | 288 | if (NULL != handle->name) |
255 | { | 289 | { |
256 | handle->lookup_request = GNUNET_GNS_lookup (handle->gns, | 290 | handle->lookup_request = GNUNET_GNS_lookup (handle->gns, |
257 | handle->name, | 291 | handle->name, |
258 | &handle->pkey, | 292 | &handle->pkey, |
259 | handle->type, | 293 | handle->type, |
260 | handle->options, | 294 | handle->options, |
261 | shorten_key, | 295 | shorten_key, |
262 | &process_lookup_result, | 296 | &process_lookup_result, |
263 | handle); | 297 | handle); |
264 | } | 298 | } |
265 | else | 299 | else |
266 | { | 300 | { |
267 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 301 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
268 | _("Please specify name to lookup!\n")); | 302 | _("Please specify name to lookup!\n")); |
269 | handle->proc (handle->proc_cls, NULL, 0, GNUNET_SYSERR); | 303 | handle->proc (handle->proc_cls, NULL, 0, GNUNET_SYSERR); |
270 | cleanup_handle (handle); | 304 | cleanup_handle (handle); |
271 | return; | 305 | return; |
@@ -286,12 +320,10 @@ lookup_with_keys (struct LookupHandle *handle, const struct GNUNET_CRYPTO_EcdsaP | |||
286 | */ | 320 | */ |
287 | static void | 321 | static void |
288 | identity_shorten_cb (void *cls, | 322 | identity_shorten_cb (void *cls, |
289 | struct GNUNET_IDENTITY_Ego *ego, | 323 | struct GNUNET_IDENTITY_Ego *ego, |
290 | void **ctx, | 324 | void **ctx, |
291 | const char *name) | 325 | const char *name) |
292 | { | 326 | { |
293 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
294 | "shorten \n"); | ||
295 | struct LookupHandle *handle = cls; | 327 | struct LookupHandle *handle = cls; |
296 | 328 | ||
297 | handle->id_op = NULL; | 329 | handle->id_op = NULL; |
@@ -299,7 +331,7 @@ identity_shorten_cb (void *cls, | |||
299 | lookup_with_keys (handle, NULL); | 331 | lookup_with_keys (handle, NULL); |
300 | else | 332 | else |
301 | lookup_with_keys (handle, | 333 | lookup_with_keys (handle, |
302 | GNUNET_IDENTITY_ego_get_private_key (ego)); | 334 | GNUNET_IDENTITY_ego_get_private_key (ego)); |
303 | } | 335 | } |
304 | 336 | ||
305 | /** | 337 | /** |
@@ -311,14 +343,12 @@ identity_shorten_cb (void *cls, | |||
311 | static void | 343 | static void |
312 | lookup_with_public_key (struct LookupHandle *handle) | 344 | lookup_with_public_key (struct LookupHandle *handle) |
313 | { | 345 | { |
314 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
315 | "Lookup w/ pkey \n"); | ||
316 | handle->pkeym = handle->pkey; | 346 | handle->pkeym = handle->pkey; |
317 | GNUNET_break (NULL == handle->id_op); | 347 | GNUNET_break (NULL == handle->id_op); |
318 | handle->id_op = GNUNET_IDENTITY_get (handle->identity, | 348 | handle->id_op = GNUNET_IDENTITY_get (handle->identity, |
319 | "gns-short", | 349 | "gns-short", |
320 | &identity_shorten_cb, | 350 | &identity_shorten_cb, |
321 | handle); | 351 | handle); |
322 | if (NULL == handle->id_op) | 352 | if (NULL == handle->id_op) |
323 | { | 353 | { |
324 | GNUNET_break (0); | 354 | GNUNET_break (0); |
@@ -335,7 +365,7 @@ lookup_with_public_key (struct LookupHandle *handle) | |||
335 | */ | 365 | */ |
336 | static void | 366 | static void |
337 | identity_zone_cb (void *cls, | 367 | identity_zone_cb (void *cls, |
338 | const struct GNUNET_IDENTITY_Ego *ego) | 368 | const struct GNUNET_IDENTITY_Ego *ego) |
339 | { | 369 | { |
340 | struct LookupHandle *handle = cls; | 370 | struct LookupHandle *handle = cls; |
341 | 371 | ||
@@ -343,7 +373,7 @@ identity_zone_cb (void *cls, | |||
343 | if (NULL == ego) | 373 | if (NULL == ego) |
344 | { | 374 | { |
345 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 375 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
346 | _("Ego for not found, cannot perform lookup.\n")); | 376 | _("Ego for not found, cannot perform lookup.\n")); |
347 | handle->proc (handle->proc_cls, NULL, 0, GNUNET_SYSERR); | 377 | handle->proc (handle->proc_cls, NULL, 0, GNUNET_SYSERR); |
348 | cleanup_handle (handle); | 378 | cleanup_handle (handle); |
349 | return; | 379 | return; |
@@ -370,20 +400,18 @@ identity_zone_cb (void *cls, | |||
370 | */ | 400 | */ |
371 | static void | 401 | static void |
372 | identity_master_cb (void *cls, | 402 | identity_master_cb (void *cls, |
373 | struct GNUNET_IDENTITY_Ego *ego, | 403 | struct GNUNET_IDENTITY_Ego *ego, |
374 | void **ctx, | 404 | void **ctx, |
375 | const char *name) | 405 | const char *name) |
376 | { | 406 | { |
377 | const char *dot; | 407 | const char *dot; |
378 | struct LookupHandle *handle = cls; | 408 | struct LookupHandle *handle = cls; |
379 | 409 | ||
380 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
381 | "Master cb \n"); | ||
382 | handle->id_op = NULL; | 410 | handle->id_op = NULL; |
383 | if (NULL == ego) | 411 | if (NULL == ego) |
384 | { | 412 | { |
385 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 413 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
386 | _("Ego for `gns-master' not found, cannot perform lookup. Did you run gnunet-gns-import.sh?\n")); | 414 | _("Ego for `gns-master' not found, cannot perform lookup. Did you run gnunet-gns-import.sh?\n")); |
387 | handle->proc (handle->proc_cls, NULL, 0, GNUNET_SYSERR); | 415 | handle->proc (handle->proc_cls, NULL, 0, GNUNET_SYSERR); |
388 | cleanup_handle (handle); | 416 | cleanup_handle (handle); |
389 | return; | 417 | return; |
@@ -401,93 +429,98 @@ identity_master_cb (void *cls, | |||
401 | lookup_with_public_key (handle); | 429 | lookup_with_public_key (handle); |
402 | } | 430 | } |
403 | 431 | ||
432 | /** | ||
433 | * Parse REST uri for name and record type | ||
434 | * | ||
435 | * @param url Url to parse | ||
436 | * @param handle lookup handle to populate | ||
437 | * @return GNUNET_SYSERR on error | ||
438 | */ | ||
404 | int | 439 | int |
405 | parse_url (const char *url, struct LookupHandle *handle) | 440 | parse_url (const char *url, struct LookupHandle *handle) |
406 | { | 441 | { |
407 | char *name; | 442 | char *name; |
408 | char *type; | 443 | char *type; |
409 | char tmp_url[strlen(url)+1]; | 444 | char tmp_url[strlen(url)+1]; |
410 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Parsing %s\n", url); | 445 | char *tok; |
411 | strcpy (tmp_url, url); | 446 | |
412 | 447 | strcpy (tmp_url, url); | |
413 | char *tok = strtok ((char*)tmp_url, "/"); | 448 | tok = strtok ((char*)tmp_url, "/"); |
414 | 449 | if (NULL == tok) | |
415 | 450 | return GNUNET_SYSERR; | |
416 | if (NULL == tok) | 451 | name = strtok (NULL, "/"); |
417 | return GNUNET_SYSERR; | 452 | if (NULL == name) |
418 | 453 | return GNUNET_SYSERR; | |
419 | name = strtok (NULL, "/"); | 454 | GNUNET_asprintf (&handle->name, |
420 | 455 | "%s", | |
421 | if (NULL == name) | 456 | name); |
422 | return GNUNET_SYSERR; | 457 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
423 | 458 | "Got name: %s\n", handle->name); | |
424 | GNUNET_asprintf (&handle->name, | 459 | type = strtok (NULL, "/"); |
425 | "%s", | 460 | if (NULL == type) |
426 | name); | 461 | { |
427 | 462 | handle->type = GNUNET_GNSRECORD_TYPE_ANY; | |
428 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
429 | "Got name: %s\n", handle->name); | ||
430 | |||
431 | type = strtok (NULL, "/"); | ||
432 | |||
433 | if (NULL == type) | ||
434 | { | ||
435 | handle->type = GNUNET_GNSRECORD_TYPE_ANY; | ||
436 | return GNUNET_OK; | ||
437 | } | ||
438 | |||
439 | handle->type = GNUNET_GNSRECORD_typename_to_number (type); | ||
440 | |||
441 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
442 | "Got type: %s\n", type); | ||
443 | return GNUNET_OK; | 463 | return GNUNET_OK; |
464 | } | ||
465 | handle->type = GNUNET_GNSRECORD_typename_to_number (type); | ||
466 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
467 | "Got type: %s\n", type); | ||
468 | return GNUNET_OK; | ||
444 | } | 469 | } |
445 | 470 | ||
471 | /** | ||
472 | * Parse json from REST request | ||
473 | * | ||
474 | * @param data REST data | ||
475 | * @param data_size data size | ||
476 | * @param handle Handle to populate | ||
477 | * @return GNUNET_SYSERR on error | ||
478 | */ | ||
446 | int | 479 | int |
447 | parse_json (const char *data, size_t data_size, struct LookupHandle *handle) | 480 | parse_json (const char *data, size_t data_size, struct LookupHandle *handle) |
448 | { | 481 | { |
449 | json_error_t error; | 482 | json_error_t error; |
450 | json_t *pkey_json; | 483 | json_t *pkey_json; |
451 | json_t *ego_json; | 484 | json_t *ego_json; |
452 | json_t *options_json; | 485 | json_t *options_json; |
453 | 486 | ||
454 | char term_data[data_size+1]; | 487 | char term_data[data_size+1]; |
455 | term_data[data_size] = '\0'; | 488 | term_data[data_size] = '\0'; |
456 | 489 | ||
457 | memcpy (term_data, data, data_size); | 490 | memcpy (term_data, data, data_size); |
458 | 491 | ||
459 | handle->json_root = json_loads (term_data, 0, &error); | 492 | handle->json_root = json_loads (term_data, 0, &error); |
460 | 493 | ||
461 | if (NULL == handle->json_root) | 494 | if (NULL == handle->json_root) |
462 | { | 495 | { |
463 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, error.text); | 496 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, error.text); |
464 | return GNUNET_SYSERR; | 497 | return GNUNET_SYSERR; |
465 | } | 498 | } |
466 | 499 | ||
467 | if(!json_is_object(handle->json_root)) | 500 | if(!json_is_object(handle->json_root)) |
468 | { | 501 | { |
469 | return GNUNET_SYSERR; | 502 | return GNUNET_SYSERR; |
470 | } | 503 | } |
471 | |||
472 | ego_json = json_object_get (handle->json_root, "ego"); | ||
473 | |||
474 | if(json_is_string(ego_json)) | ||
475 | { | ||
476 | handle->ego_str = json_string_value (ego_json); | ||
477 | } | ||
478 | 504 | ||
479 | pkey_json = json_object_get (handle->json_root, "pkey"); | 505 | ego_json = json_object_get (handle->json_root, "ego"); |
480 | if(json_is_string(pkey_json)) | ||
481 | { | ||
482 | handle->pkey_str = json_string_value (pkey_json); | ||
483 | } | ||
484 | 506 | ||
485 | options_json = json_object_get (handle->json_root, "options"); | 507 | if(json_is_string(ego_json)) |
486 | if(json_is_integer (options_json)) | 508 | { |
487 | { | 509 | handle->ego_str = json_string_value (ego_json); |
488 | handle->options = json_integer_value (options_json); | 510 | } |
489 | } | 511 | |
490 | return GNUNET_OK; | 512 | pkey_json = json_object_get (handle->json_root, "pkey"); |
513 | if(json_is_string(pkey_json)) | ||
514 | { | ||
515 | handle->pkey_str = json_string_value (pkey_json); | ||
516 | } | ||
517 | |||
518 | options_json = json_object_get (handle->json_root, "options"); | ||
519 | if(json_is_integer (options_json)) | ||
520 | { | ||
521 | handle->options = json_integer_value (options_json); | ||
522 | } | ||
523 | return GNUNET_OK; | ||
491 | } | 524 | } |
492 | 525 | ||
493 | 526 | ||
@@ -510,103 +543,90 @@ rest_gns_process_request(const char *method, | |||
510 | GNUNET_REST_ResultProcessor proc, | 543 | GNUNET_REST_ResultProcessor proc, |
511 | void *proc_cls) | 544 | void *proc_cls) |
512 | { | 545 | { |
513 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 546 | struct LookupHandle *handle = GNUNET_new (struct LookupHandle); |
514 | "In plugin\n"); | 547 | handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; |
515 | struct LookupHandle *handle = GNUNET_new (struct LookupHandle); | ||
516 | |||
517 | handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; //TODO read from json | ||
518 | 548 | ||
519 | //parse name and type from url | 549 | //parse name and type from url |
520 | if (GNUNET_OK != parse_url (url, handle)) | 550 | if (GNUNET_OK != parse_url (url, handle)) |
521 | { | 551 | { |
522 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error parsing url...\n"); | 552 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error parsing url...\n"); |
523 | proc (proc_cls, NULL, 0, GNUNET_SYSERR); | 553 | proc (proc_cls, NULL, 0, GNUNET_SYSERR); |
524 | cleanup_handle (handle); | 554 | cleanup_handle (handle); |
525 | return; | 555 | return; |
526 | } | 556 | } |
527 | 557 | ||
528 | handle->proc_cls = proc_cls; | 558 | handle->proc_cls = proc_cls; |
529 | handle->proc = proc; | 559 | handle->proc = proc; |
530 | 560 | if (0 < data_size) | |
531 | if (0 < data_size) | 561 | { |
562 | if (GNUNET_OK != parse_json (data, data_size, handle)) | ||
532 | { | 563 | { |
533 | if (GNUNET_OK != parse_json (data, data_size, handle)) | 564 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error parsing json...\n"); |
534 | { | 565 | proc (proc_cls, NULL, 0, GNUNET_SYSERR); |
535 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error parsing json...\n"); | 566 | cleanup_handle (handle); |
536 | proc (proc_cls, NULL, 0, GNUNET_SYSERR); | 567 | return; |
537 | cleanup_handle (handle); | ||
538 | return; | ||
539 | } | ||
540 | } | 568 | } |
541 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 569 | } |
542 | "Connecting...\n"); | 570 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
543 | handle->gns = GNUNET_GNS_connect (cfg); | 571 | "Connecting...\n"); |
544 | handle->identity = GNUNET_IDENTITY_connect (cfg, NULL, NULL); | 572 | handle->gns = GNUNET_GNS_connect (cfg); |
573 | handle->identity = GNUNET_IDENTITY_connect (cfg, NULL, NULL); | ||
574 | handle->timeout_task = GNUNET_SCHEDULER_add_delayed (handle->timeout, | ||
575 | &do_error, handle); | ||
576 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
577 | "Connected\n"); | ||
545 | 578 | ||
546 | handle->timeout_task = GNUNET_SCHEDULER_add_delayed (handle->timeout, | 579 | if (NULL == handle->gns) |
547 | &do_error, handle); | 580 | { |
548 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 581 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
549 | "Connected\n"); | 582 | "Connecting to GNS failed\n"); |
550 | 583 | proc (proc_cls, NULL, 0, GNUNET_SYSERR); | |
551 | if (NULL == handle->gns) | 584 | cleanup_handle (handle); |
552 | { | 585 | return; |
553 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 586 | } |
554 | "Connecting to GNS failed\n"); | ||
555 | proc (proc_cls, NULL, 0, GNUNET_SYSERR); | ||
556 | cleanup_handle (handle); | ||
557 | return; | ||
558 | } | ||
559 | 587 | ||
560 | if (NULL != handle->pkey_str) | 588 | if (NULL != handle->pkey_str) |
561 | { | 589 | { |
562 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 590 | if (GNUNET_OK != |
563 | "pkey_str\n"); | ||
564 | if (GNUNET_OK != | ||
565 | GNUNET_CRYPTO_ecdsa_public_key_from_string (handle->pkey_str, | 591 | GNUNET_CRYPTO_ecdsa_public_key_from_string (handle->pkey_str, |
566 | strlen(handle->pkey_str), | 592 | strlen(handle->pkey_str), |
567 | &(handle->pkey))) | 593 | &(handle->pkey))) |
568 | { | ||
569 | proc (proc_cls, NULL, 0, GNUNET_SYSERR); | ||
570 | cleanup_handle (handle); | ||
571 | return; | ||
572 | } | ||
573 | lookup_with_public_key (handle); | ||
574 | |||
575 | } | ||
576 | if (NULL != handle->ego_str) | ||
577 | { | ||
578 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
579 | "ego_str\n"); | ||
580 | handle->el = GNUNET_IDENTITY_ego_lookup (cfg, | ||
581 | handle->ego_str, | ||
582 | &identity_zone_cb, | ||
583 | handle); | ||
584 | return; | ||
585 | } | ||
586 | if ( (NULL != handle->name) && | ||
587 | (strlen (handle->name) > 4) && | ||
588 | (0 == strcmp (".zkey", | ||
589 | &handle->name[strlen (handle->name) - 4])) ) | ||
590 | { | ||
591 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
592 | "zkey\n"); | ||
593 | /* no zone required, use 'anonymous' zone */ | ||
594 | GNUNET_CRYPTO_ecdsa_key_get_public | ||
595 | (GNUNET_CRYPTO_ecdsa_key_get_anonymous (), | ||
596 | &(handle->pkey)); | ||
597 | lookup_with_public_key (handle); | ||
598 | } | ||
599 | else | ||
600 | { | 594 | { |
601 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 595 | proc (proc_cls, NULL, 0, GNUNET_SYSERR); |
602 | "gns_master\n"); | 596 | cleanup_handle (handle); |
603 | GNUNET_break (NULL == handle->id_op); | 597 | return; |
604 | handle->id_op = GNUNET_IDENTITY_get (handle->identity, | ||
605 | "gns-master", | ||
606 | &identity_master_cb, | ||
607 | handle); | ||
608 | GNUNET_assert (NULL != handle->id_op); | ||
609 | } | 598 | } |
599 | lookup_with_public_key (handle); | ||
600 | |||
601 | } | ||
602 | if (NULL != handle->ego_str) | ||
603 | { | ||
604 | handle->el = GNUNET_IDENTITY_ego_lookup (cfg, | ||
605 | handle->ego_str, | ||
606 | &identity_zone_cb, | ||
607 | handle); | ||
608 | return; | ||
609 | } | ||
610 | if ( (NULL != handle->name) && | ||
611 | (strlen (handle->name) > 4) && | ||
612 | (0 == strcmp (".zkey", | ||
613 | &handle->name[strlen (handle->name) - 4])) ) | ||
614 | { | ||
615 | /* no zone required, use 'anonymous' zone */ | ||
616 | GNUNET_CRYPTO_ecdsa_key_get_public | ||
617 | (GNUNET_CRYPTO_ecdsa_key_get_anonymous (), | ||
618 | &(handle->pkey)); | ||
619 | lookup_with_public_key (handle); | ||
620 | } | ||
621 | else | ||
622 | { | ||
623 | GNUNET_break (NULL == handle->id_op); | ||
624 | handle->id_op = GNUNET_IDENTITY_get (handle->identity, | ||
625 | "gns-master", | ||
626 | &identity_master_cb, | ||
627 | handle); | ||
628 | GNUNET_assert (NULL != handle->id_op); | ||
629 | } | ||
610 | } | 630 | } |
611 | 631 | ||
612 | /** | 632 | /** |
@@ -631,7 +651,7 @@ libgnunet_plugin_rest_gns_init (void *cls) | |||
631 | api->name = API_NAMESPACE; | 651 | api->name = API_NAMESPACE; |
632 | api->process_request = &rest_gns_process_request; | 652 | api->process_request = &rest_gns_process_request; |
633 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 653 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
634 | _("GNS REST API initialized\n")); | 654 | _("GNS REST API initialized\n")); |
635 | return api; | 655 | return api; |
636 | } | 656 | } |
637 | 657 | ||
@@ -651,7 +671,7 @@ libgnunet_plugin_namestore_sqlite_done (void *cls) | |||
651 | plugin->cfg = NULL; | 671 | plugin->cfg = NULL; |
652 | GNUNET_free (api); | 672 | GNUNET_free (api); |
653 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 673 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
654 | "GNS REST plugin is finished\n"); | 674 | "GNS REST plugin is finished\n"); |
655 | return NULL; | 675 | return NULL; |
656 | } | 676 | } |
657 | 677 | ||