anntp

a nntp implementation in pure C99
Log | Files | Refs | README | LICENSE

commit 613bc8cd77bb552dc1b3ec5a302f0a8329c8184f
parent f7f20a74dd85bafbf0350d9be0556abbd13ec81b
Author: Mario Rosell R. Martinez <mario@mariorosell.es>
Date:   Wed, 18 Mar 2026 20:47:01 +0100

Add readline_dot

Diffstat:
Manntp.h | 36++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+), 0 deletions(-)

diff --git a/anntp.h b/anntp.h @@ -86,6 +86,7 @@ ANNTP_API ssize_t anntp_write(AnntpConnection* conn, const uchar_t* buf, ANNTP_API ssize_t anntp_write_all(AnntpConnection* conn, const uchar_t* buf, size_t bufsize); ANNTP_API ssize_t anntp_write_line(AnntpConnection* conn, const uchar_t* buf, size_t bufsize); ANNTP_API ssize_t anntp_readline(AnntpConnection* conn, char* buf, size_t maxlen); +ANNTP_API ssize_t anntp_readdot(AnntpConnection* conn, char* buf, size_t maxlen); #endif /* ANNTP_H */ @@ -272,5 +273,40 @@ anntp_writeline(AnntpConnection* cv, const char* line) return n; } +ssize_t +anntp_readdot(AnntpConnection* cv, char* buf, size_t maxlen) +{ + if (!cv || !buf) return -1; + + size_t pos = 0; + char line[ANNTP_BUFSIZE]; + ssize_t n; + + for (;;) { + n = anntp_readline(cv, line, sizeof(line)); + if (n <= 0) + break; /* closed or error */ + + /* end of response is a single period */ + if (strcmp(line, ".\r\n") == 0) + break; + + /* lines starting with .. are dot-stuffed, do a /^\.\././ ;) */ + char* out = line; + if (line[0] == '.', line[1] == '.') + ++out; + + size_t len = strlen(out); + if (pos + len >= maxlen - 1) + break; /* Say NO to overflows */ + + memcpy(buf + pos, out, len); + pos += len; + } + + buf[pos] = '\0'; + return (ssize_t)pos; +} + #endif /* ANNTP_IMPLEMENTATION */