aboutsummaryrefslogtreecommitdiff
path: root/src/credential/plugin_rest_credential.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/credential/plugin_rest_credential.c')
-rw-r--r--src/credential/plugin_rest_credential.c1368
1 files changed, 685 insertions, 683 deletions
diff --git a/src/credential/plugin_rest_credential.c b/src/credential/plugin_rest_credential.c
index 78267b54e..51c1f8b8c 100644
--- a/src/credential/plugin_rest_credential.c
+++ b/src/credential/plugin_rest_credential.c
@@ -11,12 +11,12 @@
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
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20/** 20/**
21 * @author Martin Schanzenbach 21 * @author Martin Schanzenbach
22 * @file credential/plugin_rest_credential.c 22 * @file credential/plugin_rest_credential.c
@@ -62,15 +62,13 @@
62/** 62/**
63 * @brief struct returned by the initialization function of the plugin 63 * @brief struct returned by the initialization function of the plugin
64 */ 64 */
65struct Plugin 65struct Plugin {
66{
67 const struct GNUNET_CONFIGURATION_Handle *cfg; 66 const struct GNUNET_CONFIGURATION_Handle *cfg;
68}; 67};
69 68
70const struct GNUNET_CONFIGURATION_Handle *cfg; 69const struct GNUNET_CONFIGURATION_Handle *cfg;
71 70
72struct RequestHandle 71struct RequestHandle {
73{
74 /** 72 /**
75 * Handle to Credential service. 73 * Handle to Credential service.
76 */ 74 */
@@ -155,7 +153,6 @@ struct RequestHandle
155 * Timeout 153 * Timeout
156 */ 154 */
157 struct GNUNET_TIME_Relative timeout; 155 struct GNUNET_TIME_Relative timeout;
158
159}; 156};
160 157
161 158
@@ -165,44 +162,44 @@ struct RequestHandle
165 * @param handle Handle to clean up 162 * @param handle Handle to clean up
166 */ 163 */
167static void 164static void
168cleanup_handle (struct RequestHandle *handle) 165cleanup_handle(struct RequestHandle *handle)
169{ 166{
170 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 167 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
171 "Cleaning up\n"); 168 "Cleaning up\n");
172 if (NULL != handle->json_root) 169 if (NULL != handle->json_root)
173 json_decref (handle->json_root); 170 json_decref(handle->json_root);
174 171
175 if (NULL != handle->issuer_attr) 172 if (NULL != handle->issuer_attr)
176 GNUNET_free (handle->issuer_attr); 173 GNUNET_free(handle->issuer_attr);
177 if (NULL != handle->subject_attr) 174 if (NULL != handle->subject_attr)
178 GNUNET_free (handle->subject_attr); 175 GNUNET_free(handle->subject_attr);
179 if (NULL != handle->verify_request) 176 if (NULL != handle->verify_request)
180 GNUNET_CREDENTIAL_request_cancel (handle->verify_request); 177 GNUNET_CREDENTIAL_request_cancel(handle->verify_request);
181 if (NULL != handle->credential) 178 if (NULL != handle->credential)
182 GNUNET_CREDENTIAL_disconnect (handle->credential); 179 GNUNET_CREDENTIAL_disconnect(handle->credential);
183 if (NULL != handle->id_op) 180 if (NULL != handle->id_op)
184 GNUNET_IDENTITY_cancel (handle->id_op); 181 GNUNET_IDENTITY_cancel(handle->id_op);
185 if (NULL != handle->ego_lookup) 182 if (NULL != handle->ego_lookup)
186 GNUNET_IDENTITY_ego_lookup_cancel (handle->ego_lookup); 183 GNUNET_IDENTITY_ego_lookup_cancel(handle->ego_lookup);
187 if (NULL != handle->identity) 184 if (NULL != handle->identity)
188 GNUNET_IDENTITY_disconnect (handle->identity); 185 GNUNET_IDENTITY_disconnect(handle->identity);
189 if (NULL != handle->timeout_task) 186 if (NULL != handle->timeout_task)
190 { 187 {
191 GNUNET_SCHEDULER_cancel (handle->timeout_task); 188 GNUNET_SCHEDULER_cancel(handle->timeout_task);
192 } 189 }
193 GNUNET_free (handle); 190 GNUNET_free(handle);
194} 191}
195 192
196 193
197static void 194static void
198do_error (void *cls) 195do_error(void *cls)
199{ 196{
200 struct RequestHandle *handle = cls; 197 struct RequestHandle *handle = cls;
201 struct MHD_Response *resp; 198 struct MHD_Response *resp;
202 199
203 resp = GNUNET_REST_create_response (NULL); 200 resp = GNUNET_REST_create_response(NULL);
204 handle->proc (handle->proc_cls, resp, handle->response_code); 201 handle->proc(handle->proc_cls, resp, handle->response_code);
205 cleanup_handle (handle); 202 cleanup_handle(handle);
206} 203}
207 204
208/** 205/**
@@ -212,41 +209,41 @@ do_error (void *cls)
212 * @return JSON, NULL if failed 209 * @return JSON, NULL if failed
213 */ 210 */
214static json_t* 211static json_t*
215attribute_delegation_to_json (struct GNUNET_CREDENTIAL_Delegation *delegation_chain_entry) 212attribute_delegation_to_json(struct GNUNET_CREDENTIAL_Delegation *delegation_chain_entry)
216{ 213{
217 char *subject; 214 char *subject;
218 char *issuer; 215 char *issuer;
219 json_t *attr_obj; 216 json_t *attr_obj;
220 217
221 issuer = GNUNET_CRYPTO_ecdsa_public_key_to_string (&delegation_chain_entry->issuer_key); 218 issuer = GNUNET_CRYPTO_ecdsa_public_key_to_string(&delegation_chain_entry->issuer_key);
222 if (NULL == issuer) 219 if (NULL == issuer)
223 { 220 {
224 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 221 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
225 "Issuer in delegation malformed\n"); 222 "Issuer in delegation malformed\n");
226 return NULL; 223 return NULL;
227 } 224 }
228 subject = GNUNET_CRYPTO_ecdsa_public_key_to_string (&delegation_chain_entry->subject_key); 225 subject = GNUNET_CRYPTO_ecdsa_public_key_to_string(&delegation_chain_entry->subject_key);
229 if (NULL == subject) 226 if (NULL == subject)
230 { 227 {
231 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 228 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
232 "Subject in credential malformed\n"); 229 "Subject in credential malformed\n");
233 GNUNET_free (issuer); 230 GNUNET_free(issuer);
234 return NULL; 231 return NULL;
235 } 232 }
236 attr_obj = json_object (); 233 attr_obj = json_object();
237 234
238 json_object_set_new (attr_obj, "issuer", json_string (issuer)); 235 json_object_set_new(attr_obj, "issuer", json_string(issuer));
239 json_object_set_new (attr_obj, "issuer_attribute", 236 json_object_set_new(attr_obj, "issuer_attribute",
240 json_string (delegation_chain_entry->issuer_attribute)); 237 json_string(delegation_chain_entry->issuer_attribute));
241 238
242 json_object_set_new (attr_obj, "subject", json_string (subject)); 239 json_object_set_new(attr_obj, "subject", json_string(subject));
243 if (0 < delegation_chain_entry->subject_attribute_len) 240 if (0 < delegation_chain_entry->subject_attribute_len)
244 { 241 {
245 json_object_set_new (attr_obj, "subject_attribute", 242 json_object_set_new(attr_obj, "subject_attribute",
246 json_string (delegation_chain_entry->subject_attribute)); 243 json_string(delegation_chain_entry->subject_attribute));
247 } 244 }
248 GNUNET_free (issuer); 245 GNUNET_free(issuer);
249 GNUNET_free (subject); 246 GNUNET_free(subject);
250 return attr_obj; 247 return attr_obj;
251} 248}
252 249
@@ -257,7 +254,7 @@ attribute_delegation_to_json (struct GNUNET_CREDENTIAL_Delegation *delegation_ch
257 * @return the resulting credential, NULL if failed 254 * @return the resulting credential, NULL if failed
258 */ 255 */
259static struct GNUNET_CREDENTIAL_Credential* 256static struct GNUNET_CREDENTIAL_Credential*
260json_to_credential (json_t *res) 257json_to_credential(json_t *res)
261{ 258{
262 struct GNUNET_CREDENTIAL_Credential *cred; 259 struct GNUNET_CREDENTIAL_Credential *cred;
263 json_t *tmp; 260 json_t *tmp;
@@ -265,58 +262,58 @@ json_to_credential (json_t *res)
265 const char *signature; 262 const char *signature;
266 char *sig; 263 char *sig;
267 264
268 tmp = json_object_get (res, "attribute"); 265 tmp = json_object_get(res, "attribute");
269 if (0 == json_is_string (tmp)) 266 if (0 == json_is_string(tmp))
270 { 267 {
271 return NULL; 268 return NULL;
272 } 269 }
273 attribute = json_string_value (tmp); 270 attribute = json_string_value(tmp);
274 cred = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Credential) 271 cred = GNUNET_malloc(sizeof(struct GNUNET_CREDENTIAL_Credential)
275 + strlen (attribute)); 272 + strlen(attribute));
276 cred->issuer_attribute = attribute; 273 cred->issuer_attribute = attribute;
277 cred->issuer_attribute_len = strlen (attribute); 274 cred->issuer_attribute_len = strlen(attribute);
278 tmp = json_object_get (res, "issuer"); 275 tmp = json_object_get(res, "issuer");
279 if (0 == json_is_string (tmp)) 276 if (0 == json_is_string(tmp))
280 { 277 {
281 GNUNET_free (cred); 278 GNUNET_free(cred);
282 return NULL; 279 return NULL;
283 } 280 }
284 281
285 GNUNET_CRYPTO_ecdsa_public_key_from_string (json_string_value(tmp), 282 GNUNET_CRYPTO_ecdsa_public_key_from_string(json_string_value(tmp),
286 strlen (json_string_value(tmp)), 283 strlen(json_string_value(tmp)),
287 &cred->issuer_key); 284 &cred->issuer_key);
288 tmp = json_object_get (res, "subject"); 285 tmp = json_object_get(res, "subject");
289 if (0 == json_is_string (tmp)) 286 if (0 == json_is_string(tmp))
290 { 287 {
291 GNUNET_free (cred); 288 GNUNET_free(cred);
292 return NULL; 289 return NULL;
293 } 290 }
294 GNUNET_CRYPTO_ecdsa_public_key_from_string (json_string_value(tmp), 291 GNUNET_CRYPTO_ecdsa_public_key_from_string(json_string_value(tmp),
295 strlen (json_string_value(tmp)), 292 strlen(json_string_value(tmp)),
296 &cred->subject_key); 293 &cred->subject_key);
297 294
298 tmp = json_object_get (res, "signature"); 295 tmp = json_object_get(res, "signature");
299 if (0 == json_is_string (tmp)) 296 if (0 == json_is_string(tmp))
300 { 297 {
301 GNUNET_free (cred); 298 GNUNET_free(cred);
302 return NULL; 299 return NULL;
303 } 300 }
304 signature = json_string_value (tmp); 301 signature = json_string_value(tmp);
305 GNUNET_STRINGS_base64_decode (signature, 302 GNUNET_STRINGS_base64_decode(signature,
306 strlen (signature), 303 strlen(signature),
307 (char**)&sig); 304 (char**)&sig);
308 GNUNET_memcpy (&cred->signature, 305 GNUNET_memcpy(&cred->signature,
309 sig, 306 sig,
310 sizeof (struct GNUNET_CRYPTO_EcdsaSignature)); 307 sizeof(struct GNUNET_CRYPTO_EcdsaSignature));
311 GNUNET_free (sig); 308 GNUNET_free(sig);
312 309
313 tmp = json_object_get (res, "expiration"); 310 tmp = json_object_get(res, "expiration");
314 if (0 == json_is_integer (tmp)) 311 if (0 == json_is_integer(tmp))
315 { 312 {
316 GNUNET_free (cred); 313 GNUNET_free(cred);
317 return NULL; 314 return NULL;
318 } 315 }
319 cred->expiration.abs_value_us = json_integer_value (tmp); 316 cred->expiration.abs_value_us = json_integer_value(tmp);
320 return cred; 317 return cred;
321} 318}
322 319
@@ -328,7 +325,7 @@ json_to_credential (json_t *res)
328 * @return the resulting json, NULL if failed 325 * @return the resulting json, NULL if failed
329 */ 326 */
330static json_t* 327static json_t*
331credential_to_json (struct GNUNET_CREDENTIAL_Credential *cred) 328credential_to_json(struct GNUNET_CREDENTIAL_Credential *cred)
332{ 329{
333 char *issuer; 330 char *issuer;
334 char *subject; 331 char *subject;
@@ -336,42 +333,42 @@ credential_to_json (struct GNUNET_CREDENTIAL_Credential *cred)
336 char attribute[cred->issuer_attribute_len + 1]; 333 char attribute[cred->issuer_attribute_len + 1];
337 json_t *cred_obj; 334 json_t *cred_obj;
338 335
339 issuer = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred->issuer_key); 336 issuer = GNUNET_CRYPTO_ecdsa_public_key_to_string(&cred->issuer_key);
340 if (NULL == issuer) 337 if (NULL == issuer)
341 { 338 {
342 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 339 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
343 "Issuer in credential malformed\n"); 340 "Issuer in credential malformed\n");
344 return NULL; 341 return NULL;
345 } 342 }
346 subject = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred->subject_key); 343 subject = GNUNET_CRYPTO_ecdsa_public_key_to_string(&cred->subject_key);
347 if (NULL == subject) 344 if (NULL == subject)
348 { 345 {
349 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 346 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
350 "Subject in credential malformed\n"); 347 "Subject in credential malformed\n");
351 GNUNET_free (issuer); 348 GNUNET_free(issuer);
352 return NULL; 349 return NULL;
353 } 350 }
354 GNUNET_STRINGS_base64_encode ((char*)&cred->signature, 351 GNUNET_STRINGS_base64_encode((char*)&cred->signature,
355 sizeof (struct GNUNET_CRYPTO_EcdsaSignature), 352 sizeof(struct GNUNET_CRYPTO_EcdsaSignature),
356 &signature); 353 &signature);
357 GNUNET_memcpy (attribute, 354 GNUNET_memcpy(attribute,
358 cred->issuer_attribute, 355 cred->issuer_attribute,
359 cred->issuer_attribute_len); 356 cred->issuer_attribute_len);
360 attribute[cred->issuer_attribute_len] = '\0'; 357 attribute[cred->issuer_attribute_len] = '\0';
361 cred_obj = json_object (); 358 cred_obj = json_object();
362 json_object_set_new (cred_obj, "issuer", json_string (issuer)); 359 json_object_set_new(cred_obj, "issuer", json_string(issuer));
363 json_object_set_new (cred_obj, "subject", json_string (subject)); 360 json_object_set_new(cred_obj, "subject", json_string(subject));
364 json_object_set_new (cred_obj, "attribute", json_string (attribute)); 361 json_object_set_new(cred_obj, "attribute", json_string(attribute));
365 json_object_set_new (cred_obj, "signature", json_string (signature)); 362 json_object_set_new(cred_obj, "signature", json_string(signature));
366 json_object_set_new (cred_obj, "expiration", json_integer (cred->expiration.abs_value_us)); 363 json_object_set_new(cred_obj, "expiration", json_integer(cred->expiration.abs_value_us));
367 GNUNET_free (issuer); 364 GNUNET_free(issuer);
368 GNUNET_free (subject); 365 GNUNET_free(subject);
369 GNUNET_free (signature); 366 GNUNET_free(signature);
370 return cred_obj; 367 return cred_obj;
371} 368}
372 369
373static void 370static void
374handle_collect_response (void *cls, 371handle_collect_response(void *cls,
375 unsigned int d_count, 372 unsigned int d_count,
376 struct GNUNET_CREDENTIAL_Delegation *delegation_chain, 373 struct GNUNET_CREDENTIAL_Delegation *delegation_chain,
377 unsigned int c_count, 374 unsigned int c_count,
@@ -389,85 +386,86 @@ handle_collect_response (void *cls,
389 uint32_t i; 386 uint32_t i;
390 387
391 handle->verify_request = NULL; 388 handle->verify_request = NULL;
392 if (NULL == cred) { 389 if (NULL == cred)
393 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 390 {
394 "Verify failed.\n"); 391 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
395 handle->response_code = MHD_HTTP_NOT_FOUND; 392 "Verify failed.\n");
396 GNUNET_SCHEDULER_add_now (&do_error, handle); 393 handle->response_code = MHD_HTTP_NOT_FOUND;
397 return; 394 GNUNET_SCHEDULER_add_now(&do_error, handle);
398 } 395 return;
399 issuer = GNUNET_CRYPTO_ecdsa_public_key_to_string (&handle->issuer_key); 396 }
397 issuer = GNUNET_CRYPTO_ecdsa_public_key_to_string(&handle->issuer_key);
400 if (NULL == issuer) 398 if (NULL == issuer)
401 { 399 {
402 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 400 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
403 "Issuer in delegation malformed\n"); 401 "Issuer in delegation malformed\n");
404 return; 402 return;
405 } 403 }
406 GNUNET_asprintf (&id, 404 GNUNET_asprintf(&id,
407 "%s.%s", 405 "%s.%s",
408 issuer, 406 issuer,
409 handle->issuer_attr); 407 handle->issuer_attr);
410 GNUNET_free (issuer); 408 GNUNET_free(issuer);
411 json_document = GNUNET_JSONAPI_document_new (); 409 json_document = GNUNET_JSONAPI_document_new();
412 json_resource = GNUNET_JSONAPI_resource_new (GNUNET_REST_JSONAPI_CREDENTIAL_TYPEINFO, 410 json_resource = GNUNET_JSONAPI_resource_new(GNUNET_REST_JSONAPI_CREDENTIAL_TYPEINFO,
413 id); 411 id);
414 GNUNET_free (id); 412 GNUNET_free(id);
415 cred_array = json_array (); 413 cred_array = json_array();
416 for (i=0;i<c_count;i++) 414 for (i = 0; i < c_count; i++)
417 { 415 {
418 cred_obj = credential_to_json (&cred[i]); 416 cred_obj = credential_to_json(&cred[i]);
419 json_array_append_new (cred_array, cred_obj); 417 json_array_append_new(cred_array, cred_obj);
420 } 418 }
421 GNUNET_JSONAPI_resource_add_attr (json_resource, 419 GNUNET_JSONAPI_resource_add_attr(json_resource,
422 GNUNET_REST_JSONAPI_CREDENTIAL, 420 GNUNET_REST_JSONAPI_CREDENTIAL,
423 cred_array); 421 cred_array);
424 GNUNET_JSONAPI_document_resource_add (json_document, json_resource); 422 GNUNET_JSONAPI_document_resource_add(json_document, json_resource);
425 GNUNET_JSONAPI_document_serialize (json_document, &result); 423 GNUNET_JSONAPI_document_serialize(json_document, &result);
426 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 424 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
427 "Result %s\n", 425 "Result %s\n",
428 result); 426 result);
429 json_decref (cred_array); 427 json_decref(cred_array);
430 GNUNET_JSONAPI_document_delete (json_document); 428 GNUNET_JSONAPI_document_delete(json_document);
431 resp = GNUNET_REST_create_response (result); 429 resp = GNUNET_REST_create_response(result);
432 GNUNET_free(result); 430 GNUNET_free(result);
433 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 431 handle->proc(handle->proc_cls, resp, MHD_HTTP_OK);
434 cleanup_handle (handle); 432 cleanup_handle(handle);
435} 433}
436 434
437static void 435static void
438subject_ego_lookup (void *cls, 436subject_ego_lookup(void *cls,
439 const struct GNUNET_IDENTITY_Ego *ego) 437 const struct GNUNET_IDENTITY_Ego *ego)
440{ 438{
441 struct RequestHandle *handle = cls; 439 struct RequestHandle *handle = cls;
442 const struct GNUNET_CRYPTO_EcdsaPrivateKey *sub_key; 440 const struct GNUNET_CRYPTO_EcdsaPrivateKey *sub_key;
441
443 handle->ego_lookup = NULL; 442 handle->ego_lookup = NULL;
444 443
445 if (NULL == ego) 444 if (NULL == ego)
446 { 445 {
447 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 446 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
448 "Subject not found\n"); 447 "Subject not found\n");
449 GNUNET_SCHEDULER_add_now (&do_error, handle); 448 GNUNET_SCHEDULER_add_now(&do_error, handle);
450 return; 449 return;
451 } 450 }
452 sub_key = GNUNET_IDENTITY_ego_get_private_key (ego); 451 sub_key = GNUNET_IDENTITY_ego_get_private_key(ego);
453 handle->verify_request = GNUNET_CREDENTIAL_collect (handle->credential, 452 handle->verify_request = GNUNET_CREDENTIAL_collect(handle->credential,
454 &handle->issuer_key, 453 &handle->issuer_key,
455 handle->issuer_attr, 454 handle->issuer_attr,
456 sub_key, 455 sub_key,
457 &handle_collect_response, 456 &handle_collect_response,
458 handle); 457 handle);
459} 458}
460 459
461 460
462 461
463static void 462static void
464handle_verify_response (void *cls, 463handle_verify_response(void *cls,
465 unsigned int d_count, 464 unsigned int d_count,
466 struct GNUNET_CREDENTIAL_Delegation *delegation_chain, 465 struct GNUNET_CREDENTIAL_Delegation *delegation_chain,
467 unsigned int c_count, 466 unsigned int c_count,
468 struct GNUNET_CREDENTIAL_Credential *cred) 467 struct GNUNET_CREDENTIAL_Credential *cred)
469{ 468{
470
471 struct RequestHandle *handle = cls; 469 struct RequestHandle *handle = cls;
472 struct MHD_Response *resp; 470 struct MHD_Response *resp;
473 struct GNUNET_JSONAPI_Document *json_document; 471 struct GNUNET_JSONAPI_Document *json_document;
@@ -482,165 +480,166 @@ handle_verify_response (void *cls,
482 uint32_t i; 480 uint32_t i;
483 481
484 handle->verify_request = NULL; 482 handle->verify_request = NULL;
485 if (NULL == cred) { 483 if (NULL == cred)
486 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 484 {
487 "Verify failed.\n"); 485 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
488 handle->response_code = MHD_HTTP_NOT_FOUND; 486 "Verify failed.\n");
489 GNUNET_SCHEDULER_add_now (&do_error, handle); 487 handle->response_code = MHD_HTTP_NOT_FOUND;
490 return; 488 GNUNET_SCHEDULER_add_now(&do_error, handle);
491 } 489 return;
492 issuer = GNUNET_CRYPTO_ecdsa_public_key_to_string (&handle->issuer_key); 490 }
491 issuer = GNUNET_CRYPTO_ecdsa_public_key_to_string(&handle->issuer_key);
493 if (NULL == issuer) 492 if (NULL == issuer)
494 { 493 {
495 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 494 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
496 "Issuer in delegation malformed\n"); 495 "Issuer in delegation malformed\n");
497 return; 496 return;
498 } 497 }
499 GNUNET_asprintf (&id, 498 GNUNET_asprintf(&id,
500 "%s.%s", 499 "%s.%s",
501 issuer, 500 issuer,
502 handle->issuer_attr); 501 handle->issuer_attr);
503 GNUNET_free (issuer); 502 GNUNET_free(issuer);
504 json_document = GNUNET_JSONAPI_document_new (); 503 json_document = GNUNET_JSONAPI_document_new();
505 json_resource = GNUNET_JSONAPI_resource_new (GNUNET_REST_JSONAPI_CREDENTIAL_TYPEINFO, 504 json_resource = GNUNET_JSONAPI_resource_new(GNUNET_REST_JSONAPI_CREDENTIAL_TYPEINFO,
506 id); 505 id);
507 GNUNET_free (id); 506 GNUNET_free(id);
508 attr_array = json_array (); 507 attr_array = json_array();
509 for (i = 0; i < d_count; i++) 508 for (i = 0; i < d_count; i++)
510 { 509 {
511 attr_obj = attribute_delegation_to_json (&delegation_chain[i]); 510 attr_obj = attribute_delegation_to_json(&delegation_chain[i]);
512 json_array_append_new (attr_array, attr_obj); 511 json_array_append_new(attr_array, attr_obj);
513 } 512 }
514 cred_array = json_array (); 513 cred_array = json_array();
515 for (i=0;i<c_count;i++) 514 for (i = 0; i < c_count; i++)
516 { 515 {
517 cred_obj = credential_to_json (&cred[i]); 516 cred_obj = credential_to_json(&cred[i]);
518 json_array_append_new (cred_array, cred_obj); 517 json_array_append_new(cred_array, cred_obj);
519 } 518 }
520 GNUNET_JSONAPI_resource_add_attr (json_resource, 519 GNUNET_JSONAPI_resource_add_attr(json_resource,
521 GNUNET_REST_JSONAPI_CREDENTIAL, 520 GNUNET_REST_JSONAPI_CREDENTIAL,
522 cred_array); 521 cred_array);
523 GNUNET_JSONAPI_resource_add_attr (json_resource, 522 GNUNET_JSONAPI_resource_add_attr(json_resource,
524 GNUNET_REST_JSONAPI_DELEGATIONS, 523 GNUNET_REST_JSONAPI_DELEGATIONS,
525 attr_array); 524 attr_array);
526 GNUNET_JSONAPI_document_resource_add (json_document, json_resource); 525 GNUNET_JSONAPI_document_resource_add(json_document, json_resource);
527 GNUNET_JSONAPI_document_serialize (json_document, &result); 526 GNUNET_JSONAPI_document_serialize(json_document, &result);
528 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 527 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
529 "Result %s\n", 528 "Result %s\n",
530 result); 529 result);
531 json_decref (attr_array); 530 json_decref(attr_array);
532 json_decref (cred_array); 531 json_decref(cred_array);
533 GNUNET_JSONAPI_document_delete (json_document); 532 GNUNET_JSONAPI_document_delete(json_document);
534 resp = GNUNET_REST_create_response (result); 533 resp = GNUNET_REST_create_response(result);
535 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 534 handle->proc(handle->proc_cls, resp, MHD_HTTP_OK);
536 GNUNET_free (result); 535 GNUNET_free(result);
537 cleanup_handle (handle); 536 cleanup_handle(handle);
538} 537}
539 538
540static void 539static void
541collect_cred_cont (struct GNUNET_REST_RequestHandle *conndata_handle, 540collect_cred_cont(struct GNUNET_REST_RequestHandle *conndata_handle,
542 const char* url, 541 const char* url,
543 void *cls) 542 void *cls)
544{ 543{
545 struct RequestHandle *handle = cls; 544 struct RequestHandle *handle = cls;
546 struct GNUNET_HashCode key; 545 struct GNUNET_HashCode key;
547 char *tmp; 546 char *tmp;
548 char *entity_attr; 547 char *entity_attr;
549 548
550 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 549 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
551 "Connecting...\n"); 550 "Connecting...\n");
552 handle->credential = GNUNET_CREDENTIAL_connect (cfg); 551 handle->credential = GNUNET_CREDENTIAL_connect(cfg);
553 handle->timeout_task = GNUNET_SCHEDULER_add_delayed (handle->timeout, 552 handle->timeout_task = GNUNET_SCHEDULER_add_delayed(handle->timeout,
554 &do_error, handle); 553 &do_error, handle);
555 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 554 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
556 "Connected\n"); 555 "Connected\n");
557 if (NULL == handle->credential) 556 if (NULL == handle->credential)
558 { 557 {
559 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 558 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
560 "Connecting to CREDENTIAL failed\n"); 559 "Connecting to CREDENTIAL failed\n");
561 GNUNET_SCHEDULER_add_now (&do_error, handle); 560 GNUNET_SCHEDULER_add_now(&do_error, handle);
562 return; 561 return;
563 } 562 }
564 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR, 563 GNUNET_CRYPTO_hash(GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR,
565 strlen (GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR), 564 strlen(GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR),
566 &key); 565 &key);
567 if ( GNUNET_NO == 566 if (GNUNET_NO ==
568 GNUNET_CONTAINER_multihashmap_contains (conndata_handle->url_param_map, 567 GNUNET_CONTAINER_multihashmap_contains(conndata_handle->url_param_map,
569 &key) ) 568 &key))
570 { 569 {
571 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 570 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
572 "Missing issuer attribute\n"); 571 "Missing issuer attribute\n");
573 GNUNET_SCHEDULER_add_now (&do_error, handle); 572 GNUNET_SCHEDULER_add_now(&do_error, handle);
574 return; 573 return;
575 } 574 }
576 tmp = GNUNET_CONTAINER_multihashmap_get (conndata_handle->url_param_map, 575 tmp = GNUNET_CONTAINER_multihashmap_get(conndata_handle->url_param_map,
577 &key); 576 &key);
578 entity_attr = GNUNET_strdup (tmp); 577 entity_attr = GNUNET_strdup(tmp);
579 tmp = strtok(entity_attr, "."); 578 tmp = strtok(entity_attr, ".");
580 if (NULL == tmp) 579 if (NULL == tmp)
581 { 580 {
582 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 581 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
583 "Malformed issuer or attribute\n"); 582 "Malformed issuer or attribute\n");
584 GNUNET_free (entity_attr); 583 GNUNET_free(entity_attr);
585 GNUNET_SCHEDULER_add_now (&do_error, handle); 584 GNUNET_SCHEDULER_add_now(&do_error, handle);
586 return; 585 return;
587 } 586 }
588 if (GNUNET_OK != 587 if (GNUNET_OK !=
589 GNUNET_CRYPTO_ecdsa_public_key_from_string (tmp, 588 GNUNET_CRYPTO_ecdsa_public_key_from_string(tmp,
590 strlen (tmp), 589 strlen(tmp),
591 &handle->issuer_key)) 590 &handle->issuer_key))
592 { 591 {
593 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 592 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
594 "Malformed issuer key\n"); 593 "Malformed issuer key\n");
595 GNUNET_free (entity_attr); 594 GNUNET_free(entity_attr);
596 GNUNET_SCHEDULER_add_now (&do_error, handle); 595 GNUNET_SCHEDULER_add_now(&do_error, handle);
597 return; 596 return;
598 } 597 }
599 tmp = strtok (NULL, "."); //Issuer attribute 598 tmp = strtok(NULL, "."); //Issuer attribute
600 if (NULL == tmp) 599 if (NULL == tmp)
601 { 600 {
602 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 601 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
603 "Malformed attribute\n"); 602 "Malformed attribute\n");
604 GNUNET_free (entity_attr); 603 GNUNET_free(entity_attr);
605 GNUNET_SCHEDULER_add_now (&do_error, handle); 604 GNUNET_SCHEDULER_add_now(&do_error, handle);
606 return; 605 return;
607 } 606 }
608 handle->issuer_attr = GNUNET_strdup (tmp); 607 handle->issuer_attr = GNUNET_strdup(tmp);
609 GNUNET_free (entity_attr); 608 GNUNET_free(entity_attr);
610 609
611 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_EGO, 610 GNUNET_CRYPTO_hash(GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_EGO,
612 strlen (GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_EGO), 611 strlen(GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_EGO),
613 &key); 612 &key);
614 if ( GNUNET_NO == 613 if (GNUNET_NO ==
615 GNUNET_CONTAINER_multihashmap_contains (conndata_handle->url_param_map, 614 GNUNET_CONTAINER_multihashmap_contains(conndata_handle->url_param_map,
616 &key) ) 615 &key))
617 { 616 {
618 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 617 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
619 "Missing subject\n"); 618 "Missing subject\n");
620 GNUNET_SCHEDULER_add_now (&do_error, handle); 619 GNUNET_SCHEDULER_add_now(&do_error, handle);
621 return; 620 return;
622 } 621 }
623 tmp = GNUNET_CONTAINER_multihashmap_get (conndata_handle->url_param_map, 622 tmp = GNUNET_CONTAINER_multihashmap_get(conndata_handle->url_param_map,
624 &key); 623 &key);
625 if (NULL == tmp) 624 if (NULL == tmp)
626 { 625 {
627 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 626 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
628 "Malformed subject\n"); 627 "Malformed subject\n");
629 GNUNET_SCHEDULER_add_now (&do_error, handle); 628 GNUNET_SCHEDULER_add_now(&do_error, handle);
630 return; 629 return;
631 } 630 }
632 handle->ego_lookup = GNUNET_IDENTITY_ego_lookup (cfg, 631 handle->ego_lookup = GNUNET_IDENTITY_ego_lookup(cfg,
633 tmp, 632 tmp,
634 &subject_ego_lookup, 633 &subject_ego_lookup,
635 handle); 634 handle);
636} 635}
637 636
638 637
639 638
640static void 639static void
641verify_cred_cont (struct GNUNET_REST_RequestHandle *conndata_handle, 640verify_cred_cont(struct GNUNET_REST_RequestHandle *conndata_handle,
642 const char* url, 641 const char* url,
643 void *cls) 642 void *cls)
644{ 643{
645 struct RequestHandle *handle = cls; 644 struct RequestHandle *handle = cls;
646 struct GNUNET_HashCode key; 645 struct GNUNET_HashCode key;
@@ -656,186 +655,186 @@ verify_cred_cont (struct GNUNET_REST_RequestHandle *conndata_handle,
656 json_t *data_js; 655 json_t *data_js;
657 json_error_t err; 656 json_error_t err;
658 657
659 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 658 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
660 "Connecting...\n"); 659 "Connecting...\n");
661 handle->credential = GNUNET_CREDENTIAL_connect (cfg); 660 handle->credential = GNUNET_CREDENTIAL_connect(cfg);
662 handle->timeout_task = GNUNET_SCHEDULER_add_delayed (handle->timeout, 661 handle->timeout_task = GNUNET_SCHEDULER_add_delayed(handle->timeout,
663 &do_error, handle); 662 &do_error, handle);
664 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 663 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
665 "Connected\n"); 664 "Connected\n");
666 if (NULL == handle->credential) 665 if (NULL == handle->credential)
667 { 666 {
668 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 667 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
669 "Connecting to CREDENTIAL failed\n"); 668 "Connecting to CREDENTIAL failed\n");
670 GNUNET_SCHEDULER_add_now (&do_error, handle); 669 GNUNET_SCHEDULER_add_now(&do_error, handle);
671 return; 670 return;
672 } 671 }
673 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR, 672 GNUNET_CRYPTO_hash(GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR,
674 strlen (GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR), 673 strlen(GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR),
675 &key); 674 &key);
676 if ( GNUNET_NO == 675 if (GNUNET_NO ==
677 GNUNET_CONTAINER_multihashmap_contains (conndata_handle->url_param_map, 676 GNUNET_CONTAINER_multihashmap_contains(conndata_handle->url_param_map,
678 &key) ) 677 &key))
679 { 678 {
680 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 679 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
681 "Missing issuer attribute\n"); 680 "Missing issuer attribute\n");
682 GNUNET_SCHEDULER_add_now (&do_error, handle); 681 GNUNET_SCHEDULER_add_now(&do_error, handle);
683 return; 682 return;
684 } 683 }
685 tmp = GNUNET_CONTAINER_multihashmap_get (conndata_handle->url_param_map, 684 tmp = GNUNET_CONTAINER_multihashmap_get(conndata_handle->url_param_map,
686 &key); 685 &key);
687 entity_attr = GNUNET_strdup (tmp); 686 entity_attr = GNUNET_strdup(tmp);
688 tmp = strtok(entity_attr, "."); 687 tmp = strtok(entity_attr, ".");
689 if (NULL == tmp) 688 if (NULL == tmp)
690 { 689 {
691 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 690 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
692 "Malformed issuer or attribute\n"); 691 "Malformed issuer or attribute\n");
693 GNUNET_free (entity_attr); 692 GNUNET_free(entity_attr);
694 GNUNET_SCHEDULER_add_now (&do_error, handle); 693 GNUNET_SCHEDULER_add_now(&do_error, handle);
695 return; 694 return;
696 } 695 }
697 if (GNUNET_OK != 696 if (GNUNET_OK !=
698 GNUNET_CRYPTO_ecdsa_public_key_from_string (tmp, 697 GNUNET_CRYPTO_ecdsa_public_key_from_string(tmp,
699 strlen (tmp), 698 strlen(tmp),
700 &handle->issuer_key)) 699 &handle->issuer_key))
701 { 700 {
702 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 701 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
703 "Malformed issuer key\n"); 702 "Malformed issuer key\n");
704 GNUNET_free (entity_attr); 703 GNUNET_free(entity_attr);
705 GNUNET_SCHEDULER_add_now (&do_error, handle); 704 GNUNET_SCHEDULER_add_now(&do_error, handle);
706 return; 705 return;
707 } 706 }
708 tmp = strtok (NULL, "."); //Issuer attribute 707 tmp = strtok(NULL, "."); //Issuer attribute
709 if (NULL == tmp) 708 if (NULL == tmp)
710 { 709 {
711 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 710 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
712 "Malformed attribute\n"); 711 "Malformed attribute\n");
713 GNUNET_free (entity_attr); 712 GNUNET_free(entity_attr);
714 GNUNET_SCHEDULER_add_now (&do_error, handle); 713 GNUNET_SCHEDULER_add_now(&do_error, handle);
715 return; 714 return;
716 } 715 }
717 handle->issuer_attr = GNUNET_strdup (tmp); 716 handle->issuer_attr = GNUNET_strdup(tmp);
718 GNUNET_free (entity_attr); 717 GNUNET_free(entity_attr);
719 718
720 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_KEY, 719 GNUNET_CRYPTO_hash(GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_KEY,
721 strlen (GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_KEY), 720 strlen(GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_KEY),
722 &key); 721 &key);
723 if ( GNUNET_NO == 722 if (GNUNET_NO ==
724 GNUNET_CONTAINER_multihashmap_contains (conndata_handle->url_param_map, 723 GNUNET_CONTAINER_multihashmap_contains(conndata_handle->url_param_map,
725 &key) ) 724 &key))
726 { 725 {
727 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 726 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
728 "Missing subject key\n"); 727 "Missing subject key\n");
729 GNUNET_SCHEDULER_add_now (&do_error, handle); 728 GNUNET_SCHEDULER_add_now(&do_error, handle);
730 return; 729 return;
731 } 730 }
732 tmp = GNUNET_CONTAINER_multihashmap_get (conndata_handle->url_param_map, 731 tmp = GNUNET_CONTAINER_multihashmap_get(conndata_handle->url_param_map,
733 &key); 732 &key);
734 if (NULL == tmp) 733 if (NULL == tmp)
735 { 734 {
736 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 735 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
737 "Malformed subject\n"); 736 "Malformed subject\n");
738 GNUNET_SCHEDULER_add_now (&do_error, handle); 737 GNUNET_SCHEDULER_add_now(&do_error, handle);
739 return; 738 return;
740 } 739 }
741 if (GNUNET_OK != 740 if (GNUNET_OK !=
742 GNUNET_CRYPTO_ecdsa_public_key_from_string (tmp, 741 GNUNET_CRYPTO_ecdsa_public_key_from_string(tmp,
743 strlen (tmp), 742 strlen(tmp),
744 &handle->subject_key)) { 743 &handle->subject_key))
745 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 744 {
746 "Malformed subject key\n"); 745 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
747 GNUNET_SCHEDULER_add_now (&do_error, handle); 746 "Malformed subject key\n");
748 return; 747 GNUNET_SCHEDULER_add_now(&do_error, handle);
749 } 748 return;
749 }
750 750
751 if (0 >= handle->rest_handle->data_size) 751 if (0 >= handle->rest_handle->data_size)
752 { 752 {
753 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 753 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
754 "Missing credentials\n"); 754 "Missing credentials\n");
755 GNUNET_SCHEDULER_add_now (&do_error, handle); 755 GNUNET_SCHEDULER_add_now(&do_error, handle);
756 return; 756 return;
757 } 757 }
758 758
759 struct GNUNET_JSON_Specification docspec[] = { 759 struct GNUNET_JSON_Specification docspec[] = {
760 GNUNET_JSON_spec_jsonapi_document (&json_obj), 760 GNUNET_JSON_spec_jsonapi_document(&json_obj),
761 GNUNET_JSON_spec_end() 761 GNUNET_JSON_spec_end()
762 }; 762 };
763 char term_data[handle->rest_handle->data_size+1]; 763 char term_data[handle->rest_handle->data_size + 1];
764 term_data[handle->rest_handle->data_size] = '\0'; 764 term_data[handle->rest_handle->data_size] = '\0';
765 credential_count = 0; 765 credential_count = 0;
766 GNUNET_memcpy (term_data, 766 GNUNET_memcpy(term_data,
767 handle->rest_handle->data, 767 handle->rest_handle->data,
768 handle->rest_handle->data_size); 768 handle->rest_handle->data_size);
769 data_js = json_loads (term_data, 769 data_js = json_loads(term_data,
770 JSON_DECODE_ANY, 770 JSON_DECODE_ANY,
771 &err); 771 &err);
772 GNUNET_assert (GNUNET_OK == GNUNET_JSON_parse (data_js, docspec, 772 GNUNET_assert(GNUNET_OK == GNUNET_JSON_parse(data_js, docspec,
773 NULL, NULL)); 773 NULL, NULL));
774 json_decref (data_js); 774 json_decref(data_js);
775 if (NULL == json_obj) 775 if (NULL == json_obj)
776 { 776 {
777 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 777 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
778 "Unable to parse JSONAPI Object from %s\n", 778 "Unable to parse JSONAPI Object from %s\n",
779 term_data); 779 term_data);
780 GNUNET_SCHEDULER_add_now (&do_error, handle); 780 GNUNET_SCHEDULER_add_now(&do_error, handle);
781 return; 781 return;
782 } 782 }
783 783
784 resource_count = GNUNET_JSONAPI_document_resource_count(json_obj); 784 resource_count = GNUNET_JSONAPI_document_resource_count(json_obj);
785 GNUNET_assert (1 == resource_count); 785 GNUNET_assert(1 == resource_count);
786 res = (GNUNET_JSONAPI_document_get_resource(json_obj, 0)); 786 res = (GNUNET_JSONAPI_document_get_resource(json_obj, 0));
787 if (GNUNET_NO == GNUNET_JSONAPI_resource_check_type(res, 787 if (GNUNET_NO == GNUNET_JSONAPI_resource_check_type(res,
788 GNUNET_REST_JSONAPI_CREDENTIAL_TYPEINFO)) 788 GNUNET_REST_JSONAPI_CREDENTIAL_TYPEINFO))
789 { 789 {
790 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 790 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
791 "Resource not a credential!\n"); 791 "Resource not a credential!\n");
792 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 792 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
793 "Unable to parse JSONAPI Object from %s\n", 793 "Unable to parse JSONAPI Object from %s\n",
794 term_data); 794 term_data);
795 GNUNET_JSONAPI_document_delete (json_obj); 795 GNUNET_JSONAPI_document_delete(json_obj);
796 GNUNET_SCHEDULER_add_now (&do_error, handle); 796 GNUNET_SCHEDULER_add_now(&do_error, handle);
797 return; 797 return;
798 } 798 }
799 cred_json = GNUNET_JSONAPI_resource_read_attr (res, 799 cred_json = GNUNET_JSONAPI_resource_read_attr(res,
800 GNUNET_REST_JSONAPI_CREDENTIAL); 800 GNUNET_REST_JSONAPI_CREDENTIAL);
801 801
802 GNUNET_assert (json_is_array (cred_json)); 802 GNUNET_assert(json_is_array(cred_json));
803 803
804 credential_count = json_array_size(cred_json); 804 credential_count = json_array_size(cred_json);
805 805
806 struct GNUNET_CREDENTIAL_Credential credentials[credential_count]; 806 struct GNUNET_CREDENTIAL_Credential credentials[credential_count];
807 for (i=0;i<credential_count;i++) 807 for (i = 0; i < credential_count; i++)
808 {
809 cred = json_to_credential (json_array_get (cred_json, i));
810 if (NULL == cred)
811 { 808 {
812 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 809 cred = json_to_credential(json_array_get(cred_json, i));
813 "Unable to parse credential!\n"); 810 if (NULL == cred)
814 continue; 811 {
812 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
813 "Unable to parse credential!\n");
814 continue;
815 }
816 GNUNET_memcpy(&credentials[i],
817 cred,
818 sizeof(struct GNUNET_CREDENTIAL_Credential));
819 credentials[i].issuer_attribute = GNUNET_strdup(cred->issuer_attribute);
820 GNUNET_free(cred);
815 } 821 }
816 GNUNET_memcpy (&credentials[i],
817 cred,
818 sizeof (struct GNUNET_CREDENTIAL_Credential));
819 credentials[i].issuer_attribute = GNUNET_strdup (cred->issuer_attribute);
820 GNUNET_free (cred);
821 }
822 GNUNET_JSONAPI_document_delete(json_obj); 822 GNUNET_JSONAPI_document_delete(json_obj);
823 handle->verify_request = GNUNET_CREDENTIAL_verify (handle->credential, 823 handle->verify_request = GNUNET_CREDENTIAL_verify(handle->credential,
824 &handle->issuer_key, 824 &handle->issuer_key,
825 handle->issuer_attr, 825 handle->issuer_attr,
826 &handle->subject_key, 826 &handle->subject_key,
827 credential_count, 827 credential_count,
828 credentials, 828 credentials,
829 &handle_verify_response, 829 &handle_verify_response,
830 handle); 830 handle);
831 for (i=0;i<credential_count;i++) 831 for (i = 0; i < credential_count; i++)
832 GNUNET_free ((char*)credentials[i].issuer_attribute); 832 GNUNET_free((char*)credentials[i].issuer_attribute);
833
834} 833}
835 834
836void 835void
837send_cred_response (struct RequestHandle *handle, 836send_cred_response(struct RequestHandle *handle,
838 struct GNUNET_CREDENTIAL_Credential *cred) 837 struct GNUNET_CREDENTIAL_Credential *cred)
839{ 838{
840 struct MHD_Response *resp; 839 struct MHD_Response *resp;
841 struct GNUNET_JSONAPI_Document *json_document; 840 struct GNUNET_JSONAPI_Document *json_document;
@@ -847,64 +846,64 @@ send_cred_response (struct RequestHandle *handle,
847 char *signature; 846 char *signature;
848 char *id; 847 char *id;
849 848
850 GNUNET_assert (NULL != cred); 849 GNUNET_assert(NULL != cred);
851 issuer = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred->issuer_key); 850 issuer = GNUNET_CRYPTO_ecdsa_public_key_to_string(&cred->issuer_key);
852 if (NULL == issuer) 851 if (NULL == issuer)
853 { 852 {
854 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 853 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
855 "Subject malformed\n"); 854 "Subject malformed\n");
856 GNUNET_free (issuer); 855 GNUNET_free(issuer);
857 return; 856 return;
858 } 857 }
859 GNUNET_asprintf (&id, 858 GNUNET_asprintf(&id,
860 "%s.%s", 859 "%s.%s",
861 issuer, 860 issuer,
862 (char*)&cred[1]); 861 (char*)&cred[1]);
863 subject = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred->subject_key); 862 subject = GNUNET_CRYPTO_ecdsa_public_key_to_string(&cred->subject_key);
864 if (NULL == subject) 863 if (NULL == subject)
865 { 864 {
866 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 865 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
867 "Subject malformed\n"); 866 "Subject malformed\n");
868 GNUNET_free (id); 867 GNUNET_free(id);
869 GNUNET_free (issuer); 868 GNUNET_free(issuer);
870 return; 869 return;
871 } 870 }
872 GNUNET_STRINGS_base64_encode ((char*)&cred->signature, 871 GNUNET_STRINGS_base64_encode((char*)&cred->signature,
873 sizeof (struct GNUNET_CRYPTO_EcdsaSignature), 872 sizeof(struct GNUNET_CRYPTO_EcdsaSignature),
874 &signature); 873 &signature);
875 json_document = GNUNET_JSONAPI_document_new (); 874 json_document = GNUNET_JSONAPI_document_new();
876 json_resource = GNUNET_JSONAPI_resource_new (GNUNET_REST_JSONAPI_CREDENTIAL_TYPEINFO, 875 json_resource = GNUNET_JSONAPI_resource_new(GNUNET_REST_JSONAPI_CREDENTIAL_TYPEINFO,
877 id); 876 id);
878 GNUNET_free (id); 877 GNUNET_free(id);
879 cred_obj = json_object(); 878 cred_obj = json_object();
880 json_object_set_new (cred_obj, "issuer", json_string (issuer)); 879 json_object_set_new(cred_obj, "issuer", json_string(issuer));
881 json_object_set_new (cred_obj, "subject", json_string (subject)); 880 json_object_set_new(cred_obj, "subject", json_string(subject));
882 json_object_set_new (cred_obj, "expiration", json_integer( cred->expiration.abs_value_us)); 881 json_object_set_new(cred_obj, "expiration", json_integer(cred->expiration.abs_value_us));
883 json_object_set_new (cred_obj, "signature", json_string (signature)); 882 json_object_set_new(cred_obj, "signature", json_string(signature));
884 GNUNET_JSONAPI_resource_add_attr (json_resource, 883 GNUNET_JSONAPI_resource_add_attr(json_resource,
885 GNUNET_REST_JSONAPI_CREDENTIAL, 884 GNUNET_REST_JSONAPI_CREDENTIAL,
886 cred_obj); 885 cred_obj);
887 GNUNET_JSONAPI_document_resource_add (json_document, json_resource); 886 GNUNET_JSONAPI_document_resource_add(json_document, json_resource);
888 GNUNET_JSONAPI_document_serialize (json_document, &result); 887 GNUNET_JSONAPI_document_serialize(json_document, &result);
889 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 888 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
890 "Result %s\n", 889 "Result %s\n",
891 result); 890 result);
892 json_decref (cred_obj); 891 json_decref(cred_obj);
893 GNUNET_JSONAPI_document_delete (json_document); 892 GNUNET_JSONAPI_document_delete(json_document);
894 resp = GNUNET_REST_create_response (result); 893 resp = GNUNET_REST_create_response(result);
895 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 894 handle->proc(handle->proc_cls, resp, MHD_HTTP_OK);
896 GNUNET_free (result); 895 GNUNET_free(result);
897 GNUNET_free (signature); 896 GNUNET_free(signature);
898 GNUNET_free (issuer); 897 GNUNET_free(issuer);
899 GNUNET_free (subject); 898 GNUNET_free(subject);
900 cleanup_handle (handle); 899 cleanup_handle(handle);
901} 900}
902 901
903void 902void
904get_cred_issuer_cb (void *cls, 903get_cred_issuer_cb(void *cls,
905 struct GNUNET_IDENTITY_Ego *ego, 904 struct GNUNET_IDENTITY_Ego *ego,
906 void **ctx, 905 void **ctx,
907 const char *name) 906 const char *name)
908{ 907{
909 struct RequestHandle *handle = cls; 908 struct RequestHandle *handle = cls;
910 struct GNUNET_TIME_Absolute etime_abs; 909 struct GNUNET_TIME_Absolute etime_abs;
@@ -918,156 +917,158 @@ get_cred_issuer_cb (void *cls,
918 handle->id_op = NULL; 917 handle->id_op = NULL;
919 918
920 if (NULL == name) 919 if (NULL == name)
921 { 920 {
922 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 921 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
923 "Issuer not configured!\n"); 922 "Issuer not configured!\n");
924 GNUNET_SCHEDULER_add_now (&do_error, handle); 923 GNUNET_SCHEDULER_add_now(&do_error, handle);
925 return; 924 return;
926 } 925 }
927 926
928 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 927 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
929 "Connecting to credential service...\n"); 928 "Connecting to credential service...\n");
930 handle->credential = GNUNET_CREDENTIAL_connect (cfg); 929 handle->credential = GNUNET_CREDENTIAL_connect(cfg);
931 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 930 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
932 "Connected\n"); 931 "Connected\n");
933 if (NULL == handle->credential) 932 if (NULL == handle->credential)
934 { 933 {
935 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 934 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
936 "Connecting to CREDENTIAL failed\n"); 935 "Connecting to CREDENTIAL failed\n");
937 GNUNET_SCHEDULER_add_now (&do_error, handle); 936 GNUNET_SCHEDULER_add_now(&do_error, handle);
938 return; 937 return;
939 } 938 }
940 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_CREDENTIAL_EXPIRATION, 939 GNUNET_CRYPTO_hash(GNUNET_REST_JSONAPI_CREDENTIAL_EXPIRATION,
941 strlen (GNUNET_REST_JSONAPI_CREDENTIAL_EXPIRATION), 940 strlen(GNUNET_REST_JSONAPI_CREDENTIAL_EXPIRATION),
942 &key); 941 &key);
943 if ( GNUNET_NO == 942 if (GNUNET_NO ==
944 GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle->url_param_map, 943 GNUNET_CONTAINER_multihashmap_contains(handle->rest_handle->url_param_map,
945 &key) ) 944 &key))
946 { 945 {
947 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 946 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
948 "Missing expiration\n"); 947 "Missing expiration\n");
949 GNUNET_SCHEDULER_add_now (&do_error, handle); 948 GNUNET_SCHEDULER_add_now(&do_error, handle);
950 return; 949 return;
951 } 950 }
952 expiration_str = GNUNET_CONTAINER_multihashmap_get (handle->rest_handle->url_param_map, 951 expiration_str = GNUNET_CONTAINER_multihashmap_get(handle->rest_handle->url_param_map,
953 &key); 952 &key);
954 if ( NULL == expiration_str ) 953 if (NULL == expiration_str)
955 { 954 {
956 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 955 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
957 "Expiration malformed\n"); 956 "Expiration malformed\n");
958 GNUNET_SCHEDULER_add_now (&do_error, handle); 957 GNUNET_SCHEDULER_add_now(&do_error, handle);
959 return; 958 return;
960 } 959 }
961 960
962 if (GNUNET_OK == GNUNET_STRINGS_fancy_time_to_relative (expiration_str, 961 if (GNUNET_OK == GNUNET_STRINGS_fancy_time_to_relative(expiration_str,
963 &etime_rel)) 962 &etime_rel))
964 { 963 {
965 etime_abs = GNUNET_TIME_relative_to_absolute (etime_rel); 964 etime_abs = GNUNET_TIME_relative_to_absolute(etime_rel);
966 } else if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_absolute (expiration_str, 965 }
967 &etime_abs)) 966 else if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_absolute(expiration_str,
968 { 967 &etime_abs))
969 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 968 {
970 "Malformed expiration: %s\n", expiration_str); 969 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
971 GNUNET_SCHEDULER_add_now (&do_error, handle); 970 "Malformed expiration: %s\n", expiration_str);
972 return; 971 GNUNET_SCHEDULER_add_now(&do_error, handle);
973 } 972 return;
974 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR, 973 }
975 strlen (GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR), 974 GNUNET_CRYPTO_hash(GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR,
976 &key); 975 strlen(GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR),
977 if ( GNUNET_NO == 976 &key);
978 GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle->url_param_map, 977 if (GNUNET_NO ==
979 &key) ) 978 GNUNET_CONTAINER_multihashmap_contains(handle->rest_handle->url_param_map,
980 { 979 &key))
981 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 980 {
982 "Missing issuer attribute\n"); 981 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
983 GNUNET_SCHEDULER_add_now (&do_error, handle); 982 "Missing issuer attribute\n");
984 return; 983 GNUNET_SCHEDULER_add_now(&do_error, handle);
985 } 984 return;
985 }
986 handle->issuer_attr = GNUNET_strdup(GNUNET_CONTAINER_multihashmap_get 986 handle->issuer_attr = GNUNET_strdup(GNUNET_CONTAINER_multihashmap_get
987 (handle->rest_handle->url_param_map, 987 (handle->rest_handle->url_param_map,
988 &key)); 988 &key));
989 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_KEY, 989 GNUNET_CRYPTO_hash(GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_KEY,
990 strlen (GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_KEY), 990 strlen(GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_KEY),
991 &key); 991 &key);
992 if ( GNUNET_NO == 992 if (GNUNET_NO ==
993 GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle->url_param_map, 993 GNUNET_CONTAINER_multihashmap_contains(handle->rest_handle->url_param_map,
994 &key) ) 994 &key))
995 { 995 {
996 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 996 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
997 "Missing subject\n"); 997 "Missing subject\n");
998 GNUNET_SCHEDULER_add_now (&do_error, handle); 998 GNUNET_SCHEDULER_add_now(&do_error, handle);
999 return; 999 return;
1000 } 1000 }
1001 tmp = GNUNET_CONTAINER_multihashmap_get (handle->rest_handle->url_param_map, 1001 tmp = GNUNET_CONTAINER_multihashmap_get(handle->rest_handle->url_param_map,
1002 &key); 1002 &key);
1003 if (NULL == tmp) 1003 if (NULL == tmp)
1004 { 1004 {
1005 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1005 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1006 "Malformed subject\n"); 1006 "Malformed subject\n");
1007 GNUNET_SCHEDULER_add_now (&do_error, handle); 1007 GNUNET_SCHEDULER_add_now(&do_error, handle);
1008 return; 1008 return;
1009 } 1009 }
1010 if (GNUNET_OK != 1010 if (GNUNET_OK !=
1011 GNUNET_CRYPTO_ecdsa_public_key_from_string (tmp, 1011 GNUNET_CRYPTO_ecdsa_public_key_from_string(tmp,
1012 strlen (tmp), 1012 strlen(tmp),
1013 &handle->subject_key)) { 1013 &handle->subject_key))
1014 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1014 {
1015 "Malformed subject key\n"); 1015 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1016 GNUNET_SCHEDULER_add_now (&do_error, handle); 1016 "Malformed subject key\n");
1017 return; 1017 GNUNET_SCHEDULER_add_now(&do_error, handle);
1018 } 1018 return;
1019 issuer_key = GNUNET_IDENTITY_ego_get_private_key (ego); 1019 }
1020 cred = GNUNET_CREDENTIAL_credential_issue (issuer_key, 1020 issuer_key = GNUNET_IDENTITY_ego_get_private_key(ego);
1021 &handle->subject_key, 1021 cred = GNUNET_CREDENTIAL_credential_issue(issuer_key,
1022 handle->issuer_attr, 1022 &handle->subject_key,
1023 &etime_abs); 1023 handle->issuer_attr,
1024 &etime_abs);
1024 if (NULL == cred) 1025 if (NULL == cred)
1025 { 1026 {
1026 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1027 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1027 "Failed to create credential\n"); 1028 "Failed to create credential\n");
1028 GNUNET_SCHEDULER_add_now (&do_error, handle); 1029 GNUNET_SCHEDULER_add_now(&do_error, handle);
1029 return; 1030 return;
1030 } 1031 }
1031 send_cred_response (handle, cred); 1032 send_cred_response(handle, cred);
1032} 1033}
1033 1034
1034 1035
1035static void 1036static void
1036issue_cred_cont (struct GNUNET_REST_RequestHandle *conndata_handle, 1037issue_cred_cont(struct GNUNET_REST_RequestHandle *conndata_handle,
1037 const char* url, 1038 const char* url,
1038 void *cls) 1039 void *cls)
1039{ 1040{
1040 struct RequestHandle *handle = cls; 1041 struct RequestHandle *handle = cls;
1041 1042
1042 handle->identity = GNUNET_IDENTITY_connect (cfg, 1043 handle->identity = GNUNET_IDENTITY_connect(cfg,
1043 NULL, 1044 NULL,
1044 NULL); 1045 NULL);
1045 handle->id_op = GNUNET_IDENTITY_get(handle->identity, 1046 handle->id_op = GNUNET_IDENTITY_get(handle->identity,
1046 "credential-issuer", 1047 "credential-issuer",
1047 &get_cred_issuer_cb, 1048 &get_cred_issuer_cb,
1048 handle); 1049 handle);
1049 handle->timeout_task = GNUNET_SCHEDULER_add_delayed (handle->timeout, 1050 handle->timeout_task = GNUNET_SCHEDULER_add_delayed(handle->timeout,
1050 &do_error, 1051 &do_error,
1051 handle); 1052 handle);
1052} 1053}
1053 1054
1054static void 1055static void
1055options_cont (struct GNUNET_REST_RequestHandle *con_handle, 1056options_cont(struct GNUNET_REST_RequestHandle *con_handle,
1056 const char* url, 1057 const char* url,
1057 void *cls) 1058 void *cls)
1058{ 1059{
1059 struct MHD_Response *resp; 1060 struct MHD_Response *resp;
1060 struct RequestHandle *handle = cls; 1061 struct RequestHandle *handle = cls;
1061 1062
1062 //For GNS, independent of path return all options 1063 //For GNS, independent of path return all options
1063 resp = GNUNET_REST_create_response (NULL); 1064 resp = GNUNET_REST_create_response(NULL);
1064 MHD_add_response_header (resp, 1065 MHD_add_response_header(resp,
1065 "Access-Control-Allow-Methods", 1066 "Access-Control-Allow-Methods",
1066 MHD_HTTP_METHOD_GET); 1067 MHD_HTTP_METHOD_GET);
1067 handle->proc (handle->proc_cls, 1068 handle->proc(handle->proc_cls,
1068 resp, 1069 resp,
1069 MHD_HTTP_OK); 1070 MHD_HTTP_OK);
1070 cleanup_handle (handle); 1071 cleanup_handle(handle);
1071} 1072}
1072 1073
1073 1074
@@ -1076,7 +1077,7 @@ rest_credential_process_request(struct GNUNET_REST_RequestHandle *conndata_handl
1076 GNUNET_REST_ResultProcessor proc, 1077 GNUNET_REST_ResultProcessor proc,
1077 void *proc_cls) 1078 void *proc_cls)
1078{ 1079{
1079 struct RequestHandle *handle = GNUNET_new (struct RequestHandle); 1080 struct RequestHandle *handle = GNUNET_new(struct RequestHandle);
1080 struct GNUNET_REST_RequestHandlerError err; 1081 struct GNUNET_REST_RequestHandlerError err;
1081 1082
1082 handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; 1083 handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
@@ -1085,21 +1086,21 @@ rest_credential_process_request(struct GNUNET_REST_RequestHandle *conndata_handl
1085 handle->rest_handle = conndata_handle; 1086 handle->rest_handle = conndata_handle;
1086 1087
1087 static const struct GNUNET_REST_RequestHandler handlers[] = { 1088 static const struct GNUNET_REST_RequestHandler handlers[] = {
1088 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_CREDENTIAL_VERIFY, &verify_cred_cont}, 1089 { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_CREDENTIAL_VERIFY, &verify_cred_cont },
1089 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_CREDENTIAL_COLLECT, &collect_cred_cont}, 1090 { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_CREDENTIAL_COLLECT, &collect_cred_cont },
1090 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_CREDENTIAL_ISSUE, &issue_cred_cont}, 1091 { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_CREDENTIAL_ISSUE, &issue_cred_cont },
1091 {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_CREDENTIAL, &options_cont}, 1092 { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_CREDENTIAL, &options_cont },
1092 GNUNET_REST_HANDLER_END 1093 GNUNET_REST_HANDLER_END
1093 }; 1094 };
1094 1095
1095 if (GNUNET_NO == GNUNET_JSONAPI_handle_request (conndata_handle, 1096 if (GNUNET_NO == GNUNET_JSONAPI_handle_request(conndata_handle,
1096 handlers, 1097 handlers,
1097 &err, 1098 &err,
1098 handle)) 1099 handle))
1099 { 1100 {
1100 handle->response_code = err.error_code; 1101 handle->response_code = err.error_code;
1101 GNUNET_SCHEDULER_add_now (&do_error, handle); 1102 GNUNET_SCHEDULER_add_now(&do_error, handle);
1102 } 1103 }
1103} 1104}
1104 1105
1105 1106
@@ -1110,22 +1111,23 @@ rest_credential_process_request(struct GNUNET_REST_RequestHandle *conndata_handl
1110 * @return NULL on error, otherwise the plugin context 1111 * @return NULL on error, otherwise the plugin context
1111 */ 1112 */
1112void * 1113void *
1113libgnunet_plugin_rest_credential_init (void *cls) 1114libgnunet_plugin_rest_credential_init(void *cls)
1114{ 1115{
1115 static struct Plugin plugin; 1116 static struct Plugin plugin;
1117
1116 cfg = cls; 1118 cfg = cls;
1117 struct GNUNET_REST_Plugin *api; 1119 struct GNUNET_REST_Plugin *api;
1118 1120
1119 if (NULL != plugin.cfg) 1121 if (NULL != plugin.cfg)
1120 return NULL; /* can only initialize once! */ 1122 return NULL; /* can only initialize once! */
1121 memset (&plugin, 0, sizeof (struct Plugin)); 1123 memset(&plugin, 0, sizeof(struct Plugin));
1122 plugin.cfg = cfg; 1124 plugin.cfg = cfg;
1123 api = GNUNET_new (struct GNUNET_REST_Plugin); 1125 api = GNUNET_new(struct GNUNET_REST_Plugin);
1124 api->cls = &plugin; 1126 api->cls = &plugin;
1125 api->name = GNUNET_REST_API_NS_CREDENTIAL; 1127 api->name = GNUNET_REST_API_NS_CREDENTIAL;
1126 api->process_request = &rest_credential_process_request; 1128 api->process_request = &rest_credential_process_request;
1127 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1129 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1128 _("GNS REST API initialized\n")); 1130 _("GNS REST API initialized\n"));
1129 return api; 1131 return api;
1130} 1132}
1131 1133
@@ -1137,15 +1139,15 @@ libgnunet_plugin_rest_credential_init (void *cls)
1137 * @return always NULL 1139 * @return always NULL
1138 */ 1140 */
1139void * 1141void *
1140libgnunet_plugin_rest_credential_done (void *cls) 1142libgnunet_plugin_rest_credential_done(void *cls)
1141{ 1143{
1142 struct GNUNET_REST_Plugin *api = cls; 1144 struct GNUNET_REST_Plugin *api = cls;
1143 struct Plugin *plugin = api->cls; 1145 struct Plugin *plugin = api->cls;
1144 1146
1145 plugin->cfg = NULL; 1147 plugin->cfg = NULL;
1146 GNUNET_free (api); 1148 GNUNET_free(api);
1147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1149 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1148 "GNS REST plugin is finished\n"); 1150 "GNS REST plugin is finished\n");
1149 return NULL; 1151 return NULL;
1150} 1152}
1151 1153