Added more const.

This commit is contained in:
default 2024-05-23 10:01:37 +02:00
parent 63e0ca5aba
commit 8cf7559a7e
20 changed files with 171 additions and 150 deletions

View File

@ -163,7 +163,7 @@ const char *get_atto(const xs_dict *msg)
if (xs_type(actor) == XSTYPE_LIST) { if (xs_type(actor) == XSTYPE_LIST) {
const xs_list *p = actor; const xs_list *p = actor;
int c = 0; int c = 0;
xs_dict *v; const xs_dict *v;
actor = NULL; actor = NULL;
while (actor == NULL && xs_list_next(p, &v, &c)) { 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 */ /* try first the attachments list */
if (!xs_is_null(p = xs_dict_get(msg, "attachment"))) { if (!xs_is_null(p = xs_dict_get(msg, "attachment"))) {
xs *attach = NULL; xs *attach = NULL;
xs_val *v; const xs_val *v;
/* ensure it's a list */ /* ensure it's a list */
if (xs_type(p) == XSTYPE_DICT) { if (xs_type(p) == XSTYPE_DICT) {
@ -257,7 +257,7 @@ xs_list *get_attachments(const xs_dict *msg)
const char *href = NULL; const char *href = NULL;
const char *type = NULL; const char *type = NULL;
int c = 0; int c = 0;
xs_val *v; const xs_val *v;
while (href == NULL && xs_list_next(p, &v, &c)) { while (href == NULL && xs_list_next(p, &v, &c)) {
if (xs_type(v) == XSTYPE_DICT) { if (xs_type(v) == XSTYPE_DICT) {
@ -271,7 +271,7 @@ xs_list *get_attachments(const xs_dict *msg)
strcmp(mtype, "application/x-mpegURL") == 0 && strcmp(mtype, "application/x-mpegURL") == 0 &&
xs_type(tag) == XSTYPE_LIST) { xs_type(tag) == XSTYPE_LIST) {
/* now iterate the tag list, looking for a video URL */ /* now iterate the tag list, looking for a video URL */
xs_dict *d; const xs_dict *d;
int c = 0; int c = 0;
while (href == NULL && xs_list_next(tag, &d, &c)) { 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 }; const xs_list *lists[] = { to, cc, NULL };
for (n = 0; lists[n]; n++) { for (n = 0; lists[n]; n++) {
xs_list *l = (xs_list *)lists[n]; xs_list *l = (xs_list *)lists[n];
char *v; const char *v;
xs *tl = NULL; xs *tl = NULL;
/* if it's a string, create a list with only one element */ /* 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) { if (expand_public && strcmp(v, public_address) == 0) {
/* iterate the followers and add them */ /* iterate the followers and add them */
xs *fwers = follower_list(snac); xs *fwers = follower_list(snac);
char *actor; const char *actor;
char *p = fwers; char *p = fwers;
while (xs_list_iter(&p, &actor)) 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"); const xs_dict *msg = xs_dict_get(c_msg, "object");
xs *rcpts = recipient_list(snac, msg, 0); xs *rcpts = recipient_list(snac, msg, 0);
xs_list *p = rcpts; xs_list *p = rcpts;
xs_str *v; const xs_str *v;
xs *actor_followers = NULL; 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_list *tl = *tag;
xs *split; xs *split;
xs_list *p; xs_list *p;
xs_val *v; const xs_val *v;
int n = 0; int n = 0;
/* create a default server for incomplete mentions */ /* 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"); const xs_dict *metadata = xs_dict_get(snac->config, "metadata");
if (xs_type(metadata) == XSTYPE_DICT) { if (xs_type(metadata) == XSTYPE_DICT) {
xs *attach = xs_list_new(); xs *attach = xs_list_new();
xs_str *k; const xs_str *k;
xs_str *v; const xs_str *v;
int c = 0; int c = 0;
while (xs_dict_next(metadata, &k, &v, &c)) { 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 *atls = xs_list_new();
xs_dict *msg = msg_base(snac, "Note", id, NULL, "@now", NULL); xs_dict *msg = msg_base(snac, "Note", id, NULL, "@now", NULL);
xs_list *p; xs_list *p;
xs_val *v; const xs_val *v;
if (rcpts == NULL) if (rcpts == NULL)
to = xs_list_new(); 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 *o = xs_list_new();
xs_list *p = (xs_list *)opts; xs_list *p = (xs_list *)opts;
xs_str *v; const xs_str *v;
xs *replies = xs_json_loads("{\"type\":\"Collection\",\"totalItems\":0}"); xs *replies = xs_json_loads("{\"type\":\"Collection\",\"totalItems\":0}");
xs_set_init(&seen); xs_set_init(&seen);
@ -1576,7 +1576,7 @@ int update_question(snac *user, const char *id)
xs *lopts = xs_list_new(); xs *lopts = xs_list_new();
const xs_list *opts; const xs_list *opts;
xs_list *p; xs_list *p;
xs_val *v; const xs_val *v;
/* get the object */ /* get the object */
if (!valid_status(object_get(id, &msg))) 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 *rcpts = recipient_list(snac, msg, 1);
xs_set inboxes; xs_set inboxes;
xs_list *p; xs_list *p;
xs_str *actor; const xs_str *actor;
xs_set_init(&inboxes); 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 (is_msg_public(msg)) {
if (xs_type(xs_dict_get(srv_config, "disable_inbox_collection")) != XSTYPE_TRUE) { if (xs_type(xs_dict_get(srv_config, "disable_inbox_collection")) != XSTYPE_TRUE) {
xs *shibx = inbox_list(); xs *shibx = inbox_list();
xs_str *inbox; const xs_str *inbox;
p = shibx; p = shibx;
while (xs_list_iter(&p, &inbox)) { while (xs_list_iter(&p, &inbox)) {
@ -2304,7 +2304,7 @@ int process_user_queue(snac *snac)
xs *list = user_queue(snac); xs *list = user_queue(snac);
xs_list *p = list; xs_list *p = list;
xs_str *fn; const xs_str *fn;
while (xs_list_iter(&p, &fn)) { while (xs_list_iter(&p, &fn)) {
xs *q_item = dequeue(fn); xs *q_item = dequeue(fn);
@ -2511,7 +2511,7 @@ void process_queue_item(xs_dict *q_item)
xs *users = user_list(); xs *users = user_list();
xs_list *p = users; xs_list *p = users;
char *v; const char *v;
int cnt = 0; int cnt = 0;
while (xs_list_iter(&p, &v)) { while (xs_list_iter(&p, &v)) {
@ -2554,7 +2554,7 @@ int process_queue(void)
xs *list = queue(); xs *list = queue();
xs_list *p = list; xs_list *p = list;
xs_str *fn; const xs_str *fn;
while (xs_list_iter(&p, &fn)) { while (xs_list_iter(&p, &fn)) {
xs *q_item = dequeue(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 *elems = timeline_simple_list(&snac, "public", 0, 20);
xs *list = xs_list_new(); xs *list = xs_list_new();
msg = msg_collection(&snac, id); msg = msg_collection(&snac, id);
char *p, *v; char *p;
const char *v;
p = elems; p = elems;
while (xs_list_iter(&p, &v)) { while (xs_list_iter(&p, &v)) {

58
data.c
View File

@ -193,7 +193,7 @@ int user_open(snac *user, const char *uid)
xs *lcuid = xs_tolower_i(xs_dup(uid)); xs *lcuid = xs_tolower_i(xs_dup(uid));
xs *ulist = user_list(); xs *ulist = user_list();
xs_list *p = ulist; xs_list *p = ulist;
xs_str *v; const xs_str *v;
while (xs_list_iter(&p, &v)) { while (xs_list_iter(&p, &v)) {
xs *v2 = xs_tolower_i(xs_dup(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 *ulist = user_list();
xs_list *p = ulist; xs_list *p = ulist;
xs_str *v; const xs_str *v;
while (xs_list_iter(&p, &v)) { while (xs_list_iter(&p, &v)) {
user_open(snac, v); user_open(snac, v);
@ -772,7 +772,8 @@ int object_del_by_md5(const char *md5)
xs *spec = xs_dup(fn); xs *spec = xs_dup(fn);
spec = xs_replace_i(spec, ".json", "*.idx"); spec = xs_replace_i(spec, ".json", "*.idx");
xs *files = xs_glob(spec, 0, 0); xs *files = xs_glob(spec, 0, 0);
char *p, *v; char *p;
const char *v;
p = files; p = files;
while (xs_list_iter(&p, &v)) { 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 = object_user_cache_list(snac, "followers", XS_ALL, 0);
xs_list *fwers = xs_list_new(); 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 */ /* resolve the list of md5 to be a list of actors */
p = list; 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 */ /* returns the top level md5 entries from this index */
{ {
xs_set seen; xs_set seen;
xs_str *v; const xs_str *v;
xs_set_init(&seen); xs_set_init(&seen);
@ -1367,7 +1369,7 @@ xs_list *following_list(snac *snac)
xs *spec = xs_fmt("%s/following/" "*.json", snac->basedir); xs *spec = xs_fmt("%s/following/" "*.json", snac->basedir);
xs *glist = xs_glob(spec, 0, 0); xs *glist = xs_glob(spec, 0, 0);
xs_list *p; xs_list *p;
xs_str *v; const xs_str *v;
xs_list *list = xs_list_new(); xs_list *list = xs_list_new();
/* iterate the list of files */ /* iterate the list of files */
@ -1537,7 +1539,8 @@ void hide(snac *snac, const char *id)
/* hide all the children */ /* hide all the children */
xs *chld = object_children(id); xs *chld = object_children(id);
char *p, *v; char *p;
const char *v;
p = chld; p = chld;
while (xs_list_iter(&p, &v)) { while (xs_list_iter(&p, &v)) {
@ -1694,7 +1697,7 @@ void tag_index(const char *id, const xs_dict *obj)
mkdirx(g_tag_dir); mkdirx(g_tag_dir);
xs_dict *v; const xs_dict *v;
int ct = 0; int ct = 0;
while (xs_list_next(tags, &v, &ct)) { while (xs_list_next(tags, &v, &ct)) {
const char *type = xs_dict_get(v, "type"); 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 *spec = xs_fmt("%s/list/" "*.id", user->basedir);
xs *ls = xs_glob(spec, 0, 0); xs *ls = xs_glob(spec, 0, 0);
int c = 0; int c = 0;
char *v; const char *v;
l = xs_list_new(); 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); xs *lol = list_maint(user, NULL, 0);
int c = 0; int c = 0;
xs_list *v; const xs_list *v;
int add = 1; int add = 1;
/* check if this list name already exists */ /* 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 *spec = xs_fmt("%s/list/" "*.lst", user->basedir);
xs *ls = xs_glob(spec, 0, 0); xs *ls = xs_glob(spec, 0, 0);
int c = 0; int c = 0;
char *v; const char *v;
while (xs_list_next(ls, &v, &c)) { while (xs_list_next(ls, &v, &c)) {
/* is the actor in this list? */ /* is the actor in this list? */
@ -2183,7 +2186,7 @@ xs_list *inbox_list(void)
xs *spec = xs_fmt("%s/inbox/" "*", srv_basedir); xs *spec = xs_fmt("%s/inbox/" "*", srv_basedir);
xs *files = xs_glob(spec, 0, 0); xs *files = xs_glob(spec, 0, 0);
xs_list *p = files; xs_list *p = files;
xs_val *v; const xs_val *v;
while (xs_list_iter(&p, &v)) { while (xs_list_iter(&p, &v)) {
FILE *f; FILE *f;
@ -2329,8 +2332,8 @@ xs_list *content_search(snac *user, const char *regex,
/* iterate all timelines simultaneously */ /* iterate all timelines simultaneously */
xs_list *tls[3] = {0}; xs_list *tls[3] = {0};
char *md5s[3] = {0}; const char *md5s[3] = {0};
int c[3] = {0}; int c[3] = {0};
tls[0] = timeline_simple_list(user, "public", 0, XS_ALL); /* public */ tls[0] = timeline_simple_list(user, "public", 0, XS_ALL); /* public */
tls[1] = timeline_instance_list(0, XS_ALL); /* instance */ 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) if (newest == -1)
break; break;
char *md5 = md5s[newest]; const char *md5 = md5s[newest];
/* advance the chosen timeline */ /* advance the chosen timeline */
if (!xs_list_next(tls[newest], &md5s[newest], &c[newest])) 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 *spec = xs_fmt("%s/notify/" "*.json", snac->basedir);
xs *lst = xs_glob(spec, 1, 0); xs *lst = xs_glob(spec, 1, 0);
xs_list *p = lst; xs_list *p = lst;
char *v; const char *v;
while (xs_list_iter(&p, &v)) { while (xs_list_iter(&p, &v)) {
char *p = strrchr(v, '.'); char *p = strrchr(v, '.');
@ -2562,7 +2565,7 @@ int notify_new_num(snac *snac)
int cnt = 0; int cnt = 0;
xs_list *p = lst; xs_list *p = lst;
xs_str *v; const xs_str *v;
while (xs_list_iter(&p, &v)) { while (xs_list_iter(&p, &v)) {
xs *id = xs_strip_i(xs_dup(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 *spec = xs_fmt("%s/notify/" "*", snac->basedir);
xs *lst = xs_glob(spec, 0, 0); xs *lst = xs_glob(spec, 0, 0);
xs_list *p = lst; xs_list *p = lst;
xs_str *v; const xs_str *v;
while (xs_list_iter(&p, &v)) while (xs_list_iter(&p, &v))
unlink(v); unlink(v);
@ -2842,7 +2845,7 @@ int was_question_voted(snac *user, const char *id)
xs *children = object_children(id); xs *children = object_children(id);
int voted = 0; int voted = 0;
xs_list *p; xs_list *p;
xs_str *md5; const xs_str *md5;
p = children; p = children;
while (xs_list_iter(&p, &md5)) { while (xs_list_iter(&p, &md5)) {
@ -2869,7 +2872,7 @@ xs_list *user_queue(snac *snac)
xs_list *list = xs_list_new(); xs_list *list = xs_list_new();
time_t t = time(NULL); time_t t = time(NULL);
xs_list *p; xs_list *p;
xs_val *v; const xs_val *v;
xs *fns = xs_glob(spec, 0, 0); xs *fns = xs_glob(spec, 0, 0);
@ -2898,7 +2901,7 @@ xs_list *queue(void)
xs_list *list = xs_list_new(); xs_list *list = xs_list_new();
time_t t = time(NULL); time_t t = time(NULL);
xs_list *p; xs_list *p;
xs_val *v; const xs_val *v;
xs *fns = xs_glob(spec, 0, 0); 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 *spec = xs_fmt("%s/" "*", dir);
xs *list = xs_glob(spec, 0, 0); xs *list = xs_glob(spec, 0, 0);
xs_list *p; xs_list *p;
xs_str *v; const xs_str *v;
p = list; p = list;
while (xs_list_iter(&p, &v)) while (xs_list_iter(&p, &v))
@ -3000,7 +3003,7 @@ void purge_server(void)
xs *spec = xs_fmt("%s/object/??", srv_basedir); xs *spec = xs_fmt("%s/object/??", srv_basedir);
xs *dirs = xs_glob(spec, 0, 0); xs *dirs = xs_glob(spec, 0, 0);
xs_list *p; xs_list *p;
xs_str *v; const xs_str *v;
int cnt = 0; int cnt = 0;
int icnt = 0; int icnt = 0;
@ -3009,7 +3012,7 @@ void purge_server(void)
p = dirs; p = dirs;
while (xs_list_iter(&p, &v)) { while (xs_list_iter(&p, &v)) {
xs_list *p2; xs_list *p2;
xs_str *v2; const xs_str *v2;
{ {
xs *spec2 = xs_fmt("%s/" "*.json", v); xs *spec2 = xs_fmt("%s/" "*.json", v);
@ -3088,7 +3091,7 @@ void purge_server(void)
xs *spec2 = xs_fmt("%s/" "*.idx", v); xs *spec2 = xs_fmt("%s/" "*.idx", v);
xs *files = xs_glob(spec2, 0, 0); xs *files = xs_glob(spec2, 0, 0);
xs_list *p2; xs_list *p2;
xs_str *v2; const xs_str *v2;
p2 = files; p2 = files;
while (xs_list_iter(&p2, &v2)) { 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 *spec = xs_fmt("%s/list/" "*.idx", snac->basedir);
xs *lol = xs_glob(spec, 0, 0); xs *lol = xs_glob(spec, 0, 0);
int c = 0; int c = 0;
char *v; const char *v;
while (xs_list_next(lol, &v, &c)) { while (xs_list_next(lol, &v, &c)) {
int gc = index_gc(v); int gc = index_gc(v);
@ -3170,7 +3173,8 @@ void purge_all(void)
{ {
snac snac; snac snac;
xs *list = user_list(); xs *list = user_list();
char *p, *uid; char *p;
const char *uid;
p = list; p = list;
while (xs_list_iter(&p, &uid)) { while (xs_list_iter(&p, &uid)) {

View File

@ -82,7 +82,8 @@ static xs_str *format_line(const char *line, xs_list **attach)
/* formats a line */ /* formats a line */
{ {
xs_str *s = xs_str_new(NULL); xs_str *s = xs_str_new(NULL);
char *p, *v; char *p;
const char *v;
/* split by markup */ /* split by markup */
xs *sm = xs_regex_split(line, 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_pre = 0;
int in_blq = 0; int in_blq = 0;
xs *list; xs *list;
char *p, *v; char *p;
const char *v;
/* work by lines */ /* work by lines */
list = xs_split(content, "\n"); 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 */ /* traditional emoticons */
xs *d = emojis(); xs *d = emojis();
int c = 0; int c = 0;
char *k, *v; const char *k, *v;
while (xs_dict_next(d, &k, &v, &c)) { while (xs_dict_next(d, &k, &v, &c)) {
const char *t = NULL; const char *t = NULL;
@ -280,7 +282,8 @@ xs_str *sanitize(const char *content)
xs_str *s = xs_str_new(NULL); xs_str *s = xs_str_new(NULL);
xs *sl; xs *sl;
int n = 0; int n = 0;
char *p, *v; char *p;
const char *v;
sl = xs_regex_split(content, "</?[^>]+>"); sl = xs_regex_split(content, "</?[^>]+>");

36
html.c
View File

@ -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); xs *style = xs_fmt("height: %dem; width: %dem; vertical-align: middle;", ems, ems);
char *v; const char *v;
int c = 0; int c = 0;
while (xs_list_next(tag_list, &v, &c)) { while (xs_list_next(tag_list, &v, &c)) {
@ -461,7 +461,7 @@ static xs_html *html_base_head(void)
xs *f; xs *f;
f = xs_fmt("%s/favicon.ico", srv_baseurl); f = xs_fmt("%s/favicon.ico", srv_baseurl);
const xs_list *p = xs_dict_get(srv_config, "cssurls"); const xs_list *p = xs_dict_get(srv_config, "cssurls");
char *v; const char *v;
int c = 0; int c = 0;
while (xs_list_next(p, &v, &c)) { 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"); const xs_dict *metadata = xs_dict_get(user->config, "metadata");
if (xs_type(metadata) == XSTYPE_DICT) { if (xs_type(metadata) == XSTYPE_DICT) {
xs_str *k; const xs_str *k;
xs_str *v; const xs_str *v;
xs_dict *val_links = user->links; xs_dict *val_links = user->links;
if (xs_is_null(val_links)) if (xs_is_null(val_links))
@ -974,8 +974,8 @@ xs_html *html_top_controls(snac *snac)
xs *metadata = xs_str_new(NULL); xs *metadata = xs_str_new(NULL);
const xs_dict *md = xs_dict_get(snac->config, "metadata"); const xs_dict *md = xs_dict_get(snac->config, "metadata");
xs_str *k; const xs_str *k;
xs_str *v; const xs_str *v;
int c = 0; int c = 0;
while (xs_dict_next(md, &k, &v, &c)) { 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); xs_str *s = xs_str_new(NULL);
const char *list = xs_dict_get(msg, "tag"); const char *list = xs_dict_get(msg, "tag");
char *v; const char *v;
int c = 0; int c = 0;
while (xs_list_next(list, &v, &c)) { 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, 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 *id = xs_dict_get(msg, "id");
const char *type = xs_dict_get(msg, "type"); 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 *oo = xs_dict_get(msg, "oneOf");
const xs_list *ao = xs_dict_get(msg, "anyOf"); const xs_list *ao = xs_dict_get(msg, "anyOf");
const xs_list *p; const xs_list *p;
xs_dict *v; const xs_dict *v;
int closed = 0; int closed = 0;
const char *f_closed = NULL; const char *f_closed = NULL;
@ -1827,7 +1827,7 @@ xs_html *html_entry(snac *user, xs_dict *msg, int read_only,
content_attachments); content_attachments);
int c = 0; int c = 0;
xs_dict *a; const xs_dict *a;
while (xs_list_next(attach, &a, &c)) { while (xs_list_next(attach, &a, &c)) {
const char *type = xs_dict_get(a, "type"); const char *type = xs_dict_get(a, "type");
const char *href = xs_dict_get(a, "href"); 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; xs_list *p = children;
char *cmd5; const char *cmd5;
int cnt = 0; int cnt = 0;
int o_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 */ /* returns the HTML for the timeline */
{ {
xs_list *p = (xs_list *)list; xs_list *p = (xs_list *)list;
char *v; const char *v;
double t = ftime(); double t = ftime();
xs *desc = NULL; 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 = history_list(user);
xs_list *p = list; xs_list *p = list;
char *v; const char *v;
while (xs_list_iter(&p, &v)) { while (xs_list_iter(&p, &v)) {
xs *fn = xs_replace(v, ".html", ""); 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_html_text("..."))));
xs_list *p = list; xs_list *p = list;
char *actor_id; const char *actor_id;
while (xs_list_iter(&p, &actor_id)) { while (xs_list_iter(&p, &actor_id)) {
xs *md5 = xs_md5_hex(actor_id, strlen(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_html *noti_seen = NULL;
xs_list *p = n_list; xs_list *p = n_list;
xs_str *v; const xs_str *v;
while (xs_list_iter(&p, &v)) { while (xs_list_iter(&p, &v)) {
xs *noti = notify_get(user, 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_dict *md = xs_dict_new();
xs *l = xs_split(v, "\n"); xs *l = xs_split(v, "\n");
xs_list *p = l; xs_list *p = l;
xs_str *kp; const xs_str *kp;
while (xs_list_iter(&p, &kp)) { while (xs_list_iter(&p, &kp)) {
xs *kpl = xs_split_n(kp, "=", 1); 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_list *p = ls;
xs_str *v; const xs_str *v;
while (xs_list_iter(&p, &v)) { while (xs_list_iter(&p, &v)) {
xs *msg = msg_note(&snac, "", actor, irt, NULL, 1); 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); xs_html_add(rss, channel);
int c = 0; int c = 0;
char *v; const char *v;
while (xs_list_next(timeline, &v, &c)) { while (xs_list_next(timeline, &v, &c)) {
xs *msg = NULL; xs *msg = NULL;

6
http.c
View File

@ -26,7 +26,7 @@ xs_dict *http_signed_request_raw(const char *keyid, const char *seckey,
xs *hdrs = NULL; xs *hdrs = NULL;
const char *host; const char *host;
const char *target; const char *target;
char *k, *v; const char *k, *v;
xs_dict *response; xs_dict *response;
date = xs_str_utctime(0, "%a, %d %b %Y %H:%M:%S GMT"); 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 */ /* extract the values */
xs *l = xs_split(sig_hdr, ","); xs *l = xs_split(sig_hdr, ",");
int c = 0; int c = 0;
xs_val *v; const xs_val *v;
while (xs_list_next(l, &v, &c)) { while (xs_list_next(l, &v, &c)) {
xs *kv = xs_split_n(v, "=", 1); 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 *l = xs_split(headers, " ");
xs_list *p; xs_list *p;
xs_val *v; const xs_val *v;
p = l; p = l;
while (xs_list_iter(&p, &v)) { while (xs_list_iter(&p, &v)) {

View File

@ -75,7 +75,7 @@ xs_str *nodeinfo_2_0(void)
int n_posts = 0; int n_posts = 0;
xs *users = user_list(); xs *users = user_list();
xs_list *p = users; xs_list *p = users;
char *v; const char *v;
double now = (double)time(NULL); double now = (double)time(NULL);
while (xs_list_iter(&p, &v)) { 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"); const char *host = xs_dict_get(srv_config, "host");
xs *list = user_list(); xs *list = user_list();
xs_list *p = list; xs_list *p = list;
xs_str *uid; const xs_str *uid;
xs_html *ul = xs_html_tag("ul", xs_html *ul = xs_html_tag("ul",
xs_html_attr("class", "snac-user-list")); xs_html_attr("class", "snac-user-list"));
@ -413,7 +413,7 @@ void httpd_connection(FILE *f)
/* if there are any additional headers, add them */ /* if there are any additional headers, add them */
const xs_dict *more_headers = xs_dict_get(srv_config, "http_headers"); const xs_dict *more_headers = xs_dict_get(srv_config, "http_headers");
if (xs_type(more_headers) == XSTYPE_DICT) { if (xs_type(more_headers) == XSTYPE_DICT) {
char *k, *v; const char *k, *v;
int c = 0; int c = 0;
while (xs_dict_next(more_headers, &k, &v, &c)) while (xs_dict_next(more_headers, &k, &v, &c))
headers = xs_dict_set(headers, k, v); headers = xs_dict_set(headers, k, v);
@ -590,7 +590,8 @@ static void *background_thread(void *arg)
{ {
xs *list = user_list(); xs *list = user_list();
char *p, *uid; char *p;
const char *uid;
/* process queues for all users */ /* process queues for all users */
p = list; p = list;

2
main.c
View File

@ -382,7 +382,7 @@ int main(int argc, char *argv[])
xs *r = content_search(&snac, url, 1, 0, XS_ALL, 10, &to); xs *r = content_search(&snac, url, 1, 0, XS_ALL, 10, &to);
int c = 0; int c = 0;
char *v; const char *v;
/* print results as standalone links */ /* print results as standalone links */
while (xs_list_next(r, &v, &c)) { while (xs_list_next(r, &v, &c)) {

View File

@ -599,7 +599,7 @@ xs_dict *mastoapi_account(const xs_dict *actor)
const xs_list *p; const xs_list *p;
if (!xs_is_null(p = xs_dict_get(actor, "tag"))) { if (!xs_is_null(p = xs_dict_get(actor, "tag"))) {
xs *eml = xs_list_new(); xs *eml = xs_list_new();
xs_dict *v; const xs_dict *v;
int c = 0; int c = 0;
while (xs_list_next(p, &v, &c)) { while (xs_list_next(p, &v, &c)) {
@ -637,7 +637,7 @@ xs_dict *mastoapi_account(const xs_dict *actor)
xs *fields = xs_list_new(); xs *fields = xs_list_new();
p = xs_dict_get(actor, "attachment"); p = xs_dict_get(actor, "attachment");
xs_dict *v; const xs_dict *v;
/* dict of validated links */ /* dict of validated links */
xs_dict *val_links = NULL; 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_dict *poll = xs_dict_new();
xs *mid = mastoapi_id(msg); xs *mid = mastoapi_id(msg);
const xs_list *opts = NULL; const xs_list *opts = NULL;
xs_val *v; const xs_val *v;
int num_votes = 0; int num_votes = 0;
xs *options = xs_list_new(); xs *options = xs_list_new();
@ -849,7 +849,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
{ {
xs_list *p = attach; xs_list *p = attach;
xs_dict *v; const xs_dict *v;
xs *matt = xs_list_new(); 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_list = xs_list_new();
tag = tag_list; tag = tag_list;
xs_dict *v; const xs_dict *v;
int c = 0; int c = 0;
while (xs_list_next(tag, &v, &c)) { 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"); const xs_dict *metadata = xs_dict_get(snac1.config, "metadata");
if (xs_type(metadata) == XSTYPE_DICT) { if (xs_type(metadata) == XSTYPE_DICT) {
xs *fields = xs_list_new(); xs *fields = xs_list_new();
xs_str *k; const xs_str *k;
xs_str *v; const xs_str *v;
xs_dict *val_links = snac1.links; xs_dict *val_links = snac1.links;
if (xs_is_null(val_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 *wers = follower_list(&snac1);
xs *ulst = user_list(); xs *ulst = user_list();
xs_list *p; xs_list *p;
xs_str *v; const xs_str *v;
xs_set seen; xs_set seen;
xs_set_init(&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 */ /* the public list of posts of a user */
xs *timeline = timeline_simple_list(&snac2, "public", 0, 256); xs *timeline = timeline_simple_list(&snac2, "public", 0, 256);
xs_list *p = timeline; xs_list *p = timeline;
xs_str *v; const xs_str *v;
out = xs_list_new(); 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 *out = xs_list_new();
xs_list *p = timeline; xs_list *p = timeline;
xs_str *v; const xs_str *v;
while (xs_list_iter(&p, &v) && cnt < limit) { while (xs_list_iter(&p, &v) && cnt < limit) {
xs *msg = NULL; 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 *timeline = timeline_instance_list(0, limit);
xs *out = xs_list_new(); xs *out = xs_list_new();
xs_list *p = timeline; xs_list *p = timeline;
xs_str *md5; const xs_str *md5;
snac *user = NULL; snac *user = NULL;
if (logged_in) 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 *timeline = tag_search(tag, 0, limit);
xs *out = xs_list_new(); xs *out = xs_list_new();
xs_list *p = timeline; xs_list *p = timeline;
xs_str *md5; const xs_str *md5;
while (xs_list_iter(&p, &md5) && cnt < limit) { while (xs_list_iter(&p, &md5) && cnt < limit) {
xs *msg = NULL; 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 *timeline = list_timeline(&snac1, list, 0, 2048);
xs *out = xs_list_new(); xs *out = xs_list_new();
int c = 0; int c = 0;
char *md5; const char *md5;
while (xs_list_next(timeline, &md5, &c)) { while (xs_list_next(timeline, &md5, &c)) {
xs *msg = NULL; 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 *l = notify_list(&snac1, 0, 64);
xs *out = xs_list_new(); xs *out = xs_list_new();
xs_list *p = l; xs_list *p = l;
xs_dict *v; const xs_dict *v;
const xs_list *excl = xs_dict_get(args, "exclude_types[]"); const xs_list *excl = xs_dict_get(args, "exclude_types[]");
while (xs_list_iter(&p, &v)) { 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 *lol = list_maint(&snac1, NULL, 0);
xs *l = xs_list_new(); xs *l = xs_list_new();
int c = 0; int c = 0;
xs_list *li; const xs_list *li;
while (xs_list_next(lol, &li, &c)) { while (xs_list_next(lol, &li, &c)) {
xs *d = xs_dict_new(); 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 *actors = list_content(&snac1, p, NULL, 0);
xs *out = xs_list_new(); xs *out = xs_list_new();
int c = 0; int c = 0;
char *v; const char *v;
while (xs_list_next(actors, &v, &c)) { while (xs_list_next(actors, &v, &c)) {
xs *actor = NULL; 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 *out = xs_list_new();
xs *lol = list_maint(&snac1, NULL, 0); xs *lol = list_maint(&snac1, NULL, 0);
int c = 0; int c = 0;
xs_list *v; const xs_list *v;
while (xs_list_next(lol, &v, &c)) { while (xs_list_next(lol, &v, &c)) {
const char *id = xs_list_get(v, 0); 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 *anc = xs_list_new();
xs *des = xs_list_new(); xs *des = xs_list_new();
xs_list *p; xs_list *p;
xs_str *v; const xs_str *v;
char pid[64]; char pid[64];
/* build the [grand]parent list, moving up */ /* 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")); l = object_likes(xs_dict_get(msg, "id"));
xs_list *p = l; xs_list *p = l;
xs_str *v; const xs_str *v;
while (xs_list_iter(&p, &v)) { while (xs_list_iter(&p, &v)) {
xs *actor2 = NULL; xs *actor2 = NULL;
@ -2267,7 +2267,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
int cnt = 40; int cnt = 40;
xs *tl = content_search(&snac1, q, 1, 0, cnt, 0, &to); xs *tl = content_search(&snac1, q, 1, 0, cnt, 0, &to);
int c = 0; int c = 0;
char *v; const char *v;
while (xs_list_next(tl, &v, &c) && --cnt) { while (xs_list_next(tl, &v, &c) && --cnt) {
xs *post = NULL; xs *post = NULL;
@ -2433,7 +2433,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
} }
xs_list *p = mi; xs_list *p = mi;
xs_str *v; const xs_str *v;
while (xs_list_iter(&p, &v)) { while (xs_list_iter(&p, &v)) {
xs *l = xs_list_new(); 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"); choices = xs_dict_get(args, "choices");
if (xs_type(choices) == XSTYPE_LIST) { if (xs_type(choices) == XSTYPE_LIST) {
xs_str *v; const xs_str *v;
int c = 0; int c = 0;
while (xs_list_next(choices, &v, &c)) { 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) { if (strcmp(op, "accounts") == 0) {
const xs_list *accts = xs_dict_get(args, "account_ids[]"); const xs_list *accts = xs_dict_get(args, "account_ids[]");
int c = 0; int c = 0;
char *v; const char *v;
while (xs_list_next(accts, &v, &c)) { while (xs_list_next(accts, &v, &c)) {
list_content(&snac, id, v, 1); 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); p = xs_list_get(l, -2);
const xs_list *accts = xs_dict_get(args, "account_ids[]"); const xs_list *accts = xs_dict_get(args, "account_ids[]");
int c = 0; int c = 0;
char *v; const char *v;
while (xs_list_next(accts, &v, &c)) { while (xs_list_next(accts, &v, &c)) {
list_content(&snac, p, v, 2); list_content(&snac, p, v, 2);
@ -3083,7 +3083,7 @@ void mastoapi_purge(void)
xs *spec = xs_fmt("%s/app/" "*.json", srv_basedir); xs *spec = xs_fmt("%s/app/" "*.json", srv_basedir);
xs *files = xs_glob(spec, 1, 0); xs *files = xs_glob(spec, 1, 0);
xs_list *p = files; xs_list *p = files;
xs_str *v; const xs_str *v;
time_t mt = time(NULL) - 3600; time_t mt = time(NULL) - 3600;

View File

@ -43,7 +43,8 @@ int snac_upgrade(xs_str **error)
else else
if (f < 2.2) { if (f < 2.2) {
xs *users = user_list(); xs *users = user_list();
char *p, *v; char *p;
const char *v;
p = users; p = users;
while (xs_list_iter(&p, &v)) { while (xs_list_iter(&p, &v)) {
@ -52,7 +53,8 @@ int snac_upgrade(xs_str **error)
if (user_open(&snac, v)) { if (user_open(&snac, v)) {
xs *spec = xs_fmt("%s/actors/" "*.json", snac.basedir); xs *spec = xs_fmt("%s/actors/" "*.json", snac.basedir);
xs *list = xs_glob(spec, 0, 0); xs *list = xs_glob(spec, 0, 0);
char *g, *fn; char *g;
const char *fn;
g = list; g = list;
while (xs_list_iter(&g, &fn)) { while (xs_list_iter(&g, &fn)) {
@ -77,14 +79,16 @@ int snac_upgrade(xs_str **error)
else else
if (f < 2.3) { if (f < 2.3) {
xs *users = user_list(); xs *users = user_list();
char *p, *v; char *p;
const char *v;
p = users; p = users;
while (xs_list_iter(&p, &v)) { while (xs_list_iter(&p, &v)) {
snac snac; snac snac;
if (user_open(&snac, v)) { if (user_open(&snac, v)) {
char *p, *v; char *p;
const char *v;
xs *dir = xs_fmt("%s/hidden", snac.basedir); xs *dir = xs_fmt("%s/hidden", snac.basedir);
/* create the hidden directory */ /* create the hidden directory */
@ -109,7 +113,8 @@ int snac_upgrade(xs_str **error)
else else
if (f < 2.4) { if (f < 2.4) {
xs *users = user_list(); xs *users = user_list();
char *p, *v; char *p;
const char *v;
p = users; p = users;
while (xs_list_iter(&p, &v)) { while (xs_list_iter(&p, &v)) {
@ -132,7 +137,8 @@ int snac_upgrade(xs_str **error)
if (f < 2.5) { if (f < 2.5) {
/* upgrade followers */ /* upgrade followers */
xs *users = user_list(); xs *users = user_list();
char *p, *v; char *p;
const char *v;
p = users; p = users;
while (xs_list_iter(&p, &v)) { while (xs_list_iter(&p, &v)) {
@ -141,7 +147,8 @@ int snac_upgrade(xs_str **error)
if (user_open(&snac, v)) { if (user_open(&snac, v)) {
xs *spec = xs_fmt("%s/followers/" "*.json", snac.basedir); xs *spec = xs_fmt("%s/followers/" "*.json", snac.basedir);
xs *dir = xs_glob(spec, 0, 0); xs *dir = xs_glob(spec, 0, 0);
char *p, *v; char *p;
const char *v;
p = dir; p = dir;
while (xs_list_iter(&p, &v)) { while (xs_list_iter(&p, &v)) {
@ -175,7 +182,8 @@ int snac_upgrade(xs_str **error)
if (f < 2.6) { if (f < 2.6) {
/* upgrade local/ to public/ */ /* upgrade local/ to public/ */
xs *users = user_list(); xs *users = user_list();
char *p, *v; char *p;
const char *v;
p = users; p = users;
while (xs_list_iter(&p, &v)) { while (xs_list_iter(&p, &v)) {
@ -184,7 +192,8 @@ int snac_upgrade(xs_str **error)
if (user_open(&snac, v)) { if (user_open(&snac, v)) {
xs *spec = xs_fmt("%s/local/" "*.json", snac.basedir); xs *spec = xs_fmt("%s/local/" "*.json", snac.basedir);
xs *dir = xs_glob(spec, 0, 0); xs *dir = xs_glob(spec, 0, 0);
char *p, *v; char *p;
const char *v;
p = dir; p = dir;
while (xs_list_iter(&p, &v)) { 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 it's from us, add to public */
if (xs_startswith(id, snac.actor)) { if (xs_startswith(id, snac.actor)) {
const xs_list *p; const xs_list *p;
char *v; const char *v;
int c; int c;
object_user_cache_add(&snac, id, "public"); object_user_cache_add(&snac, id, "public");
@ -241,7 +250,8 @@ int snac_upgrade(xs_str **error)
if (f < 2.7) { if (f < 2.7) {
/* upgrade timeline/ to private/ */ /* upgrade timeline/ to private/ */
xs *users = user_list(); xs *users = user_list();
char *p, *v; char *p;
const char *v;
p = users; p = users;
while (xs_list_iter(&p, &v)) { while (xs_list_iter(&p, &v)) {
@ -250,7 +260,8 @@ int snac_upgrade(xs_str **error)
if (user_open(&snac, v)) { if (user_open(&snac, v)) {
xs *spec = xs_fmt("%s/timeline/" "*.json", snac.basedir); xs *spec = xs_fmt("%s/timeline/" "*.json", snac.basedir);
xs *dir = xs_glob(spec, 0, 0); xs *dir = xs_glob(spec, 0, 0);
char *p, *v; char *p;
const char *v;
p = dir; p = dir;
while (xs_list_iter(&p, &v)) { while (xs_list_iter(&p, &v)) {
@ -271,7 +282,7 @@ int snac_upgrade(xs_str **error)
{ {
const xs_list *p; const xs_list *p;
char *v; const char *v;
int c = 0; int c = 0;
object_user_cache_add(&snac, id, "private"); object_user_cache_add(&snac, id, "private");

10
utils.c
View File

@ -358,7 +358,7 @@ void rm_rf(const char *dir)
xs *d = xs_str_cat(xs_dup(dir), "/" "*"); xs *d = xs_str_cat(xs_dup(dir), "/" "*");
xs *l = xs_glob(d, 0, 0); xs *l = xs_glob(d, 0, 0);
xs_list *p = l; xs_list *p = l;
xs_str *v; const xs_str *v;
if (dbglevel >= 1) if (dbglevel >= 1)
printf("Deleting directory %s\n", dir); printf("Deleting directory %s\n", dir);
@ -393,7 +393,7 @@ int deluser(snac *user)
int ret = 0; int ret = 0;
xs *fwers = following_list(user); xs *fwers = following_list(user);
xs_list *p = fwers; xs_list *p = fwers;
xs_str *v; const xs_str *v;
while (xs_list_iter(&p, &v)) { while (xs_list_iter(&p, &v)) {
xs *object = NULL; xs *object = NULL;
@ -419,7 +419,7 @@ void verify_links(snac *user)
/* verifies a user's links */ /* verifies a user's links */
{ {
const xs_dict *p = xs_dict_get(user->config, "metadata"); const xs_dict *p = xs_dict_get(user->config, "metadata");
char *k, *v; const char *k, *v;
int changed = 0; int changed = 0;
xs *headers = xs_dict_new(); xs *headers = xs_dict_new();
@ -449,7 +449,7 @@ void verify_links(snac *user)
xs *ls = xs_regex_select(payload, "< *(a|link) +[^>]+>"); xs *ls = xs_regex_select(payload, "< *(a|link) +[^>]+>");
xs_list *lp = ls; xs_list *lp = ls;
char *ll; const char *ll;
int vfied = 0; int vfied = 0;
while (!vfied && xs_list_iter(&lp, &ll)) { while (!vfied && xs_list_iter(&lp, &ll)) {
@ -463,7 +463,7 @@ void verify_links(snac *user)
xs *href = NULL; xs *href = NULL;
int is_rel_me = 0; int is_rel_me = 0;
xs_list *pr = r; xs_list *pr = r;
char *ar; const char *ar;
while (xs_list_iter(&pr, &ar)) { while (xs_list_iter(&pr, &ar)) {
xs *nq = xs_dup(ar); xs *nq = xs_dup(ar);

View File

@ -96,7 +96,7 @@ int webfinger_request_signed(snac *snac, const char *qs, char **actor, char **us
if (actor != NULL) { if (actor != NULL) {
const xs_list *list = xs_dict_get(obj, "links"); const xs_list *list = xs_dict_get(obj, "links");
int c = 0; int c = 0;
char *v; const char *v;
while (xs_list_next(list, &v, &c)) { while (xs_list_next(list, &v, &c)) {
if (xs_type(v) == XSTYPE_DICT) { if (xs_type(v) == XSTYPE_DICT) {

34
xs.h
View File

@ -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_m(xs_list *list, const char *mem, int dsz);
xs_list *_xs_list_append(xs_list *list, const xs_val *vals[]); 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 }) #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_iter(xs_list **list, const 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);
int xs_list_len(const xs_list *list); int xs_list_len(const xs_list *list);
const xs_val *xs_list_get(const xs_list *list, int num); const xs_val *xs_list_get(const xs_list *list, int num);
xs_list *xs_list_del(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_new(void);
xs_dict *xs_dict_append(xs_dict *dict, const xs_str *key, const xs_val *value); 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); 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); 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) #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); 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 */ /* iterates a list value */
{ {
int goon = 1; 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 */ /* iterates a list, with context */
{ {
if (xs_type(list) != XSTYPE_LIST) 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; int goon = 1;
char *p = (char *)list; const char *p = list;
/* skip the start of the list */ /* skip the start of the list */
if (*ctxt == 0) if (*ctxt == 0)
@ -800,7 +800,7 @@ int xs_list_len(const xs_list *list)
int c = 0; int c = 0;
xs_list *p = (xs_list *)list; xs_list *p = (xs_list *)list;
xs_val *v; const xs_val *v;
while (xs_list_iter(&p, &v)) while (xs_list_iter(&p, &v))
c++; c++;
@ -819,7 +819,7 @@ const xs_val *xs_list_get(const xs_list *list, int num)
int c = 0; int c = 0;
xs_list *p = (xs_list *)list; xs_list *p = (xs_list *)list;
xs_val *v; const xs_val *v;
while (xs_list_iter(&p, &v)) { while (xs_list_iter(&p, &v)) {
if (c == num) 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_ASSERT_TYPE(list, XSTYPE_LIST);
xs_list *p = list; xs_list *p = list;
xs_val *v = NULL; const xs_val *v = NULL;
if (!last) { if (!last) {
/* get the first */ /* get the first */
@ -910,7 +910,7 @@ int xs_list_in(const xs_list *list, const xs_val *val)
int n = 0; int n = 0;
xs_list *p = (xs_list *)list; xs_list *p = (xs_list *)list;
xs_val *v; const xs_val *v;
int sz = xs_size(val); int sz = xs_size(val);
while (xs_list_iter(&p, &v)) { 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_str *s = NULL;
xs_list *p = (xs_list *)list; xs_list *p = (xs_list *)list;
xs_val *v; const xs_val *v;
int c = 0; int c = 0;
int offset = 0; int offset = 0;
int ssz = strlen(sep); 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 */ /* iterates a dict, with context */
{ {
if (xs_type(dict) != XSTYPE_DICT) 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(dict, XSTYPE_DICT);
XS_ASSERT_TYPE(key, XSTYPE_STRING); XS_ASSERT_TYPE(key, XSTYPE_STRING);
xs_str *k; const xs_str *k;
xs_val *v; const xs_val *v;
int c = 0; int c = 0;
while (xs_dict_next(dict, &k, &v, &c)) { 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(dict, XSTYPE_DICT);
XS_ASSERT_TYPE(key, XSTYPE_STRING); XS_ASSERT_TYPE(key, XSTYPE_STRING);
xs_str *k; const xs_str *k;
xs_val *v; const xs_val *v;
int c = 0; int c = 0;
while (xs_dict_next(dict, &k, &v, &c)) { while (xs_dict_next(dict, &k, &v, &c)) {
if (strcmp(k, key) == 0) { if (strcmp(k, key) == 0) {
/* the address of the item is just behind the key */ /* 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)); dict = xs_collapse(dict, i - dict, xs_size(i));
break; break;

View File

@ -93,8 +93,8 @@ xs_dict *xs_http_request(const char *method, const char *url,
xs_dict *response; xs_dict *response;
CURL *curl; CURL *curl;
struct curl_slist *list = NULL; struct curl_slist *list = NULL;
xs_str *k; const xs_str *k;
xs_val *v; const xs_val *v;
long lstatus = 0; long lstatus = 0;
struct _payload_data pd; struct _payload_data pd;

View File

@ -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_record_header hdr = {0};
struct fcgi_end_request ereq = {0}; struct fcgi_end_request ereq = {0};
xs *out = xs_str_new(NULL); xs *out = xs_str_new(NULL);
xs_str *k; const xs_str *k;
xs_str *v; const xs_str *v;
/* no previous id? it's an error */ /* no previous id? it's an error */
if (fcgi_id == -1) if (fcgi_id == -1)

View File

@ -99,8 +99,8 @@ void xs_httpd_response(FILE *f, int status, xs_dict *headers, xs_str *body, int
/* sends an httpd response */ /* sends an httpd response */
{ {
xs *proto; xs *proto;
xs_str *k; const xs_str *k;
xs_val *v; const xs_val *v;
proto = xs_fmt("HTTP/1.1 %d %s", status, status / 100 == 2 ? "OK" : "ERROR"); proto = xs_fmt("HTTP/1.1 %d %s", status, status / 100 == 2 ? "OK" : "ERROR");
fprintf(f, "%s\r\n", proto); fprintf(f, "%s\r\n", proto);

View File

@ -76,7 +76,7 @@ static void _xs_json_dump(const xs_val *data, int level, int indent, FILE *f)
{ {
int c = 0; int c = 0;
int ct = 0; int ct = 0;
xs_val *v; const xs_val *v;
switch (xs_type(data)) { switch (xs_type(data)) {
case XSTYPE_NULL: 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: case XSTYPE_DICT:
fputc('{', f); fputc('{', f);
xs_str *k; const xs_str *k;
while (xs_dict_next(data, &k, &v, &ct)) { while (xs_dict_next(data, &k, &v, &ct)) {
if (c != 0) if (c != 0)

View File

@ -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_list *list = xs_list_new();
xs *split = NULL; xs *split = NULL;
xs_val *v; const xs_val *v;
int n = 0; int n = 0;
int c = 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_str *s = xs_str_new(NULL);
xs *split = xs_regex_split_n(str, rx, count); xs *split = xs_regex_split_n(str, rx, count);
xs_val *v; const xs_val *v;
int n = 0; int n = 0;
int c = 0; int c = 0;
int pholder = !!strchr(rep, '&'); int pholder = !!strchr(rep, '&');

View File

@ -85,7 +85,8 @@ int xs_set_add(xs_set *s, const xs_val *data)
{ {
/* is it 'full'? */ /* is it 'full'? */
if (s->used >= s->elems / 2) { if (s->used >= s->elems / 2) {
char *p, *v; char *p;
const xs_val *v;
/* expand! */ /* expand! */
s->elems *= 2; s->elems *= 2;

View File

@ -52,7 +52,7 @@ xs_dict *xs_url_vars(const char *str)
xs *args = xs_split(str, "&"); xs *args = xs_split(str, "&");
xs_list *l; xs_list *l;
xs_val *v; const xs_val *v;
l = args; l = args;
while (xs_list_iter(&l, &v)) { while (xs_list_iter(&l, &v)) {

View File

@ -1 +1 @@
/* 34850dcdec50b669a2c0bbe9f16f6d9c4b16eafd 2024-05-21T14:06:02+02:00 */ /* 65265483c102909393287bfb173d1a7ae9c3be00 2024-05-23T09:57:20+02:00 */