From 29fb43079761796e34209611ec93bd651b871cab Mon Sep 17 00:00:00 2001 From: default Date: Mon, 29 Apr 2024 09:26:37 +0200 Subject: More work in lists. --- httpd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'httpd.c') diff --git a/httpd.c b/httpd.c index e402e61..bda8159 100644 --- a/httpd.c +++ b/httpd.c @@ -360,7 +360,7 @@ void httpd_connection(FILE *f) #ifndef NO_MASTODON_API if (status == 0) status = mastoapi_delete_handler(req, q_path, - &body, &b_size, &ctype); + payload, p_size, &body, &b_size, &ctype); #endif } -- cgit v1.2.3 From ddd2af73bd2b61b13e3b7d3928184d34d4729abd Mon Sep 17 00:00:00 2001 From: default Date: Sun, 5 May 2024 11:11:32 +0200 Subject: Search by tag returns RSS if the appropriate header is defined. --- httpd.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'httpd.c') diff --git a/httpd.c b/httpd.c index bda8159..30367c8 100644 --- a/httpd.c +++ b/httpd.c @@ -169,8 +169,6 @@ int server_get_handler(xs_dict *req, const char *q_path, { int status = 0; - (void)req; - /* is it the server root? */ if (*q_path == '\0') { xs_dict *q_vars = xs_dict_get(req, "q_vars"); @@ -195,7 +193,15 @@ int server_get_handler(xs_dict *req, const char *q_path, more = 1; } - *body = html_timeline(NULL, tl, 0, skip, show, more, t, NULL, 0); + char *accept = xs_dict_get(req, "accept"); + if (!xs_is_null(accept) && strcmp(accept, "application/rss+xml") == 0) { + xs *link = xs_fmt("%s/?t=%s", srv_baseurl, t); + + *body = timeline_to_rss(NULL, tl, link, link, link); + *ctype = "application/rss+xml; charset=utf-8"; + } + else + *body = html_timeline(NULL, tl, 0, skip, show, more, t, NULL, 0); } else if (xs_type(xs_dict_get(srv_config, "show_instance_timeline")) == XSTYPE_TRUE) { -- cgit v1.2.3 From 82ec4ea95cb1040c5b9b983ec649dbde024d20f8 Mon Sep 17 00:00:00 2001 From: default Date: Tue, 7 May 2024 20:32:13 +0200 Subject: Minor "Back to top" "More..." link refactoring. --- httpd.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'httpd.c') diff --git a/httpd.c b/httpd.c index 30367c8..81b0853 100644 --- a/httpd.c +++ b/httpd.c @@ -200,14 +200,18 @@ int server_get_handler(xs_dict *req, const char *q_path, *body = timeline_to_rss(NULL, tl, link, link, link); *ctype = "application/rss+xml; charset=utf-8"; } - else - *body = html_timeline(NULL, tl, 0, skip, show, more, t, NULL, 0); + else { + xs *page = xs_fmt("?t=%s", t); + xs *title = xs_fmt(L("Search results for #%s"), t); + *body = html_timeline(NULL, tl, 0, skip, show, more, title, page, 0); + } } else if (xs_type(xs_dict_get(srv_config, "show_instance_timeline")) == XSTYPE_TRUE) { /** instance timeline **/ xs *tl = timeline_instance_list(0, 30); - *body = html_timeline(NULL, tl, 0, 0, 0, 0, NULL, NULL, 0); + *body = html_timeline(NULL, tl, 0, 0, 0, 0, + L("Recent posts by users in this instance"), NULL, 0); } else *body = greeting_html(); -- cgit v1.2.3 From 34311714ce725da9fae9fea3b29a4988977c79bd Mon Sep 17 00:00:00 2001 From: default Date: Wed, 15 May 2024 05:57:21 +0200 Subject: User search can also be done by tag. --- httpd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'httpd.c') diff --git a/httpd.c b/httpd.c index 81b0853..71cce5e 100644 --- a/httpd.c +++ b/httpd.c @@ -202,7 +202,7 @@ int server_get_handler(xs_dict *req, const char *q_path, } else { xs *page = xs_fmt("?t=%s", t); - xs *title = xs_fmt(L("Search results for #%s"), t); + xs *title = xs_fmt(L("Search results for tag #%s"), t); *body = html_timeline(NULL, tl, 0, skip, show, more, title, page, 0); } } -- cgit v1.2.3 From 4777fc86cb962917a8f34afb3bfa40f26290815d Mon Sep 17 00:00:00 2001 From: default Date: Tue, 21 May 2024 14:12:15 +0200 Subject: Added const everywhere. --- httpd.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'httpd.c') diff --git a/httpd.c b/httpd.c index 71cce5e..d63fa0f 100644 --- a/httpd.c +++ b/httpd.c @@ -125,7 +125,7 @@ static xs_str *greeting_html(void) /* does it have a %userlist% mark? */ if (xs_str_in(s, "%userlist%") != -1) { - char *host = xs_dict_get(srv_config, "host"); + const char *host = xs_dict_get(srv_config, "host"); xs *list = user_list(); xs_list *p = list; xs_str *uid; @@ -171,14 +171,14 @@ int server_get_handler(xs_dict *req, const char *q_path, /* is it the server root? */ if (*q_path == '\0') { - xs_dict *q_vars = xs_dict_get(req, "q_vars"); - char *t = NULL; + const xs_dict *q_vars = xs_dict_get(req, "q_vars"); + const char *t = NULL; if (xs_type(q_vars) == XSTYPE_DICT && (t = xs_dict_get(q_vars, "t"))) { /** search by tag **/ int skip = 0; int show = xs_number_get(xs_dict_get(srv_config, "max_timeline_entries")); - char *v; + const char *v; if ((v = xs_dict_get(q_vars, "skip")) != NULL) skip = atoi(v); @@ -193,7 +193,7 @@ int server_get_handler(xs_dict *req, const char *q_path, more = 1; } - char *accept = xs_dict_get(req, "accept"); + const char *accept = xs_dict_get(req, "accept"); if (!xs_is_null(accept) && strcmp(accept, "application/rss+xml") == 0) { xs *link = xs_fmt("%s/?t=%s", srv_baseurl, t); @@ -268,7 +268,7 @@ void httpd_connection(FILE *f) /* the connection processor */ { xs *req; - char *method; + const char *method; int status = 0; xs_str *body = NULL; int b_size = 0; @@ -278,7 +278,7 @@ void httpd_connection(FILE *f) xs *payload = NULL; xs *etag = NULL; int p_size = 0; - char *p; + const char *p; int fcgi_id; if (p_state->use_fcgi) @@ -411,7 +411,7 @@ void httpd_connection(FILE *f) headers = xs_dict_append(headers, "etag", etag); /* if there are any additional headers, add them */ - 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) { char *k, *v; int c = 0; -- cgit v1.2.3 From cdfaf6dc57a03503cec46cad5fbfd6fec45b0f52 Mon Sep 17 00:00:00 2001 From: default Date: Tue, 21 May 2024 18:57:13 +0200 Subject: New compilation variable WITHOUT_SHM, to disable shared memory functions. --- httpd.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'httpd.c') diff --git a/httpd.c b/httpd.c index d63fa0f..993aa1c 100644 --- a/httpd.c +++ b/httpd.c @@ -653,6 +653,29 @@ void term_handler(int s) } +#ifdef WITHOUT_SHM + +/* dummy versions */ + +int shm_open(const char *name, int flags, mode_t mode) +{ + (void)name; + (void)flags; + (void)mode; + + errno = ENOTSUP; + return -1; +} + +int shm_unlink(const char *name) +{ + (void)name; + return -1; +} + + +#endif + srv_state *srv_state_op(xs_str **fname, int op) /* opens or deletes the shared memory object */ { -- cgit v1.2.3 From ed973241f44f8dd1b688bbab37018f33160027bf Mon Sep 17 00:00:00 2001 From: default Date: Tue, 21 May 2024 19:08:33 +0200 Subject: Another approach to disabling SHM. --- httpd.c | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'httpd.c') diff --git a/httpd.c b/httpd.c index 993aa1c..8a20c89 100644 --- a/httpd.c +++ b/httpd.c @@ -653,29 +653,6 @@ void term_handler(int s) } -#ifdef WITHOUT_SHM - -/* dummy versions */ - -int shm_open(const char *name, int flags, mode_t mode) -{ - (void)name; - (void)flags; - (void)mode; - - errno = ENOTSUP; - return -1; -} - -int shm_unlink(const char *name) -{ - (void)name; - return -1; -} - - -#endif - srv_state *srv_state_op(xs_str **fname, int op) /* opens or deletes the shared memory object */ { @@ -687,6 +664,13 @@ srv_state *srv_state_op(xs_str **fname, int op) switch (op) { case 0: /* open for writing */ + +#ifdef WITHOUT_SHM + + errno = ENOTSUP; + +#else + if ((fd = shm_open(*fname, O_CREAT | O_RDWR, 0666)) != -1) { ftruncate(fd, sizeof(*ss)); @@ -697,6 +681,8 @@ srv_state *srv_state_op(xs_str **fname, int op) close(fd); } +#endif + if (ss == NULL) { /* shared memory error: just create a plain structure */ srv_log(xs_fmt("warning: shm object error (%s)", strerror(errno))); @@ -710,6 +696,13 @@ srv_state *srv_state_op(xs_str **fname, int op) break; case 1: /* open for reading */ + +#ifdef WITHOUT_SHM + + errno = ENOTSUP; + +#else + if ((fd = shm_open(*fname, O_RDONLY, 0666)) != -1) { if ((ss = mmap(0, sizeof(*ss), PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) ss = NULL; @@ -717,6 +710,8 @@ srv_state *srv_state_op(xs_str **fname, int op) close(fd); } +#endif + if (ss == NULL) { /* shared memory error */ srv_log(xs_fmt("error: shm object error (%s) server not running?", strerror(errno))); @@ -734,9 +729,14 @@ srv_state *srv_state_op(xs_str **fname, int op) break; case 2: /* unlink */ + +#ifndef WITHOUT_SHM + if (*fname) shm_unlink(*fname); +#endif + break; } -- cgit v1.2.3 From 8cf7559a7e21c5757455b948814d61e6e96f08f1 Mon Sep 17 00:00:00 2001 From: default Date: Thu, 23 May 2024 10:01:37 +0200 Subject: Added more const. --- httpd.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'httpd.c') 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; -- cgit v1.2.3