summaryrefslogtreecommitdiff
path: root/blabouncer.c
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2019-05-12 20:56:55 +0100
committerLuke Bratch <luke@bratch.co.uk>2019-05-12 20:56:55 +0100
commite18e670f43f0e7b126f209c040126aa02511fa32 (patch)
tree798e297304c0ce051847359ebf32af63503b67c8 /blabouncer.c
parent34836ab2c9124e17d80bd8e8a1601398297391a8 (diff)
Completely rewrite configuration file reading to remove lots of duplicated code and to simplify things. Alter everything that called the old functions.
Diffstat (limited to 'blabouncer.c')
-rw-r--r--blabouncer.c46
1 files changed, 38 insertions, 8 deletions
diff --git a/blabouncer.c b/blabouncer.c
index d96ec09..5da18e0 100644
--- a/blabouncer.c
+++ b/blabouncer.c
@@ -70,6 +70,8 @@
#define MAXREALNAMELEN 128 // Randomly picked (TODO - is there an actual maximum real name length?)
#define MAXPORTLEN 6 // Up to 65535, so 5 characters + 1 for null
+#define CONFFILE "blabouncer.conf"
+
struct channel {
char name[MAXCHANLENGTH];
char topic[MAXDATASIZE]; // TODO - Is there a particular maximum topic length?
@@ -91,7 +93,6 @@ struct ircdstrings {
char nickuserhost[MAXDATASIZE]; // TODO - Make sure this changes when nick changes, if that's meant to happen.
char ircnick[MAXNICKLENGTH]; // TODO - Make sure this changes when nick changes
char ircusername[MAXUSERNAMELEN];
- char ircrealname[MAXREALNAMELEN];
char currentmsg[MAXDATASIZE]; // Holding area for the current server-received IRC message being processed in case it needs building across multiple reads (i.e. a truncated/split message)
};
@@ -99,6 +100,9 @@ struct ircdstrings {
struct settings {
int replayseconds;
char clientport[MAXPORTLEN];
+ char ircnick[MAXNICKLENGTH]; // In both settings and ircdstrings as settings is from our file whereas server may change ircdstrings copy
+ char ircusername[MAXUSERNAMELEN]; // (Is this also true for the username? Can the server change that?)
+ char ircrealname[MAXREALNAMELEN];
};
int debugmode = 0;
@@ -665,7 +669,7 @@ int processircmessage(int *serversockfd, int *clientsockfd, char *str, int sourc
case SOURCE_CLIENT: // If message(s) were from a real IRC client
// PASS received? User is trying to log in, check their password.
if (strncmp(tokens[0], "PASS", strlen(tokens[0])) == 0) {
- if (checkpassword(tokens[1])) {
+ if (checkpassword(tokens[1], CONFFILE)) {
printf("Password accepted! Setting fd %d to authenticated.\n", sourcefd);
// Find the client in the clients array and set them as authenticated
for (int i = 0; i < MAXCLIENTS; i++) {
@@ -1049,11 +1053,11 @@ void dochat(int *serversockfd, int *clientsockfd, struct settings *settings) {
ircdstrings.nickuserhost[0] = '\0';
ircdstrings.ircnick[0] = '\0';
ircdstrings.ircusername[0] = '\0';
- ircdstrings.ircrealname[0] = '\0';
ircdstrings.currentmsg[0] = '\0';
- // Read required things from configuration file
- readnames(ircdstrings.ircnick, ircdstrings.ircusername, ircdstrings.ircrealname);
+ // Populate nick and username from our configuration file for now, real IRCd may change them later (TODO - Is this true of username?)
+ strcpy(ircdstrings.ircnick, settings->ircnick);
+ strcpy(ircdstrings.ircusername, settings->ircusername);
// Send our NICK
snprintf(outgoingmsg, MAXDATASIZE, "NICK %s", ircdstrings.ircnick); // TODO - Check for success (with return code)
@@ -1061,7 +1065,7 @@ void dochat(int *serversockfd, int *clientsockfd, struct settings *settings) {
sendtoserver(serversockfd, outgoingmsg, strlen(outgoingmsg), 0, arr_clients, arr_authed);
// Send our USER
- snprintf(outgoingmsg, MAXDATASIZE, "USER %s 8 * : %s", ircdstrings.ircusername, ircdstrings.ircrealname); // TODO - Check for success (with return code)
+ snprintf(outgoingmsg, MAXDATASIZE, "USER %s 8 * : %s", ircdstrings.ircusername, settings->ircrealname); // TODO - Check for success (with return code)
// TODO - Send a more intelligent/correct USER string
// sourcefd = 0 as this is a trusted message
sendtoserver(serversockfd, outgoingmsg, strlen(outgoingmsg), 0, arr_clients, arr_authed);
@@ -1278,8 +1282,34 @@ int main(int argc, char *argv[]) {
// Structure of our various settings which are to either be read from the configuration file or set at runtime
struct settings settings;
- settings.replayseconds = confreplayseconds();
- confclientport(settings.clientport);
+
+ // Populate said settings
+
+ // How many seconds of replay log should automatically be replayed - TODO - Can we do error checking on this?
+ settings.replayseconds = getconfint("replayseconds", CONFFILE);
+ // What port should the bouncer listen on
+ if (!getconfstr("clientport", CONFFILE, settings.clientport)) {
+ printf("main(): error getting clientport from configuration file.\n");
+ exit(1);
+ }
+
+ // What is the configured nick?
+ if (!getconfstr("nick", CONFFILE, settings.ircnick)) {
+ printf("main(): error getting nick from configuration file.\n");
+ exit(1);
+ }
+
+ // What is the configured username?
+ if (!getconfstr("username", CONFFILE, settings.ircusername)) {
+ printf("main(): error getting username from configuration file.\n");
+ exit(1);
+ }
+
+ // What is the configured real name?
+ if (!getconfstr("realname", CONFFILE, settings.ircrealname)) {
+ printf("main(): error getting real name from configuration file.\n");
+ exit(1);
+ }
// TODO: see if any of this can be shared (i.e. 1. avoid code duplication, and 2. see if variables can be shared between client/server sockets)