summaryrefslogtreecommitdiff
path: root/httpd.c
diff options
context:
space:
mode:
authorGravatar Louis Brauer2024-05-26 21:45:41 +0200
committerGravatar Louis Brauer2024-05-26 21:45:41 +0200
commit0e21d35e802bf859aa14bce688cd9544458e9e9c (patch)
tree55861603d4f702d56edafe24aa1019484b714fbc /httpd.c
parentEnable deletion of avatar and header image in user settings (diff)
downloadpenes-snac2-0e21d35e802bf859aa14bce688cd9544458e9e9c.tar.gz
penes-snac2-0e21d35e802bf859aa14bce688cd9544458e9e9c.tar.xz
penes-snac2-0e21d35e802bf859aa14bce688cd9544458e9e9c.zip
Use enum instead of numeric status codes for HTTP statuses
Diffstat (limited to '')
-rw-r--r--httpd.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/httpd.c b/httpd.c
index a7396e8..60afe28 100644
--- a/httpd.c
+++ b/httpd.c
@@ -217,17 +217,17 @@ int server_get_handler(xs_dict *req, const char *q_path,
217 *body = greeting_html(); 217 *body = greeting_html();
218 218
219 if (*body) 219 if (*body)
220 status = 200; 220 status = HTTP_STATUS_OK;
221 } 221 }
222 else 222 else
223 if (strcmp(q_path, "/susie.png") == 0 || strcmp(q_path, "/favicon.ico") == 0 ) { 223 if (strcmp(q_path, "/susie.png") == 0 || strcmp(q_path, "/favicon.ico") == 0 ) {
224 status = 200; 224 status = HTTP_STATUS_OK;
225 *body = xs_base64_dec(default_avatar_base64(), b_size); 225 *body = xs_base64_dec(default_avatar_base64(), b_size);
226 *ctype = "image/png"; 226 *ctype = "image/png";
227 } 227 }
228 else 228 else
229 if (strcmp(q_path, "/.well-known/nodeinfo") == 0) { 229 if (strcmp(q_path, "/.well-known/nodeinfo") == 0) {
230 status = 200; 230 status = HTTP_STATUS_OK;
231 *ctype = "application/json; charset=utf-8"; 231 *ctype = "application/json; charset=utf-8";
232 *body = xs_fmt("{\"links\":[" 232 *body = xs_fmt("{\"links\":["
233 "{\"rel\":\"http:/" "/nodeinfo.diaspora.software/ns/schema/2.0\"," 233 "{\"rel\":\"http:/" "/nodeinfo.diaspora.software/ns/schema/2.0\","
@@ -236,7 +236,7 @@ int server_get_handler(xs_dict *req, const char *q_path,
236 } 236 }
237 else 237 else
238 if (strcmp(q_path, "/.well-known/host-meta") == 0) { 238 if (strcmp(q_path, "/.well-known/host-meta") == 0) {
239 status = 200; 239 status = HTTP_STATUS_OK;
240 *ctype = "application/xrd+xml"; 240 *ctype = "application/xrd+xml";
241 *body = xs_fmt("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" 241 *body = xs_fmt("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
242 "<XRD>" 242 "<XRD>"
@@ -245,13 +245,13 @@ int server_get_handler(xs_dict *req, const char *q_path,
245 } 245 }
246 else 246 else
247 if (strcmp(q_path, "/nodeinfo_2_0") == 0) { 247 if (strcmp(q_path, "/nodeinfo_2_0") == 0) {
248 status = 200; 248 status = HTTP_STATUS_OK;
249 *ctype = "application/json; charset=utf-8"; 249 *ctype = "application/json; charset=utf-8";
250 *body = nodeinfo_2_0(); 250 *body = nodeinfo_2_0();
251 } 251 }
252 else 252 else
253 if (strcmp(q_path, "/robots.txt") == 0) { 253 if (strcmp(q_path, "/robots.txt") == 0) {
254 status = 200; 254 status = HTTP_STATUS_OK;
255 *ctype = "text/plain"; 255 *ctype = "text/plain";
256 *body = xs_str_new("User-agent: *\n" 256 *body = xs_str_new("User-agent: *\n"
257 "Disallow: /\n"); 257 "Disallow: /\n");
@@ -363,7 +363,7 @@ void httpd_connection(FILE *f)
363 } 363 }
364 else 364 else
365 if (strcmp(method, "OPTIONS") == 0) { 365 if (strcmp(method, "OPTIONS") == 0) {
366 status = 200; 366 status = HTTP_STATUS_OK;
367 } 367 }
368 else 368 else
369 if (strcmp(method, "DELETE") == 0) { 369 if (strcmp(method, "DELETE") == 0) {
@@ -378,22 +378,22 @@ void httpd_connection(FILE *f)
378 if (status == 0) { 378 if (status == 0) {
379 srv_archive_error("unattended_method", "unattended method", req, payload); 379 srv_archive_error("unattended_method", "unattended method", req, payload);
380 srv_debug(1, xs_fmt("httpd_connection unattended %s %s", method, q_path)); 380 srv_debug(1, xs_fmt("httpd_connection unattended %s %s", method, q_path));
381 status = 404; 381 status = HTTP_STATUS_NOT_FOUND;
382 } 382 }
383 383
384 if (status == 403) 384 if (status == HTTP_STATUS_FORBIDDEN)
385 body = xs_str_new("<h1>403 Forbidden</h1>"); 385 body = xs_str_new("<h1>403 Forbidden</h1>");
386 386
387 if (status == 404) 387 if (status == HTTP_STATUS_NOT_FOUND)
388 body = xs_str_new("<h1>404 Not Found</h1>"); 388 body = xs_str_new("<h1>404 Not Found</h1>");
389 389
390 if (status == 400 && body != NULL) 390 if (status == HTTP_STATUS_BAD_REQUEST && body != NULL)
391 body = xs_str_new("<h1>400 Bad Request</h1>"); 391 body = xs_str_new("<h1>400 Bad Request</h1>");
392 392
393 if (status == 303) 393 if (status == HTTP_STATUS_SEE_OTHER)
394 headers = xs_dict_append(headers, "location", body); 394 headers = xs_dict_append(headers, "location", body);
395 395
396 if (status == 401) { 396 if (status == HTTP_STATUS_UNAUTHORIZED) {
397 xs *www_auth = xs_fmt("Basic realm=\"@%s@%s snac login\"", 397 xs *www_auth = xs_fmt("Basic realm=\"@%s@%s snac login\"",
398 body, xs_dict_get(srv_config, "host")); 398 body, xs_dict_get(srv_config, "host"));
399 399