123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863 |
- #include "xs.h"
- #include "xs_io.h"
- #include "xs_encdec.h"
- #include "xs_json.h"
- #include "xs_regex.h"
- #include "xs_set.h"
- #include "xs_openssl.h"
- #include "snac.h"
- d_char *not_really_markdown(char *content, d_char **f_content)
- {
- d_char *s = NULL;
- int in_pre = 0;
- int in_blq = 0;
- xs *list;
- char *p, *v;
- xs *wrk = xs_str_new(NULL);
- {
-
- xs *sm = xs_regex_split(content,
- "(`[^`]+`|\\*\\*?[^\\*]+\\*?\\*|https?:/" "/[^ ]*)");
- int n = 0;
- p = sm;
- while (xs_list_iter(&p, &v)) {
- if ((n & 0x1)) {
-
- if (xs_startswith(v, "`")) {
- xs *s1 = xs_crop(xs_dup(v), 1, -1);
- xs *s2 = xs_fmt("<code>%s</code>", s1);
- wrk = xs_str_cat(wrk, s2);
- }
- else
- if (xs_startswith(v, "**")) {
- xs *s1 = xs_crop(xs_dup(v), 2, -2);
- xs *s2 = xs_fmt("<b>%s</b>", s1);
- wrk = xs_str_cat(wrk, s2);
- }
- else
- if (xs_startswith(v, "*")) {
- xs *s1 = xs_crop(xs_dup(v), 1, -1);
- xs *s2 = xs_fmt("<i>%s</i>", s1);
- wrk = xs_str_cat(wrk, s2);
- }
- else
- if (xs_startswith(v, "http")) {
- xs *s1 = xs_fmt("<a href=\"%s\">%s</a>", v, v);
- wrk = xs_str_cat(wrk, s1);
- }
- else
-
- wrk = xs_str_cat(wrk, v);
- }
- else
-
- wrk = xs_str_cat(wrk, v);
- n++;
- }
- }
-
- p = list = xs_split(wrk, "\n");
- s = xs_str_new(NULL);
- while (xs_list_iter(&p, &v)) {
- xs *ss = xs_strip(xs_dup(v));
- if (xs_startswith(ss, "```")) {
- if (!in_pre)
- s = xs_str_cat(s, "<pre>");
- else
- s = xs_str_cat(s, "</pre>");
- in_pre = !in_pre;
- continue;
- }
- if (xs_startswith(ss, ">")) {
-
- ss = xs_strip(xs_crop(ss, 1, 0));
- if (!in_blq) {
- s = xs_str_cat(s, "<blockquote>");
- in_blq = 1;
- }
- s = xs_str_cat(s, ss);
- s = xs_str_cat(s, "<br>");
- continue;
- }
- if (in_blq) {
- s = xs_str_cat(s, "</blockquote>");
- in_blq = 0;
- }
- s = xs_str_cat(s, ss);
- s = xs_str_cat(s, "<br>");
- }
- if (in_blq)
- s = xs_str_cat(s, "</blockquote>");
- if (in_pre)
- s = xs_str_cat(s, "</pre>");
-
- s = xs_replace_i(s, "</blockquote><br>", "</blockquote>");
- *f_content = s;
- return *f_content;
- }
- int login(snac *snac, char *headers)
- {
- int logged_in = 0;
- char *auth = xs_dict_get(headers, "authorization");
- if (auth && xs_startswith(auth, "Basic ")) {
- int sz;
- xs *s1 = xs_crop(xs_dup(auth), 6, 0);
- xs *s2 = xs_base64_dec(s1, &sz);
- xs *l1 = xs_split_n(s2, ":", 1);
- if (xs_list_len(l1) == 2) {
- logged_in = check_password(
- xs_list_get(l1, 0), xs_list_get(l1, 1),
- xs_dict_get(snac->config, "passwd"));
- }
- }
- return logged_in;
- }
- d_char *html_msg_icon(snac *snac, d_char *os, char *msg)
- {
- char *actor_id;
- xs *actor = NULL;
- xs *s = xs_str_new(NULL);
- if ((actor_id = xs_dict_get(msg, "attributedTo")) == NULL)
- actor_id = xs_dict_get(msg, "actor");
- if (actor_id && valid_status(actor_get(snac, actor_id, &actor))) {
- xs *name = NULL;
- xs *avatar = NULL;
- char *v;
-
- if ((v = xs_dict_get(actor, "name")) == NULL) {
- if ((v = xs_dict_get(actor, "preferredUsername")) == NULL) {
- v = "user";
- }
- }
- name = xs_dup(v);
-
- if ((v = xs_dict_get(actor, "icon")) != NULL &&
- (v = xs_dict_get(v, "url")) != NULL) {
- avatar = xs_dup(v);
- }
- if (avatar == NULL)
- avatar = xs_fmt("data:image/png;base64, %s", susie);
- {
- xs *s1 = xs_fmt("<p><img class=\"snac-avatar\" src=\"%s\" alt=\"\"/>\n", avatar);
- s = xs_str_cat(s, s1);
- }
- {
- xs *s1 = xs_fmt("<a href=\"%s\" class=\"p-author h-card snac-author\">%s</a>",
- actor_id, name);
- s = xs_str_cat(s, s1);
- }
- if (strcmp(xs_dict_get(msg, "type"), "Note") == 0) {
- xs *s1 = xs_fmt(" <a href=\"%s\">»</a>", xs_dict_get(msg, "id"));
- s = xs_str_cat(s, s1);
- }
- if (!is_msg_public(snac, msg))
- s = xs_str_cat(s, " <span title=\"private\">🔒</span>");
- if ((v = xs_dict_get(msg, "published")) == NULL)
- v = " ";
- {
- xs *s1 = xs_fmt("<br>\n<time class=\"dt-published snac-pubdate\">%s</time>\n", v);
- s = xs_str_cat(s, s1);
- }
- }
- return xs_str_cat(os, s);
- }
- d_char *html_user_header(snac *snac, d_char *s, int local)
- {
- char *p, *v;
- s = xs_str_cat(s, "<!DOCTYPE html>\n<html>\n<head>\n");
- s = xs_str_cat(s, "<meta name=\"viewport\" "
- "content=\"width=device-width, initial-scale=1\"/>\n");
- s = xs_str_cat(s, "<meta name=\"generator\" "
- "content=\"" USER_AGENT "\"/>\n");
-
- p = xs_dict_get(srv_config, "cssurls");
- while (xs_list_iter(&p, &v)) {
- xs *s1 = xs_fmt("<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\"/>\n", v);
- s = xs_str_cat(s, s1);
- }
-
- {
- xs *css = NULL;
- int size;
- if (valid_status(static_get(snac, "style.css", &css, &size))) {
- xs *s1 = xs_fmt("<style>%s</style>\n", css);
- s = xs_str_cat(s, s1);
- }
- }
- {
- xs *s1 = xs_fmt("<title>%s</title>\n", xs_dict_get(snac->config, "name"));
- s = xs_str_cat(s, s1);
- }
- s = xs_str_cat(s, "</head>\n<body>\n");
-
- s = xs_str_cat(s, "<nav class=\"snac-top-nav\">");
- {
- xs *s1;
- if (local)
- s1 = xs_fmt("<a href=\"%s/admin\">%s</a></nav>\n", snac->actor, L("admin"));
- else
- s1 = xs_fmt("<a href=\"%s\">%s</a></nav>\n", snac->actor, L("public"));
- s = xs_str_cat(s, s1);
- }
-
- {
- xs *bio = NULL;
- char *_tmpl =
- "<div class=\"h-card snac-top-user\">\n"
- "<p class=\"p-name snac-top-user-name\">%s</p>\n"
- "<p class=\"snac-top-user-id\">@%s@%s</p>\n"
- "<div class=\"p-note snac-top-user-bio\">%s</div>\n"
- "</div>\n";
- not_really_markdown(xs_dict_get(snac->config, "bio"), &bio);
- xs *s1 = xs_fmt(_tmpl,
- xs_dict_get(snac->config, "name"),
- xs_dict_get(snac->config, "uid"), xs_dict_get(srv_config, "host"),
- bio
- );
- s = xs_str_cat(s, s1);
- }
- return s;
- }
- d_char *html_top_controls(snac *snac, d_char *s)
- {
- char *_tmpl =
- "<div class=\"snac-top-controls\">\n"
- "<div class=\"snac-note\">\n"
- "<form method=\"post\" action=\"%s/admin/note\">\n"
- "<textarea class=\"snac-textarea\" name=\"content\" "
- "rows=\"8\" wrap=\"virtual\" required=\"required\"></textarea>\n"
- "<input type=\"hidden\" name=\"in_reply_to\" value=\"\">\n"
- "<input type=\"submit\" class=\"button\" value=\"%s\">\n"
- "</form><p>\n"
- "</div>\n"
- "<div class=\"snac-top-controls-more\">\n"
- "<details><summary>%s</summary>\n"
- "<form method=\"post\" action=\"%s/admin/action\">\n"
- "<input type=\"text\" name=\"actor\" required=\"required\">\n"
- "<input type=\"submit\" name=\"action\" value=\"%s\"> %s\n"
- "</form></p>\n"
- "<form method=\"post\" action=\"%s\">\n"
- "<input type=\"text\" name=\"id\" required=\"required\">\n"
- "<input type=\"submit\" name=\"action\" value=\"%s\"> %s\n"
- "</form></p>\n"
- "<details><summary>%s</summary>\n"
- "<div class=\"snac-user-setup\">\n"
- "<form method=\"post\" action=\"%s/admin/user-setup\">\n"
- "<p>%s:<br>\n"
- "<input type=\"text\" name=\"name\" value=\"%s\"></p>\n"
- "<p>%s:<br>\n"
- "<input type=\"text\" name=\"avatar\" value=\"%s\"></p>\n"
- "<p>%s:<br>\n"
- "<textarea name=\"bio\" cols=60 rows=4>%s</textarea></p>\n"
- "<p>%s:<br>\n"
- "<input type=\"password\" name=\"passwd1\" value=\"\"></p>\n"
- "<p>%s:<br>\n"
- "<input type=\"password\" name=\"passwd2\" value=\"\"></p>\n"
- "<input type=\"submit\" class=\"button\" value=\"%s\">\n"
- "</form>\n"
- "</div>\n"
- "</details>\n"
- "</details>\n"
- "</div>\n"
- "</div>\n";
- xs *s1 = xs_fmt(_tmpl,
- snac->actor,
- L("Post"),
- L("More options..."),
- snac->actor,
- L("Follow"), L("(by URL or user@host)"),
- snac->actor,
- L("Boost"), L("(by URL)"),
- L("User setup..."),
- snac->actor,
- L("User name"),
- xs_dict_get(snac->config, "name"),
- L("Avatar URL"),
- xs_dict_get(snac->config, "avatar"),
- L("Bio"),
- xs_dict_get(snac->config, "bio"),
- L("Password (only to change it)"),
- L("Repeat Password"),
- L("Update user info")
- );
- s = xs_str_cat(s, s1);
- return s;
- }
- d_char *html_button(d_char *s, char *clss, char *label)
- {
- xs *s1 = xs_fmt(
- "<input type=\"submit\" name=\"action\" "
- "class=\"snac-btn-%s\" value=\"%s\">\n",
- clss, label);
- return xs_str_cat(s, s1);
- }
- d_char *html_entry_controls(snac *snac, d_char *os, char *msg)
- {
- char *id = xs_dict_get(msg, "id");
- char *actor = xs_dict_get(msg, "attributedTo");
- char *meta = xs_dict_get(msg, "_snac");
- xs *s = xs_str_new(NULL);
- xs *md5 = xs_md5_hex(id, strlen(id));
- s = xs_str_cat(s, "<div class=\"snac-controls\">\n");
- {
- xs *s1 = xs_fmt(
- "<form method=\"post\" action=\"%s/admin/action\">\n"
- "<input type=\"hidden\" name=\"id\" value=\"%s\">\n"
- "<input type=\"hidden\" name=\"actor\" value=\"%s\">\n"
- "<input type=\"button\" name=\"action\" "
- "value=\"%s\" onclick=\""
- "x = document.getElementById('%s_reply'); "
- "if (x.style.display == 'block') "
- " x.style.display = 'none'; else "
- " x.style.display = 'block';"
- "\">\n",
- snac->actor, id, actor,
- L("Reply"),
- md5
- );
- s = xs_str_cat(s, s1);
- }
- if (strcmp(actor, snac->actor) != 0) {
-
- char *l;
- l = xs_dict_get(meta, "liked_by");
- if (xs_list_in(l, snac->actor) == -1) {
-
- s = html_button(s, "like", L("Like"));
- }
- l = xs_dict_get(meta, "announced_by");
- if (xs_list_in(l, snac->actor) == -1) {
-
- s = html_button(s, "boost", L("Boost"));
- }
- if (following_check(snac, actor)) {
- s = html_button(s, "unfollow", L("Unfollow"));
- }
- else {
- s = html_button(s, "follow", L("Follow"));
- s = html_button(s, "mute", L("MUTE"));
- }
- }
- s = html_button(s, "delete", L("Delete"));
- s = xs_str_cat(s, "</form>\n");
- {
-
- xs *ct = xs_str_new("");
- xs *s1 = xs_fmt(
- "<p><div class=\"snac-note\" style=\"display: none\" id=\"%s_reply\">\n"
- "<form method=\"post\" action=\"%s/admin/note\" id=\"%s_reply_form\">\n"
- "<textarea class=\"snac-textarea\" name=\"content\" "
- "rows=\"4\" wrap=\"virtual\" required=\"required\">%s</textarea>\n"
- "<input type=\"hidden\" name=\"in_reply_to\" value=\"%s\">\n"
- "<input type=\"submit\" class=\"button\" value=\"%s\">\n"
- "</form><p></div>\n",
- md5,
- snac->actor, md5,
- ct,
- id,
- L("Post")
- );
- s = xs_str_cat(s, s1);
- }
- s = xs_str_cat(s, "</div>\n");
- return xs_str_cat(os, s);
- }
- d_char *html_entry(snac *snac, d_char *os, char *msg, xs_set *seen, int local, int level)
- {
- char *id = xs_dict_get(msg, "id");
- char *type = xs_dict_get(msg, "type");
- char *meta = xs_dict_get(msg, "_snac");
- xs *actor_o = NULL;
- char *actor;
-
- if (xs_set_add(seen, id) == 0)
- return os;
- if (strcmp(type, "Follow") == 0)
- return os;
-
- if ((actor = xs_dict_get(msg, "attributedTo")) == NULL)
- return os;
- if (!valid_status(actor_get(snac, actor, &actor_o)))
- return os;
- xs *s = xs_str_new(NULL);
-
- if (xs_startswith(id, snac->actor)) {
- int likes = xs_list_len(xs_dict_get(meta, "liked_by"));
- int boosts = xs_list_len(xs_dict_get(meta, "announced_by"));
- xs *s1 = xs_fmt(
- "<div class=\"snac-score\">%d ★ %d ↺</div>\n",
- likes, boosts);
- s = xs_str_cat(s, s1);
- }
- if (level == 0) {
- char *referrer;
- s = xs_str_cat(s, "<div class=\"snac-post\">\n");
-
- if ((referrer = xs_dict_get(meta, "referrer")) != NULL) {
- xs *actor_r = NULL;
- if (valid_status(actor_get(snac, referrer, &actor_r))) {
- char *name;
- if ((name = xs_dict_get(actor_r, "name")) == NULL)
- name = xs_dict_get(actor_r, "preferredUsername");
- xs *s1 = xs_fmt(
- "<div class=\"snac-origin\">"
- "<a href=\"%s\">%s</a> %s</div>\n",
- xs_dict_get(actor_r, "id"),
- name,
- L("boosted")
- );
- s = xs_str_cat(s, s1);
- }
- }
- }
- else
- s = xs_str_cat(s, "<div class=\"snac-child\">\n");
- s = html_msg_icon(snac, s, msg);
-
- s = xs_str_cat(s, "<div class=\"e-content snac-content\">\n");
- {
- xs *c = xs_dup(xs_dict_get(msg, "content"));
-
- c = xs_replace_i(c, "\r", "");
- while (xs_endswith(c, "<br><br>"))
- c = xs_crop(c, 0, -4);
- c = xs_replace_i(c, "<br><br>", "<p>");
- if (!xs_startswith(c, "<p>")) {
- xs *s1 = c;
- c = xs_fmt("<p>%s</p>", s1);
- }
- s = xs_str_cat(s, c);
- }
- s = xs_str_cat(s, "\n");
-
- char *attach;
- if ((attach = xs_dict_get(msg, "attachment")) != NULL) {
- char *v;
- while (xs_list_iter(&attach, &v)) {
- char *t = xs_dict_get(v, "mediaType");
- if (t && xs_startswith(t, "image/")) {
- char *url = xs_dict_get(v, "url");
- char *name = xs_dict_get(v, "name");
- if (url != NULL) {
- xs *s1 = xs_fmt("<p><img src=\"%s\" alt=\"%s\"/></p>\n",
- url, xs_is_null(name) ? "" : name);
- s = xs_str_cat(s, s1);
- }
- }
- }
- }
- s = xs_str_cat(s, "</div>\n");
-
- if (!local)
- s = html_entry_controls(snac, s, msg);
-
- char *children = xs_dict_get(meta, "children");
- if (xs_list_len(children)) {
- int left = xs_list_len(children);
- char *id;
- s = xs_str_cat(s, "<div class=\"snac-children\">\n");
- if (left > 3)
- s = xs_str_cat(s, "<details><summary>...</summary>\n");
- while (xs_list_iter(&children, &id)) {
- xs *chd = timeline_find(snac, id);
- if (left == 0)
- s = xs_str_cat(s, "</details>\n");
- if (chd != NULL)
- s = html_entry(snac, s, chd, seen, local, level + 1);
- else
- snac_debug(snac, 1, xs_fmt("cannot read from timeline child %s", id));
- left--;
- }
- s = xs_str_cat(s, "</div>\n");
- }
- s = xs_str_cat(s, "</div>\n");
- return xs_str_cat(os, s);
- }
- d_char *html_user_footer(snac *snac, d_char *s)
- {
- xs *s1 = xs_fmt(
- "<div class=\"snac-footer\">\n"
- "<a href=\"%s\">%s</a> - "
- "powered by <abbr title=\"Social Networks Are Crap\">snac</abbr></div>\n",
- srv_baseurl,
- L("about this site")
- );
- return xs_str_cat(s, s1);
- }
- d_char *html_timeline(snac *snac, char *list, int local)
- {
- d_char *s = xs_str_new(NULL);
- xs_set *seen = xs_set_new(4096);
- char *v;
- double t = ftime();
- s = html_user_header(snac, s, local);
- if (!local)
- s = html_top_controls(snac, s);
- s = xs_str_cat(s, "<div class=\"snac-posts\">\n");
- while (xs_list_iter(&list, &v)) {
- xs *msg = timeline_get(snac, v);
- s = html_entry(snac, s, msg, seen, local, 0);
- }
- s = xs_str_cat(s, "</div>\n");
- s = html_user_footer(snac, s);
- {
- xs *s1 = xs_fmt("<!-- %lf seconds -->\n", ftime() - t);
- s = xs_str_cat(s, s1);
- }
- s = xs_str_cat(s, "</body>\n</html>\n");
- xs_set_free(seen);
- return s;
- }
- int html_get_handler(d_char *req, char *q_path, char **body, int *b_size, char **ctype)
- {
- int status = 404;
- snac snac;
- char *uid, *p_path;
- xs *l = xs_split_n(q_path, "/", 2);
- uid = xs_list_get(l, 1);
- if (!uid || !user_open(&snac, uid)) {
-
- srv_log(xs_fmt("html_get_handler bad user %s", uid));
- return 404;
- }
- p_path = xs_list_get(l, 2);
- if (p_path == NULL) {
-
- xs *list = local_list(&snac, 0xfffffff);
- *body = html_timeline(&snac, list, 1);
- *b_size = strlen(*body);
- status = 200;
- }
- else
- if (strcmp(p_path, "admin") == 0) {
-
- if (!login(&snac, req))
- status = 401;
- else {
- if (history_mtime(&snac, "_timeline.html") > timeline_mtime(&snac)) {
- snac_debug(&snac, 1, xs_fmt("serving cached timeline"));
- *body = history_get(&snac, "_timeline.html");
- *b_size = strlen(*body);
- status = 200;
- }
- else {
- snac_debug(&snac, 1, xs_fmt("building timeline"));
- xs *list = timeline_list(&snac, 0xfffffff);
- *body = html_timeline(&snac, list, 0);
- *b_size = strlen(*body);
- status = 200;
- history_add(&snac, "_timeline.html", *body, *b_size);
- }
- }
- }
- else
- if (xs_startswith(p_path, "p/")) {
-
- xs *id = xs_fmt("%s/%s", snac.actor, p_path);
- xs *fn = _timeline_find_fn(&snac, id);
- if (fn != NULL) {
- xs *list = xs_list_new();
- list = xs_list_append(list, fn);
- *body = html_timeline(&snac, list, 1);
- *b_size = strlen(*body);
- status = 200;
- }
- }
- else
- if (xs_startswith(p_path, "s/")) {
-
- }
- else
- if (xs_startswith(p_path, "h/")) {
-
- }
- else
- status = 404;
- user_free(&snac);
- if (valid_status(status)) {
- *ctype = "text/html; charset=utf-8";
- }
- return status;
- }
- int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size,
- char **body, int *b_size, char **ctype)
- {
- int status = 0;
- snac snac;
- char *uid, *p_path;
- char *p_vars;
- xs *l = xs_split_n(q_path, "/", 2);
- uid = xs_list_get(l, 1);
- if (!uid || !user_open(&snac, uid)) {
-
- srv_log(xs_fmt("html_get_handler bad user %s", uid));
- return 404;
- }
- p_path = xs_list_get(l, 2);
-
- if (!login(&snac, req))
- return 401;
- p_vars = xs_dict_get(req, "p_vars");
- {
- xs *j1 = xs_json_dumps_pp(req, 4);
- printf("%s\n", j1);
- printf("[%s]\n", p_path);
- }
- if (p_path && strcmp(p_path, "admin/note") == 0) {
-
- char *content = xs_dict_get(p_vars, "content");
- char *in_reply_to = xs_dict_get(p_vars, "in_reply_to");
- if (content != NULL) {
- xs *msg = NULL;
- xs *c_msg = NULL;
- msg = msg_note(&snac, content, NULL, in_reply_to);
- c_msg = msg_create(&snac, msg);
- post(&snac, c_msg);
- timeline_add(&snac, xs_dict_get(msg, "id"), msg, in_reply_to, NULL);
- }
- status = 303;
- }
- else
- if (p_path && strcmp(p_path, "admin/action") == 0) {
-
- char *id = xs_dict_get(p_vars, "id");
- char *actor = xs_dict_get(p_vars, "actor");
- char *action = xs_dict_get(p_vars, "action");
- if (action == NULL)
- return 404;
- if (strcmp(action, "Like") == 0) {
- xs *msg = msg_admiration(&snac, id, "Like");
- post(&snac, msg);
- timeline_admire(&snac, id, snac.actor, 1);
- status = 303;
- }
- else
- if (strcmp(action, "Boost") == 0) {
- xs *msg = msg_admiration(&snac, id, "Announce");
- post(&snac, msg);
- timeline_admire(&snac, id, snac.actor, 0);
- status = 303;
- }
- else
- status = 404;
- }
- else
- if (p_path && strcmp(p_path, "admin/user-setup") == 0) {
-
- }
- if (status == 303) {
- *body = xs_fmt("%s/admin", snac.actor);
- *b_size = strlen(*body);
- }
- return status;
- }
|