summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data.c3
-rw-r--r--format.c43
-rw-r--r--snac.h1
3 files changed, 43 insertions, 4 deletions
diff --git a/data.c b/data.c
index 83e1b15..142fe8c 100644
--- a/data.c
+++ b/data.c
@@ -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
diff --git a/format.c b/format.c
index 9944822..06e006a 100644
--- a/format.c
+++ b/format.c
@@ -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
40xs_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
39static xs_str *format_line(const char *line, xs_list **attach) 73static 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
diff --git a/snac.h b/snac.h
index 5a92abc..2953af7 100644
--- a/snac.h
+++ b/snac.h
@@ -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
307xs_dict *emojis(void);
307xs_str *not_really_markdown(const char *content, xs_list **attach); 308xs_str *not_really_markdown(const char *content, xs_list **attach);
308xs_str *sanitize(const char *content); 309xs_str *sanitize(const char *content);
309xs_str *encode_html(const char *str); 310xs_str *encode_html(const char *str);