aboutsummaryrefslogtreecommitdiff
path: root/src/bank
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2023-04-23 17:45:53 +0200
committerChristian Grothoff <christian@grothoff.org>2023-04-23 17:45:53 +0200
commit889595f986d922ffbcdcd746fdfad7f1a0e53595 (patch)
tree41571e0f04caa95c06610440d2b8c9c3698b08ed /src/bank
parent4b7d9f5e19e9f28ec1163f3b6e5c00f0805e6221 (diff)
make taler-merchant-wirewatch multi-instance capable
Diffstat (limited to 'src/bank')
-rw-r--r--src/bank/mb_parse.c98
1 files changed, 78 insertions, 20 deletions
diff --git a/src/bank/mb_parse.c b/src/bank/mb_parse.c
index eef303f3..bb668e48 100644
--- a/src/bank/mb_parse.c
+++ b/src/bank/mb_parse.c
@@ -21,6 +21,21 @@
*/
#include "platform.h"
#include "taler_merchant_bank_lib.h"
+#include <gnunet/gnunet_json_lib.h>
+
+
+/**
+ * Names of authentication methods available.
+ */
+static const struct
+{
+ const char *m;
+ enum TALER_MERCHANT_BANK_AuthenticationMethod e;
+} methods[] = {
+ { "NONE", TALER_MERCHANT_BANK_AUTH_NONE },
+ { "BASIC", TALER_MERCHANT_BANK_AUTH_BASIC },
+ { NULL, TALER_MERCHANT_BANK_AUTH_NONE }
+};
enum GNUNET_GenericReturnValue
@@ -29,15 +44,6 @@ TALER_MERCHANT_BANK_auth_parse_cfg (
const char *section,
struct TALER_MERCHANT_BANK_AuthenticationData *auth)
{
- const struct
- {
- const char *m;
- enum TALER_MERCHANT_BANK_AuthenticationMethod e;
- } methods[] = {
- { "NONE", TALER_MERCHANT_BANK_AUTH_NONE },
- { "BASIC", TALER_MERCHANT_BANK_AUTH_BASIC },
- { NULL, TALER_MERCHANT_BANK_AUTH_NONE }
- };
char *method;
if (GNUNET_OK !=
@@ -115,6 +121,67 @@ TALER_MERCHANT_BANK_auth_parse_cfg (
}
+enum GNUNET_GenericReturnValue
+TALER_MERCHANT_BANK_auth_parse_json (
+ const json_t *cred,
+ const char *backend_url,
+ struct TALER_MERCHANT_BANK_AuthenticationData *auth)
+{
+ const char *method;
+
+ auth->wire_gateway_url = GNUNET_strdup (backend_url);
+ method = json_string_value (json_object_get (cred,
+ "type"));
+ for (unsigned int i = 0; NULL != methods[i].m; i++)
+ {
+ if (0 == strcasecmp (method,
+ methods[i].m))
+ {
+ switch (methods[i].e)
+ {
+ case TALER_MERCHANT_BANK_AUTH_NONE:
+ auth->method = TALER_MERCHANT_BANK_AUTH_NONE;
+ return GNUNET_OK;
+ case TALER_MERCHANT_BANK_AUTH_BASIC:
+ {
+ const char *username;
+ const char *password;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_string ("username",
+ &username),
+ GNUNET_JSON_spec_string ("password",
+ &password),
+ GNUNET_JSON_spec_end ()
+ };
+ enum GNUNET_GenericReturnValue res;
+ const char *err;
+ unsigned int eline;
+
+ res = GNUNET_JSON_parse (cred,
+ spec,
+ &err,
+ &eline);
+ if (GNUNET_OK != res)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Credentials malformed: %s (%u)\n",
+ err,
+ eline);
+ GNUNET_free (auth->wire_gateway_url);
+ return GNUNET_SYSERR;
+ }
+ auth->details.basic.username = GNUNET_strdup (username);
+ auth->details.basic.password = GNUNET_strdup (password);
+ }
+ auth->method = TALER_MERCHANT_BANK_AUTH_BASIC;
+ return GNUNET_OK;
+ }
+ }
+ }
+ return GNUNET_SYSERR;
+}
+
+
void
TALER_MERCHANT_BANK_auth_free (
struct TALER_MERCHANT_BANK_AuthenticationData *auth)
@@ -124,20 +191,11 @@ TALER_MERCHANT_BANK_auth_free (
case TALER_MERCHANT_BANK_AUTH_NONE:
break;
case TALER_MERCHANT_BANK_AUTH_BASIC:
- if (NULL != auth->details.basic.username)
- {
- GNUNET_free (auth->details.basic.username);
- auth->details.basic.username = NULL;
- }
- if (NULL != auth->details.basic.password)
- {
- GNUNET_free (auth->details.basic.password);
- auth->details.basic.password = NULL;
- }
+ GNUNET_free (auth->details.basic.username);
+ GNUNET_free (auth->details.basic.password);
break;
}
GNUNET_free (auth->wire_gateway_url);
- auth->wire_gateway_url = NULL;
}