summaryrefslogtreecommitdiff
path: root/src/restclient
diff options
context:
space:
mode:
Diffstat (limited to 'src/restclient')
-rw-r--r--src/restclient/anastasis_api_config.c52
-rw-r--r--src/restclient/anastasis_api_policy_lookup.c23
-rw-r--r--src/restclient/anastasis_api_policy_meta_lookup.c22
3 files changed, 54 insertions, 43 deletions
diff --git a/src/restclient/anastasis_api_config.c b/src/restclient/anastasis_api_config.c
index 215d224..f82cd9e 100644
--- a/src/restclient/anastasis_api_config.c
+++ b/src/restclient/anastasis_api_config.c
@@ -86,6 +86,10 @@ handle_config_finished (void *cls,
{
struct ANASTASIS_ConfigOperation *co = cls;
const json_t *json = response;
+ struct ANASTASIS_Config acfg = {
+ .http_status = response_code,
+ .response = json
+ };
co->job = NULL;
switch (response_code)
@@ -99,27 +103,26 @@ handle_config_finished (void *cls,
case MHD_HTTP_OK:
{
const char *name;
- struct ANASTASIS_Config acfg;
const json_t *methods;
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_string ("name",
&name),
GNUNET_JSON_spec_string ("business_name",
- &acfg.business_name),
+ &acfg.details.ok.business_name),
GNUNET_JSON_spec_string ("version",
- &acfg.version),
+ &acfg.details.ok.version),
GNUNET_JSON_spec_array_const ("methods",
&methods),
GNUNET_JSON_spec_uint32 ("storage_limit_in_megabytes",
- &acfg.storage_limit_in_megabytes),
+ &acfg.details.ok.storage_limit_in_megabytes),
TALER_JSON_spec_amount_any ("annual_fee",
- &acfg.annual_fee),
+ &acfg.details.ok.annual_fee),
TALER_JSON_spec_amount_any ("truth_upload_fee",
- &acfg.truth_upload_fee),
+ &acfg.details.ok.truth_upload_fee),
TALER_JSON_spec_amount_any ("liability_limit",
- &acfg.liability_limit),
+ &acfg.details.ok.liability_limit),
GNUNET_JSON_spec_fixed_auto ("provider_salt",
- &acfg.provider_salt),
+ &acfg.details.ok.provider_salt),
GNUNET_JSON_spec_end ()
};
@@ -132,14 +135,16 @@ handle_config_finished (void *cls,
json_dumpf (json,
stderr,
JSON_INDENT (2));
- response_code = 0;
+ acfg.http_status = 0;
+ acfg.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
break;
}
if (0 != strcmp (name,
"anastasis"))
{
GNUNET_JSON_parse_free (spec);
- response_code = 0;
+ acfg.http_status = 0;
+ acfg.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
break;
}
{
@@ -148,7 +153,7 @@ handle_config_finished (void *cls,
unsigned int current;
char dummy;
- if (3 != sscanf (acfg.version,
+ if (3 != sscanf (acfg.details.ok.version,
"%u:%u:%u%c",
&current,
&revision,
@@ -156,7 +161,8 @@ handle_config_finished (void *cls,
&dummy))
{
GNUNET_break_op (0);
- response_code = 0;
+ acfg.http_status = 0;
+ acfg.ec = TALER_EC_GENERIC_VERSION_MALFORMED;
break;
}
if ( (ANASTASIS_PROTOCOL_CURRENT < current) &&
@@ -164,7 +170,8 @@ handle_config_finished (void *cls,
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Provider protocol version too new\n");
- response_code = 0;
+ acfg.http_status = 0;
+ acfg.ec = TALER_EC_GENERIC_VERSION_MALFORMED;
break;
}
if ( (ANASTASIS_PROTOCOL_CURRENT > current) &&
@@ -173,16 +180,18 @@ handle_config_finished (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Provider protocol version too old\n");
GNUNET_break_op (0);
- response_code = 0;
+ acfg.http_status = 0;
+ acfg.ec = TALER_EC_GENERIC_VERSION_MALFORMED;
break;
}
}
- acfg.methods_length = json_array_size (methods);
+ acfg.details.ok.methods_length = json_array_size (methods);
{
struct ANASTASIS_AuthorizationMethodConfig mcfg[GNUNET_NZL (
- acfg.methods_length)];
+ acfg.details.ok.
+ methods_length)];
- for (unsigned int i = 0; i<acfg.methods_length; i++)
+ for (unsigned int i = 0; i<acfg.details.ok.methods_length; i++)
{
struct ANASTASIS_AuthorizationMethodConfig *m = &mcfg[i];
struct GNUNET_JSON_Specification spec[] = {
@@ -200,16 +209,16 @@ handle_config_finished (void *cls,
NULL, NULL)) )
{
GNUNET_break_op (0);
- response_code = 0;
+ acfg.http_status = 0;
+ acfg.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
goto end;
}
}
- acfg.methods = mcfg;
+ acfg.details.ok.methods = mcfg;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Good backend found at `%s'\n",
co->url);
co->cb (co->cb_cls,
- MHD_HTTP_OK,
&acfg);
ANASTASIS_config_cancel (co);
return;
@@ -236,8 +245,7 @@ handle_config_finished (void *cls,
}
end:
co->cb (co->cb_cls,
- response_code,
- NULL);
+ &acfg);
ANASTASIS_config_cancel (co);
}
diff --git a/src/restclient/anastasis_api_policy_lookup.c b/src/restclient/anastasis_api_policy_lookup.c
index 42db90d..b3132ef 100644
--- a/src/restclient/anastasis_api_policy_lookup.c
+++ b/src/restclient/anastasis_api_policy_lookup.c
@@ -106,6 +106,9 @@ handle_policy_lookup_finished (void *cls,
size_t data_size)
{
struct ANASTASIS_PolicyLookupOperation *plo = cls;
+ struct ANASTASIS_DownloadDetails dd = {
+ .http_status = response_code
+ };
plo->job = NULL;
switch (response_code)
@@ -117,7 +120,6 @@ handle_policy_lookup_finished (void *cls,
break;
case MHD_HTTP_OK:
{
- struct ANASTASIS_DownloadDetails dd;
struct ANASTASIS_UploadSignaturePS usp = {
.purpose.purpose = htonl (TALER_SIGNATURE_ANASTASIS_POLICY_UPLOAD),
.purpose.size = htonl (sizeof (usp)),
@@ -133,18 +135,17 @@ handle_policy_lookup_finished (void *cls,
&plo->account_pub.pub))
{
GNUNET_break_op (0);
- response_code = 0;
+ dd.http_status = 0;
+ dd.ec = -1; // FIXME: needs new code in Gana!
break;
}
/* Success, call callback with all details! */
- memset (&dd, 0, sizeof (dd));
- dd.sig = plo->account_sig;
- dd.curr_policy_hash = usp.new_recovery_data_hash;
- dd.policy = data;
- dd.policy_size = data_size;
- dd.version = plo->version;
+ dd.details.ok.sig = plo->account_sig;
+ dd.details.ok.curr_policy_hash = usp.new_recovery_data_hash;
+ dd.details.ok.policy = data;
+ dd.details.ok.policy_size = data_size;
+ dd.details.ok.version = plo->version;
plo->cb (plo->cb_cls,
- response_code,
&dd);
plo->cb = NULL;
ANASTASIS_policy_lookup_cancel (plo);
@@ -167,12 +168,10 @@ handle_policy_lookup_finished (void *cls,
"Unexpected response code %u\n",
(unsigned int) response_code);
GNUNET_break (0);
- response_code = 0;
break;
}
plo->cb (plo->cb_cls,
- response_code,
- NULL);
+ &dd);
plo->cb = NULL;
ANASTASIS_policy_lookup_cancel (plo);
}
diff --git a/src/restclient/anastasis_api_policy_meta_lookup.c b/src/restclient/anastasis_api_policy_meta_lookup.c
index 3d1482f..cf381fd 100644
--- a/src/restclient/anastasis_api_policy_meta_lookup.c
+++ b/src/restclient/anastasis_api_policy_meta_lookup.c
@@ -90,6 +90,10 @@ handle_policy_meta_lookup_finished (void *cls,
{
struct ANASTASIS_PolicyMetaLookupOperation *plo = cls;
const json_t *json = response;
+ struct ANASTASIS_MetaDownloadDetails mdd = {
+ .http_status = response_code,
+ .response = json
+ };
plo->job = NULL;
switch (response_code)
@@ -116,10 +120,6 @@ handle_policy_meta_lookup_finished (void *cls,
{
struct ANASTASIS_MetaDataEntry metas[GNUNET_NZL (mlen)];
void *md[GNUNET_NZL (mlen)];
- struct ANASTASIS_MetaDownloadDetails mdd = {
- .metas = metas,
- .metas_length = mlen
- };
size_t off = 0;
const char *label;
const json_t *val;
@@ -127,6 +127,8 @@ handle_policy_meta_lookup_finished (void *cls,
memset (md,
0,
sizeof (md));
+ mdd.details.ok.metas = metas;
+ mdd.details.ok.metas_length = mlen;
json_object_foreach ((json_t *) json,
label,
val)
@@ -148,6 +150,8 @@ handle_policy_meta_lookup_finished (void *cls,
&dummy))
{
GNUNET_break (0);
+ mdd.http_status = 0;
+ mdd.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
break;
}
if (GNUNET_OK !=
@@ -156,6 +160,8 @@ handle_policy_meta_lookup_finished (void *cls,
NULL, NULL))
{
GNUNET_break_op (0);
+ mdd.http_status = 0;
+ mdd.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
break;
}
metas[off].version = (uint32_t) ver;
@@ -165,13 +171,13 @@ handle_policy_meta_lookup_finished (void *cls,
if (off < mlen)
{
GNUNET_break (0);
- response_code = 0;
+ mdd.http_status = 0;
+ mdd.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
for (size_t i = 0; i<off; i++)
GNUNET_free (md[i]);
break;
}
plo->cb (plo->cb_cls,
- response_code,
&mdd);
for (size_t i = 0; i<off; i++)
GNUNET_free (md[i]);
@@ -197,15 +203,13 @@ handle_policy_meta_lookup_finished (void *cls,
"Unexpected response code %u\n",
(unsigned int) response_code);
GNUNET_break (0);
- response_code = 0;
break;
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"HTTP status for policy meta lookup is %u\n",
(unsigned int) response_code);
plo->cb (plo->cb_cls,
- response_code,
- NULL);
+ &mdd);
plo->cb = NULL;
ANASTASIS_policy_meta_lookup_cancel (plo);
}