fixing 1584
[oweals/gnunet.git] / src / fs / gnunet-pseudonym.c
index 2d35e8e8c6a94dfbe5fef035058505b5dab13ebb..ba9213b5d0b046687d069910979976bf7c462d1b 100644 (file)
@@ -4,7 +4,7 @@
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 2, or (at your
+     by the Free Software Foundation; either version 3, or (at your
      option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
  */
 static unsigned int anonymity;
 
-/**
- * -A option.
- */
-static int start_automate;
-
-/**
- * -e option
- */
-static int stop_automate;
-
 /**
  * -C option
  */
@@ -65,11 +55,6 @@ static int print_local_only;
  */
 static struct GNUNET_CONTAINER_MetaData *adv_metadata;
 
-/**
- * -n option.
- */
-static int no_advertising;
-
 /**
  * -p option.
  */
@@ -100,6 +85,10 @@ static struct GNUNET_FS_Handle *h;
  */
 static struct GNUNET_FS_Namespace *ns;
 
+/**
+ * Our configuration.
+ */
+static const struct GNUNET_CONFIGURATION_Handle *cfg;
 
 static int ret;
 
@@ -126,11 +115,45 @@ ns_printer (void *cls,
 }
 
 
+static int
+pseudo_printer (void *cls,
+               const GNUNET_HashCode *
+               pseudonym,
+               const struct
+               GNUNET_CONTAINER_MetaData * md,
+               int rating)
+{
+  char *id;
+
+  id = GNUNET_PSEUDONYM_id_to_name (cfg,
+                                   pseudonym);
+  if (id == NULL)
+    {
+      GNUNET_break (0);
+      return GNUNET_OK;
+    }
+  fprintf (stdout, 
+          "%s (%d):\n",
+          id,
+          rating);
+  GNUNET_CONTAINER_meta_data_iterate (md,
+                                     &EXTRACTOR_meta_data_print, 
+                                     stdout);
+  fprintf (stdout, "\n");
+  GNUNET_free (id);
+  return GNUNET_OK;
+}
+
+
 static void
 post_advertising (void *cls,
                  const struct GNUNET_FS_Uri *uri,
                  const char *emsg)
 {
+  GNUNET_HashCode nsid;
+  char *set;
+  int delta;
+
   if (emsg != NULL)
     {
       fprintf (stderr, "%s", emsg);
@@ -143,17 +166,40 @@ post_advertising (void *cls,
                                      GNUNET_NO))
        ret = 1;
     }
-  if (0 != stop_automate)
-    {
-      GNUNET_break (0); // FIXME: not implemented
-    }
-  if (0 != start_automate)
-    {
-      GNUNET_break (0); // FIXME: not implemented
-    }
   if (NULL != rating_change)
     {
-      GNUNET_break (0); // FIXME: not implemented
+      set = rating_change;
+      while ((*set != '\0') && (*set != ':'))
+        set++;
+      if (*set != ':')
+       {
+         GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                     _("Invalid argument `%s'\n"),
+                     rating_change);
+       }
+      else
+       {
+         *set = '\0';
+         delta = strtol (&set[1], NULL, /* no error handling yet */
+                          10);
+         if (GNUNET_OK ==
+             GNUNET_PSEUDONYM_name_to_id (cfg,
+                                          rating_change,
+                                          &nsid))
+           {
+             (void) GNUNET_PSEUDONYM_rank (cfg,
+                                           &nsid,
+                                           delta);           
+           }
+         else
+           {
+             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                         _("Namespace `%s' unknown.\n"),
+                         rating_change);
+           }
+       }
+      GNUNET_free (rating_change);
+      rating_change = NULL;
     }
   if (0 != print_local_only)
     {
@@ -163,10 +209,10 @@ post_advertising (void *cls,
     }  
   else if (0 == no_remote_printing)
     {
-      GNUNET_break (0); // FIXME: not implemented
+      GNUNET_PSEUDONYM_list_all (cfg,
+                                &pseudo_printer,
+                                NULL);
     }
-  /* FIXME: is this OK here, or do we need
-     for completion of previous requests? */
   GNUNET_FS_stop (h);
 }
 
