Skip to content

Commit

Permalink
Merge.
Browse files Browse the repository at this point in the history
  • Loading branch information
retropc committed May 4, 2014
2 parents 8a12ea2 + b74ab3c commit 285076e
Show file tree
Hide file tree
Showing 15 changed files with 73 additions and 24 deletions.
2 changes: 1 addition & 1 deletion build.mk.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ HOOK_ENGINE=old
endif

ifndef BUILDID
BUILDID = $(shell (hg id || echo "unknown") | sed -e "s/[()]//g;s/+ /+/g;s/ /-/g" )
BUILDID := $(shell (hg id || echo "unknown") | sed -e "s/[()]//g;s/+ /+/g;s/ /-/g" )
endif
MFLAGS+=BUILDID=$(BUILDID)

Expand Down
2 changes: 1 addition & 1 deletion channel/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void _init() {
* before we register all our hooks which would otherwise get called
* during the disconnect. */
if (connected) {
irc_send("%s SQ %s 0 :Resync [adding channel support]",mynumeric->content,myserver->content); irc_disconnected();
irc_send("%s SQ %s 0 :Resync [adding channel support]",mynumeric->content,myserver->content); irc_disconnected(0);
}

/* Set up our hooks */
Expand Down
2 changes: 1 addition & 1 deletion chanserv/chancmds/addchan.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ int csc_doaddchan(void *source, int cargc, char **cargv) {
return CMD_ERROR;
}

rcp=cs_addchan(cip, sender, rup, founder, flags, type);
rcp=cs_addchan(cip, sender, rup, founder, flags, CHANMODE_DEFAULT, 0, type);
if(rcp == NULL) {
chanservstdmessage(sender, QM_ALREADYREGISTERED, cip->name->content);
if (notify)
Expand Down
2 changes: 1 addition & 1 deletion chanserv/chanserv.h
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ flag_t cs_sanitisechanlev(flag_t flags);
int cs_unbanfn(nick *sender, chanindex *cip, int (*fn)(void *arg, struct chanban *ban), void *arg, int removepermbans, int abortonfailure);
void cs_logchanop(regchan *rcp, char *nick, reguser *rup);
int checkreason(nick *np, char *reason);
regchan *cs_addchan(chanindex *cip, nick *sender, reguser *addedby, reguser *founder, flag_t flags, short type);
regchan *cs_addchan(chanindex *cip, nick *sender, reguser *addedby, reguser *founder, flag_t flags, flag_t forcemodes, flag_t denymodes, short type);

/* chanservstdcmds.c */
int cs_doshowcommands(void *source, int cargc, char **cargv);
Expand Down
2 changes: 1 addition & 1 deletion chanserv/chanserv_relay.c
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ int csa_doaddchan(void *source, int cargc, char **cargv) {
return CMD_ERROR;
}

rcp = cs_addchan(cip, sender, rup, founder, QCFLAG_JOINED, type);
rcp = cs_addchan(cip, sender, rup, founder, QCFLAG_JOINED | QCFLAG_AUTOOP | QCFLAG_BITCH | QCFLAG_FORCETOPIC | QCFLAG_PROTECT | QCFLAG_TOPICSAVE, CHANMODE_NOCTCP | CHANMODE_DELJOINS | CHANMODE_MODNOAUTH | CHANMODE_NONOTICE | CHANMODE_NOEXTMSG | CHANMODE_SINGLETARG | CHANMODE_TOPICLIMIT | CHANMODE_NOQUITMSG, 0, type);
if(!rcp) {
controlreply(sender, "ADDCHAN FALSE alreadyregistered");
return CMD_ERROR;
Expand Down
6 changes: 3 additions & 3 deletions chanserv/chanservuser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1445,7 +1445,7 @@ int checkreason(nick *np, char *reason) {
return 1;
}

regchan *cs_addchan(chanindex *cip, nick *sender, reguser *addedby, reguser *founder, flag_t flags, short type) {
regchan *cs_addchan(chanindex *cip, nick *sender, reguser *addedby, reguser *founder, flag_t flags, flag_t forcemodes, flag_t denymodes, short type) {
regchan *rcp;
regchanuser *rcup;
void *args[3];
Expand All @@ -1469,8 +1469,8 @@ regchan *cs_addchan(chanindex *cip, nick *sender, reguser *addedby, reguser *fou
rcp->lastcountersync=0;

rcp->limit=0;
rcp->forcemodes=CHANMODE_DEFAULT;
rcp->denymodes=0;
rcp->forcemodes=forcemodes;
rcp->denymodes=denymodes;

if (CIsAutoLimit(rcp)) {
rcp->forcemodes |= CHANMODE_LIMIT;
Expand Down
2 changes: 1 addition & 1 deletion control/control-lite.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ int relink(void *sender, int cargc, char **cargv) {
}

irc_send("%s SQ %s 0 :%s",mynumeric->content,myserver->content,cargv[0]);
irc_disconnected();
irc_disconnected(0);

return CMD_OK;
}
Expand Down
2 changes: 1 addition & 1 deletion control/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ int relink(void *sender, int cargc, char **cargv) {
}

irc_send("%s SQ %s 0 :%s",mynumeric->content,myserver->content,cargv[0]);
irc_disconnected();
irc_disconnected(0);

return CMD_OK;
}
Expand Down
1 change: 1 addition & 0 deletions core/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ int main(int argc, char **argv) {

/* Loading the modules will bring in the bulk of the code */
initmodules();
signal(SIGPIPE, SIG_IGN);
signal(SIGINT, siginthandler);
signal(SIGUSR1, sigusr1handler);
signal(SIGHUP, sighuphandler);
Expand Down
2 changes: 1 addition & 1 deletion glines/glines.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void _init() {
/* If we're connected to IRC, force a disconnect. */
if (connected) {
irc_send("%s SQ %s 0 :Resync [adding gline support]", mynumeric->content, myserver->content);
irc_disconnected();
irc_disconnected(0);
}

registerserverhandler("GL", handleglinemsg, 6);
Expand Down
64 changes: 56 additions & 8 deletions irc/irc.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <unistd.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <errno.h>

MODULE_VERSION("");

Expand Down Expand Up @@ -88,7 +89,7 @@ void _init() {
void _fini() {
if (connected) {
irc_send("%s SQ %s 0 :Shutting down",mynumeric->content,myserver->content);
irc_disconnected();
irc_disconnected(0);
}

deregisterserverhandler("G",&handleping);
Expand Down Expand Up @@ -319,7 +320,22 @@ int irc_handleserver(void *source, int cargc, char **cargv) {
return CMD_OK;
}

void irc_disconnected() {
static void *disconnect_schedule;
static void async_disconnect_handler(void *arg) {
disconnect_schedule = NULL;
irc_disconnected(0);
}

void irc_disconnected(int async) {
if (async) {
/* keep the fd "connected" until the next execution of the event loop */

if(disconnect_schedule == NULL)
disconnect_schedule = scheduleoneshot(time(NULL), &async_disconnect_handler, NULL);

return;
}

if (serverfd>=0) {
deregisterhandler(serverfd,1);
}
Expand All @@ -331,15 +347,40 @@ void irc_disconnected() {
} else {
nexthub();
}
if (disconnect_schedule) {
deleteschedule(disconnect_schedule, &async_disconnect_handler, NULL);
disconnect_schedule = NULL;
}
deleteschedule(NULL,&irc_connect,NULL);
deleteschedule(NULL,&sendping,NULL);
scheduleoneshot(time(NULL)+2,&irc_connect,NULL);
}

void irc_send(char *format, ... ) {
/*
static int _write(int fd, char *buf, size_t len) {
if(rand() % 10 == 0) {
errno = EPIPE;
return -1;
}
return write(fd, buf, len);
}
*/

int irc_send(char *format, ... ) {
char buf[512];
va_list val;
int len;
int ret;

if(disconnect_schedule) {
Error("irc",ERR_WARNING,"Writing to disconnected socket!");
return -1;
}

if(serverfd < 0) {
Error("irc",ERR_WARNING,"Writing to closed socket!");
return -1;
}

va_start(val,format);
len=vsnprintf(buf,509,format,val);
Expand All @@ -352,7 +393,14 @@ void irc_send(char *format, ... ) {
buf[len++]='\r';
buf[len++]='\n';

write(serverfd,buf,len);
ret = write(serverfd,buf,len);
if(ret < 0) {
Error("irc",ERR_ERROR,"Got socket error %d, dropping connection.", errno);
irc_disconnected(1);
return -1;
}

return 0;
}

void handledata(int fd, short events) {
Expand All @@ -362,15 +410,15 @@ void handledata(int fd, short events) {
if (events & (POLLPRI | POLLERR | POLLHUP | POLLNVAL)) {
/* Oh shit, we got dropped */
Error("irc",ERR_ERROR,"Got socket error, dropping connection.");
irc_disconnected();
irc_disconnected(0);
return;
}

while(again) {
res=read(serverfd, inbuf+bytesleft, READBUFSIZE-bytesleft);
if (res<=0) {
Error("irc",ERR_ERROR,"Disconnected by remote server.");
irc_disconnected();
irc_disconnected(0);
return;
}

Expand Down Expand Up @@ -571,7 +619,7 @@ void sendping(void *arg) {
Error("irc",ERR_INFO,"Connection closed due to ping timeout.");

irc_send("%s SQ %s 0 :Ping timeout",mynumeric->content,myserver->content);
irc_disconnected();
irc_disconnected(0);
} else {
awaitingping=1;
irc_send("%s G :%s",mynumeric->content,myserver->content);
Expand All @@ -584,7 +632,7 @@ void sendping(void *arg) {
nexthub();

connected=1; /* EVIL HACK */
irc_disconnected();
irc_disconnected(0);
}
}

Expand Down
4 changes: 2 additions & 2 deletions irc/irc.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ extern time_t starttime;

/* Functions from irc.c */
void irc_connect(void *arg);
void irc_disconnected();
void irc_send(char *format, ... ) __attribute__ ((format (printf, 1, 2)));
void irc_disconnected(int async);
int irc_send(char *format, ... ) __attribute__ ((format (printf, 1, 2)));
void handledata(int fd, short events);
int parseline();
int registerserverhandler(const char *command, CommandHandler handler, int maxparams);
Expand Down
2 changes: 1 addition & 1 deletion jupe/jupe.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void _init() {
/* If we're connected to IRC, force a disconnect. */
if (connected) {
irc_send("%s SQ %s 0 :Resync [adding jupe support]", mynumeric->content, myserver->content);
irc_disconnected();
irc_disconnected(0);
}

registerserverhandler("JU", &handlejupe, 5);
Expand Down
2 changes: 1 addition & 1 deletion nick/nick.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void _init() {
* before we register all our hooks which would otherwise get called
* during the disconnect. */
if (connected) {
irc_send("%s SQ %s 0 :Resync [adding nick support]",mynumeric->content,myserver->content); irc_disconnected();
irc_send("%s SQ %s 0 :Resync [adding nick support]",mynumeric->content,myserver->content); irc_disconnected(0);
}

/* Register our hooks */
Expand Down
2 changes: 1 addition & 1 deletion server/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ int handlesquitmsg(void *source, int cargc, char **cargv) {
}
if (servernum==myhub) {
Error("server",ERR_WARNING,"Rejected by our hub: %s",cargv[cargc-1]);
irc_disconnected();
irc_disconnected(0);
return CMD_OK;
}
deleteserver(servernum);
Expand Down

0 comments on commit 285076e

Please sign in to comment.