diff options
| author | 2022-09-23 17:44:02 +0200 | |
|---|---|---|
| committer | 2022-09-23 17:44:02 +0200 | |
| commit | 02b0df78c6136b81f165a3370480e84cfa5eed4c (patch) | |
| tree | 028047e0a16b14ea92e0902d6ecca170b66853e2 /httpd.c | |
| parent | webfinger_get_handler() returns the status. (diff) | |
| download | snac2-02b0df78c6136b81f165a3370480e84cfa5eed4c.tar.gz snac2-02b0df78c6136b81f165a3370480e84cfa5eed4c.tar.xz snac2-02b0df78c6136b81f165a3370480e84cfa5eed4c.zip | |
server_get_handler() returns the status.
Diffstat (limited to 'httpd.c')
| -rw-r--r-- | httpd.c | 24 |
1 files changed, 13 insertions, 11 deletions
| @@ -19,17 +19,16 @@ const char *susie = | |||
| 19 | "AYTtEsDU9F34AAAAAElFTkSuQmCC"; | 19 | "AYTtEsDU9F34AAAAAElFTkSuQmCC"; |
| 20 | 20 | ||
| 21 | 21 | ||
| 22 | void server_get_handler(d_char *req, char *q_path, int *status, | 22 | int server_get_handler(d_char *req, char *q_path, |
| 23 | char **body, int *b_size, char **ctype) | 23 | char **body, int *b_size, char **ctype) |
| 24 | /* basic server services */ | 24 | /* basic server services */ |
| 25 | { | 25 | { |
| 26 | int status = 0; | ||
| 26 | char *req_hdrs = xs_dict_get(req, "headers"); | 27 | char *req_hdrs = xs_dict_get(req, "headers"); |
| 27 | char *acpt = xs_dict_get(req_hdrs, "accept"); | 28 | char *acpt = xs_dict_get(req_hdrs, "accept"); |
| 28 | 29 | ||
| 29 | if (acpt == NULL) { | 30 | if (acpt == NULL) |
| 30 | *status = 400; | 31 | return 400; |
| 31 | return; | ||
| 32 | } | ||
| 33 | 32 | ||
| 34 | /* is it the server root? */ | 33 | /* is it the server root? */ |
| 35 | if (*q_path == '\0') { | 34 | if (*q_path == '\0') { |
| @@ -41,7 +40,7 @@ void server_get_handler(d_char *req, char *q_path, int *status, | |||
| 41 | d_char *s = xs_readall(f); | 40 | d_char *s = xs_readall(f); |
| 42 | fclose(f); | 41 | fclose(f); |
| 43 | 42 | ||
| 44 | *status = 200; | 43 | status = 200; |
| 45 | 44 | ||
| 46 | /* does it have a %userlist% mark? */ | 45 | /* does it have a %userlist% mark? */ |
| 47 | if (xs_str_in(s, "%userlist%") != -1) { | 46 | if (xs_str_in(s, "%userlist%") != -1) { |
| @@ -77,12 +76,15 @@ void server_get_handler(d_char *req, char *q_path, int *status, | |||
| 77 | } | 76 | } |
| 78 | else | 77 | else |
| 79 | if (strcmp(q_path, "/susie.png") == 0) { | 78 | if (strcmp(q_path, "/susie.png") == 0) { |
| 80 | *status = 200; | 79 | status = 200; |
| 81 | *body = xs_base64_dec(susie, b_size); | 80 | *body = xs_base64_dec(susie, b_size); |
| 82 | *ctype = "image/png"; | 81 | *ctype = "image/png"; |
| 83 | } | 82 | } |
| 83 | |||
| 84 | return status; | ||
| 84 | } | 85 | } |
| 85 | 86 | ||
| 87 | |||
| 86 | void httpd_connection(int rs) | 88 | void httpd_connection(int rs) |
| 87 | /* the connection loop */ | 89 | /* the connection loop */ |
| 88 | { | 90 | { |
| @@ -123,7 +125,7 @@ void httpd_connection(int rs) | |||
| 123 | if (strcmp(method, "GET") == 0) { | 125 | if (strcmp(method, "GET") == 0) { |
| 124 | /* cascade through */ | 126 | /* cascade through */ |
| 125 | if (status == 0) | 127 | if (status == 0) |
| 126 | server_get_handler(req, q_path, &status, &body, &b_size, &ctype); | 128 | status = server_get_handler(req, q_path, &body, &b_size, &ctype); |
| 127 | 129 | ||
| 128 | if (status == 0) | 130 | if (status == 0) |
| 129 | status = webfinger_get_handler(req, q_path, &body, &b_size, &ctype); | 131 | status = webfinger_get_handler(req, q_path, &body, &b_size, &ctype); |