pass query string to the gopher selector too - gopherproxy-c - Gopher HTTP prox… | |
git clone git://git.codemadness.org/gopherproxy-c | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 1d29587a28d81e13a3a7f4f3712dd408ce5726e0 | |
parent 78efc56f91b0956fe6e2dcc7919a4dcd64dfe66a | |
Author: Hiltjo Posthuma <[email protected]> | |
Date: Sun, 26 Feb 2023 16:11:26 +0100 | |
pass query string to the gopher selector too | |
This allows path?something which is useful in CGI programs. | |
Diffstat: | |
M gopherproxy.c | 22 +++++++++++----------- | |
1 file changed, 11 insertions(+), 11 deletions(-) | |
--- | |
diff --git a/gopherproxy.c b/gopherproxy.c | |
@@ -181,7 +181,7 @@ typestr(int c) | |
} | |
void | |
-servefile(const char *server, const char *port, const char *path) | |
+servefile(const char *server, const char *port, const char *path, const char *… | |
{ | |
char buf[1024]; | |
int r, w, fd; | |
@@ -192,7 +192,7 @@ servefile(const char *server, const char *port, const char … | |
if (pledge("stdio", NULL) == -1) | |
die(500, "pledge: %s\n", strerror(errno)); | |
- if ((w = dprintf(fd, "%s\r\n", path)) == -1) | |
+ if ((w = dprintf(fd, "%s%s%s\r\n", path, query[0] ? "?" : "", query)) … | |
die(500, "dprintf: %s\n", strerror(errno)); | |
while ((r = read(fd, buf, sizeof(buf))) > 0) { | |
@@ -212,7 +212,7 @@ servefile(const char *server, const char *port, const char … | |
} | |
void | |
-servedir(const char *server, const char *port, const char *path, const char *p… | |
+servedir(const char *server, const char *port, const char *path, const char *q… | |
{ | |
struct visited v; | |
FILE *fp; | |
@@ -227,9 +227,9 @@ servedir(const char *server, const char *port, const char *… | |
die(500, "pledge: %s\n", strerror(errno)); | |
if (param[0]) | |
- r = dprintf(fd, "%s\t%s\r\n", path, param); | |
+ r = dprintf(fd, "%s%s%s\t%s\r\n", path, query[0] ? "?" : "", q… | |
else | |
- r = dprintf(fd, "%s\r\n", path); | |
+ r = dprintf(fd, "%s%s%s\r\n", path, query[0] ? "?" : "", query… | |
if (r == -1) | |
die(500, "write: %s\n", strerror(errno)); | |
@@ -653,11 +653,11 @@ main(void) | |
break; /* handled below */ | |
case '0': | |
dprintf(1, "Content-Type: text/plain; charset=utf-8\r\… | |
- servefile(u.host, u.port, path); | |
+ servefile(u.host, u.port, path, u.query); | |
return 0; | |
case 'g': | |
dprintf(1, "Content-Type: image/gif\r\n\r\n"); | |
- servefile(u.host, u.port, path); | |
+ servefile(u.host, u.port, path, u.query); | |
return 0; | |
case 'I': | |
/* try to set Content-Type based on extension */ | |
@@ -671,18 +671,18 @@ main(void) | |
dprintf(1, "Content-Type: image/gif\r\… | |
} | |
write(1, "\r\n", 2); | |
- servefile(u.host, u.port, path); | |
+ servefile(u.host, u.port, path, u.query); | |
return 0; | |
case '9': | |
/* try to detect filename */ | |
if ((p = strrchr(path, '/'))) | |
dprintf(1, "Content-Disposition: attachment; f… | |
dprintf(1, "Content-Type: application/octet-stream\r\n… | |
- servefile(u.host, u.port, path); | |
+ servefile(u.host, u.port, path, u.query); | |
return 0; | |
default: | |
write(1, "\r\n", 2); | |
- servefile(u.host, u.port, path); | |
+ servefile(u.host, u.port, path, u.query); | |
return 0; | |
} | |
} | |
@@ -721,7 +721,7 @@ main(void) | |
if (query[0]) { | |
if (_type != '7') | |
param[0] = '\0'; | |
- servedir(u.host, u.port, path, param); | |
+ servedir(u.host, u.port, path, u.query, param); | |
} | |
fputs("</pre>\n</body>\n</html>\n", stdout); |