nightmaremail

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

netstrings.h (2171B)


      1 #ifndef NETSTRINGS_H
      2 #define NETSTRINGS_H
      3 
      4 /* include/netstrings.h - header, NightmareMail new code for handling
      5  * netstrings
      6  *
      7  * This file may be used, chopped, screwed and copied without heed to
      8  * the general licence conditions of NightmareMail itself.
      9  *
     10  * Alternatively, it may be used under the same conditions as NMM
     11  * itself.
     12  *
     13  * This comment is probably a public domain dedication with MCDDL in
     14  * the alternate.
     15  */
     16 
     17 /* include/netstrings.h requires Laurent's buffer or Daniel's substdio
     18  * because it defines methods of accessing netstrings fed to it on
     19  * ssios or bios.
     20  *
     21  * Those methods are then elaborated in netstrings.c.
     22  */
     23 
     24 #ifdef USING_SKALIBS
     25 #include <skalibs/buffer.h>
     26 #include <skalibs/stralloc.h>
     27 #else
     28 #include "substdio.h"
     29 #include "stralloc.h"
     30 #endif
     31 
     32 
     33 // XXX this should be moved to substdio.h
     34 #ifdef USING_SKALIBS
     35 #define _BUFFER buffer
     36 #define _BUFFER_GET(bio, where, len) buffer_get(bio, where, len)
     37 #define _BUFFER_PUT(bio, where, len) buffer_put(bio, where, len)
     38 #else
     39 #define _BUFFER substdio
     40 #define _BUFFER_GET(bio, where, len) substdio_get(bio, where, len)
     41 #define _BUFFER_PUT(bio, where, len) substdio_put(bio, where, len)
     42 #endif
     43 
     44 #define NS_BIOERR	-1
     45 #define NS_PROTOCOL	-2
     46 #define NS_TOOMUCH	-3
     47 #define NS_INVAL	-4
     48 #define NS_SUCCESS	0
     49 
     50 /* signed char ns_getlength. Returns information as to its success
     51  * in putting the length of the incoming netstring in *length.
     52  * Returns NS_INVAL if called with a nullptr.
     53  */
     54 signed char ns_getlength (_BUFFER *bio, unsigned long long *length);
     55 
     56 /* signed char ns_getcomma. Returns information as to whether the
     57  * next byte is an ASCII comma.
     58  * Retval: Success if so, protocol if not.
     59  */
     60 signed char ns_getcomma (_BUFFER *bio);
     61 
     62 /* signed char ns_put. Returns information as to its success in
     63  * pushing the bytes buffer, of length length, onto the buffered I/O
     64  * bio, as a netstring.
     65  */
     66 signed char ns_put (_BUFFER *bio, char *buf, unsigned long long length);
     67 
     68 /* signed char ns_print. Returns information as to its success in
     69  * pushing the bytes buffer, of length length, onto the fildes fd
     70  */
     71 signed char ns_print (int fd, char *buf, unsigned long long length);
     72 
     73 #endif