(2) Apply strict parameter condition(device_info, options, query, uri, resource_type)
(3) Add device-test
Change-Id: Ie49c67263cc9ff93e352ed6d4baab2da622fe4ef
Signed-off-by: youngman <yman.jung@samsung.com>
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include <stdbool.h>
#include <stdlib.h>
+#include <string.h>
#include <errno.h>
#include <glib.h>
#include "iotcon-struct.h"
#include "ic-common.h"
#include "ic-utils.h"
-#include "ic-struct.h"
-#include "ic-options.h"
#include "ic-ioty.h"
+#include "ic-options.h"
+#include "ic-client.h"
/* host address should begin with "coap://"
+ * The length of resource_type should be less than and equal to 61.
* If resource_type is NULL, then All resources in host are discovered. */
API int iotcon_find_resource(const char *host_addr, const char *resource_type,
iotcon_found_resource_cb cb, void *user_data)
RETV_IF(NULL == host_addr, IOTCON_ERROR_PARAM);
RETV_IF(NULL == cb, IOTCON_ERROR_PARAM);
+ if (resource_type && (IOTCON_RESOURCE_TYPE_LENGTH_MAX < strlen(resource_type))) {
+ ERR("The length of resource_type(%s) is invalid", resource_type);
+ return IOTCON_ERROR_NONE;
+ }
ret = ic_ioty_find_resource(host_addr, resource_type, cb, user_data);
if (IOTCON_ERROR_NONE != ret)
}
-/* If you know the information of resource, then you make a proxy of the resource. */
+/* If you know the information of resource, then you can make a proxy of the resource. */
API iotcon_client_h iotcon_client_new(const char *host,
const char *uri,
bool is_observable,
iotcon_interface_e resource_ifs)
{
FN_CALL;
+ int i;
iotcon_client_h resource = NULL;
RETV_IF(NULL == host, NULL);
RETV_IF(NULL == uri, NULL);
RETV_IF(NULL == resource_types, NULL);
+ for (i = 0; i < iotcon_str_list_length(resource_types); i++) {
+ if (IOTCON_RESOURCE_TYPE_LENGTH_MAX
+ < strlen(iotcon_str_list_nth_data(resource_types, i))) {
+ ERR("The length of resource_type is invalid");
+ return NULL;
+ }
+ }
+
resource = calloc(1, sizeof(struct ic_remote_resource));
if (NULL == resource) {
ERR("calloc() Fail(%d)", errno);
/* if header_options is NULL, then client's header_options is unset */
-API void iotcon_client_set_options(iotcon_client_h resource,
+API int iotcon_client_set_options(iotcon_client_h resource,
iotcon_options_h header_options)
{
- RET_IF(NULL == resource);
+ RETV_IF(NULL == resource, IOTCON_ERROR_PARAM);
if (resource->header_options)
iotcon_options_free(resource->header_options);
resource->header_options = header_options;
+
+ return IOTCON_ERROR_NONE;
}
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __IOT_CONNECTIVITY_MANAGER_INTERNAL_CLIENT_H__
+#define __IOT_CONNECTIVITY_MANAGER_INTERNAL_CLIENT_H__
+
+#include "iotcon-struct.h"
+#include "ic-options.h"
+
+typedef void* iotcon_observe_h;
+
+struct ic_remote_resource {
+ char *uri;
+ char *host;
+ bool is_observable;
+ bool is_collection;
+ iotcon_options_h header_options;
+ iotcon_str_list_s *types;
+ int ifaces;
+ iotcon_observe_h observe_handle;
+};
+
+#endif /* __IOT_CONNECTIVITY_MANAGER_INTERNAL_CLIENT_H__ */
#ifndef __IOT_CONNECTIVITY_MANAGER_INTERNAL_COMMON_H__
#define __IOT_CONNECTIVITY_MANAGER_INTERNAL_COMMON_H__
+#include "iotcon-errors.h"
#include "ic-log.h"
#ifdef API
* limitations under the License.
*/
#include <stdlib.h>
+#include <string.h>
#include <errno.h>
#include <glib.h>
#include "iotcon.h"
#include "ic-common.h"
-#include "ic-struct.h"
#include "ic-ioty.h"
+#include "ic-device.h"
+/* The length of manufacturer_name should be less than and equal to 16.
+ * The length of manufacturer_url should be less than and equal to 32. */
API int iotcon_register_device_info(
char *device_name,
char *host_name,
int ret;
struct ic_device_info device_info = {0};
+ if (manufacturer_name
+ && (IOTCON_MANUFACTURER_NAME_LENGTH_MAX < strlen(manufacturer_name))) {
+ ERR("The length of manufacturer_name(%s) is invalid.", manufacturer_name);
+ return IOTCON_ERROR_PARAM;
+ }
+
+ if (manufacturer_url
+ && (IOTCON_MANUFACTURER_URL_LENGTH_MAX < strlen(manufacturer_url))) {
+ ERR("The length of manufacturer_url(%s) is invalid.", manufacturer_url);
+ return IOTCON_ERROR_PARAM;
+ }
+
device_info.device_name = device_name;
device_info.host_name = host_name;
device_info.device_uuid = device_uuid;
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __IOT_CONNECTIVITY_MANAGER_INTERNAL_DEVICE_H__
+#define __IOT_CONNECTIVITY_MANAGER_INTERNAL_DEVICE_H__
+
+struct ic_device_info {
+ char *device_name;
+ char *host_name;
+ char *device_uuid;
+ char *content_type;
+ char *version;
+ char *manufacturer_name;
+ char *manufacturer_url;
+ char *model_number;
+ char *date_of_manufacture;
+ char *platform_ver;
+ char *firmware_ver;
+ char *support_url;
+};
+
+#endif /* __IOT_CONNECTIVITY_MANAGER_INTERNAL_DEVICE_H__ */
#include <OCApi.h>
#include <OCPlatform.h>
-#include "iotcon.h"
extern "C" {
+#include "iotcon-struct.h"
+#include "ic.h"
#include "ic-common.h"
#include "ic-utils.h"
#include "ic-repr.h"
-#include "ic.h"
-}
#include "ic-ioty-repr.h"
+}
using namespace OC;
using namespace std;
#include "ic.h"
#include "ic-common.h"
#include "ic-utils.h"
+#include "ic-client.h"
+#include "ic-device.h"
+#include "ic-request.h"
+#include "ic-response.h"
#include "ic-repr.h"
-#include "ic-struct.h"
+#include "ic-ioty-repr.h"
#include "ic-ioty.h"
}
-#include "ic-ioty-repr.h"
#define IC_UNICAST_RESOURCE_DISCOVERY ":5683/oc/core"
#define IC_MULTICAST_RESOURCE_DISCOVERY "/oc/core"
FN_CALL;
HeaderOptions headerOptions;
QueryParamsMap queryParams;
- resource_handler_s *temp_res = NULL;
+ ic_resource_s *temp_res = NULL;
struct ic_resource_request request_s = {0};
temp_res = ic_get_resource_handler_data(request->getResourceHandle());
DBG("obs_info.obsId=%d", observationInfo.obsId);
/* call handler_cb */
- if (temp_res->request_handler_cb) {
- temp_res->request_handler_cb(&request_s, temp_res->user_data);
+ if (temp_res->cb) {
+ temp_res->cb(&request_s, temp_res->user_data);
}
else {
WARN("temp_res->request_handler_cb is null");
resUri = uri;
- resType = iotcon_str_list_nth_data(res_types, 1);
+ resType = iotcon_str_list_nth_data(res_types, 0);
if (IOTCON_INTERFACE_DEFAULT & ifaces) {
resInterface = DEFAULT_INTERFACE;
OCResource::Ptr ocResource;
QueryParamsMap queryParams;
- if (query) {
+ if (query)
iotcon_query_foreach(query, _ic_ioty_accumulate_query_map, (void *)&queryParams);
- iotcon_query_free(query);
- }
ocResource = _ic_ioty_create_oc_resource(resource);
OCRepresentation ocRep;
QueryParamsMap queryParams;
- if (query) {
+ if (query)
iotcon_query_foreach(query, _ic_ioty_accumulate_query_map, (void*)&queryParams);
- iotcon_query_free(query);
- }
ocRep = ic_ioty_repr_parse(repr);
OCRepresentation ocRep;
OCResource::Ptr ocResource;
- if (query) {
+ if (query)
iotcon_query_foreach(query, _ic_ioty_accumulate_query_map, (void*)&queryParams);
- iotcon_query_free(query);
- }
ocRep = ic_ioty_repr_parse(repr);
ObserveType observeType;
QueryParamsMap queryParams;
- if (query) {
+ if (query)
iotcon_query_foreach(query, _ic_ioty_accumulate_query_map, (void*)&queryParams);
- iotcon_query_free(query);
- }
if (IOTCON_OBSERVE == observe_type) {
observeType = ObserveType::Observe;
#include <stdint.h>
#include "iotcon.h"
-#include "iotcon-constant.h"
-#include "ic-struct.h"
+#include "ic.h"
+#include "ic-response.h"
void ic_ioty_config(const char *addr, unsigned short port);
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include <stdlib.h>
#include <stdint.h>
+#include <stdlib.h>
#include <errno.h>
#include <glib.h>
-#include "iotcon.h"
+#include "iotcon-struct.h"
#include "ic-common.h"
API void iotcon_observers_free(iotcon_observers_h observers)
g_list_free(observers);
}
-/* If you want a new list, then you should set observers is NULL. */
+/* If you want to make a new list, then you should set observers is NULL. */
API iotcon_observers_h iotcon_observers_append(iotcon_observers_h observers,
uint8_t obs_id)
{
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include <stdbool.h>
#include <stdlib.h>
#include <errno.h>
#include <glib.h>
-#include "iotcon.h"
+#include "iotcon-struct.h"
#include "ic-common.h"
#include "ic-utils.h"
-#include "ic-struct.h"
#include "ic-options.h"
API iotcon_options_h iotcon_options_new()
return NULL;
}
- options->options = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, free);
+ options->hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, free);
return options;
}
{
RET_IF(NULL == options);
- g_hash_table_unref(options->options);
+ g_hash_table_unref(options->hash);
free(options);
}
}
-/* options id is always situated between 2014 and 3000 */
+/* iotcon_options_h can have up to 2 options.
+ * option id is always situated between 2014 and 3000.
+ * Length of option data is less than and equal to 15. */
API int iotcon_options_insert(iotcon_options_h options, unsigned short id,
const char *data)
{
FN_CALL;
RETV_IF(NULL == options, IOTCON_ERROR_PARAM);
+ RETVM_IF(IOTCON_OPTIONS_MAX <= g_hash_table_size(options->hash),
+ IOTCON_ERROR_MEMORY, "Options already have maximum elements.");
+
RETVM_IF(((id < IOTCON_OPTIONID_MIN) || (IOTCON_OPTIONID_MAX < id)),
IOTCON_ERROR_PARAM, "Invalid id(%d)", id);
+
RETV_IF(NULL == data, IOTCON_ERROR_PARAM);
+ RETVM_IF(IOTCON_OPTION_DATA_LENGTH_MAX < strlen(data), IOTCON_ERROR_PARAM,
+ "The length of option data(%s) is invalid.", data);
- g_hash_table_insert(options->options, GUINT_TO_POINTER(id), ic_utils_strdup(data));
+ g_hash_table_insert(options->hash, GUINT_TO_POINTER(id), ic_utils_strdup(data));
return IOTCON_ERROR_NONE;
}
RETV_IF(NULL == options, IOTCON_ERROR_PARAM);
- ret = g_hash_table_remove(options->options, GUINT_TO_POINTER(id));
+ ret = g_hash_table_remove(options->hash, GUINT_TO_POINTER(id));
if (FALSE == ret) {
ERR("g_hash_table_remove() Fail");
return IOTCON_ERROR_PARAM;
RETV_IF(NULL == options, NULL);
- ret = g_hash_table_lookup(options->options, GUINT_TO_POINTER(id));
+ ret = g_hash_table_lookup(options->hash, GUINT_TO_POINTER(id));
if (NULL == ret)
ERR("g_hash_table_lookup() Fail");
}
-API void iotcon_options_foreach(iotcon_options_h options,
- iotcon_options_foreach_cb cb, void *user_data)
+API void iotcon_options_foreach(iotcon_options_h options, iotcon_options_foreach_cb cb,
+ void *user_data)
{
GHashTableIter iter;
gpointer key, value;
RET_IF(NULL == options);
RET_IF(NULL == cb);
- g_hash_table_iter_init(&iter, options->options);
+ g_hash_table_iter_init(&iter, options->hash);
while (g_hash_table_iter_next(&iter, &key, &value))
cb(GPOINTER_TO_UINT(key), value, user_data);
}
return NULL;
}
- ref->options = g_hash_table_ref(options->options);
+ ref->hash = g_hash_table_ref(options->hash);
return ref;
}
#include "iotcon-struct.h"
+struct ic_options {
+ bool has_parent;
+ GHashTable *hash;
+};
+
void ic_options_free(iotcon_options_h options);
iotcon_options_h ic_options_ref(iotcon_options_h options);
* limitations under the License.
*/
#include <stdlib.h>
+#include <string.h>
#include <errno.h>
#include <glib.h>
-#include "iotcon.h"
+#include "iotcon-struct.h"
#include "ic-common.h"
#include "ic-utils.h"
-#include "ic-struct.h"
+#include "ic-query.h"
API iotcon_query_h iotcon_query_new()
{
- return g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
+ iotcon_query_h query = calloc(1, sizeof(struct ic_query));
+ if (NULL == query) {
+ ERR("calloc() Fail(%d)", errno);
+ return NULL;
+ }
+
+ query->hash = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
+ return query;
}
+
API void iotcon_query_free(iotcon_query_h query)
{
RET_IF(NULL == query);
- g_hash_table_unref(query);
+ g_hash_table_unref(query->hash);
+ free(query);
}
+
+/* The full length of query should be less than and equal to 64. */
API int iotcon_query_insert(iotcon_query_h query, const char *key, const char *value)
{
+ int query_len;
+
RETV_IF(NULL == query, IOTCON_ERROR_PARAM);
RETV_IF(NULL == key, IOTCON_ERROR_PARAM);
RETV_IF(NULL == value, IOTCON_ERROR_PARAM);
- g_hash_table_insert(query, ic_utils_strdup(key), ic_utils_strdup(value));
+ /* first query : ?key=value
+ * Rest of query : &key=value */
+ query_len = strlen(key) + strlen(value) + 2;
+ if (IOTCON_QUERY_LENGTH_MAX < (query->len + query_len)) {
+ ERR("Length of query is invalid.");
+ return IOTCON_ERROR_MEMORY;
+ }
+
+ g_hash_table_insert(query->hash, ic_utils_strdup(key), ic_utils_strdup(value));
+ query->len += query_len;
return IOTCON_ERROR_NONE;
}
+
API int iotcon_query_delete(iotcon_query_h query, const char *key)
{
gboolean ret;
+ int query_len;
+ char *value;
RETV_IF(NULL == query, IOTCON_ERROR_PARAM);
RETV_IF(NULL == key, IOTCON_ERROR_PARAM);
- ret = g_hash_table_remove(query, key);
+ value = g_hash_table_lookup(query->hash, key);
+ if (NULL == value) {
+ ERR("g_hash_table_lookup() Fail");
+ return IOTCON_ERROR_PARAM;
+ }
+
+ query_len = strlen(key) + strlen(value) + 2;
+
+ ret = g_hash_table_remove(query->hash, key);
if (FALSE == ret) {
ERR("g_hash_table_remove() Fail");
return IOTCON_ERROR_PARAM;
}
+ query->len -= query_len;
+
return IOTCON_ERROR_NONE;
}
+
API const char* iotcon_query_lookup(iotcon_query_h query, const char *key)
{
const char *ret = NULL;
RETV_IF(NULL == query, NULL);
RETV_IF(NULL == key, NULL);
- ret = g_hash_table_lookup(query, key);
+ ret = g_hash_table_lookup(query->hash, key);
if (NULL == ret)
ERR("g_hash_table_lookup() Fail");
return ret;
}
-API void iotcon_query_foreach(iotcon_query_h query,
- iotcon_query_foreach_cb cb, void *user_data)
+
+API void iotcon_query_foreach(iotcon_query_h query, iotcon_query_foreach_cb cb,
+ void *user_data)
{
GHashTableIter iter;
gpointer key, value;
RET_IF(NULL == query);
RET_IF(NULL == cb);
- g_hash_table_iter_init(&iter, query);
+ g_hash_table_iter_init(&iter, query->hash);
while (g_hash_table_iter_next(&iter, &key, &value))
cb(key, value, user_data);
}
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __IOT_CONNECTIVITY_MANAGER_INTERNAL_QUERY_H__
+#define __IOT_CONNECTIVITY_MANAGER_INTERNAL_QUERY_H__
+
+#include "iotcon-struct.h"
+
+struct ic_query {
+ int len;
+ GHashTable *hash;
+};
+
+#endif /* __IOT_CONNECTIVITY_MANAGER_INTERNAL_QUERY_H__ */
#include <stdlib.h>
#include <errno.h>
-
#include <json-glib/json-glib.h>
-#include "iotcon.h"
-
+#include "iotcon-struct.h"
+#include "iotcon-constant.h"
+#include "iotcon-representation.h"
#include "ic-common.h"
-#include "ic-struct.h"
#include "ic-repr-obj.h"
#include "ic-repr.h"
#include "ic-repr-value.h"
#ifndef __IOT_CONNECTIVITY_MANAGER_INTERNAL_REPRESENTATION_LIST_H__
#define __IOT_CONNECTIVITY_MANAGER_INTERNAL_REPRESENTATION_LIST_H__
+#include <glib.h>
#include <json-glib/json-glib.h>
#include "iotcon-struct.h"
+struct ic_list_s {
+ int type;
+ GList *list;
+};
+
int ic_list_remove(iotcon_list_h list, iotcon_value_h val);
iotcon_list_h ic_list_insert(iotcon_list_h list, iotcon_value_h value, int pos);
#include <glib.h>
-#include "iotcon.h"
+#include "iotcon-struct.h"
+#include "iotcon-constant.h"
+#include "iotcon-representation.h"
#include "ic-common.h"
-#include "ic-struct.h"
#include "ic-utils.h"
#include "ic-repr-list.h"
#include "ic-repr-value.h"
#include <json-glib/json-glib.h>
+#include "iotcon-struct.h"
+#include "iotcon-constant.h"
+
int ic_obj_del_value(iotcon_repr_h repr, const char *key,
iotcon_repr_types_e value_type);
#include <stdlib.h>
#include <errno.h>
-
#include <json-glib/json-glib.h>
-#include "iotcon.h"
-
+#include "iotcon-struct.h"
+#include "iotcon-representation.h"
#include "ic-common.h"
-#include "ic-struct.h"
#include "ic-utils.h"
#include "ic-repr.h"
#include "ic-repr-list.h"
#ifndef __IOT_CONNECTIVITY_MANAGER_INTERNAL_REPRESENTATION_VALUE_H__
#define __IOT_CONNECTIVITY_MANAGER_INTERNAL_REPRESENTATION_VALUE_H__
+#include <stdbool.h>
#include <json-glib/json-glib.h>
#include "iotcon-struct.h"
+struct ic_value_s {
+ int type;
+};
+
+typedef struct {
+ int type;
+ union {
+ int i;
+ bool b;
+ double d;
+ char *s;
+ } val;
+} ic_basic_s;
+
+typedef struct {
+ int type;
+ struct ic_list_s *list;
+} ic_val_list_s;
+
+typedef struct {
+ int type;
+ struct ic_repr_s *repr;
+} ic_val_repr_s;
+
iotcon_value_h ic_value_new_null();
iotcon_value_h ic_value_new_int(int val);
iotcon_value_h ic_value_new_bool(bool val);
#include <stdlib.h>
#include <errno.h>
#include <limits.h>
-
+#include <glib.h>
#include <json-glib/json-glib.h>
-#include "iotcon.h"
-
+#include "iotcon-struct.h"
+#include "iotcon-representation.h"
#include "ic-common.h"
-#include "ic-struct.h"
#include "ic-utils.h"
#include "ic-repr-list.h"
#include "ic-repr-value.h"
#ifndef __IOT_CONNECTIVITY_MANAGER_INTERNAL_REPRESENTATION_H__
#define __IOT_CONNECTIVITY_MANAGER_INTERNAL_REPRESENTATION_H__
+#include <stdbool.h>
+#include <glib.h>
#include <json-glib/json-glib.h>
-#include "ic-struct.h"
+#include "iotcon-struct.h"
#define IOTCON_KEY_OC "oc"
#define IOTCON_KEY_URI "href"
#define IOTCON_KEY_PROPERTY "prop"
#define IOTCON_KEY_REP "rep"
+struct ic_repr_s {
+ char *uri;
+ GHashTable *hash_table;
+ GList *children;
+ GList *res_types;
+ GList *interfaces;
+};
+
/**
* @ingroup CAPI_IOT_CONNECTIVITY_MODULE
* @brief Generates JSON string from Representation.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include <stdlib.h>
#include <stdint.h>
-#include <errno.h>
-#include <glib.h>
-#include "iotcon.h"
+#include "iotcon-struct.h"
+#include "iotcon-constant.h"
#include "ic-common.h"
-#include "ic-struct.h"
+#include "ic-request.h"
API iotcon_repr_h iotcon_request_get_representation(iotcon_request_h request)
{
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __IOT_CONNECTIVITY_MANAGER_INTERNAL_REQUEST_H__
+#define __IOT_CONNECTIVITY_MANAGER_INTERNAL_REQUEST_H__
+
+#include <stdint.h>
+
+#include "iotcon-struct.h"
+#include "iotcon-constant.h"
+
+typedef void* oc_request_h;
+typedef void* oc_resource_h;
+
+struct ic_observe_info {
+ iotcon_observe_action_e action;
+ uint8_t observer_id;
+};
+
+struct ic_resource_request {
+ char *request_type;
+ char *uri;
+ iotcon_options_h header_options;
+ iotcon_query_h query;
+ int request_handler_flag;
+ struct ic_observe_info observation_info;
+ iotcon_repr_h repr;
+ oc_request_h request_handle;
+ oc_resource_h resource_handle;
+};
+
+#endif /* __IOT_CONNECTIVITY_MANAGER_INTERNAL_REQUEST_H__ */
#include "iotcon.h"
#include "ic-common.h"
#include "ic-utils.h"
-#include "ic-struct.h"
#include "ic-ioty.h"
#include "ic-options.h"
+#include "ic-request.h"
+#include "ic-response.h"
API iotcon_response_h iotcon_response_new(iotcon_request_h request_h)
{
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __IOT_CONNECTIVITY_MANAGER_INTERNAL_RESPONSE_H__
+#define __IOT_CONNECTIVITY_MANAGER_INTERNAL_RESPONSE_H__
+
+#include "iotcon-struct.h"
+#include "iotcon-constant.h"
+#include "ic-request.h"
+
+struct ic_resource_response {
+ char *new_uri;
+ int error_code;
+ iotcon_options_h header_options;
+ iotcon_interface_e iface;
+ iotcon_response_result_e result;
+ iotcon_repr_h repr;
+ oc_request_h request_handle;
+ oc_resource_h resource_handle;
+};
+
+#endif /* __IOT_CONNECTIVITY_MANAGER_INTERNAL_RESPONSE_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_INTERNAL_STRUCT_H__
-#define __IOT_CONNECTIVITY_MANAGER_INTERNAL_STRUCT_H__
-
-#include <stdint.h>
-#include <stdbool.h>
-#include <glib.h>
-
-#include "iotcon.h"
-#include "iotcon-constant.h"
-#include "iotcon-struct.h"
-
-struct ic_value_s {
- int type;
-};
-
-struct ic_list_s {
- int type;
- GList *list;
-};
-
-struct ic_repr_s {
- char *uri;
- GHashTable *hash_table;
- GList *children;
- GList *res_types;
- GList *interfaces;
-};
-
-typedef struct {
- int type;
- union {
- int i;
- bool b;
- double d;
- char *s;
- } val;
-} ic_basic_s;
-
-typedef struct {
- int type;
- struct ic_list_s *list;
-} ic_val_list_s;
-
-typedef struct {
- int type;
- struct ic_repr_s *repr;
-} ic_val_repr_s;
-
-struct ic_options {
- bool has_parent;
- GHashTable *options;
-};
-
-struct ic_observe_info {
- iotcon_observe_action_e action;
- uint8_t observer_id;
-};
-
-typedef void* oc_request_h;
-typedef void* oc_resource_h;
-
-typedef struct ic_resource {
- void *handle;
- iotcon_request_handler_cb request_handler_cb;
- void *user_data;
-} resource_handler_s;
-
-struct ic_remote_resource {
- char *uri;
- char *host;
- bool is_observable;
- bool is_collection;
- iotcon_options_h header_options;
- iotcon_str_list_s *types;
- int ifaces;
- iotcon_observe_h observe_handle;
-};
-
-struct ic_resource_request {
- char *request_type;
- char *uri;
- iotcon_options_h header_options;
- iotcon_query_h query;
- int request_handler_flag;
- struct ic_observe_info observation_info;
- iotcon_repr_h repr;
- oc_request_h request_handle;
- oc_resource_h resource_handle;
-};
-
-struct ic_resource_response {
- char *new_uri;
- int error_code;
- iotcon_options_h header_options;
- iotcon_interface_e iface;
- iotcon_response_result_e result;
- iotcon_repr_h repr;
- oc_request_h request_handle;
- oc_resource_h resource_handle;
-};
-
-struct ic_notify_msg {
- int error_code;
- iotcon_interface_e iface;
- iotcon_repr_h repr;
-};
-
-struct ic_device_info {
- char *device_name;
- char *host_name;
- char *device_uuid;
- char *content_type;
- char *version;
- char *manufacturer_name;
- char *manufacturer_url;
- char *model_number;
- char *date_of_manufacture;
- char *platform_ver;
- char *firmware_ver;
- char *support_url;
-};
-
-#endif //__IOT_CONNECTIVITY_MANAGER_INTERNAL_STRUCT_H__
}
-/* If you want a new list, then you should set str_list is NULL. */
+/* If you want to make a new list, then you should set str_list is NULL. */
API iotcon_str_list_s* iotcon_str_list_append(iotcon_str_list_s *str_list,
const char *string)
{
RETV_IF(NULL == str_list, NULL);
- for (i = 1; i < n; i++) {
+ for (i = 0; i < n; i++) {
str_list = str_list->next;
if (NULL == str_list)
return NULL;
#ifndef __IOT_CONNECTIVITY_MANAGER_INTERNAL_UTILITY_H__
#define __IOT_CONNECTIVITY_MANAGER_INTERNAL_UTILITY_H__
-#include "iotcon-struct.h"
-
#define STR_EQUAL 0
char* ic_utils_strdup(const char *src);
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include <stdlib.h>
+#include <stdbool.h>
#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
#include <errno.h>
#include <glib.h>
#include <glib-object.h>
#include "iotcon.h"
#include "ic-common.h"
#include "ic-utils.h"
-#include "ic-struct.h"
#include "ic-ioty.h"
#include "ic.h"
}
-resource_handler_s* ic_get_resource_handler_data(void *handle)
+ic_resource_s* ic_get_resource_handler_data(void *handle)
{
return g_hash_table_find(ic_request_cb_hash, _find_valid_resource, handle);
}
+/* The length of uri should be less than and equal to 36. */
API iotcon_resource_h iotcon_register_resource(const char *uri,
iotcon_str_list_s *res_types,
int ifaces,
void *user_data)
{
FN_CALL;
+ int i;
iotcon_resource_h resource;
RETV_IF(NULL == uri, NULL);
+ RETVM_IF(IOTCON_URI_LENGTH_MAX < strlen(uri), NULL,
+ "The length of uri(%s) is invalid", uri);
RETV_IF(NULL == res_types, NULL);
RETV_IF(NULL == cb, NULL);
- resource = calloc(1, sizeof(struct ic_resource));
+ for (i = 0; i < iotcon_str_list_length(res_types); i++) {
+ if (IOTCON_RESOURCE_TYPE_LENGTH_MAX
+ < strlen(iotcon_str_list_nth_data(res_types, i))) {
+ ERR("The length of resource_type is invalid");
+ return NULL;
+ }
+ }
+
+ resource = calloc(1, sizeof(struct _resource_s));
if (NULL == resource) {
ERR("calloc Fail(%d)", errno);
return NULL;
return NULL;
}
- resource->request_handler_cb = cb;
+ resource->cb = cb;
resource->user_data = user_data;
g_hash_table_insert(ic_request_cb_hash, resource->handle, resource);
RETV_IF(NULL == resource, IOTCON_ERROR_PARAM);
RETV_IF(NULL == resource_type, IOTCON_ERROR_PARAM);
+ if (IOTCON_RESOURCE_TYPE_LENGTH_MAX < strlen(resource_type)) {
+ ERR("The length of resource_type(%s) is invalid", resource_type);
+ return IOTCON_ERROR_PARAM;
+ }
ret = ic_ioty_bind_type_to_res(resource->handle, resource_type);
if (IOTCON_ERROR_NONE != ret)
}
+/* The length of resource_type should be less than and equal to 61. */
API iotcon_presence_h iotcon_subscribe_presence(const char *host_address,
const char *resource_type, iotcon_presence_cb cb, void *user_data)
{
RETV_IF(NULL == host_address, NULL);
RETV_IF(NULL == cb, NULL);
+ if (resource_type &&(IOTCON_RESOURCE_TYPE_LENGTH_MAX < strlen(resource_type))) {
+ ERR("The length of resource_type(%s) is invalid", resource_type);
+ return NULL;
+ }
+
if (NULL == resource_type)
resource_type = "";
#ifndef __IOT_CONNECTIVITY_MANAGER_INTERNAL_H__
#define __IOT_CONNECTIVITY_MANAGER_INTERNAL_H__
-#include "ic-struct.h"
+#include "iotcon.h"
-resource_handler_s* ic_get_resource_handler_data(void *handle);
+typedef struct _resource_s {
+ void *handle;
+ iotcon_request_handler_cb cb;
+ void *user_data;
+} ic_resource_s;
+
+struct ic_notify_msg {
+ int error_code;
+ iotcon_interface_e iface;
+ iotcon_repr_h repr;
+};
+
+ic_resource_s* ic_get_resource_handler_data(void *handle);
#endif /* __IOT_CONNECTIVITY_MANAGER_INTERNAL_H__ */
#ifndef __IOT_CONNECTIVITY_MANAGER_CONSTANT_H__
#define __IOT_CONNECTIVITY_MANAGER_CONSTANT_H__
+#define IOTCON_ALL_INTERFACES "0.0.0.0"
+#define IOTCON_RANDOM_PORT 0
+#define IOTCON_MULTICAST_ADDRESS "coap://224.0.1.187"
+
/**
* @brief HeaderOption range from 2048 to 3000
* NOTE: HeaderOptionID is an unsigned integer value which MUST be within
#define IOTCON_OPTIONID_MIN 2048
#define IOTCON_OPTIONID_MAX 3000
-#define IOTCON_ALL_INTERFACES "0.0.0.0"
-#define IOTCON_RANDOM_PORT 0
-#define IOTCON_MULTICAST_ADDRESS "coap://224.0.1.187"
+#define IOTCON_OPTIONS_MAX 2
+#define IOTCON_OPTION_DATA_LENGTH_MAX 16
+
+#define IOTCON_URI_LENGTH_MAX 36
+
+#define IOTCON_QUERY_LENGTH_MAX 64
+
+/* IOTCON_QUERY_LENGTH_MAX - LENGTH("rt=") */
+#define IOTCON_RESOURCE_TYPE_LENGTH_MAX (IOTCON_QUERY_LENGTH_MAX - 3)
+
+#define IOTCON_MANUFACTURER_NAME_LENGTH_MAX 15
+#define IOTCON_MANUFACTURER_URL_LENGTH_MAX 32
+
+/* TODO
+#define IOTCON_CONTAINED_RESOURCES_MAX 5
+*/
/**
* @brief Action associated with observation
#define __IOT_CONNECTIVITY_MANAGER_REPRESENTATION_H__
#include <stdbool.h>
+#include <iotcon-constant.h>
+#include <iotcon-struct.h>
iotcon_repr_h iotcon_repr_new();
void iotcon_repr_free(iotcon_repr_h repr);
#define __IOT_CONNECTIVITY_MANAGER_STRUCT_H__
#include <stdint.h>
-
-#include "iotcon-constant.h"
+#include <iotcon-constant.h>
typedef struct ic_value_s* iotcon_value_h;
typedef struct ic_list_s* iotcon_list_h;
typedef struct ic_repr_s* iotcon_repr_h;
-typedef struct ic_resource* iotcon_resource_h;
+typedef struct _resource_s* iotcon_resource_h;
typedef struct ic_notify_msg* iotcon_notimsg_h;
typedef void* iotcon_presence_h;
-typedef void* iotcon_observe_h;
typedef struct _str_list {
char *string;
iotcon_options_foreach_cb cb, void *user_data);
-typedef void* iotcon_query_h;
+typedef struct ic_query* iotcon_query_h;
iotcon_query_h iotcon_query_new();
void iotcon_query_free(iotcon_query_h query);
int iotcon_query_insert(iotcon_query_h query, const char *key, const char *value);
const char* iotcon_client_get_host(iotcon_client_h resource);
iotcon_str_list_s* iotcon_client_get_types(iotcon_client_h resource);
int iotcon_client_get_interfaces(iotcon_client_h resource);
-void iotcon_client_set_options(iotcon_client_h resource,
+int iotcon_client_set_options(iotcon_client_h resource,
iotcon_options_h header_options);
typedef struct ic_resource_request* iotcon_request_h;
%license LICENSE.APLv2
%{_bindir}/crud-test-client
%{_bindir}/crud-test-server
+%{_bindir}/device-test-client
+%{_bindir}/device-test-server
%files devel
%{_libdir}/lib%{name}.so
SET(CRUD_TEST_CLIENT "crud-test-client")
SET(CRUD_TEST_SERVER "crud-test-server")
+SET(CRUD_TEST_CLIENT_SRCS "crud-test-client.c")
+SET(CRUD_TEST_SERVER_SRCS "crud-test-server.c")
-FILE(GLOB CRUD_TEST_CLIENT_SRCS crud-test-client.c)
-FILE(GLOB CRUD_TEST_SERVER_SRCS crud-test-server.c)
+SET(DEVICE_TEST_CLIENT "device-test-client")
+SET(DEVICE_TEST_SERVER "device-test-server")
+SET(DEVICE_TEST_CLIENT_SRCS "device-test-client.c")
+SET(DEVICE_TEST_SERVER_SRCS "device-test-server.c")
pkg_check_modules(test_pkgs REQUIRED dlog glib-2.0)
INCLUDE_DIRECTORIES(${test_pkgs_INCLUDE_DIRS})
ADD_EXECUTABLE(${CRUD_TEST_SERVER} ${CRUD_TEST_SERVER_SRCS})
TARGET_LINK_LIBRARIES(${CRUD_TEST_SERVER} ${test_pkgs_LIBRARIES} ${CLIENT})
-INSTALL(TARGETS ${CRUD_TEST_SERVER} DESTINATION ${BIN_INSTALL_DIR})
\ No newline at end of file
+INSTALL(TARGETS ${CRUD_TEST_SERVER} DESTINATION ${BIN_INSTALL_DIR})
+
+ADD_EXECUTABLE(${DEVICE_TEST_CLIENT} ${DEVICE_TEST_CLIENT_SRCS})
+TARGET_LINK_LIBRARIES(${DEVICE_TEST_CLIENT} ${test_pkgs_LIBRARIES} ${CLIENT})
+INSTALL(TARGETS ${DEVICE_TEST_CLIENT} DESTINATION ${BIN_INSTALL_DIR})
+
+ADD_EXECUTABLE(${DEVICE_TEST_SERVER} ${DEVICE_TEST_SERVER_SRCS})
+TARGET_LINK_LIBRARIES(${DEVICE_TEST_SERVER} ${test_pkgs_LIBRARIES} ${CLIENT})
+INSTALL(TARGETS ${DEVICE_TEST_SERVER} DESTINATION ${BIN_INSTALL_DIR})
+
+
DBG("rep : \n%s", iotcon_repr_generate_json(repr));
}
+static void _on_observe(iotcon_options_h header_options, iotcon_repr_h recv_repr,
+ int response_result, int sequence_number, void *user_data)
+{
+ INFO("_on_observe");
+}
+
static void _on_delete(iotcon_options_h header_options, int response_result,
void *user_data)
{
INFO("DELETE request was successful");
/* delete callback operations */
+
+ iotcon_observer_start(door_resource, IOTCON_OBSERVE_ALL, NULL, _on_observe, NULL);
}
static void _on_post(iotcon_options_h header_options, iotcon_repr_h recv_repr,
iotcon_query_free(query_params);
}
-static void _on_observe(iotcon_options_h header_options, iotcon_repr_h recv_repr,
- int response_result, int sequence_number, void *user_data)
-{
- INFO("_on_observe");
-}
-
static void _get_res_type_fn(const char *string, void *user_data)
{
char *resource_uri = user_data;
door_resource = iotcon_client_clone(resource);
iotcon_query_h query = iotcon_query_new();
+ iotcon_query_insert(query, "key", "value");
/* send GET Request */
iotcon_get(resource, query, _on_get, NULL);
iotcon_query_free(query);
-
- iotcon_observer_start(door_resource, IOTCON_OBSERVE_ALL, NULL, _on_observe,
- NULL);
}
}
}
static door_resource_s my_door;
static bool resource_created = false;
+
+iotcon_resource_h door_handle;
iotcon_resource_h new_door_handle;
iotcon_observers_h observers = NULL;
iotcon_str_list_s resource_types = {my_door.type, NULL};
/* register door resource */
- iotcon_resource_h door_handle = iotcon_register_resource(uri, &resource_types,
- interfaces, properties, _request_handler, door_handle);
- if (NULL == door_handle) {
+ iotcon_resource_h handle = iotcon_register_resource(uri, &resource_types,
+ interfaces, properties, _request_handler, NULL);
+ if (NULL == handle) {
ERR("iotcon_register_resource() Fail");
return NULL;
}
- return door_handle;
+ return handle;
}
static void _send_response(iotcon_response_h response, iotcon_repr_h repr,
}
+static gboolean _notifier(gpointer user_data)
+{
+ static int i = 0;
+ if ((5 == i++) && !(observers))
+ return FALSE;
+
+ INFO("NOTIFY!");
+ iotcon_repr_h repr = iotcon_repr_new();
+ iotcon_notimsg_h msg = iotcon_notimsg_new(repr, IOTCON_INTERFACE_DEFAULT);
+ iotcon_notify(user_data, msg, observers);
+
+ return TRUE;
+}
+
static void _request_handler_delete(iotcon_response_h response)
{
iotcon_repr_h resp_repr = NULL;
result = IOTCON_RESPONSE_RESULT_RESOURCE_DELETED;
_send_response(response, resp_repr, result);
+
+ /* add observe */
+ g_timeout_add_seconds(5, _notifier, door_handle);
+}
+
+static void query_cb(const char *key, const char *value, void *user_data)
+{
+ INFO("key : %s", key);
+ INFO("value : %s", value);
}
static void _request_handler(iotcon_request_h request, void *user_data)
{
const char *request_type = NULL;
int request_flag = IOTCON_INIT_FLAG;
+ iotcon_query_h query = NULL;
iotcon_response_h response = NULL;
FN_CALL;
RET_IF(NULL == request);
+ query = iotcon_request_get_query(request);
+ if (query)
+ iotcon_query_foreach(query, query_cb, NULL);
+
request_type = iotcon_request_get_request_type(request);
if (NULL == request_type) {
ERR("request_type is NULL");
}
}
-static gboolean _timeout(gpointer user_data)
+static gboolean _presence_timer(gpointer user_data)
{
static int i = 0;
i++;
return TRUE;
}
-static gboolean _observe_timeout(gpointer user_data)
-{
- INFO("NOTIFY!");
- iotcon_repr_h repr = iotcon_repr_new();
- iotcon_notimsg_h msg = iotcon_notimsg_new(repr, IOTCON_INTERFACE_DEFAULT);
- iotcon_notify(user_data, msg, observers);
-
- return TRUE;
-}
-
int main(int argc, char **argv)
{
FN_CALL;
GMainLoop *loop;
iotcon_interface_e door_interfaces = IOTCON_INTERFACE_DEFAULT;
iotcon_resource_property_e resource_properties = IOTCON_DISCOVERABLE;
- iotcon_resource_h door_handle = NULL;
iotcon_error_e iotcon_error = IOTCON_ERROR_NONE;
loop = g_main_loop_new(NULL, FALSE);
resource_properties |= IOTCON_OBSERVABLE;
/* add presence */
- g_timeout_add_seconds(10, _timeout, NULL);
+ g_timeout_add_seconds(10, _presence_timer, NULL);
/* create new door resource */
door_handle = _create_door_resource("/a/door", door_interfaces, resource_properties);
return -1;
}
- /* add observe */
- g_timeout_add_seconds(10, _observe_timeout, door_handle);
-
_check_door_state();
g_main_loop_run(loop);
--- /dev/null
+#include <glib.h>
+#include <iotcon.h>
+#include "test-log.h"
+
+static void _get_device_info(iotcon_device_info_h info, void *user_data)
+{
+ INFO("device_name : %s", iotcon_device_info_get_device_name(info));
+ INFO("host_name : %s", iotcon_device_info_get_host_name(info));
+ INFO("device_uuid : %s", iotcon_device_info_get_device_uuid(info));
+ INFO("content_type : %s", iotcon_device_info_get_content_type(info));
+ INFO("version : %s", iotcon_device_info_get_version(info));
+ INFO("manufacturer_name : %s", iotcon_device_info_get_manufacturer_name(info));
+ INFO("manufacturer_url : %s", iotcon_device_info_get_manufacturer_url(info));
+ INFO("model_number : %s", iotcon_device_info_get_model_number(info));
+ INFO("date_of_manufacture : %s", iotcon_device_info_get_date_of_manufacture(info));
+ INFO("platform_version : %s", iotcon_device_info_get_platform_version(info));
+ INFO("firmware_version : %s", iotcon_device_info_get_firmware_version(info));
+ INFO("support_url : %s", iotcon_device_info_get_support_url(info));
+}
+
+int main()
+{
+ GMainLoop *loop;
+
+ loop = g_main_loop_new(NULL, FALSE);
+
+ iotcon_initialize(IOTCON_ALL_INTERFACES, IOTCON_RANDOM_PORT);
+
+ iotcon_get_device_info(IOTCON_MULTICAST_ADDRESS, _get_device_info, NULL);
+
+ g_main_loop_run(loop);
+
+ g_main_loop_unref(loop);
+
+ return 0;
+}
--- /dev/null
+#include <glib.h>
+#include <iotcon.h>
+#include "test-log.h"
+
+int main()
+{
+ int ret;
+ GMainLoop *loop;
+
+ char *device_name = "device_name";
+ char *host_name = "host_name";
+ char *device_uuid = "device_uuid";
+ char *content_type = "content_type";
+ char *version = "version";
+ char *manufacturer_name = "manuf_name";
+ char *manufacturer_url = "manuf_url";
+ char *model_number = "model_number";
+ char *date_of_manufacture = "date_of_manufacture";
+ char *platform_version = "platform_version";
+ char *firmware_version = "firmware_version";
+ char *support_url = "support_url";
+
+ loop = g_main_loop_new(NULL, FALSE);
+
+ iotcon_initialize(IOTCON_ALL_INTERFACES, IOTCON_RANDOM_PORT);
+
+ ret = iotcon_register_device_info(device_name,
+ host_name,
+ device_uuid,
+ content_type,
+ version,
+ manufacturer_name,
+ manufacturer_url,
+ model_number,
+ date_of_manufacture,
+ platform_version,
+ firmware_version,
+ support_url);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_register_device_info() Fail(%d)", ret);
+ return -1;
+ }
+
+ g_main_loop_run(loop);
+
+ g_main_loop_unref(loop);
+
+ return 0;
+}
+
+
+
+