[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] branch master updated: add flag to return 'not present' status
From: |
gnunet |
Subject: |
[gnunet] branch master updated: add flag to return 'not present' status from GNUNET_JSON_spec_mark_optional |
Date: |
Tue, 05 Apr 2022 17:15:20 +0200 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository gnunet.
The following commit(s) were added to refs/heads/master by this push:
new 2ea635b60 add flag to return 'not present' status from
GNUNET_JSON_spec_mark_optional
2ea635b60 is described below
commit 2ea635b60d3fcc4a242089084441ea8e2747c3d4
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Tue Apr 5 17:15:10 2022 +0200
add flag to return 'not present' status from GNUNET_JSON_spec_mark_optional
---
contrib/gana | 2 +-
src/include/gnunet_json_lib.h | 14 +++++++++++---
src/json/json.c | 34 +++++++++++++++++++++++-----------
3 files changed, 35 insertions(+), 15 deletions(-)
diff --git a/contrib/gana b/contrib/gana
index 20f2185df..17a624ac8 160000
--- a/contrib/gana
+++ b/contrib/gana
@@ -1 +1 @@
-Subproject commit 20f2185df6a7cb27cb2a175a300cd822ee8b0634
+Subproject commit 17a624ac8875b011ec29eed0891bde470088fec7
diff --git a/src/include/gnunet_json_lib.h b/src/include/gnunet_json_lib.h
index 6e73a3365..2002a0130 100644
--- a/src/include/gnunet_json_lib.h
+++ b/src/include/gnunet_json_lib.h
@@ -97,15 +97,21 @@ struct GNUNET_JSON_Specification
void *ptr;
/**
- * Number of bytes available in @e ptr.
+ * Pointer to set to true if this argument is
+ * indeed missing. Can be NULL.
*/
- size_t ptr_size;
+ bool *missing;
/**
* Where should we store the final size of @e ptr.
*/
size_t *size_ptr;
+ /**
+ * Number of bytes available in @e ptr.
+ */
+ size_t ptr_size;
+
/**
* Set to true if this component is optional.
*/
@@ -157,10 +163,12 @@ GNUNET_JSON_spec_end (void);
* Set the "optional" flag for a parser specification entry.
*
* @param spec specification to modify
+ * @param[out] missing set to true if the argument is missing, NULL is allowed.
* @return spec copy of @a spec with optional bit set
*/
struct GNUNET_JSON_Specification
-GNUNET_JSON_spec_mark_optional (struct GNUNET_JSON_Specification spec);
+GNUNET_JSON_spec_mark_optional (struct GNUNET_JSON_Specification spec,
+ bool *missing);
/**
diff --git a/src/json/json.c b/src/json/json.c
index 6d11b4fdd..07ec158be 100644
--- a/src/json/json.c
+++ b/src/json/json.c
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet
- Copyright (C) 2014-2017, 2021 GNUnet e.V.
+ Copyright (C) 2014-2017, 2021, 2022 GNUnet e.V.
GNUnet is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published
@@ -48,7 +48,11 @@ GNUNET_JSON_parse (const json_t *root,
if ( ( (NULL == pos) ||
(json_is_null (pos) ) ) &&
(spec[i].is_optional) )
+ {
+ if (NULL != spec[i].missing)
+ *spec[i].missing = true;
continue;
+ }
if ( (NULL == pos) ||
(GNUNET_OK !=
spec[i].parser (spec[i].cls,
@@ -67,17 +71,21 @@ GNUNET_JSON_parse (const json_t *root,
GNUNET_JSON_parse_free (spec);
return GNUNET_SYSERR;
}
+ if (NULL != spec[i].missing)
+ *spec[i].missing = false;
}
return GNUNET_OK; /* all OK! */
}
struct GNUNET_JSON_Specification
-GNUNET_JSON_spec_mark_optional (struct GNUNET_JSON_Specification spec)
+GNUNET_JSON_spec_mark_optional (struct GNUNET_JSON_Specification spec,
+ bool *missing)
{
struct GNUNET_JSON_Specification ret = spec;
ret.is_optional = true;
+ ret.missing = missing;
return ret;
}
@@ -104,7 +112,7 @@ GNUNET_JSON_parse_free (struct GNUNET_JSON_Specification
*spec)
* @param value actual value of the option as a string.
* @return #GNUNET_OK if parsing the value worked
*/
-static int
+static enum GNUNET_GenericReturnValue
set_json (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
void *scls,
const char *option,
@@ -113,7 +121,9 @@ set_json (struct GNUNET_GETOPT_CommandLineProcessorContext
*ctx,
json_t **json = scls;
json_error_t error;
- *json = json_loads (value, JSON_REJECT_DUPLICATES, &error);
+ *json = json_loads (value,
+ JSON_REJECT_DUPLICATES,
+ &error);
if (NULL == *json)
{
fprintf (stderr,
@@ -134,13 +144,15 @@ GNUNET_JSON_getopt (char shortName,
const char *description,
json_t **json)
{
- struct GNUNET_GETOPT_CommandLineOption clo = { .shortName = shortName,
- .name = name,
- .argumentHelp = argumentHelp,
- .description = description,
- .require_argument = 1,
- .processor = &set_json,
- .scls = (void *) json };
+ struct GNUNET_GETOPT_CommandLineOption clo = {
+ .shortName = shortName,
+ .name = name,
+ .argumentHelp = argumentHelp,
+ .description = description,
+ .require_argument = 1,
+ .processor = &set_json,
+ .scls = (void *) json
+ };
return clo;
}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnunet] branch master updated: add flag to return 'not present' status from GNUNET_JSON_spec_mark_optional,
gnunet <=