diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/config.c | 2 | ||||
-rw-r--r-- | src/defs.h | 4 | ||||
-rw-r--r-- | src/json.c | 2 | ||||
-rw-r--r-- | src/json.h | 2 | ||||
-rw-r--r-- | src/logger.c | 2 | ||||
-rw-r--r-- | src/main.c | 2 | ||||
-rw-r--r-- | src/mem.c | 2 | ||||
-rw-r--r-- | src/ping903.c | 11 | ||||
-rw-r--r-- | src/ping903.h | 2 | ||||
-rw-r--r-- | src/ping903q.c | 49 | ||||
-rw-r--r-- | src/pinger.c | 4 | ||||
-rw-r--r-- | src/rbt.c | 2 | ||||
-rw-r--r-- | src/remoteip.c | 4 | ||||
-rw-r--r-- | src/strsplit.c | 2 | ||||
-rw-r--r-- | src/wrapacl.c | 2 |
16 files changed, 61 insertions, 33 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index f4fcae3..29b1bd6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,5 +1,5 @@ # This file is part of Ping903 -# Copyright (C) 2020 Sergey Poznyakoff +# Copyright (C) 2020-2023 Sergey Poznyakoff # # Ping903 is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/src/config.c b/src/config.c index 26ec810..51aac27 100644 --- a/src/config.c +++ b/src/config.c @@ -1,5 +1,5 @@ /* This file is part of Ping903 - Copyright (C) 2020 Sergey Poznyakoff + Copyright (C) 2020-2023 Sergey Poznyakoff Ping903 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -1,5 +1,5 @@ /* This file is part of Ping903 - Copyright (C) 2020 Sergey Poznyakoff + Copyright (C) 2020-2023 Sergey Poznyakoff Ping903 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -37,7 +37,7 @@ #define CRED_FILE_NAME ".ping903.cred" #define COPYLEFT "\ -Copyright (C) 2020 Sergey Poznyakoff\n\ +Copyright (C) 2020-2023 Sergey Poznyakoff\n\ License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n\ This is free software: you are free to change and redistribute it.\n\ There is NO WARRANTY, to the extent permitted by law.\n\ @@ -1,5 +1,5 @@ /* This file is part of Ping903 - Copyright (C) 2020 Sergey Poznyakoff + Copyright (C) 2020-2023 Sergey Poznyakoff Ping903 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -1,5 +1,5 @@ /* This file is part of Ping903 - Copyright (C) 2020 Sergey Poznyakoff + Copyright (C) 2020-2023 Sergey Poznyakoff Ping903 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/src/logger.c b/src/logger.c index a2b21cb..3913823 100644 --- a/src/logger.c +++ b/src/logger.c @@ -1,5 +1,5 @@ /* This file is part of Ping903. - Copyright (C) 2020 Sergey Poznyakoff + Copyright (C) 2020-2023 Sergey Poznyakoff Ping903 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -1,5 +1,5 @@ /* This file is part of Ping903 - Copyright (C) 2020 Sergey Poznyakoff + Copyright (C) 2020-2023 Sergey Poznyakoff Ping903 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -1,5 +1,5 @@ /* This file is part of Ping903 - Copyright (C) 2020 Sergey Poznyakoff + Copyright (C) 2020-2023 Sergey Poznyakoff Ping903 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/src/ping903.c b/src/ping903.c index 4ae607b..cd7c1c2 100644 --- a/src/ping903.c +++ b/src/ping903.c @@ -1,5 +1,5 @@ /* This file is part of Ping903 - Copyright (C) 2020 Sergey Poznyakoff + Copyright (C) 2020-2023 Sergey Poznyakoff Ping903 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -1285,6 +1285,15 @@ p903_httpd_handler(void *cls, } } return MHD_YES; + } else if (*con_cls == NULL) { + /* + * According to https://bugs.gnunet.org/view.php?id=7242#c19782, + * MHD_YES must be returned if con_cls points to NULL no matter + * what HTTP method is bieng used. + */ + static int first_time_marker; + *con_cls = &first_time_marker; + return MHD_YES; } /* For all other methods */ diff --git a/src/ping903.h b/src/ping903.h index 2555ddc..0bf6368 100644 --- a/src/ping903.h +++ b/src/ping903.h @@ -1,5 +1,5 @@ /* This file is part of Ping903 - Copyright (C) 2020 Sergey Poznyakoff + Copyright (C) 2020-2023 Sergey Poznyakoff Ping903 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/src/ping903q.c b/src/ping903q.c index 47e2c68..cfec097 100644 --- a/src/ping903q.c +++ b/src/ping903q.c @@ -1,5 +1,5 @@ /* This file is part of Ping903 - Copyright (C) 2020 Sergey Poznyakoff + Copyright (C) 2020-2023 Sergey Poznyakoff Ping903 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -32,6 +32,7 @@ #include "basicauth.h" static char *config_file = DEFAULT_CONFIG_FILE; +struct addrinfo *addr; FILE *http; int verbose; int resolve_ip; @@ -143,31 +144,36 @@ read_listen(char **ret_service) } static void +http_reconnect(void) +{ + int fd; + + fd = socket(addr->ai_family, addr->ai_socktype, 0); + if (fd == -1) + abend("socket: %s", strerror(errno)); + if (connect(fd, (struct sockaddr *)addr->ai_addr, addr->ai_addrlen)) + abend("failed to connect: %s", strerror(errno)); + if (http) + fclose(http); + http = fdopen(fd, "w+"); + if (http == NULL) + abend("failed to open socket: %s", strerror(errno)); +} + +static void http_connect(char *node, char *service) { struct addrinfo hints; - struct addrinfo *res; - int fd; int rc; memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; - rc = getaddrinfo(node, service, &hints, &res); + rc = getaddrinfo(node, service, &hints, &addr); if (rc) abend("%s: %s", node, gai_strerror(rc)); - - fd = socket(res->ai_family, res->ai_socktype, 0); - if (fd == -1) - abend("socket: %s", strerror(errno)); - if (connect(fd, (struct sockaddr *)res->ai_addr, res->ai_addrlen)) - abend("failed to connect to %s:%s: %s", - node, service, strerror(errno)); - http = fdopen(fd, "w+"); - if (http == NULL) - abend("failed to open socket: %s", strerror(errno)); - freeaddrinfo(res); + http_reconnect(); } struct http_resp { @@ -404,6 +410,16 @@ http_recv(struct http_resp *resp) } *p = 0; } + + hval = http_resp_get_header(resp, "connection"); + if (hval) { + if (strcasecmp(hval, "close") == 0) { + fclose(http); + http = NULL; + } else if (strcasecmp(hval, "keep-alive") != 0) { + abend("unsupported Connection: %s", hval); + } + } } static void @@ -412,6 +428,9 @@ http_query_primitive(char const *meth, char const *url, char **hdr) size_t i; int host = 0; + if (!http) + http_reconnect(); + fprintf(http, "%s %s HTTP/1.1\r\n", meth, url); if (hdr) { for (i = 0; hdr[i]; i++) { diff --git a/src/pinger.c b/src/pinger.c index 0674747..a1262b8 100644 --- a/src/pinger.c +++ b/src/pinger.c @@ -1,5 +1,5 @@ /* This file is part of Ping903 - Copyright (C) 2020 Sergey Poznyakoff + Copyright (C) 2020-2023 Sergey Poznyakoff Ping903 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -641,8 +641,8 @@ get_host_matches(struct json_value *ar) if (!(jv = json_new_string("Doesn't resolve")) || json_object_set(obj, "error", jv)) { json_value_free(jv); - errors = 1; } + errors = 1; break; case EAI_MEMORY: @@ -1,5 +1,5 @@ /* Red-black tree support for Ping903 - Copyright (C) 2020 Sergey Poznyakoff + Copyright (C) 2020-2023 Sergey Poznyakoff Ping903 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/src/remoteip.c b/src/remoteip.c index 2966eca..d31ac3b 100644 --- a/src/remoteip.c +++ b/src/remoteip.c @@ -1,5 +1,5 @@ /* This file is part of Ping903 - Copyright (C) 2020 Sergey Poznyakoff + Copyright (C) 2020-2023 Sergey Poznyakoff Ping903 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -383,7 +383,7 @@ get_remote_ip(struct MHD_Connection *conn) hdr = MHD_lookup_connection_value(conn, MHD_HEADER_KIND, - "x-forwarded-from"); + "x-forwarded-for"); if (hdr && (ret = scan_forwarded_header(hdr)) != NULL) return ret; diff --git a/src/strsplit.c b/src/strsplit.c index 3846cbf..9d96b7b 100644 --- a/src/strsplit.c +++ b/src/strsplit.c @@ -1,5 +1,5 @@ /* This file is part of Ping903 - Copyright (C) 2020 Sergey Poznyakoff + Copyright (C) 2020-2023 Sergey Poznyakoff Ping903 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/src/wrapacl.c b/src/wrapacl.c index 27e905c..8a77877 100644 --- a/src/wrapacl.c +++ b/src/wrapacl.c @@ -1,5 +1,5 @@ /* This file is part of Ping903 - Copyright (C) 2020 Sergey Poznyakoff + Copyright (C) 2020-2023 Sergey Poznyakoff Ping903 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by |