diff options
| -rw-r--r-- | data.c | 3 | ||||
| -rw-r--r-- | format.c | 43 | ||||
| -rw-r--r-- | snac.h | 1 |
3 files changed, 43 insertions, 4 deletions
| @@ -132,6 +132,9 @@ int srv_open(char *basedir, int auto_upgrade) | |||
| 132 | } | 132 | } |
| 133 | #endif /* __OpenBSD__ */ | 133 | #endif /* __OpenBSD__ */ |
| 134 | 134 | ||
| 135 | /* read (and drop) emojis.json, possibly creating it */ | ||
| 136 | xs_free(emojis()); | ||
| 137 | |||
| 135 | return ret; | 138 | return ret; |
| 136 | } | 139 | } |
| 137 | 140 | ||
| @@ -5,6 +5,7 @@ | |||
| 5 | #include "xs_regex.h" | 5 | #include "xs_regex.h" |
| 6 | #include "xs_mime.h" | 6 | #include "xs_mime.h" |
| 7 | #include "xs_html.h" | 7 | #include "xs_html.h" |
| 8 | #include "xs_json.h" | ||
| 8 | 9 | ||
| 9 | #include "snac.h" | 10 | #include "snac.h" |
| 10 | 11 | ||
| @@ -36,6 +37,39 @@ const char *smileys[] = { | |||
| 36 | }; | 37 | }; |
| 37 | 38 | ||
| 38 | 39 | ||
| 40 | xs_dict *emojis(void) | ||
| 41 | /* returns a dict with the emojis */ | ||
| 42 | { | ||
| 43 | xs *fn = xs_fmt("%s/emojis.json", srv_basedir); | ||
| 44 | FILE *f; | ||
| 45 | |||
| 46 | if (mtime(fn) == 0) { | ||
| 47 | /* file does not exist; create it with the defaults */ | ||
| 48 | xs *d = xs_dict_new(); | ||
| 49 | const char **emo = smileys; | ||
| 50 | |||
| 51 | while (*emo) { | ||
| 52 | d = xs_dict_append(d, emo[0], emo[1]); | ||
| 53 | emo += 2; | ||
| 54 | } | ||
| 55 | |||
| 56 | if ((f = fopen(fn, "w")) != NULL) { | ||
| 57 | xs_json_dump(d, 4, f); | ||
| 58 | fclose(f); | ||
| 59 | } | ||
| 60 | } | ||
| 61 | |||
| 62 | xs_dict *d = NULL; | ||
| 63 | |||
| 64 | if ((f = fopen(fn, "r")) != NULL) { | ||
| 65 | d = xs_json_load(f); | ||
| 66 | fclose(f); | ||
| 67 | } | ||
| 68 | |||
| 69 | return d; | ||
| 70 | } | ||
| 71 | |||
| 72 | |||
| 39 | static xs_str *format_line(const char *line, xs_list **attach) | 73 | static xs_str *format_line(const char *line, xs_list **attach) |
| 40 | /* formats a line */ | 74 | /* formats a line */ |
| 41 | { | 75 | { |
| @@ -190,11 +224,12 @@ xs_str *not_really_markdown(const char *content, xs_list **attach) | |||
| 190 | 224 | ||
| 191 | { | 225 | { |
| 192 | /* traditional emoticons */ | 226 | /* traditional emoticons */ |
| 193 | const char **emo = smileys; | 227 | xs *d = emojis(); |
| 228 | int c = 0; | ||
| 229 | char *k, *v; | ||
| 194 | 230 | ||
| 195 | while (*emo) { | 231 | while (xs_dict_next(d, &k, &v, &c)) { |
| 196 | s = xs_replace_i(s, emo[0], emo[1]); | 232 | s = xs_replace_i(s, k, v); |
| 197 | emo += 2; | ||
| 198 | } | 233 | } |
| 199 | } | 234 | } |
| 200 | 235 | ||
| @@ -304,6 +304,7 @@ int activitypub_post_handler(const xs_dict *req, const char *q_path, | |||
| 304 | char *payload, int p_size, | 304 | char *payload, int p_size, |
| 305 | char **body, int *b_size, char **ctype); | 305 | char **body, int *b_size, char **ctype); |
| 306 | 306 | ||
| 307 | xs_dict *emojis(void); | ||
| 307 | xs_str *not_really_markdown(const char *content, xs_list **attach); | 308 | xs_str *not_really_markdown(const char *content, xs_list **attach); |
| 308 | xs_str *sanitize(const char *content); | 309 | xs_str *sanitize(const char *content); |
| 309 | xs_str *encode_html(const char *str); | 310 | xs_str *encode_html(const char *str); |