/**
* @file bundle.h
- * @version 0.1
- * @brief This file declares API of bundle library
+ * @brief This file declares has API of the bundle library
*/
/**
#include <errno.h>
#include <stddef.h>
+#include <tizen_error.h>
#ifdef __cplusplus
extern "C" {
#define unlikely(x) __builtin_expect(x,0)
/**
- * bundle is an opaque type pointing a bundle object
+ * @brief Enumeration for error code of Bundle.
+ *
+ * @since_tizen 2.3
+ */
+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_FILE_EXISTS /**< Key exists */
+} bundle_error_e;
+
+/**
+ * @brief The bundle handle.
+ * @since_tizen 2.3
*/
typedef struct _bundle_t bundle;
/**
- * bundle_raw is an encoded data type
+ * @brief The encoded data type.
+ * @since_tizen 2.3
* @see bundle_encode()
* @see bundle_decode()
*/
/**
- * Each bundle keyval have a type.
+ * @brief Enumeration for key-value pair types.
+ * @since_tizen 2.3
*/
enum bundle_type_property {
- BUNDLE_TYPE_ARRAY = 0x0100,
- BUNDLE_TYPE_PRIMITIVE = 0x0200,
- BUNDLE_TYPE_MEASURABLE = 0x0400
+ BUNDLE_TYPE_ARRAY = 0x0100, /**< Array type */
+ BUNDLE_TYPE_PRIMITIVE = 0x0200, /**< Primitive type */
+ BUNDLE_TYPE_MEASURABLE = 0x0400 /**< Measurable type */
};
+/**
+ * @brief Enumeration for bundle types.
+ * @since_tizen 2.3
+ */
enum bundle_type {
- BUNDLE_TYPE_NONE = -1,
- BUNDLE_TYPE_ANY = 0,
- BUNDLE_TYPE_STR = 1 | BUNDLE_TYPE_MEASURABLE, /* Default */
- BUNDLE_TYPE_STR_ARRAY = BUNDLE_TYPE_STR | BUNDLE_TYPE_ARRAY | BUNDLE_TYPE_MEASURABLE,
- BUNDLE_TYPE_BYTE = 2,
- BUNDLE_TYPE_BYTE_ARRAY = BUNDLE_TYPE_BYTE | BUNDLE_TYPE_ARRAY
+ 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 */
};
/**
- * A keyval object in a bundle.
+ * @brief The key-value pair handle.
+ * @since_tizen 2.3
* @see bundle_iterator_t
*/
typedef struct keyval_t bundle_keyval_t;
/**
- * bundle_iterator is a new iterator function type for bundle_foreach()
+ * @brief Called for every key-value pair.
+ * @since_tizen 2.3
* @see bundle_foreach()
*/
typedef void (*bundle_iterator_t) (
/**
- * bundle_iterate_cb_t is an iterator function type for bundle_iterate()
+ * @internal
+ * @brief Called for every key-value pair.
+ * @since_tizen 2.3
+ * @remarks This type is obsolete. You must not use this type any more.
* @see bundle_iterate()
- * @remark This type is obsolete. Do not use this type any more.
*/
typedef void (*bundle_iterate_cb_t) (const char *key, const char *val, void *data);
-/**
- * @brief Create a bundle object.
- * @pre None
- * @post None
+/**
+ * @brief Creates a bundle object.
+ * @since_tizen 2.3
+ * @remarks The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section.
+ * @return The bundle object
+ * @retval @c NULL - Failure
+ * @exception BUNDLE_ERROR_NONE Success
+ * @exception BUNDLE_ERROR_OUT_OF_MEMORY Out of memory
* @see bundle_free()
- * @return bundle object
- * @retval NULL on failure creating an object
- * @remark When NULL is returned, errno is set to one of the following values; \n
- * ENOMEM : No memory to create an object
*
@code
#include <bundle.h>
API bundle* bundle_create(void);
/**
- * @brief Free given bundle object with key/values in it
- * @pre b must be a valid bundle object.
- * @post None
+ * @brief Frees the given bundle object with key-value pairs in it.
+ * @since_tizen 2.3
+ * @param[in] b The bundle object to be freed
+ * @return The operation result;
+ * @retval BUNDLE_ERROR_NONE Success
+ * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @pre @a b must be a valid bundle object.
* @see bundle_create()
- * @param[in] b bundle object to be freed
- * @return Operation result;
- * @retval 0 success
- * @retval -1 failure
- * @remark None
@code
#include <bundle.h>
bundle *b = bundle_create(); // Create new bundle object
@endcode
*/
API int bundle_free(bundle *b);
+
/**
- * @brief Add a string array type key-value pair into bundle.
- * @pre b must be a valid bundle object.
- * @post None
+ * @brief Adds a strings array type key-value pair into a given bundle.
+ * @since_tizen 2.3
+ * @param[in] b The bundle object
+ * @param[in] key The key
+ * @param[in] str_array The string type value; if @c NULL, an empty array is created; you can change an item with
+ * @param[in] len The length of the array
+ * @return The operation result
+ * @retval BUNDLE_ERROR_NONE Success
+ * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval BUNDLE_ERROR_KEY_EXISTS Key already exists
+ * @retval BUNDLE_ERROR_OUT_OF_MEMORY Out of memory
+ * @pre @a b must be a valid bundle object.
* @see bundle_get_str_array()
- * @see bundle_set_str_array_element()
- * @param[in] b bundle object
- * @param[in] key key
- * @param[in] str_array string type value. If NULL, empty array is created. You can change an item with
- * @param[in] len Length of array.
- * @return Operation result
- * @retval 0 success
- * @retval -1 failure
*
- * @remark When -1 is returned, errno is set to one of the following values; \n
- EKEYREJECTED : key is rejected (NULL or sth) \n
- EPERM : key is already exist, not permitted to overwrite value \n
- EINVAL : b or val is not valid (NULL or sth) \n
@code
#include <bundle.h>
char *sa = { "aaa", "bbb", "ccc" }; // A string array of length 3
@endcode
*/
API int bundle_add_str_array(bundle *b, const char *key, const char **str_array, const int len);
+
/**
- * @brief Add a string type key-value pair into bundle.
- * @pre b must be a valid bundle object.
- * @post None
+ * @internal
+ * @brief Adds a string type key-value pair into a given bundle.
+ * @since_tizen 2.3
+ * @param[in] b The bundle object
+ * @param[in] key The key
+ * @param[in] val The value
+ * @return The operation result
+ * @retval BUNDLE_ERROR_NONE Success
+ * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval BUNDLE_ERROR_KEY_EXISTS Key already exists
+ * @retval BUNDLE_ERROR_OUT_OF_MEMORY Out of memory
+ * @pre @a b must be a valid bundle object.
* @see bundle_add_str()
- * @param[in] b bundle object
- * @param[in] key key
- * @param[in] val value
- * @return Operation result
- * @retval 0 success
- * @retval -1 failure
- *
- * @remark When -1 is returned, errno is set to one of the following values; \n
- EKEYREJECTED : key is rejected (NULL or sth) \n
- EPERM : key is already exist, not permitted to overwrite value \n
- EINVAL : b or val is not valid (NULL or sth) \n
@code
#include <bundle.h>
bundle *b = bundle_create(); // Create new bundle object
API int bundle_add(bundle *b, const char *key, const char *val);
/**
- * @brief Delete val with given key
- * @pre b must be a valid bundle object.
- * @post None
- * @see None
- * @param[in] b bundle object
- * @param[in] key given key
- * @return Operation result
- * @retval 0 Success
- * @retval -1 Failure
- *
- * @remark When -1 is returned, errno is set to one of the following values; \n
- EINVAL : b is invalid (NULL or sth) \n
- ENOKEY : No key exist \n
- EKEYREJECTED : key is invalid (NULL or sth) \n
+ * @brief Deletes a key-value object with the given key.
+ * @since_tizen 2.3
+ * @param[in] b The bundle object
+ * @param[in] key The given key
+ * @return The operation result
+ * @retval BUNDLE_ERROR_NONE Success
+ * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval BUNDLE_ERROR_KEY_NOT_AVAILABLE Key not available
+ * @pre @a b must be a valid bundle object.
@code
#include <bundle.h>
bundle *b = bundle_create(); // Create new bundle object
- bundle_add(b, "foo_key", "bar_val"); // add a key-val pair
+ bundle_add_str(b, "foo_key", "bar_val"); // add a key-val pair
bundle_del(b, "foo_key"); // del "foo_key" from b
bundle_free(b);
@endcode
*/
API int bundle_del(bundle *b, const char* key);
+
/**
- * @brief Get string array value from key
- * @pre b must be a valid bundle object.
- * @post None
+ * @brief Gets a string array from a given key.
+ * @since_tizen 2.3
+ * @remarks You MUST free or modify the returned string!
+ * @remarks The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section.
+ * @param[in] b The bundle object
+ * @param[in] key The key
+ * @param[out] len The array length
+ * @return The pointer to the array of strings
+ * @retval @c NULL - Key not found
+ * @exception BUNDLE_ERROR_NONE Success
+ * @exception BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @exception BUNDLE_ERROR_KEY_NOT_AVAILABLE Key not available
+ * @pre @a b must be a valid bundle object.
* @see bundle_add_str_array()
- * @see bundle_set_str_array_element()
- * @param[in] b bundle object
- * @param[in] key key
- * @param[out] len array length
- * @return Pointer to array of string
- * @retval NULL If key is not found, returns NULL.
- * @remark DO NOT free or modify returned string!
- When NULL is returned, errno is set to one of the following values; \n
- EINVAL : b is invalid \n
- ENOKEY : No key exists \n
- EKEYREJECTED : invalid key (NULL or sth) \n
@code
#include <bundle.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");
- bundle_set_str_array_element(b, "foo", 1, "bbb");
- bundle_set_str_array_element(b, "foo", 2, "ccc");
+ char *sa = { "aaa", "bbb", "ccc" }; // A string array of length 3
+ bundle_add_str_array(b, "foo", sa, 3); // add a key-val pair
char **str_array = NULL;
int len_str_array = 0;
bundle_free(b);
@endcode
*/
-
API const char** bundle_get_str_array(bundle *b, const char *key,int *len);
+
/**
- * @brief Get value from key
- * @pre b must be a valid bundle object.
- * @post None
+ * @internal
+ * @brief Gets a value with a given key.
+ * @since_tizen 2.3
+ * @remarks You MUST free or modify the returned string!
+ * @remarks The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section.
+ * @param[in] b The bundle object
+ * @param[in] key The key
+ * @return The pointer for the value string
+ * @retval @c NULL - Key not found
+ * @exception BUNDLE_ERROR_NONE Success
+ * @exception BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @exception BUNDLE_ERROR_KEY_NOT_AVAILABLE Key not available
+ * @pre @a b must be a valid bundle object.
* @see bundle_get_str()
- * @param[in] b bundle object
- * @param[in] key key
- * @return Pointer for value string
- * @retval NULL If key is not found, returns NULL.
- * @remark DO NOT free or modify returned string!
- When NULL is returned, errno is set to one of the following values; \n
- EINVAL : b is invalid \n
- ENOKEY : No key exists \n
- EKEYREJECTED : invalid key (NULL or sth) \n
@code
#include <bundle.h>
bundle *b = bundle_create(); // Create new bundle object
- bundle_add(b, "foo_key", "bar_val"); // add a key-val pair
+ bundle_add_str(b, "foo", "bar"); //add a key-val pair
char *val = bundle_get_val(b, "foo_key"); // val = "bar_val"
bundle_free(b); // After freeing b, val becomes a dangling pointer.
API const char* bundle_get_val(bundle *b, const char *key);
/**
- * @brief Get the number of bundle items
- * @pre b must be a valid bundle object.
- * @post None
- * @see None
- * @param[in] b bundle object
- * @return Number of bundle items
- * @remark None
+ * @brief Gets the number of bundle items.
+ * @since_tizen 2.3
+ * @param[in] b The bundle object
+ * @return The number of bundle items
+ * @pre @a b must be a valid bundle object.
@code
#include <bundle.h>
bundle *b = bundle_create(); // Create new bundle object
- bundle_add(b, "key1", "val1"); // add a key-val pair
+ bundle_add_str(b, "key1", "val1"); //add a key-val pair
int count = bundle_get_count(b); // count=1
- bundle_add(b, "key2", "val2"); // add another key-val pair
+ bundle_add_str(b, "key2", "val2"); // add another key-val pair
count = bundle_get_count(b); // count=2
bundle_free(b);
*/
API int bundle_get_count(bundle *b);
-
/**
- * @brief Get a type of a value with certain key
- * @pre b must be a valid bundle object
- * @post None
- * @see bundle_type_t
+ * @brief Gets the type of a value with a given key.
+ * @since_tizen 2.3
+ * @remarks The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section.
* @param[in] b A bundle
- * @param[in] key A key in bundle
- * @return Type of a key in b
- * @remark
+ * @param[in] key A key in the bundle
+ * @return The type of a key in @a b
+ * @exception BUNDLE_ERROR_NONE Success
+ * @exception BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @exception BUNDLE_ERROR_KEY_NOT_AVAILABLE Key not available
+ * @pre @a b must be a valid bundle object.
+ * @see bundle_type_t
@code
@endcode
*/
API int bundle_get_type(bundle *b, const char *key);
-
/**
- * @brief Duplicate given bundle object
- * @pre b must be a valid bundle object.
- * @post None
- * @see None
- * @param[in] b_from bundle object to be duplicated
- * @return New bundle object
- * @retval NULL Failure
- * @remark None
+ * @internal
+ * @brief Duplicates a given bundle object.
+ * @since_tizen 2.3
+ * @remarks The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section.
+ * @param[in] b_from the bundle object to be duplicated
+ * @return The new bundle object
+ * @retval @c NULL - Failure
+ * @exception BUNDLE_ERROR_NONE Success
+ * @exception BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @pre @a b must be a valid bundle object.
@code
#include <bundle.h>
bundle *b = bundle_create(); // Create new bundle object
- bundle_add(b, "foo_key", "bar_val"); // add a key-val pair
- bundle *b_dup = bundle_dup(b); // duplicate b
+ bundle_add_str(b, "foo_key", "bar_val"); // add a key-val pair
+ bundle *b_dup = bundle_dup(b); // duplicate b
bundle_free(b);
bundle_free(b_dup);
API bundle * bundle_dup(bundle *b_from);
/**
- * @brief iterate callback function with each key/val pairs in bundle. (NOTE: Only BUNDLE_TYPE_STR type values come!)
- * @pre b must be a valid bundle object.
- * @post None
- * @see None
- * @param[in] b bundle object
- * @param[in] callback iteration callback function
- * @param[in] data data for callback function
- * @remark This function is obsolete, and does not give values whose types are not BUNDLE_TYPE_STR.
+ * @internal
+ * @brief Iterates a callback function for each key-value pairs in a given bundle.
+ * @details (NOTE: Only BUNDLE_TYPE_STR type values come!)
+ * @since_tizen 2.3
+ * @remarks The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section.
+ * @remarks This function is obsolete and does not give values whose types are not BUNDLE_TYPE_STR.
+ * @param[in] b The bundle object
+ * @param[in] callback The iteration callback function
+ * @param[in] cb_data The data for callback function
+ * @exception BUNDLE_ERROR_NONE Success
+ * @exception BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @pre @a b must be a valid bundle object.
@code
- @include <stdio.h>
+ #include <stdio.h>
#include <bundle.h>
void sample_cb(const char *k, const char *v, void *data) {
printf("%s -> %s\n", k, v);
int main(void) {
bundle *b = bundle_create(); // Create new bundle object
- bundle_add(b, "k1", "v1"); // add a key-val pair
- bundle_add(b, "k2", "v2"); // add a key-val pair
- bundle_add(b, "k3", "v3"); // add a key-val pair
- bundle_iterate(b, sample_cb, NULL); // iterate sample_cb for each key/val
+ bundle_add_str(b, "k1", "v1"); // add a key-val pair
+ bundle_add_str(b, "k2", "v2"); // add a key-val pair
+ bundle_add_str(b, "k3", "v3"); // add a key-val pair
+ bundle_iterate(b, sample_cb, NULL); // iterate sample_cb() for each key/val
return 0;
- }
+ }
@endcode
*/
API void bundle_iterate(bundle *b, bundle_iterate_cb_t callback, void *cb_data);
-
/**
- * @brief iterate callback function with each key/val pairs in bundle. (Supports all types of value)
- * @pre b must be a valid bundle object.
- * @post None
- * @see bundle_keyval_get_type bundle_keyval_type_is_array bundle_keyval_get_basic_val bundle_keyval_get_array_val
- * @param[in] b bundle object
- * @param[in] iter iteration callback function
- * @param[in] user_data data for callback function
- * @remark This function supports all types.
+ * @brief Iterates a callback function for each key-value pair in a given bundle.
+ * @details Supports all types of values.
+ * @since_tizen 2.3
+ * @remarks The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section.
+ * @remarks This function supports all types.
+ * @param[in] b The bundle object
+ * @param[in] iter The iteration callback function
+ * @param[in] user_data The data for the callback function
+ * @exception BUNDLE_ERROR_NONE Success
+ * @exception BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @pre @a b must be a valid bundle object.
+ * @see bundle_keyval_get_type()
+ * @see bundle_keyval_type_is_array()
+ * @see bundle_keyval_get_basic_val()
+ * @see bundle_keyval_get_array_val()
@code
- @include <stdio.h>
+ #include <stdio.h>
#include <bundle.h>
void sample_cb(const char *key, const int type, const bundle_keyval_t *kv, void *user_data) {
void *basic_val = NULL;
// Do something...
}
else {
- bundle_keyval_get_basic_val(kv, &basic_val, &size);
+ bundle_keyval_get_basic_val(kv, &basic_val, &basic_size);
// Do something...
}
}
-
+
int main(void) {
bundle *b = bundle_create(); // Create new bundle object
bundle_add_str(b, "k1", "v1"); // add a key-val pair
bundle_add_byte(b, "k2", "v2", 3); // add a key-val pair
char *s_arr[] = {"abc", "bcd", "cde"};
bundle_add_str_array(b, "k3", s_arr, 3); // add a key-val pair
- bundle_iterate(b, sample_cb, NULL); // iterate sample_cb for each key/val
+ bundle_foreach(b, sample_cb, NULL); // iterate sample_cb() for each key/val
return 0;
- }
+ }
@endcode
*/
API void bundle_foreach(bundle *b, bundle_iterator_t iter, void *user_data);
-
/**
- * @brief Get type for a bundle_keyval_t object.
- * @pre kv must be a valid bundle_keyval_t object.
- * @post None
- * @see bundle_foreach
+ * @brief Gets the type of a key-value pair.
+ * @since_tizen 2.3
+ * @remarks The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section.
* @param[in] kv A bundle_keyval_t object
- * @return Type of kv
- * @retval -1 Operation failure. errno is set.
- * @remark
+ * @return The type of @a kv
+ * @retval @c -1 - Failure
+ * @exception BUNDLE_ERROR_NONE Success
+ * @exception BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @pre @a kv must be a valid bundle_keyval_t object.
+ * @see bundle_foreach()
*/
API int bundle_keyval_get_type(bundle_keyval_t *kv);
-
/**
- * @brief Determine if kv is array type or not.
- * @pre kv must be a valid bundle_keyval_t object.
- * @post None
- * @see bundle_foreach
+ * @brief Determines whether the type of a key-value pair is array.
+ * @since_tizen 2.3
+ * @remarks The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section.
* @param[in] kv A bundle_keyval_t object
- * @return Operation result
- * @retval 1 kv is an array.
- * @retval 0 kv is not an array.
- * @remark
+ * @return The operation result
+ * @retval @c 1 - @a kv is an array
+ * @retval @c 0 - @a kv is not an array
+ * @exception BUNDLE_ERROR_NONE Success
+ * @exception BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @pre @a kv must be a valid bundle_keyval_t object.
+ * @see bundle_foreach()
*/
API int bundle_keyval_type_is_array(bundle_keyval_t *kv);
-
/**
- * @brief Determine if kv is measurable type or not.
- * @pre kv must be a valid bundle_keyval_t object.
- * @post None
- * @see bundle_foreach
+ * @internal
+ * @brief Determines whether the type of a key-value pair is measurable.
+ * @since_tizen 2.3
+ * @remarks The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section.
* @param[in] kv A bundle_keyval_t object
- * @return Operation result
- * @retval 1 kv is an measurable.
- * @retval 0 kv is not an measurable.
- * @remark
+ * @return The operation result
+ * @retval @c 1 - @a kv is an measurable
+ * @retval @c 0 - @a kv is not an measurable
+ * @exception BUNDLE_ERROR_NONE Success
+ * @exception BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @pre @a kv must be a valid bundle_keyval_t object.
+ * @see bundle_foreach()
*/
API int bundle_keyval_type_is_measurable(bundle_keyval_t *kv);
-
/**
- * @brief Get value and size of the value from kv of basic type.
- * @pre kv must be a valid bundle_keyval_t object.
- * @post val, size are set.
- * @see bundle_foreach
+ * @brief Gets the value and size of the value from a key-value pair of basic type.
+ * @since_tizen 2.3
+ * @remarks You must not free @a val.
* @param[in] kv A bundle_keyval_t object
- * @param[out] val Value
- * @param[out] size Size of val
- * @return Operation result
- * @retval 0 Success
- * @remark Do not free val.
+ * @param[out] val The value
+ * @param[out] size The size of @a val
+ * @return The operation result
+ * @retval BUNDLE_ERROR_NONE Success
+ * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @pre @a kv must be a valid bundle_keyval_t object.
+ * @post @a val and @a size are set.
+ * @see bundle_foreach()
*/
API int bundle_keyval_get_basic_val(bundle_keyval_t *kv, void **val, size_t *size);
-
/**
- * @brief Get value array, length of array, and size of each array item
- * @pre kv must be a valid bundle_keyval_t object.
- * @post array_val, array_len, array_item_size are set.
- * @see bundle_foreach
+ * @brief Gets the value array, length of the array, and size of each array item.
+ * @since_tizen 2.3
* @param[in] kv A bundle_keyval_t object
- * @param[out] array_val Array pointer of values
- * @param[out] array_len Length of array_val
- * @param[out] array_element_size Array of size of each array element
- * @return Operation result
- * @retval 0 Success
- * @retval 0 Failure
- * @remark
+ * @param[out] array_val The array pointer of values
+ * @param[out] array_len The length of @a array_val
+ * @param[out] array_element_size The array of size of each array element
+ * @return The operation result
+ * @retval BUNDLE_ERROR_NONE Success
+ * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @pre @a kv must be a valid bundle_keyval_t object.
+ * @post @a array_val, @a array_len, @a array_item_size are set.
+ * @see bundle_foreach()
*/
API int bundle_keyval_get_array_val(bundle_keyval_t *kv, void ***array_val, unsigned int *array_len, size_t **array_element_size);
-
/**
- * @brief Encode bundle to bundle_raw format (uses base64 format)
- * @pre b must be a valid bundle object.
- * @post None
- * @see None
- * @param[in] b bundle object
- * @param[out] r returned bundle_raw data(byte data)
- * r MUST BE FREED by free(r).
- * @param[out] len size of r (in bytes)
- * @return size of raw data
- * @retval 0 Success
- * @retval -1 Failure
- * @remark None
+ * @brief Encodes a bundle to the bundle_raw format (uses base64 format).
+ * @since_tizen 2.3
+ * @param[in] b The bundle object
+ * @param[out] r The returned bundle_raw data(byte data)
+ * @a r MUST BE FREED by free(r)
+ * @param[out] len The size of @a r (in bytes)
+ * @return The size of the raw data
+ * @retval BUNDLE_ERROR_NONE Success
+ * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @pre @a b must be a valid bundle object.
@code
#include <bundle.h>
bundle *b = bundle_create(); // Create new bundle object
- bundle_add(b, "foo_key", "bar_val"); // add a key-val pair
+ bundle_add_str(b, "foo_key", "bar_val"); // add a key-val pair
bundle_raw *r;
int len;
bundle_encode(b, &r, &len); // encode b
- bundle_free_encoded_rawdata(r);
bundle_free(b);
@endcode
*/
API int bundle_encode(bundle *b, bundle_raw **r, int *len);
/**
- * @brief Free encoded rawdata from memory
- * @pre r is a valid rawdata generated by bundle_encode().
- * @post None
- * @see bundle_encode
- * @param[in] r is a rawdata
- * @return Operation result
- * @retval 0 Success
- * @retval -1 Failure
- * @reamark None
+ * @internal
+ * @brief Frees the encoded rawdata.
+ * @since_tizen 2.3
+ * @param[in] r The rawdata
+ * @return The operation result
+ * @retval BUNDLE_ERROR_NONE Success
+ * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @pre @a r is a valid rawdata generated by bundle_encode().
+ * @see bundle_encode()
*/
API int bundle_free_encoded_rawdata(bundle_raw **r);
/**
- * @brief deserialize bundle_raw, and get bundle object
- * @pre b must be a valid bundle object.
- * @post None
- * @see None
- * @param[in] r bundle_raw data to be converted to bundle object
- * @param[in] len size of r
- * @return bundle object
- * @retval NULL Failure
- * @remark None
+ * @brief Deserializes bundle_raw and gets the bundle object.
+ * @since_tizen 2.3
+ * @remarks The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section.
+ * @param[in] r The bundle_raw data to be converted to bundle object
+ * @param[in] len The size of @a r
+ * @return The bundle object
+ * @retval @c NULL - Failure
+ * @exception BUNDLE_ERROR_NONE Success
+ * @exception BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @pre @a b must be a valid bundle object.
@code
#include <bundle.h>
bundle *b = bundle_create(); // Create new bundle object
- bundle_add(b, "foo_key", "bar_val"); // add a key-val pair
+ bundle_add_str(b, "foo_key", "bar_val"); // add a key-val pair
bundle_raw *encoded_b;
int len;
API bundle * bundle_decode(const bundle_raw *r, const int len);
/**
- * @brief Encode bundle to bundle_raw format
- * @pre b must be a valid bundle object.
- * @post None
- * @see None
- * @param[in] b bundle object
- * @param[out] r returned bundle_raw data(byte data)
- * r MUST BE FREED by free(r).
- * @param[out] len size of r (in bytes)
- * @return size of raw data
- * @retval 0 Success
- * @retval -1 Failure
- * @remark None
+ * @internal
+ * @brief Encodes a bundle to the bundle_raw format.
+ * @since_tizen 2.3
+ * @param[in] b The bundle object
+ * @param[out] r The returned bundle_raw data(byte data)
+ * @a r MUST BE FREED by free(r)
+ * @param[out] len The size of @a r (in bytes)
+ * @return The size of the raw data
+ * @retval BUNDLE_ERROR_NONE Success
+ * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval BUNDLE_ERROR_OUT_OF_MEMORY Out of memory
+ * @pre @a b must be a valid bundle object.
@code
#include <bundle.h>
bundle *b = bundle_create(); // Create new bundle object
- bundle_add(b, "foo_key", "bar_val"); // add a key-val pair
+ bundle_add_str(b, "foo_key", "bar_val"); // add a key-val pair
bundle_raw *r;
int len;
bundle_encode_raw(b, &r, &len); // encode b
- bundle_free_encoded_rawdata(r);
bundle_free(b);
@endcode
*/
API int bundle_encode_raw(bundle *b, bundle_raw **r, int *len);
/**
- * @brief deserialize bundle_raw, and get bundle object
- * @pre b must be a valid bundle object.
- * @post None
- * @see None
- * @param[in] r bundle_raw data to be converted to bundle object
- * @param[in] len size of r
- * @return bundle object
- * @retval NULL Failure
- * @remark None
+ * @internal
+ * @brief Deserializes bundle_raw and gets a bundle object.
+ * @since_tizen 2.3
+ * @remarks The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section.
+ * @param[in] r The bundle_raw data to be converted to a bundle object
+ * @param[in] len The size of @a r
+ * @return The bundle object
+ * @retval @c NULL - Failure
+ * @exception BUNDLE_ERROR_NONE Success
+ * @exception BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @pre @a b must be a valid bundle object.
@code
#include <bundle.h>
bundle *b = bundle_create(); // Create new bundle object
- bundle_add(b, "foo_key", "bar_val"); // add a key-val pair
+ bundle_add_str(b, "foo_key", "bar_val"); // add a key-val pair
bundle_raw *encoded_b;
int len;
API bundle * bundle_decode_raw(const bundle_raw *r, const int len);
/**
- * @brief Export bundle to argv
- * @pre b is a valid bundle object.
- * @post argv is a pointer of newly allocated memory. It must be freed.
- * Each item of argv points the string in the bundle object b. If b is freed, argv will have garbage pointers. DO NOT FREE b BEFORE ACCESSING argv!!
- * @see bundle_import_from_argv
- * @param[in] b bundle object
- * @param[out] argv Pointer of string array.
- * This array has NULL values for first and last item.
- * First NULL is for argv[0], and last NULL is a terminator for execv().
- * @return Number of item in argv. This value is equal to actual count of argv - 1. (Last NULL terminator is not counted.)
- * @retval -1 Function failure. Check errno to get the reason.
- * @remark None
+ * @internal
+ * @brief Exports bundle to @a argv.
+ * @since_tizen 2.3
+ * @remarks The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section.
+ * @param[in] b The bundle object
+ * @param[out] argv The pointer of the string array; \n
+ * This array has NULL values for the first and last item; \n
+ * First NULL is for argv[0], and last NULL is a terminator for execv() \n
+ * @return The number of item in @a argv. This value is equal to the actual count of argv - 1. (Last NULL terminator is not counted.)
+ * @retval @c -1 - Failure
+ * @exception BUNDLE_ERROR_NONE Success
+ * @exception BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @exception BUNDLE_ERROR_OUT_OF_MEMORY Out of memory
+ * @pre @a b is a valid bundle object.
+ * @post @a argv is a pointer of newly allocated memory. It must be freed.
+ * 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>
bundle *b = bundle_create(); // Create new bundle object
- bundle_add(b, "foo_key", "bar_val"); // add a key-val pair
+ bundle_add_str(b, "foo_key", "bar_val"); // add a key-val pair
int argc = 0;
char **argv = NULL;
argc = bundle_export_to_argv(b, &argv); // export to argv
if(0 > argc) error("export failure");
-
+
int i;
for(i=0; i < argc; i++) {
- printf("%s\n", argv[i]); // print argv
+ printf("%s\n", argv[i]); // print argv
}
bundle_free_exported_argv(argc, argv); // argv must be freed after being used.
API int bundle_export_to_argv(bundle *b, char ***argv);
/**
- * @brief Free exported argv
- * @pre argv is a valid string array generated from bundle_export_to_argv().
- * @post None
- * @see bundle_export_to_argv
- * @param[in] argc number of args, which is the return value of bundle_export_to_argv().
- * @param[in] argv array from bundle_export_to_argv().
- * @return Operation result.
- * @retval 0 on success
- * @retval -1 on failure
- * @remark You must not use this API when you use global argv.
+ * @internal
+ * @brief Frees the exported @a argv.
+ * @since_tizen 2.3
+ * @remarks You must not use this API when you use global @a argv.
+ * @param[in] argc The number of args, which is the return value of bundle_export_to_argv()
+ * @param[in] argv The array from bundle_export_to_argv()
+ * @return The operation result
+ * @retval BUNDLE_ERROR_NONE Success
+ * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @pre @a argv is a valid string array generated from bundle_export_to_argv().
+ * @see bundle_export_to_argv()
@code
bundle *b = bundle_create();
bundle_add_str(b, "foo", "bar");
-
+
int argc = 0;
char **argv = NULL;
argc = bundle_export_to_argv(b, &argv);
// Use argv...
- bundle_free_export_argv(argc, argv);
+ bundle_free_exported_argv(argc, argv);
argv = NULL;
bundle_free(b);
API int bundle_free_exported_argv(int argc, char ***argv);
/**
- * @brief import a bundle from argv
- * @pre argv is a valid string array, which is created by bundle_export_to_argv().
- * @post Returned bundle b must be freed.
- * @see bundle_export_to_argv
- * @param[in] argc argument count
- * @param[in] argv argument vector
- * @return New bundle object
- * @retval NULL Function failure
- * @remark None
+ * @internal
+ * @brief Imports a bundle from @a argv.
+ * @since_tizen 2.3
+ * @remarks The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section.
+ * @param[in] argc The argument count
+ * @param[in] argv The argument vector
+ * @return The new bundle object
+ * @retval @c NULL - Failure
+ * @exception BUNDLE_ERROR_NONE Success
+ * @exception BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @exception BUNDLE_ERROR_OUT_OF_MEMORY Out of memory
+ * @pre @a argv is a valid string array, which is created by bundle_export_to_argv().
+ * @post The returned bundle @a b must be freed.
+ * @see bundle_export_to_argv()
@code
#include <bundle.h>
API bundle * bundle_import_from_argv(int argc, char **argv);
/**
- * @brief Add a string type key-value pair into bundle.
- * @pre b must be a valid bundle object.
- * @post None
+ * @brief Adds a string type key-value pair into a bundle.
+ * @since_tizen 2.3
+ * @param[in] b The bundle object
+ * @param[in] key The key
+ * @param[in] str The string type value
+ * @return The operation result
+ * @retval BUNDLE_ERROR_NONE Success
+ * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval BUNDLE_ERROR_KEY_EXISTS Key already exists
+ * @retval BUNDLE_ERROR_OUT_OF_MEMORY Out of memory
+ * @pre @a b must be a valid bundle object.
* @see bundle_get_str()
- * @param[in] b bundle object
- * @param[in] key key
- * @param[in] str string type value
- * @return Operation result
- * @retval 0 success
- * @retval -1 failure
- *
- * @remark When -1 is returned, errno is set to one of the following values; \n
- EKEYREJECTED : key is rejected (NULL or sth) \n
- EPERM : key is already exist, not permitted to overwrite value \n
- EINVAL : b or val is not valid (NULL or sth) \n
@code
#include <bundle.h>
bundle *b = bundle_create(); // Create new bundle object
API int bundle_add_str(bundle *b, const char *key, const char *str);
/**
- * @brief Set a value of string array element
- * @pre b must be a valid bundle object.
- * @post None
+ * @internal
+ * @brief Sets a value of string array elements.
+ * @since_tizen 2.3
+ * @param[in] b The bundle object
+ * @param[in] key The key
+ * @param[in] idx The index of the array element to be changed
+ * @param[in] val The string type value; if @c NULL, an empty array is created; you can change an item with
+ * @return The operation result
+ * @retval BUNDLE_ERROR_NONE Success
+ * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @pre @a b must be a valid bundle object.
* @see bundle_add_str_array()
* @see bundle_get_str_array()
- * @param[in] b bundle object
- * @param[in] key key
- * @param[in] idx index of array element to be changed
- * @param[in] val string type value. If NULL, empty array is created. You can change an item with
- * @return Operation result
- * @retval 0 success
- * @retval -1 failure
- *
- * @remark When -1 is returned, errno is set to one of the following values; \n
- EKEYREJECTED : key is rejected (NULL or sth) \n
- EPERM : key is already exist, not permitted to overwrite value \n
- EINVAL : b or val is not valid (NULL or sth) \n
@code
#include <bundle.h>
bundle *b = bundle_create();
API int bundle_set_str_array_element(bundle *b, const char *key, const unsigned int idx, const char *val);
/**
- * @brief Add a byte type key-value pair into bundle.
- * @pre b must be a valid bundle object.
- * @post None
+ * @brief Adds a byte type key-value pair into a bundle.
+ * @since_tizen 2.3
+ * @param[in] b The bundle object
+ * @param[in] key The key
+ * @param[in] byte The string type value
+ * @param[in] size The size of @a byte
+ * @return The operation result
+ * @retval BUNDLE_ERROR_NONE Success
+ * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval BUNDLE_ERROR_KEY_EXISTS Key already exists
+ * @retval BUNDLE_ERROR_OUT_OF_MEMORY Out of memory
+ * @pre @a b must be a valid bundle object.
* @see bundle_get_byte()
- * @param[in] b bundle object
- * @param[in] key key
- * @param[in] byte string type value
- * @param[in] size size of byte
- * @return Operation result
- * @retval 0 success
- * @retval -1 failure
- *
- * @remark When -1 is returned, errno is set to one of the following values; \n
- EKEYREJECTED : key is rejected (NULL or sth) \n
- EPERM : key is already exist, not permitted to overwrite value \n
- EINVAL : b or val is not valid (NULL or sth) \n
@code
#include <bundle.h>
bundle *b = bundle_create(); // Create new bundle object
bundle_add_byte(b, "foo", "bar\0", 4); // add a key-val pair
+ int number = 12345;
+ bundle_add_byte(b, "number", &number, sizeof(int));
+
bundle_free(b);
@endcode
*/
-
API int bundle_add_byte(bundle *b, const char *key, const void *byte, const size_t size);
/**
- * @brief Add a byte array type key-value pair into bundle.
- * @pre b must be a valid bundle object.
- * @post None
- * @see bundle_get_str_array()
+ * @internal
+ * @brief Adds a byte array type key-value pair into a bundle.
+ * @since_tizen 2.3
+ * @param[in] b The bundle object
+ * @param[in] key The key
+ * @param[in] byte_array Not used
+ * @param[in] len The length of the array to be created
+ * @return The operation result
+ * @retval BUNDLE_ERROR_NONE Success
+ * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval BUNDLE_ERROR_KEY_EXISTS Key already exists
+ * @retval BUNDLE_ERROR_OUT_OF_MEMORY Out of memory
+ * @pre @a b must be a valid bundle object.
+ * @see bundle_get_byte_array()
* @see bundle_set_byte_array_element()
- * @param[in] b bundle object
- * @param[in] key key
- * @param[in] byte_array Not used.
- * @param[in] len Length of array to be created
- * @return Operation result
- * @retval 0 success
- * @retval -1 failure
- *
- * @remark When -1 is returned, errno is set to one of the following values; \n
- EKEYREJECTED : key is rejected (NULL or sth) \n
- EPERM : key is already exist, not permitted to overwrite value \n
- EINVAL : b or val is not valid (NULL or sth) \n
@code
#include <bundle.h>
bundle *b = bundle_create();
API int bundle_add_byte_array(bundle *b, const char *key, void **byte_array, const unsigned int len);
/**
- * @brief Set a value of byte array element
- * @pre b must be a valid bundle object.
- * @post None
- * @see bundle_add_str_array()
- * @see bundle_get_str_array()
- * @param[in] b bundle object
- * @param[in] key key
- * @param[in] idx index of array element to be changed
- * @param[in] val string type value. If NULL, empty array is created. You can change an item with
- * @param[in] size Size of value in byte
+ * @internal
+ * @brief Sets the value of the byte array element.
+ * @since_tizen 2.3
+ * @param[in] b The bundle object
+ * @param[in] key The key
+ * @param[in] idx The index of the array element to be changed
+ * @param[in] val The string type value; if @c NULL, an empty array is created; you can change an item with
+ * @param[in] size The size of the value in bytes
* @return Operation result
- * @retval 0 success
- * @retval -1 failure
- *
- * @remark When -1 is returned, errno is set to one of the following values; \n
- EKEYREJECTED : key is rejected (NULL or sth) \n
- EPERM : key is already exist, not permitted to overwrite value \n
- EINVAL : b or val is not valid (NULL or sth) \n
+ * @retval BUNDLE_ERROR_NONE Success
+ * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval BUNDLE_ERROR_KEY_NOT_AVAILABLE Key not available
+ * @pre @a b must be a valid bundle object.
+ * @see bundle_add_byte_array()
+ * @see bundle_get_byte_array()
@code
#include <bundle.h>
bundle *b = bundle_create();
bundle_add_byte_array(b, "foo", NULL, 3); // add a key-val pair
+
bundle_set_byte_array_element(b, "foo", 0, "aaa\0", 4);
bundle_set_byte_array_element(b, "foo", 1, "bbb\0", 4);
bundle_set_byte_array_element(b, "foo", 2, "ccc\0", 4);
unsigned char **byte_array = NULL;
int len_byte_array = 0;
- byte_array=bundle_get_str_array(b, "foo", &len_byte_array);
+ bundle_get_byte_array(b, "foo", &byte_array, &len_byte_array, &size_byte_array);
// byte_array = { "aaa\0", "bbb\0", "ccc\0" }, and len_byte_array = 3
bundle_free(b);
API int bundle_set_byte_array_element(bundle *b, const char *key, const unsigned int idx, const void *val, const size_t size);
/**
- * @brief Get string value from key
- * @pre b must be a valid bundle object.
- * @post None
+ * @brief Gets the string value with the given key.
+ * @since_tizen 2.3
+ * @remarks You must not free str!
+ * @param[in] b The bundle object
+ * @param[in] key The key
+ * @param[out] str The returned value
+ * @return The operation result
+ * @retval BUNDLE_ERROR_NONE Success
+ * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval BUNDLE_ERROR_KEY_NOT_AVAILABLE Key not available
+ * @pre @a b must be a valid bundle object.
* @see bundle_add_str()
- * @param[in] b bundle object
- * @param[in] key key
- * @param[out] str returned value
- * @return Operation result
- * @retval 0 on success
- * @retval -1 on failure
- * @remark Do not free str!
- When -1 is returned, errno is set to one of the following values; \n
- EINVAL : b is invalid \n
- ENOKEY : No key exists \n
- EKEYREJECTED : invalid key (NULL or sth) \n
@code
#include <bundle.h>
bundle *b = bundle_create(); // Create new bundle object
API int bundle_get_str(bundle *b, const char *key, char **str);
/**
- * @brief Get byte value from key
- * @pre b must be a valid bundle object.
- * @post None
+ * @brief Gets the byte value with the given key.
+ * @since_tizen 2.3
+ * @remarks You must not free @a byte!
+ * @param[in] b The bundle object
+ * @param[in] key The key
+ * @param[out] byte The returned value
+ * @param[out] size The size of the byte
+ * @return The operation result
+ * @retval BUNDLE_ERROR_NONE Success
+ * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval BUNDLE_ERROR_KEY_NOT_AVAILABLE Key not available
+ * @pre @a b must be a valid bundle object.
* @see bundle_add_byte()
- * @param[in] b bundle object
- * @param[in] key key
- * @param[out] byte returned value
- * @param[out] size Size of byte
- * @return Operation result
- * @retval 0 on success
- * @retval -1 on failure
- * @remark Do not free str!
- When -1 is returned, errno is set to one of the following values; \n
- EINVAL : b is invalid \n
- ENOKEY : No key exists \n
- EKEYREJECTED : invalid key (NULL or sth) \n
@code
#include <bundle.h>
bundle *b = bundle_create(); // Create new bundle object
- bundle_add_byte(b, "foo", "bar\0", 4); // add a key-val pair
+ bundle_add_byte(b, "foo", "bar\0", 4); // add string to bundle
+ int number = 12345;
+ bundle_add_byte(b, "number", (const void**)&number, sizeof(int)); // add integer to bundle
unsigned char *v = NULL;
- bundle_get_str(b, "foo", &v); // v = "bar\0"
+ size_t v_size;
+ bundle_get_byte(b, "foo", (void**)&v, &v_size); // v = "bar\0"
+ int *n = NULL;
+ size_t n_size;
+ bundle_get_byte(b, "number", (void**)&n, &n_size); // number = 12345
- bundle_free(b); // After freeing b, v becomes a dangling pointer.
+ bundle_free(b); // After freeing b, v and n becomes a dangling pointer.
@endcode
*/
API int bundle_get_byte(bundle *b, const char *key, void **byte, size_t *size);
/**
- * @brief Get byte array value from key
- * @pre b must be a valid bundle object.
- * @post None
- * @see bundle_add_str_array()
- * @see bundle_set_str_array_element()
- * @param[in] b bundle object
- * @param[in] key key
- * @param[out] byte_array returned value
- * @param[out] len array length
- * @param[out] array_element_size an array of sizes of each byte_array element
- * @return Operation result
- * @retval 0 on success
- * @retval -1 on failure
- * @remark Do not free str!
- When -1 is returned, errno is set to one of the following values; \n
- EINVAL : b is invalid \n
- ENOKEY : No key exists \n
- EKEYREJECTED : invalid key (NULL or sth) \n
+ * @internal
+ * @brief Gets the byte array value with the given key.
+ * @since_tizen 2.3
+ * @remarks You must not free str!
+ * @param[in] b The bundle object
+ * @param[in] key The key
+ * @param[out] byte_array The returned value
+ * @param[out] len The array length
+ * @param[out] array_element_size an array of sizes of each @a byte_array element
+ * @return The operation result
+ * @retval BUNDLE_ERROR_NONE Success
+ * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval BUNDLE_ERROR_KEY_NOT_AVAILABLE Key not available
+ * @pre @a b must be a valid bundle object.
+ * @see bundle_add_byte_array()
+ * @see bundle_set_byte_array_element()
@code
#include <bundle.h>
bundle *b = bundle_create();
int len_byte_array = 0;
size_t *size_byte_array = NULL;
- byte_array = bundle_get_str_array(b, "foo", &len_byte_array, &size_byte_array);
+ bundle_get_byte_array(b, "foo", &byte_array, &len_byte_array, &size_byte_array);
// byte_array = { "aaa\0", "bbb\0", "ccc\0" }, len_byte_array = 3, and size_byte_array = { 4, 4, 4 }
bundle_free(b);
#include <stdlib.h> /* calloc, free */
#include <string.h> /* strdup */
-#include <errno.h>
#define CHECKSUM_LENGTH 32
#define TAG_IMPORT_EXPORT_CHECK "`zaybxcwdveuftgsh`"
_bundle_find_kv(bundle *b, const char *key)
{
keyval_t *kv;
-
- if(NULL == b) { errno = EINVAL; return NULL; }
- if(NULL == key) { errno = EKEYREJECTED; return NULL; }
+ if(NULL == b) {
+ set_last_result(BUNDLE_ERROR_INVALID_PARAMETER);
+ return NULL;
+ }
+ if(NULL == key) {
+ set_last_result(BUNDLE_ERROR_INVALID_PARAMETER);
+ return NULL;
+ }
kv = b->kv_head;
while (kv != NULL) {
if(0 == strcmp(key, kv->key)) return kv;
kv = kv->next;
- }
+ }
/* Not found */
- errno = ENOKEY;
+ set_last_result(BUNDLE_ERROR_KEY_NOT_AVAILABLE);
return NULL;
}
while (NULL != kv->next) kv = kv->next;
kv->next = new_kv;
}
- return 0;
+ return BUNDLE_ERROR_NONE;
}
static int
_bundle_add_kv(bundle *b, const char *key, const void *val, const size_t size, const int type, const unsigned int len)
{
/* basic value check */
- if(NULL == b) { errno = EINVAL; return -1; }
- if(NULL == key) { errno = EKEYREJECTED; return -1; }
- if(0 == strlen(key)) { errno = EKEYREJECTED; return -1; }
+ if(NULL == b)
+ return BUNDLE_ERROR_INVALID_PARAMETER;
+ if(NULL == key)
+ return BUNDLE_ERROR_INVALID_PARAMETER;
+ if(0 == strlen(key))
+ return BUNDLE_ERROR_INVALID_PARAMETER;
keyval_t *kv = _bundle_find_kv(b, key);
if(kv) { /* Key already exists */
- errno = EPERM;
- return -1;
+ return BUNDLE_ERROR_KEY_EXISTS;
}
- errno = 0;
keyval_t *new_kv = NULL;
if(keyval_type_is_array(type)) {
new_kv = keyval_new(NULL, key, type, val, size);
}
if(!new_kv) {
- // NOTE: errno is already set. (ENOMEM, ...)
- return -1;
+ return BUNDLE_ERROR_OUT_OF_MEMORY;
}
_bundle_append_kv(b, new_kv);
- return 0;
+ return BUNDLE_ERROR_NONE;
}
{
keyval_t *kv = _bundle_find_kv(b, key);
if(!kv) { /* Key doesn't exist */
- /* NOTE: errno is already set. */
- return -1;
+ return get_last_result();
}
if(BUNDLE_TYPE_ANY != type && type != kv->type) {
- errno = ENOTSUP;
- return -1;
+ return BUNDLE_ERROR_INVALID_PARAMETER;
}
if(keyval_type_is_array(type)) {
keyval_get_data(kv, NULL, val, size);
}
- return 0;
+ return BUNDLE_ERROR_NONE;
}
/** global initialization
{
static int _is_done = 0;
if(_is_done) return;
-
+
// Run init functions
keyval_type_init();
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");
- errno = ENOMEM;
+ set_last_result(BUNDLE_ERROR_OUT_OF_MEMORY);
goto EXCEPTION;
}
+ set_last_result(BUNDLE_ERROR_NONE);
return b;
EXCEPTION:
int
bundle_free(bundle *b)
{
- keyval_t *kv, *tmp_kv;
+ keyval_t *kv, *tmp_kv;
if(NULL == b) {
BUNDLE_EXCEPTION_PRINT("Bundle is already freed\n");
- errno = EINVAL;
- return -1;
+ return BUNDLE_ERROR_INVALID_PARAMETER;
}
/* Free keyval list */
/* free bundle */
free(b);
- return 0;
+ return BUNDLE_ERROR_NONE;
}
// str type
int
bundle_add_str(bundle *b, const char *key, const char *str)
{
- if(!str) { errno = EINVAL; return -1; }
+ if(!str)
+ return BUNDLE_ERROR_INVALID_PARAMETER;
return _bundle_add_kv(b, key, str, strlen(str)+1, BUNDLE_TYPE_STR, 1);
}
keyval_t *kv = NULL, *prev_kv = NULL;
/* basic value check */
- if(NULL == b) { errno = EINVAL; return -1; }
- if(NULL == key) { errno = EKEYREJECTED; return -1; }
- if(0 == strlen(key)) { errno = EKEYREJECTED; return -1; }
+ if(NULL == b)
+ return BUNDLE_ERROR_INVALID_PARAMETER;
+ if(NULL == key)
+ return BUNDLE_ERROR_INVALID_PARAMETER;
+ if(0 == strlen(key))
+ return BUNDLE_ERROR_INVALID_PARAMETER;
kv = b->kv_head;
while (kv != NULL) {
if(0 == strcmp(key, kv->key)) break;
prev_kv = kv;
kv = kv->next;
- }
- if (NULL == kv) { errno = ENOKEY; return -1; }
+ }
+ if (NULL == kv)
+ return BUNDLE_ERROR_KEY_NOT_AVAILABLE;
else {
if(NULL != prev_kv) {
prev_kv->next = kv->next;
if(kv == b->kv_head) b->kv_head = kv->next;
kv->method->free(kv, 1);
}
- return 0;
+ return BUNDLE_ERROR_NONE;
}
bundle_get_val(bundle *b, const char *key)
{
char *val = NULL;
- int r = 0;
+ int ret = 0;
+ ret = bundle_get_str(b, key, &val);
+ set_last_result(ret);
- r = bundle_get_str(b, key, &val);
return val;
}
void
bundle_iterate(bundle *b, bundle_iterate_cb_t callback, void *data)
{
- keyval_t *kv = b->kv_head;
- if(callback) {
- while(NULL != kv) {
- callback(kv->key, kv->val, data);
- kv = kv->next;
- }
+ keyval_t *kv;
+
+ if (NULL == b || NULL == callback) {
+ set_last_result(BUNDLE_ERROR_INVALID_PARAMETER);
+ return;
}
+
+ kv = b->kv_head;
+ while (NULL != 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)
{
- if(NULL==b)
- {
+ if (NULL == b || NULL == iter) {
+ set_last_result(BUNDLE_ERROR_INVALID_PARAMETER);
return; /*TC_FIX if b=NULL- error handling */
}
+
keyval_t *kv = b->kv_head;
- if(iter) {
- while(NULL != kv) {
- iter(kv->key, kv->type, kv, user_data);
- kv = kv->next;
- }
+ while (NULL != kv) {
+ iter(kv->key, kv->type, kv, user_data);
+ kv = kv->next;
}
+ set_last_result(BUNDLE_ERROR_NONE);
}
/* keyval functions */
-int
+int
bundle_keyval_get_type(bundle_keyval_t *kv)
{
+ if(NULL == kv)
+ {
+ set_last_result(BUNDLE_ERROR_INVALID_PARAMETER);
+ return -1;
+ }
+ set_last_result(BUNDLE_ERROR_NONE);
return kv->type;
}
-int
+int
bundle_keyval_type_is_array(bundle_keyval_t *kv)
{
+ if(NULL == kv)
+ {
+ set_last_result(BUNDLE_ERROR_INVALID_PARAMETER);
+ return -1;
+ }
+ set_last_result(BUNDLE_ERROR_NONE);
return keyval_type_is_array(kv->type);
}
-int
+int
bundle_keyval_type_is_measurable(bundle_keyval_t *kv)
{
+ if(NULL == kv)
+ {
+ set_last_result(BUNDLE_ERROR_INVALID_PARAMETER);
+ return -1;
+ }
+ set_last_result(BUNDLE_ERROR_NONE);
return keyval_type_is_measurable(kv->type);
}
-int
+int
bundle_keyval_get_basic_val(bundle_keyval_t *kv, void **val, size_t *size)
{
return keyval_get_data(kv, NULL, val, size);
}
-int
+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);
bundle *b_to = NULL;
int i;
- if(NULL == b_from) { errno = EINVAL; return NULL; }
+ if(NULL == b_from) {
+ set_last_result(BUNDLE_ERROR_INVALID_PARAMETER);
+ return NULL;
+ }
b_to = bundle_create();
- if(NULL == b_to) return NULL;
+ if(NULL == b_to)
+ return NULL;
keyval_t *kv_from = b_from->kv_head;
keyval_t *kv_to = NULL;
size_t byte_len;
gchar *chksum_val;
- if(NULL == b) {
- errno = EINVAL;
- return -1;
- }
+ if (NULL == b || NULL == r || NULL == len)
+ return BUNDLE_ERROR_INVALID_PARAMETER;
+
+ if(NULL == r)
+ return BUNDLE_ERROR_INVALID_PARAMETER;
+
+ if(NULL == len)
+ return BUNDLE_ERROR_INVALID_PARAMETER;
/* calculate memory size */
size_t msize = 0; // Sum of required size
kv = kv->next;
}
m = calloc(msize+CHECKSUM_LENGTH, sizeof(unsigned char));
- if(unlikely(NULL == m )) { errno = ENOMEM; return -1; }
+ if(unlikely(NULL == m ))
+ return BUNDLE_ERROR_INVALID_PARAMETER;
p_m = m+CHECKSUM_LENGTH; /* temporary pointer */
}
/*compute checksum from the data*/
- chksum_val = g_compute_checksum_for_string(G_CHECKSUM_MD5,m+CHECKSUM_LENGTH,msize);
+ chksum_val = g_compute_checksum_for_string(G_CHECKSUM_MD5, (const char *)(m+CHECKSUM_LENGTH), msize);
/*prefix checksum to the data */
memcpy(m,chksum_val,CHECKSUM_LENGTH);
if ( NULL != r ) {
free(m);
g_free(chksum_val);/*free checksum string */
- return 0;
+ return BUNDLE_ERROR_NONE;
}
int
bundle_free_encoded_rawdata(bundle_raw **r)
{
- if(!*r) return -1; /*TC_FIX - double free sigabrt handling */
+ if(!*r)
+ return BUNDLE_ERROR_INVALID_PARAMETER; /*TC_FIX - double free sigabrt handling */
free(*r);
*r=NULL;
- return 0;
+ return BUNDLE_ERROR_NONE;
}
bundle *
gchar* compute_cksum;
if(NULL == r) {
- errno = EINVAL;
+ set_last_result(BUNDLE_ERROR_INVALID_PARAMETER);
return NULL;
}
extract_cksum = calloc(CHECKSUM_LENGTH+1, sizeof(char));
if(unlikely(NULL== extract_cksum))
{
- errno = ENOMEM;
+ set_last_result(BUNDLE_ERROR_INVALID_PARAMETER);
return NULL;
}
/* base 64 decode of input string*/
d_str = g_base64_decode((char*)r, &d_len_raw);
/*extract checksum from the received string */
- strncpy(extract_cksum,d_str,CHECKSUM_LENGTH);
+ strncpy(extract_cksum,(const char*)d_str,CHECKSUM_LENGTH);
/* compute checksum for the data */
- compute_cksum = g_compute_checksum_for_string(G_CHECKSUM_MD5,d_str+CHECKSUM_LENGTH,d_len_raw-CHECKSUM_LENGTH);
+ 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 string and computed from the data */
if(strcmp(extract_cksum,compute_cksum)!=0)
{
g_free(compute_cksum);
free(d_str);
+ set_last_result(BUNDLE_ERROR_NONE);
return b;
}
gchar *chksum_val = NULL;
if(NULL == b || NULL == r) {
- errno = EINVAL;
- return -1;
+ return BUNDLE_ERROR_INVALID_PARAMETER;
}
/* calculate memory size */
kv = kv->next;
}
m = calloc(msize+CHECKSUM_LENGTH, sizeof(unsigned char));
- if(unlikely(NULL == m )) { errno = ENOMEM; return -1; }
+ if(unlikely(NULL == m ))
+ return BUNDLE_ERROR_OUT_OF_MEMORY;
p_m = m+CHECKSUM_LENGTH; /* temporary pointer */
}
/*compute checksum from the data*/
- chksum_val = g_compute_checksum_for_string(G_CHECKSUM_MD5,m+CHECKSUM_LENGTH,msize);
+ chksum_val = g_compute_checksum_for_string(G_CHECKSUM_MD5, (const char *)(m+CHECKSUM_LENGTH), msize);
/*prefix checksum to the data */
memcpy(m,chksum_val,CHECKSUM_LENGTH);
/*if ( NULL != r ) {
*len = msize+CHECKSUM_LENGTH;
g_free(chksum_val);/*free checksum string */
- return 0;
+ return BUNDLE_ERROR_NONE;
}
bundle *
gchar* compute_cksum = NULL;
if(NULL == r) {
- errno = EINVAL;
+ set_last_result(BUNDLE_ERROR_INVALID_PARAMETER);
return NULL;
}
extract_cksum = calloc(CHECKSUM_LENGTH+1, sizeof(char));
if(unlikely(NULL== extract_cksum))
{
- errno = ENOMEM;
+ set_last_result(BUNDLE_ERROR_OUT_OF_MEMORY);
return NULL;
}
/* base 64 decode of input string*/
//d_str = g_base64_decode((char*)r, &d_len_raw);
- d_str = r;
+ d_str = (unsigned char *)r;
d_len_raw = data_size;
/*extract checksum from the received string */
- strncpy(extract_cksum,d_str,CHECKSUM_LENGTH);
+ strncpy(extract_cksum,(const char*)d_str,CHECKSUM_LENGTH);
/* compute checksum for the data */
- compute_cksum = g_compute_checksum_for_string(G_CHECKSUM_MD5,d_str+CHECKSUM_LENGTH,d_len_raw-CHECKSUM_LENGTH);
+ 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 string and computed from the data */
if(strcmp(extract_cksum,compute_cksum)!=0)
{
free(extract_cksum);
g_free(compute_cksum);
+ set_last_result(BUNDLE_ERROR_INVALID_PARAMETER);
return NULL;
}
d_r = d_str+CHECKSUM_LENGTH;
g_free(compute_cksum);
//free(d_str);
+ set_last_result(BUNDLE_ERROR_NONE);
return b;
}
-void
+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;
BUNDLE_EXCEPTION_PRINT("bundle: failed to encode byte\n");
return;
}
-
+
vi->argv[vi->idx + 1] =(char*)encoded_byte;
(vi->idx) += 2;
{
int argc, item_count;
+ if ( b == NULL || argv == NULL ) {
+ set_last_result(BUNDLE_ERROR_INVALID_PARAMETER);
+ return -1;
+ }
+
item_count = bundle_get_count(b);
argc = 2 * item_count + 2; /* 2 more count for argv[0] and arv[1] = encoded */
*argv = calloc(argc + 1, sizeof(char *));
- if(!*argv) return -1;
+ if(!*argv) {
+ set_last_result(BUNDLE_ERROR_OUT_OF_MEMORY);
+ return -1;
+ }
struct _argv_idx vi;
vi.argc = argc;
bundle_foreach(b, _iter_export_to_argv, &vi);
+ set_last_result(BUNDLE_ERROR_NONE);
return argc;
}
int bundle_free_exported_argv(int argc, char ***argv)
{
- if(!*argv) return -1; /*TC_FIX : fix for double free- sigabrt */
-
+ if(1 > argc)
+ return BUNDLE_ERROR_INVALID_PARAMETER;
+
+ if (!*argv || argc < 2)
+ return BUNDLE_ERROR_INVALID_PARAMETER;
+
int i;
- for(i=1; i < argc; i+=2) {
- free((*argv)[i+1]);
+ for(i=3; i < argc; i+=2) {
+ free((*argv)[i]); /* need to free value from g_base64_encode() */
}
free(*argv);
*argv= NULL;
- return 0;
+ return BUNDLE_ERROR_NONE;
}
bundle *
bundle_import_from_argv(int argc, char **argv)
{
- if(!argv) return NULL; /* TC_FIX error handling for argv =NULL*/
+ if(!argv) {
+ set_last_result(BUNDLE_ERROR_INVALID_PARAMETER);
+ return NULL; /* TC_FIX error handling for argv =NULL*/
+ }
bundle *b = bundle_create();
if(!b) return NULL;
// base64_decode
byte = g_base64_decode(encoded_byte, &byte_size);
if(NULL == byte) {
- if(b) bundle_free(b);
+ if(b)
+ set_last_result(bundle_free(b));
return NULL;
}
free(byte);
byte = NULL;
}
+ set_last_result(BUNDLE_ERROR_NONE);
return b;
}
keyval_t *kv = _bundle_find_kv(b, key);
if(kv) return kv->type;
else {
- errno = ENOKEY;
+ set_last_result(BUNDLE_ERROR_KEY_NOT_AVAILABLE);
return BUNDLE_TYPE_NONE;
}
}
unsigned int
bundle_get_array_len(bundle *b, const char *key)
{
- return 0;
+ return BUNDLE_ERROR_NONE;
}
/** 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)
{
- return 0;
+ return BUNDLE_ERROR_NONE;
}
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)
//void **array = NULL;
keyval_t *kv = _bundle_find_kv(b, key);
- if(NULL == kv) return -1;
+ if(NULL == kv)
+ return get_last_result();
if(type != kv->type) {
- errno = EINVAL;
- return -1;
+ return BUNDLE_ERROR_INVALID_PARAMETER;
}
if(! keyval_type_is_array(kv->type)) { // TODO: Is this needed?
- errno = EINVAL;
- return -1;
+ return BUNDLE_ERROR_INVALID_PARAMETER;
}
keyval_array_t *kva = (keyval_array_t *)kv;
if(! keyval_array_is_idx_valid(kva, idx)) {
- errno = EINVAL;
- return -1;
+ return BUNDLE_ERROR_INVALID_PARAMETER;
}
if(!kva->array_val) { // NULL value test (TODO: is this needed?)
- errno = ENOMEM;
- return -1;
+ return BUNDLE_ERROR_INVALID_PARAMETER;
}
- return keyval_array_set_element(kva, idx, val, size);
+ return keyval_array_set_element(kva, idx, (void *)val, size);
}
const char ** bundle_get_str_array(bundle *b, const char *key,int *len)
{
+ int ret = BUNDLE_ERROR_NONE;
const char **arr_val = NULL;
- int r = 0;
- r = bundle_get_val_array(b,key,(char***)&arr_val,len);
- return arr_val;
+ ret = bundle_get_val_array(b,key,(char***)&arr_val,len);
+ set_last_result(ret);
+ return arr_val;
}
bundle_set_str_array_element(bundle *b, const char *key, const unsigned int idx, const char *val)
{
if(!val) {
- errno = EINVAL;
- return -1;
+ return BUNDLE_ERROR_INVALID_PARAMETER;
}
return bundle_set_array_val(b, key, BUNDLE_TYPE_STR_ARRAY, idx, val, strlen(val)+1);
}
-// byte type
+// byte type
int
bundle_add_byte(bundle *b, const char *key, const void *byte, const size_t size)
{