From 2d2a685ec8bb30452fbf66025391f34f2bd03685 Mon Sep 17 00:00:00 2001 From: default Date: Fri, 20 Sep 2024 10:47:14 +0200 Subject: [PATCH] More migration work. --- activitypub.c | 8 ++++++++ main.c | 16 ++++++++++++---- xs.h | 6 ++---- xs_mime.h | 6 +++--- xs_set.h | 2 +- xs_unicode.h | 2 ++ xs_version.h | 2 +- 7 files changed, 29 insertions(+), 13 deletions(-) diff --git a/activitypub.c b/activitypub.c index 9a49ba9..748327b 100644 --- a/activitypub.c +++ b/activitypub.c @@ -2696,6 +2696,14 @@ int migrate_account(snac *user) return 1; } + xs *move = msg_move(user, new_account); + xs *fwers = follower_list(user); + + xs_json_dump(move, 4, stdout); + printf("\n"); + xs_json_dump(fwers, 4, stdout); + printf("\n"); + return 0; } diff --git a/main.c b/main.c index 52659fc..3c7ccb1 100644 --- a/main.c +++ b/main.c @@ -47,8 +47,8 @@ int usage(void) printf("unlimit {basedir} {uid} {actor} Unlimits an actor\n"); printf("verify_links {basedir} {uid} Verifies a user's links (in the metadata)\n"); printf("search {basedir} {uid} {regex} Searches posts by content\n"); - printf("alias {basedir} {uid} {account} Sets account (@user@host or actor url) as an alias\n"); printf("export_csv {basedir} {uid} Exports data as CSV files into current directory\n"); + printf("alias {basedir} {uid} {account} Sets account (@user@host or actor url) as an alias\n"); printf("migrate {basedir} {uid} Migrates to the account defined as the alias\n"); return 1; @@ -292,12 +292,20 @@ int main(int argc, char *argv[]) status = webfinger_request(url, &actor, &uid); if (valid_status(status)) { - snac.config = xs_dict_set(snac.config, "alias", actor); + if (strcmp(actor, snac.actor) == 0) { + snac_log(&snac, xs_fmt("You can't be your own alias")); + return 1; + } + else { + snac.config = xs_dict_set(snac.config, "alias", actor); - user_persist(&snac, 1); + user_persist(&snac, 1); + } } - else + else { snac_log(&snac, xs_fmt("Webfinger error for %s %d", url, status)); + return 1; + } return 0; } diff --git a/xs.h b/xs.h index 9c12c4a..e5269a4 100644 --- a/xs.h +++ b/xs.h @@ -23,7 +23,6 @@ typedef enum { XSTYPE_LITEM = 0x1f, /* Element of a list (any type) */ XSTYPE_DICT = 0x1c, /* Sequence of KEYVALs up to EOM (with size) */ XSTYPE_KEYVAL = 0x1e, /* key + value (STRING key + any type) */ - XSTYPE_EOM = 0x19, /* End of Multiple (LIST or DICT) */ XSTYPE_DATA = 0x10 /* A block of anonymous data */ } xstype; @@ -170,7 +169,7 @@ void *_xs_realloc(void *ptr, size_t size, const char *file, int line, const char xs_val *ndata = realloc(ptr, size); if (ndata == NULL) { - fprintf(stderr, "**OUT OF MEMORY**\n"); + fprintf(stderr, "ERROR: out of memory at %s:%d: %s()\n", file, line, func); abort(); } @@ -266,7 +265,6 @@ xstype xs_type(const xs_val *data) case XSTYPE_DICT: case XSTYPE_KEYVAL: case XSTYPE_NUMBER: - case XSTYPE_EOM: case XSTYPE_DATA: t = data[0]; break; @@ -696,7 +694,7 @@ xs_list *xs_list_new(void) { int sz = 1 + _XS_TYPE_SIZE + 1; xs_list *l = xs_realloc(NULL, sz); - memset(l, XSTYPE_EOM, sz); + memset(l, '\0', sz); l[0] = XSTYPE_LIST; _xs_put_size(l, sz); diff --git a/xs_mime.h b/xs_mime.h index 853b092..b016490 100644 --- a/xs_mime.h +++ b/xs_mime.h @@ -1,8 +1,8 @@ /* copyright (c) 2022 - 2024 grunfink et al. / MIT license */ -#ifndef _XS_MIME +#ifndef _XS_MIME_H -#define _XS_MIME +#define _XS_MIME_H const char *xs_mime_by_ext(const char *file); @@ -81,4 +81,4 @@ const char *xs_mime_by_ext(const char *file) #endif /* XS_IMPLEMENTATION */ -#endif /* XS_MIME */ +#endif /* XS_MIME_H */ diff --git a/xs_set.h b/xs_set.h index 94c2b84..f6b65aa 100644 --- a/xs_set.h +++ b/xs_set.h @@ -47,7 +47,7 @@ xs_list *xs_set_result(xs_set *s) void xs_set_free(xs_set *s) /* frees a set, dropping the list */ { - free(xs_set_result(s)); + xs_free(xs_set_result(s)); } diff --git a/xs_unicode.h b/xs_unicode.h index a5a1dcb..9663190 100644 --- a/xs_unicode.h +++ b/xs_unicode.h @@ -33,6 +33,8 @@ #ifdef XS_IMPLEMENTATION +#include + #ifndef xs_countof #define xs_countof(a) (sizeof((a)) / sizeof((*a))) #endif diff --git a/xs_version.h b/xs_version.h index 8697701..13aa7c6 100644 --- a/xs_version.h +++ b/xs_version.h @@ -1 +1 @@ -/* 9c3dd1b1165c25baa154e82d8d278926e376af81 2024-09-14T18:18:42+02:00 */ +/* ae3126a2d093c6bb5c36328e27bc93a452aff379 2024-09-20T07:39:32+02:00 */