From 62fe87f6052dc28e38f2edc940b2002ede087277 Mon Sep 17 00:00:00 2001 From: Luke Bratch Date: Sun, 12 May 2019 16:29:58 +0100 Subject: Add a settings structure for passing around everywhere to store config/settings. Also fix the insanely inconsistent spelling/naming of replay log related things. --- blabouncer.c | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) (limited to 'blabouncer.c') 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); } -- cgit v1.2.3