diff options
| author | 2023-08-05 14:50:20 +0200 | |
|---|---|---|
| committer | 2023-08-05 14:50:20 +0200 | |
| commit | 381a2f5b7bf5f5952f715e40834bb3b50dcb4032 (patch) | |
| tree | ee8d38408440ce19abade480bcb34cc98ce70539 | |
| parent | Partial import of xs_json_load() from xs. (diff) | |
| download | penes-snac2-381a2f5b7bf5f5952f715e40834bb3b50dcb4032.tar.gz penes-snac2-381a2f5b7bf5f5952f715e40834bb3b50dcb4032.tar.xz penes-snac2-381a2f5b7bf5f5952f715e40834bb3b50dcb4032.zip | |
Use xs_json_load() in some places.
| -rw-r--r-- | data.c | 21 |
1 files changed, 7 insertions, 14 deletions
| @@ -46,14 +46,11 @@ int srv_open(char *basedir, int auto_upgrade) | |||
| 46 | if ((f = fopen(cfg_file, "r")) == NULL) | 46 | if ((f = fopen(cfg_file, "r")) == NULL) |
| 47 | error = xs_fmt("ERROR: cannot opening '%s'", cfg_file); | 47 | error = xs_fmt("ERROR: cannot opening '%s'", cfg_file); |
| 48 | else { | 48 | else { |
| 49 | xs *cfg_data; | ||
| 50 | |||
| 51 | /* read full config file */ | 49 | /* read full config file */ |
| 52 | cfg_data = xs_readall(f); | 50 | srv_config = xs_json_load(f); |
| 53 | fclose(f); | 51 | fclose(f); |
| 54 | 52 | ||
| 55 | /* parse */ | 53 | /* parse */ |
| 56 | srv_config = xs_json_loads(cfg_data); | ||
| 57 | 54 | ||
| 58 | if (srv_config == NULL) | 55 | if (srv_config == NULL) |
| 59 | error = xs_fmt("ERROR: cannot parse '%s'", cfg_file); | 56 | error = xs_fmt("ERROR: cannot parse '%s'", cfg_file); |
| @@ -167,22 +164,18 @@ int user_open(snac *snac, const char *uid) | |||
| 167 | cfg_file = xs_fmt("%s/user.json", snac->basedir); | 164 | cfg_file = xs_fmt("%s/user.json", snac->basedir); |
| 168 | 165 | ||
| 169 | if ((f = fopen(cfg_file, "r")) != NULL) { | 166 | if ((f = fopen(cfg_file, "r")) != NULL) { |
| 170 | xs *cfg_data; | ||
| 171 | |||
| 172 | /* read full config file */ | 167 | /* read full config file */ |
| 173 | cfg_data = xs_readall(f); | 168 | snac->config = xs_json_load(f); |
| 174 | fclose(f); | 169 | fclose(f); |
| 175 | 170 | ||
| 176 | if ((snac->config = xs_json_loads(cfg_data)) != NULL) { | 171 | if (snac->config != NULL) { |
| 177 | xs *key_file = xs_fmt("%s/key.json", snac->basedir); | 172 | xs *key_file = xs_fmt("%s/key.json", snac->basedir); |
| 178 | 173 | ||
| 179 | if ((f = fopen(key_file, "r")) != NULL) { | 174 | if ((f = fopen(key_file, "r")) != NULL) { |
| 180 | xs *key_data; | 175 | snac->key = xs_json_load(f); |
| 181 | |||
| 182 | key_data = xs_readall(f); | ||
| 183 | fclose(f); | 176 | fclose(f); |
| 184 | 177 | ||
| 185 | if ((snac->key = xs_json_loads(key_data)) != NULL) { | 178 | if (snac->key != NULL) { |
| 186 | snac->actor = xs_fmt("%s/%s", srv_baseurl, uid); | 179 | snac->actor = xs_fmt("%s/%s", srv_baseurl, uid); |
| 187 | snac->md5 = xs_md5_hex(snac->actor, strlen(snac->actor)); | 180 | snac->md5 = xs_md5_hex(snac->actor, strlen(snac->actor)); |
| 188 | 181 | ||
| @@ -192,10 +185,10 @@ int user_open(snac *snac, const char *uid) | |||
| 192 | /* does it have a configuration override? */ | 185 | /* does it have a configuration override? */ |
| 193 | xs *cfg_file_o = xs_fmt("%s/user_o.json", snac->basedir); | 186 | xs *cfg_file_o = xs_fmt("%s/user_o.json", snac->basedir); |
| 194 | if ((f = fopen(cfg_file_o, "r")) != NULL) { | 187 | if ((f = fopen(cfg_file_o, "r")) != NULL) { |
| 195 | xs *j = xs_readall(f); | 188 | snac->config_o = xs_json_load(f); |
| 196 | fclose(f); | 189 | fclose(f); |
| 197 | 190 | ||
| 198 | if ((snac->config_o = xs_json_loads(j)) == NULL) | 191 | if (snac->config_o == NULL) |
| 199 | srv_log(xs_fmt("error parsing '%s'", cfg_file_o)); | 192 | srv_log(xs_fmt("error parsing '%s'", cfg_file_o)); |
| 200 | } | 193 | } |
| 201 | 194 | ||