aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-01-21 13:46:05 +0100
committerChristian Grothoff <christian@grothoff.org>2015-01-21 13:46:05 +0100
commit92cc995743b64f3302619caf8bf5f49e33674849 (patch)
tree7f603dc861533792149473d69c0ff31dfb498e25 /src
parent53a7140a0bcfc47a373e6392e38e498f9b091f18 (diff)
separate argument parsing from DB operations for /refresh/link
Diffstat (limited to 'src')
-rw-r--r--src/mint/taler-mint-httpd_db.c114
-rw-r--r--src/mint/taler-mint-httpd_db.h13
-rw-r--r--src/mint/taler-mint-httpd_refresh.c103
3 files changed, 137 insertions, 93 deletions
diff --git a/src/mint/taler-mint-httpd_db.c b/src/mint/taler-mint-httpd_db.c
index 2beaa8f97..a3df58658 100644
--- a/src/mint/taler-mint-httpd_db.c
+++ b/src/mint/taler-mint-httpd_db.c
@@ -807,3 +807,117 @@ TALER_MINT_db_execute_refresh_commit (struct MHD_Connection *connection,
return TALER_MINT_reply_refresh_commit_success (connection, &refresh_session);
}
+
+
+
+/**
+ * FIXME: move into response generation logic!
+ * FIXME: need to separate this from DB logic!
+ */
+static int
+link_iter (void *cls,
+ const struct LinkDataEnc *link_data_enc,
+ const struct TALER_RSA_PublicKeyBinaryEncoded *denom_pub,
+ const struct TALER_RSA_Signature *ev_sig)
+{
+ json_t *list = cls;
+ json_t *obj = json_object ();
+
+ json_array_append_new (list, obj);
+
+ json_object_set_new (obj, "link_enc",
+ TALER_JSON_from_data (link_data_enc,
+ sizeof (struct LinkDataEnc)));
+
+ json_object_set_new (obj, "denom_pub",
+ TALER_JSON_from_data (denom_pub,
+ sizeof (struct TALER_RSA_PublicKeyBinaryEncoded)));
+
+ json_object_set_new (obj, "ev_sig",
+ TALER_JSON_from_data (ev_sig,
+ sizeof (struct TALER_RSA_Signature)));
+
+ return GNUNET_OK;
+}
+
+
+/**
+ * Execute a /refresh/link.
+ *
+ * @param connection the MHD connection to handle
+ * @param coin_pub public key of the coin to link
+ * @return MHD result code
+ */
+int
+TALER_MINT_db_execute_refresh_link (struct MHD_Connection *connection,
+ const struct GNUNET_CRYPTO_EcdsaPublicKey *coin_pub)
+{
+ int res;
+ json_t *root;
+ json_t *list;
+ PGconn *db_conn;
+ struct GNUNET_CRYPTO_EcdsaPublicKey transfer_pub;
+ struct SharedSecretEnc shared_secret_enc;
+
+ if (NULL == (db_conn = TALER_MINT_DB_get_connection ()))
+ {
+ GNUNET_break (0);
+ // FIXME: return error code!
+ return MHD_NO;
+ }
+
+ res = TALER_db_get_transfer (db_conn,
+ coin_pub,
+ &transfer_pub,
+ &shared_secret_enc);
+ if (GNUNET_SYSERR == res)
+ {
+ GNUNET_break (0);
+ // FIXME: return error code!
+ return MHD_NO;
+ }
+ if (GNUNET_NO == res)
+ {
+ return TALER_MINT_reply_json_pack (connection,
+ MHD_HTTP_NOT_FOUND,
+ "{s:s}",
+ "error",
+ "link data not found (transfer)");
+ }
+ GNUNET_assert (GNUNET_OK == res);
+
+ /* FIXME: separate out response generation logic! */
+
+ list = json_array ();
+ root = json_object ();
+ json_object_set_new (root, "new_coins", list);
+
+ res = TALER_db_get_link (db_conn, coin_pub,
+ &link_iter, list);
+ if (GNUNET_SYSERR == res)
+ {
+ GNUNET_break (0);
+ // FIXME: return error code!
+ return MHD_NO;
+ }
+ if (GNUNET_NO == res)
+ {
+ return TALER_MINT_reply_json_pack (connection,
+ MHD_HTTP_NOT_FOUND,
+ "{s:s}",
+ "error",
+ "link data not found (link)");
+ }
+ GNUNET_assert (GNUNET_OK == res);
+ json_object_set_new (root, "transfer_pub",
+ TALER_JSON_from_data (&transfer_pub,
+ sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)));
+ json_object_set_new (root, "secret_enc",
+ TALER_JSON_from_data (&shared_secret_enc,
+ sizeof (struct SharedSecretEnc)));
+ return TALER_MINT_reply_json (connection,
+ root,
+ MHD_HTTP_OK);
+
+
+}
diff --git a/src/mint/taler-mint-httpd_db.h b/src/mint/taler-mint-httpd_db.h
index 307400b47..093878674 100644
--- a/src/mint/taler-mint-httpd_db.h
+++ b/src/mint/taler-mint-httpd_db.h
@@ -110,4 +110,17 @@ TALER_MINT_db_execute_refresh_commit (struct MHD_Connection *connection,
struct RefreshCommitLink *const* commit_link);
+
+/**
+ * Execute a /refresh/link.
+ *
+ * @param connection the MHD connection to handle
+ * @param coin_pub public key of the coin to link
+ * @return MHD result code
+ */
+int
+TALER_MINT_db_execute_refresh_link (struct MHD_Connection *connection,
+ const struct GNUNET_CRYPTO_EcdsaPublicKey *coin_pub);
+
+
#endif /* _NEURO_MINT_DB_H */
diff --git a/src/mint/taler-mint-httpd_refresh.c b/src/mint/taler-mint-httpd_refresh.c
index 2030eb3d6..863b812db 100644
--- a/src/mint/taler-mint-httpd_refresh.c
+++ b/src/mint/taler-mint-httpd_refresh.c
@@ -41,36 +41,6 @@
#include "taler-mint-httpd_responses.h"
-/**
- * FIXME: document!
- */
-static int
-link_iter (void *cls,
- const struct LinkDataEnc *link_data_enc,
- const struct TALER_RSA_PublicKeyBinaryEncoded *denom_pub,
- const struct TALER_RSA_Signature *ev_sig)
-{
- json_t *list = cls;
- json_t *obj = json_object ();
-
- json_array_append_new (list, obj);
-
- json_object_set_new (obj, "link_enc",
- TALER_JSON_from_data (link_data_enc,
- sizeof (struct LinkDataEnc)));
-
- json_object_set_new (obj, "denom_pub",
- TALER_JSON_from_data (denom_pub,
- sizeof (struct TALER_RSA_PublicKeyBinaryEncoded)));
-
- json_object_set_new (obj, "ev_sig",
- TALER_JSON_from_data (ev_sig,
- sizeof (struct TALER_RSA_Signature)));
-
- return GNUNET_OK;
-}
-
-
static int
check_confirm_signature (struct MHD_Connection *connection,
json_t *coin_info,
@@ -780,6 +750,8 @@ TALER_MINT_handler_refresh_reveal (struct RequestHandler *rh,
return res;
}
+
+
if (NULL == (db_conn = TALER_MINT_DB_get_connection ()))
{
GNUNET_break (0);
@@ -791,9 +763,13 @@ TALER_MINT_handler_refresh_reveal (struct RequestHandler *rh,
* and the session commited already.
* Do _not_ care about fields other than session_pub in this case. */
- res = TALER_MINT_DB_get_refresh_session (db_conn, &refresh_session_pub, &refresh_session);
+ res = TALER_MINT_DB_get_refresh_session (db_conn,
+ &refresh_session_pub,
+ &refresh_session);
if (GNUNET_YES == res && 0 != refresh_session.reveal_ok)
- return helper_refresh_reveal_send_response (connection, db_conn, &refresh_session_pub);
+ return helper_refresh_reveal_send_response (connection,
+ db_conn,
+ &refresh_session_pub);
if (GNUNET_SYSERR == res)
{
GNUNET_break (0);
@@ -1070,11 +1046,6 @@ TALER_MINT_handler_refresh_link (struct RequestHandler *rh,
{
struct GNUNET_CRYPTO_EcdsaPublicKey coin_pub;
int res;
- json_t *root;
- json_t *list;
- PGconn *db_conn;
- struct GNUNET_CRYPTO_EcdsaPublicKey transfer_pub;
- struct SharedSecretEnc shared_secret_enc;
res = TALER_MINT_mhd_request_arg_data (connection,
"coin_pub",
@@ -1089,62 +1060,8 @@ TALER_MINT_handler_refresh_link (struct RequestHandler *rh,
if (GNUNET_OK != res)
return MHD_YES;
- if (NULL == (db_conn = TALER_MINT_DB_get_connection ()))
- {
- GNUNET_break (0);
- // FIXME: return error code!
- return MHD_NO;
- }
-
- list = json_array ();
- root = json_object ();
- json_object_set_new (root, "new_coins", list);
-
- res = TALER_db_get_transfer (db_conn,
- &coin_pub,
- &transfer_pub,
- &shared_secret_enc);
- if (GNUNET_SYSERR == res)
- {
- GNUNET_break (0);
- // FIXME: return error code!
- return MHD_NO;
- }
- if (GNUNET_NO == res)
- {
- return TALER_MINT_reply_json_pack (connection,
- MHD_HTTP_NOT_FOUND,
- "{s:s}",
- "error",
- "link data not found (transfer)");
- }
- GNUNET_assert (GNUNET_OK == res);
-
- res = TALER_db_get_link (db_conn, &coin_pub, link_iter, list);
- if (GNUNET_SYSERR == res)
- {
- GNUNET_break (0);
- // FIXME: return error code!
- return MHD_NO;
- }
- if (GNUNET_NO == res)
- {
- return TALER_MINT_reply_json_pack (connection,
- MHD_HTTP_NOT_FOUND,
- "{s:s}",
- "error",
- "link data not found (link)");
- }
- GNUNET_assert (GNUNET_OK == res);
- json_object_set_new (root, "transfer_pub",
- TALER_JSON_from_data (&transfer_pub,
- sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)));
- json_object_set_new (root, "secret_enc",
- TALER_JSON_from_data (&shared_secret_enc,
- sizeof (struct SharedSecretEnc)));
- return TALER_MINT_reply_json (connection,
- root,
- MHD_HTTP_OK);
+ return TALER_MINT_db_execute_refresh_link (connection,
+ &coin_pub);
}