82 Commits
0.1 ... 1.1

Author SHA1 Message Date
6af1b812ae cleanup 2010-05-14 18:01:20 +01:00
75d42255f2 applied anonymous cleanup patch, thanks anonymous! 2010-04-17 11:12:54 +01:00
dad75aa6ba removed debug line 2010-03-23 18:00:37 +00:00
d78d10d1a1 bugfix 2010-03-22 13:29:33 +00:00
1a4256ef71 merged kris' changes into mainstream sic 2009-11-28 12:16:35 +00:00
9c7027fcbf applied clamiax' patch for null messages 2009-10-30 09:34:59 +00:00
7f1961d4c6 Update sic/util.c to match sic.c tip. 2009-09-23 12:52:13 -04:00
2b85380411 Update kris/util.c strlcpy 2009-09-23 11:26:48 -04:00
14e430ac5b added kris' sic.c and util.c temporarily, will need some time to see what will and won't be integrated into mainstream sic.c 2009-09-23 14:32:20 +01:00
261dc71e58 applied portions of Mark Edgars patch 2009-09-23 14:21:03 +01:00
4a4f924fee applied Martin Kopta's splint patch 2009-08-07 08:37:09 +01:00
b3ed5f414f thanks to Matthias-Christian Ott for this hint 2009-02-21 19:14:13 +00:00
ca6ba9a64a applied Jeroen Schot's patch 2009-02-14 11:53:47 +00:00
f3827eec2a applied Matthias-Christian Ott's remark about trailing newlines 2009-02-14 11:42:45 +00:00
8b2eeee541 Added tag 1.0 for changeset b8794f3ed15e 2008-07-29 19:22:08 +01:00
2a372e2df1 made Makefile consistent 2008-07-29 19:18:03 +01:00
888ab22725 updated LICENSE 2008-07-29 19:11:07 +01:00
8a58b25cb7 updated sic 2008-07-06 13:29:19 +01:00
589cce35c5 minor update 2008-07-02 21:29:57 +01:00
5463bed7ed updating copyright notice in sic as well 2007-04-13 11:50:51 +02:00
aa40ba1f3d applied a fix inspired by recent wmii commit 2007-02-21 11:00:12 +01:00
ef99e720ff removed LD as well, this is misleading 2007-02-14 10:05:41 +01:00
f9f6f8a19c Added tag 0.9 for changeset 96eb1bfede5b 2007-02-13 17:02:42 +01:00
82946e102d setting the topic must not be supported, its a trivial IRC command (*and rarely used btw*) 2007-02-13 16:14:52 +01:00
7ef7529687 I believe I have fixed the issue, why sic didn't handled PINGs correctly 2007-02-13 16:06:28 +01:00
bcda402396 fixed sic man page 2007-02-09 17:07:29 +01:00
1160be7ffa removed fullname, added support for tracking NICK changes 2007-02-09 16:16:06 +01:00
75f0af7c42 added eprint() 2007-02-09 16:04:49 +01:00
81238e16fe consistency patch 2007-02-09 15:40:58 +01:00
60fc462aa9 changing the special command operator 2007-02-09 15:18:08 +01:00
9b093ac5c6 removed debug output 2007-02-09 15:04:57 +01:00
264f8e9422 changed output 2007-02-09 15:02:56 +01:00
fe1e3560be small fix 2007-02-09 14:42:40 +01:00
1edd94af86 some changes 2007-02-09 14:40:11 +01:00
a3abf3b3ef Don't use sic's hg tip, it is broken atm... 2007-02-08 20:42:29 +01:00
e3cbbe71c2 adding debug support 2007-02-08 15:32:51 +01:00
93842a5fe0 fixed part message 2007-02-08 15:10:47 +01:00
1f1228547c small fix 2007-02-08 15:10:10 +01:00
ea71b6e88e small fix, don't write message to server if channel is not given 2007-02-08 15:03:42 +01:00
cb68ce9e2c some more simplifications 2007-02-08 14:51:04 +01:00
5569a14e8e testing some simplifications 2007-02-08 14:27:39 +01:00
2e945e48fb small changes, bigger simplifications are on its way 2007-02-06 16:42:17 +01:00
a63ccb4600 Added tag 0.8 for changeset 07fb3efaa2e9 2007-02-01 08:22:31 +01:00
0a903a0c79 using Tcmd successors more carefully 2007-01-31 11:01:34 +01:00
8edb0e23f4 Added tag 0.7 for changeset 643a6e8b8634 2007-01-11 11:44:41 +01:00
44e0417e14 applied some segfault patches of Adrien Krunch Kunysz (thanks to Adrien!) 2007-01-11 11:35:02 +01:00
148029905b V7 2006-12-14 16:52:12 +01:00
f8d2e7f236 fixed sizeof stuff 2006-11-26 15:53:33 +01:00
dc15c0d639 Added tag 0.6 for changeset d7923d9e717c1c6f1ed3b17ec90bfdd7e7bfcca0 2006-11-09 17:38:01 +01:00
73e181ce5b fixed a small grammar typo 2006-11-09 17:37:57 +01:00
9197fee8a9 new time info 2006-11-03 14:32:05 +01:00
45ff5ccf31 Added tag 0.5 for changeset 70d49a37b35695f2f771bddaf309f05ea60af8bc 2006-10-26 12:16:42 +02:00
fe306465d0 same problem in sic as in dmenu 2006-10-23 10:56:06 +02:00
1f3f048ab7 Added tag 0.4 for changeset a3549fb4c72ff0edb816c8c29be7ff289db5b003 2006-10-13 11:10:41 +02:00
3160fd2bed hotfix 2006-10-12 08:03:37 +02:00
560111d4ba hotfix 2006-10-11 18:23:03 +02:00
48fc6f1b10 removed useless crap 2006-10-09 18:01:26 +02:00
4120182a49 changed version 2006-10-09 07:28:43 +02:00
516c1cafaf fixed arg processing 2006-10-09 07:26:24 +02:00
3a24553892 code polishing, removed useless crap 2006-10-09 07:20:07 +02:00
83e05870ce small change to man page 2006-09-26 17:52:37 +02:00
089bad0eb0 updated README 2006-09-26 14:32:24 +02:00
1ad6394622 Added tag 0.3 for changeset d77f00af559258679a0fad5d264685d663e6975a 2006-09-26 14:27:34 +02:00
78e0c4f9ee new tag 2006-09-26 14:27:31 +02:00
b3412f0a14 new stuff 2006-09-26 14:24:26 +02:00
1230561e3d Added tag 0.3 for changeset dc05747ec127039afaa350094add73d151d17b72 2006-09-26 14:14:48 +02:00
b8950627a7 hotfix 2006-09-20 11:18:27 +02:00
5d19f0415e simplified sic 2006-09-19 16:54:52 +02:00
2c257c70bc fixed several annoyances 2006-09-05 09:47:15 +02:00
fb185a5e18 removed html crap 2006-09-05 07:32:24 +02:00
c9668b78f2 preparing new sic version 2006-09-05 07:31:46 +02:00
c2fcf48e6d applied Adriens patch 2006-09-04 08:54:14 +02:00
ee77b8efae Added tag 0.2 for changeset 56350a01f27753cfbdbb3dbc25f2a53dd4c2ac45 2006-07-21 21:12:33 +02:00
e9f9154ab7 made sic 0.2 2006-07-21 21:12:29 +02:00
9d87b90d50 fixed fullname handling in login 2006-07-21 15:46:05 +02:00
6255ad68d6 I don't care if irc server is truncated 2006-07-21 13:45:34 +02:00
348c5b3afc made more error safe 2006-07-21 10:05:51 +02:00
718c4bca32 removed dbeug 2006-07-21 08:36:20 +02:00
b1989c74e6 urgent fix 2006-07-21 08:28:25 +02:00
5b23d0e6b8 improved output printf's 2006-07-21 07:30:04 +02:00
a1237900a9 added sys/time.h inclusion 2006-07-20 17:27:30 +02:00
8693d1725f Added tag 0.1 for changeset de32c537aaf66554894712563ffba8d9bc4c2714 2006-07-20 10:45:51 +02:00
9 changed files with 284 additions and 391 deletions

