anntp is a minimalistic, light, and hackable single-header NNTP (Network News Transfer Protocol) client library implemented in (semi-)portable C99.
It is low level, but still usable, and portable between UNIX-like systems.
Right now, it supports:
- multiple connections,
- low-level server/client I/O, plus a bazillion variations of the same two functions.
- TLS (just TLS; no
STARTTLS, that is on the works, sorry), - error handling
- "idiomatic" C API
- A C compiler (
gcc,clang,tcc, ...) - OpenSSL/LibreSSL (optional, for TLS support)
- An UNIX-like system.
-
Copy
anntp.hto your project -
Include the library in as many files as you want, but in exactly ONE file, add:
#define ANNTP_IMPLEMENTATION
Before including
anntp.h -
If you want TLS support, add this to every file that uses anntp:
#define ANNTP_TLS
- If you want STARTTLS, use the
anntp_starttls()function once you've made the non-TLS connection.
- If you want STARTTLS, use the
-
ENJOY!
You need to free stuff manually, this is C, what did you expect?
The anntp_free_* functions free stuff. See their args or name to see what
they free.
NOTE: All strings returned by the library are explicitly dynamically allocated.
There is an AnntpErrCode enum with the different error types:
ANE_OK: successANE_PARAMS: wrong parametersANE_IO: very generic I/O error (OOM, sending, recieving... the spectrum is broad)ANE_TLS: only produced if TLS support is on, TLS encryption failureANE_PROTO: protocol error; the server returned an unexpected responseANE_AUTH: authentication failure
Some functions probably return their error codes in negative if they return a
ssize_t success; to get the real error code of a function use the AERR()
macro.
See examples/ for a couple of examples, but for now you can read the greeting with:
#include <stdio.h>
#define ANNTP_IMPLEMENTATION
#define ANNTP_TLS /* remove for no tls */
#include "anntp.h"
int
main(int argc, char** argv)
{
char host[] = "news.example.com";
char* port = "563"; /* change to 119 for no tls */
anntp_init();
if (argc >= 2)
host = argv[2];
AnntpConnection* c = anntp_mkconn(host, port, false);
if (!c)
return 1;
char line[256];
ssize_t res = anntp_readline(c, line, sizeof(line));
if (!ANNTP_ISERR(res))
puts(line);
else {
fprintf(stderr, anntp_strerror(AERR(res)));
return 1;
}
anntp_freeconn(c);
return 0;
}The git repository is on sr.ht, contribute patches via the anntp-devel mailing list. There's also an user's mailing list; the anntp-users list.
Send issues to this tracker.
CC0. See the LICENSE file for more information. Warranty:
Affirmer offers the Work as-is and makes no representations or warranties of any kind concerning the Work, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non infringement, or the absence of latent or other defects, accuracy, or the present or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law.
Originally written by
Mario Rosell <mario AT mariorosell DOT es>.