| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#include "config.h" |
| 24 |
#include <stdio.h> |
| 25 |
#include <errno.h> |
| 26 |
#include "trace.h" |
| 27 |
#include "collection.h" |
| 28 |
#include "collection_tools.h" |
| 29 |
#include "ini_configobj.h" |
| 30 |
#include "ini_config_priv.h" |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
void ini_free_section_list(char **section_list) |
| 35 |
{ |
| 36 |
TRACE_FLOW_ENTRY(); |
| 37 |
|
| 38 |
col_free_property_list(section_list); |
| 39 |
|
| 40 |
TRACE_FLOW_EXIT(); |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
void ini_free_attribute_list(char **section_list) |
| 45 |
{ |
| 46 |
TRACE_FLOW_ENTRY(); |
| 47 |
|
| 48 |
col_free_property_list(section_list); |
| 49 |
|
| 50 |
TRACE_FLOW_EXIT(); |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
char **ini_get_section_list(struct ini_cfgobj *ini_config, int *size, int *error) |
| 58 |
{ |
| 59 |
char **list; |
| 60 |
|
| 61 |
TRACE_FLOW_ENTRY(); |
| 62 |
|
| 63 |
|
| 64 |
if (ini_config == NULL) { |
| 65 |
TRACE_ERROR_NUMBER("Invalid argument.", EINVAL); |
| 66 |
if (error) *error = EINVAL; |
| 67 |
return NULL; |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
list = col_collection_to_list(ini_config->cfg, size, error); |
| 72 |
|
| 73 |
TRACE_FLOW_STRING("ini_get_section_list returning", |
| 74 |
((list == NULL) ? "NULL" : list[0])); |
| 75 |
return list; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
char **ini_get_attribute_list(struct ini_cfgobj *ini_config, |
| 82 |
const char *section, |
| 83 |
int *size, |
| 84 |
int *error) |
| 85 |
{ |
| 86 |
struct collection_item *subcollection = NULL; |
| 87 |
char **list; |
| 88 |
int err; |
| 89 |
int i = 0; |
| 90 |
|
| 91 |
TRACE_FLOW_ENTRY(); |
| 92 |
|
| 93 |
|
| 94 |
if (ini_config == NULL) { |
| 95 |
TRACE_ERROR_NUMBER("Invalid configuration object argument.", EINVAL); |
| 96 |
if (error) *error = EINVAL; |
| 97 |
return NULL; |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
if (section == NULL) { |
| 102 |
TRACE_ERROR_NUMBER("Invalid section argument.", EINVAL); |
| 103 |
if (error) *error = EINVAL; |
| 104 |
return NULL; |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
err = col_get_collection_reference(ini_config->cfg, &subcollection, section); |
| 109 |
|
| 110 |
if (err && (subcollection == NULL)) { |
| 111 |
TRACE_ERROR_NUMBER("Failed to get section", err); |
| 112 |
if (error) *error = EINVAL; |
| 113 |
return NULL; |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
list = col_collection_to_list(subcollection, size, error); |
| 118 |
|
| 119 |
col_destroy_collection(subcollection); |
| 120 |
|
| 121 |
|
| 122 |
if ((list != NULL) && (list[0] != NULL)) { |
| 123 |
free(list[0]); |
| 124 |
while(list[i + 1] != NULL) { |
| 125 |
list[i] = list[i + 1]; |
| 126 |
i++; |
| 127 |
} |
| 128 |
list[i] = NULL; |
| 129 |
} |
| 130 |
|
| 131 |
if (size) (*size)--; |
| 132 |
|
| 133 |
TRACE_FLOW_STRING("ini_get_attribute_list returning", ((list == NULL) ? "NULL" : list[0])); |
| 134 |
return list; |
| 135 |
} |