commit 97cc35f

default  ·  2024-09-18 16:34:17 +0000 UTC
parent 00716d1
Started account migration code.
3 files changed,  +33, -0
M main.c
M snac.h
+27, -0
 1@@ -1522,6 +1522,17 @@ xs_dict *msg_pong(snac *user, const char *rcpt, const char *object)
 2 }
 3 
 4 
 5+xs_dict *msg_move(snac *user, const char *new_account)
 6+/* creates a Move message (to move the user to new_account) */
 7+{
 8+    xs_dict *msg = msg_base(user, "Move", "@dummy", user->actor, NULL, user->actor);
 9+
10+    msg = xs_dict_append(msg, "target", new_account);
11+
12+    return msg;
13+}
14+
15+
16 xs_dict *msg_question(snac *user, const char *content, xs_list *attach,
17                       const xs_list *opts, int multiple, int end_secs)
18 /* creates a Question message */
19@@ -2653,6 +2664,22 @@ int process_queue(void)
20 }
21 
22 
23+/** account migration **/
24+
25+int migrate_account(snac *user)
26+/* migrates this account to a new one (stored in the 'aka' user field) */
27+{
28+    const char *new_account = xs_dict_get(user->config, "aka");
29+
30+    if (xs_type(new_account) != XSTYPE_STRING) {
31+        snac_log(user, xs_fmt("Cannot migrate: 'aka' (new account) not defined"));
32+        return 1;
33+    }
34+
35+    return 0;
36+}
37+
38+
39 /** HTTP handlers */
40 
41 int activitypub_get_handler(const xs_dict *req, const char *q_path,
M main.c
+4, -0
 1@@ -273,6 +273,10 @@ int main(int argc, char *argv[])
 2         return 0;
 3     }
 4 
 5+    if (strcmp(cmd, "migrate") == 0) { /** **/
 6+        return migrate_account(&snac);
 7+    }
 8+
 9     if ((url = GET_ARGV()) == NULL)
10         return usage();
11 
M snac.h
+2, -0
 1@@ -310,6 +310,7 @@ xs_dict *msg_actor(snac *snac);
 2 xs_dict *msg_update(snac *snac, const xs_dict *object);
 3 xs_dict *msg_ping(snac *user, const char *rcpt);
 4 xs_dict *msg_pong(snac *user, const char *rcpt, const char *object);
 5+xs_dict *msg_move(snac *user, const char *new_account);
 6 xs_dict *msg_question(snac *user, const char *content, xs_list *attach,
 7                       const xs_list *opts, int multiple, int end_secs);
 8 
 9@@ -389,6 +390,7 @@ void mastoapi_purge(void);
10 void verify_links(snac *user);
11 
12 void export_csv(snac *user);
13+int migrate_account(snac *user);
14 void import_csv(snac *user);
15 
16 typedef enum {