10
.hgtags Normal file
View File

@ -0,0 +1,10 @@
de32c537aaf66554894712563ffba8d9bc4c2714 0.1
56350a01f27753cfbdbb3dbc25f2a53dd4c2ac45 0.2
d77f00af559258679a0fad5d264685d663e6975a 0.3
a3549fb4c72ff0edb816c8c29be7ff289db5b003 0.4
70d49a37b35695f2f771bddaf309f05ea60af8bc 0.5
d7923d9e717c1c6f1ed3b17ec90bfdd7e7bfcca0 0.6
643a6e8b8634b70d2459637fcfff6eca776fc919 0.7
07fb3efaa2e9ed18c6c16f0ddd8576cb66fec9c6 0.8
96eb1bfede5b72fcee3f515d3113d814f7e87108 0.9
b8794f3ed15e34b24ff9fb11c93a4405d0f91433 1.0

View File

@ -1,7 +1,9 @@
MIT/X Consortium License
(C)opyright MMV-MMVI Anselm R. Garbe <garbeam@gmail.com>
(C)opyright MMV Nico Golde <nico at ngolde dot de>
© 2005-2009 Anselm R Garbe <anselm@garbe.us>
© 2008-2009 Jeroen Schot <schot@a-eskwadraat.nl>
© 2007-2009 Kris Maglione <maglione.k@gmail.com>
© 2005 Nico Golde <nico at ngolde dot de>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),

