From a0f941e7ae0e6935152e5ce42bfb8b45d224c25d Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Mon, 13 Jul 2020 19:53:05 +0200 Subject: weechat: Abstract debug file into separate module --- weechat/net.c | 48 +++++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 25 deletions(-) (limited to 'weechat/net.c') diff --git a/weechat/net.c b/weechat/net.c index 80d417b..897655a 100644 --- a/weechat/net.c +++ b/weechat/net.c @@ -7,9 +7,7 @@ #include #include #include "net.h" - - -extern FILE *debugf; +#include "debug.h" struct store_item{ @@ -57,7 +55,7 @@ bool net_sendf(int fd,net_callback_t *callback,void *payload,const char *format, } assert(store); - fprintf(debugf,"net_sendf(%d,%p,\"%s\",...)\n",fd,callback,format); + debugf("net_sendf(%d,%p,\"%s\",...)\n",fd,callback,format); va_list ap,ap2; va_start(ap,format); @@ -98,7 +96,7 @@ void net_handle_recv(int fd,const char *msg){ i64 msglen=strlen(msg); const char *p=strchr(msg,' '); if(p==NULL){ - fprintf(debugf,"net_handle_recv: no space in message <%s>\n",msg); + debugf("net_handle_recv: no space in message <%s>\n",msg); return; } i64 taglen=p-msg; @@ -111,7 +109,7 @@ void net_handle_recv(int fd,const char *msg){ cb=history_callback; } else { if(taglen!=8){ - fprintf(debugf,"net_handle_recv: tag not length 8 <%s>\n",msg); + debugf("net_handle_recv: tag not length 8 <%s>\n",msg); return; } for(i64 i=0;i\n",msg); + debugf("net_handle_recv: no viable callback found <%s>\n",msg); return; } } @@ -140,7 +138,7 @@ void net_handle_recv(int fd,const char *msg){ cb(fd,(struct net_response){.type=NET_OK},payload); } else if(cmdlen==6&&memcmp(cmd,"number",6)==0){ if(*p=='\0'){ - fprintf(debugf,"net_handle_recv: no number argument <%s>\n",msg); + debugf("net_handle_recv: no number argument <%s>\n",msg); return; } const char *nump=p+1; @@ -150,7 +148,7 @@ void net_handle_recv(int fd,const char *msg){ const char *endp; res.number=strtol(nump,(char**)&endp,10); if(nump[0]=='\0'||*endp!='\0'){ - fprintf(debugf,"net_handle_recv: invalid number argument <%s>\n",msg); + debugf("net_handle_recv: invalid number argument <%s>\n",msg); return; } cb(fd,res,payload); @@ -178,14 +176,14 @@ void net_handle_recv(int fd,const char *msg){ } else if(cmdlen==4&&memcmp(cmd,"list",4)==0){ struct net_response res=(struct net_response){.type=NET_LIST}; if(*p=='\0'){ - fprintf(debugf,"net_handle_recv: no list count <%s>\n",msg); + debugf("net_handle_recv: no list count <%s>\n",msg); return; } const char *cursor=p+1; p=strchr(cursor,' '); res.nitems=strtol(cursor,NULL,10); if(res.nitems<=0){ - fprintf(debugf,"net_handle_recv: -- 0 items <%s>\n",msg); + debugf("net_handle_recv: -- 0 items <%s>\n",msg); res.nitems=0; res.items=NULL; cb(fd,res,payload); @@ -197,7 +195,7 @@ void net_handle_recv(int fd,const char *msg){ for(i64 i=0;i\n",msg); + debugf("net_handle_recv: short list <%s>\n",msg); return; } cursor++; @@ -207,7 +205,7 @@ void net_handle_recv(int fd,const char *msg){ assert(res.items[i]); memcpy(res.items[i],cursor,p-cursor); res.items[i][p-cursor]='\0'; - fprintf(debugf,"net_handle_recv: -- item \"%s\" <%s>\n",res.items[i],msg); + debugf("net_handle_recv: -- item \"%s\" <%s>\n",res.items[i],msg); cursor=p; } cb(fd,res,payload); @@ -217,7 +215,7 @@ void net_handle_recv(int fd,const char *msg){ free(res.items); } else if(cmdlen==7&&memcmp(cmd,"message",7)==0){ if(*p=='\0'){ - fprintf(debugf,"net_handle_recv: no arguments to 'message' <%s>\n",msg); + debugf("net_handle_recv: no arguments to 'message' <%s>\n",msg); return; } const char *roomp=p+1; @@ -225,7 +223,7 @@ void net_handle_recv(int fd,const char *msg){ const char *q,*r,*s; if(p==NULL||(q=strchr(p+1,' '))==NULL||(r=strchr(q+1,' '))==NULL ||(s=strchr(r+1,' '))==NULL){ - fprintf(debugf,"net_handle_recv: not enough arguments to 'message' <%s>\n",msg); + debugf("net_handle_recv: not enough arguments to 'message' <%s>\n",msg); return; } i64 roomlen=p-roomp; @@ -245,7 +243,7 @@ void net_handle_recv(int fd,const char *msg){ const char *endp; res.timestamp=strtoll(stampp,(char**)&endp,10); if(endp-stampp!=stamplen){ - fprintf(debugf,"net_handle_recv: timestamp not a number in 'message' <%s>\n",msg); + debugf("net_handle_recv: timestamp not a number in 'message' <%s>\n",msg); return; } res.room=malloc(roomlen+1); @@ -268,12 +266,12 @@ void net_handle_recv(int fd,const char *msg){ cb(fd,res,payload); } else if(cmdlen==15&&memcmp(cmd,"history_message",15)==0){ if(*p=='\0'){ - fprintf(debugf,"net_handle_recv: no arguments to 'history_message' <%s>\n",msg); + debugf("net_handle_recv: no arguments to 'history_message' <%s>\n",msg); return; } p=strchr(p+1,' '); if(*p=='\0'){ - fprintf(debugf,"net_handle_recv: no arguments past index to 'history_message' <%s>\n",msg); + debugf("net_handle_recv: no arguments past index to 'history_message' <%s>\n",msg); return; } const char *roomp=p+1; @@ -281,7 +279,7 @@ void net_handle_recv(int fd,const char *msg){ const char *q,*r,*s; if(p==NULL||(q=strchr(p+1,' '))==NULL||(r=strchr(q+1,' '))==NULL ||(s=strchr(r+1,' '))==NULL){ - fprintf(debugf,"net_handle_recv: not enough arguments to 'history_message' <%s>\n",msg); + debugf("net_handle_recv: not enough arguments to 'history_message' <%s>\n",msg); return; } i64 roomlen=p-roomp; @@ -301,7 +299,7 @@ void net_handle_recv(int fd,const char *msg){ const char *endp; res.timestamp=strtoll(stampp,(char**)&endp,10); if(endp-stampp!=stamplen){ - fprintf(debugf,"net_handle_recv: timestamp not a number in 'history_message' <%s>\n",msg); + debugf("net_handle_recv: timestamp not a number in 'history_message' <%s>\n",msg); return; } res.room=malloc(roomlen+1); @@ -321,7 +319,7 @@ void net_handle_recv(int fd,const char *msg){ } else if(cmdlen==4&&memcmp(cmd,"join",4)==0){ const char *q; if(*p=='\0'||(q=strchr(p+1,' '))==NULL){ - fprintf(debugf,"net_handle_recv: not enough arguments to 'join' <%s>\n",msg); + debugf("net_handle_recv: not enough arguments to 'join' <%s>\n",msg); return; } const char *roomp=p+1; @@ -344,7 +342,7 @@ void net_handle_recv(int fd,const char *msg){ } else if(cmdlen==6&&memcmp(cmd,"invite",6)==0){ const char *q; if(*p=='\0'||(q=strchr(p+1,' '))==NULL){ - fprintf(debugf,"net_handle_recv: no arguments to 'invite' <%s>\n",msg); + debugf("net_handle_recv: no arguments to 'invite' <%s>\n",msg); return; } const char *roomp=p+1; @@ -366,7 +364,7 @@ void net_handle_recv(int fd,const char *msg){ } else if(cmdlen==6&&memcmp(cmd,"online",6)==0){ const char *q; if(*p=='\0'||(q=strchr(p+1,' '))==NULL){ - fprintf(debugf,"net_handle_recv: not enough arguments to 'online' <%s>\n",msg); + debugf("net_handle_recv: not enough arguments to 'online' <%s>\n",msg); return; } const char *nump=p+1; @@ -378,12 +376,12 @@ void net_handle_recv(int fd,const char *msg){ .online.num=strtol(nump,(char**)&endp,10) }; if(nump[0]==' '||*endp!=' '){ - fprintf(debugf,"net_handle_recv: invalid number argument to 'online' <%s>\n",msg); + debugf("net_handle_recv: invalid number argument to 'online' <%s>\n",msg); return; } cb(fd,res,payload); free(res.online.username); } else { - fprintf(debugf,"net_handle_recv: unknown command <%s>\n",msg); + debugf("net_handle_recv: unknown command <%s>\n",msg); } } -- cgit v1.2.3-70-g09d2