diff options
| author | 2024-01-03 11:01:25 +0100 | |
|---|---|---|
| committer | 2024-01-03 11:01:25 +0100 | |
| commit | e003f87c2d0c06868ec5c225991c38d1f6b935f8 (patch) | |
| tree | c01a80254b8392918c6f371c865bcb252ccaf9d3 /data.c | |
| parent | Try to avoid host header misconfigurations in check_signature(). (diff) | |
| download | snac2-e003f87c2d0c06868ec5c225991c38d1f6b935f8.tar.gz snac2-e003f87c2d0c06868ec5c225991c38d1f6b935f8.tar.xz snac2-e003f87c2d0c06868ec5c225991c38d1f6b935f8.zip | |
Moved most server state to a structure.
Diffstat (limited to 'data.c')
| -rw-r--r-- | data.c | 40 |
1 files changed, 20 insertions, 20 deletions
| @@ -150,12 +150,12 @@ void user_free(snac *snac) | |||
| 150 | } | 150 | } |
| 151 | 151 | ||
| 152 | 152 | ||
| 153 | int user_open(snac *snac, const char *uid) | 153 | int user_open(snac *user, const char *uid) |
| 154 | /* opens a user */ | 154 | /* opens a user */ |
| 155 | { | 155 | { |
| 156 | int ret = 0; | 156 | int ret = 0; |
| 157 | 157 | ||
| 158 | memset(snac, '\0', sizeof(struct _snac)); | 158 | *user = (snac){0}; |
| 159 | 159 | ||
| 160 | if (validate_uid(uid)) { | 160 | if (validate_uid(uid)) { |
| 161 | xs *cfg_file = NULL; | 161 | xs *cfg_file = NULL; |
| @@ -174,52 +174,52 @@ int user_open(snac *snac, const char *uid) | |||
| 174 | xs *v2 = xs_tolower_i(xs_dup(v)); | 174 | xs *v2 = xs_tolower_i(xs_dup(v)); |
| 175 | 175 | ||
| 176 | if (strcmp(lcuid, v2) == 0) { | 176 | if (strcmp(lcuid, v2) == 0) { |
| 177 | snac->uid = xs_dup(v); | 177 | user->uid = xs_dup(v); |
| 178 | break; | 178 | break; |
| 179 | } | 179 | } |
| 180 | } | 180 | } |
| 181 | } | 181 | } |
| 182 | else | 182 | else |
| 183 | snac->uid = xs_str_new(uid); | 183 | user->uid = xs_str_new(uid); |
| 184 | 184 | ||
| 185 | if (snac->uid == NULL) | 185 | if (user->uid == NULL) |
| 186 | return ret; | 186 | return ret; |
| 187 | 187 | ||
| 188 | snac->basedir = xs_fmt("%s/user/%s", srv_basedir, snac->uid); | 188 | user->basedir = xs_fmt("%s/user/%s", srv_basedir, user->uid); |
| 189 | 189 | ||
| 190 | cfg_file = xs_fmt("%s/user.json", snac->basedir); | 190 | cfg_file = xs_fmt("%s/user.json", user->basedir); |
| 191 | 191 | ||
| 192 | if ((f = fopen(cfg_file, "r")) != NULL) { | 192 | if ((f = fopen(cfg_file, "r")) != NULL) { |
| 193 | /* read full config file */ | 193 | /* read full config file */ |
| 194 | snac->config = xs_json_load(f); | 194 | user->config = xs_json_load(f); |
| 195 | fclose(f); | 195 | fclose(f); |
| 196 | 196 | ||
| 197 | if (snac->config != NULL) { | 197 | if (user->config != NULL) { |
| 198 | xs *key_file = xs_fmt("%s/key.json", snac->basedir); | 198 | xs *key_file = xs_fmt("%s/key.json", user->basedir); |
| 199 | 199 | ||
| 200 | if ((f = fopen(key_file, "r")) != NULL) { | 200 | if ((f = fopen(key_file, "r")) != NULL) { |
| 201 | snac->key = xs_json_load(f); | 201 | user->key = xs_json_load(f); |
| 202 | fclose(f); | 202 | fclose(f); |
| 203 | 203 | ||
| 204 | if (snac->key != NULL) { | 204 | if (user->key != NULL) { |
| 205 | snac->actor = xs_fmt("%s/%s", srv_baseurl, snac->uid); | 205 | user->actor = xs_fmt("%s/%s", srv_baseurl, user->uid); |
| 206 | snac->md5 = xs_md5_hex(snac->actor, strlen(snac->actor)); | 206 | user->md5 = xs_md5_hex(user->actor, strlen(user->actor)); |
| 207 | 207 | ||
| 208 | /* everything is ok right now */ | 208 | /* everything is ok right now */ |
| 209 | ret = 1; | 209 | ret = 1; |
| 210 | 210 | ||
| 211 | /* does it have a configuration override? */ | 211 | /* does it have a configuration override? */ |
| 212 | xs *cfg_file_o = xs_fmt("%s/user_o.json", snac->basedir); | 212 | xs *cfg_file_o = xs_fmt("%s/user_o.json", user->basedir); |
| 213 | if ((f = fopen(cfg_file_o, "r")) != NULL) { | 213 | if ((f = fopen(cfg_file_o, "r")) != NULL) { |
| 214 | snac->config_o = xs_json_load(f); | 214 | user->config_o = xs_json_load(f); |
| 215 | fclose(f); | 215 | fclose(f); |
| 216 | 216 | ||
| 217 | if (snac->config_o == NULL) | 217 | if (user->config_o == NULL) |
| 218 | srv_log(xs_fmt("error parsing '%s'", cfg_file_o)); | 218 | srv_log(xs_fmt("error parsing '%s'", cfg_file_o)); |
| 219 | } | 219 | } |
| 220 | 220 | ||
| 221 | if (snac->config_o == NULL) | 221 | if (user->config_o == NULL) |
| 222 | snac->config_o = xs_dict_new(); | 222 | user->config_o = xs_dict_new(); |
| 223 | } | 223 | } |
| 224 | else | 224 | else |
| 225 | srv_log(xs_fmt("error parsing '%s'", key_file)); | 225 | srv_log(xs_fmt("error parsing '%s'", key_file)); |
| @@ -237,7 +237,7 @@ int user_open(snac *snac, const char *uid) | |||
| 237 | srv_debug(1, xs_fmt("invalid user '%s'", uid)); | 237 | srv_debug(1, xs_fmt("invalid user '%s'", uid)); |
| 238 | 238 | ||
| 239 | if (!ret) | 239 | if (!ret) |
| 240 | user_free(snac); | 240 | user_free(user); |
| 241 | 241 | ||
| 242 | return ret; | 242 | return ret; |
| 243 | } | 243 | } |