commit 381a2f5
default
·
2023-08-05 12:50:20 +0000 UTC
parent d8f2bb1
Use xs_json_load() in some places.
1 files changed,
+7,
-14
M
data.c
M
data.c
+7,
-14
1@@ -46,14 +46,11 @@ int srv_open(char *basedir, int auto_upgrade)
2 if ((f = fopen(cfg_file, "r")) == NULL)
3 error = xs_fmt("ERROR: cannot opening '%s'", cfg_file);
4 else {
5- xs *cfg_data;
6-
7 /* read full config file */
8- cfg_data = xs_readall(f);
9+ srv_config = xs_json_load(f);
10 fclose(f);
11
12 /* parse */
13- srv_config = xs_json_loads(cfg_data);
14
15 if (srv_config == NULL)
16 error = xs_fmt("ERROR: cannot parse '%s'", cfg_file);
17@@ -167,22 +164,18 @@ int user_open(snac *snac, const char *uid)
18 cfg_file = xs_fmt("%s/user.json", snac->basedir);
19
20 if ((f = fopen(cfg_file, "r")) != NULL) {
21- xs *cfg_data;
22-
23 /* read full config file */
24- cfg_data = xs_readall(f);
25+ snac->config = xs_json_load(f);
26 fclose(f);
27
28- if ((snac->config = xs_json_loads(cfg_data)) != NULL) {
29+ if (snac->config != NULL) {
30 xs *key_file = xs_fmt("%s/key.json", snac->basedir);
31
32 if ((f = fopen(key_file, "r")) != NULL) {
33- xs *key_data;
34-
35- key_data = xs_readall(f);
36+ snac->key = xs_json_load(f);
37 fclose(f);
38
39- if ((snac->key = xs_json_loads(key_data)) != NULL) {
40+ if (snac->key != NULL) {
41 snac->actor = xs_fmt("%s/%s", srv_baseurl, uid);
42 snac->md5 = xs_md5_hex(snac->actor, strlen(snac->actor));
43
44@@ -192,10 +185,10 @@ int user_open(snac *snac, const char *uid)
45 /* does it have a configuration override? */
46 xs *cfg_file_o = xs_fmt("%s/user_o.json", snac->basedir);
47 if ((f = fopen(cfg_file_o, "r")) != NULL) {
48- xs *j = xs_readall(f);
49+ snac->config_o = xs_json_load(f);
50 fclose(f);
51
52- if ((snac->config_o = xs_json_loads(j)) == NULL)
53+ if (snac->config_o == NULL)
54 srv_log(xs_fmt("error parsing '%s'", cfg_file_o));
55 }
56