Modify iotcon_options API
authoryoungman <yman.jung@samsung.com>
Wed, 6 May 2015 11:57:27 +0000 (20:57 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Mon, 8 Jun 2015 10:39:35 +0000 (19:39 +0900)
Change-Id: Ieeaeb20e7ba71eeb78307a49af0af183bad41e49
Signed-off-by: youngman <yman.jung@samsung.com>
lib/ic-ioty.cpp
lib/ic-ioty.h
lib/ic-options.c [new file with mode: 0644]
lib/ic-options.h [new file with mode: 0644]
lib/ic-struct.h
lib/ic.c
lib/include/iotcon-constant.h
lib/include/iotcon-struct.h
lib/include/iotcon.h
test/crud-test-client.c
test/crud-test-server.c

index 0ecf9a5..e31d61c 100644 (file)
@@ -88,13 +88,13 @@ namespace icIotivityHandler {
                        resource_s.resource_uri = ic_utils_strdup(resource->uri().c_str());
                        resource_s.resource_host = ic_utils_strdup(resource->host().c_str());
                        resource_s.is_observable = resource->isObservable();
-                       resource_s.resource_types = iotcon_new_resource_types();
-                       resource_s.resource_interfaces = iotcon_new_resource_interfaces();
+                       resource_s.resource_types = iotcon_resource_types_new();
+                       resource_s.resource_interfaces = iotcon_resource_interfaces_new();
 
                        vector<string> resource_types = resource->getResourceTypes();
                        for (string &resource_type : resource_types)
                                resource_s.resource_types
-                                       = iotcon_add_resource_types(resource_s.resource_types,
+                                       = iotcon_resource_types_insert(resource_s.resource_types,
                                                        ic_utils_strdup(resource_type.c_str()));
 
                        vector<string> resource_interfaces = resource->getResourceInterfaces();
@@ -108,8 +108,8 @@ namespace icIotivityHandler {
 
                        free(resource_s.resource_uri);
                        free(resource_s.resource_host);
-                       iotcon_delete_resource_types(resource_s.resource_types);
-                       iotcon_delete_resource_interfaces(resource_s.resource_interfaces);
+                       iotcon_resource_types_free(resource_s.resource_types);
+                       iotcon_resource_interfaces_free(resource_s.resource_interfaces);
                }
        };
 
@@ -131,7 +131,7 @@ namespace icIotivityHandler {
                {
                        FN_CALL;
                        int res;
-                       iotcon_header_options header_options;
+                       iotcon_options_h options;
                        iotcon_repr_h repr = NULL;
 
                        if (OC_STACK_OK == eCode)
@@ -139,18 +139,18 @@ namespace icIotivityHandler {
                        else
                                res = IOTCON_ERR_IOTIVITY;
 
-                       header_options = iotcon_new_header_options();
+                       options = iotcon_options_new();
                        for (HeaderOption::OCHeaderOption option : headerOptions) {
-                               iotcon_add_header_option(header_options, option.getOptionID(),
+                               iotcon_options_insert(options, option.getOptionID(),
                                                option.getOptionData().c_str());
                        }
 
                        repr = ic_ioty_repr_generate_repr(ocRep);
 
                        if (on_get)
-                               on_get(header_options, repr, res, cb_data);
+                               on_get(options, repr, res, cb_data);
 
-                       iotcon_delete_header_options(header_options);
+                       iotcon_options_free(options);
                }
        };
 
@@ -172,7 +172,7 @@ namespace icIotivityHandler {
                {
                        FN_CALL;
                        int res;
-                       iotcon_header_options header_options;
+                       iotcon_options_h options;
                        iotcon_repr_h repr = NULL;
 
                        if (OC_STACK_OK == eCode)
@@ -180,18 +180,18 @@ namespace icIotivityHandler {
                        else
                                res = IOTCON_ERR_IOTIVITY;
 
-                       header_options = iotcon_new_header_options();
+                       options = iotcon_options_new();
                        for (HeaderOption::OCHeaderOption option : headerOptions) {
-                               iotcon_add_header_option(header_options, option.getOptionID(),
+                               iotcon_options_insert(options, option.getOptionID(),
                                                option.getOptionData().c_str());
                        }
 
                        repr = ic_ioty_repr_generate_repr(ocRep);
 
                        if (on_put)
-                               on_put(header_options, repr, res, cb_data);
+                               on_put(options, repr, res, cb_data);
 
-                       iotcon_delete_header_options(header_options);
+                       iotcon_options_free(options);
                }
        };
 
@@ -213,7 +213,7 @@ namespace icIotivityHandler {
                {
                        FN_CALL;
                        int res;
-                       iotcon_header_options header_options;
+                       iotcon_options_h options;
                        iotcon_repr_h repr = NULL;
 
                        if (OC_STACK_OK == eCode)
@@ -221,18 +221,18 @@ namespace icIotivityHandler {
                        else
                                res = IOTCON_ERR_IOTIVITY;
 
-                       header_options = iotcon_new_header_options();
+                       options = iotcon_options_new();
                        for (HeaderOption::OCHeaderOption option : headerOptions) {
-                               iotcon_add_header_option(header_options, option.getOptionID(),
+                               iotcon_options_insert(options, option.getOptionID(),
                                                option.getOptionData().c_str());
                        }
 
                        repr = ic_ioty_repr_generate_repr(ocRep);
 
                        if (on_post)
-                               on_post(header_options, repr, res, cb_data);
+                               on_post(options, repr, res, cb_data);
 
-                       iotcon_delete_header_options(header_options);
+                       iotcon_options_free(options);
                }
        };
 
@@ -252,23 +252,23 @@ namespace icIotivityHandler {
                void onDelete(const HeaderOptions& headerOptions, const int eCode)
                {
                        int res;
-                       iotcon_header_options header_options;
+                       iotcon_options_h options;
 
                        if (OC_STACK_OK == eCode)
                                res = IOTCON_ERR_NONE;
                        else
                                res = IOTCON_ERR_IOTIVITY;
 
-                       header_options = iotcon_new_header_options();
+                       options = iotcon_options_new();
                        for (HeaderOption::OCHeaderOption option : headerOptions) {
-                               iotcon_add_header_option(header_options, option.getOptionID(),
+                               iotcon_options_insert(options, option.getOptionID(),
                                                option.getOptionData().c_str());
                        }
 
                        if (on_delete)
-                               on_delete(header_options, res, cb_data);
+                               on_delete(options, res, cb_data);
 
-                       iotcon_delete_header_options(header_options);
+                       iotcon_options_free(options);
                }
        };
 
@@ -290,7 +290,7 @@ namespace icIotivityHandler {
                {
                        FN_CALL;
                        int res;
-                       iotcon_header_options header_options;
+                       iotcon_options_h options;
                        iotcon_repr_h repr = NULL;
 
                        if (OC_STACK_OK == eCode)
@@ -298,18 +298,18 @@ namespace icIotivityHandler {
                        else
                                res = IOTCON_ERR_IOTIVITY;
 
-                       header_options = iotcon_new_header_options();
+                       options = iotcon_options_new();
                        for (HeaderOption::OCHeaderOption option : headerOptions) {
-                               iotcon_add_header_option(header_options, option.getOptionID(),
+                               iotcon_options_insert(options, option.getOptionID(),
                                                option.getOptionData().c_str());
                        }
 
                        repr = ic_ioty_repr_generate_repr(ocRep);
 
                        if (on_observe)
-                               on_observe(header_options, repr, res, sequenceNumber, cb_data);
+                               on_observe(options, repr, res, sequenceNumber, cb_data);
 
-                       iotcon_delete_header_options(header_options);
+                       iotcon_options_free(options);
                }
        };
 }
@@ -341,8 +341,8 @@ static OCEntityHandlerResult _entity_handler(shared_ptr<OCResourceRequest> reque
                return OC_EH_ERROR;
        }
 
-       request_s.query_params = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
-       if (NULL == request_s.query_params) {
+       request_s.query = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
+       if (NULL == request_s.query) {
                ERR("g_hash_table_new_full() Fail");
                return OC_EH_ERROR;
        }
@@ -351,13 +351,13 @@ static OCEntityHandlerResult _entity_handler(shared_ptr<OCResourceRequest> reque
        queryParams = request->getQueryParameters();
        for (it = queryParams.begin(); it != queryParams.end(); ++it) {
                DBG("key=%s value=%s", it->first.c_str(), it->second.c_str());
-               g_hash_table_insert(request_s.query_params, ic_utils_strdup(it->first.c_str()),
+               g_hash_table_insert(request_s.query, ic_utils_strdup(it->first.c_str()),
                                ic_utils_strdup(it->second.c_str()));
        }
 
-       request_s.header_opts = iotcon_new_header_options();
-       if (NULL == request_s.header_opts) {
-               ERR("iot_new_header_options() Fail");
+       request_s.header_options = iotcon_options_new();
+       if (NULL == request_s.header_options) {
+               ERR("iotcon_options_new() Fail");
                return OC_EH_ERROR;
        }
 
@@ -366,8 +366,7 @@ static OCEntityHandlerResult _entity_handler(shared_ptr<OCResourceRequest> reque
                for (auto it1 = headerOptions.begin(); it1 != headerOptions.end(); ++it1) {
                        DBG("OptionID=%d, OptionData=%s",
                                        it1->getOptionID(), it1->getOptionData().c_str());
-                       iotcon_add_header_option(request_s.header_opts,
-                                       it1->getOptionID(),
+                       iotcon_options_insert(request_s.header_options, it1->getOptionID(),
                                        it1->getOptionData().c_str());
                }
        }
@@ -385,8 +384,8 @@ static OCEntityHandlerResult _entity_handler(shared_ptr<OCResourceRequest> reque
        request_s.request_type = ic_utils_strdup(request->getRequestType().c_str());
        if (NULL == request_s.request_type) {
                ERR("ic_utils_strdup() Fail");
-               g_hash_table_destroy(request_s.header_opts);
-               g_hash_table_destroy(request_s.query_params);
+               iotcon_options_free(request_s.header_options);
+               iotcon_query_free(request_s.query);
                return OC_EH_ERROR;
        }
 
@@ -394,8 +393,8 @@ static OCEntityHandlerResult _entity_handler(shared_ptr<OCResourceRequest> reque
        if (NULL == request_s.request_type) {
                ERR("ic_utils_strdup() Fail");
                free(request_s.request_type);
-               g_hash_table_destroy(request_s.header_opts);
-               g_hash_table_destroy(request_s.query_params);
+               iotcon_options_free(request_s.header_options);
+               iotcon_query_free(request_s.query);
                return OC_EH_ERROR;
        }
 
@@ -420,8 +419,8 @@ static OCEntityHandlerResult _entity_handler(shared_ptr<OCResourceRequest> reque
        free(request_s.res_uri);
        if (request_s.repr) /* To avoid unnecessary ERR log (repr could be NULL) */
                iotcon_repr_free(request_s.repr);
-       g_hash_table_destroy(request_s.header_opts);
-       g_hash_table_destroy(request_s.query_params);
+       iotcon_options_free(request_s.header_options);
+       iotcon_query_free(request_s.query);
 
        return OC_EH_OK;
 }
@@ -691,7 +690,7 @@ extern "C" iotcon_presence_h ic_ioty_subscribe_presence(const char *host_address
        shared_ptr<icIotivityHandler::presenceObject> object
                = make_shared<icIotivityHandler::presenceObject>(presence_handler_cb, user_data);
        SubscribeCallback subscribeCallback
-               = bind(&icIotivityHandler::presenceObject::presenceHandler,     object,
+               = bind(&icIotivityHandler::presenceObject::presenceHandler, object,
                                placeholders::_1, placeholders::_2, placeholders::_3);
 
        ret = subscribePresence(presence_handle, host_address, subscribeCallback);
@@ -748,7 +747,7 @@ extern "C" int ic_ioty_find_resource(const char *host, const char *resource_name
        shared_ptr<icIotivityHandler::findObject> object
                = make_shared<icIotivityHandler::findObject>(found_resource_cb, user_data);
        FindCallback findCallback = bind(&icIotivityHandler::findObject::foundResource,
-                       object, placeholders::_1);
+                       object, placeholders::_1);
 
        ret = findResource(host, resource_name, findCallback);
        if (OC_STACK_OK != ret) {
@@ -759,29 +758,33 @@ extern "C" int ic_ioty_find_resource(const char *host, const char *resource_name
        return IOTCON_ERR_NONE;
 }
 
-static OCResource::Ptr _create_oc_resource(iotcon_resource_s resource)
+static void _change_options(unsigned short id, char *data, void *user_data)
 {
-       RETV_IF(NULL == resource.resource_host, NULL);
-       RETV_IF(NULL == resource.resource_uri, NULL);
+       HeaderOptions *options = static_cast<HeaderOptions *>(user_data);
+       HeaderOption::OCHeaderOption option(id, data);
+       (*options).push_back(option);
+}
 
+static OCResource::Ptr _create_oc_resource(iotcon_resource_s resource)
+{
        string host = resource.resource_host;
        string uri = resource.resource_uri;
        vector<string> resource_types;
        vector<string> resource_ifs;
 
        HeaderOptions header_options;
-       GHashTableIter iter;
-       gpointer key = NULL;
-       gpointer value = NULL;
+
+       RETV_IF(NULL == resource.resource_host, NULL);
+       RETV_IF(NULL == resource.resource_uri, NULL);
 
        GList *node = resource.resource_types;
-       for (node = g_list_first(node); NULL != node; node = g_list_next(node)) {
+       for (node = g_list_first(node); node; node = g_list_next(node)) {
                string resource_type_str = (char *)node->data;
                resource_types.push_back(resource_type_str);
        }
 
        node = resource.resource_interfaces;
-       for (node = g_list_first(node); NULL != node; node = g_list_next(node)) {
+       for (node = g_list_first(node); node; node = g_list_next(node)) {
                string resource_if_str = (char *)node->data;
                resource_ifs.push_back(resource_if_str);
        }
@@ -789,13 +792,9 @@ static OCResource::Ptr _create_oc_resource(iotcon_resource_s resource)
        OCResource::Ptr ocResource = constructResourceObject(host, uri,
                        resource.is_observable, resource_types, resource_ifs);
 
-       if (NULL != resource.header_options) {
-               g_hash_table_iter_init(&iter, resource.header_options);
-               while (g_hash_table_iter_next(&iter, &key, &value)) {
-                       HeaderOption::OCHeaderOption header_option(
-                                       GPOINTER_TO_UINT(key), (const char *)value);
-                       header_options.push_back(header_option);
-               }
+       if (resource.header_options) {
+               iotcon_options_foreach(resource.header_options, _change_options,
+                               (void *)&header_options);
                ocResource->setHeaderOptions(header_options);
        }
 
@@ -803,22 +802,23 @@ static OCResource::Ptr _create_oc_resource(iotcon_resource_s resource)
 }
 
 extern "C" int ic_ioty_get(iotcon_resource_s resource,
-               iotcon_query_parameters query_params, iotcon_on_get_cb on_get_cb, void *user_data)
+               iotcon_query query, iotcon_on_get_cb on_get_cb, void *user_data)
 {
        FN_CALL;
        OCStackResult ret;
        OCResource::Ptr ocResource = NULL;
 
-       QueryParamsMap query;
+       QueryParamsMap queryParams;
+
        GHashTableIter iter;
        gpointer key, value;
 
-       if (NULL != query_params) {
-               g_hash_table_iter_init(&iter, query_params);
+       if (query) {
+               g_hash_table_iter_init(&iter, query);
                while (g_hash_table_iter_next(&iter, &key, &value)) {
                        string keyStr = (char *)key;
                        string valueStr = (char *)value;
-                       query[keyStr] = valueStr;
+                       queryParams[keyStr] = valueStr;
                }
        }
 
@@ -828,7 +828,7 @@ extern "C" int ic_ioty_get(iotcon_resource_s resource,
                = make_shared<icIotivityHandler::getObject>(on_get_cb, user_data);
        GetCallback getCallback = bind(&icIotivityHandler::getObject::onGet, object,
                        placeholders::_1, placeholders::_2, placeholders::_3);
-       ret = ocResource->get(query, getCallback);
+       ret = ocResource->get(queryParams, getCallback);
        if (OC_STACK_OK != ret) {
                ERR("get() Fail(%d)", ret);
                return IOTCON_ERR_IOTIVITY;
@@ -839,7 +839,7 @@ extern "C" int ic_ioty_get(iotcon_resource_s resource,
 
 extern "C" int ic_ioty_put(iotcon_resource_s resource,
                iotcon_repr_h repr,
-               iotcon_query_parameters query_params,
+               iotcon_query query,
                iotcon_on_put_cb on_put_cb,
                void *user_data)
 {
@@ -848,17 +848,17 @@ extern "C" int ic_ioty_put(iotcon_resource_s resource,
 
        OCResource::Ptr ocResource = NULL;
        OCRepresentation ocRep;
-       QueryParamsMap query;
+       QueryParamsMap queryParams;
 
        GHashTableIter iter;
        gpointer key, value;
 
-       if (NULL != query_params) {
-               g_hash_table_iter_init(&iter, query_params);
+       if (query) {
+               g_hash_table_iter_init(&iter, query);
                while (g_hash_table_iter_next(&iter, &key, &value)) {
                        string keyStr = (char *)key;
                        string valueStr = (char *)value;
-                       query[keyStr] = valueStr;
+                       queryParams[keyStr] = valueStr;
                }
        }
 
@@ -871,7 +871,7 @@ extern "C" int ic_ioty_put(iotcon_resource_s resource,
        PutCallback putCallback = bind(&icIotivityHandler::putObject::onPut, object,
                        placeholders::_1, placeholders::_2, placeholders::_3);
 
-       ret = ocResource->put(ocRep, query, putCallback);
+       ret = ocResource->put(ocRep, queryParams, putCallback);
        if (OC_STACK_OK != ret) {
                ERR("put() Fail(%d)", ret);
                return IOTCON_ERR_IOTIVITY;
@@ -882,7 +882,7 @@ extern "C" int ic_ioty_put(iotcon_resource_s resource,
 
 extern "C" int ic_ioty_post(iotcon_resource_s resource,
                iotcon_repr_h repr,
-               iotcon_query_parameters query_params,
+               iotcon_query query,
                iotcon_on_post_cb on_post_cb,
                void *user_data)
 {
@@ -890,16 +890,16 @@ extern "C" int ic_ioty_post(iotcon_resource_s resource,
        OCStackResult ret;
        GHashTableIter iter;
        gpointer key, value;
-       QueryParamsMap query;
+       QueryParamsMap queryParams;
        OCRepresentation ocRep;
        OCResource::Ptr ocResource = NULL;
 
-       if (NULL != query_params) {
-               g_hash_table_iter_init(&iter, query_params);
+       if (query) {
+               g_hash_table_iter_init(&iter, query);
                while (g_hash_table_iter_next(&iter, &key, &value)) {
                        string keyStr = (char *)key;
                        string valueStr = (char *)value;
-                       query[keyStr] = valueStr;
+                       queryParams[keyStr] = valueStr;
                }
        }
 
@@ -912,7 +912,7 @@ extern "C" int ic_ioty_post(iotcon_resource_s resource,
        PostCallback postCallback = bind(&icIotivityHandler::postObject::onPost, object,
                        placeholders::_1, placeholders::_2, placeholders::_3);
 
-       ret = ocResource->post(ocRep, query, postCallback);
+       ret = ocResource->post(ocRep, queryParams, postCallback);
        if (OC_STACK_OK != ret) {
                ERR("post() Fail(%d)", ret);
                return IOTCON_ERR_IOTIVITY;
@@ -933,7 +933,7 @@ extern "C" int ic_ioty_delete_res(iotcon_resource_s resource,
        shared_ptr<icIotivityHandler::deleteObject> object
                = make_shared<icIotivityHandler::deleteObject>(on_delete_cb, user_data);
        DeleteCallback deleteCallback = bind(&icIotivityHandler::deleteObject::onDelete,
-                       object, placeholders::_1, placeholders::_2);
+                       object, placeholders::_1, placeholders::_2);
 
        ret = ocResource->deleteResource(deleteCallback);
        if (OC_STACK_OK != ret) {
@@ -946,7 +946,7 @@ extern "C" int ic_ioty_delete_res(iotcon_resource_s resource,
 
 extern "C" int ic_ioty_observe(iotcon_resource_s *resource,
                iotcon_observe_type_e observe_type,
-               iotcon_query_parameters query_params,
+               iotcon_query query,
                iotcon_on_observe_cb on_observe_cb,
                void *user_data)
 {
@@ -955,16 +955,16 @@ extern "C" int ic_ioty_observe(iotcon_resource_s *resource,
        OCResource::Ptr ocResource = NULL;
        ObserveType observeType;
 
-       QueryParamsMap query;
+       QueryParamsMap queryParams;
        GHashTableIter iter;
        gpointer key, value;
 
-       if (NULL != query_params) {
-               g_hash_table_iter_init(&iter, query_params);
+       if (query) {
+               g_hash_table_iter_init(&iter, query);
                while (g_hash_table_iter_next(&iter, &key, &value)) {
                        string keyStr = (char *)key;
                        string valueStr = (char *)value;
-                       query[keyStr] = valueStr;
+                       queryParams[keyStr] = valueStr;
                }
        }
 
@@ -988,9 +988,9 @@ extern "C" int ic_ioty_observe(iotcon_resource_s *resource,
        shared_ptr<icIotivityHandler::observeObject> object
                = make_shared<icIotivityHandler::observeObject>(on_observe_cb, user_data);
        ObserveCallback observeCallback = bind(&icIotivityHandler::observeObject::onObserve,
-                       object, placeholders::_1, placeholders::_2, placeholders::_3,
+                       object, placeholders::_1, placeholders::_2, placeholders::_3,
                        placeholders::_4);
-       ret = ocResource->observe(observeType, query, observeCallback);
+       ret = ocResource->observe(observeType, queryParams, observeCallback);
        if (OC_STACK_OK != ret) {
                ERR("observe() Fail(%d)", ret);
                return IOTCON_ERR_IOTIVITY;
index ba285c5..de3d583 100644 (file)
@@ -59,29 +59,20 @@ int ic_ioty_stop_presence();
 int ic_ioty_find_resource(const char *host, const char *resource_name,
                iotcon_found_resource_cb found_resource_cb, void *user_data);
 
-int ic_ioty_get(iotcon_resource_s resource,    iotcon_query_parameters query_params,
+int ic_ioty_get(iotcon_resource_s resource,    iotcon_query query,
                iotcon_on_get_cb on_get_cb, void *user_data);
 
-int ic_ioty_put(iotcon_resource_s resource,
-               iotcon_repr_h repr,
-               iotcon_query_parameters query_params,
-               iotcon_on_put_cb on_put_cb,
-               void *user_data);
+int ic_ioty_put(iotcon_resource_s resource, iotcon_repr_h repr, iotcon_query query,
+               iotcon_on_put_cb on_put_cb, void *user_data);
 
-int ic_ioty_post(iotcon_resource_s resource,
-               iotcon_repr_h repr,
-               iotcon_query_parameters query_params,
-               iotcon_on_put_cb on_post_cb,
-               void *user_data);
+int ic_ioty_post(iotcon_resource_s resource, iotcon_repr_h repr, iotcon_query query,
+               iotcon_on_put_cb on_post_cb, void *user_data);
 
 int ic_ioty_delete_res(iotcon_resource_s resource,
                iotcon_on_delete_cb on_delete_cb, void *user_data);
 
-int ic_ioty_observe(iotcon_resource_s *resource,
-               iotcon_observe_type_e observe_type,
-               iotcon_query_parameters query_params,
-               iotcon_on_observe_cb on_observe_cb,
-               void *user_data);
+int ic_ioty_observe(iotcon_resource_s *resource, iotcon_observe_type_e observe_type,
+               iotcon_query query, iotcon_on_observe_cb on_observe_cb, void *user_data);
 
 int ic_ioty_cancel_observe(iotcon_resource_s resource);
 
diff --git a/lib/ic-options.c b/lib/ic-options.c
new file mode 100644 (file)
index 0000000..68a81e4
--- /dev/null
@@ -0,0 +1,128 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <stdlib.h>
+#include <errno.h>
+#include <glib.h>
+
+#include "iotcon.h"
+
+#include "ic-common.h"
+#include "ic-utils.h"
+#include "ic-struct.h"
+#include "ic-ioty.h"
+#include "ic-options.h"
+
+API iotcon_options_h iotcon_options_new()
+{
+       iotcon_options_h options = calloc(1, sizeof(struct ic_options_s));
+       if (NULL == options) {
+               ERR("calloc() Fail(%d)", errno);
+               return NULL;
+       }
+
+       options->options = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, free);
+       return options;
+}
+
+void ic_options_free(iotcon_options_h options)
+{
+       RET_IF(NULL == options);
+
+       g_hash_table_unref(options->options);
+       free(options);
+}
+
+API void iotcon_options_free(iotcon_options_h options)
+{
+       RET_IF(NULL == options);
+       RETM_IF(true == options->has_parent, "iotcon_options has parent");
+
+       ic_options_free(options);
+}
+
+API int iotcon_options_insert(iotcon_options_h options, const unsigned short id,
+               const char *data)
+{
+       FN_CALL;
+       gpointer value;
+
+       RETVM_IF(((id < IOTCON_OPTIONID_MIN) || (IOTCON_OPTIONID_MAX < id)), IOTCON_ERR_PARAM,
+                       "Invalid id(%d)", id);
+
+       value = ic_utils_strdup(data);
+
+       g_hash_table_insert(options->options, GUINT_TO_POINTER(id), value);
+
+       return IOTCON_ERR_NONE;
+}
+
+API int iotcon_options_delete(iotcon_options_h options, const unsigned short id)
+{
+       gboolean ret;
+
+       RETV_IF(NULL == options, IOTCON_ERR_PARAM);
+
+       ret = g_hash_table_remove(options->options, GUINT_TO_POINTER(id));
+       if (FALSE == ret) {
+               ERR("g_hash_table_remove() Fail");
+               return IOTCON_ERR_PARAM;
+       }
+       return IOTCON_ERR_NONE;
+}
+
+API const char* iotcon_options_lookup(iotcon_options_h options, const unsigned short id)
+{
+       const char *ret;
+
+       RETV_IF(NULL == options, NULL);
+
+       ret = g_hash_table_lookup(options->options, GUINT_TO_POINTER(id));
+       if (NULL == ret)
+               ERR("g_hash_table_lookup() Fail");
+
+       return ret;
+}
+
+API void iotcon_options_foreach(iotcon_options_h options,
+               iotcon_options_foreach_cb foreach_cb, void *user_data)
+{
+       GHashTableIter iter;
+       gpointer key, value;
+
+       RET_IF(NULL == options);
+
+       g_hash_table_iter_init(&iter, options->options);
+       while (g_hash_table_iter_next(&iter, &key, &value))
+               foreach_cb(GPOINTER_TO_UINT(key), value, user_data);
+}
+
+API iotcon_options_h iotcon_options_clone(iotcon_options_h options)
+{
+       iotcon_options_h clone = NULL;
+
+       RETV_IF(NULL == options, NULL);
+
+       clone = calloc(1, sizeof(struct ic_options_s));
+       if (NULL == clone) {
+               ERR("calloc() Fail(%d)", errno);
+               return NULL;
+       }
+
+       clone->options = g_hash_table_ref(options->options);
+
+       return clone;
+}
+
diff --git a/lib/ic-options.h b/lib/ic-options.h
new file mode 100644 (file)
index 0000000..ba910cc
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __IOT_CONNECTIVITY_MANAGER_INTERNAL_OPTIONS_H__
+#define __IOT_CONNECTIVITY_MANAGER_INTERNAL_OPTIONS_H__
+
+#include "iotcon-struct.h"
+
+void ic_options_free(iotcon_options_h options);
+
+#endif //__IOT_CONNECTIVITY_MANAGER_INTERNAL_OPTIONS_H__
index 3ed997c..c074f64 100644 (file)
@@ -55,11 +55,16 @@ typedef struct {
        struct ic_repr_s *repr;
 } ic_val_repr_s;
 
+struct ic_options_s {
+       bool has_parent;
+       GHashTable *options;
+};
+
 /* related with iotcon_response_property_e */
 struct ic_res_response_s {
        char *new_resource_uri;
        int error_code;
-       iotcon_header_options header_options;
+       iotcon_options_h header_options;
        iotcon_interface_e interface;
        iotcon_request_h request_handle;
        iotcon_resource_h resource_handle;
index bbd2a12..a2ca79c 100644 (file)
--- a/lib/ic.c
+++ b/lib/ic.c
@@ -13,7 +13,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
 #include <glib.h>
@@ -25,6 +24,7 @@
 #include "ic-utils.h"
 #include "ic-struct.h"
 #include "ic-ioty.h"
+#include "ic-options.h"
 
 /**
  * @brief global context
@@ -91,7 +91,7 @@ API void iotcon_deinitialize()
        _set_iotcon_init(FALSE);
 }
 
-API iotcon_response_h iotcon_create_response(iotcon_request_h req_h,
+API iotcon_response_h iotcon_response_new(iotcon_request_h req_h,
                iotcon_resource_h res_h)
 {
        FN_CALL;
@@ -114,6 +114,8 @@ API int iotcon_response_set(iotcon_response_h resp, iotcon_response_property_e p
 {
        int value;
        va_list args;
+       char *new_resource_uri = NULL;
+       iotcon_options_h options = NULL;
 
        va_start(args, prop);
 
@@ -133,7 +135,25 @@ API int iotcon_response_set(iotcon_response_h resp, iotcon_response_property_e p
                resp->error_code = va_arg(args, int);
                break;
        case IOTCON_RESP_RES_URI:
-               resp->new_resource_uri = va_arg(args, char*);
+               new_resource_uri = va_arg(args, char*);
+               if (resp->new_resource_uri)
+                       free(resp->new_resource_uri);
+
+               if (new_resource_uri)
+                       resp->new_resource_uri = ic_utils_strdup(new_resource_uri);
+               else
+                       resp->new_resource_uri = NULL;
+               break;
+       case IOTCON_RESP_HEADER_OPTIONS:
+               options = va_arg(args, iotcon_options_h);
+               if (resp->header_options)
+                       ic_options_free(resp->header_options);
+
+               if (true == options->has_parent)
+                       resp->header_options = iotcon_options_clone(options);
+               else
+                       resp->header_options = options;
+               resp->header_options->has_parent = true;
                break;
        case IOTCON_RESP_NONE:
        default:
@@ -145,7 +165,7 @@ API int iotcon_response_set(iotcon_response_h resp, iotcon_response_property_e p
        return IOTCON_ERR_NONE;
 }
 
-API void iotcon_delete_response(iotcon_response_h resp)
+API void iotcon_response_free(iotcon_response_h resp)
 {
        FN_CALL;
        struct ic_res_response_s *data = resp;
@@ -153,7 +173,7 @@ API void iotcon_delete_response(iotcon_response_h resp)
        RET_IF(NULL == resp);
 
        free(data->new_resource_uri);
-       iotcon_delete_header_options(data->header_options);
+       ic_options_free(resp->header_options);
        iotcon_repr_free(resp->repr);
        free(data);
 }
@@ -453,15 +473,15 @@ API iotcon_resource_s iotcon_construct_resource_object(const char *host,
        resource_s.resource_host = ic_utils_strdup(host);
        resource_s.resource_uri = ic_utils_strdup(uri);
        resource_s.is_observable = is_observable;
-       resource_s.resource_types = iotcon_new_resource_types();
-       resource_s.resource_interfaces = iotcon_new_resource_interfaces();
+       resource_s.resource_types = iotcon_resource_types_new();
+       resource_s.resource_interfaces = iotcon_resource_interfaces_new();
 
-       for (node = g_list_first(resource_type); NULL != node; node = g_list_next(node)) {
+       for (node = g_list_first(resource_type); node; node = g_list_next(node)) {
                resource_s.resource_types = g_list_append(resource_s.resource_types,
                                ic_utils_strdup(node->data));
        }
 
-       for (node = g_list_first(resource_if); NULL != node; node = g_list_next(node)) {
+       for (node = g_list_first(resource_if); node; node = g_list_next(node)) {
                resource_s.resource_interfaces = g_list_append(resource_s.resource_interfaces,
                                ic_utils_strdup(node->data));
        }
@@ -475,9 +495,9 @@ API void iotcon_destruct_resource_object(iotcon_resource_s *resource)
 
        free(resource->resource_uri);
        free(resource->resource_host);
-       iotcon_delete_header_options(resource->header_options);
-       iotcon_delete_resource_types(resource->resource_types);
-       iotcon_delete_resource_interfaces(resource->resource_interfaces);
+       iotcon_options_free(resource->header_options);
+       iotcon_resource_types_free(resource->resource_types);
+       iotcon_resource_interfaces_free(resource->resource_interfaces);
 }
 
 API iotcon_resource_s iotcon_copy_resource(iotcon_resource_s resource)
@@ -490,17 +510,16 @@ API iotcon_resource_s iotcon_copy_resource(iotcon_resource_s resource)
        resource_s.resource_host = ic_utils_strdup(resource.resource_host);
        resource_s.resource_uri = ic_utils_strdup(resource.resource_uri);
        resource_s.is_observable = resource.is_observable;
-       resource_s.resource_types = iotcon_new_resource_types();
-       resource_s.resource_interfaces = iotcon_new_resource_interfaces();
+       resource_s.resource_types = iotcon_resource_types_new();
+       resource_s.resource_interfaces = iotcon_resource_interfaces_new();
        resource_s.observe_handle = resource.observe_handle;
 
-       for (node = g_list_first(resource.resource_types); NULL != node;
-                       node = g_list_next(node)) {
+       for (node = g_list_first(resource.resource_types); node; node = g_list_next(node)) {
                resource_s.resource_types = g_list_append(resource_s.resource_types,
                                ic_utils_strdup(node->data));
        }
 
-       for (node = g_list_first(resource.resource_interfaces); NULL != node;
+       for (node = g_list_first(resource.resource_interfaces); node;
                        node = g_list_next(node)) {
                resource_s.resource_interfaces = g_list_append(resource_s.resource_interfaces,
                                ic_utils_strdup(node->data));
@@ -509,22 +528,22 @@ API iotcon_resource_s iotcon_copy_resource(iotcon_resource_s resource)
        return resource_s;
 }
 
-API int iotcon_get(iotcon_resource_s resource, iotcon_query_parameters query_params,
+API int iotcon_get(iotcon_resource_s resource, iotcon_query query,
                iotcon_on_get_cb on_get_cb, void *user_data)
 {
        FN_CALL;
 
        int ret = IOTCON_ERR_NONE;
 
-       ret = ic_ioty_get(resource, query_params, on_get_cb, user_data);
+       ret = ic_ioty_get(resource, query, on_get_cb, user_data);
        if (IOTCON_ERR_NONE != ret)
                ERR("ic_ioty_get() Fail(%d)", ret);
 
        return ret;
 }
 
-API int iotcon_put(iotcon_resource_s resource, iotcon_repr_h repr,
-               iotcon_query_parameters query_params, iotcon_on_put_cb on_put_cb, void *user_data)
+API int iotcon_put(iotcon_resource_s resource, iotcon_repr_h repr, iotcon_query query,
+               iotcon_on_put_cb on_put_cb, void *user_data)
 {
        FN_CALL;
 
@@ -532,7 +551,7 @@ API int iotcon_put(iotcon_resource_s resource, iotcon_repr_h repr,
 
        RETV_IF(NULL == repr, IOTCON_ERR_PARAM);
 
-       ret = ic_ioty_put(resource, repr, query_params, on_put_cb, user_data);
+       ret = ic_ioty_put(resource, repr, query, on_put_cb, user_data);
        if (IOTCON_ERR_NONE != ret)
                ERR("ic_ioty_put() Fail(%d)", ret);
 
@@ -541,7 +560,7 @@ API int iotcon_put(iotcon_resource_s resource, iotcon_repr_h repr,
 
 API int iotcon_post(iotcon_resource_s resource,
                iotcon_repr_h repr,
-               iotcon_query_parameters query_params,
+               iotcon_query query,
                iotcon_on_post_cb on_post_cb,
                void *user_data)
 {
@@ -551,7 +570,7 @@ API int iotcon_post(iotcon_resource_s resource,
 
        RETV_IF(NULL == repr, IOTCON_ERR_PARAM);
 
-       ret = ic_ioty_post(resource, repr, query_params, on_post_cb, user_data);
+       ret = ic_ioty_post(resource, repr, query, on_post_cb, user_data);
        if (IOTCON_ERR_NONE != ret)
                ERR("ic_ioty_post() Fail(%d)", ret);
 
@@ -574,7 +593,7 @@ API int iotcon_delete_resource(iotcon_resource_s resource,
 
 API int iotcon_observe(iotcon_observe_type_e observe_type,
                iotcon_resource_s *resource,
-               iotcon_query_parameters query_params,
+               iotcon_query query,
                iotcon_on_observe_cb on_observe_cb,
                void *user_data)
 {
@@ -582,7 +601,7 @@ API int iotcon_observe(iotcon_observe_type_e observe_type,
 
        int ret = IOTCON_ERR_NONE;
 
-       ret = ic_ioty_observe(resource, observe_type, query_params, on_observe_cb,
+       ret = ic_ioty_observe(resource, observe_type, query, on_observe_cb,
                        user_data);
        if (IOTCON_ERR_NONE != ret)
                ERR("ic_ioty_observe() Fail(%d)", ret);
@@ -603,13 +622,13 @@ API int iotcon_cancel_observe(iotcon_resource_s resource)
        return ret;
 }
 
-API iotcon_resource_types iotcon_new_resource_types()
+API iotcon_resource_types iotcon_resource_types_new()
 {
        return NULL;
 }
 
-API iotcon_resource_types iotcon_add_resource_types(iotcon_resource_types resource_types,
-               const char *resource_type)
+API iotcon_resource_types iotcon_resource_types_insert(
+               iotcon_resource_types resource_types, const char *resource_type)
 {
        FN_CALL;
 
@@ -617,21 +636,21 @@ API iotcon_resource_types iotcon_add_resource_types(iotcon_resource_types resour
        return resource_types;
 }
 
-API void iotcon_delete_resource_types(iotcon_resource_types resource_types)
+API void iotcon_resource_types_free(iotcon_resource_types resource_types)
 {
        FN_CALL;
 
-       g_list_free_full(resource_types, g_free);
+       g_list_free_full(resource_types, free);
 }
 
-API iotcon_resource_interfaces iotcon_new_resource_interfaces()
+API iotcon_resource_interfaces iotcon_resource_interfaces_new()
 {
        FN_CALL;
 
        return NULL;
 }
 
-API iotcon_resource_interfaces iotcon_add_resource_interfaces(
+API iotcon_resource_interfaces iotcon_resource_interfaces_insert(
                iotcon_resource_interfaces resource_interfaces, iotcon_interface_e interface)
 {
        FN_CALL;
@@ -661,75 +680,45 @@ API iotcon_resource_interfaces iotcon_add_resource_interfaces(
        return resource_interfaces;
 }
 
-API void iotcon_delete_resource_interfaces(iotcon_resource_interfaces resource_interfaces)
-{
-       FN_CALL;
-
-       g_list_free_full(resource_interfaces, g_free);
-}
-
-API iotcon_header_options iotcon_new_header_options()
-{
-       iotcon_header_options options = NULL;
-       options = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free);
-       return options;
-}
-
-API iotcon_error_e iotcon_add_header_option(iotcon_header_options options,
-               const unsigned short id, const char *data)
+API void iotcon_resource_interfaces_free(iotcon_resource_interfaces resource_interfaces)
 {
        FN_CALL;
 
-       RETV_IF(((id < IOTCON_HEADER_OPTIONID_MIN)
-                               || (IOTCON_HEADER_OPTIONID_MAX < id)), IOTCON_ERR_PARAM);
-
-       gpointer value = ic_utils_strdup(data);
-
-       g_hash_table_insert(options, GUINT_TO_POINTER(id), value);
-
-       return IOTCON_ERR_NONE;
-}
-
-API void iotcon_delete_header_options(iotcon_header_options options)
-{
-       RET_IF(NULL == options);
-
-       g_hash_table_destroy(options);
+       g_list_free_full(resource_interfaces, free);
 }
 
-API iotcon_query_parameters iotcon_new_query_params()
+API iotcon_query iotcon_query_new()
 {
-       iotcon_query_parameters query_params = NULL;
+       iotcon_query query = NULL;
 
-       query_params = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
+       query = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
 
-       return query_params;
+       return query;
 }
 
-API void iotcon_add_query_param(iotcon_query_parameters query_params, const char *key,
-               const char *value)
+API void iotcon_query_insert(iotcon_query query, const char *key, const char *value)
 {
-       g_hash_table_insert(query_params, ic_utils_strdup(key), ic_utils_strdup(value));
+       g_hash_table_insert(query, ic_utils_strdup(key), ic_utils_strdup(value));
 }
 
-API void iotcon_delete_query_params(iotcon_query_parameters query_params)
+API void iotcon_query_free(iotcon_query query)
 {
-       RET_IF(NULL == query_params);
+       RET_IF(NULL == query);
 
-       g_hash_table_destroy(query_params);
+       g_hash_table_destroy(query);
 }
 
-API char* iotcon_find_query_param(iotcon_query_parameters query_params, const char *key)
+API char* iotcon_query_lookup(iotcon_query query, const char *key)
 {
-       return g_hash_table_lookup(query_params, key);
+       return g_hash_table_lookup(query, key);
 }
 
-API iotcon_observers iotcon_new_observation()
+API iotcon_observers iotcon_observation_new()
 {
        return NULL;
 }
 
-API iotcon_observers iotcon_add_observation(iotcon_observers observers,
+API iotcon_observers iotcon_observation_insert(iotcon_observers observers,
                iotcon_observation_info_s obs)
 {
        iotcon_observation_info_s *obs_node = calloc(1, sizeof(iotcon_observation_info_s));
@@ -743,7 +732,7 @@ API iotcon_observers iotcon_add_observation(iotcon_observers observers,
        return observers;
 }
 
-API iotcon_observers iotcon_delete_observation(iotcon_observers observers,
+API iotcon_observers iotcon_observation_delete(iotcon_observers observers,
                iotcon_observation_info_s obs)
 {
        GList *node = NULL;
@@ -754,54 +743,43 @@ API iotcon_observers iotcon_delete_observation(iotcon_observers observers,
        return observers;
 }
 
-API void iotcon_free_observation(iotcon_observers observers)
+API void iotcon_observation_free(iotcon_observers observers)
 {
-       g_list_free_full(observers, g_free);
+       g_list_free_full(observers, free);
 }
 
-API char* iotcon_get_resource_uri(iotcon_resource_s resource_s)
+API char* iotcon_resource_get_uri(iotcon_resource_s resource_s)
 {
        return resource_s.resource_uri;
 }
 
-API char* iotcon_get_resource_host(iotcon_resource_s resource_s)
+API char* iotcon_resource_get_host(iotcon_resource_s resource_s)
 {
        return resource_s.resource_host;
 }
 
-API iotcon_resource_types iotcon_get_resource_types(iotcon_resource_s resource_s)
+API iotcon_resource_types iotcon_resource_get_types(iotcon_resource_s resource_s)
 {
        return resource_s.resource_types;
 }
 
-API iotcon_resource_interfaces iotcon_get_resource_interfaces(
-               iotcon_resource_s resource_s)
+API iotcon_resource_interfaces iotcon_resource_get_interfaces(iotcon_resource_s resource_s)
 {
        return resource_s.resource_interfaces;
 }
 
-API void iotcon_set_header_options(iotcon_resource_s *resource_s,
-               iotcon_header_options options)
+API void iotcon_resource_set_options(iotcon_resource_s *resource,
+               iotcon_options_h header_options)
 {
-       iotcon_header_options header_options;
-       GHashTableIter iter;
-       gpointer key = NULL;
-       gpointer value = NULL;
+       RET_IF(NULL == resource);
 
-       RET_IF(NULL == resource_s);
-       RET_IF(NULL == options);
+       if (resource->header_options)
+               iotcon_options_free(resource->header_options);
 
-       header_options = iotcon_new_header_options();
-       g_hash_table_iter_init(&iter, options);
-       while (g_hash_table_iter_next(&iter, &key, &value)) {
-               iotcon_add_header_option(header_options, GPOINTER_TO_UINT(key), value);
-       }
-       resource_s->header_options = header_options;
+       resource->header_options = header_options;
 }
 
-API void iotcon_unset_header_options(iotcon_resource_s *resource_s)
+API iotcon_options_h iotcon_request_get_options(iotcon_request_s request)
 {
-       RET_IF(NULL == resource_s);
-       iotcon_delete_header_options(resource_s->header_options);
-       resource_s->header_options = NULL;
+       return request.header_options;
 }
index 4ebb314..2e70c87 100644 (file)
@@ -22,8 +22,8 @@
  * range of 2048 to 3000 inclusive of lower and upper bound.
  * HeaderOptions instance creation fails if above condition is not satisfied.
  */
-#define IOTCON_HEADER_OPTIONID_MIN 2048
-#define IOTCON_HEADER_OPTIONID_MAX 3000
+#define IOTCON_OPTIONID_MIN 2048
+#define IOTCON_OPTIONID_MAX 3000
 
 
 /**
@@ -63,6 +63,7 @@ typedef enum {
        IOTCON_RESP_ERR_CODE = 2,
        IOTCON_RESP_RESULT = 3,
        IOTCON_RESP_REPRESENTATION = 4,
+       IOTCON_RESP_HEADER_OPTIONS = 5
 } iotcon_response_property_e;
 
 typedef enum {
index 93f2763..7268a88 100644 (file)
@@ -35,8 +35,9 @@ typedef void* iotcon_observe_h;
 
 typedef GList* iotcon_observers;
 typedef unsigned char iotcon_observation_id;
-typedef GHashTable* iotcon_header_options;
-typedef GHashTable* iotcon_query_parameters;
+
+typedef struct ic_options_s* iotcon_options_h;
+typedef GHashTable* iotcon_query;
 
 typedef GList *iotcon_resource_types;
 typedef GList *iotcon_resource_interfaces;
@@ -45,15 +46,6 @@ typedef GList *iotcon_resource_interfaces;
 typedef struct ic_res_response_s* iotcon_response_h;
 
 /**
- * @brief These are used in setting header options.
- */
-typedef struct {
-       unsigned short option_id;
-       char *option_data;
-} iotcon_header_option;
-
-
-/**
  * @brief observation information structure
  */
 typedef struct {
@@ -69,7 +61,7 @@ typedef struct {
        char *resource_host;
        bool is_observable;
        bool is_collection;
-       iotcon_header_options header_options;
+       iotcon_options_h header_options;
        iotcon_resource_types resource_types;
        iotcon_resource_interfaces resource_interfaces;
        iotcon_observe_h observe_handle;
@@ -79,8 +71,8 @@ typedef struct {
 typedef struct {
        char *request_type;
        char *res_uri;
-       iotcon_header_options header_opts;
-       iotcon_query_parameters query_params;
+       iotcon_options_h header_options;
+       iotcon_query query;
        int request_handler_flag;
        iotcon_request_h request_handle;
        iotcon_resource_h resource_handle;
index 6a5c1a4..3399aad 100644 (file)
@@ -27,9 +27,9 @@ extern "C" {
 void iotcon_initialize(const char *addr, unsigned short port);
 void iotcon_deinitialize();
 
-iotcon_response_h iotcon_create_response(iotcon_request_h req_h,
+iotcon_response_h iotcon_response_new(iotcon_request_h req_h,
                iotcon_resource_h res_h);
-void iotcon_delete_response(iotcon_response_h resp);
+void iotcon_response_free(iotcon_response_h resp);
 
 typedef void (*iotcon_rest_api_handle_cb)(const iotcon_request_s *request);
 
@@ -74,16 +74,16 @@ typedef void (*iotcon_found_resource_cb)(iotcon_resource_s *resource, void *user
 int iotcon_find_resource(const char *host, const char *resource_name,
                iotcon_found_resource_cb found_resource_cb, void *user_data);
 
-typedef void (*iotcon_on_get_cb)(const iotcon_header_options header_options,
+typedef void (*iotcon_on_get_cb)(const iotcon_options_h header_options,
                const iotcon_repr_h repr, const int e_code, void *user_data);
-typedef void (*iotcon_on_put_cb)(const iotcon_header_options header_options,
+typedef void (*iotcon_on_put_cb)(const iotcon_options_h header_options,
                const iotcon_repr_h repr, const int e_code, void *user_data);
-typedef void (*iotcon_on_post_cb)(const iotcon_header_options header_options,
+typedef void (*iotcon_on_post_cb)(const iotcon_options_h header_options,
                const iotcon_repr_h repr, const int e_code, void *user_data);
-typedef void (*iotcon_on_observe_cb)(const  iotcon_header_options header_options,
-               const iotcon_repr_h repr,       const int e_code, const int sequence_number,
+typedef void (*iotcon_on_observe_cb)(const  iotcon_options_h header_options,
+               const iotcon_repr_h repr, const int e_code, const int sequence_number,
                void *user_data);
-typedef void (*iotcon_on_delete_cb)(const iotcon_header_options header_options,
+typedef void (*iotcon_on_delete_cb)(const iotcon_options_h header_options,
                const int e_code, void *user_data);
 
 iotcon_resource_s iotcon_construct_resource_object(const char *host,
@@ -94,64 +94,62 @@ iotcon_resource_s iotcon_construct_resource_object(const char *host,
 void iotcon_destruct_resource_object(iotcon_resource_s *resource);
 iotcon_resource_s iotcon_copy_resource(iotcon_resource_s resource);
 
-int iotcon_get(iotcon_resource_s resource, iotcon_query_parameters query_params,
+int iotcon_get(iotcon_resource_s resource, iotcon_query query,
                iotcon_on_get_cb on_get_cb, void *user_data);
-int iotcon_put(iotcon_resource_s resource,
-               iotcon_repr_h repr,
-               iotcon_query_parameters query_params,
-               iotcon_on_put_cb on_put_cb,
-               void *user_data);
-int iotcon_post(iotcon_resource_s resource,
-               iotcon_repr_h repr,
-               iotcon_query_parameters query_params,
-               iotcon_on_post_cb on_post_cb,
-               void *user_data);
-int iotcon_delete_resource(iotcon_resource_s resource,
-               iotcon_on_delete_cb on_delete_cb,
+int iotcon_put(iotcon_resource_s resource, iotcon_repr_h repr, iotcon_query query,
+               iotcon_on_put_cb on_put_cb, void *user_data);
+int iotcon_post(iotcon_resource_s resource, iotcon_repr_h repr, iotcon_query query,
+               iotcon_on_post_cb on_post_cb, void *user_data);
+int iotcon_delete_resource(iotcon_resource_s resource, iotcon_on_delete_cb on_delete_cb,
                void *user_data);
 
 int iotcon_observe(iotcon_observe_type_e observe_type,
                iotcon_resource_s *resource,
-               iotcon_query_parameters query_params,
+               iotcon_query query,
                iotcon_on_observe_cb on_observe_cb,
                void *user_data);
 int iotcon_cancel_observe(iotcon_resource_s resource);
 
-iotcon_resource_types iotcon_new_resource_types();
-iotcon_resource_types iotcon_add_resource_types(iotcon_resource_types resource_types,
+iotcon_resource_types iotcon_resource_types_new();
+iotcon_resource_types iotcon_resource_types_insert(iotcon_resource_types resource_types,
                const char *resource_type);
-void iotcon_delete_resource_types(iotcon_resource_types resource_types);
+void iotcon_resource_types_free(iotcon_resource_types resource_types);
 
-iotcon_resource_interfaces iotcon_new_resource_interfaces();
-iotcon_resource_interfaces iotcon_add_resource_interfaces(
+iotcon_resource_interfaces iotcon_resource_interfaces_new();
+iotcon_resource_interfaces iotcon_resource_interfaces_insert(
                iotcon_resource_interfaces resource_interfaces, iotcon_interface_e interface);
-void iotcon_delete_resource_interfaces(iotcon_resource_interfaces resource_interfaces);
-
-iotcon_header_options iotcon_new_header_options();
-iotcon_error_e iotcon_add_header_option(iotcon_header_options options,
-               const unsigned short id, const char *data);
-void iotcon_delete_header_options(iotcon_header_options options);
+void iotcon_resource_interfaces_free(iotcon_resource_interfaces resource_interfaces);
+
+iotcon_options_h iotcon_options_new();
+void iotcon_options_free(iotcon_options_h options);
+int iotcon_options_insert(iotcon_options_h options, const unsigned short id,
+               const char *data);
+int iotcon_options_delete(iotcon_options_h options, const unsigned short id);
+const char* iotcon_options_lookup(iotcon_options_h options, const unsigned short id);
+typedef void (*iotcon_options_foreach_cb)(unsigned short id, char *data, void *user_data);
+void iotcon_options_foreach(iotcon_options_h options, iotcon_options_foreach_cb foreach_cb,
+               void *user_data);
+iotcon_options_h iotcon_options_clone(iotcon_options_h options);
 
-iotcon_query_parameters iotcon_new_query_params();
-void iotcon_add_query_param(iotcon_query_parameters query_params, const char *key,
-               const char *value);
-void iotcon_delete_query_params(iotcon_query_parameters query_params);
-char* iotcon_find_query_param(iotcon_query_parameters query_params, const char *key);
+iotcon_query iotcon_query_new();
+void iotcon_query_insert(iotcon_query query, const char *key, const char *value);
+void iotcon_query_free(iotcon_query query);
+char* iotcon_query_lookup(iotcon_query query, const char *key);
 
-iotcon_observers iotcon_new_observation();
-iotcon_observers iotcon_add_observation(iotcon_observers observers,
+iotcon_observers iotcon_observation_new();
+iotcon_observers iotcon_observation_insert(iotcon_observers observers,
                iotcon_observation_info_s obs);
-iotcon_observers iotcon_delete_observation(iotcon_observers observers,
+iotcon_observers iotcon_observation_delete(iotcon_observers observers,
                iotcon_observation_info_s obs);
-void iotcon_free_observation(iotcon_observers observers);
-
-char* iotcon_get_resource_uri(iotcon_resource_s resource_s);
-char* iotcon_get_resource_host(iotcon_resource_s resource_s);
-iotcon_resource_types iotcon_get_resource_types(iotcon_resource_s resource_s);
-iotcon_resource_interfaces iotcon_get_resource_interfaces(iotcon_resource_s resource_s);
-void iotcon_set_header_options(iotcon_resource_s *resource_s,
-               iotcon_header_options options);
-void iotcon_unset_header_options(iotcon_resource_s *resource_s);
+void iotcon_observation_free(iotcon_observers observers);
+
+char* iotcon_resource_get_uri(iotcon_resource_s resource_s);
+char* iotcon_resource_get_host(iotcon_resource_s resource_s);
+iotcon_resource_types iotcon_resource_get_types(iotcon_resource_s resource_s);
+iotcon_resource_interfaces iotcon_resource_get_interfaces(iotcon_resource_s resource_s);
+
+void iotcon_resource_set_options(iotcon_resource_s *resource,
+               iotcon_options_h header_options);
 
 iotcon_repr_h iotcon_repr_new();
 const char* iotcon_repr_get_uri(iotcon_repr_h repr);
index 45f1936..c11c537 100644 (file)
@@ -65,7 +65,7 @@ void _print_repr_info(iotcon_repr_h repr)
 
 }
 
-static void _on_put(const iotcon_header_options header_options, iotcon_repr_h repr,
+static void _on_put(const iotcon_options_h header_options, iotcon_repr_h repr,
                const int e_code, void *user_data)
 {
        FN_CALL;
@@ -92,7 +92,7 @@ static void _on_put(const iotcon_header_options header_options, iotcon_repr_h re
        /* set the flag for receiving response succesfully */
 }
 
-void _on_get(const iotcon_header_options header_options, iotcon_repr_h repr,
+void _on_get(const iotcon_options_h header_options, iotcon_repr_h repr,
                const int e_code, void *user_data)
 {
        FN_CALL;
@@ -116,8 +116,8 @@ void _on_get(const iotcon_header_options header_options, iotcon_repr_h repr,
                iotcon_repr_h repr = iotcon_repr_new();
                iotcon_repr_set_bool(repr, "opened", true);
 
-               iotcon_query_parameters query_params = iotcon_new_query_params();
-               iotcon_put(door_resource, repr, query_params, _on_put, NULL);
+               iotcon_query query = iotcon_query_new();
+               iotcon_put(door_resource, repr, query, _on_put, NULL);
 
        }
        else {
@@ -140,17 +140,17 @@ static void _found_resource(iotcon_resource_s *resource, void *user_data)
                INFO("===== resource found =====");
 
                /* Get the resource URI */
-               resource_uri = iotcon_get_resource_uri(*resource);
+               resource_uri = iotcon_resource_get_uri(*resource);
                if (NULL == resource_uri) {
                        ERR("uri is NULL");
                        return;
                }
                /* Get the resource host address */
-               resource_host = iotcon_get_resource_host(*resource);
+               resource_host = iotcon_resource_get_host(*resource);
                DBG("[%s] resource host : %s", resource_uri, resource_host);
 
                /* Get the resource interfaces */
-               resource_interfaces = iotcon_get_resource_interfaces(*resource);
+               resource_interfaces = iotcon_resource_get_interfaces(*resource);
                if (resource_interfaces) {
                        interfaces_str = _alloc_str_from_glist(resource_interfaces);
                        DBG("[%s] resource interfaces : %s", resource_uri, interfaces_str);
@@ -158,7 +158,7 @@ static void _found_resource(iotcon_resource_s *resource, void *user_data)
                }
 
                /* Get the resource types */
-               resource_types = iotcon_get_resource_types(*resource);
+               resource_types = iotcon_resource_get_types(*resource);
                if (resource_types) {
                        res_types_str = _alloc_str_from_glist(resource_types);
                        DBG("[%s] resource types : %s", resource_uri, res_types_str);
@@ -168,12 +168,12 @@ static void _found_resource(iotcon_resource_s *resource, void *user_data)
                if (!strcmp(door_uri, resource_uri)) {
                        door_resource = iotcon_copy_resource(*resource);
 
-                       iotcon_query_parameters query_params = iotcon_new_query_params();
+                       iotcon_query query = iotcon_query_new();
 
                        /* send GET Request */
-                       iotcon_get(*resource, query_params, _on_get, NULL);
+                       iotcon_get(*resource, query, _on_get, NULL);
 
-                       iotcon_delete_query_params(query_params);
+                       iotcon_query_free(query);
                }
        }
 }
index e4d78b5..124d0b0 100644 (file)
@@ -46,7 +46,7 @@ static void _entity_handler_door(const iotcon_request_s *request_s)
 
        int requestFlag = request_s->request_handler_flag;
        if (requestFlag & IOTCON_REQUEST_FLAG) {
-               iotcon_response_h pResponse = iotcon_create_response(request_s->request_handle,
+               iotcon_response_h pResponse = iotcon_response_new(request_s->request_handle,
                                request_s->resource_handle);
                if (NULL == pResponse) {
                        ERR("pResponse is NULL");