| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
} |