This commit is contained in:
anon 2023-08-03 14:33:48 +02:00
commit 399eb45986
3 changed files with 79 additions and 3 deletions

View File

@ -15,8 +15,9 @@ See doc/api.md for detailed information about this interface.
* Building and Installation
First, you'll want to customize include/config.h as detailed from
include/config.mk.h, then build via running ./build.sh
First, you'll want specify your server and channel as well as bot username
and a password. This can be done either with command-line options or in a
specified credentials file.
This'll require a few libraries:
libircclient-dev libsqlite3-dev build-essentials

View File

@ -15,6 +15,10 @@ DECL void parse_command(char * cmd);
DECL int parse_creds(char const * creds_file);
DECL void clean_creds(void);
DECL int parse_admin_list(char const * admin_list_file);
DECL int is_admin(char const * user);
DECL void clean_admin_list();
DECL char * remind(char * who);
DECL void set_repo(const char * const who, const char * const link);
DECL char * dump(void);

View File

@ -27,6 +27,7 @@
#define PARAMS_COUNT 5
creds_t creds = {0};
char ** admins = NULL;
enum cred_param_ids_e
{
@ -177,7 +178,6 @@ fail:
return 1;
}
void
clean_creds(void)
{
@ -189,3 +189,74 @@ clean_creds(void)
FULL_FREE(creds.server);
#undef FULL_FREE
}
DECL int
parse_admin_list(char const * admin_list_path)
{
#define ADMIN_LIST_INIT_SIZE 8
/* prealloc with 8 */
size_t current_array_size = ADMIN_LIST_INIT_SIZE;
FILE * stream;
size_t lines_read = 0;
char * line = NULL;
size_t nread = 0;
admins = calloc(ADMIN_LIST_INIT_SIZE, sizeof(char *));
stream = fopen(admin_list_path, "r");
if (stream == NULL)
{
PERROR(1);
}
while (getline(&line, &nread, stream) > 0)
{
if (++lines_read > current_array_size)
{
/* double the space*/
current_array_size *= 2;
realloc(admins, current_array_size);
}
admins[lines_read - 1] = line;
}
/* set up array end marker for proper clean-up later */
if (lines_read + 1 > current_array_size)
{
realloc(admins, current_array_size + 1);
}
admins[lines_read] = NULL;
return 0;
}
DECL int
is_admin(char const * user)
{
/* No Gods, no Masters */
if (admins == NULL)
{ return 0; }
for (size_t i = 0; admins[i]; ++i)
{
if (!strcmp(admins[i], user))
{ return 1; }
}
return 0;
}
DECL void
clean_admin_list()
{
if (admins == NULL)
{ return; }
for (size_t i = 0; admins[i]; ++i)
{ free(admins[i]); }
free(admins);
admins = NULL;
}