anntp

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

commit 34c08d4a32daf5761e8af037c82b284d43112135
parent cd3aeedbed21357799097326623b488963ee63b2
Author: Mario Rosell R. Martinez <mario@mariorosell.es>
Date:   Sat, 28 Mar 2026 21:57:06 +0100

anntp_overview: Add anntp_overview_cb

Diffstat:
Manntp.h | 51++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 50 insertions(+), 1 deletion(-)

diff --git a/anntp.h b/anntp.h @@ -197,6 +197,7 @@ ANNTP_API ssize_t anntp_article(AnntpConnection*, size_t num, AnntpArti ANNTP_API void anntp_article_free(AnntpArticle* art); ANNTP_API int anntp_article_cb(AnntpConnection* cv, size_t n, AnntpLineCb cb, void* extra); ANNTP_API ssize_t anntp_overview(AnntpConnection* cv, size_t start, size_t end, AnntpOverview* ov); +ANNTP_API int anntp_overview_cb(AnntpConnection*, size_t start, size_t end, AnntpLineCb, void*); ANNTP_API ssize_t anntp_write_all(AnntpConnection* conn, const uchar_t* buf, size_t bufsize); ANNTP_API ssize_t anntp_writeline(AnntpConnection* conn, const char* buf); ANNTP_API ssize_t anntp_readline(AnntpConnection* conn, char* buf, size_t maxlen); @@ -204,7 +205,7 @@ ANNTP_API ssize_t anntp_readdot(AnntpConnection* conn, char* buf, size_ ANNTP_API int anntp_readdot_cb(AnntpConnection* conn, AnntpLineCb cb, void* extra); ANNTP_API int anntp_auth(AnntpConnection* conn, const char* login, const char* password); ANNTP_API char* anntp_strerror(AnntpErrCode err); - + #endif /* ANNTP_H */ #ifdef ANNTP_IMPLEMENTATION @@ -387,6 +388,54 @@ error: return ANNTPE(ANE_IO); } +int +anntp_overview_cb(AnntpConnection* cv, size_t start, size_t end, AnntpLineCb cb, void* extra) +{ + if (!cv || !cb || start > end) + return ANE_PARAMS; + + char cmd[ANNTP_BUFSIZE]; + char line[ANNTP_BUFSIZE]; + + snprintf(cmd, sizeof(cmd), "XOVER %zu-%zu", start, end); + + if (anntp_writeline(cv, cmd) <= 0) + return ANE_IO; + + ssize_t r = anntp_readline(cv, line, sizeof(line)); + if (r <= 0) + return ANE_IO; + + /* expect 224 */ + if (strncmp(line, "224", 3) != 0) + return ANE_PROTO; + + for (;;) { + r = anntp_readline(cv, line, sizeof(line)); + if (r <= 0) + return ANE_IO; + + /* end of response */ + if (strcmp(line, ".\r\n") == 0) + break; + + /* dot-stuffing removal */ + char* out = line; + if (out[0] == '.' && out[1] == '.') + out++; + + /* strip CRLF for callback */ + size_t len = strlen(out); + while (len && (out[len-1] == '\n' || out[len-1] == '\r')) + out[--len] = '\0'; + + if (cb(out, extra) != 0) + return ANE_OK; /* user aborted early */ + } + + return ANE_OK; +} + static char* anntp__trim_left(char* s) {