From: Andrew Udvare <audvare@gmail.com>
Subject: [PATCH] Port to irssi 1.x and drop the vendored network-openssl.c

The plugin last built against irssi 0.8.x. irssi 1.0 renamed the glib-lookalike
input API and the SSL fields of SERVER_CONNECT_REC:

    g_input_add   -> i_input_add
    G_INPUT_READ  -> I_INPUT_READ
    conn->use_ssl -> conn->use_tls

The bigger problem was irssi/network-openssl.c, a 2017 copy of irssi's own
internal SSL code carried only to get at irssi_ssl_get_iochannel(), which irssi
does not export. It reads the pre-1.0 connrec->ssl_* fields and still uses the
OpenSSL 1.0 API (SSLv23_client_method, OpenSSL_add_all_algorithms), so it no
longer compiles and would need re-syncing with irssi forever.

irssi 1.2 added net_start_ssl(), a public mid-stream TLS upgrade used for IRCv3
STARTTLS, and it is exactly the operation this plugin needs:

    GIOChannel *net_start_ssl(SERVER_REC *server)
    {
        handle = net_sendbuffer_handle(server->handle);
        return irssi_ssl_get_iochannel(handle, server->connrec->port, server);
    }

So call that instead and drop the copy from the build. As a bonus the plugin no
longer links OpenSSL at all, and certificate verification now follows irssi's
own settings rather than the 2017 defaults baked into the copy. The unused
source file is left in the tree for upstream to delete.

Also stop forcing -Werror (new compilers warn on the SIGNAL_FUNC casts irssi
itself requires), honour caller CFLAGS/LDFLAGS, and use $(CC) rather than a
hardcoded gcc.

Upstream: https://github.com/phhusson/quassel-irssi (no activity since 2017-11)

diff --git a/core/Makefile b/core/Makefile
index c1c65fc..ca215c8 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -11,31 +11,29 @@ IRSSI_CFLAGS+=-I$(IRSSI_INCLUDE)/src/fe-common/
 IRSSI_CFLAGS+=-I$(IRSSI_INCLUDE)/src/fe-common/core/
 IRSSI_CFLAGS+=-I$(IRSSI_INCLUDE)/src/fe-text/
 IRSSI_CFLAGS+=$(shell pkg-config glib-2.0 --cflags)
-IRSSI_CFLAGS+=-DUOFF_T_LONG -fPIC -DHAVE_OPENSSL
-SSL_CFLAGS=$(shell pkg-config --cflags openssl)
-SSL_LDLAGS=$(shell pkg-config --libs openssl)
+IRSSI_CFLAGS+=-DUOFF_T_LONG -fPIC
 OBJECTS:=quasselc-connector.o quassel-core.o
 OBJECTS+=quassel-net.o quassel-msgs.o quassel-cmds.o
-OBJECTS+=irssi/network-openssl.o
 OBJECTS+=quassel-fe-window.o quassel-fe-level.o quassel-cfg.o
 
 LDFLAGS ?=
+LIBS =
 
 ifndef SYSTEM_QUASSELC
     QUASSELC_FLAGS:=-Ilib
+    # QuasselC's io.c is the only user of zlib.
+    LIBS += -lz
 else
     QUASSELC_FLAGS:=$(shell pkg-config --cflags quasselc)
-    LDFLAGS += -lquasselc
+    LIBS += $(shell pkg-config --libs quasselc)
 endif
 
-CFLAGS=-std=gnu11 -Wall -Wextra -Werror -g -O2 $(IRSSI_CFLAGS) $(QUASSELC_FLAGS) -Wmissing-prototypes -Wmissing-declarations
-
-CFLAGS += $(SSL_CFLAGS)
-LDFLAGS+= $(SSL_LDLAGS)
+CFLAGS ?= -g -O2
+CFLAGS += -std=gnu11 -Wall -Wextra $(IRSSI_CFLAGS) $(QUASSELC_FLAGS) -Wmissing-prototypes -Wmissing-declarations
 
 TARGET=libquassel_core.so
 
-all: libquassel_core.so
+all: $(TARGET)
 
 ifndef SYSTEM_QUASSELC
     LIBQUASSEL:=lib/cmds.o lib/display.o lib/io.o
@@ -44,12 +42,8 @@ ifndef SYSTEM_QUASSELC
     OBJECTS += $(LIBQUASSEL)
 endif
 
-irssi/network-openssl.o: CFLAGS:=$(IRSSI_CFLAGS)
-
-quasselc-connector.o: CFLAGS:=$(CFLAGS)
-
 $(TARGET): $(OBJECTS)
-	gcc -shared $^ -o $@ -lz $(LDFLAGS)
+	$(CC) -shared $(CFLAGS) $(LDFLAGS) $^ -o $@ $(LIBS)
 
 install: $(TARGET)
 	$(INSTALL) -d $(IRSSI_LIB)/modules
@@ -60,4 +54,4 @@ user_install: $(TARGET)
 	$(INSTALL) -m0644 libquassel_core.so $(HOME)/.irssi/modules/
 
 clean:
-	rm -f irssi/*.o lib/*.o *.o libquassel_core.so
+	rm -f lib/*.o *.o libquassel_core.so
diff --git a/core/quassel-net.c b/core/quassel-net.c
index 8a6eb55..7e9bcea 100644
--- a/core/quassel-net.c
+++ b/core/quassel-net.c
@@ -105,8 +105,8 @@ static void sig_connected(Quassel_SERVER_REC* r) {
 	}
 
 	r->readtag =
-		g_input_add(net_sendbuffer_handle(r->handle),
-			    G_INPUT_READ,
+		i_input_add(net_sendbuffer_handle(r->handle),
+			    I_INPUT_READ,
 			    (GInputFunction) quassel_parse_incoming, r);
 
 	quassel_init_packet(net_sendbuffer_handle(r->handle), r->ssl);
@@ -132,10 +132,10 @@ static SERVER_REC* quassel_server_init_connect(SERVER_CONNECT_REC* conn) {
 	ret->got = 0;
 	server_connect_ref(SERVER_CONNECT(conn));
 
-	if(conn->use_ssl) {
+	if(conn->use_tls) {
 		ret->ssl = 1;
 	}
-	ret->connrec->use_ssl = 0;
+	ret->connrec->use_tls = 0;
 
 	ret->channels_join = quassel_irssi_channels_join;
 	ret->send_message = quassel_irssi_send_message;
@@ -161,12 +161,11 @@ void quassel_net_init(CHAT_PROTOCOL_REC* rec) {
 	signal_add_first("server connected", (SIGNAL_FUNC) sig_connected);
 }
 
-GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, int port, SERVER_REC *server);
 void quassel_irssi_init_ack(void *arg) {
 	Quassel_SERVER_REC *server = (Quassel_SERVER_REC*)arg;
 	if(!server->ssl)
 		goto login;
-	GIOChannel* ssl_handle = irssi_ssl_get_iochannel(server->handle->handle, 1337, SERVER(server));
+	GIOChannel* ssl_handle = net_start_ssl(SERVER(server));
 	int error;
 	//That's polling, and that's really bad...
 	while( (error=irssi_ssl_handshake(ssl_handle)) & 1) {