@@ -178,24 +224,26 @@ post_advertising (void *cls,
  * @param sched the scheduler to use
  * @param args remaining command-line arguments
  * @param cfgfile name of the configuration file used (for saving, can be NULL!)
- * @param cfg configuration
+ * @param c configuration
  */
 static void
 run (void *cls,
      struct GNUNET_SCHEDULER_Handle *sched,
      char *const *args,
      const char *cfgfile,
-     const struct GNUNET_CONFIGURATION_Handle *cfg)
+     const struct GNUNET_CONFIGURATION_Handle *c)
 {
-  struct GNUNET_FS_Uri *ns_uri;
   struct GNUNET_TIME_Absolute expiration;
+  char *emsg;
 
+  cfg = c;
   h = GNUNET_FS_start (sched,
                       cfg,
                       "gnunet-pseudonym",
                       &progress_cb,
                       NULL,
-                      GNUNET_FS_FLAGS_NONE);
+                      GNUNET_FS_FLAGS_NONE,
+                      GNUNET_FS_OPTIONS_END);
   if (NULL != delete_ns)
     {
       ns = GNUNET_FS_namespace_create (h, delete_ns);
@@ -221,80 +269,45 @@ run (void *cls,
        }
       else
        {
-         if (0 == no_advertising)
+         if (NULL != root_identifier)
            {
-             GNUNET_break (0); // FIXME: not implemented
-             ns_uri = NULL; // FIXME!!
              expiration = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_YEARS);
-             GNUNET_FS_publish_ksk (h,
-                                    ksk_uri,
-                                    adv_metadata,
-                                    ns_uri,
-                                    expiration,
-                                    anonymity,
-                                    priority,
-                                    GNUNET_FS_PUBLISH_OPTION_NONE,
-                                    &post_advertising,
-                                    NULL);
+             if (ksk_uri == NULL)
+               {
+                 emsg = NULL;
+                 ksk_uri = GNUNET_FS_uri_parse ("gnunet://fs/ksk/namespace", &emsg);
+                 GNUNET_assert (NULL == emsg);
+               }
+             GNUNET_FS_namespace_advertise (h,
+                                            ksk_uri,
+                                            ns,
+                                            adv_metadata,
+                                            anonymity,
+                                            priority,                                       
+                                            expiration,
+                                            root_identifier,
+                                            &post_advertising,
+                                            NULL);
              return;
            }
+         else
+           {
+             if (ksk_uri != NULL)
+               fprintf (stderr, _("Option `%s' ignored\n"), "-k");   
+           }
        }
     }
+  else
+    {
+      if (root_identifier != NULL) 
+       fprintf (stderr, _("Option `%s' ignored\n"), "-r");
+      if (ksk_uri != NULL)
+       fprintf (stderr, _("Option `%s' ignored\n"), "-k");   
+    }    
+    
   post_advertising (NULL, NULL, NULL);
 }
 
