starting to separate out response generation API and parsing APIs
This commit is contained in:
parent
0430d6fb03
commit
f58fb4fc21
@ -61,8 +61,9 @@ taler_mint_reservemod_LDFLAGS = \
|
|||||||
|
|
||||||
taler_mint_httpd_SOURCES = \
|
taler_mint_httpd_SOURCES = \
|
||||||
taler-mint-httpd.c \
|
taler-mint-httpd.c \
|
||||||
|
taler-mint-httpd_parsing.c taler-mint-httpd_parsing.h \
|
||||||
|
taler-mint-httpd_responses.c taler-mint-httpd_responses.h \
|
||||||
taler-mint-httpd_mhd.c \
|
taler-mint-httpd_mhd.c \
|
||||||
taler-mint-httpd_json.c taler-mint-httpd_json.h \
|
|
||||||
taler-mint-httpd_keys.c \
|
taler-mint-httpd_keys.c \
|
||||||
taler-mint-httpd_deposit.c \
|
taler-mint-httpd_deposit.c \
|
||||||
taler-mint-httpd_withdraw.c \
|
taler-mint-httpd_withdraw.c \
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
#include "taler_signatures.h"
|
#include "taler_signatures.h"
|
||||||
#include "taler_rsa.h"
|
#include "taler_rsa.h"
|
||||||
#include "taler_json_lib.h"
|
#include "taler_json_lib.h"
|
||||||
#include "taler-mint-httpd_json.h"
|
#include "taler-mint-httpd_parsing.h"
|
||||||
#include "taler-mint-httpd_mhd.h"
|
#include "taler-mint-httpd_mhd.h"
|
||||||
#include "taler-mint-httpd_keys.h"
|
#include "taler-mint-httpd_keys.h"
|
||||||
#include "taler-mint-httpd_deposit.h"
|
#include "taler-mint-httpd_deposit.h"
|
||||||
@ -372,4 +372,3 @@ main (int argc, char *const *argv)
|
|||||||
MHD_stop_daemon (mydaemon);
|
MHD_stop_daemon (mydaemon);
|
||||||
return (GNUNET_OK == ret) ? 0 : 1;
|
return (GNUNET_OK == ret) ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,9 +31,10 @@
|
|||||||
#include "taler_signatures.h"
|
#include "taler_signatures.h"
|
||||||
#include "taler_rsa.h"
|
#include "taler_rsa.h"
|
||||||
#include "taler_json_lib.h"
|
#include "taler_json_lib.h"
|
||||||
#include "taler-mint-httpd_json.h"
|
#include "taler-mint-httpd_parsing.h"
|
||||||
#include "taler-mint-httpd_keys.h"
|
#include "taler-mint-httpd_keys.h"
|
||||||
#include "taler-mint-httpd_deposit.h"
|
#include "taler-mint-httpd_deposit.h"
|
||||||
|
#include "taler-mint-httpd_responses.h"
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -48,8 +49,11 @@ helper_deposit_send_response_success (struct MHD_Connection *connection,
|
|||||||
struct Deposit *deposit)
|
struct Deposit *deposit)
|
||||||
{
|
{
|
||||||
// FIXME: return more information here
|
// FIXME: return more information here
|
||||||
return request_send_json_pack (connection, MHD_HTTP_OK,
|
return TALER_MINT_reply_json_pack (connection,
|
||||||
"{s:s}", "status", "DEPOSIT_OK");
|
MHD_HTTP_OK,
|
||||||
|
"{s:s}",
|
||||||
|
"status",
|
||||||
|
"DEPOSIT_OK");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -199,9 +203,11 @@ TALER_MINT_handler_deposit (struct RequestHandler *rh,
|
|||||||
// FIXME: in the future, check if there's enough credits
|
// FIXME: in the future, check if there's enough credits
|
||||||
// left on the coin. For now: refuse
|
// left on the coin. For now: refuse
|
||||||
// FIXME: return more information here
|
// FIXME: return more information here
|
||||||
return request_send_json_pack (connection, MHD_HTTP_FORBIDDEN,
|
return TALER_MINT_reply_json_pack (connection,
|
||||||
|
MHD_HTTP_FORBIDDEN,
|
||||||
"{s:s}",
|
"{s:s}",
|
||||||
"error", "double spending");
|
"error",
|
||||||
|
"double spending");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GNUNET_SYSERR == res)
|
if (GNUNET_SYSERR == res)
|
||||||
@ -221,7 +227,8 @@ TALER_MINT_handler_deposit (struct RequestHandler *rh,
|
|||||||
// coin must have been refreshed
|
// coin must have been refreshed
|
||||||
// FIXME: check
|
// FIXME: check
|
||||||
// FIXME: return more information here
|
// FIXME: return more information here
|
||||||
return request_send_json_pack (connection, MHD_HTTP_FORBIDDEN,
|
return TALER_MINT_reply_json_pack (connection,
|
||||||
|
MHD_HTTP_FORBIDDEN,
|
||||||
"{s:s}",
|
"{s:s}",
|
||||||
"error", "coin was refreshed");
|
"error", "coin was refreshed");
|
||||||
}
|
}
|
||||||
@ -252,7 +259,9 @@ TALER_MINT_handler_deposit (struct RequestHandler *rh,
|
|||||||
|
|
||||||
EXITIF_exit:
|
EXITIF_exit:
|
||||||
if (NULL != resp)
|
if (NULL != resp)
|
||||||
res = send_response_json (connection, resp, resp_code);
|
res = TALER_MINT_reply_json (connection,
|
||||||
|
resp,
|
||||||
|
resp_code);
|
||||||
else
|
else
|
||||||
res = MHD_NO;
|
res = MHD_NO;
|
||||||
if (NULL != wire)
|
if (NULL != wire)
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
#include "taler_signatures.h"
|
#include "taler_signatures.h"
|
||||||
#include "taler_rsa.h"
|
#include "taler_rsa.h"
|
||||||
#include "taler_json_lib.h"
|
#include "taler_json_lib.h"
|
||||||
#include "taler-mint-httpd_json.h"
|
#include "taler-mint-httpd_parsing.h"
|
||||||
#include "taler-mint-httpd_keys.h"
|
#include "taler-mint-httpd_keys.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,7 +16,9 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @file taler-mint-httpd_mhd.c
|
* @file taler-mint-httpd_mhd.c
|
||||||
* @brief helpers for MHD interaction
|
* @brief helpers for MHD interaction; these are TALER_MINT_handler_ functions
|
||||||
|
* that generate simple MHD replies that do not require any real operations
|
||||||
|
* to be performed (error handling, static pages, etc.)
|
||||||
* @author Florian Dold
|
* @author Florian Dold
|
||||||
* @author Benedikt Mueller
|
* @author Benedikt Mueller
|
||||||
* @author Christian Grothoff
|
* @author Christian Grothoff
|
||||||
@ -27,9 +29,10 @@
|
|||||||
#include <microhttpd.h>
|
#include <microhttpd.h>
|
||||||
#include <libpq-fe.h>
|
#include <libpq-fe.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include "taler-mint-httpd_json.h"
|
#include "taler-mint-httpd_responses.h"
|
||||||
#include "taler-mint-httpd.h"
|
#include "taler-mint-httpd.h"
|
||||||
#include "taler-mint-httpd_mhd.h"
|
#include "taler-mint-httpd_mhd.h"
|
||||||
|
#include "taler-mint-httpd_responses.h"
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -121,63 +124,6 @@ TALER_MINT_handler_agpl_redirect (struct RequestHandler *rh,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Function to call to handle the request by building a JSON
|
|
||||||
* reply from varargs.
|
|
||||||
*
|
|
||||||
* @param rh context of the handler
|
|
||||||
* @param connection the MHD connection to handle
|
|
||||||
* @param[IN|OUT] connection_cls the connection's closure (can be updated)
|
|
||||||
* @param response_code HTTP response code to use
|
|
||||||
* @param do_cache can the response be cached? (0: no, 1: yes)
|
|
||||||
* @param fmt format string for pack
|
|
||||||
* @param ... varargs
|
|
||||||
* @return MHD result code
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
TALER_MINT_helper_send_json_pack (struct RequestHandler *rh,
|
|
||||||
struct MHD_Connection *connection,
|
|
||||||
void *connection_cls,
|
|
||||||
int response_code,
|
|
||||||
int do_cache,
|
|
||||||
const char *fmt,
|
|
||||||
...)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
json_t *json;
|
|
||||||
va_list argp;
|
|
||||||
char *json_str;
|
|
||||||
struct MHD_Response *response;
|
|
||||||
|
|
||||||
va_start (argp, fmt);
|
|
||||||
json = json_vpack_ex (NULL, 0, fmt, argp);
|
|
||||||
va_end (argp);
|
|
||||||
if (NULL == json)
|
|
||||||
return MHD_NO;
|
|
||||||
json_str = json_dumps (json, JSON_INDENT(2));
|
|
||||||
json_decref (json);
|
|
||||||
if (NULL == json_str)
|
|
||||||
return MHD_NO;
|
|
||||||
response = MHD_create_response_from_buffer (strlen (json_str),
|
|
||||||
json_str,
|
|
||||||
MHD_RESPMEM_MUST_FREE);
|
|
||||||
if (NULL == response)
|
|
||||||
{
|
|
||||||
free (json_str);
|
|
||||||
return MHD_NO;
|
|
||||||
}
|
|
||||||
if (NULL != rh->mime_type)
|
|
||||||
(void) MHD_add_response_header (response,
|
|
||||||
MHD_HTTP_HEADER_CONTENT_TYPE,
|
|
||||||
rh->mime_type);
|
|
||||||
ret = MHD_queue_response (connection,
|
|
||||||
response_code,
|
|
||||||
response);
|
|
||||||
MHD_destroy_response (response);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to call to handle the request by building a JSON
|
* Function to call to handle the request by building a JSON
|
||||||
* reply with an error message from @a rh.
|
* reply with an error message from @a rh.
|
||||||
@ -196,10 +142,7 @@ TALER_MINT_handler_send_json_pack_error (struct RequestHandler *rh,
|
|||||||
const char *upload_data,
|
const char *upload_data,
|
||||||
size_t *upload_data_size)
|
size_t *upload_data_size)
|
||||||
{
|
{
|
||||||
return TALER_MINT_helper_send_json_pack (rh,
|
return TALER_MINT_reply_json_pack (connection,
|
||||||
connection,
|
|
||||||
connection_cls,
|
|
||||||
1, /* caching enabled */
|
|
||||||
rh->response_code,
|
rh->response_code,
|
||||||
"{s:s}",
|
"{s:s}",
|
||||||
"error",
|
"error",
|
||||||
@ -207,94 +150,4 @@ TALER_MINT_handler_send_json_pack_error (struct RequestHandler *rh,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send a response for an invalid argument.
|
|
||||||
*
|
|
||||||
* @param connection the MHD connection to use
|
|
||||||
* @param param_name the parameter that is missing
|
|
||||||
* @return a GNUnet result code
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
request_arg_invalid (struct MHD_Connection *connection,
|
|
||||||
const char *param_name)
|
|
||||||
{
|
|
||||||
json_t *json;
|
|
||||||
json = json_pack ("{ s:s, s:s }",
|
|
||||||
"error", "invalid parameter",
|
|
||||||
"parameter", param_name);
|
|
||||||
if (MHD_YES != send_response_json (connection, json, MHD_HTTP_BAD_REQUEST))
|
|
||||||
{
|
|
||||||
GNUNET_break (0);
|
|
||||||
return GNUNET_SYSERR;
|
|
||||||
}
|
|
||||||
return GNUNET_NO;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a GET paramater that is a string,
|
|
||||||
* or send an error response if the parameter is missing.
|
|
||||||
*
|
|
||||||
* @param connection the connection to get the parameter from /
|
|
||||||
* send the error response to
|
|
||||||
* @param param_name the parameter name
|
|
||||||
* @param str pointer to store the parameter string,
|
|
||||||
* must be freed by the caller
|
|
||||||
* @return GNUNET_YES if the parameter is present and valid,
|
|
||||||
* GNUNET_NO if the parameter is missing
|
|
||||||
* GNUNET_SYSERR on internal error
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
request_arg_require_string (struct MHD_Connection *connection,
|
|
||||||
const char *param_name,
|
|
||||||
const char **str)
|
|
||||||
{
|
|
||||||
*str = MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, param_name);
|
|
||||||
if (NULL == *str)
|
|
||||||
{
|
|
||||||
if (MHD_NO ==
|
|
||||||
request_send_json_pack (connection, MHD_HTTP_BAD_REQUEST,
|
|
||||||
"{ s:s, s:s }",
|
|
||||||
"error", "missing parameter",
|
|
||||||
"parameter", param_name))
|
|
||||||
return GNUNET_SYSERR;
|
|
||||||
return GNUNET_NO;
|
|
||||||
}
|
|
||||||
return GNUNET_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Extraxt base32crockford encoded data from request.
|
|
||||||
*
|
|
||||||
* Queues an error response to the connection if the parameter is missing or
|
|
||||||
* invalid.
|
|
||||||
*
|
|
||||||
* @param connection the MHD connection
|
|
||||||
* @param param_name the name of the parameter with the key
|
|
||||||
* @param[out] out_data pointer to store the result
|
|
||||||
* @param out_size expected size of data
|
|
||||||
* @return
|
|
||||||
* GNUNET_YES if the the argument is present
|
|
||||||
* GNUNET_NO if the argument is absent or malformed
|
|
||||||
* GNUNET_SYSERR on internal error (error response could not be sent)
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
TALER_MINT_mhd_request_arg_data (struct MHD_Connection *connection,
|
|
||||||
const char *param_name,
|
|
||||||
void *out_data,
|
|
||||||
size_t out_size)
|
|
||||||
{
|
|
||||||
const char *str;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (GNUNET_OK != (ret = request_arg_require_string (connection, param_name, &str)))
|
|
||||||
return ret;
|
|
||||||
if (GNUNET_OK != GNUNET_STRINGS_string_to_data (str, strlen (str), out_data, out_size))
|
|
||||||
return request_arg_invalid (connection, param_name);
|
|
||||||
return GNUNET_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* end of taler-mint-httpd_mhd.c */
|
/* end of taler-mint-httpd_mhd.c */
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @file taler-mint-httpd_mhd.h
|
* @file taler-mint-httpd_mhd.h
|
||||||
* @brief helpers for MHD interaction
|
* @brief helpers for MHD interaction, used to generate simple responses
|
||||||
* @author Florian Dold
|
* @author Florian Dold
|
||||||
* @author Benedikt Mueller
|
* @author Benedikt Mueller
|
||||||
* @author Christian Grothoff
|
* @author Christian Grothoff
|
||||||
@ -108,25 +108,4 @@ TALER_MINT_handler_send_json_pack_error (struct RequestHandler *rh,
|
|||||||
size_t *upload_data_size);
|
size_t *upload_data_size);
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Extraxt base32crockford encoded data from request.
|
|
||||||
*
|
|
||||||
* Queues an error response to the connection if the parameter is missing or
|
|
||||||
* invalid.
|
|
||||||
*
|
|
||||||
* @param connection the MHD connection
|
|
||||||
* @param param_name the name of the parameter with the key
|
|
||||||
* @param[out] out_data pointer to store the result
|
|
||||||
* @param out_size expected size of data
|
|
||||||
* @return
|
|
||||||
* GNUNET_YES if the the argument is present
|
|
||||||
* GNUNET_NO if the argument is absent or malformed
|
|
||||||
* GNUNET_SYSERR on internal error (error response could not be sent)
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
TALER_MINT_mhd_request_arg_data (struct MHD_Connection *connection,
|
|
||||||
const char *param_name,
|
|
||||||
void *out_data,
|
|
||||||
size_t out_size);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,7 +1,31 @@
|
|||||||
|
/*
|
||||||
|
This file is part of TALER
|
||||||
|
(C) 2014 GNUnet e.V.
|
||||||
|
|
||||||
|
TALER is free software; you can redistribute it and/or modify it under the
|
||||||
|
terms of the GNU Affero General Public License as published by the Free Software
|
||||||
|
Foundation; either version 3, or (at your option) any later version.
|
||||||
|
|
||||||
|
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||||
|
A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License along with
|
||||||
|
TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file taler-mint-httpd_parsing.c
|
||||||
|
* @brief functions to parse incoming requests (MHD arguments and JSON snippets)
|
||||||
|
* @author Florian Dold
|
||||||
|
* @author Benedikt Mueller
|
||||||
|
* @author Christian Grothoff
|
||||||
|
*/
|
||||||
|
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
#include <gnunet/gnunet_util_lib.h>
|
#include <gnunet/gnunet_util_lib.h>
|
||||||
#include "taler-mint-httpd_json.h"
|
#include "taler-mint-httpd_parsing.h"
|
||||||
|
#include "taler-mint-httpd_responses.h"
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -49,7 +73,11 @@ struct Buffer
|
|||||||
* @return a GNUnet result code
|
* @return a GNUnet result code
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
buffer_init (struct Buffer *buf, const void *data, size_t data_size, size_t alloc_size, size_t max_size)
|
buffer_init (struct Buffer *buf,
|
||||||
|
const void *data,
|
||||||
|
size_t data_size,
|
||||||
|
size_t alloc_size,
|
||||||
|
size_t max_size)
|
||||||
{
|
{
|
||||||
if (data_size > max_size || alloc_size > max_size)
|
if (data_size > max_size || alloc_size > max_size)
|
||||||
return GNUNET_SYSERR;
|
return GNUNET_SYSERR;
|
||||||
@ -87,7 +115,10 @@ buffer_deinit (struct Buffer *buf)
|
|||||||
* GNUNET_SYSERR on fatal error (out of memory?)
|
* GNUNET_SYSERR on fatal error (out of memory?)
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
buffer_append (struct Buffer *buf, const void *data, size_t data_size, size_t max_size)
|
buffer_append (struct Buffer *buf,
|
||||||
|
const void *data,
|
||||||
|
size_t data_size,
|
||||||
|
size_t max_size)
|
||||||
{
|
{
|
||||||
if (buf->fill + data_size > max_size)
|
if (buf->fill + data_size > max_size)
|
||||||
return GNUNET_NO;
|
return GNUNET_NO;
|
||||||
@ -110,63 +141,6 @@ buffer_append (struct Buffer *buf, const void *data, size_t data_size, size_t ma
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send JSON object as response. Decreases the reference count of the
|
|
||||||
* JSON object.
|
|
||||||
*
|
|
||||||
* @param connection the MHD connection
|
|
||||||
* @param json the json object
|
|
||||||
* @param status_code the http status code
|
|
||||||
* @return MHD result code
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
send_response_json (struct MHD_Connection *connection,
|
|
||||||
json_t *json,
|
|
||||||
unsigned int status_code)
|
|
||||||
{
|
|
||||||
struct MHD_Response *resp;
|
|
||||||
char *json_str;
|
|
||||||
|
|
||||||
json_str = json_dumps (json, JSON_INDENT(2));
|
|
||||||
json_decref (json);
|
|
||||||
resp = MHD_create_response_from_buffer (strlen (json_str), json_str,
|
|
||||||
MHD_RESPMEM_MUST_FREE);
|
|
||||||
if (NULL == resp)
|
|
||||||
return MHD_NO;
|
|
||||||
return MHD_queue_response (connection, status_code, resp);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send a JSON object via an MHD connection,
|
|
||||||
* specified with the JANSSON pack syntax (see json_pack).
|
|
||||||
*
|
|
||||||
* @param connection connection to send the JSON over
|
|
||||||
* @param http_code HTTP status for the response
|
|
||||||
* @param fmt format string for pack
|
|
||||||
* @param ... varargs
|
|
||||||
* @return MHD_YES on success or MHD_NO on error
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
request_send_json_pack (struct MHD_Connection *connection,
|
|
||||||
unsigned int http_code,
|
|
||||||
const char *fmt, ...)
|
|
||||||
{
|
|
||||||
json_t *msg;
|
|
||||||
va_list argp;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
va_start(argp, fmt);
|
|
||||||
msg = json_vpack_ex (NULL, 0, fmt, argp);
|
|
||||||
va_end(argp);
|
|
||||||
if (NULL == msg)
|
|
||||||
return MHD_NO;
|
|
||||||
ret = send_response_json (connection, msg, http_code);
|
|
||||||
json_decref (msg);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process a POST request containing a JSON object.
|
* Process a POST request containing a JSON object.
|
||||||
*
|
*
|
||||||
@ -195,8 +169,12 @@ process_post_json (struct MHD_Connection *connection,
|
|||||||
/* We are seeing a fresh POST request. */
|
/* We are seeing a fresh POST request. */
|
||||||
|
|
||||||
r = GNUNET_new (struct Buffer);
|
r = GNUNET_new (struct Buffer);
|
||||||
if (GNUNET_OK != buffer_init (r, upload_data, *upload_data_size,
|
if (GNUNET_OK !=
|
||||||
REQUEST_BUFFER_INITIAL, REQUEST_BUFFER_MAX))
|
buffer_init (r,
|
||||||
|
upload_data,
|
||||||
|
*upload_data_size,
|
||||||
|
REQUEST_BUFFER_INITIAL,
|
||||||
|
REQUEST_BUFFER_MAX))
|
||||||
{
|
{
|
||||||
*con_cls = NULL;
|
*con_cls = NULL;
|
||||||
buffer_deinit (r);
|
buffer_deinit (r);
|
||||||
@ -211,7 +189,10 @@ process_post_json (struct MHD_Connection *connection,
|
|||||||
{
|
{
|
||||||
/* We are seeing an old request with more data available. */
|
/* We are seeing an old request with more data available. */
|
||||||
|
|
||||||
if (GNUNET_OK != buffer_append (r, upload_data, *upload_data_size,
|
if (GNUNET_OK !=
|
||||||
|
buffer_append (r,
|
||||||
|
upload_data,
|
||||||
|
*upload_data_size,
|
||||||
REQUEST_BUFFER_MAX))
|
REQUEST_BUFFER_MAX))
|
||||||
{
|
{
|
||||||
/* Request too long or we're out of memory. */
|
/* Request too long or we're out of memory. */
|
||||||
@ -232,11 +213,14 @@ process_post_json (struct MHD_Connection *connection,
|
|||||||
GNUNET_free (r);
|
GNUNET_free (r);
|
||||||
if (NULL == *json)
|
if (NULL == *json)
|
||||||
{
|
{
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Can't parse JSON request body\n");
|
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
|
||||||
return request_send_json_pack (connection, MHD_HTTP_BAD_REQUEST,
|
"Can't parse JSON request body\n");
|
||||||
GNUNET_NO, GNUNET_SYSERR,
|
return (MHD_YES ==
|
||||||
|
TALER_MINT_reply_json_pack (connection,
|
||||||
|
MHD_HTTP_BAD_REQUEST,
|
||||||
"{s:s}",
|
"{s:s}",
|
||||||
"error", "invalid json");
|
"error", "invalid json"))
|
||||||
|
? GNUNET_NO : GNUNET_SYSERR;
|
||||||
}
|
}
|
||||||
*con_cls = NULL;
|
*con_cls = NULL;
|
||||||
|
|
||||||
@ -284,12 +268,14 @@ request_json_require_nav (struct MHD_Connection *connection,
|
|||||||
root = json_object_get (root, fname);
|
root = json_object_get (root, fname);
|
||||||
if (NULL == root)
|
if (NULL == root)
|
||||||
{
|
{
|
||||||
|
/* FIXME: can't IGNORE this return value! */
|
||||||
(void) request_send_json_pack (connection, MHD_HTTP_BAD_REQUEST,
|
(void) TALER_MINT_reply_json_pack (connection,
|
||||||
0, 0,
|
MHD_HTTP_BAD_REQUEST,
|
||||||
"{s:s,s:o}",
|
"{s:s,s:o}",
|
||||||
"error", "missing field in JSON",
|
"error",
|
||||||
"path", path);
|
"missing field in JSON",
|
||||||
|
"path",
|
||||||
|
path);
|
||||||
ignore = GNUNET_YES;
|
ignore = GNUNET_YES;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -304,8 +290,9 @@ request_json_require_nav (struct MHD_Connection *connection,
|
|||||||
root = json_array_get (root, fnum);
|
root = json_array_get (root, fnum);
|
||||||
if (NULL == root)
|
if (NULL == root)
|
||||||
{
|
{
|
||||||
(void) request_send_json_pack (connection, MHD_HTTP_BAD_REQUEST,
|
/* FIXME: can't IGNORE this return value! */
|
||||||
0, 0,
|
(void) TALER_MINT_reply_json_pack (connection,
|
||||||
|
MHD_HTTP_BAD_REQUEST,
|
||||||
"{s:s, s:o}",
|
"{s:s, s:o}",
|
||||||
"error", "missing index in JSON",
|
"error", "missing index in JSON",
|
||||||
"path", path);
|
"path", path);
|
||||||
@ -327,21 +314,26 @@ request_json_require_nav (struct MHD_Connection *connection,
|
|||||||
str = json_string_value (root);
|
str = json_string_value (root);
|
||||||
if (NULL == str)
|
if (NULL == str)
|
||||||
{
|
{
|
||||||
(void) request_send_json_pack (connection, MHD_HTTP_BAD_REQUEST,
|
/* FIXME: can't IGNORE this return value! */
|
||||||
0, 0,
|
(void) TALER_MINT_reply_json_pack (connection,
|
||||||
|
MHD_HTTP_BAD_REQUEST,
|
||||||
"{s:s, s:o}",
|
"{s:s, s:o}",
|
||||||
"error", "string expected",
|
"error",
|
||||||
"path", path);
|
"string expected",
|
||||||
|
"path",
|
||||||
|
path);
|
||||||
return GNUNET_NO;
|
return GNUNET_NO;
|
||||||
}
|
}
|
||||||
res = GNUNET_STRINGS_string_to_data (str, strlen (str),
|
res = GNUNET_STRINGS_string_to_data (str, strlen (str),
|
||||||
where, len);
|
where, len);
|
||||||
if (GNUNET_OK != res)
|
if (GNUNET_OK != res)
|
||||||
{
|
{
|
||||||
(void) request_send_json_pack (connection, MHD_HTTP_BAD_REQUEST,
|
/* FIXME: can't IGNORE this return value! */
|
||||||
0, 0,
|
(void) TALER_MINT_reply_json_pack (connection,
|
||||||
|
MHD_HTTP_BAD_REQUEST,
|
||||||
"{s:s,s:o}",
|
"{s:s,s:o}",
|
||||||
"error", "malformed binary data in JSON",
|
"error",
|
||||||
|
"malformed binary data in JSON",
|
||||||
"path", path);
|
"path", path);
|
||||||
return GNUNET_NO;
|
return GNUNET_NO;
|
||||||
}
|
}
|
||||||
@ -372,10 +364,12 @@ request_json_require_nav (struct MHD_Connection *connection,
|
|||||||
*where, *len);
|
*where, *len);
|
||||||
if (GNUNET_OK != res)
|
if (GNUNET_OK != res)
|
||||||
{
|
{
|
||||||
(void) request_send_json_pack (connection, MHD_HTTP_BAD_REQUEST,
|
/* FIXME: can't IGNORE this return value! */
|
||||||
0, 0,
|
(void) TALER_MINT_reply_json_pack (connection,
|
||||||
|
MHD_HTTP_BAD_REQUEST,
|
||||||
"{s:s, s:o}",
|
"{s:s, s:o}",
|
||||||
"error", "malformed binary data in JSON",
|
"error",
|
||||||
|
"malformed binary data in JSON",
|
||||||
"path", path);
|
"path", path);
|
||||||
return GNUNET_NO;
|
return GNUNET_NO;
|
||||||
}
|
}
|
||||||
@ -393,8 +387,9 @@ request_json_require_nav (struct MHD_Connection *connection,
|
|||||||
return GNUNET_NO;
|
return GNUNET_NO;
|
||||||
if (typ != -1 && json_typeof (root) != typ)
|
if (typ != -1 && json_typeof (root) != typ)
|
||||||
{
|
{
|
||||||
(void) request_send_json_pack (connection, MHD_HTTP_BAD_REQUEST,
|
/* FIXME: can't IGNORE this return value! */
|
||||||
0, 0,
|
(void) TALER_MINT_reply_json_pack (connection,
|
||||||
|
MHD_HTTP_BAD_REQUEST,
|
||||||
"{s:s, s:i, s:i s:o}",
|
"{s:s, s:i, s:i s:o}",
|
||||||
"error", "wrong JSON field type",
|
"error", "wrong JSON field type",
|
||||||
"type_expected", typ,
|
"type_expected", typ,
|
||||||
@ -414,4 +409,45 @@ request_json_require_nav (struct MHD_Connection *connection,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract base32crockford encoded data from request.
|
||||||
|
*
|
||||||
|
* Queues an error response to the connection if the parameter is missing or
|
||||||
|
* invalid.
|
||||||
|
*
|
||||||
|
* @param connection the MHD connection
|
||||||
|
* @param param_name the name of the parameter with the key
|
||||||
|
* @param[out] out_data pointer to store the result
|
||||||
|
* @param out_size expected size of data
|
||||||
|
* @return
|
||||||
|
* GNUNET_YES if the the argument is present
|
||||||
|
* GNUNET_NO if the argument is absent or malformed
|
||||||
|
* GNUNET_SYSERR on internal error (error response could not be sent)
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
TALER_MINT_mhd_request_arg_data (struct MHD_Connection *connection,
|
||||||
|
const char *param_name,
|
||||||
|
void *out_data,
|
||||||
|
size_t out_size)
|
||||||
|
{
|
||||||
|
const char *str;
|
||||||
|
|
||||||
|
str = MHD_lookup_connection_value (connection,
|
||||||
|
MHD_GET_ARGUMENT_KIND,
|
||||||
|
param_name);
|
||||||
|
if (NULL == str)
|
||||||
|
{
|
||||||
|
return (MHD_NO ==
|
||||||
|
TALER_MINT_reply_arg_missing (connection, param_name))
|
||||||
|
? GNUNET_SYSERR : GNUNET_NO;
|
||||||
|
}
|
||||||
|
if (GNUNET_OK !=
|
||||||
|
GNUNET_STRINGS_string_to_data (str,
|
||||||
|
strlen (str),
|
||||||
|
out_data,
|
||||||
|
out_size))
|
||||||
|
return (MHD_NO ==
|
||||||
|
TALER_MINT_reply_arg_invalid (connection, param_name))
|
||||||
|
? GNUNET_SYSERR : GNUNET_NO;
|
||||||
|
return GNUNET_OK;
|
||||||
|
}
|
@ -1,4 +1,26 @@
|
|||||||
|
/*
|
||||||
|
This file is part of TALER
|
||||||
|
(C) 2014 GNUnet e.V.
|
||||||
|
|
||||||
|
TALER is free software; you can redistribute it and/or modify it under the
|
||||||
|
terms of the GNU Affero General Public License as published by the Free Software
|
||||||
|
Foundation; either version 3, or (at your option) any later version.
|
||||||
|
|
||||||
|
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||||
|
A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License along with
|
||||||
|
TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file taler-mint-httpd_parsing.h
|
||||||
|
* @brief functions to parse incoming requests
|
||||||
|
* @author Florian Dold
|
||||||
|
* @author Benedikt Mueller
|
||||||
|
* @author Christian Grothoff
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef TALER_MICROHTTPD_LIB_H_
|
#ifndef TALER_MICROHTTPD_LIB_H_
|
||||||
#define TALER_MICROHTTPD_LIB_H_
|
#define TALER_MICROHTTPD_LIB_H_
|
||||||
@ -45,38 +67,6 @@ enum
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send JSON object as response. Decreases
|
|
||||||
* the reference count of the JSON object.
|
|
||||||
*
|
|
||||||
* @param connection the MHD connection
|
|
||||||
* @param json the json object
|
|
||||||
* @param status_code the http status code
|
|
||||||
* @return MHD result code (MHD_YES on success)
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
send_response_json (struct MHD_Connection *connection,
|
|
||||||
json_t *json,
|
|
||||||
unsigned int status_code);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send a JSON object via an MHD connection,
|
|
||||||
* specified with the JANSSON pack syntax (see json_pack).
|
|
||||||
*
|
|
||||||
* @param connection connection to send the JSON over
|
|
||||||
* @param http_code HTTP status for the response
|
|
||||||
* @param fmt format string for pack
|
|
||||||
* @param ... varargs
|
|
||||||
* @return MHD_YES on success or MHD_NO on error
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
request_send_json_pack (struct MHD_Connection *connection,
|
|
||||||
unsigned int http_code,
|
|
||||||
const char *fmt, ...);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process a POST request containing a JSON object.
|
* Process a POST request containing a JSON object.
|
||||||
*
|
*
|
||||||
@ -116,4 +106,31 @@ int
|
|||||||
request_json_require_nav (struct MHD_Connection *connection,
|
request_json_require_nav (struct MHD_Connection *connection,
|
||||||
const json_t *root, ...);
|
const json_t *root, ...);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extraxt base32crockford encoded data from request.
|
||||||
|
*
|
||||||
|
* Queues an error response to the connection if the parameter is missing or
|
||||||
|
* invalid.
|
||||||
|
*
|
||||||
|
* @param connection the MHD connection
|
||||||
|
* @param param_name the name of the parameter with the key
|
||||||
|
* @param[out] out_data pointer to store the result
|
||||||
|
* @param out_size expected size of data
|
||||||
|
* @return
|
||||||
|
* GNUNET_YES if the the argument is present
|
||||||
|
* GNUNET_NO if the argument is absent or malformed
|
||||||
|
* GNUNET_SYSERR on internal error (error response could not be sent)
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
TALER_MINT_mhd_request_arg_data (struct MHD_Connection *connection,
|
||||||
|
const char *param_name,
|
||||||
|
void *out_data,
|
||||||
|
size_t out_size);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* TALER_MICROHTTPD_LIB_H_ */
|
#endif /* TALER_MICROHTTPD_LIB_H_ */
|
@ -31,10 +31,11 @@
|
|||||||
#include "taler_signatures.h"
|
#include "taler_signatures.h"
|
||||||
#include "taler_rsa.h"
|
#include "taler_rsa.h"
|
||||||
#include "taler_json_lib.h"
|
#include "taler_json_lib.h"
|
||||||
#include "taler-mint-httpd_json.h"
|
#include "taler-mint-httpd_parsing.h"
|
||||||
#include "taler-mint-httpd_keys.h"
|
#include "taler-mint-httpd_keys.h"
|
||||||
#include "taler-mint-httpd_mhd.h"
|
#include "taler-mint-httpd_mhd.h"
|
||||||
#include "taler-mint-httpd_refresh.h"
|
#include "taler-mint-httpd_refresh.h"
|
||||||
|
#include "taler-mint-httpd_responses.h"
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -228,7 +229,7 @@ check_confirm_signature (struct MHD_Connection *connection,
|
|||||||
coin_pub))
|
coin_pub))
|
||||||
{
|
{
|
||||||
if (MHD_YES !=
|
if (MHD_YES !=
|
||||||
request_send_json_pack (connection,
|
TALER_MINT_reply_json_pack (connection,
|
||||||
MHD_HTTP_UNAUTHORIZED,
|
MHD_HTTP_UNAUTHORIZED,
|
||||||
"{s:s}",
|
"{s:s}",
|
||||||
"error", "signature invalid"))
|
"error", "signature invalid"))
|
||||||
@ -356,13 +357,17 @@ refresh_accept_melts (struct MHD_Connection *connection,
|
|||||||
dki = &(TALER_MINT_get_denom_key (key_state, &coin_public_info.denom_pub)->issue);
|
dki = &(TALER_MINT_get_denom_key (key_state, &coin_public_info.denom_pub)->issue);
|
||||||
|
|
||||||
if (NULL == dki)
|
if (NULL == dki)
|
||||||
return (MHD_YES == request_send_json_pack (connection, MHD_HTTP_NOT_FOUND,
|
return (MHD_YES ==
|
||||||
|
TALER_MINT_reply_json_pack (connection,
|
||||||
|
MHD_HTTP_NOT_FOUND,
|
||||||
"{s:s}",
|
"{s:s}",
|
||||||
"error", "denom not found"))
|
"error", "denom not found"))
|
||||||
? GNUNET_NO : GNUNET_SYSERR;
|
? GNUNET_NO : GNUNET_SYSERR;
|
||||||
|
|
||||||
if (GNUNET_OK != TALER_MINT_test_coin_valid (key_state, &coin_public_info))
|
if (GNUNET_OK != TALER_MINT_test_coin_valid (key_state, &coin_public_info))
|
||||||
return (MHD_YES == request_send_json_pack (connection, MHD_HTTP_NOT_FOUND,
|
return (MHD_YES ==
|
||||||
|
TALER_MINT_reply_json_pack (connection,
|
||||||
|
MHD_HTTP_NOT_FOUND,
|
||||||
"{s:s}",
|
"{s:s}",
|
||||||
"error", "coin invalid"))
|
"error", "coin invalid"))
|
||||||
? GNUNET_NO : GNUNET_SYSERR;
|
? GNUNET_NO : GNUNET_SYSERR;
|
||||||
@ -379,9 +384,13 @@ refresh_accept_melts (struct MHD_Connection *connection,
|
|||||||
if (GNUNET_YES == res)
|
if (GNUNET_YES == res)
|
||||||
{
|
{
|
||||||
if (GNUNET_YES == known_coin.is_refreshed)
|
if (GNUNET_YES == known_coin.is_refreshed)
|
||||||
return (MHD_YES == request_send_json_pack (connection, MHD_HTTP_NOT_FOUND,
|
return (MHD_YES ==
|
||||||
|
TALER_MINT_reply_json_pack (connection,
|
||||||
|
MHD_HTTP_NOT_FOUND,
|
||||||
"{s:s}",
|
"{s:s}",
|
||||||
"error", "coin already refreshed")) ? GNUNET_NO : GNUNET_SYSERR;
|
"error",
|
||||||
|
"coin already refreshed"))
|
||||||
|
? GNUNET_NO : GNUNET_SYSERR;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -413,7 +422,9 @@ refresh_accept_melts (struct MHD_Connection *connection,
|
|||||||
* pay the refreshing fees of the coin. */
|
* pay the refreshing fees of the coin. */
|
||||||
|
|
||||||
if (TALER_amount_cmp (coin_gain, TALER_amount_ntoh (dki->fee_refresh)) < 0)
|
if (TALER_amount_cmp (coin_gain, TALER_amount_ntoh (dki->fee_refresh)) < 0)
|
||||||
return (MHD_YES == request_send_json_pack (connection, MHD_HTTP_NOT_FOUND,
|
return (MHD_YES ==
|
||||||
|
TALER_MINT_reply_json_pack (connection,
|
||||||
|
MHD_HTTP_NOT_FOUND,
|
||||||
"{s:s}",
|
"{s:s}",
|
||||||
"error", "depleted")) ? GNUNET_NO : GNUNET_SYSERR;
|
"error", "depleted")) ? GNUNET_NO : GNUNET_SYSERR;
|
||||||
|
|
||||||
@ -472,7 +483,7 @@ helper_refresh_send_melt_response (struct MHD_Connection *connection,
|
|||||||
json_object_set (root, "signature", sig_json);
|
json_object_set (root, "signature", sig_json);
|
||||||
}
|
}
|
||||||
|
|
||||||
return send_response_json (connection,
|
return TALER_MINT_reply_json (connection,
|
||||||
root,
|
root,
|
||||||
MHD_HTTP_OK);
|
MHD_HTTP_OK);
|
||||||
}
|
}
|
||||||
@ -524,7 +535,8 @@ request_json_check_signature (struct MHD_Connection *connection,
|
|||||||
if (purpose_num != ntohl (purpose->purpose))
|
if (purpose_num != ntohl (purpose->purpose))
|
||||||
{
|
{
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "signature invalid (purpose wrong)\n");
|
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "signature invalid (purpose wrong)\n");
|
||||||
return request_send_json_pack (connection, MHD_HTTP_BAD_REQUEST,
|
return TALER_MINT_reply_json_pack (connection,
|
||||||
|
MHD_HTTP_BAD_REQUEST,
|
||||||
"{s:s}",
|
"{s:s}",
|
||||||
"error", "signature invalid (purpose)");
|
"error", "signature invalid (purpose)");
|
||||||
}
|
}
|
||||||
@ -543,7 +555,8 @@ request_json_check_signature (struct MHD_Connection *connection,
|
|||||||
if (size != ntohl (purpose->size))
|
if (size != ntohl (purpose->size))
|
||||||
{
|
{
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "signature invalid (size wrong)\n");
|
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "signature invalid (size wrong)\n");
|
||||||
return request_send_json_pack (connection, MHD_HTTP_BAD_REQUEST,
|
return TALER_MINT_reply_json_pack (connection,
|
||||||
|
MHD_HTTP_BAD_REQUEST,
|
||||||
GNUNET_NO, GNUNET_SYSERR,
|
GNUNET_NO, GNUNET_SYSERR,
|
||||||
"{s:s}",
|
"{s:s}",
|
||||||
"error", "signature invalid (size)");
|
"error", "signature invalid (size)");
|
||||||
@ -555,9 +568,11 @@ request_json_check_signature (struct MHD_Connection *connection,
|
|||||||
pub))
|
pub))
|
||||||
{
|
{
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "signature invalid (did not verify)\n");
|
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "signature invalid (did not verify)\n");
|
||||||
return request_send_json_pack (connection, MHD_HTTP_UNAUTHORIZED,
|
return TALER_MINT_reply_json_pack (connection,
|
||||||
|
MHD_HTTP_UNAUTHORIZED,
|
||||||
"{s:s}",
|
"{s:s}",
|
||||||
"error", "invalid signature (verification)");
|
"error",
|
||||||
|
"invalid signature (verification)");
|
||||||
}
|
}
|
||||||
|
|
||||||
return GNUNET_OK;
|
return GNUNET_OK;
|
||||||
@ -705,10 +720,11 @@ TALER_MINT_handler_refresh_melt (struct RequestHandler *rh,
|
|||||||
if (NULL == melt_sig_json)
|
if (NULL == melt_sig_json)
|
||||||
{
|
{
|
||||||
GNUNET_break (GNUNET_OK == TALER_MINT_DB_rollback (db_conn));
|
GNUNET_break (GNUNET_OK == TALER_MINT_DB_rollback (db_conn));
|
||||||
return request_send_json_pack (connection,
|
return TALER_MINT_reply_json_pack (connection,
|
||||||
MHD_HTTP_BAD_REQUEST,
|
MHD_HTTP_BAD_REQUEST,
|
||||||
"{s:s}",
|
"{s:s}",
|
||||||
"error", "melt_signature missing");
|
"error",
|
||||||
|
"melt_signature missing");
|
||||||
}
|
}
|
||||||
|
|
||||||
body.melt_hash = melt_hash;
|
body.melt_hash = melt_hash;
|
||||||
@ -734,9 +750,11 @@ TALER_MINT_handler_refresh_melt (struct RequestHandler *rh,
|
|||||||
{
|
{
|
||||||
GNUNET_break (GNUNET_OK == TALER_MINT_DB_rollback (db_conn));
|
GNUNET_break (GNUNET_OK == TALER_MINT_DB_rollback (db_conn));
|
||||||
|
|
||||||
return request_send_json_pack (connection, MHD_HTTP_FORBIDDEN,
|
return TALER_MINT_reply_json_pack (connection,
|
||||||
|
MHD_HTTP_FORBIDDEN,
|
||||||
"{s:s}",
|
"{s:s}",
|
||||||
"error", "not enough coins melted");
|
"error",
|
||||||
|
"not enough coins melted");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GNUNET_OK != TALER_MINT_DB_commit (db_conn))
|
if (GNUNET_OK != TALER_MINT_DB_commit (db_conn))
|
||||||
@ -771,7 +789,8 @@ refresh_send_commit_response (struct MHD_Connection *connection,
|
|||||||
body.noreveal_index = htons (refresh_session->noreveal_index);
|
body.noreveal_index = htons (refresh_session->noreveal_index);
|
||||||
sig_json = sign_as_json (&body.purpose);
|
sig_json = sign_as_json (&body.purpose);
|
||||||
GNUNET_assert (NULL != sig_json);
|
GNUNET_assert (NULL != sig_json);
|
||||||
return request_send_json_pack (connection, MHD_HTTP_OK,
|
return TALER_MINT_reply_json_pack (connection,
|
||||||
|
MHD_HTTP_OK,
|
||||||
"{s:i, s:o}",
|
"{s:i, s:o}",
|
||||||
"noreveal_index", (int) refresh_session->noreveal_index,
|
"noreveal_index", (int) refresh_session->noreveal_index,
|
||||||
"signature", sig_json);
|
"signature", sig_json);
|
||||||
@ -1022,9 +1041,11 @@ TALER_MINT_handler_refresh_commit (struct RequestHandler *rh,
|
|||||||
if (NULL == commit_sig_json)
|
if (NULL == commit_sig_json)
|
||||||
{
|
{
|
||||||
GNUNET_break (GNUNET_OK == TALER_MINT_DB_rollback (db_conn));
|
GNUNET_break (GNUNET_OK == TALER_MINT_DB_rollback (db_conn));
|
||||||
return request_send_json_pack (connection, MHD_HTTP_BAD_REQUEST,
|
return TALER_MINT_reply_json_pack (connection,
|
||||||
|
MHD_HTTP_BAD_REQUEST,
|
||||||
"{s:s}",
|
"{s:s}",
|
||||||
"error", "commit_signature missing");
|
"error",
|
||||||
|
"commit_signature missing");
|
||||||
}
|
}
|
||||||
|
|
||||||
body.commit_hash = commit_hash;
|
body.commit_hash = commit_hash;
|
||||||
@ -1106,7 +1127,7 @@ helper_refresh_reveal_send_response (struct MHD_Connection *connection,
|
|||||||
TALER_JSON_from_data (&ev_sig,
|
TALER_JSON_from_data (&ev_sig,
|
||||||
sizeof (struct TALER_RSA_Signature)));
|
sizeof (struct TALER_RSA_Signature)));
|
||||||
}
|
}
|
||||||
return send_response_json (connection,
|
return TALER_MINT_reply_json (connection,
|
||||||
root,
|
root,
|
||||||
MHD_HTTP_OK);
|
MHD_HTTP_OK);
|
||||||
}
|
}
|
||||||
@ -1471,10 +1492,11 @@ TALER_MINT_handler_refresh_link (struct RequestHandler *rh,
|
|||||||
}
|
}
|
||||||
if (GNUNET_NO == res)
|
if (GNUNET_NO == res)
|
||||||
{
|
{
|
||||||
return request_send_json_pack (connection,
|
return TALER_MINT_reply_json_pack (connection,
|
||||||
MHD_HTTP_NOT_FOUND,
|
MHD_HTTP_NOT_FOUND,
|
||||||
"{s:s}",
|
"{s:s}",
|
||||||
"error", "link data not found (transfer)");
|
"error",
|
||||||
|
"link data not found (transfer)");
|
||||||
}
|
}
|
||||||
GNUNET_assert (GNUNET_OK == res);
|
GNUNET_assert (GNUNET_OK == res);
|
||||||
|
|
||||||
@ -1486,10 +1508,11 @@ TALER_MINT_handler_refresh_link (struct RequestHandler *rh,
|
|||||||
}
|
}
|
||||||
if (GNUNET_NO == res)
|
if (GNUNET_NO == res)
|
||||||
{
|
{
|
||||||
return request_send_json_pack (connection,
|
return TALER_MINT_reply_json_pack (connection,
|
||||||
MHD_HTTP_NOT_FOUND,
|
MHD_HTTP_NOT_FOUND,
|
||||||
"{s:s}",
|
"{s:s}",
|
||||||
"error", "link data not found (link)");
|
"error",
|
||||||
|
"link data not found (link)");
|
||||||
}
|
}
|
||||||
GNUNET_assert (GNUNET_OK == res);
|
GNUNET_assert (GNUNET_OK == res);
|
||||||
json_object_set_new (root, "transfer_pub",
|
json_object_set_new (root, "transfer_pub",
|
||||||
@ -1498,7 +1521,9 @@ TALER_MINT_handler_refresh_link (struct RequestHandler *rh,
|
|||||||
json_object_set_new (root, "secret_enc",
|
json_object_set_new (root, "secret_enc",
|
||||||
TALER_JSON_from_data (&shared_secret_enc,
|
TALER_JSON_from_data (&shared_secret_enc,
|
||||||
sizeof (struct SharedSecretEnc)));
|
sizeof (struct SharedSecretEnc)));
|
||||||
return send_response_json (connection, root, MHD_HTTP_OK);
|
return TALER_MINT_reply_json (connection,
|
||||||
|
root,
|
||||||
|
MHD_HTTP_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
146
src/mint/taler-mint-httpd_responses.c
Normal file
146
src/mint/taler-mint-httpd_responses.c
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
/*
|
||||||
|
This file is part of TALER
|
||||||
|
(C) 2014 GNUnet e.V.
|
||||||
|
|
||||||
|
TALER is free software; you can redistribute it and/or modify it under the
|
||||||
|
terms of the GNU Affero General Public License as published by the Free Software
|
||||||
|
Foundation; either version 3, or (at your option) any later version.
|
||||||
|
|
||||||
|
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||||
|
A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License along with
|
||||||
|
TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file taler-mint-httpd_responses.c
|
||||||
|
* @brief API for generating the various replies of the mint; these
|
||||||
|
* functions are called TALER_MINT_reply_ and they generate
|
||||||
|
* and queue MHD response objects for a given connection.
|
||||||
|
* @author Florian Dold
|
||||||
|
* @author Benedikt Mueller
|
||||||
|
* @author Christian Grothoff
|
||||||
|
*/
|
||||||
|
#include "platform.h"
|
||||||
|
#include "taler-mint-httpd_responses.h"
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send JSON object as response. Decreases the reference count of the
|
||||||
|
* JSON object.
|
||||||
|
*
|
||||||
|
* @param connection the MHD connection
|
||||||
|
* @param json the json object
|
||||||
|
* @param response_code the http response code
|
||||||
|
* @return MHD result code
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
TALER_MINT_reply_json (struct MHD_Connection *connection,
|
||||||
|
json_t *json,
|
||||||
|
unsigned int response_code)
|
||||||
|
{
|
||||||
|
struct MHD_Response *resp;
|
||||||
|
char *json_str;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
json_str = json_dumps (json, JSON_INDENT(2));
|
||||||
|
json_decref (json);
|
||||||
|
resp = MHD_create_response_from_buffer (strlen (json_str), json_str,
|
||||||
|
MHD_RESPMEM_MUST_FREE);
|
||||||
|
if (NULL == resp)
|
||||||
|
return MHD_NO;
|
||||||
|
(void) MHD_add_response_header (resp,
|
||||||
|
MHD_HTTP_HEADER_CONTENT_TYPE,
|
||||||
|
"application/json");
|
||||||
|
ret = MHD_queue_response (connection, response_code, resp);
|
||||||
|
MHD_destroy_response (resp);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to call to handle the request by building a JSON
|
||||||
|
* reply from a format string and varargs.
|
||||||
|
*
|
||||||
|
* @param connection the MHD connection to handle
|
||||||
|
* @param response_code HTTP response code to use
|
||||||
|
* @param fmt format string for pack
|
||||||
|
* @param ... varargs
|
||||||
|
* @return MHD result code
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
TALER_MINT_reply_json_pack (struct MHD_Connection *connection,
|
||||||
|
unsigned int response_code,
|
||||||
|
const char *fmt,
|
||||||
|
...)
|
||||||
|
{
|
||||||
|
json_t *json;
|
||||||
|
va_list argp;
|
||||||
|
|
||||||
|
va_start (argp, fmt);
|
||||||
|
json = json_vpack_ex (NULL, 0, fmt, argp);
|
||||||
|
va_end (argp);
|
||||||
|
if (NULL == json)
|
||||||
|
return MHD_NO;
|
||||||
|
return TALER_MINT_reply_json (connection,
|
||||||
|
json,
|
||||||
|
response_code);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a response indicating an invalid argument.
|
||||||
|
*
|
||||||
|
* @param connection the MHD connection to use
|
||||||
|
* @param param_name the parameter that is invalid
|
||||||
|
* @return a MHD result code
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
TALER_MINT_reply_arg_invalid (struct MHD_Connection *connection,
|
||||||
|
const char *param_name)
|
||||||
|
{
|
||||||
|
json_t *json;
|
||||||
|
|
||||||
|
json = json_pack ("{ s:s, s:s }",
|
||||||
|
"error",
|
||||||
|
"invalid parameter",
|
||||||
|
"parameter",
|
||||||
|
param_name);
|
||||||
|
return TALER_MINT_reply_json (connection,
|
||||||
|
json,
|
||||||
|
MHD_HTTP_BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a response indicating a missing argument.
|
||||||
|
*
|
||||||
|
* @param connection the MHD connection to use
|
||||||
|
* @param param_name the parameter that is missing
|
||||||
|
* @return a MHD result code
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
TALER_MINT_reply_arg_missing (struct MHD_Connection *connection,
|
||||||
|
const char *param_name)
|
||||||
|
{
|
||||||
|
json_t *json;
|
||||||
|
|
||||||
|
json = json_pack ("{ s:s, s:s }",
|
||||||
|
"error",
|
||||||
|
"missing parameter",
|
||||||
|
"parameter",
|
||||||
|
param_name);
|
||||||
|
return TALER_MINT_reply_json (connection,
|
||||||
|
json,
|
||||||
|
MHD_HTTP_BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* end of taler-mint-httpd_responses.c */
|
93
src/mint/taler-mint-httpd_responses.h
Normal file
93
src/mint/taler-mint-httpd_responses.h
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
/*
|
||||||
|
This file is part of TALER
|
||||||
|
(C) 2014 GNUnet e.V.
|
||||||
|
|
||||||
|
TALER is free software; you can redistribute it and/or modify it under the
|
||||||
|
terms of the GNU Affero General Public License as published by the Free Software
|
||||||
|
Foundation; either version 3, or (at your option) any later version.
|
||||||
|
|
||||||
|
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||||
|
A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License along with
|
||||||
|
TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file taler-mint-httpd_responses.h
|
||||||
|
* @brief API for generating the various replies of the mint; these
|
||||||
|
* functions are called TALER_MINT_reply_ and they generate
|
||||||
|
* and queue MHD response objects for a given connection.
|
||||||
|
* @author Florian Dold
|
||||||
|
* @author Benedikt Mueller
|
||||||
|
* @author Christian Grothoff
|
||||||
|
*/
|
||||||
|
#ifndef TALER_MINT_HTTPD_RESPONSES_H
|
||||||
|
#define TALER_MINT_HTTPD_RESPONSES_H
|
||||||
|
#include <gnunet/gnunet_util_lib.h>
|
||||||
|
#include <jansson.h>
|
||||||
|
#include <microhttpd.h>
|
||||||
|
#include <libpq-fe.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include "taler-mint-httpd.h"
|
||||||
|
#include "taler-mint-httpd_mhd.h"
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send JSON object as response. Decreases the reference count of the
|
||||||
|
* JSON object.
|
||||||
|
*
|
||||||
|
* @param connection the MHD connection
|
||||||
|
* @param json the json object
|
||||||
|
* @param response_code the http response code
|
||||||
|
* @return MHD result code
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
TALER_MINT_reply_json (struct MHD_Connection *connection,
|
||||||
|
json_t *json,
|
||||||
|
unsigned int response_code);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to call to handle the request by building a JSON
|
||||||
|
* reply from a format string and varargs.
|
||||||
|
*
|
||||||
|
* @param connection the MHD connection to handle
|
||||||
|
* @param response_code HTTP response code to use
|
||||||
|
* @param fmt format string for pack
|
||||||
|
* @param ... varargs
|
||||||
|
* @return MHD result code
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
TALER_MINT_reply_json_pack (struct MHD_Connection *connection,
|
||||||
|
unsigned int response_code,
|
||||||
|
const char *fmt,
|
||||||
|
...);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a response indicating an invalid argument.
|
||||||
|
*
|
||||||
|
* @param connection the MHD connection to use
|
||||||
|
* @param param_name the parameter that is invalid
|
||||||
|
* @return MHD result code
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
TALER_MINT_reply_arg_invalid (struct MHD_Connection *connection,
|
||||||
|
const char *param_name);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a response indicating a missing argument.
|
||||||
|
*
|
||||||
|
* @param connection the MHD connection to use
|
||||||
|
* @param param_name the parameter that is missing
|
||||||
|
* @return a MHD result code
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
TALER_MINT_reply_arg_missing (struct MHD_Connection *connection,
|
||||||
|
const char *param_name);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
@ -31,10 +31,11 @@
|
|||||||
#include "taler_signatures.h"
|
#include "taler_signatures.h"
|
||||||
#include "taler_rsa.h"
|
#include "taler_rsa.h"
|
||||||
#include "taler_json_lib.h"
|
#include "taler_json_lib.h"
|
||||||
#include "taler-mint-httpd_json.h"
|
#include "taler-mint-httpd_parsing.h"
|
||||||
#include "taler-mint-httpd_keys.h"
|
#include "taler-mint-httpd_keys.h"
|
||||||
#include "taler-mint-httpd_mhd.h"
|
#include "taler-mint-httpd_mhd.h"
|
||||||
#include "taler-mint-httpd_withdraw.h"
|
#include "taler-mint-httpd_withdraw.h"
|
||||||
|
#include "taler-mint-httpd_responses.h"
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -135,10 +136,7 @@ TALER_MINT_handler_withdraw_status (struct RequestHandler *rh,
|
|||||||
&reserve_pub,
|
&reserve_pub,
|
||||||
&reserve);
|
&reserve);
|
||||||
if (GNUNET_SYSERR == res)
|
if (GNUNET_SYSERR == res)
|
||||||
return TALER_MINT_helper_send_json_pack (rh,
|
return TALER_MINT_reply_json_pack (connection,
|
||||||
connection,
|
|
||||||
connection_cls,
|
|
||||||
0 /* no caching */,
|
|
||||||
MHD_HTTP_NOT_FOUND,
|
MHD_HTTP_NOT_FOUND,
|
||||||
"{s:s}",
|
"{s:s}",
|
||||||
"error",
|
"error",
|
||||||
@ -178,7 +176,7 @@ TALER_MINT_handler_withdraw_status (struct RequestHandler *rh,
|
|||||||
sig_to_json (&reserve.status_sig_purpose,
|
sig_to_json (&reserve.status_sig_purpose,
|
||||||
&reserve.status_sig));
|
&reserve.status_sig));
|
||||||
|
|
||||||
return send_response_json (connection,
|
return TALER_MINT_reply_json (connection,
|
||||||
json,
|
json,
|
||||||
MHD_HTTP_OK);
|
MHD_HTTP_OK);
|
||||||
}
|
}
|
||||||
@ -200,7 +198,7 @@ helper_withdraw_sign_send_reply (struct MHD_Connection *connection,
|
|||||||
json_object_set_new (root, "ev_sig",
|
json_object_set_new (root, "ev_sig",
|
||||||
TALER_JSON_from_data (&collectable->ev_sig,
|
TALER_JSON_from_data (&collectable->ev_sig,
|
||||||
sizeof (struct TALER_RSA_Signature)));
|
sizeof (struct TALER_RSA_Signature)));
|
||||||
return send_response_json (connection,
|
return TALER_MINT_reply_json (connection,
|
||||||
root,
|
root,
|
||||||
MHD_HTTP_OK);
|
MHD_HTTP_OK);
|
||||||
}
|
}
|
||||||
@ -317,10 +315,11 @@ TALER_MINT_handler_withdraw_sign (struct RequestHandler *rh,
|
|||||||
return MHD_NO;
|
return MHD_NO;
|
||||||
}
|
}
|
||||||
if (GNUNET_NO == res)
|
if (GNUNET_NO == res)
|
||||||
return request_send_json_pack (connection,
|
return TALER_MINT_reply_json_pack (connection,
|
||||||
MHD_HTTP_NOT_FOUND,
|
MHD_HTTP_NOT_FOUND,
|
||||||
"{s:s}",
|
"{s:s}",
|
||||||
"error", "Reserve not found");
|
"error",
|
||||||
|
"Reserve not found");
|
||||||
|
|
||||||
// fill out all the missing info in the request before
|
// fill out all the missing info in the request before
|
||||||
// we can check the signature on the request
|
// we can check the signature on the request
|
||||||
@ -334,7 +333,7 @@ TALER_MINT_handler_withdraw_sign (struct RequestHandler *rh,
|
|||||||
&wsrd.purpose,
|
&wsrd.purpose,
|
||||||
&wsrd.sig,
|
&wsrd.sig,
|
||||||
&wsrd.reserve_pub))
|
&wsrd.reserve_pub))
|
||||||
return request_send_json_pack (connection,
|
return TALER_MINT_reply_json_pack (connection,
|
||||||
MHD_HTTP_UNAUTHORIZED,
|
MHD_HTTP_UNAUTHORIZED,
|
||||||
"{s:s}",
|
"{s:s}",
|
||||||
"error", "Invalid Signature");
|
"error", "Invalid Signature");
|
||||||
@ -344,9 +343,11 @@ TALER_MINT_handler_withdraw_sign (struct RequestHandler *rh,
|
|||||||
&wsrd.denomination_pub);
|
&wsrd.denomination_pub);
|
||||||
TALER_MINT_key_state_release (key_state);
|
TALER_MINT_key_state_release (key_state);
|
||||||
if (NULL == dki)
|
if (NULL == dki)
|
||||||
return request_send_json_pack (connection, MHD_HTTP_NOT_FOUND,
|
return TALER_MINT_reply_json_pack (connection,
|
||||||
|
MHD_HTTP_NOT_FOUND,
|
||||||
"{s:s}",
|
"{s:s}",
|
||||||
"error", "Denomination not found");
|
"error",
|
||||||
|
"Denomination not found");
|
||||||
|
|
||||||
amount_required = TALER_amount_ntoh (dki->issue.value);
|
amount_required = TALER_amount_ntoh (dki->issue.value);
|
||||||
amount_required = TALER_amount_add (amount_required,
|
amount_required = TALER_amount_add (amount_required,
|
||||||
@ -354,11 +355,13 @@ TALER_MINT_handler_withdraw_sign (struct RequestHandler *rh,
|
|||||||
|
|
||||||
if (0 < TALER_amount_cmp (amount_required,
|
if (0 < TALER_amount_cmp (amount_required,
|
||||||
TALER_amount_ntoh (reserve.balance)))
|
TALER_amount_ntoh (reserve.balance)))
|
||||||
return request_send_json_pack (connection,
|
return TALER_MINT_reply_json_pack (connection,
|
||||||
MHD_HTTP_PAYMENT_REQUIRED,
|
MHD_HTTP_PAYMENT_REQUIRED,
|
||||||
"{s:s}",
|
"{s:s}",
|
||||||
"error", "Insufficient funds");
|
"error",
|
||||||
if (GNUNET_OK != TALER_RSA_sign (dki->denom_priv,
|
"Insufficient funds");
|
||||||
|
if (GNUNET_OK !=
|
||||||
|
TALER_RSA_sign (dki->denom_priv,
|
||||||
&wsrd.coin_envelope,
|
&wsrd.coin_envelope,
|
||||||
sizeof (struct TALER_RSA_BlindedSignaturePurpose),
|
sizeof (struct TALER_RSA_BlindedSignaturePurpose),
|
||||||
&ev_sig))
|
&ev_sig))
|
||||||
|
Loading…
Reference in New Issue
Block a user