Listing of References with Attributes
authorMarkus Voggenreiter <Markus.Voggenreiter@tum.de>
Fri, 1 Nov 2019 09:59:01 +0000 (10:59 +0100)
committerSchanzenbach, Martin <mschanzenbach@posteo.de>
Mon, 13 Jan 2020 12:31:04 +0000 (13:31 +0100)
src/reclaim-attribute/reclaim_attribute.c
src/reclaim/plugin_rest_reclaim.c

index d958ba7f9387b0104552a25d34d860a09988e5d0..113ec7ef5418d961b21f8087c66a5dab95cc32e6 100644 (file)
@@ -426,7 +426,7 @@ GNUNET_RECLAIM_ATTESTATION_reference_new (const char *attr_name,
   GNUNET_memcpy (write_ptr, attr_name_tmp, strlen (attr_name_tmp) + 1);
   attr->name = write_ptr;
 
-  write_ptr = (char *) &attr[1];
+  write_ptr += strlen (attr_name) +1;
   GNUNET_memcpy (write_ptr, ref_value_tmp, strlen (ref_value_tmp) + 1);
   attr->reference_value = write_ptr;
 
index 7dd6588863071509d81b3ca9d42ba2bd1ffe2af9..f7713c284d6125582c998598c937dbf7cf26bc11 100644 (file)
@@ -638,7 +638,7 @@ static void
 attest_collect (void *cls,
                 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
                 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr,
-                const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest, 
+                const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest,
                 const struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *reference)
 {
   struct RequestHandle *handle = cls;
@@ -1045,7 +1045,6 @@ add_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
   GNUNET_JSON_parse_free (attrspec);
 }
 
-
 /**
  * Collect all attributes for an ego
  *
@@ -1054,47 +1053,77 @@ static void
 attr_collect (void *cls,
               const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
               const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr,
-              const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest, 
+              const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest,
               const struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *reference)
 {
   struct RequestHandle *handle = cls;
   json_t *attr_obj;
   const char *type;
-  char *tmp_value;
   char *id_str;
 
-  if (NULL == attr)
+  if ((NULL == attr)&& (NULL == reference))
   {
     GNUNET_RECLAIM_get_attributes_next (handle->attr_it);
     return;
   }
 
-  if ((NULL == attr->name) || (NULL == attr->data))
+  if (NULL == attr)
   {
-    GNUNET_RECLAIM_get_attributes_next (handle->attr_it);
-    return;
-  }
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute: %s\n", attr->name);
+    if ((NULL == reference->name) || (NULL == reference->reference_value))
+    {
+      GNUNET_RECLAIM_get_attributes_next (handle->attr_it);
+      return;
+    }
 
-  tmp_value = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type,
-                                                        attr->data,
-                                                        attr->data_size);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding reference as attribute: %s\n",
+                reference->name);
+
+
+    attr_obj = json_object ();
+    json_object_set_new (attr_obj, "name", json_string (reference->name));
+    json_object_set_new (attr_obj, "value", json_string (
+                           reference->reference_value));
+    id_str = GNUNET_STRINGS_data_to_string_alloc (&reference->id, sizeof(uint64_t));
+    json_object_set_new (attr_obj, "id", json_string (id_str));
+    char *flag;
+    flag = "1";
+    json_object_set_new (attr_obj, "flag", json_string (flag));
+    type = "String";
+    json_object_set_new (attr_obj, "type", json_string (type));
+    json_array_append (handle->resp_object, attr_obj);
+    json_decref (attr_obj);
+    GNUNET_RECLAIM_get_attributes_next (handle->attr_it);
 
-  attr_obj = json_object ();
-  json_object_set_new (attr_obj, "value", json_string (tmp_value));
-  json_object_set_new (attr_obj, "name", json_string (attr->name));
-  type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (attr->type);
-  json_object_set_new (attr_obj, "type", json_string (type));
-  id_str = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof(uint64_t));
-  json_object_set_new (attr_obj, "id", json_string (id_str));
-  json_array_append (handle->resp_object, attr_obj);
-  json_decref (attr_obj);
-  GNUNET_free (tmp_value);
-  GNUNET_RECLAIM_get_attributes_next (handle->attr_it);
+  }
+  else
+  {
+    if ((NULL == attr->name) || (NULL == attr->data))
+    {
+      GNUNET_RECLAIM_get_attributes_next (handle->attr_it);
+      return;
+    }
+    char *tmp_value;
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute: %s\n", attr->name);
+
+    tmp_value = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type,
+                                                          attr->data,
+                                                          attr->data_size);
+
+    attr_obj = json_object ();
+    json_object_set_new (attr_obj, "value", json_string (tmp_value));
+    json_object_set_new (attr_obj, "name", json_string (attr->name));
+    type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (attr->type);
+    json_object_set_new (attr_obj, "type", json_string (type));
+    id_str = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof(uint64_t));
+    json_object_set_new (attr_obj, "id", json_string (id_str));
+    json_array_append (handle->resp_object, attr_obj);
+    json_decref (attr_obj);
+    GNUNET_free (tmp_value);
+    GNUNET_RECLAIM_get_attributes_next (handle->attr_it);
+  }
 }
 
-
 /**
  * List attributes for identity request
  *