aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-03-19 15:23:11 +0100
committerChristian Grothoff <christian@grothoff.org>2016-03-19 15:23:11 +0100
commit0d1eced630f4ed05ad95fdbb4354fd428c9cdbf6 (patch)
tree0ed4d6f189ed72287a0e003446c87a2b6db70c1a /src/include
parentd229f78da3b0b7f851d3541f59651b4f600c879d (diff)
first refactoring of JSON logic to address #4150 and #4237
Diffstat (limited to 'src/include')
-rw-r--r--src/include/taler_exchange_service.h23
-rw-r--r--src/include/taler_exchangedb_plugin.h1
-rw-r--r--src/include/taler_json_lib.h127
-rw-r--r--src/include/taler_pq_lib.h1
-rw-r--r--src/include/taler_util.h26
-rw-r--r--src/include/taler_wire_plugin.h6
6 files changed, 34 insertions, 150 deletions
diff --git a/src/include/taler_exchange_service.h b/src/include/taler_exchange_service.h
index 566dec6f8..c3ecba968 100644
--- a/src/include/taler_exchange_service.h
+++ b/src/include/taler_exchange_service.h
@@ -22,6 +22,7 @@
#ifndef _TALER_EXCHANGE_SERVICE_H
#define _TALER_EXCHANGE_SERVICE_H
+#include <jansson.h>
#include "taler_util.h"
/* ********************* event loop *********************** */
@@ -292,7 +293,7 @@ struct TALER_EXCHANGE_Keys
*/
typedef void
(*TALER_EXCHANGE_CertificationCallback) (void *cls,
- const struct TALER_EXCHANGE_Keys *keys);
+ const struct TALER_EXCHANGE_Keys *keys);
/**
@@ -319,10 +320,10 @@ struct TALER_EXCHANGE_Handle;
*/
struct TALER_EXCHANGE_Handle *
TALER_EXCHANGE_connect (struct TALER_EXCHANGE_Context *ctx,
- const char *url,
- TALER_EXCHANGE_CertificationCallback cert_cb,
- void *cert_cb_cls,
- ...);
+ const char *url,
+ TALER_EXCHANGE_CertificationCallback cert_cb,
+ void *cert_cb_cls,
+ ...);
/**
@@ -354,7 +355,7 @@ TALER_EXCHANGE_get_keys (const struct TALER_EXCHANGE_Handle *exchange);
*/
int
TALER_EXCHANGE_test_signing_key (const struct TALER_EXCHANGE_Keys *keys,
- const struct TALER_ExchangePublicKeyP *pub);
+ const struct TALER_ExchangePublicKeyP *pub);
/**
@@ -367,7 +368,7 @@ TALER_EXCHANGE_test_signing_key (const struct TALER_EXCHANGE_Keys *keys,
*/
const struct TALER_EXCHANGE_DenomPublicKey *
TALER_EXCHANGE_get_denomination_key (const struct TALER_EXCHANGE_Keys *keys,
- const struct TALER_DenominationPublicKey *pk);
+ const struct TALER_DenominationPublicKey *pk);
/**
@@ -379,7 +380,7 @@ TALER_EXCHANGE_get_denomination_key (const struct TALER_EXCHANGE_Keys *keys,
*/
const struct TALER_EXCHANGE_DenomPublicKey *
TALER_EXCHANGE_get_denomination_key_by_hash (const struct TALER_EXCHANGE_Keys *keys,
- const struct GNUNET_HashCode *hc);
+ const struct GNUNET_HashCode *hc);
/* ********************* /wire *********************** */
@@ -423,9 +424,9 @@ struct TALER_EXCHANGE_WireHandle;
*/
typedef void
(*TALER_EXCHANGE_WireResultCallback) (void *cls,
- unsigned int http_status,
- const char *method,
- json_t *obj);
+ unsigned int http_status,
+ const char *method,
+ json_t *obj);
/**
diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h
index aecb050a7..f45014463 100644
--- a/src/include/taler_exchangedb_plugin.h
+++ b/src/include/taler_exchangedb_plugin.h
@@ -22,6 +22,7 @@
#ifndef TALER_EXCHANGEDB_PLUGIN_H
#define TALER_EXCHANGEDB_PLUGIN_H
+#include <jansson.h>
#include <gnunet/gnunet_util_lib.h>
#include "taler_exchangedb_lib.h"
diff --git a/src/include/taler_json_lib.h b/src/include/taler_json_lib.h
index d9fa05188..aee151b97 100644
--- a/src/include/taler_json_lib.h
+++ b/src/include/taler_json_lib.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014, 2015 GNUnet e.V.
+ Copyright (C) 2014, 2015, 2016 GNUnet e.V.
TALER 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
@@ -17,14 +17,18 @@
* @file include/taler_json_lib.h
* @brief helper functions for JSON processing using libjansson
* @author Sree Harsha Totakura <sreeharsha@totakura.in>
+ * @author Christian Grothoff
*/
-#ifndef TALER_json_LIB_H_
-#define TALER_json_LIB_H_
+#ifndef TALER_JSON_LIB_H_
+#define TALER_JSON_LIB_H_
#include <jansson.h>
+#include <gnunet/gnunet_json_lib.h>
+#include "taler_util.h"
/**
* Print JSON parsing related error information
+ * @deprecated
*/
#define TALER_json_warn(error) \
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, \
@@ -39,106 +43,18 @@
* @return a json object describing the amount
*/
json_t *
-TALER_json_from_amount (const struct TALER_Amount *amount);
+TALER_JSON_from_amount (const struct TALER_Amount *amount);
/**
- * Convert absolute timestamp to a json string.
+ * Provide specification to parse given JSON object to an amount.
*
- * @param stamp the time stamp
- * @return a json string with the timestamp in @a stamp
- */
-json_t *
-TALER_json_from_abs (struct GNUNET_TIME_Absolute stamp);
-
-
-/**
- * Convert RSA public key to JSON.
- *
- * @param pk public key to convert
- * @return corresponding JSON encoding
- */
-json_t *
-TALER_json_from_rsa_public_key (struct GNUNET_CRYPTO_rsa_PublicKey *pk);
-
-
-/**
- * Convert RSA signature to JSON.
- *
- * @param sig signature to convert
- * @return corresponding JSON encoding
- */
-json_t *
-TALER_json_from_rsa_signature (struct GNUNET_CRYPTO_rsa_Signature *sig);
-
-
-/**
- * Convert binary data to a JSON string
- * with the base32crockford encoding.
- *
- * @param data binary data
- * @param size size of @a data in bytes
- * @return json string that encodes @a data
- */
-json_t *
-TALER_json_from_data (const void *data,
- size_t size);
-
-
-/**
- * Parse given JSON object to Amount
- *
- * @param json the json object representing Amount
+ * @param name name of the amount field in the JSON
* @param[out] r_amount where the amount has to be written
- * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
- */
-int
-TALER_json_to_amount (json_t *json,
- struct TALER_Amount *r_amount);
-
-/**
- * Parse given JSON object to absolute time.
- *
- * @param json the json object representing absolute time in seconds
- * @param[out] abs where the time has to be written
- * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
- */
-int
-TALER_json_to_abs (json_t *json,
- struct GNUNET_TIME_Absolute *abs);
-
-/**
- * Parse given JSON object to data
- *
- * @param json the json object representing data
- * @param out the pointer to hold the parsed data.
- * @param out_size the size of @a out
- * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
- */
-int
-TALER_json_to_data (json_t *json,
- void *out,
- size_t out_size);
-
-
-/**
- * Convert JSON to RSA public key.
- *
- * @param json JSON encoding to convert
- * @return corresponding public key
*/
-struct GNUNET_CRYPTO_rsa_PublicKey *
-TALER_json_to_rsa_public_key (json_t *json);
-
-
-/**
- * Convert JSON to RSA signature.
- *
- * @param json JSON encoding to convert
- * @return corresponding signature
- */
-struct GNUNET_CRYPTO_rsa_Signature *
-TALER_json_to_rsa_signature (json_t *json);
+struct GNUNET_JSON_Specification
+TALER_JSON_spec_amount (const char *name,
+ struct TALER_Amount *r_amount);
/**
@@ -149,22 +65,9 @@ TALER_json_to_rsa_signature (json_t *json);
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-TALER_hash_json (json_t *json,
+TALER_JSON_hash (json_t *json,
struct GNUNET_HashCode *hc);
-
-/**
- * Check if the given wire format JSON object is correctly formatted
- *
- * @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 **allowed,
- const json_t *wire);
-
-
-#endif /* TALER_json_LIB_H_ */
+#endif /* TALER_JSON_LIB_H_ */
/* End of taler_json_lib.h */
diff --git a/src/include/taler_pq_lib.h b/src/include/taler_pq_lib.h
index 49e067846..dfcea30e1 100644
--- a/src/include/taler_pq_lib.h
+++ b/src/include/taler_pq_lib.h
@@ -24,6 +24,7 @@
#define TALER_PQ_LIB_H_
#include <libpq-fe.h>
+#include <jansson.h>
#include <gnunet/gnunet_pq_lib.h>
#include "taler_util.h"
diff --git a/src/include/taler_util.h b/src/include/taler_util.h
index 380901812..f0da795a4 100644
--- a/src/include/taler_util.h
+++ b/src/include/taler_util.h
@@ -24,8 +24,6 @@
#include <gnunet/gnunet_util_lib.h>
#include "taler_amount_lib.h"
#include "taler_crypto_lib.h"
-#include "taler_json_lib.h"
-
/* Define logging functions */
@@ -98,30 +96,6 @@ TALER_b2s (const void *buf,
/**
- * Round a time value so that it is suitable for transmission
- * via JSON encodings.
- *
- * @param at time to round
- * @return #GNUNET_OK if time was already rounded, #GNUNET_NO if
- * it was just now rounded
- */
-int
-TALER_round_abs_time (struct GNUNET_TIME_Absolute *at);
-
-
-/**
- * Round a time value so that it is suitable for transmission
- * via JSON encodings.
- *
- * @param rt time to round
- * @return #GNUNET_OK if time was already rounded, #GNUNET_NO if
- * it was just now rounded
- */
-int
-TALER_round_rel_time (struct GNUNET_TIME_Relative *rt);
-
-
-/**
* Load configuration by parsing all configuration
* files in the given directory.
*
diff --git a/src/include/taler_wire_plugin.h b/src/include/taler_wire_plugin.h
index 8fb194c57..c80aa2e49 100644
--- a/src/include/taler_wire_plugin.h
+++ b/src/include/taler_wire_plugin.h
@@ -101,11 +101,15 @@ struct TALER_WIRE_Plugin
/**
* Check if the given wire format JSON object is correctly formatted
*
+ * @param cls the @e cls of this struct with the plugin-specific state
* @param wire the JSON wire format object
+ * @param master_pub public key of the exchange to verify against
* @return #GNUNET_YES if correctly formatted; #GNUNET_NO if not
*/
int
- (*wire_validate) (const json_t *wire);
+ (*wire_validate) (void *cls,
+ const json_t *wire,
+ const struct TALER_MasterPublicKeyP *master_pub);
/**