anntp

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

commit a4020fd17551517b9cadda9d0bbed51bc5a30773
parent 9591b402cfa2591f244985dfc0dec4203dd96db3
Author: Mario Rosell R. Martinez <mario@mariorosell.es>
Date:   Thu, 19 Mar 2026 19:27:49 +0100

Interface fixes

oopsie whoopsie

Diffstat:
A.anntp.h.swo | 0
A.anntp.h.swp | 0
MREADME | 53+++++------------------------------------------------
Manntp.h | 9+++++----
4 files changed, 10 insertions(+), 52 deletions(-)

diff --git a/.anntp.h.swo b/.anntp.h.swo Binary files differ. diff --git a/.anntp.h.swp b/.anntp.h.swp Binary files differ. diff --git a/README b/README @@ -1,49 +1,6 @@ -anntp -- a nntp implementation written in C -=========================================== - -anntp is a public-domain, TLS-capable, C implementation for POSIX systems of the Network News Transfer Protocol (NNTP), used by Usenet and other similar networks. - -It is a single header with no dependencies by default (unless you enable TLS, then it depends on OpenSSL), and implements full RFC 977 and 3977. - -Why ---- - -There is no NNTP implementation that works on C, and it is a pretty damn annoying protocol. - -Usage ------ - -Importing -~~~~~~~~~ - -Anntp is a single-header library. The easiest way is to just add a `3rdpary` directory and inside a submodule with the repo, or just copy the header and update when you want :P. - -Note that in exactly ONE C file you must define `ANNTP_IMPLEMENTATION` before including `anntp.h`. - -Config -~~~~~~ - -Before including `anntp.h`, you can define any of these macros: - -* `ANNTP_BUFSIZE`: Buffer size for all operations, -* `ANNTP_MALLOC`: A memory allocator function (only the name), -* `ANNTP_FREE`: A memory free procedure (again, only the name), -* `ANNTP_API`: A type specifier for all API functions. -* `ANNTP_TLS`: Enable TLS - -Usage -~~~~~ - -see the doc/ dir - -TODOs ------ - -* A higher-level API -* More - -License -------- - -ughh, pd? + ▄▄▄ ▄▄ ▄▄ ▄▄ ▄▄ ▄▄▄▄▄▄ ▄▄▄▄ +██▀██ ███▄██ ███▄██ ██ ██▄█▀ +██▀██ ██ ▀██ ██ ▀██ ██ ██ +================================ +A simple nntp implementation in C99. diff --git a/anntp.h b/anntp.h @@ -84,9 +84,10 @@ ANNTP_API void anntp_freeconn(AnntpConnection* conn); ANNTP_API ssize_t anntp_read(AnntpConnection* conn, uchar_t* buf, size_t bufsize); ANNTP_API ssize_t anntp_write(AnntpConnection* conn, const uchar_t* buf, size_t bufsize); 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_writeline(AnntpConnection* conn, const char* buf); 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); +ANNTP_API int anntp_auth(AnntpConnection* conn, const char* login, const char* password); #endif /* ANNTP_H */ @@ -279,7 +280,7 @@ anntp_readdot(AnntpConnection* cv, char* buf, size_t maxlen) if (!cv || !buf) return -1; size_t pos = 0; - char line[ANNTP_BUFSIZE]; + char* line = (char*)malloc(ANNTP_BUFSIZE); ssize_t n; for (;;) { @@ -297,7 +298,7 @@ anntp_readdot(AnntpConnection* cv, char* buf, size_t maxlen) ++out; size_t len = strlen(out); - if (pos + len >= maxlen - 1) + if (pos + len >= maxlen - 1 && maxlen != 0) break; /* Say NO to overflows */ memcpy(buf + pos, out, len); @@ -308,7 +309,7 @@ anntp_readdot(AnntpConnection* cv, char* buf, size_t maxlen) return (ssize_t)pos; } -/* NOTE: I have a gut feeling this is probably a bit insecure without tls... */ +/* NOTE: I have a gut feeling this auth mechanism is probably a bit insecure... */ int anntp_auth(AnntpConnection* cv, const char* user, const char* pass) {