Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
2a372e2df1 | ||
![]() |
888ab22725 | ||
![]() |
8a58b25cb7 | ||
![]() |
589cce35c5 | ||
![]() |
5463bed7ed | ||
![]() |
aa40ba1f3d | ||
![]() |
ef99e720ff | ||
![]() |
f9f6f8a19c |
1
.hgtags
1
.hgtags
@@ -6,3 +6,4 @@ a3549fb4c72ff0edb816c8c29be7ff289db5b003 0.4
|
|||||||
d7923d9e717c1c6f1ed3b17ec90bfdd7e7bfcca0 0.6
|
d7923d9e717c1c6f1ed3b17ec90bfdd7e7bfcca0 0.6
|
||||||
643a6e8b8634b70d2459637fcfff6eca776fc919 0.7
|
643a6e8b8634b70d2459637fcfff6eca776fc919 0.7
|
||||||
07fb3efaa2e9ed18c6c16f0ddd8576cb66fec9c6 0.8
|
07fb3efaa2e9ed18c6c16f0ddd8576cb66fec9c6 0.8
|
||||||
|
96eb1bfede5b72fcee3f515d3113d814f7e87108 0.9
|
||||||
|
4
LICENSE
4
LICENSE
@@ -1,7 +1,7 @@
|
|||||||
MIT/X Consortium License
|
MIT/X Consortium License
|
||||||
|
|
||||||
(C)opyright MMV-MMVI Anselm R. Garbe <garbeam@gmail.com>
|
© 2005-2008 Anselm R Garbe <garbeam at gmail dot com>
|
||||||
(C)opyright MMV Nico Golde <nico at ngolde dot de>
|
© 2005 Nico Golde <nico at ngolde dot de>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
copy of this software and associated documentation files (the "Software"),
|
copy of this software and associated documentation files (the "Software"),
|
||||||
|
9
Makefile
9
Makefile
@@ -1,5 +1,4 @@
|
|||||||
# sic - simple irc client
|
# sic - simple irc client
|
||||||
# (C)opyright MMVI Anselm R. Garbe
|
|
||||||
|
|
||||||
include config.mk
|
include config.mk
|
||||||
|
|
||||||
@@ -13,7 +12,6 @@ options:
|
|||||||
@echo "CFLAGS = ${CFLAGS}"
|
@echo "CFLAGS = ${CFLAGS}"
|
||||||
@echo "LDFLAGS = ${LDFLAGS}"
|
@echo "LDFLAGS = ${LDFLAGS}"
|
||||||
@echo "CC = ${CC}"
|
@echo "CC = ${CC}"
|
||||||
@echo "LD = ${LD}"
|
|
||||||
|
|
||||||
.c.o:
|
.c.o:
|
||||||
@echo CC $<
|
@echo CC $<
|
||||||
@@ -22,9 +20,8 @@ options:
|
|||||||
${OBJ}: config.mk
|
${OBJ}: config.mk
|
||||||
|
|
||||||
sic: ${OBJ}
|
sic: ${OBJ}
|
||||||
@echo LD $@
|
@echo CC -o $@
|
||||||
@${LD} -o $@ ${OBJ} ${LDFLAGS}
|
@${CC} -o $@ ${OBJ} ${LDFLAGS}
|
||||||
@strip $@
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@echo cleaning
|
@echo cleaning
|
||||||
@@ -45,7 +42,7 @@ install: all
|
|||||||
@chmod 755 ${DESTDIR}${PREFIX}/bin/sic
|
@chmod 755 ${DESTDIR}${PREFIX}/bin/sic
|
||||||
@echo installing manual page to ${DESTDIR}${MANPREFIX}/man1
|
@echo installing manual page to ${DESTDIR}${MANPREFIX}/man1
|
||||||
@mkdir -p ${DESTDIR}${MANPREFIX}/man1
|
@mkdir -p ${DESTDIR}${MANPREFIX}/man1
|
||||||
@sed 's/VERSION/${VERSION}/g' < sic.1 > ${DESTDIR}${MANPREFIX}/man1/sic.1
|
@sed "s/VERSION/${VERSION}/g" < sic.1 > ${DESTDIR}${MANPREFIX}/man1/sic.1
|
||||||
@chmod 644 ${DESTDIR}${MANPREFIX}/man1/sic.1
|
@chmod 644 ${DESTDIR}${MANPREFIX}/man1/sic.1
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
|
10
config.mk
10
config.mk
@@ -1,5 +1,5 @@
|
|||||||
# sic version
|
# sic version
|
||||||
VERSION = 0.9
|
VERSION = 1.0
|
||||||
|
|
||||||
# Customize below to fit your system
|
# Customize below to fit your system
|
||||||
|
|
||||||
@@ -12,11 +12,9 @@ INCS = -I. -I/usr/include
|
|||||||
LIBS = -L/usr/lib -lc
|
LIBS = -L/usr/lib -lc
|
||||||
|
|
||||||
# flags
|
# flags
|
||||||
CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\"
|
CPPFLAGS = -DVERSION=\"${VERSION}\" -D_GNU_SOURCE
|
||||||
LDFLAGS = ${LIBS}
|
CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
|
||||||
#CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\"
|
LDFLAGS = -s ${LIBS}
|
||||||
#LDFLAGS = -g ${LIBS}
|
|
||||||
|
|
||||||
# compiler and linker
|
# compiler and linker
|
||||||
CC = cc
|
CC = cc
|
||||||
LD = ${CC}
|
|
||||||
|
95
sic.c
95
sic.c
@@ -1,7 +1,6 @@
|
|||||||
/* (C)opyright MMV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
|
/* © 2005-2008 Anselm R Garbe <garbeam at gmail dot com>
|
||||||
* (C)opyright MMV-MMVI Nico Golde <nico at ngolde dot de>
|
* © 2005 Nico Golde <nico at ngolde dot de>
|
||||||
* See LICENSE file for license details.
|
* See LICENSE file for license details. */
|
||||||
*/
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
@@ -15,7 +14,14 @@
|
|||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
#define PINGTIMEOUT 300
|
#define PINGTIMEOUT 300
|
||||||
#define MAXMSG 4096
|
#define MAXMSG 4096
|
||||||
|
|
||||||
|
static void die(const char *errstr, ...);
|
||||||
|
static void printl(char *channel, char *msg);
|
||||||
|
static void privmsg(char *channel, char *msg);
|
||||||
|
static void parsein(char *msg);
|
||||||
|
static void parsesrv(char *msg);
|
||||||
|
static int readl(int fd, unsigned int len, char *buf);
|
||||||
|
|
||||||
static char *host = "irc.oftc.net";
|
static char *host = "irc.oftc.net";
|
||||||
static unsigned short port = 6667;
|
static unsigned short port = 6667;
|
||||||
@@ -27,8 +33,8 @@ static char channel[256];
|
|||||||
static int srv;
|
static int srv;
|
||||||
static time_t trespond;
|
static time_t trespond;
|
||||||
|
|
||||||
static void
|
void
|
||||||
eprint(const char *errstr, ...) {
|
die(const char *errstr, ...) {
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, errstr);
|
va_start(ap, errstr);
|
||||||
@@ -37,23 +43,8 @@ eprint(const char *errstr, ...) {
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
void
|
||||||
getline(int fd, unsigned int len, char *buf) {
|
printl(char *channel, char *msg) {
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
pout(char *channel, char *msg) {
|
|
||||||
static char timestr[18];
|
static char timestr[18];
|
||||||
time_t t = time(0);
|
time_t t = time(0);
|
||||||
|
|
||||||
@@ -61,17 +52,17 @@ pout(char *channel, char *msg) {
|
|||||||
fprintf(stdout, "%-12.12s: %s %s\n", channel, timestr, msg);
|
fprintf(stdout, "%-12.12s: %s %s\n", channel, timestr, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
void
|
||||||
privmsg(char *channel, char *msg) {
|
privmsg(char *channel, char *msg) {
|
||||||
if(channel[0] == 0)
|
if(channel[0] == 0)
|
||||||
return;
|
return;
|
||||||
snprintf(bufout, sizeof bufout, "<%s> %s", nick, msg);
|
snprintf(bufout, sizeof bufout, "<%s> %s", nick, msg);
|
||||||
pout(channel, bufout);
|
printl(channel, bufout);
|
||||||
snprintf(bufout, sizeof bufout, "PRIVMSG %s :%s\r\n", channel, msg);
|
snprintf(bufout, sizeof bufout, "PRIVMSG %s :%s\r\n", channel, msg);
|
||||||
write(srv, bufout, strlen(bufout));
|
write(srv, bufout, strlen(bufout));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
void
|
||||||
parsein(char *msg) {
|
parsein(char *msg) {
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
@@ -100,7 +91,7 @@ parsein(char *msg) {
|
|||||||
write(srv, bufout, strlen(bufout));
|
write(srv, bufout, strlen(bufout));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
void
|
||||||
parsesrv(char *msg) {
|
parsesrv(char *msg) {
|
||||||
char *chan, *cmd, *p, *txt, *usr;
|
char *chan, *cmd, *p, *txt, *usr;
|
||||||
|
|
||||||
@@ -136,7 +127,7 @@ parsesrv(char *msg) {
|
|||||||
for(; *p && *p != ' '; p++);
|
for(; *p && *p != ' '; p++);
|
||||||
*p = 0;
|
*p = 0;
|
||||||
snprintf(bufout, sizeof bufout, "<%s> %s", usr, txt);
|
snprintf(bufout, sizeof bufout, "<%s> %s", usr, txt);
|
||||||
pout(chan, bufout);
|
printl(chan, bufout);
|
||||||
}
|
}
|
||||||
else if(!strncmp("PING", cmd, 4) && txt) {
|
else if(!strncmp("PING", cmd, 4) && txt) {
|
||||||
snprintf(bufout, sizeof bufout, "PONG %s\r\n", txt);
|
snprintf(bufout, sizeof bufout, "PONG %s\r\n", txt);
|
||||||
@@ -144,12 +135,28 @@ parsesrv(char *msg) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
snprintf(bufout, sizeof bufout, ">< %s: %s", cmd, txt ? txt : "");
|
snprintf(bufout, sizeof bufout, ">< %s: %s", cmd, txt ? txt : "");
|
||||||
pout(usr, bufout);
|
printl(usr, bufout);
|
||||||
if(!strncmp("NICK", cmd, 4) && !strncmp(usr, nick, sizeof nick) && txt)
|
if(!strncmp("NICK", cmd, 4) && !strncmp(usr, nick, sizeof nick) && txt)
|
||||||
strncpy(nick, txt, sizeof nick);
|
strncpy(nick, txt, sizeof nick);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
readl(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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[]) {
|
main(int argc, char *argv[]) {
|
||||||
int i;
|
int i;
|
||||||
@@ -174,30 +181,30 @@ main(int argc, char *argv[]) {
|
|||||||
if(++i < argc) password = argv[i];
|
if(++i < argc) password = argv[i];
|
||||||
}
|
}
|
||||||
else if(!strncmp(argv[i], "-v", 3))
|
else if(!strncmp(argv[i], "-v", 3))
|
||||||
eprint("sic-"VERSION", (C)opyright MMVI Anselm R. Garbe\n");
|
die("sic-"VERSION", © 2005-2008 Anselm R Garbe, Nico Golde\n");
|
||||||
else
|
else
|
||||||
eprint("usage: sic [-h host] [-p port] [-n nick] [-k keyword] [-v]\n");
|
die("usage: sic [-h host] [-p port] [-n nick] [-k keyword] [-v]\n");
|
||||||
|
|
||||||
/* init */
|
/* init */
|
||||||
if((srv = socket(AF_INET, SOCK_STREAM, 0)) < 0)
|
if((srv = socket(AF_INET, SOCK_STREAM, 0)) < 0)
|
||||||
eprint("sic: cannot connect host '%s'\n", host);
|
die("error: cannot connect host '%s'\n", host);
|
||||||
if(NULL == (hp = gethostbyname(host)))
|
if(NULL == (hp = gethostbyname(host)))
|
||||||
eprint("sic: cannot resolve hostname '%s'\n", host);
|
die("error: cannot resolve hostname '%s'\n", host);
|
||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
addr.sin_port = htons(port);
|
addr.sin_port = htons(port);
|
||||||
memcpy(&addr.sin_addr, hp->h_addr, hp->h_length);
|
memcpy(&addr.sin_addr, hp->h_addr, hp->h_length);
|
||||||
if(connect(srv, (struct sockaddr *) &addr, sizeof(struct sockaddr_in))) {
|
if(connect(srv, (struct sockaddr *) &addr, sizeof(struct sockaddr_in))) {
|
||||||
close(srv);
|
close(srv);
|
||||||
eprint("sic: cannot connect host '%s'\n", host);
|
die("error: cannot connect host '%s'\n", host);
|
||||||
}
|
}
|
||||||
/* login */
|
/* login */
|
||||||
if(password)
|
if(password)
|
||||||
snprintf(bufout, sizeof bufout,
|
snprintf(bufout, sizeof bufout,
|
||||||
"PASS %s\r\nNICK %s\r\nUSER %s localhost %s :%s\r\n",
|
"PASS %s\r\nNICK %s\r\nUSER %s localhost %s :%s\r\n",
|
||||||
password, nick, nick, host, nick);
|
password, nick, nick, host, nick);
|
||||||
else
|
else
|
||||||
snprintf(bufout, sizeof bufout, "NICK %s\r\nUSER %s localhost %s :%s\r\n",
|
snprintf(bufout, sizeof bufout, "NICK %s\r\nUSER %s localhost %s :%s\r\n",
|
||||||
nick, nick, host, nick);
|
nick, nick, host, nick);
|
||||||
write(srv, bufout, strlen(bufout));
|
write(srv, bufout, strlen(bufout));
|
||||||
snprintf(ping, sizeof ping, "PING %s\r\n", host);
|
snprintf(ping, sizeof ping, "PING %s\r\n", host);
|
||||||
channel[0] = 0;
|
channel[0] = 0;
|
||||||
@@ -213,23 +220,23 @@ main(int argc, char *argv[]) {
|
|||||||
if(i < 0) {
|
if(i < 0) {
|
||||||
if(errno == EINTR)
|
if(errno == EINTR)
|
||||||
continue;
|
continue;
|
||||||
eprint("sic: error on select()");
|
die("error: error on select()");
|
||||||
}
|
}
|
||||||
else if(i == 0) {
|
else if(i == 0) {
|
||||||
if(time(NULL) - trespond >= PINGTIMEOUT)
|
if(time(NULL) - trespond >= PINGTIMEOUT)
|
||||||
eprint("sic shutting down: parse timeout");
|
die("error: sic shutting down: parse timeout");
|
||||||
write(srv, ping, strlen(ping));
|
write(srv, ping, strlen(ping));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(FD_ISSET(srv, &rd)) {
|
if(FD_ISSET(srv, &rd)) {
|
||||||
if(getline(srv, sizeof bufin, bufin) == -1)
|
if(readl(srv, sizeof bufin, bufin) == -1)
|
||||||
eprint("sic: remote host closed connection");
|
die("error: remote host closed connection");
|
||||||
parsesrv(bufin);
|
parsesrv(bufin);
|
||||||
trespond = time(NULL);
|
trespond = time(NULL);
|
||||||
}
|
}
|
||||||
if(FD_ISSET(0, &rd)) {
|
if(FD_ISSET(0, &rd)) {
|
||||||
if(getline(0, sizeof bufin, bufin) == -1)
|
if(readl(0, sizeof bufin, bufin) == -1)
|
||||||
eprint("sic: broken pipe");
|
die("error: broken pipe");
|
||||||
parsein(bufin);
|
parsein(bufin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user