server: intialize aux_header buffer to null if the data is missing.
[tridge/openchange.git] / branches / plugfest / libocpf / ocpf_api.h
1 /*
2    OpenChange OCPF (OpenChange Property File) implementation.
3
4    Copyright (C) Julien Kerihuel 2008-2010.
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef __OCPF_API_H_
21 #define __OCPF_API_H_
22
23 #include "libmapi/libmapi.h"
24
25 struct ocpf_var
26 {
27         struct ocpf_var         *prev;
28         struct ocpf_var         *next;
29         const char              *name;
30         const void              *value;
31         uint16_t                propType;
32 };
33
34 struct ocpf_oleguid
35 {
36         struct ocpf_oleguid     *prev;
37         struct ocpf_oleguid     *next;
38         const char              *name;
39         const char              *guid;
40 };
41
42 struct ocpf_property
43 {
44         struct ocpf_property    *prev;
45         struct ocpf_property    *next;
46         uint32_t                aulPropTag;
47         const void              *value;
48 };
49
50 struct ocpf_nprop
51 {
52         const char      *OOM;
53         const char      *mnid_string;
54         uint16_t        mnid_id;
55         uint16_t        propType;
56         const char      *guid;
57         bool            registered;
58 };
59
60 enum ocpf_ntype {
61         OCPF_OOM = 0x1,
62         OCPF_MNID_ID,
63         OCPF_MNID_STRING
64 };
65
66 struct ocpf_nproperty
67 {
68         struct ocpf_nproperty   *prev;
69         struct ocpf_nproperty   *next;
70         enum ocpf_ntype         kind;
71         const char              *OOM;
72         const char              *mnid_string;
73         uint16_t                mnid_id;
74         uint16_t                propType;
75         const char              *oleguid;
76         const void              *value;
77 };
78
79 struct ocpf_recipients
80 {
81         struct ocpf_recipients  *prev;
82         struct ocpf_recipients  *next;
83         char                    *name;
84         enum ocpf_recipClass    class;
85 };
86
87 struct ocpf_olfolder
88 {
89         int                     id;
90         const char              *name;
91 };
92
93 struct ocpf_context
94 {
95         /* lexer internal data */
96         int                     typeset;
97         bool                    folderset;
98         uint8_t                 recip_type;
99         uint16_t                ltype;
100         union SPropValue_CTR    lpProp;
101         struct Binary_r         bin;
102         struct ocpf_nprop       nprop;
103         unsigned int            lineno;
104         int                     result;
105         /* ocpf */
106         const char              *type;
107         struct ocpf_var         *vars;
108         struct ocpf_oleguid     *oleguid;
109         struct ocpf_property    *props;
110         struct ocpf_nproperty   *nprops;
111         struct ocpf_recipients  *recipients;
112         struct SPropValue       *lpProps;
113         uint32_t                cValues;
114         uint64_t                folder;
115         /* context */
116         FILE                    *fp;
117         const char              *filename;
118         uint32_t                ref_count;
119         uint32_t                context_id;
120         uint8_t                 flags;
121         struct ocpf_context     *prev;
122         struct ocpf_context     *next;
123 };
124
125 struct ocpf_freeid
126 {
127         uint32_t                context_id;
128         struct ocpf_freeid      *prev;
129         struct ocpf_freeid      *next;
130 };
131
132 struct ocpf
133 {
134         TALLOC_CTX              *mem_ctx;
135         struct ocpf_context     *context;
136         struct ocpf_freeid      *free_id;
137         uint32_t                last_id;
138 };
139
140
141 #include "libocpf/ocpf_private.h"
142
143 /**
144  * Defines
145  */
146 #define OCPF_WARN(c,x) (ocpf_do_debug(c, x))                            
147
148 #define OCPF_RETVAL_IF(x, c, msg, mem_ctx)                      \
149 do {                                                            \
150         if (x) {                                                \
151                 ocpf_do_debug(c, "%s", msg);                    \
152                 if (mem_ctx) {                                  \
153                         talloc_free(mem_ctx);                   \
154                 }                                               \
155                 return OCPF_ERROR;                              \
156         }                                                       \
157 } while (0);
158
159 #define OCPF_RETVAL_TYPE(x, c, msg, t, mem_ctx)                 \
160 do {                                                            \
161         if (x) {                                                \
162                 ocpf_do_debug(c, "%s", msg);                    \
163                 if (mem_ctx) {                                  \
164                         talloc_free(mem_ctx);                   \
165                 }                                               \
166                 return t;                                       \
167         }                                                       \
168 } while (0);
169
170 #define OCPF_INITIALIZED                "OCPF context has already been initialized"
171 #define OCPF_NOT_INITIALIZED            "OCPF context has not been initialized"
172 #define OCPF_INVALID_CONTEXT            "Invalid OCPF context"
173
174 #define OCPF_WRITE_NOT_INITIALIZED      "OCPF write context has not been initialized"
175
176 #define OCPF_FATAL_ERROR                "Fatal error encountered"
177 #define OCPF_WARN_FILENAME_INVALID      "Invalid filename"
178 #define OCPF_WARN_FILENAME_EXIST        "filename already exists"
179 #define OCPF_WARN_FILENAME_STAT         "Unable to stat file"
180
181 #define OCPF_WARN_PROP_REGISTERED       "Property already registered"
182 #define OCPF_WARN_PROP_TYPE             "Property type not supported"
183 #define OCPF_WARN_PROP_UNKNOWN          "Property Unknown"
184
185 #define OCPF_WARN_OOM_UNKNOWN           "Unknown OOM"
186 #define OCPF_WARN_OOM_REGISTERED        "OOM already registered"
187
188 #define OCPF_WARN_LID_UNKNOWN           "Unknown MNID_ID"
189 #define OCPF_WARN_LID_REGISTERED        "MNID_ID already registered"
190
191 #define OCPF_WARN_STRING_UNKNOWN        "Unknown MNID_STRING"
192 #define OCPF_WARN_STRING_REGISTERED     "MNID_STRING already registered"
193
194
195 #define OCPF_WARN_OLEGUID_N_REGISTERED  "OLEGUID name already registered"
196 #define OCPF_WARN_OLEGUID_G_REGISTERED  "OLEGUID GUID already registered"
197 #define OCPF_WARN_OLEGUID_UNREGISTERED  "OLEGUID unregistered"
198 #define OCPF_WARN_OLEGUID_INVALID       "OLEGUID invalid"
199
200 #define OCPF_WARN_VAR_REGISTERED        "Variable already registered"
201 #define OCPF_WARN_VAR_NOT_REGISTERED    "Unknown variable"
202 #define OCPF_WARN_VAR_TYPE              "Variable property type not supported"
203
204 #define OCPF_WARN_FOLDER_ID_UNKNOWN     "Unknown Folder"
205
206 #define OCPF_WARN_PROPVALUE_MISMATCH    "Property type and value mismatch"
207
208 #define OCPF_INVALID_PROPARRAY          "Invalid property array"
209 #define OCPF_INVALID_FILEHANDLE         "Invalid file handle"
210
211
212 #define OCPF_PROPERTY_BEGIN             "PROPERTY {\n"
213 #define OCPF_NPROPERTY_BEGIN            "NPROPERTY {\n"
214 #define OCPF_END                        "};\n"
215 #define OCPF_NEWLINE                    "\n"
216 #define OCPF_RECIPIENT_TO               "RECIPIENT TO "
217 #define OCPF_RECIPIENT_CC               "RECIPIENT CC "
218 #define OCPF_RECIPIENT_BCC              "RECIPIENT BCC "
219
220 #define DATE_FORMAT     "%Y-%m-%d %H:%M:%S"
221
222 #endif /* __OCPF_API_H_ */