diff options
| author | 2023-10-22 09:00:37 +0200 | |
|---|---|---|
| committer | 2023-10-22 09:00:37 +0200 | |
| commit | 0d78deef42cd1e5d461d98d2acefd4266d323046 (patch) | |
| tree | a6187aa52656349b707fa48f266d040361ab65cb | |
| parent | Backport from xs. (diff) | |
| download | penes-snac2-0d78deef42cd1e5d461d98d2acefd4266d323046.tar.gz penes-snac2-0d78deef42cd1e5d461d98d2acefd4266d323046.tar.xz penes-snac2-0d78deef42cd1e5d461d98d2acefd4266d323046.zip | |
New function deluser(), to delete a user.
Only unfollows by now.
Diffstat (limited to '')
| -rw-r--r-- | main.c | 7 | ||||
| -rw-r--r-- | snac.h | 1 | ||||
| -rw-r--r-- | utils.c | 26 |
3 files changed, 33 insertions, 1 deletions
| @@ -19,6 +19,7 @@ int usage(void) | |||
| 19 | printf("init [{basedir}] Initializes the data storage\n"); | 19 | printf("init [{basedir}] Initializes the data storage\n"); |
| 20 | printf("upgrade {basedir} Upgrade to a new version\n"); | 20 | printf("upgrade {basedir} Upgrade to a new version\n"); |
| 21 | printf("adduser {basedir} [{uid}] Adds a new user\n"); | 21 | printf("adduser {basedir} [{uid}] Adds a new user\n"); |
| 22 | printf("deluser {basedir} {uid} Deletes a user\n"); | ||
| 22 | printf("httpd {basedir} Starts the HTTPD daemon\n"); | 23 | printf("httpd {basedir} Starts the HTTPD daemon\n"); |
| 23 | printf("purge {basedir} Purges old data\n"); | 24 | printf("purge {basedir} Purges old data\n"); |
| 24 | printf("webfinger {basedir} {actor} Queries about an actor (@user@host or actor url)\n"); | 25 | printf("webfinger {basedir} {actor} Queries about an actor (@user@host or actor url)\n"); |
| @@ -169,7 +170,7 @@ int main(int argc, char *argv[]) | |||
| 169 | } | 170 | } |
| 170 | 171 | ||
| 171 | if (!user_open(&snac, user)) { | 172 | if (!user_open(&snac, user)) { |
| 172 | printf("error in user '%s'\n", user); | 173 | printf("invalid user '%s'\n", user); |
| 173 | return 1; | 174 | return 1; |
| 174 | } | 175 | } |
| 175 | 176 | ||
| @@ -179,6 +180,10 @@ int main(int argc, char *argv[]) | |||
| 179 | return resetpwd(&snac); | 180 | return resetpwd(&snac); |
| 180 | } | 181 | } |
| 181 | 182 | ||
| 183 | if (strcmp(cmd, "deluser") == 0) { /** **/ | ||
| 184 | return deluser(&snac); | ||
| 185 | } | ||
| 186 | |||
| 182 | if (strcmp(cmd, "queue") == 0) { /** **/ | 187 | if (strcmp(cmd, "queue") == 0) { /** **/ |
| 183 | process_user_queue(&snac); | 188 | process_user_queue(&snac); |
| 184 | return 0; | 189 | return 0; |
| @@ -276,6 +276,7 @@ int html_post_handler(const xs_dict *req, const char *q_path, | |||
| 276 | int snac_init(const char *_basedir); | 276 | int snac_init(const char *_basedir); |
| 277 | int adduser(const char *uid); | 277 | int adduser(const char *uid); |
| 278 | int resetpwd(snac *snac); | 278 | int resetpwd(snac *snac); |
| 279 | int deluser(snac *user); | ||
| 279 | 280 | ||
| 280 | extern const char *snac_blurb; | 281 | extern const char *snac_blurb; |
| 281 | 282 | ||
| @@ -337,3 +337,29 @@ int resetpwd(snac *snac) | |||
| 337 | 337 | ||
| 338 | return ret; | 338 | return ret; |
| 339 | } | 339 | } |
| 340 | |||
| 341 | |||
| 342 | int deluser(snac *user) | ||
| 343 | /* deletes a user */ | ||
| 344 | { | ||
| 345 | int ret = 0; | ||
| 346 | xs *fwers = following_list(user); | ||
| 347 | xs_list *p = fwers; | ||
| 348 | xs_str *v; | ||
| 349 | |||
| 350 | while (xs_list_iter(&p, &v)) { | ||
| 351 | xs *object = NULL; | ||
| 352 | |||
| 353 | if (valid_status(following_get(user, v, &object))) { | ||
| 354 | xs *msg = msg_undo(user, xs_dict_get(object, "object")); | ||
| 355 | |||
| 356 | following_del(user, v); | ||
| 357 | |||
| 358 | enqueue_output_by_actor(user, msg, v, 0); | ||
| 359 | |||
| 360 | printf("Unfollowing actor %s\n", v); | ||
| 361 | } | ||
| 362 | } | ||
| 363 | |||
| 364 | return ret; | ||
| 365 | } | ||