diff options
Diffstat (limited to 'src/backend/taler-merchant-httpd_private-patch-instances-ID.c')
-rw-r--r-- | src/backend/taler-merchant-httpd_private-patch-instances-ID.c | 274 |
1 files changed, 0 insertions, 274 deletions
diff --git a/src/backend/taler-merchant-httpd_private-patch-instances-ID.c b/src/backend/taler-merchant-httpd_private-patch-instances-ID.c index bc6e3aae..027d5869 100644 --- a/src/backend/taler-merchant-httpd_private-patch-instances-ID.c +++ b/src/backend/taler-merchant-httpd_private-patch-instances-ID.c @@ -63,14 +63,11 @@ patch_instances_ID (struct TMH_MerchantInstance *mi, struct TMH_HandlerContext *hc) { struct TALER_MERCHANTDB_InstanceSettings is; - const json_t *accounts; const char *name; const char *uts = "business"; struct TMH_WireMethod *wm_head = NULL; struct TMH_WireMethod *wm_tail = NULL; struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_array_const ("accounts", - &accounts), GNUNET_JSON_spec_string ("name", &name), GNUNET_JSON_spec_mark_optional ( @@ -102,7 +99,6 @@ patch_instances_ID (struct TMH_MerchantInstance *mi, GNUNET_JSON_spec_end () }; enum GNUNET_DB_QueryStatus qs; - bool committed = false; GNUNET_assert (NULL != mi); memset (&is, @@ -162,14 +158,6 @@ patch_instances_ID (struct TMH_MerchantInstance *mi, "jurisdiction"); } - if (! TMH_accounts_array_valid (accounts)) - { - GNUNET_JSON_parse_free (spec); - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_BAD_REQUEST, - TALER_EC_GENERIC_PAYTO_URI_MALFORMED, - NULL); - } for (unsigned int retry = 0; retry<MAX_RETRIES; retry++) { /* Cleanup after earlier loops */ @@ -236,258 +224,13 @@ patch_instances_ID (struct TMH_MerchantInstance *mi, goto giveup; } } - - /* Check for changes in accounts */ - { - unsigned int len = json_array_size (accounts); - struct TMH_WireMethod *matches[GNUNET_NZL (len)]; - bool updated[GNUNET_NZL (len)]; - - memset (matches, - 0, - sizeof (matches)); - memset (updated, - 0, - sizeof (updated)); - for (struct TMH_WireMethod *wm = mi->wm_head; - NULL != wm; - wm = wm->next) - { - bool matched = false; - for (unsigned int i = 0; i<len; i++) - { - json_t *account = json_array_get (accounts, - i); - enum GNUNET_GenericReturnValue ret; - - ret = TMH_cmp_wire_account (account, - wm); - switch (ret) - { - case GNUNET_SYSERR: - continue; - case GNUNET_NO: - matched = true; - /* our own existing payto URIs should be unique, that is no - duplicates in the list, so we cannot match twice */ - GNUNET_assert (NULL == matches[i]); - matches[i] = wm; - updated[i] = true; - break; - case GNUNET_YES: - matched = true; - /* our own existing payto URIs should be unique, that is no - duplicates in the list, so we cannot match twice */ - GNUNET_assert (NULL == matches[i]); - matches[i] = wm; - break; - } - } - - /* delete unmatched (= removed) accounts */ - if ( (! matched) && - (wm->active) ) - { - /* Account was REMOVED */ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Existing account `%s' not found, deactivating it.\n", - wm->payto_uri); - wm->deleting = true; - qs = TMH_db->inactivate_account (TMH_db->cls, - mi->settings.id, - &wm->h_wire); - if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) - { - TMH_db->rollback (TMH_db->cls); - if (GNUNET_DB_STATUS_SOFT_ERROR == qs) - goto retry; - else - goto giveup; - } - } - } /* for (wm) */ - - /* handle updates */ - for (unsigned int i = 0; i<len; i++) - { - struct TMH_WireMethod *wm = matches[i]; - - if (! updated[i]) - continue; - GNUNET_assert (NULL != wm); - { - struct TALER_MERCHANTDB_AccountDetails ad = { - .payto_uri = wm->payto_uri, - .h_wire = wm->h_wire, - .salt = wm->wire_salt, - .credit_facade_url = wm->credit_facade_url, - .credit_facade_credentials = wm->credit_facade_credentials, - .active = true - }; - - qs = TMH_db->update_account (TMH_db->cls, - mi->settings.id, - &ad); - if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) - { - TMH_db->rollback (TMH_db->cls); - if (GNUNET_DB_STATUS_SOFT_ERROR == qs) - goto retry; - else - goto giveup; - } - } /* ad scope */ - } /* for possible updates */ - - /* Find _new_ accounts or accounts to only enable */ - for (unsigned int i = 0; i<len; i++) - { - json_t *account = json_array_get (accounts, - i); - struct TMH_WireMethod *wm = matches[i]; - - if (NULL != wm) - { - if (updated[i]) - continue; /* handled above */ - if (! wm->active) - { - qs = TMH_db->activate_account (TMH_db->cls, - mi->settings.id, - &wm->h_wire); - if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) - { - TMH_db->rollback (TMH_db->cls); - if (GNUNET_DB_STATUS_SOFT_ERROR == qs) - goto retry; - else - goto giveup; - } - } - wm->enabling = true; - continue; - } - - { - const char *credit_facade_url = NULL; - const json_t *credit_facade_credentials = NULL; - const char *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_object_const ("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; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Adding NEW account `%s'\n", - uri); - wm = TMH_setup_wire_account (uri, - credit_facade_url, - credit_facade_credentials); - GNUNET_assert (NULL != wm); /* checked payto_uri validity earlier */ - GNUNET_CONTAINER_DLL_insert (wm_head, - wm_tail, - wm); - } /* ispec scope */ - - { - struct TALER_MERCHANTDB_AccountDetails ad = { - .payto_uri = wm->payto_uri, - .h_wire = wm->h_wire, - .salt = wm->wire_salt, - .credit_facade_url = wm->credit_facade_url, - .credit_facade_credentials = wm->credit_facade_credentials, - .active = true - }; - - qs = TMH_db->insert_account (TMH_db->cls, - mi->settings.id, - &ad); - if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) - { - TMH_db->rollback (TMH_db->cls); - if (GNUNET_DB_STATUS_SOFT_ERROR == qs) - goto retry; - else - goto giveup; - } - } /* ad variable scope */ - } /* for (i) to find new accounts */ - } /* scope for checking for account changes */ - - { - 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); retry: if (GNUNET_DB_STATUS_SOFT_ERROR == qs) continue; - if (qs >= 0) - committed = true; break; } /* for(... MAX_RETRIES) */ giveup: - /* Deactivate existing wire methods that were removed above */ - for (struct TMH_WireMethod *wm = mi->wm_head; - NULL != wm; - wm = wm->next) - { - /* We did not flip the 'active' bits earlier because the - DB transaction could still fail. Now it is time to update our - runtime state. */ - GNUNET_assert (! (wm->deleting & wm->enabling)); - if (committed) - { - if (wm->deleting) - wm->active = false; - if (wm->enabling) - wm->active = true; - } - wm->deleting = false; - wm->enabling = false; - } - if (! committed) - { - struct TMH_WireMethod *wm; - - while (NULL != (wm = wm_head)) - { - GNUNET_CONTAINER_DLL_remove (wm_head, - wm_tail, - wm); - free_wm (wm); - } - GNUNET_JSON_parse_free (spec); - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_DB_COMMIT_FAILED, - NULL); - } - /* Update our 'settings' */ GNUNET_free (mi->settings.name); GNUNET_free (mi->settings.email); @@ -508,23 +251,6 @@ giveup: if (NULL != is.logo) mi->settings.logo = GNUNET_strdup (is.logo); - /* Add 'new' wire methods to our list */ - { - struct TMH_WireMethod *wm; - - /* Note: this _could_ be done more efficiently if - someone wrote a GNUNET_CONTAINER_DLL_merge()... */ - while (NULL != (wm = wm_head)) - { - GNUNET_CONTAINER_DLL_remove (wm_head, - wm_tail, - wm); - GNUNET_CONTAINER_DLL_insert (mi->wm_head, - mi->wm_tail, - wm); - } - } - GNUNET_JSON_parse_free (spec); TMH_reload_instances (mi->settings.id); return TALER_MHD_reply_static (connection, |