Merge branch 'master' of https://git.lain.church/emil/probotic
This commit is contained in:
commit
5fac77e324
@ -1,4 +1,2 @@
|
||||
#!/bin/sh
|
||||
# Tested to work 100% of the time when that file doesn't exist
|
||||
# probably
|
||||
sqlite3 probotic_data.sqlite -init init.sql -line '.quit'
|
||||
|
@ -1,4 +0,0 @@
|
||||
server=irc.rizon.net
|
||||
username=probotic
|
||||
port=6667
|
||||
channel=#stop_shitting_up_chad
|
8
docs/rizon_default.cfg
Normal file
8
docs/rizon_default.cfg
Normal file
@ -0,0 +1,8 @@
|
||||
server=irc.rizon.net
|
||||
username=probotic
|
||||
port=6667
|
||||
admins=anon8697 emilemilemil fa11_1eaf
|
||||
|
||||
; provide channel yourself
|
||||
; lines without an equal sign are dropped
|
||||
; prefix comments with a semicolon for future compat
|
@ -7,5 +7,7 @@ DECL char * remind(char * who);
|
||||
DECL char * raw(char const * const sql);
|
||||
DECL int is_no_assignment(char const * const who);
|
||||
|
||||
extern char const * db;
|
||||
|
||||
#define API_H_
|
||||
#endif
|
||||
|
@ -2,11 +2,13 @@
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char * username;
|
||||
char * password;
|
||||
char * channel;
|
||||
char * server;
|
||||
int port;
|
||||
size_t admin_count;
|
||||
char * username;
|
||||
char * password;
|
||||
char * channel;
|
||||
char * server;
|
||||
char ** admins;
|
||||
int port;
|
||||
} creds_t;
|
||||
|
||||
extern creds_t creds;
|
||||
@ -16,9 +18,8 @@ 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 parse_admin_list(char const * admin_list_file);
|
||||
DECL void parse_admins(char * admin_string);
|
||||
DECL int parse_pair(char const * buf, size_t const len);
|
||||
DECL void clean_admin_list();
|
||||
DECL void creds_free_password(void);
|
||||
DECL void creds_free_rest(void);
|
||||
DECL void parse_command(char const * const cmd);
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include "irccolors.h"
|
||||
#include "stmt.h"
|
||||
|
||||
#define DBFILE "test.sqlite"
|
||||
#define DBFILE "probotic_data.sqlite"
|
||||
|
||||
#define DBERR(line) do { \
|
||||
const int e = line; \
|
||||
@ -21,12 +21,14 @@
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
char const * db = DBFILE;
|
||||
|
||||
static sqlite3 * connection = NULL;
|
||||
|
||||
DECL int
|
||||
api_init(void)
|
||||
{
|
||||
DBERR(sqlite3_open(DBFILE, &connection));
|
||||
DBERR(sqlite3_open(db, &connection));
|
||||
// dont you fucking dare to remove this spacing
|
||||
DBERR(stmt_prepare(remind_stmt));
|
||||
DBERR(stmt_prepare(set_repo_stmt));
|
||||
|
14
src/main.c
14
src/main.c
@ -78,16 +78,20 @@ main (int argc,
|
||||
{ goto help; }
|
||||
if (argc < 2)
|
||||
{ goto nop; }
|
||||
if (strcmp(arg, "server") == 0)
|
||||
{ FREE(creds.server); creds.server = argv[1]; }
|
||||
if (strcmp(arg, "db") == 0)
|
||||
{ db = argv[1]; }
|
||||
else if (strcmp(arg, "server") == 0)
|
||||
{ free(creds.server); creds.server = strdup(argv[1]); }
|
||||
else if (strcmp(arg, "port") == 0)
|
||||
{ creds.port = atoi(argv[1]); }
|
||||
else if (strcmp(arg, "channel") == 0)
|
||||
{ FREE(creds.channel);creds.channel = argv[1]; }
|
||||
{ free(creds.channel); creds.channel = strdup(argv[1]); }
|
||||
else if (strcmp(arg, "username") == 0)
|
||||
{ FREE(creds.username); creds.username = argv[1]; }
|
||||
{ free(creds.username); creds.username = strdup(argv[1]); }
|
||||
else if (strcmp(arg, "password") == 0)
|
||||
{ FREE(creds.password); creds.password = argv[1]; }
|
||||
{ free(creds.password); creds.password = strdup(argv[1]); }
|
||||
else if (strcmp(arg, "admin") == 0)
|
||||
{ free(creds.admins); parse_admins(argv[1]); } /* argv isn't constant :> */
|
||||
else if (strcmp(arg, "auth") == 0)
|
||||
{
|
||||
authfile = argv[1];
|
||||
|
73
src/parse.c
73
src/parse.c
@ -26,7 +26,7 @@
|
||||
#include "help.h"
|
||||
#include "parse.h"
|
||||
|
||||
#define PARAMS_COUNT 5
|
||||
#define PARAMS_COUNT 6
|
||||
|
||||
enum cred_param_ids_e
|
||||
{
|
||||
@ -34,7 +34,8 @@ enum cred_param_ids_e
|
||||
PASSWORD,
|
||||
CHANNEL,
|
||||
SERVER,
|
||||
PORT
|
||||
PORT,
|
||||
ADMINS
|
||||
};
|
||||
|
||||
char const * cred_names[] =
|
||||
@ -43,7 +44,8 @@ char const * cred_names[] =
|
||||
"password",
|
||||
"channel",
|
||||
"server",
|
||||
"port"
|
||||
"port",
|
||||
"admins"
|
||||
};
|
||||
|
||||
size_t const cred_names_len[] =
|
||||
@ -52,11 +54,11 @@ size_t const cred_names_len[] =
|
||||
8,
|
||||
7,
|
||||
6,
|
||||
4
|
||||
4,
|
||||
6
|
||||
};
|
||||
|
||||
creds_t creds = {0};
|
||||
char ** admins = NULL;
|
||||
|
||||
DECL char *
|
||||
slurp(char const * fn)
|
||||
@ -155,6 +157,7 @@ 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)
|
||||
@ -186,6 +189,7 @@ 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; }
|
||||
@ -200,78 +204,56 @@ parse_pair(char const * buf, size_t len)
|
||||
return 0;
|
||||
}
|
||||
|
||||
DECL int
|
||||
parse_admin_list(char const * admin_list_path)
|
||||
/* 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;
|
||||
|
||||
FILE * stream;
|
||||
size_t lines_read = 0;
|
||||
char * line = NULL;
|
||||
size_t nread = 0;
|
||||
size_t i = 0;
|
||||
char * token = NULL;
|
||||
|
||||
stream = fopen(admin_list_path, "r");
|
||||
if (stream == NULL)
|
||||
creds.admins = calloc(ADMIN_LIST_INIT_SIZE, sizeof(char *));
|
||||
|
||||
while ((token = strtok(admin_string, " ")))
|
||||
{
|
||||
/* Pretty valid case I guess? No admin file = no admins,
|
||||
maybe all configuration is performed locally */
|
||||
return 0;
|
||||
}
|
||||
|
||||
admins = calloc(ADMIN_LIST_INIT_SIZE, sizeof(char *));
|
||||
|
||||
while (getline(&line, &nread, stream) > 0)
|
||||
{
|
||||
if (++lines_read > current_array_size)
|
||||
if (++i > current_array_size)
|
||||
{
|
||||
/* double the space */
|
||||
current_array_size *= 2;
|
||||
realloc(admins, current_array_size);
|
||||
creds.admins = realloc(creds.admins, current_array_size);
|
||||
}
|
||||
|
||||
admins[lines_read - 1] = line;
|
||||
creds.admins[i - 1] = strdup(token);
|
||||
}
|
||||
|
||||
/* set up array end marker for proper clean-up later */
|
||||
if (lines_read + 1 > current_array_size)
|
||||
if (i + 1 > current_array_size)
|
||||
{
|
||||
realloc(admins, current_array_size + 1);
|
||||
creds.admins = realloc(creds.admins, current_array_size + 1);
|
||||
}
|
||||
admins[lines_read] = NULL;
|
||||
|
||||
return 0;
|
||||
creds.admins[i] = NULL;
|
||||
}
|
||||
|
||||
DECL int
|
||||
is_admin(char const * user)
|
||||
{
|
||||
/* No Gods or Kings, Only Man */
|
||||
if (admins == NULL)
|
||||
if (creds.admins == NULL)
|
||||
{ return 0; }
|
||||
|
||||
for (size_t i = 0; admins[i]; ++i)
|
||||
for (size_t i = 0; creds.admins[i]; ++i)
|
||||
{
|
||||
if (!strcmp(admins[i], user))
|
||||
if (!strcmp(creds.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);
|
||||
}
|
||||
|
||||
void
|
||||
creds_free_password(void)
|
||||
{
|
||||
@ -285,4 +267,5 @@ creds_free_rest(void)
|
||||
/* FULL_FREE(creds.password); */
|
||||
FULL_FREE(creds.channel);
|
||||
FULL_FREE(creds.server);
|
||||
FREE(creds.admins);
|
||||
}
|
||||
|
Reference in New Issue
Block a user