Prevent to modify items that already set.
authoryoungman <yman.jung@samsung.com>
Fri, 5 Jun 2015 04:57:27 +0000 (13:57 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Mon, 8 Jun 2015 10:41:50 +0000 (19:41 +0900)
Change-Id: I72a1b2584496997b9ef77fae19ef5643919e17dc
Signed-off-by: youngman <yman.jung@samsung.com>
lib/ic-client.c
lib/ic-options.c
lib/ic-resource-types.c
lib/ic-response.c

index ed2b156..50efa47 100644 (file)
@@ -181,7 +181,16 @@ API int iotcon_client_set_options(iotcon_client_h resource,
        if (resource->header_options)
                iotcon_options_free(resource->header_options);
 
-       resource->header_options = header_options;
+       if (NULL == header_options) {
+               resource->header_options = NULL;
+               return IOTCON_ERROR_NONE;
+       }
+
+       if (true == header_options->has_parent)
+               resource->header_options = ic_options_ref(header_options);
+       else
+               resource->header_options = header_options;
+       resource->header_options->has_parent = true;
 
        return IOTCON_ERROR_NONE;
 }
index 1da19e4..a5fb1bd 100644 (file)
@@ -63,6 +63,8 @@ API int iotcon_options_insert(iotcon_options_h options, unsigned short id,
        FN_CALL;
 
        RETV_IF(NULL == options, IOTCON_ERROR_INVALID_PARAMETER);
+       RETVM_IF(options->has_parent, IOTCON_ERROR_INVALID_PARAMETER,
+                       "Don't modify it. It is already set.");
        RETVM_IF(IOTCON_OPTIONS_MAX <= g_hash_table_size(options->hash),
                        IOTCON_ERROR_OUT_OF_MEMORY, "Options already have maximum elements.");
 
@@ -84,6 +86,8 @@ API int iotcon_options_delete(iotcon_options_h options, unsigned short id)
        gboolean ret;
 
        RETV_IF(NULL == options, IOTCON_ERROR_INVALID_PARAMETER);
+       RETVM_IF(options->has_parent, IOTCON_ERROR_INVALID_PARAMETER,
+                       "Don't modify it. It is already set.");
 
        ret = g_hash_table_remove(options->hash, GUINT_TO_POINTER(id));
        if (FALSE == ret) {
index 13f7f64..abb86b6 100644 (file)
@@ -89,6 +89,8 @@ API int iotcon_resource_types_insert(iotcon_resource_types_h types, const char *
        char *resource_type;
 
        RETV_IF(NULL == type, IOTCON_ERROR_INVALID_PARAMETER);
+       RETVM_IF(1 < types->ref_count, IOTCON_ERROR_INVALID_PARAMETER,
+                       "Don't modify it. It is already set.");
 
        if (IOTCON_RESOURCE_TYPE_LENGTH_MAX < strlen(type)) {
                ERR("The length of type(%s) should be less than or equal to %d.", type,
@@ -119,6 +121,8 @@ API int iotcon_resource_types_delete(iotcon_resource_types_h types, const char *
 
        RETV_IF(NULL == types, IOTCON_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == type, IOTCON_ERROR_INVALID_PARAMETER);
+       RETVM_IF(1 < types->ref_count, IOTCON_ERROR_INVALID_PARAMETER,
+                       "Don't modify it. It is already set.");
 
        found_node = g_list_find_custom(types->type_list, type, _ic_resource_types_strcmp);
        if (NULL == found_node) {
@@ -126,6 +130,7 @@ API int iotcon_resource_types_delete(iotcon_resource_types_h types, const char *
                return IOTCON_ERROR_NO_DATA;
        }
 
+       free(found_node->data);
        types->type_list = g_list_delete_link(types->type_list, found_node);
 
        return IOTCON_ERROR_NONE;
index f88797c..61d573d 100644 (file)
@@ -101,7 +101,10 @@ API int iotcon_response_set(iotcon_response_h resp, iotcon_response_property_e p
                options = va_arg(args, iotcon_options_h);
                if (resp->header_options)
                        ic_options_free(resp->header_options);
-
+               if (NULL == options) {
+                       resp->header_options = NULL;
+                       break;
+               }
                if (true == options->has_parent)
                        resp->header_options = ic_options_ref(options);
                else