[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] 02/02: Initial work on client code
From: |
gnunet |
Subject: |
[taler-anastasis] 02/02: Initial work on client code |
Date: |
Sat, 16 Nov 2019 12:12:34 +0100 |
This is an automated email from the git hooks/post-receive script.
dennis-neufeld pushed a commit to branch master
in repository anastasis.
commit 5a766965eabb93dcd0f03a86822c45bf4e1e14df
Author: Dennis Neufeld <address@hidden>
AuthorDate: Sat Nov 16 11:09:51 2019 +0000
Initial work on client code
---
src/backend/anastasis-httpd.c | 28 +++++++-------
src/backend/anastasis-httpd_policy.h | 12 +++---
src/include/anastasis_service.h | 19 ++++++++++
src/lib/anastasis_api_policy.c | 73 ++++++++++++++++++++++++++++++++----
4 files changed, 105 insertions(+), 27 deletions(-)
diff --git a/src/backend/anastasis-httpd.c b/src/backend/anastasis-httpd.c
index 680e9c7..2bb8f31 100644
--- a/src/backend/anastasis-httpd.c
+++ b/src/backend/anastasis-httpd.c
@@ -205,32 +205,32 @@ url_handler (void *cls,
if (0 == strcmp (method, MHD_HTTP_METHOD_GET))
{
return AH_handler_policy_GET (connection,
- url,
- con_cls);
+ url,
+ con_cls);
}
if (0 == strcmp (method, MHD_HTTP_METHOD_POST))
{
return AH_handler_policy_POST (connection,
- con_cls,
- url,
- upload_data,
- upload_data_size);
+ con_cls,
+ url,
+ upload_data,
+ upload_data_size);
}
}
- if (0 == strncmp (url,
+ if (0 == strncmp (url,
"/truth/",
strlen ("/truth/")))
+ {
+ // return handle_truth (...);
+ if (0 == strcmp (method, MHD_HTTP_METHOD_GET))
{
- // return handle_truth (...);
- if (0 == strcmp (method, MHD_HTTP_METHOD_GET))
- {
- }
- if (0 == strcmp (method, MHD_HTTP_METHOD_POST))
- {
+ }
+ if (0 == strcmp (method, MHD_HTTP_METHOD_POST))
+ {
- }
}
+ }
for (unsigned int i = 0; NULL != handlers[i].url; i++)
{
struct TMH_RequestHandler *rh = &handlers[i];
diff --git a/src/backend/anastasis-httpd_policy.h
b/src/backend/anastasis-httpd_policy.h
index 07619fa..e947b2e 100644
--- a/src/backend/anastasis-httpd_policy.h
+++ b/src/backend/anastasis-httpd_policy.h
@@ -33,8 +33,8 @@
*/
int
AH_handler_policy_GET (struct MHD_Connection *connection,
- const char *url,
- void **con_cls);
+ const char *url,
+ void **con_cls);
/**
* @param connection the MHD connection to handle
@@ -45,10 +45,10 @@ AH_handler_policy_GET (struct MHD_Connection *connection,
*/
int
AH_handler_policy_POST (struct MHD_Connection *connection,
- void **con_cls,
- const char *url,
- const char *upload_data,
- size_t *upload_data_size);
+ void **con_cls,
+ const char *url,
+ const char *upload_data,
+ size_t *upload_data_size);
#endif
\ No newline at end of file
diff --git a/src/include/anastasis_service.h b/src/include/anastasis_service.h
index 6efa6a7..83cabad 100644
--- a/src/include/anastasis_service.h
+++ b/src/include/anastasis_service.h
@@ -112,6 +112,25 @@ ANASTASIS_policy_lookup (struct GNUNET_CURL_Context *ctx,
ANASTASIS_PolicyLookupCallback cb,
void *cb_cls);
+/**
+ * Does a GET /policy for a specific version.
+ *
+ * @param ctx execution context
+ * @param backend_url base URL of the merchant backend
+ * @param anastasis_pub public key of the user's account
+ * @param cb callback which will work the response gotten from the backend
+ * @param cb_cls closure to pass to the callback
+ * @param version version of the policy to be requested
+ * @return handle for this operation, NULL upon errors
+ */
+struct ANASTASIS_PolicyLookupOperation *
+ANASTASIS_policy_lookup_version (struct GNUNET_CURL_Context *ctx,
+ const char *backend_url,
+ const struct ANASTASIS_AccountPubP
*anastasis_pub,
+ ANASTASIS_PolicyLookupCallback cb,
+ void *cb_cls,
+ uint32_t *version);
+
/**
* Cancel a GET /policy request.
*
diff --git a/src/lib/anastasis_api_policy.c b/src/lib/anastasis_api_policy.c
index 9572aa9..7b8359d 100644
--- a/src/lib/anastasis_api_policy.c
+++ b/src/lib/anastasis_api_policy.c
@@ -74,7 +74,7 @@ struct ANASTASIS_PolicyLookupOperation
* @param handle from the operation to cancel
*/
void
-ANASTASIS_policy_lookup_cancel (struct
+ANASTASIS_policy_lookup_cancel (struct
ANASTASIS_PolicyLookupOperation *plo)
{
if (NULL != plo->job)
@@ -156,9 +156,9 @@ handle_policy_lookup_finished (void *cls,
*/
char *
ANASTASIS_url_join (const char *base_url,
- const char *path,
- const struct ANASTASIS_AccountPubP *anastasis_pub,
- ...)
+ const char *path,
+ const struct ANASTASIS_AccountPubP *anastasis_pub,
+ ...)
{
unsigned int iparam = 0;
va_list args;
@@ -197,7 +197,8 @@ ANASTASIS_url_join (const char *base_url,
GNUNET_break (0);
// Convert account pub to base32 encoded string
- const char *acc_pub_str = GNUNET_CRYPTO_eddsa_public_key_to_string
(&anastasis_pub->pub);
+ const char *acc_pub_str = GNUNET_CRYPTO_eddsa_public_key_to_string (
+ &anastasis_pub->pub);
/* 1st pass: compute length */
len += strlen (base_url) + strlen (path) + strlen (acc_pub_str);
@@ -271,11 +272,69 @@ ANASTASIS_policy_lookup (struct GNUNET_CURL_Context *ctx,
plo->cb = cb;
plo->cb_cls = cb_cls;
- //plo->url = TALER_url_join (backend_url, "policy", "order_id", order_id,
NULL);
+ // plo->url = TALER_url_join (backend_url, "policy", "order_id", order_id,
NULL);
plo->url = TALER_url_join (backend_url,
"policy",
anastasis_pub);
-
+
+ eh = curl_easy_init ();
+ if (CURLE_OK != curl_easy_setopt (eh,
+ CURLOPT_URL,
+ plo->url))
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
+
+ if (NULL == (plo->job = GNUNET_CURL_job_add (ctx,
+ eh,
+ GNUNET_NO,
+ handle_policy_lookup_finished,
+ plo)))
+ {
+ GNUNET_break (0);
+ return NULL;
+
+ }
+
+ return plo;
+}
+
+
+/**
+ * Does a GET /policy for a specific version.
+ *
+ * @param ctx execution context
+ * @param backend_url base URL of the merchant backend
+ * @param anastasis_pub public key of the user's account
+ * @param cb callback which will work the response gotten from the backend
+ * @param cb_cls closure to pass to the callback
+ * @param version version of the policy to be requested
+ * @return handle for this operation, NULL upon errors
+ */
+struct ANASTASIS_PolicyLookupOperation *
+ANASTASIS_policy_lookup_version (struct GNUNET_CURL_Context *ctx,
+ const char *backend_url,
+ const struct ANASTASIS_AccountPubP *anastasis_pub,
+ ANASTASIS_PolicyLookupCallback cb,
+ void *cb_cls,
+ uint32_t *version)
+{
+ struct ANASTASIS_PolicyLookupOperation *plo;
+ CURL *eh;
+
+ plo = GNUNET_new (struct ANASTASIS_PolicyLookupOperation);
+ plo->ctx = ctx;
+ plo->cb = cb;
+ plo->cb_cls = cb_cls;
+
+ // plo->url = TALER_url_join (backend_url, "policy", "order_id", order_id,
NULL);
+ plo->url = TALER_url_join (backend_url,
+ "policy",
+ anastasis_pub,
+ "version",
+ version);
+
eh = curl_easy_init ();
if (CURLE_OK != curl_easy_setopt (eh,
CURLOPT_URL,
--
To stop receiving notification emails like this one, please contact
address@hidden.