geomyidae

A small C-based gopherd. (gopher://bitreich.org/1/scm/geomyidae)
git clone git://r-36.net/geomyidae
Log | Files | Refs | README | LICENSE

commit 244ea008836ed16030d843c157877c4aa8e71a08
parent f4302a23294447764096dbe4ad39bcd67dfe53b6
Author: Christoph Lohmann <20h@r-36.net>
Date:   Sat, 26 Nov 2016 22:54:33 +0100

Adding support for index.cgi and index.dcgi.

Diffstat:
main.c | 25++++++++++++++++++++-----
1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/main.c b/main.c @@ -44,7 +44,7 @@ char *logfile = nil; char *argv0; char *stdbase = "/var/gopher"; char *stdport = "70"; -char *indexf = "/index.gph"; +char *indexf[] = {"/index.gph", "/index.cgi", "/index.dcgi"}; char *err = "3Sorry, but the requested token '%s' could not be found.\tErr" "\tlocalhost\t70\r\n.\r\n\r\n"; char *htredir = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" @@ -131,7 +131,7 @@ handlerequest(int sock, char *base, char *ohost, char *port, char *clienth, { struct stat dir; char recvc[1025], recvb[1025], path[1025], *args, *sear, *c; - int len, fd; + int len, fd, i; filetype *type; memset(&dir, 0, sizeof(dir)); @@ -170,11 +170,26 @@ handlerequest(int sock, char *base, char *ohost, char *port, char *clienth, *args++ = '\0'; securepath(recvb, len - 2); + if(strlen(recvb) == 0) { + recvb[0] = '/'; + recvb[1] = '\0'; + } + snprintf(path, sizeof(path), "%s%s", base, recvb); - if(stat(path, &dir) != -1 && S_ISDIR(dir.st_mode)) - strncat(path, indexf, sizeof(path) - strlen(path)); - fd = open(path, O_RDONLY); + fd = -1; + if(stat(path, &dir) != -1 && S_ISDIR(dir.st_mode)) { + for(i = 0; i < sizeof(indexf)/sizeof(indexf)[0]; i++) { + strncat(path, indexf[i], sizeof(path) - strlen(path)); + fd = open(path, O_RDONLY); + if(fd >= 0) + break; + path[strlen(path)-strlen(indexf[i])] = '\0'; + } + } else { + fd = open(path, O_RDONLY); + } + if(fd >= 0) { close(fd); if(loglvl & FILES)