summaryrefslogtreecommitdiff
path: root/vchat-protocol.c
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2022-05-17 15:23:33 +0200
committerDirk Engling <erdgeist@erdgeist.org>2022-05-17 15:23:33 +0200
commit34a4541114318a7eda1c96ed58f83cdcd2622207 (patch)
tree77d13dae58b6b1a39c14046658d392b7d6b72e69 /vchat-protocol.c
parent986fb5638542a943a6d9cd0d38d73605a642c55a (diff)
Move packet handler and line splitting to vchat-connection.c
Diffstat (limited to 'vchat-protocol.c')
-rwxr-xr-xvchat-protocol.c64
1 files changed, 2 insertions, 62 deletions
diff --git a/vchat-protocol.c b/vchat-protocol.c
index 0451b77..77e45ec 100755
--- a/vchat-protocol.c
+++ b/vchat-protocol.c
@@ -57,9 +57,6 @@ static void pmnotsent (char *message);
57/* declaration of server message array */ 57/* declaration of server message array */
58#include "vchat-messages.h" 58#include "vchat-messages.h"
59 59
60/* status-variable from vchat-client.c
61 * eventloop is done as long as this is true */
62extern int status;
63char *encoding; 60char *encoding;
64 61
65/* handle a pm not sent error 62/* handle a pm not sent error
@@ -577,8 +574,8 @@ usernickchange (char *message)
577} 574}
578 575
579/* handle received message from server */ 576/* handle received message from server */
580static void 577void
581parsemsg (char *message) 578protocol_parsemsg (char *message)
582{ 579{
583 char *str1, *str2; 580 char *str1, *str2;
584 int i; 581 int i;
@@ -691,60 +688,3 @@ parsemsg (char *message)
691 } 688 }
692} 689}
693 690
694/* offset in buffer (for linebreaks at packet borders) */
695#define BUFSIZE 4096
696static char _buf[BUFSIZE];
697static size_t _buf_fill;
698
699/* get data from servers filedescriptor */
700void
701networkinput (void)
702{
703 char *endmsg;
704 size_t freebytes = BUFSIZE - _buf_fill;
705 ssize_t bytes = vc_receivemessage(&_buf[_buf_fill], freebytes);
706
707 /* Our tls functions may require retries with handshakes etc, this is signalled by -2 */
708 if (bytes == -2)
709 return;
710
711 /* Error on the socket read? raise error message, bail out */
712 if (bytes == -1) {
713 snprintf (tmpstr, TMPSTRSIZE, "Receive fails, %s.", strerror(errno));
714 snprintf (errstr, ERRSTRSIZE, "Receive fails, %s.\n", strerror(errno));
715 writecf (FS_ERR,tmpstr);
716 status = 0;
717 return;
718 }
719
720 /* end of file from server? */
721 if (bytes == 0) {
722 /* inform user, bail out */
723 writecf (FS_SERV, "* EOF from server.");
724 snprintf (errstr, ERRSTRSIZE, "* EOF from server.\n");
725 status = 0;
726 return;
727 }
728
729 _buf_fill += bytes;
730
731 /* as long as there are lines .. */
732 while ((endmsg = memchr(_buf, '\n', _buf_fill)) != NULL) {
733 if (endmsg > _buf) {
734 /* Zero terminate message, optionally chomp CR */
735 endmsg[0] = 0;
736 if (endmsg[-1] == '\r')
737 endmsg[-1] = 0;
738 /* If terminating and chomping left us with a message, give it to line handler */
739 if (_buf[0]) {
740#ifdef DEBUG
741 /* debugging? log network input! */
742 fprintf (stderr, "<| %s\n", _buf);
743#endif
744 parsemsg (_buf);
745 }
746 }
747 _buf_fill -= 1 + endmsg - _buf;
748 memmove(_buf, endmsg + 1, _buf_fill);
749 }
750}