diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-11-29 10:52:45 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-11-29 10:52:45 +0100 |
commit | 636488c2797b498c8861bc6864539a63323b3608 (patch) | |
tree | 11b0f04aa31c40a0736babf5ee0a4d0d29682a32 /src/auditor/taler-auditor-httpd.c | |
parent | 970e3fd4cb4a3f76d1bcf56e4cec668bcb828078 (diff) | |
parent | 785f5fb7dd5f8e4aa0258e3e72f519c77942cb7d (diff) | |
download | exchange-636488c2797b498c8861bc6864539a63323b3608.tar.xz |
merge error codes
Diffstat (limited to 'src/auditor/taler-auditor-httpd.c')
-rw-r--r-- | src/auditor/taler-auditor-httpd.c | 302 |
1 files changed, 27 insertions, 275 deletions
diff --git a/src/auditor/taler-auditor-httpd.c b/src/auditor/taler-auditor-httpd.c index e37b4a0e8..55a343776 100644 --- a/src/auditor/taler-auditor-httpd.c +++ b/src/auditor/taler-auditor-httpd.c @@ -27,11 +27,10 @@ #include <microhttpd.h> #include <pthread.h> #include <sys/resource.h> +#include "taler_mhd_lib.h" #include "taler_auditordb_lib.h" #include "taler-auditor-httpd_deposit-confirmation.h" #include "taler-auditor-httpd_exchanges.h" -#include "taler-auditor-httpd_parsing.h" -#include "taler-auditor-httpd_responses.h" #include "taler-auditor-httpd_mhd.h" #include "taler-auditor-httpd.h" @@ -291,7 +290,7 @@ handle_mhd_completion_callback (void *cls, { if (NULL == *con_cls) return; - TAH_PARSE_post_cleanup_callback (*con_cls); + TALER_MHD_parse_post_cleanup_callback (*con_cls); *con_cls = NULL; } @@ -332,9 +331,9 @@ handle_version (struct TAH_RequestHandler *rh, GNUNET_break (0); return MHD_NO; } - return TAH_RESPONSE_reply_json (connection, - ver, - MHD_HTTP_OK); + return TALER_MHD_reply_json (connection, + ver, + MHD_HTTP_OK); } @@ -384,7 +383,7 @@ handle_mhd_request (void *cls, &TAH_MHD_handler_static_response, MHD_HTTP_OK }, /* AGPL licensing page, redirect to source. As per the AGPL-license, every deployment is required to offer the user a download of the - source. We make this easy by including a redirect to the source + source. We make this easy by including a redirect t the source here. */ { "/agpl", MHD_HTTP_METHOD_GET, "text/plain", NULL, 0, @@ -392,11 +391,6 @@ handle_mhd_request (void *cls, { NULL, NULL, NULL, NULL, 0, 0 } }; - static struct TAH_RequestHandler h404 = { - "", NULL, "text/html", - "<html><title>404: not found</title></html>", 0, - &TAH_MHD_handler_static_response, MHD_HTTP_NOT_FOUND - }; struct TAH_RequestHandler *rh; GNUNET_log (GNUNET_ERROR_TYPE_INFO, @@ -419,127 +413,13 @@ handle_mhd_request (void *cls, upload_data, upload_data_size); } - return TAH_MHD_handler_static_response (&h404, - connection, - con_cls, - upload_data, - upload_data_size); -} - - -/** - * Parse the configuration to determine on which port - * or UNIX domain path we should run an HTTP service. - * - * @param section section of the configuration to parse ("auditor" or "auditor-admin") - * @param[out] rport set to the port number, or 0 for none - * @param[out] unix_path set to the UNIX path, or NULL for none - * @param[out] unix_mode set to the mode to be used for @a unix_path - * @return #GNUNET_OK on success - */ -static int -parse_port_config (const char *section, - uint16_t *rport, - char **unix_path, - mode_t *unix_mode) -{ - const char *choices[] = {"tcp", "unix"}; - const char *serve_type; - unsigned long long port; - - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_choice (cfg, - section, - "serve", - choices, - &serve_type)) - { - GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, - section, - "serve", - "serve type required"); - return GNUNET_SYSERR; - } - - if (0 == strcmp (serve_type, "tcp")) - { - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number (cfg, - section, - "port", - &port)) - { - GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, - section, - "port", - "port number required"); - return GNUNET_SYSERR; - } - - if ( (0 == port) || - (port > UINT16_MAX) ) - { - fprintf (stderr, - "Invalid configuration (value out of range): %llu is not a valid port\n", - port); - return GNUNET_SYSERR; - } - *rport = (uint16_t) port; - *unix_path = NULL; - return GNUNET_OK; - } - if (0 == strcmp (serve_type, "unix")) - { - struct sockaddr_un s_un; - char *modestring; - - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename (cfg, - section, - "unixpath", - unix_path)) - { - GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, - section, - "unixpath", - "unixpath required"); - return GNUNET_SYSERR; - } - if (strlen (*unix_path) >= sizeof (s_un.sun_path)) - { - fprintf (stderr, - "Invalid configuration: unix path too long\n"); - return GNUNET_SYSERR; - } - - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_string (cfg, - section, - "UNIXPATH_MODE", - &modestring)) - { - GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, - section, - "UNIXPATH_MODE"); - return GNUNET_SYSERR; - } - errno = 0; - *unix_mode = (mode_t) strtoul (modestring, NULL, 8); - if (0 != errno) - { - GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, - section, - "UNIXPATH_MODE", - "must be octal number"); - GNUNET_free (modestring); - return GNUNET_SYSERR; - } - GNUNET_free (modestring); - return GNUNET_OK; - } - /* not reached */ - GNUNET_assert (0); - return GNUNET_SYSERR; +#define NOT_FOUND "<html><title>404: not found</title></html>" + return TALER_MHD_reply_static (connection, + MHD_HTTP_NOT_FOUND, + "text/html", + NOT_FOUND, + strlen (NOT_FOUND)); +#undef NOT_FOUND } @@ -562,10 +442,11 @@ auditor_serve_process_config () return GNUNET_SYSERR; } if (GNUNET_OK != - parse_port_config ("auditor", - &serve_port, - &serve_unixpath, - &unixpath_mode)) + TALER_MHD_parse_config (cfg, + "auditor", + &serve_port, + &serve_unixpath, + &unixpath_mode)) { return GNUNET_SYSERR; } @@ -641,141 +522,6 @@ auditor_serve_process_config () /** - * Function called for logging by MHD. - * - * @param cls closure, NULL - * @param fm format string (`printf()`-style) - * @param ap arguments to @a fm - */ -static void -handle_mhd_logs (void *cls, - const char *fm, - va_list ap) -{ - static int cache; - char buf[2048]; - - if (-1 == cache) - return; - if (0 == cache) - { - if (0 == - GNUNET_get_log_call_status (GNUNET_ERROR_TYPE_INFO, - "auditor-httpd", - __FILE__, - __FUNCTION__, - __LINE__)) - { - cache = -1; - return; - } - } - cache = 1; - vsnprintf (buf, - sizeof (buf), - fm, - ap); - GNUNET_log_from_nocheck (GNUNET_ERROR_TYPE_INFO, - "auditor-httpd", - "%s", - buf); -} - - -/** - * Open UNIX domain socket for listining at @a unix_path with - * permissions @a unix_mode. - * - * @param unix_path where to listen - * @param unix_mode access permissions to set - * @return -1 on error, otherwise the listen socket - */ -static int -open_unix_path (const char *unix_path, - mode_t unix_mode) -{ - struct GNUNET_NETWORK_Handle *nh; - struct sockaddr_un *un; - int fd; - - if (sizeof (un->sun_path) <= strlen (unix_path)) - { - fprintf (stderr, - "unixpath `%s' too long\n", - unix_path); - return -1; - } - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Creating listen socket '%s' with mode %o\n", - unix_path, - unix_mode); - - if (GNUNET_OK != - GNUNET_DISK_directory_create_for_file (unix_path)) - { - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, - "mkdir", - unix_path); - } - - un = GNUNET_new (struct sockaddr_un); - un->sun_family = AF_UNIX; - strncpy (un->sun_path, - unix_path, - sizeof (un->sun_path) - 1); - GNUNET_NETWORK_unix_precheck (un); - - if (NULL == (nh = GNUNET_NETWORK_socket_create (AF_UNIX, - SOCK_STREAM, - 0))) - { - fprintf (stderr, - "create failed for AF_UNIX\n"); - GNUNET_free (un); - return -1; - } - if (GNUNET_OK != - GNUNET_NETWORK_socket_bind (nh, - (void *) un, - sizeof (struct sockaddr_un))) - { - fprintf (stderr, - "bind failed for AF_UNIX\n"); - GNUNET_free (un); - GNUNET_NETWORK_socket_close (nh); - return -1; - } - GNUNET_free (un); - if (GNUNET_OK != - GNUNET_NETWORK_socket_listen (nh, - UNIX_BACKLOG)) - { - fprintf (stderr, - "listen failed for AF_UNIX\n"); - GNUNET_NETWORK_socket_close (nh); - return -1; - } - - if (0 != chmod (unix_path, - unix_mode)) - { - fprintf (stderr, - "chmod failed: %s\n", - strerror (errno)); - GNUNET_NETWORK_socket_close (nh); - return -1; - } - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "set socket '%s' to mode %o\n", - unix_path, - unix_mode); - fd = GNUNET_NETWORK_get_fd (nh); - GNUNET_NETWORK_socket_free_memory_only_ (nh); - return fd; -} - - -/** * The main function of the taler-auditor-httpd server ("the auditor"). * * @param argc number of arguments from the command line @@ -811,12 +557,17 @@ main (int argc, const char *listen_pid; const char *listen_fds; int fh = -1; + enum TALER_MHD_GlobalOptions go; if (0 >= GNUNET_GETOPT_run ("taler-auditor-httpd", options, argc, argv)) return 1; + go = TALER_MHD_GO_NONE; + if (TAH_auditor_connection_close) + go |= TALER_MHD_GO_FORCE_CONNECTION_CLOSE; + TALER_MHD_setup (go); GNUNET_assert (GNUNET_OK == GNUNET_log_setup ("taler-auditor-httpd", (NULL == loglev) ? "INFO" : loglev, @@ -877,8 +628,8 @@ main (int argc, if ( (-1 == fh) && (NULL != serve_unixpath) ) { - fh = open_unix_path (serve_unixpath, - unixpath_mode); + fh = TALER_MHD_open_unix_path (serve_unixpath, + unixpath_mode); if (-1 == fh) return 1; } @@ -894,7 +645,8 @@ main (int argc, MHD_OPTION_THREAD_POOL_SIZE, (unsigned int) 32, MHD_OPTION_LISTEN_BACKLOG_SIZE, (unsigned int) 1024, MHD_OPTION_LISTEN_SOCKET, fh, - MHD_OPTION_EXTERNAL_LOGGER, &handle_mhd_logs, NULL, + MHD_OPTION_EXTERNAL_LOGGER, &TALER_MHD_handle_logs, + NULL, MHD_OPTION_NOTIFY_COMPLETED, &handle_mhd_completion_callback, NULL, MHD_OPTION_CONNECTION_TIMEOUT, connection_timeout, |