Debian Codegraph @

ini/ini_serialize.c

raw symbols SCIP
1 /*
2 INI LIBRARY
3
4 Module contains functions to serialize configuration object.
5
6 Copyright (C) Dmitri Pal <[email protected]> 2010
7
8 INI Library is free software: you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 INI Library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with INI Library. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include "config.h"
23 #include <errno.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include <stdint.h>
27 #include "simplebuffer.h"
28 #include "collection.h"
29 #include "ini_valueobj.h"
30 #include "ini_defines.h"
31 #include "ini_configobj.h"
32 #include "ini_config_priv.h"
33 #include "trace.h"
34
35 /* Callback */
36 static int ini_serialize_cb(const char *property,
37 int property_len,
38 int type,
39 void *data,
40 int length,
41 void *custom_data,
42 int *stop)
43 {
44 int error = EOK;
45 struct simplebuffer *sbobj;
46 struct value_obj *vo;
47
48 TRACE_FLOW_ENTRY();
49
50 /* Banary items are the values */
51 if(type == COL_TYPE_BINARY) {
52 sbobj = (struct simplebuffer *)custom_data;
53 vo = *((struct value_obj **)(data));
54 error = value_serialize(vo, property, sbobj);
55 if (error) {
56 TRACE_ERROR_NUMBER("Failed to serizlize value", error);
57 *stop = 1;
58 }
59 }
60
61 TRACE_FLOW_EXIT();
62 return error;
63 }
64
65 /* Traverse the collection and build the serialization object */
66 int ini_config_serialize(struct ini_cfgobj *ini_config,
67 struct simplebuffer *sbobj)
68 {
69 int error = EOK;
70 TRACE_FLOW_ENTRY();
71
72 if (!ini_config) {
73 TRACE_ERROR_NUMBER("Invalid argument", EINVAL);
74 return EINVAL;
75 }
76
77 if (ini_config->cfg) {
78 error = col_traverse_collection(ini_config->cfg,
79 COL_TRAVERSE_DEFAULT,
80 ini_serialize_cb,
81 (void *)sbobj);
82 if (error) {
83 TRACE_ERROR_NUMBER("Failed to serialize collection", error);
84 return error;
85 }
86 }
87
88 if (ini_config->last_comment) {
89 error = ini_comment_serialize(ini_config->last_comment, sbobj);
90 if (error) {
91 TRACE_ERROR_NUMBER("Failed serialize comment", error);
92 return error;
93 }
94 }
95
96 TRACE_FLOW_EXIT();
97 return error;
98 }