sic-1.3004075500000000000000000000000001431706722000107415ustar00rootwheelsic-1.3/LICENSE010064400000000000000000000023301431706722000120200ustar00rootwheelMIT/X Consortium License © 2005-2017 Anselm R Garbe © 2008-2009 Jeroen Schot © 2007-2009 Kris Maglione © 2005 Nico Golde Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. sic-1.3/Makefile010064400000000000000000000023221431706722000124540ustar00rootwheel.POSIX: NAME = sic VERSION = 1.3 # paths PREFIX = /usr/local MANPREFIX = ${PREFIX}/share/man # use system flags. SIC_CFLAGS = ${CFLAGS} SIC_LDFLAGS = ${LDFLAGS} SIC_CPPFLAGS = ${LDFLAGS} -DVERSION=\"${VERSION}\" -D_GNU_SOURCE BIN = sic SRC = ${BIN:=.c} OBJ = ${SRC:.c=.o} MAN1 = ${BIN:=.1} all: ${BIN} ${BIN}: ${@:=.o} ${OBJ}: config.h strlcpy.c util.c .o: ${CC} -o $@ $< ${SIC_LDFLAGS} .c.o: ${CC} -c ${SIC_CFLAGS} ${SIC_CPPFLAGS} -o $@ -c $< config.h: cp config.def.h $@ clean: rm -f ${BIN} ${OBJ} "${NAME}-${VERSION}.tar.gz" dist: mkdir -p "${NAME}-${VERSION}" cp -fR LICENSE Makefile README arg.h config.def.h \ ${MAN1} ${SRC} util.c strlcpy.c "${NAME}-${VERSION}" tar -cf - "${NAME}-${VERSION}" | \ gzip -c > "${NAME}-${VERSION}.tar.gz" rm -rf "${NAME}-${VERSION}" install: all mkdir -p ${DESTDIR}${PREFIX}/bin cp -f ${BIN} "${DESTDIR}${PREFIX}/bin" chmod 755 "${DESTDIR}${PREFIX}/bin/${BIN}" mkdir -p "${DESTDIR}${MANPREFIX}/man1" sed "s/VERSION/${VERSION}/g" < ${MAN1} > "${DESTDIR}${MANPREFIX}/man1/${MAN1}" chmod 644 "${DESTDIR}${MANPREFIX}/man1/${MAN1}" uninstall: rm -f \ "${DESTDIR}${PREFIX}/bin/${BIN}"\ "${DESTDIR}${MANPREFIX}/man1/${MAN1}" .PHONY: all clean dist install uninstall sic-1.3/README010064400000000000000000000012441431706722000116760ustar00rootwheelsic - simple irc client ======================= sic is an extremely fast, small and simple irc client. It reads commands from standard input and prints all server output to standard output. It multiplexes also all channel traffic into one output so that you don't have to switch different channel buffers: that's actually a feature. Installation ------------ Edit the Makefile or override the flags to match your local setup. sic is installed into /usr/local by default. Afterwards enter the following command to build and install sic (if necessary as root): $ make # make install Running sic ----------- Simply invoke the 'sic' command with the required arguments. sic-1.3/arg.h010064400000000000000000000023761431706722000117470ustar00rootwheel/* * Copy me if you can. * by 20h */ #ifndef ARG_H__ #define ARG_H__ extern char *argv0; /* use main(int argc, char *argv[]) */ #define ARGBEGIN for (argv0 = *argv, argv++, argc--;\ argv[0] && argv[0][1]\ && argv[0][0] == '-';\ argc--, argv++) {\ char argc_;\ char **argv_;\ int brk_;\ if (argv[0][1] == '-' && argv[0][2] == '\0') {\ argv++;\ argc--;\ break;\ }\ for (brk_ = 0, argv[0]++, argv_ = argv;\ argv[0][0] && !brk_;\ argv[0]++) {\ if (argv_ != argv)\ break;\ argc_ = argv[0][0];\ switch (argc_) /* Handles obsolete -NUM syntax */ #define ARGNUM case '0':\ case '1':\ case '2':\ case '3':\ case '4':\ case '5':\ case '6':\ case '7':\ case '8':\ case '9' #define ARGEND }\ } #define ARGC() argc_ #define ARGNUMF(base) (brk_ = 1, estrtol(argv[0], (base))) #define EARGF(x) ((argv[0][1] == '\0' && argv[1] == NULL)?\ ((x), abort(), (char *)0) :\ (brk_ = 1, (argv[0][1] != '\0')?\ (&argv[0][1]) :\ (argc--, argv++, argv[0]))) #define ARGF() ((argv[0][1] == '\0' && argv[1] == NULL)?\ (char *)0 :\ (brk_ = 1, (argv[0][1] != '\0')?\ (&argv[0][1]) :\ (argc--, argv++, argv[0]))) #endif sic-1.3/config.def.h010064400000000000000000000007171431706722000131750ustar00rootwheel/* Host used when "-h" is not given */ #define DEFAULT_HOST "irc.oftc.net" /* Port used when "-p" is not given */ #define DEFAULT_PORT "6667" /* Timestamp format; see strftime(3). */ #define TIMESTAMP_FORMAT "%Y-%m-%d %R" /* Command prefix character. In most IRC clients this is '/'. */ #define COMMAND_PREFIX_CHARACTER ':' /* Parting message used when none is specified with ":l ..." command. */ #define DEFAULT_PARTING_MESSAGE "sic - 250 LOC are too much!" sic-1.3/sic.1010064400000000000000000000020521431706722000116540ustar00rootwheel.TH SIC 1 sic-VERSION .SH NAME sic \- simple irc client .SH SYNOPSIS .B sic .RB [ \-h .IR host ] .RB [ \-p .IR port ] .RB [ \-n .IR nick ] .RB [ \-k .IR pass ] .RB [ \-v ] .SH DESCRIPTION .B sic is an extremely fast, small and simple irc client. It reads commands from standard input and prints all server output to standard output. It also multiplexes all channel traffic into one output. That way you don't have to switch different channel buffers. So that's actually a feature. .SH OPTIONS .TP .BI \-h " host" Overrides the default host (irc.oftc.net) .TP .BI \-p " port" Overrides the default port (6667) .TP .BI \-n " nick" Override the default nick ($USER) .TP .BI \-k " pass" Specifies the PASS connection password .TP .B \-v Prints version information to stderr, then exits .SH COMMANDS .TP .BI :j " #channel" Join a channel .TP .BI :l " #channel" Leave a channel .TP .BI :m " #channel/user message" Send a message to channel or user .TP .BI :s " #channel/user" Set default channel or user .TP .BI : command Any line beginning with .B : is sent as a command sic-1.3/sic.c010064400000000000000000000104511431706722000117400ustar00rootwheel /* See LICENSE file for license details. */ #include #include #include #include #include #include #include #include #include #include "arg.h" #include "config.h" char *argv0; static char *host = DEFAULT_HOST; static char *port = DEFAULT_PORT; static char *password; static char nick[32]; static char bufin[4096]; static char bufout[4096]; static char channel[256]; static time_t trespond; static FILE *srv; #undef strlcpy #include "strlcpy.c" #include "util.c" static void pout(char *channel, char *fmt, ...) { static char timestr[80]; time_t t; va_list ap; va_start(ap, fmt); vsnprintf(bufout, sizeof bufout, fmt, ap); va_end(ap); t = time(NULL); strftime(timestr, sizeof timestr, TIMESTAMP_FORMAT, localtime(&t)); fprintf(stdout, "%-12s: %s %s\n", channel, timestr, bufout); } static void sout(char *fmt, ...) { va_list ap; va_start(ap, fmt); vsnprintf(bufout, sizeof bufout, fmt, ap); va_end(ap); fprintf(srv, "%s\r\n", bufout); } static void privmsg(char *channel, char *msg) { if(channel[0] == '\0') { pout("", "No channel to send to"); return; } pout(channel, "<%s> %s", nick, msg); sout("PRIVMSG %s :%s", channel, msg); } static void parsein(char *s) { char c, *p; if(s[0] == '\0') return; skip(s, '\n'); if(s[0] != COMMAND_PREFIX_CHARACTER) { privmsg(channel, s); return; } c = *++s; if(c != '\0' && isspace((unsigned char)s[1])) { p = s + 2; switch(c) { case 'j': sout("JOIN %s", p); if(channel[0] == '\0') strlcpy(channel, p, sizeof channel); return; case 'l': s = eat(p, isspace, 1); p = eat(s, isspace, 0); if(!*s) s = channel; if(*p) *p++ = '\0'; if(!*p) p = DEFAULT_PARTING_MESSAGE; sout("PART %s :%s", s, p); return; case 'm': s = eat(p, isspace, 1); p = eat(s, isspace, 0); if(*p) *p++ = '\0'; privmsg(s, p); return; case 's': strlcpy(channel, p, sizeof channel); return; } } sout("%s", s); } static void parsesrv(char *cmd) { char *usr, *par, *txt; usr = host; if(!cmd || !*cmd) return; if(cmd[0] == ':') { usr = cmd + 1; cmd = skip(usr, ' '); if(cmd[0] == '\0') return; skip(usr, '!'); } skip(cmd, '\r'); par = skip(cmd, ' '); txt = skip(par, ':'); trim(par); if(!strcmp("PONG", cmd)) return; if(!strcmp("PRIVMSG", cmd)) pout(par, "<%s> %s", usr, txt); else if(!strcmp("PING", cmd)) sout("PONG %s", txt); else { pout(usr, ">< %s (%s): %s", cmd, par, txt); if(!strcmp("NICK", cmd) && !strcmp(usr, nick)) strlcpy(nick, txt, sizeof nick); } } static void usage(void) { eprint("usage: sic [-h host] [-p port] [-n nick] [-k keyword] [-v]\n", argv0); } int main(int argc, char *argv[]) { struct timeval tv; const char *user = getenv("USER"); int n; fd_set rd; strlcpy(nick, user ? user : "unknown", sizeof nick); ARGBEGIN { case 'h': host = EARGF(usage()); break; case 'p': port = EARGF(usage()); break; case 'n': strlcpy(nick, EARGF(usage()), sizeof nick); break; case 'k': password = EARGF(usage()); break; case 'v': eprint("sic-"VERSION", © 2005-2014 Kris Maglione, Anselm R. Garbe, Nico Golde\n"); break; default: usage(); } ARGEND; /* init */ srv = fdopen(dial(host, port), "r+"); if (!srv) eprint("fdopen:"); /* login */ if(password) sout("PASS %s", password); sout("NICK %s", nick); sout("USER %s localhost %s :%s", nick, host, nick); fflush(srv); setbuf(stdout, NULL); setbuf(srv, NULL); setbuf(stdin, NULL); #ifdef __OpenBSD__ if (pledge("stdio", NULL) == -1) eprint("error: pledge:"); #endif for(;;) { /* main loop */ FD_ZERO(&rd); FD_SET(0, &rd); FD_SET(fileno(srv), &rd); tv.tv_sec = 120; tv.tv_usec = 0; n = select(fileno(srv) + 1, &rd, 0, 0, &tv); if(n < 0) { if(errno == EINTR) continue; eprint("sic: error on select():"); } else if(n == 0) { if(time(NULL) - trespond >= 300) eprint("sic shutting down: parse timeout\n"); sout("PING %s", host); continue; } if(FD_ISSET(fileno(srv), &rd)) { if(fgets(bufin, sizeof bufin, srv) == NULL) eprint("sic: remote host closed connection\n"); parsesrv(bufin); trespond = time(NULL); } if(FD_ISSET(0, &rd)) { if(fgets(bufin, sizeof bufin, stdin) == NULL) eprint("sic: broken pipe\n"); parsein(bufin); } } return 0; } sic-1.3/util.c010064400000000000000000000025041431706722000121370ustar00rootwheel/* See LICENSE file for license details. */ #include #include #include static void eprint(const char *fmt, ...) { va_list ap; va_start(ap, fmt); vsnprintf(bufout, sizeof bufout, fmt, ap); va_end(ap); fprintf(stderr, "%s", bufout); if(fmt[0] && fmt[strlen(fmt) - 1] == ':') fprintf(stderr, " %s\n", strerror(errno)); exit(1); } static int dial(char *host, char *port) { struct addrinfo hints; struct addrinfo *res, *r; int fd; memset(&hints, 0, sizeof hints); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; if(getaddrinfo(host, port, &hints, &res) != 0) eprint("error: cannot resolve hostname '%s':", host); for(r = res; r; r = r->ai_next) { if((fd = socket(r->ai_family, r->ai_socktype, r->ai_protocol)) == -1) continue; if(connect(fd, r->ai_addr, r->ai_addrlen) == 0) break; close(fd); } freeaddrinfo(res); if(!r) eprint("error: cannot connect to host '%s'\n", host); return fd; } static char * eat(char *s, int (*p)(int), int r) { while(*s != '\0' && p((unsigned char)*s) == r) s++; return s; } static char* skip(char *s, char c) { while(*s != c && *s != '\0') s++; if(*s != '\0') *s++ = '\0'; return s; } static void trim(char *s) { char *e; for (e = s + strlen(s); e > s && isspace((unsigned char)*(e - 1)); e--) ; *e = '\0'; } sic-1.3/strlcpy.c010064400000000000000000000027171431706722000126700ustar00rootwheel/* * Copyright (c) 1998 Todd C. Miller * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include /* * Copy src to string dst of size siz. At most siz-1 characters * will be copied. Always NUL terminates (unless siz == 0). * Returns strlen(src); if retval >= siz, truncation occurred. */ size_t strlcpy(char *dst, const char *src, size_t siz) { char *d = dst; const char *s = src; size_t n = siz; /* Copy as many bytes as will fit */ if (n != 0) { while (--n != 0) { if ((*d++ = *s++) == '\0') break; } } /* Not enough room in dst, add NUL and traverse rest of src */ if (n == 0) { if (siz != 0) *d = '\0'; /* NUL-terminate dst */ while (*s++) ; } return(s - src - 1); /* count does not include NUL */ }