From 8cf7559a7e21c5757455b948814d61e6e96f08f1 Mon Sep 17 00:00:00 2001 From: default Date: Thu, 23 May 2024 10:01:37 +0200 Subject: [PATCH] Added more const. --- activitypub.c | 39 +++++++++++++++++----------------- data.c | 58 +++++++++++++++++++++++++++------------------------ format.c | 11 ++++++---- html.c | 36 ++++++++++++++++---------------- http.c | 6 +++--- httpd.c | 9 ++++---- main.c | 2 +- mastoapi.c | 50 ++++++++++++++++++++++---------------------- upgrade.c | 37 ++++++++++++++++++++------------ utils.c | 10 ++++----- webfinger.c | 2 +- xs.h | 34 +++++++++++++++--------------- xs_curl.h | 4 ++-- xs_fcgi.h | 4 ++-- xs_httpd.h | 4 ++-- xs_json.h | 4 ++-- xs_regex.h | 4 ++-- xs_set.h | 3 ++- xs_url.h | 2 +- xs_version.h | 2 +- 20 files changed, 171 insertions(+), 150 deletions(-) diff --git a/activitypub.c b/activitypub.c index f4b4eac..6e40a88 100644 --- a/activitypub.c +++ b/activitypub.c @@ -163,7 +163,7 @@ const char *get_atto(const xs_dict *msg) if (xs_type(actor) == XSTYPE_LIST) { const xs_list *p = actor; int c = 0; - xs_dict *v; + const xs_dict *v; actor = NULL; while (actor == NULL && xs_list_next(p, &v, &c)) { @@ -192,7 +192,7 @@ xs_list *get_attachments(const xs_dict *msg) /* try first the attachments list */ if (!xs_is_null(p = xs_dict_get(msg, "attachment"))) { xs *attach = NULL; - xs_val *v; + const xs_val *v; /* ensure it's a list */ if (xs_type(p) == XSTYPE_DICT) { @@ -257,7 +257,7 @@ xs_list *get_attachments(const xs_dict *msg) const char *href = NULL; const char *type = NULL; int c = 0; - xs_val *v; + const xs_val *v; while (href == NULL && xs_list_next(p, &v, &c)) { if (xs_type(v) == XSTYPE_DICT) { @@ -271,7 +271,7 @@ xs_list *get_attachments(const xs_dict *msg) strcmp(mtype, "application/x-mpegURL") == 0 && xs_type(tag) == XSTYPE_LIST) { /* now iterate the tag list, looking for a video URL */ - xs_dict *d; + const xs_dict *d; int c = 0; while (href == NULL && xs_list_next(tag, &d, &c)) { @@ -482,7 +482,7 @@ xs_list *recipient_list(snac *snac, const xs_dict *msg, int expand_public) const xs_list *lists[] = { to, cc, NULL }; for (n = 0; lists[n]; n++) { xs_list *l = (xs_list *)lists[n]; - char *v; + const char *v; xs *tl = NULL; /* if it's a string, create a list with only one element */ @@ -497,7 +497,7 @@ xs_list *recipient_list(snac *snac, const xs_dict *msg, int expand_public) if (expand_public && strcmp(v, public_address) == 0) { /* iterate the followers and add them */ xs *fwers = follower_list(snac); - char *actor; + const char *actor; char *p = fwers; while (xs_list_iter(&p, &actor)) @@ -628,7 +628,7 @@ int is_msg_for_me(snac *snac, const xs_dict *c_msg) const xs_dict *msg = xs_dict_get(c_msg, "object"); xs *rcpts = recipient_list(snac, msg, 0); xs_list *p = rcpts; - xs_str *v; + const xs_str *v; xs *actor_followers = NULL; @@ -693,7 +693,7 @@ xs_str *process_tags(snac *snac, const char *content, xs_list **tag) xs_list *tl = *tag; xs *split; xs_list *p; - xs_val *v; + const xs_val *v; int n = 0; /* create a default server for incomplete mentions */ @@ -1205,8 +1205,8 @@ xs_dict *msg_actor(snac *snac) const xs_dict *metadata = xs_dict_get(snac->config, "metadata"); if (xs_type(metadata) == XSTYPE_DICT) { xs *attach = xs_list_new(); - xs_str *k; - xs_str *v; + const xs_str *k; + const xs_str *v; int c = 0; while (xs_dict_next(metadata, &k, &v, &c)) { @@ -1351,7 +1351,7 @@ xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts, xs *atls = xs_list_new(); xs_dict *msg = msg_base(snac, "Note", id, NULL, "@now", NULL); xs_list *p; - xs_val *v; + const xs_val *v; if (rcpts == NULL) to = xs_list_new(); @@ -1528,7 +1528,7 @@ xs_dict *msg_question(snac *user, const char *content, xs_list *attach, xs *o = xs_list_new(); xs_list *p = (xs_list *)opts; - xs_str *v; + const xs_str *v; xs *replies = xs_json_loads("{\"type\":\"Collection\",\"totalItems\":0}"); xs_set_init(&seen); @@ -1576,7 +1576,7 @@ int update_question(snac *user, const char *id) xs *lopts = xs_list_new(); const xs_list *opts; xs_list *p; - xs_val *v; + const xs_val *v; /* get the object */ if (!valid_status(object_get(id, &msg))) @@ -2190,7 +2190,7 @@ void process_user_queue_item(snac *snac, xs_dict *q_item) xs *rcpts = recipient_list(snac, msg, 1); xs_set inboxes; xs_list *p; - xs_str *actor; + const xs_str *actor; xs_set_init(&inboxes); @@ -2212,7 +2212,7 @@ void process_user_queue_item(snac *snac, xs_dict *q_item) if (is_msg_public(msg)) { if (xs_type(xs_dict_get(srv_config, "disable_inbox_collection")) != XSTYPE_TRUE) { xs *shibx = inbox_list(); - xs_str *inbox; + const xs_str *inbox; p = shibx; while (xs_list_iter(&p, &inbox)) { @@ -2304,7 +2304,7 @@ int process_user_queue(snac *snac) xs *list = user_queue(snac); xs_list *p = list; - xs_str *fn; + const xs_str *fn; while (xs_list_iter(&p, &fn)) { xs *q_item = dequeue(fn); @@ -2511,7 +2511,7 @@ void process_queue_item(xs_dict *q_item) xs *users = user_list(); xs_list *p = users; - char *v; + const char *v; int cnt = 0; while (xs_list_iter(&p, &v)) { @@ -2554,7 +2554,7 @@ int process_queue(void) xs *list = queue(); xs_list *p = list; - xs_str *fn; + const xs_str *fn; while (xs_list_iter(&p, &fn)) { xs *q_item = dequeue(fn); @@ -2616,7 +2616,8 @@ int activitypub_get_handler(const xs_dict *req, const char *q_path, xs *elems = timeline_simple_list(&snac, "public", 0, 20); xs *list = xs_list_new(); msg = msg_collection(&snac, id); - char *p, *v; + char *p; + const char *v; p = elems; while (xs_list_iter(&p, &v)) { diff --git a/data.c b/data.c index 6ac115d..f507078 100644 --- a/data.c +++ b/data.c @@ -193,7 +193,7 @@ int user_open(snac *user, const char *uid) xs *lcuid = xs_tolower_i(xs_dup(uid)); xs *ulist = user_list(); xs_list *p = ulist; - xs_str *v; + const xs_str *v; while (xs_list_iter(&p, &v)) { xs *v2 = xs_tolower_i(xs_dup(v)); @@ -289,7 +289,7 @@ int user_open_by_md5(snac *snac, const char *md5) { xs *ulist = user_list(); xs_list *p = ulist; - xs_str *v; + const xs_str *v; while (xs_list_iter(&p, &v)) { user_open(snac, v); @@ -772,7 +772,8 @@ int object_del_by_md5(const char *md5) xs *spec = xs_dup(fn); spec = xs_replace_i(spec, ".json", "*.idx"); xs *files = xs_glob(spec, 0, 0); - char *p, *v; + char *p; + const char *v; p = files; while (xs_list_iter(&p, &v)) { @@ -1033,7 +1034,8 @@ xs_list *follower_list(snac *snac) { xs *list = object_user_cache_list(snac, "followers", XS_ALL, 0); xs_list *fwers = xs_list_new(); - char *p, *v; + char *p; + const char *v; /* resolve the list of md5 to be a list of actors */ p = list; @@ -1196,7 +1198,7 @@ xs_list *timeline_top_level(snac *snac, const xs_list *list) /* returns the top level md5 entries from this index */ { xs_set seen; - xs_str *v; + const xs_str *v; xs_set_init(&seen); @@ -1367,7 +1369,7 @@ xs_list *following_list(snac *snac) xs *spec = xs_fmt("%s/following/" "*.json", snac->basedir); xs *glist = xs_glob(spec, 0, 0); xs_list *p; - xs_str *v; + const xs_str *v; xs_list *list = xs_list_new(); /* iterate the list of files */ @@ -1537,7 +1539,8 @@ void hide(snac *snac, const char *id) /* hide all the children */ xs *chld = object_children(id); - char *p, *v; + char *p; + const char *v; p = chld; while (xs_list_iter(&p, &v)) { @@ -1694,7 +1697,7 @@ void tag_index(const char *id, const xs_dict *obj) mkdirx(g_tag_dir); - xs_dict *v; + const xs_dict *v; int ct = 0; while (xs_list_next(tags, &v, &ct)) { const char *type = xs_dict_get(v, "type"); @@ -1758,7 +1761,7 @@ xs_val *list_maint(snac *user, const char *list, int op) xs *spec = xs_fmt("%s/list/" "*.id", user->basedir); xs *ls = xs_glob(spec, 0, 0); int c = 0; - char *v; + const char *v; l = xs_list_new(); @@ -1784,7 +1787,7 @@ xs_val *list_maint(snac *user, const char *list, int op) { xs *lol = list_maint(user, NULL, 0); int c = 0; - xs_list *v; + const xs_list *v; int add = 1; /* check if this list name already exists */ @@ -1925,7 +1928,7 @@ void list_distribute(snac *user, const char *who, const xs_dict *post) xs *spec = xs_fmt("%s/list/" "*.lst", user->basedir); xs *ls = xs_glob(spec, 0, 0); int c = 0; - char *v; + const char *v; while (xs_list_next(ls, &v, &c)) { /* is the actor in this list? */ @@ -2183,7 +2186,7 @@ xs_list *inbox_list(void) xs *spec = xs_fmt("%s/inbox/" "*", srv_basedir); xs *files = xs_glob(spec, 0, 0); xs_list *p = files; - xs_val *v; + const xs_val *v; while (xs_list_iter(&p, &v)) { FILE *f; @@ -2329,8 +2332,8 @@ xs_list *content_search(snac *user, const char *regex, /* iterate all timelines simultaneously */ xs_list *tls[3] = {0}; - char *md5s[3] = {0}; - int c[3] = {0}; + const char *md5s[3] = {0}; + int c[3] = {0}; tls[0] = timeline_simple_list(user, "public", 0, XS_ALL); /* public */ tls[1] = timeline_instance_list(0, XS_ALL); /* instance */ @@ -2368,7 +2371,7 @@ xs_list *content_search(snac *user, const char *regex, if (newest == -1) break; - char *md5 = md5s[newest]; + const char *md5 = md5s[newest]; /* advance the chosen timeline */ if (!xs_list_next(tls[newest], &md5s[newest], &c[newest])) @@ -2534,7 +2537,7 @@ xs_list *notify_list(snac *snac, int skip, int show) xs *spec = xs_fmt("%s/notify/" "*.json", snac->basedir); xs *lst = xs_glob(spec, 1, 0); xs_list *p = lst; - char *v; + const char *v; while (xs_list_iter(&p, &v)) { char *p = strrchr(v, '.'); @@ -2562,7 +2565,7 @@ int notify_new_num(snac *snac) int cnt = 0; xs_list *p = lst; - xs_str *v; + const xs_str *v; while (xs_list_iter(&p, &v)) { xs *id = xs_strip_i(xs_dup(v)); @@ -2584,7 +2587,7 @@ void notify_clear(snac *snac) xs *spec = xs_fmt("%s/notify/" "*", snac->basedir); xs *lst = xs_glob(spec, 0, 0); xs_list *p = lst; - xs_str *v; + const xs_str *v; while (xs_list_iter(&p, &v)) unlink(v); @@ -2842,7 +2845,7 @@ int was_question_voted(snac *user, const char *id) xs *children = object_children(id); int voted = 0; xs_list *p; - xs_str *md5; + const xs_str *md5; p = children; while (xs_list_iter(&p, &md5)) { @@ -2869,7 +2872,7 @@ xs_list *user_queue(snac *snac) xs_list *list = xs_list_new(); time_t t = time(NULL); xs_list *p; - xs_val *v; + const xs_val *v; xs *fns = xs_glob(spec, 0, 0); @@ -2898,7 +2901,7 @@ xs_list *queue(void) xs_list *list = xs_list_new(); time_t t = time(NULL); xs_list *p; - xs_val *v; + const xs_val *v; xs *fns = xs_glob(spec, 0, 0); @@ -2974,7 +2977,7 @@ static void _purge_dir(const char *dir, int days) xs *spec = xs_fmt("%s/" "*", dir); xs *list = xs_glob(spec, 0, 0); xs_list *p; - xs_str *v; + const xs_str *v; p = list; while (xs_list_iter(&p, &v)) @@ -3000,7 +3003,7 @@ void purge_server(void) xs *spec = xs_fmt("%s/object/??", srv_basedir); xs *dirs = xs_glob(spec, 0, 0); xs_list *p; - xs_str *v; + const xs_str *v; int cnt = 0; int icnt = 0; @@ -3009,7 +3012,7 @@ void purge_server(void) p = dirs; while (xs_list_iter(&p, &v)) { xs_list *p2; - xs_str *v2; + const xs_str *v2; { xs *spec2 = xs_fmt("%s/" "*.json", v); @@ -3088,7 +3091,7 @@ void purge_server(void) xs *spec2 = xs_fmt("%s/" "*.idx", v); xs *files = xs_glob(spec2, 0, 0); xs_list *p2; - xs_str *v2; + const xs_str *v2; p2 = files; while (xs_list_iter(&p2, &v2)) { @@ -3152,7 +3155,7 @@ void purge_user(snac *snac) xs *spec = xs_fmt("%s/list/" "*.idx", snac->basedir); xs *lol = xs_glob(spec, 0, 0); int c = 0; - char *v; + const char *v; while (xs_list_next(lol, &v, &c)) { int gc = index_gc(v); @@ -3170,7 +3173,8 @@ void purge_all(void) { snac snac; xs *list = user_list(); - char *p, *uid; + char *p; + const char *uid; p = list; while (xs_list_iter(&p, &uid)) { diff --git a/format.c b/format.c index df3b5d9..b021f55 100644 --- a/format.c +++ b/format.c @@ -82,7 +82,8 @@ static xs_str *format_line(const char *line, xs_list **attach) /* formats a line */ { xs_str *s = xs_str_new(NULL); - char *p, *v; + char *p; + const char *v; /* split by markup */ xs *sm = xs_regex_split(line, @@ -155,7 +156,8 @@ xs_str *not_really_markdown(const char *content, xs_list **attach, xs_list **tag int in_pre = 0; int in_blq = 0; xs *list; - char *p, *v; + char *p; + const char *v; /* work by lines */ list = xs_split(content, "\n"); @@ -234,7 +236,7 @@ xs_str *not_really_markdown(const char *content, xs_list **attach, xs_list **tag /* traditional emoticons */ xs *d = emojis(); int c = 0; - char *k, *v; + const char *k, *v; while (xs_dict_next(d, &k, &v, &c)) { const char *t = NULL; @@ -280,7 +282,8 @@ xs_str *sanitize(const char *content) xs_str *s = xs_str_new(NULL); xs *sl; int n = 0; - char *p, *v; + char *p; + const char *v; sl = xs_regex_split(content, "]+>"); diff --git a/html.c b/html.c index 6521726..11fe4bf 100644 --- a/html.c +++ b/html.c @@ -57,7 +57,7 @@ xs_str *replace_shortnames(xs_str *s, const xs_list *tag, int ems) xs *style = xs_fmt("height: %dem; width: %dem; vertical-align: middle;", ems, ems); - char *v; + const char *v; int c = 0; while (xs_list_next(tag_list, &v, &c)) { @@ -461,7 +461,7 @@ static xs_html *html_base_head(void) xs *f; f = xs_fmt("%s/favicon.ico", srv_baseurl); const xs_list *p = xs_dict_get(srv_config, "cssurls"); - char *v; + const char *v; int c = 0; while (xs_list_next(p, &v, &c)) { @@ -801,8 +801,8 @@ static xs_html *html_user_body(snac *user, int read_only) const xs_dict *metadata = xs_dict_get(user->config, "metadata"); if (xs_type(metadata) == XSTYPE_DICT) { - xs_str *k; - xs_str *v; + const xs_str *k; + const xs_str *v; xs_dict *val_links = user->links; if (xs_is_null(val_links)) @@ -974,8 +974,8 @@ xs_html *html_top_controls(snac *snac) xs *metadata = xs_str_new(NULL); const xs_dict *md = xs_dict_get(snac->config, "metadata"); - xs_str *k; - xs_str *v; + const xs_str *k; + const xs_str *v; int c = 0; while (xs_dict_next(md, &k, &v, &c)) { @@ -1161,7 +1161,7 @@ xs_str *build_mentions(snac *snac, const xs_dict *msg) { xs_str *s = xs_str_new(NULL); const char *list = xs_dict_get(msg, "tag"); - char *v; + const char *v; int c = 0; while (xs_list_next(list, &v, &c)) { @@ -1372,7 +1372,7 @@ xs_html *html_entry_controls(snac *snac, const char *actor, xs_html *html_entry(snac *user, xs_dict *msg, int read_only, - int level, char *md5, int hide_children) + int level, const char *md5, int hide_children) { const char *id = xs_dict_get(msg, "id"); const char *type = xs_dict_get(msg, "type"); @@ -1670,7 +1670,7 @@ xs_html *html_entry(snac *user, xs_dict *msg, int read_only, const xs_list *oo = xs_dict_get(msg, "oneOf"); const xs_list *ao = xs_dict_get(msg, "anyOf"); const xs_list *p; - xs_dict *v; + const xs_dict *v; int closed = 0; const char *f_closed = NULL; @@ -1827,7 +1827,7 @@ xs_html *html_entry(snac *user, xs_dict *msg, int read_only, content_attachments); int c = 0; - xs_dict *a; + const xs_dict *a; while (xs_list_next(attach, &a, &c)) { const char *type = xs_dict_get(a, "type"); const char *href = xs_dict_get(a, "href"); @@ -1945,7 +1945,7 @@ xs_html *html_entry(snac *user, xs_dict *msg, int read_only, } xs_list *p = children; - char *cmd5; + const char *cmd5; int cnt = 0; int o_cnt = 0; @@ -2021,7 +2021,7 @@ xs_str *html_timeline(snac *user, const xs_list *list, int read_only, /* returns the HTML for the timeline */ { xs_list *p = (xs_list *)list; - char *v; + const char *v; double t = ftime(); xs *desc = NULL; @@ -2130,7 +2130,7 @@ xs_str *html_timeline(snac *user, const xs_list *list, int read_only, xs *list = history_list(user); xs_list *p = list; - char *v; + const char *v; while (xs_list_iter(&p, &v)) { xs *fn = xs_replace(v, ".html", ""); @@ -2203,7 +2203,7 @@ xs_html *html_people_list(snac *snac, xs_list *list, char *header, char *t) xs_html_text("...")))); xs_list *p = list; - char *actor_id; + const char *actor_id; while (xs_list_iter(&p, &actor_id)) { xs *md5 = xs_md5_hex(actor_id, strlen(actor_id)); @@ -2363,7 +2363,7 @@ xs_str *html_notifications(snac *user, int skip, int show) xs_html *noti_seen = NULL; xs_list *p = n_list; - xs_str *v; + const xs_str *v; while (xs_list_iter(&p, &v)) { xs *noti = notify_get(user, v); @@ -3232,7 +3232,7 @@ int html_post_handler(const xs_dict *req, const char *q_path, xs_dict *md = xs_dict_new(); xs *l = xs_split(v, "\n"); xs_list *p = l; - xs_str *kp; + const xs_str *kp; while (xs_list_iter(&p, &kp)) { xs *kpl = xs_split_n(kp, "=", 1); @@ -3333,7 +3333,7 @@ int html_post_handler(const xs_dict *req, const char *q_path, } xs_list *p = ls; - xs_str *v; + const xs_str *v; while (xs_list_iter(&p, &v)) { xs *msg = msg_note(&snac, "", actor, irt, NULL, 1); @@ -3405,7 +3405,7 @@ xs_str *timeline_to_rss(snac *user, const xs_list *timeline, char *title, char * xs_html_add(rss, channel); int c = 0; - char *v; + const char *v; while (xs_list_next(timeline, &v, &c)) { xs *msg = NULL; diff --git a/http.c b/http.c index 4d85631..b21f1dc 100644 --- a/http.c +++ b/http.c @@ -26,7 +26,7 @@ xs_dict *http_signed_request_raw(const char *keyid, const char *seckey, xs *hdrs = NULL; const char *host; const char *target; - char *k, *v; + const char *k, *v; xs_dict *response; date = xs_str_utctime(0, "%a, %d %b %Y %H:%M:%S GMT"); @@ -144,7 +144,7 @@ int check_signature(const xs_dict *req, xs_str **err) /* extract the values */ xs *l = xs_split(sig_hdr, ","); int c = 0; - xs_val *v; + const xs_val *v; while (xs_list_next(l, &v, &c)) { xs *kv = xs_split_n(v, "=", 1); @@ -205,7 +205,7 @@ int check_signature(const xs_dict *req, xs_str **err) { xs *l = xs_split(headers, " "); xs_list *p; - xs_val *v; + const xs_val *v; p = l; while (xs_list_iter(&p, &v)) { diff --git a/httpd.c b/httpd.c index 8a20c89..a7396e8 100644 --- a/httpd.c +++ b/httpd.c @@ -75,7 +75,7 @@ xs_str *nodeinfo_2_0(void) int n_posts = 0; xs *users = user_list(); xs_list *p = users; - char *v; + const char *v; double now = (double)time(NULL); while (xs_list_iter(&p, &v)) { @@ -128,7 +128,7 @@ static xs_str *greeting_html(void) const char *host = xs_dict_get(srv_config, "host"); xs *list = user_list(); xs_list *p = list; - xs_str *uid; + const xs_str *uid; xs_html *ul = xs_html_tag("ul", xs_html_attr("class", "snac-user-list")); @@ -413,7 +413,7 @@ void httpd_connection(FILE *f) /* if there are any additional headers, add them */ const xs_dict *more_headers = xs_dict_get(srv_config, "http_headers"); if (xs_type(more_headers) == XSTYPE_DICT) { - char *k, *v; + const char *k, *v; int c = 0; while (xs_dict_next(more_headers, &k, &v, &c)) headers = xs_dict_set(headers, k, v); @@ -590,7 +590,8 @@ static void *background_thread(void *arg) { xs *list = user_list(); - char *p, *uid; + char *p; + const char *uid; /* process queues for all users */ p = list; diff --git a/main.c b/main.c index 9c906a6..c88eebe 100644 --- a/main.c +++ b/main.c @@ -382,7 +382,7 @@ int main(int argc, char *argv[]) xs *r = content_search(&snac, url, 1, 0, XS_ALL, 10, &to); int c = 0; - char *v; + const char *v; /* print results as standalone links */ while (xs_list_next(r, &v, &c)) { diff --git a/mastoapi.c b/mastoapi.c index 852713e..3936c2a 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -599,7 +599,7 @@ xs_dict *mastoapi_account(const xs_dict *actor) const xs_list *p; if (!xs_is_null(p = xs_dict_get(actor, "tag"))) { xs *eml = xs_list_new(); - xs_dict *v; + const xs_dict *v; int c = 0; while (xs_list_next(p, &v, &c)) { @@ -637,7 +637,7 @@ xs_dict *mastoapi_account(const xs_dict *actor) xs *fields = xs_list_new(); p = xs_dict_get(actor, "attachment"); - xs_dict *v; + const xs_dict *v; /* dict of validated links */ xs_dict *val_links = NULL; @@ -713,7 +713,7 @@ xs_dict *mastoapi_poll(snac *snac, const xs_dict *msg) xs_dict *poll = xs_dict_new(); xs *mid = mastoapi_id(msg); const xs_list *opts = NULL; - xs_val *v; + const xs_val *v; int num_votes = 0; xs *options = xs_list_new(); @@ -849,7 +849,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) { xs_list *p = attach; - xs_dict *v; + const xs_dict *v; xs *matt = xs_list_new(); @@ -898,7 +898,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) tag_list = xs_list_new(); tag = tag_list; - xs_dict *v; + const xs_dict *v; int c = 0; while (xs_list_next(tag, &v, &c)) { @@ -1210,8 +1210,8 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, const xs_dict *metadata = xs_dict_get(snac1.config, "metadata"); if (xs_type(metadata) == XSTYPE_DICT) { xs *fields = xs_list_new(); - xs_str *k; - xs_str *v; + const xs_str *k; + const xs_str *v; xs_dict *val_links = snac1.links; if (xs_is_null(val_links)) @@ -1334,7 +1334,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, xs *wers = follower_list(&snac1); xs *ulst = user_list(); xs_list *p; - xs_str *v; + const xs_str *v; xs_set seen; xs_set_init(&seen); @@ -1410,7 +1410,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, /* the public list of posts of a user */ xs *timeline = timeline_simple_list(&snac2, "public", 0, 256); xs_list *p = timeline; - xs_str *v; + const xs_str *v; out = xs_list_new(); @@ -1475,7 +1475,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, xs *out = xs_list_new(); xs_list *p = timeline; - xs_str *v; + const xs_str *v; while (xs_list_iter(&p, &v) && cnt < limit) { xs *msg = NULL; @@ -1579,7 +1579,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, xs *timeline = timeline_instance_list(0, limit); xs *out = xs_list_new(); xs_list *p = timeline; - xs_str *md5; + const xs_str *md5; snac *user = NULL; if (logged_in) @@ -1633,7 +1633,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, xs *timeline = tag_search(tag, 0, limit); xs *out = xs_list_new(); xs_list *p = timeline; - xs_str *md5; + const xs_str *md5; while (xs_list_iter(&p, &md5) && cnt < limit) { xs *msg = NULL; @@ -1673,7 +1673,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, xs *timeline = list_timeline(&snac1, list, 0, 2048); xs *out = xs_list_new(); int c = 0; - char *md5; + const char *md5; while (xs_list_next(timeline, &md5, &c)) { xs *msg = NULL; @@ -1747,7 +1747,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, xs *l = notify_list(&snac1, 0, 64); xs *out = xs_list_new(); xs_list *p = l; - xs_dict *v; + const xs_dict *v; const xs_list *excl = xs_dict_get(args, "exclude_types[]"); while (xs_list_iter(&p, &v)) { @@ -1858,7 +1858,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, xs *lol = list_maint(&snac1, NULL, 0); xs *l = xs_list_new(); int c = 0; - xs_list *li; + const xs_list *li; while (xs_list_next(lol, &li, &c)) { xs *d = xs_dict_new(); @@ -1890,7 +1890,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, xs *actors = list_content(&snac1, p, NULL, 0); xs *out = xs_list_new(); int c = 0; - char *v; + const char *v; while (xs_list_next(actors, &v, &c)) { xs *actor = NULL; @@ -1911,7 +1911,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, xs *out = xs_list_new(); xs *lol = list_maint(&snac1, NULL, 0); int c = 0; - xs_list *v; + const xs_list *v; while (xs_list_next(lol, &v, &c)) { const char *id = xs_list_get(v, 0); @@ -2105,7 +2105,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, xs *anc = xs_list_new(); xs *des = xs_list_new(); xs_list *p; - xs_str *v; + const xs_str *v; char pid[64]; /* build the [grand]parent list, moving up */ @@ -2159,7 +2159,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, l = object_likes(xs_dict_get(msg, "id")); xs_list *p = l; - xs_str *v; + const xs_str *v; while (xs_list_iter(&p, &v)) { xs *actor2 = NULL; @@ -2267,7 +2267,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, int cnt = 40; xs *tl = content_search(&snac1, q, 1, 0, cnt, 0, &to); int c = 0; - char *v; + const char *v; while (xs_list_next(tl, &v, &c) && --cnt) { xs *post = NULL; @@ -2433,7 +2433,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, } xs_list *p = mi; - xs_str *v; + const xs_str *v; while (xs_list_iter(&p, &v)) { xs *l = xs_list_new(); @@ -2783,7 +2783,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, choices = xs_dict_get(args, "choices"); if (xs_type(choices) == XSTYPE_LIST) { - xs_str *v; + const xs_str *v; int c = 0; while (xs_list_next(choices, &v, &c)) { @@ -2855,7 +2855,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, if (strcmp(op, "accounts") == 0) { const xs_list *accts = xs_dict_get(args, "account_ids[]"); int c = 0; - char *v; + const char *v; while (xs_list_next(accts, &v, &c)) { list_content(&snac, id, v, 1); @@ -2934,7 +2934,7 @@ int mastoapi_delete_handler(const xs_dict *req, const char *q_path, p = xs_list_get(l, -2); const xs_list *accts = xs_dict_get(args, "account_ids[]"); int c = 0; - char *v; + const char *v; while (xs_list_next(accts, &v, &c)) { list_content(&snac, p, v, 2); @@ -3083,7 +3083,7 @@ void mastoapi_purge(void) xs *spec = xs_fmt("%s/app/" "*.json", srv_basedir); xs *files = xs_glob(spec, 1, 0); xs_list *p = files; - xs_str *v; + const xs_str *v; time_t mt = time(NULL) - 3600; diff --git a/upgrade.c b/upgrade.c index 266a4be..847c62e 100644 --- a/upgrade.c +++ b/upgrade.c @@ -43,7 +43,8 @@ int snac_upgrade(xs_str **error) else if (f < 2.2) { xs *users = user_list(); - char *p, *v; + char *p; + const char *v; p = users; while (xs_list_iter(&p, &v)) { @@ -52,7 +53,8 @@ int snac_upgrade(xs_str **error) if (user_open(&snac, v)) { xs *spec = xs_fmt("%s/actors/" "*.json", snac.basedir); xs *list = xs_glob(spec, 0, 0); - char *g, *fn; + char *g; + const char *fn; g = list; while (xs_list_iter(&g, &fn)) { @@ -77,14 +79,16 @@ int snac_upgrade(xs_str **error) else if (f < 2.3) { xs *users = user_list(); - char *p, *v; + char *p; + const char *v; p = users; while (xs_list_iter(&p, &v)) { snac snac; if (user_open(&snac, v)) { - char *p, *v; + char *p; + const char *v; xs *dir = xs_fmt("%s/hidden", snac.basedir); /* create the hidden directory */ @@ -109,7 +113,8 @@ int snac_upgrade(xs_str **error) else if (f < 2.4) { xs *users = user_list(); - char *p, *v; + char *p; + const char *v; p = users; while (xs_list_iter(&p, &v)) { @@ -132,7 +137,8 @@ int snac_upgrade(xs_str **error) if (f < 2.5) { /* upgrade followers */ xs *users = user_list(); - char *p, *v; + char *p; + const char *v; p = users; while (xs_list_iter(&p, &v)) { @@ -141,7 +147,8 @@ int snac_upgrade(xs_str **error) if (user_open(&snac, v)) { xs *spec = xs_fmt("%s/followers/" "*.json", snac.basedir); xs *dir = xs_glob(spec, 0, 0); - char *p, *v; + char *p; + const char *v; p = dir; while (xs_list_iter(&p, &v)) { @@ -175,7 +182,8 @@ int snac_upgrade(xs_str **error) if (f < 2.6) { /* upgrade local/ to public/ */ xs *users = user_list(); - char *p, *v; + char *p; + const char *v; p = users; while (xs_list_iter(&p, &v)) { @@ -184,7 +192,8 @@ int snac_upgrade(xs_str **error) if (user_open(&snac, v)) { xs *spec = xs_fmt("%s/local/" "*.json", snac.basedir); xs *dir = xs_glob(spec, 0, 0); - char *p, *v; + char *p; + const char *v; p = dir; while (xs_list_iter(&p, &v)) { @@ -206,7 +215,7 @@ int snac_upgrade(xs_str **error) /* if it's from us, add to public */ if (xs_startswith(id, snac.actor)) { const xs_list *p; - char *v; + const char *v; int c; object_user_cache_add(&snac, id, "public"); @@ -241,7 +250,8 @@ int snac_upgrade(xs_str **error) if (f < 2.7) { /* upgrade timeline/ to private/ */ xs *users = user_list(); - char *p, *v; + char *p; + const char *v; p = users; while (xs_list_iter(&p, &v)) { @@ -250,7 +260,8 @@ int snac_upgrade(xs_str **error) if (user_open(&snac, v)) { xs *spec = xs_fmt("%s/timeline/" "*.json", snac.basedir); xs *dir = xs_glob(spec, 0, 0); - char *p, *v; + char *p; + const char *v; p = dir; while (xs_list_iter(&p, &v)) { @@ -271,7 +282,7 @@ int snac_upgrade(xs_str **error) { const xs_list *p; - char *v; + const char *v; int c = 0; object_user_cache_add(&snac, id, "private"); diff --git a/utils.c b/utils.c index daaa583..0e8e3be 100644 --- a/utils.c +++ b/utils.c @@ -358,7 +358,7 @@ void rm_rf(const char *dir) xs *d = xs_str_cat(xs_dup(dir), "/" "*"); xs *l = xs_glob(d, 0, 0); xs_list *p = l; - xs_str *v; + const xs_str *v; if (dbglevel >= 1) printf("Deleting directory %s\n", dir); @@ -393,7 +393,7 @@ int deluser(snac *user) int ret = 0; xs *fwers = following_list(user); xs_list *p = fwers; - xs_str *v; + const xs_str *v; while (xs_list_iter(&p, &v)) { xs *object = NULL; @@ -419,7 +419,7 @@ void verify_links(snac *user) /* verifies a user's links */ { const xs_dict *p = xs_dict_get(user->config, "metadata"); - char *k, *v; + const char *k, *v; int changed = 0; xs *headers = xs_dict_new(); @@ -449,7 +449,7 @@ void verify_links(snac *user) xs *ls = xs_regex_select(payload, "< *(a|link) +[^>]+>"); xs_list *lp = ls; - char *ll; + const char *ll; int vfied = 0; while (!vfied && xs_list_iter(&lp, &ll)) { @@ -463,7 +463,7 @@ void verify_links(snac *user) xs *href = NULL; int is_rel_me = 0; xs_list *pr = r; - char *ar; + const char *ar; while (xs_list_iter(&pr, &ar)) { xs *nq = xs_dup(ar); diff --git a/webfinger.c b/webfinger.c index b1d85e9..c79fd44 100644 --- a/webfinger.c +++ b/webfinger.c @@ -96,7 +96,7 @@ int webfinger_request_signed(snac *snac, const char *qs, char **actor, char **us if (actor != NULL) { const xs_list *list = xs_dict_get(obj, "links"); int c = 0; - char *v; + const char *v; while (xs_list_next(list, &v, &c)) { if (xs_type(v) == XSTYPE_DICT) { diff --git a/xs.h b/xs.h index b46f0e1..f361830 100644 --- a/xs.h +++ b/xs.h @@ -94,8 +94,8 @@ xs_list *xs_list_new(void); xs_list *xs_list_append_m(xs_list *list, const char *mem, int dsz); xs_list *_xs_list_append(xs_list *list, const xs_val *vals[]); #define xs_list_append(list, ...) _xs_list_append(list, (const xs_val *[]){ __VA_ARGS__, NULL }) -int xs_list_iter(xs_list **list, xs_val **value); -int xs_list_next(const xs_list *list, xs_val **value, int *ctxt); +int xs_list_iter(xs_list **list, const xs_val **value); +int xs_list_next(const xs_list *list, const xs_val **value, int *ctxt); int xs_list_len(const xs_list *list); const xs_val *xs_list_get(const xs_list *list, int num); xs_list *xs_list_del(xs_list *list, int num); @@ -118,7 +118,7 @@ xs_keyval *xs_keyval_make(xs_keyval *keyval, const xs_str *key, const xs_val *va xs_dict *xs_dict_new(void); xs_dict *xs_dict_append(xs_dict *dict, const xs_str *key, const xs_val *value); xs_dict *xs_dict_prepend(xs_dict *dict, const xs_str *key, const xs_val *value); -int xs_dict_next(const xs_dict *dict, xs_str **key, xs_val **value, int *ctxt); +int xs_dict_next(const xs_dict *dict, const xs_str **key, const xs_val **value, int *ctxt); const xs_val *xs_dict_get_def(const xs_dict *dict, const xs_str *key, const xs_val *def); #define xs_dict_get(dict, key) xs_dict_get_def(dict, key, NULL) xs_dict *xs_dict_del(xs_dict *dict, const xs_str *key); @@ -726,7 +726,7 @@ xs_list *_xs_list_append(xs_list *list, const xs_val *vals[]) } -int xs_list_iter(xs_list **list, xs_val **value) +int xs_list_iter(xs_list **list, const xs_val **value) /* iterates a list value */ { int goon = 1; @@ -757,7 +757,7 @@ int xs_list_iter(xs_list **list, xs_val **value) } -int xs_list_next(const xs_list *list, xs_val **value, int *ctxt) +int xs_list_next(const xs_list *list, const xs_val **value, int *ctxt) /* iterates a list, with context */ { if (xs_type(list) != XSTYPE_LIST) @@ -765,7 +765,7 @@ int xs_list_next(const xs_list *list, xs_val **value, int *ctxt) int goon = 1; - char *p = (char *)list; + const char *p = list; /* skip the start of the list */ if (*ctxt == 0) @@ -800,7 +800,7 @@ int xs_list_len(const xs_list *list) int c = 0; xs_list *p = (xs_list *)list; - xs_val *v; + const xs_val *v; while (xs_list_iter(&p, &v)) c++; @@ -819,7 +819,7 @@ const xs_val *xs_list_get(const xs_list *list, int num) int c = 0; xs_list *p = (xs_list *)list; - xs_val *v; + const xs_val *v; while (xs_list_iter(&p, &v)) { if (c == num) @@ -881,7 +881,7 @@ xs_list *xs_list_dequeue(xs_list *list, xs_val **data, int last) XS_ASSERT_TYPE(list, XSTYPE_LIST); xs_list *p = list; - xs_val *v = NULL; + const xs_val *v = NULL; if (!last) { /* get the first */ @@ -910,7 +910,7 @@ int xs_list_in(const xs_list *list, const xs_val *val) int n = 0; xs_list *p = (xs_list *)list; - xs_val *v; + const xs_val *v; int sz = xs_size(val); while (xs_list_iter(&p, &v)) { @@ -931,7 +931,7 @@ xs_str *xs_join(const xs_list *list, const char *sep) xs_str *s = NULL; xs_list *p = (xs_list *)list; - xs_val *v; + const xs_val *v; int c = 0; int offset = 0; int ssz = strlen(sep); @@ -1087,7 +1087,7 @@ xs_dict *xs_dict_prepend(xs_dict *dict, const xs_str *key, const xs_val *value) } -int xs_dict_next(const xs_dict *dict, xs_str **key, xs_val **value, int *ctxt) +int xs_dict_next(const xs_dict *dict, const xs_str **key, const xs_val **value, int *ctxt) /* iterates a dict, with context */ { if (xs_type(dict) != XSTYPE_DICT) @@ -1131,8 +1131,8 @@ const xs_val *xs_dict_get_def(const xs_dict *dict, const xs_str *key, const xs_v XS_ASSERT_TYPE(dict, XSTYPE_DICT); XS_ASSERT_TYPE(key, XSTYPE_STRING); - xs_str *k; - xs_val *v; + const xs_str *k; + const xs_val *v; int c = 0; while (xs_dict_next(dict, &k, &v, &c)) { @@ -1150,14 +1150,14 @@ xs_dict *xs_dict_del(xs_dict *dict, const xs_str *key) XS_ASSERT_TYPE(dict, XSTYPE_DICT); XS_ASSERT_TYPE(key, XSTYPE_STRING); - xs_str *k; - xs_val *v; + const xs_str *k; + const xs_val *v; int c = 0; while (xs_dict_next(dict, &k, &v, &c)) { if (strcmp(k, key) == 0) { /* the address of the item is just behind the key */ - char *i = k - 1; + char *i = (char *)k - 1; dict = xs_collapse(dict, i - dict, xs_size(i)); break; diff --git a/xs_curl.h b/xs_curl.h index 2628d91..215db7f 100644 --- a/xs_curl.h +++ b/xs_curl.h @@ -93,8 +93,8 @@ xs_dict *xs_http_request(const char *method, const char *url, xs_dict *response; CURL *curl; struct curl_slist *list = NULL; - xs_str *k; - xs_val *v; + const xs_str *k; + const xs_val *v; long lstatus = 0; struct _payload_data pd; diff --git a/xs_fcgi.h b/xs_fcgi.h index 4727c5c..a1433a2 100644 --- a/xs_fcgi.h +++ b/xs_fcgi.h @@ -293,8 +293,8 @@ void xs_fcgi_response(FILE *f, int status, xs_dict *headers, xs_str *body, int b struct fcgi_record_header hdr = {0}; struct fcgi_end_request ereq = {0}; xs *out = xs_str_new(NULL); - xs_str *k; - xs_str *v; + const xs_str *k; + const xs_str *v; /* no previous id? it's an error */ if (fcgi_id == -1) diff --git a/xs_httpd.h b/xs_httpd.h index 60933c8..4195b81 100644 --- a/xs_httpd.h +++ b/xs_httpd.h @@ -99,8 +99,8 @@ void xs_httpd_response(FILE *f, int status, xs_dict *headers, xs_str *body, int /* sends an httpd response */ { xs *proto; - xs_str *k; - xs_val *v; + const xs_str *k; + const xs_val *v; proto = xs_fmt("HTTP/1.1 %d %s", status, status / 100 == 2 ? "OK" : "ERROR"); fprintf(f, "%s\r\n", proto); diff --git a/xs_json.h b/xs_json.h index 3a7742d..b65e825 100644 --- a/xs_json.h +++ b/xs_json.h @@ -76,7 +76,7 @@ static void _xs_json_dump(const xs_val *data, int level, int indent, FILE *f) { int c = 0; int ct = 0; - xs_val *v; + const xs_val *v; switch (xs_type(data)) { case XSTYPE_NULL: @@ -116,7 +116,7 @@ static void _xs_json_dump(const xs_val *data, int level, int indent, FILE *f) case XSTYPE_DICT: fputc('{', f); - xs_str *k; + const xs_str *k; while (xs_dict_next(data, &k, &v, &ct)) { if (c != 0) diff --git a/xs_regex.h b/xs_regex.h index cb73a01..cdb2cf8 100644 --- a/xs_regex.h +++ b/xs_regex.h @@ -64,7 +64,7 @@ xs_list *xs_regex_select_n(const char *str, const char *rx, int count) { xs_list *list = xs_list_new(); xs *split = NULL; - xs_val *v; + const xs_val *v; int n = 0; int c = 0; @@ -89,7 +89,7 @@ xs_list *xs_regex_replace_in(xs_str *str, const char *rx, const char *rep, int c { xs_str *s = xs_str_new(NULL); xs *split = xs_regex_split_n(str, rx, count); - xs_val *v; + const xs_val *v; int n = 0; int c = 0; int pholder = !!strchr(rep, '&'); diff --git a/xs_set.h b/xs_set.h index b7eb091..12bac94 100644 --- a/xs_set.h +++ b/xs_set.h @@ -85,7 +85,8 @@ int xs_set_add(xs_set *s, const xs_val *data) { /* is it 'full'? */ if (s->used >= s->elems / 2) { - char *p, *v; + char *p; + const xs_val *v; /* expand! */ s->elems *= 2; diff --git a/xs_url.h b/xs_url.h index 69313b6..488a65f 100644 --- a/xs_url.h +++ b/xs_url.h @@ -52,7 +52,7 @@ xs_dict *xs_url_vars(const char *str) xs *args = xs_split(str, "&"); xs_list *l; - xs_val *v; + const xs_val *v; l = args; while (xs_list_iter(&l, &v)) { diff --git a/xs_version.h b/xs_version.h index 9ecf9b8..9fb70ef 100644 --- a/xs_version.h +++ b/xs_version.h @@ -1 +1 @@ -/* 34850dcdec50b669a2c0bbe9f16f6d9c4b16eafd 2024-05-21T14:06:02+02:00 */ +/* 65265483c102909393287bfb173d1a7ae9c3be00 2024-05-23T09:57:20+02:00 */