diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2015-03-12 17:32:37 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2015-03-12 17:32:37 +0000 |
commit | 44bd35d03db9385e6b93dd8a60c13582709380d1 (patch) | |
tree | 272df83b4edf41095ed0b1049b413747e04fe5bd /src/identity/plugin_rest_identity.c | |
parent | 59f6e4b0c42486d16a370c3524b78d88ac7fbcbc (diff) | |
download | gnunet-44bd35d03db9385e6b93dd8a60c13582709380d1.tar.gz gnunet-44bd35d03db9385e6b93dd8a60c13582709380d1.zip |
-add ego creation
Diffstat (limited to 'src/identity/plugin_rest_identity.c')
-rw-r--r-- | src/identity/plugin_rest_identity.c | 147 |
1 files changed, 131 insertions, 16 deletions
diff --git a/src/identity/plugin_rest_identity.c b/src/identity/plugin_rest_identity.c index 622653b09..2bfcbfe79 100644 --- a/src/identity/plugin_rest_identity.c +++ b/src/identity/plugin_rest_identity.c | |||
@@ -32,9 +32,7 @@ | |||
32 | 32 | ||
33 | #define API_NAMESPACE "/identity" | 33 | #define API_NAMESPACE "/identity" |
34 | 34 | ||
35 | #define EGO_NAMESPACE "/identity/ego" | 35 | #define EGO_NAMESPACE "/identity" |
36 | |||
37 | #define SVC_NAMESPACE "/identity/service" | ||
38 | 36 | ||
39 | #define ID_REST_STATE_INIT 0 | 37 | #define ID_REST_STATE_INIT 0 |
40 | 38 | ||
@@ -96,6 +94,11 @@ struct RequestHandle | |||
96 | struct GNUNET_IDENTITY_Handle *identity_handle; | 94 | struct GNUNET_IDENTITY_Handle *identity_handle; |
97 | 95 | ||
98 | /** | 96 | /** |
97 | * IDENTITY Operation | ||
98 | */ | ||
99 | struct GNUNET_IDENTITY_Operation *op; | ||
100 | |||
101 | /** | ||
99 | * Desired timeout for the lookup (default is no timeout). | 102 | * Desired timeout for the lookup (default is no timeout). |
100 | */ | 103 | */ |
101 | struct GNUNET_TIME_Relative timeout; | 104 | struct GNUNET_TIME_Relative timeout; |
@@ -150,6 +153,11 @@ struct RequestHandle | |||
150 | */ | 153 | */ |
151 | size_t data_size; | 154 | size_t data_size; |
152 | 155 | ||
156 | /** | ||
157 | * HTTP method | ||
158 | */ | ||
159 | const char* method; | ||
160 | |||
153 | }; | 161 | }; |
154 | 162 | ||
155 | /** | 163 | /** |
@@ -254,6 +262,111 @@ ego_info_response (struct RequestHandle *handle) | |||
254 | 262 | ||
255 | } | 263 | } |
256 | 264 | ||
265 | static void | ||
266 | create_finished (void *cls, const char *emsg) | ||
267 | { | ||
268 | struct RequestHandle *handle = cls; | ||
269 | |||
270 | handle->op = NULL; | ||
271 | if (NULL != emsg) | ||
272 | { | ||
273 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
274 | } | ||
275 | handle->proc (handle->proc_cls, NULL, 0, GNUNET_OK); | ||
276 | cleanup_handle (handle); | ||
277 | } | ||
278 | |||
279 | static void | ||
280 | ego_create_cont (struct RequestHandle *handle) | ||
281 | { | ||
282 | const char* egoname; | ||
283 | char term_data[handle->data_size]; | ||
284 | json_t *egoname_json; | ||
285 | json_t *root_json; | ||
286 | json_error_t error; | ||
287 | struct EgoEntry *ego_entry; | ||
288 | |||
289 | if (strlen (API_NAMESPACE) != strlen (handle->url)) | ||
290 | { | ||
291 | GNUNET_break(0); | ||
292 | handle->proc (handle->proc_cls, NULL, 0, GNUNET_SYSERR); | ||
293 | cleanup_handle (handle); | ||
294 | return; | ||
295 | } | ||
296 | if (0 >= handle->data_size) | ||
297 | { | ||
298 | GNUNET_break(0); | ||
299 | handle->proc (handle->proc_cls, NULL, 0, GNUNET_SYSERR); | ||
300 | cleanup_handle (handle); | ||
301 | return; | ||
302 | } | ||
303 | |||
304 | term_data[handle->data_size] = '\0'; | ||
305 | memcpy (term_data, handle->data, handle->data_size); | ||
306 | root_json = json_loads (term_data, 0, &error); | ||
307 | |||
308 | if ((NULL == root_json) || !json_is_object (root_json)) | ||
309 | { | ||
310 | GNUNET_break(0); | ||
311 | handle->proc (handle->proc_cls, NULL, 0, GNUNET_SYSERR); | ||
312 | cleanup_handle (handle); | ||
313 | return; | ||
314 | } | ||
315 | egoname_json = json_object_get (root_json, "ego"); | ||
316 | if (!json_is_string (egoname_json)) | ||
317 | { | ||
318 | GNUNET_break(0); | ||
319 | handle->proc (handle->proc_cls, NULL, 0, GNUNET_SYSERR); | ||
320 | cleanup_handle (handle); | ||
321 | return; | ||
322 | } | ||
323 | egoname = json_string_value (egoname_json); | ||
324 | for (ego_entry = handle->ego_head; | ||
325 | NULL != ego_entry; | ||
326 | ego_entry = ego_entry->next) | ||
327 | { | ||
328 | if (0 == strcasecmp (egoname, ego_entry->identifier)) | ||
329 | { | ||
330 | json_decref (egoname_json); | ||
331 | json_decref (root_json); | ||
332 | handle->proc (handle->proc_cls, NULL, 0, GNUNET_SYSERR); | ||
333 | cleanup_handle (handle); | ||
334 | return; | ||
335 | } | ||
336 | } | ||
337 | GNUNET_asprintf (&handle->name, "%s", egoname); | ||
338 | json_decref (egoname_json); | ||
339 | json_decref (root_json); | ||
340 | handle->op = GNUNET_IDENTITY_create (handle->identity_handle, | ||
341 | handle->name, | ||
342 | &create_finished, | ||
343 | handle); | ||
344 | } | ||
345 | |||
346 | void | ||
347 | subsys_set_cont (struct RequestHandle *handle) | ||
348 | { | ||
349 | } | ||
350 | |||
351 | void | ||
352 | ego_delete_cont (struct RequestHandle *handle) | ||
353 | { | ||
354 | } | ||
355 | |||
356 | void | ||
357 | init_cont (struct RequestHandle *handle) | ||
358 | { | ||
359 | if (0 == strcasecmp (handle->method, MHD_HTTP_METHOD_GET)) | ||
360 | ego_info_response (handle); | ||
361 | else if (0 == strcasecmp (handle->method, MHD_HTTP_METHOD_POST)) | ||
362 | ego_create_cont (handle); | ||
363 | else if (0 == strcasecmp (handle->method, MHD_HTTP_METHOD_PUT)) | ||
364 | subsys_set_cont (handle); | ||
365 | else if (0 == strcasecmp (handle->method, MHD_HTTP_METHOD_DELETE)) | ||
366 | ego_delete_cont (handle); | ||
367 | else | ||
368 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
369 | } | ||
257 | 370 | ||
258 | /** | 371 | /** |
259 | * If listing is enabled, prints information about the egos. | 372 | * If listing is enabled, prints information about the egos. |
@@ -297,6 +410,19 @@ list_ego (void *cls, | |||
297 | struct RequestHandle *handle = cls; | 410 | struct RequestHandle *handle = cls; |
298 | struct EgoEntry *ego_entry; | 411 | struct EgoEntry *ego_entry; |
299 | 412 | ||
413 | if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state)) | ||
414 | { | ||
415 | handle->state = ID_REST_STATE_POST_INIT; | ||
416 | init_cont (handle); | ||
417 | return; | ||
418 | } | ||
419 | if (ID_REST_STATE_INIT == handle->state) { | ||
420 | ego_entry = GNUNET_new (struct EgoEntry); | ||
421 | GNUNET_IDENTITY_ego_get_public_key (ego, &(ego_entry->pk)); | ||
422 | GNUNET_asprintf (&ego_entry->identifier, "%s", identifier); | ||
423 | GNUNET_CONTAINER_DLL_insert_tail(handle->ego_head,handle->ego_tail, ego_entry); | ||
424 | } | ||
425 | |||
300 | if ( (NULL == handle->set_ego) && | 426 | if ( (NULL == handle->set_ego) && |
301 | (NULL != ego) && | 427 | (NULL != ego) && |
302 | (NULL != identifier) && | 428 | (NULL != identifier) && |
@@ -325,19 +451,7 @@ list_ego (void *cls, | |||
325 | GNUNET_free (handle->set_ego); //decref? | 451 | GNUNET_free (handle->set_ego); //decref? |
326 | handle->set_ego = NULL; | 452 | handle->set_ego = NULL; |
327 | } | 453 | } |
328 | if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state)) | 454 | |
329 | { | ||
330 | //TODO all read | ||
331 | handle->state = ID_REST_STATE_POST_INIT; | ||
332 | ego_info_response (handle); | ||
333 | return; | ||
334 | } | ||
335 | if (ID_REST_STATE_INIT == handle->state) { | ||
336 | ego_entry = GNUNET_new (struct EgoEntry); | ||
337 | GNUNET_IDENTITY_ego_get_public_key (ego, &(ego_entry->pk)); | ||
338 | GNUNET_asprintf (&ego_entry->identifier, "%s", identifier); | ||
339 | GNUNET_CONTAINER_DLL_insert_tail(handle->ego_head,handle->ego_tail, ego_entry); | ||
340 | } | ||
341 | } | 455 | } |
342 | 456 | ||
343 | /** | 457 | /** |
@@ -378,6 +492,7 @@ rest_identity_process_request(const char *method, | |||
378 | handle->url = url; | 492 | handle->url = url; |
379 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 493 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
380 | "Connected\n"); | 494 | "Connected\n"); |
495 | handle->method = method; | ||
381 | } | 496 | } |
382 | 497 | ||
383 | /** | 498 | /** |