taler-merchant-httpd_mhd.c (2654B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2014-2020 Taler Systems SA 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 * @file taler-merchant-httpd_mhd.c 18 * @brief helpers for MHD interaction; these are TALER_EXCHANGE_handler_ functions 19 * that generate simple MHD replies that do not require any real operations 20 * to be performed (error handling, static pages, etc.) 21 * @author Florian Dold 22 * @author Benedikt Mueller 23 * @author Christian Grothoff 24 */ 25 #include "platform.h" 26 #include <jansson.h> 27 #include "taler-merchant-httpd_mhd.h" 28 29 30 MHD_RESULT 31 TMH_MHD_handler_static_response (const struct TMH_RequestHandler *rh, 32 struct MHD_Connection *connection, 33 struct TMH_HandlerContext *hc) 34 { 35 (void) hc; 36 return TALER_MHD_reply_static (connection, 37 rh->response_code, 38 rh->mime_type, 39 rh->data, 40 rh->data_size); 41 } 42 43 44 MHD_RESULT 45 TMH_MHD_handler_agpl_redirect (const struct TMH_RequestHandler *rh, 46 struct MHD_Connection *connection, 47 struct TMH_HandlerContext *hc) 48 { 49 (void) rh; 50 (void) hc; 51 return TALER_MHD_reply_agpl (connection, 52 "http://www.git.taler.net/?p=merchant.git"); 53 } 54 55 56 bool 57 TMH_MHD_test_html_desired (struct MHD_Connection *connection) 58 { 59 const char *accept; 60 double json_q; 61 double html_q; 62 63 accept = MHD_lookup_connection_value (connection, 64 MHD_HEADER_KIND, 65 MHD_HTTP_HEADER_ACCEPT); 66 if (NULL == accept) 67 return false; /* nothing selected, we read this as not HTML */ 68 html_q = TALER_pattern_matches (accept, 69 "text/html"); 70 json_q = TALER_pattern_matches (accept, 71 "application/json"); 72 if (html_q > json_q) 73 return true; 74 return false; 75 } 76 77 78 /* end of taler-exchange-httpd_mhd.c */