[MOD] Use server_base instead of the API host

This wasn't an issue because the server I test on has the same API host
as its name.
This commit is contained in:
LDA 2024-07-26 17:13:02 +02:00
commit dd180ee3f4
10 changed files with 29 additions and 28 deletions

View file

@ -130,7 +130,7 @@ ASInvite(const ParseeConfig *conf, char *id, char *invited)
bridge = StrConcat(4,
"@", conf->sender_localpart,
":", conf->homeserver_host
":", conf->server_base
);
path = StrConcat(5,
"/_matrix/client/v3/rooms/", id, "/invite",
@ -165,7 +165,7 @@ ASBan(const ParseeConfig *conf, char *id, char *banned)
bridge = StrConcat(4,
"@", conf->sender_localpart,
":", conf->homeserver_host
":", conf->server_base
);
path = StrConcat(5,
"/_matrix/client/v3/rooms/", id, "/ban",
@ -200,7 +200,7 @@ ASKick(const ParseeConfig *conf, char *id, char *banned)
bridge = StrConcat(4,
"@", conf->sender_localpart,
":", conf->homeserver_host
":", conf->server_base
);
path = StrConcat(5,
"/_matrix/client/v3/rooms/", id, "/kick",
@ -237,7 +237,7 @@ ASJoin(const ParseeConfig *conf, char *id, char *masquerade)
{
char *raw = StrConcat(4,
"@", conf->sender_localpart,
":", conf->homeserver_host
":", conf->server_base
);
masquerade = HttpUrlEncode(raw);
Free(raw);
@ -287,7 +287,7 @@ ASLeave(const ParseeConfig *conf, char *id, char *masquerade)
{
char *raw = StrConcat(4,
"@", conf->sender_localpart,
":", conf->homeserver_host
":", conf->server_base
);
masquerade = HttpUrlEncode(raw);
Free(raw);
@ -540,7 +540,7 @@ ASFind(const ParseeConfig *c, char *room, char *event)
return NULL;
}
user = StrConcat(4, "@", c->sender_localpart, ":", c->homeserver_host);
user = StrConcat(4, "@", c->sender_localpart, ":", c->server_base);
path = StrConcat(7,
"/_matrix/client/v3/rooms/",
room, "/event/", event, "?",
@ -665,7 +665,7 @@ ASSetPL(const ParseeConfig *conf, char *id, HashMap *m)
}
user = StrConcat(4,
"@",conf->sender_localpart,
":",conf->homeserver_host
":",conf->server_base
);
ASSetState(conf, id, "m.room.power_levels", "", user, m);
Free(user);
@ -684,7 +684,7 @@ ASUpload(const ParseeConfig *c, Stream *from, unsigned int size, char *mime)
}
size_str = StrInt(size);
user = StrConcat(4, "@",c->sender_localpart,":",c->homeserver_host);
user = StrConcat(4, "@",c->sender_localpart,":",c->server_base);
path = StrConcat(2,
"/_matrix/media/v3/upload?user_id=", user
);
@ -866,7 +866,7 @@ ASGetUserConfig(const ParseeConfig *c, char *user, char *key)
{
char *raw = StrConcat(4,
"@", c->sender_localpart,
":", c->homeserver_host
":", c->server_base
);
user = HttpUrlEncode(raw);
Free(raw);
@ -909,7 +909,7 @@ ASSetUserConfig(const ParseeConfig *c, char *user, char *key, HashMap *map)
{
char *raw = StrConcat(4,
"@", c->sender_localpart,
":", c->homeserver_host
":", c->server_base
);
user = HttpUrlEncode(raw);
Free(raw);
@ -951,7 +951,7 @@ ASRedact(const ParseeConfig *c, char *room, char *user, char *e_id)
{
char *raw = StrConcat(4,
"@", c->sender_localpart,
":", c->homeserver_host
":", c->server_base
);
user = HttpUrlEncode(raw);
Free(raw);

View file

@ -104,10 +104,7 @@ ParseeBotHandler(ParseeData *data, HashMap *event)
char *body = GrabString(event, 2, "content", "body");
char *id = GrabString(event, 1, "room_id");
char *sender = GrabString(event, 1, "sender");
char *profile = StrConcat(4,
"@", data->config->sender_localpart,
":", data->config->homeserver_host
);
char *profile = ParseeMXID(data);
Command *cmd = NULL;
ParseeCmdArg arg = {
.data = data,

View file

@ -181,6 +181,10 @@ ParseeConfigInit(void)
"Base media URL for bridged media",
NULL
);
/* TODO: Make that configurable. */
config->server_base = StrDuplicate(config->homeserver_host);
Log(LOG_NOTICE, "Done! Please look over to the parsee.yaml file, ");
Log(LOG_NOTICE, "and follow the instructions listed in it. Then, ");
Log(LOG_NOTICE, "restart Parsee. ");
@ -196,6 +200,7 @@ ParseeConfigInit(void)
HashMapSet(json, "listen_as", JsonValueString(config->listen_as));
HashMapSet(json, "port", JsonValueInteger(config->port));
HashMapSet(json, "hs_base", JsonValueString(config->server_base));
HashMapSet(json, "hs_host", JsonValueString(config->homeserver_host));
HashMapSet(json, "hs_port", JsonValueInteger(config->homeserver_port));
@ -239,6 +244,7 @@ ParseeConfigLoad(char *conf)
CopyToStr(listen_as, "listen_as");
CopyToInt(port, "port");
CopyToStr(server_base, "hs_base");
CopyToStr(homeserver_host, "hs_host");
CopyToInt(homeserver_port, "hs_port");
@ -296,6 +302,7 @@ ParseeConfigFree(void)
Free(config->as_token);
Free(config->hs_token);
Free(config->server_base);
Free(config->sender_localpart);
Free(config->namespace_base);
Free(config->media_base);

View file

@ -180,7 +180,7 @@ ParseeEncodeJID(const ParseeConfig *c, char *jid, bool trim)
Free(tmp);
}
tmp = ret;
ret = StrConcat(4, "@", ret, ":", c->homeserver_host);
ret = StrConcat(4, "@", ret, ":", c->server_base);
Free(tmp);
return ret;
@ -754,5 +754,5 @@ char *
ParseeMXID(ParseeData *data)
{
return StrConcat(4, "@", data->config->sender_localpart,
":", data->config->homeserver_host);
":", data->config->server_base);
}

View file

@ -97,11 +97,8 @@ RouteHead(RouteRoomAck, arr, argp)
);
goto end;
}
creator = StrConcat(
4,
"@", args->data->config->sender_localpart, ":",
args->data->config->homeserver_host
);
creator = ParseeMXID(args->data);
id = ASCreateRoom(
args->data->config,
creator, room

View file

@ -208,7 +208,7 @@ XEP393Decode(StrView view, XEP393Element *root)
span_view.end = subview.start;
Spanify(XEP393_NL);
}
else if (IdentifySpans('>', '\n', subview, &span_view))
else if (sol && IdentifySpans('>', '\n', subview, &span_view))
{
/* TODO: This doesnt work with more than one line of quotes. */
Spanify(XEP393_QUOT);

View file

@ -184,7 +184,7 @@ ScrambleOID(ParseeData *data, char *opaque_oid)
mxid = StrConcat(
6,
"@", c->namespace_base, "_l_", sha, ":",
c->homeserver_host
c->server_base
);
Free(sha);
return mxid;

View file

@ -9,10 +9,7 @@
#include <Parsee.h>
#define BotInitialise() char *profile = StrConcat(4, \
"@", data->config->sender_localpart, \
":", data->config->homeserver_host \
); \
#define BotInitialise() char *profile = ParseeMXID(data); \
char *id = GrabString(event, 1, "room_id")
#define BotRequired(prop) prop = HashMapGet(cmd->arguments, #prop); \

View file

@ -19,6 +19,7 @@ typedef struct ParseeConfig {
char *sender_localpart;
char *namespace_base;
char *server_base;
char *listen_as;
char *media_base;
int port;

View file

@ -32,4 +32,6 @@ extern size_t StrLines(char **split);
/* Creates a full zone covering every part of the split */
extern StringRect StrFullRect(char **split);
extern char Str
#endif