commit 0f4db7c
default
·
2023-02-12 08:17:38 +0000 UTC
parent dca071b
New file ~user/user_o.json, for the admin to override user settings.
M
data.c
+16,
-0
1@@ -130,6 +130,7 @@ void user_free(snac *snac)
2 xs_free(snac->uid);
3 xs_free(snac->basedir);
4 xs_free(snac->config);
5+ xs_free(snac->config_o);
6 xs_free(snac->key);
7 xs_free(snac->actor);
8 xs_free(snac->md5);
9@@ -172,7 +173,22 @@ int user_open(snac *snac, const char *uid)
10 if ((snac->key = xs_json_loads(key_data)) != NULL) {
11 snac->actor = xs_fmt("%s/%s", srv_baseurl, uid);
12 snac->md5 = xs_md5_hex(snac->actor, strlen(snac->actor));
13+
14+ /* everything is ok right now */
15 ret = 1;
16+
17+ /* does it have a configuration override? */
18+ xs *cfg_file_o = xs_fmt("%s/user_o.json", snac->basedir);
19+ if ((f = fopen(cfg_file_o, "r")) != NULL) {
20+ xs *j = xs_readall(f);
21+ fclose(f);
22+
23+ if ((snac->config_o = xs_json_loads(j)) == NULL)
24+ srv_log(xs_fmt("cannot parse '%s'", cfg_file_o));
25+ }
26+
27+ if (snac->config_o == NULL)
28+ snac->config_o = xs_dict_new();
29 }
30 else
31 srv_log(xs_fmt("cannot parse '%s'", key_file));
M
snac.h
+8,
-7
1@@ -1,7 +1,7 @@
2 /* snac - A simple, minimalistic ActivityPub instance */
3 /* copyright (c) 2022 - 2023 grunfink / MIT license */
4
5-#define VERSION "2.22"
6+#define VERSION "2.23-dev"
7
8 #define USER_AGENT "snac/" VERSION
9
10@@ -30,12 +30,13 @@ int srv_open(char *basedir, int auto_upgrade);
11 void srv_free(void);
12
13 typedef struct _snac {
14- d_char *uid; /* uid */
15- d_char *basedir; /* user base directory */
16- d_char *config; /* user configuration */
17- d_char *key; /* keypair */
18- d_char *actor; /* actor url */
19- d_char *md5; /* actor url md5 */
20+ xs_str *uid; /* uid */
21+ xs_str *basedir; /* user base directory */
22+ xs_dict *config; /* user configuration */
23+ xs_dict *config_o; /* user configuration admin override */
24+ xs_dict *key; /* keypair */
25+ xs_str *actor; /* actor url */
26+ xs_str *md5; /* actor url md5 */
27 } snac;
28
29 int user_open(snac *snac, const char *uid);