]> code.citadel.org Git - citadel.git/blobdiff - webcit-ng/request.c
/ctdl/f/ to get a list of all floors
[citadel.git] / webcit-ng / request.c
index 9f6966b2387db55a0561ae4ed9c9a0ae1389df34..f11865bbd3e9209b7f449ded9ce5405fa2f65454 100644 (file)
@@ -4,7 +4,7 @@
 // and pass control back down to the HTTP layer to output the response back to
 // the client.
 //
-// Copyright (c) 1996-2021 by the citadel.org team
+// Copyright (c) 1996-2022 by the citadel.org team
 //
 // This program is open source software.  It runs great on the
 // Linux operating system (and probably elsewhere).  You can use,
@@ -41,9 +41,7 @@ void do_502(struct http_transaction *h) {
        h->response_code = 502;
        h->response_string = strdup("bad gateway");
        add_response_header(h, strdup("Content-type"), strdup("text/plain"));
-       h->response_body =
-           strdup(_
-                  ("This program was unable to connect or stay connected to the Citadel server.  Please report this problem to your system administrator."));
+       h->response_body = strdup(_("This program was unable to connect or stay connected to the Citadel server.  Please report this problem to your system administrator."));
        h->response_body_length = strlen(h->response_body);
 }
 
@@ -72,11 +70,11 @@ void http_redirect(struct http_transaction *h, char *to_where) {
 void perform_request(struct http_transaction *h) {
        struct ctdlsession *c;
 
-       // Determine which code path to take based on the beginning of the URI.
+       // Determine which code path to take based on the beginning of the URL.
        // This is implemented as a series of strncasecmp() calls rather than a
        // lookup table in order to make the code more readable.
 
-       if (IsEmptyStr(h->uri)) {       // Sanity check
+       if (IsEmptyStr(h->url)) {       // Sanity check
                do_404(h);
                return;
        }
@@ -85,27 +83,38 @@ void perform_request(struct http_transaction *h) {
        // with the /ctdl/ prefix.
        // Root (/) ...
 
-       if ((!strcmp(h->uri, "/")) && (!strcasecmp(h->method, "GET"))) {
+       if ((!strcmp(h->url, "/")) && (!strcasecmp(h->method, "GET"))) {
                http_redirect(h, "/ctdl/s/index.html");
                return;
        }
 
-       // Legacy URI patterns (/readnew?gotoroom=xxx&start_reading_at=yyy) ...
+       // Legacy URL patterns (/readnew?gotoroom=xxx&start_reading_at=yyy) ...
        // Direct room name (/my%20blog) ...
 
-       // Everything below this line is strictly REST URI patterns.
+       // HTTP-01 challenge [RFC5785 section 3, RFC8555 section 9.2]
+       if (!strncasecmp(h->url, HKEY("/.well-known"))) {       // Static content
+               output_static(h);
+               return;
+       }
 
-       if (strncasecmp(h->uri, HKEY("/ctdl/"))) {      // Reject non-REST
+       if (!strcasecmp(h->url, "/favicon.ico")) {
+               output_static(h);
+               return;
+       }
+
+       // Everything below this line is strictly REST URL patterns.
+
+       if (strncasecmp(h->url, HKEY("/ctdl/"))) {              // Reject non-REST
                do_404(h);
                return;
        }
 
-       if (!strncasecmp(h->uri, HKEY("/ctdl/s/"))) {   // Static content
+       if (!strncasecmp(h->url, HKEY("/ctdl/s/"))) {           // Static content
                output_static(h);
                return;
        }
 
-       if (h->uri[7] != '/') {
+       if (h->url[7] != '/') {
                do_404(h);
                return;
        }
@@ -123,25 +132,28 @@ void perform_request(struct http_transaction *h) {
        // WebDAV methods like OPTIONS and PROPFIND *require* a logged-in session,
        // even if the Citadel server allows anonymous access.
        if (IsEmptyStr(c->auth)) {
-               if ((!strcasecmp(h->method, "OPTIONS"))
-                   || (!strcasecmp(h->method, "PROPFIND"))
-                   || (!strcasecmp(h->method, "REPORT"))
-                   || (!strcasecmp(h->method, "DELETE"))
-                   ) {
+               if (    (!strcasecmp(h->method, "OPTIONS"))
+                       || (!strcasecmp(h->method, "PROPFIND"))
+                       || (!strcasecmp(h->method, "REPORT"))
+                       || (!strcasecmp(h->method, "DELETE"))
+               ) {
                        request_http_authenticate(h);
                        disconnect_from_citadel(c);
                        return;
                }
        }
 
-       // Break down the URI by path and send the request to the appropriate part of the program.
-       switch (h->uri[6]) {
+       // Break down the URL by path and send the request to the appropriate part of the program.
+       switch (h->url[6]) {
        case 'a':               // /ctdl/a/ == RESTful path to admin functions
                ctdl_a(h, c);
                break;
        case 'c':               // /ctdl/c/ == misc Citadel server commands
                ctdl_c(h, c);
                break;
+       case 'f':               // /ctdl/f/ == RESTful path to floors
+               ctdl_f(h, c);
+               break;
        case 'r':               // /ctdl/r/ == RESTful path to rooms
                ctdl_r(h, c);
                break;
@@ -161,7 +173,7 @@ void perform_request(struct http_transaction *h) {
                add_response_header(h, strdup("Set-Cookie"), strdup(koekje));
        }
 
-       // During development we are foiling the browser cache completely.  In production we'll be more selective.
+       // Durlng development we are foiling the browser cache completely.  In production we'll be more selective.
        add_response_header(h, strdup("Cache-Control"), strdup("no-store, must-revalidate"));
        add_response_header(h, strdup("Pragma"), strdup("no-cache"));
        add_response_header(h, strdup("Expires"), strdup("0"));