summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--html.c111
-rw-r--r--snac.h1
2 files changed, 63 insertions, 49 deletions
diff --git a/html.c b/html.c
index 9de1cca..fe070c1 100644
--- a/html.c
+++ b/html.c
@@ -2728,55 +2728,7 @@ int html_get_handler(const xs_dict *req, const char *q_path,
2728 xs_dict_get(srv_config, "host")); 2728 xs_dict_get(srv_config, "host"));
2729 xs *rss_link = xs_fmt("%s.rss", snac.actor); 2729 xs *rss_link = xs_fmt("%s.rss", snac.actor);
2730 2730
2731 xs_html *rss = xs_html_tag("rss", 2731 *body = timeline_to_rss(&snac, elems, rss_title, rss_link, bio);
2732 xs_html_attr("version", "0.91"));
2733
2734 xs_html *channel = xs_html_tag("channel",
2735 xs_html_tag("title",
2736 xs_html_text(rss_title)),
2737 xs_html_tag("language",
2738 xs_html_text("en")),
2739 xs_html_tag("link",
2740 xs_html_text(rss_link)),
2741 xs_html_tag("description",
2742 xs_html_text(bio)));
2743
2744 xs_html_add(rss, channel);
2745
2746 xs_list *p = elems;
2747 char *v;
2748
2749 while (xs_list_iter(&p, &v)) {
2750 xs *msg = NULL;
2751
2752 if (!valid_status(timeline_get_by_md5(&snac, v, &msg)))
2753 continue;
2754
2755 char *id = xs_dict_get(msg, "id");
2756 char *content = xs_dict_get(msg, "content");
2757
2758 if (!xs_startswith(id, snac.actor))
2759 continue;
2760
2761 /* create a title with the first line of the content */
2762 xs *es_title = xs_replace(content, "<br>", "\n");
2763 xs *title = xs_str_new(NULL);
2764 int i;
2765
2766 for (i = 0; es_title[i] && es_title[i] != '\n' && es_title[i] != '&' && i < 50; i++)
2767 title = xs_append_m(title, &es_title[i], 1);
2768
2769 xs_html_add(channel,
2770 xs_html_tag("item",
2771 xs_html_tag("title",
2772 xs_html_text(title)),
2773 xs_html_tag("link",
2774 xs_html_text(id)),
2775 xs_html_tag("description",
2776 xs_html_text(content))));
2777 }
2778
2779 *body = xs_html_render_s(rss, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
2780 *b_size = strlen(*body); 2732 *b_size = strlen(*body);
2781 *ctype = "application/rss+xml; charset=utf-8"; 2733 *ctype = "application/rss+xml; charset=utf-8";
2782 status = 200; 2734 status = 200;
@@ -3336,3 +3288,64 @@ int html_post_handler(const xs_dict *req, const char *q_path,
3336 3288
3337 return status; 3289 return status;
3338} 3290}
3291
3292
3293xs_str *timeline_to_rss(snac *user, const xs_list *timeline, char *title, char *link, char *desc)
3294/* converts a timeline to rss */
3295{
3296 xs_html *rss = xs_html_tag("rss",
3297 xs_html_attr("version", "0.91"));
3298
3299 xs_html *channel = xs_html_tag("channel",
3300 xs_html_tag("title",
3301 xs_html_text(title)),
3302 xs_html_tag("language",
3303 xs_html_text("en")),
3304 xs_html_tag("link",
3305 xs_html_text(link)),
3306 xs_html_tag("description",
3307 xs_html_text(desc)));
3308
3309 xs_html_add(rss, channel);
3310
3311 int c = 0;
3312 char *v;
3313
3314 while (xs_list_next(timeline, &v, &c)) {
3315 xs *msg = NULL;
3316
3317 if (user) {
3318 if (!valid_status(timeline_get_by_md5(user, v, &msg)))
3319 continue;
3320 }
3321 else {
3322 if (!valid_status(object_get_by_md5(v, &msg)))
3323 continue;
3324 }
3325
3326 char *id = xs_dict_get(msg, "id");
3327 char *content = xs_dict_get(msg, "content");
3328
3329 if (user && !xs_startswith(id, user->actor))
3330 continue;
3331
3332 /* create a title with the first line of the content */
3333 xs *es_title = xs_replace(content, "<br>", "\n");
3334 xs *title = xs_str_new(NULL);
3335 int i;
3336
3337 for (i = 0; es_title[i] && es_title[i] != '\n' && es_title[i] != '&' && i < 50; i++)
3338 title = xs_append_m(title, &es_title[i], 1);
3339
3340 xs_html_add(channel,
3341 xs_html_tag("item",
3342 xs_html_tag("title",
3343 xs_html_text(title)),
3344 xs_html_tag("link",
3345 xs_html_text(id)),
3346 xs_html_tag("description",
3347 xs_html_text(content))));
3348 }
3349
3350 return xs_html_render_s(rss, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
3351}
diff --git a/snac.h b/snac.h
index 721d088..ae6e975 100644
--- a/snac.h
+++ b/snac.h
@@ -324,6 +324,7 @@ int html_get_handler(const xs_dict *req, const char *q_path,
324int html_post_handler(const xs_dict *req, const char *q_path, 324int html_post_handler(const xs_dict *req, const char *q_path,
325 char *payload, int p_size, 325 char *payload, int p_size,
326 char **body, int *b_size, char **ctype); 326 char **body, int *b_size, char **ctype);
327xs_str *timeline_to_rss(snac *user, const xs_list *timeline, char *title, char *link, char *desc);
327 328
328int snac_init(const char *_basedir); 329int snac_init(const char *_basedir);
329int adduser(const char *uid); 330int adduser(const char *uid);