+
[oweals/gnunet.git] / src / credential / plugin_gnsrecord_credential.c
index 5c3c038323ec11529e165ea6f7298905f5f48794..cba362a50484162ba35b51062c546b14d497ae2d 100644 (file)
@@ -21,7 +21,7 @@
 /**
  * @file credential/plugin_gnsrecord_credential.c
  * @brief gnsrecord plugin to provide the API for CREDENTIAL records
- * @author Adnan Husain
+ * @author Martin Schanzenbach
  */
 
 #include "platform.h"
@@ -62,9 +62,9 @@ credential_value_to_string (void *cls,
     int i;
     if (data_size < sizeof (struct GNUNET_CREDENTIAL_DelegationRecord))
       return NULL; /* malformed */
-    memcpy (&sets,
-            data,
-            sizeof (sets));
+    GNUNET_memcpy (&sets,
+                   data,
+                   sizeof (sets));
     cdata = data;
     struct GNUNET_CREDENTIAL_DelegationSet set[ntohl(sets.set_count)];
     if (GNUNET_OK != GNUNET_CREDENTIAL_delegation_set_deserialize (GNUNET_ntohll (sets.data_size),
@@ -76,7 +76,7 @@ credential_value_to_string (void *cls,
     for (i=0;i<ntohl(sets.set_count);i++)
     {
       subject_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string (&set[i].subject_key);
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   "%d len attr\n", set[i].subject_attribute_len);
       if (0 == set[i].subject_attribute_len)
       {
@@ -125,6 +125,10 @@ credential_value_to_string (void *cls,
      GNUNET_free (cred);
      return cred_str;
    }
+   case GNUNET_GNSRECORD_TYPE_POLICY:
+   {
+     return GNUNET_strndup (data,data_size);
+   }
    default:
    return NULL;
   }
@@ -195,6 +199,13 @@ credential_string_to_value (void *cls,
         GNUNET_free (tmp_str);
         tmp_str = GNUNET_strdup (s);
         token = strtok (tmp_str, ",");
+        if (NULL == token)
+        {
+          GNUNET_free (tmp_str);
+          GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                      "Malformed string %s\n", s);
+          return GNUNET_SYSERR;
+        }
         struct GNUNET_CREDENTIAL_DelegationSet set[entries];
         for (i=0;i<entries;i++)
         {
@@ -213,9 +224,12 @@ credential_string_to_value (void *cls,
         }
         tmp_data_size = GNUNET_CREDENTIAL_delegation_set_get_size (entries,
                                                                    set);
-        
+
         if (-1 == tmp_data_size)
+        {
+          GNUNET_free (tmp_str);
           return GNUNET_SYSERR;
+        }
         *data_size += tmp_data_size;
         *data = sets = GNUNET_malloc (*data_size);
         GNUNET_CREDENTIAL_delegation_set_serialize (entries,
@@ -234,7 +248,7 @@ credential_string_to_value (void *cls,
         return GNUNET_OK;
       }
     case GNUNET_GNSRECORD_TYPE_CREDENTIAL:
-      { 
+      {
         struct GNUNET_CREDENTIAL_Credential *cred;
         cred = GNUNET_CREDENTIAL_credential_from_string (s);
 
@@ -242,6 +256,12 @@ credential_string_to_value (void *cls,
                                                              (char**)data);
         return GNUNET_OK;
       }
+    case GNUNET_GNSRECORD_TYPE_POLICY:
+      {
+        *data_size = strlen (s);
+        *data = GNUNET_strdup (s);
+        return GNUNET_OK;
+      }
     default:
       return GNUNET_SYSERR;
   }
@@ -258,6 +278,7 @@ static struct {
 } name_map[] = {
   { "CRED", GNUNET_GNSRECORD_TYPE_CREDENTIAL },
   { "ATTR", GNUNET_GNSRECORD_TYPE_ATTRIBUTE },
+  { "POLICY", GNUNET_GNSRECORD_TYPE_POLICY },
   { NULL, UINT32_MAX }
 };