From 3dd05e6279a03b9321982e01237401745909670d Mon Sep 17 00:00:00 2001 From: epoch Date: Mon, 17 Mar 2014 07:23:40 -0500 Subject: updated the function that converts tail modes to strings for !tails other general cleaning --- .gitignore | 1 + TODO | 5 ++- segfault.c | 118 +++++++++++++++++++++++++++---------------------------------- 3 files changed, 58 insertions(+), 66 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..db7cf1b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +segfault diff --git a/TODO b/TODO index c941d9a..760b05f 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,10 @@ o convert aliases from a linked list to a hash-table with linked lists in each bucket. so O(whatever), much fast, many speed, wow. + o fix the ugly stuff that is casted to void in returns. + +--- ^^^ done ^^^ --- + o add stuff to libirc to buffer stuff being written to the socket so that it can put a speed limit on that kind of stuff. (but why would the bot get an fd from the runit function?) - o fix the ugly stuff that is casted to void in returns. o make the source code smaller or something. diff --git a/segfault.c b/segfault.c index 39968bb..0b38a20 100644 --- a/segfault.c +++ b/segfault.c @@ -23,16 +23,30 @@ #define TSIZE 65536 //size of hashtable. 65k isn't bad, right? // !c uses 56 for its tail. // 56 == 32 + 16 + 8 == 0x38 == 0x20+0x10+0x8 == SPAM | BEGIN | MSG -#define TAILO_RAW (0x1) //output gets sent directly to server -#define TAILO_EVAL (0x2) //interpret the lines read from the tail as if they were messages to segfault -#define TAILO_CLOSE (0x4) //close the file at EOF, default is to leave it open. -#define TAILO_MSG (0x8) //output gets sent as a PM to the place the tail was made. -#define TAILO_BEGIN (0x10) //start the tail at the beginning of the file instead of the end. -#define TAILO_SPAM (0x20) //Spam control is enabled for this stream. -#define TAILO_ENDMSG (0x40) //show a message when the tail reaches the end of a chunk +#define TAILO_RAW (0x1) // r output gets sent directly to server +#define TAILO_EVAL (0x2) // e interpret the lines read from the tail as if they were messages to segfault +#define TAILO_CLOSE (0x4) // c close the file at EOF, default is to leave it open. +#define TAILO_MSG (0x8) // m output gets sent as a PM to the place the tail was made. +#define TAILO_BEGIN (0x10) //b start the tail at the beginning of the file instead of the end. +#define TAILO_SPAM (0x20) //s Spam control is enabled for this stream. +#define TAILO_ENDMSG (0x40) //n show a message when the tail reaches the end of a chunk #define TAILO_Q_EVAL (TAILO_EVAL|TAILO_CLOSE|TAILO_BEGIN) //0x2+0x4+0x10 = 2+4+16 = 22 #define TAILO_Q_COUT (TAILO_SPAM|TAILO_BEGIN|TAILO_MSG) //0x20+0x10+0x8 = 32+16+8 = 56 +//this function isn't with the rest of them because... meh. +char *tailmode_to_txt(int mode) { + char *modes="recmbsn"; + int i,j=0; + char *m=malloc(strlen(modes)); + for(i=0;ill=0; //we now have a valid hashtable entry and a NULL ll in it. //don't bother with the new ll entry yet... @@ -418,31 +429,28 @@ void setkey_h(char *key,char *value) { if((tmp=leetgetalias(hashtable[h]->ll,key)) != NULL) { //we found this alias in the ll. now to replace the value free(tmp->target); - tmp->target=strdup(value); - return; + if(!(tmp->target=strdup(value))) return 2; + return 0; } - //else { - if(hashtable[h]->ll == NULL) { - hashtable[h]->ll=malloc(sizeof(struct alias)); - hashtable[h]->ll->next=0; - hashtable[h]->ll->prev=0; - hashtable[h]->ll->original=strdup(key); - hashtable[h]->ll->target=strdup(value); - } else { - //go to the end and add another entry to the ll. - for(tmp=hashtable[h]->ll;tmp->next;tmp=tmp->next); - tmp->next=malloc(sizeof(struct alias)); - tmp->next->prev=tmp; - tmp=tmp->next; - tmp->original=strdup(key); - tmp->target=strdup(value); - tmp->next=0; - } - //} + if(hashtable[h]->ll == NULL) { + if(!(hashtable[h]->ll=malloc(sizeof(struct alias)))) return 3; + hashtable[h]->ll->next=0; + hashtable[h]->ll->prev=0; + if(!(hashtable[h]->ll->original=strdup(key))) return 4; + if(!(hashtable[h]->ll->target=strdup(value))) return 5; + } else { + //go to the end and add another entry to the ll. + for(tmp=hashtable[h]->ll;tmp->next;tmp=tmp->next); + if(!(tmp->next=malloc(sizeof(struct alias)))) return 6; + tmp->next->prev=tmp; + tmp=tmp->next; + if(!(tmp->original=strdup(key))) return 7; + if(!(tmp->target=strdup(value))) return 8; + tmp->next=0; + } + return 0; } -//#endif ///////////////////////// HASH TABLE SHIT ///////////////////////////////// - void c_aliases_h(int fd,char *from,char *line) { char tmp[512]; struct alias *m; @@ -677,17 +685,10 @@ void c_leetappend(int fd,char *from,char *msg) { append_file(fd,from,file,line,nl); } -char *tailmode_to_txt(int mode) {//this needs to be updated. - if(mode & TAILO_RAW) return "raw"; - if(mode & TAILO_MSG) return "msg"; - if(mode & TAILO_EVAL) return "eval"; - return "undef"; -} - void c_tails(int fd,char *from) { int i; int l; - char *tmp; + char *tmp,*x; //privmsg(fd,from,"filename@filepos --msg|raw-> IRCdestination"); for(i=0;i %s",tailf[i].file,tailf[i].inode,ftell(tailf[i].fp),tailf[i].lines,tailmode_to_txt(tailf[i].opt),tailf[i].opt,tailf[i].to); + x=tailmode_to_txt(tailf[i].opt); + snprintf(tmp,l,"%s [i:%d] @ %ld (%d) --[%s(%02x)]--> %s",tailf[i].file,tailf[i].inode,ftell(tailf[i].fp),tailf[i].lines,x,tailf[i].opt,tailf[i].to); + free(x); privmsg(fd,from,tmp); free(tmp); } @@ -748,11 +751,6 @@ void c_leetsetout(int fd,char *from,char *msg) { void c_linelimit(int fd,char *from,char *msg) { char tmp[256]; - //struct itimerspec settime; - //settime.it_interval.tv_sec=0; - //settime.it_interval.tv_nsec=10; - //settime.it_value.tv_nsec=0; - //settime.it_value.tv_nsec=10; if(!msg) { snprintf(tmp,255,"current spam line limit: %d (debug: %d)",line_limit,debug); privmsg(fd,from,tmp); @@ -765,17 +763,6 @@ void c_linelimit(int fd,char *from,char *msg) { } else { privmsg(fd,from,"please set the limit to > 1... oi. (btw, debug has been flipped)"); debug^=1; -// if(debug) { -// if(timer_create(CLOCK_REALTIME,SIGEV_NONE,&timer) == -1) { -// privmsg(fd,from,(debug=0,"error making debug timer. shit.")); -// } -// if(timer_settime(timer,0,&settime,&settime) == -1) { -// privmsg(fd,from,(debug=0,"error setting debug timer. shit.")); -// } -// } -// else if(timer_delete(timer) == -1) { -// privmsg(fd,from,"error deleting timer. shit."); -// } } } } @@ -882,6 +869,7 @@ void message_handler(int fd,char *from,char *nick,char *msg,int redones) { else if(!strncmp(msg,"!aliases",8) && (!msg[8] || msg[8] == ' ')) { c_aliases_h(fd,from,*(msg+8)?msg+9:0); } + else if(redones < 5) { debug_time(fd,from,"checking aliases..."); //CONVERT -- cgit v1.2.3