summaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/Makefile.am3
-rw-r--r--src/backend/taler-merchant-httpd.c7
-rw-r--r--src/backend/taler-merchant-httpd.h2
-rw-r--r--src/backend/taler-merchant-httpd_contract.c4
-rw-r--r--src/backend/taler-merchant-httpd_map.c137
5 files changed, 106 insertions, 47 deletions
diff --git a/src/backend/Makefile.am b/src/backend/Makefile.am
index a1aaf540..f7fc4c88 100644
--- a/src/backend/Makefile.am
+++ b/src/backend/Makefile.am
@@ -23,7 +23,8 @@ taler_merchant_httpd_SOURCES = \
taler-merchant-httpd_pay.c taler-merchant-httpd_pay.h \
taler-merchant-httpd_history.c taler-merchant-httpd_history.h \
taler-merchant-httpd_track-transaction.c taler-merchant-httpd_track-transaction.h \
- taler-merchant-httpd_track-transfer.c taler-merchant-httpd_track-transfer.h
+ taler-merchant-httpd_track-transfer.c taler-merchant-httpd_track-transfer.h \
+ taler-merchant-httpd_map.c taler-merchant-httpd_map.h
taler_merchant_httpd_LDADD = \
diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c
index c5ebe21e..fd41c614 100644
--- a/src/backend/taler-merchant-httpd.c
+++ b/src/backend/taler-merchant-httpd.c
@@ -40,6 +40,7 @@
#include "taler-merchant-httpd_track-transaction.h"
#include "taler-merchant-httpd_track-transfer.h"
#include "taler-merchant-httpd_history.h"
+#include "taler-merchant-httpd_map.h"
/**
* Backlog for listen operation on unix-domain sockets.
@@ -191,6 +192,12 @@ url_handler (void *cls,
{ "/history", MHD_HTTP_METHOD_GET, "text/plain",
"Only GET is allowed", 0,
&MH_handler_history, MHD_HTTP_OK},
+ { "/map/in", MHD_HTTP_METHOD_POST, "text/plain",
+ "Only POST is allowed", 0,
+ &MH_handler_map_in, MHD_HTTP_OK},
+ { "/map/out", MHD_HTTP_METHOD_GET, "text/plain",
+ "Only GET is allowed", 0,
+ &MH_handler_map_out, MHD_HTTP_OK},
{NULL, NULL, NULL, NULL, 0, 0 }
};
static struct TMH_RequestHandler h404 =
diff --git a/src/backend/taler-merchant-httpd.h b/src/backend/taler-merchant-httpd.h
index 9d45ab67..f5adeac9 100644
--- a/src/backend/taler-merchant-httpd.h
+++ b/src/backend/taler-merchant-httpd.h
@@ -190,7 +190,7 @@ typedef void
* Each MHD response handler that sets the "connection_cls" to a
* non-NULL value must use a struct that has this struct as its first
* member. This struct contains a single callback, which will be
- * invoked to clean up the memory when the contection is completed.
+ * invoked to clean up the memory when the connection is completed.
*/
struct TM_HandlerContext
{
diff --git a/src/backend/taler-merchant-httpd_contract.c b/src/backend/taler-merchant-httpd_contract.c
index f47e5ba9..b3ed8bba 100644
--- a/src/backend/taler-merchant-httpd_contract.c
+++ b/src/backend/taler-merchant-httpd_contract.c
@@ -81,7 +81,7 @@ check_products (json_t *products)
/**
- * Information we keep for an individual calls
+ * Information we keep for individual calls
* to requests that parse JSON, but keep no other state.
*/
struct TMH_JsonParseContext
@@ -169,7 +169,7 @@ MH_handler_contract (struct TMH_RequestHandler *rh,
GNUNET_JSON_spec_absolute_time ("timestamp", &timestamp),
GNUNET_JSON_spec_absolute_time ("refund_deadline", &refund_deadline),
GNUNET_JSON_spec_absolute_time ("pay_deadline", &pay_deadline),
- GNUNET_JSON_spec_end()
+ GNUNET_JSON_spec_end ()
};
if (NULL == *connection_cls)
diff --git a/src/backend/taler-merchant-httpd_map.c b/src/backend/taler-merchant-httpd_map.c
index 39473a3a..5c69fe41 100644
--- a/src/backend/taler-merchant-httpd_map.c
+++ b/src/backend/taler-merchant-httpd_map.c
@@ -24,50 +24,47 @@
#include <taler/taler_json_lib.h>
#include "taler-merchant-httpd.h"
#include "taler-merchant-httpd_responses.h"
+#include "taler-merchant-httpd_parsing.h"
/**
- * Function called with information about a transaction. Checks whether the
- * returned tuple
- *
- * @param cls closure
- * @param transaction_id of the contract
- * @param merchant_pub merchant's public key
- * @param exchange_uri URI of the exchange
- * @param h_contract hash of the contract
- * @param h_wire hash of our wire details
- * @param timestamp time of the confirmation
- * @param refund refund deadline
- * @param total_amount total amount we receive for the contract after fees
+ * Information we keep for individual calls
+ * to requests that parse JSON, but keep no other state.
*/
+struct TMH_JsonParseContext
+{
+
+ /**
+ * This field MUST be first.
+ * FIXME: Explain why!
+ */
+ struct TM_HandlerContext hc;
+
+ /**
+ * Placeholder for #TMH_PARSE_post_json() to keep its internal state.
+ */
+ void *json_parse_context;
+};
+
+
+/**
+ * Custom cleanup routine for a `struct TMH_JsonParseContext`.
+ *
+ * @param hc the `struct TMH_JsonParseContext` to clean up.
+ */
static void
-history_cb (void *cls,
- uint64_t transaction_id,
- const struct TALER_MerchantPublicKeyP *merchant_pub,
- const char *exchange_uri,
- const struct GNUNET_HashCode *h_contract,
- const struct GNUNET_HashCode *h_wire,
- struct GNUNET_TIME_Absolute timestamp,
- struct GNUNET_TIME_Absolute refund,
- const struct TALER_Amount *total_amount)
+json_parse_cleanup (struct TM_HandlerContext *hc)
{
- json_t *response = cls;
- json_t *entry;
-
- GNUNET_break (NULL !=
- (entry = json_pack ("{s:I, s:s, s:o, s:o, s:o}",
- "transaction_id", transaction_id,
- "exchange", exchange_uri,
- "h_contract", GNUNET_JSON_from_data_auto (h_contract),
- "timestamp", GNUNET_JSON_from_time_abs (timestamp),
- "total_amount",
- TALER_JSON_from_amount (total_amount))));
- GNUNET_break (0 == json_array_append (response, entry));
+ struct TMH_JsonParseContext *jpc = (struct TMH_JsonParseContext *) hc;
+
+ TMH_PARSE_post_cleanup_callback (jpc->json_parse_context);
+ GNUNET_free (jpc);
}
+
/**
- * Manage a /map request. Store in db the contract given along
- * with its hashcode.
+ * Manage a /map/in request. Store in db a plain text contract
+ * and its hashcode.
*
* @param rh context of the handler
* @param connection the MHD connection to handle
@@ -77,20 +74,74 @@ history_cb (void *cls,
* @return MHD result code
*/
int
-MH_handler_history (struct TMH_RequestHandler *rh,
+MH_handler_map_in (struct TMH_RequestHandler *rh,
+ struct MHD_Connection *connection,
+ void **connection_cls,
+ const char *upload_data,
+ size_t *upload_data_size)
+{
+
+ int res;
+ json_t *root;
+ json_t *contract;
+ struct GNUNET_HashCode h_contract;
+ struct TMH_JsonParseContext *ctx;
+
+/* Fetch body */
+
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_json ("contract", &contract),
+ GNUNET_JSON_spec_fixed_auto ("h_contract", &h_contract),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (NULL == *connection_cls)
+ {
+ ctx = GNUNET_new (struct TMH_JsonParseContext);
+ ctx->hc.cc = &json_parse_cleanup;
+ *connection_cls = ctx;
+ }
+ else
+ {
+ ctx = *connection_cls;
+ }
+
+ res = TMH_PARSE_post_json (connection,
+ &ctx->json_parse_context,
+ upload_data,
+ upload_data_size,
+ &root);
+ if (GNUNET_SYSERR == res)
+ return MHD_NO;
+ /* the POST's body has to be further fetched */
+ if ((GNUNET_NO == res) || (NULL == root))
+ return MHD_YES;
+
+
+/* Store body */
+
+}
+
+
+/**
+ * Manage a /map/out request. Query the db and returns a plain
+ * text contract associated with the hashcode given as input
+ *
+ * @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 upload_data upload data
+ * @param[in,out] upload_data_size number of bytes (left) in @a upload_data
+ * @return MHD result code
+ */
+int
+MH_handler_map_out (struct TMH_RequestHandler *rh,
struct MHD_Connection *connection,
void **connection_cls,
const char *upload_data,
size_t *upload_data_size)
{
- #define LOG_INFO(...) GNUNET_log (GNUNET_ERROR_TYPE_INFO, __VA_ARGS__)
- const char *str;
- struct GNUNET_TIME_Absolute date;
- json_t *response;
- unsigned int ret;
- /* TBD */
}
-
/* end of taler-merchant-httpd_history.c */