diff options
author | Dmitri Pal <dpal@redhat.com> | 2012-09-21 19:33:55 -0400 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2012-10-17 14:02:51 +0200 |
commit | 634441aaab657d0850469714a7a1f3f5fff7d34b (patch) | |
tree | 2600e3ecae538b99c22658f30b680597ac606023 | |
parent | 2196f6eb06a6178eea688935fb315f87eb2d9b51 (diff) | |
download | ding-libs-634441aaab657d0850469714a7a1f3f5fff7d34b.tar.gz ding-libs-634441aaab657d0850469714a7a1f3f5fff7d34b.tar.xz ding-libs-634441aaab657d0850469714a7a1f3f5fff7d34b.zip |
Adding couple functions to value object
The patch adds function to get the length of
the concatenated value. It also adds a convenince
print function that is convenint in debugging
the values inside configuration object.
Patch also add checkes for input values
that can be passed by pointer.
-rw-r--r-- | ini/ini_valueobj.c | 71 | ||||
-rw-r--r-- | ini/ini_valueobj.h | 6 | ||||
-rw-r--r-- | ini/ini_valueobj_ut.c | 9 |
3 files changed, 85 insertions, 1 deletions
diff --git a/ini/ini_valueobj.c b/ini/ini_valueobj.c index 8c378ac..662719b 100644 --- a/ini/ini_valueobj.c +++ b/ini/ini_valueobj.c @@ -695,12 +695,42 @@ int value_get_concatenated(struct value_obj *vo, return EINVAL; } + if (!fullstr) + { + TRACE_ERROR_NUMBER("Invalid output value", EINVAL); + return EINVAL; + } + *fullstr = (const char *)simplebuffer_get_buf(vo->unfolded); TRACE_FLOW_EXIT(); return EOK; } +/* Get length of the concatenated value */ +int value_get_concatenated_len(struct value_obj *vo, + uint32_t *len) +{ + TRACE_FLOW_ENTRY(); + + if (!vo) { + TRACE_ERROR_NUMBER("Invalid object", EINVAL); + return EINVAL; + } + + if (!len) + { + TRACE_ERROR_NUMBER("Invalid output value", EINVAL); + return EINVAL; + } + + *len = simplebuffer_get_len(vo->unfolded); + + TRACE_FLOW_EXIT(); + return EOK; +} + + /* Get value's origin */ int value_get_origin(struct value_obj *vo, uint32_t *origin) { @@ -711,6 +741,12 @@ int value_get_origin(struct value_obj *vo, uint32_t *origin) return EINVAL; } + if (!origin) + { + TRACE_ERROR_NUMBER("Invalid output value", EINVAL); + return EINVAL; + } + *origin = vo->origin; TRACE_FLOW_EXIT(); @@ -727,6 +763,12 @@ int value_get_line(struct value_obj *vo, uint32_t *line) return EINVAL; } + if (!line) + { + TRACE_ERROR_NUMBER("Invalid output value", EINVAL); + return EINVAL; + } + *line = vo->line; TRACE_FLOW_EXIT(); @@ -1077,3 +1119,32 @@ extern void ref_array_debug(struct ref_array *ra, int num); TRACE_FLOW_EXIT(); return error; } + +/* Print value */ +void value_print(const char *key, struct value_obj *vo) +{ + + int error = EOK; + struct simplebuffer *sbobj = NULL; + + TRACE_FLOW_ENTRY(); + + error = simplebuffer_alloc(&sbobj); + if (error) { + printf("Failed to allocate dynamic string %d.\n", error); + return; + } + + /* Serialize */ + error = value_serialize(vo, key, sbobj); + if (error) { + printf("Failed to serialize a value object %d.\n", error); + simplebuffer_free(sbobj); + return; + } + + printf("%s", simplebuffer_get_buf(sbobj)); + simplebuffer_free(sbobj); + + TRACE_FLOW_EXIT(); +} diff --git a/ini/ini_valueobj.h b/ini/ini_valueobj.h index 3267bcc..cbecc75 100644 --- a/ini/ini_valueobj.h +++ b/ini/ini_valueobj.h @@ -98,6 +98,10 @@ void value_destroy(struct value_obj *vo); int value_get_concatenated(struct value_obj *vo, const char **fullstr); +/* Get length of the concatenated value */ +int value_get_concatenated_len(struct value_obj *vo, + uint32_t *len); + /* Get value's origin */ int value_get_origin(struct value_obj *vo, uint32_t *origin); @@ -133,5 +137,7 @@ int value_serialize(struct value_obj *vo, const char *key, struct simplebuffer *sbobj); +/* Print value */ +void value_print(const char *key, struct value_obj *vo); #endif diff --git a/ini/ini_valueobj_ut.c b/ini/ini_valueobj_ut.c index 0e7959f..e4fc6b4 100644 --- a/ini/ini_valueobj_ut.c +++ b/ini/ini_valueobj_ut.c @@ -141,6 +141,8 @@ int other_create_test(FILE *ff, struct value_obj **vo) int i; uint32_t origin = 0; uint32_t line = 0; + uint32_t len = 0; + uint32_t expected_len = 0; TRACE_FLOW_ENTRY(); @@ -230,7 +232,12 @@ int other_create_test(FILE *ff, struct value_obj **vo) return error; } - if (strncmp(fullstr, expected, strlen(expected) + 1) != 0) { + /* Get length of the concatenated value */ + value_get_concatenated_len(new_vo, &len); + expected_len = strlen(expected); + + if ((len != expected_len) || + (strncmp(fullstr, expected, expected_len + 1) != 0)) { printf("The expected value is different.\n%s\n", fullstr); value_destroy(new_vo); return EINVAL; |