* @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
* @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);
* @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
* @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);
* @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
* @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);
/**
* @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;
/**
IOTCON_QOS_HIGH, /**< Indicates high quality of service */
} iotcon_qos_e;
-
/**
* @}
*/
#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__ */
}
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)
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;
}
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)
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;
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:
}
-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;
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;
}
#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);
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;
break;
}
+ resource->is_found = false;
}
}
icl_destroy_find_cb_data(find_cb_data);
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;
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;
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;
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;
}
}
}
-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;
}
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;
}
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;
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,
#define __IOTCON_INTERNAL_IOTIVITY_PARSE_H__
#include <stdbool.h>
+#include <glib.h>
#include "iotcon-types.h"
#include "iotcon-errors.h"
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,
int ic_ioty_parse_oic_rep_payload(OCRepPayload *payload, bool is_parent,
iotcon_representation_h *representation);
-
#endif /*__IOTCON_INTERNAL_IOTIVITY_PARSE_H__*/
}
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;
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) {
}
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};
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) {
}
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};
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) {
}
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,
{
int ret;
int index = 0;
+ int conn_extra;
+ int conn_options;
OCDoHandle handle;
const char *address;
char uri[PATH_MAX] = {0};
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);
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) {
}
/* 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;
}
}
/* 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;
}
}
/* 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) {
int result;
int timeout;
OCDoHandle handle;
+ int connectivity_type;
+ int connectivity_extra;
} icl_cb_s;
int icl_ioty_mutex_lock();
/* 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,
#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
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;
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;
{
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;
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;
}
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),
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;
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),
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;
}
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),
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;
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),
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;
}
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),
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;
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),
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;
}
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),
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;
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),
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;
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),
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;
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),
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;
}
/* 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)
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;
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);
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;
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;
#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;
cd->cb_data = cb_data;
cd->resource_list = resource_list;
- cd->resource_count = resource_count;
*find_cb_data = cd;
return IOTCON_ERROR_NONE;
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 {
} 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);
&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;
+}
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,
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__ */
}
/* 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);
int ret;
GMainLoop *loop;
iotcon_query_h query;
+ int connectivity_type;
iotcon_remote_resource_h resource;
loop = g_main_loop_new(NULL, FALSE);
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);
}
/* 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);