Adaugă codul complet al proiectului underchat-ircd
This commit is contained in:
1 parent
caba5224bf
commit
5fdc1cc27c
462 files changed
+164488
No files matched your search
@@ -0,0 +1,6 @@
|
||||
Makefile
|
||||
ircd_chattr_t
|
||||
ircd_in_addr_t
|
||||
ircd_string_t
|
||||
ircd_match_t
|
||||
*.log
|
||||
@@ -0,0 +1,81 @@
|
||||
top_srcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
CPPFLAGS = -I${top_srcdir}/include -I../..
|
||||
CFLAGS = -g -Wall
|
||||
LDFLAGS =
|
||||
CC = @CC@
|
||||
|
||||
TESTPROGS = \
|
||||
ircd_chattr_t \
|
||||
ircd_in_addr_t \
|
||||
ircd_match_t \
|
||||
ircd_string_t
|
||||
|
||||
DEP_SRC = \
|
||||
ircd_chattr_t.c \
|
||||
ircd_in_addr_t.c \
|
||||
ircd_match_t.c \
|
||||
ircd_string_t.c \
|
||||
test_stub.c
|
||||
|
||||
all: ${TESTPROGS}
|
||||
|
||||
build: ${TESTPROGS}
|
||||
|
||||
depend: ${DEP_SRC}
|
||||
@cd ${srcdir} && \
|
||||
if [ -f Makefile.in.bak ]; then \
|
||||
echo "make depend: First remove ircd/Makefile.in.bak"; \
|
||||
else \
|
||||
mv Makefile.in Makefile.in.bak && \
|
||||
grep -A1 -B10000 '^# DO NOT DELETE THIS LINE' Makefile.in.bak > Makefile.in && \
|
||||
${CC} ${CFLAGS} -MM ${CPPFLAGS} ${DEP_SRC} >> Makefile.in; \
|
||||
fi
|
||||
|
||||
install:
|
||||
|
||||
IRCD_CHATTR_T_OBJS = ircd_chattr_t.o test_stub.o ../ircd_string.o
|
||||
ircd_chattr_t: $(IRCD_CHATTR_T_OBJS)
|
||||
${CC} -o $@ $(LDFLAGS) $(IRCD_CHATTR_T_OBJS)
|
||||
|
||||
IRCD_IN_ADDR_T_OBJS = ircd_in_addr_t.o test_stub.o ../ircd_alloc.o ../ircd_string.o ../match.o ../numnicks.o
|
||||
ircd_in_addr_t: $(IRCD_IN_ADDR_T_OBJS)
|
||||
${CC} -o $@ $(LDFLAGS) $(IRCD_IN_ADDR_T_OBJS)
|
||||
|
||||
IRCD_MATCH_T_OBJS = ircd_match_t.o test_stub.o ../ircd_string.o ../match.o
|
||||
ircd_match_t: $(IRCD_MATCH_T_OBJS)
|
||||
${CC} -o $@ $(LDFLAGS) $(IRCD_MATCH_T_OBJS)
|
||||
|
||||
IRCD_STRING_T_OBJS = ircd_string_t.o test_stub.o ../ircd_string.o
|
||||
ircd_string_t: $(IRCD_STRING_T_OBJS)
|
||||
${CC} -o $@ $(LDFLAGS) $(IRCD_STRING_T_OBJS)
|
||||
|
||||
.c.o:
|
||||
${CC} ${CFLAGS} ${CPPFLAGS} -c $< -o $@
|
||||
|
||||
.PHONY: distclean clean
|
||||
|
||||
distclean: clean
|
||||
rm -f Makefile
|
||||
|
||||
clean:
|
||||
rm -f core *.o *.log ${TESTPROGS}
|
||||
|
||||
# DO NOT DELETE THIS LINE (or the blank line after it) -- make depend depends on them.
|
||||
|
||||
ircd_chattr_t.o: ircd_chattr_t.c ../../include/ircd_chattr.h
|
||||
ircd_in_addr_t.o: ircd_in_addr_t.c ../../include/ircd_log.h \
|
||||
../../include/ircd_string.h ../../include/ircd_chattr.h \
|
||||
../../include/numnicks.h ../../include/client.h \
|
||||
../../include/ircd_defs.h ../../include/dbuf.h ../../include/msgq.h \
|
||||
../../include/ircd_events.h ../../config.h ../../include/ircd_handler.h \
|
||||
../../include/res.h ../../include/capab.h ../../include/res.h
|
||||
ircd_match_t.o: ircd_match_t.c ../../include/ircd_log.h \
|
||||
../../include/match.h ../../include/res.h ../../config.h
|
||||
ircd_string_t.o: ircd_string_t.c ../../include/ircd_string.h \
|
||||
../../include/ircd_chattr.h
|
||||
test_stub.o: test_stub.c ../../include/client.h ../../include/ircd_defs.h \
|
||||
../../include/dbuf.h ../../include/msgq.h ../../include/ircd_events.h \
|
||||
../../config.h ../../include/ircd_handler.h ../../include/res.h \
|
||||
../../include/capab.h ../../include/ircd_log.h ../../include/s_debug.h
|
||||
@@ -0,0 +1,74 @@
|
||||
define srv localhost
|
||||
|
||||
connect cl1 Alex alex %srv%:7701 :Test client 1
|
||||
connect cl2 Bubb bubb %srv%:7711 :Test client 2
|
||||
:cl1 join #test
|
||||
:cl1 join #test2
|
||||
:cl1 mode #test +bb *!*@127.0.0.1 *!*@127.0.0.2
|
||||
:cl2 wait cl1
|
||||
:cl2 raw :away :I'm not here, go away. I'm not here, go away. I'm not here, go away. I'm not here, go away. I'm not here, go away. I'm not here, go away. I'm not here, go away. I'm not here, go away. I'm not here, go away. I'm not here, go away.
|
||||
:cl2 raw :away :I'm not here, go away.
|
||||
:cl2 join #test,#test3,#test4,+local
|
||||
:cl1 wait cl2
|
||||
:cl1 join #test3
|
||||
:cl1 raw :invite Bubb
|
||||
:cl1 raw :invite #test
|
||||
:cl1 invite Bubb #non-existent-channel
|
||||
:cl1 invite Bubb #test3
|
||||
:cl1 invite Bubb #test4
|
||||
:cl1 invite Bubb #test
|
||||
:cl2 expect *cl1 invite #test
|
||||
:cl2 mode #test3 +o Alex
|
||||
:cl2 raw :invite
|
||||
:cl2 join #test
|
||||
:cl2 privmsg #test :Hello, *cl1.
|
||||
:cl2 notice #test :Hello, *cl1 (via notice).
|
||||
:cl2 notice @#test :Hello, *cl1 (via wallchops).
|
||||
:cl2 privmsg #test5 :Hello, *cl1.
|
||||
:cl2 nick Buba
|
||||
:cl2 mode #test +l 15
|
||||
:cl1 wait cl2
|
||||
:cl1 privmsg #test :Hello, *cl2.
|
||||
:cl1 raw :cprivmsg bubb #test :Hello, bubb.
|
||||
:cl1 raw :cnotice bubb #test :Hello, bubb.
|
||||
:cl1 mode #test -b+kv *!*@127.0.0.1 secret Bubb
|
||||
:cl1 mode #test +b foo!bar@baz
|
||||
:cl1 mode #test +b
|
||||
:cl1 mode #test :
|
||||
:cl1 mode #test
|
||||
:cl1 raw :names
|
||||
:cl1 raw :names #test
|
||||
:cl1 raw :names +local
|
||||
:cl1 raw :names +local test-2.*
|
||||
:cl1 raw :who #test %lfuh
|
||||
:cl2 wait cl1
|
||||
:cl2 raw :part
|
||||
:cl2 part #test
|
||||
:cl2 part #test5
|
||||
:cl1 wait cl2
|
||||
:cl2 join #test public
|
||||
:cl2 join #test secret
|
||||
:cl1 join 0
|
||||
:cl1 join #test2
|
||||
:cl2 wait cl1
|
||||
:cl2 join #test2
|
||||
:cl1 wait cl2
|
||||
:cl1 mode #test2 +smtinrDlAU 15 apples oranges
|
||||
:cl1 mode #test2
|
||||
:cl2 wait cl1
|
||||
:cl2 join #test2 apples
|
||||
:cl2 privmsg #test2 :Hello, oplevels.
|
||||
:cl2 mode #test2
|
||||
:cl2 mode #test2 -io+v Alex Alex
|
||||
:cl1 wait cl2
|
||||
:cl1 part #test2
|
||||
:cl1 join #test2
|
||||
:cl2 wait cl1
|
||||
:cl2 mode #test2 -D
|
||||
:cl2 mode #test +v Alex
|
||||
:cl1 raw :kick #test bubb
|
||||
:cl2 raw :squit test-1.*
|
||||
:cl2 sleep 1
|
||||
:cl2 raw :connect test-1.*
|
||||
:cl2 raw :away :
|
||||
:cl1 wait cl2
|
||||
@@ -0,0 +1,25 @@
|
||||
define srv localhost
|
||||
|
||||
connect cl1 Alex alex %srv%:7701 :Test client 1
|
||||
:cl1 oper oper1 oper1
|
||||
:cl1 oper oper1 oper1
|
||||
connect cl2 Bubb bubb %srv%:7711 :Test client 2
|
||||
:cl1 raw :time
|
||||
:cl2 oper oper3 oper4
|
||||
:cl1 raw :version
|
||||
:cl2 oper oldoper wrongpass
|
||||
:cl2 oper md5oper wrongpass
|
||||
:cl2 oper cryptoper wrongpass
|
||||
:cl2 oper oper2 oper2
|
||||
:cl2 raw :privs Alex Alex
|
||||
:cl1 wait cl2
|
||||
:cl1 raw :privs Bubb
|
||||
:cl1 nick A
|
||||
:cl1 nick Alexey
|
||||
:cl1 raw :privmsg :
|
||||
:cl1 raw :privmsg Alexey :
|
||||
:cl1 raw :privmsg Bubb :hello Bubb
|
||||
:cl1 raw :privmsg $*.net :Hello all *.net servers.
|
||||
:cl1 raw :notice $*.net :Hello all *.net servers.
|
||||
:cl1 raw :kill Bubb :goodbye Bubb
|
||||
:cl1 raw :whowas Alex,Bubb 5
|
||||
@@ -0,0 +1,43 @@
|
||||
define srv localhost:7701
|
||||
|
||||
connect cl1 Alex alex %srv% :Test client 1
|
||||
connect cl2 Bubb bubb %srv% :Test client 2
|
||||
:cl1 raw :help
|
||||
:cl1 raw :admin
|
||||
:cl1 raw :admin test-2.*
|
||||
:cl1 raw :info
|
||||
:cl1 raw :wallops :HELLO OPERZ!!!
|
||||
:cl1 wait cl2
|
||||
:cl1 raw :ison alex,bubb,alex,bubb,alex,bubb
|
||||
:cl1 raw :who b*b
|
||||
:cl1 raw :burst the bubble
|
||||
:cl1 raw :server huh huh i'm a server
|
||||
:cl1 raw :links
|
||||
:cl1 raw :map
|
||||
:cl1 raw :nick
|
||||
:cl1 raw :nick ~
|
||||
:cl1 raw :nick -dude-
|
||||
:cl1 raw :nick alex
|
||||
:cl1 raw :nick Bubb
|
||||
:cl1 raw :ping alex test-1.*
|
||||
|
||||
:cl1 oper oper1 oper1
|
||||
:cl1 raw :admin
|
||||
:cl1 raw :admin test-2.*
|
||||
:cl1 raw :asll
|
||||
:cl1 raw :asll test-2.*
|
||||
:cl1 raw :info
|
||||
:cl1 raw :info test-2.*
|
||||
:cl1 raw :who x b*b
|
||||
:cl1 raw :close
|
||||
:cl1 raw :map
|
||||
:cl1 raw :links
|
||||
:cl1 raw :links test-2.*
|
||||
:cl1 raw :lusers
|
||||
:cl1 raw :lusers test-2.*
|
||||
:cl1 raw :motd
|
||||
:cl1 raw :motd test-2.*
|
||||
:cl1 raw :ping alex test-2.*
|
||||
:cl1 raw :rping test-2.*
|
||||
|
||||
:cl2 raw :quit
|
||||
@@ -0,0 +1,5 @@
|
||||
connect cl1 Alex alex localhost:7701 :Test client 1
|
||||
:cl1 oper oper1 oper1
|
||||
:cl1 raw :restart brb
|
||||
:cl1 oper oper1 oper1
|
||||
:cl1 raw :die :testing over
|
||||
@@ -0,0 +1,18 @@
|
||||
define srv localhost:7701
|
||||
|
||||
connect cl1 Alex alex %srv% :Test client 1
|
||||
:cl1 oper oper1 oper1
|
||||
:cl1 raw :GET LOG
|
||||
:cl1 raw :RESET LOG
|
||||
:cl1 raw :GET RANDOM_SEED
|
||||
:cl1 raw :SET RANDOM_SEED
|
||||
:cl1 raw :SET RANDOM_SEED abcdefghijklmnop
|
||||
:cl1 raw :GET DEFAULT_LIST_PARAM
|
||||
:cl1 raw :SET DEFAULT_LIST_PARAM FALSE
|
||||
:cl1 raw :SET DEFAULT_LIST_PARAM TRUE
|
||||
:cl1 nick Alexey
|
||||
:cl1 nick Amdahl
|
||||
:cl1 nick Andy
|
||||
:cl1 nick Aon
|
||||
:cl1 nick Apple
|
||||
:cl1 raw :SET NICKNAMEHISTORYLENGTH 4
|
||||
@@ -0,0 +1,29 @@
|
||||
define srv localhost:7701
|
||||
|
||||
connect cl1 Alex alex %srv% :Test client 1
|
||||
:cl1 oper oper1 oper1
|
||||
:cl1 raw :gline !+$Rbubb 30 :Bubb is not welcome here
|
||||
:cl1 sleep 35
|
||||
:cl1 raw :gline !+127.2.* 3600 :Localclone?
|
||||
:cl1 sleep 5
|
||||
:cl1 raw :gline !+127.2.* 3600 :Localclone?
|
||||
:cl1 raw :gline !+127.2.*/15 3600 :Localclone?
|
||||
:cl1 raw :gline !+127.2.0.0/33 3600 :Localclone?
|
||||
:cl1 raw :gline !+127.2.0.0/15 3600 :Localclone?
|
||||
connect cl2 Bubb bubb %srv% :Test client 2
|
||||
:cl1 raw :gline
|
||||
:cl1 raw :gline $Rbubb
|
||||
:cl1 raw :gline -$Rbubb
|
||||
:cl1 wait cl2
|
||||
:cl1 raw :gline !+$Rbubb * 3600 :Bubb is not welcome here
|
||||
:cl1 sleep 5
|
||||
:cl1 raw :gline -$Rbubb
|
||||
:cl1 raw :gline +#warez 30 :Warez r bad mmkay
|
||||
:cl2 wait cl1
|
||||
:cl2 join #warez
|
||||
:cl1 sleep 35
|
||||
:cl1 raw :stats glines
|
||||
:cl1 raw :gline !+*@127.0.0.2 3600 :Localclone?
|
||||
:cl1 raw :gline !+127.1.* 3600 :Localclone?
|
||||
:cl1 raw :stats memory
|
||||
:cl2 raw :gline
|
||||
@@ -0,0 +1,93 @@
|
||||
General {
|
||||
name = "test-1.example.net";
|
||||
vhost = "127.0.0.1";
|
||||
vhost = "::1";
|
||||
description = "Test Server 1";
|
||||
numeric = 1;
|
||||
};
|
||||
|
||||
Admin {
|
||||
location = "Somewhere";
|
||||
contact = "Someone";
|
||||
};
|
||||
|
||||
Class {
|
||||
name = "Server";
|
||||
pingfreq = 180 seconds;
|
||||
connectfreq = 300 seconds;
|
||||
maxlinks = 1;
|
||||
sendq = 9000000;
|
||||
};
|
||||
|
||||
Class {
|
||||
name = "others";
|
||||
pingfreq = 180 seconds;
|
||||
sendq = 160000;
|
||||
maxlinks = 100;
|
||||
usermode = "+oiwx";
|
||||
};
|
||||
|
||||
Class {
|
||||
name = "Opers";
|
||||
pingfreq = 180 seconds;
|
||||
sendq = 160000;
|
||||
maxlinks = 10;
|
||||
local = no;
|
||||
};
|
||||
|
||||
Connect {
|
||||
name = "bogus.example.net";
|
||||
host = "example.net";
|
||||
password = "bogus_example";
|
||||
port = 7700;
|
||||
class = "Server";
|
||||
maxhops = 2;
|
||||
hub = "*.example.net";
|
||||
autoconnect = yes; # forces a DNS resolution attempt
|
||||
};
|
||||
|
||||
CRule {
|
||||
server = "bogus.example.net";
|
||||
all = yes;
|
||||
rule = "connected(*)";
|
||||
};
|
||||
|
||||
CRule {
|
||||
server = "bogus.example.net";
|
||||
all = no;
|
||||
rule = "directcon(*)";
|
||||
};
|
||||
|
||||
UWorld {
|
||||
name = "uworld.example.net";
|
||||
name = "uworld2.example.net";
|
||||
};
|
||||
|
||||
Jupe {
|
||||
nick = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q";
|
||||
nick = "R,S,T,U,V,W,X,Y,Z,{,|,},~,-,_,`";
|
||||
};
|
||||
|
||||
Operator { name = "oper1"; host = "*@*"; password = "$PLAIN$oper1"; class = "Opers"; };
|
||||
Operator { name = "oper2"; host = "*@*"; password = "$PLAIN$oper2"; class = "Opers"; local = yes; };
|
||||
Operator { name = "oldoper"; host = "*@*"; password = "Xlfc26b4eYGWs"; class = "Opers"; };
|
||||
Operator { name = "md5oper"; host = "*@*"; password = "$SMD5$2O$4O.rSAmhE4Fg05MmG.047/"; class = "Opers"; };
|
||||
Operator { name = "cryptoper"; host = "*@*"; password = "$CRYPT$41ndrxPQu3B66"; class = "Opers"; };
|
||||
|
||||
Kill { username = "sub7"; realname = "s*7*"; reason = "You are infected with a Trojan"; };
|
||||
Kill { realname = "Chloe"; reason = "drones"; };
|
||||
Kill { username = "sub7"; reason = "You are infected with a Trojan"; };
|
||||
|
||||
Client { class = "others"; ip = "*"; };
|
||||
|
||||
Port { server = yes; port = 7700; };
|
||||
Port { server = no; port = 7702; };
|
||||
|
||||
Quarantine {
|
||||
"#shells" = "Thou shalt not support the h4><0rz";
|
||||
};
|
||||
|
||||
Features {
|
||||
"HIS_STATS_k" = "FALSE";
|
||||
"PPATH" = "ircd-t1.pid";
|
||||
};
|
||||
@@ -0,0 +1,107 @@
|
||||
General {
|
||||
name = "test-1.example.net";
|
||||
vhost = "127.0.0.1";
|
||||
vhost = "::1";
|
||||
description = "Test Server 1";
|
||||
numeric = 1;
|
||||
};
|
||||
|
||||
Admin {
|
||||
location = "Somewhere";
|
||||
contact = "Someone";
|
||||
};
|
||||
|
||||
Class {
|
||||
name = "Server";
|
||||
pingfreq = 180 seconds;
|
||||
connectfreq = 300 seconds;
|
||||
maxlinks = 1;
|
||||
sendq = 9000000;
|
||||
};
|
||||
|
||||
Class {
|
||||
name = "others";
|
||||
pingfreq = 180 seconds;
|
||||
sendq = 160000;
|
||||
maxlinks = 100;
|
||||
usermode = "+oiwx";
|
||||
};
|
||||
|
||||
Class {
|
||||
name = "Opers";
|
||||
pingfreq = 180 seconds;
|
||||
sendq = 160000;
|
||||
maxlinks = 10;
|
||||
local = no;
|
||||
};
|
||||
|
||||
Connect {
|
||||
name = "bogus.example.net";
|
||||
host = "example.net";
|
||||
password = "bogus_example";
|
||||
port = 7700;
|
||||
class = "Server";
|
||||
maxhops = 2;
|
||||
hub = "*.example.net";
|
||||
autoconnect = yes; # forces a DNS resolution attempt
|
||||
};
|
||||
|
||||
Connect {
|
||||
name = "test-2.example.net";
|
||||
host = "::1";
|
||||
password = "bogus_example";
|
||||
port = 7710;
|
||||
class = "Server";
|
||||
autoconnect = no;
|
||||
};
|
||||
|
||||
CRule {
|
||||
server = "bogus.example.net";
|
||||
all = yes;
|
||||
rule = "connected(*)";
|
||||
};
|
||||
|
||||
CRule {
|
||||
server = "bogus.example.net";
|
||||
all = no;
|
||||
rule = "directcon(*)";
|
||||
};
|
||||
|
||||
UWorld {
|
||||
name = "uworld.example.net";
|
||||
name = "uworld2.example.net";
|
||||
};
|
||||
|
||||
Jupe {
|
||||
nick = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q";
|
||||
nick = "R,S,T,U,V,W,X,Y,Z,{,|,},~,-,_,`";
|
||||
};
|
||||
|
||||
Operator { name = "oper1"; host = "*@*"; password = "$PLAIN$oper1"; class = "Opers"; };
|
||||
Operator { name = "oper2"; host = "*@*"; password = "$PLAIN$oper2"; class = "Opers"; local = yes; };
|
||||
Operator { name = "oldoper"; host = "*@*"; password = "Xlfc26b4eYGWs"; class = "Opers"; };
|
||||
Operator { name = "md5oper"; host = "*@*"; password = "$SMD5$2O$4O.rSAmhE4Fg05MmG.047/"; class = "Opers"; };
|
||||
Operator { name = "cryptoper"; host = "*@*"; password = "$CRYPT$41ndrxPQu3B66"; class = "Opers"; };
|
||||
|
||||
Kill { username = "sub7"; realname = "s*7*"; reason = "You are infected with a Trojan"; };
|
||||
Kill { realname = "Chloe"; reason = "drones"; };
|
||||
Kill { username = "sub7"; reason = "You are infected with a Trojan"; };
|
||||
|
||||
Client { class = "others"; ip = "*"; };
|
||||
|
||||
Port { server = yes; port = 7700; };
|
||||
Port { server = no; port = 7701; };
|
||||
|
||||
Quarantine {
|
||||
"#shells" = "Thou shalt not support the h4><0rz";
|
||||
};
|
||||
|
||||
Pseudo "X" {
|
||||
name = "X";
|
||||
nick = "X@channels.example.net";
|
||||
};
|
||||
|
||||
Features {
|
||||
"HIS_STATS_k" = "FALSE";
|
||||
"PPATH" = "ircd-t1.pid";
|
||||
};
|
||||
@@ -0,0 +1,95 @@
|
||||
General {
|
||||
name = "test-2.example.net";
|
||||
vhost = "127.0.0.1";
|
||||
vhost = "::1";
|
||||
description = "Test Server 2";
|
||||
numeric = 2;
|
||||
};
|
||||
|
||||
Admin {
|
||||
location = "Somewhere";
|
||||
contact = "Someone";
|
||||
};
|
||||
|
||||
Class {
|
||||
name = "Server";
|
||||
pingfreq = 180 seconds;
|
||||
connectfreq = 300 seconds;
|
||||
maxlinks = 1;
|
||||
sendq = 9000000;
|
||||
};
|
||||
|
||||
Class {
|
||||
name = "others";
|
||||
pingfreq = 180 seconds;
|
||||
sendq = 160000;
|
||||
maxlinks = 100;
|
||||
usermode = "+oiwx";
|
||||
};
|
||||
|
||||
Class {
|
||||
name = "Opers";
|
||||
pingfreq = 180 seconds;
|
||||
sendq = 160000;
|
||||
maxlinks = 10;
|
||||
local = no;
|
||||
};
|
||||
|
||||
Connect {
|
||||
name = "test-1.example.net";
|
||||
host = "::1";
|
||||
password = "bogus_example";
|
||||
port = 7700;
|
||||
class = "Server";
|
||||
maxhops = 2;
|
||||
hub = "*.example.net";
|
||||
autoconnect = yes;
|
||||
};
|
||||
|
||||
CRule {
|
||||
server = "bogus.example.net";
|
||||
all = yes;
|
||||
rule = "connected(*)";
|
||||
};
|
||||
|
||||
CRule {
|
||||
server = "bogus.example.net";
|
||||
all = no;
|
||||
rule = "directcon(*)";
|
||||
};
|
||||
|
||||
UWorld {
|
||||
name = "uworld.example.net";
|
||||
name = "uworld2.example.net";
|
||||
};
|
||||
|
||||
Jupe {
|
||||
nick = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q";
|
||||
nick = "R,S,T,U,V,W,X,Y,Z,{,|,},~,-,_,`";
|
||||
};
|
||||
|
||||
Operator { name = "oper1"; host = "*@*"; password = "$PLAIN$oper1"; class = "Opers"; };
|
||||
Operator { name = "oper2"; host = "*@*"; password = "$PLAIN$oper2"; class = "Opers"; local = yes; };
|
||||
|
||||
Kill { realname = "Chloe"; reason = "drones"; };
|
||||
Kill { username = "sub7"; reason = "You are infected with a Trojan"; };
|
||||
|
||||
Client { class = "others"; ip = "*"; };
|
||||
|
||||
Port { server = yes; port = 7710; };
|
||||
Port { server = no; port = 7711; mask = "127.0.0.0/8"; };
|
||||
|
||||
Quarantine {
|
||||
"#shells" = "Thou shalt not support the h4><0rz";
|
||||
};
|
||||
|
||||
Pseudo "X" {
|
||||
name = "X";
|
||||
nick = "X@channels.example.net";
|
||||
};
|
||||
|
||||
Features {
|
||||
"PPATH" = "ircd-t2.pid";
|
||||
"LOG" = "SYSTEM" "FILE" "ircd-t2.log";
|
||||
"LOG" = "SYSTEM" "LEVEL" "NOTICE";
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
IsAlnum: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^abcdefghijklmnopqrstuvwxyz{|}~
|
||||
IsAlpha: ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^abcdefghijklmnopqrstuvwxyz{|}~
|
||||
IsDigit: 0123456789
|
||||
IsLower: abcdefghijklmnopqrstuvwxyz{|}~
|
||||
IsSpace: \t\n\v\f\r
|
||||
IsUpper: ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^
|
||||
IsCntrl: \0\1\2\3\4\5\6\a\b\t\n\v\f\r\e\f\10\11\12\13\14\15\16\17\18\19\1a\1b\1c\1d\1e\1f
|
||||
IsChannelChar: \0\1\2\3\4\5\6\b\t\n\v\f\r\e\f\10\11\12\13\14\15\16\17\18\19\1a\1b\1c\1d\1e\1f!"#$%&'()*+-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~\7f\80\81\82\83\84\85\86\87\88\89\8a\8b\8c\8d\8e\8f\90\91\92\93\94\95\96\97\98\99\9a\9b\9c\9d\9e\9f\a1\a2\a3\a4\a5\a6\a7\a8\a9\aa\ab\ac\ad\ae\af\b0\b1\b2\b3\b4\b5\b6\b7\b8\b9\ba\bb\bc\bd\be\bf\c0\c1\c2\c3\c4\c5\c6\c7\c8\c9\ca\cb\cc\cd\ce\cf\d0\d1\d2\d3\d4\d5\d6\d7\d8\d9\da\db\dc\dd\de\df\e0\e1\e2\e3\e4\e5\e6\e7\e8\e9\ea\eb\ec\ed\ee\ef\f0\f1\f2\f3\f4\f5\f6\f7\f8\f9\fa\fb\fc\fd\fe\ff
|
||||
IsChannelLower: \c0\c1\c2\c3\c4\c5\c6\c7\c8\c9\ca\cb\cc\cd\ce\cf\d0\d1\d2\d3\d4\d5\d6\d8\d9\da\db\dc\dd\de
|
||||
IsChannelPrefix: #&
|
||||
IsNickChar: -0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
|
||||
IsUserChar: '-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~\c0\c1\c2\c3\c4\c5\c6\c7\c8\c9\ca\cb\cc\cd\ce\cf\d0\d1\d2\d3\d4\d5\d6\d8\d9\da\db\dc\dd\de\e0\e1\e2\e3\e4\e5\e6\e7\e8\e9\ea\eb\ec\ed\ee\ef\f0\f1\f2\f3\f4\f5\f6\f8\f9\fa\fb\fc\fd\fe
|
||||
IsHostChar: -.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_abcdefghijklmnopqrstuvwxyz{|}~
|
||||
IsIPChar: .0123456789
|
||||
IsEol: \n\r
|
||||
IsKTimeChar: ,-0123456789
|
||||
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* ircd_chattr_t.c - Test file for character attributes
|
||||
*/
|
||||
#include "ircd_chattr.h"
|
||||
/* #include <assert.h> -- not used here */
|
||||
#include <stdio.h>
|
||||
|
||||
typedef int (*EvalFn)(char);
|
||||
|
||||
int eval_alnum(char c)
|
||||
{
|
||||
return (0 != IsAlnum(c));
|
||||
}
|
||||
|
||||
int eval_alpha(char c)
|
||||
{
|
||||
return (0 != IsAlpha(c));
|
||||
}
|
||||
|
||||
int eval_digit(char c)
|
||||
{
|
||||
return (0 != IsDigit(c));
|
||||
}
|
||||
|
||||
int eval_lower(char c)
|
||||
{
|
||||
return (0 != IsLower(c));
|
||||
}
|
||||
|
||||
int eval_space(char c)
|
||||
{
|
||||
return (0 != IsSpace(c));
|
||||
}
|
||||
|
||||
int eval_upper(char c)
|
||||
{
|
||||
return (0 != IsUpper(c));
|
||||
}
|
||||
|
||||
int eval_cntrl(char c)
|
||||
{
|
||||
return (0 != IsCntrl(c));
|
||||
}
|
||||
|
||||
int eval_channel_char(char c)
|
||||
{
|
||||
return (0 != IsChannelChar(c));
|
||||
}
|
||||
|
||||
int eval_channel_lower(char c)
|
||||
{
|
||||
return (0 != IsChannelLower(c));
|
||||
}
|
||||
|
||||
int eval_channel_prefix(char c)
|
||||
{
|
||||
return (0 != IsChannelPrefix(c));
|
||||
}
|
||||
|
||||
int eval_nick_char(char c)
|
||||
{
|
||||
return (0 != IsNickChar(c));
|
||||
}
|
||||
|
||||
int eval_user_char(char c)
|
||||
{
|
||||
return (0 != IsUserChar(c));
|
||||
}
|
||||
|
||||
int eval_host_char(char c)
|
||||
{
|
||||
return (0 != IsHostChar(c));
|
||||
}
|
||||
|
||||
int eval_ip_char(char c)
|
||||
{
|
||||
return (0 != IsIPChar(c));
|
||||
}
|
||||
|
||||
int eval_eol(char c)
|
||||
{
|
||||
return (0 != IsEol(c));
|
||||
}
|
||||
|
||||
int eval_ktime_char(char c)
|
||||
{
|
||||
return (0 != IsKTimeChar(c));
|
||||
}
|
||||
|
||||
struct CharTest {
|
||||
const char* name;
|
||||
EvalFn evaluator;
|
||||
} testList[] = {
|
||||
{ "IsAlnum: ", eval_alnum },
|
||||
{ "IsAlpha: ", eval_alpha },
|
||||
{ "IsDigit: ", eval_digit },
|
||||
{ "IsLower: ", eval_lower },
|
||||
{ "IsSpace: ", eval_space },
|
||||
{ "IsUpper: ", eval_upper },
|
||||
{ "IsCntrl: ", eval_cntrl },
|
||||
{ "IsChannelChar: ", eval_channel_char },
|
||||
{ "IsChannelLower: ", eval_channel_lower },
|
||||
{ "IsChannelPrefix: ", eval_channel_prefix },
|
||||
{ "IsNickChar: ", eval_nick_char },
|
||||
{ "IsUserChar: ", eval_user_char },
|
||||
{ "IsHostChar: ", eval_host_char },
|
||||
{ "IsIPChar: ", eval_ip_char },
|
||||
{ "IsEol: ", eval_eol },
|
||||
{ "IsKTimeChar: ", eval_ktime_char }
|
||||
};
|
||||
|
||||
#define TESTLIST_SIZE sizeof(testList) / sizeof(struct CharTest)
|
||||
|
||||
void print_char(unsigned char c)
|
||||
{
|
||||
if (c < 0x20) {
|
||||
switch (c) {
|
||||
case '\a': printf("\\a"); break;
|
||||
case '\b': printf("\\b"); break;
|
||||
case '\f': printf("\\f"); break;
|
||||
case '\n': printf("\\n"); break;
|
||||
case '\r': printf("\\r"); break;
|
||||
case '\t': printf("\\t"); break;
|
||||
case '\v': printf("\\v"); break;
|
||||
default:
|
||||
printf("\\%x", c); break;
|
||||
}
|
||||
}
|
||||
else if (c < 0x7F) {
|
||||
printf("%c", c);
|
||||
}
|
||||
else {
|
||||
printf("\\%x", c);
|
||||
}
|
||||
}
|
||||
|
||||
void print_char_attr(struct CharTest* test)
|
||||
{
|
||||
int i;
|
||||
|
||||
printf("%s", test->name);
|
||||
|
||||
for (i = 0; i < 256; ++i) {
|
||||
if ((*test->evaluator)(i))
|
||||
print_char(i);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < TESTLIST_SIZE; ++i)
|
||||
print_char_attr(&testList[i]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
/* ircd_in_addr_t.c - Test file for IP address manipulation */
|
||||
|
||||
#include "ircd_log.h"
|
||||
#include "ircd_string.h"
|
||||
#include "numnicks.h"
|
||||
#include "res.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
/** Structure to describe a test for IP address parsing and unparsing. */
|
||||
struct address_test {
|
||||
const char *text; /**< Textual address to parse. */
|
||||
const char *canonical; /**< Canonical form of address. */
|
||||
struct irc_in_addr expected; /**< Parsed address. */
|
||||
const char *base64_v4; /**< v4-only compatible base64 encoding. */
|
||||
const char *base64_v6; /**< v6-compatible base64 encoding. */
|
||||
unsigned int is_valid : 1; /**< is address valid? */
|
||||
unsigned int is_ipv4 : 1; /**< is address ipv4? */
|
||||
unsigned int is_loopback : 1; /**< is address loopback? */
|
||||
};
|
||||
|
||||
/** Array of addresses to test with. */
|
||||
static struct address_test test_addrs[] = {
|
||||
{ "::", "0::",
|
||||
{{ 0, 0, 0, 0, 0, 0, 0, 0 }},
|
||||
"AAAAAA", "_", 0, 0, 0 },
|
||||
{ "::1", "0::1",
|
||||
{{ 0, 0, 0, 0, 0, 0, 0, 1 }},
|
||||
"AAAAAA", "_AAB", 1, 0, 1 },
|
||||
{ "127.0.0.1", "127.0.0.1",
|
||||
{{ 0, 0, 0, 0, 0, 0xffff, 0x7f00, 1 }},
|
||||
"B]AAAB", "B]AAAB", 1, 1, 1 },
|
||||
{ "::ffff:127.0.0.3", "127.0.0.3",
|
||||
{{ 0, 0, 0, 0, 0, 0xffff, 0x7f00, 3 }},
|
||||
"B]AAAD", "B]AAAD", 1, 1, 1 },
|
||||
{ "::127.0.0.1", "127.0.0.1",
|
||||
{{ 0, 0, 0, 0, 0, 0, 0x7f00, 1 }},
|
||||
"B]AAAB", "B]AAAB", 1, 1, 1 },
|
||||
{ "2002:7f00:3::1", "2002:7f00:3::1",
|
||||
{{ 0x2002, 0x7f00, 3, 0, 0, 0, 0, 1 }},
|
||||
"B]AAAD", "CACH8AAAD_AAB", 1, 0, 0 },
|
||||
{ "8352:0344:0:0:0:0:2001:1204", "8352:344::2001:1204",
|
||||
{{ 0x8352, 0x344, 0, 0, 0, 0, 0x2001, 0x1204 }},
|
||||
"AAAAAA", "INSANE_CABBIE", 1, 0, 0 },
|
||||
{ "1:2:3:4:5:6:7:8", "1:2:3:4:5:6:7:8",
|
||||
{{ 1, 2, 3, 4, 5, 6, 7, 8 }},
|
||||
"AAAAAA", "AABAACAADAAEAAFAAGAAHAAI", 1, 0, 0 },
|
||||
{ 0 },
|
||||
};
|
||||
|
||||
/** Perform tests for a single IP address.
|
||||
* @param[in] addr Address test structure.
|
||||
*/
|
||||
static void
|
||||
test_address(struct address_test *addr)
|
||||
{
|
||||
struct irc_in_addr parsed;
|
||||
unsigned int ii, len, val;
|
||||
char unparsed[64], base64_v4[64], base64_v6[64];
|
||||
|
||||
/* Convert expected address to network order. */
|
||||
for (ii = 0; ii < 8; ++ii)
|
||||
addr->expected.in6_16[ii] = htons(addr->expected.in6_16[ii]);
|
||||
/* Make sure the text form is parsed as expected. */
|
||||
len = ircd_aton(&parsed, addr->text);
|
||||
assert(len == strlen(addr->text));
|
||||
assert(!irc_in_addr_cmp(&parsed, &addr->expected));
|
||||
/* Make sure it converts back to ASCII. */
|
||||
ircd_ntoa_r(unparsed, &parsed);
|
||||
assert(!strcmp(unparsed, addr->canonical));
|
||||
/* Check IP-to-base64 conversion. */
|
||||
iptobase64(base64_v4, &parsed, sizeof(base64_v4), 0);
|
||||
iptobase64(base64_v6, &parsed, sizeof(base64_v6), 1);
|
||||
if (addr->base64_v4)
|
||||
assert(!strcmp(base64_v4, addr->base64_v4));
|
||||
if (addr->base64_v6)
|
||||
assert(!strcmp(base64_v6, addr->base64_v6));
|
||||
/* Check testable attributes. */
|
||||
val = irc_in_addr_valid(&parsed);
|
||||
assert(!!val == addr->is_valid);
|
||||
val = irc_in_addr_is_ipv4(&parsed);
|
||||
assert(!!val == addr->is_ipv4);
|
||||
val = irc_in_addr_is_loopback(&parsed);
|
||||
assert(!!val == addr->is_loopback);
|
||||
/* Check base64-to-IP conversion. */
|
||||
if (addr->is_ipv4) {
|
||||
base64toip(addr->base64_v4, &parsed);
|
||||
assert(!memcmp(parsed.in6_16+6, addr->expected.in6_16+6, 4));
|
||||
} else {
|
||||
base64toip(addr->base64_v6, &parsed);
|
||||
assert(!memcmp(&parsed, &addr->expected, sizeof(parsed)));
|
||||
}
|
||||
/* Tests completed. */
|
||||
printf("Passed: %s (%s/%s)\n", addr->text, base64_v4, base64_v6);
|
||||
}
|
||||
|
||||
/** Structure to describe a test for IP mask parsing. */
|
||||
struct ipmask_test {
|
||||
const char *text; /**< Textual IP mask to parse. */
|
||||
struct irc_in_addr expected; /**< Canonical form of address. */
|
||||
unsigned int is_ipmask : 1; /**< Parse as an ipmask? */
|
||||
unsigned int is_parseable : 1; /**< Is address parseable? */
|
||||
unsigned int exp_bits : 8; /**< Number of bits expected in netmask */
|
||||
};
|
||||
|
||||
/** Array of ipmasks to test with. */
|
||||
static struct ipmask_test test_masks[] = {
|
||||
{ "::", {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 1, 1, 128 },
|
||||
{ "::/0", {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 1, 1, 0 },
|
||||
{ "::10.0.0.0", {{ 0, 0, 0, 0, 0, 0, 0xa00, 0 }}, 1, 1, 128 },
|
||||
{ "192.168/16", {{ 0, 0, 0, 0, 0, 0xffff, 0xc0a8, 0 }}, 1, 1, 112 },
|
||||
{ "192.*", {{ 0, 0, 0, 0, 0, 0xffff, 0xc000, 0 }}, 1, 1, 104 },
|
||||
{ "192.*.*.*", {{ 0, 0, 0, 0, 0, 0xffff, 0xc000, 0 }}, 1, 1, 104 },
|
||||
{ "192.*/8", {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 1, 0, 0 },
|
||||
{ "192*", {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 1, 0, 0 },
|
||||
{ "192.168.0.0/16", {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 0, 0, 0 },
|
||||
{ "ab.*", {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 1, 0, 0 },
|
||||
{ "a*", {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 1, 0, 0 },
|
||||
{ "*", {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 1, 1, 0 },
|
||||
{ "a:b", {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 1, 0, 0 },
|
||||
{ "a::*", {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 1, 0, 0 },
|
||||
{ "a:*", {{ 0xa, 0, 0, 0, 0, 0, 0, 0 }}, 1, 1, 16 },
|
||||
{ "a:*:*", {{ 0xa, 0, 0, 0, 0, 0, 0, 0 }}, 1, 1, 16 },
|
||||
{ "a:/16", {{ 0xa, 0, 0, 0, 0, 0, 0, 0 }}, 1, 1, 16 },
|
||||
{ "0.0.0.0.0/1", {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 0, 0, 0 },
|
||||
{ "2607:3f00:1:30c:9999*",
|
||||
{{ 0x2607, 0x3f00, 1, 0x30c, 0x9999, 0, 0, 0 }}, 1, 1, 80 },
|
||||
{ "1234:5678:9abc:def0:feed:abba:cabb:1e55::",
|
||||
{{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 1, 0, 0 },
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
/** Perform tests for a single IP mask.
|
||||
* @param[in] mask IP mask test structure.
|
||||
*/
|
||||
static void
|
||||
test_ipmask(struct ipmask_test *mask)
|
||||
{
|
||||
struct irc_in_addr parsed;
|
||||
unsigned int len, ii;
|
||||
unsigned char bits = 0;
|
||||
|
||||
/* Convert expected address to network order. */
|
||||
for (ii = 0; ii < 8; ++ii)
|
||||
mask->expected.in6_16[ii] = htons(mask->expected.in6_16[ii]);
|
||||
/* Try to parse; make sure its parseability and netmask length are
|
||||
* as expected. */
|
||||
len = ipmask_parse(mask->text, &parsed, mask->is_ipmask ? &bits : 0);
|
||||
assert(!!len == mask->is_parseable);
|
||||
if (!len) {
|
||||
printf("X-Fail: %s\n", mask->text);
|
||||
return;
|
||||
}
|
||||
if (mask->is_ipmask)
|
||||
assert(bits == mask->exp_bits);
|
||||
assert(!memcmp(&parsed, &mask->expected, sizeof(parsed)));
|
||||
printf("Passed: %s (%s/%u)\n", mask->text, ircd_ntoa(&parsed), bits);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
unsigned int ii;
|
||||
|
||||
printf("Testing address parsing..\n");
|
||||
for (ii = 0; test_addrs[ii].text; ++ii)
|
||||
test_address(&test_addrs[ii]);
|
||||
|
||||
printf("\nTesting ipmask parsing..\n");
|
||||
for (ii = 0; test_masks[ii].text; ++ii)
|
||||
test_ipmask(&test_masks[ii]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
* ircd_match_t.c - test cases for irc glob matching
|
||||
*/
|
||||
|
||||
#include "ircd_log.h"
|
||||
#include "match.h"
|
||||
|
||||
#include <errno.h> /* errno */
|
||||
#include <fcntl.h> /* O_RDONLY */
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h> /* mmap(), munmap() */
|
||||
#include <unistd.h> /* sysconf() */
|
||||
|
||||
#if !defined(MAP_ANONYMOUS)
|
||||
# if defined(MAP_ANON)
|
||||
# define MAP_ANONYMOUS MAP_ANON
|
||||
# else
|
||||
# error I do not know how to request an anonymous mmap from your OS.
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined(_SC_PAGE_SIZE)
|
||||
# if defined(_SC_PAGESIZE)
|
||||
# define _SC_PAGE_SIZE _SC_PAGESIZE
|
||||
# else
|
||||
# error I do not know how to request the page size from your OS.
|
||||
# endif
|
||||
#endif
|
||||
|
||||
struct match_test {
|
||||
const char *glob;
|
||||
const char *should_match;
|
||||
const char *shouldnt_match;
|
||||
};
|
||||
|
||||
const struct match_test match_tests[] = {
|
||||
{ "\\*",
|
||||
"*\0",
|
||||
"a\0*PeacefuL*\0" },
|
||||
{ "*a*",
|
||||
"a\0pizza\0abe\0brack\0",
|
||||
"b\0" },
|
||||
{ "?",
|
||||
"*\0a\0?\0",
|
||||
"*PeacefuL*\0pizza\0???\0" },
|
||||
{ "abc",
|
||||
"abc\0",
|
||||
"abcd\0cabc\0" },
|
||||
{ "*abc",
|
||||
"abc\0fooabc\0ababc\0",
|
||||
"abra\0abcd\0" },
|
||||
{ "\\?",
|
||||
"?\0",
|
||||
"a\0" },
|
||||
{ "*\\\\[*!~*",
|
||||
"har\\[dy!~boy\0",
|
||||
"dark\\s|de!pimp\0joe\\[mama\0" },
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
int test_match(const char glob[], const char name[])
|
||||
{
|
||||
static unsigned int page_size;
|
||||
static char *pages;
|
||||
char *test_glob;
|
||||
char *test_name;
|
||||
size_t length;
|
||||
int res;
|
||||
|
||||
/* If we have not yet set up our test mappings, do so. */
|
||||
if (!page_size)
|
||||
{
|
||||
int dev_zero_fd;
|
||||
|
||||
page_size = sysconf(_SC_PAGE_SIZE);
|
||||
if (page_size == 0 || page_size == (unsigned int)-1)
|
||||
{
|
||||
fprintf(stderr, "sysconf(_SC_PAGE_SIZE) failed: %s\n", strerror(errno));
|
||||
assert(0);
|
||||
}
|
||||
dev_zero_fd = open("/dev/zero", O_RDONLY);
|
||||
/* If dev_zero_fd == -1 (failed), we may still be able to mmap anonymously. */
|
||||
pages = mmap(NULL, 4 * page_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, dev_zero_fd, 0);
|
||||
if (pages == MAP_FAILED)
|
||||
{
|
||||
/* Try using fd == -1 for MAP_ANONYMOUS, which BSD systems require. */
|
||||
pages = mmap(NULL, 4 * page_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||
}
|
||||
if (pages == MAP_FAILED)
|
||||
{
|
||||
fprintf(stderr, "Unable to map pages: %s\n", strerror(errno));
|
||||
assert(0);
|
||||
}
|
||||
if (dev_zero_fd >= 0)
|
||||
{
|
||||
close(dev_zero_fd);
|
||||
dev_zero_fd = -1;
|
||||
}
|
||||
res = munmap(pages + page_size * 1, page_size);
|
||||
if (res < 0)
|
||||
{
|
||||
fprintf(stderr, "Unable to unmap page 2/4: %s\n", strerror(errno));
|
||||
/* Dysfunctional OSes */
|
||||
}
|
||||
munmap(pages + page_size * 3, page_size);
|
||||
if (res < 0)
|
||||
{
|
||||
fprintf(stderr, "Unable to unmap page 4/4: %s\n", strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
/* Copy the strings to the end of their respective pages. */
|
||||
length = strlen(glob) + 1;
|
||||
test_glob = pages + page_size * 1 - length;
|
||||
memcpy(test_glob, glob, length);
|
||||
length = strlen(name) + 1;
|
||||
test_name = pages + page_size * 3 - length;
|
||||
memcpy(test_name, name, length);
|
||||
|
||||
/* Perform the test. */
|
||||
return match(test_glob, test_name);
|
||||
}
|
||||
|
||||
void do_match_test(const struct match_test *test)
|
||||
{
|
||||
const char *candidate;
|
||||
unsigned int matched, not_matched;
|
||||
int res;
|
||||
|
||||
for (candidate = test->should_match, matched = 0;
|
||||
*candidate;
|
||||
candidate += strlen(candidate) + 1, ++matched) {
|
||||
res = test_match(test->glob, candidate);
|
||||
if (res != 0) {
|
||||
fprintf(stderr, "\"%s\" failed to match \"%s\".\n", test->glob, candidate);
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
for (candidate = test->shouldnt_match, not_matched = 0;
|
||||
*candidate;
|
||||
candidate += strlen(candidate) + 1, ++not_matched) {
|
||||
res = test_match(test->glob, candidate);
|
||||
if (res == 0) {
|
||||
fprintf(stderr, "\"%s\" incorrectly matched \"%s\".\n", test->glob, candidate);
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
printf("Passed: %s (%u matches, %u non-matches)\n",
|
||||
test->glob, matched, not_matched);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const struct match_test *match;
|
||||
for (match = match_tests; match->glob; ++match)
|
||||
do_match_test(match);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* ircd_string_t.c - string test program
|
||||
*/
|
||||
#include "ircd_string.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char* vector[20];
|
||||
char* names;
|
||||
int count;
|
||||
int i;
|
||||
|
||||
names = strdup(",,,a,b,a,X,ne,blah,A,z,#foo,&Bar,foo,,crud,Foo,z,x,bzet,,");
|
||||
printf("input: %s\n", names);
|
||||
count = unique_name_vector(names, ',', vector, 20);
|
||||
printf("count: %d\n", count);
|
||||
printf("output:");
|
||||
for (i = 0; i < count; ++i)
|
||||
printf(" %s", vector[i]);
|
||||
printf("\n");
|
||||
free(names);
|
||||
|
||||
names = strdup("foo");
|
||||
printf("input: %s\n", names);
|
||||
count = unique_name_vector(names, ',', vector, 20);
|
||||
printf("count: %d\n", count);
|
||||
printf("output:");
|
||||
for (i = 0; i < count; ++i)
|
||||
printf(" %s", vector[i]);
|
||||
printf("\n");
|
||||
free(names);
|
||||
|
||||
names = strdup("");
|
||||
printf("input: %s\n", names);
|
||||
count = unique_name_vector(names, ',', vector, 20);
|
||||
printf("count: %d\n", count);
|
||||
printf("output:");
|
||||
for (i = 0; i < count; ++i)
|
||||
printf(" %s", vector[i]);
|
||||
printf("\n");
|
||||
free(names);
|
||||
|
||||
names = strdup("a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z");
|
||||
printf("input: %s\n", names);
|
||||
count = unique_name_vector(names, ',', vector, 20);
|
||||
printf("count: %d\n", count);
|
||||
printf("output:");
|
||||
for (i = 0; i < count; ++i)
|
||||
printf(" %s", vector[i]);
|
||||
printf("\n");
|
||||
free(names);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
define srv localhost:7701
|
||||
|
||||
connect cl1 Alex alex %srv% :Test client 1
|
||||
:cl1 oper oper1 oper1
|
||||
:cl1 raw :jupe +irc-3.example.net 3600 :Server 3 not welcome here.
|
||||
:cl1 raw :jupe -irc-3.example.net 3600 :Server 3 not welcome here.
|
||||
:cl1 raw :jupe +irc-3.example.net * 3600 :Server 3 not welcome here.
|
||||
:cl1 raw :jupe -irc-3.example.net * 3600 :Server 3 not welcome here.
|
||||
@@ -0,0 +1,6 @@
|
||||
define srv localhost:7701
|
||||
|
||||
connect cl1 Alex sub7 %srv% :s7server
|
||||
connect cl2 Chloe chloe %srv% :Chloe
|
||||
cl1 sleep 30
|
||||
cl2 sleep 30
|
||||
@@ -0,0 +1,30 @@
|
||||
#! /bin/sh
|
||||
|
||||
set -e
|
||||
srcdir=`dirname $0`
|
||||
ircdir=$1
|
||||
|
||||
cp ${srcdir}/ircd-t1.conf ircd-t1.conf
|
||||
cp ${srcdir}/ircd-t2.conf ircd-t2.conf
|
||||
echo "Testing one-shot ircd invocations."
|
||||
${ircdir}/ircd -v
|
||||
${ircdir}/ircd -x 6 -k -d . -f ircd-t1.conf -c user@127.0.0.1
|
||||
echo "Starting ircd."
|
||||
${ircdir}/ircd -d . -f ircd-t1.conf
|
||||
${ircdir}/ircd -d . -f ircd-t2.conf
|
||||
sleep 10
|
||||
# stats-1 is out of alphabetical order to avoid triggering IPcheck.
|
||||
for script in channel-1 client-1 commands-1 feature-1 gline-1 stats-1 jupe-1 kill-block-1 ; do
|
||||
echo "Running test $script."
|
||||
${srcdir}/test-driver.pl -D ${srcdir}/${script}.cmd 2> ${script}.log
|
||||
done
|
||||
echo "Sending signals to server."
|
||||
cp ${srcdir}/ircd-t1-2.conf ircd-t1.conf
|
||||
kill -HUP `cat ircd-t1.pid`
|
||||
sleep 1
|
||||
kill -INT `cat ircd-t1.pid`
|
||||
# A long sleep is necessary to make the server flush its IPcheck entries.
|
||||
sleep 610
|
||||
kill -TERM `cat ircd-t1.pid` `cat ircd-t2.pid`
|
||||
sleep 1
|
||||
${ircdir}/ircd -? || true
|
||||
@@ -0,0 +1,97 @@
|
||||
# Connect to server
|
||||
connect cl1 Alex alex localhost:7701 :Test client 1
|
||||
:cl1 oper oper1 oper1
|
||||
|
||||
# Single letter stats commands
|
||||
:cl1 raw :stats a
|
||||
:cl1 raw :stats c
|
||||
:cl1 raw :stats d
|
||||
:cl1 raw :stats D
|
||||
:cl1 raw :stats e
|
||||
:cl1 raw :stats f
|
||||
:cl1 raw :stats g
|
||||
:cl1 raw :stats i
|
||||
:cl1 raw :stats j
|
||||
:cl1 raw :stats J
|
||||
:cl1 raw :stats k
|
||||
:cl1 raw :stats l
|
||||
:cl1 raw :stats L
|
||||
:cl1 raw :stats m
|
||||
:cl1 raw :stats o
|
||||
:cl1 raw :stats p
|
||||
:cl1 raw :stats q
|
||||
:cl1 raw :stats r
|
||||
:cl1 raw :stats R
|
||||
:cl1 raw :stats t
|
||||
:cl1 raw :stats T
|
||||
:cl1 raw :stats u
|
||||
:cl1 raw :stats U
|
||||
:cl1 raw :stats v
|
||||
:cl1 raw :stats V
|
||||
:cl1 raw :stats w
|
||||
:cl1 raw :stats x
|
||||
:cl1 raw :stats z
|
||||
:cl1 raw :stats *
|
||||
|
||||
# Remote stats requests
|
||||
:cl1 raw :stats f test-2.*
|
||||
|
||||
# Named stats commands
|
||||
:cl1 raw :stats nameservers
|
||||
:cl1 raw :stats connect
|
||||
:cl1 raw :stats maskrules
|
||||
:cl1 raw :stats crules
|
||||
:cl1 raw :stats engine
|
||||
:cl1 raw :stats features
|
||||
:cl1 raw :stats glines
|
||||
:cl1 raw :stats access
|
||||
:cl1 raw :stats histogram
|
||||
:cl1 raw :stats jupes
|
||||
:cl1 raw :stats klines
|
||||
:cl1 raw :stats links
|
||||
:cl1 raw :stats modules
|
||||
:cl1 raw :stats commands
|
||||
:cl1 raw :stats operators
|
||||
:cl1 raw :stats ports
|
||||
:cl1 raw :stats quarantines
|
||||
:cl1 raw :stats mappings
|
||||
:cl1 raw :stats usage
|
||||
:cl1 raw :stats motds
|
||||
:cl1 raw :stats locals
|
||||
:cl1 raw :stats uworld
|
||||
:cl1 raw :stats uptime
|
||||
:cl1 raw :stats vservers
|
||||
:cl1 raw :stats vserversmach
|
||||
:cl1 raw :stats userload
|
||||
:cl1 raw :stats memusage
|
||||
:cl1 raw :stats classes
|
||||
:cl1 raw :stats memory
|
||||
:cl1 raw :stats help
|
||||
:cl1 raw :hash
|
||||
:cl1 raw :rehash m
|
||||
:cl1 raw :rehash l
|
||||
:cl1 raw :rehash q
|
||||
:cl1 raw :rehash
|
||||
:cl1 nick Alexey
|
||||
|
||||
# Varparam stats
|
||||
:cl1 raw :stats access * 127.0.0.1
|
||||
:cl1 raw :stats access * *
|
||||
:cl1 raw :stats klines * *
|
||||
:cl1 raw :stats klines * *@*
|
||||
:cl1 raw :stats links * *
|
||||
:cl1 raw :stats ports * 7700
|
||||
:cl1 raw :stats quarantines * #frou-frou
|
||||
:cl1 raw :stats vservers * *.example.net
|
||||
|
||||
# Invalid or nonexistent stats requests
|
||||
:cl1 raw :stats y
|
||||
:cl1 raw :stats ÿ
|
||||
:cl1 raw :stats mºD٣˧
|
||||
:cl1 raw :stats long_garbage_here_to_hopefully_trigger_the_core_reported_by_dan
|
||||
|
||||
# Drop oper status and try a few others
|
||||
:cl1 mode Alex -o
|
||||
:cl1 raw :stats k
|
||||
:cl1 raw :stats k * *
|
||||
:cl1 raw :stats k * *@*
|
||||
@@ -0,0 +1,545 @@
|
||||
#! /usr/bin/perl -wT
|
||||
|
||||
# If you edit this file, please check carefully that the garbage
|
||||
# collection isn't broken. POE is sometimes too clever for our good
|
||||
# in finding references to sessions, and keeps running even after we
|
||||
# want to stop.
|
||||
# $Id: test-driver.pl 1419 2005-05-31 00:26:19Z entrope $
|
||||
|
||||
# This interprets a simple scripting language. Lines starting with a
|
||||
# hash mark (#, aka octothorpe, pound sign, etc) are ignored. The
|
||||
# special commands look like this, where angle brackets indicate a
|
||||
# metavariable:
|
||||
# define <macro> <value>
|
||||
# undef <macro>
|
||||
# connect <name> <nick> <ident> <server> :<userinfo>
|
||||
# sync <name1>,<name2>[,<name3>]*
|
||||
# :<name> <command>[ <args]*
|
||||
# For the last line syntax, <command> may be an IRC or IRC-like
|
||||
# command. Supported non-IRC commands are:
|
||||
# :<name> expect <source|*name2> [...]
|
||||
# :<name> raw <text>
|
||||
# :<name> sleep <seconds>
|
||||
# :<name> wait <name2>
|
||||
|
||||
require 5.006;
|
||||
|
||||
use bytes;
|
||||
use warnings;
|
||||
use strict;
|
||||
use vars;
|
||||
use constant DELAY => 2;
|
||||
use constant EXPECT_TIMEOUT => 15;
|
||||
use constant RECONNECT_TIMEOUT => 5;
|
||||
use constant THROTTLED_TIMEOUT => 90;
|
||||
|
||||
use FileHandle;
|
||||
use POE;
|
||||
use POE::Component::IRC;
|
||||
|
||||
# this defines commands that take "zero time" to execute
|
||||
# (specifically, those which do not send commands from the issuing
|
||||
# client to the server)
|
||||
our $zero_time = {
|
||||
expect => 1,
|
||||
sleep => 1,
|
||||
wait => 1,
|
||||
};
|
||||
|
||||
# Create the main session and start POE.
|
||||
# All the empty anonymous subs are just to make POE:Session::ASSERT_STATES happy.
|
||||
POE::Session->create(inline_states =>
|
||||
{
|
||||
# POE kernel interaction
|
||||
_start => \&drv_start,
|
||||
_child => sub {},
|
||||
_stop => sub {
|
||||
my $heap = $_[HEAP];
|
||||
print "\nThat's all, folks!";
|
||||
print "(exiting at line $heap->{lineno}: $heap->{line})"
|
||||
if $heap->{line};
|
||||
print "\n";
|
||||
},
|
||||
_default => \&drv_default,
|
||||
# generic utilities or miscellaneous functions
|
||||
heartbeat => \&drv_heartbeat,
|
||||
timeout_expect => \&drv_timeout_expect,
|
||||
reconnect => \&drv_reconnect,
|
||||
enable_client => sub { $_[ARG0]->{ready} = 1; },
|
||||
disable_client => sub { $_[ARG0]->{ready} = 0; },
|
||||
die => sub { $_[KERNEL]->signal($_[SESSION], 'TERM'); },
|
||||
# client-based command issuers
|
||||
cmd_die => \&cmd_generic,
|
||||
cmd_expect => \&cmd_expect,
|
||||
cmd_invite => \&cmd_generic,
|
||||
cmd_join => \&cmd_generic,
|
||||
cmd_mode => \&cmd_generic,
|
||||
cmd_nick => \&cmd_generic,
|
||||
cmd_notice => \&cmd_message,
|
||||
cmd_oper => \&cmd_generic,
|
||||
cmd_part => \&cmd_generic,
|
||||
cmd_privmsg => \&cmd_message,
|
||||
cmd_quit => \&cmd_generic,
|
||||
cmd_raw => \&cmd_raw,
|
||||
cmd_sleep => \&cmd_sleep,
|
||||
cmd_wait => \&cmd_wait,
|
||||
# handlers for messages from IRC
|
||||
irc_001 => \&irc_connected, # Welcome to ...
|
||||
irc_snotice => sub {}, # notice from a server (anonymous/our uplink)
|
||||
irc_notice => \&irc_notice, # NOTICE to self or channel
|
||||
irc_msg => \&irc_msg, # PRIVMSG to self
|
||||
irc_public => \&irc_public, # PRIVMSG to channel
|
||||
irc_connected => sub {},
|
||||
irc_ctcp_action => sub {},
|
||||
irc_ctcp_ping => sub {},
|
||||
irc_ctcp_time => sub {},
|
||||
irc_ctcpreply_ping => sub {},
|
||||
irc_ctcpreply_time => sub {},
|
||||
irc_invite => \&irc_invite, # INVITE to channel
|
||||
irc_join => sub {},
|
||||
irc_kick => sub {},
|
||||
irc_kill => sub {},
|
||||
irc_mode => sub {},
|
||||
irc_nick => sub {},
|
||||
irc_part => sub {},
|
||||
irc_ping => sub {},
|
||||
irc_pong => sub {},
|
||||
irc_rpong => sub {},
|
||||
irc_quit => sub {},
|
||||
irc_topic => sub {},
|
||||
irc_plugin_add => sub {},
|
||||
irc_error => \&irc_error,
|
||||
irc_disconnected => \&irc_disconnected,
|
||||
irc_socketerr => \&irc_socketerr,
|
||||
},
|
||||
args => [@ARGV]);
|
||||
|
||||
$| = 1;
|
||||
$poe_kernel->run();
|
||||
exit;
|
||||
|
||||
# Core/bookkeeping test driver functions
|
||||
|
||||
sub drv_start {
|
||||
my ($kernel, $session, $heap) = @_[KERNEL, SESSION, HEAP];
|
||||
|
||||
# initialize heap
|
||||
$heap->{clients} = {}; # session details, indexed by (short) session name
|
||||
$heap->{sessions} = {}; # session details, indexed by session ref
|
||||
$heap->{servers} = {}; # server addresses, indexed by short names
|
||||
$heap->{macros} = {}; # macros
|
||||
|
||||
# Parse arguments
|
||||
foreach my $arg (@_[ARG0..$#_]) {
|
||||
if ($arg =~ /^-D$/) {
|
||||
$heap->{irc_debug} = 1;
|
||||
} elsif ($arg =~ /^-V$/) {
|
||||
$heap->{verbose} = 1;
|
||||
} elsif ($arg =~ /^-vhost=(.*)$/) {
|
||||
$heap->{vhost} = $1;
|
||||
} else {
|
||||
die "Extra command-line argument $arg\n" if $heap->{script};
|
||||
$heap->{script} = new FileHandle($arg, 'r')
|
||||
or die "Unable to open $arg for reading: $!\n";
|
||||
}
|
||||
}
|
||||
die "No test name specified\n" unless $heap->{script};
|
||||
|
||||
# hook in to POE
|
||||
$kernel->alias_set('control');
|
||||
$kernel->yield('heartbeat');
|
||||
}
|
||||
|
||||
sub drv_heartbeat {
|
||||
my ($kernel, $session, $heap) = @_[KERNEL, SESSION, HEAP];
|
||||
my $script = $heap->{script};
|
||||
my $used = {};
|
||||
my $delay = DELAY;
|
||||
|
||||
while (1) {
|
||||
my ($line, $lineno);
|
||||
if ($heap->{line}) {
|
||||
$line = delete $heap->{line};
|
||||
} elsif (defined($line = <$script>)) {
|
||||
$heap->{lineno} = $.;
|
||||
print "." unless $heap->{irc_debug};
|
||||
} else {
|
||||
# close all connections
|
||||
foreach my $client (values %{$heap->{clients}}) {
|
||||
$kernel->call($client->{irc}, 'quit', "I fell off the end of my script");
|
||||
$client->{quitting} = 1;
|
||||
}
|
||||
# unalias the control session
|
||||
$kernel->alias_remove('control');
|
||||
# die in a few seconds
|
||||
$kernel->delay_set('die', 5);
|
||||
return;
|
||||
}
|
||||
|
||||
chomp $line;
|
||||
# ignore comments and blank lines
|
||||
next if $line =~ /^\#/ or $line !~ /\S/;
|
||||
|
||||
# expand any macros in the line
|
||||
$line =~ s/(?<=[^\\])%(\S+?)%/$heap->{macros}->{$1}
|
||||
or die "Use of undefined macro $1 at $heap->{lineno}\n"/eg;
|
||||
# remove any \-escapes
|
||||
$line =~ s/\\(.)/$1/g;
|
||||
# figure out the type of line
|
||||
if ($line =~ /^#/) {
|
||||
# comment, silently ignore it
|
||||
} elsif ($line =~ /^define (\S+) (.+)$/i) {
|
||||
# define a new macro
|
||||
$heap->{macros}->{$1} = $2;
|
||||
} elsif ($line =~ /^undef (\S+)$/i) {
|
||||
# remove the macro
|
||||
delete $heap->{macros}->{$1};
|
||||
} elsif ($line =~ /^connect (\S+) (\S+) (\S+) (\S+) :(.+)$/i) {
|
||||
# connect a new session (named $1) to server $4
|
||||
my ($name, $nick, $ident, $server, $userinfo, $port) = ($1, $2, $3, $4, $5, 6667);
|
||||
$server = $heap->{servers}->{$server} || $server;
|
||||
if ($server =~ /(.+):(\d+)/) {
|
||||
$server = $1;
|
||||
$port = $2;
|
||||
}
|
||||
die "Client with nick $nick already exists (line $heap->{lineno})" if $heap->{clients}->{$nick};
|
||||
my $alias = "client_$name";
|
||||
POE::Component::IRC->new($alias)
|
||||
or die "Unable to create new user $nick (line $heap->{lineno}): $!";
|
||||
my $client = { name => $name,
|
||||
nick => $nick,
|
||||
ready => 0,
|
||||
expect => [],
|
||||
expect_alarms => [],
|
||||
irc => $kernel->alias_resolve($alias),
|
||||
params => { Nick => $nick,
|
||||
Server => $server,
|
||||
Port => $port,
|
||||
Username => $ident,
|
||||
Ircname => $userinfo,
|
||||
Debug => $heap->{irc_debug},
|
||||
}
|
||||
};
|
||||
$client->params->{LocalAddr} = $heap->{vhost}
|
||||
if $heap->{vhost};
|
||||
$heap->{clients}->{$client->{name}} = $client;
|
||||
$heap->{sessions}->{$client->{irc}} = $client;
|
||||
$kernel->call($client->{irc}, 'register', 'all');
|
||||
$kernel->call($client->{irc}, 'connect', $client->{params});
|
||||
$used->{$name} = 1;
|
||||
} elsif ($line =~ /^sync (.+)$/i) {
|
||||
# do multi-way synchronization between every session named in $1
|
||||
my @synced = split(/,|\s/, $1);
|
||||
# first, check that they exist and are ready
|
||||
foreach my $clnt (@synced) {
|
||||
die "Unknown session name $clnt (line $heap->{lineno})" unless $heap->{clients}->{$clnt};
|
||||
goto REDO unless $heap->{clients}->{$clnt}->{ready};
|
||||
}
|
||||
# next we actually send the synchronization signals
|
||||
foreach my $clnt (@synced) {
|
||||
my $client = $heap->{clients}->{$clnt};
|
||||
$client->{sync_wait} = [map { $_ eq $clnt ? () : $heap->{clients}->{$_}->{nick} } @synced];
|
||||
$kernel->call($client->{irc}, 'notice', $client->{sync_wait}, 'SYNC');
|
||||
$kernel->call($session, 'disable_client', $client);
|
||||
}
|
||||
} elsif ($line =~ /^:(\S+) (\S+)(.*)$/i) {
|
||||
# generic command handler
|
||||
my ($names, $cmd, $args) = ($1, lc($2), $3);
|
||||
my (@avail, @unavail);
|
||||
# figure out whether each listed client is available or not
|
||||
foreach my $c (split ',', $names) {
|
||||
my $client = $heap->{clients}->{$c};
|
||||
if (not $client) {
|
||||
print "ERROR: Unknown session name $c (line $heap->{lineno}; ignoring)\n";
|
||||
} elsif (($used->{$c} and not $zero_time->{$cmd}) or not $client->{ready}) {
|
||||
push @unavail, $c;
|
||||
} else {
|
||||
push @avail, $c;
|
||||
}
|
||||
}
|
||||
# redo command with unavailable clients
|
||||
if (@unavail) {
|
||||
# This will break if the command can cause a redo for
|
||||
# available clients.. this should be fixed sometime
|
||||
$line = ':'.join(',', @unavail).' '.$cmd.$args;
|
||||
$heap->{redo} = 1;
|
||||
}
|
||||
# do command with available clients
|
||||
if (@avail) {
|
||||
# split up the argument part of the line
|
||||
$args =~ /^((?:(?: [^:])|[^ ])+)?(?: :(.+))?$/;
|
||||
$args = [($1 ? split(' ', $1) : ()), ($2 ? $2 : ())];
|
||||
# find the client and figure out if we need to wait
|
||||
foreach my $c (@avail) {
|
||||
my $client = $heap->{clients}->{$c};
|
||||
die "Client $c used twice as source (line $heap->{lineno})" if $used->{c} and not $zero_time->{$cmd};
|
||||
$kernel->call($session, 'cmd_'.$cmd, $client, $args);
|
||||
$used->{$c} = 1 unless $zero_time->{$cmd};
|
||||
}
|
||||
}
|
||||
} else {
|
||||
die "Unrecognized input line $heap->{lineno}: $line";
|
||||
}
|
||||
if ($heap->{redo}) {
|
||||
REDO:
|
||||
delete $heap->{redo};
|
||||
$heap->{line} = $line;
|
||||
last;
|
||||
}
|
||||
}
|
||||
# issue new heartbeat with appropriate delay
|
||||
$kernel->delay_set('heartbeat', $delay);
|
||||
}
|
||||
|
||||
sub drv_timeout_expect {
|
||||
my ($kernel, $session, $client) = @_[KERNEL, SESSION, ARG0];
|
||||
print "ERROR: Dropping timed-out expectation by $client->{name}: ".join(',', @{$client->{expect}->[0]})."\n";
|
||||
$client->{expect_alarms}->[0] = undef;
|
||||
unexpect($kernel, $session, $client);
|
||||
}
|
||||
|
||||
sub drv_reconnect {
|
||||
my ($kernel, $session, $client) = @_[KERNEL, SESSION, ARG0];
|
||||
$kernel->call($client->{irc}, 'connect', $client->{params});
|
||||
}
|
||||
|
||||
sub drv_default {
|
||||
my ($kernel, $heap, $sender, $session, $state, $args) = @_[KERNEL, HEAP, SENDER, SESSION, ARG0, ARG1];
|
||||
if ($state =~ /^irc_(\d\d\d)$/) {
|
||||
my $client = $heap->{sessions}->{$sender};
|
||||
if (@{$client->{expect}}
|
||||
and $args->[0] eq $client->{expect}->[0]->[0]
|
||||
and $client->{expect}->[0]->[1] eq "$1") {
|
||||
my $expect = $client->{expect}->[0];
|
||||
my $mismatch;
|
||||
for (my $x=2; ($x<=$#$expect) and ($x<=$#$args) and not $mismatch; $x++) {
|
||||
$mismatch = 1 unless $args->[$x] =~ /$expect->[$x]/i;
|
||||
}
|
||||
unexpect($kernel, $session, $client) unless $mismatch;
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
print "ERROR: Unexpected event $state to test driver (from ".$sender->ID.")\n"
|
||||
unless $state eq '_signal';
|
||||
return undef;
|
||||
}
|
||||
|
||||
# client-based command issuers
|
||||
|
||||
sub cmd_message {
|
||||
my ($kernel, $heap, $event, $client, $args) = @_[KERNEL, HEAP, STATE, ARG0, ARG1];
|
||||
die "Missing arguments" unless $#$args >= 1;
|
||||
# translate each target as appropriate (e.g. *sessionname)
|
||||
my @targets = split(/,/, $args->[0]);
|
||||
foreach my $target (@targets) {
|
||||
if ($target =~ /^\*(.+)$/) {
|
||||
my $other = $heap->{clients}->{$1} or die "Unknown session name $1 (line $heap->{lineno})\n";
|
||||
$target = $other->{nick};
|
||||
}
|
||||
}
|
||||
$kernel->call($client->{irc}, substr($event, 4), \@targets, $args->[1]);
|
||||
}
|
||||
|
||||
sub cmd_generic {
|
||||
my ($kernel, $heap, $event, $client, $args) = @_[KERNEL, HEAP, STATE, ARG0, ARG1];
|
||||
$event =~ s/^cmd_//;
|
||||
$kernel->call($client->{irc}, $event, @$args);
|
||||
}
|
||||
|
||||
sub cmd_raw {
|
||||
my ($kernel, $heap, $client, $args) = @_[KERNEL, HEAP, ARG0, ARG1];
|
||||
die "Missing argument" unless $#$args >= 0;
|
||||
$kernel->call($client->{irc}, 'sl', $args->[0]);
|
||||
}
|
||||
|
||||
sub cmd_sleep {
|
||||
my ($kernel, $session, $heap, $client, $args) = @_[KERNEL, SESSION, HEAP, ARG0, ARG1];
|
||||
die "Missing argument" unless $#$args >= 0;
|
||||
$kernel->call($session, 'disable_client', $client);
|
||||
$kernel->delay_set('enable_client', $args->[0], $client);
|
||||
}
|
||||
|
||||
sub cmd_wait {
|
||||
my ($kernel, $session, $heap, $client, $args) = @_[KERNEL, SESSION, HEAP, ARG0, ARG1];
|
||||
die "Missing argument" unless $#$args >= 0;
|
||||
# if argument was comma-delimited, split it up (space-delimited is split by generic parser)
|
||||
$args = [split(/,/, $args->[0])] if $args->[0] =~ /,/;
|
||||
# make sure we only wait if all the other clients are ready
|
||||
foreach my $other (@$args) {
|
||||
if (not $heap->{clients}->{$other}->{ready}) {
|
||||
$heap->{redo} = 1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
# disable this client, make the others send SYNC to it
|
||||
$kernel->call($session, 'disable_client', $client);
|
||||
$client->{sync_wait} = [map { $heap->{clients}->{$_}->{nick} } @$args];
|
||||
foreach my $other (@$args) {
|
||||
die "Cannot wait on self" if $other eq $client->{name};
|
||||
$kernel->call($heap->{clients}->{$other}->{irc}, 'notice', $client->{nick}, 'SYNC');
|
||||
}
|
||||
}
|
||||
|
||||
sub cmd_expect {
|
||||
my ($kernel, $session, $heap, $client, $args) = @_[KERNEL, SESSION, HEAP, ARG0, ARG1];
|
||||
die "Missing argument" unless $#$args >= 0;
|
||||
push @{$client->{expect}}, $args;
|
||||
push @{$client->{expect_alarms}}, $kernel->delay_set('timeout_expect', EXPECT_TIMEOUT, $client);
|
||||
$kernel->call($session, 'disable_client', $client);
|
||||
}
|
||||
|
||||
# handlers for messages from IRC
|
||||
|
||||
sub unexpect {
|
||||
my ($kernel, $session, $client) = @_;
|
||||
shift @{$client->{expect}};
|
||||
my $alarm_id = shift @{$client->{expect_alarms}};
|
||||
$kernel->alarm_remove($alarm_id) if $alarm_id;
|
||||
$kernel->call($session, 'enable_client', $client) unless @{$client->{expect}};
|
||||
}
|
||||
|
||||
sub check_expect {
|
||||
my ($kernel, $session, $heap, $poe_sender, $sender, $text) = @_[KERNEL, SESSION, HEAP, SENDER, ARG0, ARG1];
|
||||
my $client = $heap->{sessions}->{$poe_sender};
|
||||
my $expected = $client->{expect}->[0];
|
||||
|
||||
# check sender
|
||||
if ($expected->[0] =~ /\*(.+)/) {
|
||||
# we expect *sessionname, so look up session's current nick
|
||||
my $exp = $1;
|
||||
$sender =~ /^(.+)!/;
|
||||
return 0 if lc($heap->{clients}->{$exp}->{nick}) ne lc($1);
|
||||
} elsif ($expected->[0] =~ /^:?(.+!.+)/) {
|
||||
# expect :nick!user@host, so compare whole thing
|
||||
return 0 if lc($1) ne lc($sender);
|
||||
} else {
|
||||
# we only expect :nick, so compare that part
|
||||
$sender =~ /^:?(.+)!/;
|
||||
return 0 if lc($expected->[0]) ne lc($1);
|
||||
}
|
||||
|
||||
# compare text
|
||||
return 0 if lc($text) !~ /$expected->[2]/i;
|
||||
|
||||
# drop expectation of event
|
||||
unexpect($kernel, $session, $client);
|
||||
}
|
||||
|
||||
sub irc_connected {
|
||||
my ($kernel, $session, $heap, $sender) = @_[KERNEL, SESSION, HEAP, SENDER];
|
||||
my $client = $heap->{sessions}->{$sender};
|
||||
print "Client $client->{name} connected to server $_[ARG0]\n" if $heap->{verbose};
|
||||
$kernel->call($session, 'enable_client', $client);
|
||||
}
|
||||
|
||||
sub irc_disconnected {
|
||||
my ($kernel, $session, $heap, $sender, $server) = @_[KERNEL, SESSION, HEAP, SENDER, ARG0];
|
||||
my $client = $heap->{sessions}->{$sender};
|
||||
print "Client $client->{name} disconnected from server $_[ARG0]\n" if $heap->{verbose};
|
||||
if ($client->{quitting}) {
|
||||
$kernel->call($sender, 'unregister', 'all');
|
||||
delete $heap->{sessions}->{$sender};
|
||||
delete $heap->{clients}->{$client->{name}};
|
||||
} else {
|
||||
if ($client->{disconnect_expected}) {
|
||||
delete $client->{disconnect_expected};
|
||||
} else {
|
||||
print "Got unexpected disconnect for $client->{name} (nick $client->{nick})\n";
|
||||
}
|
||||
$kernel->call($session, 'disable_client', $client);
|
||||
$kernel->delay_set('reconnect', $client->{throttled} ? THROTTLED_TIMEOUT : RECONNECT_TIMEOUT, $client);
|
||||
delete $client->{throttled};
|
||||
}
|
||||
}
|
||||
|
||||
sub irc_socketerr {
|
||||
my ($kernel, $session, $heap, $sender, $msg) = @_[KERNEL, SESSION, HEAP, SENDER, ARG0];
|
||||
my $client = $heap->{sessions}->{$sender};
|
||||
print "Client $client->{name} (re-)connect error: $_[ARG0]\n";
|
||||
if ($client->{quitting}) {
|
||||
$kernel->call($sender, 'unregister', 'all');
|
||||
delete $heap->{sessions}->{$sender};
|
||||
delete $heap->{clients}->{$client->{name}};
|
||||
} else {
|
||||
if ($client->{disconnect_expected}) {
|
||||
delete $client->{disconnect_expected};
|
||||
} else {
|
||||
print "Got unexpected disconnect for $client->{name} (nick $client->{nick})\n";
|
||||
}
|
||||
$kernel->call($session, 'disable_client', $client);
|
||||
$kernel->delay_set('reconnect', $client->{throttled} ? THROTTLED_TIMEOUT : RECONNECT_TIMEOUT, $client);
|
||||
delete $client->{throttled};
|
||||
}
|
||||
}
|
||||
|
||||
sub irc_notice {
|
||||
my ($kernel, $session, $heap, $sender, $from, $to, $text) = @_[KERNEL, SESSION, HEAP, SENDER, ARG0, ARG1, ARG2];
|
||||
my $client = $heap->{sessions}->{$sender};
|
||||
if ($client->{sync_wait} and $text eq 'SYNC') {
|
||||
$from =~ s/!.+$//;
|
||||
my $x;
|
||||
# find who sent it..
|
||||
for ($x=0; $x<=$#{$client->{sync_wait}}; $x++) {
|
||||
last if $from eq $client->{sync_wait}->[$x];
|
||||
}
|
||||
# exit if we don't expect them
|
||||
if ($x>$#{$client->{sync_wait}}) {
|
||||
print "Got unexpected SYNC from $from to $client->{name} ($client->{nick})\n";
|
||||
return;
|
||||
}
|
||||
# remove from the list of people we're waiting for
|
||||
splice @{$client->{sync_wait}}, $x, 1;
|
||||
# re-enable client if we're done waiting
|
||||
if ($#{$client->{sync_wait}} == -1) {
|
||||
delete $client->{sync_wait};
|
||||
$kernel->call($session, 'enable_client', $client);
|
||||
}
|
||||
} elsif (@{$client->{expect}}
|
||||
and $client->{expect}->[0]->[1] =~ /notice/i) {
|
||||
check_expect(@_[0..ARG0], $text);
|
||||
}
|
||||
}
|
||||
|
||||
sub irc_msg {
|
||||
my ($kernel, $session, $heap, $sender, $from, $to, $text) = @_[KERNEL, SESSION, HEAP, SENDER, ARG0, ARG1, ARG2];
|
||||
my $client = $heap->{sessions}->{$sender};
|
||||
if (@{$client->{expect}}
|
||||
and $client->{expect}->[0]->[1] =~ /msg/i) {
|
||||
check_expect(@_[0..ARG0], $text);
|
||||
}
|
||||
}
|
||||
|
||||
sub irc_public {
|
||||
my ($kernel, $session, $heap, $sender, $from, $to, $text) = @_[KERNEL, SESSION, HEAP, SENDER, ARG0, ARG1, ARG2];
|
||||
my $client = $heap->{sessions}->{$sender};
|
||||
if (@{$client->{expect}}
|
||||
and $client->{expect}->[0]->[1] =~ /public/i
|
||||
and grep($client->{expect}->[0]->[2], @$to)) {
|
||||
splice @{$client->{expect}->[0]}, 2, 1;
|
||||
check_expect(@_[0..ARG0], $text);
|
||||
}
|
||||
}
|
||||
|
||||
sub irc_invite {
|
||||
my ($kernel, $session, $heap, $sender, $from, $to) = @_[KERNEL, SESSION, HEAP, SENDER, ARG0, ARG1, ARG2];
|
||||
my $client = $heap->{sessions}->{$sender};
|
||||
if (ref $client->{expect} eq 'ARRAY'
|
||||
and $client->{expect}->[0]->[1] =~ /invite/i
|
||||
and $to =~ /$client->{expect}->[0]->[2]/) {
|
||||
check_expect(@_[0..ARG0], $to);
|
||||
}
|
||||
}
|
||||
|
||||
sub irc_error {
|
||||
my ($kernel, $session, $heap, $sender, $what) = @_[KERNEL, SESSION, HEAP, SENDER, ARG0];
|
||||
my $client = $heap->{sessions}->{$sender};
|
||||
if (@{$client->{expect}}
|
||||
and $client->{expect}->[0]->[1] =~ /error/i) {
|
||||
splice @{$client->{expect}->[0]}, 2, 1;
|
||||
unexpect($kernel, $session, $client);
|
||||
$client->{disconnect_expected} = 1;
|
||||
} else {
|
||||
print "ERROR: From server to $client->{name}: $what\n";
|
||||
}
|
||||
$client->{throttled} = 1 if $what =~ /throttled/i;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/* test_stub.c - support stubs for test programs */
|
||||
|
||||
#include "client.h"
|
||||
#include "ircd_log.h"
|
||||
#include "s_debug.h"
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
struct Client me;
|
||||
int log_inassert;
|
||||
|
||||
void
|
||||
log_write(enum LogSys subsys, enum LogLevel severity, unsigned int flags,
|
||||
const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
vfprintf(stderr, fmt, args);
|
||||
fputc('\n', stderr);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void
|
||||
debug(int level, const char *form, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, form);
|
||||
vfprintf(stdout, form, args);
|
||||
fputc('\n', stdout);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
int
|
||||
exit_client(struct Client *cptr, struct Client *victim, struct Client *killer,
|
||||
const char *comment)
|
||||
{
|
||||
Debug((DEBUG_LIST, "exit_client(%p, %p, %p, \"%s\")\n", cptr, victim, killer, comment));
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user