From ecb12efc5ce737532402167679c0f7ffb22c495b Mon Sep 17 00:00:00 2001 From: epochqwert Date: Sun, 8 Mar 2015 07:18:38 -0500 Subject: fixed support of optional : before channel name when parsing JOIN messages from server. --- libirc/examples/link.c | 4 +- libirc/libirc.c | 107 +++++-------------------------------------------- segfault.c | 2 +- 3 files changed, 12 insertions(+), 101 deletions(-) diff --git a/libirc/examples/link.c b/libirc/examples/link.c index 5c13e94..0c9e7dd 100644 --- a/libirc/examples/link.c +++ b/libirc/examples/link.c @@ -91,7 +91,7 @@ void line_handler(int fd,char *line) {//this should be built into the libary? } if(s && user->nick && t) { if(!strcmp(s,"JOIN")) { - snprintf(tmp,sizeof(tmp)-1,"%cACTION %s has joined %s%c",1,user->nick,t+1,1); + snprintf(tmp,sizeof(tmp)-1,"%cACTION %s has joined %s%c",1,user->nick,t+(*t==':'),1); privmsg_others(fd,tmp); //send a join message to the other end. } @@ -116,7 +116,7 @@ int main(int argc,char *argv[]) { printf("%d server: %s port: %s channel: %s\n",i,argv[(i*3)+1],argv[(i*3)+2],argv[(i*3)+3]); fds[i]=serverConnect(argv[(i*3)+1],argv[(i*3)+2]); chans[i]=strdup(argv[(i*3)+3]); - mywrite(fds[i],"NICK link\r\nUSER a b c :d\r\n"); + mywrite(fds[i],"NICK link8239\r\nUSER a b c :d\r\n"); } fds[i]=-1; //heh. you can write your own code for picking a different nick per server. fuck you. diff --git a/libirc/libirc.c b/libirc/libirc.c index 7968f76..fad958d 100644 --- a/libirc/libirc.c +++ b/libirc/libirc.c @@ -37,101 +37,6 @@ int serverConnect(char *serv,char *port) { return p?fd:0; } -int runit(int fd,void (*line_handler)(),void (*extra_handler)()) { - fd_set master; - fd_set readfs; - struct timeval timeout; - int fdmax,n,s,i; - char *backlog=malloc(CHUNK+1); - char *t,*line=0; - int blsize=CHUNK; - int bllen=0; - char buffer[CHUNK];//THIS IS *NOT* NULL TERMINATED. - if(!backlog) return 252; - FD_ZERO(&master); - FD_ZERO(&readfs); - FD_SET(fd,&master); - fdmax=fd; - memset(backlog,0,CHUNK); - memset(buffer,0,CHUNK); - if(fd) { - int done=0; - while(!done) { - extra_handler(fd); - readfs=master; - timeout.tv_sec=0; - timeout.tv_usec=1000; - if( select(fdmax+1,&readfs,0,0,&timeout) == -1 ) { - printf("\n!!!It is crashing here!!!\n\n"); - perror("select"); - return 1; - } - if(FD_ISSET(fd,&readfs)) { - if((n=recv(fd,buffer,CHUNK,0)) <= 0) {//read CHUNK bytes - fprintf(stderr,"recv: %d\n",n); - perror("recv"); - return 2; - } else { - buffer[n]=0;//deff right. - if(bllen+n >= blsize) {//this is probably off... - blsize+=n; - t=malloc(blsize); - if(!t) { - printf("OH FUCK! MALLOC FAILED!\n"); - exit(253); - } - memset(t,0,blsize);//optional? - memcpy(t,backlog,blsize-n+1);//??? - free(backlog); - backlog=t; - } - memcpy(backlog+bllen,buffer,n); - bllen+=n; - for(i=0,s=0;i bllen) { //if the ending position is after the size of the backlog... - bllen=0;//fuck shifting. :P - } else { - for(i=s;i<=bllen;i++) {//should work. - backlog[i-s]=backlog[i]; - } - bllen-=s; - } - } - } - } - } - return 0; -} - //yeah. this is a copy of the previous function. //with a bit of different stuff. didn't want to break anything yet. int runem(int *fds,void (*line_handler)(),void (*extra_handler)()) { @@ -165,7 +70,7 @@ int runem(int *fds,void (*line_handler)(),void (*extra_handler)()) { timeout.tv_sec=0; timeout.tv_usec=1000; if( select(fdmax+1,&readfs,0,0,&timeout) == -1 ) { - printf("\n!!!It is rashing here!!!\n\n"); + printf("\n!!!It is crashing here!!!\n\n"); perror("select"); return 1; } @@ -206,8 +111,6 @@ int runem(int *fds,void (*line_handler)(),void (*extra_handler)()) { strcpy(t,"PONG "); strcat(t,line+6); write(fd,t,strlen(t)); - //fprintf(fp,"PONG %s",line+6);//a whole FILE * and fdopen JUST for this??? oy... - //fflush(fp); #ifdef DEBUG printf("%s\nPONG %s\n",line,line+6); write(fd,"PRIVMSG %s :PONG! w00t!\r\n",DEBUG,28); @@ -239,6 +142,14 @@ int runem(int *fds,void (*line_handler)(),void (*extra_handler)()) { return 0; } +//wrap runem to keep runit around :P +int runit(int fd,void (*line_handler)(),void (*extra_handler)()) { + int fds[2]; + fds[0]=fd; + fds[1]=-1; + runem(fds,line_handler,extra_handler); +} + //not needed? int ircConnect(char *serv,char *port,char *nick,char *user) { char sendstr[1024]; diff --git a/segfault.c b/segfault.c index 2706543..8013e0b 100644 --- a/segfault.c +++ b/segfault.c @@ -1129,7 +1129,7 @@ void line_handler(int fd,char *line) {//this should be built into the libary? } if(s && user->nick && t) { if(!strcmp(s,"JOIN")) { - irc_mode(fd,t+1,"+o",user->nick);//why t+1? it starts with :? + irc_mode(fd,t+(*t==':'),"+o",user->nick);//sometimes t will start with a : This check should go into the parser up there. } if(!strcmp(s,"MODE") && mode_magic) { if(u) { -- cgit v1.2.3