summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHwankyu Jhun <h.jhun@samsung.com>2016-01-08 14:42:39 +0900
committerHwankyu Jhun <h.jhun@samsung.com>2016-01-08 15:52:52 +0900
commit3be3a1bb488fb81fa73d4e11bbc23f8edf632733 (patch)
tree268f5a1c1c7502bf64f0238b7f92ecb34ccaf3e2
parent7d650ad3ab1c8707dd3acbf4f271505f84d1336c (diff)
downloadbundle-3be3a1bb488fb81fa73d4e11bbc23f8edf632733.tar.gz
bundle-3be3a1bb488fb81fa73d4e11bbc23f8edf632733.tar.bz2
bundle-3be3a1bb488fb81fa73d4e11bbc23f8edf632733.zip
Change-Id: I8b8c5b6041d924df5ee59c6fc7b23af13381c714 Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
-rwxr-xr-xinclude/SLP_bundle_PG.h9
-rwxr-xr-xinclude/bundle.h59
-rwxr-xr-xinclude/bundle_internal.h49
-rwxr-xr-xinclude/bundle_log.h38
-rwxr-xr-xinclude/keyval.h38
-rwxr-xr-xinclude/keyval_array.h39
-rwxr-xr-xinclude/keyval_type.h15
-rw-r--r--src/bundle.c515
-rw-r--r--src/bundle_json.c16
-rwxr-xr-xsrc/keyval.c112
-rwxr-xr-xsrc/keyval_array.c155
-rwxr-xr-xsrc/keyval_type.c26
12 files changed, 506 insertions, 565 deletions
diff --git a/include/SLP_bundle_PG.h b/include/SLP_bundle_PG.h
index 65993de..5106081 100755
--- a/include/SLP_bundle_PG.h
+++ b/include/SLP_bundle_PG.h
@@ -1,10 +1,5 @@
/*
- * bundle
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
- * Jaeho Lee <jaeho81.lee@samsung.com>
+ * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,10 +12,8 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
*/
-
/**
*
* @ingroup SLP_PG
diff --git a/include/bundle.h b/include/bundle.h
index 38dc6bb..412d337 100755
--- a/include/bundle.h
+++ b/include/bundle.h
@@ -1,10 +1,5 @@
/*
- * bundle
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
- * Jaeho Lee <jaeho81.lee@samsung.com>
+ * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,10 +12,8 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
*/
-
#ifndef __BUNDLE_H__
#define __BUNDLE_H__
@@ -42,7 +35,7 @@
extern "C" {
# endif
-#define API __attribute__((visibility("default")))
+#define API __attribute__((visibility("default")))
#define likely(x) __builtin_expect(x,1)
#define unlikely(x) __builtin_expect(x,0)
@@ -53,11 +46,11 @@ extern "C" {
*/
typedef enum
{
- BUNDLE_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
- BUNDLE_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
- BUNDLE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
- BUNDLE_ERROR_KEY_NOT_AVAILABLE = TIZEN_ERROR_KEY_NOT_AVAILABLE, /**< Required key not available */
- BUNDLE_ERROR_KEY_EXISTS = TIZEN_ERROR_BUNDLE | 0x01 /**< Key exists */
+ BUNDLE_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
+ BUNDLE_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
+ BUNDLE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
+ BUNDLE_ERROR_KEY_NOT_AVAILABLE = TIZEN_ERROR_KEY_NOT_AVAILABLE, /**< Required key not available */
+ BUNDLE_ERROR_KEY_EXISTS = TIZEN_ERROR_BUNDLE | 0x01 /**< Key exists */
} bundle_error_e;
/**
@@ -74,15 +67,14 @@ typedef struct _bundle_t bundle;
*/
typedef unsigned char bundle_raw;
-
/**
* @brief Enumeration for key-value pair types.
* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
*/
enum bundle_type_property {
- BUNDLE_TYPE_ARRAY = 0x0100, /**< Array type */
- BUNDLE_TYPE_PRIMITIVE = 0x0200, /**< Primitive type */
- BUNDLE_TYPE_MEASURABLE = 0x0400 /**< Measurable type */
+ BUNDLE_TYPE_ARRAY = 0x0100, /**< Array type */
+ BUNDLE_TYPE_PRIMITIVE = 0x0200, /**< Primitive type */
+ BUNDLE_TYPE_MEASURABLE = 0x0400 /**< Measurable type */
};
/**
@@ -90,12 +82,12 @@ enum bundle_type_property {
* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
*/
enum bundle_type {
- BUNDLE_TYPE_NONE = -1, /**< None */
- BUNDLE_TYPE_ANY = 0, /**< Any type */
- BUNDLE_TYPE_STR = 1 | BUNDLE_TYPE_MEASURABLE, /**< String type (Default) */
- BUNDLE_TYPE_STR_ARRAY = BUNDLE_TYPE_STR | BUNDLE_TYPE_ARRAY | BUNDLE_TYPE_MEASURABLE, /**< String array type */
- BUNDLE_TYPE_BYTE = 2, /**< Byte type */
- BUNDLE_TYPE_BYTE_ARRAY = BUNDLE_TYPE_BYTE | BUNDLE_TYPE_ARRAY /**< Byte array type */
+ BUNDLE_TYPE_NONE = -1, /**< None */
+ BUNDLE_TYPE_ANY = 0, /**< Any type */
+ BUNDLE_TYPE_STR = 1 | BUNDLE_TYPE_MEASURABLE, /**< String type (Default) */
+ BUNDLE_TYPE_STR_ARRAY = BUNDLE_TYPE_STR | BUNDLE_TYPE_ARRAY | BUNDLE_TYPE_MEASURABLE, /**< String array type */
+ BUNDLE_TYPE_BYTE = 2, /**< Byte type */
+ BUNDLE_TYPE_BYTE_ARRAY = BUNDLE_TYPE_BYTE | BUNDLE_TYPE_ARRAY /**< Byte array type */
};
/**
@@ -105,7 +97,6 @@ enum bundle_type {
*/
typedef struct keyval_t bundle_keyval_t;
-
/**
* @brief Called for every key-value pair.
* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
@@ -134,7 +125,7 @@ typedef void (*bundle_iterator_t) (
bundle_free(b); // free bundle
@endcode
*/
-API bundle* bundle_create(void);
+API bundle *bundle_create(void);
/**
* @brief Frees the given bundle object with key-value pairs in it.
@@ -151,7 +142,7 @@ API bundle* bundle_create(void);
bundle_free(b); // free bundle
@endcode
*/
-API int bundle_free(bundle *b);
+API int bundle_free(bundle *b);
/**
* @brief Adds a strings array type key-value pair into a given bundle.
@@ -197,7 +188,7 @@ API int bundle_add_str_array(bundle *b, const char *key, const char **str_array,
bundle_free(b);
@endcode
*/
-API int bundle_del(bundle *b, const char* key);
+API int bundle_del(bundle *b, const char *key);
/**
* @brief Gets a string array from a given key.
@@ -229,7 +220,7 @@ API int bundle_del(bundle *b, const char* key);
bundle_free(b);
@endcode
*/
-API const char** bundle_get_str_array(bundle *b, const char *key,int *len);
+API const char **bundle_get_str_array(bundle *b, const char *key, int *len);
/**
* @brief Gets the number of bundle items.
@@ -248,7 +239,7 @@ API const char** bundle_get_str_array(bundle *b, const char *key,int *len);
bundle_free(b);
@endcode
*/
-API int bundle_get_count(bundle *b);
+API int bundle_get_count(bundle *b);
/**
* @brief Gets the type of a value with a given key.
@@ -287,7 +278,7 @@ API int bundle_get_type(bundle *b, const char *key);
bundle_free(b_dup);
@endcode
*/
-API bundle * bundle_dup(bundle *b_from);
+API bundle *bundle_dup(bundle *b_from);
/**
* @brief Iterates a callback function for each key-value pair in a given bundle.
@@ -337,7 +328,7 @@ API bundle * bundle_dup(bundle *b_from);
}
@endcode
*/
-API void bundle_foreach(bundle *b, bundle_iterator_t iter, void *user_data);
+API void bundle_foreach(bundle *b, bundle_iterator_t iter, void *user_data);
/**
* @brief Gets the type of a key-value pair.
@@ -422,7 +413,7 @@ API int bundle_keyval_get_array_val(bundle_keyval_t *kv, void ***array_val, unsi
bundle_free(b);
@endcode
*/
-API int bundle_encode(bundle *b, bundle_raw **r, int *len);
+API int bundle_encode(bundle *b, bundle_raw **r, int *len);
/**
* @brief Deserializes bundle_raw and gets the bundle object.
@@ -452,7 +443,7 @@ API int bundle_encode(bundle *b, bundle_raw **r, int *len);
bundle_free(b_dup);
@endcode
*/
-API bundle * bundle_decode(const bundle_raw *r, const int len);
+API bundle *bundle_decode(const bundle_raw *r, const int len);
/**
* @brief Adds a string type key-value pair into a bundle.
diff --git a/include/bundle_internal.h b/include/bundle_internal.h
index 975c54b..633c256 100755
--- a/include/bundle_internal.h
+++ b/include/bundle_internal.h
@@ -1,10 +1,5 @@
/*
- * bundle
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
- * Jaeho Lee <jaeho81.lee@samsung.com>
+ * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,10 +12,8 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
*/
-
#ifndef __BUNDLE_INTERNAL_H__
#define __BUNDLE_INTERNAL_H__
@@ -62,14 +55,14 @@ typedef void (*bundle_iterate_cb_t) (const char *key, const char *val, void *dat
* @pre @a b must be a valid bundle object.
* @see bundle_add_str()
@code
- #include <bundle.h>
+ #include <bundle_internal.h>
bundle *b = bundle_create(); // Create new bundle object
bundle_add(b, "foo_key", "bar_val"); // add a key-val pair
bundle_free(b);
@endcode
*/
-API int bundle_add(bundle *b, const char *key, const char *val);
+API int bundle_add(bundle *b, const char *key, const char *val);
/**
* @brief Gets a value with a given key.
@@ -86,7 +79,7 @@ API int bundle_add(bundle *b, const char *key, const char *val);
* @pre @a b must be a valid bundle object.
* @see bundle_get_str()
@code
- #include <bundle.h>
+ #include <bundle_internal.h>
bundle *b = bundle_create(); // Create new bundle object
bundle_add_str(b, "foo", "bar"); //add a key-val pair
char *val = bundle_get_val(b, "foo_key"); // val = "bar_val"
@@ -95,7 +88,7 @@ API int bundle_add(bundle *b, const char *key, const char *val);
val = NULL;
@endcode
*/
-API const char* bundle_get_val(bundle *b, const char *key);
+API const char *bundle_get_val(bundle *b, const char *key);
/**
* @brief Iterates a callback function for each key-value pairs in a given bundle.
@@ -111,7 +104,7 @@ API const char* bundle_get_val(bundle *b, const char *key);
* @pre @a b must be a valid bundle object.
@code
#include <stdio.h>
- #include <bundle.h>
+ #include <bundle_internal.h>
void sample_cb(const char *k, const char *v, void *data) {
printf("%s -> %s\n", k, v);
}
@@ -126,7 +119,7 @@ API const char* bundle_get_val(bundle *b, const char *key);
}
@endcode
*/
-API void bundle_iterate(bundle *b, bundle_iterate_cb_t callback, void *cb_data);
+API void bundle_iterate(bundle *b, bundle_iterate_cb_t callback, void *cb_data);
/**
* @brief Determines whether the type of a key-value pair is measurable.
@@ -153,7 +146,7 @@ API int bundle_keyval_type_is_measurable(bundle_keyval_t *kv);
* @pre @a r is a valid rawdata generated by bundle_encode().
* @see bundle_encode()
*/
-API int bundle_free_encoded_rawdata(bundle_raw **r);
+API int bundle_free_encoded_rawdata(bundle_raw **r);
/**
* @brief Encodes a bundle to the bundle_raw format.
@@ -168,7 +161,7 @@ API int bundle_free_encoded_rawdata(bundle_raw **r);
* @retval BUNDLE_ERROR_OUT_OF_MEMORY Out of memory
* @pre @a b must be a valid bundle object.
@code
- #include <bundle.h>
+ #include <bundle_internal.h>
bundle *b = bundle_create(); // Create new bundle object
bundle_add_str(b, "foo_key", "bar_val"); // add a key-val pair
bundle_raw *r;
@@ -178,7 +171,7 @@ API int bundle_free_encoded_rawdata(bundle_raw **r);
bundle_free(b);
@endcode
*/
-API int bundle_encode_raw(bundle *b, bundle_raw **r, int *len);
+API int bundle_encode_raw(bundle *b, bundle_raw **r, int *len);
/**
* @brief Deserializes bundle_raw and gets a bundle object.
@@ -192,7 +185,7 @@ API int bundle_encode_raw(bundle *b, bundle_raw **r, int *len);
* @exception BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
* @pre @a b must be a valid bundle object.
@code
- #include <bundle.h>
+ #include <bundle_internal.h>
bundle *b = bundle_create(); // Create new bundle object
bundle_add_str(b, "foo_key", "bar_val"); // add a key-val pair
@@ -208,7 +201,7 @@ API int bundle_encode_raw(bundle *b, bundle_raw **r, int *len);
bundle_free(b_dup);
@endcode
*/
-API bundle * bundle_decode_raw(const bundle_raw *r, const int len);
+API bundle *bundle_decode_raw(const bundle_raw *r, const int len);
/**
* @brief Exports bundle to @a argv.
@@ -228,7 +221,7 @@ API bundle * bundle_decode_raw(const bundle_raw *r, const int len);
* Each item of @a argv points to the string in the bundle object @a b. If @a b is freed, @a argv will have garbage pointers. DO NOT FREE @a b BEFORE ACCESSING @a argv!!
* @see bundle_import_from_argv()
@code
- #include <bundle.h>
+ #include <bundle_internal.h>
bundle *b = bundle_create(); // Create new bundle object
bundle_add_str(b, "foo_key", "bar_val"); // add a key-val pair
@@ -246,7 +239,7 @@ API bundle * bundle_decode_raw(const bundle_raw *r, const int len);
bundle_free(b);
@endcode
*/
-API int bundle_export_to_argv(bundle *b, char ***argv);
+API int bundle_export_to_argv(bundle *b, char ***argv);
/**
* @brief Frees the exported @a argv.
@@ -276,7 +269,7 @@ API int bundle_export_to_argv(bundle *b, char ***argv);
bundle_free(b);
@endcode
*/
-API int bundle_free_exported_argv(int argc, char ***argv);
+API int bundle_free_exported_argv(int argc, char ***argv);
/**
* @brief Imports a bundle from @a argv.
@@ -293,7 +286,7 @@ API int bundle_free_exported_argv(int argc, char ***argv);
* @post The returned bundle @a b must be freed.
* @see bundle_export_to_argv()
@code
- #include <bundle.h>
+ #include <bundle_internal.h>
int main(int argc, char **argv) {
bundle *b = bundle_import_from_argv(argc, argv); // import from argc+argv
@@ -304,7 +297,7 @@ API int bundle_free_exported_argv(int argc, char ***argv);
}
@endcode
*/
-API bundle * bundle_import_from_argv(int argc, char **argv);
+API bundle *bundle_import_from_argv(int argc, char **argv);
/**
* @brief Sets a value of string array elements.
@@ -320,7 +313,7 @@ API bundle * bundle_import_from_argv(int argc, char **argv);
* @see bundle_add_str_array()
* @see bundle_get_str_array()
@code
- #include <bundle.h>
+ #include <bundle_internal.h>
bundle *b = bundle_create();
bundle_add_str_array(b, "foo", NULL, 3); // add a key-val pair
bundle_set_str_array_element(b, "foo", 0, "aaa");
@@ -354,7 +347,7 @@ API int bundle_set_str_array_element(bundle *b, const char *key, const unsigned
* @see bundle_get_byte_array()
* @see bundle_set_byte_array_element()
@code
- #include <bundle.h>
+ #include <bundle_internal.h>
bundle *b = bundle_create();
bundle_add_byte_array(b, "foo", NULL, 3); // add a byte-array with length 3
@@ -383,7 +376,7 @@ API int bundle_add_byte_array(bundle *b, const char *key, void **byte_array, con
* @see bundle_add_byte_array()
* @see bundle_get_byte_array()
@code
- #include <bundle.h>
+ #include <bundle_internal.h>
bundle *b = bundle_create();
bundle_add_byte_array(b, "foo", NULL, 3); // add a key-val pair
@@ -419,7 +412,7 @@ API int bundle_set_byte_array_element(bundle *b, const char *key, const unsigned
* @see bundle_add_byte_array()
* @see bundle_set_byte_array_element()
@code
- #include <bundle.h>
+ #include <bundle_internal.h>
bundle *b = bundle_create();
bundle_add_byte_array(b, "foo", NULL, 3);
bundle_set_byte_array_element(b, "foo", 0, "aaa\0", 4);
diff --git a/include/bundle_log.h b/include/bundle_log.h
index 192c283..b3bda77 100755
--- a/include/bundle_log.h
+++ b/include/bundle_log.h
@@ -1,10 +1,5 @@
/*
- * bundle
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
- * Jaeho Lee <jaeho81.lee@samsung.com>
+ * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,11 +12,13 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
*/
+#ifndef __BUNDLE_LOG_H__
+#define __BUNDLE_LOG_H__
#include <dlog/dlog.h>
+
#ifdef LOG_TAG
#undef LOG_TAG
#endif
@@ -29,14 +26,27 @@
#define LOG_TAG "BUNDLE"
#ifdef _DEBUG_MODE_
-#define BUNDLE_LOG_PRINT(FMT, ARG...) do { printf("%5d", getpid()); printf
- ("%s() : "FMT"\n", __FUNCTION__, ##ARG); } while (false)
-#define BUNDLE_EXCEPTION_PRINT(FMT, ARG...) do { printf("%5d", getpid());
- printf("%s() : "FMT"\n", __FUNCTION__, ##ARG); } while (false)
-#define BUNDLE_ASSERT_PRINT(FMT, ARG...) do { printf("%5d", getpid()); printf
- ("%s() : "FMT"\n", __FUNCTION__, ##ARG); } while (false)
+#define BUNDLE_LOG_PRINT(FMT, ARG...) \
+ do { \
+ printf("%5d", getpid()); \
+ printf("%s() : "FMT"\n", __FUNCTION__, ##ARG); \
+ } while (0)
+
+#define BUNDLE_EXCEPTION_PRINT(FMT, ARG...) \
+ do { \
+ printf("%5d", getpid()); \
+ printf("%s() : "FMT"\n", __FUNCTION__, ##ARG); \
+ } while (0)
+
+#define BUNDLE_ASSERT_PRINT(FMT, ARG...) \
+ do { \
+ printf("%5d", getpid()); \
+ printf("%s() : "FMT"\n", __FUNCTION__, ##ARG); \
+ } while (0)
#else
#define BUNDLE_LOG_PRINT(FMT, ARG...) SLOGD(FMT, ##ARG);
#define BUNDLE_EXCEPTION_PRINT(FMT, ARG...) SLOGW(FMT, ##ARG);
#define BUNDLE_ASSERT_PRINT(FMT, ARG...) SLOGE(FMT, ##ARG);
-#endif
+#endif /* _DEBUG_MODE_ */
+
+#endif /* __BUNDLE_LOG_H__ */
diff --git a/include/keyval.h b/include/keyval.h
index ce1e7f8..459c4ac 100755
--- a/include/keyval.h
+++ b/include/keyval.h
@@ -1,10 +1,5 @@
/*
- * bundle
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
- * Jaeho Lee <jaeho81.lee@samsung.com>
+ * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,10 +12,8 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
*/
-
#ifndef __KEYVAL_H__
#define __KEYVAL_H__
@@ -32,21 +25,22 @@
#include <stddef.h>
-// ADT: object
+/* ADT: object */
typedef struct keyval_t keyval_t;
-// Object methods
+/* Object methods */
typedef struct keyval_method_collection_t keyval_method_collection_t;
typedef void (*keyval_method_free_t)(keyval_t *kv, int do_free_object);
typedef int (*keyval_method_compare_t) (keyval_t *kv1, keyval_t *kv2);
typedef size_t (*keyval_method_get_encoded_size_t)(keyval_t *kv);
-typedef size_t (*keyval_method_encode_t)(keyval_t *, unsigned char **byte, size_t *byte_len);
+typedef size_t (*keyval_method_encode_t)(
+ keyval_t *,
+ unsigned char **byte,
+ size_t *byte_len);
typedef size_t (*keyval_method_decode_t)(unsigned char *byte, keyval_t **kv);
-
-struct keyval_method_collection_t
-{
+struct keyval_method_collection_t {
keyval_method_free_t free;
keyval_method_compare_t compare;
keyval_method_get_encoded_size_t get_encoded_size;
@@ -54,20 +48,17 @@ struct keyval_method_collection_t
keyval_method_decode_t decode;
};
-struct keyval_t
-{
+struct keyval_t {
int type;
- char *key; // To be freed.
- void *val; // To be freed.
- size_t size; // Size of a single value.
+ char *key; /* To be freed. */
+ void *val; /* To be freed. */
+ size_t size; /* Size of a single value. */
struct keyval_t *next;
-
keyval_method_collection_t *method;
-
};
-
-keyval_t * keyval_new(keyval_t *kv, const char *key, const int type, const void *val, const size_t size);
+keyval_t * keyval_new(keyval_t *kv, const char *key,
+ const int type, const void *val, const size_t size);
void keyval_free(keyval_t *kv, int do_free_object);
int keyval_compare(keyval_t *kv1, keyval_t *kv2);
size_t keyval_get_encoded_size(keyval_t *kv);
@@ -77,4 +68,3 @@ int keyval_get_data(keyval_t *kv, int *type, void **val, size_t *size);
int keyval_get_type_from_encoded_byte(unsigned char *byte);
#endif /* __KEYVAL_H__ */
-
diff --git a/include/keyval_array.h b/include/keyval_array.h
index 66cf31d..47b38a9 100755
--- a/include/keyval_array.h
+++ b/include/keyval_array.h
@@ -1,10 +1,5 @@
/*
- * bundle
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
- * Jaeho Lee <jaeho81.lee@samsung.com>
+ * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,9 +12,10 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
*/
+#ifndef __KEYVAL_ARRAY_H__
+#define __kEYVAL_ARRAY_H__
/**
* keyval_array.h
@@ -29,25 +25,26 @@
#include "keyval.h"
-
-typedef struct keyval_array_t
-{
- struct keyval_t kv; // Inherits keyval_t
-
- unsigned int len; // length of array_val
- size_t *array_element_size; // Array of size of each element
- void **array_val; // Array
-
+typedef struct keyval_array_t {
+ struct keyval_t kv; /* Inherits keyval_t */
+ unsigned int len; /* length of array_val */
+ size_t *array_element_size; /* Array of size of each element */
+ void **array_val; /* Array */
} keyval_array_t;
-
-keyval_array_t *keyval_array_new(keyval_array_t *kva, const char *key, const int type, const void **array_val, const unsigned int len);
+keyval_array_t *keyval_array_new(keyval_array_t *kva, const char *key,
+ const int type, const void **array_val, const unsigned int len);
void keyval_array_free(keyval_array_t *kva, int do_free_object);
int keyval_array_compare(keyval_array_t *kva1, keyval_array_t *kva2);
size_t keyval_array_get_encoded_size(keyval_array_t *kva);
size_t keyval_array_encode(keyval_array_t *kva, void **byte, size_t *byte_len);
size_t keyval_array_decode(void *byte, keyval_array_t **kva);
-int keyval_array_copy_array(keyval_array_t *kva, void **array_val, unsigned int array_len, size_t (*measure_val_len)(void * val));
-int keyval_array_get_data(keyval_array_t *kva, int *type,void ***array_val, unsigned int *len, size_t **array_element_size);
-int keyval_array_set_element(keyval_array_t *kva, int idx, void *val, size_t size);
+int keyval_array_copy_array(keyval_array_t *kva, void **array_val,
+ unsigned int array_len, size_t (*measure_val_len)(void * val));
+int keyval_array_get_data(keyval_array_t *kva, int *type, void ***array_val,
+ unsigned int *len, size_t **array_element_size);
+int keyval_array_set_element(keyval_array_t *kva,
+ int idx, void *val, size_t size);
int keyval_array_is_idx_valid(keyval_array_t *kva, int idx);
+
+#endif /* __KEYVAL_ARRAY_H__ */
diff --git a/include/keyval_type.h b/include/keyval_type.h
index 9561c5a..3d9ff15 100755
--- a/include/keyval_type.h
+++ b/include/keyval_type.h
@@ -1,10 +1,5 @@
/*
- * bundle
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
- * Jaeho Lee <jaeho81.lee@samsung.com>
+ * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,10 +12,8 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
*/
-
#ifndef __KEYVAL_TYPE_H__
#define __KEYVAL_TYPE_H__
@@ -30,11 +23,12 @@
* Definitions & short funcs for keyval type
*/
-#include "bundle.h"
#include <stddef.h>
#include <string.h>
-// measure_size function type
+#include "bundle.h"
+
+/* measure_size function type */
typedef size_t (*keyval_type_measure_size_func_t) (void *val);
void _type_init_measure_size_func(void);
@@ -42,7 +36,6 @@ int keyval_type_is_array(int type);
int keyval_type_is_measurable(int type);
keyval_type_measure_size_func_t keyval_type_get_measure_size_func(int type);
-
/* Measure functions for each type */
size_t keyval_type_measure_size_str(void *val);
void keyval_type_init(void);
diff --git a/src/bundle.c b/src/bundle.c
index 0da2fea..d5fbba7 100644
--- a/src/bundle.c
+++ b/src/bundle.c
@@ -1,10 +1,5 @@
/*
- * bundle
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
- * Jaeho Lee <jaeho81.lee@samsung.com>
+ * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,53 +12,51 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
*/
-
-
/**
* bundle.c
*/
+#include <stdlib.h>
+#include <string.h>
+#include <glib.h>
+
#include "bundle.h"
#include "bundle_internal.h"
#include "keyval.h"
#include "keyval_array.h"
#include "keyval_type.h"
#include "bundle_log.h"
-#include <glib.h>
-
-#include <stdlib.h> /* calloc, free */
-#include <string.h> /* strdup */
#define CHECKSUM_LENGTH 32
#define TAG_IMPORT_EXPORT_CHECK "`zaybxcwdveuftgsh`"
+
/* ADT */
struct _bundle_t {
keyval_t *kv_head;
};
-
/**
* Find a kv from bundle
*/
-static keyval_t *
-_bundle_find_kv(bundle *b, const char *key)
+static keyval_t *_bundle_find_kv(bundle *b, const char *key)
{
keyval_t *kv;
- if (NULL == b) {
+
+ if (b == NULL) {
set_last_result(BUNDLE_ERROR_INVALID_PARAMETER);
return NULL;
}
- if (NULL == key) {
+
+ if (key == NULL) {
set_last_result(BUNDLE_ERROR_INVALID_PARAMETER);
return NULL;
}
kv = b->kv_head;
while (kv != NULL) {
- if (0 == strcmp(key, kv->key)) {
+ if (strcmp(key, kv->key) == 0) {
set_last_result(BUNDLE_ERROR_NONE);
return kv;
}
@@ -77,71 +70,75 @@ _bundle_find_kv(bundle *b, const char *key)
/**
* Append kv into bundle
*/
-static int
-_bundle_append_kv(bundle *b, keyval_t *new_kv)
+static int _bundle_append_kv(bundle *b, keyval_t *new_kv)
{
keyval_t *kv;
- if (NULL == b->kv_head)
+ if (b->kv_head == NULL) {
b->kv_head = new_kv;
- else {
+ } else {
kv = b->kv_head;
- while (NULL != kv->next)
+ while (kv->next)
kv = kv->next;
kv->next = new_kv;
}
+
return BUNDLE_ERROR_NONE;
}
-static int
-_bundle_add_kv(bundle *b, const char *key, const void *val,
+static int _bundle_add_kv(bundle *b, const char *key, const void *val,
const size_t size, const int type, const unsigned int len)
{
+ keyval_t *kv;
+ keyval_t *new_kv;
+ keyval_array_t *kva;
+
/* basic value check */
- if (NULL == b)
+ if (b == NULL)
return BUNDLE_ERROR_INVALID_PARAMETER;
- if (NULL == key)
+ if (key == NULL)
return BUNDLE_ERROR_INVALID_PARAMETER;
- if (0 == strlen(key))
+ if (strlen(key) == 0)
return BUNDLE_ERROR_INVALID_PARAMETER;
- keyval_t *kv = _bundle_find_kv(b, key);
- if (kv) { /* Key already exists */
+ kv = _bundle_find_kv(b, key);
+ if (kv) /* Key already exists */
return BUNDLE_ERROR_KEY_EXISTS;
- }
- keyval_t *new_kv = NULL;
if (keyval_type_is_array(type)) {
/* array type */
- keyval_array_t *kva = keyval_array_new(NULL, key, type,
+ kva = keyval_array_new(NULL, key, type,
(const void **) val, len);
new_kv = (keyval_t *)kva;
} else {
/* normal type */
new_kv = keyval_new(NULL, key, type, val, size);
}
+
if (!new_kv)
return BUNDLE_ERROR_OUT_OF_MEMORY;
_bundle_append_kv(b, new_kv);
return BUNDLE_ERROR_NONE;
-
}
-static int
-_bundle_get_val(bundle *b, const char *key, const int type, void **val,
- size_t *size, unsigned int *len, size_t **array_element_size)
+static int _bundle_get_val(bundle *b, const char *key, const int type,
+ void **val, size_t *size, unsigned int *len,
+ size_t **array_element_size)
{
- keyval_t *kv = _bundle_find_kv(b, key);
- if (!kv) /* Key doesn't exist */
+ keyval_t *kv;
+ keyval_array_t *kva;
+
+ kv = _bundle_find_kv(b, key);
+ if (!kv) /* Key doesn't exist */
return get_last_result();
if (BUNDLE_TYPE_ANY != type && type != kv->type)
return BUNDLE_ERROR_INVALID_PARAMETER;
if (keyval_type_is_array(type)) {
- keyval_array_t *kva = (keyval_array_t *)kv;
+ kva = (keyval_array_t *)kv;
keyval_array_get_data(kva, NULL, (void ***)val,
len, array_element_size);
} else {
@@ -151,11 +148,11 @@ _bundle_get_val(bundle *b, const char *key, const int type, void **val,
return BUNDLE_ERROR_NONE;
}
-/** global initialization
- * Run only once.
+/**
+ * global initialization
+ * Run only once.
*/
-static void
-_bundle_global_init(void)
+static void _bundle_global_init(void)
{
static int _is_done;
@@ -169,42 +166,41 @@ _bundle_global_init(void)
return;
}
-
/* APIs */
-bundle *
-bundle_create(void)
+bundle *bundle_create(void)
{
bundle *b = NULL;
_bundle_global_init();
b = calloc(1, sizeof(bundle)); /* fill mem with NULL */
- if (NULL == b) {
- BUNDLE_EXCEPTION_PRINT("Unable to allocate memory for bundle\n");
+ if (b == NULL) {
+ BUNDLE_EXCEPTION_PRINT(
+ "Unable to allocate memory for bundle\n");
set_last_result(BUNDLE_ERROR_OUT_OF_MEMORY);
- goto EXCEPTION;
+ goto exception;
}
set_last_result(BUNDLE_ERROR_NONE);
return b;
-EXCEPTION:
+exception:
return NULL;
}
-int
-bundle_free(bundle *b)
+int bundle_free(bundle *b)
{
- keyval_t *kv, *tmp_kv;
+ keyval_t *kv;
+ keyval_t *tmp_kv;
- if (NULL == b) {
+ if (b == NULL) {
BUNDLE_EXCEPTION_PRINT("Bundle is already freed\n");
return BUNDLE_ERROR_INVALID_PARAMETER;
}
/* Free keyval list */
kv = b->kv_head;
- while (kv != NULL) {
+ while (kv) {
tmp_kv = kv;
kv = kv->next;
tmp_kv->method->free(tmp_kv, 1);
@@ -216,133 +212,129 @@ bundle_free(bundle *b)
return BUNDLE_ERROR_NONE;
}
-int
-bundle_add_str(bundle *b, const char *key, const char *str)
+int bundle_add_str(bundle *b, const char *key, const char *str)
{
if (!str)
return BUNDLE_ERROR_INVALID_PARAMETER;
- return _bundle_add_kv(b, key, str, strlen(str)+1, BUNDLE_TYPE_STR, 1);
+ return _bundle_add_kv(b, key, str, strlen(str) + 1, BUNDLE_TYPE_STR, 1);
}
-int
-bundle_get_str(bundle *b, const char *key, char **str)
+int bundle_get_str(bundle *b, const char *key, char **str)
{
- return _bundle_get_val(b, key, BUNDLE_TYPE_STR, (void **) str,
+ return _bundle_get_val(b, key, BUNDLE_TYPE_STR, (void **)str,
NULL, NULL, NULL);
}
-int
-bundle_add(bundle *b, const char *key, const char *val)
+int bundle_add(bundle *b, const char *key, const char *val)
{
return bundle_add_str(b, key, val);
}
-int
-bundle_del(bundle *b, const char *key)
+int bundle_del(bundle *b, const char *key)
{
- keyval_t *kv = NULL, *prev_kv = NULL;
+ keyval_t *kv;
+ keyval_t *prev_kv = NULL;
/* basic value check */
- if (NULL == b)
+ if (b == NULL)
return BUNDLE_ERROR_INVALID_PARAMETER;
- if (NULL == key)
+ if (key == NULL)
return BUNDLE_ERROR_INVALID_PARAMETER;
- if (0 == strlen(key))
+ if (strlen(key) == 0)
return BUNDLE_ERROR_INVALID_PARAMETER;
kv = b->kv_head;
- while (kv != NULL) {
- if (0 == strcmp(key, kv->key))
+ while (kv) {
+ if (strcmp(key, kv->key) == 0)
break;
prev_kv = kv;
kv = kv->next;
}
- if (NULL == kv)
+
+ if (kv == NULL) {
return BUNDLE_ERROR_KEY_NOT_AVAILABLE;
- else {
- if (NULL != prev_kv)
+ } else {
+ if (prev_kv)
prev_kv->next = kv->next;
if (kv == b->kv_head)
b->kv_head = kv->next;
kv->method->free(kv, 1);
}
- return BUNDLE_ERROR_NONE;
+ return BUNDLE_ERROR_NONE;
}
-const char *
-bundle_get_val(bundle *b, const char *key)
+const char *bundle_get_val(bundle *b, const char *key)
{
char *val = NULL;
- int ret = 0;
+ int ret = BUNDLE_ERROR_NONE;
ret = bundle_get_str(b, key, &val);
set_last_result(ret);
return val;
-
}
/**
* @brief used by bundle_get_count() API, to count number of items in a bundle
*/
-static void
-_bundle_get_count_iter(const char *k, const int type,
+static void _bundle_get_count_iter(const char *k, const int type,
const bundle_keyval_t *kv, void *user_data)
{
int *count = (int *)user_data;
*count += 1;
}
-int
-bundle_get_count(bundle *b)
+int bundle_get_count(bundle *b)
{
int count = 0;
- if (NULL == b)
+
+ if (b == NULL)
return count;
bundle_foreach(b, _bundle_get_count_iter, &count);
return count;
}
-void
-bundle_iterate(bundle *b, bundle_iterate_cb_t callback, void *data)
+void bundle_iterate(bundle *b, bundle_iterate_cb_t callback, void *data)
{
keyval_t *kv;
- if (NULL == b || NULL == callback) {
+ if (b == NULL || callback == NULL) {
set_last_result(BUNDLE_ERROR_INVALID_PARAMETER);
return;
}
kv = b->kv_head;
- while (NULL != kv) {
+ while (kv) {
callback(kv->key, kv->val, data);
kv = kv->next;
}
+
set_last_result(BUNDLE_ERROR_NONE);
}
-void
-bundle_foreach(bundle *b, bundle_iterator_t iter, void *user_data)
+void bundle_foreach(bundle *b, bundle_iterator_t iter, void *user_data)
{
- if (NULL == b || NULL == iter) {
+ keyval_t *kv;
+
+ if (b == NULL || iter == NULL) {
set_last_result(BUNDLE_ERROR_INVALID_PARAMETER);
- return; /*TC_FIX if b=NULL- error handling */
+ return; /* TC_FIX if b = NULL- error handling */
}
- keyval_t *kv = b->kv_head;
- while (NULL != kv) {
+ kv = b->kv_head;
+ while (kv) {
iter(kv->key, kv->type, kv, user_data);
kv = kv->next;
}
+
set_last_result(BUNDLE_ERROR_NONE);
}
/* keyval functions */
-int
-bundle_keyval_get_type(bundle_keyval_t *kv)
+int bundle_keyval_get_type(bundle_keyval_t *kv)
{
- if (NULL == kv) {
+ if (kv == NULL) {
set_last_result(BUNDLE_ERROR_INVALID_PARAMETER);
return -1;
}
@@ -350,10 +342,9 @@ bundle_keyval_get_type(bundle_keyval_t *kv)
return kv->type;
}
-int
-bundle_keyval_type_is_array(bundle_keyval_t *kv)
+int bundle_keyval_type_is_array(bundle_keyval_t *kv)
{
- if (NULL == kv) {
+ if (kv == NULL) {
set_last_result(BUNDLE_ERROR_INVALID_PARAMETER);
return -1;
}
@@ -361,10 +352,9 @@ bundle_keyval_type_is_array(bundle_keyval_t *kv)
return keyval_type_is_array(kv->type);
}
-int
-bundle_keyval_type_is_measurable(bundle_keyval_t *kv)
+int bundle_keyval_type_is_measurable(bundle_keyval_t *kv)
{
- if (NULL == kv) {
+ if (kv == NULL) {
set_last_result(BUNDLE_ERROR_INVALID_PARAMETER);
return -1;
}
@@ -372,80 +362,71 @@ bundle_keyval_type_is_measurable(bundle_keyval_t *kv)
return keyval_type_is_measurable(kv->type);
}
-int
-bundle_keyval_get_basic_val(bundle_keyval_t *kv, void **val, size_t *size)
+int bundle_keyval_get_basic_val(bundle_keyval_t *kv, void **val, size_t *size)
{
return keyval_get_data(kv, NULL, val, size);
}
-int
-bundle_keyval_get_array_val(bundle_keyval_t *kv, void ***array_val,
+int bundle_keyval_get_array_val(bundle_keyval_t *kv, void ***array_val,
unsigned int *array_len, size_t **array_item_size)
{
return keyval_array_get_data((keyval_array_t *)kv, NULL,
array_val, array_len, array_item_size);
}
-
-/*static void
-_iter_do_bundle_dup(const char *key, const void *val, const int type, const size_t size, const unsigned int len, void *user_data)
+bundle *bundle_dup(bundle *b_from)
{
- //int r;
- bundle *b_to = (bundle *)user_data;
-
- _bundle_add_kv(b_to, key, val, size, type, len);
-
-}
-*/
-bundle *
-bundle_dup(bundle *b_from)
-{
- bundle *b_to = NULL;
+ bundle *b_to;
+ keyval_t *kv_from;
+ keyval_t *kv_to;
+ keyval_array_t *kva_from;
int i;
- if (NULL == b_from) {
+ if (b_from == NULL) {
set_last_result(BUNDLE_ERROR_INVALID_PARAMETER);
return NULL;
}
+
b_to = bundle_create();
- if (NULL == b_to)
+ if (b_to == NULL)
return NULL;
- keyval_t *kv_from = b_from->kv_head;
- keyval_t *kv_to = NULL;
+ kv_from = b_from->kv_head;
while (kv_from != NULL) {
if (keyval_type_is_array(kv_from->type)) {
- keyval_array_t *kva_from = (keyval_array_t *)kv_from;
- kv_to = (keyval_t *) keyval_array_new(NULL, kv_from->key,
+ kva_from = (keyval_array_t *)kv_from;
+ kv_to = (keyval_t *)keyval_array_new(NULL, kv_from->key,
kv_from->type, NULL, kva_from->len);
if (!kv_to)
- goto ERR_CLEANUP;
+ goto err;
+
for (i = 0; i < kva_from->len; i++) {
if (((keyval_array_t *)kv_from)->array_val[i]) {
- keyval_array_set_element((keyval_array_t *)kv_to, i,
+ keyval_array_set_element(
+ (keyval_array_t *)kv_to, i,
((keyval_array_t *)kv_from)->array_val[i],
((keyval_array_t *)kv_from)->array_element_size[i]);
}
}
+
_bundle_append_kv(b_to, kv_to);
} else {
- if (_bundle_add_kv(b_to, kv_from->key, kv_from->val,
- kv_from->size, kv_from->type, 0))
- goto ERR_CLEANUP;
+ if (_bundle_add_kv(b_to, kv_from->key,
+ kv_from->val, kv_from->size, kv_from->type, 0))
+ goto err;
}
kv_from = kv_from->next;
}
+
return b_to;
-ERR_CLEANUP:
+err:
bundle_free(b_to);
return NULL;
}
-
-int
-bundle_encode(bundle *b, bundle_raw **r, int *len)
+int bundle_encode(bundle *b, bundle_raw **r, int *len)
{
keyval_t *kv;
unsigned char *m;
@@ -453,23 +434,23 @@ bundle_encode(bundle *b, bundle_raw **r, int *len)
unsigned char *byte;
size_t byte_len;
gchar *chksum_val;
+ size_t msize = 0;
- if (NULL == b || NULL == r || NULL == len)
+ if (b == NULL || r == NULL || len == NULL)
return BUNDLE_ERROR_INVALID_PARAMETER;
/* calculate memory size */
- size_t msize = 0; /* Sum of required size */
-
kv = b->kv_head;
while (kv != NULL) {
msize += kv->method->get_encoded_size(kv);
kv = kv->next;
}
+
m = calloc(msize + CHECKSUM_LENGTH, sizeof(unsigned char));
- if (unlikely(NULL == m))
+ if (unlikely(m == NULL))
return BUNDLE_ERROR_OUT_OF_MEMORY;
- p_m = m + CHECKSUM_LENGTH; /* temporary pointer */
+ p_m = m + CHECKSUM_LENGTH; /* temporary pointer */
kv = b->kv_head;
while (kv != NULL) {
@@ -485,37 +466,34 @@ bundle_encode(bundle *b, bundle_raw **r, int *len)
free(byte);
}
- /*compute checksum from the data*/
+ /* compute checksum from the data */
chksum_val = g_compute_checksum_for_string(G_CHECKSUM_MD5,
- (const char *)(m+CHECKSUM_LENGTH), msize);
- /*prefix checksum to the data */
+ (const char *)(m + CHECKSUM_LENGTH), msize);
+ /* prefix checksum to the data */
memcpy(m, chksum_val, CHECKSUM_LENGTH);
- if (NULL != r) {
- /*base64 encode for whole string checksum and data*/
+ if (r) {
+ /* base64 encode for whole string checksum and data */
*r = (unsigned char *)g_base64_encode(m, msize + CHECKSUM_LENGTH);
- if (NULL != len)
+ if (len)
*len = strlen((char *)*r);
}
free(m);
- g_free(chksum_val);/*free checksum string */
+ g_free(chksum_val); /* free checksum string */
return BUNDLE_ERROR_NONE;
}
-int
-bundle_free_encoded_rawdata(bundle_raw **r)
+int bundle_free_encoded_rawdata(bundle_raw **r)
{
if (!*r)
- return BUNDLE_ERROR_INVALID_PARAMETER;
- /*TC_FIX - double free sigabrt handling */
+ return BUNDLE_ERROR_INVALID_PARAMETER; /* TC_FIX - double free sigabrt handling */
free(*r);
*r = NULL;
return BUNDLE_ERROR_NONE;
}
-bundle *
-bundle_decode(const bundle_raw *r, const int data_size)
+bundle *bundle_decode(const bundle_raw *r, const int data_size)
{
bundle *b;
bundle_raw *p_r;
@@ -527,24 +505,28 @@ bundle_decode(const bundle_raw *r, const int data_size)
unsigned int d_len;
char *extract_cksum;
gchar *compute_cksum;
+ size_t bytes_read;
+ keyval_t *kv;
+ int type;
- if (NULL == r) {
+ if (r == NULL) {
set_last_result(BUNDLE_ERROR_INVALID_PARAMETER);
return NULL;
}
- extract_cksum = calloc(CHECKSUM_LENGTH+1, sizeof(char));
- if (unlikely(NULL == extract_cksum)) {
+ extract_cksum = calloc(CHECKSUM_LENGTH + 1, sizeof(char));
+ if (unlikely(extract_cksum == NULL)) {
set_last_result(BUNDLE_ERROR_INVALID_PARAMETER);
return NULL;
}
- /* base 64 decode of input string
+ /*
+ * base 64 decode of input string
* Since base64 encodes 3 bytes in 4 chars (+3 may be needed in case of non-zero state)
* refer to: https://developer.gnome.org/glib/stable/glib-Base64-Encoding.html#g-base64-decode-step
*/
d_str = malloc((data_size / 4) * 3 + 3);
- if (unlikely(NULL == d_str)) {
+ if (unlikely(d_str == NULL)) {
set_last_result(BUNDLE_ERROR_OUT_OF_MEMORY);
free(extract_cksum);
return NULL;
@@ -558,12 +540,14 @@ bundle_decode(const bundle_raw *r, const int data_size)
return NULL;
}
- /*extract checksum from the received string */
+ /* extract checksum from the received string */
strncpy(extract_cksum, (const char *)d_str, CHECKSUM_LENGTH);
/* compute checksum for the data */
compute_cksum = g_compute_checksum_for_string(G_CHECKSUM_MD5,
- (const char *)(d_str+CHECKSUM_LENGTH), d_len_raw-CHECKSUM_LENGTH);
- /* compare checksum values- extracted from the received
+ (const char *)(d_str + CHECKSUM_LENGTH),
+ d_len_raw - CHECKSUM_LENGTH);
+ /*
+ * compare checksum values- extracted from the received
* string and computed from the data
*/
if (strcmp(extract_cksum, compute_cksum) != 0) {
@@ -585,18 +569,14 @@ bundle_decode(const bundle_raw *r, const int data_size)
}
p_r = (bundle_raw *)d_r;
-
- size_t bytes_read;
- keyval_t *kv;
-
while (p_r < d_r + d_len - 1) {
kv = NULL; /* To get a new kv */
/* Find type, and use decode function according to type */
- int type = keyval_get_type_from_encoded_byte(p_r);
-
+ type = keyval_get_type_from_encoded_byte(p_r);
if (keyval_type_is_array(type))
- bytes_read = keyval_array_decode(p_r, (keyval_array_t **) &kv);
+ bytes_read = keyval_array_decode(p_r,
+ (keyval_array_t **) &kv);
else
bytes_read = keyval_decode(p_r, &kv);
@@ -621,8 +601,7 @@ struct _argv_idx {
int idx;
};
-int
-bundle_encode_raw(bundle *b, bundle_raw **r, int *len)
+int bundle_encode_raw(bundle *b, bundle_raw **r, int *len)
{
keyval_t *kv = NULL;
unsigned char *m = NULL;
@@ -630,20 +609,20 @@ bundle_encode_raw(bundle *b, bundle_raw **r, int *len)
unsigned char *byte = NULL;
size_t byte_len;
gchar *chksum_val = NULL;
+ size_t msize = 0;
- if (NULL == b || NULL == r)
+ if (b == NULL || r == NULL)
return BUNDLE_ERROR_INVALID_PARAMETER;
/* calculate memory size */
- size_t msize = 0; /* Sum of required size */
-
kv = b->kv_head;
while (kv != NULL) {
msize += kv->method->get_encoded_size(kv);
kv = kv->next;
}
+
m = calloc(msize+CHECKSUM_LENGTH, sizeof(unsigned char));
- if (unlikely(NULL == m))
+ if (unlikely(m == NULL))
return BUNDLE_ERROR_OUT_OF_MEMORY;
p_m = m + CHECKSUM_LENGTH; /* temporary pointer */
@@ -662,25 +641,20 @@ bundle_encode_raw(bundle *b, bundle_raw **r, int *len)
free(byte);
}
- /*compute checksum from the data*/
+ /* compute checksum from the data */
chksum_val = g_compute_checksum_for_string(G_CHECKSUM_MD5,
- (const char *)(m+CHECKSUM_LENGTH), msize);
- /*prefix checksum to the data */
+ (const char *)(m + CHECKSUM_LENGTH), msize);
+ /* prefix checksum to the data */
memcpy(m, chksum_val, CHECKSUM_LENGTH);
- /*if ( NULL != r ) {
- *r =(unsigned char*)g_base64_encode(m,msize+CHECKSUM_LENGTH);
- if ( NULL != len ) *len = strlen((char*)*r);
- }
- free(m);*/
+
*r = m;
*len = msize + CHECKSUM_LENGTH;
- g_free(chksum_val);/*free checksum string */
+ g_free(chksum_val); /* free checksum string */
return BUNDLE_ERROR_NONE;
}
-bundle *
-bundle_decode_raw(const bundle_raw *r, const int data_size)
+bundle *bundle_decode_raw(const bundle_raw *r, const int data_size)
{
bundle *b = NULL;
bundle_raw *p_r = NULL;
@@ -688,16 +662,19 @@ bundle_decode_raw(const bundle_raw *r, const int data_size)
unsigned int d_len_raw;
unsigned char *d_r = NULL;
unsigned int d_len;
- char *extract_cksum = NULL;
+ char *extract_cksum;
gchar *compute_cksum = NULL;
+ size_t bytes_read;
+ keyval_t *kv;
+ int type;
- if (NULL == r) {
+ if (r == NULL) {
set_last_result(BUNDLE_ERROR_INVALID_PARAMETER);
return NULL;
}
extract_cksum = calloc(CHECKSUM_LENGTH + 1, sizeof(char));
- if (unlikely(NULL == extract_cksum)) {
+ if (unlikely(extract_cksum == NULL)) {
set_last_result(BUNDLE_ERROR_OUT_OF_MEMORY);
return NULL;
}
@@ -710,9 +687,10 @@ bundle_decode_raw(const bundle_raw *r, const int data_size)
strncpy(extract_cksum, (const char *)d_str, CHECKSUM_LENGTH);
/* compute checksum for the data */
compute_cksum = g_compute_checksum_for_string(G_CHECKSUM_MD5,
- (const char *)(d_str+CHECKSUM_LENGTH),
- d_len_raw-CHECKSUM_LENGTH);
- /*compare checksum values- extracted from the received
+ (const char *)(d_str + CHECKSUM_LENGTH),
+ d_len_raw - CHECKSUM_LENGTH);
+ /*
+ * compare checksum values- extracted from the received
* string and computed from the data
*/
if (strcmp(extract_cksum, compute_cksum) != 0) {
@@ -733,18 +711,14 @@ bundle_decode_raw(const bundle_raw *r, const int data_size)
}
p_r = (bundle_raw *)d_r;
-
- size_t bytes_read;
- keyval_t *kv;
-
while (p_r < d_r + d_len - 1) {
kv = NULL; /* To get a new kv */
/* Find type, and use decode function according to type */
- int type = keyval_get_type_from_encoded_byte(p_r);
-
+ type = keyval_get_type_from_encoded_byte(p_r);
if (keyval_type_is_array(type))
- bytes_read = keyval_array_decode(p_r, (keyval_array_t **) &kv);
+ bytes_read = keyval_array_decode(p_r,
+ (keyval_array_t **) &kv);
else
bytes_read = keyval_decode(p_r, &kv);
@@ -757,31 +731,29 @@ bundle_decode_raw(const bundle_raw *r, const int data_size)
free(extract_cksum);
g_free(compute_cksum);
-
set_last_result(BUNDLE_ERROR_NONE);
+
return b;
}
-
-void
-_iter_export_to_argv(const char *key, const int type, const keyval_t *kv,
+void _iter_export_to_argv(const char *key, const int type, const keyval_t *kv,
void *user_data)
{
struct _argv_idx *vi = (struct _argv_idx *)user_data;
-
- vi->argv[vi->idx] = (char *)key;
-
- unsigned char *byte = NULL, *encoded_byte = NULL;
+ unsigned char *byte = NULL;
+ unsigned char *encoded_byte = NULL;
size_t byte_len = 0;
- if (0 == kv->method->encode((struct keyval_t *)kv, &byte, &byte_len)) {
+ vi->argv[vi->idx] = (char *)key;
+ if (kv->method->encode((struct keyval_t *)kv, &byte, &byte_len) == 0) {
/* TODO: encode FAILED! */
- BUNDLE_EXCEPTION_PRINT("bundle: FAILED to encode keyval: %s\n", key);
+ BUNDLE_EXCEPTION_PRINT("bundle: FAILED to encode keyval: %s\n",
+ key);
return;
}
encoded_byte = (unsigned char *)g_base64_encode(byte, byte_len);
- if (NULL == encoded_byte) {
+ if (encoded_byte == NULL) {
BUNDLE_EXCEPTION_PRINT("bundle: failed to encode byte\n");
return;
}
@@ -792,10 +764,11 @@ _iter_export_to_argv(const char *key, const int type, const keyval_t *kv,
free(byte);
}
-int
-bundle_export_to_argv(bundle *b, char ***argv)
+int bundle_export_to_argv(bundle *b, char ***argv)
{
- int argc, item_count;
+ struct _argv_idx vi;
+ int argc;
+ int item_count;
if (b == NULL || argv == NULL) {
set_last_result(BUNDLE_ERROR_INVALID_PARAMETER);
@@ -811,12 +784,11 @@ bundle_export_to_argv(bundle *b, char ***argv)
return -1;
}
- struct _argv_idx vi;
vi.argc = argc;
vi.argv = *argv;
vi.idx = 2; /* start from index 2*/
vi.argv[1] = TAG_IMPORT_EXPORT_CHECK; /* set argv[1] as encoded*/
- /*BUNDLE_LOG_PRINT("\nargument 1 is %s",vi.argv[1]);*/
+ /* BUNDLE_LOG_PRINT("\nargument 1 is %s",vi.argv[1]); */
bundle_foreach(b, _iter_export_to_argv, &vi);
@@ -826,20 +798,19 @@ bundle_export_to_argv(bundle *b, char ***argv)
int bundle_free_exported_argv(int argc, char ***argv)
{
+ int i;
+
if (argc < 1)
return BUNDLE_ERROR_INVALID_PARAMETER;
if (!*argv || argc < 2)
return BUNDLE_ERROR_INVALID_PARAMETER;
- int i;
- for (i = 3; i < argc; i += 2) {
- free((*argv)[i]);
- /* need to free value from g_base64_encode() */
- }
-
+ for (i = 3; i < argc; i += 2)
+ free((*argv)[i]); /* need to free value from g_base64_encode() */
free(*argv);
*argv = NULL;
+
return BUNDLE_ERROR_NONE;
}
@@ -871,7 +842,7 @@ bundle *bundle_import_from_argv(int argc, char **argv)
}
if (!argv[1] || strcmp(argv[1], TAG_IMPORT_EXPORT_CHECK)) {
- /*start idx from one as argv[1] is user given argument*/
+ /* start idx from one as argv[1] is user given argument */
for (idx = 1; idx + 1 < argc; idx = idx + 2)
bundle_add(b, argv[idx], argv[idx + 1]);
@@ -887,7 +858,7 @@ bundle *bundle_import_from_argv(int argc, char **argv)
/* base64_decode */
byte = g_base64_decode(encoded_byte, &byte_size);
- if (NULL == byte) {
+ if (byte == NULL) {
if (b)
set_last_result(bundle_free(b));
return NULL;
@@ -895,16 +866,12 @@ bundle *bundle_import_from_argv(int argc, char **argv)
type = keyval_get_type_from_encoded_byte(byte);
if (keyval_type_is_array(type)) {
- if (0 == keyval_array_decode(byte, &kva)) {
- /* TODO: error! */
+ if (keyval_array_decode(byte, &kva) == 0) /* TODO: error! */
BUNDLE_EXCEPTION_PRINT("Unable to Decode array\n");
- }
kv = (keyval_t *)kva;
} else {
- if (0 == keyval_decode(byte, &kv)) {
- /* TODO: error! */
+ if (keyval_decode(byte, &kv) == 0) /* TODO: error! */
BUNDLE_EXCEPTION_PRINT("Unable to Decode\n");
- }
}
_bundle_append_kv(b, kv);
@@ -916,40 +883,43 @@ bundle *bundle_import_from_argv(int argc, char **argv)
return b;
}
-
- int
-bundle_get_type(bundle *b, const char *key)
+int bundle_get_type(bundle *b, const char *key)
{
keyval_t *kv = _bundle_find_kv(b, key);
- if (kv)
+
+ if (kv) {
return kv->type;
- else {
+ } else {
set_last_result(BUNDLE_ERROR_KEY_NOT_AVAILABLE);
return BUNDLE_TYPE_NONE;
}
}
-/** Get length of an array
+/*
+ * Get length of an array
*/
- unsigned int
-bundle_get_array_len(bundle *b, const char *key)
+unsigned int bundle_get_array_len(bundle *b, const char *key)
{
return BUNDLE_ERROR_NONE;
}
-/** Get size of an item in byte, of given pointer
+/*
+ * Get size of an item in byte, of given pointer
*/
- size_t
-bundle_get_array_val_size(bundle *b, const char *key, const void *val_ptr)
+size_t bundle_get_array_val_size(bundle *b, const char *key,
+ const void *val_ptr)
{
return BUNDLE_ERROR_NONE;
}
-static int
-bundle_set_array_val(bundle *b, const char *key, const int type,
+
+static int bundle_set_array_val(bundle *b, const char *key, const int type,
const unsigned int idx, const void *val, const size_t size)
{
- keyval_t *kv = _bundle_find_kv(b, key);
- if (NULL == kv)
+ keyval_t *kv;
+ keyval_array_t *kva;
+
+ kv = _bundle_find_kv(b, key);
+ if (kv == NULL)
return get_last_result();
if (type != kv->type)
@@ -959,8 +929,7 @@ bundle_set_array_val(bundle *b, const char *key, const int type,
if (!keyval_type_is_array(kv->type))
return BUNDLE_ERROR_INVALID_PARAMETER;
- keyval_array_t *kva = (keyval_array_t *)kv;
-
+ kva = (keyval_array_t *)kv;
if (!keyval_array_is_idx_valid(kva, idx))
return BUNDLE_ERROR_INVALID_PARAMETER;
@@ -971,17 +940,14 @@ bundle_set_array_val(bundle *b, const char *key, const int type,
return keyval_array_set_element(kva, idx, (void *)val, size);
}
-
- int
-bundle_add_str_array(bundle *b, const char *key, const char **str_array,
+int bundle_add_str_array(bundle *b, const char *key, const char **str_array,
const int len)
{
return _bundle_add_kv(b, key, str_array, 0, BUNDLE_TYPE_STR_ARRAY, len);
}
-
- int
-bundle_get_val_array(bundle *b, const char *key, char ***str_array, int *len)
+int bundle_get_val_array(bundle *b, const char *key, char ***str_array,
+ int *len)
{
return _bundle_get_val(b, key, BUNDLE_TYPE_STR_ARRAY,
(void **)str_array, NULL, (unsigned int *)len, NULL);
@@ -998,17 +964,17 @@ const char **bundle_get_str_array(bundle *b, const char *key, int *len)
return arr_val;
}
-
- int
-bundle_compare(bundle *b1, bundle *b2)
+int bundle_compare(bundle *b1, bundle *b2)
{
+ keyval_t *kv1;
+ keyval_t *kv2;
+
if (!b1 || !b2)
return -1;
- keyval_t *kv1, *kv2;
-
if (bundle_get_count(b1) != bundle_get_count(b2))
return 1;
+
for (kv1 = b1->kv_head; kv1 != NULL; kv1 = kv1->next) {
kv2 = _bundle_find_kv(b2, kv1->key);
if (!kv2)
@@ -1016,58 +982,49 @@ bundle_compare(bundle *b1, bundle *b2)
if (kv1->method->compare(kv1, kv2))
return 1;
}
+
return 0;
}
-
-
- int
-bundle_set_str_array_element(bundle *b, const char *key,
+int bundle_set_str_array_element(bundle *b, const char *key,
const unsigned int idx, const char *val)
{
if (!val)
return BUNDLE_ERROR_INVALID_PARAMETER;
return bundle_set_array_val(b, key, BUNDLE_TYPE_STR_ARRAY,
- idx, val, strlen(val)+1);
+ idx, val, strlen(val) + 1);
}
-
- int
-bundle_add_byte(bundle *b, const char *key, const void *byte,
+int bundle_add_byte(bundle *b, const char *key, const void *byte,
const size_t size)
{
return _bundle_add_kv(b, key, byte, size, BUNDLE_TYPE_BYTE, 1);
}
- int
-bundle_get_byte(bundle *b, const char *key, void **byte, size_t *size)
+int bundle_get_byte(bundle *b, const char *key, void **byte, size_t *size)
{
- return _bundle_get_val(b, key, BUNDLE_TYPE_BYTE, (void **) byte,
+ return _bundle_get_val(b, key, BUNDLE_TYPE_BYTE, (void **)byte,
size, NULL, NULL);
}
- int
-bundle_add_byte_array(bundle *b, const char *key, void **byte_array,
+int bundle_add_byte_array(bundle *b, const char *key, void **byte_array,
const unsigned int len)
{
- return _bundle_add_kv(b, key, byte_array, 0, BUNDLE_TYPE_BYTE_ARRAY, len);
+ return _bundle_add_kv(b, key, byte_array, 0,
+ BUNDLE_TYPE_BYTE_ARRAY, len);
}
- int
-bundle_get_byte_array(bundle *b, const char *key, void ***byte_array,
+int bundle_get_byte_array(bundle *b, const char *key, void ***byte_array,
unsigned int *len, unsigned int **array_element_size)
{
return _bundle_get_val(b, key, BUNDLE_TYPE_BYTE_ARRAY,
(void **)byte_array, NULL, len, array_element_size);
}
-
- int
-bundle_set_byte_array_element(bundle *b, const char *key,
+int bundle_set_byte_array_element(bundle *b, const char *key,
const unsigned int idx, const void *val, const size_t size)
{
return bundle_set_array_val(b, key, BUNDLE_TYPE_BYTE_ARRAY,
idx, val, size);
}
-
diff --git a/src/bundle_json.c b/src/bundle_json.c
index f8601ba..3b142f5 100644
--- a/src/bundle_json.c
+++ b/src/bundle_json.c
@@ -1,3 +1,19 @@
+/*
+ * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
#include <stdlib.h>
#include <string.h>
#include <glib.h>
diff --git a/src/keyval.c b/src/keyval.c
index 35472c6..4ca41bd 100755
--- a/src/keyval.c
+++ b/src/keyval.c
@@ -1,10 +1,5 @@
/*
- * bundle
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
- * Jaeho Lee <jaeho81.lee@samsung.com>
+ * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,20 +12,19 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
*/
-
/**
* keyval.c
* Implementation of keyval object
*/
+#include <stdlib.h>
+
#include "keyval_type.h"
#include "keyval.h"
#include "bundle_log.h"
#include "bundle.h"
-#include <stdlib.h>
static keyval_method_collection_t method = {
keyval_free,
@@ -40,12 +34,10 @@ static keyval_method_collection_t method = {
keyval_decode
};
-keyval_t *
-keyval_new(keyval_t *kv, const char *key, const int type, const void *val,
- const size_t size)
+keyval_t *keyval_new(keyval_t *kv, const char *key,
+ const int type, const void *val, const size_t size)
{
- int must_free_obj;
- must_free_obj = kv ? 0 : 1;
+ int must_free_obj = kv ? 0 : 1;
if (!kv) {
kv = calloc(1, sizeof(keyval_t));
@@ -59,6 +51,7 @@ keyval_new(keyval_t *kv, const char *key, const int type, const void *val,
keyval_free(kv, must_free_obj);
return NULL;
}
+
kv->key = strdup(key);
if (!kv->key) {
set_last_result(BUNDLE_ERROR_OUT_OF_MEMORY);
@@ -85,10 +78,9 @@ keyval_new(keyval_t *kv, const char *key, const int type, const void *val,
return kv;
}
-void
-keyval_free(keyval_t *kv, int do_free_object)
+void keyval_free(keyval_t *kv, int do_free_object)
{
- if (NULL == kv)
+ if (kv == NULL)
return;
if (kv->key) {
@@ -96,7 +88,7 @@ keyval_free(keyval_t *kv, int do_free_object)
kv->key = NULL;
}
- if (NULL != kv->val) {
+ if (kv->val != NULL) {
free(kv->val);
kv->val = NULL;
}
@@ -107,11 +99,11 @@ keyval_free(keyval_t *kv, int do_free_object)
return;
}
-int
-keyval_get_data(keyval_t *kv, int *type, void **val, size_t *size)
+int keyval_get_data(keyval_t *kv, int *type, void **val, size_t *size)
{
if (!kv)
return BUNDLE_ERROR_INVALID_PARAMETER;
+
if (keyval_type_is_array(kv->type))
return BUNDLE_ERROR_INVALID_PARAMETER;
@@ -125,13 +117,12 @@ keyval_get_data(keyval_t *kv, int *type, void **val, size_t *size)
return 0;
}
-int
-keyval_compare(keyval_t *kv1, keyval_t *kv2)
+int keyval_compare(keyval_t *kv1, keyval_t *kv2)
{
if (!kv1 || !kv2)
return -1;
- if (0 != strcmp(kv1->key, kv2->key))
+ if (strcmp(kv1->key, kv2->key) != 0)
return 1;
if (kv1->type != kv2->type)
return 1;
@@ -142,20 +133,20 @@ keyval_compare(keyval_t *kv1, keyval_t *kv2)
return 0;
if (kv1->val == NULL || kv2->val == NULL)
return 1;
- if (0 != memcmp(kv1->val, kv2->val, kv1->size))
+ if (memcmp(kv1->val, kv2->val, kv1->size) != 0)
return 1;
return 0;
}
-size_t
-keyval_get_encoded_size(keyval_t *kv)
+size_t keyval_get_encoded_size(keyval_t *kv)
{
+ size_t encoded_size;
+
if (!kv)
return 0;
- size_t encoded_size
- = sizeof(size_t) /* total size */
+ encoded_size = sizeof(size_t) /* total size */
+ sizeof(int) /* type */
+ sizeof(size_t) /* key size */
+ strlen(kv->key) + 1 /* key (+ null byte) */
@@ -175,14 +166,14 @@ keyval_get_encoded_size(keyval_t *kv)
* @param[out] byte_len
* @return byte_len
*/
-size_t
-keyval_encode(keyval_t *kv, unsigned char **byte, size_t *byte_len)
+size_t keyval_encode(keyval_t *kv, unsigned char **byte, size_t *byte_len)
{
static const size_t sz_type = sizeof(int);
static const size_t sz_keysize = sizeof(size_t);
size_t sz_key = strlen(kv->key) + 1;
static const size_t sz_size = sizeof(size_t);
size_t sz_val = kv->size;
+ unsigned char *p;
*byte_len = keyval_get_encoded_size(kv);
@@ -190,14 +181,20 @@ keyval_encode(keyval_t *kv, unsigned char **byte, size_t *byte_len)
if (!*byte)
return 0;
- unsigned char *p = *byte;
-
- memcpy(p, byte_len, sizeof(size_t)); p += sizeof(size_t);
- memcpy(p, &(kv->type), sz_type); p += sz_type;
- memcpy(p, &sz_key, sz_keysize); p += sz_keysize;
- memcpy(p, kv->key, sz_key); p += sz_key;
- memcpy(p, &(kv->size), sz_size); p += sz_size;
- memcpy(p, kv->val, sz_val); p += sz_val;
+ p = *byte;
+
+ memcpy(p, byte_len, sizeof(size_t));
+ p += sizeof(size_t);
+ memcpy(p, &(kv->type), sz_type);
+ p += sz_type;
+ memcpy(p, &sz_key, sz_keysize);
+ p += sz_keysize;
+ memcpy(p, kv->key, sz_key);
+ p += sz_key;
+ memcpy(p, &(kv->size), sz_size);
+ p += sz_size;
+ memcpy(p, kv->val, sz_val);
+ p += sz_val;
return *byte_len;
}
@@ -211,22 +208,32 @@ keyval_encode(keyval_t *kv, unsigned char **byte, size_t *byte_len)
* If kv is not NULL, given kv is used. (No new kv is created.)
* @return Number of bytes read from byte.
*/
-size_t
-keyval_decode(unsigned char *byte, keyval_t **kv)
+size_t keyval_decode(unsigned char *byte, keyval_t **kv)
{
static const size_t sz_byte_len = sizeof(size_t);
static const size_t sz_type = sizeof(int);
static const size_t sz_keysize = sizeof(size_t);
static const size_t sz_size = sizeof(size_t);
-
+ size_t byte_len;
+ int type;
+ size_t keysize;
+ char *key;
+ size_t size;
+ void *val;
unsigned char *p = byte;
- size_t byte_len = *((size_t *)p); p += sz_byte_len;
- int type = *((int *)p); p += sz_type;
- size_t keysize = *((size_t *)p); p += sz_keysize;
- char *key = (char *)p; p += keysize;
- size_t size = *((size_t *)p); p += sz_size;
- void *val = (void *)p; p += size;
+ byte_len = *((size_t *)p);
+ p += sz_byte_len;
+ type = *((int *)p);
+ p += sz_type;
+ keysize = *((size_t *)p);
+ p += sz_keysize;
+ key = (char *)p;
+ p += keysize;
+ size = *((size_t *)p);
+ p += sz_size;
+ val = (void *)p;
+ p += size;
if (kv)
*kv = keyval_new(*kv, key, type, val, size);
@@ -234,15 +241,14 @@ keyval_decode(unsigned char *byte, keyval_t **kv)
return byte_len;
}
-
-int
-keyval_get_type_from_encoded_byte(unsigned char *byte)
+int keyval_get_type_from_encoded_byte(unsigned char *byte)
{
static const size_t sz_byte_len = sizeof(size_t);
-
unsigned char *p = byte;
+ int type;
+
p += sz_byte_len;
- int type = *((int *)p);
+ type = *((int *)p);
+
return type;
}
-
diff --git a/src/keyval_array.c b/src/keyval_array.c
index aa9e994..8774140 100755
--- a/src/keyval_array.c
+++ b/src/keyval_array.c
@@ -1,10 +1,5 @@
/*
- * bundle
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
- * Jaeho Lee <jaeho81.lee@samsung.com>
+ * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,25 +12,22 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
*/
-
/**
* keyval_array.c
* Implementation of keyval_array object
*/
+#include <stdlib.h>
+#include <string.h>
+
#include "keyval_array.h"
#include "keyval.h"
#include "keyval_type.h"
#include "bundle.h"
#include "bundle_log.h"
-#include <stdlib.h>
-#include <string.h>
-
-
static keyval_method_collection_t method = {
(keyval_method_free_t) keyval_array_free,
(keyval_method_compare_t) keyval_array_compare,
@@ -44,30 +36,28 @@ static keyval_method_collection_t method = {
(keyval_method_decode_t) keyval_array_decode
};
-keyval_array_t *
-keyval_array_new(keyval_array_t *kva, const char *key, const int type,
- const void **array_val, const unsigned int len)
+keyval_array_t *keyval_array_new(keyval_array_t *kva, const char *key,
+ const int type, const void **array_val, const unsigned int len)
{
- int must_free_obj;
- must_free_obj = kva ? 0 : 1;
+ int must_free_obj = kva ? 0 : 1;
+ keyval_t *kv;
if (!kva) {
kva = calloc(1, sizeof(keyval_array_t));
- if (unlikely(NULL == kva)) {
+ if (unlikely(kva == NULL)) {
set_last_result(BUNDLE_ERROR_OUT_OF_MEMORY);
return NULL;
}
}
/* keyval setting */
- keyval_t *kv = keyval_new((keyval_t *)kva, key, type, NULL, 0);
- if (unlikely(NULL == kv)) {
+ kv = keyval_new((keyval_t *)kva, key, type, NULL, 0);
+ if (unlikely(kv == NULL)) {
set_last_result(BUNDLE_ERROR_OUT_OF_MEMORY);
return NULL;
}
kv->type = kv->type | BUNDLE_TYPE_ARRAY;
-
kva->len = len;
/* Set array value, if exist */
@@ -100,7 +90,7 @@ keyval_array_new(keyval_array_t *kva, const char *key, const int type,
(void **)array_val,
len,
keyval_type_get_measure_size_func(type))
- ) {
+ ) {
keyval_array_free(kva, 1);
return NULL;
}
@@ -112,15 +102,15 @@ keyval_array_new(keyval_array_t *kva, const char *key, const int type,
return kva;
}
-void
-keyval_array_free(keyval_array_t *kva, int do_free_object)
+void keyval_array_free(keyval_array_t *kva, int do_free_object)
{
+ int i;
+
if (!kva)
return;
/* free keyval_array elements */
free(kva->array_element_size);
- int i;
for (i = 0; i < kva->len; i++) {
if (kva->array_val[i])
free(kva->array_val[i]);
@@ -135,46 +125,47 @@ keyval_array_free(keyval_array_t *kva, int do_free_object)
free(kva);
}
-int
-keyval_array_compare(keyval_array_t *kva1, keyval_array_t *kva2)
+int keyval_array_compare(keyval_array_t *kva1, keyval_array_t *kva2)
{
- keyval_t *kv1, *kv2;
+ keyval_t *kv1;
+ keyval_t *kv2;
+ int i;
+
if (!kva1 || !kva2)
return -1;
kv1 = (keyval_t *)kva1;
kv2 = (keyval_t *)kva2;
- if (0 != strcmp(kv1->key, kv2->key))
+ if (strcmp(kv1->key, kv2->key) != 0)
return 1;
if (kv1->type != kv2->type)
return 1;
if (kva1->len != kva2->len)
return 1;
- int i;
+
for (i = 0; i < kva1->len; i++) {
if (kva1->array_val[i] == NULL && kva2->array_val[i] == NULL)
continue;
if (kva1->array_val[i] == NULL || kva2->array_val[i] == NULL)
return 1;
- if (0 != memcmp(kva1->array_val[i], kva2->array_val[i],
- kva1->array_element_size[i]))
+ if (memcmp(kva1->array_val[i], kva2->array_val[i],
+ kva1->array_element_size[i]) != 0)
return 1;
}
return 0;
}
-int
-keyval_array_copy_array(keyval_array_t *kva, void **array_val,
+int keyval_array_copy_array(keyval_array_t *kva, void **array_val,
unsigned int array_len, size_t (*measure_val_len)(void *val))
{
keyval_t *kv = (keyval_t *)kva;
+ keyval_type_measure_size_func_t measure_size;
int i;
/* Get measure_size function of the value type */
- keyval_type_measure_size_func_t measure_size =
- keyval_type_get_measure_size_func(kv->type);
+ measure_size = keyval_type_get_measure_size_func(kv->type);
if (!measure_size)
return -1;
@@ -201,16 +192,14 @@ cleanup_exit:
return -1;
}
-int
-keyval_array_is_idx_valid(keyval_array_t *kva, int idx)
+int keyval_array_is_idx_valid(keyval_array_t *kva, int idx)
{
if (kva && kva->len > idx && 0 <= idx)
return 1;
return 0;
}
-int
-keyval_array_set_element(keyval_array_t *kva, int idx, void *val, size_t size)
+int keyval_array_set_element(keyval_array_t *kva, int idx, void *val, size_t size)
{
/* An element is already exist in the idx! */
if (kva->array_val[idx]) {
@@ -237,13 +226,15 @@ keyval_array_set_element(keyval_array_t *kva, int idx, void *val, size_t size)
return BUNDLE_ERROR_NONE;
}
-int
-keyval_array_get_data(keyval_array_t *kva, int *type,
- void ***array_val, unsigned int *len, size_t **array_element_size)
+int keyval_array_get_data(keyval_array_t *kva, int *type, void ***array_val,
+ unsigned int *len, size_t **array_element_size)
{
+ keyval_t *kv;
+
if (!kva)
return BUNDLE_ERROR_INVALID_PARAMETER;
- keyval_t *kv = (keyval_t *)kva;
+
+ kv = (keyval_t *)kva;
if (!keyval_type_is_array(kv->type))
return BUNDLE_ERROR_INVALID_PARAMETER;
@@ -260,32 +251,30 @@ keyval_array_get_data(keyval_array_t *kva, int *type,
return BUNDLE_ERROR_NONE;
}
-size_t
-keyval_array_get_encoded_size(keyval_array_t *kva)
+size_t keyval_array_get_encoded_size(keyval_array_t *kva)
{
size_t sum_array_element_size = 0;
int i;
+ size_t encoded_size;
+
for (i = 0; i < kva->len; i++)
sum_array_element_size += kva->array_element_size[i];
- size_t encoded_size
- = sizeof(size_t) /* total size */
+ encoded_size = sizeof(size_t) /* total size */
+ sizeof(int) /* type */
+ sizeof(size_t) /* keysize */
+ strlen(((keyval_t *)kva)->key) + 1 /* key (+ null byte) */
+ sizeof(int) /* len */
- + kva->len * sizeof(size_t) /* array_element_size */
+ + kva->len * sizeof(size_t) /* array_element_size */
+ sum_array_element_size;
return encoded_size;
}
-size_t
-keyval_array_encode(keyval_array_t *kva, void **byte, size_t *byte_len)
+size_t keyval_array_encode(keyval_array_t *kva, void **byte, size_t *byte_len)
{
keyval_t *kv = (keyval_t *)kva;
int i;
-
/* Calculate memory size for kva */
static const size_t sz_type = sizeof(int);
static const size_t sz_keysize = sizeof(size_t);
@@ -293,6 +282,8 @@ keyval_array_encode(keyval_array_t *kva, void **byte, size_t *byte_len)
static const unsigned int sz_len = sizeof(int);
size_t sz_array_element_size = kva->len * sizeof(size_t);
size_t sz_array_val = 0;
+ unsigned char *p;
+
for (i = 0; i < kva->len; i++)
sz_array_val += kva->array_element_size[i];
@@ -303,15 +294,21 @@ keyval_array_encode(keyval_array_t *kva, void **byte, size_t *byte_len)
return 0;
/* Copy data */
- unsigned char *p = *byte;
-
- memcpy(p, byte_len, sizeof(size_t)); p += sizeof(size_t);
- memcpy(p, &(kv->type), sz_type); p += sz_type;
- memcpy(p, &sz_key, sz_keysize); p += sz_keysize;
- memcpy(p, kv->key, sz_key); p += sz_key;
- memcpy(p, &(kva->len), sz_len); p += sz_len;
+ p = *byte;
+
+ memcpy(p, byte_len, sizeof(size_t));
+ p += sizeof(size_t);
+ memcpy(p, &(kv->type), sz_type);
+ p += sz_type;
+ memcpy(p, &sz_key, sz_keysize);
+ p += sz_keysize;
+ memcpy(p, kv->key, sz_key);
+ p += sz_key;
+ memcpy(p, &(kva->len), sz_len);
+ p += sz_len;
memcpy(p, kva->array_element_size, sz_array_element_size);
p += sz_array_element_size;
+
for (i = 0; i < kva->len; i++) {
memcpy(p, kva->array_val[i], kva->array_element_size[i]);
p += kva->array_element_size[i];
@@ -320,32 +317,43 @@ keyval_array_encode(keyval_array_t *kva, void **byte, size_t *byte_len)
return *byte_len;
}
-size_t
-keyval_array_decode(void *byte, keyval_array_t **kva)
+size_t keyval_array_decode(void *byte, keyval_array_t **kva)
{
static const size_t sz_byte_len = sizeof(size_t);
static const size_t sz_type = sizeof(int);
static const size_t sz_keysize = sizeof(size_t);
static const int sz_len = sizeof(unsigned int);
-
unsigned char *p = byte;
+ size_t byte_len;
+ int type;
+ size_t keysize;
+ char *key;
+ unsigned int len;
+ size_t *array_element_size;
+ void *array_val;
+ int i;
+ size_t elem_size = 0;
/* Get data */
- size_t byte_len = *((size_t *)p); p += sz_byte_len;
- int type = *((int *)p); p += sz_type;
- size_t keysize = *((size_t *)p); p += sz_keysize;
- char *key = (char *)p; p += keysize;
- unsigned int len = *((unsigned int *)p); p += sz_len;
- size_t *array_element_size = (size_t *) p; p += sizeof(size_t) * len;
- void *array_val = (void *)p;
+ byte_len = *((size_t *)p);
+ p += sz_byte_len;
+ type = *((int *)p);
+ p += sz_type;
+ keysize = *((size_t *)p);
+ p += sz_keysize;
+ key = (char *)p;
+ p += keysize;
+ len = *((unsigned int *)p);
+ p += sz_len;
+ array_element_size = (size_t *)p;
+ p += sizeof(size_t) * len;
+ array_val = (void *)p;
*kva = keyval_array_new(NULL, key, type, NULL, len);
- int i;
- size_t elem_size = 0;
for (i = 0; i < len; i++) {
- elem_size += i ? array_element_size[i-1] : 0;
+ elem_size += i ? array_element_size[i - 1] : 0;
if (keyval_array_set_element(*kva, i,
- (void *)(array_val+elem_size),
+ (void *)(array_val + elem_size),
array_element_size[i])) {
keyval_array_free(*kva, 1);
*kva = NULL;
@@ -355,4 +363,3 @@ keyval_array_decode(void *byte, keyval_array_t **kva)
return byte_len;
}
-
diff --git a/src/keyval_type.c b/src/keyval_type.c
index 78004de..8365c7c 100755
--- a/src/keyval_type.c
+++ b/src/keyval_type.c
@@ -1,10 +1,5 @@
/*
- * bundle
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
- * Jaeho Lee <jaeho81.lee@samsung.com>
+ * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,16 +12,14 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
*/
+#include <stddef.h>
#include "keyval_type.h"
#include "bundle_log.h"
-#include <stddef.h>
-void
-keyval_type_init(void)
+void keyval_type_init(void)
{
static int is_done;
@@ -36,24 +29,21 @@ keyval_type_init(void)
is_done = 1;
}
-int
-keyval_type_is_array(int type)
+int keyval_type_is_array(int type)
{
if (type & BUNDLE_TYPE_ARRAY)
return 1;
return 0;
}
-int
-keyval_type_is_measurable(int type)
+int keyval_type_is_measurable(int type)
{
if (type & BUNDLE_TYPE_MEASURABLE)
return 1;
return 0;
}
-keyval_type_measure_size_func_t
-keyval_type_get_measure_size_func(int type)
+keyval_type_measure_size_func_t keyval_type_get_measure_size_func(int type)
{
switch (type) {
case BUNDLE_TYPE_STR:
@@ -65,11 +55,9 @@ keyval_type_get_measure_size_func(int type)
return NULL;
}
-size_t
-keyval_type_measure_size_str(void *val)
+size_t keyval_type_measure_size_str(void *val)
{
if (!val)
return 0;
return strlen((char *)val) + 1;
}
-