GIOCondition cond,
gpointer data)
{
+ char *buf = NULL;
+ int nbytes;
+ guint nb;
+ int request_type = 0;
+ const char *request_code = NULL;
+ const char *p = NULL;
+ int request_id = -1;
+ bundle *kb = NULL;
gint fd = g_io_channel_unix_get_fd(channel);
LOGI("__recv_map_message: ...from %d:%s%s%s%s\n", fd,
(cond & G_IO_ERR) ? " ERR" : "",
goto error;
if (cond & G_IO_IN) {
- char *buf;
- int nbytes;
- guint nb;
- int request_type = 0;
- const char *request_code = NULL;
- const char *p = NULL;
- int request_id = -1;
if (_read_socket(fd, (char *)&nbytes, sizeof(nbytes), &nb)) {
LOGE("Fail to read nbytes from socket");
LOGI("__recv_map_message: ...from %d: %d bytes\n", fd, nbytes);
if (nbytes > 0) {
- bundle *kb = NULL;
buf = (char *) calloc(nbytes + 1, sizeof(char));
if (buf == NULL) {
goto error;
}
if (_read_socket(fd, buf, nbytes, &nb)) {
- free(buf);
LOGE("Fail to read buf from socket");
goto error;
}
if (nb == 0) {
- free(buf);
LOGE("__recv_map_message: ...from %d: socket closed\n", fd);
goto error;
}
kb = bundle_decode_raw((bundle_raw *)buf, nbytes);
if (kb == NULL) {
- free(buf);
LOGE("__recv_map_message: Unable to decode the bundle\n");
goto error;
}
request_code = bundle_get_val(kb, OSP_K_DATACONTROL_REQUEST_TYPE);
if (!request_code) {
LOGE("Invalid Bundle: data-control request type is null");
- free(buf);
- bundle_free(kb);
goto error;
}
request_type = atoi(request_code);
- if (__map_handle_cb(fd, kb, request_type, request_id, 0, data) != DATACONTROL_ERROR_NONE) {
- free(buf);
- bundle_free(kb);
+ if (__map_handle_cb(fd, kb, request_type, request_id, 0, data) != DATACONTROL_ERROR_NONE)
goto error;
- }
} else {
LOGE("error: listener information is null");
- free(buf);
- bundle_free(kb);
goto error;
}
__remove_map_request_info(request_id, data);
- free(buf);
- bundle_free(kb);
+
+ if (kb)
+ bundle_free(kb);
+ if (buf)
+ free(buf);
}
}
return TRUE;
error:
+ if (kb)
+ bundle_free(kb);
+ if (buf)
+ free(buf);
+
if (((map_response_cb_s *)data) != NULL) {
map_response_cb_s *map_dc = (map_response_cb_s *)data;
return DATACONTROL_ERROR_NONE;
}
+static int _get_int_from_str(const char *str)
+{
+ int result = 0;
+ char *pend;
+ errno = 0;
+ result = strtol(str, &pend, 10);
+ if ((result == LONG_MIN || result == LONG_MAX)
+ && errno != 0) {
+ result = 0;
+ }
+
+ if (*pend != '\0')
+ result = 0;
+
+ return result;
+}
+
static int __send_get_value_result(int fd, bundle *b, void *data)
{
LOGI("page num: %s, count_per_page: %s, value_count %s", page_num_str, count_per_page_str, value_count_str);
- int page_number = atoi(page_num_str);
- int count_per_page = atoi(count_per_page_str);
- int value_count = atoi(value_count_str);
- int current_offset = (page_number - 1) * count_per_page;
- int remain_count = value_count - current_offset;
+ int page_number = 0;
+ int count_per_page = 0;
+ int value_count = 0;
+ int current_offset = 0;
+ int remain_count = 0;
unsigned int nb;
+ page_number = _get_int_from_str(page_num_str);
+ count_per_page = _get_int_from_str(count_per_page_str);
+ value_count = _get_int_from_str(value_count_str);
+
+ current_offset = (page_number - 1) * count_per_page;
+ remain_count = value_count - current_offset;
remain_count = (remain_count > 0) ? remain_count : 0; /* round off to zero if the negative num is found */
int add_value_count = (count_per_page > remain_count) ? remain_count : count_per_page;