libinn - Man Page

InterNetNews library routines

Synopsis

    #include "inn/libinn.h"

    #define ISWHITE(c) ...

    /* Headers-related routines. */
    extern char *GenerateMessageID(char *domain);
    extern void HeaderCleanFrom(char *from);
    extern struct _DDHANDLE *DDstart(FILE *FromServer, FILE *ToServer);
    extern void DDcheck(struct _DDHANDLE *h, char *group);
    extern char *DDend(struct _DDHANDLE *h);

    /* Opening the active file on a client. */
    extern FILE *CAopen(FILE *FromServer, FILE *ToServer);
    extern FILE *CAlistopen(FILE *FromServer, FILE *ToServer,
                            const char *request);
    extern void CAclose(void);

    /* File locking. */
    enum inn_locktype
    {
        INN_LOCK_READ,
        INN_LOCK_WRITE,
        INN_LOCK_UNLOCK
    };

    extern bool inn_lock_file(int fd, enum inn_locktype type,
                              bool block);

    /* NNTP functions. */
    extern int NNTPlocalopen(FILE **FromServerp, FILE **ToServerp,
                             char *errbuff, size_t len);
    extern int NNTPremoteopen(int port, FILE **FromServerp,
                              FILE **ToServerp, char *errbuff,
                              size_t len);
    extern int NNTPconnect(const char *host, int port,
                           FILE **FromServerp, FILE **ToServerp,
                           char *errbuff, size_t len);
    extern int NNTPsendarticle(char *text, FILE *ToServer,
                               bool terminate);
    extern int NNTPsendpassword(char *server, FILE *FromServer,
                                FILE *ToServer);

    /* Hash functions. */
    typedef struct {
        char hash[16];
    } HASH;

    extern HASH HashMessageID(const char *MessageID);

    /* Other useful functions. */
    extern char *inn_getfqdn(const char *domain);
    extern char *GetModeratorAddress(FILE *FromServer, FILE *ToServer,
                                     char *group, char *moderatormailer);

    /* Miscellaneous. */
    extern int GetResourceUsage(double *usertime, double *systime);
    extern void Radix32(unsigned long value, char *buff);
    extern char *ReadInDescriptor(int fd, struct stat *Sbp);
    extern char *ReadInFile(const char *name, struct stat *Sbp);

    /* Setting or clearing file descriptor flags. */
    #include "inn/fdflag.h"

    bool fdflag_close_exec(int fd, bool flag);
    bool fdflag_nonblocking(socket_type fd, bool flag);

Description

libinn is a library of utility routines for manipulating Usenet articles and related data.  The whole documentation of libinn routines is split into several specific man pages besides this one: libinn_clientlib(3), libinn_dbz(3), libinn_inndcomm(3), libinn_list(3), libinn_qio(3), libinn_tst(3) and libinn_uwildmat(3).

Macros

ISWHITE is a macro which tests whether its char argument is a space or a tabulation.

Client Active File

CAopen and CAclose provide news clients with access to the active file; the CA stands for Client Active.  CAopen opens the active file for reading.  It returns a pointer to an open FILE, or NULL on error.  If a local or NFS-mounted copy exists, CAopen will use that file. The FromServer and ToServer parameters should be FILE's connected to the NNTP server for input and output, respectively.  See NNTPremoteopen or NNTPlocalopen, below.  If either parameter is NULL, then CAopen will just return NULL if the file is not locally available.  If they are not NULL, CAopen will use them to query the NNTP server using the LIST command to make a local temporary copy.

The CAlistopen sends a LIST command to the server and returns a temporary file containing the results.  The request parameter, if not NULL, will be sent as an argument to the command.  Unlike CAopen, this routine will never use a locally-available copy of the active file.

CAclose closes the active file and removes any temporary file that might have been created by CAopen or CAlistopen.

File Locking

inn_lock_file tries to lock the file descriptor fd.  If block is true, it will block until the lock can be made, otherwise it will return false if the file cannot be locked.  type is one of INN_LOCK_READ, INN_LOCK_WRITE or INN_LOCK_UNLOCK.  It returns false on failure or true on success.

NNTP Functions

NNTPlocalopen opens a connection to the private port of an InterNetNews server running on the local host, if HAVE_UNIX_DOMAIN_SOCKETS in include/config.h is defined.  It returns -1 on failure, or 0 on success.  FromServerp and ToServerp will be filled in with FILE's which can be used to communicate with the server.  errbuff can either be NULL or a pointer to a buffer at least 512 bytes long.  If not NULL, and the server refuses the connection, then it will be filled in with the text of the server's reply.  len should be the length of the errbuff buffer. This routine is not for general use.  If HAVE_UNIX_DOMAIN_SOCKETS in include/config.h is not defined, this is a stub routine, for compatibility with systems that have Unix-domain stream sockets, and it then always returns -1.

