99b9f9e5db801cfaa4fd5b07f22cb8d8fe5857f7
[tridge/openchange.git] / branches / plugfest / libocpf / ocpf_dump.c
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 #include "libocpf/ocpf.h"
21 #include "libocpf/ocpf_api.h"
22 #include "libocpf/ocpf_dump.h"
23
24 /**
25    \file ocpf_dump.c
26
27    \brief ocpf Dump API
28  */
29
30 static void ocpf_do_dump(const char *format, ...)
31 {
32         va_list ap;
33         char    *s = NULL;
34         int     ret;
35
36         va_start(ap, format);
37         ret = vasprintf(&s, format, ap);
38         va_end(ap);
39
40         if (ret == -1) {
41                 printf("[Dump failure]\n");
42         } else {
43                 printf("%s\n", s);
44         }
45         free(s);
46 }
47
48
49 /**
50    \details Dump OCPF Type
51
52    Dump OCPF Registered Type
53 */
54 _PUBLIC_ void ocpf_dump_type(uint32_t context_id)
55 {
56         struct ocpf_context     *ctx;
57
58         ctx = ocpf_context_search_by_context_id(ocpf->context, context_id);
59         if (!ctx) return;
60
61         OCPF_DUMP_TITLE(indent, "TYPE", OCPF_DUMP_TOPLEVEL);
62         indent++;
63         
64         INDENT();
65         OCPF_DUMP(("* %s", ctx->type ? ctx->type : "Undefined"));
66         indent--;
67 }
68
69
70 /**
71    \details Dump OCPF Destination Folder
72
73    Dump OCPF Registered Destination Folder
74  */
75 _PUBLIC_ void ocpf_dump_folder(uint32_t context_id)
76 {
77         struct ocpf_context     *ctx;
78
79         ctx = ocpf_context_search_by_context_id(ocpf->context, context_id);
80         if (!ctx) return;
81
82         OCPF_DUMP_TITLE(indent, "FOLDER", OCPF_DUMP_TOPLEVEL);
83         indent++;
84
85         INDENT();
86         OCPF_DUMP(("* 0x%llx", ctx->folder ? ctx->folder : 0xFFFFFFFF));
87         indent--;
88 }
89
90
91 /**
92    \details Dump OCPF Recipients
93
94    Dump OCPF Recipients
95  */
96 _PUBLIC_ void ocpf_dump_recipients(uint32_t context_id)
97 {
98         struct ocpf_context     *ctx;
99         struct ocpf_recipients  *element;
100
101         ctx = ocpf_context_search_by_context_id(ocpf->context, context_id);
102         if (!ctx) return;
103
104         OCPF_DUMP_TITLE(indent, "RECIPIENTS", OCPF_DUMP_TOPLEVEL);
105         indent++;
106
107         INDENT();
108         printf("* To: ");
109         for (element = ctx->recipients; element->next; element = element->next) {
110                 if (element->class == OCPF_MAPI_TO) {
111                         printf("%s;", element->name);
112                 }
113         }
114         printf("\n");
115
116         INDENT();
117         printf("* Cc: ");
118         for (element = ctx->recipients; element->next; element = element->next) {
119                 if (element->class == OCPF_MAPI_CC) {
120                         printf("%s;", element->name);
121                 }
122         }
123         printf("\n");
124
125         INDENT();
126         printf("* Bcc: ");
127         for (element = ctx->recipients; element->next; element = element->next) {
128                 if (element->class == OCPF_MAPI_BCC) {
129                         printf("%s;", element->name);
130                 }
131         }
132         printf("\n");
133 }
134
135
136 /**
137    \details Dump OCPF OLEGUID
138
139    Dump OCPF Registered OLEGUID
140 */
141 _PUBLIC_ void ocpf_dump_oleguid(uint32_t context_id)
142 {
143         struct ocpf_context     *ctx;
144         struct ocpf_oleguid     *element;
145
146         ctx = ocpf_context_search_by_context_id(ocpf->context, context_id);
147         if (!ctx) return;
148
149         OCPF_DUMP_TITLE(indent, "OLEGUID", OCPF_DUMP_TOPLEVEL);
150         indent++;
151         for (element = ctx->oleguid; element->next; element = element->next) {
152                 INDENT();
153                 printf("%-25s: %s\n", element->name, element->guid);
154         }
155         indent--;
156 }
157
158
159 _PUBLIC_ void ocpf_dump_variable(uint32_t context_id)
160 {
161         struct ocpf_context     *ctx;
162         struct ocpf_var         *element;
163
164         ctx = ocpf_context_search_by_context_id(ocpf->context, context_id);
165         if (!ctx) return;
166
167         OCPF_DUMP_TITLE(indent, "VARIABLE", OCPF_DUMP_TOPLEVEL);
168         indent++;
169         for (element = ctx->vars; element->next; element = element->next) {
170                 INDENT();
171                 printf("%s\n", element->name);
172         }
173         indent--;
174 }
175
176 _PUBLIC_ void ocpf_dump_property(uint32_t context_id)
177 {
178         struct ocpf_context     *ctx;
179         struct ocpf_property    *element;
180         const char              *proptag;
181
182         ctx = ocpf_context_search_by_context_id(ocpf->context, context_id);
183         if (!ctx) return;
184
185         OCPF_DUMP_TITLE(indent, "PROPERTIES", OCPF_DUMP_TOPLEVEL);
186         indent++;
187         for (element = ctx->props; element->next; element = element->next) {
188                 INDENT();
189                 proptag = (const char *)get_proptag_name(element->aulPropTag);
190                 printf("0x%.8x = %s\n", element->aulPropTag,
191                        (char *)(proptag ? proptag : "UNKNOWN"));
192         
193         }
194         indent--;
195 }
196
197
198 _PUBLIC_ void ocpf_dump_named_property(uint32_t context_id)
199 {
200         struct ocpf_context     *ctx;
201         struct ocpf_nproperty   *element;
202
203         ctx = ocpf_context_search_by_context_id(ocpf->context, context_id);
204         if (!ctx) return;
205
206         OCPF_DUMP_TITLE(indent, "NAMED PROPERTIES", OCPF_DUMP_TOPLEVEL);
207         indent++;
208
209         OCPF_DUMP_TITLE(indent, "OOM", OCPF_DUMP_SUBLEVEL);
210         indent++;
211         for (element = ctx->nprops; element->next; element = element->next) {
212                 if (element->kind == OCPF_OOM) {
213                         INDENT();
214                         printf("* %s\n", element->OOM);
215                 }
216         }
217         indent--;
218
219         OCPF_DUMP_TITLE(indent, "MNID_ID", OCPF_DUMP_SUBLEVEL);
220         indent++;
221         for (element = ctx->nprops; element->next; element = element->next) {
222                 if (element->kind == OCPF_MNID_ID) {
223                         INDENT();
224                         printf("* 0x%.4x\n", element->mnid_id);
225                 }
226         }
227         indent--;
228
229         OCPF_DUMP_TITLE(indent, "MNID_STRING", OCPF_DUMP_SUBLEVEL);
230         indent++;
231         for (element = ctx->nprops; element->next; element = element->next) {
232                 if (element->kind == OCPF_MNID_STRING) {
233                         INDENT();
234                         printf("* %s\n", element->mnid_string);
235                 }
236         }
237         indent--;
238
239         indent--;
240 }
241
242
243 _PUBLIC_ void ocpf_dump(uint32_t context_id)
244 {
245         indent = 0;
246         ocpf_dump_type(context_id);
247         ocpf_dump_folder(context_id);
248         ocpf_dump_oleguid(context_id);
249         ocpf_dump_recipients(context_id);
250         ocpf_dump_variable(context_id);
251         ocpf_dump_property(context_id);
252         ocpf_dump_named_property(context_id);
253 }