diff options
| author | Drew DeVault <sir@cmpwn.com> | 2020-11-01 10:30:35 -0500 |
|---|---|---|
| committer | Drew DeVault <sir@cmpwn.com> | 2020-11-01 10:32:44 -0500 |
| commit | 16e55c62623ef33db5e143126582d93c44ea950e (patch) | |
| tree | 9642b16d19dcae22a9b00e7179016fcd92972457 /src/serve.c | |
| parent | 36e53f1f7f4681edd15fd4925357d6676db6aa8e (diff) | |
| download | gmnisrv-16e55c62623ef33db5e143126582d93c44ea950e.tar.gz gmnisrv-16e55c62623ef33db5e143126582d93c44ea950e.tar.xz gmnisrv-16e55c62623ef33db5e143126582d93c44ea950e.zip | |
Change meaning of root (backwards incompatible!)
This takes the nginx approach to the "root" directive, which is simpler
to implement and more consistent with more complex routing behaviors
like regexp.
The path component of the URL is now simply appended to the root to form
the path to the file which should be served to the client.
Diffstat (limited to 'src/serve.c')
| -rw-r--r-- | src/serve.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/serve.c b/src/serve.c index 9d0bcf3..6d9d87d 100644 --- a/src/serve.c +++ b/src/serve.c @@ -198,8 +198,9 @@ serve_cgi(struct gmnisrv_client *client, const char *path, } static bool -route_match(struct gmnisrv_route *route, const char *path, const char **revised) +route_match(struct gmnisrv_route *route, const char *path, char **revised) { + free(*revised); switch (route->routing) { case ROUTE_PATH:; size_t l = strlen(route->path); @@ -211,11 +212,7 @@ route_match(struct gmnisrv_route *route, const char *path, const char **revised) // route == "/foo": return false; } - if (route->path[l-1] == '/') { - *revised = &path[l-1]; - } else { - *revised = &path[l]; - } + *revised = strdup(path); return true; case ROUTE_REGEX:; int ncapture = lre_get_capture_count(route->regex); @@ -230,8 +227,7 @@ route_match(struct gmnisrv_route *route, const char *path, const char **revised) free(capture); return false; } - // TODO: Process captures and rewrites - *revised = path; + *revised = strdup(path); return true; } @@ -246,7 +242,7 @@ serve_request(struct gmnisrv_client *client) struct gmnisrv_route *route = host->routes; assert(route); - const char *url_path; + char *url_path = NULL; while (route) { if (route_match(route, client->path, &url_path)) { break; @@ -315,6 +311,7 @@ serve_request(struct gmnisrv_client *client) if (S_ISDIR(st.st_mode)) { if (route->autoindex) { serve_autoindex(client, real_path); + free(url_path); return; } else { strncat(real_path, @@ -329,6 +326,7 @@ serve_request(struct gmnisrv_client *client) client_submit_response(client, GEMINI_STATUS_NOT_FOUND, "Not found", NULL); + free(url_path); return; } ssize_t s = readlink(real_path, temp_path, sizeof(temp_path)); @@ -340,10 +338,13 @@ serve_request(struct gmnisrv_client *client) // Don't serve special files client_submit_response(client, GEMINI_STATUS_NOT_FOUND, "Not found", NULL); + free(url_path); return; } } + free(url_path); + if (route->cgi) { serve_cgi(client, real_path, (const char *)client_path, |
