From 1f3d738bb461f4e6265ca0dcbe5a7b058c6aaf5b Mon Sep 17 00:00:00 2001 From: LDA Date: Sat, 31 Aug 2024 13:16:58 +0200 Subject: [PATCH] [MOD] Import PNG media. --- .gitignore | 1 + Makefile | 18 ++++++++++++++---- README.MD | 32 +++++++++++++++++++------------- XEPS-TBD.TXT | 27 ++++++++++++++------------- etc/media/README | 5 +++++ etc/media/parsee_logo.png | Bin 0 -> 871 bytes src/AS/Media.c | 1 - src/Main.c | 5 +++-- src/Parsee/HMAC.c | 9 ++++++--- src/Routes/Media.c | 12 +++++++++--- src/Routes/Root.c | 16 +++++++++++++--- src/include/Parsee.h | 3 +++ 12 files changed, 87 insertions(+), 42 deletions(-) create mode 100644 etc/media/README create mode 100644 etc/media/parsee_logo.png diff --git a/.gitignore b/.gitignore index 7f1e762..f2c57e6 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ tags # Whitelists !etc/* +!etc/** diff --git a/Makefile b/Makefile index c76e361..8d71552 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,9 @@ # ================================ # TODO: Consider making something akin to a configure script that checks # for dependencies, or maybe even use *autoconf* (the devil!) +# +# TODO: Either get rid of the GNU extensions, or use a script/program +# to build Parsee on a POSIXly environment. I'd dig parsee-buildout, tbf. # =========================== Parsee Flags ============================= @@ -31,13 +34,13 @@ LDFLAGS=-L $(CYTO_LIB) -lCytoplasm -O3 -g AFLAGS=-C "$(ETC)/ayadoc/style.css" -p "$(NAME)" BINARY=parsee # ============================ Compilation ================================= -SRC_FILES:=$(shell find $(SOURCE) -name '*.c') -OBJ_FILES:=${subst $(SOURCE)/,$(OBJECT)/,$(patsubst %.c, %.o, $(SRC_FILES))} +SRC_FILES:=$(shell find $(SOURCE) -name '*.c') $(shell find $(ETC)/media -name '*.png') +OBJ_FILES:=${subst $(ETC)/media/,$(OBJECT)/,${subst $(SOURCE)/,$(OBJECT)/,$(patsubst %.png, %.o, $(patsubst %.c, %.o, $(SRC_FILES)))}} CPP_FILES:=$(shell find $(INCLUDES) -name '*.h') AYA_FILES:=${subst $(INCLUDES)/,$(AYAS)/,$(patsubst %.h, %.html, $(CPP_FILES))} -all: binary utils +all: utils binary binary: $(OBJ_FILES) $(CC) $(LDFLAGS) $(OBJ_FILES) -o $(BINARY) @@ -47,9 +50,16 @@ tags: $(SRC_FILES) clean: rm -rf $(OBJECT) $(BINARY) $(AYAS) +$(OBJECT)/%.o: $(ETC)/media/%.png + @mkdir -p $(shell dirname "$@") + @echo "const char media_$(shell basename $< .png)[] =" > $@.c + @base64 $< | \ + sed -e 's/^\(.*\)$$/ "\1"/' | \ + sed -e '$$ s/^\(.*\)$$/\1;/' >> $@.c + $(CC) -c $(CFLAGS) $@.c -o $@ $(OBJECT)/%.o: $(SOURCE)/%.c @mkdir -p $(shell dirname "$@") - $(CC) -c $(CFLAGS) $< -o $@ + $(CC) -c $(CFLAGS) $< -o $@ utils: (cd tools && make) diff --git a/README.MD b/README.MD index fa305db..51fcf7f 100644 --- a/README.MD +++ b/README.MD @@ -1,15 +1,16 @@ # Parsee - the jealous XMPP<=>Matrix bridge -Parsee is a Matrix<=>XMPP bridge written in C99, with Cytoplasm, similar to Bifrost, but it is NOT a drop-in replacment. +Parsee is a Matrix<=>XMPP bridge written in C99, with Cytoplasm, similar to Bifrost, but it is +NOT a drop-in replacment. ## Why? ### Naming -The name 'Parsee' is actually a reference to [Parsee Mizuhashi](https://en.touhouwiki.net/wiki/Parsee_Mizuhashi), a -"*bridge* princess". +The name 'Parsee' is actually a reference to [Parsee Mizuhashi](https://en.touhouwiki.net/wiki/Parsee_Mizuhashi), +a "*bridge* princess". ### Reasoning (personal to LDA) -I hate Bifrost. I also wanted to dip my toes in XMPP, XML, and bridges a bit. Also, as a sister project to KappaChat, -this means that I can integrate Parsee with KappaChat however I wish it to be, which allows me to mess around with a -codebase I'm already familiar with. +I hate Bifrost. I also wanted to dip my toes in XMPP, XML, and bridges a bit. Also, as a sister +project to KappaChat, this means that I can integrate Parsee with KappaChat however I wish it +to be, which allows me to mess around with a codebase I'm already familiar with. A more "up-to-date" reason may be to have a small, 'Just Werks' bridging solution *that is good*. Well, I'm *trying* to do that, at least. @@ -31,10 +32,13 @@ $ make ayadoc # If you want to build HTML documentation $ make [PREFIX=(install path)] install # To install Parsee. ``` If there are any Cytoplasm-related build failures, you may want to check the Makefile to -change a few variables (you can set `CYTO_INC` and `CYTO_LIB`) +change a few variables (you can set `CYTO_INC` and `CYTO_LIB` for Cytoplasm's include and +library paths specifically.) ### DEPENDENCIES -Parsee tries to avoid dependencies aside from [Cytoplasm](https://git.telodendria.io/Telodendria/Cytoplasm). Itself optionally depends on a good POSIX implementation, and optionally OpenSSL/LMDB (highly recommended, but you can get away without those). +Parsee tries to avoid dependencies aside from [Cytoplasm](https://git.telodendria.io/Telodendria/Cytoplasm). +Itself optionally depends on a good POSIX implementation, and optionally OpenSSL/LMDB (highly recommended, but +you can get away without those if you're adventurous). ## RUNNING First off, you may want to configure Parsee by running the `config` tool(generally named @@ -62,19 +66,20 @@ returns with a landing page, then this side works. You can read it for some more Currently, the main sources of documentation are the Ayadocs(for headers) and the manpages (see `etc/man`) -## TODOS -- Add [libomemo](https://github.com/gkdr/libomemo) as an optional dependency. +## TODOS before 1.0 rolls around +- Add [libomemo](https://github.com/gkdr/libomemo) or something as an optional dependency. - It depends on more stuff anyways, and I don't want to weigh down the dependency list of Parsee for that. - Matrix's libolm is deprecated. They replaced it with a Rust version that pulls in *way too many* dependencies, and that lacks a C binding. We may put in the work of either forking off libolm or making a binding to KappaChat. + - Josh did infact tell me that maybe C bindings may happen. I'd be + willing to help out, but IDK. In any case, this will at best be an + extension packagers may integrate properly. - Get rid of the '?'-syntax and use another invalid Matrix char/valid XMPP char ('$'?) for escaped? - PROPER FUCKING AVATARS - XEP-0084 IS THE WORST PIECE OF SHIT KNOWN TO MAN. If any Jabberbros want to - look at terrible code/XML and suggest things to have *proper* avatar support, - I'm all in. + XMPP->Matrix is decent, Matrix->XMPP is effectiveny not done - Consider making room/MUC admins/owners be able to plumb instead of it being restricted to Parsee admins, with permission from MUC owners, too - Limiting to admins may be a way to "control" consent for both, but this is @@ -85,6 +90,7 @@ restricted to Parsee admins, with permission from MUC owners, too support XMPP->Matrix bridging. - Manage MUC DMs in a reasonable manner. Thanks `@freeoffers4u:matrix.org` for being a fucking annoyance and DMing an old Parsee semi-anon user for no clear reason. +- Deadlocks. It's always deadlocks. ## DONATING/CONTRIBUTING If you know things about XMPP or Matrix, yet aren't familiar with C99, or just diff --git a/XEPS-TBD.TXT b/XEPS-TBD.TXT index 02a68ca..ae74f4f 100644 --- a/XEPS-TBD.TXT +++ b/XEPS-TBD.TXT @@ -1,6 +1,19 @@ XEPs current supported are in src/XMPPThread, at the IQ disco advertising. Somewhat implemented XEPs: + v https://xmpp.org/extensions/xep-0050.html + Ad-hoc commands that bridge maintainers can deal with XMPP-style are + also a nice to have. + There are commands, but not a lot of them as of now, and localisation + is missing. + v https://xmpp.org/extensions/xep-0421.html + Using the occupant ID in semi-anonymous MUCs is a desirable property. + I dont know of a lot of places that don't use the occupant ID anymore + within Parsee. + v "also it [Bifrost] doesn't respect voice either" + As far as I am aware, works. + v https://xmpp.org/extensions/xep-0425.html + As mentionned in #2, moderation _needs_ to be done. ~ https://xmpp.org/extensions/xep-0085.html Only XMPP->Matrix at the moment. Still need to figure out how to get typing indicators as an AS. @@ -12,17 +25,6 @@ Somewhat implemented XEPs: ~ https://xmpp.org/extensions/xep-0184.html Only Matrix->XMPP as of now. Requesting data from Matrix ASes without /sync seems like a non-option as of now, which _sucks_. - ~ https://xmpp.org/extensions/xep-0050.html - Ad-hoc commands that bridge maintainers can deal with XMPP-style are - also a nice to have. - There are commands, but not a lot of them as of now, and localisation - is missing. - ~ https://xmpp.org/extensions/xep-0421.html - Using the occupant ID in semi-anonymous MUCs is a desirable property. - I dont know of a lot of places that don't use the occupant ID anymore - within Parsee. - ~ https://xmpp.org/extensions/xep-0425.html - As mentionned in #2, moderation _needs_ to be done. For future XEPs: - https://xmpp.org/extensions/xep-0449.html @@ -44,9 +46,8 @@ THESE I WANT TO SEND THEM A NICE, BRIGHT GIFT: Not XEPs, but ideas that _needs_ to be added: - v "also it [Bifrost] doesn't respect voice either" -> Send a form on moderated - MUCs (which is standard, so its not too bad!). Currently WIP, and barely tested. ~ "GIVE THE PUPPETS APPROPRIATE PLS/ROLES" - Hydro/t4d + Happens on Matrix. I'll need to handle that on XMPP as well. - Standalone/Static Parsee, ideally as small as it can be(if not as APE). - Kappa-like extension system(maybe bridging more than just Matrix-XMPP.) - https://www.youtube.com/watch?v=InL414iDZmY diff --git a/etc/media/README b/etc/media/README new file mode 100644 index 0000000..2ef7300 --- /dev/null +++ b/etc/media/README @@ -0,0 +1,5 @@ +This directory is for any PNG media that needs to be integrated into Parsee. +Each file here is Base64-encoded then defined as a const char[] symbol with +the name being a function of the PNG filename: N(FILE.png)=media_FILE + +NOTE: Medias should be about ~1024B MAX. Avoid to stride for anything larger. diff --git a/etc/media/parsee_logo.png b/etc/media/parsee_logo.png new file mode 100644 index 0000000000000000000000000000000000000000..1e0a8a1006e6cbf38662bf856d085c0c7baa15d3 GIT binary patch literal 871 zcmV-t1DO1YP)Px#U{Fj{MF0Q*A|NzHC_H94F^^U|W;`W3Bn?$50Q>Sb4^=&CzAzO#EK6xGQcEN< zJUKrX zreR|42KR?6M<<&Gn>et30on5YvL>0)t3*20G8y@)CdvboNI8&)Wge0+Lq)y|=3YU|doQfbjS9p68OTHW(Le@6h^^za5Z-TCDArax$yNdIRFPUGFUY|K+wdH>Gnuk1z^T%)pP+x z_V}1;EkG&ar4QiUO6vd=vR;qkb#3oH0^sSdGvF*e0(1`dw7&yfdVtG6;7N>z)433aaj)9^@7?W@j?S<0W3D;-$z~CZk0&Wl{6G1Z*sU0Kv$|P)v^+KGNIiZ xZf_0)w7Dfdxw%OZOTDZeEQfMB`CRpCzX9ghe&NM6@>~D_002ovPDHLkV1mPkhwlIY literal 0 HcmV?d00001 diff --git a/src/AS/Media.c b/src/AS/Media.c index 31c7231..4e642e9 100644 --- a/src/AS/Media.c +++ b/src/AS/Media.c @@ -19,7 +19,6 @@ ASUpload(const ParseeConfig *c, Stream *from, unsigned int size, char *mime) HashMap *reply; if (!c || !from) { - Log(LOG_ERR, "No ASUpload input (c=%p from=%p)", c, from); return NULL; } diff --git a/src/Main.c b/src/Main.c index fd599ba..e99e627 100644 --- a/src/Main.c +++ b/src/Main.c @@ -224,8 +224,9 @@ Main(Array *args, HashMap *env) } Log(LOG_NOTICE, "Starting up local cronjobs..."); - cron = CronCreate( 10 SECONDS ); - CronEvery(cron, 5 MINUTES, ParseeCleanup, conf.handlerArgs); + cron = CronCreate( 30 MINUTES ); + CronEvery(cron, 1 HOURS, ParseeCleanup, conf.handlerArgs); + ParseeCleanup(conf.handlerArgs); CronStart(cron); diff --git a/src/Parsee/HMAC.c b/src/Parsee/HMAC.c index efdd09a..abb65ef 100644 --- a/src/Parsee/HMAC.c +++ b/src/Parsee/HMAC.c @@ -13,6 +13,7 @@ ComputeKPad(char *key, uint8_t pad, uint8_t *kopad) { size_t klen; uint8_t *kp; + uint8_t kpi[64] = { 0 }; size_t i; if ((klen = strlen(key)) <= 64) { @@ -25,14 +26,16 @@ ComputeKPad(char *key, uint8_t pad, uint8_t *kopad) klen = 32; } + memset(kpi, 0x00, 64); + memcpy(kpi, kp, klen); + Free(kp); + /* Now that we have K', lets compute it XORd with opad */ for (i = 0; i < 64; i++) { - uint8_t byte = i < klen ? kp[i] : 0x00; + uint8_t byte = kpi[i]; kopad[i] = byte ^ pad; } - - Free(kp); } char * diff --git a/src/Routes/Media.c b/src/Routes/Media.c index 137ef0f..7d6bc68 100644 --- a/src/Routes/Media.c +++ b/src/Routes/Media.c @@ -23,8 +23,8 @@ RouteHead(RouteMedia, arr, argp) params = HttpRequestParams(args->ctx); hmac = HashMapGet(params, "hmac"); - /* TODO: Make it check the DB for its validicity. "Purging" would be useful. - */ + /* TODO: Make it check the DB for its validicity. "Purging" would be + * useful, alongside checking if someone isn't just a little idiotic. */ { char *concat = StrConcat(3, server, "/", identi); chkmak = ParseeHMACS(args->data->id, concat); @@ -32,12 +32,18 @@ RouteHead(RouteMedia, arr, argp) } if (!server || !identi || !hmac || !StrEquals(hmac, chkmak)) { + char *err = + hmac && StrEquals(hmac, chkmak) ? + "No server/identifier/HMAC code" : + "Hah! You _dirty_ little liar! Try a little harder!"; Free(chkmak); HttpResponseStatus(args->ctx, HTTP_BAD_REQUEST); - return MatrixCreateError("M_NOT_YET_UPLOADED", "No server/identifier"); + return MatrixCreateError("M_NOT_YET_UPLOADED", err); } Free(chkmak); + /* Proxy the media through an authenticated endpoint if the HMAC + * is valid. */ server = HttpUrlEncode(server); identi = HttpUrlEncode(identi); path = StrConcat(4, "/_matrix/media/v3/download/", server, "/", identi); diff --git a/src/Routes/Root.c b/src/Routes/Root.c index 831d4b0..af89909 100644 --- a/src/Routes/Root.c +++ b/src/Routes/Root.c @@ -76,6 +76,7 @@ RouteHead(RouteRoot, arr, argp) { P("%s Lander", NAME); P(""); + P("", media_parsee_logo); P("