From 0eaa8afa930e3575ec2b0974eba75f0aea861c00 Mon Sep 17 00:00:00 2001 From: fall-leaf Date: Thu, 3 Aug 2023 14:57:04 +0300 Subject: [PATCH 1/3] admin list parsing base --- src/parse.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/src/parse.c b/src/parse.c index 122060d..85522b3 100644 --- a/src/parse.c +++ b/src/parse.c @@ -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,58 @@ 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 void +clean_admin_list() +{ + if (admins == NULL) + { return; } + + for (size_t i = 0; admins[i]; ++i) + { free(admins[i]); } + + free(admins); + admins = NULL; +} \ No newline at end of file From c33e5e4c7263e537ba556b431d2a0c7fd4393613 Mon Sep 17 00:00:00 2001 From: fall-leaf Date: Thu, 3 Aug 2023 15:06:42 +0300 Subject: [PATCH 2/3] admins check --- include/parse.h | 4 ++++ src/parse.c | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/parse.h b/include/parse.h index 2245b26..efa4e01 100644 --- a/include/parse.h +++ b/include/parse.h @@ -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); diff --git a/src/parse.c b/src/parse.c index 85522b3..13993b0 100644 --- a/src/parse.c +++ b/src/parse.c @@ -232,6 +232,22 @@ parse_admin_list(char const * admin_list_path) 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() { From 160c8ddceaf754fca95bea362f9ae7558e10c6f3 Mon Sep 17 00:00:00 2001 From: fall-leaf Date: Thu, 3 Aug 2023 15:29:42 +0300 Subject: [PATCH 3/3] updated readme: replaced mention of a non-existent config.h --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9c2da5b..8e1bcc1 100644 --- a/README.md +++ b/README.md @@ -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