taler-merchant-httpd_mhd.h (3967B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2014, 2015 GNUnet e.V. and INRIA 4 5 TALER is free software; you can redistribute it and/or modify it under the 6 terms of the GNU Affero General Public License as published by the Free Software 7 Foundation; either version 3, or (at your option) any later version. 8 9 TALER is distributed in the hope that it will be useful, but WITHOUT ANY 10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. 12 13 You should have received a copy of the GNU Affero General Public License along with 14 TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 */ 16 17 /** 18 * @file taler-merchant-httpd_mhd.h 19 * @brief helpers for MHD interaction, used to generate simple responses 20 * @author Florian Dold 21 * @author Benedikt Mueller 22 * @author Christian Grothoff 23 */ 24 #ifndef TALER_EXCHANGE_HTTPD_MHD_H 25 #define TALER_EXCHANGE_HTTPD_MHD_H 26 #include <gnunet/gnunet_util_lib.h> 27 #include <microhttpd.h> 28 #include "taler-merchant-httpd.h" 29 30 31 /** 32 * Function to call to handle the request by sending 33 * back static data from the @a rh. 34 * 35 * @param rh context of the handler 36 * @param connection the MHD connection to handle 37 * @param[in,out] hc handler context (can be updated) 38 * @return MHD result code 39 */ 40 MHD_RESULT 41 TMH_MHD_handler_static_response (const struct TMH_RequestHandler *rh, 42 struct MHD_Connection *connection, 43 struct TMH_HandlerContext *hc); 44 45 46 /** 47 * Function to call to handle the request by sending 48 * back a redirect to the AGPL source code. 49 * 50 * @param rh context of the handler 51 * @param connection the MHD connection to handle 52 * @param[in,out] hc handler context (can be updated) 53 * @return MHD result code 54 */ 55 MHD_RESULT 56 TMH_MHD_handler_agpl_redirect (const struct TMH_RequestHandler *rh, 57 struct MHD_Connection *connection, 58 struct TMH_HandlerContext *hc); 59 60 61 /** 62 * Function to call to handle the request by building a JSON 63 * reply from varargs. 64 * 65 * @param rh context of the handler 66 * @param connection the MHD connection to handle 67 * @param[in,out] connection_cls the connection's closure (can be updated) 68 * @param response_code HTTP response code to use 69 * @param do_cache can the response be cached? (0: no, 1: yes) 70 * @param fmt format string for pack 71 * @param ... varargs 72 * @return MHD result code 73 */ 74 MHD_RESULT 75 TMH_MHD_helper_send_json_pack (struct TMH_RequestHandler *rh, 76 struct MHD_Connection *connection, 77 void *connection_cls, 78 int response_code, 79 int do_cache, 80 const char *fmt, 81 ...); 82 83 84 /** 85 * Function to call to handle the request by building a JSON 86 * reply with an error message from @a rh. 87 * 88 * @param rh context of the handler 89 * @param connection the MHD connection to handle 90 * @param[in,out] connection_cls the connection's closure (can be updated) 91 * @param upload_data upload data 92 * @param[in,out] upload_data_size number of bytes (left) in @a upload_data 93 * @param mi merchant backend instance, never NULL 94 * @return MHD result code 95 */ 96 MHD_RESULT 97 TMH_MHD_handler_send_json_pack_error (struct TMH_RequestHandler *rh, 98 struct MHD_Connection *connection, 99 void **connection_cls, 100 const char *upload_data, 101 size_t *upload_data_size, 102 struct TMH_MerchantInstance *mi); 103 104 105 /** 106 * Test if the client requested HTML output. 107 * 108 * @param connection client to test 109 * @return true if HTML was requested 110 */ 111 bool 112 TMH_MHD_test_html_desired (struct MHD_Connection *connection); 113 114 #endif