Add byte string type
authoryoungman <yman.jung@samsung.com>
Wed, 13 Jan 2016 08:52:25 +0000 (17:52 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Fri, 15 Jan 2016 07:48:05 +0000 (16:48 +0900)
Change-Id: I9997af7bc4d0d61ce548a88ae958696ea92be084
Signed-off-by: youngman <yman.jung@samsung.com>
daemon/icd-payload.c
lib/icl-list.c
lib/icl-payload.c
lib/icl-state.c
lib/icl-state.h
lib/icl-value.c
lib/icl-value.h
lib/include/iotcon-constant.h
lib/include/iotcon-list.h
lib/include/iotcon-representation.h
lib/include/iotcon-state.h

index 5f701c98f6825371337a4a6ed27ee747a93fa639..c842184e0f11b97a66baacefe9ad883dec70cebb 100644 (file)
@@ -154,13 +154,23 @@ static GVariant* _icd_state_array_attr_to_gvariant(OCRepPayloadValueArray *arr,
                for (i = 0; i < len; i++)
                        g_variant_builder_add(&builder, "s", arr->strArray[index + i]);
                break;
+       case OCREP_PROP_BYTE_STRING:
+               for (i = 0; i < len; i++) {
+                       var = g_variant_new_fixed_array(G_VARIANT_TYPE("y"),
+                                       arr->ocByteStrArray[index + i].bytes,
+                                       arr->ocByteStrArray[index + i].len,
+                                       sizeof(uint8_t));
+                       g_variant_builder_add(&builder, "v", var);
+               }
+               break;
        case OCREP_PROP_NULL:
                for (i = 0; i < len; i++)
                        g_variant_builder_add(&builder, "s", IC_STR_NULL);
                break;
        case OCREP_PROP_OBJECT:
                for (i = 0; i < len; i++) {
-                       GVariantBuilder *state_var = _icd_state_value_to_gvariant_builder(arr->objArray[index + i]);
+                       GVariantBuilder *state_var
+                               = _icd_state_value_to_gvariant_builder(arr->objArray[index + i]);
                        var = g_variant_builder_end(state_var);
                        g_variant_builder_add(&builder, "v", var);
                }
@@ -234,6 +244,10 @@ static GVariantBuilder* _icd_state_value_to_gvariant_builder(OCRepPayload *repr)
                case OCREP_PROP_STRING:
                        var = g_variant_new_string(val->str);
                        break;
+               case OCREP_PROP_BYTE_STRING:
+                       var = g_variant_new_fixed_array(G_VARIANT_TYPE("y"), val->ocByteStr.bytes,
+                                       val->ocByteStr.len, sizeof(uint8_t));
+                       break;
                case OCREP_PROP_NULL:
                        var = g_variant_new_string(IC_STR_NULL);
                        break;
@@ -245,7 +259,7 @@ static GVariantBuilder* _icd_state_value_to_gvariant_builder(OCRepPayload *repr)
                        var = _icd_state_value_to_gvariant(val->obj);
                        break;
                default:
-                       ERR("Invalid Type");
+                       ERR("Invalid Type(%d)", val->type);
                }
                if (var) {
                        g_variant_builder_add(builder, "{sv}", val->name, var);
@@ -465,6 +479,28 @@ static void _icd_state_list_from_gvariant(GVariant *var,
                                        value_list->list = g_list_append(value_list->list, repr);
                                } while (g_variant_iter_loop(&iter, "v", &value));
 
+                       } else if (g_variant_is_of_type(value, G_VARIANT_TYPE("ay"))) {
+                               OCByteString *byte_str;
+                               value_list->type = OCREP_PROP_BYTE_STRING;
+                               do {
+                                       byte_str = calloc(1, sizeof(OCByteString));
+                                       if (NULL == byte_str) {
+                                               ERR("calloc() Fail(%d)", errno);
+                                               return;
+                                       }
+
+                                       byte_str->len = g_variant_get_size(value);
+                                       byte_str->bytes = calloc(byte_str->len, sizeof(uint8_t));
+                                       if (NULL == byte_str->bytes) {
+                                               ERR("calloc() Fail(%d)", errno);
+                                               free(byte_str);
+                                               return;
+                                       }
+                                       memcpy(byte_str->bytes, g_variant_get_data(value), byte_str->len);
+
+                                       value_list->list = g_list_append(value_list->list, byte_str);
+                               } while (g_variant_iter_loop(&iter, "v", &value));
+
                        } else if (g_variant_is_of_type(value, G_VARIANT_TYPE_ARRAY)) {
                                do {
                                        _icd_state_list_from_gvariant(value, value_list, depth + 1);
@@ -492,6 +528,7 @@ static void _icd_state_array_from_list(OCRepPayload *repr,
        double *d_arr;
        char **str_arr;
        int64_t *i_arr;
+       OCByteString *byte_arr;
        union icd_state_value_u *value;
        struct OCRepPayload **state_arr;
 
@@ -547,6 +584,21 @@ static void _icd_state_array_from_list(OCRepPayload *repr,
                        str_arr[i] = strdup(node->data);
                g_list_free_full(value_list->list, free);
                OCRepPayloadSetStringArrayAsOwner(repr, key, str_arr, value_list->dimensions);
+               break;
+       case OCREP_PROP_BYTE_STRING:
+               byte_arr = calloc(len, sizeof(OCByteString));
+               if (NULL == byte_arr) {
+                       ERR("calloc() Fail(%d)", errno);
+                       return;
+               }
+               for (node = value_list->list, i = 0; node; node = node->next, i++) {
+                       OCByteString *byte_str = node->data;
+                       byte_arr[i].bytes = byte_str->bytes;
+                       byte_arr[i].len = byte_str->len;
+               }
+               g_list_free(value_list->list);
+               OCRepPayloadSetByteStringArray(repr, key, byte_arr, value_list->dimensions);
+
                break;
        case OCREP_PROP_OBJECT:
                state_arr = calloc(len, sizeof(struct OCRepPayload *));
@@ -597,6 +649,12 @@ static void _icd_state_value_from_gvariant(OCRepPayload *repr, GVariantIter *ite
                        else
                                OCRepPayloadSetPropString(repr, key, str_value);
 
+               } else if (g_variant_is_of_type(var, G_VARIANT_TYPE("ay"))) {
+                       OCByteString byte_value;
+                       byte_value.bytes = (uint8_t*)g_variant_get_data(var);
+                       byte_value.len = g_variant_get_size(var);
+                       OCRepPayloadSetPropByteString(repr, key, byte_value);
+
                } else if (g_variant_is_of_type(var, G_VARIANT_TYPE("a{sv}"))) {
                        GVariantIter state_iter;
                        repr_value = OCRepPayloadCreate();
@@ -744,6 +802,13 @@ static int _representation_compare_array(OCRepPayloadValueArray arr1,
                                return 1;
                }
                break;
+       case OCREP_PROP_BYTE_STRING:
+               for (i = 0; i < len1; i++) {
+                       if (IC_EQUAL != memcmp(arr1.ocByteStrArray[i].bytes,
+                                               arr2.ocByteStrArray[i].bytes, arr2.ocByteStrArray[i].len))
+                               return 1;
+               }
+               break;
        case OCREP_PROP_OBJECT:
                for (i = 0; i < len1; i++) {
                        if (IC_EQUAL != icd_payload_representation_compare(arr1.objArray[i],
@@ -792,6 +857,10 @@ static int _representation_compare_value(OCRepPayloadValue *value1,
        case OCREP_PROP_STRING:
                ret = (IC_STR_EQUAL == g_strcmp0(value1->str, value2->str)) ? IC_EQUAL : 1;
                break;
+       case OCREP_PROP_BYTE_STRING:
+               ret = (IC_EQUAL == memcmp(value1->ocByteStr.bytes, value2->ocByteStr.bytes,
+                                       value2->ocByteStr.len));
+               break;
        case OCREP_PROP_OBJECT:
                ret = icd_payload_representation_compare(value1->obj, value2->obj);
                break;
index a03c26872e73767ac0ef295f84813a73ef103d45..72d5015936da03d298d5b810ef8583d6f77aef83 100644 (file)
@@ -134,6 +134,25 @@ API int iotcon_list_add_str(iotcon_list_h list, char *val, int pos)
 }
 
 
+API int iotcon_list_add_byte_str(iotcon_list_h list, unsigned char *val, int len, int pos)
+{
+       iotcon_value_h value;
+
+       RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
+       RETVM_IF(IOTCON_TYPE_BYTE_STR != list->type, IOTCON_ERROR_INVALID_TYPE,
+                       "Invalid Type(%d)", list->type);
+
+       value = icl_value_create_byte_str(val, len);
+       if (NULL == value) {
+               ERR("icl_value_create_str() Fail");
+               return IOTCON_ERROR_OUT_OF_MEMORY;
+       }
+
+       return icl_list_insert(list, value, pos);
+}
+
+
 API int iotcon_list_add_list(iotcon_list_h list, iotcon_list_h val, int pos)
 {
        iotcon_value_h value;
@@ -283,6 +302,37 @@ API int iotcon_list_get_nth_str(iotcon_list_h list, int pos, char **val)
 }
 
 
+API int iotcon_list_get_nth_byte_str(iotcon_list_h list, int pos, unsigned char **val,
+               int *len)
+{
+       unsigned char *byte_val;
+       int ret, byte_len;
+       iotcon_value_h value;
+
+       RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == list->list, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == len, IOTCON_ERROR_INVALID_PARAMETER);
+
+       value = g_list_nth_data(list->list, pos);
+       if (NULL == value) {
+               ERR("g_list_nth_data() Fail");
+               return IOTCON_ERROR_NO_DATA;
+       }
+
+       ret = icl_value_get_byte_str(value, &byte_val, &byte_len);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("icl_value_get_byte_str() Fail(%d)", ret);
+               return IOTCON_ERROR_REPRESENTATION;
+       }
+
+       *val = byte_val;
+       *len = byte_len;
+
+       return IOTCON_ERROR_NONE;
+}
+
+
 API int iotcon_list_get_nth_list(iotcon_list_h src, int pos, iotcon_list_h *dest)
 {
        int ret;
@@ -339,7 +389,7 @@ API int iotcon_list_get_nth_state(iotcon_list_h list, int pos, iotcon_state_h *s
 }
 
 
-static int _icl_list_remove_nth_value(iotcon_list_h list, int pos)
+API int iotcon_list_remove_nth(iotcon_list_h list, int pos)
 {
        iotcon_value_h value;
 
@@ -352,33 +402,14 @@ static int _icl_list_remove_nth_value(iotcon_list_h list, int pos)
                return IOTCON_ERROR_NO_DATA;
        }
 
-       if (IOTCON_TYPE_STR == value->type) {
-               icl_basic_s *real = (icl_basic_s*)value;
-               free(real->val.s);
-       } else if (IOTCON_TYPE_LIST == value->type) {
-               icl_val_list_s *real = (icl_val_list_s*)value;
-               iotcon_list_destroy(real->list);
-       } else if (IOTCON_TYPE_STATE == value->type) {
-               icl_val_state_s *real = (icl_val_state_s*)value;
-               iotcon_state_destroy(real->state);
-       }
+       list->list = g_list_remove(list->list, value);
+
+       icl_value_destroy(value);
 
-       icl_list_remove(list, value);
        return IOTCON_ERROR_NONE;
 }
 
 
-API int iotcon_list_remove_nth(iotcon_list_h list, int pos)
-{
-       int ret;
-
-       ret = _icl_list_remove_nth_value(list, pos);
-       if (IOTCON_ERROR_NONE != ret)
-               ERR("_icl_list_remove_nth_value() Fail(%d)", ret);
-
-       return ret;
-}
-
 API int iotcon_list_get_type(iotcon_list_h list, iotcon_type_e *type)
 {
        RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
@@ -403,16 +434,6 @@ API int iotcon_list_get_length(iotcon_list_h list, unsigned int *length)
 }
 
 
-int icl_list_remove(iotcon_list_h list, iotcon_value_h val)
-{
-       RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
-
-       list->list = g_list_remove(list->list, val);
-
-       return IOTCON_ERROR_NONE;
-}
-
-
 int icl_list_insert(iotcon_list_h list, iotcon_value_h value, int pos)
 {
        RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
@@ -522,6 +543,31 @@ API int iotcon_list_foreach_str(iotcon_list_h list, iotcon_list_str_cb cb,
        return IOTCON_ERROR_NONE;
 }
 
+API int iotcon_list_foreach_byte_str(iotcon_list_h list, iotcon_list_byte_str_cb cb,
+               void *user_data)
+{
+       GList *cur;
+       int index = 0;
+       icl_val_byte_str_s *real = NULL;
+
+       RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
+       RETVM_IF(IOTCON_TYPE_BYTE_STR != list->type, IOTCON_ERROR_INVALID_TYPE,
+                       "Invalid Type(%d)", list->type);
+       RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
+
+       cur = list->list;
+       while (cur) {
+               GList *next = cur->next;
+               real = cur->data;
+               if (IOTCON_FUNC_STOP == cb(index, real->s, real->len, user_data))
+                       break;
+               index++;
+               cur = next;
+       }
+
+       return IOTCON_ERROR_NONE;
+}
+
 API int iotcon_list_foreach_list(iotcon_list_h list, iotcon_list_list_cb cb,
                void *user_data)
 {
@@ -736,6 +782,7 @@ iotcon_list_h icl_list_clone(iotcon_list_h list)
        case IOTCON_TYPE_DOUBLE:
        case IOTCON_TYPE_STR:
        case IOTCON_TYPE_NULL:
+       case IOTCON_TYPE_BYTE_STR:
                ret = _icl_list_clone_value(list, ret_list);
                if (IOTCON_ERROR_NONE != ret) {
                        ERR("_icl_list_clone_value() Fail(%d)", ret);
index c90a637d2c88b741b33df2de7372e497f9861083..177199c4ed6db76d6603875b2e3f9652045be360 100644 (file)
@@ -67,6 +67,16 @@ static GVariant* _icl_state_list_to_gvariant(iotcon_list_h list)
                        g_variant_builder_add(&builder, "s", ((icl_basic_s*)state_value)->val.s);
                }
                break;
+       case IOTCON_TYPE_BYTE_STR:
+               for (node = list->list; node; node = node->next) {
+                       state_value = node->data;
+                       var = g_variant_new_fixed_array(G_VARIANT_TYPE("y"),
+                                       ((icl_val_byte_str_s*)state_value)->s,
+                                       ((icl_val_byte_str_s*)state_value)->len,
+                                       sizeof(unsigned char));
+                       g_variant_builder_add(&builder, "v", var);
+               }
+               break;
        case IOTCON_TYPE_LIST:
                for (node = list->list; node; node = node->next) {
                        state_value = node->data;
@@ -125,6 +135,12 @@ static GVariantBuilder* _icl_state_value_to_gvariant_builder(GHashTable *hash)
                case IOTCON_TYPE_NULL:
                        var = g_variant_new_string(IC_STR_NULL);
                        break;
+               case IOTCON_TYPE_BYTE_STR:
+                       var = g_variant_new_fixed_array(G_VARIANT_TYPE("y"),
+                                       ((icl_val_byte_str_s*)state_value)->s,
+                                       ((icl_val_byte_str_s*)state_value)->len,
+                                       sizeof(unsigned char));
+                       break;
                case IOTCON_TYPE_LIST:
                        var = _icl_state_list_to_gvariant(((icl_val_list_s*)state_value)->list);
                        break;
@@ -252,6 +268,9 @@ void icl_state_from_gvariant(iotcon_state_h state, GVariantIter *iter)
                        g_variant_iter_init(&state_iter, var);
                        icl_state_from_gvariant(state_value, &state_iter);
                        value = icl_value_create_state(state_value);
+               } else if (g_variant_is_of_type(var, G_VARIANT_TYPE("ay"))) {
+                       value = icl_value_create_byte_str(g_variant_get_data(var),
+                                       g_variant_get_size(var));
                } else if (g_variant_is_of_type(var, G_VARIANT_TYPE_ARRAY)) {
                        list_value = _icl_state_list_from_gvariant(var);
                        value = icl_value_create_list(list_value);
@@ -335,6 +354,17 @@ static iotcon_list_h _icl_state_list_from_gvariant(GVariant *var)
                                g_variant_iter_init(&state_iter, variant);
                                icl_state_from_gvariant(state_value, &state_iter);
                                iotcon_list_add_state(list, state_value, -1);
+                       } else if (g_variant_is_of_type(variant, G_VARIANT_TYPE("ay"))) {
+                               unsigned char *byte_str;
+                               if (NULL == list) {
+                                       ret = iotcon_list_create(IOTCON_TYPE_BYTE_STR, &list);
+                                       if (IOTCON_ERROR_NONE != ret) {
+                                               ERR("iotcon_list_create() Fail(%d)", ret);
+                                               return NULL;
+                                       }
+                               }
+                               byte_str = (unsigned char*)g_variant_get_data(variant);
+                               iotcon_list_add_byte_str(list, byte_str, g_variant_get_size(variant), -1);
                        } else if (g_variant_is_of_type(variant, G_VARIANT_TYPE_ARRAY)) {
                                if (NULL == list) {
                                        ret = iotcon_list_create(IOTCON_TYPE_LIST, &list);
index 02356c8f83a72da8c66e4e289530162f6b09753d..bf292bd5b71987eae14b0b4d4ec1e8113311ff03 100644 (file)
@@ -72,7 +72,7 @@ API void iotcon_state_destroy(iotcon_state_h state)
 }
 
 
-int icl_state_del_value(iotcon_state_h state, const char *key)
+API int iotcon_state_remove(iotcon_state_h state, const char *key)
 {
        gboolean ret = FALSE;
        iotcon_value_h value = NULL;
@@ -95,6 +95,7 @@ int icl_state_del_value(iotcon_state_h state, const char *key)
        return IOTCON_ERROR_NONE;
 }
 
+
 API int iotcon_state_get_int(iotcon_state_h state, const char *key, int *val)
 {
        iotcon_value_h value;
@@ -138,20 +139,6 @@ API int iotcon_state_add_int(iotcon_state_h state, const char *key, int val)
        return IOTCON_ERROR_NONE;
 }
 
-API int iotcon_state_remove(iotcon_state_h state, const char *key)
-{
-       int ret;
-
-       RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
-
-       ret = icl_state_del_value(state, key);
-       if (IOTCON_ERROR_NONE != ret)
-               ERR("icl_state_del_value() Fail(%d)", ret);
-
-       return ret;
-}
-
 API int iotcon_state_get_bool(iotcon_state_h state, const char *key, bool *val)
 {
        icl_basic_s *real = NULL;
@@ -285,6 +272,56 @@ API int iotcon_state_add_str(iotcon_state_h state, const char *key, char *val)
        return IOTCON_ERROR_NONE;
 }
 
+API int iotcon_state_get_byte_str(iotcon_state_h state, const char *key,
+               unsigned char **val, int *len)
+{
+       iotcon_value_h value = NULL;
+       icl_val_byte_str_s *real = NULL;
+
+       RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == len, IOTCON_ERROR_INVALID_PARAMETER);
+
+       value = g_hash_table_lookup(state->hash_table, key);
+       if (NULL == value) {
+               ERR("g_hash_table_lookup() Fail");
+               return IOTCON_ERROR_NO_DATA;
+       }
+
+       real = (icl_val_byte_str_s*)value;
+       if (IOTCON_TYPE_BYTE_STR != real->type) {
+               ERR("Invalid Type(%d)", real->type);
+               return IOTCON_ERROR_INVALID_TYPE;
+       }
+
+       *val = real->s;
+       *len = real->len;
+
+       return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_state_add_byte_str(iotcon_state_h state, const char *key,
+               unsigned char *val, int len)
+{
+       iotcon_value_h value = NULL;
+
+       RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(len <= 0, IOTCON_ERROR_INVALID_PARAMETER);
+
+       value = icl_value_create_byte_str(val, len);
+       if (NULL == value) {
+               ERR("icl_value_create_byte_str() Fail");
+               return IOTCON_ERROR_OUT_OF_MEMORY;
+       }
+
+       g_hash_table_replace(state->hash_table, ic_utils_strdup(key), value);
+
+       return IOTCON_ERROR_NONE;
+}
+
 API int iotcon_state_is_null(iotcon_state_h state, const char *key, bool *is_null)
 {
        icl_basic_s *real = NULL;
@@ -497,6 +534,7 @@ void icl_state_clone_foreach(char *key, iotcon_value_h src_val, iotcon_state_h d
        case IOTCON_TYPE_BOOL:
        case IOTCON_TYPE_DOUBLE:
        case IOTCON_TYPE_STR:
+       case IOTCON_TYPE_BYTE_STR:
        case IOTCON_TYPE_NULL:
                copied_val = icl_value_clone(src_val);
                if (NULL == copied_val) {
index e3ed4d2219c34ad60047a25a8a0ccf85e08bf5a3..4520cdcdd8a660852c84000248cd82d26335dc5a 100644 (file)
@@ -19,8 +19,6 @@
 #include "icl-value.h"
 #include "icl-representation.h"
 
-int icl_state_del_value(iotcon_state_h state, const char *key);
-
 int icl_state_set_value(iotcon_state_h state, const char *key, iotcon_value_h value);
 
 void icl_state_clone_foreach(char *key, iotcon_value_h src_val,
index 58c08aaa1bec447c0cb3e48578a04868b2ab558b..fd73f294c0a4f362b9dcaab267185fea1a23d9b0 100644 (file)
@@ -38,6 +38,9 @@ static iotcon_value_h _icl_value_create(int type)
        case IOTCON_TYPE_NULL:
                ret_val = calloc(1, sizeof(icl_basic_s));
                break;
+       case IOTCON_TYPE_BYTE_STR:
+               ret_val = calloc(1, sizeof(icl_val_byte_str_s));
+               break;
        case IOTCON_TYPE_LIST:
                ret_val = calloc(1, sizeof(icl_val_list_s));
                break;
@@ -136,6 +139,31 @@ iotcon_value_h icl_value_create_str(const char *val)
 }
 
 
+iotcon_value_h icl_value_create_byte_str(const unsigned char *val, int len)
+{
+       icl_val_byte_str_s *value;
+
+       RETV_IF(NULL == val, NULL);
+
+       value = (icl_val_byte_str_s*)_icl_value_create(IOTCON_TYPE_BYTE_STR);
+       if (NULL == value) {
+               ERR("_icl_value_create(BYTE STRING) Fail");
+               return NULL;
+       }
+
+       value->s = calloc(len, sizeof(unsigned char));
+       if (NULL == value->s) {
+               ERR("calloc() Fail(%d)", errno);
+               free(value);
+               return NULL;
+       }
+       memcpy(value->s, val, len);
+       value->len = len;
+
+       return (iotcon_value_h)value;
+}
+
+
 iotcon_value_h icl_value_create_list(iotcon_list_h val)
 {
        icl_val_list_s *value;
@@ -219,6 +247,21 @@ int icl_value_get_str(iotcon_value_h value, char **val)
 }
 
 
+int icl_value_get_byte_str(iotcon_value_h value, unsigned char **val, int *len)
+{
+       icl_val_byte_str_s *real = (icl_val_byte_str_s*)value;
+
+       RETV_IF(NULL == value, IOTCON_ERROR_INVALID_PARAMETER);
+       RETVM_IF(IOTCON_TYPE_BYTE_STR != real->type, IOTCON_ERROR_INVALID_PARAMETER,
+                       "Invalid Type(%d)", real->type);
+
+       *val = real->s;
+       *len = real->len;
+
+       return IOTCON_ERROR_NONE;
+}
+
+
 int icl_value_get_list(iotcon_value_h value, iotcon_list_h *list)
 {
        icl_val_list_s *real = (icl_val_list_s*)value;
@@ -266,8 +309,10 @@ void icl_value_destroy(gpointer data)
        case IOTCON_TYPE_DOUBLE:
        case IOTCON_TYPE_NULL:
                break;
+       case IOTCON_TYPE_BYTE_STR:
+               free(((icl_val_byte_str_s*)value)->s);
+               break;
        case IOTCON_TYPE_LIST:
-               DBG("value is list");
                ret = icl_value_get_list(value, &list);
                if (IOTCON_ERROR_NONE != ret) {
                        ERR("icl_value_get_list() Fail(%d)", ret);
@@ -276,7 +321,6 @@ void icl_value_destroy(gpointer data)
                iotcon_list_destroy(list);
                break;
        case IOTCON_TYPE_STATE:
-               DBG("value is Repr");
                ret = icl_value_get_state(value, &state);
                if (IOTCON_ERROR_NONE != ret) {
                        ERR("icl_value_get_state() Fail(%d)", ret);
@@ -310,11 +354,15 @@ iotcon_value_h icl_value_clone(iotcon_value_h src)
                dest = icl_value_create_double(real->val.d);
                break;
        case IOTCON_TYPE_STR:
-               dest = icl_value_create_str(ic_utils_strdup(real->val.s));
+               dest = icl_value_create_str(real->val.s);
                break;
        case IOTCON_TYPE_NULL:
                dest = icl_value_create_null();
                break;
+       case IOTCON_TYPE_BYTE_STR:
+               dest = icl_value_create_byte_str(((icl_val_byte_str_s*)real)->s,
+                               ((icl_val_byte_str_s*)real)->len);
+               break;
        default:
                ERR("Invalid type(%d)", src->type);
                break;
index 79085b8f793d2bbafc2d4c9a939b450fd68b4215..d06e60c421362b6d86254f94665f4019fc64876f 100644 (file)
@@ -34,6 +34,12 @@ typedef struct {
        } val;
 } icl_basic_s;
 
+typedef struct {
+       int type;
+       unsigned char *s;
+       int len;
+} icl_val_byte_str_s;
+
 typedef struct {
        int type;
        struct icl_list_s *list;
@@ -56,6 +62,7 @@ typedef struct {
  * #IOTCON_TYPE_DOUBLE\n
  * #IOTCON_TYPE_STR\n
  * #IOTCON_TYPE_NULL\n
+ * #IOTCON_TYPE_BYTE_STR\n
  * #IOTCON_TYPE_LIST\n
  * #IOTCON_TYPE_STATE
  *
@@ -68,6 +75,7 @@ iotcon_value_h icl_value_create_int(int val);
 iotcon_value_h icl_value_create_bool(bool val);
 iotcon_value_h icl_value_create_double(double val);
 iotcon_value_h icl_value_create_str(const char *val);
+iotcon_value_h icl_value_create_byte_str(const unsigned char *val, int len);
 iotcon_value_h icl_value_create_list(iotcon_list_h val);
 iotcon_value_h icl_value_create_state(iotcon_state_h val);
 
@@ -76,6 +84,7 @@ int icl_value_get_int(iotcon_value_h value, int *val);
 int icl_value_get_bool(iotcon_value_h value, bool *val);
 int icl_value_get_double(iotcon_value_h value, double *val);
 int icl_value_get_str(iotcon_value_h value, char **val);
+int icl_value_get_byte_str(iotcon_value_h value, unsigned char **val, int *len);
 int icl_value_get_list(iotcon_value_h value, iotcon_list_h *list);
 int icl_value_get_state(iotcon_value_h value, iotcon_state_h *state);
 
index 47433abcbdf39ba05e80d4499ad745680f19d8c1..7ff066efe63e9278ac5c39a02e79bc77c970d0bf 100644 (file)
@@ -172,6 +172,7 @@ typedef enum {
        IOTCON_TYPE_BOOL, /**< Indicates for representation that have bool type */
        IOTCON_TYPE_DOUBLE, /**< Indicates for representation that have double type */
        IOTCON_TYPE_STR, /**< Indicates for representation that have string type */
+       IOTCON_TYPE_BYTE_STR, /**< Indicates for representation that have byte string type */
        IOTCON_TYPE_NULL, /**< Indicates for representation that have null type */
        IOTCON_TYPE_LIST, /**< Indicates for representation that have list type */
        IOTCON_TYPE_STATE, /**< Indicates for representation that have another representation type */
index e5631ada6c916bd18fb53f0022658ee126a37234..51984c5acdd9a628c19c35efad4ee92ef8b85fbd 100644 (file)
@@ -32,7 +32,7 @@
  *  \#include <iotcon.h>
  *
  * @section CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_STATE_LIST_MODULE_OVERVIEW Overview
- * The iotcon list API provides list of bool, integer, double, string, list and state handle.
+ * The iotcon list API provides list of bool, integer, double, string, byte string, list and state handle.
  *
  * Example :
  * @code
@@ -265,6 +265,26 @@ int iotcon_list_add_double(iotcon_list_h list, double val, int pos);
  */
 int iotcon_list_add_str(iotcon_list_h list, char *val, int pos);
 
+/**
+ * @brief Adds a new element byte string value into the list at the given position.
+ * @details If @a pos is negative, or is larger than the number of elements in the list,
+ * the new value is added on to the end of the list.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] list The list handle
+ * @param[in] val The new byte string value
+ * @param[in] len The length of @a val
+ * @param[in] pos The position to insert value
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE  Successful
+ * @retval #IOTCON_ERROR_OUT_OF_MEMORY  Out of memory
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER  Invalid parameter
+ * @retval #IOTCON_ERROR_INVALID_TYPE  Invalid type
+ */
+int iotcon_list_add_byte_str(iotcon_list_h list, unsigned char *val, int len, int pos);
+
 /**
  * @brief Adds a new element list into the list at the given position.
  * @details If @a pos is negative, or is larger than the number of elements in the list,
@@ -377,6 +397,28 @@ int iotcon_list_get_nth_double(iotcon_list_h list, int pos, double *val);
  */
 int iotcon_list_get_nth_str(iotcon_list_h list, int pos, char **val);
 
+/**
+ * @brief Gets the string value at the given position.
+ * @details Iterates over the list until it reaches the @a pos-1 position.
+ *
+ * @since_tizen 3.0
+ *
+ * @remarks @a val must not be released using free().
+ *
+ * @param[in] list The list handle
+ * @param[in] pos The position
+ * @param[out] val The byte string value to get
+ * @param[out] len The length of the @a val
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE  Successful
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER  Invalid parameter
+ * @retval #IOTCON_ERROR_NO_DATA  No data available
+ * @retval #IOTCON_ERROR_REPRESENTATION  Representation errors
+ */
+int iotcon_list_get_nth_byte_str(iotcon_list_h list, int pos, unsigned char **val,
+               int *len);
+
 /**
  * @brief Gets the list value at the given position.
  * @details Iterates over the list until it reaches the @a pos-1 position.
@@ -581,6 +623,48 @@ typedef bool (*iotcon_list_double_cb)(int pos, double value, void *user_data);
 int iotcon_list_foreach_double(iotcon_list_h list, iotcon_list_double_cb cb,
                void *user_data);
 
+/**
+ * @brief Specifies the type of function passed to iotcon_list_foreach_byte_str()
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] pos The number of the string value (0 being the first)
+ * @param[in] value The byte string value
+ * @param[in] len The length of @a value
+ * @param[in] user_data The user data to pass to the function
+ *
+ * @return true to continue with the next iteration of the loop,
+ * otherwise false to break out of the loop. #IOTCON_FUNC_CONTINUE and #IOTCON_FUNC_STOP
+ * are more friendly values for the return.
+ *
+ * @pre iotcon_list_foreach_byte_str() will invoke this callback function.
+ *
+ * @see iotcon_list_foreach_byte_str()
+ */
+typedef bool (*iotcon_list_byte_str_cb)(int pos, const unsigned char *value, int len,
+               void *user_data);
+
+/**
+ * @brief Gets all string values of the given list by invoking the callback function.
+ * @details iotcon_list_byte_str_cb() will be called for each child.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] list The handle to the list
+ * @param[in] cb The callback function to get each string value
+ * @param[in] user_data The user data to be passed to the callback function
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE  Successful
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER  Invalid parameter
+ *
+ * @post iotcon_list_byte_str_cb() will be called for each item.
+ *
+ * @see iotcon_list_byte_str_cb()
+ */
+int iotcon_list_foreach_byte_str(iotcon_list_h list, iotcon_list_byte_str_cb cb,
+               void *user_data);
+
 /**
  * @brief Specifies the type of function passed to iotcon_list_foreach_str()
  *
index e15d53cf82350c10ebbd541554ebe8633497e34b..ca60bec5ebc8ac7346599e402aeeca939112255d 100644 (file)
  * The Iotcon Representation API provides data type of resp_repr handling.\n
  * A resp_repr is a payload of a request or a response.\n
  * It has uri_path, interface, list of resource types and its attributes.\n
- * Attributes have capabilties to store and retrieve integer, boolean, double, string, list, null,
- * resp_repr.\n
+ * Attributes have capabilties to store and retrieve integer, boolean, double, string,
+ * byte string, list, null, resp_repr.\n
  * A list is a container that includes number of datas of same type.\n
- * It has capabilties to store and retrieve integer, boolean, double, string, list, null, resp_repr.
+ * It has capabilties to store and retrieve integer, boolean, double, string, byte string,
+ * list, null, resp_repr.
  *
  * Example :
  *@code
index 61e99616ad14f2836283c75752b78a7f04afa5dc..8e4adeef2b1cf96babb9f7065a70e9b135dadcc5 100644 (file)
@@ -181,7 +181,7 @@ void iotcon_state_destroy(iotcon_state_h state);
 int iotcon_state_clone(iotcon_state_h state, iotcon_state_h *state_clone);
 
 /**
- * @brief Adds a new key and integer value into the representation.
+ * @brief Adds a new key and integer value into the state.
  * @details If @a key is already exists, current value will be replaced with new @a val.
  *
  * @since_tizen 3.0
@@ -198,7 +198,7 @@ int iotcon_state_clone(iotcon_state_h state, iotcon_state_h *state_clone);
 int iotcon_state_add_int(iotcon_state_h state, const char *key, int val);
 
 /**
- * @brief Adds a new key and boolean value into the representation.
+ * @brief Adds a new key and boolean value into the state.
  * @details If @a key is already exists, current value will be replaced with new @a val.
  *
  * @since_tizen 3.0
@@ -215,7 +215,7 @@ int iotcon_state_add_int(iotcon_state_h state, const char *key, int val);
 int iotcon_state_add_bool(iotcon_state_h state, const char *key, bool val);
 
 /**
- * @brief Adds a new key and double value into the representation.
+ * @brief Adds a new key and double value into the state.
  * @details If @a key is already exists, current value will be replaced with new @a val.
  *
  * @since_tizen 3.0
@@ -232,7 +232,7 @@ int iotcon_state_add_bool(iotcon_state_h state, const char *key, bool val);
 int iotcon_state_add_double(iotcon_state_h state, const char *key, double val);
 
 /**
- * @brief Adds a new key and string value into the representation.
+ * @brief Adds a new key and string value into the state.
  * @details If @a key is already exists, current value will be replaced with new @a val.
  *
  * @since_tizen 3.0
@@ -249,7 +249,26 @@ int iotcon_state_add_double(iotcon_state_h state, const char *key, double val);
 int iotcon_state_add_str(iotcon_state_h state, const char *key, char *val);
 
 /**
- * @brief Adds a new key and list value into the representation.
+ * @brief Adds a new key and byte string value into the state.
+ * @details If @a key is already exists, current value will be replaced with new @a val.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] state The state handle
+ * @param[in] key The key
+ * @param[in] val The value
+ * @param[in] len The length of @a val
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE  Successful
+ * @retval #IOTCON_ERROR_OUT_OF_MEMORY  Out of memory
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER  Invalid parameter
+ */
+int iotcon_state_add_byte_str(iotcon_state_h state, const char *key, unsigned char *val,
+               int len);
+
+/**
+ * @brief Adds a new key and list value into the state.
  * @details If @a key is already exists, current list will be replaced with new @a list.
  *
  * @since_tizen 3.0
@@ -266,7 +285,7 @@ int iotcon_state_add_str(iotcon_state_h state, const char *key, char *val);
 int iotcon_state_add_list(iotcon_state_h state, const char *key, iotcon_list_h list);
 
 /**
- * @brief Adds a new key and state value into the representation.
+ * @brief Adds a new key and state value into the state.
  * @details If @a key is already exists, current state will be replaced with new @a src.
  *
  * @since_tizen 3.0
@@ -283,7 +302,7 @@ int iotcon_state_add_list(iotcon_state_h state, const char *key, iotcon_list_h l
 int iotcon_state_add_state(iotcon_state_h dest, const char *key, iotcon_state_h src);
 
 /**
- * @brief Adds a new key with NULL value into the representation.
+ * @brief Adds a new key with NULL value into the state.
  * @details If @a key is already exists, current value will be replaced with NULL
  *
  * @since_tizen 3.0
@@ -368,6 +387,27 @@ int iotcon_state_get_double(iotcon_state_h state, const char *key, double *val);
  */
 int iotcon_state_get_str(iotcon_state_h state, const char *key, char **val);
 
+/**
+ * @brief Gets the byte string value from the given key.
+ *
+ * @since_tizen 3.0
+ *
+ * @remarks @a val must not be released using free().
+ *
+ * @param[in] state The state handle
+ * @param[in] key The key
+ * @param[out] val The byte string value
+ * @param[out] len The length of @a val
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE  Successful
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER  Invalid parameter
+ * @retval #IOTCON_ERROR_NO_DATA  No data available
+ * @retval #IOTCON_ERROR_INVALID_TYPE  Invalid type
+ */
+int iotcon_state_get_byte_str(iotcon_state_h state, const char *key, unsigned char **val,
+               int *len);
+
 /**
  * @brief Gets the list value from the given key.
  *