diff options
| author | 2022-09-27 18:20:25 +0200 | |
|---|---|---|
| committer | 2022-09-27 18:20:25 +0200 | |
| commit | b6c4906c6af96ca3847cc716f3c3174bbc0085b4 (patch) | |
| tree | e81399914f175c3e1872232afcbf778782a8eed8 | |
| parent | New variable USER_AGENT. (diff) | |
| download | snac2-b6c4906c6af96ca3847cc716f3c3174bbc0085b4.tar.gz snac2-b6c4906c6af96ca3847cc716f3c3174bbc0085b4.tar.xz snac2-b6c4906c6af96ca3847cc716f3c3174bbc0085b4.zip | |
New function process_tags() (untested).
| -rw-r--r-- | activitypub.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/activitypub.c b/activitypub.c index edb32c7..47e9efe 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include "xs_curl.h" | 7 | #include "xs_curl.h" |
| 8 | #include "xs_mime.h" | 8 | #include "xs_mime.h" |
| 9 | #include "xs_openssl.h" | 9 | #include "xs_openssl.h" |
| 10 | #include "xs_regex.h" | ||
| 10 | 11 | ||
| 11 | #include "snac.h" | 12 | #include "snac.h" |
| 12 | 13 | ||
| @@ -202,6 +203,57 @@ int is_msg_public(snac *snac, char *msg) | |||
| 202 | } | 203 | } |
| 203 | 204 | ||
| 204 | 205 | ||
| 206 | void process_tags(const char *content, d_char **n_content, d_char **tag) | ||
| 207 | /* parses mentions and tags from content */ | ||
| 208 | { | ||
| 209 | d_char *nc = xs_str_new(NULL); | ||
| 210 | d_char *tl = xs_list_new(); | ||
| 211 | xs *split; | ||
| 212 | char *p, *v; | ||
| 213 | int n = 0; | ||
| 214 | |||
| 215 | p = split = xs_regex_split(content, "(@[A-Za-z0-9_]+@[A-Za-z0-9-\\.]+|#[^ ]+)"); | ||
| 216 | while (xs_list_iter(&p, &v)) { | ||
| 217 | if ((n & 0x1)) { | ||
| 218 | if (*v == '@') { | ||
| 219 | /* query the webfinger about this fellow */ | ||
| 220 | xs *actor = NULL; | ||
| 221 | xs *uid = NULL; | ||
| 222 | int status; | ||
| 223 | |||
| 224 | status = webfinger_request(v, &actor, &uid); | ||
| 225 | |||
| 226 | if (valid_status(status)) { | ||
| 227 | xs *d = xs_dict_new(); | ||
| 228 | |||
| 229 | d = xs_dict_append(d, "type", "Mention"); | ||
| 230 | d = xs_dict_append(d, "href", actor); | ||
| 231 | d = xs_dict_append(d, "name", uid); | ||
| 232 | |||
| 233 | tl = xs_list_append(tl, d); | ||
| 234 | } | ||
| 235 | else | ||
| 236 | /* store as is */ | ||
| 237 | nc = xs_str_cat(nc, v); | ||
| 238 | } | ||
| 239 | else | ||
| 240 | if (*v == '#') { | ||
| 241 | /* hashtag */ | ||
| 242 | /* store as is by now */ | ||
| 243 | nc = xs_str_cat(nc, v); | ||
| 244 | } | ||
| 245 | } | ||
| 246 | else | ||
| 247 | nc = xs_str_cat(nc, v); | ||
| 248 | |||
| 249 | n++; | ||
| 250 | } | ||
| 251 | |||
| 252 | *n_content = nc; | ||
| 253 | *tag = tl; | ||
| 254 | } | ||
| 255 | |||
| 256 | |||
| 205 | /** messages **/ | 257 | /** messages **/ |
| 206 | 258 | ||
| 207 | d_char *msg_base(snac *snac, char *type, char *id, char *actor, char *date, char *object) | 259 | d_char *msg_base(snac *snac, char *type, char *id, char *actor, char *date, char *object) |