forked from Telodendria/Telodendria
[FIX] Fix the user ID parser to actually work
This commit is contained in:
parent
30679d7999
commit
4e7554d241
1 changed files with 47 additions and 12 deletions
57
src/Parser.c
57
src/Parser.c
|
@ -25,14 +25,49 @@
|
|||
#include <Parser.h>
|
||||
|
||||
#include <Cytoplasm/Str.h>
|
||||
#include <Cytoplasm/Memory.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
/* Parse an extended localpart */
|
||||
static int
|
||||
ParseUserLocalpart(char **str, char **out)
|
||||
{
|
||||
char c;
|
||||
char *start;
|
||||
size_t length;
|
||||
|
||||
if (!str || !out)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
/* An extended localpart contains every ASCII printable character,
|
||||
* except an ':'. */
|
||||
start = *str;
|
||||
while (isascii((c = (*(*str)++))) && c != ':' && c)
|
||||
{
|
||||
/* Do nothing */
|
||||
}
|
||||
length = (size_t) (*str - start) -1;
|
||||
if (c != ':' || length < 1)
|
||||
{
|
||||
*str = start;
|
||||
return 0;
|
||||
}
|
||||
|
||||
*out = Malloc(length + 1);
|
||||
memcpy(*out, start, length);
|
||||
*out[length] = '\0';
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
ParseCommonID(char *str, CommonID *id)
|
||||
{
|
||||
char sigil;
|
||||
char *servstart;
|
||||
|
||||
if (!str || !id)
|
||||
{
|
||||
|
@ -55,16 +90,16 @@ ParseCommonID(char *str, CommonID *id)
|
|||
}
|
||||
id->sigil = sigil;
|
||||
|
||||
/* Find the position of a ':' if there is one. */
|
||||
if ((servstart = strchr(str, ':')))
|
||||
switch(sigil)
|
||||
{
|
||||
id->local = StrSubstr(str, 1, (char) (servstart - str));
|
||||
id->server = StrDuplicate(servstart + 1);
|
||||
return 1;
|
||||
}
|
||||
/* Otherwise, just take the rest of the string. */
|
||||
id->local = StrDuplicate(str + 1) ;
|
||||
id->server = NULL ;
|
||||
|
||||
case '@':
|
||||
if (!ParseUserLocalpart(&str, &id->local))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
/* TODO: Match whenever str is valid. */
|
||||
id->server = StrDuplicate(str);
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue