add codes for TCP 67/88667/11
authoryoungman <yman.jung@samsung.com>
Mon, 19 Sep 2016 04:38:16 +0000 (13:38 +0900)
committeryoungman <yman.jung@samsung.com>
Wed, 2 Nov 2016 11:27:28 +0000 (20:27 +0900)
Change-Id: I0b7811c605a6e6805002566c60b485cb69a90f96
Signed-off-by: youngman <yman.jung@samsung.com>
26 files changed:
include/iotcon-client.h
include/iotcon-constant.h
src/ic-common.h
src/ic-device.c
src/ic-ioty-convert.c
src/ic-ioty-convert.h
src/ic-ioty-ocprocess.c
src/ic-ioty-parse.c
src/ic-ioty-parse.h
src/ic-ioty.c
src/ic-ioty.h
src/ic-log.h
src/ic-presence.c
src/ic-provisioning-struct.c
src/ic-remote-resource-caching.c
src/ic-remote-resource-crud.c
src/ic-remote-resource-monitoring.c
src/ic-remote-resource.c
src/ic-remote-resource.h
src/ic-types.c
src/ic-types.h
src/ic-utils.c
src/ic-utils.h
test/iotcon-test-basic-client.c
test/iotcon-test-encap-client.c
test/iotcon-test-iface-client.c

index 0388758..e03f499 100644 (file)
@@ -358,7 +358,18 @@ typedef bool (*iotcon_found_resource_cb)(iotcon_remote_resource_h resource,
  * @privilege %http://tizen.org/privilege/internet
  *
  * @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)
