From c3d79d07b96c3e2bee7bbdfbc7ec3f6e7af59e17 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Tue, 24 Jan 2023 17:35:12 +0000 Subject: support passwords for joining channels, and refactor channel list into a separate module --- Makefile | 7 ++++--- bee.c | 1 + chanlist.c | 18 ++++++++++++++++++ chanlist.h | 13 +++++++++++++ conf.h | 2 +- irc.c | 18 +++++++++--------- irc.h | 6 ------ 7 files changed, 46 insertions(+), 19 deletions(-) create mode 100644 chanlist.c create mode 100644 chanlist.h diff --git a/Makefile b/Makefile index 97d5d35..a7f0cb9 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ CC=cc debug=-g -DDEBUG -DLOCAL CFLAGS=$(MORE_CFLAGS) -Wall -Wpedantic -OBJS=bee.o irc.o util.o unix.o +OBJS=bee.o irc.o util.o unix.o chanlist.o all: apiobot apiobot: $(OBJS) @@ -19,11 +19,12 @@ local: .c.o: $(CC) $(CFLAGS) -c $< -o $@ -bee.o: bee.c irc.h unix.h conf.h debug.h -irc.o: irc.c irc.h debug.h conf.h util.h +bee.o: bee.c irc.h unix.h conf.h debug.h chanlist.h +irc.o: irc.c irc.h debug.h conf.h util.h chanlist.h thing.o: thing.c conf.h unix.o: unix.c unix.h conf.h irc.h util.o: util.c util.h debug.h conf.h +chanlist.o: chanlist.c run: all diff --git a/bee.c b/bee.c index daa52bd..89ad3ff 100644 --- a/bee.c +++ b/bee.c @@ -1,4 +1,5 @@ #include "irc.h" +#include "chanlist.h" #include "unix.h" #include "conf.h" #include "debug.h" diff --git a/chanlist.c b/chanlist.c new file mode 100644 index 0000000..3ccd291 --- /dev/null +++ b/chanlist.c @@ -0,0 +1,18 @@ +#include "chanlist.h" + +#include +char *g_chanlist[] = { + "a", + "b", + "g", + "the", +}; +const int g_nchannels = sizeof(g_chanlist)/sizeof(g_chanlist[0]); +char *g_chanpwlist[] = { + NULL, + NULL, + NULL, + "password", +}; + + diff --git a/chanlist.h b/chanlist.h new file mode 100644 index 0000000..95d428e --- /dev/null +++ b/chanlist.h @@ -0,0 +1,13 @@ +#ifndef chanlist_h_INCLUDED +#define chanlist_h_INCLUDED + +// list of channels to join +extern char *g_chanlist[]; +// length of the above +extern const int g_nchannels; +// list of passwords for channels, or NULL if no password +// parallel to g_chanlist +extern char *g_chanpwlist[]; + +#endif // chanlist_h_INCLUDED + diff --git a/conf.h b/conf.h index d42838d..c88bb3c 100644 --- a/conf.h +++ b/conf.h @@ -15,7 +15,7 @@ #define HOST "ubq323.website" #define PORT "6667" // directory to put the unix sockets into - #define SOCKETDIR "/srv/apiobot" + #define SOCKETDIR "/srv/apiobot/ch" // group to assign as the owner of all the unix sockets #define SOCKETGROUP "apionet" #endif diff --git a/irc.c b/irc.c index b30af48..548ee33 100644 --- a/irc.c +++ b/irc.c @@ -1,20 +1,12 @@ #include "irc.h" #include "debug.h" +#include "chanlist.h" #include "conf.h" #include "util.h" int g_ircsock = -1; -char *g_chanlist[] = { - "a", - "b", - "g", - "cg", - "secret-channel", -}; -const int g_nchannels = sizeof(g_chanlist)/sizeof(g_chanlist[0]); - int irc_connect() @@ -70,6 +62,14 @@ irc_handshake() } E(irc_sendall("JOIN #",6)); E(irc_sendall(g_chanlist[i],strlen(g_chanlist[i]))); + if (g_chanpwlist[i] != NULL) { + if (strlen(g_chanpwlist[i]) > 32) { + fprintf(stderr,"channel password too long for #(%s)\n",g_chanlist[i]); + return -1; + } + E(irc_sendall(" ",1)); + E(irc_sendall(g_chanpwlist[i],strlen(g_chanpwlist[i]))); + } E(irc_sendall("\r\n",2)); } #undef E diff --git a/irc.h b/irc.h index 870508f..d319eee 100644 --- a/irc.h +++ b/irc.h @@ -13,12 +13,6 @@ // fd of the irc connection socket extern int g_ircsock; -// list of channels to join -extern char *g_chanlist[]; -// length of the above -extern const int g_nchannels; - - // connects to the irc server, as defined in config.h // returns -1 on failure. int irc_connect(); -- cgit v1.2.3