diff options
author | Marcello Stanisci <marcello.stanisci@inria.fr> | 2015-11-03 17:32:29 +0100 |
---|---|---|
committer | Marcello Stanisci <marcello.stanisci@inria.fr> | 2015-11-03 17:32:29 +0100 |
commit | 6e80a32260f1edc4c36e758749dedaf1622cae62 (patch) | |
tree | 368100094ff1d8961c86ba1ee6717ac178c318d8 | |
parent | 2d198327bc71954ff4d78042f67612a3a3b40361 (diff) | |
download | merchant-6e80a32260f1edc4c36e758749dedaf1622cae62.tar.gz merchant-6e80a32260f1edc4c36e758749dedaf1622cae62.tar.bz2 merchant-6e80a32260f1edc4c36e758749dedaf1622cae62.zip |
Adding:
- new JNC for fetching strings within JSONs (tested, and presumably
to be included into the mint codebase).
- error handling if the the wallet gives (inside a deposit permission)
a wrong denomination key for a right mint
Fixing minor issues.
-rw-r--r-- | src/backend/taler-merchant-httpd.c | 17 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_pay.c | 59 | ||||
-rw-r--r-- | src/backend/taler-mint-httpd_parsing.c | 27 | ||||
-rw-r--r-- | src/backend/taler-mint-httpd_parsing.h | 13 | ||||
-rw-r--r-- | src/tests/deposit_permission.sample | 2 | ||||
-rw-r--r-- | src/tests/deposit_permission_backend.sample | 6 | ||||
-rw-r--r-- | src/tests/deposit_permission_edate_backend.sample | 10 |
7 files changed, 92 insertions, 42 deletions
diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c index 95dbec6b..288aa330 100644 --- a/src/backend/taler-merchant-httpd.c +++ b/src/backend/taler-merchant-httpd.c @@ -247,10 +247,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); } @@ -281,7 +281,12 @@ keys_mgmt_cb (void *cls, const struct TALER_MINT_Keys *keys) the wallet didn't exceede the limit imposed by the merchant on the total deposit fee for a purchase */ - ((struct MERCHANT_Mint *) cls)->pending = 0; + if (NULL != keys) + { + ((struct MERCHANT_Mint *) cls)->pending = 0; + } + else + printf ("no keys gotten\n"); } @@ -532,7 +537,7 @@ main (int argc, char *const *argv) if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, - "taler-merchant-serve", + "taler-merchant-http", "Serve merchant's HTTP interface", options, &run, NULL)) return 3; diff --git a/src/backend/taler-merchant-httpd_pay.c b/src/backend/taler-merchant-httpd_pay.c index 5258b6d7..5f69a847 100644 --- a/src/backend/taler-merchant-httpd_pay.c +++ b/src/backend/taler-merchant-httpd_pay.c @@ -49,11 +49,12 @@ extern struct GNUNET_TIME_Relative edate_delay; * @param coin_aggregate a coin "aggregate" is the JSON set of * values contained in a single cell of the 'coins' array sent * in a payment - * @param deposit_fee where to store the resulting deposi fee + * @param deposit_fee where to store the resulting deposit fee * @param mint_index the index which points the chosen mint within * the global 'mints' array * @return GNUNET_OK if successful, GNUNET_NO if the data supplied - * is invalid, GNUNET_SYSERR upon internal errors + * is invalid (including the case when the key is not found), + * GNUNET_SYSERR upon internal errors */ int deposit_fee_from_coin_aggregate (struct MHD_Connection *connection, @@ -67,7 +68,8 @@ deposit_fee_from_coin_aggregate (struct MHD_Connection *connection, struct TALER_DenominationPublicKey denom; struct TMH_PARSE_FieldSpecification spec[] = { - TMH_PARSE_member_denomination_public_key ("denom_pub", &denom) + TMH_PARSE_member_denomination_public_key ("denom_pub", &denom), + TMH_PARSE_MEMBER_END }; res = TMH_PARSE_json_data (connection, @@ -76,11 +78,24 @@ deposit_fee_from_coin_aggregate (struct MHD_Connection *connection, if (GNUNET_OK != res) return res; /* may return GNUNET_NO */ + /*printf ("mint %s (%d), pends: %d\n", + mints[mint_index].hostname, + mint_index, + mints[mint_index].pending);*/ + if (1 == mints[mint_index].pending) return GNUNET_SYSERR; keys = TALER_MINT_get_keys (mints[mint_index].conn); - denom_details = TALER_MINT_get_denomination_key (keys, &denom); + if (NULL == + (denom_details = TALER_MINT_get_denomination_key (keys, &denom))) + TMH_RESPONSE_reply_json_pack (connection, + MHD_HTTP_BAD_REQUEST, + "{s:s, s:o}", + "hint", "unknown denom to mint", + "denom_pub", TALER_json_from_rsa_public_key (denom.rsa_public_key)); + return GNUNET_NO; + *deposit_fee = denom_details->fee_deposit; return GNUNET_OK; } @@ -107,10 +122,9 @@ MH_handler_pay (struct TMH_RequestHandler *rh, json_t *root; json_t *coins; char *chosen_mint; - size_t chosen_mint_length; json_t *coin_aggregate; unsigned int coins_cnt; - unsigned int mint_index; //pointing global array + unsigned int mint_index; /*a cell in the global array*/ uint64_t transaction_id; int res; @@ -122,13 +136,11 @@ MH_handler_pay (struct TMH_RequestHandler *rh, struct TMH_PARSE_FieldSpecification spec[] = { TMH_PARSE_member_array ("coins", &coins), - TMH_PARSE_member_variable ("mint", - (void *) &chosen_mint, - &chosen_mint_length), - + TMH_PARSE_member_string ("mint", &chosen_mint), TMH_PARSE_member_amount ("max_fee", &max_fee), TMH_PARSE_member_time_abs ("timestamp", ×tamp), TMH_PARSE_member_uint64 ("transaction_id", &transaction_id), + TMH_PARSE_MEMBER_END }; res = TMH_PARSE_post_json (connection, connection_cls, @@ -141,8 +153,6 @@ MH_handler_pay (struct TMH_RequestHandler *rh, if ((GNUNET_NO == res) || (NULL == root)) return MHD_YES; - //printf ("/pay\n"); - res = TMH_PARSE_json_data (connection, root, spec); @@ -164,19 +174,26 @@ MH_handler_pay (struct TMH_RequestHandler *rh, merchant from POSTing coins to untrusted mints. */ - for (mint_index = 0; mint_index < nmints; mint_index++) + + for (mint_index = 0; mint_index <= nmints; mint_index++) { - if (0 == strncmp (mints[mint_index].hostname, - chosen_mint, chosen_mint_length)) + /* no mint found in array */ + if (mint_index == nmints) + { + mint_index = -1; break; - mint_index = -1; + } + + /* test it by checking public key */ + if (0 == strcmp (mints[mint_index].hostname, + chosen_mint)) + break; + } - if (-1 == mint_index); + if (-1 == mint_index) return TMH_RESPONSE_reply_external_error (connection, "unknown mint"); - printf ("mint idx %d", mint_index); - /* no 'edate' from frontend. Generate it here; it will be timestamp + a edate delay supplied in config file */ if (NULL == json_object_get (root, "edate")) @@ -197,7 +214,9 @@ MH_handler_pay (struct TMH_RequestHandler *rh, coin_aggregate, &coin_fee, mint_index); - if (GNUNET_OK != res) + if (GNUNET_NO == res) + return MHD_YES; + if (GNUNET_SYSERR == res) return MHD_NO; if (0 == coins_cnt) diff --git a/src/backend/taler-mint-httpd_parsing.c b/src/backend/taler-mint-httpd_parsing.c index 5c71e813..9efd6c23 100644 --- a/src/backend/taler-mint-httpd_parsing.c +++ b/src/backend/taler-mint-httpd_parsing.c @@ -184,6 +184,9 @@ release_data (struct TMH_PARSE_FieldSpecification *spec, case TMH_PARSE_JNC_FIELD: GNUNET_break (0); return; + case TMH_PARSE_JNC_RET_STRING: + GNUNET_break (0); + return; case TMH_PARSE_JNC_INDEX: GNUNET_break (0); return; @@ -351,7 +354,7 @@ TMH_PARSE_post_json (struct MHD_Connection *connection, * Generate line in parser specification for string. The returned * string is already nul-terminated internally by JSON, so no length * information is provided. The string will live as long as the containg - * JSON will, and mut not be freed by the user + * JSON will, and must not be freed by the user * @param field name of the field * @param[out] pointer to the string * @return corresponding field spec @@ -363,8 +366,6 @@ TMH_PARSE_member_string (const char *field, struct TMH_PARSE_FieldSpecification ret = {field, (void **) out, 0, NULL, TMH_PARSE_JNC_RET_STRING, 0}; return ret; - - } /** @@ -632,12 +633,12 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, break; case TMH_PARSE_JNC_RET_STRING: - { - void **where = va_arg (argp, void **); - *where = json_string_value (root); - ret = GNUNET_OK; - - } + { + void **where = va_arg (argp, void **); + *where = (void*) json_string_value (root); + ret = GNUNET_OK; + } + break; case TMH_PARSE_JNC_RET_DATA_VAR: { void **where = va_arg (argp, void **); @@ -985,6 +986,14 @@ TMH_PARSE_json_data (struct MHD_Connection *connection, (void **) spec[i].destination, spec[i].destination_size_out); break; + case TMH_PARSE_JNC_RET_STRING: + ret = TMH_PARSE_navigate_json (connection, + root, + TMH_PARSE_JNC_FIELD, + spec[i].field_name, + TMH_PARSE_JNC_RET_STRING, + spec[i].destination); + break; case TMH_PARSE_JNC_RET_TYPED_JSON: ret = TMH_PARSE_navigate_json (connection, root, diff --git a/src/backend/taler-mint-httpd_parsing.h b/src/backend/taler-mint-httpd_parsing.h index 0e959761..dae65092 100644 --- a/src/backend/taler-mint-httpd_parsing.h +++ b/src/backend/taler-mint-httpd_parsing.h @@ -271,7 +271,18 @@ TMH_PARSE_member_variable (const char *field, void **ptr, size_t *ptr_size); - +/** + * Generate line in parser specification for string. The returned + * string is already nul-terminated internally by JSON, so no length + * information is provided. The string will live as long as the containg + * JSON will, and must not be freed by the user + * @param field name of the field + * @param[out] pointer to the string + * @return corresponding field spec + */ +struct TMH_PARSE_FieldSpecification +TMH_PARSE_member_string (const char *field, + char **out); /** * Generate line in parser specification for 64-bit integer * given as an integer in JSON. diff --git a/src/tests/deposit_permission.sample b/src/tests/deposit_permission.sample index 8070d603..c1f2d704 100644 --- a/src/tests/deposit_permission.sample +++ b/src/tests/deposit_permission.sample @@ -1,4 +1,6 @@ { + "transaction_id" : 1, + "timestamp": "\/Date(1447334003)\/", "H_wire": "V1F0F5AWSNX60E6TXZEYDZRE84J8HMBGXEM09AEVV3N97MM75P6JQRSWR5KQVC1RBBF2SRXY7P10H0ZM0VETWPFAJJRBVJSXNMDWTYR", "merchant_pub": "BQ0TMTBV2XEJ8G2PXA9KRDD5WDT5EV29KPVS6J9RBQJCS8BCPQ70", "mint": "localmint", diff --git a/src/tests/deposit_permission_backend.sample b/src/tests/deposit_permission_backend.sample index 161a72d0..3cd920ed 100644 --- a/src/tests/deposit_permission_backend.sample +++ b/src/tests/deposit_permission_backend.sample @@ -1,7 +1,9 @@ { + "transaction_id" : 1, + "timestamp": "\/Date(1447334003)\/", "H_wire": "V1F0F5AWSNX60E6TXZEYDZRE84J8HMBGXEM09AEVV3N97MM75P6JQRSWR5KQVC1RBBF2SRXY7P10H0ZM0VETWPFAJJRBVJSXNMDWTYR", "merchant_pub": "BQ0TMTBV2XEJ8G2PXA9KRDD5WDT5EV29KPVS6J9RBQJCS8BCPQ70", - "mint": "localmint", + "mint": "demo.taler.net", "coins": [ { "f": { @@ -31,4 +33,4 @@ "fraction": 8, "currency": "KUDOS" } -}
\ No newline at end of file +} diff --git a/src/tests/deposit_permission_edate_backend.sample b/src/tests/deposit_permission_edate_backend.sample index db7609d5..259a62bc 100644 --- a/src/tests/deposit_permission_edate_backend.sample +++ b/src/tests/deposit_permission_edate_backend.sample @@ -1,7 +1,10 @@ { + "transaction_id" : 1, + "timestamp": "\/Date(1447334003)\/", + "edate": "\/Date(1447334003)\/", "H_wire": "V1F0F5AWSNX60E6TXZEYDZRE84J8HMBGXEM09AEVV3N97MM75P6JQRSWR5KQVC1RBBF2SRXY7P10H0ZM0VETWPFAJJRBVJSXNMDWTYR", "merchant_pub": "BQ0TMTBV2XEJ8G2PXA9KRDD5WDT5EV29KPVS6J9RBQJCS8BCPQ70", - "mint": "localmint", + "mint": "demo.taler.net", "coins": [ { "f": { @@ -30,6 +33,5 @@ "value": 3, "fraction": 8, "currency": "KUDOS" - }, - "edate": "\/Date(1447392206)\/" -}
\ No newline at end of file + } +} |