[MOD] Change media path, connect to component through another address

This commit is contained in:
lda 2025-01-06 17:09:36 +00:00
commit 5e1931a19f
9 changed files with 30 additions and 9 deletions

View file

@ -18,8 +18,7 @@ A more "up-to-date" reason may be to have a small, 'Just Werks' bridging solutio
and maybe as a testing ground for Cytoplasm features I sometimes add.
(Well, I'm *trying* to do that, at least.
Please scream at me if that fails(or just doesn't run on a overclocked Raspberry
Pi 4B, which, by the way, is literally where Parsee+XMPP is running for now.))
Please scream at me if that fails(or just doesn't run on a overclocked Raspberry Pi 4B))
### "Why not just use Matrix lol"
### "Why not just use XMPP lol"

View file

@ -73,7 +73,7 @@ ParseeCreateRequest(const ParseeConfig *conf, HttpRequestMethod meth, char *path
ctx = HttpRequest(
meth,
HTTP_FLAG_TLS,
conf->homeserver_tls ? HTTP_FLAG_TLS : HTTP_FLAG_NONE,
conf->homeserver_port, conf->homeserver_host,
path
);

View file

@ -223,9 +223,11 @@ Main(Array *args, HashMap *env)
Log(LOG_NOTICE, "Connecting to XMPP...");
jabber = XMPPInitialiseCompStream(
parsee_conf->component_addr,
parsee_conf->component_host,
parsee_conf->component_port
);
Log(LOG_NOTICE, "Connecting to XMPP... %p", jabber);
if (!XMPPAuthenticateCompStream(
jabber,
parsee_conf->shared_comp_secret
@ -290,7 +292,6 @@ Main(Array *args, HashMap *env)
{
char *parsee = ParseeMXID(conf.handlerArgs);
/* TODO: An hardcoded avatar like this sucks. */
ASSetAvatar(parsee_conf,
parsee,
"mxc://tedomum.net/"

View file

@ -44,6 +44,9 @@ ParseeConfigLoad(char *conf)
#define CopyToInt(to, str) config->to = (int) ( \
JsonValueAsInteger(HashMapGet(json, str)) \
)
#define CopyToBool(to, str) config->to = (int) ( \
JsonValueAsBoolean(HashMapGet(json, str)) \
)
config->http_threads = 8;
config->xmpp_threads = 8;
@ -58,8 +61,14 @@ ParseeConfigLoad(char *conf)
CopyToStr(server_base, "hs_base");
CopyToStr(homeserver_host, "hs_host");
CopyToInt(homeserver_port, "hs_port");
CopyToBool(homeserver_tls, "hs_tls");
if (!HashMapGet(json, "hs_tls"))
{
config->homeserver_tls = true;
}
CopyToInt(component_port, "component_port");
CopyToStr(component_addr, "component_addr");
CopyToStr(component_host, "component_host");
CopyToStr(shared_comp_secret, "shared_secret");
CopyToInt(max_stanza_size, "max_stanza_size");
@ -129,6 +138,7 @@ ParseeConfigFree(void)
return;
}
Free(config->component_host);
Free(config->component_addr);
Free(config->shared_comp_secret);
Free(config->db_path);
Free(config->homeserver_host);

View file

@ -692,7 +692,7 @@ ParseeToUnauth(ParseeData *data, char *mxc)
Uri *url = NULL;
char *ret;
char *key, *hmac;
#define PAT "%s/_matrix/client/v1/media/download/%s%s?hmac=%s"
#define PAT "%s/media/%s%s?hmac=%s"
size_t l;
if (!data || !mxc)
{

View file

@ -19,7 +19,7 @@
#define DEFAULT_PROSODY_PORT 5347
XMPPComponent *
XMPPInitialiseCompStream(char *host, int port)
XMPPInitialiseCompStream(char *addr, char *host, int port)
{
int sd = -1;
struct addrinfo hints, *res, *res0;
@ -28,12 +28,17 @@ XMPPInitialiseCompStream(char *host, int port)
Stream *stream;
XMPPComponent *comp;
if (!addr)
{
addr = host;
}
snprintf(serv, sizeof(serv), "%hu", port ? port : DEFAULT_PROSODY_PORT);
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
error = getaddrinfo(host, serv, &hints, &res0);
error = getaddrinfo(addr, serv, &hints, &res0);
if (error)
{
const char *error_str = gai_strerror(error);
@ -66,6 +71,10 @@ XMPPInitialiseCompStream(char *host, int port)
if (sd < 0)
{
Log(LOG_ERR,
"%s: cannot connect to '%s': no socket available", __func__,
host
);
return NULL;
}
freeaddrinfo(res0);

View file

@ -41,9 +41,11 @@ typedef struct ParseeConfig {
/* Homeserver port info */
char *homeserver_host;
int homeserver_port;
int homeserver_tls;
/* ------- JABBER -------- */
char *component_addr;
char *component_host;
char *shared_comp_secret;
int component_port;

View file

@ -75,7 +75,7 @@ typedef struct ParseeCmdArg {
X_ROUTE("/_matrix/app/v1/users/(.*)", RouteUserAck) \
X_ROUTE("/_matrix/app/v1/rooms/(.*)", RouteRoomAck) \
X_ROUTE("/_matrix/app/v1/ping", RoutePing) \
X_ROUTE("/_matrix/client/v1/media/download/(.*)/(.*)", RouteMedia)
X_ROUTE("/media/(.*)/(.*)", RouteMedia)
#define X_ROUTE(path, name) extern void * name(Array *, void *);
ROUTES

View file

@ -22,7 +22,7 @@ typedef struct XMPPComponent {
/* Initialises a raw component stream to host, with an optional port.
* If said port is 0, then it is set to the default Prosody port */
extern XMPPComponent * XMPPInitialiseCompStream(char *host, int port);
extern XMPPComponent * XMPPInitialiseCompStream(char *addr, char *host, int port);
/* Authenticates a component stream with a given shared secret,
* with a stream ID from the server. This should be called right