From b12ea9fb05e636213b35d46ddaec3e255e1a6992 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Wed, 29 Jul 2020 22:32:24 +0200 Subject: weechat: Protocol version 2, display replies --- weechat/net.c | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) (limited to 'weechat/net.c') diff --git a/weechat/net.c b/weechat/net.c index 897655a..ce8da6a 100644 --- a/weechat/net.c +++ b/weechat/net.c @@ -220,9 +220,9 @@ void net_handle_recv(int fd,const char *msg){ } const char *roomp=p+1; p=strchr(roomp,' '); - const char *q,*r,*s; + const char *q,*r,*s,*t; if(p==NULL||(q=strchr(p+1,' '))==NULL||(r=strchr(q+1,' '))==NULL - ||(s=strchr(r+1,' '))==NULL){ + ||(s=strchr(r+1,' '))==NULL||(t=strchr(s+1,' '))==NULL){ debugf("net_handle_recv: not enough arguments to 'message' <%s>\n",msg); return; } @@ -233,10 +233,12 @@ void net_handle_recv(int fd,const char *msg){ i64 stamplen=r-stampp; const char *msgidp=r+1; i64 msgidlen=s-msgidp; - const char *textp=s+1; + const char *replyidp=s+1; + i64 replyidlen=t-replyidp; + const char *textp=t+1; i64 textlen=msglen-(textp-msg); - (void)msgidp; (void)msgidlen; + (void)msgidp; (void)msgidlen; (void)replyidlen; struct net_response res; res.type=NET_MESSAGE; @@ -246,6 +248,16 @@ void net_handle_recv(int fd,const char *msg){ debugf("net_handle_recv: timestamp not a number in 'message' <%s>\n",msg); return; } + res.msgid=strtoll(msgidp,(char**)&endp,10); + if(endp-msgidp!=msgidlen){ + debugf("net_handle_recv: msgid not a number in 'message' <%s>\n",msg); + return; + } + res.replyid=strtoll(replyidp,(char**)&endp,10); + if(endp-replyidp!=replyidlen){ + debugf("net_handle_recv: replyid not a number in 'message' <%s>\n",msg); + return; + } res.room=malloc(roomlen+1); res.username=malloc(usernamelen+1); res.message=malloc(textlen+1); @@ -276,9 +288,9 @@ void net_handle_recv(int fd,const char *msg){ } const char *roomp=p+1; p=strchr(roomp,' '); - const char *q,*r,*s; + const char *q,*r,*s,*t; if(p==NULL||(q=strchr(p+1,' '))==NULL||(r=strchr(q+1,' '))==NULL - ||(s=strchr(r+1,' '))==NULL){ + ||(s=strchr(r+1,' '))==NULL||(t=strchr(s+1,' '))==NULL){ debugf("net_handle_recv: not enough arguments to 'history_message' <%s>\n",msg); return; } @@ -289,11 +301,11 @@ void net_handle_recv(int fd,const char *msg){ i64 stamplen=r-stampp; const char *msgidp=r+1; i64 msgidlen=s-msgidp; - const char *textp=s+1; + const char *replyidp=s+1; + i64 replyidlen=t-replyidp; + const char *textp=t+1; i64 textlen=msglen-(textp-msg); - (void)msgidp; (void)msgidlen; - struct net_response res; res.type=NET_HISTORY; const char *endp; @@ -302,6 +314,16 @@ void net_handle_recv(int fd,const char *msg){ debugf("net_handle_recv: timestamp not a number in 'history_message' <%s>\n",msg); return; } + res.msgid=strtoll(msgidp,(char**)&endp,10); + if(endp-msgidp!=msgidlen){ + debugf("net_handle_recv: msgid not a number in 'history_message' <%s>\n",msg); + return; + } + res.replyid=strtoll(replyidp,(char**)&endp,10); + if(endp-replyidp!=replyidlen){ + debugf("net_handle_recv: replyid not a number in 'history_message' <%s>\n",msg); + return; + } res.room=malloc(roomlen+1); res.username=malloc(usernamelen+1); res.message=malloc(textlen+1); -- cgit v1.2.3-54-g00ecf