free(resource->uri);
free(resource->host);
- ic_options_free(resource->header_options);
+
+ /* null COULD be allowed */
+ if (resource->header_options)
+ ic_options_free(resource->header_options);
iotcon_resource_types_free(resource->types);
free(resource);
}
resource->header_options = ic_options_ref(header_options);
else
resource->header_options = header_options;
+ if (NULL == resource->header_options) {
+ ERR("header_options is NULL");
+ return IOTCON_ERROR_NO_DATA;
+ }
+
resource->header_options->has_parent = true;
return IOTCON_ERROR_NONE;
iotcon_repr_h repr_child = _ic_ioty_repr_create_child(ocChild);
if (NULL == repr_child) {
ERR("_ic_ioty_repr_create_child() Fail");
+ /* free parent because adding child is failed.
+ * this func also will free children */
iotcon_repr_free(repr_parent);
return NULL;
}
return repr_parent;
}
-OCRepresentation ic_ioty_repr_parse(iotcon_repr_h repr)
+int ic_ioty_repr_parse(iotcon_repr_h repr, OCRepresentation &ocRep)
{
FN_CALL;
- OCRepresentation ocRep;
+
+ int ret = IOTCON_ERROR_NONE;
MessageContainer info;
/* TODO: It's better that iotcon_repr_h is changed to OCRepresentation at once. */
}
else {
ERR("Invalid parameter(%s)", repr_json);
+ ret = IOTCON_ERROR_INVALID_PARAMETER;
}
} catch (exception &e) {
ERR("setJSONRepresentation() Fail(%s)", e.what());
+ ret = IOTCON_ERROR_INVALID_PARAMETER;
}
free(repr_json);
- return ocRep;
+ return ret;
}
void ic_ioty_repr_found_device_cb(const OC::OCRepresentation& ocRep);
iotcon_repr_h ic_ioty_repr_generate_repr(const OC::OCRepresentation& ocRep);
-OC::OCRepresentation ic_ioty_repr_parse(iotcon_repr_h repr);
+int ic_ioty_repr_parse(iotcon_repr_h repr, OC::OCRepresentation &ocRep);
#endif /* __IOT_CONNECTIVITY_MANAGER_INTERNAL_IOTIVITY_REPRESENTATION_H__ */
void foundResource(shared_ptr<OCResource> resource)
{
struct ic_remote_resource resource_s = {0};
-
- resource_s.uri = ic_utils_strdup(resource->uri().c_str());
- resource_s.host = ic_utils_strdup(resource->host().c_str());
- resource_s.is_observable = resource->isObservable();
resource_s.types = NULL;
vector<string> resource_types = resource->getResourceTypes();
if (0 < resource_types.size()) {
resource_s.types = iotcon_resource_types_new();
+ if (NULL == resource_s.types) {
+ ERR("iotcon_resource_types_new() Fail");
+ return;
+ }
+
for (string &resource_type : resource_types)
iotcon_resource_types_insert(resource_s.types, resource_type.c_str());
}
+ resource_s.uri = ic_utils_strdup(resource->uri().c_str());
+ resource_s.host = ic_utils_strdup(resource->host().c_str());
+ resource_s.is_observable = resource->isObservable();
+
vector<string> resource_interfaces = resource->getResourceInterfaces();
for (string &resource_interface : resource_interfaces) {
if (IC_STR_EQUAL == resource_interface.compare(DEFAULT_INTERFACE))
request_s.repr = ic_ioty_repr_generate_repr(ocRep);
if (NULL == request_s.repr) {
ERR("request_s.repr is NULL");
+ if (request_s.header_options)
+ iotcon_options_free(request_s.header_options);
+ if (request_s.query)
+ iotcon_query_free(request_s.query);
return OC_EH_ERROR;
}
}
if (RequestFlag & request->getRequestHandlerFlag()) {
- request_type = request->getRequestType().c_str();
+ request_type = ic_utils_strdup(request->getRequestType().c_str());
if (NULL == request_type) {
ERR("request_type is NULL");
if (request_s.repr)
int ret;
OCStackResult ocRet;
ObservationIds obsIds;
+ OCRepresentation ocRep;
string iface;
GList *node = g_list_first((GList*)observers);
shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
resourceResponse->setErrorCode(msg->error_code);
- OCRepresentation ocRep = ic_ioty_repr_parse(msg->repr);
+ ret = ic_ioty_repr_parse(msg->repr, ocRep);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("ic_ioty_repr_parse() Fail(%d)", ret);
+ return ret;
+ }
if (IOTCON_INTERFACE_NONE != msg->iface) {
ret = _ic_ioty_convert_interface_flag(msg->iface, iface);
string iface;
int ret;
OCStackResult ocRet;
+ OCRepresentation ocRep;
- OCRepresentation ocRep = ic_ioty_repr_parse(resp->repr);
+ ret = ic_ioty_repr_parse(resp->repr, ocRep);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("ic_ioty_repr_parse() Fail(%d)", ret);
+ return ret;
+ }
auto pResponse = make_shared<OCResourceResponse>();
if (pResponse) {
iotcon_query_h query, iotcon_on_cru_cb cb, void *user_data)
{
FN_CALL;
- OCStackResult ret;
+ int ret;
+ OCStackResult result;
OCResource::Ptr ocResource;
OCRepresentation ocRep;
QueryParamsMap queryParams;
if (query)
iotcon_query_foreach(query, _ic_ioty_accumulate_query_map, (void*)&queryParams);
- ocRep = ic_ioty_repr_parse(repr);
+ ret = ic_ioty_repr_parse(repr, ocRep);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("ic_ioty_repr_parse() Fail(%d)", ret);
+ return ret;
+ }
ocResource = _ic_ioty_create_oc_resource(resource);
PutCallback putCallback = bind(&icIotivityHandler::putObject::onPut, object,
placeholders::_1, placeholders::_2, placeholders::_3);
- ret = ocResource->put(ocRep, queryParams, putCallback);
- if (OC_STACK_OK != ret) {
- ERR("put() Fail(%d)", ret);
+ result = ocResource->put(ocRep, queryParams, putCallback);
+ if (OC_STACK_OK != result) {
+ ERR("put() Fail(%d)", result);
return IOTCON_ERROR_IOTIVITY;
}
iotcon_query_h query, iotcon_on_cru_cb cb, void *user_data)
{
FN_CALL;
- OCStackResult ret;
+ int ret;
+ OCStackResult ocRet;
QueryParamsMap queryParams;
OCRepresentation ocRep;
OCResource::Ptr ocResource;
if (query)
iotcon_query_foreach(query, _ic_ioty_accumulate_query_map, (void*)&queryParams);
- ocRep = ic_ioty_repr_parse(repr);
+ ret = ic_ioty_repr_parse(repr, ocRep);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("ic_ioty_repr_parse() Fail(%d)", ret);
+ return ret;
+ }
ocResource = _ic_ioty_create_oc_resource(resource);
PostCallback postCallback = bind(&icIotivityHandler::postObject::onPost, object,
placeholders::_1, placeholders::_2, placeholders::_3);
- ret = ocResource->post(ocRep, queryParams, postCallback);
- if (OC_STACK_OK != ret) {
- ERR("post() Fail(%d)", ret);
+ ocRet = ocResource->post(ocRep, queryParams, postCallback);
+ if (OC_STACK_OK != ocRet) {
+ ERR("post() Fail(%d)", ocRet);
return IOTCON_ERROR_IOTIVITY;
}
int count = json_array_get_length(parray);
iotcon_list_h list = _ic_list_new(IOTCON_TYPE_NONE);
- /* DBG("array count(%d)", count); */
+ if (NULL == list) {
+ ERR("_ic_list_new() Fail");
+ return NULL;
+ }
for (i = 0; i < count; i++) {
JsonNode *child_node = json_array_get_element(parray, i);
count = g_list_length(list->list);
for (i = 0; i < count; i++) {
value = _ic_list_get_nth_value(list, i);
+ if (NULL == value) {
+ ERR("_ic_list_get_nth_value() Fail");
+ return IOTCON_ERROR_INVALID_PARAMETER;
+ }
if (list->type != value->type) {
ERR("Type Mismatching(list:%d, value:%d)", list->type, value->type);
return IOTCON_ERROR_INVALID_TYPE;
RETV_IF(NULL == obj, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == key_list, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(index < 0, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == ret_repr, IOTCON_ERROR_INVALID_PARAMETER);
key = g_list_nth_data(key_list, index);
if (0 < rt_count) {
res_types = iotcon_resource_types_new();
+ if (NULL == res_types) {
+ ERR("iotcon_resource_types_new() Fail");
+ iotcon_repr_free(repr);
+ g_object_unref(parser);
+ return NULL;
+ }
+
for (rt_index = 0; rt_index < rt_count; rt_index++) {
rtype_str = json_array_get_string_element(rt_array, rt_index);
iotcon_resource_types_insert(res_types, rtype_str);
/* (GDestroyNotify) : iotcon_repr_h is proper type than gpointer */
g_list_free_full(repr->children, (GDestroyNotify)iotcon_repr_free);
- /* repr->res_types COULD be not null */
+ /* null COULD be allowed */
if (repr->res_types)
iotcon_resource_types_free(repr->res_types);
g_hash_table_destroy(repr->hash_table);
{
FN_CALL;
int type, ret;
+ char *dup_key;
iotcon_value_h value, copied_val;
iotcon_list_h child_list, copied_list;
iotcon_repr_h child_repr, copied_repr;
ERR("ic_value_clone() Fail");
return;
}
- ic_obj_set_value(dest_repr, ic_utils_strdup(key), copied_val);
+
+ dup_key = ic_utils_strdup(key);
+ if (NULL == dup_key) {
+ ERR("dupic_utils_strdup() Fail");
+ return;
+ }
+
+ ic_obj_set_value(dest_repr, dup_key, copied_val);
break;
case IOTCON_TYPE_LIST:
ret = ic_value_get_list(src_val, &child_list);
{
GList *ret = NULL;
+ RETV_IF(NULL == types, false);
+ RETV_IF(NULL == type, false);
+
ret = g_list_find_custom(types->type_list, type, _ic_resource_types_strcmp);
if (NULL == ret)
return false;
}
-/* If you want to make a new list, then you should set res_types is NULL.
- * The length of resource type should be less than or equal to 61.
+/* The length of resource type should be less than or equal to 61.
* Duplicate strings are not allowed. */
API int iotcon_resource_types_insert(iotcon_resource_types_h types, const char *type)
{
char *resource_type;
+ RETV_IF(NULL == types, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == type, IOTCON_ERROR_INVALID_PARAMETER);
RETVM_IF(1 < types->ref_count, IOTCON_ERROR_INVALID_PARAMETER,
"Don't modify it. It is already set.");
resp->header_options = ic_options_ref(options);
else
resp->header_options = options;
+ if (NULL == resp->header_options) {
+ ERR("header_options is NULL");
+ return IOTCON_ERROR_NO_DATA;
+ }
+
resp->header_options->has_parent = true;
break;
case IOTCON_RESPONSE_NONE:
new_door_resource = iotcon_client_new(host, created_uri, true, types, ifaces);
iotcon_delete(new_door_resource, _on_delete, NULL);
+
+ iotcon_client_free(new_door_resource);
}
static void _on_put(iotcon_options_h header_options, iotcon_repr_h recv_repr,
iotcon_resource_property_e properties)
{
iotcon_resource_types_h resource_types = iotcon_resource_types_new();
+ if (NULL == resource_types) {
+ ERR("iotcon_resource_types_new() Fail");
+ return NULL;
+ }
+
int ret = iotcon_resource_types_insert(resource_types, my_door.type);
if (IOTCON_ERROR_NONE != ret) {
iotcon_resource_types_free(resource_types);
iotcon_repr_set_bool(resp_repr, "opened", my_door.state);
_send_response(response, resp_repr, IOTCON_RESPONSE_RESULT_OK);
+
+ iotcon_repr_free(resp_repr);
}
static void _request_handler_put(iotcon_request_h request, iotcon_response_h response)
iotcon_repr_set_bool(resp_repr, "opened", my_door.state);
_send_response(response, resp_repr, IOTCON_RESPONSE_RESULT_OK);
+
+ iotcon_repr_free(resp_repr);
}
static void _request_handler_post(iotcon_response_h response)
iotcon_repr_set_str(resp_repr, "createduri", "/a/door1");
_send_response(response, resp_repr, IOTCON_RESPONSE_RESULT_RESOURCE_CREATED);
+
+ iotcon_repr_free(resp_repr);
}
static gboolean _notifier(gpointer user_data)
iotcon_notimsg_h msg = iotcon_notimsg_new(repr, IOTCON_INTERFACE_DEFAULT);
iotcon_notify(user_data, msg, observers);
+ iotcon_repr_free(repr);
+
return TRUE;
}
/* add observe */
g_timeout_add_seconds(5, _notifier, door_handle);
+
+ iotcon_repr_free(resp_repr);
}
static int _query_cb(const char *key, const char *value, void *user_data)
}
iotcon_repr_get_uri(child_repr, &uri);
- if (uri)
- DBG("uri : %s", uri);
+ if (NULL == uri)
+ continue;
+
+ DBG("uri : %s", uri);
if (!strcmp("/a/light", uri)) {
key_count = iotcon_repr_get_keys_count(child_repr);
iotcon_repr_get_int(child_repr, "brightness", &brightness);
DBG("brightness : %d", brightness);
}
- }
- else if (!strcmp("/a/switch", uri)) {
+ } else if (!strcmp("/a/switch", uri)) {
key_count = iotcon_repr_get_keys_count(child_repr);
if (key_count) {
bool bswitch;
iotcon_list_insert_int(temperature_list, 25, -1);
iotcon_list_insert_int(temperature_list, 26, -1);
iotcon_repr_set_list(room_repr, "today_temp", temperature_list);
+ iotcon_list_free(temperature_list);
/* create a light Representation */
light_repr = iotcon_repr_new();
ret = iotcon_request_get_query(request, &query);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_request_get_query() Fail(%d)", ret);
+ iotcon_repr_free(room_repr);
return;
}
if (query)
/* register room resource */
light_rtypes = iotcon_resource_types_new();
+ if (NULL == light_rtypes) {
+ ERR("iotcon_resource_types_new() Fail");
+ return -1;
+ }
+
iotcon_resource_types_insert(light_rtypes, "core.light");
iotcon_resource_h light_handle = iotcon_register_resource("/a/light", light_rtypes,
(IOTCON_INTERFACE_DEFAULT | IOTCON_INTERFACE_BATCH),
return -1;
}
+ iotcon_resource_types_free(light_rtypes);
+
g_main_loop_run(loop);
g_main_loop_unref(loop);