View File

@ -1,19 +1,14 @@
# ii - irc it - simple but flexible IRC client
# (C)opyright MMV Anselm R. Garbe, Nico Golde
# sic - simple irc client
include config.mk
SRC = sic.c
OBJ = ${SRC:.c=.o}
MAN1 = sic.1
BIN = sic
all: options sic
@echo built sic
options:
@echo ii build options:
@echo "LIBS = ${LIBS}"
@echo sic build options:
@echo "CFLAGS = ${CFLAGS}"
@echo "LDFLAGS = ${LDFLAGS}"
@echo "CC = ${CC}"
@ -22,38 +17,38 @@ options:
@echo CC $<
@${CC} -c ${CFLAGS} $<
${OBJ}: config.mk
sic: ${OBJ}
@echo CC -o $@
@${CC} -o $@ ${OBJ} ${LDFLAGS}
clean:
rm -f sic *.o core sic-${VERSION}.tar.gz
@echo cleaning
@rm -f sic ${OBJ} sic-${VERSION}.tar.gz
dist: clean
@echo creating dist tarball
@mkdir -p sic-${VERSION}
@cp -R Makefile README LICENSE config.mk sic.c sic.1 sic-${VERSION}
@cp -R LICENSE Makefile README config.mk sic.1 ${SRC} sic-${VERSION}
@tar -cf sic-${VERSION}.tar sic-${VERSION}
@gzip sic-${VERSION}.tar
@rm -rf sic-${VERSION}
sic: ${OBJ}
@echo LD $@
@${CC} -o $@ ${OBJ} ${LDFLAGS}
install: all
@echo installing executable file to ${DESTDIR}${PREFIX}/bin
@mkdir -p ${DESTDIR}${PREFIX}/bin
@cp -f ${BIN} ${DESTDIR}${PREFIX}/bin
@for i in ${BIN}; do \
chmod 755 ${DESTDIR}${PREFIX}/bin/`basename $$i`; \
done
@echo installed executable files to ${DESTDIR}${PREFIX}/bin
@cp -f sic ${DESTDIR}${PREFIX}/bin
@chmod 755 ${DESTDIR}${PREFIX}/bin/sic
@echo installing manual page to ${DESTDIR}${MANPREFIX}/man1
@mkdir -p ${DESTDIR}${MANPREFIX}/man1
@cp -f ${MAN1} ${DESTDIR}${MANPREFIX}/man1
@for i in ${MAN1}; do \
chmod 444 ${DESTDIR}${MANPREFIX}/man1/`basename $$i`; \
done
@echo installed manual pages to ${DESTDIR}${MANPREFIX}/man1
@sed "s/VERSION/${VERSION}/g" < sic.1 > ${DESTDIR}${MANPREFIX}/man1/sic.1
@chmod 644 ${DESTDIR}${MANPREFIX}/man1/sic.1
uninstall:
for i in ${BIN}; do \
rm -f ${DESTDIR}${PREFIX}/bin/`basename $$i`; \
done
for i in ${MAN1}; do \
rm -f ${DESTDIR}${MANPREFIX}/man1/`basename $$i`; \
done
@echo removing executable file from ${DESTDIR}${PREFIX}/bin
@rm -f ${DESTDIR}${PREFIX}/bin/sic
@echo removing manual page from ${DESTDIR}${MANPREFIX}/man1
@rm -f ${DESTDIR}${MANPREFIX}/man1/sic.1
.PHONY: all options clean dist install uninstall

