1 /*
2  * XML Security Library (http://www.aleksey.com/xmlsec).
3  *
4  * Memory buffer.
5  *
6  * This is free software; see Copyright file in the source
7  * distribution for preciese wording.
8  *
9  * Copyright (C) 2002-2016 Aleksey Sanin <aleksey@aleksey.com>. All Rights Reserved.
10  */
11 #ifndef __XMLSEC_BUFFER_H__
12 #define __XMLSEC_BUFFER_H__
13 
14 #include <libxml/tree.h>
15 #include <xmlsec/xmlsec.h>
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif /* __cplusplus */
20 
21 typedef struct _xmlSecBuffer                                    xmlSecBuffer,
22                                                                 *xmlSecBufferPtr;
23 
24 
25 /**
26  * xmlSecAllocMode:
27  * @xmlSecAllocModeExact:       the memory allocation mode that minimizes total
28  *                              allocated memory size.
29  * @xmlSecAllocModeDouble:      the memory allocation mode that tries to minimize
30  *                              the number of malloc calls.
31  *
32  * The memory allocation mode (used by @xmlSecBuffer and @xmlSecList).
33  */
34 typedef enum {
35     xmlSecAllocModeExact = 0,
36     xmlSecAllocModeDouble
37 } xmlSecAllocMode;
38 
39 /*****************************************************************************
40  *
41  * xmlSecBuffer
42  *
43  ****************************************************************************/
44 
45 /**
46  * xmlSecBuffer:
47  * @data: the pointer to buffer data.
48  * @size: the current data size.
49  * @maxSize: the max data size (allocated buffer size).
50  * @allocMode: the buffer memory allocation mode.
51  *
52  * Binary data buffer.
53  */
54 struct _xmlSecBuffer {
55     xmlSecByte*         data;
56     xmlSecSize          size;
57     xmlSecSize          maxSize;
58     xmlSecAllocMode     allocMode;
59 };
60 
61 XMLSEC_EXPORT void              xmlSecBufferSetDefaultAllocMode (xmlSecAllocMode defAllocMode,
62                                                                  xmlSecSize defInitialSize);
63 
64 XMLSEC_EXPORT xmlSecBufferPtr   xmlSecBufferCreate              (xmlSecSize size);
65 XMLSEC_EXPORT void              xmlSecBufferDestroy             (xmlSecBufferPtr buf);
66 XMLSEC_EXPORT int               xmlSecBufferInitialize          (xmlSecBufferPtr buf,
67                                                                  xmlSecSize size);
68 XMLSEC_EXPORT void              xmlSecBufferFinalize            (xmlSecBufferPtr buf);
69 XMLSEC_EXPORT xmlSecByte*       xmlSecBufferGetData             (xmlSecBufferPtr buf);
70 XMLSEC_EXPORT int               xmlSecBufferSetData             (xmlSecBufferPtr buf,
71                                                                  const xmlSecByte* data,
72                                                                  xmlSecSize size);
73 XMLSEC_EXPORT xmlSecSize        xmlSecBufferGetSize             (xmlSecBufferPtr buf);
74 XMLSEC_EXPORT int               xmlSecBufferSetSize             (xmlSecBufferPtr buf,
75                                                                  xmlSecSize size);
76 XMLSEC_EXPORT xmlSecSize        xmlSecBufferGetMaxSize          (xmlSecBufferPtr buf);
77 XMLSEC_EXPORT int               xmlSecBufferSetMaxSize          (xmlSecBufferPtr buf,
78                                                                  xmlSecSize size);
79 XMLSEC_EXPORT void              xmlSecBufferEmpty               (xmlSecBufferPtr buf);
80 XMLSEC_EXPORT int               xmlSecBufferAppend              (xmlSecBufferPtr buf,
81                                                                  const xmlSecByte* data,
82                                                                  xmlSecSize size);
83 XMLSEC_EXPORT int               xmlSecBufferPrepend             (xmlSecBufferPtr buf,
84                                                                  const xmlSecByte* data,
85                                                                  xmlSecSize size);
86 XMLSEC_EXPORT int               xmlSecBufferRemoveHead          (xmlSecBufferPtr buf,
87                                                                  xmlSecSize size);
88 XMLSEC_EXPORT int               xmlSecBufferRemoveTail          (xmlSecBufferPtr buf,
89                                                                  xmlSecSize size);
90 
91 XMLSEC_EXPORT int               xmlSecBufferReadFile            (xmlSecBufferPtr buf,
92                                                                  const char* filename);
93 
94 XMLSEC_EXPORT int               xmlSecBufferBase64NodeContentRead(xmlSecBufferPtr buf,
95                                                                  xmlNodePtr node);
96 XMLSEC_EXPORT int               xmlSecBufferBase64NodeContentWrite(xmlSecBufferPtr buf,
97                                                                  xmlNodePtr node,
98                                                                  int columns);
99 
100 XMLSEC_EXPORT xmlOutputBufferPtr xmlSecBufferCreateOutputBuffer (xmlSecBufferPtr buf);
101 
102 
103 #ifdef __cplusplus
104 }
105 #endif /* __cplusplus */
106 
107 #endif /* __XMLSEC_BUFFER_H__ */
108 
109