/*
     This file is part of GNUnet.
     Copyright (C) 2026 Taler Systems SA

     Paivana is free software; you can redistribute it and/or
     modify it under the terms of the GNU Affero General Public License
     as published by the Free Software Foundation; either version
     3, or (at your option) any later version.

     Paivana is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty
     of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
     the GNU Affero General Public License for more details.

     You should have received a copy of the GNU Affero General Public
     License along with Paivana; see the file COPYING.  If not,
     write to the Free Software Foundation, Inc., 51 Franklin
     Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

/**
 * @author Christian Grothoff
 * @file paivana-httpd_reverse.h
 *
 * @brief Project data definition
 */
#ifndef PAIVANA_HTTPD_REVERSE_H
#define PAIVANA_HTTPD_REVERSE_H

#include <gnunet/gnunet_util_lib.h>
#include <microhttpd.h>
#include "paivana-httpd.h"

bool
PAIVANA_HTTPD_reverse_init (void);


void
PAIVANA_HTTPD_reverse_shutdown (void);


struct HttpRequest *
PAIVANA_HTTPD_reverse_create (struct MHD_Connection *connection,
                              const char *url);

/**
 * Main MHD callback for reverse proxy.
 *
 * @param hr the HTTP request context
 * @param con MHD connection handle
 * @param url the url in the request (unused; the URL to forward was
 *        captured by #PAIVANA_HTTPD_reverse_create() and is kept in
 *        @a hr, but the parameter is retained to mirror the MHD
 *        access handler's signature)
 * @param meth the HTTP method used ("GET", "PUT", etc.)
 * @param ver the HTTP version string (i.e. "HTTP/1.1")
 * @param upload_data the data being uploaded (excluding HEADERS,
 *        for a POST that fits into memory and that is encoded
 *        with a supported encoding, the POST data will NOT be
 *        given in upload_data and is instead available as
 *        part of MHD_get_connection_values; very large POST
 *        data *will* be made available incrementally in
 *        upload_data)
 * @param upload_data_size set initially to the size of the
 *        @a upload_data provided; the method must update this
 *        value to the number of bytes NOT processed;
 * @return #MHD_YES if the connection was handled successfully,
 *         #MHD_NO if the socket must be closed due to a serious
 *         error while handling the request
 */
enum MHD_Result
PAIVANA_HTTPD_reverse (struct HttpRequest *hr,
                       struct MHD_Connection *con,
                       const char *url,
                       const char *meth,
                       const char *ver,
                       const char *upload_data,
                       size_t *upload_data_size);


void
PAIVANA_HTTPD_reverse_cleanup (struct HttpRequest *hr);

#endif
