diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-01-20 12:31:50 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-01-20 12:31:50 +0100 |
commit | edecea4cacfffc1ef82affb8c21a1af3dc418ca4 (patch) | |
tree | 9ae55a7156768231ce7988efa4ec71b6c38d6357 | |
parent | 1234fa22095d521c88cf5f8bc4f4abdb09366732 (diff) | |
download | twister-edecea4cacfffc1ef82affb8c21a1af3dc418ca4.tar.gz twister-edecea4cacfffc1ef82affb8c21a1af3dc418ca4.tar.bz2 twister-edecea4cacfffc1ef82affb8c21a1af3dc418ca4.zip |
build system issues fixed
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | src/include/Makefile.am | 2 | ||||
-rw-r--r-- | src/include/platform.h | 61 | ||||
-rw-r--r-- | src/twister/Makefile.am | 130 | ||||
-rw-r--r-- | src/twister/taler-twister.c | 412 |
5 files changed, 277 insertions, 329 deletions
diff --git a/configure.ac b/configure.ac index 6fb87c6..c1cc215 100644 --- a/configure.ac +++ b/configure.ac @@ -384,6 +384,7 @@ fi AC_CONFIG_FILES([Makefile doc/Makefile src/Makefile + src/include/Makefile src/twister/Makefile ]) AC_OUTPUT diff --git a/src/include/Makefile.am b/src/include/Makefile.am index ab99efc..238babf 100644 --- a/src/include/Makefile.am +++ b/src/include/Makefile.am @@ -1,4 +1,6 @@ # This Makefile.am is in the public domain +SUBDIRS = . + talerincludedir = $(includedir)/taler talerinclude_HEADERS = \ diff --git a/src/include/platform.h b/src/include/platform.h new file mode 100644 index 0000000..673256c --- /dev/null +++ b/src/include/platform.h @@ -0,0 +1,61 @@ +/* + This file is part of TALER + Copyright (C) 2014 Chrisitan Grothoff (and other contributing authors) + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER 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 General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +*/ + +/** + * @file include/platform.h + * @brief This file contains the includes and definitions which are used by the + * rest of the modules + * @author Sree Harsha Totakura <sreeharsha@totakura.in> + */ + +#ifndef PLATFORM_H_ +#define PLATFORM_H_ + +/* Include our configuration header */ +#ifndef HAVE_USED_CONFIG_H +# define HAVE_USED_CONFIG_H +# ifdef HAVE_CONFIG_H +# include "twister_config.h" +# endif +#endif + + +#if (GNUNET_EXTRA_LOGGING >= 1) +#define VERBOSE(cmd) cmd +#else +#define VERBOSE(cmd) do { break; }while(0) +#endif + +/* Include the features available for GNU source */ +#define _GNU_SOURCE + +/* Include GNUnet's platform file */ +#include <gnunet/platform.h> + +/* Do not use shortcuts for gcrypt mpi */ +#define GCRYPT_NO_MPI_MACROS 1 + +/* Do not use deprecated functions from gcrypt */ +#define GCRYPT_NO_DEPRECATED 1 + +/* Ignore MHD deprecations for now as we want to be compatible + to "ancient" MHD releases. */ +#define MHD_NO_DEPRECATION 1 + + +#endif /* PLATFORM_H_ */ + +/* end of platform.h */ diff --git a/src/twister/Makefile.am b/src/twister/Makefile.am index 9ff98d1..bca7dfb 100644 --- a/src/twister/Makefile.am +++ b/src/twister/Makefile.am @@ -1,135 +1,19 @@ # This Makefile.am is in the public domain -AM_CPPFLAGS = -I$(top_srcdir)/src/include -I$(top_srcdir)/src/bank-lib/ +AM_CPPFLAGS = -I$(top_srcdir)/src/include if USE_COVERAGE AM_CFLAGS = --coverage -O0 XLIB = -lgcov endif -pkgcfgdir = $(prefix)/share/taler/config.d/ - -pkgcfg_DATA = \ - exchange.conf - bin_PROGRAMS = \ - taler-exchange-aggregator \ - taler-exchange-httpd \ - taler-exchange-wirewatch - -dist_bin_SCRIPTS = \ - taler-config-generate - -taler_exchange_aggregator_SOURCES = \ - taler-exchange-aggregator.c -taler_exchange_aggregator_LDADD = \ - $(LIBGCRYPT_LIBS) \ - $(top_builddir)/src/json/libtalerjson.la \ - $(top_builddir)/src/util/libtalerutil.la \ - $(top_builddir)/src/wire/libtalerwire.la \ - $(top_builddir)/src/exchangedb/libtalerexchangedb.la \ - -ljansson \ - -lgnunetutil - -taler_exchange_wirewatch_SOURCES = \ - taler-exchange-wirewatch.c -taler_exchange_wirewatch_LDADD = \ - $(LIBGCRYPT_LIBS) \ - $(top_builddir)/src/json/libtalerjson.la \ - $(top_builddir)/src/util/libtalerutil.la \ - $(top_builddir)/src/wire/libtalerwire.la \ - $(top_builddir)/src/exchangedb/libtalerexchangedb.la \ - -ljansson \ - -lgnunetutil - -taler_exchange_httpd_SOURCES = \ - taler-exchange-httpd.c taler-exchange-httpd.h \ - taler-exchange-httpd_admin.c taler-exchange-httpd_admin.h \ - taler-exchange-httpd_db.c taler-exchange-httpd_db.h \ - taler-exchange-httpd_deposit.c taler-exchange-httpd_deposit.h \ - taler-exchange-httpd_keystate.c taler-exchange-httpd_keystate.h \ - taler-exchange-httpd_mhd.c taler-exchange-httpd_mhd.h \ - taler-exchange-httpd_parsing.c taler-exchange-httpd_parsing.h \ - taler-exchange-httpd_payback.c taler-exchange-httpd_payback.h \ - taler-exchange-httpd_refresh_link.c taler-exchange-httpd_refresh_link.h \ - taler-exchange-httpd_refresh_melt.c taler-exchange-httpd_refresh_melt.h \ - taler-exchange-httpd_refresh_reveal.c taler-exchange-httpd_refresh_reveal.h \ - taler-exchange-httpd_refund.c taler-exchange-httpd_refund.h \ - taler-exchange-httpd_reserve_status.c taler-exchange-httpd_reserve_status.h \ - taler-exchange-httpd_reserve_withdraw.c taler-exchange-httpd_reserve_withdraw.h \ - taler-exchange-httpd_responses.c taler-exchange-httpd_responses.h \ - taler-exchange-httpd_track_transaction.c taler-exchange-httpd_track_transaction.h \ - taler-exchange-httpd_track_transfer.c taler-exchange-httpd_track_transfer.h \ - taler-exchange-httpd_wire.c taler-exchange-httpd_wire.h \ - taler-exchange-httpd_validation.c taler-exchange-httpd_validation.h -taler_exchange_httpd_LDADD = \ - $(LIBGCRYPT_LIBS) \ - $(top_builddir)/src/wire/libtalerwire.la \ - $(top_builddir)/src/json/libtalerjson.la \ - $(top_builddir)/src/exchangedb/libtalerexchangedb.la \ - $(top_builddir)/src/util/libtalerutil.la \ - -lmicrohttpd \ - -lgnunetutil \ - -lgnunetjson \ - -ljansson \ - -lz \ - -lpthread + taler-twister -if HAVE_DEVELOPER -taler_exchange_httpd_SOURCES += \ - taler-exchange-httpd_test.c taler-exchange-httpd_test.h -endif - -check_SCRIPTS = \ - test_taler_exchange_httpd.sh - -if HAVE_EXPENSIVE_TESTS -check_SCRIPTS += \ - test_taler_exchange_httpd_afl.sh -endif - -test_taler_exchange_aggregator_postgres_SOURCES = \ - test_taler_exchange_aggregator.c -test_taler_exchange_aggregator_postgres_LDADD = \ +taler_twister_SOURCES = \ + taler-twister.c +taler_twister_LDADD = \ $(LIBGCRYPT_LIBS) \ - $(top_builddir)/src/exchangedb/libtalerexchangedb.la \ - $(top_builddir)/src/bank-lib/libtalerfakebank.la \ - $(top_builddir)/src/json/libtalerjson.la \ - $(top_builddir)/src/util/libtalerutil.la \ -lmicrohttpd \ - -lgnunetutil \ - -lgnunetjson \ + -lcurl \ -ljansson \ - -lpthread - -test_taler_exchange_wirewatch_postgres_SOURCES = \ - test_taler_exchange_wirewatch.c -test_taler_exchange_wirewatch_postgres_LDADD = \ - $(LIBGCRYPT_LIBS) \ - $(top_builddir)/src/exchangedb/libtalerexchangedb.la \ - $(top_builddir)/src/bank-lib/libtalerfakebank.la \ - $(top_builddir)/src/json/libtalerjson.la \ - $(top_builddir)/src/util/libtalerutil.la \ - -lmicrohttpd \ - -lgnunetutil \ - -lgnunetjson \ - -ljansson \ - -lpthread - -check_PROGRAMS = \ - test_taler_exchange_aggregator-postgres \ - test_taler_exchange_wirewatch-postgres - -AM_TESTS_ENVIRONMENT=export TALER_PREFIX=$${TALER_PREFIX:-@libdir@};export PATH=$${TALER_PREFIX:-@prefix@}/bin:$$PATH; - -TESTS = \ - $(check_SCRIPTS) \ - $(check_PROGRAMS) - - -EXTRA_DIST = \ - test-taler-exchange-aggregator-postgres.conf \ - test-taler-exchange-wirewatch-postgres.conf \ - test_taler_exchange_httpd_home/.local/share/taler/exchange/offline-keys/master.priv \ - test_taler_exchange_httpd.conf \ - exchange.conf \ - $(check_SCRIPTS) + -lgnunetutil diff --git a/src/twister/taler-twister.c b/src/twister/taler-twister.c index bfbe894..9c309b0 100644 --- a/src/twister/taler-twister.c +++ b/src/twister/taler-twister.c @@ -120,18 +120,18 @@ struct HttpResponseHeader /** * A structure for socks requests */ -struct Socks5Request +struct HttpRequest { /** * DLL. */ - struct Socks5Request *next; + struct HttpRequest *next; /** * DLL. */ - struct Socks5Request *prev; + struct HttpRequest *prev; /** * Client socket read task @@ -253,12 +253,12 @@ static struct GNUNET_SCHEDULER_Task *httpd_task; /** * DLL of active socks requests. */ -static struct Socks5Request *s5r_head; +static struct HttpRequest *hr_head; /** * DLL of active socks requests. */ -static struct Socks5Request *s5r_tail; +static struct HttpRequest *hr_tail; /** * Response we return on cURL failures. @@ -293,7 +293,7 @@ curl_download_prepare (); * MHD whenever MHD expects to get data back. Copies data from the * io_buf, if available. * - * @param cls closure with our `struct Socks5Request` + * @param cls closure with our `struct HttpRequest` * @param pos in buffer * @param buf where to copy data * @param max available space in @a buf @@ -305,11 +305,11 @@ mhd_content_cb (void *cls, char* buf, size_t max) { - struct Socks5Request *s5r = cls; + struct HttpRequest *hr = cls; size_t bytes_to_copy; - if ( (SOCKS5_SOCKET_UPLOAD_STARTED == s5r->state) || - (SOCKS5_SOCKET_UPLOAD_DONE == s5r->state) ) + if ( (SOCKS5_SOCKET_UPLOAD_STARTED == hr->state) || + (SOCKS5_SOCKET_UPLOAD_DONE == hr->state) ) { /* we're still not done with the upload, do not yet start the download, the IO buffer is still full @@ -319,35 +319,35 @@ mhd_content_cb (void *cls, return 0; /* not yet ready for data download */ } bytes_to_copy = GNUNET_MIN (max, - s5r->io_len); + hr->io_len); if ( (0 == bytes_to_copy) && - (SOCKS5_SOCKET_DOWNLOAD_DONE != s5r->state) ) + (SOCKS5_SOCKET_DOWNLOAD_DONE != hr->state) ) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Pausing MHD download, no data available\n"); - if (NULL != s5r->curl) + if (NULL != hr->curl) { - curl_easy_pause (s5r->curl, CURLPAUSE_CONT); + curl_easy_pause (hr->curl, CURLPAUSE_CONT); curl_download_prepare (); } return 0; /* more data later */ } if ( (0 == bytes_to_copy) && - (SOCKS5_SOCKET_DOWNLOAD_DONE == s5r->state) ) + (SOCKS5_SOCKET_DOWNLOAD_DONE == hr->state) ) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Completed MHD download\n"); return MHD_CONTENT_READER_END_OF_STREAM; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Writing %lu/%lu bytes\n", bytes_to_copy, s5r->io_len); - GNUNET_memcpy (buf, s5r->io_buf, bytes_to_copy); - memmove (s5r->io_buf, - &s5r->io_buf[bytes_to_copy], - s5r->io_len - bytes_to_copy); - s5r->io_len -= bytes_to_copy; - if (NULL != s5r->curl) - curl_easy_pause (s5r->curl, CURLPAUSE_CONT); + "Writing %lu/%lu bytes\n", bytes_to_copy, hr->io_len); + GNUNET_memcpy (buf, hr->io_buf, bytes_to_copy); + memmove (hr->io_buf, + &hr->io_buf[bytes_to_copy], + hr->io_len - bytes_to_copy); + hr->io_len -= bytes_to_copy; + if (NULL != hr->curl) + curl_easy_pause (hr->curl, CURLPAUSE_CONT); return bytes_to_copy; } @@ -360,13 +360,13 @@ mhd_content_cb (void *cls, * @param buffer curl buffer with a single line of header data; not 0-terminated! * @param size curl blocksize * @param nmemb curl blocknumber - * @param cls our `struct Socks5Request *` + * @param cls our `struct HttpRequest *` * @return size of processed bytes */ static size_t curl_check_hdr (void *buffer, size_t size, size_t nmemb, void *cls) { - struct Socks5Request *s5r = cls; + struct HttpRequest *hr = cls; struct HttpResponseHeader *header; size_t bytes = size * nmemb; char *ndup; @@ -381,10 +381,10 @@ curl_check_hdr (void *buffer, size_t size, size_t nmemb, void *cls) char *tok; /* first, check SSL certificate */ - if ((GNUNET_YES != s5r->ssl_checked) && - (HTTPS_PORT == s5r->port)) + if ((GNUNET_YES != hr->ssl_checked) && + (HTTPS_PORT == hr->port)) { - if (GNUNET_OK != check_ssl_certificate (s5r)) + if (GNUNET_OK != check_ssl_certificate (hr)) return 0; } @@ -407,13 +407,13 @@ curl_check_hdr (void *buffer, size_t size, size_t nmemb, void *cls) /* custom logic for certain header types */ #if 0 new_cookie_hdr = NULL; - if ( (NULL != s5r->leho) && + if ( (NULL != hr->leho) && (0 == strcasecmp (hdr_type, MHD_HTTP_HEADER_SET_COOKIE)) ) { new_cookie_hdr = GNUNET_malloc (strlen (hdr_val) + - strlen (s5r->domain) + 1); + strlen (hr->domain) + 1); offset = 0; domain_matched = GNUNET_NO; /* make sure we match domain at most once */ for (tok = strtok (hdr_val, ";"); NULL != tok; tok = strtok (NULL, ";")) @@ -423,22 +423,22 @@ curl_check_hdr (void *buffer, size_t size, size_t nmemb, void *cls) { domain_matched = GNUNET_YES; cookie_domain = tok + strlen (" domain") + 1; - if (strlen (cookie_domain) < strlen (s5r->leho)) + if (strlen (cookie_domain) < strlen (hr->leho)) { - delta_cdomain = strlen (s5r->leho) - strlen (cookie_domain); - if (0 == strcasecmp (cookie_domain, s5r->leho + delta_cdomain)) + delta_cdomain = strlen (hr->leho) - strlen (cookie_domain); + if (0 == strcasecmp (cookie_domain, hr->leho + delta_cdomain)) { offset += sprintf (new_cookie_hdr + offset, " domain=%s;", - s5r->domain); + hr->domain); continue; } } - else if (0 == strcmp (cookie_domain, s5r->leho)) + else if (0 == strcmp (cookie_domain, hr->leho)) { offset += sprintf (new_cookie_hdr + offset, " domain=%s;", - s5r->domain); + hr->domain); continue; } GNUNET_log (GNUNET_ERROR_TYPE_WARNING, @@ -458,20 +458,20 @@ curl_check_hdr (void *buffer, size_t size, size_t nmemb, void *cls) char *leho_host; GNUNET_asprintf (&leho_host, - (HTTPS_PORT != s5r->port) + (HTTPS_PORT != hr->port) ? "http://%s" : "https://%s", - s5r->leho); + hr->leho); if (0 == strncmp (leho_host, hdr_val, strlen (leho_host))) { GNUNET_asprintf (&new_location, "%s%s%s", - (HTTPS_PORT != s5r->port) + (HTTPS_PORT != hr->port) ? "http://" : "https://", - s5r->domain, + hr->domain, hdr_val + strlen (leho_host)); hdr_val = new_location; } @@ -494,8 +494,8 @@ curl_check_hdr (void *buffer, size_t size, size_t nmemb, void *cls) header = GNUNET_new (struct HttpResponseHeader); header->type = GNUNET_strndup (hdr_type, strlen (hdr_type)); header->value = GNUNET_strndup (hdr_val, strlen (hdr_val)); - GNUNET_CONTAINER_DLL_insert (s5r->header_head, - s5r->header_tail, + GNUNET_CONTAINER_DLL_insert (hr->header_head, + hr->header_tail, header); } GNUNET_free (ndup); @@ -506,13 +506,13 @@ curl_check_hdr (void *buffer, size_t size, size_t nmemb, void *cls) static int -create_mhd_response_from_s5r (struct Socks5Request *s5r) +create_mhd_response_from_hr (struct HttpRequest *hr) { long resp_code; double content_length; struct HttpResponseHeader *header; - if (NULL != s5r->response) + if (NULL != hr->response) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Response already set!\n"); @@ -520,42 +520,42 @@ create_mhd_response_from_s5r (struct Socks5Request *s5r) } GNUNET_break (CURLE_OK == - curl_easy_getinfo (s5r->curl, + curl_easy_getinfo (hr->curl, CURLINFO_RESPONSE_CODE, &resp_code)); GNUNET_break (CURLE_OK == - curl_easy_getinfo (s5r->curl, + curl_easy_getinfo (hr->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &content_length)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating MHD response with code %d and size %d\n", (int) resp_code, (int) content_length); - s5r->response_code = resp_code; - s5r->response = MHD_create_response_from_callback ((-1 == content_length) ? MHD_SIZE_UNKNOWN : content_length, + hr->response_code = resp_code; + hr->response = MHD_create_response_from_callback ((-1 == content_length) ? MHD_SIZE_UNKNOWN : content_length, IO_BUFFERSIZE, &mhd_content_cb, - s5r, + hr, NULL); - for (header = s5r->header_head; NULL != header; header = header->next) + for (header = hr->header_head; NULL != header; header = header->next) { GNUNET_break (MHD_YES == - MHD_add_response_header (s5r->response, + MHD_add_response_header (hr->response, header->type, header->value)); } - if (NULL != s5r->leho) + if (NULL != hr->leho) { char *cors_hdr; GNUNET_asprintf (&cors_hdr, - (HTTPS_PORT == s5r->port) + (HTTPS_PORT == hr->port) ? "https://%s" : "http://%s", - s5r->leho); + hr->leho); GNUNET_break (MHD_YES == - MHD_add_response_header (s5r->response, + MHD_add_response_header (hr->response, MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN, cors_hdr)); GNUNET_free (cors_hdr); @@ -563,7 +563,7 @@ create_mhd_response_from_s5r (struct Socks5Request *s5r) /* force connection to be closed after each request, as we do not support HTTP pipelining (yet, FIXME!) */ /*GNUNET_break (MHD_YES == - MHD_add_response_header (s5r->response, + MHD_add_response_header (hr->response, MHD_HTTP_HEADER_CONNECTION, "close"));*/ return GNUNET_OK; @@ -576,20 +576,20 @@ create_mhd_response_from_s5r (struct Socks5Request *s5r) * @param ptr pointer to the data * @param size number of blocks of data * @param nmemb blocksize - * @param ctx our `struct Socks5Request *` + * @param ctx our `struct HttpRequest *` * @return number of bytes handled */ static size_t curl_download_cb (void *ptr, size_t size, size_t nmemb, void* ctx) { - struct Socks5Request *s5r = ctx; + struct HttpRequest *hr = ctx; size_t total = size * nmemb; - if (NULL == s5r->response) - GNUNET_assert (GNUNET_OK == create_mhd_response_from_s5r (s5r)); + if (NULL == hr->response) + GNUNET_assert (GNUNET_OK == create_mhd_response_from_hr (hr)); - if ( (SOCKS5_SOCKET_UPLOAD_STARTED == s5r->state) || - (SOCKS5_SOCKET_UPLOAD_DONE == s5r->state) ) + if ( (SOCKS5_SOCKET_UPLOAD_STARTED == hr->state) || + (SOCKS5_SOCKET_UPLOAD_DONE == hr->state) ) { /* we're still not done with the upload, do not yet start the download, the IO buffer is still full @@ -598,19 +598,19 @@ curl_download_cb (void *ptr, size_t size, size_t nmemb, void* ctx) "Pausing CURL download, waiting for UPLOAD to finish\n"); return CURL_WRITEFUNC_PAUSE; /* not yet ready for data download */ } - if (sizeof (s5r->io_buf) - s5r->io_len < total) + if (sizeof (hr->io_buf) - hr->io_len < total) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Pausing CURL download, not enough space %lu %lu %lu\n", sizeof (s5r->io_buf), - s5r->io_len, total); + "Pausing CURL download, not enough space %lu %lu %lu\n", sizeof (hr->io_buf), + hr->io_len, total); return CURL_WRITEFUNC_PAUSE; /* not enough space */ } - GNUNET_memcpy (&s5r->io_buf[s5r->io_len], + GNUNET_memcpy (&hr->io_buf[hr->io_len], ptr, total); - s5r->io_len += total; - if (s5r->io_len == total) - run_mhd_now (s5r->hd); + hr->io_len += total; + if (hr->io_len == total) + run_mhd_now (hr->hd); return total; } @@ -622,46 +622,46 @@ curl_download_cb (void *ptr, size_t size, size_t nmemb, void* ctx) * @param buf where to write the data * @param size number of bytes per member * @param nmemb number of members available in @a buf - * @param cls our `struct Socks5Request` that generated the data + * @param cls our `struct HttpRequest` that generated the data * @return number of bytes copied to @a buf */ static size_t curl_upload_cb (void *buf, size_t size, size_t nmemb, void *cls) { - struct Socks5Request *s5r = cls; + struct HttpRequest *hr = cls; size_t len = size * nmemb; size_t to_copy; - if ( (0 == s5r->io_len) && - (SOCKS5_SOCKET_UPLOAD_DONE != s5r->state) ) + if ( (0 == hr->io_len) && + (SOCKS5_SOCKET_UPLOAD_DONE != hr->state) ) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Pausing CURL UPLOAD, need more data\n"); return CURL_READFUNC_PAUSE; } - if ( (0 == s5r->io_len) && - (SOCKS5_SOCKET_UPLOAD_DONE == s5r->state) ) + if ( (0 == hr->io_len) && + (SOCKS5_SOCKET_UPLOAD_DONE == hr->state) ) { - s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; + hr->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Completed CURL UPLOAD\n"); return 0; /* upload finished, can now download */ } - if ( (SOCKS5_SOCKET_UPLOAD_STARTED != s5r->state) && - (SOCKS5_SOCKET_UPLOAD_DONE != s5r->state) ) + if ( (SOCKS5_SOCKET_UPLOAD_STARTED != hr->state) && + (SOCKS5_SOCKET_UPLOAD_DONE != hr->state) ) { GNUNET_break (0); return CURL_READFUNC_ABORT; } - to_copy = GNUNET_MIN (s5r->io_len, + to_copy = GNUNET_MIN (hr->io_len, len); - GNUNET_memcpy (buf, s5r->io_buf, to_copy); - memmove (s5r->io_buf, - &s5r->io_buf[to_copy], - s5r->io_len - to_copy); - s5r->io_len -= to_copy; - if (s5r->io_len + to_copy == sizeof (s5r->io_buf)) - run_mhd_now (s5r->hd); /* got more space for upload now */ + GNUNET_memcpy (buf, hr->io_buf, to_copy); + memmove (hr->io_buf, + &hr->io_buf[to_copy], + hr->io_len - to_copy); + hr->io_len -= to_copy; + if (hr->io_len + to_copy == sizeof (hr->io_buf)) + run_mhd_now (hr->hd); /* got more space for upload now */ return to_copy; } @@ -752,7 +752,7 @@ curl_task_download (void *cls) int msgnum; struct CURLMsg *msg; CURLMcode mret; - struct Socks5Request *s5r; + struct HttpRequest *hr; curl_download_task = NULL; do @@ -764,8 +764,8 @@ curl_task_download (void *cls) GNUNET_break (CURLE_OK == curl_easy_getinfo (msg->easy_handle, CURLINFO_PRIVATE, - (char **) &s5r )); - if (NULL == s5r) + (char **) &hr )); + if (NULL == hr) { GNUNET_break (0); continue; @@ -783,22 +783,22 @@ curl_task_download (void *cls) case CURLE_GOT_NOTHING: GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CURL download completed.\n"); - if (NULL == s5r->response) - GNUNET_assert (GNUNET_OK == create_mhd_response_from_s5r (s5r)); - s5r->state = SOCKS5_SOCKET_DOWNLOAD_DONE; - run_mhd_now (s5r->hd); + if (NULL == hr->response) + GNUNET_assert (GNUNET_OK == create_mhd_response_from_hr (hr)); + hr->state = SOCKS5_SOCKET_DOWNLOAD_DONE; + run_mhd_now (hr->hd); break; default: GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Download curl failed: %s\n", curl_easy_strerror (msg->data.result)); /* FIXME: indicate error somehow? close MHD connection badly as well? */ - s5r->state = SOCKS5_SOCKET_DOWNLOAD_DONE; - run_mhd_now (s5r->hd); + hr->state = SOCKS5_SOCKET_DOWNLOAD_DONE; + run_mhd_now (hr->hd); break; } - if (NULL == s5r->response) - s5r->response = curl_failure_response; + if (NULL == hr->response) + hr->response = curl_failure_response; break; case CURLMSG_LAST: /* documentation says this is not used */ @@ -836,7 +836,7 @@ curl_task_download (void *cls) * 'Connection' header value to "close" as the proxy does not support * pipelining. * - * @param cls our `struct Socks5Request` + * @param cls our `struct HttpRequest` * @param kind value kind * @param key field key * @param value field value @@ -848,12 +848,12 @@ con_val_iter (void *cls, const char *key, const char *value) { - struct Socks5Request *s5r = cls; + struct HttpRequest *hr = cls; char *hdr; if ( (0 == strcasecmp (MHD_HTTP_HEADER_HOST, key)) && - (NULL != s5r->leho) ) - value = s5r->leho; + (NULL != hr->leho) ) + value = hr->leho; if (0 == strcasecmp (MHD_HTTP_HEADER_CONTENT_LENGTH, key)) return MHD_YES; if (0 == strcasecmp (MHD_HTTP_HEADER_ACCEPT_ENCODING, key)) @@ -865,7 +865,7 @@ con_val_iter (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding HEADER `%s' to HTTP request\n", hdr); - s5r->headers = curl_slist_append (s5r->headers, + hr->headers = curl_slist_append (hr->headers, hdr); GNUNET_free (hdr); return MHD_YES; @@ -905,7 +905,7 @@ create_response (void *cls, size_t *upload_data_size, void **con_cls) { - struct Socks5Request *s5r = *con_cls; + struct HttpRequest *hr = *con_cls; char *curlurl; char *curl_hosts; char ipstring[INET6_ADDRSTRLEN]; @@ -916,20 +916,20 @@ create_response (void *cls, uint16_t port; size_t left; - if (NULL == s5r) + if (NULL == hr) { GNUNET_break (0); return MHD_NO; } //Fresh connection. - if (SOCKS5_SOCKET_WITH_MHD == s5r->state) + if (SOCKS5_SOCKET_WITH_MHD == hr->state) { /* first time here, initialize curl handle */ - sa = (const struct sockaddr *) &s5r->destination_address; + sa = (const struct sockaddr *) &hr->destination_address; switch (sa->sa_family) { case AF_INET: - s4 = (const struct sockaddr_in *) &s5r->destination_address; + s4 = (const struct sockaddr_in *) &hr->destination_address; if (NULL == inet_ntop (AF_INET, &s4->sin_addr, ipstring, @@ -945,7 +945,7 @@ create_response (void *cls, port = ntohs (s4->sin_port); break; case AF_INET6: - s6 = (const struct sockaddr_in6 *) &s5r->destination_address; + s6 = (const struct sockaddr_in6 *) &hr->destination_address; if (NULL == inet_ntop (AF_INET6, &s6->sin6_addr, ipstring, @@ -964,138 +964,138 @@ create_response (void *cls, GNUNET_break (0); return MHD_NO; } - if (NULL == s5r->curl) - s5r->curl = curl_easy_init (); - if (NULL == s5r->curl) + if (NULL == hr->curl) + hr->curl = curl_easy_init (); + if (NULL == hr->curl) return MHD_queue_response (con, MHD_HTTP_INTERNAL_SERVER_ERROR, curl_failure_response); - curl_easy_setopt (s5r->curl, CURLOPT_HEADERFUNCTION, &curl_check_hdr); - curl_easy_setopt (s5r->curl, CURLOPT_HEADERDATA, s5r); - curl_easy_setopt (s5r->curl, CURLOPT_FOLLOWLOCATION, 0); - curl_easy_setopt (s5r->curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); - curl_easy_setopt (s5r->curl, CURLOPT_CONNECTTIMEOUT, 600L); - curl_easy_setopt (s5r->curl, CURLOPT_TIMEOUT, 600L); - curl_easy_setopt (s5r->curl, CURLOPT_NOSIGNAL, 1L); - curl_easy_setopt (s5r->curl, CURLOPT_HTTP_CONTENT_DECODING, 0); - curl_easy_setopt (s5r->curl, CURLOPT_HTTP_TRANSFER_DECODING, 0); - curl_easy_setopt (s5r->curl, CURLOPT_NOSIGNAL, 1L); - curl_easy_setopt (s5r->curl, CURLOPT_PRIVATE, s5r); - curl_easy_setopt (s5r->curl, CURLOPT_VERBOSE, 0); + curl_easy_setopt (hr->curl, CURLOPT_HEADERFUNCTION, &curl_check_hdr); + curl_easy_setopt (hr->curl, CURLOPT_HEADERDATA, hr); + curl_easy_setopt (hr->curl, CURLOPT_FOLLOWLOCATION, 0); + curl_easy_setopt (hr->curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); + curl_easy_setopt (hr->curl, CURLOPT_CONNECTTIMEOUT, 600L); + curl_easy_setopt (hr->curl, CURLOPT_TIMEOUT, 600L); + curl_easy_setopt (hr->curl, CURLOPT_NOSIGNAL, 1L); + curl_easy_setopt (hr->curl, CURLOPT_HTTP_CONTENT_DECODING, 0); + curl_easy_setopt (hr->curl, CURLOPT_HTTP_TRANSFER_DECODING, 0); + curl_easy_setopt (hr->curl, CURLOPT_NOSIGNAL, 1L); + curl_easy_setopt (hr->curl, CURLOPT_PRIVATE, hr); + curl_easy_setopt (hr->curl, CURLOPT_VERBOSE, 0); /** * Pre-populate cache to resolve Hostname. * This is necessary as the DNS name in the CURLOPT_URL is used * for SNI http://de.wikipedia.org/wiki/Server_Name_Indication */ - if (NULL != s5r->leho) + if (NULL != hr->leho) { GNUNET_asprintf (&curl_hosts, "%s:%d:%s", - s5r->leho, + hr->leho, port, ipaddr); - s5r->hosts = curl_slist_append(NULL, curl_hosts); - curl_easy_setopt(s5r->curl, CURLOPT_RESOLVE, s5r->hosts); + hr->hosts = curl_slist_append(NULL, curl_hosts); + curl_easy_setopt(hr->curl, CURLOPT_RESOLVE, hr->hosts); GNUNET_free (curl_hosts); } GNUNET_asprintf (&curlurl, - (HTTPS_PORT != s5r->port) + (HTTPS_PORT != hr->port) ? "http://%s:%d%s" : "https://%s:%d%s", - (NULL != s5r->leho) - ? s5r->leho + (NULL != hr->leho) + ? hr->leho : ipaddr, port, - s5r->url); - curl_easy_setopt (s5r->curl, + hr->url); + curl_easy_setopt (hr->curl, CURLOPT_URL, curlurl); GNUNET_free (curlurl); if (0 == strcasecmp (meth, MHD_HTTP_METHOD_PUT)) { - s5r->state = SOCKS5_SOCKET_UPLOAD_STARTED; - curl_easy_setopt (s5r->curl, CURLOPT_UPLOAD, 1); - curl_easy_setopt (s5r->curl, CURLOPT_WRITEFUNCTION, &curl_download_cb); - curl_easy_setopt (s5r->curl, CURLOPT_WRITEDATA, s5r); - curl_easy_setopt (s5r->curl, CURLOPT_READFUNCTION, &curl_upload_cb); - curl_easy_setopt (s5r->curl, CURLOPT_READDATA, s5r); + hr->state = SOCKS5_SOCKET_UPLOAD_STARTED; + curl_easy_setopt (hr->curl, CURLOPT_UPLOAD, 1); + curl_easy_setopt (hr->curl, CURLOPT_WRITEFUNCTION, &curl_download_cb); + curl_easy_setopt (hr->curl, CURLOPT_WRITEDATA, hr); + curl_easy_setopt (hr->curl, CURLOPT_READFUNCTION, &curl_upload_cb); + curl_easy_setopt (hr->curl, CURLOPT_READDATA, hr); } else if (0 == strcasecmp (meth, MHD_HTTP_METHOD_POST)) { - s5r->state = SOCKS5_SOCKET_UPLOAD_STARTED; - curl_easy_setopt (s5r->curl, CURLOPT_POST, 1L); - curl_easy_setopt (s5r->curl, CURLOPT_WRITEFUNCTION, &curl_download_cb); - curl_easy_setopt (s5r->curl, CURLOPT_WRITEDATA, s5r); - curl_easy_setopt (s5r->curl, CURLOPT_READFUNCTION, &curl_upload_cb); - curl_easy_setopt (s5r->curl, CURLOPT_READDATA, s5r); + hr->state = SOCKS5_SOCKET_UPLOAD_STARTED; + curl_easy_setopt (hr->curl, CURLOPT_POST, 1L); + curl_easy_setopt (hr->curl, CURLOPT_WRITEFUNCTION, &curl_download_cb); + curl_easy_setopt (hr->curl, CURLOPT_WRITEDATA, hr); + curl_easy_setopt (hr->curl, CURLOPT_READFUNCTION, &curl_upload_cb); + curl_easy_setopt (hr->curl, CURLOPT_READDATA, hr); } else if (0 == strcasecmp (meth, MHD_HTTP_METHOD_HEAD)) { - s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; - curl_easy_setopt (s5r->curl, CURLOPT_NOBODY, 1); + hr->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; + curl_easy_setopt (hr->curl, CURLOPT_NOBODY, 1); } else if (0 == strcasecmp (meth, MHD_HTTP_METHOD_OPTIONS)) { - s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; - curl_easy_setopt (s5r->curl, CURLOPT_CUSTOMREQUEST, "OPTIONS"); + hr->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; + curl_easy_setopt (hr->curl, CURLOPT_CUSTOMREQUEST, "OPTIONS"); } else if (0 == strcasecmp (meth, MHD_HTTP_METHOD_GET)) { - s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; - curl_easy_setopt (s5r->curl, CURLOPT_HTTPGET, 1); - curl_easy_setopt (s5r->curl, CURLOPT_WRITEFUNCTION, &curl_download_cb); - curl_easy_setopt (s5r->curl, CURLOPT_WRITEDATA, s5r); + hr->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; + curl_easy_setopt (hr->curl, CURLOPT_HTTPGET, 1); + curl_easy_setopt (hr->curl, CURLOPT_WRITEFUNCTION, &curl_download_cb); + curl_easy_setopt (hr->curl, CURLOPT_WRITEDATA, hr); } else { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Unsupported HTTP method `%s'\n"), meth); - curl_easy_cleanup (s5r->curl); - s5r->curl = NULL; + curl_easy_cleanup (hr->curl); + hr->curl = NULL; return MHD_NO; } if (0 == strcasecmp (ver, MHD_HTTP_VERSION_1_0)) { - curl_easy_setopt (s5r->curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); + curl_easy_setopt (hr->curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); } else if (0 == strcasecmp (ver, MHD_HTTP_VERSION_1_1)) { - curl_easy_setopt (s5r->curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); + curl_easy_setopt (hr->curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); } else { - curl_easy_setopt (s5r->curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_NONE); + curl_easy_setopt (hr->curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_NONE); } - if (HTTPS_PORT == s5r->port) + if (HTTPS_PORT == hr->port) { - curl_easy_setopt (s5r->curl, CURLOPT_USE_SSL, CURLUSESSL_ALL); - if (NULL != s5r->dane_data) - curl_easy_setopt (s5r->curl, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt (hr->curl, CURLOPT_USE_SSL, CURLUSESSL_ALL); + if (NULL != hr->dane_data) + curl_easy_setopt (hr->curl, CURLOPT_SSL_VERIFYPEER, 0L); else - curl_easy_setopt (s5r->curl, CURLOPT_SSL_VERIFYPEER, 1L); + curl_easy_setopt (hr->curl, CURLOPT_SSL_VERIFYPEER, 1L); /* Disable cURL checking the hostname, as we will check ourselves as only we have the domain name or the LEHO or the DANE record */ - curl_easy_setopt (s5r->curl, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt (hr->curl, CURLOPT_SSL_VERIFYHOST, 0L); } else { - curl_easy_setopt (s5r->curl, CURLOPT_USE_SSL, CURLUSESSL_NONE); + curl_easy_setopt (hr->curl, CURLOPT_USE_SSL, CURLUSESSL_NONE); } - if (CURLM_OK != curl_multi_add_handle (curl_multi, s5r->curl)) + if (CURLM_OK != curl_multi_add_handle (curl_multi, hr->curl)) { GNUNET_break (0); - curl_easy_cleanup (s5r->curl); - s5r->curl = NULL; + curl_easy_cleanup (hr->curl); + hr->curl = NULL; return MHD_NO; } MHD_get_connection_values (con, MHD_HEADER_KIND, - &con_val_iter, s5r); - curl_easy_setopt (s5r->curl, CURLOPT_HTTPHEADER, s5r->headers); + &con_val_iter, hr); + curl_easy_setopt (hr->curl, CURLOPT_HTTPHEADER, hr->headers); curl_download_prepare (); return MHD_YES; } @@ -1111,33 +1111,33 @@ create_response (void *cls, /* FIXME: This must be set or a header with Transfer-Encoding: chunked. Else * upload callback is not called! */ - curl_easy_setopt (s5r->curl, CURLOPT_POSTFIELDSIZE, *upload_data_size); + curl_easy_setopt (hr->curl, CURLOPT_POSTFIELDSIZE, *upload_data_size); left = GNUNET_MIN (*upload_data_size, - sizeof (s5r->io_buf) - s5r->io_len); - GNUNET_memcpy (&s5r->io_buf[s5r->io_len], + sizeof (hr->io_buf) - hr->io_len); + GNUNET_memcpy (&hr->io_buf[hr->io_len], upload_data, left); - s5r->io_len += left; + hr->io_len += left; *upload_data_size -= left; - GNUNET_assert (NULL != s5r->curl); - curl_easy_pause (s5r->curl, CURLPAUSE_CONT); + GNUNET_assert (NULL != hr->curl); + curl_easy_pause (hr->curl, CURLPAUSE_CONT); return MHD_YES; } - if (SOCKS5_SOCKET_UPLOAD_STARTED == s5r->state) + if (SOCKS5_SOCKET_UPLOAD_STARTED == hr->state) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished processing UPLOAD\n"); - s5r->state = SOCKS5_SOCKET_UPLOAD_DONE; + hr->state = SOCKS5_SOCKET_UPLOAD_DONE; } - if (NULL == s5r->response) + if (NULL == hr->response) return MHD_YES; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Queueing response with MHD\n"); - run_mhd_now (s5r->hd); + run_mhd_now (hr->hd); return MHD_queue_response (con, - s5r->response_code, - s5r->response); + hr->response_code, + hr->response); } @@ -1150,7 +1150,7 @@ create_response (void *cls, * @param cls NULL * @param connection connection handle * @param con_cls value as set by the last call to - * the MHD_AccessHandlerCallback, should be our `struct Socks5Request *` + * the MHD_AccessHandlerCallback, should be our `struct HttpRequest *` * @param toe reason for request termination (ignored) */ static void @@ -1159,35 +1159,35 @@ mhd_completed_cb (void *cls, void **con_cls, enum MHD_RequestTerminationCode toe) { - struct Socks5Request *s5r = *con_cls; + struct HttpRequest *hr = *con_cls; struct HttpResponseHeader *header; - if (NULL == s5r) + if (NULL == hr) return; if (MHD_REQUEST_TERMINATED_COMPLETED_OK != toe) GNUNET_log (GNUNET_ERROR_TYPE_INFO, "MHD encountered error handling request: %d\n", toe); - if (NULL != s5r->curl) + if (NULL != hr->curl) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Resetting cURL handle\n"); curl_multi_remove_handle (curl_multi, - s5r->curl); - curl_slist_free_all (s5r->headers); - s5r->headers = NULL; - curl_easy_reset (s5r->curl); - s5r->rbuf_len = 0; - s5r->wbuf_len = 0; - s5r->io_len = 0; + hr->curl); + curl_slist_free_all (hr->headers); + hr->headers = NULL; + curl_easy_reset (hr->curl); + hr->rbuf_len = 0; + hr->wbuf_len = 0; + hr->io_len = 0; } - if ( (NULL != s5r->response) && - (curl_failure_response != s5r->response) ) - MHD_destroy_response (s5r->response); - for (header = s5r->header_head; header != NULL; header = s5r->header_head) + if ( (NULL != hr->response) && + (curl_failure_response != hr->response) ) + MHD_destroy_response (hr->response); + for (header = hr->header_head; header != NULL; header = hr->header_head) { - GNUNET_CONTAINER_DLL_remove (s5r->header_head, - s5r->header_tail, + GNUNET_CONTAINER_DLL_remove (hr->header_head, + hr->header_tail, header); GNUNET_free (header->type); GNUNET_free (header->value); @@ -1195,9 +1195,9 @@ mhd_completed_cb (void *cls, } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished request for %s\n", - s5r->url); - GNUNET_free (s5r->url); - GNUNET_free (s5r); + hr->url); + GNUNET_free (hr->url); + GNUNET_free (hr); *con_cls = NULL; } @@ -1207,20 +1207,20 @@ mhd_completed_cb (void *cls, * Gives us the respective URI information. * * We use this to associate the `struct MHD_Connection` with our - * internal `struct Socks5Request` data structure (by checking + * internal `struct HttpRequest` data structure (by checking * for matching sockets). * * @param cls the HTTP server handle (a `struct MhdHttpList`) * @param url the URL that is being requested * @param connection MHD connection object for the request - * @return the `struct Socks5Request` that this @a connection is for + * @return the `struct HttpRequest` that this @a connection is for */ static void * mhd_log_callback (void *cls, const char *url, struct MHD_Connection *connection) { - struct Socks5Request *s5r; + struct HttpRequest *hr; const union MHD_ConnectionInfo *ci; ci = MHD_get_connection_info (connection, @@ -1234,9 +1234,9 @@ mhd_log_callback (void *cls, return NULL; } - s5r = GNUNET_new (struct Socks5Request); - s5r->url = GNUNET_strdup (url); - return s5r; + hr = GNUNET_new (struct HttpRequest); + hr->url = GNUNET_strdup (url); + return hr; } |