[wiki] [sites] update ii patch for ucspi support || Jan Klemkow

From: <git_AT_suckless.org>
Date: Fri, 21 Oct 2022 22:58:58 +0200

commit 73fd5cf216481bc5983e27d642fbe3ca432a1c8a
Author: Jan Klemkow <j.klemkow_AT_wemelug.de>
Date: Fri Oct 21 22:56:39 2022 +0200

    update ii patch for ucspi support

diff --git a/tools.suckless.org/ii/patches/ucspi/ii-2.0-ucspi.diff b/tools.suckless.org/ii/patches/ucspi/ii-2.0-ucspi.diff
new file mode 100644
index 00000000..ebaeaf1f
--- /dev/null
+++ b/tools.suckless.org/ii/patches/ucspi/ii-2.0-ucspi.diff
_AT_@ -0,0 +1,331 @@
+commit 42a582d675b09f387b154f8149c0c75e303955e0
+Author: Jan Klemkow <j.klemkow_AT_wemelug.de>
+Date: Sat Sep 2 12:36:34 2017 +0200
+
+ replace socket handling with ucspi backend
+
+diff --git a/ii.c b/ii.c
+index c402a87..193b0b9 100644
+--- a/ii.c
++++ b/ii.c
+_AT_@ -1,16 +1,13 @@
+ /* See LICENSE file for license details. */
+ #include <sys/select.h>
+-#include <sys/socket.h>
+ #include <sys/stat.h>
+ #include <sys/types.h>
+-#include <sys/un.h>
+
+ #include <ctype.h>
+ #include <errno.h>
+ #include <fcntl.h>
+ #include <limits.h>
+ #include <netdb.h>
+-#include <netinet/in.h>
+ #include <pwd.h>
+ #include <signal.h>
+ #include <stdarg.h>
+_AT_@ -20,6 +17,9 @@
+ #include <time.h>
+ #include <unistd.h>
+
++#define READ_FD 6
++#define WRITE_FD 7
++
+ char *argv0;
+
+ #include "arg.h"
+_AT_@ -59,16 +59,16 @@ static void create_dirtree(const char *);
+ static void create_filepath(char *, size_t, const char *, const char *, const char *);
+ static void die(const char *, ...);
+ static void ewritestr(int, const char *);
+-static void handle_channels_input(int, Channel *);
+-static void handle_server_output(int);
++static void handle_channels_input(Channel *);
++static void handle_server_output(void);
+ static int isnumeric(const char *);
+-static void loginkey(int, const char *);
+-static void loginuser(int, const char *, const char *);
+-static void proc_channels_input(int, Channel *, char *);
+-static void proc_channels_privmsg(int, Channel *, char *);
+-static void proc_server_cmd(int, char *);
++static void loginkey(const char *);
++static void loginuser(const char *, const char *);
++static void proc_channels_input(Channel *, char *);
++static void proc_channels_privmsg(Channel *, char *);
++static void proc_server_cmd(char *);
+ static int read_line(int, char *, size_t);
+-static void run(int, const char *);
++static void run(const char *);
+ static void setup(void);
+ static void sighandler(int);
+ static int tcpopen(const char *, const char *);
+_AT_@ -341,73 +341,19 @@ channel_leave(Channel *c)
+ }
+
+ static void
+-loginkey(int ircfd, const char *key)
++loginkey(const char *key)
+ {
+ snprintf(msg, sizeof(msg), "PASS %s
", key);
+- ewritestr(ircfd, msg);
++ ewritestr(WRITE_FD, msg);
+ }
+
+ static void
+-loginuser(int ircfd, const char *host, const char *fullname)
++loginuser(const char *host, const char *fullname)
+ {
+ snprintf(msg, sizeof(msg), "NICK %s
USER %s localhost %s :%s
",
+ nick, nick, host, fullname);
+ puts(msg);
+- ewritestr(ircfd, msg);
+-}
+-
+-static int
+-udsopen(const char *uds)
+-{
+- struct sockaddr_un sun;
+- size_t len;
+- int fd;
+-
+- if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
+- die("%s: socket: %s
", argv0, strerror(errno));
+-
+- sun.sun_family = AF_UNIX;
+- if (strlcpy(sun.sun_path, uds, sizeof(sun.sun_path)) >= sizeof(sun.sun_path))
+- die("%s: UNIX domain socket path truncation
", argv0);
+-
+- len = strlen(sun.sun_path) + 1 + sizeof(sun.sun_family);
+- if (connect(fd, (struct sockaddr *)&sun, len) == -1)
+- die("%s: connect: %s
", argv0, strerror(errno));
+-
+- return fd;
+-}
+-
+-static int
+-tcpopen(const char *host, const char *service)
+-{
+- struct addrinfo hints, *res = NULL, *rp;
+- int fd = -1, e;
+-
+- memset(&hints, 0, sizeof(hints));
+- hints.ai_family = AF_UNSPEC; /* allow IPv4 or IPv6 */
+- hints.ai_flags = AI_NUMERICSERV; /* avoid name lookup for port */
+- hints.ai_socktype = SOCK_STREAM;
+-
+- if ((e = getaddrinfo(host, service, &hints, &res)))
+- die("%s: getaddrinfo: %s
", argv0, gai_strerror(e));
+-
+- for (rp = res; rp; rp = rp->ai_next) {
+- fd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
+- if (fd == -1)
+- continue;
+- if (connect(fd, rp->ai_addr, rp->ai_addrlen) == -1) {
+- close(fd);
+- fd = -1;
+- continue;
+- }
+- break; /* success */
+- }
+- if (fd == -1)
+- die("%s: could not connect to %s:%s: %s
",
+- argv0, host, service, strerror(errno));
+-
+- freeaddrinfo(res);
+- return fd;
++ ewritestr(WRITE_FD, msg);
+ }
+
+ static int
+_AT_@ -459,16 +405,16 @@ channel_print(Channel *c, const char *buf)
+ }
+
+ static void
+-proc_channels_privmsg(int ircfd, Channel *c, char *buf)
++proc_channels_privmsg(Channel *c, char *buf)
+ {
+ snprintf(msg, sizeof(msg), "<%s> %s", nick, buf);
+ channel_print(c, msg);
+ snprintf(msg, sizeof(msg), "PRIVMSG %s :%s
", c->name, buf);
+- ewritestr(ircfd, msg);
++ ewritestr(WRITE_FD, msg);
+ }
+
+ static void
+-proc_channels_input(int ircfd, Channel *c, char *buf)
++proc_channels_input(Channel *c, char *buf)
+ {
+ char *p = NULL;
+ size_t buflen;
+_AT_@ -476,7 +422,7 @@ proc_channels_input(int ircfd, Channel *c, char *buf)
+ if (buf[0] == '+ return;
+ if (buf[0] != '/') {
+- proc_channels_privmsg(ircfd, c, buf);
++ proc_channels_privmsg(c, buf);
+ return;
+ }
+
+_AT_@ -501,7 +447,7 @@ proc_channels_input(int ircfd, Channel *c, char *buf)
+ channel_join(&buf[3]);
+ } else if (p) {
+ if ((c = channel_join(&buf[3])))
+- proc_channels_privmsg(ircfd, c, p + 1);
++ proc_channels_privmsg(c, p + 1);
+ return;
+ }
+ break;
+_AT_@ -533,7 +479,7 @@ proc_channels_input(int ircfd, Channel *c, char *buf)
+ else
+ snprintf(msg, sizeof(msg),
+ "PART %s :leaving
", c->name);
+- ewritestr(ircfd, msg);
++ ewritestr(WRITE_FD, msg);
+ channel_leave(c);
+ return;
+ break;
+_AT_@ -543,7 +489,7 @@ proc_channels_input(int ircfd, Channel *c, char *buf)
+ else
+ snprintf(msg, sizeof(msg),
+ "QUIT %s
", "bye");
+- ewritestr(ircfd, msg);
++ ewritestr(WRITE_FD, msg);
+ isrunning = 0;
+ return;
+ break;
+_AT_@ -556,11 +502,11 @@ proc_channels_input(int ircfd, Channel *c, char *buf)
+ snprintf(msg, sizeof(msg), "%s
", &buf[1]);
+ }
+ if (msg[0] != '+- ewritestr(ircfd, msg);
++ ewritestr(WRITE_FD, msg);
+ }
+
+ static void
+-proc_server_cmd(int fd, char *buf)
++proc_server_cmd(char *buf)
+ {
+ Channel *c;
+ const char *channel;
+_AT_@ -608,7 +554,7 @@ proc_server_cmd(int fd, char *buf)
+ return;
+ } else if (!strcmp("PING", argv[TOK_CMD])) {
+ snprintf(msg, sizeof(msg), "PONG %s
", argv[TOK_TEXT]);
+- ewritestr(fd, msg);
++ ewritestr(WRITE_FD, msg);
+ return;
+ } else if (!argv[TOK_NICKSRV] || !argv[TOK_USER]) {
+ /* server command */
+_AT_@ -695,7 +641,7 @@ read_line(int fd, char *buf, size_t bufsiz)
+ }
+
+ static void
+-handle_channels_input(int ircfd, Channel *c)
++handle_channels_input(Channel *c)
+ {
+ /*
+ * Do not allow to read this fully, since commands will be
+_AT_@ -711,20 +657,19 @@ handle_channels_input(int ircfd, Channel *c)
+ channel_rm(c);
+ return;
+ }
+- proc_channels_input(ircfd, c, buf);
++ proc_channels_input(c, buf);
+ }
+
+ static void
+-handle_server_output(int ircfd)
++handle_server_output(void)
+ {
+ char buf[IRC_MSG_MAX];
+
+- if (read_line(ircfd, buf, sizeof(buf)) == -1)
++ if (read_line(READ_FD, buf, sizeof(buf)) == -1)
+ die("%s: remote host closed connection: %s
", argv0, strerror(errno));
+-
+ fprintf(stdout, "%lu %s
", (unsigned long)time(NULL), buf);
+ fflush(stdout);
+- proc_server_cmd(ircfd, buf);
++ proc_server_cmd(buf);
+ }
+
+ static void
+_AT_@ -746,7 +691,7 @@ setup(void)
+ }
+
+ static void
+-run(int ircfd, const char *host)
++run(const char *host)
+ {
+ Channel *c, *tmp;
+ fd_set rdset;
+_AT_@ -756,9 +701,9 @@ run(int ircfd, const char *host)
+
+ snprintf(ping_msg, sizeof(ping_msg), "PING %s
", host);
+ while (isrunning) {
+- maxfd = ircfd;
++ maxfd = READ_FD;
+ FD_ZERO(&rdset);
+- FD_SET(ircfd, &rdset);
++ FD_SET(READ_FD, &rdset);
+ for (c = channels; c; c = c->next) {
+ if (c->fdin > maxfd)
+ maxfd = c->fdin;
+_AT_@ -777,17 +722,17 @@ run(int ircfd, const char *host)
+ cleanup();
+ exit(2); /* status code 2 for timeout */
+ }
+- ewritestr(ircfd, ping_msg);
++ ewritestr(WRITE_FD, ping_msg);
+ continue;
+ }
+- if (FD_ISSET(ircfd, &rdset)) {
+- handle_server_output(ircfd);
++ if (FD_ISSET(READ_FD, &rdset)) {
++ handle_server_output();
+ last_response = time(NULL);
+ }
+ for (c = channels; c; c = tmp) {
+ tmp = c->next;
+ if (FD_ISSET(c->fdin, &rdset))
+- handle_channels_input(ircfd, c);
++ handle_channels_input(c);
+ }
+ }
+ }
+_AT_@ -799,7 +744,7 @@ main(int argc, char *argv[])
+ const char *key = NULL, *fullname = NULL, *host = "";
+ const char *uds = NULL, *service = "6667";
+ char prefix[PATH_MAX];
+- int ircfd, r;
++ int r;
+
+ /* use nickname and home dir of user by default */
+ if (!(spw = getpwuid(getuid())))
+_AT_@ -838,11 +783,6 @@ main(int argc, char *argv[])
+ if (!*host)
+ usage();
+
+- if (uds)
+- ircfd = udsopen(uds);
+- else
+- ircfd = tcpopen(host, service);
+-
+ #ifdef __OpenBSD__
+ /* OpenBSD pledge(2) support */
+ if (pledge("stdio rpath wpath cpath dpath", NULL) == -1)
+_AT_@ -856,10 +796,10 @@ main(int argc, char *argv[])
+
+ channelmaster = channel_add(""); /* master channel */
+ if (key)
+- loginkey(ircfd, key);
+- loginuser(ircfd, host, fullname && *fullname ? fullname : nick);
++ loginkey(key);
++ loginuser(host, fullname && *fullname ? fullname : nick);
+ setup();
+- run(ircfd, host);
++ run(host);
+ cleanup();
+
+ return 0;
diff --git a/tools.suckless.org/ii/patches/ucspi/index.md b/tools.suckless.org/ii/patches/ucspi/index.md
index f487a9c4..61ddf68e 100644
--- a/tools.suckless.org/ii/patches/ucspi/index.md
+++ b/tools.suckless.org/ii/patches/ucspi/index.md
_AT__AT_ -11,9 +11,10 @@ socks](https://github.com/younix/ucspi).
 
 Download
 --------
+* [ii-2.0-ucspi.diff](ii-2.0-ucspi.diff)
 * [ii-1.8-ucspi.diff](ii-1.8-ucspi.diff)
 * [ii-1.7-ucspi.diff](ii-1.7-ucspi.diff)
 
 Author
 ------
-* Jan Klemkow (younix) <j.klemkow_AT_wemelug.de>
+* Jan Klemkow <j.klemkow_AT_wemelug.de>
Received on Fri Oct 21 2022 - 22:58:58 CEST

This archive was generated by hypermail 2.3.0 : Fri Oct 21 2022 - 23:00:51 CEST