summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2023-01-12 09:28:02 +0100
committerGravatar default2023-01-12 09:28:02 +0100
commitbb0d8f2a2755af5e11b46d32be84155ba71ea534 (patch)
tree86eb998f66c875dc7d2d40ba3021a3e69ffe9400
parentShow the More... link above the 'About this site'. (diff)
downloadsnac2-bb0d8f2a2755af5e11b46d32be84155ba71ea534.tar.gz
snac2-bb0d8f2a2755af5e11b46d32be84155ba71ea534.tar.xz
snac2-bb0d8f2a2755af5e11b46d32be84155ba71ea534.zip
Backport from xs.
-rw-r--r--data.c2
-rw-r--r--format.c14
-rw-r--r--html.c10
-rw-r--r--http.c10
-rw-r--r--httpd.c4
-rw-r--r--utils.c16
-rw-r--r--webfinger.c4
-rw-r--r--xs.h18
-rw-r--r--xs_curl.h4
-rw-r--r--xs_httpd.h6
-rw-r--r--xs_version.h2
11 files changed, 45 insertions, 45 deletions
diff --git a/data.c b/data.c
index f623111..18efd92 100644
--- a/data.c
+++ b/data.c
@@ -31,7 +31,7 @@ int srv_open(char *basedir, int auto_upgrade)
31 srv_basedir = xs_str_new(basedir); 31 srv_basedir = xs_str_new(basedir);
32 32
33 if (xs_endswith(srv_basedir, "/")) 33 if (xs_endswith(srv_basedir, "/"))
34 srv_basedir = xs_crop(srv_basedir, 0, -1); 34 srv_basedir = xs_crop_i(srv_basedir, 0, -1);
35 35
36 cfg_file = xs_fmt("%s/server.json", basedir); 36 cfg_file = xs_fmt("%s/server.json", basedir);
37 37
diff --git a/format.c b/format.c
index 7ded83c..58b6c7d 100644
--- a/format.c
+++ b/format.c
@@ -53,19 +53,19 @@ static d_char *format_line(const char *line)
53 if ((n & 0x1)) { 53 if ((n & 0x1)) {
54 /* markup */ 54 /* markup */
55 if (xs_startswith(v, "`")) { 55 if (xs_startswith(v, "`")) {
56 xs *s1 = xs_crop(xs_dup(v), 1, -1); 56 xs *s1 = xs_crop_i(xs_dup(v), 1, -1);
57 xs *s2 = xs_fmt("<code>%s</code>", s1); 57 xs *s2 = xs_fmt("<code>%s</code>", s1);
58 s = xs_str_cat(s, s2); 58 s = xs_str_cat(s, s2);
59 } 59 }
60 else 60 else
61 if (xs_startswith(v, "**")) { 61 if (xs_startswith(v, "**")) {
62 xs *s1 = xs_crop(xs_dup(v), 2, -2); 62 xs *s1 = xs_crop_i(xs_dup(v), 2, -2);
63 xs *s2 = xs_fmt("<b>%s</b>", s1); 63 xs *s2 = xs_fmt("<b>%s</b>", s1);
64 s = xs_str_cat(s, s2); 64 s = xs_str_cat(s, s2);
65 } 65 }
66 else 66 else
67 if (xs_startswith(v, "*")) { 67 if (xs_startswith(v, "*")) {
68 xs *s1 = xs_crop(xs_dup(v), 1, -1); 68 xs *s1 = xs_crop_i(xs_dup(v), 1, -1);
69 xs *s2 = xs_fmt("<i>%s</i>", s1); 69 xs *s2 = xs_fmt("<i>%s</i>", s1);
70 s = xs_str_cat(s, s2); 70 s = xs_str_cat(s, s2);
71 } 71 }
@@ -117,11 +117,11 @@ d_char *not_really_markdown(const char *content)
117 if (in_pre) 117 if (in_pre)
118 ss = xs_dup(v); 118 ss = xs_dup(v);
119 else 119 else
120 ss = xs_strip(format_line(v)); 120 ss = xs_strip_i(format_line(v));
121 121
122 if (xs_startswith(ss, ">")) { 122 if (xs_startswith(ss, ">")) {
123 /* delete the > and subsequent spaces */ 123 /* delete the > and subsequent spaces */
124 ss = xs_strip(xs_crop(ss, 1, 0)); 124 ss = xs_strip_i(xs_crop_i(ss, 1, 0));
125 125
126 if (!in_blq) { 126 if (!in_blq) {
127 s = xs_str_cat(s, "<blockquote>"); 127 s = xs_str_cat(s, "<blockquote>");
@@ -184,9 +184,9 @@ d_char *sanitize(const char *content)
184 184
185 while (xs_list_iter(&p, &v)) { 185 while (xs_list_iter(&p, &v)) {
186 if (n & 0x1) { 186 if (n & 0x1) {
187 xs *s1 = xs_strip(xs_crop(xs_dup(v), v[1] == '/' ? 2 : 1, -1)); 187 xs *s1 = xs_strip_i(xs_crop_i(xs_dup(v), v[1] == '/' ? 2 : 1, -1));
188 xs *l1 = xs_split_n(s1, " ", 1); 188 xs *l1 = xs_split_n(s1, " ", 1);
189 xs *tag = xs_tolower(xs_dup(xs_list_get(l1, 0))); 189 xs *tag = xs_tolower_i(xs_dup(xs_list_get(l1, 0)));
190 xs *s2 = NULL; 190 xs *s2 = NULL;
191 int i; 191 int i;
192 192
diff --git a/html.c b/html.c
index 089da03..530c573 100644
--- a/html.c
+++ b/html.c
@@ -21,7 +21,7 @@ int login(snac *snac, char *headers)
21 21
22 if (auth && xs_startswith(auth, "Basic ")) { 22 if (auth && xs_startswith(auth, "Basic ")) {
23 int sz; 23 int sz;
24 xs *s1 = xs_crop(xs_dup(auth), 6, 0); 24 xs *s1 = xs_crop_i(xs_dup(auth), 6, 0);
25 xs *s2 = xs_base64_dec(s1, &sz); 25 xs *s2 = xs_base64_dec(s1, &sz);
26 26
27 xs *l1 = xs_split_n(s2, ":", 1); 27 xs *l1 = xs_split_n(s2, ":", 1);
@@ -108,11 +108,11 @@ d_char *html_actor_icon(snac *snac, d_char *os, char *actor,
108 s = xs_str_cat(s, "<br>\n&nbsp;\n"); 108 s = xs_str_cat(s, "<br>\n&nbsp;\n");
109 } 109 }
110 else { 110 else {
111 xs *date_label = xs_crop(xs_dup(date), 0, 10); 111 xs *date_label = xs_crop_i(xs_dup(date), 0, 10);
112 xs *date_title = xs_dup(date); 112 xs *date_title = xs_dup(date);
113 113
114 if (!xs_is_null(udate)) { 114 if (!xs_is_null(udate)) {
115 xs *sd = xs_crop(xs_dup(udate), 0, 10); 115 xs *sd = xs_crop_i(xs_dup(udate), 0, 10);
116 116
117 date_label = xs_str_cat(date_label, " / "); 117 date_label = xs_str_cat(date_label, " / ");
118 date_label = xs_str_cat(date_label, sd); 118 date_label = xs_str_cat(date_label, sd);
@@ -682,7 +682,7 @@ d_char *html_entry(snac *snac, d_char *os, char *msg, int local, int level, cons
682 c = xs_replace_i(c, "\r", ""); 682 c = xs_replace_i(c, "\r", "");
683 683
684 while (xs_endswith(c, "<br><br>")) 684 while (xs_endswith(c, "<br><br>"))
685 c = xs_crop(c, 0, -4); 685 c = xs_crop_i(c, 0, -4);
686 686
687 c = xs_replace_i(c, "<br><br>", "<p>"); 687 c = xs_replace_i(c, "<br><br>", "<p>");
688 688
@@ -1045,7 +1045,7 @@ int html_get_handler(d_char *req, char *q_path, char **body, int *b_size, char *
1045 1045
1046 /* rss extension? */ 1046 /* rss extension? */
1047 if (xs_endswith(uid, ".rss")) { 1047 if (xs_endswith(uid, ".rss")) {
1048 uid = xs_crop(uid, 0, -4); 1048 uid = xs_crop_i(uid, 0, -4);
1049 p_path = ".rss"; 1049 p_path = ".rss";
1050 } 1050 }
1051 else 1051 else
diff --git a/http.c b/http.c
index eab686e..4b45753 100644
--- a/http.c
+++ b/http.c
@@ -123,19 +123,19 @@ static int _check_signature(snac *snac, char *req, char **err)
123 p = l; 123 p = l;
124 while (xs_list_iter(&p, &v)) { 124 while (xs_list_iter(&p, &v)) {
125 if (xs_startswith(v, "keyId")) 125 if (xs_startswith(v, "keyId"))
126 keyId = xs_crop(xs_dup(v), 7, -1); 126 keyId = xs_crop_i(xs_dup(v), 7, -1);
127 else 127 else
128 if (xs_startswith(v, "headers")) 128 if (xs_startswith(v, "headers"))
129 headers = xs_crop(xs_dup(v), 9, -1); 129 headers = xs_crop_i(xs_dup(v), 9, -1);
130 else 130 else
131 if (xs_startswith(v, "signature")) 131 if (xs_startswith(v, "signature"))
132 signature = xs_crop(xs_dup(v), 11, -1); 132 signature = xs_crop_i(xs_dup(v), 11, -1);
133 else 133 else
134 if (xs_startswith(v, "created")) 134 if (xs_startswith(v, "created"))
135 created = xs_crop(xs_dup(v), 9, -1); 135 created = xs_crop_i(xs_dup(v), 9, -1);
136 else 136 else
137 if (xs_startswith(v, "expires")) 137 if (xs_startswith(v, "expires"))
138 expires = xs_crop(xs_dup(v), 9, -1); 138 expires = xs_crop_i(xs_dup(v), 9, -1);
139 } 139 }
140 } 140 }
141 141
diff --git a/httpd.c b/httpd.c
index f85188c..52b4307 100644
--- a/httpd.c
+++ b/httpd.c
@@ -160,11 +160,11 @@ void httpd_connection(FILE *f)
160 160
161 /* crop the q_path from leading / and the prefix */ 161 /* crop the q_path from leading / and the prefix */
162 if (xs_endswith(q_path, "/")) 162 if (xs_endswith(q_path, "/"))
163 q_path = xs_crop(q_path, 0, -1); 163 q_path = xs_crop_i(q_path, 0, -1);
164 164
165 p = xs_dict_get(srv_config, "prefix"); 165 p = xs_dict_get(srv_config, "prefix");
166 if (xs_startswith(q_path, p)) 166 if (xs_startswith(q_path, p))
167 q_path = xs_crop(q_path, strlen(p), 0); 167 q_path = xs_crop_i(q_path, strlen(p), 0);
168 168
169 if (strcmp(method, "GET") == 0 || strcmp(method, "HEAD") == 0) { 169 if (strcmp(method, "GET") == 0 || strcmp(method, "HEAD") == 0) {
170 /* cascade through */ 170 /* cascade through */
diff --git a/utils.c b/utils.c
index 14b4816..2ae0c63 100644
--- a/utils.c
+++ b/utils.c
@@ -85,7 +85,7 @@ int initdb(const char *basedir)
85 85
86 if (basedir == NULL) { 86 if (basedir == NULL) {
87 printf("Base directory:\n"); 87 printf("Base directory:\n");
88 srv_basedir = xs_strip(xs_readline(stdin)); 88 srv_basedir = xs_strip_i(xs_readline(stdin));
89 } 89 }
90 else 90 else
91 srv_basedir = xs_str_new(basedir); 91 srv_basedir = xs_str_new(basedir);
@@ -94,7 +94,7 @@ int initdb(const char *basedir)
94 return 1; 94 return 1;
95 95
96 if (xs_endswith(srv_basedir, "/")) 96 if (xs_endswith(srv_basedir, "/"))
97 srv_basedir = xs_crop(srv_basedir, 0, -1); 97 srv_basedir = xs_crop_i(srv_basedir, 0, -1);
98 98
99 if (mtime(srv_basedir) != 0.0) { 99 if (mtime(srv_basedir) != 0.0) {
100 printf("ERROR: directory '%s' must not exist\n", srv_basedir); 100 printf("ERROR: directory '%s' must not exist\n", srv_basedir);
@@ -108,14 +108,14 @@ int initdb(const char *basedir)
108 108
109 printf("Network address [%s]:\n", xs_dict_get(srv_config, "address")); 109 printf("Network address [%s]:\n", xs_dict_get(srv_config, "address"));
110 { 110 {
111 xs *i = xs_strip(xs_readline(stdin)); 111 xs *i = xs_strip_i(xs_readline(stdin));
112 if (*i) 112 if (*i)
113 srv_config = xs_dict_set(srv_config, "address", i); 113 srv_config = xs_dict_set(srv_config, "address", i);
114 } 114 }
115 115
116 printf("Network port [%d]:\n", (int)xs_number_get(xs_dict_get(srv_config, "port"))); 116 printf("Network port [%d]:\n", (int)xs_number_get(xs_dict_get(srv_config, "port")));
117 { 117 {
118 xs *i = xs_strip(xs_readline(stdin)); 118 xs *i = xs_strip_i(xs_readline(stdin));
119 if (*i) { 119 if (*i) {
120 xs *n = xs_number_new(atoi(i)); 120 xs *n = xs_number_new(atoi(i));
121 srv_config = xs_dict_set(srv_config, "port", n); 121 srv_config = xs_dict_set(srv_config, "port", n);
@@ -124,7 +124,7 @@ int initdb(const char *basedir)
124 124
125 printf("Host name:\n"); 125 printf("Host name:\n");
126 { 126 {
127 xs *i = xs_strip(xs_readline(stdin)); 127 xs *i = xs_strip_i(xs_readline(stdin));
128 if (*i == '\0') 128 if (*i == '\0')
129 return 1; 129 return 1;
130 130
@@ -133,11 +133,11 @@ int initdb(const char *basedir)
133 133
134 printf("URL prefix:\n"); 134 printf("URL prefix:\n");
135 { 135 {
136 xs *i = xs_strip(xs_readline(stdin)); 136 xs *i = xs_strip_i(xs_readline(stdin));
137 137
138 if (*i) { 138 if (*i) {
139 if (xs_endswith(i, "/")) 139 if (xs_endswith(i, "/"))
140 i = xs_crop(i, 0, -1); 140 i = xs_crop_i(i, 0, -1);
141 141
142 srv_config = xs_dict_set(srv_config, "prefix", i); 142 srv_config = xs_dict_set(srv_config, "prefix", i);
143 } 143 }
@@ -215,7 +215,7 @@ int adduser(const char *uid)
215 215
216 if (uid == NULL) { 216 if (uid == NULL) {
217 printf("User id:\n"); 217 printf("User id:\n");
218 uid = xs_strip(xs_readline(stdin)); 218 uid = xs_strip_i(xs_readline(stdin));
219 } 219 }
220 220
221 if (!validate_uid(uid)) { 221 if (!validate_uid(uid)) {
diff --git a/webfinger.c b/webfinger.c
index 928af22..6a6133d 100644
--- a/webfinger.c
+++ b/webfinger.c
@@ -33,7 +33,7 @@ int webfinger_request(char *qs, char **actor, char **user)
33 xs *s = xs_dup(qs); 33 xs *s = xs_dup(qs);
34 34
35 if (xs_startswith(s, "@")) 35 if (xs_startswith(s, "@"))
36 s = xs_crop(s, 1, 0); 36 s = xs_crop_i(s, 1, 0);
37 37
38 l = xs_split_n(s, "@", 1); 38 l = xs_split_n(s, "@", 1);
39 39
@@ -141,7 +141,7 @@ int webfinger_get_handler(d_char *req, char *q_path,
141 141
142 /* strip a possible leading @ */ 142 /* strip a possible leading @ */
143 if (xs_startswith(an, "@")) 143 if (xs_startswith(an, "@"))
144 an = xs_crop(an, 1, 0); 144 an = xs_crop_i(an, 1, 0);
145 145
146 l = xs_split_n(an, "@", 1); 146 l = xs_split_n(an, "@", 1);
147 147
diff --git a/xs.h b/xs.h
index e3126fd..36445e4 100644
--- a/xs.h
+++ b/xs.h
@@ -60,11 +60,11 @@ d_char *xs_fmt(const char *fmt, ...);
60int xs_str_in(const char *haystack, const char *needle); 60int xs_str_in(const char *haystack, const char *needle);
61int xs_startswith(const char *str, const char *prefix); 61int xs_startswith(const char *str, const char *prefix);
62int xs_endswith(const char *str, const char *postfix); 62int xs_endswith(const char *str, const char *postfix);
63d_char *xs_crop(d_char *str, int start, int end); 63d_char *xs_crop_i(d_char *str, int start, int end);
64d_char *xs_strip_chars(d_char *str, const char *chars); 64d_char *xs_strip_chars_i(d_char *str, const char *chars);
65#define xs_strip(str) xs_strip_chars(str, " \r\n\t\v\f") 65#define xs_strip_i(str) xs_strip_chars_i(str, " \r\n\t\v\f")
66d_char *xs_tolower(d_char *str); 66d_char *xs_tolower_i(d_char *str);
67d_char *xs_str_prepend(d_char *str, const char *prefix); 67d_char *xs_str_prepend_i(d_char *str, const char *prefix);
68d_char *xs_list_new(void); 68d_char *xs_list_new(void);
69d_char *xs_list_append_m(d_char *list, const char *mem, int dsz); 69d_char *xs_list_append_m(d_char *list, const char *mem, int dsz);
70#define xs_list_append(list, data) xs_list_append_m(list, data, xs_size(data)) 70#define xs_list_append(list, data) xs_list_append_m(list, data, xs_size(data))
@@ -439,7 +439,7 @@ int xs_endswith(const char *str, const char *postfix)
439} 439}
440 440
441 441
442d_char *xs_crop(d_char *str, int start, int end) 442d_char *xs_crop_i(d_char *str, int start, int end)
443/* crops the d_char to be only from start to end */ 443/* crops the d_char to be only from start to end */
444{ 444{
445 int sz = strlen(str); 445 int sz = strlen(str);
@@ -457,7 +457,7 @@ d_char *xs_crop(d_char *str, int start, int end)
457} 457}
458 458
459 459
460d_char *xs_strip_chars(d_char *str, const char *chars) 460d_char *xs_strip_chars_i(d_char *str, const char *chars)
461/* strips the string of chars from the start and the end */ 461/* strips the string of chars from the start and the end */
462{ 462{
463 int n; 463 int n;
@@ -478,7 +478,7 @@ d_char *xs_strip_chars(d_char *str, const char *chars)
478} 478}
479 479
480 480
481d_char *xs_tolower(d_char *str) 481d_char *xs_tolower_i(d_char *str)
482/* convert to lowercase */ 482/* convert to lowercase */
483{ 483{
484 int n; 484 int n;
@@ -490,7 +490,7 @@ d_char *xs_tolower(d_char *str)
490} 490}
491 491
492 492
493d_char *xs_str_prepend(d_char *str, const char *prefix) 493d_char *xs_str_prepend_i(d_char *str, const char *prefix)
494/* prepends prefix into string */ 494/* prepends prefix into string */
495{ 495{
496 int sz = strlen(prefix); 496 int sz = strlen(prefix);
diff --git a/xs_curl.h b/xs_curl.h
index 2b07cad..c39c42d 100644
--- a/xs_curl.h
+++ b/xs_curl.h
@@ -21,13 +21,13 @@ static size_t _header_callback(char *buffer, size_t size,
21 /* get the line */ 21 /* get the line */
22 l = xs_str_new(NULL); 22 l = xs_str_new(NULL);
23 l = xs_append_m(l, buffer, size * nitems); 23 l = xs_append_m(l, buffer, size * nitems);
24 l = xs_strip(l); 24 l = xs_strip_i(l);
25 25
26 /* only the HTTP/x 200 line and the last one doesn't have ': ' */ 26 /* only the HTTP/x 200 line and the last one doesn't have ': ' */
27 if (xs_str_in(l, ": ") != -1) { 27 if (xs_str_in(l, ": ") != -1) {
28 xs *knv = xs_split_n(l, ": ", 1); 28 xs *knv = xs_split_n(l, ": ", 1);
29 29
30 xs_tolower(xs_list_get(knv, 0)); 30 xs_tolower_i(xs_list_get(knv, 0));
31 31
32 headers = xs_dict_set(headers, xs_list_get(knv, 0), xs_list_get(knv, 1)); 32 headers = xs_dict_set(headers, xs_list_get(knv, 0), xs_list_get(knv, 1));
33 } 33 }
diff --git a/xs_httpd.h b/xs_httpd.h
index 9edc638..7121214 100644
--- a/xs_httpd.h
+++ b/xs_httpd.h
@@ -185,7 +185,7 @@ d_char *xs_httpd_request(FILE *f, d_char **payload, int *p_size)
185 xs_socket_timeout(fileno(f), 2.0, 0.0); 185 xs_socket_timeout(fileno(f), 2.0, 0.0);
186 186
187 /* read the first line and split it */ 187 /* read the first line and split it */
188 l1 = xs_strip(xs_readline(f)); 188 l1 = xs_strip_i(xs_readline(f));
189 l2 = xs_split(l1, " "); 189 l2 = xs_split(l1, " ");
190 190
191 if (xs_list_len(l2) != 3) { 191 if (xs_list_len(l2) != 3) {
@@ -214,7 +214,7 @@ d_char *xs_httpd_request(FILE *f, d_char **payload, int *p_size)
214 for (;;) { 214 for (;;) {
215 xs *l, *p = NULL; 215 xs *l, *p = NULL;
216 216
217 l = xs_strip(xs_readline(f)); 217 l = xs_strip_i(xs_readline(f));
218 218
219 /* done with the header? */ 219 /* done with the header? */
220 if (strcmp(l, "") == 0) 220 if (strcmp(l, "") == 0)
@@ -224,7 +224,7 @@ d_char *xs_httpd_request(FILE *f, d_char **payload, int *p_size)
224 p = xs_split_n(l, ": ", 1); 224 p = xs_split_n(l, ": ", 1);
225 225
226 if (xs_list_len(p) == 2) 226 if (xs_list_len(p) == 2)
227 req = xs_dict_append(req, xs_tolower(xs_list_get(p, 0)), xs_list_get(p, 1)); 227 req = xs_dict_append(req, xs_tolower_i(xs_list_get(p, 0)), xs_list_get(p, 1));
228 } 228 }
229 229
230 xs_socket_timeout(fileno(f), 5.0, 0.0); 230 xs_socket_timeout(fileno(f), 5.0, 0.0);
diff --git a/xs_version.h b/xs_version.h
index 0e03cfb..a91e805 100644
--- a/xs_version.h
+++ b/xs_version.h
@@ -1 +1 @@
/* 38b055a19829fb788f1bb6917f76cc4830388e35 */ /* 41985e780c622a078118ea7c7143dc304758d958 */