aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorepochqwert <epoch@hacking.allowed.org>2015-03-31 13:38:31 -0500
committerepochqwert <epoch@hacking.allowed.org>2015-03-31 13:38:31 -0500
commit3b1466afd58e7cfbf5be09df8cfc52409171f5d3 (patch)
tree83ff40686c230866ac8c245366cacf4c9ed019cf
parent7f43ddc3b96848b1a788a86ae663279dead86f27 (diff)
downloadsegfault-3b1466afd58e7cfbf5be09df8cfc52409171f5d3.tar.gz
segfault-3b1466afd58e7cfbf5be09df8cfc52409171f5d3.zip
moved libhashtable and libirc into their own repos.
-rw-r--r--Makefile8
-rw-r--r--libhashtable/Makefile15
-rw-r--r--libhashtable/example.c25
-rwxr-xr-xlibhashtable/genheader.sh3
-rw-r--r--libhashtable/hashtable.h27
-rw-r--r--libhashtable/libhashtable.c165
-rw-r--r--libirc/Makefile15
-rw-r--r--libirc/examples/link.c134
-rw-r--r--libirc/irc.h4
-rw-r--r--libirc/libirc.c256
-rw-r--r--segfault.c109
11 files changed, 31 insertions, 730 deletions
diff --git a/Makefile b/Makefile
index 2871beb..5111042 100644
--- a/Makefile
+++ b/Makefile
@@ -2,18 +2,10 @@ LDFLAGS=-lirc -Llibirc -lhashtable -Llibhashtable
CFLAGS=-std=c99 -pedantic -Wall
all:
- cd libirc && $(MAKE)
- cd libhashtable && $(MAKE)
$(MAKE) segfault
clean:
- cd libirc && $(MAKE) clean
- cd libhashtable && $(MAKE) clean
rm -f segfault
install:
- cp -f libirc/libirc.so /usr/local/lib
- cp -f libhashtable/libhashtable.so /usr/local/lib
-# cd libirc && $(MAKE) install
-# cd libhashtable && $(MAKE) install
cp -f segfault /usr/local/bin/segfault
diff --git a/libhashtable/Makefile b/libhashtable/Makefile
deleted file mode 100644
index 6649739..0000000
--- a/libhashtable/Makefile
+++ /dev/null
@@ -1,15 +0,0 @@
-LDFLAGS=-lhashtable -Llibhashtable
-CFLAGS=-fpic -shared -pedantic -Wall
-TARGET=libhashtable.so
-
-all: $(TARGET)
-
-$(TARGET):
- $(CC) $(CFLAGS) -o $(TARGET) libhashtable.c
-
-clean:
- rm -f libhashtable.so
-
-install:
- cp $(TARGET) /usr/local/lib/$(TARGET)
- cp hashtable.h /usr/local/include/hashtable.h
diff --git a/libhashtable/example.c b/libhashtable/example.c
deleted file mode 100644
index 919d75c..0000000
--- a/libhashtable/example.c
+++ /dev/null
@@ -1,25 +0,0 @@
-#include <stdio.h>
-#include "hashtable.h"
-
-extern char **environ;
-
-int main(int argc,char *argv[]) {
- struct hashtable ht;
- int i;
- char *name;
- char *value;
- inittable(&ht,65535);
- for(i=0;environ[i];i++) {
- name=strdup(environ[i]);
- if((value=strchr(name,'=') )){
- *value=0;
- value++;
- }
- ht_setkey(&ht,name,value);
- free(name);
- }
- printf("PATH='%s'\n",ht_getvalue(&ht,"PATH"));
- //if you want to get a whole entry struct use ht_getnode();
- //getentry() just returns the first struct in the linked list in that bucket.
- return 0;
-}
diff --git a/libhashtable/genheader.sh b/libhashtable/genheader.sh
deleted file mode 100755
index 3995579..0000000
--- a/libhashtable/genheader.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/sh
-cat libhashtable.c | head -n 22 | tail -n 16 > hashtable.h
-cat libhashtable.c | grep '(.*) *{' | egrep -v 'if|for|while' | sed 's/ {/;/' >> hashtable.h
diff --git a/libhashtable/hashtable.h b/libhashtable/hashtable.h
deleted file mode 100644
index a58a392..0000000
--- a/libhashtable/hashtable.h
+++ /dev/null
@@ -1,27 +0,0 @@
-struct entry {//linked list node.
- char *original;
- void *target;
- struct entry *prev;// doubly linked list. why?
- struct entry *next;
-};
-
-struct hitem {
- struct entry *ll;
-};
-
-struct hashtable {
- int kl;//number of keys in the table
- struct hitem **bucket;
- int *keys;
-};
-unsigned short hash(char *key);//maybe use a seeded rand()? :) Thanks FreeArtMan
-void inittable(struct hashtable *ht,int tsize);
-void ll_delete(struct entry *ll);
-void ll_destroy(struct entry *ll);
-void ht_destroy(struct hashtable *ht);
-void ht_freevalues(struct hashtable *ht);
-int ht_setkey(struct hashtable *ht,char *key,void *value);
-struct entry *ll_getentry(struct entry *start,char *msg);
-struct entry *ht_getentry(struct hashtable *ht,char *key);
-struct entry *ht_getnode(struct hashtable *ht,char *msg);
-void *ht_getvalue(struct hashtable *ht,char *msg);
diff --git a/libhashtable/libhashtable.c b/libhashtable/libhashtable.c
deleted file mode 100644
index 496a3ee..0000000
--- a/libhashtable/libhashtable.c
+++ /dev/null
@@ -1,165 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include "hashtable.h"
-
-/*
-struct entry {//linked list node.
- char *original;
- void *target;
- struct entry *prev;// doubly linked list. why?
- struct entry *next;
-};
-
-struct hitem {
- struct entry *ll;
-};
-
-struct hashtable {
- int kl;//number of keys in the table
- struct hitem **bucket;
- int *keys;
-};
-*/
-
-unsigned short hash(char *key) {//maybe use a seeded rand()? :) Thanks FreeArtMan
- return (strlen(key)<<8)+(key[0]<<4)+key[1];
-}
-
-void inittable(struct hashtable *ht,int tsize) {
- int i;
- ht->bucket=malloc(sizeof(char *)*tsize);
- ht->kl=0;
- ht->keys=malloc(sizeof(int *)*tsize);
- if(!ht) {
- fprintf(stderr,"malloc error 6 in hash table.\n");
- return;
- }
- for(i=0;i<tsize;i++) {
- ht->bucket[i]=0;
- }
-}
-
-void ll_delete(struct entry *ll) {
- //do I have to free() any of this shit?
- //keys are always allocated. strdup().
- //gotta free that. anything else isn't my fault.
- if(ll->prev) {
- ll->prev->next=ll->next;
- } else {
- //I am the first node.
- }
- if(ll->next) {
- ll->next->prev=ll->prev;
- } else {
- //I am the last node.
- }
- free(ll);//all these nodes are malloc()d.
-}
-
-void ll_destroy(struct entry *ll) {
- if(ll->next) ll_destroy(ll->next);
- free(ll->original);
- free(ll);
- //destroy_this_node.
- //ll->original //malloc()d
- //ll->target //I dunno where this comes from.
-}
-
-void ht_destroy(struct hashtable *ht) {
- int i=0;
- for(i=0;i<ht->kl;i++) {
- ll_destroy(ht->bucket[ht->keys[i]]->ll);
- }
- free(ht->bucket);
-}
-
-void ll_freevalues(struct entry *ll) {//only use if you malloc your table.
- if(ll->next) ll_destroy(ll->next);
- free(ll->target);
-}
-
-void ht_freevalues(struct hashtable *ht) {
- int i;
- for(i=0;i<ht->kl;i++) {
- ll_freevalues(ht->bucket[ht->keys[i]]->ll);
- }
-}
-
-//this seems too complicated.
-int ht_setkey(struct hashtable *ht,char *key,void *value) {
- unsigned short h;
- struct entry *tmp;
- int i;
- if(!key) key="(null)";
- h=hash(key);
- for(i=0;i<ht->kl;i++) {
- if(ht->keys[i]==h) break;
- }
- ht->keys[i]=h;
- ht->kl=(ht->kl)>i+1?ht->kl:i+1;
- if(!ht->bucket[h]) { //empty bucket!
- //add this to the list of used buckets so we can easily
- //use that list later for stuff.
- if(!(ht->bucket[h]=malloc(sizeof(struct hitem)))) return 1;
- ht->bucket[h]->ll=0;
- //we now have a valid hashtable entry and a NULL ll in it.
- //don't bother with the new ll entry yet...
- }
- if((tmp=ll_getentry(ht->bucket[h]->ll,key)) != NULL) {
- tmp->target=value;
- return 0;
- }
- if(ht->bucket[h]->ll == NULL) {
- if(!(ht->bucket[h]->ll=malloc(sizeof(struct entry)))) return 3;
- ht->bucket[h]->ll->next=0;
- ht->bucket[h]->ll->prev=0;
- if(!(ht->bucket[h]->ll->original=strdup(key))) return 4;
- ht->bucket[h]->ll->target=value;
- } else {
- //go to the end and add another entry to the ll.
- for(tmp=ht->bucket[h]->ll;tmp->next;tmp=tmp->next);
- if(!(tmp->next=malloc(sizeof(struct entry)))) return 6;
- tmp->next->prev=tmp;
- tmp=tmp->next;
- if(!(tmp->original=strdup(key))) return 7;
- tmp->target=value;
- tmp->next=0;
- }
- return 0;
-}
-
-struct entry *ll_getentry(struct entry *start,char *key) {
- struct entry *m;
- if(!key) return NULL;
- if(!start) return NULL;
- for(m=start;m;m=m->next) {
- if(!strncmp(key,m->original,strlen(m->original)) && (key[strlen(m->original)]==' ' || key[strlen(m->original)] == 0)) {//this allows !c to get called when using !c2 if !c2 is defined after !c. >_>
- return m;
- }
- }
- return NULL;
-}
-
-//returns the table entry (a linked list) at the key.
-struct entry *ht_getentry(struct hashtable *ht,char *key) {
- unsigned short h=hash(key);
- if(!ht->bucket[h]) return NULL;
- return ht->bucket[h]->ll;
-}
-
-//returns the node in the linked list in the table entry that matches the key.
-struct entry *ht_getnode(struct hashtable *ht,char *key) {
- return ll_getentry(ht_getentry(ht,key),key);
-}
-
-//you'll probably want to use me.
-void *ht_getvalue(struct hashtable *ht,char *key) {
- struct entry *tmp=ll_getentry(ht_getentry(ht,key),key);
- return tmp?tmp->target:0;
-}
-
-//delete the node in the linked list in the table entry that matches the key.
-void *ht_delete(struct hashtable *ht,char *key) {
- ll_delete(ht_getentry(ht,key));
-}
diff --git a/libirc/Makefile b/libirc/Makefile
deleted file mode 100644
index e6c38fb..0000000
--- a/libirc/Makefile
+++ /dev/null
@@ -1,15 +0,0 @@
-LDFLAGS=-lirc -Llibirc
-CFLAGS=-fpic -shared -pedantic -Wall
-TARGET=libirc.so
-
-all: $(TARGET)
-
-$(TARGET):
- $(CC) $(CFLAGS) -o $(TARGET) libirc.c
-
-clean:
- rm -f libirc.so
-
-install:
- cp $(TARGET) /usr/local/lib/$(TARGET)
- cp irc.h /usr/local/include/irc.h
diff --git a/libirc/examples/link.c b/libirc/examples/link.c
deleted file mode 100644
index c175595..0000000
--- a/libirc/examples/link.c
+++ /dev/null
@@ -1,134 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <irc.h>
-
-#define mywrite(a,b) write(a,b,strlen(b))
-
-int *fds;
-char **chans;
-
-void extra_handler(int fd) {
- return;
-}
-
-struct user {
- char *nick;
- char *user;
- char *host;
-};
-
-void privmsg_others(int fd,char *msg) {
- int i;
- char tmp[512];
- for(i=0;fds[i] != -1;i++) {
- if(fds[i] != fd) {
- snprintf(tmp,sizeof(tmp)-1,"PRIVMSG %s :%s\r\n",chans[fdtoi(fds[i])],msg);
- write(fds[i],tmp,strlen(tmp));
- }
- }
-}
-
-void message_handler(int fd,char *from,struct user *user,char *line) {
- int i;
- char tmp[512];
- if(!strcmp(from,chans[fdtoi(fd)])) {//don't want to be forwarding PMs. :P
- snprintf(tmp,sizeof(tmp)-1,"<%s> %s",user->nick,line);
- privmsg_others(fd,tmp);
- }
-}
-
-void line_handler(int fd,char *line) {//this should be built into the libary?
- char *s=line,*t=0,*u=0;
- char *temp;
- char tmp[512];
- struct user *user=malloc(sizeof(struct user));
- user->nick=0;
- user->user=0;
- user->host=0;
- if(strchr(line,'\r')) *strchr(line,'\r')=0;
- if(strchr(line,'\n')) *strchr(line,'\n')=0;
- printf("line: '%s'\n",line);
- if(line[0]==':') {
- if((user->nick=strchr(line,':'))) {
- *(user->nick)=0;
- (user->nick)++;
- }
- }
- if(user->nick) {
- if((s=strchr((user->nick),' '))) {
- *s=0;
- s++;
- if((t=strchr(s,' '))) {
- *t=0;
- t++;
- if((u=strchr(t,' '))) {//:
- *u=0;
- u++;
- }
- }
- }
- if(((user->user)=strchr((user->nick),'!'))) {
- *(user->user)=0;
- (user->user)++;
- if(((user->host)=strchr((user->user),'@'))) {
- *(user->host)=0;
- (user->host)++;
- }
- } else {
- user->host=user->nick;
- }
- }
- if(!user->user && s) {
- if(!strcmp(s,"004")) {
- snprintf(tmp,sizeof(tmp)-1,"JOIN %s\r\n",chans[fdtoi(fd)]);
- temp=strchr(chans[fdtoi(fd)],' ');
- if(temp) *temp=0;
- mywrite(fd,tmp);
- }
- }
- if(s && t && u) {
- if(!strcmp(s,"PRIVMSG")) {
- message_handler(fd,*t=='#'?t:user->nick,user,++u);
- }
- }
- if(s && user->nick && t) {
- if(!strcmp(s,"JOIN")) {
- snprintf(tmp,sizeof(tmp)-1,"%cACTION %s has joined %s%c",1,user->nick,t+(*t==':'),1);
- privmsg_others(fd,tmp);
- }
- if(!strcmp(s,"PART")) {
- snprintf(tmp,sizeof(tmp)-1,"%cACTION %s has parted %s%c",1,user->nick,t+(*t==':'),1);
- privmsg_others(fd,tmp);
- }
- if(!strcmp(s,"QUIT")) {
- snprintf(tmp,sizeof(tmp)-1,"%cACTION %s has quited %s%c",1,user->nick,t+(*t==':'),1);
- privmsg_others(fd,tmp);
- }
- }
- free(user);
-}
-
-int fdtoi(int fd) {
- int i;
- for(i=0;fds[i] != -1;i++) {
- if(fds[i] == fd) return i;
- }
- return -1;
-}
-
-int main(int argc,char *argv[]) {
- fds=malloc(sizeof(int) * (argc+3) / 3);
- chans=malloc(sizeof(char *) * (argc+3) / 3);
- int i=0;
- printf("%d\n",argc);
- for(i=0;((i*3)+3)<argc;i++) {
- 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 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.
- runem(fds,line_handler,extra_handler);
-}
diff --git a/libirc/irc.h b/libirc/irc.h
deleted file mode 100644
index 231cd84..0000000
--- a/libirc/irc.h
+++ /dev/null
@@ -1,4 +0,0 @@
-int runit(int fd,void (*line_handler)(),void (*extra_handler)()) ;
-int ircConnect(char *serv,char *port,char *nick,char *user) ;
-int serverConnect(char *serv,char *port) ;
-char **line_cutter(int fd,char *line,struct user *user) ;
diff --git a/libirc/libirc.c b/libirc/libirc.c
deleted file mode 100644
index dd1c0d0..0000000
--- a/libirc/libirc.c
+++ /dev/null
@@ -1,256 +0,0 @@
-#include <sys/time.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#include <sys/socket.h>
-#include <arpa/inet.h>
-#include <unistd.h>
-#include <sys/select.h>
-
-//#define DEBUG "epoch" //nick or channel to send debug info to.
-#define CHUNK 4096
-
-int main(int argc,char *argv[]) {
- return 0;
-}
-
-#define SILLYLIMIT 256
-
-int serverConnect(char *serv,char *port) {
- int rv;
- int fd=0;
- int n=1;
- int try_ipv4=0;
- char buf[SILLYLIMIT];
- struct addrinfo hints, *servinfo, *p=0;
- struct in_addr saddr;
- struct in6_addr saddr6;
- struct hostent *he;
- memset(&hints,0,sizeof hints);
- hints.ai_family=AF_INET;
- hints.ai_socktype=SOCK_STREAM;
- if((fd=socket(PF_INET,SOCK_STREAM,IPPROTO_TCP)) < 0) {
- perror("socket");
- return -1;
- }
-/*
- for(try_ipv4=0;try_ipv4 < 2;try_ipv4++) {
- if(!(he=gethostbyname2(
- try_ipv4
- ?inet_aton(serv,&saddr)
- ?inet_ntoa(saddr)
- :serv
- :inet_pton(AF_INET6,serv,&saddr6)
- ?inet_ntop(AF_INET6,&saddr6,buf,SILLYLIMIT)
- :serv
- ,try_ipv4?AF_INET:AF_INET6))) return -1;
-
- for(;*(he->h_addr_list);he->h_addr_list++) {
- printf("trying to connect to %s:%s attempt #%d\n",serv,port,n);
- n++;
-*/
-// if((rv=getaddrinfo(he->h_addr_list,port,&hints,&servinfo)) != 0) {
- if((rv=getaddrinfo(serv,port,&hints,&servinfo)) != 0) {
- fprintf(stderr,"error resolving '%s'.\n",serv);
- return -1;
- }
- for(p=servinfo;p;p=p->ai_next) {
- if(connect(fd,p->ai_addr, p->ai_addrlen) < 0) {
- perror("connect");
- continue;
- } else {
- return fd;
- }
- }
- //printf("trying a differnt address...\n");
- //}
- //printf("trying a different AF...\n");
- //}
- //printf("well, shit. how'd I get here?\n");
- return -1;
-}
-
-int fdlen(int *fds) {
- int i;
- for(i=0;fds[i] != -1;i++);
- return i+1;
-}
-
-int runem(int *fds,void (*line_handler)(),void (*extra_handler)()) {
- int j;
- int fdl=fdlen(fds);
- fd_set master;
- fd_set readfs;
- struct timeval timeout;
- int fdmax=0,n,s,i;
- int fd;
- char *backlogs[fdl];
- char *t,*line=0;
- int blsize=CHUNK;
- int bllen=0;
- char buffers[fdl][CHUNK];//THIS IS *NOT* NULL TERMINATED.
- FD_ZERO(&master);
- FD_ZERO(&readfs);
- for(i=0;fds[i] != -1;i++) {
- //if(!backlogs[i]) return 252;//wtf is this here for? ofc they're not set!
- FD_SET(fds[i],&master);
- backlogs[i]=malloc(CHUNK+1);
- memset(backlogs[i],0,CHUNK);
- memset(buffers[i],0,CHUNK);
- fdmax=fds[i]>fdmax?fds[i]:fdmax;
- }
- int done=0;
- while(!done) {
- for(fd=0;fd<=fdmax;fd++) {
- if(FD_ISSET(fd,&master)) {
- if(extra_handler) 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;
- }
- for(i=0;fds[i] != -1;i++) {
- if(FD_ISSET(fds[i],&readfs)) {
- if((n=recv(fds[i],buffers[i],CHUNK,0)) <= 0) {//read CHUNK bytes
- fprintf(stderr,"recv: %d\n",n);
- perror("recv");
- return 2;
- } else {
- buffers[i][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,backlogs[i],blsize-n+1);//???
- free(backlogs[i]);
- backlogs[i]=t;
- }
- memcpy(backlogs[i]+bllen,buffers[i],n);
- bllen+=n;
- for(j=0,s=0;j<bllen;j++) {
- if(backlogs[i][j]=='\n') {
- line=malloc(j-s+3);//on linux it crashes without the +1 +3? weird. when did I do that?
- if(!line) {
- printf("ANOTHER malloc error!\n");
- exit(254);
- }
- memcpy(line,backlogs[i]+s,j-s+2);
- line[j-s+1]=0;//gotta null terminate this. line_handler expects it .
- s=j+1;//the character after the newline.
- if(!strncmp(line,"PING",4)) {
- t=malloc(strlen(line));
- strcpy(t,"PONG ");
- strcat(t,line+6);
- write(fds[i],t,strlen(t));
- #ifdef DEBUG
- printf("%s\nPONG %s\n",line,line+6);
- write(fds[i],"PRIVMSG %s :PONG! w00t!\r\n",DEBUG,28);
- #endif
- } else if(!strncmp(line,"ERROR",5)) {
- #ifdef DEBUG
- printf("error: %s\n",line);
- #endif
- return 0;
- } else {
- line_handler(fds[i],line);
- }
- free(line);
- }
- }
- //left shift the backlog so the last thing we got to is at the start
- if(s > bllen) { //if the ending position is after the size of the backlog...
- bllen=0;//fuck shifting. :P
- } else {
- for(j=s;j<=bllen;j++) {//should work.
- backlogs[i][j-s]=backlogs[i][j];
- }
- bllen-=s;
- }
- }
- }
- }
- }
- 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;
- return runem(fds,line_handler,extra_handler);
-}
-
-//not needed?
-int ircConnect(char *serv,char *port,char *nick,char *user) {
- char sendstr[1024];
- int fd;
- fd=serverConnect(serv,port);
- if(!fd) {
- return 0;
- }
- snprintf(sendstr,sizeof(sendstr)-1,"NICK %s\r\nUSER %s\r\n",nick,user);
- write(fd,sendstr,strlen(sendstr));
- return fd;
-}
-
-struct user {
- char *nick;
- char *user;
- char *host;
-};
-
-//this function mangles the input.
-//gotta free the returned pointer but not each pointer in the array.
-char **line_cutter(int fd,char *line,struct user *user) {
- int i;
- char **a=malloc(16);//heh.
- memset(a,0,sizeof(char *)*16);
- if(!user) return 0;
- user->nick=0;
- user->user=0;
- user->host=0;
-
- if(strchr(line,'\r')) *strchr(line,'\r')=0;
- if(strchr(line,'\n')) *strchr(line,'\n')=0;
- if(line[0]==':') {
- if((user->nick=strchr(line,':'))) {
- *(user->nick)=0;
- (user->nick)++;
- }
- }
- if(user->nick) {
- if((a[0]=strchr((user->nick),' '))) {
- for(i=0;a[i+1]=strchr(a[i],' ') && i<15;i++) {
- *a[i]=0;
- a[i]++;
- if(a[i][0] == ':') {//we're done.
- a[i]++;
- break;
- }
- }
- }
- if(((user->user)=strchr((user->nick),'!'))) {
- *(user->user)=0;
- (user->user)++;
- if(((user->host)=strchr((user->user),'@'))) {
- *(user->host)=0;
- (user->host)++;
- }
- } else {
- user->host=user->nick;
- }
- }
- return a;
-}
diff --git a/segfault.c b/segfault.c
index 7df026f..bd2a427 100644
--- a/segfault.c
+++ b/segfault.c
@@ -12,8 +12,8 @@
#include <sys/stat.h>
#include <sys/resource.h>
-#include "libirc/irc.h" //epoch's libirc. should be included with segfault.
-#include "libhashtable/hashtable.h" //epoch's also.
+#include <irc.h>
+#include <hashtable.h>
/*// just in case your system doesn't have strndup
char *strndup(char *s,int l) {
@@ -76,12 +76,6 @@ union hack {
void (*func)(int fd,...);
-struct user {
- char *nick;
- char *user;
- char *host;
-};
-
struct tail {
FILE *fp;
char *file;
@@ -170,13 +164,12 @@ void privmsg(int fd,char *who,char *msg) {
//try to shorten this up sometime...
char *format_magic(int fd,char *from,struct user *user,char *orig_fmt,char *arg) {
int i=0,j=1,sz=0,c=1;
- char overflow_space[100];
char *output,*fmt,*argCopy;
char **args,**notargs;
char *argN[10],randC[10][2]={"0","1","2","3","4","5","6","7","8","9"};
if(!arg) arg="%s";
if(!(argCopy=strdup(arg))) return 0;
- for(argN[0]=argCopy;argCopy[i];i++) {
+ for(argN[0]=argCopy;argCopy[i] && i<10;i++) {
if(argCopy[i] == ' ') {
argN[j]=argCopy+i;
argN[j][0]=0;
@@ -187,14 +180,21 @@ char *format_magic(int fd,char *from,struct user *user,char *orig_fmt,char *arg)
for(;j<10;j++) {
argN[j]="(null)";//fill up the rest to prevent null deref.
}
- if(!orig_fmt) exit(70);
+ if(!orig_fmt) return 0;
if(!(fmt=strdup(orig_fmt))) return 0;
- for(i=0;fmt[i];i++)
- if(fmt[i] == '%')
- switch(fmt[++i])
+ for(i=0;fmt[i];i++) {
+ if(fmt[i] == '%') {
+ i++;
+ switch(fmt[i]) {
case '~':case 'p':case 'n':case 'h':case 'u':case 'f':case 's':
case 'm':case '%':case '0':case '1':case '2':case '3':case '4':
- case '5':case '6':case '7':case '8':case '9':case 'r': c++;
+ case '5':case '6':case '7':case '8':case '9':case 'r':
+ c++;
+ default:
+ break;
+ }
+ }
+ }
args=malloc((sizeof(char *)) * (c + 1));
notargs=malloc((sizeof(char *)) * (c + 2));
c=0;
@@ -205,14 +205,14 @@ char *format_magic(int fd,char *from,struct user *user,char *orig_fmt,char *arg)
case '~':case 'p':case 'n':case 'h':case 'u':case 'f':case 's':
case 'm':case '%':case '0':case '1':case '2':case '3':case '4':
case '5':case '6':case '7':case '8':case '9':case 'r':
- args[c]=((fmt[i]=='n')?user->nick:
- ((fmt[i]=='u')?user->user:
+ args[c]=((fmt[i]=='n')?(user->nick?user->nick:"user->nick"):
+ ((fmt[i]=='u')?(user->user?user->user:"user->user"):
((fmt[i]=='~')?seghome:
- ((fmt[i]=='h')?user->host:
- ((fmt[i]=='f')?from:
+ ((fmt[i]=='h')?(user->host?user->host:"user->host"):
+ ((fmt[i]=='f')?(from?from:"from"):
((fmt[i]=='p')?pid:
- ((fmt[i]=='m')?myuser->nick://and here.
- ((fmt[i]=='s')?arg:
+ ((fmt[i]=='m')?(myuser->nick?myuser->nick:"myuser->nick")://and here.
+ ((fmt[i]=='s')?(arg?arg:"arg"):
((fmt[i]=='0')?argN[0]:
((fmt[i]=='1')?argN[1]:
((fmt[i]=='2')?argN[2]:
@@ -228,6 +228,7 @@ char *format_magic(int fd,char *from,struct user *user,char *orig_fmt,char *arg)
fmt[i-1]=0;
if(!(fmt+j)) exit(68);
if(!(notargs[c]=strdup(fmt+j))) exit(66);
+ if(!args[c]) exit(200+c);
sz+=strlen(args[c]);
sz+=strlen(notargs[c]);
c++;
@@ -272,12 +273,12 @@ void extra_handler(int fd) {
int tmpo,i;
char tmp[BS+1];
char *tmp2;
- if(oldtime == time(0) && lines_sent > LINES_SENT_LIMIT) {//if it is still the same second, skip this function.
- return;
- } else {
- lines_sent=0;
- }
- oldtime=time(0);//this might fix it?
+ //if(oldtime == time(0) && lines_sent > LINES_SENT_LIMIT) {//if it is still the same second, skip this function.
+ // return;
+ //} else {
+ // lines_sent=0;
+ //}
+ //oldtime=time(0);//this might fix it?
if(redirect_to_fd != -1) {
fd=redirect_to_fd;
}
@@ -1016,13 +1017,13 @@ void message_handler(int fd,char *from,struct user *user,char *msg,int redones)
*args=0;
args++;
}
- if(!strncmp(command,"lambda",6)) {
+ while(!strncmp(command,"lambda",6)) {
command+=8;
if((args=strchr(command,' '))) {
*args=0;
args++;
}
- args=format_magic(fd,from,user,args,":/");
+ args=format_magic(fd,from,user,args,args);
lambdad=1;
}
if((lol.data=ht_getvalue(&builtin,command))) {
@@ -1063,54 +1064,6 @@ void line_handler(int fd,char *line) {//this should be built into the libary?
}
//line will be mangled by the cutter.
char **a=line_cutter(fd,line,user);
-
-//stuff covered by line_cutter below here.
-/*
- user->nick=0;
- user->user=0;
- user->host=0;
- if(strchr(line,'\r')) *strchr(line,'\r')=0;
- if(strchr(line,'\n')) *strchr(line,'\n')=0;
- printf("line: '%s'\n",line);
- //:nick!user@host MERP DERP :message
- //:nick!user@host s t :u
- //:armitage.hacking.allowed.org MERP DERP :message
- //:nickhost s t :u
- //only sub-parse nickuserhost stuff if starts with :
- //strchr doesn't like null pointers. :/ why not just take them and return null?
- //check that I haven't gone past the end of the string? nah. it should take care of itself.
- if(line[0]==':') {
- if((user->nick=strchr(line,':'))) {
- *(user->nick)=0;
- (user->nick)++;
- }
- }
- if(user->nick) {
- if((s=strchr((user->nick),' '))) {
- *s=0;
- s++;
- if((t=strchr(s,' '))) {
- *t=0;
- t++;
- if((u=strchr(t,' '))) {//:
- *u=0;
- u++;
- }
- }
- }
- if(((user->user)=strchr((user->nick),'!'))) {
- *(user->user)=0;
- (user->user)++;
- if(((user->host)=strchr((user->user),'@'))) {
- *(user->host)=0;
- (user->host)++;
- }
- } else {
- user->host=user->nick;
- }
- }
-*/
-//end of stuff covered by line_cutter
if(!user->user && a[0]) { //server message
//:armitage.hacking.allowed.org 353 asdf = #default :@SegFault @FreeArtMan @foobaz @wall @Lamb3_13 @gizmore @blackh0le
strcpy(tmp,"!");
@@ -1134,7 +1087,7 @@ void line_handler(int fd,char *line) {//this should be built into the libary?
if(a[0] && a[1] && a[2]) {
if(!strcmp(a[0],"PRIVMSG") && strcmp(user->nick,myuser->nick)) {
if(strcmp(user->nick,myuser->nick)) {
- message_handler(fd,*a[1]=='#'?a[1]:user->nick,user,++a[2],0);
+ message_handler(fd,*a[1]=='#'?a[1]:user->nick,user,a[2],0);
}
else {
if(debug) privmsg(fd,*a[2]=='#'?a[2]:user->nick,"This server has an echo");