html.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. /* snac - A simple, minimalistic ActivityPub instance */
  2. /* copyright (c) 2022 grunfink - MIT license */
  3. #include "xs.h"
  4. #include "xs_io.h"
  5. #include "xs_encdec.h"
  6. #include "xs_json.h"
  7. #include "xs_regex.h"
  8. #include "xs_set.h"
  9. #include "xs_openssl.h"
  10. #include "snac.h"
  11. d_char *not_really_markdown(char *content, d_char **f_content)
  12. /* formats a content using some Markdown rules */
  13. {
  14. d_char *s = NULL;
  15. int in_pre = 0;
  16. int in_blq = 0;
  17. xs *list;
  18. char *p, *v;
  19. xs *wrk = xs_str_new(NULL);
  20. {
  21. /* split by special markup */
  22. xs *sm = xs_regex_split(content,
  23. "(`[^`]+`|\\*\\*?[^\\*]+\\*?\\*|https?:/" "/[^ ]*)");
  24. int n = 0;
  25. p = sm;
  26. while (xs_list_iter(&p, &v)) {
  27. if ((n & 0x1)) {
  28. /* markup */
  29. if (xs_startswith(v, "`")) {
  30. xs *s1 = xs_crop(xs_dup(v), 1, -1);
  31. xs *s2 = xs_fmt("<code>%s</code>", s1);
  32. wrk = xs_str_cat(wrk, s2);
  33. }
  34. else
  35. if (xs_startswith(v, "**")) {
  36. xs *s1 = xs_crop(xs_dup(v), 2, -2);
  37. xs *s2 = xs_fmt("<b>%s</b>", s1);
  38. wrk = xs_str_cat(wrk, s2);
  39. }
  40. else
  41. if (xs_startswith(v, "*")) {
  42. xs *s1 = xs_crop(xs_dup(v), 1, -1);
  43. xs *s2 = xs_fmt("<i>%s</i>", s1);
  44. wrk = xs_str_cat(wrk, s2);
  45. }
  46. else
  47. if (xs_startswith(v, "http")) {
  48. xs *s1 = xs_fmt("<a href=\"%s\">%s</a>", v, v);
  49. wrk = xs_str_cat(wrk, s1);
  50. }
  51. else
  52. /* what the hell is this */
  53. wrk = xs_str_cat(wrk, v);
  54. }
  55. else
  56. /* surrounded text, copy directly */
  57. wrk = xs_str_cat(wrk, v);
  58. n++;
  59. }
  60. }
  61. /* now work by lines */
  62. p = list = xs_split(wrk, "\n");
  63. s = xs_str_new(NULL);
  64. while (xs_list_iter(&p, &v)) {
  65. xs *ss = xs_strip(xs_dup(v));
  66. if (xs_startswith(ss, "```")) {
  67. if (!in_pre)
  68. s = xs_str_cat(s, "<pre>");
  69. else
  70. s = xs_str_cat(s, "</pre>");
  71. in_pre = !in_pre;
  72. continue;
  73. }
  74. if (xs_startswith(ss, ">")) {
  75. /* delete the > and subsequent spaces */
  76. ss = xs_strip(xs_crop(ss, 1, 0));
  77. if (!in_blq) {
  78. s = xs_str_cat(s, "<blockquote>");
  79. in_blq = 1;
  80. }
  81. s = xs_str_cat(s, ss);
  82. s = xs_str_cat(s, "<br>");
  83. continue;
  84. }
  85. if (in_blq) {
  86. s = xs_str_cat(s, "</blockquote>");
  87. in_blq = 0;
  88. }
  89. s = xs_str_cat(s, ss);
  90. s = xs_str_cat(s, "<br>");
  91. }
  92. if (in_blq)
  93. s = xs_str_cat(s, "</blockquote>");
  94. if (in_pre)
  95. s = xs_str_cat(s, "</pre>");
  96. /* some beauty fixes */
  97. s = xs_replace_i(s, "</blockquote><br>", "</blockquote>");
  98. *f_content = s;
  99. return *f_content;
  100. }
  101. int login(snac *snac, char *headers)
  102. /* tries a login */
  103. {
  104. int logged_in = 0;
  105. char *auth = xs_dict_get(headers, "authorization");
  106. if (auth && xs_startswith(auth, "Basic ")) {
  107. int sz;
  108. xs *s1 = xs_crop(xs_dup(auth), 6, 0);
  109. xs *s2 = xs_base64_dec(s1, &sz);
  110. xs *l1 = xs_split_n(s2, ":", 1);
  111. if (xs_list_len(l1) == 2) {
  112. logged_in = check_password(
  113. xs_list_get(l1, 0), xs_list_get(l1, 1),
  114. xs_dict_get(snac->config, "passwd"));
  115. }
  116. }
  117. return logged_in;
  118. }
  119. d_char *html_msg_icon(snac *snac, d_char *os, char *msg)
  120. {
  121. char *actor_id;
  122. xs *actor = NULL;
  123. xs *s = xs_str_new(NULL);
  124. if ((actor_id = xs_dict_get(msg, "attributedTo")) == NULL)
  125. actor_id = xs_dict_get(msg, "actor");
  126. if (actor_id && valid_status(actor_get(snac, actor_id, &actor))) {
  127. xs *name = NULL;
  128. xs *avatar = NULL;
  129. char *v;
  130. /* get the name */
  131. if ((v = xs_dict_get(actor, "name")) == NULL) {
  132. if ((v = xs_dict_get(actor, "preferredUsername")) == NULL) {
  133. v = "user";
  134. }
  135. }
  136. name = xs_dup(v);
  137. /* get the avatar */
  138. if ((v = xs_dict_get(actor, "icon")) != NULL &&
  139. (v = xs_dict_get(v, "url")) != NULL) {
  140. avatar = xs_dup(v);
  141. }
  142. if (avatar == NULL)
  143. avatar = xs_fmt("data:image/png;base64, %s", susie);
  144. {
  145. xs *s1 = xs_fmt("<p><img class=\"snac-avatar\" src=\"%s\" alt=\"\"/>\n", avatar);
  146. s = xs_str_cat(s, s1);
  147. }
  148. {
  149. xs *s1 = xs_fmt("<a href=\"%s\" class=\"p-author h-card snac-author\">%s</a>",
  150. actor_id, name);
  151. s = xs_str_cat(s, s1);
  152. }
  153. if (strcmp(xs_dict_get(msg, "type"), "Note") == 0) {
  154. xs *s1 = xs_fmt(" <a href=\"%s\">»</a>", xs_dict_get(msg, "id"));
  155. s = xs_str_cat(s, s1);
  156. }
  157. if (!is_msg_public(snac, msg))
  158. s = xs_str_cat(s, " <span title=\"private\">&#128274;</span>");
  159. if ((v = xs_dict_get(msg, "published")) == NULL)
  160. v = "&nbsp;";
  161. {
  162. xs *s1 = xs_fmt("<br>\n<time class=\"dt-published snac-pubdate\">%s</time>\n", v);
  163. s = xs_str_cat(s, s1);
  164. }
  165. }
  166. return xs_str_cat(os, s);
  167. }
  168. d_char *html_user_header(snac *snac, d_char *s, int local)
  169. /* creates the HTML header */
  170. {
  171. char *p, *v;
  172. s = xs_str_cat(s, "<!DOCTYPE html>\n<html>\n<head>\n");
  173. s = xs_str_cat(s, "<meta name=\"viewport\" "
  174. "content=\"width=device-width, initial-scale=1\"/>\n");
  175. s = xs_str_cat(s, "<meta name=\"generator\" "
  176. "content=\"" USER_AGENT "\"/>\n");
  177. /* add server CSS */
  178. p = xs_dict_get(srv_config, "cssurls");
  179. while (xs_list_iter(&p, &v)) {
  180. xs *s1 = xs_fmt("<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\"/>\n", v);
  181. s = xs_str_cat(s, s1);
  182. }
  183. /* add the user CSS */
  184. {
  185. xs *css = NULL;
  186. int size;
  187. if (valid_status(static_get(snac, "style.css", &css, &size))) {
  188. xs *s1 = xs_fmt("<style>%s</style>\n", css);
  189. s = xs_str_cat(s, s1);
  190. }
  191. }
  192. {
  193. xs *s1 = xs_fmt("<title>%s</title>\n", xs_dict_get(snac->config, "name"));
  194. s = xs_str_cat(s, s1);
  195. }
  196. s = xs_str_cat(s, "</head>\n<body>\n");
  197. /* top nav */
  198. s = xs_str_cat(s, "<nav class=\"snac-top-nav\">");
  199. {
  200. xs *s1;
  201. if (local)
  202. s1 = xs_fmt("<a href=\"%s/admin\">%s</a></nav>\n", snac->actor, L("admin"));
  203. else
  204. s1 = xs_fmt("<a href=\"%s\">%s</a></nav>\n", snac->actor, L("public"));
  205. s = xs_str_cat(s, s1);
  206. }
  207. /* user info */
  208. {
  209. xs *bio = NULL;
  210. char *_tmpl =
  211. "<div class=\"h-card snac-top-user\">\n"
  212. "<p class=\"p-name snac-top-user-name\">%s</p>\n"
  213. "<p class=\"snac-top-user-id\">@%s@%s</p>\n"
  214. "<div class=\"p-note snac-top-user-bio\">%s</div>\n"
  215. "</div>\n";
  216. not_really_markdown(xs_dict_get(snac->config, "bio"), &bio);
  217. xs *s1 = xs_fmt(_tmpl,
  218. xs_dict_get(snac->config, "name"),
  219. xs_dict_get(snac->config, "uid"), xs_dict_get(srv_config, "host"),
  220. bio
  221. );
  222. s = xs_str_cat(s, s1);
  223. }
  224. return s;
  225. }
  226. d_char *html_top_controls(snac *snac, d_char *s)
  227. /* generates the top controls */
  228. {
  229. char *_tmpl =
  230. "<div class=\"snac-top-controls\">\n"
  231. "<div class=\"snac-note\">\n"
  232. "<form method=\"post\" action=\"%s/admin/note\">\n"
  233. "<textarea class=\"snac-textarea\" name=\"content\" "
  234. "rows=\"8\" wrap=\"virtual\" required=\"required\"></textarea>\n"
  235. "<input type=\"hidden\" name=\"in_reply_to\" value=\"\">\n"
  236. "<input type=\"submit\" class=\"button\" value=\"%s\">\n"
  237. "</form><p>\n"
  238. "</div>\n"
  239. "<div class=\"snac-top-controls-more\">\n"
  240. "<details><summary>%s</summary>\n"
  241. "<form method=\"post\" action=\"%s/admin/action\">\n"
  242. "<input type=\"text\" name=\"actor\" required=\"required\">\n"
  243. "<input type=\"submit\" name=\"action\" value=\"%s\"> %s\n"
  244. "</form></p>\n"
  245. "<form method=\"post\" action=\"%s\">\n"
  246. "<input type=\"text\" name=\"id\" required=\"required\">\n"
  247. "<input type=\"submit\" name=\"action\" value=\"%s\"> %s\n"
  248. "</form></p>\n"
  249. "<details><summary>%s</summary>\n"
  250. "<div class=\"snac-user-setup\">\n"
  251. "<form method=\"post\" action=\"%s/admin/user-setup\">\n"
  252. "<p>%s:<br>\n"
  253. "<input type=\"text\" name=\"name\" value=\"%s\"></p>\n"
  254. "<p>%s:<br>\n"
  255. "<input type=\"text\" name=\"avatar\" value=\"%s\"></p>\n"
  256. "<p>%s:<br>\n"
  257. "<textarea name=\"bio\" cols=60 rows=4>%s</textarea></p>\n"
  258. "<p>%s:<br>\n"
  259. "<input type=\"password\" name=\"passwd1\" value=\"\"></p>\n"
  260. "<p>%s:<br>\n"
  261. "<input type=\"password\" name=\"passwd2\" value=\"\"></p>\n"
  262. "<input type=\"submit\" class=\"button\" value=\"%s\">\n"
  263. "</form>\n"
  264. "</div>\n"
  265. "</details>\n"
  266. "</details>\n"
  267. "</div>\n"
  268. "</div>\n";
  269. xs *s1 = xs_fmt(_tmpl,
  270. snac->actor,
  271. L("Post"),
  272. L("More options..."),
  273. snac->actor,
  274. L("Follow"), L("(by URL or user@host)"),
  275. snac->actor,
  276. L("Boost"), L("(by URL)"),
  277. L("User setup..."),
  278. snac->actor,
  279. L("User name"),
  280. xs_dict_get(snac->config, "name"),
  281. L("Avatar URL"),
  282. xs_dict_get(snac->config, "avatar"),
  283. L("Bio"),
  284. xs_dict_get(snac->config, "bio"),
  285. L("Password (only to change it)"),
  286. L("Repeat Password"),
  287. L("Update user info")
  288. );
  289. s = xs_str_cat(s, s1);
  290. return s;
  291. }
  292. d_char *html_button(d_char *s, char *clss, char *label)
  293. {
  294. xs *s1 = xs_fmt(
  295. "<input type=\"submit\" name=\"action\" "
  296. "class=\"snac-btn-%s\" value=\"%s\">\n",
  297. clss, label);
  298. return xs_str_cat(s, s1);
  299. }
  300. d_char *html_entry_controls(snac *snac, d_char *os, char *msg)
  301. {
  302. char *id = xs_dict_get(msg, "id");
  303. char *actor = xs_dict_get(msg, "attributedTo");
  304. char *meta = xs_dict_get(msg, "_snac");
  305. xs *s = xs_str_new(NULL);
  306. xs *md5 = xs_md5_hex(id, strlen(id));
  307. s = xs_str_cat(s, "<div class=\"snac-controls\">\n");
  308. {
  309. xs *s1 = xs_fmt(
  310. "<form method=\"post\" action=\"%s/admin/action\">\n"
  311. "<input type=\"hidden\" name=\"id\" value=\"%s\">\n"
  312. "<input type=\"hidden\" name=\"actor\" value=\"%s\">\n"
  313. "<input type=\"button\" name=\"action\" "
  314. "value=\"%s\" onclick=\""
  315. "x = document.getElementById('%s_reply'); "
  316. "if (x.style.display == 'block') "
  317. " x.style.display = 'none'; else "
  318. " x.style.display = 'block';"
  319. "\">\n",
  320. snac->actor, id, actor,
  321. L("Reply"),
  322. md5
  323. );
  324. s = xs_str_cat(s, s1);
  325. }
  326. if (strcmp(actor, snac->actor) != 0) {
  327. /* controls for other actors than this one */
  328. char *l;
  329. l = xs_dict_get(meta, "liked_by");
  330. if (xs_list_in(l, snac->actor) == -1) {
  331. /* not already liked; add button */
  332. s = html_button(s, "like", L("Like"));
  333. }
  334. l = xs_dict_get(meta, "announced_by");
  335. if (xs_list_in(l, snac->actor) == -1) {
  336. /* not already boosted; add button */
  337. s = html_button(s, "boost", L("Boost"));
  338. }
  339. if (following_check(snac, actor)) {
  340. s = html_button(s, "unfollow", L("Unfollow"));
  341. }
  342. else {
  343. s = html_button(s, "follow", L("Follow"));
  344. s = html_button(s, "mute", L("MUTE"));
  345. }
  346. }
  347. s = html_button(s, "delete", L("Delete"));
  348. s = xs_str_cat(s, "</form>\n");
  349. {
  350. /* the post textarea */
  351. xs *ct = xs_str_new("");
  352. xs *s1 = xs_fmt(
  353. "<p><div class=\"snac-note\" style=\"display: none\" id=\"%s_reply\">\n"
  354. "<form method=\"post\" action=\"%s/admin/note\" id=\"%s_reply_form\">\n"
  355. "<textarea class=\"snac-textarea\" name=\"content\" "
  356. "rows=\"4\" wrap=\"virtual\" required=\"required\">%s</textarea>\n"
  357. "<input type=\"hidden\" name=\"in_reply_to\" value=\"%s\">\n"
  358. "<input type=\"submit\" class=\"button\" value=\"%s\">\n"
  359. "</form><p></div>\n",
  360. md5,
  361. snac->actor, md5,
  362. ct,
  363. id,
  364. L("Post")
  365. );
  366. s = xs_str_cat(s, s1);
  367. }
  368. s = xs_str_cat(s, "</div>\n");
  369. return xs_str_cat(os, s);
  370. }
  371. d_char *html_entry(snac *snac, d_char *os, char *msg, xs_set *seen, int local, int level)
  372. {
  373. char *id = xs_dict_get(msg, "id");
  374. char *type = xs_dict_get(msg, "type");
  375. char *meta = xs_dict_get(msg, "_snac");
  376. xs *actor_o = NULL;
  377. char *actor;
  378. /* return if already seen */
  379. if (xs_set_add(seen, id) == 0)
  380. return os;
  381. if (strcmp(type, "Follow") == 0)
  382. return os;
  383. /* bring the main actor */
  384. if ((actor = xs_dict_get(msg, "attributedTo")) == NULL)
  385. return os;
  386. if (!valid_status(actor_get(snac, actor, &actor_o)))
  387. return os;
  388. xs *s = xs_str_new(NULL);
  389. /* if this is our post, add the score */
  390. if (xs_startswith(id, snac->actor)) {
  391. int likes = xs_list_len(xs_dict_get(meta, "liked_by"));
  392. int boosts = xs_list_len(xs_dict_get(meta, "announced_by"));
  393. xs *s1 = xs_fmt(
  394. "<div class=\"snac-score\">%d &#9733; %d &#8634;</div>\n",
  395. likes, boosts);
  396. s = xs_str_cat(s, s1);
  397. }
  398. if (level == 0) {
  399. char *referrer;
  400. s = xs_str_cat(s, "<div class=\"snac-post\">\n");
  401. /* print the origin of the post, if any */
  402. if ((referrer = xs_dict_get(meta, "referrer")) != NULL) {
  403. xs *actor_r = NULL;
  404. if (valid_status(actor_get(snac, referrer, &actor_r))) {
  405. char *name;
  406. if ((name = xs_dict_get(actor_r, "name")) == NULL)
  407. name = xs_dict_get(actor_r, "preferredUsername");
  408. xs *s1 = xs_fmt(
  409. "<div class=\"snac-origin\">"
  410. "<a href=\"%s\">%s</a> %s</div>\n",
  411. xs_dict_get(actor_r, "id"),
  412. name,
  413. L("boosted")
  414. );
  415. s = xs_str_cat(s, s1);
  416. }
  417. }
  418. }
  419. else
  420. s = xs_str_cat(s, "<div class=\"snac-child\">\n");
  421. s = html_msg_icon(snac, s, msg);
  422. /* add the content */
  423. s = xs_str_cat(s, "<div class=\"e-content snac-content\">\n");
  424. {
  425. xs *c = xs_dup(xs_dict_get(msg, "content"));
  426. /* do some tweaks to the content */
  427. c = xs_replace_i(c, "\r", "");
  428. while (xs_endswith(c, "<br><br>"))
  429. c = xs_crop(c, 0, -4);
  430. c = xs_replace_i(c, "<br><br>", "<p>");
  431. if (!xs_startswith(c, "<p>")) {
  432. xs *s1 = c;
  433. c = xs_fmt("<p>%s</p>", s1);
  434. }
  435. s = xs_str_cat(s, c);
  436. }
  437. s = xs_str_cat(s, "\n");
  438. /* add the attachments */
  439. char *attach;
  440. if ((attach = xs_dict_get(msg, "attachment")) != NULL) {
  441. char *v;
  442. while (xs_list_iter(&attach, &v)) {
  443. char *t = xs_dict_get(v, "mediaType");
  444. if (t && xs_startswith(t, "image/")) {
  445. char *url = xs_dict_get(v, "url");
  446. char *name = xs_dict_get(v, "name");
  447. if (url != NULL) {
  448. xs *s1 = xs_fmt("<p><img src=\"%s\" alt=\"%s\"/></p>\n",
  449. url, xs_is_null(name) ? "" : name);
  450. s = xs_str_cat(s, s1);
  451. }
  452. }
  453. }
  454. }
  455. s = xs_str_cat(s, "</div>\n");
  456. /** controls **/
  457. if (!local)
  458. s = html_entry_controls(snac, s, msg);
  459. /** children **/
  460. char *children = xs_dict_get(meta, "children");
  461. if (xs_list_len(children)) {
  462. int left = xs_list_len(children);
  463. char *id;
  464. s = xs_str_cat(s, "<div class=\"snac-children\">\n");
  465. if (left > 3)
  466. s = xs_str_cat(s, "<details><summary>...</summary>\n");
  467. while (xs_list_iter(&children, &id)) {
  468. xs *chd = timeline_find(snac, id);
  469. if (left == 0)
  470. s = xs_str_cat(s, "</details>\n");
  471. if (chd != NULL)
  472. s = html_entry(snac, s, chd, seen, local, level + 1);
  473. else
  474. snac_debug(snac, 1, xs_fmt("cannot read from timeline child %s", id));
  475. left--;
  476. }
  477. s = xs_str_cat(s, "</div>\n");
  478. }
  479. s = xs_str_cat(s, "</div>\n");
  480. return xs_str_cat(os, s);
  481. }
  482. d_char *html_user_footer(snac *snac, d_char *s)
  483. {
  484. xs *s1 = xs_fmt(
  485. "<div class=\"snac-footer\">\n"
  486. "<a href=\"%s\">%s</a> - "
  487. "powered by <abbr title=\"Social Networks Are Crap\">snac</abbr></div>\n",
  488. srv_baseurl,
  489. L("about this site")
  490. );
  491. return xs_str_cat(s, s1);
  492. }
  493. d_char *html_timeline(snac *snac, char *list, int local)
  494. /* returns the HTML for the timeline */
  495. {
  496. d_char *s = xs_str_new(NULL);
  497. xs_set *seen = xs_set_new(4096);
  498. char *v;
  499. double t = ftime();
  500. s = html_user_header(snac, s, local);
  501. if (!local)
  502. s = html_top_controls(snac, s);
  503. s = xs_str_cat(s, "<div class=\"snac-posts\">\n");
  504. while (xs_list_iter(&list, &v)) {
  505. xs *msg = timeline_get(snac, v);
  506. s = html_entry(snac, s, msg, seen, local, 0);
  507. }
  508. s = xs_str_cat(s, "</div>\n");
  509. s = html_user_footer(snac, s);
  510. {
  511. xs *s1 = xs_fmt("<!-- %lf seconds -->\n", ftime() - t);
  512. s = xs_str_cat(s, s1);
  513. }
  514. s = xs_str_cat(s, "</body>\n</html>\n");
  515. xs_set_free(seen);
  516. return s;
  517. }
  518. int html_get_handler(d_char *req, char *q_path, char **body, int *b_size, char **ctype)
  519. {
  520. int status = 404;
  521. snac snac;
  522. char *uid, *p_path;
  523. xs *l = xs_split_n(q_path, "/", 2);
  524. uid = xs_list_get(l, 1);
  525. if (!uid || !user_open(&snac, uid)) {
  526. /* invalid user */
  527. srv_log(xs_fmt("html_get_handler bad user %s", uid));
  528. return 404;
  529. }
  530. p_path = xs_list_get(l, 2);
  531. if (p_path == NULL) {
  532. /* public timeline */
  533. xs *list = local_list(&snac, 0xfffffff);
  534. *body = html_timeline(&snac, list, 1);
  535. *b_size = strlen(*body);
  536. status = 200;
  537. }
  538. else
  539. if (strcmp(p_path, "admin") == 0) {
  540. /* private timeline */
  541. if (!login(&snac, req))
  542. status = 401;
  543. else {
  544. xs *list = timeline_list(&snac, 0xfffffff);
  545. *body = html_timeline(&snac, list, 0);
  546. *b_size = strlen(*body);
  547. status = 200;
  548. }
  549. }
  550. else
  551. if (xs_startswith(p_path, "p/") == 0) {
  552. /* a timeline with just one entry */
  553. }
  554. else
  555. if (xs_startswith(p_path, "s/") == 0) {
  556. /* a static file */
  557. }
  558. else
  559. if (xs_startswith(p_path, "h/") == 0) {
  560. /* an entry from the history */
  561. }
  562. else
  563. status = 404;
  564. user_free(&snac);
  565. if (valid_status(status)) {
  566. *ctype = "text/html; charset=utf-8";
  567. }
  568. return status;
  569. }
  570. int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size,
  571. char **body, int *b_size, char **ctype)
  572. {
  573. int status = 0;
  574. return status;
  575. }