aboutsummaryrefslogtreecommitdiff
path: root/src/mint/taler-mint-httpd_db.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mint/taler-mint-httpd_db.c')
-rw-r--r--src/mint/taler-mint-httpd_db.c114
1 files changed, 114 insertions, 0 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}