commit d26b31e
default
·
2023-08-16 16:18:46 +0000 UTC
parent a291d3d
mastoapi: minor fix in verify_credentials.
3 files changed,
+51,
-2
+1,
-1
1@@ -980,7 +980,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
2 if (logged_in) {
3 xs *acct = xs_dict_new();
4
5- acct = xs_dict_append(acct, "id", xs_dict_get(snac1.config, "uid"));
6+ acct = xs_dict_append(acct, "id", snac1.md5);
7 acct = xs_dict_append(acct, "username", xs_dict_get(snac1.config, "uid"));
8 acct = xs_dict_append(acct, "acct", xs_dict_get(snac1.config, "uid"));
9 acct = xs_dict_append(acct, "display_name", xs_dict_get(snac1.config, "name"));
+49,
-0
1@@ -8,6 +8,8 @@ xs_list *xs_regex_split_n(const char *str, const char *rx, int count);
2 #define xs_regex_split(str, rx) xs_regex_split_n(str, rx, XS_ALL)
3 xs_list *xs_regex_match_n(const char *str, const char *rx, int count);
4 #define xs_regex_match(str, rx) xs_regex_match_n(str, rx, XS_ALL)
5+xs_list *xs_regex_replace_n(const char *str, const char *rx, const char *rep, int count);
6+#define xs_regex_replace(str, rx, rep) xs_regex_replace_n(str, rx, rep, XS_ALL)
7
8 #ifdef XS_IMPLEMENTATION
9
10@@ -75,6 +77,53 @@ xs_list *xs_regex_match_n(const char *str, const char *rx, int count)
11 return list;
12 }
13
14+
15+xs_list *xs_regex_replace_n(const char *str, const char *rx, const char *rep, int count)
16+/* replaces all matches with the rep string. If it contains unescaped &,
17+ they are replaced with the match */
18+{
19+ xs_str *s = xs_str_new(NULL);
20+ xs *split = xs_regex_split_n(str, rx, count);
21+ xs_list *p;
22+ xs_val *v;
23+ int n = 0;
24+ int pholder = !!strchr(rep, '&');
25+
26+ p = split;
27+ while (xs_list_iter(&p, &v)) {
28+ if (n & 0x1) {
29+ if (pholder) {
30+ /* rep has a placeholder; process char by char */
31+ const char *p = rep;
32+
33+ while (*p) {
34+ if (*p == '&')
35+ s = xs_str_cat(s, v);
36+ else {
37+ if (*p == '\\')
38+ p++;
39+
40+ if (!*p)
41+ break;
42+
43+ s = xs_append_m(s, p, 1);
44+ }
45+
46+ p++;
47+ }
48+ }
49+ else
50+ s = xs_str_cat(s, rep);
51+ }
52+ else
53+ s = xs_str_cat(s, v);
54+
55+ n++;
56+ }
57+
58+ return s;
59+}
60+
61 #endif /* XS_IMPLEMENTATION */
62
63 #endif /* XS_REGEX_H */
+1,
-1
1@@ -1 +1 @@
2-/* 17cae699036ab791f9bd4e9c1b875b1f808121f0 */
3+/* b7e9713d90382d8da0b58023f4c78416e6ca1bc5 */