netstrings.h (2247B)
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_BYTES -5 49 #define NS_SUCCESS 0 50 51 /* signed char ns_getlength. Returns information as to its success 52 * in putting the length of the incoming netstring in *length. 53 * Returns NS_INVAL if called with a nullptr. 54 */ 55 signed char ns_getlength (_BUFFER *bio, unsigned long long *length); 56 57 /* signed char ns_getcomma. Returns information as to whether the 58 * next byte is an ASCII comma. 59 * Retval: Success if so, protocol if not (or if ran out of bytes). 60 */ 61 signed char ns_getcomma (_BUFFER *bio, unsigned long long *bytesleft); 62 63 /* signed char ns_put. Returns information as to its success in 64 * pushing the bytes buffer, of length length, onto the buffered I/O 65 * bio, as a netstring. 66 */ 67 signed char ns_put (_BUFFER *bio, char *buf, unsigned long long length); 68 69 /* signed char ns_print. Returns information as to its success in 70 * pushing the bytes buffer, of length length, onto the fildes fd 71 */ 72 signed char ns_print (int fd, char *buf, unsigned long long length); 73 74 #endif