1 /*===========================================================================
2   bistream.h
3     see parsifal.h for copyright info
4 ===========================================================================*/
5 #ifndef BISTREAM__H
6 #define BISTREAM__H
7 
8 #include <stddef.h>
9 #include <limits.h>
10 #ifdef ICONV_SUPPORT
11 #include "iconv.h"
12 #endif
13 #include "pns.h"
14 
15 #ifndef BYTE
16  #define BYTE unsigned char
17 #endif
18 
19 #ifndef COUNTBUFSIZE
20 #define COUNTBUFSIZE(cBytes, blocksize) \
21 ((!(cBytes)) ? (blocksize) : (!( (cBytes) % (blocksize) ) ? (int)(cBytes) : (int)( (((cBytes) / (blocksize)) + 1) * (blocksize) )) )
22 #endif
23 
24 #define BIS_DEFAULT_MAXBUFSIZE INT_MAX
25 #define BIS_DEFAULT_BLOCKSIZE 512
26 #define BIS_CHAR_MAX 16
27 
28 enum BIS_ERRORS {	BIS_ERR_MEMALLOC = -40,
29 					BIS_ERR_MAXBUF,
30 					BIS_ERR_INVALIDARG,
31 					BIS_ERR_ENCODING,
32 					BIS_ERR_INPUT,
33 					BIS_EOF = 1 };
34 
35 typedef int (*LPFNINPUTSRC)(BYTE *buf, int cBytes, int *cBytesActual, void *inputData);
36 
37 typedef struct tagBUFFEREDISTREAM
38 {
39 	BYTE *buf;
40 	BYTE *inbuf;
41 	int bufsize;
42 	int maxbufsize;
43 	int blocksize;
44 	int bytesavail;
45 	int pos;
46 	int eof;
47 	int err;
48 	int encerr;
49 	int inbufrest;
50 	void *userdata;
51 	void *inputData;
52 	LPFNINPUTSRC inputsrc;
53 	size_t (*encode) (struct tagBUFFEREDISTREAM *reader, const BYTE **inbuf, size_t *inbytesleft, BYTE **outbuf, size_t *outbytesleft);
54 #ifdef ICONV_SUPPORT
55 	iconv_t cd;
56 #endif
57 } BUFFEREDISTREAM, *LPBUFFEREDISTREAM;
58 
59 typedef size_t (*LPFNENCODE) (LPBUFFEREDISTREAM r, const BYTE **inbuf, size_t *inbytesleft, BYTE **outbuf, size_t *outbytesleft);
60 
61 #ifdef __cplusplus
62    extern "C" {
63 #endif
64 
65 int BufferedIStream_EncodeBuffer(LPBUFFEREDISTREAM r);
66 
67 int BufferedIStream_Peek(LPBUFFEREDISTREAM r,
68 						const BYTE *tok,
69 						int len,
70 						int offset);
71 
72 int BufferedIStream_ResetBuf(LPBUFFEREDISTREAM r,
73 						 int numBytes);
74 
75 LPBUFFEREDISTREAM BufferedIStream_Init(LPBUFFEREDISTREAM r,
76 						int blocksize);
77 
78 int BufferedIStream_AppendBytes(LPBUFFEREDISTREAM r,
79 						 const BYTE *bytes,
80 						 int len);
81 
82 void BufferedIStream_Free(LPBUFFEREDISTREAM r);
83 
84 #ifdef __cplusplus
85    }
86 #endif /* __cplusplus */
87 #endif /* BISTREAM__H */
88 
89 
90 
91