10
README
View File

@ -1,11 +1,11 @@
sic - simple irc client
-----------------------
=======================
sic is an extremly 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, that you don't have to switch
different channel buffers, that's actually a feature.
Installation
------------
Edit config.mk to match your local setup. sic is installed into
@ -16,11 +16,7 @@ Afterwards enter the following command to build and install sic
$ make clean install
Running sic
-----------
Simply invoke the 'sic' command with the required arguments.
Configuration
-------------
No configuration is needed.

View File

@ -1,18 +1,20 @@
# Customize to fit your system
# sic version
VERSION = 1.1
# Customize below to fit your system
# paths
PREFIX = /usr/local
MANPREFIX = ${PREFIX}/share/man
VERSION = 0.1
# includes and libs
LIBS = -L${PREFIX}/lib -L/usr/lib -lc
INCS = -I. -I/usr/include
LIBS = -L/usr/lib -lc
# compiler
CFLAGS = -Os -I${PREFIX}/include -I/usr/include \
-DVERSION=\"${VERSION}\"
LDFLAGS = ${LIBS}
#CFLAGS = -g -Wall -O2 -I${PREFIX}/include -I/usr/include \
# -DVERSION=\"${VERSION}\"
#LDFLAGS = -g ${LIBS}
# flags
CPPFLAGS = -DVERSION=\"${VERSION}\" -D_GNU_SOURCE
CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
LDFLAGS = -s ${LIBS}
# compiler and linker
CC = cc

46
sic.1
View File

@ -1,19 +1,12 @@
.TH SIC 1 sic-0.1
.TH SIC 1 sic-VERSION
.SH NAME
sic \- simple irc client
.SH SYNOPSIS
.B sic
.RB [ \-s
.IR server ]
.RB [ \-p
.IR port ]
.RB [ \-n
.IR nick ]
.RB [ \-k
.IR keyword ]
.RB [ \-f
.IR fullname ]
.RB \-v
.RB [ \-h " <host>"]
.RB [ \-p " <port>"]
.RB [ \-n " <nick>"]
.RB [ \-k " <keyword>"]
.RB [ \-v ]
.SH DESCRIPTION
.B sic
@ -23,39 +16,32 @@ also all channel traffic into one output, that you don't have to switch
different channel buffers, that's actually a feature.
.SH OPTIONS
.TP
.BI \-s " server"
Overrides the default server (irc.oftc.net)
.B \-h <host>
Overrides the default host (irc6.oftc.net)
.TP
.BI \-p " port"
.B \-p <port>
Overrides the default port (6667)
.TP
.BI \-n " nickname"
.B \-n <nickname>
Override the default nick ($USER)
.TP
.BI \-k " keyword"
Specifies the keyword to authenticate your nick on the server
.TP
.BI \-f " fullname"
Specify the real name (default is $USER)
.B \-k <keyword>
Specifies the keyword to authenticate your nick on the host
.TP
.BI \-v
Prints version information to standard output, then exits.
.SH COMMANDS
.TP
.BI /j " #channel "
.B :j #channel
Join a channel
.TP
.BI /l " #channel "
.B :l #channel
Leave a channel
.TP
.BI /m " #channel/user msg "
.B :m #channel/user msg
Write a message to #channel/user
.TP
.BI /s " #channel/user "
.B :s #channel/user
Set default channel/user
.TP
.BI /t " topic"
Set the channel topic
.TP
Everything which is not a command will simply be posted into the channel or to
the server.
Everything which is not a command is simply send the server.

