Merge branch 'master' of https://git.lain.church/emil/probotic
This commit is contained in:
commit
2e063532a9
4
build.sh
4
build.sh
@ -1,4 +1,4 @@
|
|||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
# Script handling unity builds and options.
|
# Script handling unity builds and options.
|
||||||
|
|
||||||
DIR=$(dirname $(readlink -f "$0"))
|
DIR=$(dirname $(readlink -f "$0"))
|
||||||
@ -26,5 +26,5 @@ fi
|
|||||||
[ ! -z ${SAN} ] && CFLAGS=`echo "$CFLAGS -fsanitize=$SAN"`
|
[ ! -z ${SAN} ] && CFLAGS=`echo "$CFLAGS -fsanitize=$SAN"`
|
||||||
|
|
||||||
echo "$CC $CFLAGS -pipe $DIR/src/unity.c -o $PREFIX/$PROGN $CPPFLAGS $LDFLAGS"
|
echo "$CC $CFLAGS -pipe $DIR/src/unity.c -o $PREFIX/$PROGN $CPPFLAGS $LDFLAGS"
|
||||||
$CC $CFLAGS -pipe $DIR/src/unity.c -o $PREFIX/$PROGN $CPPFLAGS $LDFLAGS
|
time $CC $CFLAGS -pipe $DIR/src/unity.c -o $PREFIX/$PROGN $CPPFLAGS $LDFLAGS
|
||||||
echo -e "\nStatus: $?"
|
echo -e "\nStatus: $?"
|
||||||
|
@ -13,10 +13,12 @@ typedef struct
|
|||||||
|
|
||||||
VARDECL creds_t creds;
|
VARDECL creds_t creds;
|
||||||
|
|
||||||
DECL char * dump(void);
|
DECL char ** str_split(char const * s, char c);
|
||||||
DECL char * raw(char const * const sql);
|
DECL void split_clean(char ** split);
|
||||||
DECL char * remind(char * who);
|
DECL char * dump(void);
|
||||||
DECL char * slurp(char const * fn);
|
DECL char * raw(char const * const sql);
|
||||||
|
DECL char * remind(char * who);
|
||||||
|
DECL char * slurp(char const * fn);
|
||||||
DECL int is_admin(char const * user);
|
DECL int is_admin(char const * user);
|
||||||
DECL void parse_admins(char * admin_string);
|
DECL void parse_admins(char * admin_string);
|
||||||
DECL int parse_pair(char const * buf, size_t const len);
|
DECL int parse_pair(char const * buf, size_t const len);
|
||||||
|
65
src/parse.c
65
src/parse.c
@ -52,6 +52,67 @@ VARDECL size_t const cred_names_len[] =
|
|||||||
|
|
||||||
VARDECL creds_t creds = {0};
|
VARDECL creds_t creds = {0};
|
||||||
|
|
||||||
|
DECL char **
|
||||||
|
str_split(char const * s, char c)
|
||||||
|
{
|
||||||
|
char ** ret = NULL;
|
||||||
|
size_t i = 0;
|
||||||
|
|
||||||
|
size_t current_token_i = 0;
|
||||||
|
|
||||||
|
size_t token_start_i = 0;
|
||||||
|
size_t tokens_q = 0;
|
||||||
|
|
||||||
|
/* count tokens */
|
||||||
|
for (i = 1; s[i]; ++i)
|
||||||
|
{
|
||||||
|
/* end of a token*/
|
||||||
|
if (s[i] == c && s[i - 1] != c)
|
||||||
|
{ ++tokens_q; }
|
||||||
|
}
|
||||||
|
++tokens_q;
|
||||||
|
|
||||||
|
ret = (char **)calloc(tokens_q + 1, sizeof(char *));
|
||||||
|
if (!ret)
|
||||||
|
{ return ret; }
|
||||||
|
|
||||||
|
for (i = 1; s[i]; ++i)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (s[i] == c && s[i - 1] != c)
|
||||||
|
{
|
||||||
|
/* end of a token*/
|
||||||
|
ret[current_token_i] = strndup(s + token_start_i, i - token_start_i);
|
||||||
|
if (!ret[current_token_i])
|
||||||
|
{
|
||||||
|
split_clean(ret);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
++current_token_i;
|
||||||
|
}
|
||||||
|
else if (s[i] != c && s[i - 1] == c)
|
||||||
|
{
|
||||||
|
/* start of a token */
|
||||||
|
token_start_i = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Signal that the split array is ended (for iteration purposes) */
|
||||||
|
ret[current_token_i + 1] = NULL;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
DECL void
|
||||||
|
split_clean(char ** split)
|
||||||
|
{
|
||||||
|
while (*split)
|
||||||
|
{
|
||||||
|
free(*split);
|
||||||
|
}
|
||||||
|
free(split);
|
||||||
|
}
|
||||||
|
|
||||||
DECL char *
|
DECL char *
|
||||||
slurp(char const * fn)
|
slurp(char const * fn)
|
||||||
{
|
{
|
||||||
@ -164,8 +225,8 @@ parse_pair(char const * buf, size_t len)
|
|||||||
/* X macro for handling this data may be better */
|
/* X macro for handling this data may be better */
|
||||||
if (strncmp(buf, cred_names[f], cred_names_len[f]) == 0)
|
if (strncmp(buf, cred_names[f], cred_names_len[f]) == 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "f%ld:len%ld:%s\n", f, cred_names_len[f],
|
/* fprintf(stderr, "f%ld:len%ld:%s\n", f, cred_names_len[f], */
|
||||||
cred_names[f]); fflush(stderr);
|
/* cred_names[f]); fflush(stderr); */
|
||||||
buf += i;
|
buf += i;
|
||||||
while (buf[x] != '\0')
|
while (buf[x] != '\0')
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user