+ * (ex. coaps://[fe80::ae5a:14ff:fe24:b8fe]:12345, or coaps://192.168.1.10:12345)\n
+ * @a connectivity_type can be set with extra options.
+ * If @a connectivity_type is set without IOTCON_CONNECTIVITY_IPV4_ONLY
+ * and IOTCON_CONNECTIVITY_IPV6_ONLY, the resources are discovered by default setting
+ * of IoTivity(IPv6 is preferred over IPv4).\n
+ * If there are no preference options(PREFER_XXX), resources will reply using each of
+ * opened protocol(TCP/UDP).
+ * Therefore, you can get remote resource handles which include different host address,
+ * but indicates same resource.\n (coaps://192.168.0.2:1234/res/light,
+ * coaps+tcp://192.168.0.2/1235/res/light)
+ * @a query can be set using specific resource types, or resource interfaces.
+ * If @a query is NULL, every resource discovered is listed.
  *
  * @param[in] host_address The address or addressable name of server
  * @param[in] connectivity_type The connectivity type
@@ -380,7 +391,7 @@ typedef bool (*iotcon_found_resource_cb)(iotcon_remote_resource_h resource,
  * @see iotcon_set_timeout()
  */
 int iotcon_find_resource(const char *host_address,
-               iotcon_connectivity_type_e connectivity_type,
+               int connectivity_type,
                iotcon_query_h query,
                iotcon_found_resource_cb cb,
                void *user_data);
@@ -419,7 +430,12 @@ typedef bool (*iotcon_device_info_cb)(iotcon_device_info_h device_info,
  * @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)
+ * (ex. coap://[fe80::ae5a:14ff:fe24:b8fe]:12345, or coap://192.168.1.10:12345)\n
+ * @a connectivity_type can be set with extra options.
+ * If @a connectivity_type is set without IOTCON_CONNECTIVITY_IPV4_ONLY
+ * and IOTCON_CONNECTIVITY_IPV6_ONLY, device informations are discovered by default setting
+ * of IoTivity(IPv6 is preferred over IPv4).\n
+ * If there are no preference options(PREFER_XXX), it will reply using UDP.
  *
  * @param[in] host_address The host address of remote server
  * @param[in] connectivity_type The connectivity type
@@ -443,7 +459,7 @@ typedef bool (*iotcon_device_info_cb)(iotcon_device_info_h device_info,
  * @see iotcon_set_timeout()
  */
 int iotcon_find_device_info(const char *host_address,
-               iotcon_connectivity_type_e connectivity_type,
+               int connectivity_type,
                iotcon_query_h query,
                iotcon_device_info_cb cb,
                void *user_data);
@@ -505,7 +521,12 @@ typedef bool (*iotcon_platform_info_cb)(iotcon_platform_info_h platform_info,
  * @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)
+ * (ex. coap://[fe80::ae5a:14ff:fe24:b8fe]:12345, or coap://192.168.1.10:12345)\n
+ * @a connectivity_type can be set with extra options.
+ * If @a connectivity_type is set without IOTCON_CONNECTIVITY_IPV4_ONLY
+ * and IOTCON_CONNECTIVITY_IPV6_ONLY, platform informations are discovered by default setting
+ * of IoTivity(IPv6 is preferred over IPv4).\n
+ * If there are no preference options(PREFER_XXX), it will reply using UDP.
  *
  * @param[in] host_address The host address of remote server
  * @param[in] connectivity_type The connectivity type
@@ -530,7 +551,7 @@ typedef bool (*iotcon_platform_info_cb)(iotcon_platform_info_h platform_info,
  * @see iotcon_set_timeout()
  */
 int iotcon_find_platform_info(const char *host_address,
-               iotcon_connectivity_type_e connectivity_type,
+               int connectivity_type,
                iotcon_query_h query,
                iotcon_platform_info_cb cb,
                void *user_data);
index 5963635..6da1ae2 100644 (file)
@@ -110,12 +110,21 @@ typedef enum {
 /**
  * @brief Enumeration for of connectivities which can be held in a resource.
  *
+ * @remarks IOTCON_CONNECTIVITY_PREFER_UDP and IOTCON_CONNECTIVITY_PREFER_TCP should be
+ * mutually exclusive.
+ * @remarks IOTCON_CONNECTIVITY_IPV4_ONLY and IOTCON_CONNECTIVITY_IPV6_ONLY should be
+ * mutually exclusive.
+ *
  * @since_tizen 3.0
  */
 typedef enum {
        IOTCON_CONNECTIVITY_ALL = 0, /**< Indicates all connectivities */
-       IOTCON_CONNECTIVITY_IPV4, /**< Indicates Internet Protocol version 4 connectivity */
-       IOTCON_CONNECTIVITY_IPV6, /**< Indicates Internet Protocol version 6 connectivity */
+       IOTCON_CONNECTIVITY_IP = (1 << 0), /**< Indicates Internet Protocol connectivity */
+       /* Extra options for Connectivity */
+       IOTCON_CONNECTIVITY_PREFER_UDP = (1 << 16), /**< It is related to IOTCON_CONNECTIVITY_IP, and it indicates UDP is preferred */
+       IOTCON_CONNECTIVITY_PREFER_TCP = (1 << 17), /**< It is related to IOTCON_CONNECTIVITY_IP, and it indicates TCP is preferred */
+       IOTCON_CONNECTIVITY_IPV4_ONLY = (1 << 18), /**< When this bit is set with IOTCON_CONNECTIVITY_IP, resources are discovered for IPv4 */
+       IOTCON_CONNECTIVITY_IPV6_ONLY = (1 << 19), /**< When this bit is set with IOTCON_CONNECTIVITY_IP, resources are discovered for IPv6 */
 } iotcon_connectivity_type_e;
 
 /**
@@ -251,7 +260,6 @@ typedef enum {
        IOTCON_QOS_HIGH, /**< Indicates high quality of service  */
 } iotcon_qos_e;
 
-
 /**
  * @}
  */
index 20cc074..a620b97 100644 (file)
 
 #define IC_COAP "coap://"
 #define IC_COAPS "coaps://"
+#define IC_COAP_TCP "coap+tcp://"
+#define IC_COAPS_TCP "coaps+tcp://"
 #define IC_COAP_PREFIX "coap"
 #define IC_MULTICAST_ADDRESS "224.0.1.187:5683"
 
+/* IOTCON_CONNECTIVITY_PREFER_UDP is the first option for connectivity type */
+#define IC_CONNECTIVITY_REMOVE_EXTRA_OPTIONS IOTCON_CONNECTIVITY_PREFER_UDP
+
 #endif /* __IOTCON_INTERNAL_COMMON_H__ */
index b666494..ba68037 100644 (file)
@@ -53,7 +53,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,
+               int connectivity_type,
                iotcon_query_h query,
                iotcon_device_info_cb cb,
                void *user_data)
@@ -63,22 +63,15 @@ API int iotcon_find_device_info(const char *host_address,
        RETV_IF(false == ic_utils_check_ocf_feature(), IOTCON_ERROR_NOT_SUPPORTED);
        RETV_IF(false == ic_utils_check_permission(IC_PERMISSION_INTERNET),
                        IOTCON_ERROR_PERMISSION_DENIED);
+       RETV_IF(false == ic_utils_check_connectivity_type(connectivity_type),
+                       IOTCON_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
 
-       switch (connectivity_type) {
-       case IOTCON_CONNECTIVITY_IPV4:
-       case IOTCON_CONNECTIVITY_IPV6:
-       case IOTCON_CONNECTIVITY_ALL:
-               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;
-               }
-               break;
-       default:
-               ERR("Invalid Connectivity Type(%d)", connectivity_type);
-               return IOTCON_ERROR_INVALID_PARAMETER;
+       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;
        }
 
        return IOTCON_ERROR_NONE;
@@ -150,7 +143,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,
+               int connectivity_type,
                iotcon_query_h query,
                iotcon_platform_info_cb cb,
                void *user_data)
@@ -160,22 +153,15 @@ API int iotcon_find_platform_info(const char *host_address,
        RETV_IF(false == ic_utils_check_ocf_feature(), IOTCON_ERROR_NOT_SUPPORTED);
        RETV_IF(false == ic_utils_check_permission(IC_PERMISSION_INTERNET),
                        IOTCON_ERROR_PERMISSION_DENIED);
+       RETV_IF(false == ic_utils_check_connectivity_type(connectivity_type),
+                       IOTCON_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
 
-       switch (connectivity_type) {
-       case IOTCON_CONNECTIVITY_IPV4:
-       case IOTCON_CONNECTIVITY_IPV6:
-       case IOTCON_CONNECTIVITY_ALL:
-               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;
-               }
-               break;
-       default:
-               ERR("Invalid Connectivity Type(%d)", connectivity_type);
-               return IOTCON_ERROR_INVALID_PARAMETER;
+       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;
        }
 
        return IOTCON_ERROR_NONE;
index 8fbe393..002a8b6 100644 (file)
@@ -43,39 +43,57 @@ static int _icl_ioty_fill_oic_rep_payload_value(OCRepPayload *payload,
                iotcon_attributes_h attributes);
 
 
-OCConnectivityType ic_ioty_convert_connectivity_type(
-               iotcon_connectivity_type_e conn_type)
+OCConnectivityType ic_ioty_convert_connectivity_type(iotcon_connectivity_type_e conn_type,
+               int conn_options)
 {
-       int connectivity_type = conn_type;
+       OCConnectivityType type = 0;
 
-       switch (connectivity_type) {
-       case IOTCON_CONNECTIVITY_IPV4:
-               return CT_ADAPTER_IP | CT_IP_USE_V4;
-       case IOTCON_CONNECTIVITY_IPV6:
-               return CT_ADAPTER_IP | CT_IP_USE_V6;
+       switch (conn_type) {
+       case IOTCON_CONNECTIVITY_IP:
+               if (IC_UTILS_CONNECTIVITY_UDP & conn_options)
+                       type |= CT_ADAPTER_IP;
+               else if (IC_UTILS_CONNECTIVITY_TCP & conn_options)
+                       type |= CT_ADAPTER_TCP;
+               else
+                       type |= CT_DEFAULT;
+
+               if (IC_UTILS_CONNECTIVITY_IPV4 & conn_options)
+                       type |= CT_IP_USE_V4;
+               else if (IC_UTILS_CONNECTIVITY_IPV6 & conn_options)
+                       type |= CT_IP_USE_V6;
+               else
+                       type |= CT_DEFAULT;
+               break;
        case IOTCON_CONNECTIVITY_ALL:
-               return CT_DEFAULT;
        default:
-               ERR("Invalid conn_type(%d)", conn_type);
+               type |= CT_DEFAULT;
        }
-       return CT_DEFAULT;
+
+       return type;
 }
 
 
-static void _ic_ioty_conn_type_to_oic_transport_type(int conn_type,
-               OCTransportAdapter *adapter, OCTransportFlags *flag)
+static void _ic_ioty_conn_type_to_oic_transport_type(iotcon_connectivity_type_e conn_type,
+               int conn_options, OCTransportAdapter *adapter, OCTransportFlags *flag)
 {
        RET_IF(NULL == adapter);
        RET_IF(NULL == flag);
 
        switch (conn_type) {
-       case IOTCON_CONNECTIVITY_IPV4:
-               *adapter = OC_ADAPTER_IP;
-               *flag = OC_IP_USE_V4;
-               break;
-       case IOTCON_CONNECTIVITY_IPV6:
-               *adapter = OC_ADAPTER_IP;
-               *flag = OC_IP_USE_V6;
+       case IOTCON_CONNECTIVITY_IP:
+               if (IC_UTILS_CONNECTIVITY_UDP & conn_options)
+                       *adapter = OC_ADAPTER_IP;
+               else if (IC_UTILS_CONNECTIVITY_TCP & conn_options)
+                       *adapter = OC_ADAPTER_TCP;
+               else
+                       *adapter = OC_DEFAULT_ADAPTER;
+
+               if (IC_UTILS_CONNECTIVITY_IPV4 & conn_options)
+                       *flag = OC_IP_USE_V4;
+               else if (IC_UTILS_CONNECTIVITY_IPV6 & conn_options)
+                       *flag = OC_IP_USE_V6;
+               else
+                       *flag = OC_DEFAULT_FLAGS;
                break;
        case IOTCON_CONNECTIVITY_ALL:
        default:
@@ -85,7 +103,9 @@ 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,
+int ic_ioty_convert_host_address(const char *host_address,
+               iotcon_connectivity_type_e conn_type,
+               int conn_options,
                OCDevAddr *dev_addr)
 {
        int index = 0;
@@ -98,27 +118,33 @@ int ic_ioty_convert_connectivity(const char *host_address, int conn_type,
                index = strlen(IC_COAPS);
        else if (IC_EQUAL == strncmp(IC_COAP, host_address, strlen(IC_COAP)))
                index = strlen(IC_COAP);
+       else if (IC_EQUAL == strncmp(IC_COAP_TCP, host_address, strlen(IC_COAP_TCP)))
+               index = strlen(IC_COAP_TCP);
+       else if (IC_EQUAL == strncmp(IC_COAPS_TCP, host_address, strlen(IC_COAPS_TCP)))
+               index = strlen(IC_COAPS_TCP);
 
        snprintf(host, sizeof(host), "%s", &host_address[index]);
 
        switch (conn_type) {
-       case IOTCON_CONNECTIVITY_IPV4:
-               dev_host = strtok_r(host, ":", &ptr);
-               snprintf(dev_addr->addr, sizeof(dev_addr->addr), "%s", dev_host);
-               dev_addr->port = atoi(strtok_r(NULL, ":", &ptr));
-               break;
-       case IOTCON_CONNECTIVITY_IPV6:
-               dev_host = strtok_r(host, "]", &ptr);
-               snprintf(dev_addr->addr, sizeof(dev_addr->addr), "%s", dev_host + 1);
-               dev_addr->port = atoi(strtok_r(NULL, ":", &ptr));
+       case IOTCON_CONNECTIVITY_IP:
+               if (IC_UTILS_CONNECTIVITY_IPV4 & conn_options) {
+                       dev_host = strtok_r(host, ":", &ptr);
+                       snprintf(dev_addr->addr, sizeof(dev_addr->addr), "%s", dev_host);
+                       dev_addr->port = atoi(strtok_r(NULL, ":", &ptr));
+               } else if (IC_UTILS_CONNECTIVITY_IPV6 & conn_options) {
+                       dev_host = strtok_r(host, "]", &ptr);
+                       snprintf(dev_addr->addr, sizeof(dev_addr->addr), "%s", dev_host + 1);
+                       dev_addr->port = atoi(strtok_r(NULL, ":", &ptr));
+               }
                break;
+       case IOTCON_CONNECTIVITY_ALL:
        default:
                ERR("Invalid Connectivity Type(%d)", conn_type);
                return IOTCON_ERROR_INVALID_PARAMETER;
        }
 
-       _ic_ioty_conn_type_to_oic_transport_type(conn_type, &(dev_addr->adapter),
-                       &(dev_addr->flags));
+       _ic_ioty_conn_type_to_oic_transport_type(conn_type, conn_options, &dev_addr->adapter,
+                       &dev_addr->flags);
 
        return IOTCON_ERROR_NONE;
 }
index 42bf8cf..cad3d0f 100644 (file)
 #include "iotcon-types.h"
 
 /* iotcon -> oic */
-OCConnectivityType ic_ioty_convert_connectivity_type(
-               iotcon_connectivity_type_e conn_type);
+OCConnectivityType ic_ioty_convert_connectivity_type(iotcon_connectivity_type_e conn_type,
+               int conn_options);
 OCMethod ic_ioty_convert_request_type(iotcon_request_type_e req_type);
 OCEntityHandlerResult ic_ioty_convert_response_result(iotcon_response_result_e result);
 OCQualityOfService ic_ioty_convert_qos(iotcon_qos_e qos);
-int ic_ioty_convert_connectivity(const char *host_address, int conn_type,
+int ic_ioty_convert_host_address(const char *host_address,
+               iotcon_connectivity_type_e conn_type,
+               int conn_options,
                OCDevAddr *dev_addr);
 uint8_t ic_ioty_convert_policies(uint8_t policies);
 
index da8cc8d..a9fe77f 100644 (file)
@@ -123,20 +123,25 @@ void* icl_ioty_ocprocess_thread(void *data)
 
 static gboolean _icl_ioty_ocprocess_find_idle_cb(gpointer p)
 {
-       int i, ret;
+       int ret;
        icl_cb_s *cb_data;
        icl_find_cb_s *find_cb_data = p;
        iotcon_found_resource_cb cb;
+       iotcon_remote_resource_h resource;
+       GList *resource_list;
 
        RETV_IF(NULL == find_cb_data, G_SOURCE_REMOVE);
        cb_data = find_cb_data->cb_data;
 
+       resource_list = find_cb_data->resource_list;
+
        if (cb_data && cb_data->cb) {
-               for (i = 0; i < find_cb_data->resource_count; i++) {
-                       find_cb_data->resource_list[i]->is_found = true;
+               for (; resource_list; resource_list = resource_list->next) {
+                       resource = resource_list->data;
+                       resource->is_found = true;
                        cb = (iotcon_found_resource_cb)cb_data->cb;
-                       if (IOTCON_FUNC_STOP == cb(find_cb_data->resource_list[i], IOTCON_ERROR_NONE,
-                                               cb_data->user_data)) { /* Stop */
+                       if (IOTCON_FUNC_STOP == cb(resource, IOTCON_ERROR_NONE, cb_data->user_data)) {
+                               /* Stop */
                                INFO("Stop the callback");
                                cb_data->cb = NULL;
 
@@ -151,6 +156,7 @@ static gboolean _icl_ioty_ocprocess_find_idle_cb(gpointer p)
 
                                break;
                        }
+                       resource->is_found = false;
                }
        }
        icl_destroy_find_cb_data(find_cb_data);
@@ -188,8 +194,8 @@ OCStackApplicationResult icl_ioty_ocprocess_find_cb(void *ctx, OCDoHandle handle
                OCClientResponse *resp)
 {
        FN_CALL;
-       int ret, resource_count;
-       iotcon_remote_resource_h *resource_list;
+       int ret;
+       GList *resource_list;
        icl_find_cb_s *find_cb_data = NULL;
        icl_cb_s *cb_data = ctx;
 
@@ -200,8 +206,8 @@ OCStackApplicationResult icl_ioty_ocprocess_find_cb(void *ctx, OCDoHandle handle
        RETVM_IF(PAYLOAD_TYPE_DISCOVERY != resp->payload->type,
                        OC_STACK_KEEP_TRANSACTION, "Invalid payload type(%d)", resp->payload->type);
 
-       ret = ic_ioty_parse_oic_discovery_payload(&(resp->devAddr),
-                       (OCDiscoveryPayload*)resp->payload, &resource_list, &resource_count);
+       ret = ic_ioty_parse_oic_discovery_payload(&(resp->devAddr), cb_data->connectivity_type,
+                       cb_data->connectivity_extra, (OCDiscoveryPayload*)resp->payload, &resource_list);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("_icl_ioty_ocprocess_parse_find_payload() Fail(%d)", ret);
                cb_data->result = ret;
@@ -209,7 +215,7 @@ OCStackApplicationResult icl_ioty_ocprocess_find_cb(void *ctx, OCDoHandle handle
                return OC_STACK_KEEP_TRANSACTION;
        }
 
-       ret = icl_create_find_cb_data(cb_data, resource_list, resource_count, &find_cb_data);
+       ret = icl_create_find_cb_data(cb_data, resource_list, &find_cb_data);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("icl_create_find_cb_data() Fail(%d)", ret);
                cb_data->result = ret;
index a0e10de..94cd59d 100644 (file)
@@ -65,62 +65,80 @@ iotcon_error_e ic_ioty_parse_oic_error(OCStackResult ret)
        return IOTCON_ERROR_IOTIVITY;
 }
 
-static iotcon_connectivity_type_e _ioty_parse_oic_transport(OCTransportAdapter adapter,
-               OCTransportFlags flag)
-{
-       iotcon_connectivity_type_e type = IOTCON_CONNECTIVITY_ALL;
 
+static void _ioty_parse_oic_transport(OCTransportAdapter adapter, OCTransportFlags flag,
+               iotcon_connectivity_type_e *conn_type, int *conn_options)
+{
        /* Need to consider to allow various connectivity types */
        switch (adapter) {
        case OC_ADAPTER_IP:
+               *conn_options = IC_UTILS_CONNECTIVITY_UDP;
                if (OC_IP_USE_V4 & flag)
-                       type = IOTCON_CONNECTIVITY_IPV4;
+                       *conn_options |= IC_UTILS_CONNECTIVITY_IPV4;
                else if (OC_IP_USE_V6 & flag)
-                       type = IOTCON_CONNECTIVITY_IPV6;
-               else
-                       ERR("Invalid Flag(%d)", flag);
+                       *conn_options |= IC_UTILS_CONNECTIVITY_IPV6;
+               break;
+       case OC_ADAPTER_TCP:
+               *conn_options = IC_UTILS_CONNECTIVITY_TCP;
+               if (OC_IP_USE_V4 & flag)
+                       *conn_options |= IC_UTILS_CONNECTIVITY_IPV4;
+               else if (OC_IP_USE_V6 & flag)
+                       *conn_options |= IC_UTILS_CONNECTIVITY_IPV6;
                break;
        default:
-               ERR("Invalid Adpater(%d)", adapter);
+               ERR("Invalid Adapter(%d) / Flag(%d)", adapter, flag);
+               return;
        }
-       return type;
+
+       *conn_type = IOTCON_CONNECTIVITY_IP;
 }
 
 
 int ic_ioty_parse_oic_dev_address(OCDevAddr *dev_addr, char **host_address,
                int *conn_type)
 {
-       int connectivity_type;
+       int conn_options;
        char host_addr[PATH_MAX] = {0};
        const char *coap_str;
+       iotcon_connectivity_type_e temp_conn_type;
 
        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);
+       _ioty_parse_oic_transport(dev_addr->adapter, dev_addr->flags, &temp_conn_type,
+                       &conn_options);
 
-       if (OC_FLAG_SECURE & dev_addr->flags)
-               coap_str = IC_COAPS;
-       else
-               coap_str = IC_COAP;
+       if (OC_FLAG_SECURE & dev_addr->flags) {
+               if (OC_ADAPTER_TCP & dev_addr->adapter)
+                       coap_str = IC_COAPS_TCP;
+               else
+                       coap_str = IC_COAPS;
+       } else {
+               if (OC_ADAPTER_TCP & dev_addr->adapter)
+                       coap_str = IC_COAP_TCP;
+               else
+                       coap_str = IC_COAP;
+       }
 
-       switch (connectivity_type) {
-       case IOTCON_CONNECTIVITY_IPV6:
-               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%s:%d", coap_str, dev_addr->addr,
-                               dev_addr->port);
+       switch (temp_conn_type) {
+       case IOTCON_CONNECTIVITY_IP:
+               if (IC_UTILS_CONNECTIVITY_IPV6 & conn_options) {
+                       snprintf(host_addr, sizeof(host_addr), "%s[%s]:%d", coap_str, dev_addr->addr,
+                                       dev_addr->port);
+               } else {
+                       snprintf(host_addr, sizeof(host_addr), "%s%s:%d", coap_str, dev_addr->addr,
+                                       dev_addr->port);
+               }
                break;
+       case IOTCON_CONNECTIVITY_ALL:
        default:
-               ERR("Invalid Connectivity Type(%d)", connectivity_type);
+               ERR("Invalid Connectivity Type(%d)", temp_conn_type);
                return IOTCON_ERROR_INVALID_PARAMETER;
        }
 
        *host_address = strdup(host_addr);
 
-       *conn_type = connectivity_type;
+       *conn_type = temp_conn_type;
 
        return IOTCON_ERROR_NONE;
 }
@@ -204,59 +222,119 @@ iotcon_request_type_e ic_ioty_parse_oic_method(OCMethod method)
        }
 }
 
-static void _icl_ioty_free_resource_list(iotcon_remote_resource_h *resource_list,
-               int resource_count)
+void ic_ioty_free_resource_list(gpointer data)
+{
+       iotcon_remote_resource_h resource = data;
+
+       iotcon_remote_resource_destroy(resource);
+}
+
+static int _parse_remote_resource(OCDevAddr *dev_addr,
+               OCTransportAdapter adapter,
+               int port,
+               uint8_t policies,
+               char *uri,
+               iotcon_resource_interfaces_h ifaces,
+               iotcon_resource_types_h types,
+               char *device_id,
+               char *device_name,
+               iotcon_remote_resource_h *resource)
 {
-       int i;
+       int ret;
+       int conn_options;
+       const char *coap_str = IC_COAP;
+       char host_address[PATH_MAX] = {0};
+       iotcon_remote_resource_h temp;
+       iotcon_connectivity_type_e conn_type;
+
+       _ioty_parse_oic_transport(adapter, dev_addr->flags, &conn_type, &conn_options);
+
+       switch (conn_type) {
+       case IOTCON_CONNECTIVITY_IP:
+               if (IC_UTILS_CONNECTIVITY_TCP & conn_options) {
+                       if (IOTCON_RESOURCE_SECURE & policies)
+                               coap_str = IC_COAPS_TCP;
+                       else
+                               coap_str = IC_COAP_TCP;
+               }
+               else if (IC_UTILS_CONNECTIVITY_UDP & conn_options) {
+                       if (IOTCON_RESOURCE_SECURE & policies)
+                               coap_str = IC_COAPS;
+                       else
+                               coap_str = IC_COAP;
+               }
+
+               if (IC_UTILS_CONNECTIVITY_IPV6 & conn_options) {
+                       snprintf(host_address, sizeof(host_address), "%s[%s]:%d", coap_str,
+                                       dev_addr->addr, port);
+               } else {
+                       snprintf(host_address, sizeof(host_address), "%s%s:%d", coap_str,
+                                       dev_addr->addr, port);
+               }
+               break;
+       case IOTCON_CONNECTIVITY_ALL:
+       default:
+               snprintf(host_address, sizeof(host_address), "%s%s", coap_str, dev_addr->addr);
+       }
 
-       RET_IF(NULL == resource_list);
+       /* remote resource */
+       ret = iotcon_remote_resource_create(host_address, conn_type, uri, policies, types,
+                       ifaces, &temp);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_remote_resource_create() Fail(%d)", ret);
+               return ret;
+       }
 
-       for (i = 0; i < resource_count; i++)
-               iotcon_remote_resource_destroy(resource_list[i]);
+       temp->device_id = strdup(device_id);
+       if (NULL == temp->device_id) {
+               ERR("strdup(device_id) Fail(%d)", errno);
+               iotcon_remote_resource_destroy(temp);
+               return IOTCON_ERROR_OUT_OF_MEMORY;
+       }
 
-       free(resource_list);
+       if (device_name)
+               temp->device_name = strdup(device_name);
+       else
+               temp->device_name = strdup("");
+       if (NULL == temp->device_name) {
+               ERR("strdup(device_name) Fail(%d)", errno);
+               iotcon_remote_resource_destroy(temp);
+               return IOTCON_ERROR_OUT_OF_MEMORY;
+       }
+
+       *resource = temp;
+
+       return IOTCON_ERROR_NONE;
 }
 
 int ic_ioty_parse_oic_discovery_payload(OCDevAddr *dev_addr,
+               iotcon_connectivity_type_e connectivity_type,
+               int connectivity_prefer,
                OCDiscoveryPayload *payload,
-               iotcon_remote_resource_h **resource_list,
-               int *resource_count)
+               GList **resource_list)
 {
-       int i, ret, res_count;
-       iotcon_remote_resource_h *res_list;
+       int ret;
+       GList *res_list = NULL;
        struct OCResourcePayload *res_payload;
 
        RETV_IF(NULL == payload, IOTCON_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == dev_addr, IOTCON_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == resource_list, IOTCON_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == resource_count, IOTCON_ERROR_INVALID_PARAMETER);
-
-       res_payload = payload->resources;
-       res_count = OCDiscoveryPayloadGetResourceCount(payload);
-       if (res_count <= 0) {
-               ERR("Invalid count(%d)", res_count);
-               return IOTCON_ERROR_IOTIVITY;
-       }
-
-       res_list = calloc(res_count, sizeof(iotcon_remote_resource_h));
-       if (NULL == res_list) {
-               ERR("calloc() Fail(%d)", errno);
-               return IOTCON_ERROR_OUT_OF_MEMORY;
-       }
 
-       for (i = 0; res_payload; i++, res_payload = res_payload->next) {
-               int port, conn_type;
+       for (res_payload = payload->resources; res_payload; res_payload = res_payload->next) {
+               int port;
+               bool udp_on;
+               bool tcp_on;
                uint8_t policies;
+               iotcon_remote_resource_h res;
                iotcon_resource_interfaces_h ifaces;
                iotcon_resource_types_h types;
-               char host_addr[PATH_MAX] = {0};
-               char *device_name;
                OCStringLL *node;
 
                /* uri path */
                if (NULL == res_payload->uri) {
                        ERR("res_payload uri is NULL");
-                       _icl_ioty_free_resource_list(res_list, res_count);
+                       g_list_free_full(res_list, ic_ioty_free_resource_list);
                        return IOTCON_ERROR_IOTIVITY;
                }
 
@@ -264,14 +342,14 @@ int ic_ioty_parse_oic_discovery_payload(OCDevAddr *dev_addr,
                node = res_payload->types;
                if (NULL == node) {
                        ERR("res_payload types is NULL");
-                       _icl_ioty_free_resource_list(res_list, res_count);
+                       g_list_free_full(res_list, ic_ioty_free_resource_list);
                        return IOTCON_ERROR_IOTIVITY;
                }
 
                ret = iotcon_resource_types_create(&types);
                if (IOTCON_ERROR_NONE != ret) {
                        ERR("iotcon_resource_types_create() Fail(%d)", ret);
-                       _icl_ioty_free_resource_list(res_list, res_count);
+                       g_list_free_full(res_list, ic_ioty_free_resource_list);
                        return ret;
                }
 
@@ -280,7 +358,7 @@ int ic_ioty_parse_oic_discovery_payload(OCDevAddr *dev_addr,
                        if (IOTCON_ERROR_NONE != ret) {
                                ERR("iotcon_resource_types_add() Fail(%d)", ret);
                                iotcon_resource_types_destroy(types);
-                               _icl_ioty_free_resource_list(res_list, res_count);
+                               g_list_free_full(res_list, ic_ioty_free_resource_list);
                                return ret;
                        }
                        node = node->next;
@@ -302,61 +380,57 @@ int ic_ioty_parse_oic_discovery_payload(OCDevAddr *dev_addr,
                if (res_payload->secure)
                        policies |= IOTCON_RESOURCE_SECURE;
 
-               /* port */
-               port = (res_payload->port) ? res_payload->port : dev_addr->port;
+               /* preference is not set */
+               tcp_on = true;
+               udp_on = true;
 
-               /* connectivity type */
-               conn_type = _ioty_parse_oic_transport(dev_addr->adapter, dev_addr->flags);
-
-               /* host address */
-               switch (conn_type) {
-               case IOTCON_CONNECTIVITY_IPV6:
-                       snprintf(host_addr, sizeof(host_addr), "[%s]:%d", dev_addr->addr, port);
-                       break;
-               case IOTCON_CONNECTIVITY_IPV4:
-                       snprintf(host_addr, sizeof(host_addr), "%s:%d", dev_addr->addr, port);
-                       break;
-               default:
-                       snprintf(host_addr, sizeof(host_addr), "%s", dev_addr->addr);
+               if ((IOTCON_CONNECTIVITY_PREFER_UDP | IOTCON_CONNECTIVITY_PREFER_TCP)
+                               & connectivity_prefer) {
+                       udp_on = IOTCON_CONNECTIVITY_PREFER_UDP & connectivity_prefer;
+                       tcp_on = IOTCON_CONNECTIVITY_PREFER_TCP & connectivity_prefer;
                }
 
-               ret = iotcon_remote_resource_create(host_addr, conn_type, res_payload->uri,
-                               policies, types, ifaces, &(res_list[i]));
-               if (IOTCON_ERROR_NONE != ret) {
-                       ERR("iotcon_remote_resource_create() Fail(%d)", ret);
-                       iotcon_resource_interfaces_destroy(ifaces);
-                       iotcon_resource_types_destroy(types);
-                       _icl_ioty_free_resource_list(res_list, res_count);
-                       return ret;
-               }
+               /* UDP */
+               if (udp_on || (0 == res_payload->tcpPort)) {
+                       /* port */
+                       port = (res_payload->port) ? res_payload->port : dev_addr->port;
 
-               res_list[i]->device_id = strdup(payload->sid);
-               if (NULL == res_list[i]->device_id) {
-                       ERR("strdup(device_id) Fail(%d)", errno);
-                       _icl_ioty_free_resource_list(res_list, res_count);
-                       return IOTCON_ERROR_OUT_OF_MEMORY;
-               }
+                       ret = _parse_remote_resource(dev_addr, dev_addr->adapter, port, policies,
+                                       res_payload->uri, ifaces, types, payload->sid, payload->name, &res);
+                       if (IOTCON_ERROR_NONE != ret) {
+                               ERR("_parse_remote_resource() Fail(%d)", ret);
+                               iotcon_resource_interfaces_destroy(ifaces);
+                               iotcon_resource_types_destroy(types);
+                               continue;
+                       }
 
-               if (payload->name)
-                       device_name = strdup(payload->name);
-               else
-                       device_name = strdup("");
-               if (NULL == device_name) {
-                       ERR("strdup(device_name) Fail(%d)", errno);
-                       _icl_ioty_free_resource_list(res_list, res_count);
-                       return IOTCON_ERROR_OUT_OF_MEMORY;
+                       res_list = g_list_append(res_list, res);
                }
 
-               res_list[i]->device_name = device_name;
+               /* TCP */
+               if (tcp_on && res_payload->tcpPort) {
+                       /* port */
+                       port = res_payload->tcpPort;
+
+                       ret = _parse_remote_resource(dev_addr, OC_ADAPTER_TCP, port, policies,
+                                       res_payload->uri, ifaces, types, payload->sid, payload->name, &res);
+                       if (IOTCON_ERROR_NONE != ret) {
+                               ERR("_parse_remote_resource() Fail(%d)", ret);
+                               iotcon_resource_interfaces_destroy(ifaces);
+                               iotcon_resource_types_destroy(types);
+                               continue;
+                       }
+
+                       res_list = g_list_append(res_list, res);
+               }
 
                iotcon_resource_interfaces_destroy(ifaces);
                iotcon_resource_types_destroy(types);
        }
 
        *resource_list = res_list;
-       *resource_count = res_count;
-       return IOTCON_ERROR_NONE;
 
+       return IOTCON_ERROR_NONE;
 }
 
 int ic_ioty_parse_oic_device_payload(OCDevicePayload *payload,
index 1e9a508..0fb0753 100644 (file)
@@ -17,6 +17,7 @@
 #define __IOTCON_INTERNAL_IOTIVITY_PARSE_H__
 
 #include <stdbool.h>
+#include <glib.h>
 
 #include "iotcon-types.h"
 #include "iotcon-errors.h"
@@ -31,10 +32,12 @@ int ic_ioty_parse_oic_dev_address(OCDevAddr *dev_addr, char **host_address,
 
 int ic_ioty_parse_oic_header_option(OCHeaderOption *option, int option_size,
                iotcon_options_h *options);
+void ic_ioty_free_resource_list(gpointer data);
 int ic_ioty_parse_oic_discovery_payload(OCDevAddr *dev_addr,
+               iotcon_connectivity_type_e connectivity_type,
+               int connectivity_prefer,
                OCDiscoveryPayload *discovered,
-               iotcon_remote_resource_h **resource_list,
-               int *resource_count);
+               GList **resource_list);
 int ic_ioty_parse_oic_device_payload(OCDevicePayload *payload,
                iotcon_device_info_h *device_info);
 int ic_ioty_parse_oic_platform_payload(OCPlatformPayload *payload,
@@ -46,5 +49,4 @@ int ic_ioty_parse_oic_presence_payload(OCDevAddr *dev_addr,
 int ic_ioty_parse_oic_rep_payload(OCRepPayload *payload, bool is_parent,
                iotcon_representation_h *representation);
 
-
 #endif /*__IOTCON_INTERNAL_IOTIVITY_PARSE_H__*/
index fdf0892..0fce711 100644 (file)
@@ -386,12 +386,13 @@ static char* _icl_ioty_resource_generate_uri(const char *uri_path, iotcon_query_
 }
 
 int icl_ioty_find_resource(const char *host_address,
-               iotcon_connectivity_type_e connectivity_type,
+               int connectivity_type,
                iotcon_query_h query,
                iotcon_found_resource_cb cb,
                void *user_data)
 {
        FN_CALL;
+       int conn_options;
        int ret, timeout;
        char *coap_str = NULL;
        char *full_uri;
@@ -428,15 +429,27 @@ int icl_ioty_find_resource(const char *host_address,
                free(full_uri);
                return IOTCON_ERROR_OUT_OF_MEMORY;
        }
+
        cb_data->op = ICL_FIND_RESOURCE;
        cb_data->cb = cb;
        cb_data->user_data = user_data;
+       cb_data->connectivity_type = connectivity_type % IC_CONNECTIVITY_REMOVE_EXTRA_OPTIONS;
+       cb_data->connectivity_extra = connectivity_type - cb_data->connectivity_type;
 
        cbdata.context = cb_data;
        cbdata.cb = icl_ioty_ocprocess_find_cb;
        cbdata.cd = _icl_ioty_free_cb_data;
 
-       oic_conn_type = ic_ioty_convert_connectivity_type(connectivity_type);
+       conn_options = ic_utils_host_address_get_connectivity(host_address,
+                       cb_data->connectivity_type);
+       if (NULL == host_address && IOTCON_CONNECTIVITY_IP == cb_data->connectivity_type) {
+               if (IOTCON_CONNECTIVITY_IPV4_ONLY & cb_data->connectivity_extra)
+                       conn_options |= IC_UTILS_CONNECTIVITY_IPV4;
+               else if (IOTCON_CONNECTIVITY_IPV6_ONLY & cb_data->connectivity_extra)
+                       conn_options |= IC_UTILS_CONNECTIVITY_IPV6;
+       }
+       oic_conn_type = ic_ioty_convert_connectivity_type(cb_data->connectivity_type,
+                       conn_options);
 
        ret = icl_ioty_mutex_lock();
        if (IOTCON_ERROR_NONE != ret) {
@@ -467,12 +480,14 @@ 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,
+               int connectivity_type,
                iotcon_query_h query,
                iotcon_device_info_cb cb,
                void *user_data)
 {
        int ret, timeout;
+       int conn_extra;
+       int conn_options;
        char *coap_str = NULL;
        char *full_uri;
        char uri[PATH_MAX] = {0};
@@ -514,7 +529,18 @@ int icl_ioty_find_device_info(const char *host_address,
        cbdata.cb = icl_ioty_ocprocess_device_info_cb;
        cbdata.cd = _icl_ioty_free_cb_data;
 
-       oic_conn_type = ic_ioty_convert_connectivity_type(connectivity_type);
+       conn_extra = connectivity_type;
+       connectivity_type %= IC_CONNECTIVITY_REMOVE_EXTRA_OPTIONS;
+       conn_extra -= connectivity_type;
+
+       conn_options = ic_utils_host_address_get_connectivity(host_address, connectivity_type);
+       if (NULL == host_address && IOTCON_CONNECTIVITY_IP == connectivity_type) {
+               if (IOTCON_CONNECTIVITY_IPV4_ONLY & conn_extra)
+                       conn_options |= IC_UTILS_CONNECTIVITY_IPV4;
+               else if (IOTCON_CONNECTIVITY_IPV6_ONLY & conn_extra)
+                       conn_options |= IC_UTILS_CONNECTIVITY_IPV6;
+       }
+       oic_conn_type = ic_ioty_convert_connectivity_type(connectivity_type, conn_options);
 
        ret = icl_ioty_mutex_lock();
        if (IOTCON_ERROR_NONE != ret) {
@@ -543,12 +569,14 @@ 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,
+               int connectivity_type,
                iotcon_query_h query,
                iotcon_platform_info_cb cb,
                void *user_data)
 {
        int ret, timeout;
+       int conn_extra;
+       int conn_options;
        char *coap_str = NULL;
        char *full_uri;
        char uri[PATH_MAX] = {0};
@@ -590,7 +618,18 @@ int icl_ioty_find_platform_info(const char *host_address,
        cbdata.cb = icl_ioty_ocprocess_platform_info_cb;
        cbdata.cd = _icl_ioty_free_cb_data;
 
-       oic_conn_type = ic_ioty_convert_connectivity_type(connectivity_type);
+       conn_extra = connectivity_type;
+       connectivity_type %= IC_CONNECTIVITY_REMOVE_EXTRA_OPTIONS;
+       conn_extra -= connectivity_type;
+
+       conn_options = ic_utils_host_address_get_connectivity(host_address, connectivity_type);
+       if (NULL == host_address && IOTCON_CONNECTIVITY_IP == connectivity_type) {
+               if (IOTCON_CONNECTIVITY_IPV4_ONLY & conn_extra)
+                       conn_options |= IC_UTILS_CONNECTIVITY_IPV4;
+               else if (IOTCON_CONNECTIVITY_IPV6_ONLY & conn_extra)
+                       conn_options |= IC_UTILS_CONNECTIVITY_IPV6;
+       }
+       oic_conn_type = ic_ioty_convert_connectivity_type(connectivity_type, conn_options);
 
        ret = icl_ioty_mutex_lock();
        if (IOTCON_ERROR_NONE != ret) {
@@ -681,7 +720,7 @@ int icl_ioty_set_platform_info()
 }
 
 int icl_ioty_add_presence_cb(const char *host_address,
-               iotcon_connectivity_type_e connectivity_type,
+               int connectivity_type,
                const char *resource_type,
                iotcon_presence_cb cb,
                void *user_data,
@@ -689,6 +728,8 @@ int icl_ioty_add_presence_cb(const char *host_address,
 {
        int ret;
        int index = 0;
+       int conn_extra;
+       int conn_options;
        OCDoHandle handle;
        const char *address;
        char uri[PATH_MAX] = {0};
@@ -720,7 +761,8 @@ int icl_ioty_add_presence_cb(const char *host_address,
        presence->user_data = user_data;
        if (host_address)
                presence->host_address = strdup(host_address);
-       presence->connectivity_type = connectivity_type;
+       presence->connectivity_type
+               = connectivity_type % IC_CONNECTIVITY_REMOVE_EXTRA_OPTIONS;
        if (resource_type)
                presence->resource_type = strdup(resource_type);
 
@@ -728,7 +770,18 @@ int icl_ioty_add_presence_cb(const char *host_address,
        cbdata.cd = NULL;
        cbdata.cb = icl_ioty_ocprocess_presence_cb;
 
-       oic_conn_type = ic_ioty_convert_connectivity_type(connectivity_type);
+       conn_extra = connectivity_type - presence->connectivity_type;
+
+       conn_options = ic_utils_host_address_get_connectivity(host_address,
+                       presence->connectivity_type);
+       if (NULL == host_address && IOTCON_CONNECTIVITY_IP == presence->connectivity_type) {
+               if (IOTCON_CONNECTIVITY_IPV4_ONLY & conn_extra)
+                       conn_options |= IC_UTILS_CONNECTIVITY_IPV4;
+               else if (IOTCON_CONNECTIVITY_IPV6_ONLY & conn_extra)
+                       conn_options |= IC_UTILS_CONNECTIVITY_IPV6;
+       }
+       oic_conn_type = ic_ioty_convert_connectivity_type(presence->connectivity_type,
+                       conn_options);
 
        ret = icl_ioty_mutex_lock();
        if (IOTCON_ERROR_NONE != ret) {
@@ -826,13 +879,14 @@ static int _icl_ioty_remote_resource_observe(iotcon_remote_resource_h resource,
        }
 
        /* connectivity type */
-       oic_conn_type = ic_ioty_convert_connectivity_type(resource->connectivity_type);
+       oic_conn_type = ic_ioty_convert_connectivity_type(resource->connectivity_type,
+                       resource->connectivity_options);
 
        /* host address, port */
-       ret = ic_ioty_convert_connectivity(resource->host_address,
-                       resource->connectivity_type, &dev_addr);
+       ret = ic_ioty_convert_host_address(resource->host_address,
+                       resource->connectivity_type, resource->connectivity_options, &dev_addr);
        if (IOTCON_ERROR_NONE != ret) {
-               ERR("ic_ioty_convert_connectivity() Fail(%d)", ret);
+               ERR("ic_ioty_convert_host_address() Fail(%d)", ret);
                free(uri);
                return ret;
        }
@@ -1042,10 +1096,10 @@ static int _icl_ioty_remote_resource_crud(
        }
 
        /* host address, port */
-       ret = ic_ioty_convert_connectivity(resource->host_address,
-                       resource->connectivity_type, &dev_addr);
+       ret = ic_ioty_convert_host_address(resource->host_address,
+                       resource->connectivity_type, resource->connectivity_options, &dev_addr);
        if (IOTCON_ERROR_NONE != ret) {
-               ERR("ic_ioty_convert_connectivity() Fail(%d)", ret);
+               ERR("ic_ioty_convert_host_address() Fail(%d)", ret);
                free(uri);
                return ret;
        }
@@ -1064,7 +1118,8 @@ static int _icl_ioty_remote_resource_crud(
        }
 
        /* connectivity type */
-       oic_conn_type = ic_ioty_convert_connectivity_type(resource->connectivity_type);
+       oic_conn_type = ic_ioty_convert_connectivity_type(resource->connectivity_type,
+                       resource->connectivity_options);
 
        /* options */
        if (resource->header_options && resource->header_options->hash) {
index 182f9fd..293b609 100644 (file)
@@ -38,6 +38,8 @@ typedef struct {
        int result;
        int timeout;
        OCDoHandle handle;
+       int connectivity_type;
+       int connectivity_extra;
 } icl_cb_s;
 
 int icl_ioty_mutex_lock();
@@ -54,23 +56,23 @@ int icl_ioty_set_platform_info();
 
 /* client APIs */
 int icl_ioty_find_resource(const char *host_address,
-               iotcon_connectivity_type_e connectivity_type,
+               int connectivity_type,
                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,
+               int 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,
+               int connectivity_type,
                iotcon_query_h query,
                iotcon_platform_info_cb cb,
                void *user_data);
 
 int icl_ioty_add_presence_cb(const char *host_address,
-               iotcon_connectivity_type_e connectivity_type,
+               int connectivity_type,
                const char *resource_type,
                iotcon_presence_cb cb,
                void *user_data,
index b2068b5..33d7de6 100644 (file)
 #ifndef __IOTCON_INTERNAL_LOG_H__
 #define __IOTCON_INTERNAL_LOG_H__
 
-#define IC_LOG_RED "\033[0;31m"
-#define IC_LOG_GREEN "\033[0;32m"
-#define IC_LOG_BROWN "\033[0;33m"
-#define IC_LOG_BLUE "\033[0;34m"
-#define IC_LOG_END "\033[0;m"
+#define IC_LOG_RED "\033[31m"
+#define IC_LOG_GREEN "\033[32m"
+#define IC_LOG_BROWN "\033[33m"
+#define IC_LOG_BLUE "\033[34m"
+#define IC_LOG_END "\033[0m"
 
 #undef _DBG
 #undef _INFO
index 21f8149..9b2d409 100644 (file)
@@ -86,27 +86,11 @@ API int iotcon_add_presence_cb(const char *host_address,
        RETV_IF(resource_type && (false == icl_resource_check_type(resource_type)),
                        IOTCON_ERROR_INVALID_PARAMETER);
 
-       if ((IOTCON_MULTICAST_ADDRESS == host_address || '\0' == host_address[0])
-                       && (IOTCON_CONNECTIVITY_IPV4 != connectivity_type
-                               && IOTCON_CONNECTIVITY_ALL != connectivity_type)) {
-               ERR("Multicast is available only if IPV4");
-               return IOTCON_ERROR_INVALID_PARAMETER;
-       }
-
-       switch (connectivity_type) {
-       case IOTCON_CONNECTIVITY_IPV4:
-       case IOTCON_CONNECTIVITY_IPV6:
-       case IOTCON_CONNECTIVITY_ALL:
-               ret = icl_ioty_add_presence_cb(host_address, connectivity_type, resource_type,
-                               cb, user_data, presence_handle);
-               if (IOTCON_ERROR_NONE != ret) {
-                       ERR("icl_ioty_add_presence_cb() Fail(%d)", ret);
-                       return ret;
-               }
-               break;
-       default:
-               ERR("Invalid Connectivity Type(%d)", connectivity_type);
-               return IOTCON_ERROR_INVALID_PARAMETER;
+       ret = icl_ioty_add_presence_cb(host_address, connectivity_type, resource_type,
+                       cb, user_data, presence_handle);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("icl_ioty_add_presence_cb() Fail(%d)", ret);
+               return ret;
        }
 
        return IOTCON_ERROR_NONE;
@@ -116,28 +100,17 @@ API int iotcon_add_presence_cb(const char *host_address,
 API int iotcon_remove_presence_cb(iotcon_presence_h presence)
 {
        FN_CALL;
-       int ret, connectivity_type;
+       int ret;
 
        RETV_IF(false == ic_utils_check_ocf_feature(), IOTCON_ERROR_NOT_SUPPORTED);
        RETV_IF(false == ic_utils_check_permission(IC_PERMISSION_INTERNET),
                        IOTCON_ERROR_PERMISSION_DENIED);
        RETV_IF(NULL == presence, IOTCON_ERROR_INVALID_PARAMETER);
 
-       connectivity_type = presence->connectivity_type;
-
-       switch (connectivity_type) {
-       case IOTCON_CONNECTIVITY_IPV4:
-       case IOTCON_CONNECTIVITY_IPV6:
-       case IOTCON_CONNECTIVITY_ALL:
-               ret = icl_ioty_remove_presence_cb(presence);
-               if (IOTCON_ERROR_NONE != ret) {
-                       ERR("icl_ioty_remove_presence_cb() Fail(%d)", ret);
-                       return ret;
-               }
-               break;
-       default:
-               ERR("Invalid Connectivity Type(%d)", connectivity_type);
-               return IOTCON_ERROR_INVALID_PARAMETER;
+       ret = icl_ioty_remove_presence_cb(presence);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("icl_ioty_remove_presence_cb() Fail(%d)", ret);
+               return ret;
        }
 
        return IOTCON_ERROR_NONE;
index b6aba53..0bfd799 100644 (file)
@@ -222,13 +222,14 @@ static int _provisioning_device_get_host_address(OCProvisionDev_t *device,
 {
        FN_CALL;
        char host[PATH_MAX] = {0};
-       int temp_connectivity_type = CT_DEFAULT;
 
        if (device->connType & CT_ADAPTER_IP) {
                if (device->connType & CT_IP_USE_V4) {
-                       temp_connectivity_type = IOTCON_CONNECTIVITY_IPV4;
+                       snprintf(host, sizeof(host), "%s:%d", device->endpoint.addr,
+                                       device->endpoint.port);
                } else if (device->connType & CT_IP_USE_V6) {
-                       temp_connectivity_type = IOTCON_CONNECTIVITY_IPV6;
+                       snprintf(host, sizeof(host), "[%s]:%d", device->endpoint.addr,
+                                       device->endpoint.port);
                } else {
                        ERR("Invalid Connectivity Type(%d)", device->connType);
                        return IOTCON_ERROR_IOTIVITY;
@@ -238,22 +239,8 @@ static int _provisioning_device_get_host_address(OCProvisionDev_t *device,
                return IOTCON_ERROR_IOTIVITY;
        }
 
-       switch (temp_connectivity_type) {
-       case IOTCON_CONNECTIVITY_IPV6:
-               snprintf(host, sizeof(host), "[%s]:%d", device->endpoint.addr,
-                               device->endpoint.port);
-               break;
-       case IOTCON_CONNECTIVITY_IPV4:
-               snprintf(host, sizeof(host), "%s:%d", device->endpoint.addr,
-                               device->endpoint.port);
-               break;
-       default:
-               ERR("Invalid Connectivity Type(%d)", device->connType);
-               return IOTCON_ERROR_IOTIVITY;
-       }
-
        *host_address = strdup(host);
-       *connectivity_type = temp_connectivity_type;
+       *connectivity_type = IOTCON_CONNECTIVITY_IP;
 
        return IOTCON_ERROR_NONE;
 }
index 211b6d8..5832d04 100644 (file)
@@ -29,7 +29,7 @@
 API int iotcon_remote_resource_start_caching(iotcon_remote_resource_h resource,
                iotcon_remote_resource_cached_representation_changed_cb cb, void *user_data)
 {
-       int ret, connectivity_type;
+       int ret;
 
        RETV_IF(false == ic_utils_check_ocf_feature(), IOTCON_ERROR_NOT_SUPPORTED);
        RETV_IF(false == ic_utils_check_permission(IC_PERMISSION_INTERNET),
@@ -47,23 +47,11 @@ API int iotcon_remote_resource_start_caching(iotcon_remote_resource_h resource,
 
        INFO("Start Caching");
 
-       connectivity_type = resource->connectivity_type;
-
-       switch (connectivity_type) {
-       case IOTCON_CONNECTIVITY_IPV4:
-       case IOTCON_CONNECTIVITY_IPV6:
-       case IOTCON_CONNECTIVITY_ALL:
-               icl_remote_resource_ref(resource);
-               ret = icl_ioty_remote_resource_start_caching(resource, cb, user_data);
-               if (IOTCON_ERROR_NONE != ret) {
-                       ERR("icl_ioty_remote_resource_start_caching() Fail(%d)", ret);
-                       icl_remote_resource_unref(resource);
-                       return ret;
-               }
-               break;
-       default:
-               ERR("Invalid Connectivity Type(%d)", connectivity_type);
-               return IOTCON_ERROR_INVALID_PARAMETER;
+       ret = icl_ioty_remote_resource_start_caching(resource, cb, user_data);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("icl_ioty_remote_resource_start_caching() Fail(%d)", ret);
+               icl_remote_resource_unref(resource);
+               return ret;
        }
 
        return IOTCON_ERROR_NONE;
@@ -72,7 +60,7 @@ API int iotcon_remote_resource_start_caching(iotcon_remote_resource_h resource,
 
 API int iotcon_remote_resource_stop_caching(iotcon_remote_resource_h resource)
 {
-       int ret, connectivity_type;
+       int ret;
 
        RETV_IF(false == ic_utils_check_ocf_feature(), IOTCON_ERROR_NOT_SUPPORTED);
        RETV_IF(false == ic_utils_check_permission(IC_PERMISSION_INTERNET),
@@ -86,23 +74,12 @@ API int iotcon_remote_resource_stop_caching(iotcon_remote_resource_h resource)
 
        INFO("Stop Caching");
 
-       connectivity_type = resource->connectivity_type;
-
-       switch (connectivity_type) {
-       case IOTCON_CONNECTIVITY_IPV4:
-       case IOTCON_CONNECTIVITY_IPV6:
-       case IOTCON_CONNECTIVITY_ALL:
-               ret = icl_ioty_remote_resource_stop_caching(resource);
-               if (IOTCON_ERROR_NONE != ret) {
-                       ERR("icl_ioty_remote_resource_stop_caching() Fail(%d)", ret);
-                       return ret;
-               }
-               icl_remote_resource_unref(resource);
-               break;
-       default:
-               ERR("Invalid Connectivity Type(%d)", connectivity_type);
-               return IOTCON_ERROR_INVALID_PARAMETER;
+       ret = icl_ioty_remote_resource_stop_caching(resource);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("icl_ioty_remote_resource_stop_caching() Fail(%d)", ret);
+               return ret;
        }
+       icl_remote_resource_unref(resource);
 
        return IOTCON_ERROR_NONE;
 }
index ed7e822..d8dc861 100644 (file)
@@ -25,7 +25,7 @@
 API int iotcon_remote_resource_get(iotcon_remote_resource_h resource,
                iotcon_query_h query, iotcon_remote_resource_response_cb cb, void *user_data)
 {
-       int ret, connectivity_type;
+       int ret;
 
        RETV_IF(false == ic_utils_check_ocf_feature(), IOTCON_ERROR_NOT_SUPPORTED);
        RETV_IF(false == ic_utils_check_permission(IC_PERMISSION_INTERNET),
@@ -38,21 +38,10 @@ API int iotcon_remote_resource_get(iotcon_remote_resource_h resource,
                return IOTCON_ERROR_INVALID_PARAMETER;
        }
 
-       connectivity_type = resource->connectivity_type;
-
-       switch (connectivity_type) {
-       case IOTCON_CONNECTIVITY_IPV4:
-       case IOTCON_CONNECTIVITY_IPV6:
-       case IOTCON_CONNECTIVITY_ALL:
-               ret = icl_ioty_remote_resource_get(resource, query, cb, user_data);
-               if (IOTCON_ERROR_NONE != ret) {
-                       ERR("icl_ioty_remote_resource_get() Fail(%d)", ret);
-                       return ret;
-               }
-               break;
-       default:
-               ERR("Invalid Connectivity Type(%d)", connectivity_type);
-               return IOTCON_ERROR_INVALID_PARAMETER;
+       ret = icl_ioty_remote_resource_get(resource, query, cb, user_data);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("icl_ioty_remote_resource_get() Fail(%d)", ret);
+               return ret;
        }
 
        return IOTCON_ERROR_NONE;
@@ -65,7 +54,7 @@ API int iotcon_remote_resource_put(iotcon_remote_resource_h resource,
                iotcon_remote_resource_response_cb cb,
                void *user_data)
 {
-       int ret, connectivity_type;
+       int ret;
 
        RETV_IF(false == ic_utils_check_ocf_feature(), IOTCON_ERROR_NOT_SUPPORTED);
        RETV_IF(false == ic_utils_check_permission(IC_PERMISSION_INTERNET),
@@ -79,22 +68,12 @@ API int iotcon_remote_resource_put(iotcon_remote_resource_h resource,
                return IOTCON_ERROR_INVALID_PARAMETER;
        }
 
-       connectivity_type = resource->connectivity_type;
-
-       switch (connectivity_type) {
-       case IOTCON_CONNECTIVITY_IPV4:
-       case IOTCON_CONNECTIVITY_IPV6:
-       case IOTCON_CONNECTIVITY_ALL:
-               ret = icl_ioty_remote_resource_put(resource, repr, query, cb, user_data);
-               if (IOTCON_ERROR_NONE != ret) {
-                       ERR("icl_ioty_remote_resource_put() Fail(%d)", ret);
-                       return ret;
-               }
-               break;
-       default:
-               ERR("Invalid Connectivity Type(%d)", connectivity_type);
-               return IOTCON_ERROR_INVALID_PARAMETER;
+       ret = icl_ioty_remote_resource_put(resource, repr, query, cb, user_data);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("icl_ioty_remote_resource_put() Fail(%d)", ret);
+               return ret;
        }
+
        return IOTCON_ERROR_NONE;
 }
 
@@ -106,7 +85,7 @@ API int iotcon_remote_resource_post(iotcon_remote_resource_h resource,
                void *user_data)
 {
 
-       int ret, connectivity_type;
+       int ret;
 
        RETV_IF(false == ic_utils_check_ocf_feature(), IOTCON_ERROR_NOT_SUPPORTED);
        RETV_IF(false == ic_utils_check_permission(IC_PERMISSION_INTERNET),
@@ -120,21 +99,10 @@ API int iotcon_remote_resource_post(iotcon_remote_resource_h resource,
                return IOTCON_ERROR_INVALID_PARAMETER;
        }
 
-       connectivity_type = resource->connectivity_type;
-
-       switch (connectivity_type) {
-       case IOTCON_CONNECTIVITY_IPV4:
-       case IOTCON_CONNECTIVITY_IPV6:
-       case IOTCON_CONNECTIVITY_ALL:
-               ret = icl_ioty_remote_resource_post(resource, repr, query, cb, user_data);
-               if (IOTCON_ERROR_NONE != ret) {
-                       ERR("icl_ioty_remote_resource_post() Fail(%d)", ret);
-                       return ret;
-               }
-               break;
-       default:
-               ERR("Invalid Connectivity Type(%d)", connectivity_type);
-               return IOTCON_ERROR_INVALID_PARAMETER;
+       ret = icl_ioty_remote_resource_post(resource, repr, query, cb, user_data);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("icl_ioty_remote_resource_post() Fail(%d)", ret);
+               return ret;
        }
 
        return IOTCON_ERROR_NONE;
@@ -143,7 +111,7 @@ API int iotcon_remote_resource_post(iotcon_remote_resource_h resource,
 API int iotcon_remote_resource_delete(iotcon_remote_resource_h resource,
                iotcon_remote_resource_response_cb cb, void *user_data)
 {
-       int ret, connectivity_type;
+       int ret;
 
        RETV_IF(false == ic_utils_check_ocf_feature(), IOTCON_ERROR_NOT_SUPPORTED);
        RETV_IF(false == ic_utils_check_permission(IC_PERMISSION_INTERNET),
@@ -156,22 +124,12 @@ API int iotcon_remote_resource_delete(iotcon_remote_resource_h resource,
                return IOTCON_ERROR_INVALID_PARAMETER;
        }
 
-       connectivity_type = resource->connectivity_type;
-
-       switch (connectivity_type) {
-       case IOTCON_CONNECTIVITY_IPV4:
-       case IOTCON_CONNECTIVITY_IPV6:
-       case IOTCON_CONNECTIVITY_ALL:
-               ret = icl_ioty_remote_resource_delete(resource, cb, user_data);
-               if (IOTCON_ERROR_NONE != ret) {
-                       ERR("icl_ioty_remote_resource_delete() Fail(%d)", ret);
-                       return ret;
-               }
-               break;
-       default:
-               ERR("Invalid Connectivity Type(%d)", connectivity_type);
-               return IOTCON_ERROR_INVALID_PARAMETER;
+       ret = icl_ioty_remote_resource_delete(resource, cb, user_data);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("icl_ioty_remote_resource_delete() Fail(%d)", ret);
+               return ret;
        }
+
        return IOTCON_ERROR_NONE;
 }
 
@@ -182,7 +140,7 @@ API int iotcon_remote_resource_observe_register(
                iotcon_remote_resource_observe_cb cb,
                void *user_data)
 {
-       int ret, connectivity_type;
+       int ret;
 
        RETV_IF(false == ic_utils_check_ocf_feature(), IOTCON_ERROR_NOT_SUPPORTED);
        RETV_IF(false == ic_utils_check_permission(IC_PERMISSION_INTERNET),
@@ -196,22 +154,11 @@ API int iotcon_remote_resource_observe_register(
                return IOTCON_ERROR_INVALID_PARAMETER;
        }
 
-       connectivity_type = resource->connectivity_type;
-
-       switch (connectivity_type) {
-       case IOTCON_CONNECTIVITY_IPV4:
-       case IOTCON_CONNECTIVITY_IPV6:
-       case IOTCON_CONNECTIVITY_ALL:
-               ret = icl_ioty_remote_resource_observe_register(resource, observe_policy, query, cb,
-                               user_data);
-               if (IOTCON_ERROR_NONE != ret) {
-                       ERR("icl_ioty_remote_resource_observe_register() Fail(%d)", ret);
-                       return ret;
-               }
-               break;
-       default:
-               ERR("Invalid Connectivity Type(%d)", connectivity_type);
-               return IOTCON_ERROR_INVALID_PARAMETER;
+       ret = icl_ioty_remote_resource_observe_register(resource, observe_policy, query, cb,
+                       user_data);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("icl_ioty_remote_resource_observe_register() Fail(%d)", ret);
+               return ret;
        }
 
        return IOTCON_ERROR_NONE;
@@ -221,7 +168,7 @@ API int iotcon_remote_resource_observe_register(
 API int iotcon_remote_resource_observe_deregister(
                iotcon_remote_resource_h resource)
 {
-       int ret, connectivity_type;
+       int ret;
 
        RETV_IF(false == ic_utils_check_ocf_feature(), IOTCON_ERROR_NOT_SUPPORTED);
        RETV_IF(false == ic_utils_check_permission(IC_PERMISSION_INTERNET),
@@ -238,21 +185,10 @@ API int iotcon_remote_resource_observe_deregister(
                return IOTCON_ERROR_INVALID_PARAMETER;
        }
 
-       connectivity_type = resource->connectivity_type;
-
-       switch (connectivity_type) {
-       case IOTCON_CONNECTIVITY_IPV4:
-       case IOTCON_CONNECTIVITY_IPV6:
-       case IOTCON_CONNECTIVITY_ALL:
-               ret = icl_ioty_remote_resource_observe_deregister(resource);
-               if (IOTCON_ERROR_NONE != ret) {
-                       ERR("icl_ioty_remote_resource_observe_deregister() Fail(%d)", ret);
-                       return ret;
-               }
-               break;
-       default:
-               ERR("Invalid Connectivity Type(%d)", connectivity_type);
-               return IOTCON_ERROR_INVALID_PARAMETER;
+       ret = icl_ioty_remote_resource_observe_deregister(resource);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("icl_ioty_remote_resource_observe_deregister() Fail(%d)", ret);
+               return ret;
        }
 
        return IOTCON_ERROR_NONE;
index c2ec76a..ddf41c7 100644 (file)
@@ -28,7 +28,7 @@ API int iotcon_remote_resource_start_monitoring(
                iotcon_remote_resource_state_changed_cb cb,
                void *user_data)
 {
-       int ret, connectivity_type;
+       int ret;
 
        RETV_IF(false == ic_utils_check_ocf_feature(), IOTCON_ERROR_NOT_SUPPORTED);
        RETV_IF(false == ic_utils_check_permission(IC_PERMISSION_INTERNET),
@@ -49,23 +49,12 @@ API int iotcon_remote_resource_start_monitoring(
 
        resource->monitoring.state = IOTCON_REMOTE_RESOURCE_ALIVE;
 
-       connectivity_type = resource->connectivity_type;
-
-       switch (connectivity_type) {
-       case IOTCON_CONNECTIVITY_IPV4:
-       case IOTCON_CONNECTIVITY_IPV6:
-       case IOTCON_CONNECTIVITY_ALL:
-               icl_remote_resource_ref(resource);
-               ret = icl_ioty_remote_resource_start_monitoring(resource, cb, user_data);
-               if (IOTCON_ERROR_NONE != ret) {
-                       ERR("icl_ioty_remote_resource_start_monitoring() Fail(%d)", ret);
-                       icl_remote_resource_unref(resource);
-                       return ret;
-               }
-               break;
-       default:
-               ERR("Invalid Connectivity Type(%d)", connectivity_type);
-               return IOTCON_ERROR_INVALID_PARAMETER;
+       icl_remote_resource_ref(resource);
+       ret = icl_ioty_remote_resource_start_monitoring(resource, cb, user_data);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("icl_ioty_remote_resource_start_monitoring() Fail(%d)", ret);
+               icl_remote_resource_unref(resource);
+               return ret;
        }
 
        return IOTCON_ERROR_NONE;
@@ -74,7 +63,7 @@ API int iotcon_remote_resource_start_monitoring(
 
 API int iotcon_remote_resource_stop_monitoring(iotcon_remote_resource_h resource)
 {
-       int ret, connectivity_type;
+       int ret;
 
        RETV_IF(false == ic_utils_check_ocf_feature(), IOTCON_ERROR_NOT_SUPPORTED);
        RETV_IF(false == ic_utils_check_permission(IC_PERMISSION_INTERNET),
@@ -88,23 +77,12 @@ API int iotcon_remote_resource_stop_monitoring(iotcon_remote_resource_h resource
 
        INFO("Stop Monitoring");
 
-       connectivity_type = resource->connectivity_type;
-
-       switch (connectivity_type) {
-       case IOTCON_CONNECTIVITY_IPV4:
-       case IOTCON_CONNECTIVITY_IPV6:
-       case IOTCON_CONNECTIVITY_ALL:
-               ret = icl_ioty_remote_resource_stop_monitoring(resource);
-               if (IOTCON_ERROR_NONE != ret) {
-                       ERR("icl_ioty_remote_resource_stop_monitoring() Fail(%d)", ret);
-                       return ret;
-               }
-               icl_remote_resource_unref(resource);
-               break;
-       default:
-               ERR("Invalid Connectivity Type(%d)", connectivity_type);
-               return IOTCON_ERROR_INVALID_PARAMETER;
+       ret = icl_ioty_remote_resource_stop_monitoring(resource);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("icl_ioty_remote_resource_stop_monitoring() Fail(%d)", ret);
+               return ret;
        }
+       icl_remote_resource_unref(resource);
 
        return IOTCON_ERROR_NONE;
 }
index 740075a..d094a80 100644 (file)
@@ -35,7 +35,7 @@
 /* The length of resource_type should be less than or equal to 61.
  * 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,
+               int connectivity_type,
                iotcon_query_h query,
                iotcon_found_resource_cb cb,
                void *user_data)
@@ -45,22 +45,15 @@ API int iotcon_find_resource(const char *host_address,
        RETV_IF(false == ic_utils_check_ocf_feature(), IOTCON_ERROR_NOT_SUPPORTED);
        RETV_IF(false == ic_utils_check_permission(IC_PERMISSION_INTERNET),
                        IOTCON_ERROR_PERMISSION_DENIED);
+       RETV_IF(false == ic_utils_check_connectivity_type(connectivity_type),
+                       IOTCON_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == cb, 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, query, cb,
-                               user_data);
-               if (IOTCON_ERROR_NONE != ret) {
-                       ERR("icl_ioty_find_resource() Fail(%d)", ret);
-                       return ret;
-               }
-               break;
-       default:
-               ERR("Invalid Connectivity Type(%d)", connectivity_type);
-               return IOTCON_ERROR_INVALID_PARAMETER;
+       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;
        }
 
        return IOTCON_ERROR_NONE;
@@ -103,8 +96,11 @@ API int iotcon_remote_resource_create(const char *host_address,
                return IOTCON_ERROR_OUT_OF_MEMORY;
        }
 
-       resource->host_address = ic_utils_strdup(temp);
+       resource->connectivity_options = ic_utils_host_address_get_connectivity(temp,
+                       connectivity_type);
+
        resource->connectivity_type = connectivity_type;
+       resource->host_address = ic_utils_strdup(temp);
        resource->uri_path = ic_utils_strdup(uri_path);
        resource->policies = policies;
        resource->types = icl_resource_types_ref(resource_types);
@@ -225,6 +221,7 @@ API int iotcon_remote_resource_clone(iotcon_remote_resource_h src,
        resource->uri_path = ic_utils_strdup(src->uri_path);
        resource->host_address = ic_utils_strdup(src->host_address);
        resource->connectivity_type = src->connectivity_type;
+       resource->connectivity_options = src->connectivity_options;
        resource->device_id = ic_utils_strdup(src->device_id);
        resource->device_name = ic_utils_strdup(src->device_name);
        resource->policies = src->policies;
index de21b65..6e2cc04 100644 (file)
@@ -49,6 +49,7 @@ struct icl_remote_resource {
        iotcon_resource_types_h types;
        iotcon_resource_interfaces_h ifaces;
        iotcon_connectivity_type_e connectivity_type;
+       int connectivity_options;
        int64_t observe_handle;
        int checking_interval;
        unsigned int timer_id;
index a46ddbc..8b4799d 100644 (file)
 #include "ic-remote-resource.h"
 #include "ic-presence.h"
 #include "ic-request.h"
+#include "ic-ioty-parse.h"
 #include "ic-types.h"
 
 void icl_destroy_find_cb_data(icl_find_cb_s *cb_data)
 {
-       int i;
        RET_IF(NULL == cb_data);
 
-       for (i = 0; i < cb_data->resource_count; i++) {
-               cb_data->resource_list[i]->is_found = false;
-               iotcon_remote_resource_destroy(cb_data->resource_list[i]);
-       }
+       g_list_free_full(cb_data->resource_list, ic_ioty_free_resource_list);
 
-       free(cb_data->resource_list);
        free(cb_data);
 }
 
-int icl_create_find_cb_data(icl_cb_s *cb_data,
-               iotcon_remote_resource_h *resource_list,
-               int resource_count,
+int icl_create_find_cb_data(icl_cb_s *cb_data, GList *resource_list,
                icl_find_cb_s **find_cb_data)
 {
        icl_find_cb_s *cd;
@@ -57,7 +51,6 @@ int icl_create_find_cb_data(icl_cb_s *cb_data,
 
        cd->cb_data = cb_data;
        cd->resource_list = resource_list;
-       cd->resource_count = resource_count;
 
        *find_cb_data = cd;
        return IOTCON_ERROR_NONE;
index 1908fd0..45d5b2b 100644 (file)
@@ -24,8 +24,7 @@
 
 typedef struct {
        icl_cb_s *cb_data;
-       iotcon_remote_resource_h *resource_list;
-       int resource_count;
+       GList *resource_list;
 } icl_find_cb_s;
 
 typedef struct {
@@ -99,9 +98,7 @@ typedef struct {
 } icl_request_container_s;
 
 void icl_destroy_find_cb_data(icl_find_cb_s *cb_data);
-int icl_create_find_cb_data(icl_cb_s *cb_data,
-               iotcon_remote_resource_h *resource_list,
-               int resource_count,
+int icl_create_find_cb_data(icl_cb_s *cb_data, GList *resource_list,
                icl_find_cb_s **find_callback_data);
 
 void icl_destroy_device_cb_data(icl_device_cb_s *cb_data);
index 55fbe1c..baf25e0 100644 (file)
@@ -357,3 +357,60 @@ void ic_utils_cond_timedwait(int cond_type, int mutex_type, int polling_interval
                        &ts);
        WARN_IF(ETIMEDOUT != ret && 0 != ret, "pthread_cond_timedwait() Fail(%d)", ret);
 }
+
+int ic_utils_host_address_get_connectivity(const char *host_address, int conn_type)
+{
+       int options;
+
+       if (NULL == host_address || IOTCON_CONNECTIVITY_ALL == conn_type) {
+               return 0;
+       }
+
+       /* IOTCON_CONNECTIVITY_IP == conn_type */
+       if (IC_EQUAL == strncmp(IC_COAP, host_address, strlen(IC_COAP))) {
+               options = IC_UTILS_CONNECTIVITY_UDP;
+               if ('[' == host_address[strlen(IC_COAP)])
+                       options |= IC_UTILS_CONNECTIVITY_IPV6;
+               else
+                       options |= IC_UTILS_CONNECTIVITY_IPV4;
+       } else if (IC_EQUAL == strncmp(IC_COAPS, host_address, strlen(IC_COAPS))) {
+               options = IC_UTILS_CONNECTIVITY_UDP;
+               if ('[' == host_address[strlen(IC_COAPS)])
+                       options |= IC_UTILS_CONNECTIVITY_IPV6;
+               else
+                       options |= IC_UTILS_CONNECTIVITY_IPV4;
+       } else if (IC_EQUAL == strncmp(IC_COAP_TCP, host_address, strlen(IC_COAP_TCP))) {
+               options = IC_UTILS_CONNECTIVITY_TCP;
+               if ('[' == host_address[strlen(IC_COAP_TCP)])
+                       options |= IC_UTILS_CONNECTIVITY_IPV6;
+               else
+                       options |= IC_UTILS_CONNECTIVITY_IPV4;
+       } else if (IC_EQUAL == strncmp(IC_COAPS_TCP, host_address, strlen(IC_COAPS_TCP))) {
+               options = IC_UTILS_CONNECTIVITY_TCP;
+               if ('[' == host_address[strlen(IC_COAPS_TCP)])
+                       options |= IC_UTILS_CONNECTIVITY_IPV6;
+               else
+                       options |= IC_UTILS_CONNECTIVITY_IPV4;
+       } else {
+               options = IC_UTILS_CONNECTIVITY_UDP;
+               if ('[' == host_address[strlen(IC_COAPS_TCP)])
+                       options |= IC_UTILS_CONNECTIVITY_IPV6;
+               else
+                       options |= IC_UTILS_CONNECTIVITY_IPV4;
+       }
+
+       return options;
+}
+
+bool ic_utils_check_connectivity_type(int conn_type)
+{
+       if ((IOTCON_CONNECTIVITY_PREFER_UDP & conn_type)
+                       && (IOTCON_CONNECTIVITY_PREFER_TCP & conn_type))
+               return false;
+
+       if ((IOTCON_CONNECTIVITY_IPV4_ONLY & conn_type)
+                       && (IOTCON_CONNECTIVITY_IPV6_ONLY & conn_type))
+               return false;
+
+       return true;
+}
index 2e43b5e..20aba19 100644 (file)
@@ -42,6 +42,9 @@ void ic_utils_cond_polling_destroy();
 void ic_utils_cond_signal(int type);
 void ic_utils_cond_timedwait(int cond_type, int mutex_type, int polling_interval);
 
+int ic_utils_host_address_get_connectivity(const char *host_address, int conn_type);
+bool ic_utils_check_connectivity_type(int conn_type);
+
 enum IC_UTILS_MUTEX {
        IC_UTILS_MUTEX_INIT,
        IC_UTILS_MUTEX_IOTY,
@@ -54,4 +57,11 @@ enum IC_UTILS_COND {
        IC_UTILS_COND_MAX
 };
 
+enum IC_UTILS_CONNECTIVITY {
+       IC_UTILS_CONNECTIVITY_IPV4 = (1 << 0),
+       IC_UTILS_CONNECTIVITY_IPV6 = (1 << 1),
+       IC_UTILS_CONNECTIVITY_UDP = (1 << 2),
+       IC_UTILS_CONNECTIVITY_TCP = (1 << 3)
+};
+
 #endif /* __IOTCON_INTERNAL_UTILITY_H__ */
index a788fda..75f5f7c 100644 (file)
@@ -619,8 +619,8 @@ int main(int argc, char **argv)
        }
 
        /* find door typed resources */
-       ret = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_ALL,
-                       query, _found_resource, NULL);
+       ret = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP
+                       | IOTCON_CONNECTIVITY_PREFER_UDP, query, _found_resource, NULL);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("iotcon_find_resource() Fail(%d)", ret);
                iotcon_query_destroy(query);
index 642dab8..7d7ab90 100644 (file)
@@ -235,6 +235,7 @@ int main(int argc, char **argv)
        int ret;
        GMainLoop *loop;
        iotcon_query_h query;
+       int connectivity_type;
        iotcon_remote_resource_h resource;
 
        loop = g_main_loop_new(NULL, FALSE);
@@ -259,9 +260,12 @@ int main(int argc, char **argv)
                return -1;
        }
 
+       connectivity_type = IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_IPV4_ONLY
+               | IOTCON_CONNECTIVITY_PREFER_TCP;
+
        /* find door typed resources */
-       ret = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_ALL,
-                       query, _found_resource, &resource);
+       ret = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, connectivity_type, query,
+                       _found_resource, &resource);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("iotcon_find_resource() Fail(%d)", ret);
                iotcon_query_destroy(query);
index 6887a09..f0a9a74 100644 (file)
@@ -425,8 +425,8 @@ int main(int argc, char **argv)
        }
 
        /* find room typed resources */
-       ret = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_ALL,
-                       query, _found_resource, NULL);
+       ret = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_ALL
+                       | IOTCON_CONNECTIVITY_PREFER_UDP, query, _found_resource, NULL);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("iotcon_find_resource() Fail(%d)", ret);
                iotcon_query_destroy(query);