(1) Remove internal struct file
authoryoungman <yman.jung@samsung.com>
Thu, 28 May 2015 08:59:22 +0000 (17:59 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Mon, 8 Jun 2015 10:40:45 +0000 (19:40 +0900)
(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>
39 files changed:
lib/ic-client.c
lib/ic-client.h [new file with mode: 0755]
lib/ic-common.h
lib/ic-device.c
lib/ic-device.h [new file with mode: 0755]
lib/ic-ioty-repr.cpp
lib/ic-ioty.cpp
lib/ic-ioty.h
lib/ic-observation.c
lib/ic-options.c [changed mode: 0644->0755]
lib/ic-options.h [changed mode: 0644->0755]
lib/ic-query.c [changed mode: 0644->0755]
lib/ic-query.h [new file with mode: 0755]
lib/ic-repr-list.c
lib/ic-repr-list.h [changed mode: 0644->0755]
lib/ic-repr-obj.c
lib/ic-repr-obj.h
lib/ic-repr-value.c
lib/ic-repr-value.h [changed mode: 0644->0755]
lib/ic-repr.c
lib/ic-repr.h [changed mode: 0644->0755]
lib/ic-request.c
lib/ic-request.h [new file with mode: 0755]
lib/ic-response.c
lib/ic-response.h [new file with mode: 0755]
lib/ic-struct.h [deleted file]
lib/ic-utils.c
lib/ic-utils.h
lib/ic.c
lib/ic.h [changed mode: 0644->0755]
lib/include/iotcon-constant.h [changed mode: 0644->0755]
lib/include/iotcon-representation.h
lib/include/iotcon-struct.h
packaging/iotcon.spec
test/CMakeLists.txt
test/crud-test-client.c
test/crud-test-server.c
test/device-test-client.c [new file with mode: 0644]
test/device-test-server.c [new file with mode: 0644]

index 2757f17..eb6c19f 100755 (executable)
  * 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)
@@ -34,6 +37,10 @@ API int iotcon_find_resource(const char *host_addr, const char *resource_type,
 
        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)
@@ -43,7 +50,7 @@ API int iotcon_find_resource(const char *host_addr, const char *resource_type,
 }
 
 
-/* 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,
@@ -51,12 +58,21 @@ API iotcon_client_h iotcon_client_new(const char *host,
                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);
@@ -138,15 +154,17 @@ API int iotcon_client_get_interfaces(iotcon_client_h resource)
 
 
 /* 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;
 }
 
 
diff --git a/lib/ic-client.h b/lib/ic-client.h
new file mode 100755 (executable)
index 0000000..43dffad
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * 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__ */
index 81a77f8..9b71155 100644 (file)
@@ -16,6 +16,7 @@
 #ifndef __IOT_CONNECTIVITY_MANAGER_INTERNAL_COMMON_H__
 #define __IOT_CONNECTIVITY_MANAGER_INTERNAL_COMMON_H__
 
+#include "iotcon-errors.h"
 #include "ic-log.h"
 
 #ifdef API
index aeb6ca3..d60b7c3 100755 (executable)
  * 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,
@@ -39,6 +42,18 @@ API int iotcon_register_device_info(
        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;
diff --git a/lib/ic-device.h b/lib/ic-device.h
new file mode 100755 (executable)
index 0000000..36e9be9
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * 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__ */
index 571c06e..2331ebd 100644 (file)
 #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;
index c8f31f5..ccbe305 100755 (executable)
@@ -22,11 +22,14 @@ extern "C" {
 #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"
@@ -439,7 +442,7 @@ static OCEntityHandlerResult _ic_ioty_request_handler(
        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());
@@ -514,8 +517,8 @@ static OCEntityHandlerResult _ic_ioty_request_handler(
        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");
@@ -548,7 +551,7 @@ extern "C" OCResourceHandle ic_ioty_register_res(const char *uri,
 
        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;
@@ -978,10 +981,8 @@ extern "C" int ic_ioty_get(iotcon_client_h resource, iotcon_query_h query,
        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);
 
@@ -1008,10 +1009,8 @@ extern "C" int ic_ioty_put(iotcon_client_h resource, iotcon_repr_h repr,
        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);
 
@@ -1040,10 +1039,8 @@ extern "C" int ic_ioty_post(iotcon_client_h resource, iotcon_repr_h 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);
 
@@ -1097,10 +1094,8 @@ extern "C" int ic_ioty_observe(iotcon_client_h resource,
        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;
index 26094e9..a64d24e 100644 (file)
@@ -19,8 +19,8 @@
 #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);
 
index b06e432..a9aec15 100644 (file)
  * 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)
@@ -28,7 +28,7 @@ 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)
 {
old mode 100644 (file)
new mode 100755 (executable)
index ae99844..5dde44c
  * 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()
@@ -31,7 +31,7 @@ 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;
 }
 
@@ -40,7 +40,7 @@ void ic_options_free(iotcon_options_h options)
 {
        RET_IF(NULL == options);
 
-       g_hash_table_unref(options->options);
+       g_hash_table_unref(options->hash);
        free(options);
 }
 
@@ -54,18 +54,26 @@ API void iotcon_options_free(iotcon_options_h 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;
 }
@@ -77,7 +85,7 @@ API int iotcon_options_delete(iotcon_options_h options, unsigned short id)
 
        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;
@@ -92,7 +100,7 @@ API const char* iotcon_options_lookup(iotcon_options_h options, unsigned short i
 
        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");
 
@@ -100,8 +108,8 @@ API const char* iotcon_options_lookup(iotcon_options_h options, unsigned short i
 }
 
 
-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;
@@ -109,7 +117,7 @@ API void iotcon_options_foreach(iotcon_options_h options,
        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);
 }
@@ -127,7 +135,7 @@ iotcon_options_h ic_options_ref(iotcon_options_h options)
                return NULL;
        }
 
-       ref->options = g_hash_table_ref(options->options);
+       ref->hash = g_hash_table_ref(options->hash);
 
        return ref;
 }
old mode 100644 (file)
new mode 100755 (executable)
index ba52be2..caa44e2
 
 #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);
 
old mode 100644 (file)
new mode 100755 (executable)
index e328e58..a5d2da4
  * 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;
@@ -67,15 +104,16 @@ API const char* iotcon_query_lookup(iotcon_query_h query, const char *key)
        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;
@@ -83,7 +121,7 @@ API void iotcon_query_foreach(iotcon_query_h query,
        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);
 }
diff --git a/lib/ic-query.h b/lib/ic-query.h
new file mode 100755 (executable)
index 0000000..b8325fb
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * 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__ */
index 7e0740c..3c08db5 100755 (executable)
 
 #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"
old mode 100644 (file)
new mode 100755 (executable)
index 54ac17c..26bc6d4
 #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);
 
index c231cff..7ba1d0b 100644 (file)
 
 #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"
index 24f665a..636f26d 100644 (file)
@@ -18,6 +18,9 @@
 
 #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);
 
index 880392d..32e6072 100644 (file)
 
 #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"
old mode 100644 (file)
new mode 100755 (executable)
index a919366..16cabe6
 #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);
index 6a0dc25..2dc16c4 100644 (file)
 #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"
old mode 100644 (file)
new mode 100755 (executable)
index 2a39462..33a87d1
 #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.
index e6ea5fc..76757df 100755 (executable)
  * 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)
 {
diff --git a/lib/ic-request.h b/lib/ic-request.h
new file mode 100755 (executable)
index 0000000..4b4bb29
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * 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__ */
index efea995..4e49e5b 100755 (executable)
 #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)
 {
diff --git a/lib/ic-response.h b/lib/ic-response.h
new file mode 100755 (executable)
index 0000000..3bbf70b
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * 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__ */
diff --git a/lib/ic-struct.h b/lib/ic-struct.h
deleted file mode 100755 (executable)
index 6adfe3d..0000000
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * 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__
index 30c603a..a85ff92 100755 (executable)
@@ -64,7 +64,7 @@ API void iotcon_str_list_free(iotcon_str_list_s *str_list)
 }
 
 
-/* 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)
 {
@@ -170,7 +170,7 @@ API const char* iotcon_str_list_nth_data(iotcon_str_list_s *str_list, unsigned i
 
        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;
index 5573298..4dc5e5a 100644 (file)
@@ -16,8 +16,6 @@
 #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);
index 0b68b47..182a1f0 100755 (executable)
--- a/lib/ic.c
+++ b/lib/ic.c
  * 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>
@@ -22,7 +24,6 @@
 #include "iotcon.h"
 #include "ic-common.h"
 #include "ic-utils.h"
-#include "ic-struct.h"
 #include "ic-ioty.h"
 #include "ic.h"
 
@@ -84,12 +85,13 @@ static gboolean _find_valid_resource(gpointer key, gpointer value, gpointer user
 }
 
 
-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,
@@ -98,13 +100,24 @@ API iotcon_resource_h iotcon_register_resource(const char *uri,
                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;
@@ -117,7 +130,7 @@ API iotcon_resource_h iotcon_register_resource(const char *uri,
                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);
@@ -158,6 +171,10 @@ API int iotcon_bind_type(iotcon_resource_h resource, const char *resource_type)
 
        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)
@@ -209,6 +226,7 @@ API int iotcon_stop_presence()
 }
 
 
+/* 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)
 {
@@ -216,6 +234,11 @@ API iotcon_presence_h iotcon_subscribe_presence(const char *host_address,
 
        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 = "";
 
old mode 100644 (file)
new mode 100755 (executable)
index f570313..b58bcbf
--- a/lib/ic.h
+++ b/lib/ic.h
 #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__ */
old mode 100644 (file)
new mode 100755 (executable)
index 491d518..5dbe37d
 #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
index 181225b..8c42ac4 100755 (executable)
@@ -17,6 +17,8 @@
 #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);
index ab2dc06..06f3f5e 100755 (executable)
 #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;
@@ -49,7 +47,7 @@ void iotcon_options_foreach(iotcon_options_h options,
                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);
@@ -71,7 +69,7 @@ const char* iotcon_client_get_uri(iotcon_client_h resource);
 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;
index c537dcd..28df3f5 100644 (file)
@@ -48,6 +48,8 @@ MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
 %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
index d9e0adb..0971782 100644 (file)
@@ -3,9 +3,13 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/lib/include)
 
 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})
