aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/test_wireformats.c24
-rw-r--r--src/util/wireformats.c26
2 files changed, 29 insertions, 21 deletions
diff --git a/src/util/test_wireformats.c b/src/util/test_wireformats.c
index ebb96604c..e4bd238f7 100644
--- a/src/util/test_wireformats.c
+++ b/src/util/test_wireformats.c
@@ -15,9 +15,9 @@
*/
/**
- * @file util/test_json_validations.c
+ * @file util/test_wireformats.c
* @brief Tests for JSON validations
- * @author Sree Harsha Totakura <sreeharsha@totakura.in>
+ * @author Sree Harsha Totakura <sreeharsha@totakura.in>
*/
#include "platform.h"
@@ -65,10 +65,18 @@ static const char * const unsupported_wire_str =
\"address\": \"foobar\"}";
-int
-main(int argc,
+int
+main(int argc,
const char *const argv[])
{
+ const char *unsupported[] = {
+ "unsupported",
+ NULL
+ };
+ const char *sepa[] = {
+ "SEPA",
+ NULL
+ };
json_t *wire;
json_error_t error;
int ret;
@@ -76,16 +84,16 @@ main(int argc,
GNUNET_log_setup ("test-json-validations", "WARNING", NULL);
(void) memset(&error, 0, sizeof(error));
GNUNET_assert (NULL != (wire = json_loads (unsupported_wire_str, 0, NULL)));
- GNUNET_assert (1 != TALER_json_validate_wireformat ("unsupported", wire));
+ GNUNET_assert (1 != TALER_json_validate_wireformat (unsupported, wire));
json_decref (wire);
GNUNET_assert (NULL != (wire = json_loads (invalid_wire_str, 0, NULL)));
- GNUNET_assert (1 != TALER_json_validate_wireformat ("SEPA", wire));
+ GNUNET_assert (1 != TALER_json_validate_wireformat (sepa, wire));
json_decref (wire);
GNUNET_assert (NULL != (wire = json_loads (invalid_wire_str2, 0, NULL)));
- GNUNET_assert (1 != TALER_json_validate_wireformat ("SEPA", wire));
+ GNUNET_assert (1 != TALER_json_validate_wireformat (sepa, wire));
json_decref (wire);
GNUNET_assert (NULL != (wire = json_loads (valid_wire_str, 0, &error)));
- ret = TALER_json_validate_wireformat ("SEPA", wire);
+ ret = TALER_json_validate_wireformat (sepa, wire);
json_decref (wire);
if (1 == ret)
return 0;
diff --git a/src/util/wireformats.c b/src/util/wireformats.c
index 88af4a438..5f9678526 100644
--- a/src/util/wireformats.c
+++ b/src/util/wireformats.c
@@ -395,12 +395,12 @@ struct FormatHandler
/**
* Check if the given wire format JSON object is correctly formatted
*
- * @param type the expected type of the wire format
+ * @param allowed NULL-terminated array of allowed wire format types
* @param wire the JSON wire format object
* @return #GNUNET_YES if correctly formatted; #GNUNET_NO if not
*/
int
-TALER_json_validate_wireformat (const char *type,
+TALER_json_validate_wireformat (const char **allowed,
const json_t *wire)
{
static const struct FormatHandler format_handlers[] = {
@@ -409,33 +409,33 @@ TALER_json_validate_wireformat (const char *type,
{ NULL, NULL}
};
unsigned int i;
- char *stype;
+ const char *stype;
json_error_t error;
UNPACK_EXITIF (0 != json_unpack_ex
((json_t *) wire,
&error, 0,
- "{"
- "s:s " /* TYPE: type */
- "}",
+ "{s:s}",
"type", &stype));
- if (0 != strcasecmp (type,
- stype))
+ for (i=0;NULL != allowed[i];i++)
+ if (0 == strcasecmp (allowed[i],
+ stype))
+ break;
+ if (NULL == allowed[i])
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Wireformat `%s' does not match mint's expected `%s' format\n",
- stype,
- type);
+ "Wireformat `%s' does not match mint's allowed formats\n",
+ stype);
return GNUNET_NO;
}
for (i=0;NULL != format_handlers[i].type;i++)
if (0 == strcasecmp (format_handlers[i].type,
- type))
+ stype))
return format_handlers[i].handler (wire);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Wireformat `%s' not supported\n",
- type);
+ stype);
return GNUNET_NO;
EXITIF_exit:
return GNUNET_NO;