diff options
| author | 2022-09-28 05:36:35 +0200 | |
|---|---|---|
| committer | 2022-09-28 05:36:35 +0200 | |
| commit | b3b15cec292d3671897afdb7ff549dae66735647 (patch) | |
| tree | d90bc7e18f3d8cce021c8512cc8ae80432f8775d /html.c | |
| parent | Added dummy HTTP handlers for html. (diff) | |
| download | snac2-b3b15cec292d3671897afdb7ff549dae66735647.tar.gz snac2-b3b15cec292d3671897afdb7ff549dae66735647.tar.xz snac2-b3b15cec292d3671897afdb7ff549dae66735647.zip | |
New function login() (untested).
Diffstat (limited to 'html.c')
| -rw-r--r-- | html.c | 24 |
1 files changed, 24 insertions, 0 deletions
| @@ -3,6 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | #include "xs.h" | 4 | #include "xs.h" |
| 5 | #include "xs_io.h" | 5 | #include "xs_io.h" |
| 6 | #include "xs_encdec.h" | ||
| 6 | #include "xs_json.h" | 7 | #include "xs_json.h" |
| 7 | #include "xs_regex.h" | 8 | #include "xs_regex.h" |
| 8 | 9 | ||
| @@ -118,6 +119,29 @@ d_char *not_really_markdown(char *content, d_char **f_content) | |||
| 118 | } | 119 | } |
| 119 | 120 | ||
| 120 | 121 | ||
| 122 | int login(snac *snac, char *headers) | ||
| 123 | /* tries a login */ | ||
| 124 | { | ||
| 125 | int logged_in = 0; | ||
| 126 | char *auth = xs_dict_get(headers, "authorization"); | ||
| 127 | |||
| 128 | if (auth && xs_startswith(auth, "Basic ")) { | ||
| 129 | int sz; | ||
| 130 | xs *s1 = xs_crop(xs_dup(auth), 6, 0); | ||
| 131 | xs *s2 = xs_base64_dec(s1, &sz); | ||
| 132 | xs *l1 = xs_split_n(s2, ":", 1); | ||
| 133 | |||
| 134 | if (xs_list_len(l1) == 2) { | ||
| 135 | logged_in = check_password( | ||
| 136 | xs_list_get(l1, 0), xs_list_get(l1, 1), | ||
| 137 | xs_dict_get(snac->config, "passwd")); | ||
| 138 | } | ||
| 139 | } | ||
| 140 | |||
| 141 | return logged_in; | ||
| 142 | } | ||
| 143 | |||
| 144 | |||
| 121 | int html_get_handler(d_char *req, char *q_path, char **body, int *b_size, char **ctype) | 145 | int html_get_handler(d_char *req, char *q_path, char **body, int *b_size, char **ctype) |
| 122 | { | 146 | { |
| 123 | int status = 0; | 147 | int status = 0; |