aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2015-09-16 13:18:29 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2015-09-16 13:18:29 +0000
commita8bb50dcefdab19f4990995ded586b237501b2c1 (patch)
tree23f9318d56e995ead3037a07419d63ca7ade90a5
parent84df54a9f2aa5a81883cd789da311c627d338fb0 (diff)
downloadgnunet-a8bb50dcefdab19f4990995ded586b237501b2c1.tar.gz
gnunet-a8bb50dcefdab19f4990995ded586b237501b2c1.zip
- add identity attribute processing
-rw-r--r--src/identity-token/plugin_rest_identity_token.c59
1 files changed, 56 insertions, 3 deletions
diff --git a/src/identity-token/plugin_rest_identity_token.c b/src/identity-token/plugin_rest_identity_token.c
index cea0dbcf5..3800c38bd 100644
--- a/src/identity-token/plugin_rest_identity_token.c
+++ b/src/identity-token/plugin_rest_identity_token.c
@@ -75,6 +75,10 @@
75 */ 75 */
76#define GNUNET_REST_JSONAPI_IDENTITY_ISS_REQUEST "issuer" 76#define GNUNET_REST_JSONAPI_IDENTITY_ISS_REQUEST "issuer"
77 77
78/**
79 * Attributes passed to issue request
80 */
81#define GNUNET_IDENTITY_TOKEN_ATTR_LIST "requested_attrs"
78 82
79/** 83/**
80 * Error messages 84 * Error messages
@@ -254,6 +258,11 @@ struct RequestHandle
254 */ 258 */
255 struct JsonApiObject *resp_object; 259 struct JsonApiObject *resp_object;
256 260
261 /**
262 * ID Attribute list given
263 */
264 struct GNUNET_CONTAINER_MultiHashMap *attr_map;
265
257 266
258}; 267};
259 268
@@ -283,6 +292,8 @@ cleanup_handle (struct RequestHandle *handle)
283 GNUNET_NAMESTORE_cancel (handle->ns_qe); 292 GNUNET_NAMESTORE_cancel (handle->ns_qe);
284 if (NULL != handle->ns_handle) 293 if (NULL != handle->ns_handle)
285 GNUNET_NAMESTORE_disconnect (handle->ns_handle); 294 GNUNET_NAMESTORE_disconnect (handle->ns_handle);
295 if (NULL != handle->attr_map)
296 GNUNET_CONTAINER_multihashmap_destroy (handle->attr_map);
286 297
287 if (NULL != handle->url) 298 if (NULL != handle->url)
288 GNUNET_free (handle->url); 299 GNUNET_free (handle->url);
@@ -497,6 +508,7 @@ attr_collect (void *cls,
497 char* data; 508 char* data;
498 json_t *attr_arr; 509 json_t *attr_arr;
499 struct RequestHandle *handle = cls; 510 struct RequestHandle *handle = cls;
511 struct GNUNET_HashCode key;
500 512
501 if (NULL == label) 513 if (NULL == label)
502 { 514 {
@@ -506,14 +518,23 @@ attr_collect (void *cls,
506 return; 518 return;
507 } 519 }
508 520
509 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Adding attribute: %s\n", label); 521 GNUNET_CRYPTO_hash (label,
522 strlen (label),
523 &key);
510 524
511 if (0 == rd_count) 525 if (0 == rd_count ||
526 ( (NULL != handle->attr_map) &&
527 (GNUNET_YES != GNUNET_CONTAINER_multihashmap_contains (handle->attr_map,
528 &key))
529 )
530 )
512 { 531 {
513 GNUNET_NAMESTORE_zone_iterator_next (handle->ns_it); 532 GNUNET_NAMESTORE_zone_iterator_next (handle->ns_it);
514 return; 533 return;
515 } 534 }
516 535
536 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Adding attribute: %s\n", label);
537
517 if (1 == rd_count) 538 if (1 == rd_count)
518 { 539 {
519 if (rd->record_type == GNUNET_GNSRECORD_TYPE_ID_ATTR) 540 if (rd->record_type == GNUNET_GNSRECORD_TYPE_ID_ATTR)
@@ -951,8 +972,14 @@ rest_identity_process_request(struct RestConnectionDataHandle *conndata_handle,
951 void *proc_cls) 972 void *proc_cls)
952{ 973{
953 struct RequestHandle *handle = GNUNET_new (struct RequestHandle); 974 struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
975 struct GNUNET_HashCode key;
976 char* attr_list;
977 char* attr_list_tmp;
978 char* attr;
954 979
955 980 GNUNET_CRYPTO_hash (GNUNET_IDENTITY_TOKEN_ATTR_LIST,
981 strlen (GNUNET_IDENTITY_TOKEN_ATTR_LIST),
982 &key);
956 983
957 handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; 984 handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
958 985
@@ -963,6 +990,32 @@ rest_identity_process_request(struct RestConnectionDataHandle *conndata_handle,
963 handle->data = conndata_handle->data; 990 handle->data = conndata_handle->data;
964 handle->data_size = conndata_handle->data_size; 991 handle->data_size = conndata_handle->data_size;
965 handle->method = conndata_handle->method; 992 handle->method = conndata_handle->method;
993 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (handle->conndata_handle->url_param_map,
994 &key))
995 {
996 handle->attr_map = GNUNET_CONTAINER_multihashmap_create (5,
997 GNUNET_NO);
998 attr_list = GNUNET_CONTAINER_multihashmap_get (handle->conndata_handle->url_param_map,
999 &key);
1000 if (NULL != attr_list)
1001 {
1002 attr_list_tmp = GNUNET_strdup (attr_list);
1003 attr = strtok(attr_list_tmp, ",");
1004 for (; NULL != attr; attr = strtok (NULL, ","))
1005 {
1006 GNUNET_CRYPTO_hash (attr,
1007 strlen (attr),
1008 &key);
1009 GNUNET_CONTAINER_multihashmap_put (handle->attr_map,
1010 &key,
1011 attr,
1012 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
1013 }
1014 GNUNET_free (attr_list_tmp);
1015 }
1016 }
1017
1018
966 GNUNET_asprintf (&handle->url, "%s", conndata_handle->url); 1019 GNUNET_asprintf (&handle->url, "%s", conndata_handle->url);
967 if (handle->url[strlen (handle->url)-1] == '/') 1020 if (handle->url[strlen (handle->url)-1] == '/')
968 handle->url[strlen (handle->url)-1] = '\0'; 1021 handle->url[strlen (handle->url)-1] = '\0';