tClose connection when a single-dot line is read - sacc - [fork] customized build of sacc, the simple console gopher client
 (HTM) git clone git://src.adamsgaard.dk/sacc
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
 (DIR) commit 1a1233685015795bf84fb623f4fec0a46535d887
 (DIR) parent 555e4735b22a5980dc39bda9da4a74d277d2f9f0
 (HTM) Author: Quentin Rameau <quinq@fifth.space>
       Date:   Mon,  8 Feb 2021 22:59:52 +0100
       
       Close connection when a single-dot line is read
       
       This approach instead of always warning that something might have been
       wrong in case the message isn't terminated single-dot line is more
       forgiving as not all gopher server follow that aspect of the standard.
       
       Diffstat:
         M sacc.c                              |      17 +++++++++++------
       
       1 file changed, 11 insertions(+), 6 deletions(-)
       ---
 (DIR) diff --git a/sacc.c b/sacc.c
       t@@ -377,8 +377,6 @@ molddiritem(char *raw)
                        s = nl;
                        nl = p+1;
                }
       -        if (!strcmp(s, ".\r\n") || !strcmp(s, ".\n"))
       -                --nitems;
                if (!nitems) {
                        diag("Couldn't parse dir item");
                        return NULL;
       t@@ -421,6 +419,17 @@ getrawitem(int sock)
                do {
                        bs -= n;
                        buf += n;
       +
       +                if (buf - raw >= 5) {
       +                        if (strncmp(buf-5, "\r\n.\r\n", 5) == 0) {
       +                                buf[-3] = '\0';
       +                                break;
       +                        }
       +                } else if (buf - raw == 3 && strncmp(buf-3, ".\r\n", 3)) {
       +                        buf[-3] = '\0';
       +                        break;
       +                }
       +
                        if (bs < 1) {
                                raw = xreallocarray(raw, ++bn, BUFSIZ);
                                buf = raw + (bn-1) * BUFSIZ;
       t@@ -611,10 +620,6 @@ fetchitem(Item *item)
                if (raw == NULL || !*raw) {
                        diag("Empty response from server");
                        clear(&raw);
       -        } else if ((r = strrchr(raw, '.')) == NULL || strcmp(r, ".\r\n")) {
       -                diag("Incomplete response from server");
       -        } else {
       -                *r = '\0';
                }
        
                return ((item->raw = raw) != NULL);