mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-25 22:45:05 +00:00
server_get_handler() returns the status.
This commit is contained in:
parent
11134e58a3
commit
02b0df78c6
1 changed files with 13 additions and 11 deletions
18
httpd.c
18
httpd.c
|
@ -19,17 +19,16 @@ const char *susie =
|
||||||
"AYTtEsDU9F34AAAAAElFTkSuQmCC";
|
"AYTtEsDU9F34AAAAAElFTkSuQmCC";
|
||||||
|
|
||||||
|
|
||||||
void server_get_handler(d_char *req, char *q_path, int *status,
|
int server_get_handler(d_char *req, char *q_path,
|
||||||
char **body, int *b_size, char **ctype)
|
char **body, int *b_size, char **ctype)
|
||||||
/* basic server services */
|
/* basic server services */
|
||||||
{
|
{
|
||||||
|
int status = 0;
|
||||||
char *req_hdrs = xs_dict_get(req, "headers");
|
char *req_hdrs = xs_dict_get(req, "headers");
|
||||||
char *acpt = xs_dict_get(req_hdrs, "accept");
|
char *acpt = xs_dict_get(req_hdrs, "accept");
|
||||||
|
|
||||||
if (acpt == NULL) {
|
if (acpt == NULL)
|
||||||
*status = 400;
|
return 400;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* is it the server root? */
|
/* is it the server root? */
|
||||||
if (*q_path == '\0') {
|
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);
|
d_char *s = xs_readall(f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
*status = 200;
|
status = 200;
|
||||||
|
|
||||||
/* does it have a %userlist% mark? */
|
/* does it have a %userlist% mark? */
|
||||||
if (xs_str_in(s, "%userlist%") != -1) {
|
if (xs_str_in(s, "%userlist%") != -1) {
|
||||||
|
@ -77,12 +76,15 @@ void server_get_handler(d_char *req, char *q_path, int *status,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (strcmp(q_path, "/susie.png") == 0) {
|
if (strcmp(q_path, "/susie.png") == 0) {
|
||||||
*status = 200;
|
status = 200;
|
||||||
*body = xs_base64_dec(susie, b_size);
|
*body = xs_base64_dec(susie, b_size);
|
||||||
*ctype = "image/png";
|
*ctype = "image/png";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void httpd_connection(int rs)
|
void httpd_connection(int rs)
|
||||||
/* the connection loop */
|
/* the connection loop */
|
||||||
{
|
{
|
||||||
|
@ -123,7 +125,7 @@ void httpd_connection(int rs)
|
||||||
if (strcmp(method, "GET") == 0) {
|
if (strcmp(method, "GET") == 0) {
|
||||||
/* cascade through */
|
/* cascade through */
|
||||||
if (status == 0)
|
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)
|
if (status == 0)
|
||||||
status = webfinger_get_handler(req, q_path, &body, &b_size, &ctype);
|
status = webfinger_get_handler(req, q_path, &body, &b_size, &ctype);
|
||||||
|
|
Loading…
Reference in a new issue