From 15b362373ff01ec9205ac921bdcdbb627455081a Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 28 Mar 2015 17:10:39 +0100 Subject: fix use of struct TALER_DepositRequestPS (unfinished) --- src/include/taler_mintdb_plugin.h | 22 ++++ src/mint/taler-mint-httpd_deposit.c | 32 ++++-- src/mint/taler-mint-httpd_parsing.c | 200 +++++++++++++++++++--------------- src/mint/taler-mint-httpd_parsing.h | 21 +++- src/mint/taler-mint-httpd_responses.c | 5 + 5 files changed, 178 insertions(+), 102 deletions(-) (limited to 'src') diff --git a/src/include/taler_mintdb_plugin.h b/src/include/taler_mintdb_plugin.h index 0cf8ba848..67ef3895b 100644 --- a/src/include/taler_mintdb_plugin.h +++ b/src/include/taler_mintdb_plugin.h @@ -239,6 +239,28 @@ struct TALER_MINTDB_Deposit */ uint64_t transaction_id; + /** + * Time when this request was generated. Used, for example, to + * assess when (roughly) the income was achieved for tax purposes. + * Note that the Mint will only check that the timestamp is not "too + * far" into the future (i.e. several days). The fact that the + * timestamp falls within the validity period of the coin's + * denomination key is irrelevant for the validity of the deposit + * request, as obviously the customer and merchant could conspire to + * set any timestamp. Also, the Mint must accept very old deposit + * requests, as the merchant might have been unable to transmit the + * deposit request in a timely fashion (so back-dating is not + * prevented). + */ + struct GNUNET_TIME_Absolute timestamp; + + /** + * How much time does the merchant have to issue a refund request? + * Zero if refunds are not allowed. After this time, the coin + * cannot be refunded. + */ + struct GNUNET_TIME_Absolute refund_deadline; + /** * Fraction of the coin's remaining value to be deposited, including * depositing fee (if any). The coin is identified by @e coin_pub. diff --git a/src/mint/taler-mint-httpd_deposit.c b/src/mint/taler-mint-httpd_deposit.c index 18f83240a..5bbc17464 100644 --- a/src/mint/taler-mint-httpd_deposit.c +++ b/src/mint/taler-mint-httpd_deposit.c @@ -64,9 +64,14 @@ verify_and_execute_deposit (struct MHD_Connection *connection, dr.purpose.size = htonl (sizeof (struct TALER_DepositRequestPS)); dr.h_contract = deposit->h_contract; dr.h_wire = deposit->h_wire; + dr.timestamp = GNUNET_TIME_absolute_hton (deposit->timestamp); + dr.refund_deadline = GNUNET_TIME_absolute_hton (deposit->refund_deadline); dr.transaction_id = GNUNET_htonll (deposit->transaction_id); TALER_amount_hton (&dr.amount_with_fee, &deposit->amount_with_fee); + TALER_amount_hton (&dr.deposit_fee, + &deposit->deposit_fee); + dr.merchant = deposit->merchant_pub; dr.coin_pub = deposit->coin.coin_pub; if (GNUNET_OK != GNUNET_CRYPTO_ecdsa_verify (TALER_SIGNATURE_WALLET_COIN_DEPOSIT, @@ -145,13 +150,15 @@ parse_and_handle_deposit_request (struct MHD_Connection *connection, TMH_PARSE_MEMBER_FIXED ("H_wire", &deposit.h_wire), TMH_PARSE_MEMBER_FIXED ("csig", &deposit.csig), TMH_PARSE_MEMBER_FIXED ("transaction_id", &deposit.transaction_id), + TMH_PARSE_MEMBER_TIME_ABS ("timestamp", &deposit.timestamp), + TMH_PARSE_MEMBER_TIME_ABS ("refund_deadline", &deposit.refund_deadline), TMH_PARSE_MEMBER_END }; memset (&deposit, 0, sizeof (deposit)); res = TMH_PARSE_json_data (connection, - root, - spec); + root, + spec); if (GNUNET_SYSERR == res) return MHD_NO; /* hard failure */ if (GNUNET_NO == res) @@ -169,7 +176,7 @@ parse_and_handle_deposit_request (struct MHD_Connection *connection, TALER_LOG_WARNING ("Failed to parse JSON wire format specification for /deposit request\n"); TMH_PARSE_release_data (spec); return TMH_RESPONSE_reply_arg_invalid (connection, - "wire"); + "wire"); } len = strlen (wire_enc) + 1; GNUNET_CRYPTO_hash (wire_enc, @@ -179,6 +186,7 @@ parse_and_handle_deposit_request (struct MHD_Connection *connection, deposit.wire = wire; deposit.amount_with_fee = *amount; + deposit.deposit_fee = *amount; // FIXME: get fee from denomination key! res = verify_and_execute_deposit (connection, &deposit); TMH_PARSE_release_data (spec); @@ -216,10 +224,10 @@ TMH_DEPOSIT_handler_deposit (struct TMH_RequestHandler *rh, json_t *f; res = TMH_PARSE_post_json (connection, - connection_cls, - upload_data, - upload_data_size, - &json); + connection_cls, + upload_data, + upload_data_size, + &json); if (GNUNET_SYSERR == res) return MHD_NO; if ( (GNUNET_NO == res) || (NULL == json) ) @@ -232,13 +240,13 @@ TMH_DEPOSIT_handler_deposit (struct TMH_RequestHandler *rh, GNUNET_break_op (0); json_decref (json); return TMH_RESPONSE_reply_json_pack (connection, - MHD_HTTP_BAD_REQUEST, - "{s:s}", - "error", "Bad format"); + MHD_HTTP_BAD_REQUEST, + "{s:s}", + "error", "Bad format"); } res = TMH_PARSE_amount_json (connection, - f, - &amount); + f, + &amount); json_decref (f); if (GNUNET_SYSERR == res) { diff --git a/src/mint/taler-mint-httpd_parsing.c b/src/mint/taler-mint-httpd_parsing.c index 5182e15fe..c9e060b9e 100644 --- a/src/mint/taler-mint-httpd_parsing.c +++ b/src/mint/taler-mint-httpd_parsing.c @@ -320,9 +320,9 @@ TMH_PARSE_mhd_request_arg_data (struct MHD_Connection *connection, */ int TMH_PARSE_mhd_request_var_arg_data (struct MHD_Connection *connection, - const char *param_name, - void **out_data, - size_t *out_size) + const char *param_name, + void **out_data, + size_t *out_size) { const char *str; size_t slen; @@ -567,12 +567,12 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, { ret = (MHD_YES == TMH_RESPONSE_reply_json_pack (connection, - MHD_HTTP_BAD_REQUEST, - "{s:s, s:o}", - "error", - "string expected", - "path", - path)) + MHD_HTTP_BAD_REQUEST, + "{s:s, s:o}", + "error", + "string expected", + "path", + path)) ? GNUNET_NO : GNUNET_SYSERR; break; } @@ -587,12 +587,12 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, GNUNET_free (buf); ret = (MHD_YES == TMH_RESPONSE_reply_json_pack (connection, - MHD_HTTP_BAD_REQUEST, - "{s:s, s:o}", - "error", - "malformed binary data in JSON", - "path", - path)) + MHD_HTTP_BAD_REQUEST, + "{s:s, s:o}", + "error", + "malformed binary data in JSON", + "path", + path)) ? GNUNET_NO : GNUNET_SYSERR; break; } @@ -603,12 +603,12 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, { ret = (MHD_YES == TMH_RESPONSE_reply_json_pack (connection, - MHD_HTTP_BAD_REQUEST, - "{s:s, s:o}", - "error", - "malformed RSA public key in JSON", - "path", - path)) + MHD_HTTP_BAD_REQUEST, + "{s:s, s:o}", + "error", + "malformed RSA public key in JSON", + "path", + path)) ? GNUNET_NO : GNUNET_SYSERR; break; } @@ -630,12 +630,12 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, { ret = (MHD_YES == TMH_RESPONSE_reply_json_pack (connection, - MHD_HTTP_BAD_REQUEST, - "{s:s, s:o}", - "error", - "string expected", - "path", - path)) + MHD_HTTP_BAD_REQUEST, + "{s:s, s:o}", + "error", + "string expected", + "path", + path)) ? GNUNET_NO : GNUNET_SYSERR; break; } @@ -650,12 +650,12 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, GNUNET_free (buf); ret = (MHD_YES == TMH_RESPONSE_reply_json_pack (connection, - MHD_HTTP_BAD_REQUEST, - "{s:s, s:o}", - "error", - "malformed binary data in JSON", - "path", - path)) + MHD_HTTP_BAD_REQUEST, + "{s:s, s:o}", + "error", + "malformed binary data in JSON", + "path", + path)) ? GNUNET_NO : GNUNET_SYSERR; break; } @@ -666,12 +666,12 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, { ret = (MHD_YES == TMH_RESPONSE_reply_json_pack (connection, - MHD_HTTP_BAD_REQUEST, - "{s:s, s:o}", - "error", - "malformed RSA signature in JSON", - "path", - path)) + MHD_HTTP_BAD_REQUEST, + "{s:s, s:o}", + "error", + "malformed RSA signature in JSON", + "path", + path)) ? GNUNET_NO : GNUNET_SYSERR; break; } @@ -684,8 +684,22 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, struct TALER_Amount *where = va_arg (argp, void *); ret = TMH_PARSE_amount_json (connection, - (json_t *) root, - where); + (json_t *) root, + where); + break; + } + + case TMH_PARSE_JNC_RET_TIME_ABSOLUTE: + { + struct GNUNET_TIME_Absolute *where = va_arg (argp, void *); +#if 0 + ret = TMH_PARSE_time_abs_json (connection, + (json_t *) root, + where); +#endif + GNUNET_assert (0); /* FIXME: not implemented (#3741) */ + (void) where; + ret = GNUNET_SYSERR; break; } @@ -693,7 +707,7 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, GNUNET_break (0); ret = (MHD_YES == TMH_RESPONSE_reply_internal_error (connection, - "unhandled value in switch")) + "unhandled value in switch")) ? GNUNET_NO : GNUNET_SYSERR; break; } @@ -742,64 +756,74 @@ TMH_PARSE_json_data (struct MHD_Connection *connection, return GNUNET_SYSERR; case TMH_PARSE_JNC_RET_DATA: ret = TMH_PARSE_navigate_json (connection, - root, - TMH_PARSE_JNC_FIELD, - spec[i].field_name, - TMH_PARSE_JNC_RET_DATA, - spec[i].destination, - spec[i].destination_size_in); + root, + TMH_PARSE_JNC_FIELD, + spec[i].field_name, + TMH_PARSE_JNC_RET_DATA, + spec[i].destination, + spec[i].destination_size_in); break; case TMH_PARSE_JNC_RET_DATA_VAR: ptr = NULL; ret = TMH_PARSE_navigate_json (connection, - root, - TMH_PARSE_JNC_FIELD, - spec[i].field_name, - TMH_PARSE_JNC_RET_DATA_VAR, - &ptr, - &spec[i].destination_size_out); + root, + TMH_PARSE_JNC_FIELD, + spec[i].field_name, + TMH_PARSE_JNC_RET_DATA_VAR, + &ptr, + &spec[i].destination_size_out); spec[i].destination = ptr; break; case TMH_PARSE_JNC_RET_TYPED_JSON: ptr = NULL; ret = TMH_PARSE_navigate_json (connection, - root, - TMH_PARSE_JNC_FIELD, - spec[i].field_name, - TMH_PARSE_JNC_RET_TYPED_JSON, - spec[i].type, - &ptr); + root, + TMH_PARSE_JNC_FIELD, + spec[i].field_name, + TMH_PARSE_JNC_RET_TYPED_JSON, + spec[i].type, + &ptr); *((void**)spec[i].destination) = ptr; break; case TMH_PARSE_JNC_RET_RSA_PUBLIC_KEY: ptr = NULL; ret = TMH_PARSE_navigate_json (connection, - root, - TMH_PARSE_JNC_FIELD, - spec[i].field_name, - TMH_PARSE_JNC_RET_RSA_PUBLIC_KEY, - &ptr); + root, + TMH_PARSE_JNC_FIELD, + spec[i].field_name, + TMH_PARSE_JNC_RET_RSA_PUBLIC_KEY, + &ptr); spec[i].destination = ptr; break; case TMH_PARSE_JNC_RET_RSA_SIGNATURE: ptr = NULL; ret = TMH_PARSE_navigate_json (connection, - root, - TMH_PARSE_JNC_FIELD, - spec[i].field_name, - TMH_PARSE_JNC_RET_RSA_SIGNATURE, - &ptr); + root, + TMH_PARSE_JNC_FIELD, + spec[i].field_name, + TMH_PARSE_JNC_RET_RSA_SIGNATURE, + &ptr); spec[i].destination = ptr; break; case TMH_PARSE_JNC_RET_AMOUNT: GNUNET_assert (sizeof (struct TALER_Amount) == spec[i].destination_size_in); ret = TMH_PARSE_navigate_json (connection, - root, - TMH_PARSE_JNC_FIELD, - spec[i].field_name, - TMH_PARSE_JNC_RET_AMOUNT, - &spec[i].destination); + root, + TMH_PARSE_JNC_FIELD, + spec[i].field_name, + TMH_PARSE_JNC_RET_AMOUNT, + &spec[i].destination); + break; + case TMH_PARSE_JNC_RET_TIME_ABSOLUTE: + GNUNET_assert (sizeof (struct GNUNET_TIME_Absolute) == + spec[i].destination_size_in); + ret = TMH_PARSE_navigate_json (connection, + root, + TMH_PARSE_JNC_FIELD, + spec[i].field_name, + TMH_PARSE_JNC_RET_TIME_ABSOLUTE, + &spec[i].destination); break; } } @@ -870,6 +894,8 @@ TMH_PARSE_release_data (struct TMH_PARSE_FieldSpecification *spec) 0, sizeof (struct TALER_Amount)); break; + case TMH_PARSE_JNC_RET_TIME_ABSOLUTE: + break; } } } @@ -888,8 +914,8 @@ TMH_PARSE_release_data (struct TMH_PARSE_FieldSpecification *spec) */ int TMH_PARSE_amount_json (struct MHD_Connection *connection, - json_t *f, - struct TALER_Amount *amount) + json_t *f, + struct TALER_Amount *amount) { json_int_t value; json_int_t fraction; @@ -907,9 +933,9 @@ TMH_PARSE_amount_json (struct MHD_Connection *connection, TALER_LOG_WARNING ("Failed to parse JSON amount specification\n"); if (MHD_YES != TMH_RESPONSE_reply_json_pack (connection, - MHD_HTTP_BAD_REQUEST, - "{s:s}", - "error", "Bad format")) + MHD_HTTP_BAD_REQUEST, + "{s:s}", + "error", "Bad format")) return GNUNET_SYSERR; return GNUNET_NO; } @@ -921,9 +947,9 @@ TMH_PARSE_amount_json (struct MHD_Connection *connection, TALER_LOG_WARNING ("Amount specified not in allowed range\n"); if (MHD_YES != TMH_RESPONSE_reply_json_pack (connection, - MHD_HTTP_BAD_REQUEST, - "{s:s}", - "error", "Amount outside of allowed range")) + MHD_HTTP_BAD_REQUEST, + "{s:s}", + "error", "Amount outside of allowed range")) return GNUNET_SYSERR; return GNUNET_NO; } @@ -933,10 +959,10 @@ TMH_PARSE_amount_json (struct MHD_Connection *connection, TALER_LOG_WARNING ("Currency specified not supported by this mint\n"); if (MHD_YES != TMH_RESPONSE_reply_json_pack (connection, - MHD_HTTP_BAD_REQUEST, - "{s:s, s:s}", - "error", "Currency not supported", - "currency", currency)) + MHD_HTTP_BAD_REQUEST, + "{s:s, s:s}", + "error", "Currency not supported", + "currency", currency)) return GNUNET_SYSERR; return GNUNET_NO; } diff --git a/src/mint/taler-mint-httpd_parsing.h b/src/mint/taler-mint-httpd_parsing.h index 087f3e110..6e10ac2a1 100644 --- a/src/mint/taler-mint-httpd_parsing.h +++ b/src/mint/taler-mint-httpd_parsing.h @@ -126,7 +126,14 @@ enum TMH_PARSE_JsonNavigationCommand * Return a `struct TALER_Amount` which was * encoded within its own json object. */ - TMH_PARSE_JNC_RET_AMOUNT + TMH_PARSE_JNC_RET_AMOUNT, + + /** + * Return a `struct GNUNET_TIME_Absolute` which was + * encoded within its own json object. + * Param: struct GNUNET_TIME_Absolute * + */ + TMH_PARSE_JNC_RET_TIME_ABSOLUTE }; @@ -215,8 +222,8 @@ struct TMH_PARSE_FieldSpecification */ int TMH_PARSE_json_data (struct MHD_Connection *connection, - const json_t *root, - struct TMH_PARSE_FieldSpecification *spec); + const json_t *root, + struct TMH_PARSE_FieldSpecification *spec); /** @@ -284,6 +291,14 @@ TMH_PARSE_release_data (struct TMH_PARSE_FieldSpecification *spec); */ #define TMH_PARSE_MEMBER_AMOUNT(field,amount) { field, amount, sizeof(*amount), 0, TMH_PARSE_JNC_RET_AMOUNT, 0 } +/** + * Generate line in parser specification for an absolute time. + * + * @param field name of the field + * @param atime a `struct GNUNET_TIME_Absolute *` to initialize + */ +#define TMH_PARSE_MEMBER_TIME_ABS(field,atime) { field, atime, sizeof(*atime), 0, TMH_PARSE_JNC_RET_TIME_ABSOLUTE, 0 } + /** * Generate line in parser specification indicating the end of the spec. */ diff --git a/src/mint/taler-mint-httpd_responses.c b/src/mint/taler-mint-httpd_responses.c index e2b982b9f..e8f657d25 100644 --- a/src/mint/taler-mint-httpd_responses.c +++ b/src/mint/taler-mint-httpd_responses.c @@ -348,9 +348,14 @@ compile_transaction_history (const struct TALER_MINTDB_TransactionList *tl) dr.purpose.size = htonl (sizeof (struct TALER_DepositRequestPS)); dr.h_contract = deposit->h_contract; dr.h_wire = deposit->h_wire; + dr.timestamp = GNUNET_TIME_absolute_hton (deposit->timestamp); + dr.refund_deadline = GNUNET_TIME_absolute_hton (deposit->refund_deadline); dr.transaction_id = GNUNET_htonll (deposit->transaction_id); TALER_amount_hton (&dr.amount_with_fee, &deposit->amount_with_fee); + TALER_amount_hton (&dr.deposit_fee, + &deposit->deposit_fee); + dr.merchant = deposit->merchant_pub; dr.coin_pub = deposit->coin.coin_pub; transaction = TALER_json_from_ecdsa_sig (&dr.purpose, &deposit->csig.ecdsa_signature); -- cgit v1.2.3