summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcello Stanisci <marcello.stanisci@inria.fr>2015-10-26 16:28:11 +0100
committerMarcello Stanisci <marcello.stanisci@inria.fr>2015-10-26 16:28:11 +0100
commit4254332bd1bd01c41088a158d21d3e1e4ab4eb90 (patch)
tree2d6f044251b154927b3d1c9a646aebf0be1297c5
parentb0097e0389376fe5b1fc78684c53c2b0de647582 (diff)
downloadmerchant-4254332bd1bd01c41088a158d21d3e1e4ab4eb90.tar.gz
merchant-4254332bd1bd01c41088a158d21d3e1e4ab4eb90.tar.bz2
merchant-4254332bd1bd01c41088a158d21d3e1e4ab4eb90.zip
Fetching mint's details (compliant to the new API) from the
configuration file. To test.
-rw-r--r--src/backend-lib/Makefile.am2
-rw-r--r--src/backend-lib/merchant_api_contract.c22
-rw-r--r--src/backend-lib/merchant_api_deposit.c23
-rw-r--r--src/backend/Makefile.am3
-rw-r--r--src/backend/merchant.c95
-rw-r--r--src/backend/merchant.conf7
-rw-r--r--src/backend/taler-merchant-httpd.c113
-rw-r--r--src/backend/taler-merchant-httpd_contract.c4
-rw-r--r--src/backend/taler-merchant-httpd_contract.h46
-rw-r--r--src/include/merchant.h44
10 files changed, 329 insertions, 30 deletions
diff --git a/src/backend-lib/Makefile.am b/src/backend-lib/Makefile.am
index 230cb066..583c4d03 100644
--- a/src/backend-lib/Makefile.am
+++ b/src/backend-lib/Makefile.am
@@ -6,7 +6,7 @@ lib_LTLIBRARIES = \
include_HEADERS = \
taler_merchant_lib.h \
- taler_merchant_contract_lib.h
+ taler_merchant_contract_lib.h \
taler_merchant_deposit_lib.h
libtalermerchant_la_SOURCES = \
diff --git a/src/backend-lib/merchant_api_contract.c b/src/backend-lib/merchant_api_contract.c
index 5f6744aa..42e1e064 100644
--- a/src/backend-lib/merchant_api_contract.c
+++ b/src/backend-lib/merchant_api_contract.c
@@ -1,3 +1,25 @@
+/*
+ This file is part of TALER
+ (C) 2014 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 merchant/merchant_db.c
+ * @brief DB work related to contract management
+ * @author Marcello Stanisci
+ */
+
#include "platform.h"
#include <jansson.h>
#include <taler/taler_signatures.h>
diff --git a/src/backend-lib/merchant_api_deposit.c b/src/backend-lib/merchant_api_deposit.c
index 41d4ca3d..a3cae20c 100644
--- a/src/backend-lib/merchant_api_deposit.c
+++ b/src/backend-lib/merchant_api_deposit.c
@@ -1,3 +1,26 @@
+/*
+ This file is part of TALER
+ (C) 2014 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 merchant/merchant_db.c
+ * @brief DB and crypto work related to deposit management
+ * @author Marcello Stanisci
+ */
+
+
#include "platform.h"
#include <jansson.h>
#include <taler/taler_signatures.h>
diff --git a/src/backend/Makefile.am b/src/backend/Makefile.am
index 11b49002..f0c543ea 100644
--- a/src/backend/Makefile.am
+++ b/src/backend/Makefile.am
@@ -12,7 +12,8 @@ taler_merchant_httpd_SOURCES = \
taler-mint-httpd_responses.c taler-mint-httpd_responses.h \
taler-mint-httpd.h \
taler-mint-httpd_mhd.c taler-mint-httpd_mhd.h \
- ../backend-lib/taler-merchant-httpd_contract.h
+ taler-merchant-httpd_contract.c \
+ taler-merchant-httpd_contract.h
taler_merchant_httpd_LDADD = \
$(LIBGCRYPT_LIBS) \
diff --git a/src/backend/merchant.c b/src/backend/merchant.c
index f124a030..31223aeb 100644
--- a/src/backend/merchant.c
+++ b/src/backend/merchant.c
@@ -48,10 +48,18 @@ TALER_MERCHANT_parse_mints (const struct GNUNET_CONFIGURATION_Handle *cfg,
char *token_nf; /* do no free (nf) */
char *mint_section;
char *mint_hostname;
+ char *mint_country;
+ char *mint_city;
+ char *mint_state;
+ char *mint_region;
+ char *mint_province;
char *mint_pubkey_enc;
+ char *mint_street;
struct MERCHANT_MintInfo *r_mints;
struct MERCHANT_MintInfo mint;
unsigned long long mint_port;
+ unsigned long long mint_zip_code;
+ unsigned long long mint_street_no;
unsigned int cnt;
int OK;
@@ -60,6 +68,15 @@ TALER_MERCHANT_parse_mints (const struct GNUNET_CONFIGURATION_Handle *cfg,
token_nf = NULL;
mint_section = NULL;
mint_hostname = NULL;
+ mint_port = 0;
+ mint_country = NULL;
+ mint_city = NULL;
+ mint_state = NULL;
+ mint_region = NULL;
+ mint_province = NULL;
+ mint_zip_code = 0;
+ mint_street = NULL;
+ mint_street_no = 0;
mint_pubkey_enc = NULL;
r_mints = NULL;
cnt = 0;
@@ -73,6 +90,8 @@ TALER_MERCHANT_parse_mints (const struct GNUNET_CONFIGURATION_Handle *cfg,
{
GNUNET_assert (0 < GNUNET_asprintf (&mint_section,
"mint-%s", token_nf));
+ memset (&mint, 0, sizeof (mint));
+
EXITIF (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
mint_section,
@@ -92,14 +111,86 @@ TALER_MERCHANT_parse_mints (const struct GNUNET_CONFIGURATION_Handle *cfg,
GNUNET_CRYPTO_eddsa_public_key_from_string (mint_pubkey_enc,
strlen (mint_pubkey_enc),
&mint.pubkey));
+
+ EXITIF (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ mint_section,
+ "COUNTRY",
+ &mint_country));
+
+ EXITIF (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ mint_section,
+ "CITY",
+ &mint_city));
+
+
+ if (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ mint_section,
+ "STATE",
+ &mint_state))
+ mint.state = mint_state;
+
+
+ if (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ mint_section,
+ "REGION",
+ &mint_region))
+ mint.region = mint_region;
+
+
+ if (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ mint_section,
+ "PROVINCE",
+ &mint_province))
+ mint.province = mint_province;
+
+
+ EXITIF (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_number (cfg,
+ mint_section,
+ "ZIP_CODE",
+ &mint_zip_code));
+
+ EXITIF (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ mint_section,
+ "STREET",
+ &mint_street));
+
+ EXITIF (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_number (cfg,
+ mint_section,
+ "STREET_NUMBER",
+ &mint_street_no));
mint.hostname = mint_hostname;
mint.port = (uint16_t) mint_port;
+ mint.country = mint_country;
+ mint.city = mint_city;
+ mint.zip_code = (uint16_t) mint_zip_code;
+ mint.street = mint_street;
+ mint.street_no = (uint16_t) mint_street_no;
GNUNET_array_append (r_mints, cnt, mint);
+ GNUNET_free (mint_hostname);
mint_hostname = NULL;
- GNUNET_free (mint_pubkey_enc);
+ GNUNET_free (mint_country);
+ mint_country = NULL;
+ GNUNET_free (mint_city);
+ mint_city = NULL;
+ GNUNET_free_non_null (mint_state);
+ mint_state = NULL;
+ GNUNET_free_non_null (mint_region);
+ mint_region = NULL;
+ GNUNET_free_non_null (mint_province);
+ mint_province = NULL;
+ GNUNET_free_non_null (mint_pubkey_enc);
mint_pubkey_enc = NULL;
- GNUNET_free (mint_section);
+ GNUNET_free_non_null (mint_section);
mint_section = NULL;
+
}
OK = 1;
diff --git a/src/backend/merchant.conf b/src/backend/merchant.conf
index 3b637448..1f069a58 100644
--- a/src/backend/merchant.conf
+++ b/src/backend/merchant.conf
@@ -8,6 +8,13 @@ KEYFILE = merchant.priv
HOSTNAME = demo.taler.net
PORT = 80
PUBKEY = Q1WVGRGC1F4W7RYC6M23AEGFEXQEHQ730K3GG0B67VPHQSRR75H0
+COUNTRY = France
+CITY = Rennes
+REGION = Bretagne
+PROVINCE = Ile-et-Vilaine
+ZIP_CODE = 35510
+STREET = Avenue du General Leclerc
+STREET_NUMBER = 21
[merchant-db]
CONFIG = postgres:///taler
diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c
index 014b6fa6..0438f511 100644
--- a/src/backend/taler-merchant-httpd.c
+++ b/src/backend/taler-merchant-httpd.c
@@ -33,6 +33,7 @@
#include "merchant.h"
#include "taler_merchant_lib.h"
#include "taler-mint-httpd_mhd.h"
+#include "taler-merchant-httpd_contract.h"
/**
* Our hostname
@@ -60,7 +61,7 @@ char *keyfile;
static struct TALER_MINT_Context *mctx;
/**
- * Mints' URL,port,key triples
+ * Collection of all trusted mints informations
*/
struct MERCHANT_MintInfo *mint_infos;
@@ -231,10 +232,10 @@ url_handler (void *cls,
upload_data_size);
}
return TMH_MHD_handler_static_response (&h404,
- connection,
- con_cls,
- upload_data,
- upload_data_size);
+ connection,
+ con_cls,
+ upload_data,
+ upload_data_size);
}
@@ -296,6 +297,65 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
}
/**
+ * Debugging function which prints all non-null fields within
+ * a mint descriptor. FIXME: Convert 'printf' in 'GNUNET_log'
+ * @param mint mint whose values are getting dumped
+ */
+void
+dump_mint (struct MERCHANT_MintInfo *mint)
+{
+ char dump[];
+
+ #define GET_MINT_VALUE_STRING(fieldname) \
+ do { if (NULL != mint->fieldname) \
+ { \
+ dump = GNUNET_realloc (dump, strlen (dump) \
+ + strlen (mint->fieldname) \
+ + strlen ("fieldname: ") \
+ + 2); \
+ sprintf (dump[strlen (dump)], "fieldname: %s\n", mint->fieldname); \
+ } \
+ } while (0);
+
+ #define GET_MINT_VALUE_UINT16(fieldname) \
+ do { if (0 != mint->fieldname && mint->fieldname < 65536) \
+ { \
+ dump = GNUNET_realloc (dump, strlen (dump) \
+ + 5 \
+ + strlen ("fieldname: ") \
+ + 2); \
+ sprintf (dump[strlen (dump)], "fieldname: %d\n", mint->fieldname); \
+ } \
+ } while (0);
+
+ dump = GNUNET_malloc (1);
+
+ // TODO public key fetch
+
+ #define MAXUINT16 65536
+ if (0 != mint->port && mint->port <= MAXUINT16)
+ {
+ dump = GNUNET_realloc (dump, strlen (dump)
+ + 5
+ + strlen ("port: ")
+ + 1);
+
+ sprintf (dump[strlen (dump) + 1], "port: %d\n", mint->port);
+ }
+
+ GET_MINT_VALUE_STRING(state);
+ GET_MINT_VALUE_STRING(region);
+ GET_MINT_VALUE_STRING(province);
+ GET_MINT_VALUE_UINT16(zip_code);
+ GET_MINT_VALUE_STRING(street);
+ GET_MINT_VALUE_UINT16(street_no);
+
+ printf ("Dumping mint:\n%s", dump);
+ GNUNET_free (dump);
+
+}
+
+/**
* Main function that will be run by the scheduler.
*
* @param cls closure
@@ -317,6 +377,8 @@ run (void *cls, char *const *args, const char *cfgfile,
result = GNUNET_SYSERR;
shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
&do_shutdown, NULL);
+
+
EXITIF (GNUNET_SYSERR == (nmints = TALER_MERCHANT_parse_mints (config,
&mint_infos)));
EXITIF (NULL == (wire = TALER_MERCHANT_parse_wireformat_sepa (config)));
@@ -348,37 +410,38 @@ run (void *cls, char *const *args, const char *cfgfile,
for (cnt = 0; cnt < nmints; cnt++)
{
+ dump_mint (&mint_infos[cnt]);
+
struct Mint *mint;
struct GNUNET_HashCode mint_key;
mint = GNUNET_new (struct Mint);
mint->pubkey = mint_infos[cnt].pubkey;
+
/* port this to the new API */
+
+ /* ToTest
mint->conn = TALER_MINT_connect (mctx,
mint_infos[cnt].hostname,
&keys_mgmt_cb,
- keys_mgmt_cls); /*<- safe?segfault friendly?*/
-
- /* NOTE: the keys mgmt callback should roughly do what the following lines do */
+ keys_mgmt_cls);
EXITIF (NULL == mint->conn);
+ */
- EXITIF (GNUNET_SYSERR == GNUNET_CONTAINER_multipeermap_put
- (mints_map,
- (struct GNUNET_PeerIdentity *) /* to retrieve now from cb's args -> */&mint->pubkey,
- mint,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
-
- /* 1 create hash key
- 2 create big entry
- 3 put
- */
- GNUNET_CRYPTO_hash (mint_infos[cnt].hostname,
- strlen (mint_infos[cnt].hostname),
- &mint_key);
- GNUNET_CONTAINER_multihashmap_put (mints_hashmap,
- &mint_key,
- &mint_infos[cnt],
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+ EXITIF (GNUNET_SYSERR ==
+ GNUNET_CONTAINER_multipeermap_put (mints_map,
+ (struct GNUNET_PeerIdentity *) &mint->pubkey,
+ mint,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
+
+ GNUNET_CRYPTO_hash (mint_infos[cnt].hostname,
+ strlen (mint_infos[cnt].hostname),
+ &mint_key);
+
+ GNUNET_CONTAINER_multihashmap_put (mints_hashmap,
+ &mint_key,
+ &mint_infos[cnt],
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
}
mhd = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY,
diff --git a/src/backend/taler-merchant-httpd_contract.c b/src/backend/taler-merchant-httpd_contract.c
index cbbf2616..71b09ef7 100644
--- a/src/backend/taler-merchant-httpd_contract.c
+++ b/src/backend/taler-merchant-httpd_contract.c
@@ -27,6 +27,7 @@
#include <curl/curl.h>
#include <taler/taler_json_lib.h>
#include <taler/taler_mint_service.h>
+#include "taler-mint-httpd.h"
#include "taler-mint-httpd_parsing.h"
#include "taler-mint-httpd_responses.h"
#include "merchant_db.h"
@@ -68,7 +69,8 @@ MH_handler_contract (struct TMH_RequestHandler *rh,
*/
-
+ /* To suppress compilation warning */
+ return 0;
}
diff --git a/src/backend/taler-merchant-httpd_contract.h b/src/backend/taler-merchant-httpd_contract.h
new file mode 100644
index 00000000..5e72c514
--- /dev/null
+++ b/src/backend/taler-merchant-httpd_contract.h
@@ -0,0 +1,46 @@
+/*
+ This file is part of TALER
+ (C) 2014 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 merchant/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>
+#include "taler-mint-httpd.h"
+
+/**
+ * Manage a contract request
+ *
+ * @param rh context of the handler
+ * @param connection the MHD connection to handle
+ * @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
+MH_handler_contract (struct TMH_RequestHandler *rh,
+ struct MHD_Connection *connection,
+ void **connection_cls,
+ const char *upload_data,
+ size_t *upload_data_size);
+
+#endif
diff --git a/src/include/merchant.h b/src/include/merchant.h
index a5273507..dcd4388e 100644
--- a/src/include/merchant.h
+++ b/src/include/merchant.h
@@ -58,6 +58,50 @@ struct MERCHANT_MintInfo {
*/
uint16_t port;
+ /* According to the mint's location, some of the following
+ fields may be omitted. In case of numbers, they will be set
+ to zero, otherwise SET TO nuLL */
+
+ /**
+ * The Country where the mint operates from
+ */
+ char *country;
+
+ /**
+ * The city where the mint operates from
+ */
+ char *city;
+
+ /**
+ * The State (within a Country) where the mint
+ * operates from
+ */
+ char *state;
+
+ /**
+ * The region where the mint operates from
+ */
+ char *region;
+
+ /**
+ * The province where the mint operates from
+ */
+ char *province;
+
+ /**
+ * The ZIP code where the mint operates from
+ */
+ uint16_t zip_code;
+
+ /**
+ * The street's name where the mint operates from
+ */
+ char *street;
+
+ /**
+ * The street number where the mint operates from
+ */
+ uint16_t street_no;
};