aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSchanzenbach, Martin <mschanzenbach@posteo.de>2019-04-14 15:44:08 +0200
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2019-04-14 15:44:08 +0200
commit1eea290a7aaa845db727773bc7e9f2a0fdc5bebd (patch)
tree08e1f6d5267820a3aad33f113aa87d6c31631ffb /src
parent494af3383d2a5d3402e1f03209cb574af86079a8 (diff)
downloadgnunet-1eea290a7aaa845db727773bc7e9f2a0fdc5bebd.tar.gz
gnunet-1eea290a7aaa845db727773bc7e9f2a0fdc5bebd.zip
RECLAIM/REST: add attribute ID to JSON
Diffstat (limited to 'src')
-rw-r--r--src/reclaim/json_reclaim.c166
-rw-r--r--src/reclaim/plugin_rest_reclaim.c477
2 files changed, 241 insertions, 402 deletions
diff --git a/src/reclaim/json_reclaim.c b/src/reclaim/json_reclaim.c
index 0fe9150d9..79110490a 100644
--- a/src/reclaim/json_reclaim.c
+++ b/src/reclaim/json_reclaim.c
@@ -24,10 +24,13 @@
24 * @author Martin Schanzenbach 24 * @author Martin Schanzenbach
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
27
27#include "gnunet_util_lib.h" 28#include "gnunet_util_lib.h"
29
28#include "gnunet_json_lib.h" 30#include "gnunet_json_lib.h"
29#include "gnunet_reclaim_service.h"
30#include "gnunet_reclaim_attribute_lib.h" 31#include "gnunet_reclaim_attribute_lib.h"
32#include "gnunet_reclaim_service.h"
33
31 34
32/** 35/**
33 * Parse given JSON object to a claim 36 * Parse given JSON object to a claim
@@ -38,54 +41,48 @@
38 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error 41 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
39 */ 42 */
40static int 43static int
41parse_attr (void *cls, 44parse_attr (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
42 json_t *root,
43 struct GNUNET_JSON_Specification *spec)
44{ 45{
45 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr; 46 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr;
46 const char* name_str; 47 const char *name_str;
47 const char* val_str; 48 const char *val_str;
48 const char* type_str; 49 const char *type_str;
50 const char *id_str;
49 char *data; 51 char *data;
50 int unpack_state; 52 int unpack_state;
51 uint32_t type; 53 uint32_t type;
52 size_t data_size; 54 size_t data_size;
53 55
54 GNUNET_assert(NULL != root); 56 GNUNET_assert (NULL != root);
55 57
56 if(!json_is_object(root)) 58 if (!json_is_object (root)) {
57 {
58 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 59 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
59 "Error json is not array nor object!\n"); 60 "Error json is not array nor object!\n");
60 return GNUNET_SYSERR; 61 return GNUNET_SYSERR;
61 } 62 }
62 //interpret single attribute 63 // interpret single attribute
63 unpack_state = json_unpack(root, 64 unpack_state =
64 "{s:s, s:s, s:s!}", 65 json_unpack (root, "{s:s, s:s, s:s, s:s!}", "name", &name_str, "id",
65 "name", &name_str, 66 &id_str, "type", &type_str, "value", &val_str);
66 "type", &type_str, 67 if (0 != unpack_state) {
67 "value", &val_str); 68 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
68 if (0 != unpack_state) 69 "Error json object has a wrong format!\n");
69 {
70 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
71 "Error json object has a wrong format!\n");
72 return GNUNET_SYSERR; 70 return GNUNET_SYSERR;
73 } 71 }
74 type = GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (type_str); 72 type = GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (type_str);
75 if (GNUNET_SYSERR == (GNUNET_RECLAIM_ATTRIBUTE_string_to_value (type, 73 if (GNUNET_SYSERR == (GNUNET_RECLAIM_ATTRIBUTE_string_to_value (
76 val_str, 74 type, val_str, (void **)&data, &data_size))) {
77 (void**)&data, 75 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Attribute value invalid!\n");
78 &data_size)))
79 {
80 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
81 "Attribute value invalid!\n");
82 return GNUNET_SYSERR; 76 return GNUNET_SYSERR;
83 } 77 }
84 attr = GNUNET_RECLAIM_ATTRIBUTE_claim_new (name_str, 78 attr = GNUNET_RECLAIM_ATTRIBUTE_claim_new (name_str, type, data, data_size);
85 type, 79 if (0 == strlen (id_str))
86 data, 80 attr->id = 0;
87 data_size); 81 else
88 *(struct GNUNET_RECLAIM_ATTRIBUTE_Claim **) spec->ptr = attr; 82 GNUNET_STRINGS_string_to_data (id_str, strlen (id_str), &attr->id,
83 sizeof (uint64_t));
84
85 *(struct GNUNET_RECLAIM_ATTRIBUTE_Claim **)spec->ptr = attr;
89 return GNUNET_OK; 86 return GNUNET_OK;
90} 87}
91 88
@@ -99,10 +96,9 @@ static void
99clean_attr (void *cls, struct GNUNET_JSON_Specification *spec) 96clean_attr (void *cls, struct GNUNET_JSON_Specification *spec)
100{ 97{
101 struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr; 98 struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr;
102 attr = (struct GNUNET_RECLAIM_ATTRIBUTE_Claim **) spec->ptr; 99 attr = (struct GNUNET_RECLAIM_ATTRIBUTE_Claim **)spec->ptr;
103 if (NULL != *attr) 100 if (NULL != *attr) {
104 { 101 GNUNET_free (*attr);
105 GNUNET_free(*attr);
106 *attr = NULL; 102 *attr = NULL;
107 } 103 }
108} 104}
@@ -116,15 +112,13 @@ clean_attr (void *cls, struct GNUNET_JSON_Specification *spec)
116struct GNUNET_JSON_Specification 112struct GNUNET_JSON_Specification
117GNUNET_RECLAIM_JSON_spec_claim (struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr) 113GNUNET_RECLAIM_JSON_spec_claim (struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr)
118{ 114{
119 struct GNUNET_JSON_Specification ret = { 115 struct GNUNET_JSON_Specification ret = {.parser = &parse_attr,
120 .parser = &parse_attr, 116 .cleaner = &clean_attr,
121 .cleaner = &clean_attr, 117 .cls = NULL,
122 .cls = NULL, 118 .field = NULL,
123 .field = NULL, 119 .ptr = attr,
124 .ptr = attr, 120 .ptr_size = 0,
125 .ptr_size = 0, 121 .size_ptr = NULL};
126 .size_ptr = NULL
127 };
128 *attr = NULL; 122 *attr = NULL;
129 return ret; 123 return ret;
130} 124}
@@ -137,67 +131,54 @@ GNUNET_RECLAIM_JSON_spec_claim (struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr)
137 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error 131 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
138 */ 132 */
139static int 133static int
140parse_ticket (void *cls, 134parse_ticket (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
141 json_t *root,
142 struct GNUNET_JSON_Specification *spec)
143{ 135{
144 struct GNUNET_RECLAIM_Ticket *ticket; 136 struct GNUNET_RECLAIM_Ticket *ticket;
145 const char* rnd_str; 137 const char *rnd_str;
146 const char* aud_str; 138 const char *aud_str;
147 const char* id_str; 139 const char *id_str;
148 int unpack_state; 140 int unpack_state;
149 141
150 GNUNET_assert(NULL != root); 142 GNUNET_assert (NULL != root);
151 143
152 if(!json_is_object(root)) 144 if (!json_is_object (root)) {
153 {
154 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 145 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
155 "Error json is not array nor object!\n"); 146 "Error json is not array nor object!\n");
156 return GNUNET_SYSERR; 147 return GNUNET_SYSERR;
157 } 148 }
158 //interpret single ticket 149 // interpret single ticket
159 unpack_state = json_unpack(root, 150 unpack_state = json_unpack (root, "{s:s, s:s, s:s!}", "rnd", &rnd_str,
160 "{s:s, s:s, s:s!}", 151 "audience", &aud_str, "identity", &id_str);
161 "rnd", &rnd_str, 152 if (0 != unpack_state) {
162 "audience", &aud_str, 153 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
163 "identity", &id_str); 154 "Error json object has a wrong format!\n");
164 if (0 != unpack_state)
165 {
166 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
167 "Error json object has a wrong format!\n");
168 return GNUNET_SYSERR; 155 return GNUNET_SYSERR;
169 } 156 }
170 ticket = GNUNET_new (struct GNUNET_RECLAIM_Ticket); 157 ticket = GNUNET_new (struct GNUNET_RECLAIM_Ticket);
171 if (GNUNET_OK != GNUNET_STRINGS_string_to_data (rnd_str, 158 if (GNUNET_OK != GNUNET_STRINGS_string_to_data (rnd_str, strlen (rnd_str),
172 strlen (rnd_str),
173 &ticket->rnd, 159 &ticket->rnd,
174 sizeof (uint64_t))) 160 sizeof (uint64_t))) {
175 { 161 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Rnd invalid\n");
176 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,"Rnd invalid\n"); 162 GNUNET_free (ticket);
177 GNUNET_free(ticket);
178 return GNUNET_SYSERR; 163 return GNUNET_SYSERR;
179 } 164 }
180 GNUNET_STRINGS_string_to_data (id_str, 165 GNUNET_STRINGS_string_to_data (id_str, strlen (id_str), &ticket->identity,
181 strlen (id_str),
182 &ticket->identity,
183 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); 166 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
184 { 167 {
185 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,"Identity invalid\n"); 168 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Identity invalid\n");
186 GNUNET_free(ticket); 169 GNUNET_free (ticket);
187 return GNUNET_SYSERR; 170 return GNUNET_SYSERR;
188 } 171 }
189 172
190 GNUNET_STRINGS_string_to_data (aud_str, 173 GNUNET_STRINGS_string_to_data (aud_str, strlen (aud_str), &ticket->audience,
191 strlen (aud_str),
192 &ticket->audience,
193 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); 174 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
194 { 175 {
195 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,"Audience invalid\n"); 176 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Audience invalid\n");
196 GNUNET_free(ticket); 177 GNUNET_free (ticket);
197 return GNUNET_SYSERR; 178 return GNUNET_SYSERR;
198 } 179 }
199 180
200 *(struct GNUNET_RECLAIM_Ticket **) spec->ptr = ticket; 181 *(struct GNUNET_RECLAIM_Ticket **)spec->ptr = ticket;
201 return GNUNET_OK; 182 return GNUNET_OK;
202} 183}
203 184
@@ -211,10 +192,9 @@ static void
211clean_ticket (void *cls, struct GNUNET_JSON_Specification *spec) 192clean_ticket (void *cls, struct GNUNET_JSON_Specification *spec)
212{ 193{
213 struct GNUNET_RECLAIM_Ticket **ticket; 194 struct GNUNET_RECLAIM_Ticket **ticket;
214 ticket = (struct GNUNET_RECLAIM_Ticket **) spec->ptr; 195 ticket = (struct GNUNET_RECLAIM_Ticket **)spec->ptr;
215 if (NULL != *ticket) 196 if (NULL != *ticket) {
216 { 197 GNUNET_free (*ticket);
217 GNUNET_free(*ticket);
218 *ticket = NULL; 198 *ticket = NULL;
219 } 199 }
220} 200}
@@ -228,15 +208,13 @@ clean_ticket (void *cls, struct GNUNET_JSON_Specification *spec)
228struct GNUNET_JSON_Specification 208struct GNUNET_JSON_Specification
229GNUNET_RECLAIM_JSON_spec_ticket (struct GNUNET_RECLAIM_Ticket **ticket) 209GNUNET_RECLAIM_JSON_spec_ticket (struct GNUNET_RECLAIM_Ticket **ticket)
230{ 210{
231 struct GNUNET_JSON_Specification ret = { 211 struct GNUNET_JSON_Specification ret = {.parser = &parse_ticket,
232 .parser = &parse_ticket, 212 .cleaner = &clean_ticket,
233 .cleaner = &clean_ticket, 213 .cls = NULL,
234 .cls = NULL, 214 .field = NULL,
235 .field = NULL, 215 .ptr = ticket,
236 .ptr = ticket, 216 .ptr_size = 0,
237 .ptr_size = 0, 217 .size_ptr = NULL};
238 .size_ptr = NULL
239 };
240 *ticket = NULL; 218 *ticket = NULL;
241 return ret; 219 return ret;
242} 220}
diff --git a/src/reclaim/plugin_rest_reclaim.c b/src/reclaim/plugin_rest_reclaim.c
index b36ed2bb6..ae46211d5 100644
--- a/src/reclaim/plugin_rest_reclaim.c
+++ b/src/reclaim/plugin_rest_reclaim.c
@@ -11,7 +11,7 @@
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 Affero 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 Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -24,22 +24,22 @@
24 * @brief GNUnet reclaim REST plugin 24 * @brief GNUnet reclaim REST plugin
25 * 25 *
26 */ 26 */
27
28#include "platform.h" 27#include "platform.h"
29#include "gnunet_rest_plugin.h" 28
30#include "gnunet_identity_service.h" 29#include "microhttpd.h"
30#include <inttypes.h>
31#include <jansson.h>
32
31#include "gnunet_gns_service.h" 33#include "gnunet_gns_service.h"
32#include "gnunet_gnsrecord_lib.h" 34#include "gnunet_gnsrecord_lib.h"
35#include "gnunet_identity_service.h"
33#include "gnunet_namestore_service.h" 36#include "gnunet_namestore_service.h"
34#include "gnunet_rest_lib.h"
35#include "microhttpd.h"
36#include <jansson.h>
37#include <inttypes.h>
38#include "gnunet_signatures.h"
39#include "gnunet_reclaim_attribute_lib.h" 37#include "gnunet_reclaim_attribute_lib.h"
40#include "gnunet_reclaim_service.h" 38#include "gnunet_reclaim_service.h"
39#include "gnunet_rest_lib.h"
40#include "gnunet_rest_plugin.h"
41#include "gnunet_signatures.h"
41#include "json_reclaim.h" 42#include "json_reclaim.h"
42
43/** 43/**
44 * REST root namespace 44 * REST root namespace
45 */ 45 */
@@ -83,7 +83,7 @@ const struct GNUNET_CONFIGURATION_Handle *cfg;
83/** 83/**
84 * HTTP methods allows for this plugin 84 * HTTP methods allows for this plugin
85 */ 85 */
86static char* allow_methods; 86static char *allow_methods;
87 87
88/** 88/**
89 * @brief struct returned by the initialization function of the plugin 89 * @brief struct returned by the initialization function of the plugin
@@ -246,7 +246,6 @@ struct RequestHandle
246 * Response object 246 * Response object
247 */ 247 */
248 json_t *resp_object; 248 json_t *resp_object;
249
250}; 249};
251 250
252/** 251/**
@@ -260,8 +259,7 @@ cleanup_handle (struct RequestHandle *handle)
260 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *claim_tmp; 259 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *claim_tmp;
261 struct EgoEntry *ego_entry; 260 struct EgoEntry *ego_entry;
262 struct EgoEntry *ego_tmp; 261 struct EgoEntry *ego_tmp;
263 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 262 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n");
264 "Cleaning up\n");
265 if (NULL != handle->resp_object) 263 if (NULL != handle->resp_object)
266 json_decref (handle->resp_object); 264 json_decref (handle->resp_object);
267 if (NULL != handle->timeout_task) 265 if (NULL != handle->timeout_task)
@@ -280,30 +278,24 @@ cleanup_handle (struct RequestHandle *handle)
280 GNUNET_free (handle->emsg); 278 GNUNET_free (handle->emsg);
281 if (NULL != handle->namestore_handle) 279 if (NULL != handle->namestore_handle)
282 GNUNET_NAMESTORE_disconnect (handle->namestore_handle); 280 GNUNET_NAMESTORE_disconnect (handle->namestore_handle);
283 if ( NULL != handle->attr_list ) 281 if (NULL != handle->attr_list) {
284 { 282 for (claim_entry = handle->attr_list->list_head; NULL != claim_entry;) {
285 for (claim_entry = handle->attr_list->list_head;
286 NULL != claim_entry;)
287 {
288 claim_tmp = claim_entry; 283 claim_tmp = claim_entry;
289 claim_entry = claim_entry->next; 284 claim_entry = claim_entry->next;
290 GNUNET_free(claim_tmp->claim); 285 GNUNET_free (claim_tmp->claim);
291 GNUNET_free(claim_tmp); 286 GNUNET_free (claim_tmp);
292 } 287 }
293 GNUNET_free (handle->attr_list); 288 GNUNET_free (handle->attr_list);
294 } 289 }
295 for (ego_entry = handle->ego_head; 290 for (ego_entry = handle->ego_head; NULL != ego_entry;) {
296 NULL != ego_entry;)
297 {
298 ego_tmp = ego_entry; 291 ego_tmp = ego_entry;
299 ego_entry = ego_entry->next; 292 ego_entry = ego_entry->next;
300 GNUNET_free (ego_tmp->identifier); 293 GNUNET_free (ego_tmp->identifier);
301 GNUNET_free (ego_tmp->keystring); 294 GNUNET_free (ego_tmp->keystring);
302 GNUNET_free (ego_tmp); 295 GNUNET_free (ego_tmp);
303 } 296 }
304 if (NULL != handle->attr_it) 297 if (NULL != handle->attr_it) {
305 { 298 GNUNET_free (handle->attr_it);
306 GNUNET_free(handle->attr_it);
307 } 299 }
308 GNUNET_free (handle); 300 GNUNET_free (handle);
309} 301}
@@ -327,10 +319,8 @@ do_error (void *cls)
327 struct MHD_Response *resp; 319 struct MHD_Response *resp;
328 char *json_error; 320 char *json_error;
329 321
330 GNUNET_asprintf (&json_error, "{ \"error\" : \"%s\" }", 322 GNUNET_asprintf (&json_error, "{ \"error\" : \"%s\" }", handle->emsg);
331 handle->emsg); 323 if (0 == handle->response_code) {
332 if ( 0 == handle->response_code )
333 {
334 handle->response_code = MHD_HTTP_BAD_REQUEST; 324 handle->response_code = MHD_HTTP_BAD_REQUEST;
335 } 325 }
336 resp = GNUNET_REST_create_response (json_error); 326 resp = GNUNET_REST_create_response (json_error);
@@ -365,16 +355,13 @@ collect_error_cb (void *cls)
365} 355}
366 356
367static void 357static void
368finished_cont (void *cls, 358finished_cont (void *cls, int32_t success, const char *emsg)
369 int32_t success,
370 const char *emsg)
371{ 359{
372 struct RequestHandle *handle = cls; 360 struct RequestHandle *handle = cls;
373 struct MHD_Response *resp; 361 struct MHD_Response *resp;
374 362
375 resp = GNUNET_REST_create_response (emsg); 363 resp = GNUNET_REST_create_response (emsg);
376 if (GNUNET_OK != success) 364 if (GNUNET_OK != success) {
377 {
378 GNUNET_SCHEDULER_add_now (&do_error, handle); 365 GNUNET_SCHEDULER_add_now (&do_error, handle);
379 return; 366 return;
380 } 367 }
@@ -391,7 +378,7 @@ finished_cont (void *cls,
391static void 378static void
392return_response (void *cls) 379return_response (void *cls)
393{ 380{
394 char* result_str; 381 char *result_str;
395 struct RequestHandle *handle = cls; 382 struct RequestHandle *handle = cls;
396 struct MHD_Response *resp; 383 struct MHD_Response *resp;
397 384
@@ -407,7 +394,7 @@ static void
407collect_finished_cb (void *cls) 394collect_finished_cb (void *cls)
408{ 395{
409 struct RequestHandle *handle = cls; 396 struct RequestHandle *handle = cls;
410 //Done 397 // Done
411 handle->attr_it = NULL; 398 handle->attr_it = NULL;
412 handle->ticket_it = NULL; 399 handle->ticket_it = NULL;
413 GNUNET_SCHEDULER_add_now (&return_response, handle); 400 GNUNET_SCHEDULER_add_now (&return_response, handle);
@@ -419,48 +406,37 @@ collect_finished_cb (void *cls)
419 * 406 *
420 */ 407 */
421static void 408static void
422ticket_collect (void *cls, 409ticket_collect (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket)
423 const struct GNUNET_RECLAIM_Ticket *ticket)
424{ 410{
425 json_t *json_resource; 411 json_t *json_resource;
426 struct RequestHandle *handle = cls; 412 struct RequestHandle *handle = cls;
427 json_t *value; 413 json_t *value;
428 char* tmp; 414 char *tmp;
429 415
430 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding ticket\n"); 416 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding ticket\n");
431 tmp = GNUNET_STRINGS_data_to_string_alloc (&ticket->rnd, 417 tmp = GNUNET_STRINGS_data_to_string_alloc (&ticket->rnd, sizeof (uint64_t));
432 sizeof (uint64_t));
433 json_resource = json_object (); 418 json_resource = json_object ();
434 GNUNET_free (tmp); 419 GNUNET_free (tmp);
435 json_array_append (handle->resp_object, 420 json_array_append (handle->resp_object, json_resource);
436 json_resource);
437 421
438 tmp = GNUNET_STRINGS_data_to_string_alloc (&ticket->identity, 422 tmp = GNUNET_STRINGS_data_to_string_alloc (
439 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); 423 &ticket->identity, sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
440 value = json_string (tmp); 424 value = json_string (tmp);
441 json_object_set_new (json_resource, 425 json_object_set_new (json_resource, "issuer", value);
442 "issuer",
443 value);
444 GNUNET_free (tmp); 426 GNUNET_free (tmp);
445 tmp = GNUNET_STRINGS_data_to_string_alloc (&ticket->audience, 427 tmp = GNUNET_STRINGS_data_to_string_alloc (
446 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); 428 &ticket->audience, sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
447 value = json_string (tmp); 429 value = json_string (tmp);
448 json_object_set_new (json_resource, 430 json_object_set_new (json_resource, "audience", value);
449 "audience",
450 value);
451 GNUNET_free (tmp); 431 GNUNET_free (tmp);
452 tmp = GNUNET_STRINGS_data_to_string_alloc (&ticket->rnd, 432 tmp = GNUNET_STRINGS_data_to_string_alloc (&ticket->rnd, sizeof (uint64_t));
453 sizeof (uint64_t));
454 value = json_string (tmp); 433 value = json_string (tmp);
455 json_object_set_new (json_resource, 434 json_object_set_new (json_resource, "rnd", value);
456 "rnd",
457 value);
458 GNUNET_free (tmp); 435 GNUNET_free (tmp);
459 GNUNET_RECLAIM_ticket_iteration_next (handle->ticket_it); 436 GNUNET_RECLAIM_ticket_iteration_next (handle->ticket_it);
460} 437}
461 438
462 439
463
464/** 440/**
465 * List tickets for identity request 441 * List tickets for identity request
466 * 442 *
@@ -470,8 +446,7 @@ ticket_collect (void *cls,
470 */ 446 */
471static void 447static void
472list_tickets_cont (struct GNUNET_REST_RequestHandle *con_handle, 448list_tickets_cont (struct GNUNET_REST_RequestHandle *con_handle,
473 const char* url, 449 const char *url, void *cls)
474 void *cls)
475{ 450{
476 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; 451 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key;
477 struct RequestHandle *handle = cls; 452 struct RequestHandle *handle = cls;
@@ -480,172 +455,138 @@ list_tickets_cont (struct GNUNET_REST_RequestHandle *con_handle,
480 455
481 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Getting tickets for %s.\n", 456 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Getting tickets for %s.\n",
482 handle->url); 457 handle->url);
483 if ( strlen (GNUNET_REST_API_NS_IDENTITY_TICKETS) >= 458 if (strlen (GNUNET_REST_API_NS_IDENTITY_TICKETS) >= strlen (handle->url)) {
484 strlen (handle->url))
485 {
486 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n"); 459 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n");
487 GNUNET_SCHEDULER_add_now (&do_error, handle); 460 GNUNET_SCHEDULER_add_now (&do_error, handle);
488 return; 461 return;
489 } 462 }
490 identity = handle->url + strlen (GNUNET_REST_API_NS_IDENTITY_TICKETS) + 1; 463 identity = handle->url + strlen (GNUNET_REST_API_NS_IDENTITY_TICKETS) + 1;
491 464
492 for (ego_entry = handle->ego_head; 465 for (ego_entry = handle->ego_head; NULL != ego_entry;
493 NULL != ego_entry;
494 ego_entry = ego_entry->next) 466 ego_entry = ego_entry->next)
495 if (0 == strcmp (identity, ego_entry->identifier)) 467 if (0 == strcmp (identity, ego_entry->identifier))
496 break; 468 break;
497 handle->resp_object = json_array (); 469 handle->resp_object = json_array ();
498 470
499 if (NULL == ego_entry) 471 if (NULL == ego_entry) {
500 { 472 // Done
501 //Done 473 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity);
502 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n",
503 identity);
504 GNUNET_SCHEDULER_add_now (&return_response, handle); 474 GNUNET_SCHEDULER_add_now (&return_response, handle);
505 return; 475 return;
506 } 476 }
507 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); 477 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
508 handle->idp = GNUNET_RECLAIM_connect (cfg); 478 handle->idp = GNUNET_RECLAIM_connect (cfg);
509 handle->ticket_it = GNUNET_RECLAIM_ticket_iteration_start (handle->idp, 479 handle->ticket_it = GNUNET_RECLAIM_ticket_iteration_start (
510 priv_key, 480 handle->idp, priv_key, &collect_error_cb, handle, &ticket_collect, handle,
511 &collect_error_cb, 481 &collect_finished_cb, handle);
512 handle,
513 &ticket_collect,
514 handle,
515 &collect_finished_cb,
516 handle);
517} 482}
518 483
519 484
520static void 485static void
521add_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, 486add_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
522 const char* url, 487 const char *url, void *cls)
523 void *cls)
524{ 488{
525 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv; 489 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv;
526 const char* identity; 490 const char *identity;
527 struct RequestHandle *handle = cls; 491 struct RequestHandle *handle = cls;
528 struct EgoEntry *ego_entry; 492 struct EgoEntry *ego_entry;
529 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attribute; 493 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attribute;
530 struct GNUNET_TIME_Relative exp; 494 struct GNUNET_TIME_Relative exp;
531 char term_data[handle->rest_handle->data_size+1]; 495 char term_data[handle->rest_handle->data_size + 1];
532 json_t *data_json; 496 json_t *data_json;
533 json_error_t err; 497 json_error_t err;
534 struct GNUNET_JSON_Specification attrspec[] = { 498 struct GNUNET_JSON_Specification attrspec[] = {
535 GNUNET_RECLAIM_JSON_spec_claim (&attribute), 499 GNUNET_RECLAIM_JSON_spec_claim (&attribute), GNUNET_JSON_spec_end ()};
536 GNUNET_JSON_spec_end()
537 };
538 500
539 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding an attribute for %s.\n", 501 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding an attribute for %s.\n",
540 handle->url); 502 handle->url);
541 if ( strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) >= 503 if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) >= strlen (handle->url)) {
542 strlen (handle->url))
543 {
544 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n"); 504 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n");
545 GNUNET_SCHEDULER_add_now (&do_error, handle); 505 GNUNET_SCHEDULER_add_now (&do_error, handle);
546 return; 506 return;
547 } 507 }
548 identity = handle->url + strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1; 508 identity = handle->url + strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1;
549 509
550 for (ego_entry = handle->ego_head; 510 for (ego_entry = handle->ego_head; NULL != ego_entry;
551 NULL != ego_entry;
552 ego_entry = ego_entry->next) 511 ego_entry = ego_entry->next)
553 if (0 == strcmp (identity, ego_entry->identifier)) 512 if (0 == strcmp (identity, ego_entry->identifier))
554 break; 513 break;
555 514
556 if (NULL == ego_entry) 515 if (NULL == ego_entry) {
557 { 516 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Identity unknown (%s)\n", identity);
558 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
559 "Identity unknown (%s)\n", identity);
560 return; 517 return;
561 } 518 }
562 identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); 519 identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
563 520
564 if (0 >= handle->rest_handle->data_size) 521 if (0 >= handle->rest_handle->data_size) {
565 {
566 GNUNET_SCHEDULER_add_now (&do_error, handle); 522 GNUNET_SCHEDULER_add_now (&do_error, handle);
567 return; 523 return;
568 } 524 }
569 525
570 term_data[handle->rest_handle->data_size] = '\0'; 526 term_data[handle->rest_handle->data_size] = '\0';
571 GNUNET_memcpy (term_data, 527 GNUNET_memcpy (term_data, handle->rest_handle->data,
572 handle->rest_handle->data,
573 handle->rest_handle->data_size); 528 handle->rest_handle->data_size);
574 data_json = json_loads (term_data, 529 data_json = json_loads (term_data, JSON_DECODE_ANY, &err);
575 JSON_DECODE_ANY,
576 &err);
577 GNUNET_assert (GNUNET_OK == 530 GNUNET_assert (GNUNET_OK ==
578 GNUNET_JSON_parse (data_json, attrspec, 531 GNUNET_JSON_parse (data_json, attrspec, NULL, NULL));
579 NULL, NULL));
580 json_decref (data_json); 532 json_decref (data_json);
581 if (NULL == attribute) 533 if (NULL == attribute) {
582 { 534 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unable to parse attribute from %s\n",
583 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
584 "Unable to parse attribute from %s\n",
585 term_data); 535 term_data);
586 GNUNET_SCHEDULER_add_now (&do_error, handle); 536 GNUNET_SCHEDULER_add_now (&do_error, handle);
587 return; 537 return;
588 } 538 }
539 /**
540 * New ID for attribute
541 */
542 attribute->id =
543 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX);
589 handle->idp = GNUNET_RECLAIM_connect (cfg); 544 handle->idp = GNUNET_RECLAIM_connect (cfg);
590 exp = GNUNET_TIME_UNIT_HOURS; 545 exp = GNUNET_TIME_UNIT_HOURS;
591 handle->idp_op = GNUNET_RECLAIM_attribute_store (handle->idp, 546 handle->idp_op = GNUNET_RECLAIM_attribute_store (
592 identity_priv, 547 handle->idp, identity_priv, attribute, &exp, &finished_cont, handle);
593 attribute,
594 &exp,
595 &finished_cont,
596 handle);
597 GNUNET_JSON_parse_free (attrspec); 548 GNUNET_JSON_parse_free (attrspec);
598} 549}
599 550
600 551
601
602/** 552/**
603 * Collect all attributes for an ego 553 * Collect all attributes for an ego
604 * 554 *
605 */ 555 */
606static void 556static void
607attr_collect (void *cls, 557attr_collect (void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
608 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
609 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) 558 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr)
610{ 559{
611 struct RequestHandle *handle = cls; 560 struct RequestHandle *handle = cls;
612 json_t *attr_obj; 561 json_t *attr_obj;
613 const char* type; 562 const char *type;
614 char* tmp_value; 563 char *tmp_value;
564 char *id_str;
615 565
616 if ((NULL == attr->name) || (NULL == attr->data)) 566 if ((NULL == attr->name) || (NULL == attr->data)) {
617 {
618 GNUNET_RECLAIM_get_attributes_next (handle->attr_it); 567 GNUNET_RECLAIM_get_attributes_next (handle->attr_it);
619 return; 568 return;
620 } 569 }
621 570
622 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute: %s\n", 571 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute: %s\n", attr->name);
623 attr->name);
624 572
625 tmp_value = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type, 573 tmp_value = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type, attr->data,
626 attr->data,
627 attr->data_size); 574 attr->data_size);
628 575
629 attr_obj = json_object (); 576 attr_obj = json_object ();
630 json_object_set_new (attr_obj, 577 json_object_set_new (attr_obj, "value", json_string (tmp_value));
631 "value", 578 json_object_set_new (attr_obj, "name", json_string (attr->name));
632 json_string (tmp_value));
633 json_object_set_new (attr_obj,
634 "name",
635 json_string (attr->name));
636 type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (attr->type); 579 type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (attr->type);
637 json_object_set_new (attr_obj, 580 json_object_set_new (attr_obj, "type", json_string (type));
638 "type", 581 id_str = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof (uint64_t));
639 json_string (type)); 582 json_object_set_new (attr_obj, "id", json_string (id_str));
640 json_array_append (handle->resp_object, 583 json_array_append (handle->resp_object, attr_obj);
641 attr_obj);
642 json_decref (attr_obj); 584 json_decref (attr_obj);
643 GNUNET_free(tmp_value); 585 GNUNET_free (tmp_value);
644 GNUNET_RECLAIM_get_attributes_next (handle->attr_it); 586 GNUNET_RECLAIM_get_attributes_next (handle->attr_it);
645} 587}
646 588
647 589
648
649/** 590/**
650 * List attributes for identity request 591 * List attributes for identity request
651 * 592 *
@@ -655,8 +596,7 @@ attr_collect (void *cls,
655 */ 596 */
656static void 597static void
657list_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, 598list_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
658 const char* url, 599 const char *url, void *cls)
659 void *cls)
660{ 600{
661 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; 601 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key;
662 struct RequestHandle *handle = cls; 602 struct RequestHandle *handle = cls;
@@ -665,91 +605,68 @@ list_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
665 605
666 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Getting attributes for %s.\n", 606 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Getting attributes for %s.\n",
667 handle->url); 607 handle->url);
668 if ( strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) >= 608 if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) >= strlen (handle->url)) {
669 strlen (handle->url))
670 {
671 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n"); 609 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n");
672 GNUNET_SCHEDULER_add_now (&do_error, handle); 610 GNUNET_SCHEDULER_add_now (&do_error, handle);
673 return; 611 return;
674 } 612 }
675 identity = handle->url + strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1; 613 identity = handle->url + strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1;
676 614
677 for (ego_entry = handle->ego_head; 615 for (ego_entry = handle->ego_head; NULL != ego_entry;
678 NULL != ego_entry;
679 ego_entry = ego_entry->next) 616 ego_entry = ego_entry->next)
680 if (0 == strcmp (identity, ego_entry->identifier)) 617 if (0 == strcmp (identity, ego_entry->identifier))
681 break; 618 break;
682 handle->resp_object = json_array (); 619 handle->resp_object = json_array ();
683 620
684 621
685 if (NULL == ego_entry) 622 if (NULL == ego_entry) {
686 { 623 // Done
687 //Done 624 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity);
688 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n",
689 identity);
690 GNUNET_SCHEDULER_add_now (&return_response, handle); 625 GNUNET_SCHEDULER_add_now (&return_response, handle);
691 return; 626 return;
692 } 627 }
693 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); 628 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
694 handle->idp = GNUNET_RECLAIM_connect (cfg); 629 handle->idp = GNUNET_RECLAIM_connect (cfg);
695 handle->attr_it = GNUNET_RECLAIM_get_attributes_start (handle->idp, 630 handle->attr_it = GNUNET_RECLAIM_get_attributes_start (
696 priv_key, 631 handle->idp, priv_key, &collect_error_cb, handle, &attr_collect, handle,
697 &collect_error_cb, 632 &collect_finished_cb, handle);
698 handle,
699 &attr_collect,
700 handle,
701 &collect_finished_cb,
702 handle);
703} 633}
704 634
705 635
706static void 636static void
707revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle, 637revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle,
708 const char* url, 638 const char *url, void *cls)
709 void *cls)
710{ 639{
711 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv; 640 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv;
712 struct RequestHandle *handle = cls; 641 struct RequestHandle *handle = cls;
713 struct EgoEntry *ego_entry; 642 struct EgoEntry *ego_entry;
714 struct GNUNET_RECLAIM_Ticket *ticket; 643 struct GNUNET_RECLAIM_Ticket *ticket;
715 struct GNUNET_CRYPTO_EcdsaPublicKey tmp_pk; 644 struct GNUNET_CRYPTO_EcdsaPublicKey tmp_pk;
716 char term_data[handle->rest_handle->data_size+1]; 645 char term_data[handle->rest_handle->data_size + 1];
717 json_t *data_json; 646 json_t *data_json;
718 json_error_t err; 647 json_error_t err;
719 struct GNUNET_JSON_Specification tktspec[] = { 648 struct GNUNET_JSON_Specification tktspec[] = {
720 GNUNET_RECLAIM_JSON_spec_ticket (&ticket), 649 GNUNET_RECLAIM_JSON_spec_ticket (&ticket), GNUNET_JSON_spec_end ()};
721 GNUNET_JSON_spec_end()
722 };
723 650
724 if (0 >= handle->rest_handle->data_size) 651 if (0 >= handle->rest_handle->data_size) {
725 {
726 GNUNET_SCHEDULER_add_now (&do_error, handle); 652 GNUNET_SCHEDULER_add_now (&do_error, handle);
727 return; 653 return;
728 } 654 }
729 655
730 term_data[handle->rest_handle->data_size] = '\0'; 656 term_data[handle->rest_handle->data_size] = '\0';
731 GNUNET_memcpy (term_data, 657 GNUNET_memcpy (term_data, handle->rest_handle->data,
732 handle->rest_handle->data,
733 handle->rest_handle->data_size); 658 handle->rest_handle->data_size);
734 data_json = json_loads (term_data, 659 data_json = json_loads (term_data, JSON_DECODE_ANY, &err);
735 JSON_DECODE_ANY,
736 &err);
737 GNUNET_assert (GNUNET_OK == 660 GNUNET_assert (GNUNET_OK ==
738 GNUNET_JSON_parse (data_json, tktspec, 661 GNUNET_JSON_parse (data_json, tktspec, NULL, NULL));
739 NULL, NULL));
740 json_decref (data_json); 662 json_decref (data_json);
741 if (NULL == ticket) 663 if (NULL == ticket) {
742 { 664 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unable to parse ticket from %s\n",
743 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
744 "Unable to parse ticket from %s\n",
745 term_data); 665 term_data);
746 GNUNET_SCHEDULER_add_now (&do_error, handle); 666 GNUNET_SCHEDULER_add_now (&do_error, handle);
747 return; 667 return;
748 } 668 }
749 if (GNUNET_OK != GNUNET_JSON_parse (data_json, 669 if (GNUNET_OK != GNUNET_JSON_parse (data_json, tktspec, NULL, NULL)) {
750 tktspec,
751 NULL, NULL))
752 {
753 handle->emsg = GNUNET_strdup ("Not a ticket!\n"); 670 handle->emsg = GNUNET_strdup ("Not a ticket!\n");
754 GNUNET_SCHEDULER_add_now (&do_error, handle); 671 GNUNET_SCHEDULER_add_now (&do_error, handle);
755 GNUNET_JSON_parse_free (tktspec); 672 GNUNET_JSON_parse_free (tktspec);
@@ -757,149 +674,111 @@ revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle,
757 return; 674 return;
758 } 675 }
759 676
760 for (ego_entry = handle->ego_head; 677 for (ego_entry = handle->ego_head; NULL != ego_entry;
761 NULL != ego_entry; 678 ego_entry = ego_entry->next) {
762 ego_entry = ego_entry->next) 679 GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &tmp_pk);
763 { 680 if (0 == memcmp (&ticket->identity, &tmp_pk,
764 GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego,
765 &tmp_pk);
766 if (0 == memcmp (&ticket->identity,
767 &tmp_pk,
768 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) 681 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
769 break; 682 break;
770 } 683 }
771 if (NULL == ego_entry) 684 if (NULL == ego_entry) {
772 { 685 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Identity unknown\n");
773 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
774 "Identity unknown\n");
775 GNUNET_JSON_parse_free (tktspec); 686 GNUNET_JSON_parse_free (tktspec);
776 return; 687 return;
777 } 688 }
778 identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); 689 identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
779 690
780 handle->idp = GNUNET_RECLAIM_connect (cfg); 691 handle->idp = GNUNET_RECLAIM_connect (cfg);
781 handle->idp_op = GNUNET_RECLAIM_ticket_revoke (handle->idp, 692 handle->idp_op = GNUNET_RECLAIM_ticket_revoke (
782 identity_priv, 693 handle->idp, identity_priv, ticket, &finished_cont, handle);
783 ticket,
784 &finished_cont,
785 handle);
786 GNUNET_JSON_parse_free (tktspec); 694 GNUNET_JSON_parse_free (tktspec);
787} 695}
788 696
789static void 697static void
790consume_cont (void *cls, 698consume_cont (void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
791 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
792 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) 699 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr)
793{ 700{
794 struct RequestHandle *handle = cls; 701 struct RequestHandle *handle = cls;
795 char *val_str; 702 char *val_str;
796 json_t *value; 703 json_t *value;
797 704
798 if (NULL == identity) 705 if (NULL == identity) {
799 {
800 GNUNET_SCHEDULER_add_now (&return_response, handle); 706 GNUNET_SCHEDULER_add_now (&return_response, handle);
801 return; 707 return;
802 } 708 }
803 709
804 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute: %s\n", 710 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute: %s\n", attr->name);
805 attr->name); 711 val_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type, attr->data,
806 val_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type,
807 attr->data,
808 attr->data_size); 712 attr->data_size);
809 if (NULL == val_str) 713 if (NULL == val_str) {
810 {
811 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to parse value for: %s\n", 714 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to parse value for: %s\n",
812 attr->name); 715 attr->name);
813 return; 716 return;
814 } 717 }
815 value = json_string(val_str); 718 value = json_string (val_str);
816 json_object_set_new (handle->resp_object, 719 json_object_set_new (handle->resp_object, attr->name, value);
817 attr->name,
818 value);
819 json_decref (value); 720 json_decref (value);
820 GNUNET_free (val_str); 721 GNUNET_free (val_str);
821} 722}
822 723
823static void 724static void
824consume_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle, 725consume_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle,
825 const char* url, 726 const char *url, void *cls)
826 void *cls)
827{ 727{
828 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv; 728 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv;
829 struct RequestHandle *handle = cls; 729 struct RequestHandle *handle = cls;
830 struct EgoEntry *ego_entry; 730 struct EgoEntry *ego_entry;
831 struct GNUNET_RECLAIM_Ticket *ticket; 731 struct GNUNET_RECLAIM_Ticket *ticket;
832 struct GNUNET_CRYPTO_EcdsaPublicKey tmp_pk; 732 struct GNUNET_CRYPTO_EcdsaPublicKey tmp_pk;
833 char term_data[handle->rest_handle->data_size+1]; 733 char term_data[handle->rest_handle->data_size + 1];
834 json_t *data_json; 734 json_t *data_json;
835 json_error_t err; 735 json_error_t err;
836 struct GNUNET_JSON_Specification tktspec[] = { 736 struct GNUNET_JSON_Specification tktspec[] = {
837 GNUNET_RECLAIM_JSON_spec_ticket (&ticket), 737 GNUNET_RECLAIM_JSON_spec_ticket (&ticket), GNUNET_JSON_spec_end ()};
838 GNUNET_JSON_spec_end ()
839 };
840 738
841 if (0 >= handle->rest_handle->data_size) 739 if (0 >= handle->rest_handle->data_size) {
842 {
843 GNUNET_SCHEDULER_add_now (&do_error, handle); 740 GNUNET_SCHEDULER_add_now (&do_error, handle);
844 return; 741 return;
845 } 742 }
846 743
847 term_data[handle->rest_handle->data_size] = '\0'; 744 term_data[handle->rest_handle->data_size] = '\0';
848 GNUNET_memcpy (term_data, 745 GNUNET_memcpy (term_data, handle->rest_handle->data,
849 handle->rest_handle->data,
850 handle->rest_handle->data_size); 746 handle->rest_handle->data_size);
851 data_json = json_loads (term_data, 747 data_json = json_loads (term_data, JSON_DECODE_ANY, &err);
852 JSON_DECODE_ANY, 748 if (NULL == data_json) {
853 &err);
854 if (NULL == data_json)
855 {
856 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 749 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
857 "Unable to parse JSON Object from %s\n", 750 "Unable to parse JSON Object from %s\n", term_data);
858 term_data);
859 GNUNET_SCHEDULER_add_now (&do_error, handle); 751 GNUNET_SCHEDULER_add_now (&do_error, handle);
860 return; 752 return;
861 } 753 }
862 if (GNUNET_OK != GNUNET_JSON_parse (data_json, 754 if (GNUNET_OK != GNUNET_JSON_parse (data_json, tktspec, NULL, NULL)) {
863 tktspec,
864 NULL, NULL))
865 {
866 handle->emsg = GNUNET_strdup ("Not a ticket!\n"); 755 handle->emsg = GNUNET_strdup ("Not a ticket!\n");
867 GNUNET_SCHEDULER_add_now (&do_error, handle); 756 GNUNET_SCHEDULER_add_now (&do_error, handle);
868 GNUNET_JSON_parse_free(tktspec); 757 GNUNET_JSON_parse_free (tktspec);
869 json_decref (data_json); 758 json_decref (data_json);
870 return; 759 return;
871 } 760 }
872 for (ego_entry = handle->ego_head; 761 for (ego_entry = handle->ego_head; NULL != ego_entry;
873 NULL != ego_entry; 762 ego_entry = ego_entry->next) {
874 ego_entry = ego_entry->next) 763 GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &tmp_pk);
875 { 764 if (0 == memcmp (&ticket->audience, &tmp_pk,
876 GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego,
877 &tmp_pk);
878 if (0 == memcmp (&ticket->audience,
879 &tmp_pk,
880 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) 765 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
881 break; 766 break;
882 } 767 }
883 if (NULL == ego_entry) 768 if (NULL == ego_entry) {
884 { 769 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Identity unknown\n");
885 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
886 "Identity unknown\n");
887 GNUNET_JSON_parse_free (tktspec); 770 GNUNET_JSON_parse_free (tktspec);
888 return; 771 return;
889 } 772 }
890 identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); 773 identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
891 handle->resp_object = json_object (); 774 handle->resp_object = json_object ();
892 handle->idp = GNUNET_RECLAIM_connect (cfg); 775 handle->idp = GNUNET_RECLAIM_connect (cfg);
893 handle->idp_op = GNUNET_RECLAIM_ticket_consume (handle->idp, 776 handle->idp_op = GNUNET_RECLAIM_ticket_consume (
894 identity_priv, 777 handle->idp, identity_priv, ticket, &consume_cont, handle);
895 ticket,
896 &consume_cont,
897 handle);
898 GNUNET_JSON_parse_free (tktspec); 778 GNUNET_JSON_parse_free (tktspec);
899} 779}
900 780
901 781
902
903/** 782/**
904 * Respond to OPTIONS request 783 * Respond to OPTIONS request
905 * 784 *
@@ -908,18 +787,15 @@ consume_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle,
908 * @param cls the RequestHandle 787 * @param cls the RequestHandle
909 */ 788 */
910static void 789static void
911options_cont (struct GNUNET_REST_RequestHandle *con_handle, 790options_cont (struct GNUNET_REST_RequestHandle *con_handle, const char *url,
912 const char* url,
913 void *cls) 791 void *cls)
914{ 792{
915 struct MHD_Response *resp; 793 struct MHD_Response *resp;
916 struct RequestHandle *handle = cls; 794 struct RequestHandle *handle = cls;
917 795
918 //For now, independent of path return all options 796 // For now, independent of path return all options
919 resp = GNUNET_REST_create_response (NULL); 797 resp = GNUNET_REST_create_response (NULL);
920 MHD_add_response_header (resp, 798 MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods);
921 "Access-Control-Allow-Methods",
922 allow_methods);
923 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 799 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
924 cleanup_handle (handle); 800 cleanup_handle (handle);
925 return; 801 return;
@@ -935,21 +811,21 @@ init_cont (struct RequestHandle *handle)
935{ 811{
936 struct GNUNET_REST_RequestHandlerError err; 812 struct GNUNET_REST_RequestHandlerError err;
937 static const struct GNUNET_REST_RequestHandler handlers[] = { 813 static const struct GNUNET_REST_RequestHandler handlers[] = {
938 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, &list_attribute_cont}, 814 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES,
939 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, &add_attribute_cont}, 815 &list_attribute_cont},
940 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_TICKETS, &list_tickets_cont}, 816 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES,
941 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY_REVOKE, &revoke_ticket_cont}, 817 &add_attribute_cont},
942 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY_CONSUME, &consume_ticket_cont}, 818 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_TICKETS,
943 {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_RECLAIM, 819 &list_tickets_cont},
944 &options_cont}, 820 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY_REVOKE,
945 GNUNET_REST_HANDLER_END 821 &revoke_ticket_cont},
946 }; 822 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY_CONSUME,
947 823 &consume_ticket_cont},
948 if (GNUNET_NO == GNUNET_REST_handle_request (handle->rest_handle, 824 {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_RECLAIM, &options_cont},
949 handlers, 825 GNUNET_REST_HANDLER_END};
950 &err, 826
951 handle)) 827 if (GNUNET_NO == GNUNET_REST_handle_request (handle->rest_handle, handlers,
952 { 828 &err, handle)) {
953 handle->response_code = err.error_code; 829 handle->response_code = err.error_code;
954 GNUNET_SCHEDULER_add_now (&do_error, handle); 830 GNUNET_SCHEDULER_add_now (&do_error, handle);
955 } 831 }
@@ -989,17 +865,14 @@ init_cont (struct RequestHandle *handle)
989 * must thus no longer be used 865 * must thus no longer be used
990 */ 866 */
991static void 867static void
992list_ego (void *cls, 868list_ego (void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx,
993 struct GNUNET_IDENTITY_Ego *ego,
994 void **ctx,
995 const char *identifier) 869 const char *identifier)
996{ 870{
997 struct RequestHandle *handle = cls; 871 struct RequestHandle *handle = cls;
998 struct EgoEntry *ego_entry; 872 struct EgoEntry *ego_entry;
999 struct GNUNET_CRYPTO_EcdsaPublicKey pk; 873 struct GNUNET_CRYPTO_EcdsaPublicKey pk;
1000 874
1001 if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state)) 875 if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state)) {
1002 {
1003 handle->state = ID_REST_STATE_POST_INIT; 876 handle->state = ID_REST_STATE_POST_INIT;
1004 init_cont (handle); 877 init_cont (handle);
1005 return; 878 return;
@@ -1007,19 +880,17 @@ list_ego (void *cls,
1007 if (ID_REST_STATE_INIT == handle->state) { 880 if (ID_REST_STATE_INIT == handle->state) {
1008 ego_entry = GNUNET_new (struct EgoEntry); 881 ego_entry = GNUNET_new (struct EgoEntry);
1009 GNUNET_IDENTITY_ego_get_public_key (ego, &pk); 882 GNUNET_IDENTITY_ego_get_public_key (ego, &pk);
1010 ego_entry->keystring = 883 ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk);
1011 GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk);
1012 ego_entry->ego = ego; 884 ego_entry->ego = ego;
1013 ego_entry->identifier = GNUNET_strdup (identifier); 885 ego_entry->identifier = GNUNET_strdup (identifier);
1014 GNUNET_CONTAINER_DLL_insert_tail(handle->ego_head,handle->ego_tail, ego_entry); 886 GNUNET_CONTAINER_DLL_insert_tail (handle->ego_head, handle->ego_tail,
887 ego_entry);
1015 } 888 }
1016
1017} 889}
1018 890
1019static void 891static void
1020rest_identity_process_request(struct GNUNET_REST_RequestHandle *rest_handle, 892rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle,
1021 GNUNET_REST_ResultProcessor proc, 893 GNUNET_REST_ResultProcessor proc, void *proc_cls)
1022 void *proc_cls)
1023{ 894{
1024 struct RequestHandle *handle = GNUNET_new (struct RequestHandle); 895 struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
1025 handle->response_code = 0; 896 handle->response_code = 0;
@@ -1030,20 +901,14 @@ rest_identity_process_request(struct GNUNET_REST_RequestHandle *rest_handle,
1030 handle->rest_handle = rest_handle; 901 handle->rest_handle = rest_handle;
1031 902
1032 handle->url = GNUNET_strdup (rest_handle->url); 903 handle->url = GNUNET_strdup (rest_handle->url);
1033 if (handle->url[strlen (handle->url)-1] == '/') 904 if (handle->url[strlen (handle->url) - 1] == '/')
1034 handle->url[strlen (handle->url)-1] = '\0'; 905 handle->url[strlen (handle->url) - 1] = '\0';
1035 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 906 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n");
1036 "Connecting...\n"); 907 handle->identity_handle = GNUNET_IDENTITY_connect (cfg, &list_ego, handle);
1037 handle->identity_handle = GNUNET_IDENTITY_connect (cfg,
1038 &list_ego,
1039 handle);
1040 handle->namestore_handle = GNUNET_NAMESTORE_connect (cfg); 908 handle->namestore_handle = GNUNET_NAMESTORE_connect (cfg);
1041 handle->timeout_task = 909 handle->timeout_task =
1042 GNUNET_SCHEDULER_add_delayed (handle->timeout, 910 GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_timeout, handle);
1043 &do_timeout, 911 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n");
1044 handle);
1045 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1046 "Connected\n");
1047} 912}
1048 913
1049/** 914/**
@@ -1060,23 +925,19 @@ libgnunet_plugin_rest_reclaim_init (void *cls)
1060 925
1061 cfg = cls; 926 cfg = cls;
1062 if (NULL != plugin.cfg) 927 if (NULL != plugin.cfg)
1063 return NULL; /* can only initialize once! */ 928 return NULL; /* can only initialize once! */
1064 memset (&plugin, 0, sizeof (struct Plugin)); 929 memset (&plugin, 0, sizeof (struct Plugin));
1065 plugin.cfg = cfg; 930 plugin.cfg = cfg;
1066 api = GNUNET_new (struct GNUNET_REST_Plugin); 931 api = GNUNET_new (struct GNUNET_REST_Plugin);
1067 api->cls = &plugin; 932 api->cls = &plugin;
1068 api->name = GNUNET_REST_API_NS_RECLAIM; 933 api->name = GNUNET_REST_API_NS_RECLAIM;
1069 api->process_request = &rest_identity_process_request; 934 api->process_request = &rest_identity_process_request;
1070 GNUNET_asprintf (&allow_methods, 935 GNUNET_asprintf (&allow_methods, "%s, %s, %s, %s, %s", MHD_HTTP_METHOD_GET,
1071 "%s, %s, %s, %s, %s", 936 MHD_HTTP_METHOD_POST, MHD_HTTP_METHOD_PUT,
1072 MHD_HTTP_METHOD_GET, 937 MHD_HTTP_METHOD_DELETE, MHD_HTTP_METHOD_OPTIONS);
1073 MHD_HTTP_METHOD_POST,
1074 MHD_HTTP_METHOD_PUT,
1075 MHD_HTTP_METHOD_DELETE,
1076 MHD_HTTP_METHOD_OPTIONS);
1077 938
1078 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 939 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1079 _("Identity Provider REST API initialized\n")); 940 _ ("Identity Provider REST API initialized\n"));
1080 return api; 941 return api;
1081} 942}
1082 943