diff options
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | Makefile | 7 | ||||
-rw-r--r-- | bee.c | 5 | ||||
-rw-r--r-- | conf.h | 2 | ||||
-rw-r--r-- | irc.c | 14 | ||||
-rw-r--r-- | util.c | 2 |
6 files changed, 26 insertions, 7 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c484265 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.o +apiobot + @@ -1,9 +1,9 @@ .POSIX: .SUFFIXES: .c .o -CFLAGS=-Wall CC=cc debug=-g -DDEBUG -DLOCAL +CFLAGS=$(MORE_CFLAGS) -Wall OBJS=bee.o irc.o util.o @@ -12,10 +12,11 @@ apiobot: $(OBJS) $(CC) $(CFLAGS) -o apiobot $(OBJS) debug: - $(CC) $(CFLAGS) $(debug) -o apiobot $(OBJS) + make apiobot MORE_CFLAGS="-DDEBUG -DLOCAL -g" + .c.o: - $(CC) -c $< $(CFLAGS) -o $@ + $(CC) $(CFLAGS) -c $< -o $@ run: all ./apiobot @@ -3,11 +3,12 @@ #include <stdio.h> + int main() { - if (!irc_connect()) { fputs("irc_connect\n",stderr); return 1; } - if (!irc_handshake()) { fputs("irc_handshake\n",stderr); return 1; } + if (irc_connect()) { fputs("falure in irc_connect\n",stderr); return 1; } + if (irc_handshake()) { fputs("failure in irc_handshake\n",stderr); return 1; } int x; do { @@ -25,9 +25,11 @@ printf(name " [%s]\n",__xxx); \ free(__xxx); \ } while (0) + #define DPf(...) fprintf(stderr,__VA_ARGS__) #else #define DP(x) #define DPn(n,x,l) + #define DPf(...) #endif #define NICK "Bee" @@ -13,6 +13,8 @@ irc_connect() hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; + printf("connecting to %s:%s....\n",HOST,PORT); + int status; struct addrinfo *res; if ((status = getaddrinfo(HOST, PORT, &hints, &res)) != 0) { @@ -103,10 +105,16 @@ irc_recv() return -1; } + DPf("recieved %ld ",amt); + // find the end of a message char *c; char *end = recv_cur+amt; char *msg_start = recv_buf; + + + DPn("BUF",recv_buf,end-recv_buf); + for (c=recv_buf; c<end; c++) { if (*c == '\r' && *(c+1) == '\n') { handle(msg_start, (c+2)-msg_start); @@ -123,7 +131,11 @@ irc_recv() fprintf(stderr,"my receive buffer is filled with NONSENSE!!!\n"); return -1; } - memmove(recv_buf, msg_start, remlen); + if (recv_buf != msg_start) { + DPf("mem moving %ld\n",remlen); + memmove(recv_buf, msg_start, remlen); + } + recv_cur = recv_buf + remlen; } return 0; @@ -13,5 +13,5 @@ ssize_t sendall(int sockfd, void *buf, size_t len) { total_sent += sent; } while (total_sent < len); DPn("SEND",buf,len); - return total_sent; + return 0; } |