diff options
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | data.c | 30 | ||||
| -rw-r--r-- | snac.c | 3 | ||||
| -rw-r--r-- | utils.c | 2 | ||||
| -rw-r--r-- | webfinger.c | 29 |
5 files changed, 47 insertions, 19 deletions
| @@ -53,4 +53,4 @@ snac.o: snac.c xs.h xs_io.h xs_unicode.h xs_json.h xs_curl.h xs_openssl.h \ | |||
| 53 | upgrade.o: upgrade.c xs.h xs_io.h xs_json.h xs_glob.h snac.h | 53 | upgrade.o: upgrade.c xs.h xs_io.h xs_json.h xs_glob.h snac.h |
| 54 | utils.o: utils.c xs.h xs_io.h xs_json.h xs_time.h xs_openssl.h \ | 54 | utils.o: utils.c xs.h xs_io.h xs_json.h xs_time.h xs_openssl.h \ |
| 55 | xs_random.h snac.h | 55 | xs_random.h snac.h |
| 56 | webfinger.o: webfinger.c xs.h xs_json.h xs_curl.h snac.h | 56 | webfinger.o: webfinger.c xs.h xs_json.h xs_curl.h xs_mime.h snac.h |
| @@ -154,12 +154,34 @@ int user_open(snac *snac, const char *uid) | |||
| 154 | memset(snac, '\0', sizeof(struct _snac)); | 154 | memset(snac, '\0', sizeof(struct _snac)); |
| 155 | 155 | ||
| 156 | if (validate_uid(uid)) { | 156 | if (validate_uid(uid)) { |
| 157 | xs *cfg_file; | 157 | xs *cfg_file = NULL; |
| 158 | FILE *f; | 158 | FILE *f; |
| 159 | 159 | ||
| 160 | snac->uid = xs_str_new(uid); | 160 | xs *t = xs_fmt("%s/user/%s", srv_basedir, uid); |
| 161 | 161 | ||
| 162 | snac->basedir = xs_fmt("%s/user/%s", srv_basedir, uid); | 162 | if (mtime(t) == 0.0) { |
| 163 | /* user folder does not exist; try with a different case */ | ||
| 164 | xs *lcuid = xs_tolower_i(xs_dup(uid)); | ||
| 165 | xs *ulist = user_list(); | ||
| 166 | xs_list *p = ulist; | ||
| 167 | xs_str *v; | ||
| 168 | |||
| 169 | while (xs_list_iter(&p, &v)) { | ||
| 170 | xs *v2 = xs_tolower_i(xs_dup(v)); | ||
| 171 | |||
| 172 | if (strcmp(lcuid, v2) == 0) { | ||
| 173 | snac->uid = xs_dup(v); | ||
| 174 | break; | ||
| 175 | } | ||
| 176 | } | ||
| 177 | } | ||
| 178 | else | ||
| 179 | snac->uid = xs_str_new(uid); | ||
| 180 | |||
| 181 | if (snac->uid == NULL) | ||
| 182 | return ret; | ||
| 183 | |||
| 184 | snac->basedir = xs_fmt("%s/user/%s", srv_basedir, snac->uid); | ||
| 163 | 185 | ||
| 164 | cfg_file = xs_fmt("%s/user.json", snac->basedir); | 186 | cfg_file = xs_fmt("%s/user.json", snac->basedir); |
| 165 | 187 | ||
| @@ -176,7 +198,7 @@ int user_open(snac *snac, const char *uid) | |||
| 176 | fclose(f); | 198 | fclose(f); |
| 177 | 199 | ||
| 178 | if (snac->key != NULL) { | 200 | if (snac->key != NULL) { |
| 179 | snac->actor = xs_fmt("%s/%s", srv_baseurl, uid); | 201 | snac->actor = xs_fmt("%s/%s", srv_baseurl, snac->uid); |
| 180 | snac->md5 = xs_md5_hex(snac->actor, strlen(snac->actor)); | 202 | snac->md5 = xs_md5_hex(snac->actor, strlen(snac->actor)); |
| 181 | 203 | ||
| 182 | /* everything is ok right now */ | 204 | /* everything is ok right now */ |
| @@ -79,6 +79,9 @@ double ftime(void) | |||
| 79 | int validate_uid(const char *uid) | 79 | int validate_uid(const char *uid) |
| 80 | /* returns if uid is a valid identifier */ | 80 | /* returns if uid is a valid identifier */ |
| 81 | { | 81 | { |
| 82 | if (!uid || *uid == '\0') | ||
| 83 | return 0; | ||
| 84 | |||
| 82 | while (*uid) { | 85 | while (*uid) { |
| 83 | if (!(isalnum(*uid) || *uid == '_')) | 86 | if (!(isalnum(*uid) || *uid == '_')) |
| 84 | return 0; | 87 | return 0; |
| @@ -244,7 +244,7 @@ int adduser(const char *uid) | |||
| 244 | } | 244 | } |
| 245 | 245 | ||
| 246 | if (user_open(&snac, uid)) { | 246 | if (user_open(&snac, uid)) { |
| 247 | printf("ERROR: user '%s' already exists\n", uid); | 247 | printf("ERROR: user '%s' already exists\n", snac.uid); |
| 248 | return 1; | 248 | return 1; |
| 249 | } | 249 | } |
| 250 | 250 | ||
diff --git a/webfinger.c b/webfinger.c index 46867e9..13a6e6c 100644 --- a/webfinger.c +++ b/webfinger.c | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | #include "xs.h" | 4 | #include "xs.h" |
| 5 | #include "xs_json.h" | 5 | #include "xs_json.h" |
| 6 | #include "xs_curl.h" | 6 | #include "xs_curl.h" |
| 7 | #include "xs_mime.h" | ||
| 7 | 8 | ||
| 8 | #include "snac.h" | 9 | #include "snac.h" |
| 9 | 10 | ||
| @@ -128,20 +129,11 @@ int webfinger_get_handler(xs_dict *req, char *q_path, | |||
| 128 | 129 | ||
| 129 | if (xs_startswith(resource, "https:/" "/")) { | 130 | if (xs_startswith(resource, "https:/" "/")) { |
| 130 | /* actor search: find a user with this actor */ | 131 | /* actor search: find a user with this actor */ |
| 131 | xs *list = user_list(); | 132 | xs *l = xs_split(resource, "/"); |
| 132 | char *p, *uid; | 133 | char *uid = xs_list_get(l, -1); |
| 133 | |||
| 134 | p = list; | ||
| 135 | while (xs_list_iter(&p, &uid)) { | ||
| 136 | if (user_open(&snac, uid)) { | ||
| 137 | if (strcmp(snac.actor, resource) == 0) { | ||
| 138 | found = 1; | ||
| 139 | break; | ||
| 140 | } | ||
| 141 | 134 | ||
| 142 | user_free(&snac); | 135 | if (uid) |
| 143 | } | 136 | found = user_open(&snac, uid); |
| 144 | } | ||
| 145 | } | 137 | } |
| 146 | else | 138 | else |
| 147 | if (xs_startswith(resource, "acct:")) { | 139 | if (xs_startswith(resource, "acct:")) { |
| @@ -180,6 +172,17 @@ int webfinger_get_handler(xs_dict *req, char *q_path, | |||
| 180 | 172 | ||
| 181 | links = xs_list_append(links, aaj); | 173 | links = xs_list_append(links, aaj); |
| 182 | 174 | ||
| 175 | char *avatar = xs_dict_get(snac.config, "avatar"); | ||
| 176 | if (!xs_is_null(avatar) && *avatar) { | ||
| 177 | xs *d = xs_dict_new(); | ||
| 178 | |||
| 179 | d = xs_dict_append(d, "rel", "http:/" "/webfinger.net/rel/avatar"); | ||
| 180 | d = xs_dict_append(d, "type", xs_mime_by_ext(avatar)); | ||
| 181 | d = xs_dict_append(d, "href", avatar); | ||
| 182 | |||
| 183 | links = xs_list_append(links, d); | ||
| 184 | } | ||
| 185 | |||
| 183 | obj = xs_dict_append(obj, "subject", acct); | 186 | obj = xs_dict_append(obj, "subject", acct); |
| 184 | obj = xs_dict_append(obj, "links", links); | 187 | obj = xs_dict_append(obj, "links", links); |
| 185 | 188 | ||