mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 16:55:10 +00:00
[ADD/MOD/WIP] Mess with lander, try to get quotes
Still WIP-tier for the latter.
This commit is contained in:
parent
1103425912
commit
41a0ae20ea
3 changed files with 188 additions and 98 deletions
|
|
@ -6,13 +6,92 @@
|
||||||
|
|
||||||
#include <AS.h>
|
#include <AS.h>
|
||||||
|
|
||||||
|
static bool
|
||||||
|
HasAdmin(ParseeData *data)
|
||||||
|
{
|
||||||
|
DbRef *admins;
|
||||||
|
HashMap *json;
|
||||||
|
bool ret = false;
|
||||||
|
|
||||||
|
admins = DbLock(data->db, 1, "admins");
|
||||||
|
if (!admins)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
json = DbJson(admins);
|
||||||
|
ret = ArraySize(JsonValueAsArray(HashMapGet(json, "admins")));
|
||||||
|
|
||||||
|
DbUnlock(data->db, admins);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
RouteHead(RouteRoot, arr, argp)
|
RouteHead(RouteRoot, arr, argp)
|
||||||
{
|
{
|
||||||
ParseeHttpArg *args = argp;
|
ParseeHttpArg *args = argp;
|
||||||
const ParseeConfig *config = args->data->config;
|
const ParseeConfig *config = args->data->config;
|
||||||
|
|
||||||
|
HttpResponseHeader(args->ctx, "Content-Type", "text/html");
|
||||||
|
HttpSendHeaders(args->ctx);
|
||||||
|
#define P(...) StreamPrintf(args->stream, __VA_ARGS__)
|
||||||
|
P("<!DOCTYPE html>");
|
||||||
|
P("<html lang='en'>");
|
||||||
|
{
|
||||||
|
P("<head>");
|
||||||
|
{
|
||||||
|
P("<title>%s Lander</title>", NAME);
|
||||||
|
P("<style>");
|
||||||
|
{
|
||||||
|
P("html {");
|
||||||
|
P("background-color: #222;");
|
||||||
|
P("color: #eee;");
|
||||||
|
P("font-family: sans-serif;");
|
||||||
|
P("}");
|
||||||
|
P("blockquote {");
|
||||||
|
P("border-left: 2px solid #ccc;");
|
||||||
|
P("margin: 1.5em 10px;");
|
||||||
|
P("background: #444;");
|
||||||
|
P("padding: 0.5em;");
|
||||||
|
P("}");
|
||||||
|
P("blockquote p {");
|
||||||
|
P("display: inline-block;");
|
||||||
|
P("}");
|
||||||
|
P("a:visited {");
|
||||||
|
P("color: #bedead;");
|
||||||
|
P("}");
|
||||||
|
P("a:link {");
|
||||||
|
P("color: #fad;");
|
||||||
|
P("}");
|
||||||
|
}
|
||||||
|
P("</style>");
|
||||||
|
}
|
||||||
|
P("</head>");
|
||||||
|
|
||||||
|
P("<body>");
|
||||||
|
{
|
||||||
|
P("<center><h1>");
|
||||||
|
P("Your %s is running!", NAME);
|
||||||
|
P("</h1></center>");
|
||||||
|
P("<hr/>");
|
||||||
|
P("<blockquote><i>");
|
||||||
|
{
|
||||||
const char *quote = RandInt(2) ?
|
const char *quote = RandInt(2) ?
|
||||||
"Kinda jealous of that, to be fair." :
|
"Kinda jealous of that, to be fair." :
|
||||||
"Why look inward when you can challenge the mainstream media?";
|
"Why look inward when you can challenge the mainstream "
|
||||||
|
"media?";
|
||||||
|
P("%s", quote);
|
||||||
|
}
|
||||||
|
P("</i></blockquote>");
|
||||||
|
|
||||||
|
P("<p>");
|
||||||
|
{
|
||||||
|
P("Your homeserver now can interact with the bridge, with ");
|
||||||
|
P("the generated YAML file and Jabber component shared ");
|
||||||
|
P("secret.");
|
||||||
|
}
|
||||||
|
P("</p>");
|
||||||
|
|
||||||
|
P("<p>");
|
||||||
|
{
|
||||||
char *mxid, *jid;
|
char *mxid, *jid;
|
||||||
char *m_to;
|
char *m_to;
|
||||||
|
|
||||||
|
|
@ -20,96 +99,91 @@ RouteHead(RouteRoot, arr, argp)
|
||||||
m_to = ParseeGenerateMTO(mxid);
|
m_to = ParseeGenerateMTO(mxid);
|
||||||
jid = ParseeJID(args->data);
|
jid = ParseeJID(args->data);
|
||||||
|
|
||||||
HttpResponseHeader(args->ctx, "Content-Type", "text/html");
|
P("You may be interested in sending <code>!help</code> to ");
|
||||||
HttpSendHeaders(args->ctx);
|
P("the Matrix <a href='%s'>%s bridge</a>, or pop out ", m_to, NAME);
|
||||||
#define P(...) StreamPrintf(args->stream, __VA_ARGS__)
|
P("<code>%s</code>'s command list on XMPP as a starter.", jid);
|
||||||
P("<html lang='en'>");
|
|
||||||
P(" <head>");
|
|
||||||
P(" <title>%s Lander</title>", NAME);
|
|
||||||
P(" <style>");
|
|
||||||
P(" html {");
|
|
||||||
P(" background-color: #222;");
|
|
||||||
P(" color: #eee;");
|
|
||||||
P(" font-family: sans-serif;");
|
|
||||||
P(" }");
|
|
||||||
P(" blockquote {");
|
|
||||||
P(" border-left: 2px solid #ccc;");
|
|
||||||
P(" margin: 1.5em 10px;");
|
|
||||||
P(" background: #444;");
|
|
||||||
P(" padding: 0.5em;");
|
|
||||||
P(" }");
|
|
||||||
P(" blockquote p {");
|
|
||||||
P(" display: inline-block;");
|
|
||||||
P(" }");
|
|
||||||
P(" </style>");
|
|
||||||
P(" </head>");
|
|
||||||
P(" <body>");
|
|
||||||
P(" <center><h1>");
|
|
||||||
P(" Your %s is running!", NAME);
|
|
||||||
P(" </h1></center>");
|
|
||||||
P(" <hr/>");
|
|
||||||
P(" <blockquote><i>");
|
|
||||||
P(" %s", quote);
|
|
||||||
P(" </i></blockquote>");
|
|
||||||
P(" <p>");
|
|
||||||
P(" Your homeserver now can interact with the bridge, with ");
|
|
||||||
P(" the generated YAML file and Jabber component shared ");
|
|
||||||
P(" secret.");
|
|
||||||
P(" </p>");
|
|
||||||
P(" <p>");
|
|
||||||
P(" You may be interested in sending <code>!help</code> to ");
|
|
||||||
P(" the Matrix <a href='%s'>%s bridge</a>, or pop out ", m_to, NAME);
|
|
||||||
P(" <code>%s</code>'s command list on XMPP as a starter.", jid);
|
|
||||||
P(" </p>");
|
|
||||||
P(" <p>");
|
|
||||||
P(" More information available at ");
|
|
||||||
P(" <a");
|
|
||||||
P(" href='https://kappach.at/parsee'");
|
|
||||||
P(" >the actual page</a>.");
|
|
||||||
P(" </p>");
|
|
||||||
P(" <h2>Permissions?</h2>");
|
|
||||||
P(" <p>");
|
|
||||||
P(" If you have problems running commands, you may want to ");
|
|
||||||
P(" look into if you have set yourself as an admin.");
|
|
||||||
P(" <p>");
|
|
||||||
P(" If you happen to have a build-from-source copy of %s,", NAME);
|
|
||||||
P(" please build all utilities and run ");
|
|
||||||
P(" <code>tools/out/adminify '%s' '[glob]'</code>.", config->db_path);
|
|
||||||
P(" </p>");
|
|
||||||
|
|
||||||
P(" <h2>Extra information</h2>");
|
|
||||||
P(" <p>");
|
|
||||||
P(" <h3>Dev documentations!!!!</h3>");
|
|
||||||
P(" Developers may be interested into looking up the ");
|
|
||||||
P(" <a href='https://at.kappach.at'>at.kappach.at</a> ");
|
|
||||||
P(" page for extensions used by Parsee on Matrix. ");
|
|
||||||
P(" </p>");
|
|
||||||
P(" <p>");
|
|
||||||
P(" <h3>Parsee statistics</h3>");
|
|
||||||
P("<pre><code>");
|
|
||||||
P("Software: %s (v%s/Cyto %s)\n", NAME, VERSION, CytoplasmGetVersionStr());
|
|
||||||
P("Cytoplasm heap used: %d B\n", MemoryAllocated());
|
|
||||||
P("</code></pre>");
|
|
||||||
P(" </p>");
|
|
||||||
P(" <p>");
|
|
||||||
P(" Some clicky links relating to %s:", NAME);
|
|
||||||
P(" <ul>");
|
|
||||||
P(" <li><a href='%s'>Repository</a></li>", REPOSITORY);
|
|
||||||
P(" <li><a href='%s'>Fediverse</a></li>", "https://ak.ari.lt/parsee");
|
|
||||||
P(" <li>CC0 88x31: <img src='%s' /></li>", "https://kappach.at/parsee.gif");
|
|
||||||
P(" </ul>");
|
|
||||||
P(" </p>");
|
|
||||||
P(" <blockquote><i>");
|
|
||||||
P(" Good luck, and have fun! :D");
|
|
||||||
P(" </i></blockquote>");
|
|
||||||
P(" <p>— LDA</p>");
|
|
||||||
P(" </body>");
|
|
||||||
P("</html>");
|
|
||||||
#undef P
|
|
||||||
|
|
||||||
Free(mxid);
|
Free(mxid);
|
||||||
Free(m_to);
|
Free(m_to);
|
||||||
Free(jid);
|
Free(jid);
|
||||||
|
}
|
||||||
|
P("</p>");
|
||||||
|
|
||||||
|
P("<p>");
|
||||||
|
{
|
||||||
|
P("More information available at ");
|
||||||
|
P("<a");
|
||||||
|
P("href='https://kappach.at/parsee'");
|
||||||
|
P(">the actual page</a>.");
|
||||||
|
}
|
||||||
|
P("</p>");
|
||||||
|
|
||||||
|
P("<h2>Permissions?</h2>");
|
||||||
|
P("<p>");
|
||||||
|
{
|
||||||
|
const char *perms = !HasAdmin(args->data) ?
|
||||||
|
" <strong style='color: red;'>(which I know you do)</strong>" :
|
||||||
|
"";
|
||||||
|
|
||||||
|
P("If you have problems running commands%s, you may want to ", perms);
|
||||||
|
P("look into if you have set yourself as an admin.");
|
||||||
|
}
|
||||||
|
P("</p>");
|
||||||
|
|
||||||
|
P("<p>");
|
||||||
|
{
|
||||||
|
P("If you happen to have a build-from-source copy of %s, ", NAME);
|
||||||
|
P("please build all utilities and run ");
|
||||||
|
P("<code>tools/out/adminify '%s' '[glob]'</code>.", config->db_path);
|
||||||
|
}
|
||||||
|
P("</p>");
|
||||||
|
|
||||||
|
P("<h2>Extra information</h2>");
|
||||||
|
P("<p>");
|
||||||
|
{
|
||||||
|
P("<h3>Dev documentations!!!!</h3>");
|
||||||
|
P("Developers may be interested into looking up the ");
|
||||||
|
P("<a href='https://at.kappach.at'>at.kappach.at</a> ");
|
||||||
|
P("page for extensions used by Parsee on Matrix. ");
|
||||||
|
}
|
||||||
|
P("</p>");
|
||||||
|
|
||||||
|
P("<h3>Parsee statistics</h3>");
|
||||||
|
P("<p>");
|
||||||
|
{
|
||||||
|
const char *cyto_ver = CytoplasmGetVersionStr();
|
||||||
|
size_t alloc = MemoryAllocated();
|
||||||
|
P("<pre><code>");
|
||||||
|
P("Software: %s (v%s/Cyto %s)\n", NAME, VERSION, cyto_ver);
|
||||||
|
P("Cytoplasm heap used: %d B\n", alloc);
|
||||||
|
P("</code></pre>");
|
||||||
|
}
|
||||||
|
P("</p>");
|
||||||
|
|
||||||
|
P("<p>");
|
||||||
|
{
|
||||||
|
P("Some clicky links relating to %s:", NAME);
|
||||||
|
P("<ul>");
|
||||||
|
{
|
||||||
|
const char *fedi = "https://ak.ari.lt/parsee";
|
||||||
|
const char *icon = "https://kappach.at/parsee.gif";
|
||||||
|
P("<li><a href='%s'>Repository</a></li>", REPOSITORY);
|
||||||
|
P("<li><a href='%s'>Fediverse</a></li>", fedi);
|
||||||
|
P("<li>CC0 88x31: <img src='%s' /></li>", icon);
|
||||||
|
}
|
||||||
|
P("</ul>");
|
||||||
|
}
|
||||||
|
P("</p>");
|
||||||
|
|
||||||
|
P("<blockquote><i>");
|
||||||
|
P("Good luck, and have fun! :D");
|
||||||
|
P("</i></blockquote>");
|
||||||
|
P("<p>— LDA</p>");
|
||||||
|
}
|
||||||
|
P("</body>");
|
||||||
|
}
|
||||||
|
P("</html>");
|
||||||
|
#undef P
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -98,10 +98,10 @@ CreateStaticView(char *str)
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
static bool
|
static bool
|
||||||
IdentifySpan(char span_tag, StrView in, StrView *view)
|
IdentifySpans(char span_tag, char end_tag, StrView in, StrView *view)
|
||||||
{
|
{
|
||||||
size_t length;
|
size_t length;
|
||||||
bool found = false;
|
bool found = false, equal, flag;
|
||||||
char prev = '\0';
|
char prev = '\0';
|
||||||
if (in.start >= in.end)
|
if (in.start >= in.end)
|
||||||
{
|
{
|
||||||
|
|
@ -112,7 +112,10 @@ IdentifySpan(char span_tag, StrView in, StrView *view)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*in.start != span_tag || isspace(*(in.start + 1)))
|
equal = span_tag == end_tag;
|
||||||
|
|
||||||
|
flag = equal && isspace(*(in.start + 1));
|
||||||
|
if (*in.start != span_tag || flag)
|
||||||
{
|
{
|
||||||
/* The opening styling directive MUST NOT be followed
|
/* The opening styling directive MUST NOT be followed
|
||||||
* by a whitespace character */
|
* by a whitespace character */
|
||||||
|
|
@ -123,7 +126,7 @@ IdentifySpan(char span_tag, StrView in, StrView *view)
|
||||||
|
|
||||||
for (length = 0; ViewLength(in) > 0; length++, in.start++)
|
for (length = 0; ViewLength(in) > 0; length++, in.start++)
|
||||||
{
|
{
|
||||||
if (*in.start == span_tag)
|
if (*in.start == end_tag)
|
||||||
{
|
{
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
|
|
@ -131,7 +134,7 @@ IdentifySpan(char span_tag, StrView in, StrView *view)
|
||||||
|
|
||||||
prev = *in.start;
|
prev = *in.start;
|
||||||
}
|
}
|
||||||
if (!found || !length || (prev && isspace(prev)))
|
if (!found || !length || (prev && equal && isspace(prev)))
|
||||||
{
|
{
|
||||||
/* the closing styling directive MUST NOT be preceeded
|
/* the closing styling directive MUST NOT be preceeded
|
||||||
* by a whitespace character. */
|
* by a whitespace character. */
|
||||||
|
|
@ -141,6 +144,7 @@ IdentifySpan(char span_tag, StrView in, StrView *view)
|
||||||
view->end = in.start;
|
view->end = in.start;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
#define IdentifySpan(span_tag, in, view) IdentifySpans(span_tag, span_tag, in, view)
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -155,12 +159,14 @@ XEP393Decode(StrView view, XEP393Element *root)
|
||||||
textview.end = subview.start;
|
textview.end = subview.start;
|
||||||
for (; subview.start < subview.end; subview.start++)
|
for (; subview.start < subview.end; subview.start++)
|
||||||
{
|
{
|
||||||
|
bool sol = false;
|
||||||
StrView span_view;
|
StrView span_view;
|
||||||
managed = false;
|
managed = false;
|
||||||
curr = *subview.start;
|
curr = *subview.start;
|
||||||
if (prev == '\0' || prev == '\n')
|
if (prev == '\0' || prev == '\n')
|
||||||
{
|
{
|
||||||
/* TODO: Start of line, start parsing blocks. */
|
/* TODO: Start of line, start parsing blocks. */
|
||||||
|
sol = true;
|
||||||
}
|
}
|
||||||
#define Spanify(xep_symbol) \
|
#define Spanify(xep_symbol) \
|
||||||
managed = true; \
|
managed = true; \
|
||||||
|
|
@ -195,6 +201,11 @@ XEP393Decode(StrView view, XEP393Element *root)
|
||||||
{
|
{
|
||||||
Spanify(XEP393_MONO);
|
Spanify(XEP393_MONO);
|
||||||
}
|
}
|
||||||
|
else if (sol && IdentifySpans('>', '\n', subview, &span_view))
|
||||||
|
{
|
||||||
|
/* TODO: This doesnt work with more than one line of quotes. */
|
||||||
|
Spanify(XEP393_QUOT);
|
||||||
|
}
|
||||||
else if (curr == '\n')
|
else if (curr == '\n')
|
||||||
{
|
{
|
||||||
/* TODO: Remove this */
|
/* TODO: Remove this */
|
||||||
|
|
@ -259,6 +270,10 @@ ShoveXML(XEP393Element *element, XMLElement *xmlparent)
|
||||||
case XEP393_NL:
|
case XEP393_NL:
|
||||||
XMLAddChild(xmlparent, XMLCreateTag("br"));
|
XMLAddChild(xmlparent, XMLCreateTag("br"));
|
||||||
break;
|
break;
|
||||||
|
case XEP393_QUOT:
|
||||||
|
head = XMLCreateTag("blockquote");
|
||||||
|
XMLAddChild(xmlparent, head);
|
||||||
|
break;
|
||||||
case XEP393_EMPH:
|
case XEP393_EMPH:
|
||||||
head = XMLCreateTag("strong");
|
head = XMLCreateTag("strong");
|
||||||
XMLAddChild(xmlparent, head);
|
XMLAddChild(xmlparent, head);
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ typedef enum XEP393Type {
|
||||||
XEP393_EMPH,
|
XEP393_EMPH,
|
||||||
XEP393_MONO,
|
XEP393_MONO,
|
||||||
XEP393_TEXT,
|
XEP393_TEXT,
|
||||||
|
XEP393_QUOT,
|
||||||
XEP393_NL
|
XEP393_NL
|
||||||
} XEP393Type;
|
} XEP393Type;
|
||||||
typedef struct XEP393Element {
|
typedef struct XEP393Element {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue