Remove shit
This commit is contained in:
parent
8605323aa8
commit
fcc7493bb9
@ -1,5 +1,5 @@
|
||||
#!/bin/sh
|
||||
DBFILE=probotic_data.sqlite
|
||||
|
||||
rm "$DBFILE"
|
||||
rm -f "$DBFILE"
|
||||
sqlite3 "$DBFILE" -init bootstrap.sql -line '.quit'
|
||||
|
@ -20,7 +20,6 @@ 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 void parse_admins(char * admin_string);
|
||||
DECL int parse_pair(char const * buf, size_t const len);
|
||||
DECL void creds_free_password(void);
|
||||
DECL void creds_free_rest(void);
|
||||
|
@ -82,9 +82,6 @@ main (int argc,
|
||||
{ free(creds.username); creds.username = strdup(argv[1]); }
|
||||
else if (strcmp(arg, "password") == 0)
|
||||
{ free(creds.password); creds.password = strdup(argv[1]); }
|
||||
else if (strcmp(arg, "admin") == 0)
|
||||
/* argv isn't constant :>, this can make even valgrind shutter */
|
||||
{ free(creds.admins); parse_admins(argv[1]); }
|
||||
else if (strcmp(arg, "auth") == 0)
|
||||
{
|
||||
authfile = argv[1];
|
||||
|
58
src/parse.c
58
src/parse.c
@ -27,8 +27,7 @@ enum cred_names_map
|
||||
PASSWORD,
|
||||
CHANNEL,
|
||||
SERVER,
|
||||
PORT,
|
||||
ADMINS
|
||||
PORT
|
||||
};
|
||||
|
||||
VARDECL char const * cred_names[] =
|
||||
@ -38,8 +37,7 @@ VARDECL char const * cred_names[] =
|
||||
"password",
|
||||
"channel",
|
||||
"server",
|
||||
"port",
|
||||
"admins"
|
||||
"port"
|
||||
};
|
||||
|
||||
VARDECL size_t const cred_names_len[] =
|
||||
@ -214,7 +212,6 @@ DECL int
|
||||
parse_pair(char const * buf, size_t len)
|
||||
{
|
||||
size_t i, f, x;
|
||||
char * adm;
|
||||
/* fprintf(stderr, "ENT len:%ld buf:%sEOF\n", len, buf); */
|
||||
for (i = 0; buf[i] &&
|
||||
i < len; ++i)
|
||||
@ -247,10 +244,6 @@ parse_pair(char const * buf, size_t len)
|
||||
case CHANNEL: creds.channel = strndup(buf,x); break;
|
||||
case SERVER: creds.server = strndup(buf,x); break;
|
||||
case PORT: creds.port = atoi(buf); break;
|
||||
case ADMINS: adm = strndup(buf,x);
|
||||
parse_admins(adm);
|
||||
free(adm);
|
||||
break;
|
||||
}
|
||||
if (x + 2 < len)
|
||||
{ buf += x + 1; }
|
||||
@ -265,54 +258,11 @@ parse_pair(char const * buf, size_t len)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* FIXME MAKE parse_admins constant! */
|
||||
/* WARNING: admin_string WILL be changed */
|
||||
DECL void
|
||||
parse_admins(char * admin_string)
|
||||
{
|
||||
#define ADMIN_LIST_INIT_SIZE 8
|
||||
/* prealloc with 8 */
|
||||
size_t current_array_size = ADMIN_LIST_INIT_SIZE;
|
||||
|
||||
size_t i = 0;
|
||||
char * token = NULL;
|
||||
|
||||
creds.admins = calloc(ADMIN_LIST_INIT_SIZE, sizeof(char *));
|
||||
|
||||
while ((token = strtok(admin_string, " ")))
|
||||
{
|
||||
if (++i > current_array_size)
|
||||
{
|
||||
/* double the space */
|
||||
current_array_size *= 2;
|
||||
creds.admins = realloc(creds.admins, current_array_size);
|
||||
}
|
||||
|
||||
creds.admins[i - 1] = strdup(token);
|
||||
}
|
||||
|
||||
/* set up array end marker for proper clean-up later */
|
||||
if (i + 1 > current_array_size)
|
||||
{
|
||||
creds.admins = realloc(creds.admins, current_array_size + 1);
|
||||
}
|
||||
creds.admins[i] = NULL;
|
||||
}
|
||||
|
||||
DECL int
|
||||
is_admin(char const * user)
|
||||
{
|
||||
/* No Gods or Kings, Only Man */
|
||||
if (creds.admins == NULL)
|
||||
{ return 0; }
|
||||
|
||||
for (size_t i = 0; creds.admins[i]; ++i)
|
||||
{
|
||||
if (!strcmp(creds.admins[i], user))
|
||||
{ return 1; }
|
||||
}
|
||||
|
||||
return 0;
|
||||
/* No Gods or Kings, Only size_t */
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
|
Reference in New Issue
Block a user