-/**
- * gnunet-pseudonym command line options
- */
-static struct GNUNET_GETOPT_CommandLineOption options[] = {
-  {'a', "anonymity", "LEVEL",
-   gettext_noop ("set the desired LEVEL of sender-anonymity"),
-   1, &GNUNET_GETOPT_set_uint, &anonymity},
-  {'A', "automate", NULL,
-   gettext_noop ("start a collection"),
-   0, &GNUNET_GETOPT_set_one, &start_automate},
-  {'C', "create", "NAME",
-   gettext_noop
-   ("create or advertise namespace NAME"),
-   1, &GNUNET_GETOPT_set_string, &create_ns},
-  {'D', "delete", "NAME",
-   gettext_noop
-   ("delete namespace NAME "),
-   1, &GNUNET_GETOPT_set_string, &delete_ns},
-  {'e', "end", NULL,
-   gettext_noop ("end current collection"),
-   0, &GNUNET_GETOPT_set_one, &stop_automate},
-  {'k', "keyword", "VALUE",
-  gettext_noop
-   ("add an additional keyword for the advertisment"
-    " (this option can be specified multiple times)"),
-   1, &GNUNET_FS_getopt_set_keywords, &ksk_uri},
-  {'l', "local-only", NULL,
-   gettext_noop ("print names of local namespaces"),
-   0, &GNUNET_GETOPT_set_one, &print_local_only},
-  {'m', "meta", "TYPE:VALUE",
-   gettext_noop ("set the meta-data for the given TYPE to the given VALUE"),
-   1, &GNUNET_FS_getopt_set_metadata, &adv_metadata},
-  {'n', "no-advertisement", NULL,
-   gettext_noop ("do not create an advertisement"),
-   0, &GNUNET_GETOPT_set_one, &no_advertising},
-  {'p', "priority", "PRIORITY",
-   gettext_noop ("use the given PRIORITY for the advertisments"),
-   1, &GNUNET_GETOPT_set_uint, &priority},
-  {'q', "quiet", NULL,
-   gettext_noop ("do not print names of remote namespaces"),
-   0, &GNUNET_GETOPT_set_one, &no_remote_printing},
-  {'r', "root", "ID",
-   gettext_noop
-   ("specify ID of the root of the namespace"),
-   1, &GNUNET_GETOPT_set_string, &root_identifier},
-  {'s', "set-rating", "ID:VALUE",
-   gettext_noop
-   ("change rating of namespace ID by VALUE"),
-   1, &GNUNET_GETOPT_set_string, &rating_change},
-  GNUNET_GETOPT_OPTION_END
-};
-
 
 /**
  * The main function to inspect GNUnet directories.
@@ -306,6 +319,45 @@ static struct GNUNET_GETOPT_CommandLineOption options[] = {
 int
 main (int argc, char *const *argv)
 {
+  static const struct GNUNET_GETOPT_CommandLineOption options[] = {
+    {'a', "anonymity", "LEVEL",
+     gettext_noop ("set the desired LEVEL of sender-anonymity"),
+     1, &GNUNET_GETOPT_set_uint, &anonymity},
+    {'C', "create", "NAME",
+     gettext_noop
+     ("create or advertise namespace NAME"),
+     1, &GNUNET_GETOPT_set_string, &create_ns},
+    {'D', "delete", "NAME",
+     gettext_noop
+     ("delete namespace NAME "),
+     1, &GNUNET_GETOPT_set_string, &delete_ns},
+    {'k', "keyword", "VALUE",
+     gettext_noop
+     ("add an additional keyword for the advertisment"
+      " (this option can be specified multiple times)"),
+     1, &GNUNET_FS_getopt_set_keywords, &ksk_uri},
+    {'m', "meta", "TYPE:VALUE",
+     gettext_noop ("set the meta-data for the given TYPE to the given VALUE"),
+     1, &GNUNET_FS_getopt_set_metadata, &adv_metadata},
+    {'o', "only-local", NULL,
+     gettext_noop ("print names of local namespaces"),
+     0, &GNUNET_GETOPT_set_one, &print_local_only},
+    {'p', "priority", "PRIORITY",
+     gettext_noop ("use the given PRIORITY for the advertisments"),
+     1, &GNUNET_GETOPT_set_uint, &priority},
+    {'q', "quiet", NULL,
+     gettext_noop ("do not print names of remote namespaces"),
+     0, &GNUNET_GETOPT_set_one, &no_remote_printing},
+    {'r', "root", "ID",
+     gettext_noop
+     ("specify ID of the root of the namespace"),
+     1, &GNUNET_GETOPT_set_string, &root_identifier},
+    {'s', "set-rating", "ID:VALUE",
+     gettext_noop
+     ("change rating of namespace ID by VALUE"),
+     1, &GNUNET_GETOPT_set_string, &rating_change},
+    GNUNET_GETOPT_OPTION_END
+  };
   return (GNUNET_OK ==
           GNUNET_PROGRAM_run (argc,
                               argv,