From 49da00cc2b857708d53fc092c0ff2bef96fe08e1 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 4 Jul 2015 21:27:28 +0200 Subject: [PATCH] fix misc small bugs --- src/mint-lib/mint_api_admin.c | 6 +-- src/mint-lib/test_mint_api.c | 2 +- src/mint/taler-mint-httpd_admin.c | 11 +++--- src/mint/taler-mint-httpd_deposit.c | 4 +- src/mint/taler-mint-httpd_parsing.c | 55 ++++++++++++++++++++++++++- src/mint/taler-mint-httpd_parsing.h | 26 ++++++++++--- src/mint/taler-mint-httpd_refresh.c | 2 +- src/mint/taler-mint-httpd_responses.c | 16 +++++++- 8 files changed, 99 insertions(+), 23 deletions(-) diff --git a/src/mint-lib/mint_api_admin.c b/src/mint-lib/mint_api_admin.c index c8f8f21d5..09cb3fa80 100644 --- a/src/mint-lib/mint_api_admin.c +++ b/src/mint-lib/mint_api_admin.c @@ -115,6 +115,9 @@ handle_admin_add_incoming_finished (void *cls, json_error_t error; json_t *json; + fprintf (stderr, + "FINISHED AAI request\n"); + json = NULL; if (0 == aai->eno) { @@ -203,9 +206,6 @@ admin_add_incoming_download_cb (char *bufptr, size_t msize; void *buf; - fprintf (stderr, - "Downloading %u bytes from aai\n", - (unsigned int) (nitems * size)); if (0 == size * nitems) { /* Nothing (left) to do */ diff --git a/src/mint-lib/test_mint_api.c b/src/mint-lib/test_mint_api.c index 06ce47bc5..cbcf83797 100644 --- a/src/mint-lib/test_mint_api.c +++ b/src/mint-lib/test_mint_api.c @@ -605,7 +605,7 @@ context_task (void *cls, rs = GNUNET_NETWORK_fdset_create (); GNUNET_NETWORK_fdset_copy_native (rs, &read_fd_set, - max_fd); + max_fd + 1); ws = GNUNET_NETWORK_fdset_create (); GNUNET_NETWORK_fdset_copy_native (ws, &write_fd_set, diff --git a/src/mint/taler-mint-httpd_admin.c b/src/mint/taler-mint-httpd_admin.c index 22ead53ee..ce63917ef 100644 --- a/src/mint/taler-mint-httpd_admin.c +++ b/src/mint/taler-mint-httpd_admin.c @@ -57,7 +57,7 @@ check_permissions (struct MHD_Connection *connection) { const struct sockaddr_in *sin = (const struct sockaddr_in *) addr; - if (INADDR_LOOPBACK != sin->sin_addr.s_addr) + if (INADDR_LOOPBACK != ntohl (sin->sin_addr.s_addr)) { res = TMH_RESPONSE_reply_permission_denied (connection, "/admin/ only allowed via loopback"); @@ -114,17 +114,16 @@ TMH_ADMIN_handler_admin_add_incoming (struct TMH_RequestHandler *rh, json_t *root; struct TMH_PARSE_FieldSpecification spec[] = { TMH_PARSE_MEMBER_FIXED ("reserve_pub", &reserve_pub), - TMH_PARSE_MEMBER_AMOUNT ("amount", &amount), - TMH_PARSE_MEMBER_TIME_ABS ("execution_date", &at), - TMH_PARSE_MEMBER_OBJECT ("wire", &wire), + TMH_PARSE_member_amount ("amount", &amount), + TMH_PARSE_member_time_abs ("execution_date", &at), + TMH_PARSE_member_object ("wire", &wire), TMH_PARSE_MEMBER_END }; int res; res = check_permissions (connection); if (GNUNET_OK != res) - return (GNUNET_OK == res) ? MHD_YES : MHD_NO; - + return (GNUNET_NO == res) ? MHD_YES : MHD_NO; res = TMH_PARSE_post_json (connection, connection_cls, upload_data, diff --git a/src/mint/taler-mint-httpd_deposit.c b/src/mint/taler-mint-httpd_deposit.c index 53187dcb0..1d4ef26df 100644 --- a/src/mint/taler-mint-httpd_deposit.c +++ b/src/mint/taler-mint-httpd_deposit.c @@ -147,8 +147,8 @@ parse_and_handle_deposit_request (struct MHD_Connection *connection, TMH_PARSE_MEMBER_FIXED ("H_wire", &deposit.h_wire), TMH_PARSE_MEMBER_FIXED ("coin_sig", &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_time_abs ("timestamp", &deposit.timestamp), + TMH_PARSE_member_time_abs ("refund_deadline", &deposit.refund_deadline), TMH_PARSE_MEMBER_END }; diff --git a/src/mint/taler-mint-httpd_parsing.c b/src/mint/taler-mint-httpd_parsing.c index 15c7215ea..d48674d2b 100644 --- a/src/mint/taler-mint-httpd_parsing.c +++ b/src/mint/taler-mint-httpd_parsing.c @@ -531,6 +531,7 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, if ( (-1 != typ) && (json_typeof (root) != typ)) { + *r_json = NULL; ret = (MHD_YES == TMH_RESPONSE_reply_json_pack (connection, MHD_HTTP_BAD_REQUEST, @@ -543,6 +544,7 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, break; } *r_json = root; + json_incref ((json_t *) root); ret = GNUNET_OK; } break; @@ -793,7 +795,7 @@ TMH_PARSE_json_data (struct MHD_Connection *connection, TMH_PARSE_JNC_FIELD, spec[i].field_name, TMH_PARSE_JNC_RET_AMOUNT, - &spec[i].destination); + spec[i].destination); break; case TMH_PARSE_JNC_RET_TIME_ABSOLUTE: GNUNET_assert (sizeof (struct GNUNET_TIME_Absolute) == @@ -803,7 +805,7 @@ TMH_PARSE_json_data (struct MHD_Connection *connection, TMH_PARSE_JNC_FIELD, spec[i].field_name, TMH_PARSE_JNC_RET_TIME_ABSOLUTE, - &spec[i].destination); + spec[i].destination); break; } } @@ -1049,5 +1051,54 @@ TMH_PARSE_amount_json (struct MHD_Connection *connection, } +/** + * Generate line in parser specification for JSON object value. + * + * @param field name of the field + * @param ptraddr address of pointer to JSON to initialize + * @return corresponding field spec + */ +struct TMH_PARSE_FieldSpecification +TMH_PARSE_member_object (const char *field, + json_t **jsonp) +{ + struct TMH_PARSE_FieldSpecification ret = + { field, (void **) jsonp, 0, 0, TMH_PARSE_JNC_RET_TYPED_JSON, JSON_OBJECT }; + return ret; +} + + +/** + * Generate line in parser specification for an absolute time. + * + * @param field name of the field + * @param[out] atime time to initialize + */ +struct TMH_PARSE_FieldSpecification +TMH_PARSE_member_time_abs (const char *field, + struct GNUNET_TIME_Absolute *atime) +{ + struct TMH_PARSE_FieldSpecification ret = + { field, atime, sizeof(struct GNUNET_TIME_Absolute), 0, TMH_PARSE_JNC_RET_TIME_ABSOLUTE, 0 }; + return ret; +} + + +/** + * Generate line in parser specification for an amount. + * + * @param field name of the field + * @param amount a `struct TALER_Amount *` to initialize + * @return corresponding field spec + */ +struct TMH_PARSE_FieldSpecification +TMH_PARSE_member_amount (const char *field, + struct TALER_Amount *amount) +{ + struct TMH_PARSE_FieldSpecification ret = + { field, amount, sizeof(struct TALER_Amount), 0, TMH_PARSE_JNC_RET_AMOUNT, 0 }; + return ret; +} + /* end of taler-mint-httpd_parsing.c */ diff --git a/src/mint/taler-mint-httpd_parsing.h b/src/mint/taler-mint-httpd_parsing.h index 2439f39f9..c6981e60e 100644 --- a/src/mint/taler-mint-httpd_parsing.h +++ b/src/mint/taler-mint-httpd_parsing.h @@ -260,13 +260,18 @@ TMH_PARSE_release_data (struct TMH_PARSE_FieldSpecification *spec); */ #define TMH_PARSE_MEMBER_ARRAY(field,ptraddr) { field, ptraddr, 0, 0, TMH_PARSE_JNC_RET_TYPED_JSON, JSON_ARRAY } + /** * Generate line in parser specification for JSON object value. * * @param field name of the field - * @param ptraddr address of pointer to initialize (a `void **`) + * @param ptraddr address of pointer to JSON to initialize + * @return corresponding field spec */ -#define TMH_PARSE_MEMBER_OBJECT(field,ptraddr) { field, ptraddr, 0, 0, TMH_PARSE_JNC_RET_TYPED_JSON, JSON_OBJECT } +struct TMH_PARSE_FieldSpecification +TMH_PARSE_member_object (const char *field, + json_t **jsonp); + /** * Generate line in parser specification for RSA public key. @@ -284,21 +289,30 @@ TMH_PARSE_release_data (struct TMH_PARSE_FieldSpecification *spec); */ #define TMH_PARSE_MEMBER_DENOMINATION_SIGNATURE(field,ptrsig) { field, ptrsig, 0, 0, TMH_PARSE_JNC_RET_RSA_SIGNATURE, 0 } + /** * Generate line in parser specification for an amount. * * @param field name of the field - * @param amount a `struct TALER_Amount *` to initialize + * @param[out] amount a `struct TALER_Amount *` to initialize + * @return corresponding field spec */ -#define TMH_PARSE_MEMBER_AMOUNT(field,amount) { field, amount, sizeof(*amount), 0, TMH_PARSE_JNC_RET_AMOUNT, 0 } +struct TMH_PARSE_FieldSpecification +TMH_PARSE_member_amount (const char *field, + struct TALER_Amount *amount); + /** * Generate line in parser specification for an absolute time. * * @param field name of the field - * @param atime a `struct GNUNET_TIME_Absolute *` to initialize + * @param[out] atime time to initialize + * @return corresponding field spec */ -#define TMH_PARSE_MEMBER_TIME_ABS(field,atime) { field, atime, sizeof(*atime), 0, TMH_PARSE_JNC_RET_TIME_ABSOLUTE, 0 } +struct TMH_PARSE_FieldSpecification +TMH_PARSE_member_time_abs (const char *field, + struct GNUNET_TIME_Absolute *atime); + /** diff --git a/src/mint/taler-mint-httpd_refresh.c b/src/mint/taler-mint-httpd_refresh.c index 0ffba6e87..661376f5e 100644 --- a/src/mint/taler-mint-httpd_refresh.c +++ b/src/mint/taler-mint-httpd_refresh.c @@ -177,7 +177,7 @@ get_coin_public_info (struct MHD_Connection *connection, TMH_PARSE_MEMBER_DENOMINATION_SIGNATURE ("denom_sig", &sig.rsa_signature), TMH_PARSE_MEMBER_DENOMINATION_PUBLIC_KEY ("denom_pub", &pk.rsa_public_key), TMH_PARSE_MEMBER_FIXED ("confirm_sig", &melt_sig), - TMH_PARSE_MEMBER_AMOUNT ("value_with_fee", &amount), + TMH_PARSE_member_amount ("value_with_fee", &amount), TMH_PARSE_MEMBER_END }; diff --git a/src/mint/taler-mint-httpd_responses.c b/src/mint/taler-mint-httpd_responses.c index 013cc19b8..477db86ed 100644 --- a/src/mint/taler-mint-httpd_responses.c +++ b/src/mint/taler-mint-httpd_responses.c @@ -50,11 +50,20 @@ TMH_RESPONSE_reply_json (struct MHD_Connection *connection, resp = MHD_create_response_from_buffer (strlen (json_str), json_str, MHD_RESPMEM_MUST_FREE); if (NULL == resp) + { + GNUNET_break (0); return MHD_NO; + } (void) MHD_add_response_header (resp, MHD_HTTP_HEADER_CONTENT_TYPE, "application/json"); - ret = MHD_queue_response (connection, response_code, resp); + ret = MHD_queue_response (connection, + response_code, + resp); + fprintf (stderr, + "Queued response %u (%d)\n", + response_code, + ret); MHD_destroy_response (resp); return ret; } @@ -84,7 +93,10 @@ TMH_RESPONSE_reply_json_pack (struct MHD_Connection *connection, json = json_vpack_ex (NULL, 0, fmt, argp); va_end (argp); if (NULL == json) + { + GNUNET_break (0); return MHD_NO; + } ret = TMH_RESPONSE_reply_json (connection, json, response_code); @@ -256,7 +268,7 @@ int TMH_RESPONSE_reply_internal_db_error (struct MHD_Connection *connection) { return TMH_RESPONSE_reply_internal_error (connection, - "Failed to connect to database"); + "Failed to connect to database"); }