summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--blabouncer.c44
-rw-r--r--blabouncer.conf4
-rw-r--r--config.c10
-rw-r--r--config.h2
-rw-r--r--replay.c10
-rw-r--r--replay.h6
6 files changed, 41 insertions, 35 deletions
diff --git a/blabouncer.c b/blabouncer.c
index c3eed3b..1a781df 100644
--- a/blabouncer.c
+++ b/blabouncer.c
@@ -8,7 +8,7 @@
// - Add blabouncer MOTD (375, 372, 376)
// - "01:53:47 -!- ServerMode/#test [b] by irc.tghost.co.uk" on existing clients when new client connects
// - Keep track of changing user nicks/modes
-// - Should relay log do more than PRIVMSGs?
+// - Should replay log do more than PRIVMSGs?
// - Make certificate paths configurable
// - Implement TLS on real IRCd server side
// - Make TLS optional
@@ -92,6 +92,11 @@ struct ircdstrings {
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)
};
+// Structure of settings either to be read from the configuration file or set/changed at runtime
+struct settings {
+ int replayseconds;
+};
+
int debugmode = 0;
// Return index of requested client FD within arr_clients
@@ -220,7 +225,7 @@ int sendtoallclients(int *clientsockfd, int fdmax, int arr_clients[], char *str,
// Send whatever string to the real IRC server
// Client FD and arrays needed to make sure anything relayed from a client is from an authenticated client.
// clientfd of "0" means trusted, used when we are sending things ourselves that weren't relayed
-// from a relay client.
+// from a real client.
int sendtoserver(int *serversockfd, char *str, int str_len, int clientfd, int arr_clients[], int arr_authed[]) {
appendcrlf(str); // Do this just before sending so callers don't need to worry about it
str_len = strlen(str); // Recalculate str_len in case it changed (TODO: so do we even need to pass it to this function?)
@@ -436,7 +441,7 @@ int removechannel(struct channel *channels, char *name) {
// Return 1 if we processed something and expect the caller to not need to do anything more
// Return 0 if we didn't process it and the caller might want to do something
//int processircmessage(int *serversockfd, int *clientsockfd, char *str, int source) {
-int processircmessage(int *serversockfd, int *clientsockfd, char *str, int source, int fdmax, int arr_clients[], int sourcefd, struct ircdstrings *ircdstrings, struct channel *channels, int arr_authed[], SSL **arr_ssl) {
+int processircmessage(int *serversockfd, int *clientsockfd, char *str, int source, int fdmax, int arr_clients[], int sourcefd, struct ircdstrings *ircdstrings, struct channel *channels, int arr_authed[], SSL **arr_ssl, struct settings *settings) {
// Track which space-separated token within this response we're on
int counter = 0;
@@ -643,8 +648,8 @@ int processircmessage(int *serversockfd, int *clientsockfd, char *str, int sourc
sendtoallclients(clientsockfd, fdmax, arr_clients, str, sourcefd, arr_authed, arr_ssl);
- // Write to relay log
- writerelayline(str);
+ // Write to replay log
+ writereplayline(str);
return 1;
}
@@ -767,11 +772,8 @@ int processircmessage(int *serversockfd, int *clientsockfd, char *str, int sourc
sendtoclient(sourcefd, outgoingmsg, arr_clients, arr_authed, arr_ssl);
}
- // Send the client however many relay lines have been requested
- int relaysecs = confrelayseconds();
-
- // Figure out how many lines to relay
- int numlines = relaylines(relaysecs);
+ // Figure out how many lines to replay
+ int numlines = replaylines(settings->replayseconds);
printf("Replay log lines: '%d'.\n", numlines);
if (numlines < 0) {
@@ -781,11 +783,11 @@ int processircmessage(int *serversockfd, int *clientsockfd, char *str, int sourc
// Relay those lines!
for (int i = 0; i < numlines; i++) {
- if (!readrelayline(relaysecs, i, outgoingmsg)) {
- printf("Error requesting relay line.\n");
+ if (!readreplayline(settings->replayseconds, i, outgoingmsg)) {
+ printf("Error requesting replay line.\n");
exit(1);
}
- printf("Sending relay line: '%s'.\n", outgoingmsg);
+ printf("Sending replay line: '%s'.\n", outgoingmsg);
sendtoclient(sourcefd, outgoingmsg, arr_clients, arr_authed, arr_ssl);
}
@@ -836,8 +838,8 @@ int processircmessage(int *serversockfd, int *clientsockfd, char *str, int sourc
// Send to all except source client
sendtoallclients(clientsockfd, fdmax, arr_clients, outgoingmsg, sourcefd, arr_authed, arr_ssl);
- // Write to relay log
- writerelayline(outgoingmsg);
+ // Write to replay log
+ writereplayline(outgoingmsg);
return 1;
}
@@ -901,7 +903,7 @@ int processircmessage(int *serversockfd, int *clientsockfd, char *str, int sourc
//
// Return 0 if something went wrong
// Return 1 if everything OK
-int processrawstring(int *serversockfd, int *clientsockfd, char *str, int source, int fdmax, int arr_clients[], int sourcefd, struct ircdstrings *ircdstrings, struct channel *channels, int arr_authed[], SSL **arr_ssl) {
+int processrawstring(int *serversockfd, int *clientsockfd, char *str, int source, int fdmax, int arr_clients[], int sourcefd, struct ircdstrings *ircdstrings, struct channel *channels, int arr_authed[], SSL **arr_ssl, struct settings *settings) {
// Copy to a temporary string so we still have the original in case it's not processed
char *strcopy = strdup(str);
@@ -956,7 +958,7 @@ int processrawstring(int *serversockfd, int *clientsockfd, char *str, int source
for (int i = 0; i < messagecount; i++) {
// Copy to a temporary string so we still have the original in case it's not processed
char *messagecopy = strdup(messages[i]);
- if (processircmessage(serversockfd, clientsockfd, messagecopy, source, fdmax, arr_clients, sourcefd, ircdstrings, channels, arr_authed, arr_ssl)) {
+ if (processircmessage(serversockfd, clientsockfd, messagecopy, source, fdmax, arr_clients, sourcefd, ircdstrings, channels, arr_authed, arr_ssl, settings)) {
printf("Message processed: \"%s\", NULLing...\n", messages[i]);
messages[i][0] = '\0';
}
@@ -1046,6 +1048,10 @@ void dochat(int *serversockfd, int *clientsockfd) {
ircdstrings.ircrealname[0] = '\0';
ircdstrings.currentmsg[0] = '\0';
+ // 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();
+
// Read required things from configuration file
readnames(ircdstrings.ircnick, ircdstrings.ircusername, ircdstrings.ircrealname);
@@ -1120,7 +1126,7 @@ void dochat(int *serversockfd, int *clientsockfd) {
// Try to process received string (which should contain one or more server responses/commands)
// TODO - What if there were two server respones/commands and only one didn't need relaying?
- if (!processrawstring(serversockfd, clientsockfd, serverbuf, SOURCE_SERVER, fdmax, arr_clients, EXCEPT_NONE, &ircdstrings, channels, arr_authed, arr_ssl)) {
+ if (!processrawstring(serversockfd, clientsockfd, serverbuf, SOURCE_SERVER, fdmax, arr_clients, EXCEPT_NONE, &ircdstrings, channels, arr_authed, arr_ssl, &settings)) {
fprintf(stderr, "Error: bouncer-server failed to process raw string.\n");
exit(1);
}
@@ -1246,7 +1252,7 @@ void dochat(int *serversockfd, int *clientsockfd) {
// Try to process received string (which should contain one or more client responses/commands)
// TODO - What if there were two server respones/commands and only one didn't need relaying?
- if (!processrawstring(serversockfd, clientsockfd, clientbuf, SOURCE_CLIENT, fdmax, arr_clients, i, &ircdstrings, channels, arr_authed, arr_ssl)) {
+ if (!processrawstring(serversockfd, clientsockfd, clientbuf, SOURCE_CLIENT, fdmax, arr_clients, i, &ircdstrings, channels, arr_authed, arr_ssl, &settings)) {
fprintf(stderr, "Error: bouncer-client failed to process raw string.\n");
exit(1);
}
diff --git a/blabouncer.conf b/blabouncer.conf
index 5be29ca..32ad54b 100644
--- a/blabouncer.conf
+++ b/blabouncer.conf
@@ -8,8 +8,8 @@ nick = "blabounce"
username = "blabounce"
realname = "Mr Bla Bouncer"
-# How many seconds of relay log should be sent to connecting clients
-relayseconds = "7200"
+# How many seconds of replay log should be sent to connecting clients
+replayseconds = "7200"
# Connect password clients must provided to connect
password = "bananas"
diff --git a/config.c b/config.c
index 8bfead9..7d26ca0 100644
--- a/config.c
+++ b/config.c
@@ -1,6 +1,6 @@
#include "config.h"
-// TODO - Multiple functions here (at least readnames(), relayseconds() and checkpassword()) have the file opening code, rewrite.
+// TODO - Multiple functions here (at least readnames(), replayseconds() and checkpassword()) have the file opening code, rewrite.
// TODO - Can isconf() and getconf() just be merged into one function?
@@ -107,9 +107,9 @@ int readnames(char *nick, char *username, char *realname) {
return 1;
}
-// Return the relayseconds configuration option
-// (How many seconds of relay should be sent to connecting clients)
-int confrelayseconds() {
+// Return the replayseconds configuration option
+// (How many seconds of replay should be sent to connecting clients)
+int confreplayseconds() {
FILE *fp;
char str[MAXCHAR];
char* filename = "blabouncer.conf";
@@ -126,7 +126,7 @@ int confrelayseconds() {
while (fgets(str, MAXCHAR, fp) != NULL) {
long int len;
- if ((len = isconf(str, "relayseconds"))) {
+ if ((len = isconf(str, "replayseconds"))) {
getconf(str, len);
strncpy(secondsstr, str, strlen(str));
secondsstr[strlen(str)] = '\0';
diff --git a/config.h b/config.h
index d74af82..3d81d2f 100644
--- a/config.h
+++ b/config.h
@@ -9,7 +9,7 @@
int readnames(char *nick, char *username, char *realname);
-int confrelayseconds();
+int confreplayseconds();
int checkpassword(char *password);
diff --git a/replay.c b/replay.c
index 0ab3238..9ae4d82 100644
--- a/replay.c
+++ b/replay.c
@@ -139,11 +139,11 @@ void formattime(char *str) {
strncpy(str, newline, len + TIMELEN);
str[len + TIMELEN] = '\0';
- printf("Ended up with relay string of: '%s'.\n", str);
+ printf("Ended up with replay string of: '%s'.\n", str);
}
// Return the number of lines in the replay log since 'seconds' seconds ago, or -1 if there a problem.
-int relaylines(int seconds) {
+int replaylines(int seconds) {
FILE *fp;
char str[MAXCHAR];
char* filename = "replay.log";
@@ -187,7 +187,7 @@ int relaylines(int seconds) {
// Also modify the line to include a timestamp in the form "[HH:MM:SS]".
// Returns 1 on success, or 0 on failure.
// TODO - This is horribly inefficient since it re-reads the entire file each call, rewrite this!
-int readrelayline(int seconds, int linenum, char *str) {
+int readreplayline(int seconds, int linenum, char *str) {
FILE *fp;
char line[MAXCHAR];
char* filename = "replay.log";
@@ -234,13 +234,13 @@ int readrelayline(int seconds, int linenum, char *str) {
return 0;
}
-// Write the line 'str' to the relay log file after prepending it with
+// Write the line 'str' to the replay log file after prepending it with
// the current unixtime timestamp.
// Expects a string in the format:
// :foo!bar@baz PRIVMSG foo :[17:41:41] hello world
// With the ":foo!bar@baz "prefix being important.
// Returns 1 on success or 0 on failure.
-int writerelayline(char *str) {
+int writereplayline(char *str) {
FILE *fp;
char line[MAXCHAR];
char* filename = "replay.log";
diff --git a/replay.h b/replay.h
index e0b5822..7f1e331 100644
--- a/replay.h
+++ b/replay.h
@@ -12,10 +12,10 @@
#define TIMELEN 11 // 32-bit unixtime is up to 10 characters (+1 for null char) // TODO - Make this Year 2038 proof
#define TIMELENF 11 // [HH:MM:SS] = 10 characters + 1 for null char
-int relaylines(int seconds);
+int replaylines(int seconds);
-int readrelayline(int seconds, int linenum, char *str);
+int readreplayline(int seconds, int linenum, char *str);
-int writerelayline(char *str);
+int writereplayline(char *str);
#endif