This commit is contained in:
lda 2024-08-22 14:39:25 +02:00
commit 69d913d92b
8 changed files with 70 additions and 15 deletions

3
.gitignore vendored
View file

@ -12,3 +12,6 @@ tools/out/*
ayaya/* ayaya/*
ayaya ayaya
#ctags
tags

View file

@ -41,6 +41,8 @@ all: binary utils
binary: $(OBJ_FILES) binary: $(OBJ_FILES)
$(CC) $(LDFLAGS) $(OBJ_FILES) -o $(BINARY) $(CC) $(LDFLAGS) $(OBJ_FILES) -o $(BINARY)
tags:
@ctags --recurse $(SOURCE)/
clean: clean:
rm -rf $(OBJECT) $(BINARY) $(AYAS) rm -rf $(OBJECT) $(BINARY) $(AYAS)

View file

@ -11,6 +11,8 @@
#include <Matrix.h> #include <Matrix.h>
#include <AS.h> #include <AS.h>
#include <ctype.h>
static void static void
JoinMUC(ParseeData *data, HashMap *event, char *jid, char *muc, char *name) JoinMUC(ParseeData *data, HashMap *event, char *jid, char *muc, char *name)
{ {
@ -20,7 +22,7 @@ JoinMUC(ParseeData *data, HashMap *event, char *jid, char *muc, char *name)
char *rev = StrConcat(3, muc, "/", nick); char *rev = StrConcat(3, muc, "/", nick);
int nonce = 0; int nonce = 0;
while (!XMPPJoinMUC(data->jabber, jid, rev, true) && nonce < 20) while (!XMPPJoinMUC(data->jabber, jid, rev, true) && nonce < 32)
{ {
char *nonce_str = StrInt(nonce); char *nonce_str = StrInt(nonce);
char *input = StrConcat(4, sender, name, data->id, nonce_str); char *input = StrConcat(4, sender, name, data->id, nonce_str);
@ -122,10 +124,6 @@ ParseeMemberHandler(ParseeData *data, HashMap *event)
goto end; goto end;
} }
/* TODO: We need to deal with the nick properly, as XMPP
* requires us to provide it whenever we want to even think
* about leaving...
* I love how this is the last place victim of the dreaded [p]... */
name = StrDuplicate(ParseeLookupNick(muc_id, sender)); name = StrDuplicate(ParseeLookupNick(muc_id, sender));
rev = StrConcat(3, muc_id, "/", name); rev = StrConcat(3, muc_id, "/", name);

34
src/MatrixID.c Normal file
View file

@ -0,0 +1,34 @@
#include <Matrix.h>
#include <Cytoplasm/Memory.h>
#include <string.h>
UserID *
MatrixParseID(char *user)
{
UserID *ret = NULL;
char *localstart, *serverstart;
if (!user || *user != '@')
{
return NULL;
}
localstart = user + 1;
serverstart = strchr(user, ':');
if (!*localstart || !serverstart || localstart == serverstart)
{
return NULL;
}
if (!*++serverstart)
{
return NULL;
}
ret = Malloc(sizeof(*ret));
memset(ret, '\0', sizeof(*ret));
memcpy(ret->localpart, localstart, serverstart - localstart - 1);
memcpy(ret->server, serverstart, strlen(serverstart));
return ret;
}

View file

@ -10,32 +10,36 @@
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h> #include <ctype.h>
#include <Matrix.h>
bool bool
ParseeIsPuppet(const ParseeConfig *conf, char *user) ParseeIsPuppet(const ParseeConfig *conf, char *user)
{ {
char *localpart; UserID *id;
bool flag = true; bool flag = true;
size_t len; size_t len;
if (!user || !conf || *user != '@') if (!user ||
!conf ||
*user != '@' ||
!(id = MatrixParseID(user)))
{ {
return false; return false;
} }
localpart = user + 1;
len = strlen(conf->namespace_base); len = strlen(conf->namespace_base);
if (strncmp(localpart, conf->namespace_base, len)) if (strncmp(id->localpart, conf->namespace_base, len))
{ {
flag = false; flag = false;
} }
len = strlen(conf->sender_localpart); if (StrEquals(id->localpart, conf->sender_localpart))
if (!strncmp(localpart, conf->sender_localpart, len))
{ {
flag = true; flag = true;
} }
/* TODO: Check serverpart. 2 Parsee instances may be running in the same flag = flag && StrEquals(id->server, conf->server_base);
* room. */
Free(id);
return flag; return flag;
} }
char * char *

View file

@ -163,6 +163,7 @@ XMPPAuthenticateCompStream(XMPPComponent *comp, char *shared)
if (ev->type != XML_LEXER_ELEM || if (ev->type != XML_LEXER_ELEM ||
!StrEquals(ev->element, "handshake")) !StrEquals(ev->element, "handshake"))
{ {
Log(LOG_DEBUG, "type=%d elem='%s'", ev->type, ev->element);
Log(LOG_ERR, "Excepted empty handshake reply, got nonsense."); Log(LOG_ERR, "Excepted empty handshake reply, got nonsense.");
Log(LOG_ERR, "Another service (possibly Parsee) may have taken over."); Log(LOG_ERR, "Another service (possibly Parsee) may have taken over.");
Log(LOG_ERR, ""); Log(LOG_ERR, "");

View file

@ -162,7 +162,6 @@ end_error:
PEPManagerHandle(thr->info->pep_manager, stanza); PEPManagerHandle(thr->info->pep_manager, stanza);
/* TODO: Separate the chatstate processing code. */
ProcessChatstates(args, stanza); ProcessChatstates(args, stanza);
to = ParseeDecodeMXID(HashMapGet(stanza->attrs, "to")); to = ParseeDecodeMXID(HashMapGet(stanza->attrs, "to"));
@ -317,7 +316,6 @@ end_error:
reaction = ArrayGet(react_child, i); reaction = ArrayGet(react_child, i);
react_data = ArrayGet(reaction->children, 0); react_data = ArrayGet(reaction->children, 0);
/* TODO: We should manage removed reactions. */
Free(ASSend( Free(ASSend(
args->config, mroom_id, encoded, args->config, mroom_id, encoded,
"m.reaction", "m.reaction",

View file

@ -3,6 +3,21 @@
#include <Cytoplasm/Json.h> #include <Cytoplasm/Json.h>
/* A simple representation of everything. It is not as complex as
* Telodendria's CommonID parser, simply because Parsee does not
* need such complexity. */
typedef struct UserID {
/* We're being extra leinent. */
char localpart[256];
char server[256];
} UserID;
/** Parses a Matrix user ID, with no attention to detail.
* -----------
* Returns: a valid user ID[HEAP] | NULL
* Thrasher: Free */
extern UserID * MatrixParseID(char *user);
/* Creates an error message JSON, with the specified code and message. */ /* Creates an error message JSON, with the specified code and message. */
extern HashMap * MatrixCreateError(char *err, char *msg); extern HashMap * MatrixCreateError(char *err, char *msg);