summaryrefslogtreecommitdiff
path: root/httpd.c
diff options
context:
space:
mode:
authorGravatar grunfink2024-05-30 08:44:54 +0000
committerGravatar grunfink2024-05-30 08:44:54 +0000
commitd56d4beb90f613b82ebf705a3e81a667b9601860 (patch)
tree5998501d0ea9a09f26db65e2d29fcb0927b5eee0 /httpd.c
parentBackport from xs. (diff)
parentImplement image uploads for Tokodon (diff)
downloadsnac2-d56d4beb90f613b82ebf705a3e81a667b9601860.tar.gz
snac2-d56d4beb90f613b82ebf705a3e81a667b9601860.tar.xz
snac2-d56d4beb90f613b82ebf705a3e81a667b9601860.zip
Merge pull request 'Mastodon PATCH API for user profile updates' (#169) from louis77/snac2:master into master
Reviewed-on: https://codeberg.org/grunfink/snac2/pulls/169
Diffstat (limited to 'httpd.c')
-rw-r--r--httpd.c38
1 files changed, 24 insertions, 14 deletions
diff --git a/httpd.c b/httpd.c
index a7396e8..d566b1e 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");
@@ -362,8 +362,18 @@ void httpd_connection(FILE *f)
362 362
363 } 363 }
364 else 364 else
365 if (strcmp(method, "PATCH") == 0) {
366
367#ifndef NO_MASTODON_API
368 if (status == 0)
369 status = mastoapi_patch_handler(req, q_path,
370 payload, p_size, &body, &b_size, &ctype);
371#endif
372
373 }
374 else
365 if (strcmp(method, "OPTIONS") == 0) { 375 if (strcmp(method, "OPTIONS") == 0) {
366 status = 200; 376 status = HTTP_STATUS_OK;
367 } 377 }
368 else 378 else
369 if (strcmp(method, "DELETE") == 0) { 379 if (strcmp(method, "DELETE") == 0) {
@@ -378,22 +388,22 @@ void httpd_connection(FILE *f)
378 if (status == 0) { 388 if (status == 0) {
379 srv_archive_error("unattended_method", "unattended method", req, payload); 389 srv_archive_error("unattended_method", "unattended method", req, payload);
380 srv_debug(1, xs_fmt("httpd_connection unattended %s %s", method, q_path)); 390 srv_debug(1, xs_fmt("httpd_connection unattended %s %s", method, q_path));
381 status = 404; 391 status = HTTP_STATUS_NOT_FOUND;
382 } 392 }
383 393
384 if (status == 403) 394 if (status == HTTP_STATUS_FORBIDDEN)
385 body = xs_str_new("<h1>403 Forbidden</h1>"); 395 body = xs_str_new("<h1>403 Forbidden</h1>");
386 396
387 if (status == 404) 397 if (status == HTTP_STATUS_NOT_FOUND)
388 body = xs_str_new("<h1>404 Not Found</h1>"); 398 body = xs_str_new("<h1>404 Not Found</h1>");
389 399
390 if (status == 400 && body != NULL) 400 if (status == HTTP_STATUS_BAD_REQUEST && body != NULL)
391 body = xs_str_new("<h1>400 Bad Request</h1>"); 401 body = xs_str_new("<h1>400 Bad Request</h1>");
392 402
393 if (status == 303) 403 if (status == HTTP_STATUS_SEE_OTHER)
394 headers = xs_dict_append(headers, "location", body); 404 headers = xs_dict_append(headers, "location", body);
395 405
396 if (status == 401) { 406 if (status == HTTP_STATUS_UNAUTHORIZED) {
397 xs *www_auth = xs_fmt("Basic realm=\"@%s@%s snac login\"", 407 xs *www_auth = xs_fmt("Basic realm=\"@%s@%s snac login\"",
398 body, xs_dict_get(srv_config, "host")); 408 body, xs_dict_get(srv_config, "host"));
399 409
@@ -432,7 +442,7 @@ void httpd_connection(FILE *f)
432 if (p_state->use_fcgi) 442 if (p_state->use_fcgi)
433 xs_fcgi_response(f, status, headers, body, b_size, fcgi_id); 443 xs_fcgi_response(f, status, headers, body, b_size, fcgi_id);
434 else 444 else
435 xs_httpd_response(f, status, headers, body, b_size); 445 xs_httpd_response(f, status, http_status_text(status), headers, body, b_size);
436 446
437 fclose(f); 447 fclose(f);
438 448