[ADD] Add basic Matrix ID parser

This commit is contained in:
LDA 2024-08-22 00:04:50 +02:00
commit 8042ccc0cc
8 changed files with 70 additions and 15 deletions

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;
}