+
[oweals/gnunet.git] / src / credential / gnunet-credential.c
index fb7bdb7f882cc5b29c3ae184237c4794241776bd..b5bcc4d433f1377b070180dea14ffcc47a8d67b3 100644 (file)
@@ -20,7 +20,7 @@
 /**
  * @file gnunet-credential.c
  * @brief command line tool to access command line Credential service
- * @author Adnan Husain
+ * @author Martin Schanzenbach
  */
 #include "platform.h"
 #include <gnunet_util_lib.h>
@@ -108,17 +108,17 @@ static char *issuer_attr;
 /**
  * Verify mode
  */
-static uint32_t verify;
+static int verify;
 
 /**
  * Issue mode
  */
-static uint32_t create_cred;
+static int create_cred;
 
 /**
  * Collect mode
  */
-static uint32_t collect;
+static int collect;
 
 /**
  * Task run on shutdown.  Cleans up everything.
@@ -130,7 +130,7 @@ do_shutdown (void *cls)
 {
   if (NULL != verify_request)
   {
-    GNUNET_CREDENTIAL_verify_cancel (verify_request);
+    GNUNET_CREDENTIAL_request_cancel (verify_request);
     verify_request = NULL;
   }
   if (NULL != credential)
@@ -158,13 +158,6 @@ do_timeout (void *cls)
   GNUNET_SCHEDULER_shutdown ();
 }
 
-/**
- * Function called with the result of a Credential lookup.
- *
- * @param cls the 'const char *' name that was resolved
- * @param cd_count number of records returned
- * @param cd array of @a cd_count records with the results
- */
 static void
 handle_collect_result (void *cls,
                       unsigned int d_count,
@@ -192,13 +185,6 @@ handle_collect_result (void *cls,
 }
 
 
-/**
- * Function called with the result of a Credential lookup.
- *
- * @param cls the 'const char *' name that was resolved
- * @param cd_count number of records returned
- * @param cd array of @a cd_count records with the results
- */
 static void
 handle_verify_result (void *cls,
                       unsigned int d_count,
@@ -385,12 +371,14 @@ run (void *cls,
       fprintf (stderr,
                _("Failed to connect to CREDENTIAL\n"));
       GNUNET_SCHEDULER_shutdown ();
+      return;
     }
     if (NULL == issuer_attr)
     {
       fprintf (stderr,
                _("You must provide issuer the attribute\n"));
       GNUNET_SCHEDULER_shutdown ();
+      return;
     }
 
     if (NULL == ego_name)
@@ -446,6 +434,7 @@ run (void *cls,
                _("Issuer public key `%s' is not well-formed\n"),
                issuer_key);
       GNUNET_SCHEDULER_shutdown ();
+      return;
     }
     credential = GNUNET_CREDENTIAL_connect (cfg);
 
@@ -454,12 +443,14 @@ run (void *cls,
       fprintf (stderr,
                _("Failed to connect to CREDENTIAL\n"));
       GNUNET_SCHEDULER_shutdown ();
+      return;
     }
     if (NULL == issuer_attr || NULL == subject_credential)
     {
       fprintf (stderr,
                _("You must provide issuer and subject attributes\n"));
       GNUNET_SCHEDULER_shutdown ();
+      return;
     }
 
     //Subject credentials are comma separated
@@ -471,6 +462,7 @@ run (void *cls,
                "Invalid subject credentials\n");
       GNUNET_free (tmp);
       GNUNET_SCHEDULER_shutdown ();
+      return;
     }
     int count = 1;
     int i;
@@ -504,6 +496,7 @@ run (void *cls,
     {
       GNUNET_free ((char*)credentials[i].issuer_attribute);
     }
+    GNUNET_free (tmp);
   } else if (GNUNET_YES == create_cred) {
     if (NULL == ego_name)
     {
@@ -537,34 +530,49 @@ run (void *cls,
 int
 main (int argc, char *const *argv)
 {
-  static const struct GNUNET_GETOPT_CommandLineOption options[] = {
-    {'I', "issue", NULL,
-      gettext_noop ("create credential"), 0,
-      &GNUNET_GETOPT_set_one, &create_cred},
-    {'V', "verify", NULL,
-      gettext_noop ("verify credential against attribute"), 0,
-      &GNUNET_GETOPT_set_one, &verify},
-    {'s', "subject", "PKEY",
-      gettext_noop ("The public key of the subject to lookup the credential for"), 1,
-      &GNUNET_GETOPT_set_string, &subject_key},
-    {'b', "credential", "CRED",
-      gettext_noop ("The name of the credential presented by the subject"), 1,
-      &GNUNET_GETOPT_set_string, &subject_credential},
-    {'i', "issuer", "PKEY",
-      gettext_noop ("The public key of the authority to verify the credential against"), 1,
-      &GNUNET_GETOPT_set_string, &issuer_key},
-    {'e', "ego", "EGO",
-      gettext_noop ("The ego to use"), 1,
-      &GNUNET_GETOPT_set_string, &ego_name},
-    {'a', "attribute", "ATTR",
-      gettext_noop ("The issuer attribute to verify against or to issue"), 1, 
-      &GNUNET_GETOPT_set_string, &issuer_attr},
-    {'T', "ttl", "EXP",
-      gettext_noop ("The time to live for the credential"), 1,
-      &GNUNET_GETOPT_set_string, &expiration},
-    {'g', "collect", NULL,
-      gettext_noop ("collect credentials"), 0,
-      &GNUNET_GETOPT_set_one, &collect},
+  struct GNUNET_GETOPT_CommandLineOption options[] = {
+    GNUNET_GETOPT_option_flag ('I',
+                               "issue",
+                               gettext_noop ("create credential"),
+                               &create_cred),
+    GNUNET_GETOPT_option_flag ('V',
+                               "verify",
+                               gettext_noop ("verify credential against attribute"),
+                               &verify),
+    GNUNET_GETOPT_option_string ('s',
+                                 "subject",
+                                 "PKEY",
+                                 gettext_noop ("The public key of the subject to lookup the credential for"),
+                                 &subject_key),
+    GNUNET_GETOPT_option_string ('b',
+                                 "credential",
+                                 "CRED",
+                                 gettext_noop ("The name of the credential presented by the subject"),
+                                 &subject_credential),
+    GNUNET_GETOPT_option_string ('i',
+                                 "issuer",
+                                 "PKEY",
+                                 gettext_noop ("The public key of the authority to verify the credential against"),
+                                 &issuer_key),
+    GNUNET_GETOPT_option_string ('e',
+                                 "ego",
+                                 "EGO",
+                                 gettext_noop ("The ego to use"),
+                                 &ego_name),
+    GNUNET_GETOPT_option_string ('a',
+                                 "attribute",
+                                 "ATTR",
+                                 gettext_noop ("The issuer attribute to verify against or to issue"),
+                                 &issuer_attr),
+    GNUNET_GETOPT_option_string ('T',
+                                 "ttl",
+                                 "EXP",
+                                 gettext_noop ("The time to live for the credential"),
+                                 &expiration),
+    GNUNET_GETOPT_option_flag ('g',
+                               "collect",
+                               gettext_noop ("collect credentials"),
+                               &collect),
     GNUNET_GETOPT_OPTION_END
   };
   int ret;