summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-11-25 21:15:47 +0100
committerChristian Grothoff <christian@grothoff.org>2015-11-25 21:15:47 +0100
commit034884b08cc32ce3b9bc99ee12cd78a68a3cb495 (patch)
tree80728e53e564ddf052f206496fb7a627db2cbdca
parentba2cfa136c0835f79798f31c9abf67b423584697 (diff)
downloadmerchant-034884b08cc32ce3b9bc99ee12cd78a68a3cb495.tar.gz
merchant-034884b08cc32ce3b9bc99ee12cd78a68a3cb495.tar.bz2
merchant-034884b08cc32ce3b9bc99ee12cd78a68a3cb495.zip
refactor auditors code to be in its own file(s)
-rw-r--r--src/backend/Makefile.am1
-rw-r--r--src/backend/taler-merchant-httpd.c95
-rw-r--r--src/backend/taler-merchant-httpd.h7
-rw-r--r--src/backend/taler-merchant-httpd_auditors.c116
-rw-r--r--src/backend/taler-merchant-httpd_auditors.h52
-rw-r--r--src/backend/taler-merchant-httpd_contract.c62
-rw-r--r--src/backend/taler-merchant-httpd_contract.h7
-rw-r--r--src/backend/taler-merchant-httpd_pay.h8
8 files changed, 200 insertions, 148 deletions
diff --git a/src/backend/Makefile.am b/src/backend/Makefile.am
index 8d730f3e..d9f988a8 100644
--- a/src/backend/Makefile.am
+++ b/src/backend/Makefile.am
@@ -9,6 +9,7 @@ taler_merchant_httpd_SOURCES = \
taler-merchant-httpd_parsing.c taler-merchant-httpd_parsing.h \
taler-merchant-httpd_responses.c taler-merchant-httpd_responses.h \
taler-merchant-httpd_mhd.c taler-merchant-httpd_mhd.h \
+ taler-merchant-httpd_auditors.c taler-merchant-httpd_auditors.h \
taler-merchant-httpd_mints.c taler-merchant-httpd_mints.h \
taler-merchant-httpd_contract.c taler-merchant-httpd_contract.h \
taler-merchant-httpd_pay.c taler-merchant-httpd_pay.h
diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c
index 83c902fd..c2f6bb75 100644
--- a/src/backend/taler-merchant-httpd.c
+++ b/src/backend/taler-merchant-httpd.c
@@ -33,8 +33,9 @@
#include "taler_merchantdb_lib.h"
#include "taler-merchant-httpd.h"
#include "taler-merchant-httpd_mhd.h"
-#include "taler-merchant-httpd_contract.h"
+#include "taler-merchant-httpd_auditors.h"
#include "taler-merchant-httpd_mints.h"
+#include "taler-merchant-httpd_contract.h"
#include "taler-merchant-httpd_pay.h"
@@ -86,11 +87,6 @@ struct GNUNET_TIME_Relative edate_delay;
char *TMH_merchant_currency_string;
/**
- * Active auditors
- */
-struct MERCHANT_Auditor *auditors;
-
-/**
* Shutdown task identifier
*/
static struct GNUNET_SCHEDULER_Task *shutdown_task;
@@ -101,11 +97,6 @@ static struct GNUNET_SCHEDULER_Task *shutdown_task;
static struct GNUNET_SCHEDULER_Task *mhd_task;
/**
- * The number of active auditors
- */
-unsigned int nauditors;
-
-/**
* Should we do a dry run where temporary tables are used for storing the data.
*/
static int dry;
@@ -331,74 +322,6 @@ TMH_trigger_daemon ()
/**
- * Parses auditors from the configuration.
- *
- * @param cfg the configuration
- * @param mints the array of auditors upon successful parsing. Will be NULL upon
- * error.
- * @return the number of auditors in the above array; #GNUNET_SYSERR upon error in
- * parsing.
- */
-static int
-parse_auditors (const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct MERCHANT_Auditor **auditors)
-{
- char *auditors_str;
- char *token_nf; /* do no free (nf) */
- char *auditor_section;
- char *auditor_name;
- struct MERCHANT_Auditor *r_auditors;
- struct MERCHANT_Auditor auditor;
- unsigned int cnt;
- int ok;
-
- ok = 0;
- auditors_str = NULL;
- token_nf = NULL;
- auditor_section = NULL;
- auditor_name = NULL;
- r_auditors = NULL;
- cnt = 0;
- EXITIF (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "merchant",
- "AUDITORS",
- &auditors_str));
- for (token_nf = strtok (auditors_str, " ");
- NULL != token_nf;
- token_nf = strtok (NULL, " "))
- {
- GNUNET_assert (0 < GNUNET_asprintf (&auditor_section,
- "auditor-%s", token_nf));
- EXITIF (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- auditor_section,
- "NAME",
- &auditor_name));
- auditor.name = auditor_name;
- GNUNET_array_append (r_auditors, cnt, auditor);
- auditor_name = NULL;
- GNUNET_free (auditor_section);
- auditor_section = NULL;
- }
- ok = 1;
-
- EXITIF_exit:
- GNUNET_free_non_null (auditors_str);
- GNUNET_free_non_null (auditor_section);
- GNUNET_free_non_null (auditor_name);
- if (! ok)
- {
- GNUNET_free_non_null (r_auditors);
- return GNUNET_SYSERR;
- }
-
- *auditors = r_auditors;
- return cnt;
-}
-
-
-/**
* Parse the SEPA information from the configuration. If any of the
* required fields is missing return an error.
*
@@ -548,7 +471,7 @@ prepare_daemon ()
* @param cls closure
* @param args remaining command-line arguments
* @param cfgfile name of the configuration file used (for saving, can be
- * NULL!)
+ * NULL!)
* @param config configuration
*/
void
@@ -565,9 +488,7 @@ run (void *cls,
EXITIF (GNUNET_SYSERR ==
TMH_MINTS_parse_cfg (config));
EXITIF (GNUNET_SYSERR ==
- (nauditors =
- parse_auditors (config,
- &auditors)));
+ TMH_AUDITORS_init (config));
/* FIXME: for now, we just support SEPA here: */
EXITIF (GNUNET_OK !=
parse_wireformat_sepa (config));
@@ -605,11 +526,9 @@ run (void *cls,
EXITIF (GNUNET_SYSERR ==
GNUNET_CONFIGURATION_get_value_time (config,
- "merchant",
- "EDATE",
- &edate_delay));
-
-
+ "merchant",
+ "EDATE",
+ &edate_delay));
mhd = MHD_start_daemon (MHD_USE_SUSPEND_RESUME,
port,
diff --git a/src/backend/taler-merchant-httpd.h b/src/backend/taler-merchant-httpd.h
index a66148b0..26982c6d 100644
--- a/src/backend/taler-merchant-httpd.h
+++ b/src/backend/taler-merchant-httpd.h
@@ -153,13 +153,6 @@ extern struct GNUNET_CRYPTO_EddsaPrivateKey *privkey;
extern struct TALER_MerchantPublicKeyP pubkey;
-extern struct MERCHANT_Auditor *auditors;
-
-extern unsigned int nauditors;
-
-
-
-
extern PGconn *db_conn;
diff --git a/src/backend/taler-merchant-httpd_auditors.c b/src/backend/taler-merchant-httpd_auditors.c
new file mode 100644
index 00000000..ba3c63fc
--- /dev/null
+++ b/src/backend/taler-merchant-httpd_auditors.c
@@ -0,0 +1,116 @@
+/*
+ This file is part of TALER
+ (C) 2014, 2015 Christian Grothoff (and other contributing authors)
+
+ 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
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file backend/taler-merchant-httpd_auditors.c
+ * @brief logic this HTTPD keeps for each mint we interact with
+ * @author Marcello Stanisci
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler-merchant-httpd_auditors.h"
+
+/**
+ * Active auditors
+ */
+static struct MERCHANT_Auditor *auditors;
+
+/**
+ * The number of active auditors
+ */
+static unsigned int nauditors;
+
+/**
+ * Array of auditors accepted by this mint.
+ */
+json_t *j_auditors;
+
+
+/**
+ * Parses auditors from the configuration.
+ *
+ * @param cfg the configuration
+ * @param mints the array of auditors upon successful parsing. Will be NULL upon
+ * error.
+ * @return the number of auditors in the above array; #GNUNET_SYSERR upon error in
+ * parsing.
+ */
+int
+TMH_AUDITORS_init (const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ char *auditors_str;
+ char *token_nf; /* do no free (nf) */
+ char *auditor_section;
+ char *auditor_name;
+ struct MERCHANT_Auditor *r_auditors;
+ struct MERCHANT_Auditor auditor;
+ unsigned int cnt;
+ int ok;
+
+ ok = 0;
+ auditors_str = NULL;
+ token_nf = NULL;
+ auditor_section = NULL;
+ auditor_name = NULL;
+ r_auditors = NULL;
+ cnt = 0;
+ EXITIF (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ "merchant",
+ "AUDITORS",
+ &auditors_str));
+ for (token_nf = strtok (auditors_str, " ");
+ NULL != token_nf;
+ token_nf = strtok (NULL, " "))
+ {
+ GNUNET_assert (0 < GNUNET_asprintf (&auditor_section,
+ "auditor-%s", token_nf));
+ EXITIF (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ auditor_section,
+ "NAME",
+ &auditor_name));
+ auditor.name = auditor_name;
+ GNUNET_array_append (r_auditors, cnt, auditor);
+ auditor_name = NULL;
+ GNUNET_free (auditor_section);
+ auditor_section = NULL;
+ }
+ ok = 1;
+
+ EXITIF_exit:
+ GNUNET_free_non_null (auditors_str);
+ GNUNET_free_non_null (auditor_section);
+ GNUNET_free_non_null (auditor_name);
+ if (! ok)
+ {
+ GNUNET_free_non_null (r_auditors);
+ return GNUNET_SYSERR;
+ }
+
+ auditors = r_auditors;
+ nauditors = cnt;
+
+ /* Generate preferred mint(s) array. */
+ j_auditors = json_array ();
+ for (cnt = 0; cnt < nauditors; cnt++)
+ {
+ json_array_append_new (j_auditors,
+ json_pack ("{s:s}",
+ "name", auditors[cnt].name));
+ }
+
+ return nauditors;
+}
diff --git a/src/backend/taler-merchant-httpd_auditors.h b/src/backend/taler-merchant-httpd_auditors.h
new file mode 100644
index 00000000..3cbc4e1b
--- /dev/null
+++ b/src/backend/taler-merchant-httpd_auditors.h
@@ -0,0 +1,52 @@
+/*
+ This file is part of TALER
+ (C) 2014, 2015 Christian Grothoff (and other contributing authors)
+
+ 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
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file backend/taler-merchant-httpd_auditors.h
+ * @brief logic this HTTPD keeps for each mint we interact with
+ * @author Marcello Stanisci
+ * @author Christian Grothoff
+ */
+#ifndef TALER_MERCHANT_HTTPD_AUDITORS_H
+#define TALER_MERCHANT_HTTPD_AUDITORS_H
+
+#include <jansson.h>
+#include <gnunet/gnunet_util_lib.h>
+#include <curl/curl.h>
+#include <taler/taler_util.h>
+#include <taler/taler_mint_service.h>
+#include "taler-merchant-httpd.h"
+
+
+/**
+ * Array of auditors accepted by this mint.
+ */
+extern json_t *j_auditors;
+
+
+/**
+ * Parses auditors from the configuration.
+ *
+ * @param cfg the configuration
+ * @param mints the array of auditors upon successful parsing. Will be NULL upon
+ * error.
+ * @return the number of auditors in the above array; #GNUNET_SYSERR upon error in
+ * parsing.
+ */
+int
+TMH_AUDITORS_init (const struct GNUNET_CONFIGURATION_Handle *cfg);
+
+
+#endif
diff --git a/src/backend/taler-merchant-httpd_contract.c b/src/backend/taler-merchant-httpd_contract.c
index 81bf3ed9..090682e7 100644
--- a/src/backend/taler-merchant-httpd_contract.c
+++ b/src/backend/taler-merchant-httpd_contract.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- (C) 2014 Christian Grothoff (and other contributing authors)
+ (C) 2014, 2015 Christian Grothoff (and other contributing authors)
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
@@ -13,13 +13,11 @@
You should have received a copy of the GNU General Public License along with
TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
*/
-
/**
- * @file merchant/backend/taler-merchant-httpd.c
+ * @file backend/taler-merchant-httpd_contract.c
* @brief HTTP serving layer mainly intended to communicate with the frontend
* @author Marcello Stanisci
*/
-
#include "platform.h"
#include <microhttpd.h>
#include <jansson.h>
@@ -31,6 +29,7 @@
#include <taler/taler_mint_service.h>
#include "taler-merchant-httpd.h"
#include "taler-merchant-httpd_parsing.h"
+#include "taler-merchant-httpd_auditors.h"
#include "taler-merchant-httpd_mints.h"
#include "taler-merchant-httpd_responses.h"
#include "taler_merchantdb_lib.h"
@@ -58,14 +57,10 @@ MH_handler_contract (struct TMH_RequestHandler *rh,
size_t *upload_data_size)
{
json_t *root;
- json_t *j_auditors;
- json_t *auditor;
int res;
- int cnt;
struct GNUNET_HashCode h_wire;
struct GNUNET_CRYPTO_EddsaPublicKey pubkey;
struct TALER_ContractPS contract;
- char *contract_str;
struct GNUNET_CRYPTO_EddsaSignature contract_sig;
res = TMH_PARSE_post_json (connection,
@@ -75,38 +70,17 @@ MH_handler_contract (struct TMH_RequestHandler *rh,
&root);
if (GNUNET_SYSERR == res)
return MHD_NO;
- /* the POST's body has to be further fetched */ if ((GNUNET_NO == res) || (NULL == root))
+ /* the POST's body has to be further fetched */
+ if ((GNUNET_NO == res) || (NULL == root))
return MHD_YES;
- /* Generate preferred mint(s) array. */
-
- j_auditors = json_array ();
- for (cnt = 0; cnt < nauditors; cnt++)
- {
- auditor = json_pack ("{s:s}",
- "name", auditors[cnt].name);
- json_array_append_new (j_auditors, auditor);
- }
-
- /**
- * Return badly if no mints are trusted (or no call to /keys has still
- * returned the expected data). WARNING: it
- * may be possible that a mint trusted by the wallet is good, but
- * still pending; that case must be handled with some "polling-style"
- * routine, simply ignored, or ended with an invitation to the wallet
- * to just retry later
- */
- if (! json_array_size (trusted_mints))
- return MHD_NO;
-
- /**
- * Hard error, no action can be taken by a wallet
- */
- if (! json_array_size (j_auditors))
- return MHD_NO;
- json_object_set_new (root, "mints", trusted_mints);
- json_object_set_new (root, "auditors", j_auditors);
+ json_object_set_new (root,
+ "mints",
+ trusted_mints);
+ json_object_set_new (root,
+ "auditors",
+ j_auditors);
json_object_set_new (root,
"H_wire",
@@ -118,21 +92,23 @@ MH_handler_contract (struct TMH_RequestHandler *rh,
"merchant_pub",
TALER_json_from_data (&pubkey, sizeof (pubkey)));
- /* Sign */
- contract_str = json_dumps (root, JSON_COMPACT | JSON_SORT_KEYS);
- GNUNET_CRYPTO_hash (contract_str, strlen (contract_str), &contract.h_contract);
+ GNUNET_assert (GNUNET_OK ==
+ TALER_hash_json (root,
+ &contract.h_contract));
contract.purpose.purpose = htonl (TALER_SIGNATURE_MERCHANT_CONTRACT);
contract.purpose.size = htonl (sizeof (contract));
- GNUNET_CRYPTO_eddsa_sign (privkey, &contract.purpose, &contract_sig);
+ GNUNET_CRYPTO_eddsa_sign (privkey,
+ &contract.purpose,
+ &contract_sig);
return TMH_RESPONSE_reply_json_pack (connection,
MHD_HTTP_OK,
"{s:o, s:o, s:o}",
"contract", root,
"sig", TALER_json_from_data
- (&contract_sig, sizeof (contract_sig)),
+ (&contract_sig,
+ sizeof (contract_sig)),
"H_contract", TALER_json_from_data
(&contract.h_contract,
sizeof (contract.h_contract)));
-
}
diff --git a/src/backend/taler-merchant-httpd_contract.h b/src/backend/taler-merchant-httpd_contract.h
index 5a1aa6dd..44cef909 100644
--- a/src/backend/taler-merchant-httpd_contract.h
+++ b/src/backend/taler-merchant-httpd_contract.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- (C) 2014 Christian Grothoff (and other contributing authors)
+ (C) 2014, 2015 Christian Grothoff (and other contributing authors)
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
@@ -13,13 +13,11 @@
You should have received a copy of the GNU General Public License along with
TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
*/
-
/**
- * @file merchant/backend/taler-merchant-httpd_contract.h
+ * @file backend/taler-merchant-httpd_contract.h
* @brief headers for /contract handler
* @author Marcello Stanisci
*/
-
#ifndef TALER_MINT_HTTPD_CONTRACT_H
#define TALER_MINT_HTTPD_CONTRACT_H
#include <microhttpd.h>
@@ -33,7 +31,6 @@
* @param[in,out] connection_cls the connection's closure (can be updated)
* @param upload_data upload data
* @param[in,out] upload_data_size number of bytes (left) in @a upload_data
- *
* @return MHD result code
*/
int
diff --git a/src/backend/taler-merchant-httpd_pay.h b/src/backend/taler-merchant-httpd_pay.h
index 6fa7b8f3..0836f9ba 100644
--- a/src/backend/taler-merchant-httpd_pay.h
+++ b/src/backend/taler-merchant-httpd_pay.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- (C) 2014 Christian Grothoff (and other contributing authors)
+ (C) 2014, 2015 Christian Grothoff (and other contributing authors)
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
@@ -13,18 +13,17 @@
You should have received a copy of the GNU General Public License along with
TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
*/
-
/**
- * @file merchant/backend/taler-merchant-httpd_contract.h
+ * @file backend/taler-merchant-httpd_pay.h
* @brief headers for /pay handler
* @author Marcello Stanisci
*/
-
#ifndef TALER_MINT_HTTPD_PAY_H
#define TALER_MINT_HTTPD_PAY_H
#include <microhttpd.h>
#include "taler-merchant-httpd.h"
+
/**
* Manage a payment
*
@@ -33,7 +32,6 @@
* @param[in,out] connection_cls the connection's closure (can be updated)
* @param upload_data upload data
* @param[in,out] upload_data_size number of bytes (left) in @a upload_data
- *
* @return MHD result code
*/
int