[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] branch master updated: fix handler context usage'
From: |
gnunet |
Subject: |
[taler-anastasis] branch master updated: fix handler context usage' |
Date: |
Wed, 14 Oct 2020 10:42:47 +0200 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository anastasis.
The following commit(s) were added to refs/heads/master by this push:
new 9ea122b fix handler context usage'
9ea122b is described below
commit 9ea122bc58898bed112a3925159f480e8a96a3a1
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Wed Oct 14 10:42:42 2020 +0200
fix handler context usage'
---
src/backend/anastasis-httpd.c | 84 +++++++++--------------------
src/backend/anastasis-httpd.h | 9 +---
src/backend/anastasis-httpd_config.c | 12 ++---
src/backend/anastasis-httpd_config.h | 10 +---
src/backend/anastasis-httpd_mhd.c | 22 +-------
src/backend/anastasis-httpd_mhd.h | 14 +----
src/backend/anastasis-httpd_policy.h | 6 +--
src/backend/anastasis-httpd_policy_upload.c | 20 +++----
src/backend/anastasis-httpd_salt.c | 11 ++--
src/backend/anastasis-httpd_salt.h | 11 ++--
src/backend/anastasis-httpd_terms.c | 11 +---
src/backend/anastasis-httpd_terms.h | 10 +---
src/backend/anastasis-httpd_truth.h | 6 +--
src/backend/anastasis-httpd_truth_upload.c | 29 +++++-----
14 files changed, 71 insertions(+), 184 deletions(-)
diff --git a/src/backend/anastasis-httpd.c b/src/backend/anastasis-httpd.c
index 7e29ef3..252b893 100644
--- a/src/backend/anastasis-httpd.c
+++ b/src/backend/anastasis-httpd.c
@@ -181,7 +181,7 @@ run_daemon (void *cls)
* the task processing MHD's activities to run immediately.
*/
void
-AH_trigger_daemon ()
+AH_trigger_daemon (void)
{
if (NULL != mhd_task)
{
@@ -200,7 +200,7 @@ AH_trigger_daemon ()
* Kick GNUnet Curl scheduler to begin curl interactions.
*/
void
-AH_trigger_curl ()
+AH_trigger_curl (void)
{
GNUNET_CURL_gnunet_scheduler_reschedule (&rc);
}
@@ -269,6 +269,9 @@ url_handler (void *cls,
{ "/config", MHD_HTTP_METHOD_GET, "text/plain",
NULL, 0,
&AH_handler_config, MHD_HTTP_OK },
+ { "/salt", MHD_HTTP_METHOD_GET, "text/plain",
+ NULL, 0,
+ &AH_handler_salt, MHD_HTTP_OK },
{NULL, NULL, NULL, NULL, 0, 0 }
};
static struct TMH_RequestHandler h404 = {
@@ -278,11 +281,12 @@ url_handler (void *cls,
};
struct TM_HandlerContext *hc = *con_cls;
- struct GNUNET_AsyncScopeId aid;
const char *correlation_id = NULL;
if (NULL == hc)
{
+ struct GNUNET_AsyncScopeId aid;
+
GNUNET_async_scope_fresh (&aid);
/* We only read the correlation ID on the first callback for every client
*/
correlation_id = MHD_lookup_connection_value (connection,
@@ -295,13 +299,12 @@ url_handler (void *cls,
"illegal incoming correlation ID\n");
correlation_id = NULL;
}
- }
- else
- {
- aid = hc->async_scope_id;
+ hc = GNUNET_new (struct TM_HandlerContext);
+ *con_cls = hc;
+ hc->async_scope_id = aid;
}
- GNUNET_SCHEDULER_begin_async_scope (&aid);
+ GNUNET_SCHEDULER_begin_async_scope (&hc->async_scope_id);
if (NULL != correlation_id)
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Handling request for (%s) URL '%s', correlation_id=%s\n",
@@ -327,20 +330,11 @@ url_handler (void *cls,
if (0 == strcmp (method,
MHD_HTTP_METHOD_POST))
{
- MHD_RESULT ret;
- ret = AH_handler_policy_post (connection,
- con_cls,
- url,
- upload_data,
- upload_data_size);
- hc = *con_cls;
- if (NULL != hc)
- {
- /* Store the async context ID, so we can restore it if
- * we get another callack for this request. */
- hc->async_scope_id = aid;
- }
- return ret;
+ return AH_handler_policy_post (connection,
+ hc,
+ url + strlen ("/policy/"),
+ upload_data,
+ upload_data_size);
}
}
if (0 == strncmp (url,
@@ -353,31 +347,18 @@ url_handler (void *cls,
{
return AH_handler_truth_get (connection,
url,
- con_cls);
+ hc);
}
if (0 == strcmp (method,
MHD_HTTP_METHOD_POST))
{
return AH_handler_truth_post (connection,
- con_cls,
- url,
+ hc,
+ url + strlen ("/truth/"),
upload_data,
upload_data_size);
}
}
- if (0 == strncmp (url,
- "/salt",
- strlen ("/salt")))
- {
- // return handle_salt (...);
- if (0 == strcmp (method,
- MHD_HTTP_METHOD_GET))
- {
- return AH_handler_salt (connection,
- url,
- con_cls);
- }
- }
for (unsigned int i = 0; NULL != handlers[i].url; i++)
{
struct TMH_RequestHandler *rh = &handlers[i];
@@ -394,30 +375,14 @@ url_handler (void *cls,
(0 == strcasecmp (method,
rh->method)) )
{
- MHD_RESULT ret;
-
- ret = rh->handler (rh,
- connection,
- con_cls,
- upload_data,
- upload_data_size);
- hc = *con_cls;
- if (NULL != hc)
- {
- hc->rh = rh;
- /* Store the async context ID, so we can restore it if
- * we get another callack for this request. */
- hc->async_scope_id = aid;
- }
- return ret;
+ return rh->handler (rh,
+ connection);
}
}
}
+ // FIXME: HTTP 405? METHOD_NOT_ALLOWED
return TMH_MHD_handler_static_response (&h404,
- connection,
- con_cls,
- upload_data,
- upload_data_size);
+ connection);
}
@@ -490,7 +455,8 @@ handle_mhd_completion_callback (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Finished handling request with status %d\n",
(int) toe);
- hc->cc (hc);
+ if (NULL != hc->cc)
+ hc->cc (hc);
*con_cls = NULL;
}
diff --git a/src/backend/anastasis-httpd.h b/src/backend/anastasis-httpd.h
index 188a824..b0b6fba 100644
--- a/src/backend/anastasis-httpd.h
+++ b/src/backend/anastasis-httpd.h
@@ -64,18 +64,11 @@ struct TMH_RequestHandler
* Function to call to handle the request.
*
* @param rh this struct
- * @param mime_type the @e mime_type for the reply (hint, can be NULL)
* @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
*/
MHD_RESULT (*handler)(struct TMH_RequestHandler *rh,
- struct MHD_Connection *connection,
- void **connection_cls,
- const char *upload_data,
- size_t *upload_data_size);
+ struct MHD_Connection *connection);
/**
* Default response code.
diff --git a/src/backend/anastasis-httpd_config.c
b/src/backend/anastasis-httpd_config.c
index dae879a..97b184c 100644
--- a/src/backend/anastasis-httpd_config.c
+++ b/src/backend/anastasis-httpd_config.c
@@ -30,21 +30,15 @@
*
* @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
- * @param mi merchant backend instance, never NULL
* @return MHD result code
*/
MHD_RESULT
AH_handler_config (struct TMH_RequestHandler *rh,
- struct MHD_Connection *connection,
- void **connection_cls,
- const char *upload_data,
- size_t *upload_data_size)
+ struct MHD_Connection *connection)
{
json_t *methods = json_object ();
json_t *method_arr = json_array ();
+
if (! method_arr)
return MHD_HTTP_BAD_GATEWAY;
@@ -136,4 +130,4 @@ AH_handler_config (struct TMH_RequestHandler *rh,
}
-/* end of anastasis-httpd_config.c */
\ No newline at end of file
+/* end of anastasis-httpd_config.c */
diff --git a/src/backend/anastasis-httpd_config.h
b/src/backend/anastasis-httpd_config.h
index f096369..3acf5a4 100644
--- a/src/backend/anastasis-httpd_config.h
+++ b/src/backend/anastasis-httpd_config.h
@@ -30,18 +30,12 @@
*
* @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
*/
MHD_RESULT
AH_handler_config (struct TMH_RequestHandler *rh,
- struct MHD_Connection *connection,
- void **connection_cls,
- const char *upload_data,
- size_t *upload_data_size);
+ struct MHD_Connection *connection);
#endif
-/* end of anastasis-httpd_config.h */
\ No newline at end of file
+/* end of anastasis-httpd_config.h */
diff --git a/src/backend/anastasis-httpd_mhd.c
b/src/backend/anastasis-httpd_mhd.c
index 0913b5e..4712210 100644
--- a/src/backend/anastasis-httpd_mhd.c
+++ b/src/backend/anastasis-httpd_mhd.c
@@ -33,21 +33,12 @@
*
* @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
*/
MHD_RESULT
TMH_MHD_handler_static_response (struct TMH_RequestHandler *rh,
- struct MHD_Connection *connection,
- void **connection_cls,
- const char *upload_data,
- size_t *upload_data_size)
+ struct MHD_Connection *connection)
{
- (void) connection_cls;
- (void) upload_data;
- (void) upload_data_size;
if (0 == rh->data_size)
rh->data_size = strlen ((const char *) rh->data);
return TALER_MHD_reply_static (connection,
@@ -64,22 +55,13 @@ TMH_MHD_handler_static_response (struct TMH_RequestHandler
*rh,
*
* @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
*/
MHD_RESULT
TMH_MHD_handler_agpl_redirect (struct TMH_RequestHandler *rh,
- struct MHD_Connection *connection,
- void **connection_cls,
- const char *upload_data,
- size_t *upload_data_size)
+ struct MHD_Connection *connection)
{
(void) rh;
- (void) connection_cls;
- (void) upload_data;
- (void) upload_data_size;
return TALER_MHD_reply_agpl (connection,
"http://www.git.taler.net/anastasis.git");
}
diff --git a/src/backend/anastasis-httpd_mhd.h
b/src/backend/anastasis-httpd_mhd.h
index 61986cf..a9b8b83 100644
--- a/src/backend/anastasis-httpd_mhd.h
+++ b/src/backend/anastasis-httpd_mhd.h
@@ -42,10 +42,7 @@
*/
MHD_RESULT
TMH_MHD_handler_static_response (struct TMH_RequestHandler *rh,
- struct MHD_Connection *connection,
- void **connection_cls,
- const char *upload_data,
- size_t *upload_data_size);
+ struct MHD_Connection *connection);
/**
@@ -54,18 +51,11 @@ TMH_MHD_handler_static_response (struct TMH_RequestHandler
*rh,
*
* @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
- * @param mi merchant backend instance, never NULL
* @return MHD result code
*/
MHD_RESULT
TMH_MHD_handler_agpl_redirect (struct TMH_RequestHandler *rh,
- struct MHD_Connection *connection,
- void **connection_cls,
- const char *upload_data,
- size_t *upload_data_size);
+ struct MHD_Connection *connection);
#endif
diff --git a/src/backend/anastasis-httpd_policy.h
b/src/backend/anastasis-httpd_policy.h
index 1373cf0..ff2b8c9 100644
--- a/src/backend/anastasis-httpd_policy.h
+++ b/src/backend/anastasis-httpd_policy.h
@@ -44,15 +44,15 @@ AH_policy_get (struct MHD_Connection *connection,
/**
* @param connection the MHD connection to handle
* @param con_cls the connection's closure
- * @param url handles a URL of the format "/policy/$ACCOUNT_PUB"
+ * @param account name of the account of the format "$ACCOUNT_PUB"
* @param upload_data upload data
* @param upload_data_size number of bytes (left) in @a upload_data
* @return MHD result code
*/
MHD_RESULT
AH_handler_policy_post (struct MHD_Connection *connection,
- void **con_cls,
- const char *url,
+ struct TM_HandlerContext *hc,
+ const char *account,
const char *upload_data,
size_t *upload_data_size);
diff --git a/src/backend/anastasis-httpd_policy_upload.c
b/src/backend/anastasis-httpd_policy_upload.c
index 2cd5b18..3c439b9 100644
--- a/src/backend/anastasis-httpd_policy_upload.c
+++ b/src/backend/anastasis-httpd_policy_upload.c
@@ -206,7 +206,7 @@ AH_resume_all_bc ()
static void
cleanup_ctx (struct TM_HandlerContext *hc)
{
- struct PolicyUploadContext *puc = (struct PolicyUploadContext *) hc;
+ struct PolicyUploadContext *puc = hc->ctx;
if (NULL != puc->po)
TALER_MERCHANT_orders_post_cancel (puc->po);
@@ -654,19 +654,19 @@ handle_database_error (struct PolicyUploadContext *puc,
/**
* @param connection the MHD connection to handle
* @param con_cls the connection's closure
- * @param url handles a URL of the format "/policy/$ACCOUNT_PUB"
+ * @param account name of the account of the format "$ACCOUNT_PUB"
* @param recovery_data upload data
* @param recovery_data_size number of bytes (left) in @a recovery_data
* @return MHD result code
*/
MHD_RESULT
AH_handler_policy_post (struct MHD_Connection *connection,
- void **con_cls,
- const char *url,
+ struct TM_HandlerContext *hc,
+ const char *account,
const char *recovery_data,
size_t *recovery_data_size)
{
- struct PolicyUploadContext *puc;
+ struct PolicyUploadContext *puc = hc->ctx;
struct ANASTASIS_CRYPTO_AccountPublicKeyP accountPubP;
struct TALER_Amount zero_amount;
bool zero_cost = false;
@@ -675,11 +675,11 @@ AH_handler_policy_post (struct MHD_Connection *connection,
if (0 == TALER_amount_cmp (&AH_annual_fee, &zero_amount))
zero_cost = true;
- puc = *con_cls;
if (NULL == puc)
{
/* first call, setup internals */
puc = GNUNET_new (struct PolicyUploadContext);
+ hc->ctx = puc;
puc->hc.cc = &cleanup_ctx;
puc->con = connection;
@@ -687,13 +687,7 @@ AH_handler_policy_post (struct MHD_Connection *connection,
"At %s:%d handler is policy_post\n", __FILE__, __LINE__);
/* extract publickey from url */
- GNUNET_assert (0 == strncmp (url,
- "/policy/",
- strlen ("/policy/")));
{
- const char *account;
-
- account = &url[strlen ("/policy/")];
if (GNUNET_OK !=
GNUNET_CRYPTO_eddsa_public_key_from_string (account,
strlen (account),
@@ -711,8 +705,6 @@ AH_handler_policy_post (struct MHD_Connection *connection,
TALER_B2S (&puc->account),
(unsigned long long) sizeof (struct
ANASTASIS_CRYPTO_AccountPublicKeyP));
- *con_cls = puc;
-
/* now setup 'puc' */
{
const char *lens;
diff --git a/src/backend/anastasis-httpd_salt.c
b/src/backend/anastasis-httpd_salt.c
index b2c76fb..4be8620 100644
--- a/src/backend/anastasis-httpd_salt.c
+++ b/src/backend/anastasis-httpd_salt.c
@@ -29,14 +29,11 @@
/**
* @param connection the MHD connection to handle
- * @param url handles a URL of the format "/salt"
- * @param con_cls
* @return MHD result code
*/
-int
-AH_handler_salt (struct MHD_Connection *connection,
- const char *url,
- void **con_cls)
+MHD_RESULT
+AH_handler_salt (struct TMH_RequestHandler *rh,
+ struct MHD_Connection *connection)
{
struct ANASTASIS_CRYPTO_PowSalt salt;
@@ -54,4 +51,4 @@ AH_handler_salt (struct MHD_Connection *connection,
"{s:o}",
"server_salt",
GNUNET_JSON_from_data_auto (&salt));
-}
\ No newline at end of file
+}
diff --git a/src/backend/anastasis-httpd_salt.h
b/src/backend/anastasis-httpd_salt.h
index 1ea3da4..6c46bd8 100644
--- a/src/backend/anastasis-httpd_salt.h
+++ b/src/backend/anastasis-httpd_salt.h
@@ -26,13 +26,10 @@
/**
* @param connection the MHD connection to handle
- * @param url handles a URL of the format "/salt"
- * @param con_cls
* @return MHD result code
*/
-int
-AH_handler_salt (struct MHD_Connection *connection,
- const char *url,
- void **con_cls);
+MHD_RESULT
+AH_handler_salt (struct TMH_RequestHandler *rh,
+ struct MHD_Connection *connection);
-#endif
\ No newline at end of file
+#endif
diff --git a/src/backend/anastasis-httpd_terms.c
b/src/backend/anastasis-httpd_terms.c
index c908975..7e79a94 100644
--- a/src/backend/anastasis-httpd_terms.c
+++ b/src/backend/anastasis-httpd_terms.c
@@ -29,18 +29,11 @@
*
* @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
- * @param mi merchant backend instance, never NULL
* @return MHD result code
*/
MHD_RESULT
AH_handler_terms (struct TMH_RequestHandler *rh,
- struct MHD_Connection *connection,
- void **connection_cls,
- const char *upload_data,
- size_t *upload_data_size)
+ struct MHD_Connection *connection)
{
// FIXME AGB
return TALER_MHD_reply_json_pack (connection,
@@ -55,4 +48,4 @@ AH_handler_terms (struct TMH_RequestHandler *rh,
}
-/* end of anastasis-httpd_terms.c */
\ No newline at end of file
+/* end of anastasis-httpd_terms.c */
diff --git a/src/backend/anastasis-httpd_terms.h
b/src/backend/anastasis-httpd_terms.h
index 8d918d9..b477ecf 100644
--- a/src/backend/anastasis-httpd_terms.h
+++ b/src/backend/anastasis-httpd_terms.h
@@ -30,18 +30,12 @@
*
* @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
*/
MHD_RESULT
AH_handler_terms (struct TMH_RequestHandler *rh,
- struct MHD_Connection *connection,
- void **connection_cls,
- const char *upload_data,
- size_t *upload_data_size);
+ struct MHD_Connection *connection);
#endif
-/* end of anastasis-httpd_terms.h */
\ No newline at end of file
+/* end of anastasis-httpd_terms.h */
diff --git a/src/backend/anastasis-httpd_truth.h
b/src/backend/anastasis-httpd_truth.h
index efa6b1b..c34c268 100644
--- a/src/backend/anastasis-httpd_truth.h
+++ b/src/backend/anastasis-httpd_truth.h
@@ -42,15 +42,15 @@ AH_handler_truth_get (struct MHD_Connection *connection,
/**
* @param connection the MHD connection to handle
* @param con_cls the connection's closure
- * @param url handles a URL of the format "/truth/$TRUTH_PUBLIC_KEY
+ * @param pub_key_str base32 encoded truth public key
* @param truth_data truth data
* @param truth_data_size number of bytes (left) in @a truth_data
* @return MHD result code
*/
int
AH_handler_truth_post (struct MHD_Connection *connection,
- void **con_cls,
- const char *url,
+ struct TM_HandlerContext *hc,
+ const char *pub_key_str,
const char *truth_data,
size_t *truth_data_size);
diff --git a/src/backend/anastasis-httpd_truth_upload.c
b/src/backend/anastasis-httpd_truth_upload.c
index 41f5366..cfc6793 100644
--- a/src/backend/anastasis-httpd_truth_upload.c
+++ b/src/backend/anastasis-httpd_truth_upload.c
@@ -57,18 +57,25 @@ verify_and_execute_truth (struct MHD_Connection *connection,
}
+static void
+cleanup_parse_post_json (struct TM_HandlerContext *hc)
+{
+ TALER_MHD_parse_post_cleanup_callback (hc->ctx);
+}
+
+
/**
* @param connection the MHD connection to handle
* @param con_cls the connection's closure
- * @param url handles a URL of the format "/truth/$TRUTH_PUBLIC_KEY
+ * @param pub_key_str base32 encoded truth public key
* @param truth_data truth data
* @param truth_data_size number of bytes (left) in @a truth_data
* @return MHD result code
*/
int
AH_handler_truth_post (struct MHD_Connection *connection,
- void **con_cls,
- const char *url,
+ struct TM_HandlerContext *hc,
+ const char *pub_key_str,
const char *truth_data,
size_t *truth_data_size)
{
@@ -79,21 +86,12 @@ AH_handler_truth_post (struct MHD_Connection *connection,
struct ANASTASIS_DB_Truth truth;
/* extract public key from url */
- GNUNET_assert (0 == strncmp (url,
- "/truth/",
- strlen ("/truth/")));
{
- const char *pub_key_str;
-
- pub_key_str = &url[strlen ("/truth/")];
- GNUNET_assert (NULL != pub_key_str);
-
GNUNET_STRINGS_string_to_data (pub_key_str,
strlen (pub_key_str),
&truth_public_key,
sizeof(struct
ANASTASIS_CRYPTO_TruthPublicKeyP));
-
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"public key from Url: %s\n",
pub_key_str);
@@ -108,12 +106,9 @@ AH_handler_truth_post (struct MHD_Connection *connection,
GNUNET_JSON_spec_end ()
};
- (void) con_cls;
- (void) truth_data;
- (void) truth_data_size;
-
+ hc->cc = &cleanup_parse_post_json;
res = TALER_MHD_parse_post_json (connection,
- con_cls,
+ &hc->ctx,
truth_data,
truth_data_size,
&json);
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-anastasis] branch master updated: fix handler context usage',
gnunet <=