commit be5f08e
default
·
2023-05-02 04:49:00 +0000 UTC
parent 29815a3
Use xs_replace_n() where it suits.
3 files changed,
+11,
-11
M
http.c
+1,
-1
1@@ -33,7 +33,7 @@ xs_dict *http_signed_request_raw(const char *keyid, const char *seckey,
2 date = xs_str_utctime(0, "%a, %d %b %Y %H:%M:%S GMT");
3
4 {
5- xs *s = xs_replace(url, "https:/" "/", "");
6+ xs *s = xs_replace_n(url, "https:/" "/", "", 1);
7 l1 = xs_split_n(s, "/", 1);
8 }
9
+7,
-7
1@@ -185,7 +185,7 @@ int oauth_get_handler(const xs_dict *req, const char *q_path,
2
3 int status = 404;
4 xs_dict *msg = xs_dict_get(req, "q_vars");
5- xs *cmd = xs_replace(q_path, "/oauth", "");
6+ xs *cmd = xs_replace_n(q_path, "/oauth", "", 1);
7
8 srv_debug(1, xs_fmt("oauth_get_handler %s", q_path));
9
10@@ -245,7 +245,7 @@ int oauth_post_handler(const xs_dict *req, const char *q_path,
11 else
12 args = xs_dup(xs_dict_get(req, "p_vars"));
13
14- xs *cmd = xs_replace(q_path, "/oauth", "");
15+ xs *cmd = xs_replace_n(q_path, "/oauth", "", 1);
16
17 srv_debug(1, xs_fmt("oauth_post_handler %s", q_path));
18
19@@ -328,7 +328,7 @@ int oauth_post_handler(const xs_dict *req, const char *q_path,
20 const char *auhdr = xs_dict_get(req, "authorization");
21
22 if (!xs_is_null(auhdr) && xs_startswith(auhdr, "Basic ")) {
23- xs *s1 = xs_replace(auhdr, "Basic ", "");
24+ xs *s1 = xs_replace_n(auhdr, "Basic ", "", 1);
25 int size;
26 xs *s2 = xs_base64_dec(s1, &size);
27
28@@ -787,7 +787,7 @@ int process_auth_token(snac *snac, const xs_dict *req)
29
30 /* if there is an authorization field, try to validate it */
31 if (!xs_is_null(v = xs_dict_get(req, "authorization")) && xs_startswith(v, "Bearer ")) {
32- xs *tokid = xs_replace(v, "Bearer ", "");
33+ xs *tokid = xs_replace_n(v, "Bearer ", "", 1);
34 xs *token = token_get(tokid);
35
36 if (token != NULL) {
37@@ -826,7 +826,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
38
39 int status = 404;
40 xs_dict *args = xs_dict_get(req, "q_vars");
41- xs *cmd = xs_replace(q_path, "/api", "");
42+ xs *cmd = xs_replace_n(q_path, "/api", "", 1);
43
44 snac snac1 = {0};
45 int logged_in = process_auth_token(&snac1, req);
46@@ -1500,7 +1500,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
47 printf("%s\n", j);
48 }*/
49
50- xs *cmd = xs_replace(q_path, "/api", "");
51+ xs *cmd = xs_replace_n(q_path, "/api", "", 1);
52
53 snac snac = {0};
54 int logged_in = process_auth_token(&snac, req);
55@@ -1916,7 +1916,7 @@ int mastoapi_put_handler(const xs_dict *req, const char *q_path,
56 if (args == NULL)
57 return 400;
58
59- xs *cmd = xs_replace(q_path, "/api", "");
60+ xs *cmd = xs_replace_n(q_path, "/api", "", 1);
61
62 snac snac = {0};
63 int logged_in = process_auth_token(&snac, req);
+3,
-3
1@@ -21,7 +21,7 @@ int webfinger_request(const char *qs, char **actor, char **user)
2
3 if (xs_startswith(qs, "https:/" "/")) {
4 /* actor query: pick the host */
5- xs *s = xs_replace(qs, "https:/" "/", "");
6+ xs *s = xs_replace_n(qs, "https:/" "/", "", 1);
7
8 l = xs_split_n(s, "/", 1);
9
10@@ -74,7 +74,7 @@ int webfinger_request(const char *qs, char **actor, char **user)
11 char *subject = xs_dict_get(obj, "subject");
12
13 if (subject)
14- *user = xs_replace(subject, "acct:", "");
15+ *user = xs_replace_n(subject, "acct:", "", 1);
16 }
17
18 if (actor != NULL) {
19@@ -136,7 +136,7 @@ int webfinger_get_handler(d_char *req, char *q_path,
20 else
21 if (xs_startswith(resource, "acct:")) {
22 /* it's an account name */
23- xs *an = xs_replace(resource, "acct:", "");
24+ xs *an = xs_replace_n(resource, "acct:", "", 1);
25 xs *l = NULL;
26
27 /* strip a possible leading @ */