modify discovery APIs for using query 64/85364/4
authoryoungman <yman.jung@samsung.com>
Wed, 24 Aug 2016 23:16:23 +0000 (08:16 +0900)
committeryoungman <yman.jung@samsung.com>
Tue, 30 Aug 2016 06:39:37 +0000 (15:39 +0900)
Change-Id: I2aefe9667c975695dca1314e41dd57ffda15a0d7
Signed-off-by: youngman <yman.jung@samsung.com>
16 files changed:
include/iotcon-client.h
include/iotcon-query.h
src/ic-common.h
src/ic-device.c
src/ic-ioty-convert.c
src/ic-ioty-parse.c
src/ic-ioty.c
src/ic-ioty.h
src/ic-provisioning-find.c
src/ic-provisioning-remove.c
src/ic-remote-resource.c
test/iotcon-test-basic-client.c
test/iotcon-test-basic-server.c
test/iotcon-test-device-client.c
test/iotcon-test-encap-client.c
test/iotcon-test-iface-client.c

index 5774c0b..0388758 100644 (file)
@@ -348,7 +348,7 @@ typedef bool (*iotcon_found_resource_cb)(iotcon_remote_resource_h resource,
 
 /**
  * @brief Finds resources, asynchronously.
- * @details Request to find a resource of @a host_address server with @a resource_type.\n
+ * @details Request to find a resource of @a host_address server with @a query.\n
  * @a host_address could be #IOTCON_MULTICAST_ADDRESS for multicast.\n
  * If succeed to find the resource, iotcon_found_resource_cb() will be invoked with
  * information of the resource.
@@ -357,14 +357,12 @@ typedef bool (*iotcon_found_resource_cb)(iotcon_remote_resource_h resource,
  * @privlevel public
  * @privilege %http://tizen.org/privilege/internet
  *
- * @remarks The length of @a resource_type should be less than or equal to 61.\n
- * The @a resource_type must start with a lowercase alphabetic character, followed by a sequence
- * of lowercase alphabetic, numeric, ".", or "-" characters, and contains no white space.
+ * @remarks @a host_address should be in the format coap://address:port.\n
+ * (ex. coaps://[fe80::ae5a:14ff:fe24:b8fe]:12345, or coaps://192.168.1.10:12345)
  *
  * @param[in] host_address The address or addressable name of server
  * @param[in] connectivity_type The connectivity type
- * @param[in] resource_type The resource type specified as a filter for the resource
- * @param[in] is_secure The flag for secure communication with the server
+ * @param[in] query The query specified as a filter for the resource
  * @param[in] cb The callback function to invoke
  * @param[in] user_data The user data to pass to the function
  *
@@ -383,8 +381,7 @@ typedef bool (*iotcon_found_resource_cb)(iotcon_remote_resource_h resource,
  */
 int iotcon_find_resource(const char *host_address,
                iotcon_connectivity_type_e connectivity_type,
-               const char *resource_type,
-               bool is_secure,
+               iotcon_query_h query,
                iotcon_found_resource_cb cb,
                void *user_data);
 
@@ -421,8 +418,12 @@ typedef bool (*iotcon_device_info_cb)(iotcon_device_info_h device_info,
  * @privlevel public
  * @privilege %http://tizen.org/privilege/internet
  *
+ * @remarks @a host_address should be in the format coap://address:port.\n
+ * (ex. coap://[fe80::ae5a:14ff:fe24:b8fe]:12345, or coap://192.168.1.10:12345)
+ *
  * @param[in] host_address The host address of remote server
  * @param[in] connectivity_type The connectivity type
+ * @param[in] query The query specified as a filter for the device information
  * @param[in] cb The callback function to invoke
  * @param[in] user_data The user data to pass to the function
  *
@@ -443,6 +444,7 @@ typedef bool (*iotcon_device_info_cb)(iotcon_device_info_h device_info,
  */
 int iotcon_find_device_info(const char *host_address,
                iotcon_connectivity_type_e connectivity_type,
+               iotcon_query_h query,
                iotcon_device_info_cb cb,
                void *user_data);
 
@@ -502,8 +504,12 @@ typedef bool (*iotcon_platform_info_cb)(iotcon_platform_info_h platform_info,
  * @privlevel public
  * @privilege %http://tizen.org/privilege/internet
  *
+ * @remarks @a host_address should be in the format coap://address:port.\n
+ * (ex. coap://[fe80::ae5a:14ff:fe24:b8fe]:12345, or coap://192.168.1.10:12345)
+ *
  * @param[in] host_address The host address of remote server
  * @param[in] connectivity_type The connectivity type
+ * @param[in] query The query specified as a filter for the platform information
  * @param[in] cb The callback function to invoke
  * @param[in] user_data The user data to pass to the function
  *
@@ -525,6 +531,7 @@ typedef bool (*iotcon_platform_info_cb)(iotcon_platform_info_h platform_info,
  */
 int iotcon_find_platform_info(const char *host_address,
                iotcon_connectivity_type_e connectivity_type,
+               iotcon_query_h query,
                iotcon_platform_info_cb cb,
                void *user_data);
 
index ca43e28..5dd1064 100644 (file)
@@ -151,7 +151,9 @@ void iotcon_query_destroy(iotcon_query_h query);
  *
  * @since_tizen 3.0
  *
- * @remarks @a type must not be released using free().
+ * @remarks @a resource_type must not be released using free().
+ * @a resource_type must start with a lowercase alphabetic character, followed by a sequence
+ * of lowercase alphabetic, numeric, ".", or "-" characters, and contains no white space.
  *
  * @param[in] query The handle of the query
  * @param[out] resource_type Found resource type from query
index 8f05aaa..0c09ed1 100644 (file)
@@ -28,8 +28,9 @@
 
 #define IC_OBSERVE_ID_MAX_LEN 256
 
-#define IC_IOTY_COAP "coap://"
-#define IC_IOTY_COAPS "coaps://"
-#define IC_IOTY_MULTICAST_ADDRESS "224.0.1.187:5683"
+#define IC_COAP "coap://"
+#define IC_COAPS "coaps://"
+#define IC_COAP_PREFIX "coap"
+#define IC_MULTICAST_ADDRESS "224.0.1.187:5683"
 
 #endif /* __IOTCON_INTERNAL_COMMON_H__ */
index ac653df..b666494 100644 (file)
@@ -54,6 +54,7 @@ API int iotcon_device_info_get_property(iotcon_device_info_h device_info,
 
 API int iotcon_find_device_info(const char *host_address,
                iotcon_connectivity_type_e connectivity_type,
+               iotcon_query_h query,
                iotcon_device_info_cb cb,
                void *user_data)
 {
@@ -68,7 +69,8 @@ API int iotcon_find_device_info(const char *host_address,
        case IOTCON_CONNECTIVITY_IPV4:
        case IOTCON_CONNECTIVITY_IPV6:
        case IOTCON_CONNECTIVITY_ALL:
-               ret = icl_ioty_find_device_info(host_address, connectivity_type, cb, user_data);
+               ret = icl_ioty_find_device_info(host_address, connectivity_type, query, cb,
+                               user_data);
                if (IOTCON_ERROR_NONE != ret) {
                        ERR("icl_ioty_find_device_info() Fail(%d)", ret);
                        return ret;
@@ -149,6 +151,7 @@ API int iotcon_platform_info_get_property(iotcon_platform_info_h platform_info,
 
 API int iotcon_find_platform_info(const char *host_address,
                iotcon_connectivity_type_e connectivity_type,
+               iotcon_query_h query,
                iotcon_platform_info_cb cb,
                void *user_data)
 {
@@ -163,7 +166,8 @@ API int iotcon_find_platform_info(const char *host_address,
        case IOTCON_CONNECTIVITY_IPV4:
        case IOTCON_CONNECTIVITY_IPV6:
        case IOTCON_CONNECTIVITY_ALL:
-               ret = icl_ioty_find_platform_info(host_address, connectivity_type, cb, user_data);
+               ret = icl_ioty_find_platform_info(host_address, connectivity_type, query, cb,
+                               user_data);
                if (IOTCON_ERROR_NONE != ret) {
                        ERR("icl_ioty_find_platform_info() Fail(%d)", ret);
                        return ret;
index f725d82..8fbe393 100644 (file)
@@ -23,6 +23,8 @@
 
 #include "iotcon.h"
 #include "ic.h"
+#include "ic-utils.h"
+#include "ic-common.h"
 #include "ic-list.h"
 #include "ic-value.h"
 #include "ic-options.h"
@@ -86,12 +88,18 @@ static void _ic_ioty_conn_type_to_oic_transport_type(int conn_type,
 int ic_ioty_convert_connectivity(const char *host_address, int conn_type,
                OCDevAddr *dev_addr)
 {
+       int index = 0;
        char host[PATH_MAX] = {0};
        char *dev_host, *ptr = NULL;
 
        RETV_IF(NULL == dev_addr, IOTCON_ERROR_INVALID_PARAMETER);
 
-       snprintf(host, sizeof(host), "%s", host_address);
+       if (IC_EQUAL == strncmp(IC_COAPS, host_address, strlen(IC_COAPS)))
+               index = strlen(IC_COAPS);
+       else if (IC_EQUAL == strncmp(IC_COAP, host_address, strlen(IC_COAP)))
+               index = strlen(IC_COAP);
+
+       snprintf(host, sizeof(host), "%s", &host_address[index]);
 
        switch (conn_type) {
        case IOTCON_CONNECTIVITY_IPV4:
index 180a367..a0e10de 100644 (file)
@@ -92,20 +92,25 @@ int ic_ioty_parse_oic_dev_address(OCDevAddr *dev_addr, char **host_address,
 {
        int connectivity_type;
        char host_addr[PATH_MAX] = {0};
+       const char *coap_str;
 
        RETV_IF(NULL == host_address, IOTCON_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == conn_type, IOTCON_ERROR_INVALID_PARAMETER);
 
-       connectivity_type = _ioty_parse_oic_transport(dev_addr->adapter,
-                       dev_addr->flags);
+       connectivity_type = _ioty_parse_oic_transport(dev_addr->adapter, dev_addr->flags);
+
+       if (OC_FLAG_SECURE & dev_addr->flags)
+               coap_str = IC_COAPS;
+       else
+               coap_str = IC_COAP;
 
        switch (connectivity_type) {
        case IOTCON_CONNECTIVITY_IPV6:
-               snprintf(host_addr, sizeof(host_addr), "[%s]:%d", dev_addr->addr,
+               snprintf(host_addr, sizeof(host_addr), "%s[%s]:%d", coap_str, dev_addr->addr,
                                dev_addr->port);
                break;
        case IOTCON_CONNECTIVITY_IPV4:
-               snprintf(host_addr, sizeof(host_addr), "%s:%d", dev_addr->addr,
+               snprintf(host_addr, sizeof(host_addr), "%s%s:%d", coap_str, dev_addr->addr,
                                dev_addr->port);
                break;
        default:
@@ -120,7 +125,7 @@ int ic_ioty_parse_oic_dev_address(OCDevAddr *dev_addr, char **host_address,
        return IOTCON_ERROR_NONE;
 }
 
-iotcon_response_result_e  ic_ioty_parse_oic_response_result(OCStackResult result)
+iotcon_response_result_e ic_ioty_parse_oic_response_result(OCStackResult result)
 {
        switch (result) {
        case OC_STACK_OK:
index 9c771de..43464c7 100644 (file)
@@ -276,16 +276,58 @@ static void _icl_ioty_free_cb_data(void *data)
        g_idle_add(_icl_ioty_free_cb_data_idle_cb, cb_info);
 }
 
+static char* _icl_ioty_resource_generate_uri(const char *uri_path, iotcon_query_h query)
+{
+       int len;
+       bool loop_first = true;
+       char uri_buf[PATH_MAX] = {0};
+       GHashTableIter iter;
+       gpointer key, value;
+
+       RETV_IF(NULL == uri_path, NULL);
+
+       if (NULL == query || NULL == query->hash)
+               return strdup(uri_path);
+
+       len = snprintf(uri_buf, sizeof(uri_buf), "%s", uri_path);
+
+       /* remove suffix '/' */
+       if ('/' == uri_buf[strlen(uri_buf) - 1]) {
+               uri_buf[strlen(uri_buf) - 1] = '\0';
+               len--;
+       }
+
+       if (query->hash) {
+               g_hash_table_iter_init(&iter, query->hash);
+               while (g_hash_table_iter_next(&iter, &key, &value)) {
+                       int query_len;
+                       DBG("query exist. key(%s), value(%s)", key, value);
+
+                       if (true == loop_first) {
+                               query_len = snprintf(uri_buf + len, sizeof(uri_buf) - len, "?%s=%s",
+                                               (char *)key, (char *)value);
+                               loop_first = false;
+                       } else {
+                               query_len = snprintf(uri_buf + len, sizeof(uri_buf) - len, ";%s=%s",
+                                               (char *)key, (char *)value);
+                       }
+                       len += query_len;
+               }
+       }
+
+       return strdup(uri_buf);
+}
+
 int icl_ioty_find_resource(const char *host_address,
                iotcon_connectivity_type_e connectivity_type,
-               const char *resource_type,
-               bool is_secure,
+               iotcon_query_h query,
                iotcon_found_resource_cb cb,
                void *user_data)
 {
        FN_CALL;
-       int ret, len, timeout;
+       int ret, timeout;
        char *coap_str;
+       char *full_uri;
        char uri[PATH_MAX] = {0};
        icl_cb_s *cb_data;
        OCDoHandle handle;
@@ -294,25 +336,28 @@ int icl_ioty_find_resource(const char *host_address,
 
        RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
 
-       coap_str = is_secure ? IC_IOTY_COAPS : IC_IOTY_COAP;
+       if (IC_EQUAL != strncmp(IC_COAP_PREFIX, host_address, strlen(IC_COAP_PREFIX)))
+               coap_str = IC_COAPS;
 
        if (NULL == host_address) {
-               len = snprintf(uri, sizeof(uri), "%s", OC_RSRVD_WELL_KNOWN_URI);
+               snprintf(uri, sizeof(uri), "%s", OC_RSRVD_WELL_KNOWN_URI);
+       } else if (NULL == coap_str) {
+               snprintf(uri, sizeof(uri), "%s%s", host_address, OC_RSRVD_WELL_KNOWN_URI);
        } else {
-               len = snprintf(uri, sizeof(uri), "%s%s%s", coap_str, host_address,
+               snprintf(uri, sizeof(uri), "%s%s%s", coap_str, host_address,
                                OC_RSRVD_WELL_KNOWN_URI);
        }
-       if (len <= 0 || sizeof(uri) <= len) {
-               ERR("snprintf() Fail(%d)", len);
-               return IOTCON_ERROR_IO_ERROR;
-       }
 
-       if (resource_type)
-               snprintf(uri + len, sizeof(uri) - len, "?rt=%s", resource_type);
+       full_uri = _icl_ioty_resource_generate_uri(uri, query);
+       if (NULL == full_uri) {
+               ERR("_icl_ioty_resource_generate_uri() Fail");
+               return IOTCON_ERROR_INVALID_PARAMETER;
+       }
 
        cb_data = calloc(1, sizeof(icl_cb_s));
        if (NULL == cb_data) {
                ERR("calloc() Fail(%d)", errno);
+               free(full_uri);
                return IOTCON_ERROR_OUT_OF_MEMORY;
        }
        cb_data->op = ICL_FIND_RESOURCE;
@@ -329,21 +374,24 @@ int icl_ioty_find_resource(const char *host_address,
        if (IOTCON_ERROR_NONE != ret) {
                ERR("icl_ioty_mutex_lock() Fail(%d)", ret);
                _icl_ioty_free_cb_data(cb_data);
+               free(full_uri);
                return ret;
        }
 
        // TODO: QoS is come from lib.
-       ret = OCDoResource(&handle, OC_REST_DISCOVER, uri, NULL, NULL, oic_conn_type,
+       ret = OCDoResource(&handle, OC_REST_DISCOVER, full_uri, NULL, NULL, oic_conn_type,
                        OC_LOW_QOS, &cbdata, NULL, 0);
        icl_ioty_mutex_unlock();
-       cb_data->handle = handle;
 
        if (OC_STACK_OK != ret) {
                ERR("OCDoResource(DISCOVER) Fail(%d)", ret);
                _icl_ioty_free_cb_data(cb_data);
+               free(full_uri);
                return ic_ioty_parse_oic_error(ret);
        }
+       free(full_uri);
 
+       cb_data->handle = handle;
        iotcon_get_timeout(&timeout);
        cb_data->timeout = g_timeout_add_seconds(timeout, _icl_ioty_timeout, cb_data);
 
@@ -352,10 +400,13 @@ int icl_ioty_find_resource(const char *host_address,
 
 int icl_ioty_find_device_info(const char *host_address,
                iotcon_connectivity_type_e connectivity_type,
+               iotcon_query_h query,
                iotcon_device_info_cb cb,
                void *user_data)
 {
        int ret, timeout;
+       char *coap_str;
+       char *full_uri;
        char uri[PATH_MAX] = {0};
        icl_cb_s *cb_data = NULL;
        OCDoHandle handle;
@@ -364,14 +415,26 @@ int icl_ioty_find_device_info(const char *host_address,
 
        RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
 
+       if (IC_EQUAL != strncmp(IC_COAP_PREFIX, host_address, strlen(IC_COAP_PREFIX)))
+               coap_str = IC_COAP;
+
        if (NULL == host_address)
                snprintf(uri, sizeof(uri), "%s", OC_RSRVD_DEVICE_URI);
-       else
+       else if (NULL == coap_str)
                snprintf(uri, sizeof(uri), "%s%s", host_address, OC_RSRVD_DEVICE_URI);
+       else
+               snprintf(uri, sizeof(uri), "%s%s%s", coap_str, host_address, OC_RSRVD_DEVICE_URI);
+
+       full_uri = _icl_ioty_resource_generate_uri(uri, query);
+       if (NULL == full_uri) {
+               ERR("_icl_ioty_resource_generate_uri() Fail");
+               return IOTCON_ERROR_INVALID_PARAMETER;
+       }
 
        cb_data = calloc(1, sizeof(icl_cb_s));
        if (NULL == cb_data) {
                ERR("calloc() Fail(%d)", errno);
+               free(full_uri);
                return IOTCON_ERROR_OUT_OF_MEMORY;
        }
        cb_data->cb = cb;
@@ -388,20 +451,22 @@ int icl_ioty_find_device_info(const char *host_address,
        if (IOTCON_ERROR_NONE != ret) {
                ERR("icl_ioty_mutex_lock() Fail(%d)", ret);
                _icl_ioty_free_cb_data(cb_data);
+               free(full_uri);
                return ret;
        }
        // TODO: QoS is come from lib. And user can set QoS to client structure.
-       ret = OCDoResource(&handle, OC_REST_DISCOVER, uri, NULL, NULL, oic_conn_type,
+       ret = OCDoResource(&handle, OC_REST_DISCOVER, full_uri, NULL, NULL, oic_conn_type,
                        OC_LOW_QOS, &cbdata, NULL, 0);
        icl_ioty_mutex_unlock();
-       cb_data->handle = handle;
 
        if (OC_STACK_OK != ret) {
                ERR("OCDoResource(DISCOVER) Fail(%d)", ret);
                _icl_ioty_free_cb_data(cb_data);
+               free(full_uri);
                return ic_ioty_parse_oic_error(ret);
        }
 
+       cb_data->handle = handle;
        iotcon_get_timeout(&timeout);
        cb_data->timeout = g_timeout_add_seconds(timeout, _icl_ioty_timeout, cb_data);
 
@@ -410,10 +475,13 @@ int icl_ioty_find_device_info(const char *host_address,
 
 int icl_ioty_find_platform_info(const char *host_address,
                iotcon_connectivity_type_e connectivity_type,
+               iotcon_query_h query,
                iotcon_platform_info_cb cb,
                void *user_data)
 {
        int ret, timeout;
+       char *coap_str;
+       char *full_uri;
        char uri[PATH_MAX] = {0};
        icl_cb_s *cb_data = NULL;
        OCDoHandle handle;
@@ -422,14 +490,26 @@ int icl_ioty_find_platform_info(const char *host_address,
 
        RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
 
+       if (IC_EQUAL != strncmp(IC_COAP_PREFIX, host_address, strlen(IC_COAP_PREFIX)))
+               coap_str = IC_COAP;
+
        if (NULL == host_address)
                snprintf(uri, sizeof(uri), "%s", OC_RSRVD_PLATFORM_URI);
-       else
+       else if (NULL == coap_str)
                snprintf(uri, sizeof(uri), "%s%s", host_address, OC_RSRVD_PLATFORM_URI);
+       else
+               snprintf(uri, sizeof(uri), "%s%s%s", coap_str, host_address, OC_RSRVD_PLATFORM_URI);
+
+       full_uri = _icl_ioty_resource_generate_uri(uri, query);
+       if (NULL == full_uri) {
+               ERR("_icl_ioty_resource_generate_uri() Fail");
+               return IOTCON_ERROR_INVALID_PARAMETER;
+       }
 
        cb_data = calloc(1, sizeof(icl_cb_s));
        if (NULL == cb_data) {
                ERR("calloc() Fail(%d)", errno);
+               free(full_uri);
                return IOTCON_ERROR_OUT_OF_MEMORY;
        }
        cb_data->cb = cb;
@@ -446,20 +526,22 @@ int icl_ioty_find_platform_info(const char *host_address,
        if (IOTCON_ERROR_NONE != ret) {
                ERR("icl_ioty_mutex_lock() Fail(%d)", ret);
                _icl_ioty_free_cb_data(cb_data);
+               free(full_uri);
                return ret;
        }
        // TODO: QoS is come from lib. And user can set QoS to client structure.
-       ret = OCDoResource(&handle, OC_REST_DISCOVER, uri, NULL, NULL, oic_conn_type,
+       ret = OCDoResource(&handle, OC_REST_DISCOVER, full_uri, NULL, NULL, oic_conn_type,
                        OC_LOW_QOS, &cbdata, NULL, 0);
        icl_ioty_mutex_unlock();
-       cb_data->handle = handle;
 
        if (OC_STACK_OK != ret) {
                ERR("OCDoResource(DISCOVER) Fail(%d)", ret);
                _icl_ioty_free_cb_data(cb_data);
+               free(full_uri);
                return ic_ioty_parse_oic_error(ret);
        }
 
+       cb_data->handle = handle;
        iotcon_get_timeout(&timeout);
        cb_data->timeout = g_timeout_add_seconds(timeout, _icl_ioty_timeout, cb_data);
 
@@ -536,6 +618,7 @@ int icl_ioty_add_presence_cb(const char *host_address,
                iotcon_presence_h *presence_handle)
 {
        int ret;
+       int index = 0;
        OCDoHandle handle;
        const char *address;
        char uri[PATH_MAX] = {0};
@@ -547,11 +630,16 @@ int icl_ioty_add_presence_cb(const char *host_address,
        RETV_IF(NULL == presence_handle, IOTCON_ERROR_INVALID_PARAMETER);
 
        if (NULL == host_address)
-               address = IC_IOTY_MULTICAST_ADDRESS;
+               address = IC_MULTICAST_ADDRESS;
        else
                address = host_address;
 
-       snprintf(uri, sizeof(uri), "%s%s", address, OC_RSRVD_PRESENCE_URI);
+       if (IC_EQUAL == strncmp(IC_COAPS, host_address, strlen(IC_COAPS)))
+               index = strlen(IC_COAPS);
+       else if (IC_EQUAL == strncmp(IC_COAP, host_address , strlen(IC_COAP)))
+               index = strlen(IC_COAP);
+
+       snprintf(uri, sizeof(uri), "%s%s", &address[index], OC_RSRVD_PRESENCE_URI);
 
        presence = calloc(1, sizeof(struct icl_presence));
        if (NULL == presence) {
@@ -618,45 +706,6 @@ int icl_ioty_remove_presence_cb(iotcon_presence_h presence)
        return IOTCON_ERROR_NONE;
 }
 
-static char* _icl_ioty_resource_generate_uri(char *uri_path, GHashTable *hash)
-{
-       int len;
-       bool loop_first = true;
-       char uri_buf[PATH_MAX] = {0};
-       GHashTableIter iter;
-       gpointer key, value;
-
-       RETV_IF(NULL == uri_path, NULL);
-
-       len = snprintf(uri_buf, sizeof(uri_buf), "%s", uri_path);
-
-       /* remove suffix '/' */
-       if ('/' == uri_buf[strlen(uri_buf) - 1]) {
-               uri_buf[strlen(uri_buf) - 1] = '\0';
-               len--;
-       }
-
-       if (hash) {
-               g_hash_table_iter_init(&iter, hash);
-               while (g_hash_table_iter_next(&iter, &key, &value)) {
-                       int query_len;
-                       DBG("query exist. key(%s), value(%s)", key, value);
-
-                       if (true == loop_first) {
-                               query_len = snprintf(uri_buf + len, sizeof(uri_buf) - len, "?%s=%s",
-                                               (char *)key, (char *)value);
-                               loop_first = false;
-                       } else {
-                               query_len = snprintf(uri_buf + len, sizeof(uri_buf) - len, ";%s=%s",
-                                               (char *)key, (char *)value);
-                       }
-                       len += query_len;
-               }
-       }
-
-       return strdup(uri_buf);
-}
-
 static void _icl_ioty_free_observe_container(void *data)
 {
        icl_observe_container_s *cb_container = data;
@@ -684,17 +733,15 @@ static int _icl_ioty_remote_resource_observe(iotcon_remote_resource_h resource,
        OCConnectivityType oic_conn_type;
        OCHeaderOption *oic_options_ptr = NULL;
        OCHeaderOption oic_options[MAX_HEADER_OPTIONS];
-       GHashTable *query_hash;
        icl_observe_container_s *cb_container;
 
        RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
 
        /* uri */
-       query_hash = (query && query->hash) ? query->hash : NULL;
-       uri = _icl_ioty_resource_generate_uri(resource->uri_path, query_hash);
+       uri = _icl_ioty_resource_generate_uri(resource->uri_path, query);
        if (NULL == uri) {
-               ERR("_icd_ioty_resource_generate_uri() Fail");
+               ERR("_icl_ioty_resource_generate_uri() Fail");
                return IOTCON_ERROR_INVALID_PARAMETER;
        }
 
@@ -903,7 +950,6 @@ static int _icl_ioty_remote_resource_crud(
        FN_CALL;
        int ret, timeout, options_size = 0;
        char *uri;
-       GHashTable *query_hash;
        icl_response_container_s *cb_container;
        OCCallbackData cbdata = {0};
        OCHeaderOption *oic_options_ptr = NULL;
@@ -919,10 +965,7 @@ static int _icl_ioty_remote_resource_crud(
        /* method (request type) */
        method = ic_ioty_convert_request_type(req_type);
 
-       /* uri */
-       query_hash = (query && query->hash) ? query->hash : NULL;
-
-       uri = _icl_ioty_resource_generate_uri(resource->uri_path, query_hash);
+       uri = _icl_ioty_resource_generate_uri(resource->uri_path, query);
        if (NULL == uri) {
                ERR("_icl_ioty_resource_generate_uri() Fail");
                return IOTCON_ERROR_INVALID_PARAMETER;
index 1c1d74d..590d0d4 100644 (file)
@@ -53,16 +53,17 @@ int icl_ioty_set_platform_info();
 /* client APIs */
 int icl_ioty_find_resource(const char *host_address,
                iotcon_connectivity_type_e connectivity_type,
-               const char *resource_type,
-               bool is_secure,
+               iotcon_query_h query,
                iotcon_found_resource_cb cb,
                void *user_data);
 int icl_ioty_find_device_info(const char *host_address,
                iotcon_connectivity_type_e connectivity_type,
+               iotcon_query_h query,
                iotcon_device_info_cb cb,
                void *user_data);
 int icl_ioty_find_platform_info(const char *host_address,
                iotcon_connectivity_type_e connectivity_type,
+               iotcon_query_h query,
                iotcon_platform_info_cb cb,
                void *user_data);
 
index 01d504d..0ec9d41 100644 (file)
@@ -415,7 +415,7 @@ static int _provisioning_find_security_version(
                return ret;
        }
 
-       snprintf(uri, sizeof(uri), "%s%s%s", IC_IOTY_COAP, host_address, version_uri);
+       snprintf(uri, sizeof(uri), "%s%s%s", IC_COAP, host_address, version_uri);
        DBG("uri : %s", uri);
 
        cbdata.cb = _provisioning_find_security_version_cb;
@@ -522,7 +522,7 @@ static int _provisioning_find_secure_port(icl_provisioning_find_cb_container_s *
                return ret;
        }
 
-       snprintf(uri, sizeof(uri), "%s%s%s", IC_IOTY_COAP, host_address,
+       snprintf(uri, sizeof(uri), "%s%s%s", IC_COAP, host_address,
                        OC_RSRVD_WELL_KNOWN_URI);
 
        cbdata.cb = _provisioning_find_secure_port_cb;
index 666e6f8..20d0a0e 100644 (file)
@@ -260,7 +260,7 @@ static int _provisioning_remove_device_delete(
                return ret;
        }
 
-       snprintf(uri, sizeof(uri), "%s%s%s?%s=%s", IC_IOTY_COAPS, host_address, cred_uri,
+       snprintf(uri, sizeof(uri), "%s%s%s?%s=%s", IC_COAPS, host_address, cred_uri,
                        subject_uuid, container->cb_data->device_id);
 
        free(host_address);
index f223550..cc0235e 100644 (file)
@@ -35,8 +35,7 @@
  * If resource_type is NULL, then All resources in host are discovered. */
 API int iotcon_find_resource(const char *host_address,
                iotcon_connectivity_type_e connectivity_type,
-               const char *resource_type,
-               bool is_secure,
+               iotcon_query_h query,
                iotcon_found_resource_cb cb,
                void *user_data)
 {
@@ -46,15 +45,13 @@ API int iotcon_find_resource(const char *host_address,
        RETV_IF(false == ic_utils_check_permission(IC_PERMISSION_INTERNET),
                        IOTCON_ERROR_PERMISSION_DENIED);
        RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
-       RETV_IF(resource_type && (false == icl_resource_check_type(resource_type)),
-                       IOTCON_ERROR_INVALID_PARAMETER);
 
        switch (connectivity_type) {
        case IOTCON_CONNECTIVITY_IPV4:
        case IOTCON_CONNECTIVITY_IPV6:
        case IOTCON_CONNECTIVITY_ALL:
-               ret = icl_ioty_find_resource(host_address, connectivity_type, resource_type,
-                               is_secure, cb, user_data);
+               ret = icl_ioty_find_resource(host_address, connectivity_type, query, cb,
+                               user_data);
                if (IOTCON_ERROR_NONE != ret) {
                        ERR("icl_ioty_find_resource() Fail(%d)", ret);
                        return ret;
@@ -78,6 +75,7 @@ API int iotcon_remote_resource_create(const char *host_address,
                iotcon_remote_resource_h *resource_handle)
 {
        FN_CALL;
+       char temp[PATH_MAX] = {0};
        iotcon_remote_resource_h resource = NULL;
 
        RETV_IF(false == ic_utils_check_ocf_feature(), IOTCON_ERROR_NOT_SUPPORTED);
@@ -91,13 +89,20 @@ API int iotcon_remote_resource_create(const char *host_address,
        RETVM_IF(IOTCON_CONNECTIVITY_ALL == connectivity_type, IOTCON_ERROR_INVALID_PARAMETER,
                "Should use specific connectivity type of the remote resource");
 
+       if (IC_EQUAL == strncmp(IC_COAP_PREFIX, host_address, strlen(IC_COAP_PREFIX)))
+               snprintf(temp, sizeof(temp), "%s", host_address);
+       else if (policies & IOTCON_RESOURCE_SECURE)
+               snprintf(temp, sizeof(temp), "%s%s", IC_COAPS, host_address);
+       else
+               snprintf(temp, sizeof(temp), "%s%s", IC_COAP, host_address);
+
        resource = calloc(1, sizeof(struct icl_remote_resource));
        if (NULL == resource) {
                ERR("calloc() Fail(%d)", errno);
                return IOTCON_ERROR_OUT_OF_MEMORY;
        }
 
-       resource->host_address = ic_utils_strdup(host_address);
+       resource->host_address = ic_utils_strdup(temp);
        resource->connectivity_type = connectivity_type;
        resource->uri_path = ic_utils_strdup(uri_path);
        resource->policies = policies;
index e5fd976..a788fda 100644 (file)
@@ -594,6 +594,7 @@ int main(int argc, char **argv)
        FN_CALL;
        int ret;
        GMainLoop *loop;
+       iotcon_query_h query;
 
        loop = g_main_loop_new(NULL, FALSE);
 
@@ -604,15 +605,31 @@ int main(int argc, char **argv)
                return -1;
        }
 
+       ret = iotcon_query_create(&query);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_query_create() Fail(%d)", ret);
+               return -1;
+       }
+
+       ret = iotcon_query_set_resource_type(query, DOOR_RESOURCE_TYPE);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_query_set_resource_type() Fail(%d)", ret);
+               iotcon_query_destroy(query);
+               return -1;
+       }
+
        /* find door typed resources */
        ret = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_ALL,
-                       DOOR_RESOURCE_TYPE, true, _found_resource, NULL);
+                       query, _found_resource, NULL);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("iotcon_find_resource() Fail(%d)", ret);
+               iotcon_query_destroy(query);
                iotcon_deinitialize();
                return -1;
        }
 
+       iotcon_query_destroy(query);
+
        g_main_loop_run(loop);
        g_main_loop_unref(loop);
 
index 9d02dd6..6e7d94e 100644 (file)
@@ -488,7 +488,6 @@ static void _request_handler(iotcon_resource_h resource, iotcon_request_h reques
                return;
        }
 
-
        door = user_data;
 
        if (IOTCON_REQUEST_GET == type)
index 55ec377..c1c92aa 100644 (file)
@@ -187,7 +187,7 @@ int main(int argc, char **argv)
        }
 
        ret = iotcon_find_device_info(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_ALL,
-                       _request_device_info, NULL);
+                       NULL, _request_device_info, NULL);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("iotcon_find_device_info() Fail(%d)", ret);
                iotcon_deinitialize();
@@ -195,7 +195,7 @@ int main(int argc, char **argv)
        }
 
        ret = iotcon_find_platform_info(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_ALL,
-                       _request_platform_info, NULL);
+                       NULL, _request_platform_info, NULL);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("iotcon_find_platform_info() Fail(%d)", ret);
                iotcon_deinitialize();
index 19408e1..642dab8 100644 (file)
@@ -234,6 +234,7 @@ int main(int argc, char **argv)
        FN_CALL;
        int ret;
        GMainLoop *loop;
+       iotcon_query_h query;
        iotcon_remote_resource_h resource;
 
        loop = g_main_loop_new(NULL, FALSE);
@@ -245,15 +246,31 @@ int main(int argc, char **argv)
                return -1;
        }
 
+       ret = iotcon_query_create(&query);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_query_create() Fail(%d)", ret);
+               return -1;
+       }
+
+       ret = iotcon_query_set_resource_type(query, DOOR_RESOURCE_TYPE);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_query_set_resource_type() Fail(%d)", ret);
+               iotcon_query_destroy(query);
+               return -1;
+       }
+
        /* find door typed resources */
        ret = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_ALL,
-                       DOOR_RESOURCE_TYPE, true, _found_resource, &resource);
+                       query, _found_resource, &resource);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("iotcon_find_resource() Fail(%d)", ret);
+               iotcon_query_destroy(query);
                iotcon_deinitialize();
                return -1;
        }
 
+       iotcon_query_destroy(query);
+
        g_main_loop_run(loop);
        g_main_loop_unref(loop);
 
index 9e6ac77..6887a09 100644 (file)
@@ -400,6 +400,7 @@ int main(int argc, char **argv)
        FN_CALL;
        int ret;
        GMainLoop *loop;
+       iotcon_query_h query;
 
        loop = g_main_loop_new(NULL, FALSE);
 
@@ -410,15 +411,31 @@ int main(int argc, char **argv)
                return -1;
        }
 
+       ret = iotcon_query_create(&query);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_query_create() Fail(%d)", ret);
+               return -1;
+       }
+
+       ret = iotcon_query_set_resource_type(query, ROOM_RESOURCE_TYPE);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_query_set_resource_type() Fail(%d)", ret);
+               iotcon_query_destroy(query);
+               return -1;
+       }
+
        /* find room typed resources */
        ret = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_ALL,
-                       ROOM_RESOURCE_TYPE, true, _found_resource, NULL);
+                       query, _found_resource, NULL);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("iotcon_find_resource() Fail(%d)", ret);
+               iotcon_query_destroy(query);
                iotcon_deinitialize();
                return -1;
        }
 
+       iotcon_query_destroy(query);
+
        g_main_loop_run(loop);
        g_main_loop_unref(loop);