413
sic.c
View File

@ -1,340 +1,207 @@
/*
* (C)opyright MMV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
* (C)opyright MMV-MMVI Nico Golde <nico at ngolde dot de>
* See LICENSE file for license details.
*/
/* See LICENSE file for license details. */
#include <ctype.h>
#include <errno.h>
#include <netdb.h>
#include <netinet/in.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <time.h>
#include <unistd.h>
#define PINGTIMEOUT 300
#define MAXMSG 4096
enum { Tnick, Tuser, Tcmd, Tchan, Targ, Ttext, Tlast };
static char *server = "irc.oftc.net";
static int port = 6667;
static char *nick = NULL;
static char *fullname = NULL;
static char *password = NULL;
static char bufin[MAXMSG], bufout[MAXMSG];
static char *host = "irc.oftc.net";
static char *port = "ircd";
static char *password;
static char nick[32];
static char bufin[4096];
static char bufout[4096];
static char channel[256];
static int srv;
static time_t trespond;
static FILE *srv;
static int
getline(int fd, unsigned int len, char *buf)
{
unsigned int i = 0;
char c;
do {
if(read(fd, &c, sizeof(char)) != sizeof(char))
return -1;
buf[i++] = c;
}
while(c != '\n' && i < len);
buf[i - 1] = 0;
return 0;
}
#include "util.c"
static void
pout(char *channel, char *msg)
{
pout(char *channel, char *fmt, ...) {
static char timestr[18];
time_t t = time(0);
time_t t;
va_list ap;
strftime(timestr, sizeof(timestr), "%a %R", localtime(&t));
fprintf(stdout, "%s: %s %s\n", channel, timestr, msg);
va_start(ap, fmt);
vsnprintf(bufout, sizeof bufout, fmt, ap);
va_end(ap);
t = time(NULL);
strftime(timestr, sizeof timestr, "%D %R", localtime(&t));
fprintf(stdout, "%-12s: %s %s\n", channel, timestr, bufout);
}
static void
privmsg(char *channel, char *msg)
{
snprintf(bufout, sizeof(bufout), "<%s> %s", nick, msg);
pout(channel, bufout);
snprintf(bufout, sizeof(bufout), "PRIVMSG %s :%s\r\n", channel, msg);
write(srv, bufout, strlen(bufout));
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
parsein(char *msg)
{
char *p;
if(msg[0] != '/') {
privmsg(channel, msg);
privmsg(char *channel, char *msg) {
if(channel[0] == '\0') {
pout("", "No channel to send to");
return;
}
if((p = strchr(&msg[3], ' ')))
*(p++) = 0;
switch (msg[1]) {
default:
snprintf(bufout, sizeof(bufout), "%s\r\n", &msg[1]);
break;
case 'j':
if(msg[3] == '#')
snprintf(bufout, sizeof(bufout), "JOIN %s\r\n", &msg[3]);
else if(p) {
privmsg(&msg[3], p + 1);
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] != ':') {
privmsg(channel, s);
return;
}
c = *++s;
if(c != '\0' && isspace(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 = "sic - 250 LOC are too much!";
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;
}
break;
case 'l':
if(p)
snprintf(bufout, sizeof(bufout), "PART %s :%s\r\n", &msg[3], p);
else
snprintf(bufout, sizeof(bufout), "PART %s :sic\r\n", &msg[3]);
break;
case 'm':
privmsg(&msg[3], p);
return;
case 's':
strncpy(channel, &msg[3], sizeof(channel));
return;
case 't':
snprintf(bufout, sizeof(bufout), "TOPIC %s :%s\r\n", &msg[3], p);
break;
}
write(srv, bufout, strlen(bufout));
}
static unsigned int
tokenize(char **result, unsigned int reslen, char *str, char delim)
{
char *p, *n;
unsigned int i = 0;
if(!str)
return 0;
for(n = str; *n == delim; n++);
p = n;
for(i = 0; *n != 0;) {
if(i == reslen)
return i;
if(*n == delim) {
*n = 0;
if(strlen(p))
result[i++] = p;
p = ++n;
} else
n++;
}
if((i < reslen) && (p < n) && strlen(p))
result[i++] = p;
return i; /* number of tokens */
sout("%s", s);
}
static void
parsesrv(char *msg)
{
char *argv[Tlast], *cmd, *p;
int i;
if(!msg || !(*msg))
parsesrv(char *cmd) {
char *usr, *par, *txt;
usr = host;
if(!cmd || !*cmd)
return;
for(i = 0; i < Tlast; i++)
argv[i] = NULL;
/*
<bufout> ::= [':' <prefix> <SPACE> ] <command> <params> <crlf>
<prefix> ::= <servername> | <nick> [ '!' <user> ] [ '@' <server> ]
<command> ::= <letter> { <letter> } | <number> <number> <number>
<SPACE> ::= ' ' { ' ' }
<params> ::= <SPACE> [ ':' <trailing> | <middle> <params> ]
<middle> ::= <Any *non-empty* sequence of octets not including SPACE
or NUL or CR or LF, the first of which may not be ':'>
<trailing> ::= <Any, possibly *empty*, sequence of octets not including NUL or CR or LF>
<crlf> ::= CR LF
*/
if(msg[0] == ':') { /* check prefix */
p = strchr(msg, ' ');
*p = 0;
for(++p; *p == ' '; p++);
cmd = p;
argv[Tnick] = &msg[1];
if((p = strchr(msg, '!'))) {
*p = 0;
argv[Tuser] = ++p;
}
} else
cmd = msg;
/* remove CRLFs */
for(p = cmd; p && *p != 0; p++)
if(*p == '\r' || *p == '\n')
*p = 0;
if((p = strchr(cmd, ':'))) {
*p = 0;
argv[Ttext] = ++p;
if(cmd[0] == ':') {
usr = cmd + 1;
cmd = skip(usr, ' ');
if(cmd[0] == '\0')
return;
skip(usr, '!');
}
tokenize(&argv[Tcmd], Tlast - Tcmd, cmd, ' ');
if(!strncmp("PONG", argv[Tcmd], 5)) {
skip(cmd, '\r');
par = skip(cmd, ' ');
txt = skip(par, ':');
trim(par);
if(!strcmp("PONG", cmd))
return;
} else if(!strncmp("PING", argv[Tcmd], 5)) {
snprintf(bufout, sizeof(bufout), "PONG %s\r\n", argv[Ttext]);
write(srv, bufout, strlen(bufout));
return;
} else if(!argv[Tnick] || !argv[Tuser]) { /* server command */
snprintf(bufout, sizeof(bufout), "%s", argv[Ttext] ? argv[Ttext] : "");
pout(server, bufout);
return;
} else if(!strncmp("ERROR", argv[Tcmd], 6))
snprintf(bufout, sizeof(bufout), "-!- error %s",
argv[Ttext] ? argv[Ttext] : "unknown");
else if(!strncmp("JOIN", argv[Tcmd], 5)) {
if(argv[Ttext]!=NULL){
p = strchr(argv[Ttext], ' ');
if(p)
*p = 0;
}
argv[Tchan] = argv[Ttext];
snprintf(bufout, sizeof(bufout), "-!- %s(%s) has joined %s",
argv[Tnick], argv[Tuser], argv[Ttext]);
} else if(!strncmp("PART", argv[Tcmd], 5)) {
snprintf(bufout, sizeof(bufout), "-!- %s(%s) has left %s",
argv[Tnick], argv[Tuser], argv[Tchan]);
} else if(!strncmp("MODE", argv[Tcmd], 5))
snprintf(bufout, sizeof(bufout), "-!- %s changed mode/%s -> %s %s",
argv[Tnick], argv[Tcmd + 1],
argv[Tcmd + 2], argv[Tcmd + 3]);
else if(!strncmp("QUIT", argv[Tcmd], 5))
snprintf(bufout, sizeof(bufout), "-!- %s(%s) has quit \"%s\"",
argv[Tnick], argv[Tuser],
argv[Ttext] ? argv[Ttext] : "");
else if(!strncmp("NICK", argv[Tcmd], 5))
snprintf(bufout, sizeof(bufout), "-!- %s changed nick to %s",
argv[Tnick], argv[Ttext]);
else if(!strncmp("TOPIC", argv[Tcmd], 6))
snprintf(bufout, sizeof(bufout), "-!- %s changed topic to \"%s\"",
argv[Tnick], argv[Ttext] ? argv[Ttext] : "");
else if(!strncmp("KICK", argv[Tcmd], 5))
snprintf(bufout, sizeof(bufout), "-!- %s kicked %s (\"%s\")",
argv[Tnick], argv[Targ],
argv[Ttext] ? argv[Ttext] : "");
else if(!strncmp("NOTICE", argv[Tcmd], 7))
snprintf(bufout, sizeof(bufout), "-!- \"%s\")",
argv[Ttext] ? argv[Ttext] : "");
else if(!strncmp("PRIVMSG", argv[Tcmd], 8)) snprintf(bufout, sizeof(bufout), "<%s> %s",
argv[Tnick], argv[Ttext] ? argv[Ttext] : "");
if(!argv[Tchan] || !strncmp(argv[Tchan], nick, strlen(nick)))
pout(argv[Tnick], bufout);
else
pout(argv[Tchan], bufout);
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);
}
}
int
main(int argc, char *argv[])
{
int i;
main(int argc, char *argv[]) {
int i, c;
struct timeval tv;
struct hostent *hp;
struct sockaddr_in addr = { 0 };
char ping[256];
const char *user = getenv("USER");
fd_set rd;
nick = fullname = getenv("USER");
for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) {
switch (argv[i][1]) {
default:
fputs("usage: sic [-s server] [-p port] [-n nick]"
" [-k keyword] [-f fullname] [-v]\n", stderr);
exit(EXIT_FAILURE);
break;
case 's':
server = argv[++i];
strlcpy(nick, user ? user : "unknown", sizeof nick);
for(i = 1; i < argc; i++) {
c = argv[i][1];
if(argv[i][0] != '-' || argv[i][2])
c = -1;
switch(c) {
case 'h':
if(++i < argc) host = argv[i];
break;
case 'p':
port = atoi(argv[++i]);
if(++i < argc) port = argv[i];
break;
case 'n':
nick = argv[++i];
if(++i < argc) strlcpy(nick, argv[i], sizeof nick);
break;
case 'k':
password = argv[++i];
break;
case 'f':
fullname = argv[++i];
if(++i < argc) password = argv[i];
break;
case 'v':
fputs("sic-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout);
exit(EXIT_SUCCESS);
break;
eprint("sic-"VERSION", © 2005-2009 Kris Maglione, Anselm R. Garbe, Nico Golde\n");
default:
eprint("usage: sic [-h host] [-p port] [-n nick] [-k keyword] [-v]\n");
}
}
/* init */
if((srv = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
fprintf(stderr, "sic: cannot connect server '%s'\n", server);
exit(EXIT_FAILURE);
}
hp = gethostbyname(server);
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
bcopy(hp->h_addr, &addr.sin_addr, hp->h_length);
if(connect(srv, (struct sockaddr *) &addr, sizeof(struct sockaddr_in))) {
close(srv);
fprintf(stderr, "sic: cannot connect server '%s'\n", server);
exit(EXIT_FAILURE);
}
i = dial(host, port);
srv = fdopen(i, "r+");
/* login */
if(password)
snprintf(bufout, sizeof(bufout),
"PASS %s\r\nNICK %s\r\nUSER %s localserver %s :%s\r\n",
password, nick, nick, server, fullname ? fullname : nick);
else
snprintf(bufout, sizeof(bufout), "NICK %s\r\nUSER %s localserver %s :%s\r\n",
nick, nick, server, fullname ? fullname : nick);
write(srv, bufout, strlen(bufout));
snprintf(ping, sizeof(ping), "PING %s\r\n", server);
channel[0] = 0;
setbuf(stdout, NULL); /* unbuffered stdout */
for(;;) {
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);
for(;;) { /* main loop */
FD_ZERO(&rd);
FD_SET(0, &rd);
FD_SET(srv, &rd);
FD_SET(fileno(srv), &rd);
tv.tv_sec = 120;
tv.tv_usec = 0;
i = select(srv + 1, &rd, 0, 0, &tv);
i = select(fileno(srv) + 1, &rd, 0, 0, &tv);
if(i < 0) {
if(errno == EINTR)
continue;
perror("sic: error on select()");
exit(EXIT_FAILURE);
} else if(i == 0) {
if(time(NULL) - trespond >= PINGTIMEOUT) {
pout(server, "-!- sic shutting down: parseing timeout");
exit(EXIT_FAILURE);
}
write(srv, ping, strlen(ping));
eprint("sic: error on select():");
}
else if(i == 0) {
if(time(NULL) - trespond >= 300)
eprint("sic shutting down: parse timeout\n");
sout("PING %s", host);
continue;
}
if(FD_ISSET(srv, &rd)) {
if(getline(srv, sizeof(bufin), bufin) == -1) {
perror("sic: remote server closed connection");
exit(EXIT_FAILURE);
}
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(getline(0, sizeof(bufin), bufin) == -1) {
perror("sic: broken pipe");
exit(EXIT_FAILURE);
}
if(fgets(bufin, sizeof bufin, stdin) == NULL)
eprint("sic: broken pipe\n");
parsein(bufin);
}
}
return 0;
}

View File

@ -1,39 +0,0 @@
<html>
<head>
<title>sic - simple irc client</title>
<meta name="author" content="Anselm R. Garbe">
<meta name="generator" content="ed">
<meta name="copyright" content="(C)opyright 2006 by Anselm R. Garbe">
<style type="text/css">
body {
color: #000000;
font-family: sans-serif;
margin: 20px 20px 20px 20px;
}
</style>
</head>
<body>
<center>
<h3>simple irc client</h3>
</center>
<h3>Description</h3>
<p>
sic is an extremly simple IRC client. It consists of lesser than 400 lines of code.
</p>
<ul>
<li><a href="http://10kloc.org/cgi-bin/man/man2html?query=sic">Man page</a></li>
</ul>
<h3>Download</h3>
<ul>
<li><a href="http://10kloc.org/download/sic-0.1.tar.gz">sic 0.1</a> (5kb) (20060720)</li>
</ul>
<h3>Development</h3>
<p>
You can <a href="http://10kloc.org/cgi-bin/hgwebdir.cgi/sic">browse</a> its source code repository or get a copy using <a href="http://www.selenic.com/mercurial/">Mercurial</a> with following command:
</p>
<p>
<code>hg clone http://10kloc.org/cgi-bin/hgwebdir.cgi/sic</code>
</p>
<p><small>--Anselm (20060719)</small></p>
</body>
</html>

74
util.c Normal file
View File

@ -0,0 +1,74 @@
/* See LICENSE file for license details. */
#include <netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>
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) {
static struct addrinfo hints;
int srv;
struct addrinfo *res, *r;
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((srv = socket(r->ai_family, r->ai_socktype, r->ai_protocol)) == -1)
continue;
if(connect(srv, r->ai_addr, r->ai_addrlen) == 0)
break;
close(srv);
}
freeaddrinfo(res);
if(!r)
eprint("error: cannot connect to host '%s'\n", host);
return srv;
}
#define strlcpy _strlcpy
static void
strlcpy(char *to, const char *from, int l) {
memccpy(to, from, '\0', l);
to[l-1] = '\0';
}
static char *
eat(char *s, int (*p)(int), int r) {
while(s != '\0' && p(*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;
e = s + strlen(s) - 1;
while(isspace(*e) && e > s)
e--;
*(e + 1) = '\0';
}