From 34d7ffdf32a59019fc750bb3f365cb7b5f229fc6 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Tue, 7 Jul 2020 21:21:46 +0200 Subject: weechat: Update to latest protocol --- weechat/net.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'weechat/net.c') diff --git a/weechat/net.c b/weechat/net.c index bab7f3a..80d417b 100644 --- a/weechat/net.c +++ b/weechat/net.c @@ -222,8 +222,9 @@ void net_handle_recv(int fd,const char *msg){ } const char *roomp=p+1; p=strchr(roomp,' '); - const char *q,*r; - if(p==NULL||(q=strchr(p+1,' '))==NULL||(r=strchr(q+1,' '))==NULL){ + 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); return; } @@ -232,9 +233,13 @@ void net_handle_recv(int fd,const char *msg){ i64 usernamelen=q-usernamep; const char *stampp=q+1; i64 stamplen=r-stampp; - const char *textp=r+1; + const char *msgidp=r+1; + i64 msgidlen=s-msgidp; + const char *textp=s+1; i64 textlen=msglen-(textp-msg); + (void)msgidp; (void)msgidlen; + struct net_response res; res.type=NET_MESSAGE; const char *endp; @@ -337,19 +342,25 @@ void net_handle_recv(int fd,const char *msg){ free(res.room); free(res.username); } else if(cmdlen==6&&memcmp(cmd,"invite",6)==0){ - if(*p=='\0'){ + const char *q; + if(*p=='\0'||(q=strchr(p+1,' '))==NULL){ fprintf(debugf,"net_handle_recv: no arguments to 'invite' <%s>\n",msg); return; } const char *roomp=p+1; - i64 roomlen=msglen-(roomp-msg); + i64 roomlen=q-roomp; + const char *userp=q+1; + i64 userlen=msglen-(userp-msg); struct net_response res; res.type=NET_INVITE; res.room=malloc(roomlen+1); - assert(res.room); + res.username=malloc(userlen+1); + assert(res.room&&res.username); memcpy(res.room,roomp,roomlen); res.room[roomlen]='\0'; + memcpy(res.username,userp,userlen); + res.username[userlen]='\0'; cb(fd,res,payload); free(res.room); } else if(cmdlen==6&&memcmp(cmd,"online",6)==0){ -- cgit v1.2.3-70-g09d2