Channel autoconnect, installable using make and some fixes.
This commit is contained in:
parent
817ca368c7
commit
3cae7a8242
4 changed files with 66 additions and 8 deletions
21
Makefile
21
Makefile
|
|
@ -1,6 +1,10 @@
|
||||||
CC ?= cc
|
CC ?= cc
|
||||||
|
CFLAGS ?= -O2
|
||||||
CFLAGS ?= -O2 -Wall -Wextra -Wpedantic -pthread $(shell pkg-config --cflags ncurses 2>/dev/null)
|
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)
|
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)
|
HAVE_OPENSSL := $(shell pkg-config --exists openssl && echo yes)
|
||||||
ifeq ($(HAVE_OPENSSL),yes)
|
ifeq ($(HAVE_OPENSSL),yes)
|
||||||
|
|
@ -8,10 +12,23 @@ CFLAGS += -DUSE_OPENSSL $(shell pkg-config --cflags openssl)
|
||||||
LDLIBS += $(shell pkg-config --libs openssl)
|
LDLIBS += $(shell pkg-config --libs openssl)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(AUTOJOIN),1)
|
||||||
|
CPPFLAGS += -DUSE_AUTOJOIN
|
||||||
|
endif
|
||||||
|
|
||||||
irc9: irc9.c
|
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:
|
clean:
|
||||||
rm -f irc9
|
rm -f irc9
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean install uninstall
|
||||||
|
|
|
||||||
|
|
@ -57,10 +57,11 @@ TLS; use port `6697` for Libera and OFTC. A `sasl <user> <pass>` line applies to
|
||||||
the most recent `server` line and enables SASL PLAIN for that server only. The
|
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).
|
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
|
To enable startup channel joins, build with `make -B AUTOJOIN=1`. Add one
|
||||||
accepted but ignored; use `/join` after connecting. Blank lines and whole-line
|
`channel #name` line per channel below the corresponding `server` line.
|
||||||
comments starting with `#` are ignored — channel names can start with `#`
|
irc9 sends the joins when that server first confirms registration. Default
|
||||||
without being mistaken for comments.
|
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.
|
TLS certificates are verified against a system CA bundle when one is found.
|
||||||
If no usable bundle is available, verification is disabled rather than
|
If no usable bundle is available, verification is disabled rather than
|
||||||
|
|
|
||||||
41
irc9.c
41
irc9.c
|
|
@ -71,6 +71,13 @@ typedef struct Window {
|
||||||
Member *members;
|
Member *members;
|
||||||
} Window;
|
} Window;
|
||||||
|
|
||||||
|
#ifdef USE_AUTOJOIN
|
||||||
|
typedef struct AutojoinChannel {
|
||||||
|
char name[CHANLEN];
|
||||||
|
struct AutojoinChannel *next;
|
||||||
|
} AutojoinChannel;
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct Server {
|
typedef struct Server {
|
||||||
char host[HOSTLEN];
|
char host[HOSTLEN];
|
||||||
int port;
|
int port;
|
||||||
|
|
@ -95,6 +102,9 @@ typedef struct Server {
|
||||||
char umode[32];
|
char umode[32];
|
||||||
#ifdef USE_OPENSSL
|
#ifdef USE_OPENSSL
|
||||||
SSL *ssl;
|
SSL *ssl;
|
||||||
|
#endif
|
||||||
|
#ifdef USE_AUTOJOIN
|
||||||
|
AutojoinChannel *autojoin;
|
||||||
#endif
|
#endif
|
||||||
struct Server *next;
|
struct Server *next;
|
||||||
} Server;
|
} Server;
|
||||||
|
|
@ -484,6 +494,9 @@ static void load_config(const char *path)
|
||||||
|
|
||||||
char line[1024];
|
char line[1024];
|
||||||
Server *last = NULL;
|
Server *last = NULL;
|
||||||
|
#ifdef USE_AUTOJOIN
|
||||||
|
AutojoinChannel **channel_tail = NULL;
|
||||||
|
#endif
|
||||||
while (fgets(line, sizeof line, f)) {
|
while (fgets(line, sizeof line, f)) {
|
||||||
size_t n = strlen(line);
|
size_t n = strlen(line);
|
||||||
while (n && (line[n - 1] == '\n' || line[n - 1] == '\r')) line[--n] = 0;
|
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;
|
s->retry_at = 0;
|
||||||
if (!servers) servers = s; else last->next = s;
|
if (!servers) servers = s; else last->next = s;
|
||||||
last = s;
|
last = s;
|
||||||
|
#ifdef USE_AUTOJOIN
|
||||||
|
channel_tail = &s->autojoin;
|
||||||
|
#endif
|
||||||
window_new(s, s->host, W_SERVER);
|
window_new(s, s->host, W_SERVER);
|
||||||
} else if (strcasecmp(key, "sasl") == 0 && a1 && a2 && last) {
|
} else if (strcasecmp(key, "sasl") == 0 && a1 && a2 && last) {
|
||||||
snprintf(last->sasl_user, sizeof last->sasl_user, "%s", a1);
|
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") ||
|
strip_formatting = !strcasecmp(a1, "on") || !strcasecmp(a1, "true") ||
|
||||||
!strcasecmp(a1, "yes") || strcmp(a1, "1") == 0;
|
!strcasecmp(a1, "yes") || strcmp(a1, "1") == 0;
|
||||||
} else if (strcasecmp(key, "channel") == 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 {
|
} else {
|
||||||
fprintf(stderr, "irc9: ignoring config line: %s\n", line);
|
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) {
|
if (strcmp(cmd, "001") == 0) {
|
||||||
s->connected = 1;
|
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);
|
appendf(sw, "%s", narg > 0 ? arg[narg - 1] : cmd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -2340,6 +2372,13 @@ int main(int argc, char **argv)
|
||||||
if (s->ssl) SSL_free(s->ssl);
|
if (s->ssl) SSL_free(s->ssl);
|
||||||
#endif
|
#endif
|
||||||
if (s->fd >= 0) close(s->fd);
|
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);
|
free(s);
|
||||||
s = sn;
|
s = sn;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,8 @@ server irc.libera.chat 6697 ssl
|
||||||
server irc.oftc.net 6697 ssl
|
server irc.oftc.net 6697 ssl
|
||||||
# sasl armin my-sasl-password
|
# 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 #linux
|
||||||
# channel #c
|
# channel #c
|
||||||
# channel #irc9
|
# channel #irc9
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue