NAMESTORE/JSON: fix parsing exp and flags
[oweals/gnunet.git] / src / namestore / gnunet-namestore.c
index 8386a696dd1be1a1d8beceef73581fc5f8c62bd5..470716f43afc6e779081ca4a9d76f7ffbf21fe75 100644 (file)
@@ -14,6 +14,8 @@
     
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+     SPDX-License-Identifier: AGPL3.0-or-later
 */
 /**
  * @file gnunet-namestore.c
@@ -1000,7 +1002,7 @@ identity_cb (void *cls,
   GNUNET_free_non_null (ego_name);
   ego_name = NULL;
 
-  if (! (add|del|list|(NULL != nickstring)|(NULL != uri)|(NULL != reverse_pkey))|(NULL != recordset) )
+  if (! (add|del|list|(NULL != nickstring)|(NULL != uri)|(NULL != reverse_pkey)|(NULL != recordset)) )
   {
     /* nothing more to be done */
     fprintf (stderr,
@@ -1028,7 +1030,7 @@ identity_cb (void *cls,
     {
       fprintf (stderr,
                _("Missing option `%s' for operation `%s'\n"),
-               "-n", _("replace"));
+               "-R", _("replace"));
       GNUNET_SCHEDULER_shutdown ();
       ret = 1;
       return;
@@ -1334,6 +1336,10 @@ run (void *cls,
   (void) cls;
   (void) args;
   (void) cfgfile;
+  if (NULL != args[0])
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+               _("Superfluous command line arguments (starting with `%s') ignored\n"),
+               args[0]);
   if ( (NULL != args[0]) &&
        (NULL == uri) )
     uri = GNUNET_strdup (args[0]);
@@ -1370,6 +1376,7 @@ run (void *cls,
  * @param option name of the option (typically 'R')
  * @param value command line argument given; format is
  *        "TTL TYPE FLAGS VALUE" where TTL is an expiration time (rel or abs),
+ *        always given in seconds (without the unit),
  *         TYPE is a DNS/GNS record type, FLAGS is either "n" for no flags or
  *         a combination of 's' (shadow) and 'p' (public) and VALUE is the 
  *         value (in human-readable format)
@@ -1386,35 +1393,45 @@ multirecord_process (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
   struct GNUNET_GNSRECORD_Data record;
   char *cp;
   char *tok;
+  char *saveptr;
   int etime_is_rel;
   void *raw_data;
 
   (void) ctx;
   (void) option;
   cp = GNUNET_strdup (value);
-  tok = strtok (cp, " ");
+  tok = strtok_r (cp, " ", &saveptr);
   if (NULL == tok)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                _("Empty record line argument is not allowed.\n"));
     GNUNET_free (cp);
     return GNUNET_SYSERR;
   }
-  if (GNUNET_OK !=
-      parse_expiration (tok,
-                       &etime_is_rel,
-                       &record.expiration_time))
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
-               _("Invalid expiration time `%s'\n"),
-               tok);
-    GNUNET_free (cp);
-    return GNUNET_SYSERR;
+    char *etime_in_s;
+
+    GNUNET_asprintf (&etime_in_s,
+                    "%s s",
+                    tok);
+    if (GNUNET_OK !=
+       parse_expiration (etime_in_s,
+                         &etime_is_rel,
+                         &record.expiration_time))
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                 _("Invalid expiration time `%s' (must be without unit)\n"),
+                 tok);
+      GNUNET_free (cp);
+      GNUNET_free (etime_in_s);
+      return GNUNET_SYSERR;
+    }
+    GNUNET_free (etime_in_s);
   }
-  tok = strtok (NULL, " ");
+  tok = strtok_r (NULL, " ", &saveptr);
   if (NULL == tok)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                _("Missing entries in record line `%s'.\n"),
                value);
     GNUNET_free (cp);
@@ -1423,16 +1440,16 @@ multirecord_process (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
   record.record_type = GNUNET_GNSRECORD_typename_to_number (tok);
   if (UINT32_MAX == record.record_type)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                _("Unknown record type `%s'\n"),
                tok);
     GNUNET_free (cp);
     return GNUNET_SYSERR;
   }
-  tok = strtok (NULL, " ");
+  tok = strtok_r (NULL, " ", &saveptr);
   if (NULL == tok)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                _("Missing entries in record line `%s'.\n"),
                value);
     GNUNET_free (cp);
@@ -1449,7 +1466,7 @@ multirecord_process (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
   tok = strchr (&value[tok - cp], (unsigned char) ' ');
   if (NULL == tok)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                _("Missing entries in record line `%s'.\n"),
                value);
     GNUNET_free (cp);
@@ -1463,7 +1480,7 @@ multirecord_process (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
                                        &raw_data,
                                        &record.data_size))
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                _("Invalid record data for type %s: `%s'.\n"),
                GNUNET_GNSRECORD_number_to_typename (record.record_type),               
                tok);