aboutsummaryrefslogtreecommitdiff
path: root/src/backend/taler-merchant-httpd_private-post-instances.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2023-04-23 22:57:55 +0200
committerChristian Grothoff <christian@grothoff.org>2023-04-23 22:57:55 +0200
commit154f964aab5df00cbadaa015474c2b323161aa96 (patch)
tree084f300e664fb96d0693baf73434ed245ef56641 /src/backend/taler-merchant-httpd_private-post-instances.c
parent889595f986d922ffbcdcd746fdfad7f1a0e53595 (diff)
API change for #6363
Diffstat (limited to 'src/backend/taler-merchant-httpd_private-post-instances.c')
-rw-r--r--src/backend/taler-merchant-httpd_private-post-instances.c169
1 files changed, 84 insertions, 85 deletions
diff --git a/src/backend/taler-merchant-httpd_private-post-instances.c b/src/backend/taler-merchant-httpd_private-post-instances.c
index 4d9320ba..c8f443cd 100644
--- a/src/backend/taler-merchant-httpd_private-post-instances.c
+++ b/src/backend/taler-merchant-httpd_private-post-instances.c
@@ -25,6 +25,8 @@
#include "platform.h"
#include "taler-merchant-httpd_private-post-instances.h"
#include "taler-merchant-httpd_helper.h"
+#include "taler_merchant_bank_lib.h"
+#include <taler/taler_dbevents.h>
#include <taler/taler_json_lib.h>
#include <regex.h>
@@ -39,51 +41,45 @@
* URIs as those already in @a mi (possibly in a different order).
*
* @param mi a merchant instance with accounts
- * @param payto_uris a JSON array with accounts (presumably)
+ * @param accounts a JSON array with accounts (presumably)
* @return true if they are 'equal', false if not or of payto_uris is not an array
*/
static bool
accounts_equal (const struct TMH_MerchantInstance *mi,
- json_t *payto_uris)
+ const json_t *accounts)
{
- if (! json_is_array (payto_uris))
+ if (! json_is_array (accounts))
return false;
{
- unsigned int len = json_array_size (payto_uris);
- bool matches[GNUNET_NZL (len)];
- struct TMH_WireMethod *wm;
+ unsigned int len = json_array_size (accounts);
+ enum GNUNET_GenericReturnValue matches[GNUNET_NZL (len)];
- memset (matches,
- 0,
- sizeof (matches));
- for (wm = mi->wm_head;
+ for (unsigned int i = 0; i<len; i++)
+ matches[i] = GNUNET_SYSERR;
+ for (struct TMH_WireMethod *wm = mi->wm_head;
NULL != wm;
wm = wm->next)
{
- const char *uri = wm->payto_uri;
-
- GNUNET_assert (NULL != uri);
for (unsigned int i = 0; i<len; i++)
{
- const char *str = json_string_value (json_array_get (payto_uris,
- i));
+ json_t *account = json_array_get (accounts,
+ i);
+ enum GNUNET_GenericReturnValue ret;
- GNUNET_assert (NULL != str);
- if (0 == strcasecmp (uri,
- str))
+ ret = TMH_cmp_wire_account (account,
+ wm);
+ if (GNUNET_SYSERR == ret)
+ continue;
+ if (GNUNET_SYSERR != matches[i])
{
- if (matches[i])
- {
- GNUNET_break (0);
- return false; /* duplicate entry!? */
- }
- matches[i] = true;
- break;
+ GNUNET_break (0);
+ return false; /* duplicate entry!? */
}
+ matches[i] = ret;
}
}
for (unsigned int i = 0; i<len; i++)
- if (! matches[i])
+ if (GNUNET_YES != matches[i])
return false;
}
return true;
@@ -91,48 +87,6 @@ accounts_equal (const struct TMH_MerchantInstance *mi,
/**
- * Free memory used by @a wm
- *
- * @param wm wire method to free
- */
-static void
-free_wm (struct TMH_WireMethod *wm)
-{
- GNUNET_free (wm->payto_uri);
- GNUNET_free (wm->wire_method);
- GNUNET_free (wm);
-}
-
-
-/**
- * Free memory used by @a mi.
- *
- * @param mi instance to free
- */
-static void
-free_mi (struct TMH_MerchantInstance *mi)
-{
- struct TMH_WireMethod *wm;
-
- while (NULL != (wm = mi->wm_head))
- {
- GNUNET_CONTAINER_DLL_remove (mi->wm_head,
- mi->wm_tail,
- wm);
- free_wm (wm);
- }
- GNUNET_free (mi->settings.id);
- GNUNET_free (mi->settings.name);
- GNUNET_free (mi->settings.website);
- GNUNET_free (mi->settings.email);
- GNUNET_free (mi->settings.logo);
- json_decref (mi->settings.address);
- json_decref (mi->settings.jurisdiction);
- GNUNET_free (mi);
-}
-
-
-/**
* Generate an instance, given its configuration.
*
* @param rh context of the handler
@@ -147,15 +101,15 @@ TMH_private_post_instances (const struct TMH_RequestHandler *rh,
{
struct TALER_MERCHANTDB_InstanceSettings is;
struct TALER_MERCHANTDB_InstanceAuthSettings ias;
- json_t *payto_uris;
+ json_t *accounts;
const char *auth_token = NULL;
const char *uts = "business";
struct TMH_WireMethod *wm_head = NULL;
struct TMH_WireMethod *wm_tail = NULL;
json_t *jauth;
struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_json ("payto_uris",
- &payto_uris),
+ GNUNET_JSON_spec_json ("accounts",
+ &accounts),
GNUNET_JSON_spec_string ("id",
(const char **) &is.id),
GNUNET_JSON_spec_string ("name",
@@ -208,7 +162,6 @@ TMH_private_post_instances (const struct TMH_RequestHandler *rh,
? MHD_YES
: MHD_NO;
}
-
if (NULL == uts)
uts = "business";
if (GNUNET_OK !=
@@ -233,8 +186,8 @@ TMH_private_post_instances (const struct TMH_RequestHandler *rh,
return (GNUNET_NO == ret) ? MHD_YES : MHD_NO;
}
- /* check payto_uris for well-formedness */
- if (! TMH_payto_uri_array_valid (payto_uris))
+ /* check accounts for well-formedness */
+ if (! TMH_accounts_array_valid (accounts))
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_BAD_REQUEST,
TALER_EC_GENERIC_PAYTO_URI_MALFORMED,
@@ -341,12 +294,14 @@ TMH_private_post_instances (const struct TMH_RequestHandler *rh,
is.address)) &&
(1 == json_equal (mi->settings.jurisdiction,
is.jurisdiction)) &&
- (GNUNET_OK == TALER_amount_cmp_currency (
+ (GNUNET_OK ==
+ TALER_amount_cmp_currency (
&mi->settings.default_max_deposit_fee,
&is.default_max_deposit_fee)) &&
(0 == TALER_amount_cmp (&mi->settings.default_max_deposit_fee,
&is.default_max_deposit_fee)) &&
- (GNUNET_OK == TALER_amount_cmp_currency (
+ (GNUNET_OK ==
+ TALER_amount_cmp_currency (
&mi->settings.default_max_wire_fee,
&is.default_max_wire_fee)) &&
(0 == TALER_amount_cmp (&mi->settings.default_max_wire_fee,
@@ -360,7 +315,7 @@ TMH_private_post_instances (const struct TMH_RequestHandler *rh,
==,
is.default_pay_delay)) &&
(accounts_equal (mi,
- payto_uris)) )
+ accounts)) )
{
GNUNET_JSON_parse_free (spec);
return TALER_MHD_reply_static (connection,
@@ -382,18 +337,46 @@ TMH_private_post_instances (const struct TMH_RequestHandler *rh,
/* convert provided payto URIs into internal data structure with salts */
{
- unsigned int len = json_array_size (payto_uris);
+ unsigned int len = json_array_size (accounts);
for (unsigned int i = 0; i<len; i++)
{
- json_t *payto_uri = json_array_get (payto_uris,
- i);
+ json_t *account = json_array_get (accounts,
+ i);
+ const char *credit_facade_url = NULL;
+ json_t *credit_facade_credentials = NULL;
+ const char *uri;
struct TMH_WireMethod *wm;
-
- wm = TMH_setup_wire_account (json_string_value (payto_uri));
+ struct GNUNET_JSON_Specification ispec[] = {
+ GNUNET_JSON_spec_string ("payto_uri",
+ &uri),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_string ("credit_facade_url",
+ &credit_facade_url),
+ NULL),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_json ("credit_facade_credentials",
+ &credit_facade_credentials),
+ NULL),
+ GNUNET_JSON_spec_end ()
+ };
+ enum GNUNET_GenericReturnValue res;
+
+ res = TALER_MHD_parse_json_data (connection,
+ account,
+ ispec);
+ if (GNUNET_OK != res)
+ return (GNUNET_NO == res)
+ ? MHD_YES
+ : MHD_NO;
+ wm = TMH_setup_wire_account (uri,
+ credit_facade_url,
+ credit_facade_credentials);
+ GNUNET_assert (NULL != wm);
GNUNET_CONTAINER_DLL_insert (wm_head,
wm_tail,
wm);
+ GNUNET_JSON_parse_free (ispec);
}
}
@@ -446,7 +429,8 @@ TMH_private_post_instances (const struct TMH_RequestHandler *rh,
"post /instances"))
{
GNUNET_JSON_parse_free (spec);
- free_mi (mi);
+ mi->rc = 1;
+ TMH_instance_decref (mi);
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_GENERIC_DB_START_FAILED,
@@ -469,7 +453,8 @@ TMH_private_post_instances (const struct TMH_RequestHandler *rh,
TALER_EC_MERCHANT_PRIVATE_POST_INSTANCES_ALREADY_EXISTS,
is.id);
GNUNET_JSON_parse_free (spec);
- free_mi (mi);
+ mi->rc = 1;
+ TMH_instance_decref (mi);
return ret;
}
for (struct TMH_WireMethod *wm = wm_head;
@@ -480,6 +465,8 @@ TMH_private_post_instances (const struct TMH_RequestHandler *rh,
.payto_uri = wm->payto_uri,
.salt = wm->wire_salt,
.h_wire = wm->h_wire,
+ .credit_facade_url = wm->credit_facade_url,
+ .credit_facade_credentials = wm->credit_facade_credentials,
.active = wm->active
};
@@ -497,6 +484,17 @@ TMH_private_post_instances (const struct TMH_RequestHandler *rh,
break;
goto retry;
}
+ {
+ struct GNUNET_DB_EventHeaderP es = {
+ .size = htons (sizeof (es)),
+ .type = htons (TALER_DBEVENT_MERCHANT_ACCOUNTS_CHANGED)
+ };
+
+ TMH_db->event_notify (TMH_db->cls,
+ &es,
+ NULL,
+ 0);
+ }
qs = TMH_db->commit (TMH_db->cls);
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
@@ -507,7 +505,8 @@ retry:
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
{
GNUNET_JSON_parse_free (spec);
- free_mi (mi);
+ mi->rc = 1;
+ TMH_instance_decref (mi);
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_GENERIC_DB_COMMIT_FAILED,