@@ -17,4 +21,14 @@ INSTALL(TARGETS ${CRUD_TEST_CLIENT} DESTINATION ${BIN_INSTALL_DIR})
 
 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})
+
+
index 4428509..639ae24 100755 (executable)
@@ -47,6 +47,12 @@ void _print_repr_info(iotcon_repr_h repr)
                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)
 {
@@ -56,6 +62,8 @@ static void _on_delete(iotcon_options_h header_options, int response_result,
        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,
@@ -127,12 +135,6 @@ static void _on_get(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;
@@ -192,13 +194,11 @@ static void _found_resource(iotcon_client_h resource, void *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);
                }
        }
 }
index 4eb7c32..cb99c8b 100644 (file)
@@ -31,6 +31,8 @@ typedef struct _door_resource_s {
 
 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;
@@ -69,14 +71,14 @@ static iotcon_resource_h _create_door_resource(char *uri, iotcon_interface_e int
        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,
@@ -143,6 +145,20 @@ static void _request_handler_post(iotcon_response_h response)
 
 }
 
+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;
@@ -154,17 +170,31 @@ static void _request_handler_delete(iotcon_response_h response)
        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");
@@ -200,7 +230,7 @@ static void _request_handler(iotcon_request_h request, void *user_data)
        }
 }
 
-static gboolean _timeout(gpointer user_data)
+static gboolean _presence_timer(gpointer user_data)
 {
        static int i = 0;
        i++;
@@ -215,23 +245,12 @@ static gboolean _timeout(gpointer user_data)
        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);
@@ -251,7 +270,7 @@ int main(int argc, char **argv)
        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);
@@ -260,9 +279,6 @@ int main(int argc, char **argv)
                return -1;
        }
 
-       /* add observe */
-       g_timeout_add_seconds(10, _observe_timeout, door_handle);
-
        _check_door_state();
 
        g_main_loop_run(loop);
diff --git a/test/device-test-client.c b/test/device-test-client.c
new file mode 100644 (file)
index 0000000..8e0e756
--- /dev/null
@@ -0,0 +1,36 @@
+#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;
+}
diff --git a/test/device-test-server.c b/test/device-test-server.c
new file mode 100644 (file)
index 0000000..ba62a70
--- /dev/null
@@ -0,0 +1,53 @@
+#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;
+}
+
+
+
+