LCOV - code coverage report
Current view: top level - exchange - taler-exchange-httpd_mhd.c (source / functions) Hit Total Coverage
Test: rcoverage.info Lines: 0 36 0.0 %
Date: 2017-09-17 17:24:28 Functions: 0 3 0.0 %

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   Copyright (C) 2014 GNUnet e.V.
       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-exchange-httpd_mhd.c
      19             :  * @brief helpers for MHD interaction; these are TALER_EXCHANGE_handler_ functions
      20             :  *        that generate simple MHD replies that do not require any real operations
      21             :  *        to be performed (error handling, static pages, etc.)
      22             :  * @author Florian Dold
      23             :  * @author Benedikt Mueller
      24             :  * @author Christian Grothoff
      25             :  */
      26             : #include "platform.h"
      27             : #include <gnunet/gnunet_util_lib.h>
      28             : #include <jansson.h>
      29             : #include <microhttpd.h>
      30             : #include <pthread.h>
      31             : #include "taler-exchange-httpd_responses.h"
      32             : #include "taler-exchange-httpd.h"
      33             : #include "taler-exchange-httpd_mhd.h"
      34             : 
      35             : /**
      36             :  * Function to call to handle the request by sending
      37             :  * back static data from the @a rh.
      38             :  *
      39             :  * @param rh context of the handler
      40             :  * @param connection the MHD connection to handle
      41             :  * @param[in,out] connection_cls the connection's closure (can be updated)
      42             :  * @param upload_data upload data
      43             :  * @param[in,out] upload_data_size number of bytes (left) in @a upload_data
      44             :  * @return MHD result code
      45             :  */
      46             : int
      47           0 : TEH_MHD_handler_static_response (struct TEH_RequestHandler *rh,
      48             :                                     struct MHD_Connection *connection,
      49             :                                     void **connection_cls,
      50             :                                     const char *upload_data,
      51             :                                     size_t *upload_data_size)
      52             : {
      53             :   struct MHD_Response *response;
      54             :   int ret;
      55             : 
      56           0 :   if (0 == rh->data_size)
      57           0 :     rh->data_size = strlen ((const char *) rh->data);
      58           0 :   response = MHD_create_response_from_buffer (rh->data_size,
      59           0 :                                               (void *) rh->data,
      60             :                                               MHD_RESPMEM_PERSISTENT);
      61           0 :   if (NULL == response)
      62             :   {
      63           0 :     GNUNET_break (0);
      64           0 :     return MHD_NO;
      65             :   }
      66           0 :   TEH_RESPONSE_add_global_headers (response);
      67           0 :   if (NULL != rh->mime_type)
      68           0 :     (void) MHD_add_response_header (response,
      69             :                                     MHD_HTTP_HEADER_CONTENT_TYPE,
      70             :                                     rh->mime_type);
      71           0 :   ret = MHD_queue_response (connection,
      72           0 :                             rh->response_code,
      73             :                             response);
      74           0 :   MHD_destroy_response (response);
      75           0 :   return ret;
      76             : }
      77             : 
      78             : 
      79             : /**
      80             :  * Function to call to handle the request by sending
      81             :  * back a redirect to the AGPL source code.
      82             :  *
      83             :  * @param rh context of the handler
      84             :  * @param connection the MHD connection to handle
      85             :  * @param[in,out] connection_cls the connection's closure (can be updated)
      86             :  * @param upload_data upload data
      87             :  * @param[in,out] upload_data_size number of bytes (left) in @a upload_data
      88             :  * @return MHD result code
      89             :  */
      90             : int
      91           0 : TEH_MHD_handler_agpl_redirect (struct TEH_RequestHandler *rh,
      92             :                                   struct MHD_Connection *connection,
      93             :                                   void **connection_cls,
      94             :                                   const char *upload_data,
      95             :                                   size_t *upload_data_size)
      96             : {
      97           0 :   const char *agpl =
      98             :     "This server is licensed under the Affero GPL. You will now be redirected to the source code.";
      99             :   struct MHD_Response *response;
     100             :   int ret;
     101             : 
     102           0 :   response = MHD_create_response_from_buffer (strlen (agpl),
     103             :                                               (void *) agpl,
     104             :                                               MHD_RESPMEM_PERSISTENT);
     105           0 :   if (NULL == response)
     106             :   {
     107           0 :     GNUNET_break (0);
     108           0 :     return MHD_NO;
     109             :   }
     110           0 :   TEH_RESPONSE_add_global_headers (response);
     111           0 :   if (NULL != rh->mime_type)
     112           0 :     (void) MHD_add_response_header (response,
     113             :                                     MHD_HTTP_HEADER_CONTENT_TYPE,
     114             :                                     rh->mime_type);
     115           0 :   if (MHD_NO ==
     116           0 :       MHD_add_response_header (response,
     117             :                                MHD_HTTP_HEADER_LOCATION,
     118             :                                "http://www.git.taler.net/?p=exchange.git"))
     119             :   {
     120           0 :     GNUNET_break (0);
     121           0 :     MHD_destroy_response (response);
     122           0 :     return MHD_NO;
     123             :   }
     124           0 :   ret = MHD_queue_response (connection,
     125           0 :                             rh->response_code,
     126             :                             response);
     127           0 :   MHD_destroy_response (response);
     128           0 :   return ret;
     129             : }
     130             : 
     131             : 
     132             : /**
     133             :  * Function to call to handle the request by building a JSON
     134             :  * reply with an error message from @a rh.
     135             :  *
     136             :  * @param rh context of the handler
     137             :  * @param connection the MHD connection to handle
     138             :  * @param[in,out] connection_cls the connection's closure (can be updated)
     139             :  * @param upload_data upload data
     140             :  * @param[in,out] upload_data_size number of bytes (left) in @a upload_data
     141             :  * @return MHD result code
     142             :  */
     143             : int
     144           0 : TEH_MHD_handler_send_json_pack_error (struct TEH_RequestHandler *rh,
     145             :                                          struct MHD_Connection *connection,
     146             :                                          void **connection_cls,
     147             :                                          const char *upload_data,
     148             :                                          size_t *upload_data_size)
     149             : {
     150           0 :   return TEH_RESPONSE_reply_json_pack (connection,
     151           0 :                                      rh->response_code,
     152             :                                      "{s:s}",
     153             :                                      "error",
     154             :                                      rh->data);
     155             : }
     156             : 
     157             : 
     158             : /* end of taler-exchange-httpd_mhd.c */

Generated by: LCOV version 1.13