diff --git a/src/Routes/Root.c b/src/Routes/Root.c index fba70b9..1ebf14a 100644 --- a/src/Routes/Root.c +++ b/src/Routes/Root.c @@ -6,110 +6,184 @@ #include +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) { ParseeHttpArg *args = argp; const ParseeConfig *config = args->data->config; - const char *quote = RandInt(2) ? - "Kinda jealous of that, to be fair." : - "Why look inward when you can challenge the mainstream media?"; - char *mxid, *jid; - char *m_to; - - mxid = ParseeMXID(args->data); - m_to = ParseeGenerateMTO(mxid); - jid = ParseeJID(args->data); HttpResponseHeader(args->ctx, "Content-Type", "text/html"); HttpSendHeaders(args->ctx); #define P(...) StreamPrintf(args->stream, __VA_ARGS__) + P(""); P(""); - P(" "); - P(" %s Lander", NAME); - P(" "); - P(" "); - P(" "); - P("

"); - P(" Your %s is running!", NAME); - P("

"); - P("
"); - P("
"); - P(" %s", quote); - 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(" You may be interested in sending !help to "); - P(" the Matrix %s bridge, or pop out ", m_to, NAME); - P(" %s's command list on XMPP as a starter.", jid); - P("

"); - P("

"); - P(" More information available at "); - P(" the actual page."); - P("

"); - P("

Permissions?

"); - 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(" If you happen to have a build-from-source copy of %s,", NAME); - P(" please build all utilities and run "); - P(" tools/out/adminify '%s' '[glob]'.", config->db_path); - P("

"); + { + P(""); + { + P("%s Lander", NAME); + P(""); + } + P(""); - P("

Extra information

"); - P("

"); - P("

Dev documentations!!!!

"); - P(" Developers may be interested into looking up the "); - P(" at.kappach.at "); - P(" page for extensions used by Parsee on Matrix. "); - P("

"); - P("

"); - P("

Parsee statistics

"); - P("
");
-    P("Software: %s (v%s/Cyto %s)\n", NAME, VERSION, CytoplasmGetVersionStr());
-    P("Cytoplasm heap used: %d B\n", MemoryAllocated());
-    P("
"); - P("

"); - P("

"); - P(" Some clicky links relating to %s:", NAME); - P("

"); - P("

"); - P("
"); - P(" Good luck, and have fun! :D"); - P("
"); - P("

— LDA

"); - P(" "); + P(""); + { + P("

"); + P("Your %s is running!", NAME); + P("

"); + P("
"); + P("
"); + { + const char *quote = RandInt(2) ? + "Kinda jealous of that, to be fair." : + "Why look inward when you can challenge the mainstream " + "media?"; + P("%s", quote); + } + 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("

"); + { + char *mxid, *jid; + char *m_to; + + mxid = ParseeMXID(args->data); + m_to = ParseeGenerateMTO(mxid); + jid = ParseeJID(args->data); + + P("You may be interested in sending !help to "); + P("the Matrix %s bridge, or pop out ", m_to, NAME); + P("%s's command list on XMPP as a starter.", jid); + + Free(mxid); + Free(m_to); + Free(jid); + } + P("

"); + + P("

"); + { + P("More information available at "); + P("the actual page."); + } + P("

"); + + P("

Permissions?

"); + P("

"); + { + const char *perms = !HasAdmin(args->data) ? + " (which I know you do)" : + ""; + + 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("If you happen to have a build-from-source copy of %s, ", NAME); + P("please build all utilities and run "); + P("tools/out/adminify '%s' '[glob]'.", config->db_path); + } + P("

"); + + P("

Extra information

"); + P("

"); + { + P("

Dev documentations!!!!

"); + P("Developers may be interested into looking up the "); + P("at.kappach.at "); + P("page for extensions used by Parsee on Matrix. "); + } + P("

"); + + P("

Parsee statistics

"); + P("

"); + { + const char *cyto_ver = CytoplasmGetVersionStr(); + size_t alloc = MemoryAllocated(); + P("

");
+                P("Software: %s (v%s/Cyto %s)\n", NAME, VERSION, cyto_ver);
+                P("Cytoplasm heap used: %d B\n", alloc);
+                P("
"); + } + P("

"); + + P("

"); + { + P("Some clicky links relating to %s:", NAME); + P("

"); + } + P("

"); + + P("
"); + P("Good luck, and have fun! :D"); + P("
"); + P("

— LDA

"); + } + P(""); + } P(""); #undef P - Free(mxid); - Free(m_to); - Free(jid); - return NULL; } diff --git a/src/XEP-0393.c b/src/XEP-0393.c index 474af60..a16bf9b 100644 --- a/src/XEP-0393.c +++ b/src/XEP-0393.c @@ -98,10 +98,10 @@ CreateStaticView(char *str) return view; } static bool -IdentifySpan(char span_tag, StrView in, StrView *view) +IdentifySpans(char span_tag, char end_tag, StrView in, StrView *view) { size_t length; - bool found = false; + bool found = false, equal, flag; char prev = '\0'; if (in.start >= in.end) { @@ -112,7 +112,10 @@ IdentifySpan(char span_tag, StrView in, StrView *view) 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 * 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++) { - if (*in.start == span_tag) + if (*in.start == end_tag) { found = true; break; @@ -131,7 +134,7 @@ IdentifySpan(char span_tag, StrView in, StrView *view) prev = *in.start; } - if (!found || !length || (prev && isspace(prev))) + if (!found || !length || (prev && equal && isspace(prev))) { /* the closing styling directive MUST NOT be preceeded * by a whitespace character. */ @@ -141,6 +144,7 @@ IdentifySpan(char span_tag, StrView in, StrView *view) view->end = in.start; return true; } +#define IdentifySpan(span_tag, in, view) IdentifySpans(span_tag, span_tag, in, view) static void @@ -155,12 +159,14 @@ XEP393Decode(StrView view, XEP393Element *root) textview.end = subview.start; for (; subview.start < subview.end; subview.start++) { + bool sol = false; StrView span_view; managed = false; curr = *subview.start; if (prev == '\0' || prev == '\n') { /* TODO: Start of line, start parsing blocks. */ + sol = true; } #define Spanify(xep_symbol) \ managed = true; \ @@ -195,6 +201,11 @@ XEP393Decode(StrView view, XEP393Element *root) { 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') { /* TODO: Remove this */ @@ -259,6 +270,10 @@ ShoveXML(XEP393Element *element, XMLElement *xmlparent) case XEP393_NL: XMLAddChild(xmlparent, XMLCreateTag("br")); break; + case XEP393_QUOT: + head = XMLCreateTag("blockquote"); + XMLAddChild(xmlparent, head); + break; case XEP393_EMPH: head = XMLCreateTag("strong"); XMLAddChild(xmlparent, head); diff --git a/src/include/XEP393.h b/src/include/XEP393.h index 8c8bff8..68a9b67 100644 --- a/src/include/XEP393.h +++ b/src/include/XEP393.h @@ -9,6 +9,7 @@ typedef enum XEP393Type { XEP393_EMPH, XEP393_MONO, XEP393_TEXT, + XEP393_QUOT, XEP393_NL } XEP393Type; typedef struct XEP393Element {