4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7 * Jaeho Lee <jaeho81.lee@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
30 * @brief This file declares API of bundle library
34 * @addtogroup APPLICATION_FRAMEWORK
40 * @section Header to use them:
56 #define API __attribute__((visibility("default")))
57 #define likely(x) __builtin_expect(x,1)
58 #define unlikely(x) __builtin_expect(x,0)
61 * bundle is an opaque type pointing a bundle object
63 typedef struct _bundle_t bundle;
66 * bundle_raw is an encoded data type
67 * @see bundle_encode()
68 * @see bundle_decode()
70 typedef unsigned char bundle_raw;
74 * Each bundle keyval have a type.
76 enum bundle_type_property {
77 BUNDLE_TYPE_ARRAY = 0x0100,
78 BUNDLE_TYPE_PRIMITIVE = 0x0200,
79 BUNDLE_TYPE_MEASURABLE = 0x0400
83 BUNDLE_TYPE_NONE = -1,
85 BUNDLE_TYPE_STR = 1 | BUNDLE_TYPE_MEASURABLE, /* Default */
86 BUNDLE_TYPE_STR_ARRAY = BUNDLE_TYPE_STR | BUNDLE_TYPE_ARRAY | BUNDLE_TYPE_MEASURABLE,
88 BUNDLE_TYPE_BYTE_ARRAY = BUNDLE_TYPE_BYTE | BUNDLE_TYPE_ARRAY
92 * A keyval object in a bundle.
93 * @see bundle_iterator_t
95 typedef struct keyval_t bundle_keyval_t;
99 * bundle_iterator is a new iterator function type for bundle_foreach()
100 * @see bundle_foreach()
102 typedef void (*bundle_iterator_t) (
105 const bundle_keyval_t *kv,
111 * bundle_iterate_cb_t is an iterator function type for bundle_iterate()
112 * @see bundle_iterate()
113 * @remark This type is obsolete. Do not use this type any more.
115 typedef void (*bundle_iterate_cb_t) (const char *key, const char *val, void *data);
119 * @brief Create a bundle object.
123 * @return bundle object
124 * @retval NULL on failure creating an object
125 * @remark When NULL is returned, errno is set to one of the following values; \n
126 * ENOMEM : No memory to create an object
130 bundle *b = bundle_create(); // Create new bundle object
131 bundle_free(b); // free bundle
134 API bundle* bundle_create(void);
137 * @brief Free given bundle object with key/values in it
138 * @pre b must be a valid bundle object.
140 * @see bundle_create()
141 * @param[in] b bundle object to be freed
142 * @return Operation result;
148 bundle *b = bundle_create(); // Create new bundle object
149 bundle_free(b); // free bundle
152 API int bundle_free(bundle *b);
154 * @brief Add a string array type key-value pair into bundle.
155 * @pre b must be a valid bundle object.
157 * @see bundle_get_str_array()
158 * @see bundle_set_str_array_element()
159 * @param[in] b bundle object
161 * @param[in] str_array string type value. If NULL, empty array is created. You can change an item with
162 * @param[in] len Length of array.
163 * @return Operation result
167 * @remark When -1 is returned, errno is set to one of the following values; \n
168 EKEYREJECTED : key is rejected (NULL or sth) \n
169 EPERM : key is already exist, not permitted to overwrite value \n
170 EINVAL : b or val is not valid (NULL or sth) \n
173 char *sa = { "aaa", "bbb", "ccc" }; // A string array of length 3
174 bundle *b = bundle_create();
175 bundle_add_str_array(b, "foo", sa, 3); // add a key-val pair
179 API int bundle_add_str_array(bundle *b, const char *key, const char **str_array, const int len);
181 * @brief Add a string type key-value pair into bundle.
182 * @pre b must be a valid bundle object.
184 * @see bundle_add_str()
185 * @param[in] b bundle object
187 * @param[in] val value
188 * @return Operation result
192 * @remark When -1 is returned, errno is set to one of the following values; \n
193 EKEYREJECTED : key is rejected (NULL or sth) \n
194 EPERM : key is already exist, not permitted to overwrite value \n
195 EINVAL : b or val is not valid (NULL or sth) \n
198 bundle *b = bundle_create(); // Create new bundle object
199 bundle_add(b, "foo_key", "bar_val"); // add a key-val pair
204 API int bundle_add(bundle *b, const char *key, const char *val);
207 * @brief Delete val with given key
208 * @pre b must be a valid bundle object.
211 * @param[in] b bundle object
212 * @param[in] key given key
213 * @return Operation result
217 * @remark When -1 is returned, errno is set to one of the following values; \n
218 EINVAL : b is invalid (NULL or sth) \n
219 ENOKEY : No key exist \n
220 EKEYREJECTED : key is invalid (NULL or sth) \n
223 bundle *b = bundle_create(); // Create new bundle object
224 bundle_add(b, "foo_key", "bar_val"); // add a key-val pair
225 bundle_del(b, "foo_key"); // del "foo_key" from b
230 API int bundle_del(bundle *b, const char* key);
232 * @brief Get string array value from key
233 * @pre b must be a valid bundle object.
235 * @see bundle_add_str_array()
236 * @see bundle_set_str_array_element()
237 * @param[in] b bundle object
239 * @param[out] len array length
240 * @return Pointer to array of string
241 * @retval NULL If key is not found, returns NULL.
242 * @remark DO NOT free or modify returned string!
243 When NULL is returned, errno is set to one of the following values; \n
244 EINVAL : b is invalid \n
245 ENOKEY : No key exists \n
246 EKEYREJECTED : invalid key (NULL or sth) \n
249 bundle *b = bundle_create();
250 bundle_add_str_array(b, "foo", NULL, 3); // add a key-val pair
251 bundle_set_str_array_element(b, "foo", 0, "aaa");
252 bundle_set_str_array_element(b, "foo", 1, "bbb");
253 bundle_set_str_array_element(b, "foo", 2, "ccc");
255 char **str_array = NULL;
256 int len_str_array = 0;
258 str_array=bundle_get_str_array(b, "foo", &len_str_array);
259 // str_array = { "aaa", "bbb", "ccc" }, and len_str_array = 3
265 API const char** bundle_get_str_array(bundle *b, const char *key,int *len);
267 * @brief Get value from key
268 * @pre b must be a valid bundle object.
270 * @see bundle_get_str()
271 * @param[in] b bundle object
273 * @return Pointer for value string
274 * @retval NULL If key is not found, returns NULL.
275 * @remark DO NOT free or modify returned string!
276 When NULL is returned, errno is set to one of the following values; \n
277 EINVAL : b is invalid \n
278 ENOKEY : No key exists \n
279 EKEYREJECTED : invalid key (NULL or sth) \n
282 bundle *b = bundle_create(); // Create new bundle object
283 bundle_add(b, "foo_key", "bar_val"); // add a key-val pair
284 char *val = bundle_get_val(b, "foo_key"); // val = "bar_val"
286 bundle_free(b); // After freeing b, val becomes a dangling pointer.
290 API const char* bundle_get_val(bundle *b, const char *key);
293 * @brief Get the number of bundle items
294 * @pre b must be a valid bundle object.
297 * @param[in] b bundle object
298 * @return Number of bundle items
302 bundle *b = bundle_create(); // Create new bundle object
303 bundle_add(b, "key1", "val1"); // add a key-val pair
304 int count = bundle_get_count(b); // count=1
305 bundle_add(b, "key2", "val2"); // add another key-val pair
306 count = bundle_get_count(b); // count=2
311 API int bundle_get_count(bundle *b);
315 * @brief Get a type of a value with certain key
316 * @pre b must be a valid bundle object
319 * @param[in] b A bundle
320 * @param[in] key A key in bundle
321 * @return Type of a key in b
326 API int bundle_get_type(bundle *b, const char *key);
330 * @brief Duplicate given bundle object
331 * @pre b must be a valid bundle object.
334 * @param[in] b_from bundle object to be duplicated
335 * @return New bundle object
336 * @retval NULL Failure
340 bundle *b = bundle_create(); // Create new bundle object
341 bundle_add(b, "foo_key", "bar_val"); // add a key-val pair
342 bundle *b_dup = bundle_dup(b); // duplicate b
348 API bundle * bundle_dup(bundle *b_from);
351 * @brief iterate callback function with each key/val pairs in bundle. (NOTE: Only BUNDLE_TYPE_STR type values come!)
352 * @pre b must be a valid bundle object.
355 * @param[in] b bundle object
356 * @param[in] callback iteration callback function
357 * @param[in] data data for callback function
358 * @remark This function is obsolete, and does not give values whose types are not BUNDLE_TYPE_STR.
362 void sample_cb(const char *k, const char *v, void *data) {
363 printf("%s -> %s\n", k, v);
367 bundle *b = bundle_create(); // Create new bundle object
368 bundle_add(b, "k1", "v1"); // add a key-val pair
369 bundle_add(b, "k2", "v2"); // add a key-val pair
370 bundle_add(b, "k3", "v3"); // add a key-val pair
371 bundle_iterate(b, sample_cb, NULL); // iterate sample_cb for each key/val
376 API void bundle_iterate(bundle *b, bundle_iterate_cb_t callback, void *cb_data);
380 * @brief iterate callback function with each key/val pairs in bundle. (Supports all types of value)
381 * @pre b must be a valid bundle object.
383 * @see bundle_keyval_get_type bundle_keyval_type_is_array bundle_keyval_get_basic_val bundle_keyval_get_array_val
384 * @param[in] b bundle object
385 * @param[in] iter iteration callback function
386 * @param[in] user_data data for callback function
387 * @remark This function supports all types.
391 void sample_cb(const char *key, const int type, const bundle_keyval_t *kv, void *user_data) {
392 void *basic_val = NULL;
393 size_t basic_size = 0;
394 void **array_val = NULL;
396 size_t *array_elem_size = NULL;
398 printf("Key:%s, Type:%d\n", key, type);
399 if(bundle_keyval_type_is_array(kv)) {
400 bundle_keyval_get_array_val(kv, &array_val, &array_len, &array_elem_size);
404 bundle_keyval_get_basic_val(kv, &basic_val, &size);
410 bundle *b = bundle_create(); // Create new bundle object
411 bundle_add_str(b, "k1", "v1"); // add a key-val pair
412 bundle_add_byte(b, "k2", "v2", 3); // add a key-val pair
413 char *s_arr[] = {"abc", "bcd", "cde"};
414 bundle_add_str_array(b, "k3", s_arr, 3); // add a key-val pair
415 bundle_iterate(b, sample_cb, NULL); // iterate sample_cb for each key/val
420 API void bundle_foreach(bundle *b, bundle_iterator_t iter, void *user_data);
424 * @brief Get type for a bundle_keyval_t object.
425 * @pre kv must be a valid bundle_keyval_t object.
427 * @see bundle_foreach
428 * @param[in] kv A bundle_keyval_t object
430 * @retval -1 Operation failure. errno is set.
433 API int bundle_keyval_get_type(bundle_keyval_t *kv);
437 * @brief Determine if kv is array type or not.
438 * @pre kv must be a valid bundle_keyval_t object.
440 * @see bundle_foreach
441 * @param[in] kv A bundle_keyval_t object
442 * @return Operation result
443 * @retval 1 kv is an array.
444 * @retval 0 kv is not an array.
447 API int bundle_keyval_type_is_array(bundle_keyval_t *kv);
451 * @brief Determine if kv is measurable type or not.
452 * @pre kv must be a valid bundle_keyval_t object.
454 * @see bundle_foreach
455 * @param[in] kv A bundle_keyval_t object
456 * @return Operation result
457 * @retval 1 kv is an measurable.
458 * @retval 0 kv is not an measurable.
461 API int bundle_keyval_type_is_measurable(bundle_keyval_t *kv);
465 * @brief Get value and size of the value from kv of basic type.
466 * @pre kv must be a valid bundle_keyval_t object.
467 * @post val, size are set.
468 * @see bundle_foreach
469 * @param[in] kv A bundle_keyval_t object
470 * @param[out] val Value
471 * @param[out] size Size of val
472 * @return Operation result
474 * @remark Do not free val.
476 API int bundle_keyval_get_basic_val(bundle_keyval_t *kv, void **val, size_t *size);
480 * @brief Get value array, length of array, and size of each array item
481 * @pre kv must be a valid bundle_keyval_t object.
482 * @post array_val, array_len, array_item_size are set.
483 * @see bundle_foreach
484 * @param[in] kv A bundle_keyval_t object
485 * @param[out] array_val Array pointer of values
486 * @param[out] array_len Length of array_val
487 * @param[out] array_element_size Array of size of each array element
488 * @return Operation result
493 API int bundle_keyval_get_array_val(bundle_keyval_t *kv, void ***array_val, unsigned int *array_len, size_t **array_element_size);
497 * @brief Encode bundle to bundle_raw format (uses base64 format)
498 * @pre b must be a valid bundle object.
501 * @param[in] b bundle object
502 * @param[out] r returned bundle_raw data(byte data)
503 * r MUST BE FREED by free(r).
504 * @param[out] len size of r (in bytes)
505 * @return size of raw data
511 bundle *b = bundle_create(); // Create new bundle object
512 bundle_add(b, "foo_key", "bar_val"); // add a key-val pair
515 bundle_encode(b, &r, &len); // encode b
517 bundle_free_encoded_rawdata(r);
521 API int bundle_encode(bundle *b, bundle_raw **r, int *len);
524 * @brief Free encoded rawdata from memory
525 * @pre r is a valid rawdata generated by bundle_encode().
528 * @param[in] r is a rawdata
529 * @return Operation result
534 API int bundle_free_encoded_rawdata(bundle_raw **r);
537 * @brief deserialize bundle_raw, and get bundle object
538 * @pre b must be a valid bundle object.
541 * @param[in] r bundle_raw data to be converted to bundle object
542 * @param[in] len size of r
543 * @return bundle object
544 * @retval NULL Failure
548 bundle *b = bundle_create(); // Create new bundle object
549 bundle_add(b, "foo_key", "bar_val"); // add a key-val pair
551 bundle_raw *encoded_b;
553 bundle_encode(b, &encoded_b, &len); // encode b
556 b_dup = bundle_decode(encoded_b, len); // decoded bundle object
563 API bundle * bundle_decode(const bundle_raw *r, const int len);
567 * @brief Export bundle to argv
568 * @pre b is a valid bundle object.
569 * @post argv is a pointer of newly allocated memory. It must be freed.
570 * 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!!
571 * @see bundle_import_from_argv
572 * @param[in] b bundle object
573 * @param[out] argv Pointer of string array.
574 * This array has NULL values for first and last item.
575 * First NULL is for argv[0], and last NULL is a terminator for execv().
576 * @return Number of item in argv. This value is equal to actual count of argv - 1. (Last NULL terminator is not counted.)
577 * @retval -1 Function failure. Check errno to get the reason.
581 bundle *b = bundle_create(); // Create new bundle object
582 bundle_add(b, "foo_key", "bar_val"); // add a key-val pair
586 argc = bundle_export_to_argv(b, &argv); // export to argv
587 if(0 > argc) error("export failure");
590 for(i=0; i < argc; i++) {
591 printf("%s\n", argv[i]); // print argv
593 bundle_free_exported_argv(argc, argv); // argv must be freed after being used.
598 API int bundle_export_to_argv(bundle *b, char ***argv);
601 * @brief Free exported argv
602 * @pre argv is a valid string array generated from bundle_export_to_argv().
604 * @see bundle_export_to_argv
605 * @param[in] argc number of args, which is the return value of bundle_export_to_argv().
606 * @param[in] argv array from bundle_export_to_argv().
607 * @return Operation result.
608 * @retval 0 on success
609 * @retval -1 on failure
610 * @remark You must not use this API when you use global argv.
612 bundle *b = bundle_create();
613 bundle_add_str(b, "foo", "bar");
617 argc = bundle_export_to_argv(b, &argv);
618 if(0 > argc) error("export failure");
622 bundle_free_export_argv(argc, argv);
628 API int bundle_free_exported_argv(int argc, char ***argv);
631 * @brief import a bundle from argv
632 * @pre argv is a valid string array, which is created by bundle_export_to_argv().
633 * @post Returned bundle b must be freed.
634 * @see bundle_export_to_argv
635 * @param[in] argc argument count
636 * @param[in] argv argument vector
637 * @return New bundle object
638 * @retval NULL Function failure
643 int main(int argc, char **argv) {
644 bundle *b = bundle_import_from_argv(argc, argv); // import from argc+argv
645 char *val = bundle_get_val(b, "foo_key"); // value for "foo_key"
647 bundle_free(b); // After freeing b, val becomes a dangling pointer.
652 API bundle * bundle_import_from_argv(int argc, char **argv);
655 * @brief Add a string type key-value pair into bundle.
656 * @pre b must be a valid bundle object.
658 * @see bundle_get_str()
659 * @param[in] b bundle object
661 * @param[in] str string type value
662 * @return Operation result
666 * @remark When -1 is returned, errno is set to one of the following values; \n
667 EKEYREJECTED : key is rejected (NULL or sth) \n
668 EPERM : key is already exist, not permitted to overwrite value \n
669 EINVAL : b or val is not valid (NULL or sth) \n
672 bundle *b = bundle_create(); // Create new bundle object
673 bundle_add_str(b, "foo", "bar"); // add a key-val pair
678 API int bundle_add_str(bundle *b, const char *key, const char *str);
681 * @brief Set a value of string array element
682 * @pre b must be a valid bundle object.
684 * @see bundle_add_str_array()
685 * @see bundle_get_str_array()
686 * @param[in] b bundle object
688 * @param[in] idx index of array element to be changed
689 * @param[in] val string type value. If NULL, empty array is created. You can change an item with
690 * @return Operation result
694 * @remark When -1 is returned, errno is set to one of the following values; \n
695 EKEYREJECTED : key is rejected (NULL or sth) \n
696 EPERM : key is already exist, not permitted to overwrite value \n
697 EINVAL : b or val is not valid (NULL or sth) \n
700 bundle *b = bundle_create();
701 bundle_add_str_array(b, "foo", NULL, 3); // add a key-val pair
702 bundle_set_str_array_element(b, "foo", 0, "aaa");
703 bundle_set_str_array_element(b, "foo", 1, "bbb");
704 bundle_set_str_array_element(b, "foo", 2, "ccc");
706 char **str_array = NULL;
707 int len_str_array = 0;
709 str_array=bundle_get_str_array(b, "foo", &len_str_array);
710 // str_array = { "aaa", "bbb", "ccc" }, and len_str_array = 3
715 API int bundle_set_str_array_element(bundle *b, const char *key, const unsigned int idx, const char *val);
718 * @brief Add a byte type key-value pair into bundle.
719 * @pre b must be a valid bundle object.
721 * @see bundle_get_byte()
722 * @param[in] b bundle object
724 * @param[in] byte string type value
725 * @param[in] size size of byte
726 * @return Operation result
730 * @remark When -1 is returned, errno is set to one of the following values; \n
731 EKEYREJECTED : key is rejected (NULL or sth) \n
732 EPERM : key is already exist, not permitted to overwrite value \n
733 EINVAL : b or val is not valid (NULL or sth) \n
736 bundle *b = bundle_create(); // Create new bundle object
737 bundle_add_byte(b, "foo", "bar\0", 4); // add a key-val pair
743 API int bundle_add_byte(bundle *b, const char *key, const void *byte, const size_t size);
746 * @brief Add a byte array type key-value pair into bundle.
747 * @pre b must be a valid bundle object.
749 * @see bundle_get_str_array()
750 * @see bundle_set_byte_array_element()
751 * @param[in] b bundle object
753 * @param[in] byte_array Not used.
754 * @param[in] len Length of array to be created
755 * @return Operation result
759 * @remark When -1 is returned, errno is set to one of the following values; \n
760 EKEYREJECTED : key is rejected (NULL or sth) \n
761 EPERM : key is already exist, not permitted to overwrite value \n
762 EINVAL : b or val is not valid (NULL or sth) \n
765 bundle *b = bundle_create();
766 bundle_add_byte_array(b, "foo", NULL, 3); // add a byte-array with length 3
768 bundle_set_byte_array_element(b, "foo", 0, "aaa\0", 4); array[0] = "aaa\0"
769 bundle_set_byte_array_element(b, "foo", 1, "bbb\0", 4); array[1] = "bbb\0"
770 bundle_set_byte_array_element(b, "foo", 2, "ccc\0", 4); array[2] = "ccc\0"
775 API int bundle_add_byte_array(bundle *b, const char *key, void **byte_array, const unsigned int len);
778 * @brief Set a value of byte array element
779 * @pre b must be a valid bundle object.
781 * @see bundle_add_str_array()
782 * @see bundle_get_str_array()
783 * @param[in] b bundle object
785 * @param[in] idx index of array element to be changed
786 * @param[in] val string type value. If NULL, empty array is created. You can change an item with
787 * @param[in] size Size of value in byte
788 * @return Operation result
792 * @remark When -1 is returned, errno is set to one of the following values; \n
793 EKEYREJECTED : key is rejected (NULL or sth) \n
794 EPERM : key is already exist, not permitted to overwrite value \n
795 EINVAL : b or val is not valid (NULL or sth) \n
798 bundle *b = bundle_create();
799 bundle_add_byte_array(b, "foo", NULL, 3); // add a key-val pair
800 bundle_set_byte_array_element(b, "foo", 0, "aaa\0", 4);
801 bundle_set_byte_array_element(b, "foo", 1, "bbb\0", 4);
802 bundle_set_byte_array_element(b, "foo", 2, "ccc\0", 4);
804 unsigned char **byte_array = NULL;
805 int len_byte_array = 0;
807 byte_array=bundle_get_str_array(b, "foo", &len_byte_array);
808 // byte_array = { "aaa\0", "bbb\0", "ccc\0" }, and len_byte_array = 3
813 API int bundle_set_byte_array_element(bundle *b, const char *key, const unsigned int idx, const void *val, const size_t size);
816 * @brief Get string value from key
817 * @pre b must be a valid bundle object.
819 * @see bundle_add_str()
820 * @param[in] b bundle object
822 * @param[out] str returned value
823 * @return Operation result
824 * @retval 0 on success
825 * @retval -1 on failure
826 * @remark Do not free str!
827 When -1 is returned, errno is set to one of the following values; \n
828 EINVAL : b is invalid \n
829 ENOKEY : No key exists \n
830 EKEYREJECTED : invalid key (NULL or sth) \n
833 bundle *b = bundle_create(); // Create new bundle object
834 bundle_add_str(b, "foo_key", "bar_val"); // add a key-val pair
837 bundle_get_str(b, "foo_key", &v); // v = "bar_val"
839 bundle_free(b); // After freeing b, v becomes a dangling pointer.
843 API int bundle_get_str(bundle *b, const char *key, char **str);
846 * @brief Get byte value from key
847 * @pre b must be a valid bundle object.
849 * @see bundle_add_byte()
850 * @param[in] b bundle object
852 * @param[out] byte returned value
853 * @param[out] size Size of byte
854 * @return Operation result
855 * @retval 0 on success
856 * @retval -1 on failure
857 * @remark Do not free str!
858 When -1 is returned, errno is set to one of the following values; \n
859 EINVAL : b is invalid \n
860 ENOKEY : No key exists \n
861 EKEYREJECTED : invalid key (NULL or sth) \n
864 bundle *b = bundle_create(); // Create new bundle object
865 bundle_add_byte(b, "foo", "bar\0", 4); // add a key-val pair
867 unsigned char *v = NULL;
868 bundle_get_str(b, "foo", &v); // v = "bar\0"
870 bundle_free(b); // After freeing b, v becomes a dangling pointer.
873 API int bundle_get_byte(bundle *b, const char *key, void **byte, size_t *size);
876 * @brief Get byte array value from key
877 * @pre b must be a valid bundle object.
879 * @see bundle_add_str_array()
880 * @see bundle_set_str_array_element()
881 * @param[in] b bundle object
883 * @param[out] byte_array returned value
884 * @param[out] len array length
885 * @param[out] array_element_size an array of sizes of each byte_array element
886 * @return Operation result
887 * @retval 0 on success
888 * @retval -1 on failure
889 * @remark Do not free str!
890 When -1 is returned, errno is set to one of the following values; \n
891 EINVAL : b is invalid \n
892 ENOKEY : No key exists \n
893 EKEYREJECTED : invalid key (NULL or sth) \n
896 bundle *b = bundle_create();
897 bundle_add_byte_array(b, "foo", NULL, 3);
898 bundle_set_byte_array_element(b, "foo", 0, "aaa\0", 4);
899 bundle_set_byte_array_element(b, "foo", 1, "bbb\0", 4);
900 bundle_set_byte_array_element(b, "foo", 2, "ccc\0", 4);
902 char **byte_array = NULL;
903 int len_byte_array = 0;
904 size_t *size_byte_array = NULL;
906 byte_array = bundle_get_str_array(b, "foo", &len_byte_array, &size_byte_array);
907 // byte_array = { "aaa\0", "bbb\0", "ccc\0" }, len_byte_array = 3, and size_byte_array = { 4, 4, 4 }
912 API int bundle_get_byte_array(bundle *b, const char *key, void ***byte_array, unsigned int *len, unsigned int **array_element_size);
924 #endif /* __BUNDLE_H__ */