fix misc small bugs

This commit is contained in:
Christian Grothoff 2015-07-04 21:27:28 +02:00
parent 841950b910
commit 49da00cc2b
8 changed files with 99 additions and 23 deletions

View File

@ -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 */

View File

@ -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,

View File

@ -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,

View File

@ -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
};

View File

@ -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 */

View File

@ -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);
/**

View File

@ -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
};

View File

@ -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");
}