diff options
author | Marcello Stanisci <marcello.stanisci@inria.fr> | 2015-10-30 08:25:26 +0100 |
---|---|---|
committer | Marcello Stanisci <marcello.stanisci@inria.fr> | 2015-10-30 08:25:26 +0100 |
commit | a5658415628c57d7405036059eb03a9112a03596 (patch) | |
tree | 910f8f4a6825c38351a73559a4d1998266b39473 /src | |
parent | d0871c3b8fcd2cbeb37175579d6f114d048520e9 (diff) | |
download | merchant-a5658415628c57d7405036059eb03a9112a03596.tar.gz merchant-a5658415628c57d7405036059eb03a9112a03596.tar.bz2 merchant-a5658415628c57d7405036059eb03a9112a03596.zip |
adding auditors indication in contract generation, and auditor entry parsing from the config file
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/merchant.c | 67 | ||||
-rw-r--r-- | src/backend/merchant.conf | 9 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd.c | 16 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_contract.c | 21 | ||||
-rw-r--r-- | src/include/merchant.h | 23 |
5 files changed, 129 insertions, 7 deletions
diff --git a/src/backend/merchant.c b/src/backend/merchant.c index 4fa66f16..02b37fb8 100644 --- a/src/backend/merchant.c +++ b/src/backend/merchant.c @@ -97,6 +97,73 @@ TALER_MERCHANT_parse_mints (const struct GNUNET_CONFIGURATION_Handle *cfg, return cnt; } +/** + * 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 +TALER_MERCHANT_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 diff --git a/src/backend/merchant.conf b/src/backend/merchant.conf index f24611a9..68aeacfe 100644 --- a/src/backend/merchant.conf +++ b/src/backend/merchant.conf @@ -3,13 +3,16 @@ PORT = 9966 HOSTNAME = localhost TRUSTED_MINTS = taler KEYFILE = merchant.priv +CURRENCY = KUDOS +EDATE = 3 week +AUDITORS = france [mint-taler] -HOSTNAME = demo.taler.net - -[mint-localmint] HOSTNAME = localmint +[auditor-france] +NAME = Charles De Gaulle + [merchant-db] CONFIG = postgres:///talerdemo diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c index 3806115a..b0b37546 100644 --- a/src/backend/taler-merchant-httpd.c +++ b/src/backend/taler-merchant-httpd.c @@ -74,11 +74,16 @@ struct GNUNET_TIME_Relative edate; char *TMH_mint_currency_string; /** - * Mints' URL,port,key triples + * Trusted mints */ struct MERCHANT_Mint *mints; /** + * Active auditors + */ +struct MERCHANT_Auditor *auditors; + +/** * Shutdown task identifier */ static struct GNUNET_SCHEDULER_Task *shutdown_task; @@ -104,6 +109,11 @@ long long salt; unsigned int nmints; /** + * 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; @@ -423,6 +433,10 @@ run (void *cls, char *const *args, const char *cfgfile, (nmints = TALER_MERCHANT_parse_mints (config, &mints))); + EXITIF (GNUNET_SYSERR == + (nauditors = + TALER_MERCHANT_parse_auditors (config, + &auditors))); EXITIF (NULL == (wire = TALER_MERCHANT_parse_wireformat_sepa (config))); diff --git a/src/backend/taler-merchant-httpd_contract.c b/src/backend/taler-merchant-httpd_contract.c index 4d1584b3..834cfce8 100644 --- a/src/backend/taler-merchant-httpd_contract.c +++ b/src/backend/taler-merchant-httpd_contract.c @@ -37,9 +37,11 @@ #include "taler_merchant_lib.h" extern struct MERCHANT_Mint *mints; +extern struct MERCHANT_Auditor *auditors; extern struct GNUNET_CRYPTO_EddsaPrivateKey privkey; extern const struct MERCHANT_WIREFORMAT_Sepa *wire; extern unsigned int nmints; +extern unsigned int nauditors; extern PGconn *db_conn; extern long long salt; @@ -65,6 +67,8 @@ MH_handler_contract (struct TMH_RequestHandler *rh, { json_t *root; json_t *trusted_mints; + json_t *j_auditors; + json_t *auditor; json_t *mint; json_t *j_wire; const struct TALER_MINT_Keys *keys; @@ -83,8 +87,7 @@ 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. */ @@ -104,6 +107,13 @@ MH_handler_contract (struct TMH_RequestHandler *rh, json_array_append_new (trusted_mints, mint); } } + 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 @@ -116,7 +126,14 @@ MH_handler_contract (struct TMH_RequestHandler *rh, if (!json_array_size (trusted_mints)) return MHD_NO; + /** + * Hard error, no action can be taken by a wallet + */ + if (!json_array_size (auditors)) + return MHD_NO; + json_object_set_new (root, "mints", trusted_mints); + json_object_set_new (root, "auditors", j_auditors); if (NULL == (j_wire = MERCHANT_get_wire_json (wire, salt))) diff --git a/src/include/merchant.h b/src/include/merchant.h index 0efd4388..8289a337 100644 --- a/src/include/merchant.h +++ b/src/include/merchant.h @@ -41,7 +41,7 @@ } while (0) /** - * A mint + * Mint */ struct MERCHANT_Mint { @@ -63,6 +63,15 @@ struct MERCHANT_Mint }; +struct MERCHANT_Auditor +{ + /** + * Auditor's legal name + */ + char *name; + +}; + /** * The contract sent by the merchant to the wallet */ @@ -96,6 +105,18 @@ int TALER_MERCHANT_parse_mints (const struct GNUNET_CONFIGURATION_Handle *cfg, struct MERCHANT_Mint **mints); +/** + * 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 +TALER_MERCHANT_parse_auditors (const struct GNUNET_CONFIGURATION_Handle *cfg, + struct MERCHANT_Auditor **auditors); GNUNET_NETWORK_STRUCT_BEGIN struct MERCHANT_WIREFORMAT_Sepa |