From 7e848f1e72a3717ae524d912e370c207b0e79c57 Mon Sep 17 00:00:00 2001 From: onefang Date: Sat, 4 Jun 2022 09:49:14 +1000 Subject: Add experimental XMPP chat stuff. --- src/sledjchisl/sledjchisl.c | 263 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 236 insertions(+), 27 deletions(-) diff --git a/src/sledjchisl/sledjchisl.c b/src/sledjchisl/sledjchisl.c index 317d079..4f91fae 100644 --- a/src/sledjchisl/sledjchisl.c +++ b/src/sledjchisl/sledjchisl.c @@ -140,6 +140,9 @@ extern char **environ; #include "lib/fcgi_SC.h" #include "lib/handlekeys.h" +#include "lib/json.h" +#include "lib/json-builder.h" + // Both my_config.h and fcgi_config.h define the same PACKAGE* variables, which we don't use anyway, // I deal with that by using a sed invokation when building fcgi2. @@ -518,7 +521,7 @@ static void showSesh(qgrow_t *reply, sesh *shs) } -char toybuf[4096]; +//char toybuf[4096]; lua_State *L; qhashtbl_t *configs; MYSQL *database, *dbconn; @@ -548,6 +551,7 @@ int startPort = 8002; char *backupIARsim = "Sandbox"; char *rSync = ""; int rSyncPort = 0; +char *webHost = "localhost"; char *webRoot = "/var/www/html"; char *webSocket = "sledjchisl.socket"; char *ToS = "Be good."; @@ -808,6 +812,87 @@ char *myHMACkey(char *key, char *in, boolean b64) } +static void print_depth_shift(int depth) +{ + int j; + for (j=0; j < depth; j++) { + printf(" "); + } +} +static void process_value(json_value* value, int depth); +static void process_object(json_value* value, int depth) +{ + int length, x; + if (value == NULL) { + return; + } + length = value->u.object.length; + for (x = 0; x < length; x++) { + print_depth_shift(depth); + printf("object[%d].name = %s\n", x, value->u.object.values[x].name); + process_value(value->u.object.values[x].value, depth+1); + } +} +static void process_array(json_value* value, int depth) +{ + int length, x; + if (value == NULL) { + return; + } + length = value->u.array.length; + printf("array\n"); + for (x = 0; x < length; x++) { + process_value(value->u.array.values[x], depth); + } +} +static void process_value(json_value* value, int depth) +{ + if (value == NULL) { + return; + } + if (value->type != json_object) { + print_depth_shift(depth); + } + switch (value->type) { + case json_none: + printf("none\n"); + break; + case json_null: + printf("null\n"); + break; + case json_object: + process_object(value, depth+1); + break; + case json_array: + process_array(value, depth+1); + break; + case json_integer: + printf("int: %10ld\n", (long)value->u.integer); + break; + case json_double: + printf("double: %f\n", value->u.dbl); + break; + case json_string: + printf("string: %s\n", value->u.string.ptr); + break; + case json_boolean: + printf("bool: %d\n", value->u.boolean); + break; + } +} +void PrintJSON(json_char* json) +{ + json_value* value = json_parse(json, strlen((char *) json)); + + if (value == NULL) + { + E("Unable to parse data! - %s", (char *) json); + return; + } + process_value(value, 0); + json_value_free(value); +} + // In Lua 5.0 reference manual is a table traversal example at page 29. void PrintTable(lua_State *L) { @@ -4626,8 +4711,17 @@ static void HTMLheader(qgrow_t *reply, char *title) "
\n" "This account manager system is currently experimental, and under heavy development. " @@ -4994,16 +5088,48 @@ static void HTMLfooter(qgrow_t *reply) "
You will then be logged off. Now you have to wait for an admin to approve your new account. " " They should check with the person you listed as vouching for you first. They will tell you after they approve your account.
" "Missing bits that are still being written - editing accounts, listing accounts, deleting accounts.
\n" + "In the bottom right corner is an experimental chat thingy, based on Jabber / XMPP.
\n" + "Click on the 'Toggle chat' button to pop it up, then use your grid user name for the 'XMPP Address:' field. " + " Your user name has to be in the format 'first.last', two words with a dot in the middle. " + " Then put your grid account password in the 'Password' field and click the 'Log in' button. " + " Ignore the 'Don't have a chat account? Create an account' bit.
\n" + "Note that the chat windows can be resized by dragging their top or left edges, which I suggest you do, coz the default size is too small.
\n" + "You can also use any other Jabber / XMPP client as well.
\n" + "Remember this is EXPERIMENTAL, I'll be changing things. Next I'll make it so you don't have to log in to both this chat thingy and the account page separataly.
" + "
P.S. Yes, I hate the default theme to. lol
\n" "