From 02b0df78c6136b81f165a3370480e84cfa5eed4c Mon Sep 17 00:00:00 2001 From: default Date: Fri, 23 Sep 2022 17:44:02 +0200 Subject: [PATCH] server_get_handler() returns the status. --- httpd.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/httpd.c b/httpd.c index a56ce2a..1ef766c 100644 --- a/httpd.c +++ b/httpd.c @@ -19,17 +19,16 @@ const char *susie = "AYTtEsDU9F34AAAAAElFTkSuQmCC"; -void server_get_handler(d_char *req, char *q_path, int *status, - char **body, int *b_size, char **ctype) +int server_get_handler(d_char *req, char *q_path, + char **body, int *b_size, char **ctype) /* basic server services */ { + int status = 0; char *req_hdrs = xs_dict_get(req, "headers"); char *acpt = xs_dict_get(req_hdrs, "accept"); - if (acpt == NULL) { - *status = 400; - return; - } + if (acpt == NULL) + return 400; /* is it the server root? */ if (*q_path == '\0') { @@ -41,7 +40,7 @@ void server_get_handler(d_char *req, char *q_path, int *status, d_char *s = xs_readall(f); fclose(f); - *status = 200; + status = 200; /* does it have a %userlist% mark? */ if (xs_str_in(s, "%userlist%") != -1) { @@ -77,12 +76,15 @@ void server_get_handler(d_char *req, char *q_path, int *status, } else if (strcmp(q_path, "/susie.png") == 0) { - *status = 200; - *body = xs_base64_dec(susie, b_size); - *ctype = "image/png"; + status = 200; + *body = xs_base64_dec(susie, b_size); + *ctype = "image/png"; } + + return status; } + void httpd_connection(int rs) /* the connection loop */ { @@ -123,7 +125,7 @@ void httpd_connection(int rs) if (strcmp(method, "GET") == 0) { /* cascade through */ if (status == 0) - server_get_handler(req, q_path, &status, &body, &b_size, &ctype); + status = server_get_handler(req, q_path, &body, &b_size, &ctype); if (status == 0) status = webfinger_get_handler(req, q_path, &body, &b_size, &ctype);