NNTPremoteopen does the same, except that it uses the server parameter set in inn.conf as the local server, and opens a connection to the port. Any client program can use this routine.  It returns -1 on failure, or 0 on success.

NNTPconnect is the same as NNTPremoteopen except that the desired host is given as the host parameter.

NNTPsendarticle writes text on ToServer using NNTP conventions for line termination.  The text should consist of one or more lines ending with a newline.  If terminate is true, then the routine will also write the NNTP data-termination marker on the stream.  It returns -1 on failure, or 0 on success.

NNTPsendpassword sends authentication information to an NNTP server by finding the appropriate entry in the passwd.nntp file.  server contains the name of the host; the server parameter in inn.conf will be used if server is NULL.  FromServer and ToServer should be FILE's that are connected to the server.  No action is taken if the specified host is not listed in the password file.

Hashes

HashMessageID returns hashed Message-ID using MD5.

Other Useful Functions

inn_getfqdn returns the fully qualified domain name of the local host. domain is used to qualify the local host name if local host cannot be resolved in DNS.  The returned value points to newly-allocated memory that the caller is responsible for freeing, or NULL on error.

GetModeratorAddress returns the mailing address of the moderator for specified group or NULL on error.  moderatormailer is used as its address, if there is no matched moderator.  See moderators(5) for details on how the address is determined.  GetModeratorAddress does no checking to see if the specified group is actually moderated.  The returned value points to static space that is reused on subsequent calls.  The FromServer and ToServer parameters should be FILE's connected to the NNTP server for input and output, respectively.  If either of these parameters is NULL, then an attempt to get the list from a local copy is made.

Miscellaneous

GetResourceUsage fills in the usertime and systime parameters with the total user and system time used by the current process and any children it may have spawned.  If HAVE_GETRUSAGE in include/config.h is defined, it gets the values by doing a getrusage(2) system call; otherwise it calls times(2).  It returns -1 on failure, or 0 on success.

Radix32 converts the number in value into a radix-32 string into the buffer pointed to by buff.  The number is split into five-bit pieces and each piece is converted into a character using the alphabet 0..9a..v to represent the numbers 0..32.  Only the lowest 32 bits of value are used, so buff needs only pointing to a buffer of eight bytes (seven characters and the trailing \0).

ReadInFile reads the file named name into allocated memory, appending a terminating \0 byte.  It returns a pointer to the space, or NULL on error. If Sbp is not NULL, it is taken as the address of a place to store the results of a stat(2) call.

ReadInDescriptor performs the same function as ReadInFile except that fd refers to an already-open file.

File Descriptor Flags

fdflag_close_exec can make a descriptor close-on-exec so that it is not shared with any child processes.  If the flag is true, the file is so marked; if false, the close-on-exec mode is cleared.  It returns false on failure (or when the function is unsupported) or true on success.

fdflag_nonblocking enables (if flag is true) or disables (if flag is false) non-blocking I/O on the indicated socket_type (which can be a non-socket file descriptor on UNIX systems, but a socket_type is expected on Windows).  It returns false on failure or true on success.

Examples

    #include "inn/fdflag.h"
    #include "inn/libinn.h"

    char *p;
    char frombuff[256], errbuff[256];
    FILE *F;
    FILE *ToServer;
    FILE *FromServer;
    int port = 119;

    strlcpy(frombuff, HDR(HDR__FROM), sizeof(frombuff));
    HeaderCleanFrom(frombuff);

    if ((F = CAopen(FromServer, ToServer)) == NULL)
        Fatal("Can't open active file");

    /* Don't pass the file on to our children. */
    fdflag_close_exec(fileno(F), true);

    /* Make a local copy. */
    p = ReadInDescriptor(fileno(F), (struct stat *) NULL);

    /* Close the file. */
    CAclose();

    if (NNTPremoteopen(port, &FromServer, &ToServer, errbuff,
                       sizeof(errbuff)) < 0)
        Fatal("Can't connect to server");

    if ((p = GetModeratorAddress(NULL, NULL, "comp.sources.unix",
                                 "%s@example.com")) == NULL)
        Fatal("Can't find moderator's address");

History

Written by Rich $alz <rsalz@uunet.uu.net> for InterNetNews.  Rewritten into POD by Julien Elie.

See Also

active(5), inn.conf(5), libinn_clientlib(3), libinn_dbz(3), libinn_inndcomm(3), libinn_list(3), libinn_qio(3), libinn_tst(3), libinn_uwildmat(3), moderators(5), passwd.nntp(5).

Referenced By

inn.conf(5), libinn_clientlib(3), libinn_dbz(3), libinnhist(3), libinn_inndcomm(3), libinn_qio(3), passwd.nntp(5).

2022-02-18 INN 2.6.5 InterNetNews Documentation