diff --git a/Makefile b/Makefile index 0a777ca..0410722 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,10 @@ CC ?= cc +CFLAGS ?= -O2 CFLAGS ?= -O2 -Wall -Wextra -Wpedantic -pthread $(shell pkg-config --cflags ncurses 2>/dev/null) LDLIBS ?= -pthread $(shell pkg-config --libs ncurses 2>/dev/null || echo -lncurses) +PREFIX ?= /usr/local +BINDIR = $(PREFIX)/bin +MANDIR ?= $(PREFIX)/share/man HAVE_OPENSSL := $(shell pkg-config --exists openssl && echo yes) ifeq ($(HAVE_OPENSSL),yes) @@ -8,10 +12,23 @@ CFLAGS += -DUSE_OPENSSL $(shell pkg-config --cflags openssl) LDLIBS += $(shell pkg-config --libs openssl) endif +ifeq ($(AUTOJOIN),1) +CPPFLAGS += -DUSE_AUTOJOIN +endif + irc9: irc9.c - $(CC) $(CFLAGS) -D_DARWIN_C_SOURCE -o $@ $< $(LDLIBS) + $(CC) $(CPPFLAGS) $(CFLAGS) -D_DARWIN_C_SOURCE -o $@ $< $(LDLIBS) + +install: irc9 + install -d "$(DESTDIR)$(BINDIR)" "$(DESTDIR)$(MANDIR)/man1" + install -m 755 irc9 "$(DESTDIR)$(BINDIR)/irc9" +# install -m 644 irc9.1 "$(DESTDIR)$(MANDIR)/man1/irc9.1" + +uninstall: + rm -f "$(DESTDIR)$(BINDIR)/irc9" +# rm -f "$(DESTDIR)$(MANDIR)/man1/irc9.1" clean: rm -f irc9 -.PHONY: clean +.PHONY: clean install uninstall diff --git a/README.md b/README.md index 88be67c..0f86ee7 100644 --- a/README.md +++ b/README.md @@ -57,10 +57,11 @@ TLS; use port `6697` for Libera and OFTC. A `sasl ` line applies to the most recent `server` line and enables SASL PLAIN for that server only. The SASL user is your account name (for many people this is the same as the nick). -Channels are never joined automatically. `channel` lines from older configs are -accepted but ignored; use `/join` after connecting. Blank lines and whole-line -comments starting with `#` are ignored — channel names can start with `#` -without being mistaken for comments. +To enable startup channel joins, build with `make -B AUTOJOIN=1`. Add one +`channel #name` line per channel below the corresponding `server` line. +irc9 sends the joins when that server first confirms registration. Default +builds ignore `channel` lines. Use `make -B` to rebuild with autojoin disabled. +Blank lines and whole-line comments starting with `#` are ignored. TLS certificates are verified against a system CA bundle when one is found. If no usable bundle is available, verification is disabled rather than diff --git a/irc9.c b/irc9.c index 7a8e857..47b2df9 100644 --- a/irc9.c +++ b/irc9.c @@ -71,6 +71,13 @@ typedef struct Window { Member *members; } Window; +#ifdef USE_AUTOJOIN +typedef struct AutojoinChannel { + char name[CHANLEN]; + struct AutojoinChannel *next; +} AutojoinChannel; +#endif + typedef struct Server { char host[HOSTLEN]; int port; @@ -95,6 +102,9 @@ typedef struct Server { char umode[32]; #ifdef USE_OPENSSL SSL *ssl; +#endif +#ifdef USE_AUTOJOIN + AutojoinChannel *autojoin; #endif struct Server *next; } Server; @@ -484,6 +494,9 @@ static void load_config(const char *path) char line[1024]; Server *last = NULL; +#ifdef USE_AUTOJOIN + AutojoinChannel **channel_tail = NULL; +#endif while (fgets(line, sizeof line, f)) { size_t n = strlen(line); while (n && (line[n - 1] == '\n' || line[n - 1] == '\r')) line[--n] = 0; @@ -520,6 +533,9 @@ static void load_config(const char *path) s->retry_at = 0; if (!servers) servers = s; else last->next = s; last = s; +#ifdef USE_AUTOJOIN + channel_tail = &s->autojoin; +#endif window_new(s, s->host, W_SERVER); } else if (strcasecmp(key, "sasl") == 0 && a1 && a2 && last) { snprintf(last->sasl_user, sizeof last->sasl_user, "%s", a1); @@ -530,7 +546,15 @@ static void load_config(const char *path) strip_formatting = !strcasecmp(a1, "on") || !strcasecmp(a1, "true") || !strcasecmp(a1, "yes") || strcmp(a1, "1") == 0; } else if (strcasecmp(key, "channel") == 0) { - /* Accepted for compatibility; join channels manually with /join. */ +#ifdef USE_AUTOJOIN + if (channel_tail && a1 && strlen(a1) < CHANLEN) { + AutojoinChannel *channel = xmalloc(sizeof *channel); + strcpy(channel->name, a1); + channel->next = NULL; + *channel_tail = channel; + channel_tail = &channel->next; + } +#endif } else { fprintf(stderr, "irc9: ignoring config line: %s\n", line); } @@ -1298,6 +1322,14 @@ static void handle_line(Server *s, char *line) if (strcmp(cmd, "001") == 0) { s->connected = 1; +#ifdef USE_AUTOJOIN + while (s->autojoin) { + AutojoinChannel *channel = s->autojoin; + sendf(s, "JOIN %s", channel->name); + s->autojoin = channel->next; + free(channel); + } +#endif appendf(sw, "%s", narg > 0 ? arg[narg - 1] : cmd); return; } @@ -2340,6 +2372,13 @@ int main(int argc, char **argv) if (s->ssl) SSL_free(s->ssl); #endif if (s->fd >= 0) close(s->fd); +#ifdef USE_AUTOJOIN + while (s->autojoin) { + AutojoinChannel *channel = s->autojoin; + s->autojoin = channel->next; + free(channel); + } +#endif free(s); s = sn; } diff --git a/irc9rc-example b/irc9rc-example index 971d11e..17c6d48 100644 --- a/irc9rc-example +++ b/irc9rc-example @@ -15,7 +15,8 @@ server irc.libera.chat 6697 ssl server irc.oftc.net 6697 ssl # sasl armin my-sasl-password -# channel lines are accepted for compatibility but ignored. Join manually. +# Build with make -B AUTOJOIN=1 and uncomment channel lines to join at startup. +# Each channel line applies to the server above it. # channel #linux # channel #c # channel #irc9