X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit-ng%2Frequest.c;h=71b1290bcb819c72c5443515caa3c80fc01e62bf;hb=35406dcce3e45f6a52012ded8bb9fa5e99f484d9;hp=c182a2912b065a547e127fb0fa5495271e4d67fc;hpb=52b6f96d74b3faf7e25f87618493c1ffd8cc3571;p=citadel.git diff --git a/webcit-ng/request.c b/webcit-ng/request.c index c182a2912..71b1290bc 100644 --- a/webcit-ng/request.c +++ b/webcit-ng/request.c @@ -50,7 +50,9 @@ 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); } @@ -92,31 +94,29 @@ void perform_request(struct http_transaction *h) // 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->uri)) { // Sanity check do_404(h); return; } - // Right about here is where we should try to handle anything that doesn't start // with the /ctdl/ prefix. // Root (/) ... - if ( (!strcmp(h->uri, "/")) && (!strcasecmp(h->method, "GET")) ) { + if ((!strcmp(h->uri, "/")) && (!strcasecmp(h->method, "GET"))) { http_redirect(h, "/ctdl/s/index.html"); return; } - // Legacy URI patterns (/readnew?gotoroom=xxx&start_reading_at=yyy) ... // Direct room name (/my%20blog) ... // Everything below this line is strictly REST URI patterns. - if (strncasecmp(h->uri, HKEY("/ctdl/"))) { // Reject non-REST + if (strncasecmp(h->uri, HKEY("/ctdl/"))) { // Reject non-REST do_404(h); return; } - if (!strncasecmp(h->uri, HKEY("/ctdl/s/"))) { // Static content + if (!strncasecmp(h->uri, HKEY("/ctdl/s/"))) { // Static content output_static(h); return; } @@ -125,48 +125,45 @@ void perform_request(struct http_transaction *h) do_404(h); return; } - // Anything below this line: - // 1. Is in the format of /ctdl/?/* - // 2. Requires a connection to a Citadel server. + // 1. Is in the format of /ctdl/?/* + // 2. Requires a connection to a Citadel server. c = connect_to_citadel(h); if (c == NULL) { do_502(h); return; } - // 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]) { - 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 'r': // /ctdl/r/ == RESTful path to rooms - ctdl_r(h, c); - break; - case 'u': // /ctdl/u/ == RESTful path to users - do_404(h); - break; - default: - do_404(h); + switch (h->uri[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 'r': // /ctdl/r/ == RESTful path to rooms + ctdl_r(h, c); + break; + case 'u': // /ctdl/u/ == RESTful path to users + ctdl_u(h, c); + break; + default: + do_404(h); } // Are we in an authenticated session? If so, set a cookie so we stay logged in. @@ -177,7 +174,6 @@ void perform_request(struct http_transaction *h) free(exp); 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. add_response_header(h, strdup("Cache-Control"), strdup("no-store, must-revalidate")); add_response_header(h, strdup("Pragma"), strdup("no-cache"));