aboutsummaryrefslogtreecommitdiff
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
parent53a7140a0bcfc47a373e6392e38e498f9b091f18 (diff)
downloadexchange-92cc995743b64f3302619caf8bf5f49e33674849.tar.gz
exchange-92cc995743b64f3302619caf8bf5f49e33674849.zip
separate argument parsing from DB operations for /refresh/link
-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,
807 807
808 return TALER_MINT_reply_refresh_commit_success (connection, &refresh_session); 808 return TALER_MINT_reply_refresh_commit_success (connection, &refresh_session);
809 } 809 }
810
811
812
813/**
814 * FIXME: move into response generation logic!
815 * FIXME: need to separate this from DB logic!
816 */
817static int
818link_iter (void *cls,
819 const struct LinkDataEnc *link_data_enc,
820 const struct TALER_RSA_PublicKeyBinaryEncoded *denom_pub,
821 const struct TALER_RSA_Signature *ev_sig)
822{
823 json_t *list = cls;
824 json_t *obj = json_object ();
825
826 json_array_append_new (list, obj);
827
828 json_object_set_new (obj, "link_enc",
829 TALER_JSON_from_data (link_data_enc,
830 sizeof (struct LinkDataEnc)));
831
832 json_object_set_new (obj, "denom_pub",
833 TALER_JSON_from_data (denom_pub,
834 sizeof (struct TALER_RSA_PublicKeyBinaryEncoded)));
835
836 json_object_set_new (obj, "ev_sig",
837 TALER_JSON_from_data (ev_sig,
838 sizeof (struct TALER_RSA_Signature)));
839
840 return GNUNET_OK;
841}
842
843
844/**
845 * Execute a /refresh/link.
846 *
847 * @param connection the MHD connection to handle
848 * @param coin_pub public key of the coin to link
849 * @return MHD result code
850 */
851int
852TALER_MINT_db_execute_refresh_link (struct MHD_Connection *connection,
853 const struct GNUNET_CRYPTO_EcdsaPublicKey *coin_pub)
854{
855 int res;
856 json_t *root;
857 json_t *list;
858 PGconn *db_conn;
859 struct GNUNET_CRYPTO_EcdsaPublicKey transfer_pub;
860 struct SharedSecretEnc shared_secret_enc;
861
862 if (NULL == (db_conn = TALER_MINT_DB_get_connection ()))
863 {
864 GNUNET_break (0);
865 // FIXME: return error code!
866 return MHD_NO;
867 }
868
869 res = TALER_db_get_transfer (db_conn,
870 coin_pub,
871 &transfer_pub,
872 &shared_secret_enc);
873 if (GNUNET_SYSERR == res)
874 {
875 GNUNET_break (0);
876 // FIXME: return error code!
877 return MHD_NO;
878 }
879 if (GNUNET_NO == res)
880 {
881 return TALER_MINT_reply_json_pack (connection,
882 MHD_HTTP_NOT_FOUND,
883 "{s:s}",
884 "error",
885 "link data not found (transfer)");
886 }
887 GNUNET_assert (GNUNET_OK == res);
888
889 /* FIXME: separate out response generation logic! */
890
891 list = json_array ();
892 root = json_object ();
893 json_object_set_new (root, "new_coins", list);
894
895 res = TALER_db_get_link (db_conn, coin_pub,
896 &link_iter, list);
897 if (GNUNET_SYSERR == res)
898 {
899 GNUNET_break (0);
900 // FIXME: return error code!
901 return MHD_NO;
902 }
903 if (GNUNET_NO == res)
904 {
905 return TALER_MINT_reply_json_pack (connection,
906 MHD_HTTP_NOT_FOUND,
907 "{s:s}",
908 "error",
909 "link data not found (link)");
910 }
911 GNUNET_assert (GNUNET_OK == res);
912 json_object_set_new (root, "transfer_pub",
913 TALER_JSON_from_data (&transfer_pub,
914 sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)));
915 json_object_set_new (root, "secret_enc",
916 TALER_JSON_from_data (&shared_secret_enc,
917 sizeof (struct SharedSecretEnc)));
918 return TALER_MINT_reply_json (connection,
919 root,
920 MHD_HTTP_OK);
921
922
923}
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,
110 struct RefreshCommitLink *const* commit_link); 110 struct RefreshCommitLink *const* commit_link);
111 111
112 112
113
114/**
115 * Execute a /refresh/link.
116 *
117 * @param connection the MHD connection to handle
118 * @param coin_pub public key of the coin to link
119 * @return MHD result code
120 */
121int
122TALER_MINT_db_execute_refresh_link (struct MHD_Connection *connection,
123 const struct GNUNET_CRYPTO_EcdsaPublicKey *coin_pub);
124
125
113#endif /* _NEURO_MINT_DB_H */ 126#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 @@
41#include "taler-mint-httpd_responses.h" 41#include "taler-mint-httpd_responses.h"
42 42
43 43
44/**
45 * FIXME: document!
46 */
47static int
48link_iter (void *cls,
49 const struct LinkDataEnc *link_data_enc,
50 const struct TALER_RSA_PublicKeyBinaryEncoded *denom_pub,
51 const struct TALER_RSA_Signature *ev_sig)
52{
53 json_t *list = cls;
54 json_t *obj = json_object ();
55
56 json_array_append_new (list, obj);
57
58 json_object_set_new (obj, "link_enc",
59 TALER_JSON_from_data (link_data_enc,
60 sizeof (struct LinkDataEnc)));
61
62 json_object_set_new (obj, "denom_pub",
63 TALER_JSON_from_data (denom_pub,
64 sizeof (struct TALER_RSA_PublicKeyBinaryEncoded)));
65
66 json_object_set_new (obj, "ev_sig",
67 TALER_JSON_from_data (ev_sig,
68 sizeof (struct TALER_RSA_Signature)));
69
70 return GNUNET_OK;
71}
72
73
74static int 44static int
75check_confirm_signature (struct MHD_Connection *connection, 45check_confirm_signature (struct MHD_Connection *connection,
76 json_t *coin_info, 46 json_t *coin_info,
@@ -780,6 +750,8 @@ TALER_MINT_handler_refresh_reveal (struct RequestHandler *rh,
780 return res; 750 return res;
781 } 751 }
782 752
753
754
783 if (NULL == (db_conn = TALER_MINT_DB_get_connection ())) 755 if (NULL == (db_conn = TALER_MINT_DB_get_connection ()))
784 { 756 {
785 GNUNET_break (0); 757 GNUNET_break (0);
@@ -791,9 +763,13 @@ TALER_MINT_handler_refresh_reveal (struct RequestHandler *rh,
791 * and the session commited already. 763 * and the session commited already.
792 * Do _not_ care about fields other than session_pub in this case. */ 764 * Do _not_ care about fields other than session_pub in this case. */
793 765
794 res = TALER_MINT_DB_get_refresh_session (db_conn, &refresh_session_pub, &refresh_session); 766 res = TALER_MINT_DB_get_refresh_session (db_conn,
767 &refresh_session_pub,
768 &refresh_session);
795 if (GNUNET_YES == res && 0 != refresh_session.reveal_ok) 769 if (GNUNET_YES == res && 0 != refresh_session.reveal_ok)
796 return helper_refresh_reveal_send_response (connection, db_conn, &refresh_session_pub); 770 return helper_refresh_reveal_send_response (connection,
771 db_conn,
772 &refresh_session_pub);
797 if (GNUNET_SYSERR == res) 773 if (GNUNET_SYSERR == res)
798 { 774 {
799 GNUNET_break (0); 775 GNUNET_break (0);
@@ -1070,11 +1046,6 @@ TALER_MINT_handler_refresh_link (struct RequestHandler *rh,
1070{ 1046{
1071 struct GNUNET_CRYPTO_EcdsaPublicKey coin_pub; 1047 struct GNUNET_CRYPTO_EcdsaPublicKey coin_pub;
1072 int res; 1048 int res;
1073 json_t *root;
1074 json_t *list;
1075 PGconn *db_conn;
1076 struct GNUNET_CRYPTO_EcdsaPublicKey transfer_pub;
1077 struct SharedSecretEnc shared_secret_enc;
1078 1049
1079 res = TALER_MINT_mhd_request_arg_data (connection, 1050 res = TALER_MINT_mhd_request_arg_data (connection,
1080 "coin_pub", 1051 "coin_pub",
@@ -1089,62 +1060,8 @@ TALER_MINT_handler_refresh_link (struct RequestHandler *rh,
1089 if (GNUNET_OK != res) 1060 if (GNUNET_OK != res)
1090 return MHD_YES; 1061 return MHD_YES;
1091 1062
1092 if (NULL == (db_conn = TALER_MINT_DB_get_connection ())) 1063 return TALER_MINT_db_execute_refresh_link (connection,
1093 { 1064 &coin_pub);
1094 GNUNET_break (0);
1095 // FIXME: return error code!
1096 return MHD_NO;
1097 }
1098
1099 list = json_array ();
1100 root = json_object ();
1101 json_object_set_new (root, "new_coins", list);
1102
1103 res = TALER_db_get_transfer (db_conn,
1104 &coin_pub,
1105 &transfer_pub,
1106 &shared_secret_enc);
1107 if (GNUNET_SYSERR == res)
1108 {
1109 GNUNET_break (0);
1110 // FIXME: return error code!
1111 return MHD_NO;
1112 }
1113 if (GNUNET_NO == res)
1114 {
1115 return TALER_MINT_reply_json_pack (connection,
1116 MHD_HTTP_NOT_FOUND,
1117 "{s:s}",
1118 "error",
1119 "link data not found (transfer)");
1120 }
1121 GNUNET_assert (GNUNET_OK == res);
1122
1123 res = TALER_db_get_link (db_conn, &coin_pub, link_iter, list);
1124 if (GNUNET_SYSERR == res)
1125 {
1126 GNUNET_break (0);
1127 // FIXME: return error code!
1128 return MHD_NO;
1129 }
1130 if (GNUNET_NO == res)
1131 {
1132 return TALER_MINT_reply_json_pack (connection,
1133 MHD_HTTP_NOT_FOUND,
1134 "{s:s}",
1135 "error",
1136 "link data not found (link)");
1137 }
1138 GNUNET_assert (GNUNET_OK == res);
1139 json_object_set_new (root, "transfer_pub",
1140 TALER_JSON_from_data (&transfer_pub,
1141 sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)));
1142 json_object_set_new (root, "secret_enc",
1143 TALER_JSON_from_data (&shared_secret_enc,
1144 sizeof (struct SharedSecretEnc)));
1145 return TALER_MINT_reply_json (connection,
1146 root,
1147 MHD_HTTP_OK);
1148} 1065}
1149 1066
1150 1067