diff options
author | Hyihong Chae <hh.chae@samsung.com> | 2017-01-13 10:50:22 +0900 |
---|---|---|
committer | Hyihong Chae <hh.chae@samsung.com> | 2017-01-13 19:29:06 +0900 |
commit | d18f62ff3655deabccc1361475443911f40cdc48 (patch) | |
tree | fc2a7e706d156c79aeedcd409ad098999c72d95d | |
parent | 6bc392414b5e28f85f8feabc2c5ec83bdb7fbfda (diff) | |
download | mtp-responder-accepted/tizen_tv.tar.gz mtp-responder-accepted/tizen_tv.tar.bz2 mtp-responder-accepted/tizen_tv.zip |
Sync code with Tizen 3.0 branchsubmit/tizen_unified/20170308.100406submit/tizen/20170113.103502accepted/tizen/wearable/20170113.225406accepted/tizen/unified/20170309.032713accepted/tizen/tv/20170113.225348accepted/tizen/mobile/20170113.225335accepted/tizen/ivi/20170113.225426accepted/tizen/common/20170113.184432accepted/tizen_wearableaccepted/tizen_tvaccepted/tizen_mobileaccepted/tizen_iviaccepted/tizen_common
Change-Id: I623bf81942d5b0d9d0e154741430d2a418918280
Signed-off-by: HyiHong Chae <hh.chae@samsung.com>
-rwxr-xr-x | include/entity/mtp_property.h | 2 | ||||
-rwxr-xr-x | include/mtp_cmd_handler.h | 2 | ||||
-rwxr-xr-x | include/mtp_config.h | 4 | ||||
-rwxr-xr-x | include/mtp_datatype.h | 2 | ||||
-rwxr-xr-x | include/util/mtp_fs.h | 14 | ||||
-rwxr-xr-x | include/util/mtp_thread.h | 10 | ||||
-rwxr-xr-x | packaging/mtp-responder.spec | 14 | ||||
-rwxr-xr-x | src/entity/mtp_device.c | 2 | ||||
-rwxr-xr-x | src/entity/mtp_object.c | 6 | ||||
-rwxr-xr-x | src/entity/mtp_property.c | 211 | ||||
-rwxr-xr-x | src/entity/mtp_store.c | 71 | ||||
-rwxr-xr-x | src/mtp_cmd_handler.c | 221 | ||||
-rwxr-xr-x | src/mtp_cmd_handler_util.c | 95 | ||||
-rwxr-xr-x | src/mtp_event_handler.c | 13 | ||||
-rwxr-xr-x | src/mtp_init.c | 14 | ||||
-rwxr-xr-x | src/mtp_inoti_handler.c | 40 | ||||
-rwxr-xr-x | src/ptp_container.c | 11 | ||||
-rwxr-xr-x | src/transport/mtp_transport.c | 14 | ||||
-rwxr-xr-x | src/transport/mtp_usb_driver.c | 21 | ||||
-rwxr-xr-x | src/util/mtp_fs.c | 64 | ||||
-rwxr-xr-x | src/util/mtp_list.c | 6 | ||||
-rwxr-xr-x | src/util/mtp_media_info.c | 10 | ||||
-rwxr-xr-x | src/util/mtp_msgq.c | 5 | ||||
-rwxr-xr-x | src/util/mtp_support.c | 39 | ||||
-rwxr-xr-x | src/util/mtp_thread.c | 5 | ||||
-rwxr-xr-x | src/util/mtp_util.c | 20 |
26 files changed, 394 insertions, 522 deletions
diff --git a/include/entity/mtp_property.h b/include/entity/mtp_property.h index 4bb6591..8ad9818 100755 --- a/include/entity/mtp_property.h +++ b/include/entity/mtp_property.h @@ -84,7 +84,7 @@ enum { _prop_destroy_obj_propval(prop_val);\ ERR("_util_add_node() Fail");\ return (FALSE);\ - }\ + } \ } while (0); #define propvalue_alloc_and_check(prop_val)\ diff --git a/include/mtp_cmd_handler.h b/include/mtp_cmd_handler.h index 1fc6992..90559cf 100755 --- a/include/mtp_cmd_handler.h +++ b/include/mtp_cmd_handler.h @@ -77,7 +77,7 @@ typedef struct { mtp_uint32 cmd_size; mtp_uint32 data_size; mtp_uint32 data_count; - mtp_uint32 fhandle; /* for temporary mtp file */ + FILE* fhandle; /* for temporary mtp file */ mtp_char *filepath; mtp_uint32 file_size; mtp_uint32 size_remaining; diff --git a/include/mtp_config.h b/include/mtp_config.h index b4249e1..d7052a9 100755 --- a/include/mtp_config.h +++ b/include/mtp_config.h @@ -28,7 +28,7 @@ /*MtpObject.c, for unknown metadata */ #define MTP_USE_FILL_EMPTYMETADATA_WITH_UNKNOWN -/*define MTP_USE_VARIABLE_PTP_STRING_MALLOC*/ /*allocPtpString in ptpstring.c*/ +/*define MTP_USE_VARIABLE_PTP_STRING_MALLOC*/ /*allocPtpString in ptpstring.c*/ #define MTP_USE_RUNTIME_GETOBJECTPROPVALUE /*use runtime get object property list*/ /*keywords has many space. not support*/ @@ -143,7 +143,7 @@ #define MTP_MAX_PACKET_SIZE_SEND_HS 512 /* High speed */ #define MTP_MAX_PACKET_SIZE_SEND_FS 64 /* Full speed */ -#define MTP_FILESIZE_4GB 4294967296L +#define MTP_FILESIZE_4GB 4294967296L /* approximately 3 times of media files. consider album*/ #define MTP_MAX_REFDB_ROWCNT 4500 diff --git a/include/mtp_datatype.h b/include/mtp_datatype.h index 07f51f4..4fa9782 100755 --- a/include/mtp_datatype.h +++ b/include/mtp_datatype.h @@ -25,8 +25,6 @@ #endif #ifdef _MTP_USE_OWNTYPES -#define INVALID_FILE (0) - typedef unsigned char mtp_byte; typedef unsigned char mtp_bool; typedef unsigned char mtp_uchar; diff --git a/include/util/mtp_fs.h b/include/util/mtp_fs.h index 3a88e55..6ce634d 100755 --- a/include/util/mtp_fs.h +++ b/include/util/mtp_fs.h @@ -67,13 +67,13 @@ typedef struct { mtp_uint64 reserved_size; } fs_info_t; -mtp_uint32 _util_file_open(const mtp_char *filename, file_mode_t mode, +FILE* _util_file_open(const mtp_char *filename, file_mode_t mode, mtp_int32 *error); -void _util_file_read(mtp_uint32 fhandle, void *bufptr, mtp_uint32 size, +void _util_file_read(FILE* fhandle, void *bufptr, mtp_uint32 size, mtp_uint32 *read_count); -mtp_uint32 _util_file_write(mtp_uint32 fhandle, void *bufptr, mtp_uint32 size); -mtp_int32 _util_file_close(mtp_uint32 fhandle); -mtp_bool _util_file_seek(mtp_uint32 fhandle, off_t offset, mtp_int32 whence); +mtp_uint32 _util_file_write(FILE* fhandle, void *bufptr, mtp_uint32 size); +mtp_int32 _util_file_close(FILE* fhandle); +mtp_bool _util_file_seek(FILE* fhandle, off_t offset, mtp_int32 whence); mtp_bool _util_file_copy(const mtp_char *origpath, const mtp_char *newpath, mtp_int32 *error); mtp_bool _util_copy_dir_children_recursive(const mtp_char *origpath, @@ -89,8 +89,8 @@ mtp_bool _util_ifind_next(char *dir_name, DIR *dirp, dir_entry_t *dir_info); mtp_bool _util_ifind_first(char *dir_name, DIR **dirp, dir_entry_t *dir_info); mtp_bool _util_is_file_opened(const mtp_char *fullpath); mtp_bool _util_get_filesystem_info(mtp_char *storepath, fs_info_t *fs_info); -void _util_count_num_lines(mtp_uint32 fhandle, mtp_uint32 *num_lines); -void _util_fill_guid_array(void *guidarray, mtp_uint32 start_index, mtp_uint32 fhandle, +void _util_count_num_lines(FILE* fhandle, mtp_uint32 *num_lines); +void _util_fill_guid_array(void *guidarray, mtp_uint32 start_index, FILE* fhandle, mtp_uint32 size); void FLOGD(const char *fmt, ...); diff --git a/include/util/mtp_thread.h b/include/util/mtp_thread.h index 41c4cfe..f742158 100755 --- a/include/util/mtp_thread.h +++ b/include/util/mtp_thread.h @@ -28,15 +28,15 @@ typedef void *(*thread_func_t) (void *pArg); int lock_ret = 0;\ DBG("Thread [%d] trying to lock the Mutex \n", syscall(__NR_gettid));\ lock_ret = pthread_mutex_lock(mut);\ - if(lock_ret != 0) {\ - if(lock_ret == EDEADLK) {\ + if (lock_ret != 0) {\ + if (lock_ret == EDEADLK) {\ DBG("Mutex is already locked by the same thread");\ } else {\ ERR("Error locking mutex. Error = %d \n", lock_ret);\ - }\ + } \ } else {\ DBG("Mutex locked by thread [%d] \n", syscall(__NR_gettid));\ - }\ + } \ } while (0);\ @@ -48,7 +48,7 @@ typedef void *(*thread_func_t) (void *pArg); ERR("Error unlocking mutex. Error = %d \n", unlock_ret);\ } else {\ DBG("Mutex unlocked by thread [%d] \n", syscall(__NR_gettid));\ - }\ + } \ } while (0);\ mtp_bool _util_thread_create(pthread_t *tid, const mtp_char *tname, diff --git a/packaging/mtp-responder.spec b/packaging/mtp-responder.spec index 93ef8c5..d292281 100755 --- a/packaging/mtp-responder.spec +++ b/packaging/mtp-responder.spec @@ -5,7 +5,7 @@ ExcludeArch: %arm aarch64 Name: mtp-responder Summary: Media Transfer Protocol daemon (responder) -Version: 0.0.18 +Version: 0.0.19 Release: 1 Group: Network & Connectivity/Other License: Apache-2.0 @@ -43,24 +43,24 @@ make %{?jobs:-j%jobs} %install %make_install -mkdir -p %{buildroot}%{_libdir}/udev/rules.d -cp packaging/99-mtp-responder.rules %{buildroot}%{_libdir}/udev/rules.d/99-mtp-responder.rules +mkdir -p %{buildroot}/%{_prefix}/lib/udev/rules.d +cp packaging/99-mtp-responder.rules %{buildroot}/%{_prefix}/lib/udev/rules.d/99-mtp-responder.rules mkdir -p %{buildroot}%{upgrade_script_path} cp -f scripts/500.%{name}-upgrade.sh %{buildroot}%{upgrade_script_path} -install -D -m 0644 mtp-responder.service %{buildroot}%{_libdir}/systemd/system/mtp-responder.service +install -D -m 0644 mtp-responder.service %{buildroot}/%{_unitdir}/mtp-responder.service %post mkdir -p %{_sysconfdir}/systemd/default-extra-dependencies/ignore-units.d/ -ln -sf %{_libdir}/systemd/system/mtp-responder.service %{_sysconfdir}/systemd/default-extra-dependencies/ignore-units.d/ +ln -sf %{_unitdir}/mtp-responder.service %{_sysconfdir}/systemd/default-extra-dependencies/ignore-units.d/ %files %manifest mtp-responder.manifest %defattr(-,root,root,-) %{_bindir}/mtp-responder -%{_libdir}/systemd/system/mtp-responder.service -%{_libdir}/udev/rules.d/99-mtp-responder.rules +%{_unitdir}/mtp-responder.service +%{_prefix}/lib/udev/rules.d/99-mtp-responder.rules /opt/var/lib/misc/mtp-responder.conf %{upgrade_script_path}/500.%{name}-upgrade.sh #%license LICENSE.APLv2 diff --git a/src/entity/mtp_device.c b/src/entity/mtp_device.c index 8bf6485..da88199 100755 --- a/src/entity/mtp_device.c +++ b/src/entity/mtp_device.c @@ -742,7 +742,7 @@ mtp_bool _device_install_storage(mtp_int32 type) break; mounted = _device_is_store_mounted(MTP_STORAGE_EXTERNAL); if (mounted == FALSE) { - if (__add_store_to_device(MTP_STORAGE_EXTERNAL)== FALSE) { + if (__add_store_to_device(MTP_STORAGE_EXTERNAL) == FALSE) { ERR("__add_store_to_device() Fail"); return FALSE; } diff --git a/src/entity/mtp_object.c b/src/entity/mtp_object.c index 1cc13bf..358af3c 100755 --- a/src/entity/mtp_object.c +++ b/src/entity/mtp_object.c @@ -501,9 +501,8 @@ mtp_bool _entity_check_child_obj_path(mtp_obj_t *obj, mtp_uint32 *ptr32 = child_arr.array_entry; child_obj = _entity_get_object_from_store(src_store, ptr32[idx]); - if (NULL == child_obj) { + if (NULL == child_obj) continue; - } if (_util_is_file_opened(child_obj->file_path) == TRUE) { ERR_SECURE("File [%s] is already opened\n", @@ -524,9 +523,8 @@ mtp_bool _entity_check_child_obj_path(mtp_obj_t *obj, } ptr = strstr(child_obj->file_path, src_path); - if (NULL == ptr) { + if (NULL == ptr) continue; - } _util_utf8_to_utf16(dest_chld_wpath, sizeof(dest_chld_wpath) / WCHAR_SIZ, src_path); diff --git a/src/entity/mtp_property.c b/src/entity/mtp_property.c index 37151d2..9f33c6c 100755 --- a/src/entity/mtp_property.c +++ b/src/entity/mtp_property.c @@ -148,8 +148,8 @@ static mtp_bool __create_prop_string(mtp_obj_t *obj, mtp_uint16 propcode, static mtp_bool __create_prop_timestring(mtp_obj_t *obj, mtp_uint32 propcode, ptp_time_string_t *value) { - obj_prop_desc_t *prop = NULL; - obj_prop_val_t *prop_val= NULL; + obj_prop_desc_t *prop = NULL; + obj_prop_val_t *prop_val = NULL; mtp_uint32 fmt_code = obj->obj_info->obj_fmt; retv_if(obj == NULL, FALSE); @@ -195,7 +195,7 @@ static mtp_bool __update_prop_values_audio(mtp_obj_t *obj) { mtp_bool success = TRUE; mtp_int32 converted_rating = 0; - comp_audio_meta_t audio_data = {{0}, {0}}; + comp_audio_meta_t audio_data = {{0}, {0} }; retv_if(obj == NULL, FALSE); retv_if(obj->obj_info == NULL, FALSE); @@ -727,9 +727,8 @@ ptp_array_t *_prop_alloc_ptparray(data_type_t type) { ptp_array_t *parray; parray = (ptp_array_t *)g_malloc(sizeof(ptp_array_t)); - if (parray != NULL) { + if (parray != NULL) _prop_init_ptparray(parray, type); - } return (parray); } @@ -799,18 +798,16 @@ mtp_int32 _prop_find_ele_ptparray(ptp_array_t *parray, mtp_uint32 element) case UINT8_TYPE: ptr8 = parray->array_entry; for (ii = 0; ii < parray->num_ele; ii++) { - if (ptr8[ii] == (mtp_uchar) element) { + if (ptr8[ii] == (mtp_uchar) element) return ii; - } } break; case UINT16_TYPE: ptr16 = parray->array_entry; for (ii = 0; ii < parray->num_ele; ii++) { - if (ptr16[ii] == (mtp_uint16) element) { + if (ptr16[ii] == (mtp_uint16) element) return ii; - } } break; @@ -818,9 +815,8 @@ mtp_int32 _prop_find_ele_ptparray(ptp_array_t *parray, mtp_uint32 element) case UINT32_TYPE: ptr32 = parray->array_entry; for (ii = 0; ii < parray->num_ele; ii++) { - if (ptr32[ii] == (mtp_uint32)element) { + if (ptr32[ii] == (mtp_uint32)element) return ii; - } } break; @@ -1087,9 +1083,9 @@ void _prop_deinit_ptparray(ptp_array_t *parray) { parray->num_ele = 0; parray->arr_size = 0; - if (parray->array_entry) { + if (parray->array_entry) g_free(parray->array_entry); - } + parray->array_entry = NULL; return; } @@ -1099,9 +1095,9 @@ void _prop_destroy_ptparray(ptp_array_t *parray) if (parray == NULL) return; - if (parray->array_entry != NULL) { + if (parray->array_entry != NULL) g_free(parray->array_entry); - } + parray->arr_size = 0; parray->num_ele = 0; g_free(parray); @@ -1141,9 +1137,8 @@ static ptp_string_t *__alloc_ptpstring(void) ptp_string_t *pstring = NULL; pstring = (ptp_string_t *)g_malloc(sizeof(ptp_string_t)); - if (pstring != NULL) { + if (pstring != NULL) _prop_init_ptpstring(pstring); - } return (pstring); } @@ -1158,9 +1153,8 @@ static ptp_string_t *__alloc_ptpstring(mtp_uint32 size) alloc_size = ((size_tmp >> 5) + 1) << 5; /* multiple of 32 */ pstring = (ptp_string_t *)g_malloc(alloc_size); /* for margin */ - if (pstring != NULL) { + if (pstring != NULL) _prop_init_ptpstring(pstring); - } return (pstring); } @@ -1200,17 +1194,15 @@ void _prop_copy_char_to_ptpstring(ptp_string_t *pstring, void *str, pstring->num_chars = 0; return; } - for (i = 0; i < MAX_PTP_STRING_CHARS && pchar[i]; i++) { + for (i = 0; i < MAX_PTP_STRING_CHARS && pchar[i]; i++) pstring->str[i] = (mtp_wchar)pchar[i]; - } } else if (cmode == WCHAR_TYPE) { if (pwchar[0] == 0) { pstring->num_chars = 0; return; } - for (i = 0; i < MAX_PTP_STRING_CHARS && pwchar[i]; i++) { + for (i = 0; i < MAX_PTP_STRING_CHARS && pwchar[i]; i++) pstring->str[i] = pwchar[i]; - } } else { ERR("Unknown character mode : %d\n", cmode); pstring->num_chars = 0; @@ -1261,9 +1253,9 @@ void _prop_copy_ptpstring(ptp_string_t *dst, ptp_string_t *src) mtp_uint16 ii; dst->num_chars = src->num_chars; - for (ii = 0; ii < src->num_chars; ii++) { + for (ii = 0; ii < src->num_chars; ii++) dst->str[ii] = src->str[ii]; - } + return; } @@ -1272,9 +1264,9 @@ void _prop_copy_ptptimestring(ptp_time_string_t *dst, ptp_time_string_t *src) mtp_uint16 ii; dst->num_chars = src->num_chars; - for (ii = 0; ii < src->num_chars; ii++) { + for (ii = 0; ii < src->num_chars; ii++) dst->str[ii] = src->str[ii]; - } + return; } @@ -1338,9 +1330,8 @@ mtp_uint32 _prop_pack_ptpstring(ptp_string_t *pstring, mtp_uchar *buf, buf[0] = pstring->num_chars; bytes_written = _prop_size_ptpstring(pstring); - for (ii = 0; ii < (bytes_written - 1); ii++) { + for (ii = 0; ii < (bytes_written - 1); ii++) buf[ii + 1] = pchar[ii]; - } } return bytes_written; } @@ -1386,9 +1377,8 @@ mtp_uint32 _prop_parse_rawstring(ptp_string_t *pstring, mtp_uchar *buf, { mtp_uint16 ii; - if (buf == NULL) { + if (buf == NULL) return 0; - } if (buf[0] == 0) { pstring->num_chars = 0; @@ -1396,9 +1386,8 @@ mtp_uint32 _prop_parse_rawstring(ptp_string_t *pstring, mtp_uchar *buf, } else { pstring->num_chars = buf[0]; ii = (mtp_uint16) ((size - 1) / sizeof(mtp_wchar)); - if (pstring->num_chars > ii) { + if (pstring->num_chars > ii) pstring->num_chars = (mtp_uchar)ii; - } for (ii = 1; ii <= pstring->num_chars; ii++) { #ifdef __BIG_ENDIAN__ @@ -1416,9 +1405,9 @@ mtp_uint32 _prop_parse_rawstring(ptp_string_t *pstring, mtp_uchar *buf, void _prop_destroy_ptpstring(ptp_string_t *pstring) { - if (pstring != NULL) { + if (pstring != NULL) g_free(pstring); - } + return; } @@ -1442,9 +1431,8 @@ mtp_bool _prop_is_valid_integer(prop_info_t *prop_info, mtp_uint64 value) mtp_uint32 ii; for (ii = 0; ii < prop_info->supp_value_list.nnodes; ii++, node = node->link) { - if (value == (mtp_uint32) node->value) { + if (value == (mtp_uint32) node->value) return TRUE; - } } /* if it hits here, must be an invalid value */ @@ -1460,12 +1448,10 @@ mtp_bool _prop_is_valid_integer(prop_info_t *prop_info, mtp_uint64 value) mtp_bool _prop_is_valid_string(prop_info_t *prop_info, ptp_string_t *pstring) { - if ((prop_info->data_type != PTP_DATATYPE_STRING) || (pstring == NULL)) { + if ((prop_info->data_type != PTP_DATATYPE_STRING) || (pstring == NULL)) return FALSE; - } - if (prop_info->form_flag == ENUM_FORM) - { + if (prop_info->form_flag == ENUM_FORM) { slist_node_t *node = NULL; mtp_uint32 ii; ptp_string_t *ele_str = NULL; @@ -1515,8 +1501,7 @@ mtp_bool _prop_set_default_string(prop_info_t *prop_info, mtp_wchar *val) _prop_copy_char_to_ptpstring(prop_info->default_val.str, val, WCHAR_TYPE); return TRUE; - } - else { + } else { return FALSE; } } @@ -1553,8 +1538,7 @@ mtp_bool _prop_set_default_array(prop_info_t *prop_info, mtp_uchar *parray, return FALSE; /* Copies the data into the PTP array */ - if ((prop_info->default_val.array != NULL) && (num_ele != 0)) - { + if ((prop_info->default_val.array != NULL) && (num_ele != 0)) { mtp_uchar *ptr8 = NULL; mtp_uint16 *ptr16 = NULL; mtp_uint32 *ptr32 = NULL; @@ -1563,8 +1547,7 @@ mtp_bool _prop_set_default_array(prop_info_t *prop_info, mtp_uchar *parray, _prop_grow_ptparray(prop_info->default_val.array, num_ele); if ((prop_info->data_type == PTP_DATATYPE_AUINT8) || - (prop_info->data_type == PTP_DATATYPE_AINT8)) - { + (prop_info->data_type == PTP_DATATYPE_AINT8)) { ptr8 = (mtp_uchar *) parray; for (ii = 0; ii < num_ele; ii++) _prop_append_ele_ptparray(prop_info->default_val.array, @@ -1599,9 +1582,8 @@ mtp_bool _prop_set_current_integer(device_prop_desc_t *prop, mtp_uint32 val) ptr = (mtp_uchar *) &val; - for (ii = 0; ii < sizeof(mtp_uint32); ii++) { + for (ii = 0; ii < sizeof(mtp_uint32); ii++) prop->current_val.integer[ii] = ptr[ii]; - } return TRUE; } else { @@ -1612,8 +1594,7 @@ mtp_bool _prop_set_current_integer(device_prop_desc_t *prop, mtp_uint32 val) mtp_bool _prop_set_current_string(device_prop_desc_t *prop, ptp_string_t *str) { - if (_prop_is_valid_string(&(prop->propinfo), str)) - { + if (_prop_is_valid_string(&(prop->propinfo), str)) { _prop_destroy_ptpstring(prop->current_val.str); #ifndef MTP_USE_VARIABLE_PTP_STRING_MALLOC prop->current_val.str = __alloc_ptpstring(); @@ -1623,8 +1604,7 @@ mtp_bool _prop_set_current_string(device_prop_desc_t *prop, ptp_string_t *str) if (prop->current_val.str != NULL) { _prop_copy_ptpstring(prop->current_val.str, str); return TRUE; - } - else { + } else { _prop_destroy_ptpstring(prop->current_val.str); return FALSE; } @@ -1739,21 +1719,19 @@ mtp_bool _prop_set_current_device_prop(device_prop_desc_t *prop, mtp_uchar *val, PTP_DATATYPE_ARRAY) { mtp_uint32 *ptr = (mtp_uint32 *) val; - if (size < sizeof(mtp_uint32)) { + if (size < sizeof(mtp_uint32)) return FALSE; - } - if (size < sizeof(mtp_uint32) + ptr[0] * prop->propinfo.dts_size) { + + if (size < sizeof(mtp_uint32) + ptr[0] * prop->propinfo.dts_size) return FALSE; - } + return _prop_set_current_array(prop, val); - } - else if ((prop->propinfo.data_type & PTP_DATATYPE_VALUEMASK) == + } else if ((prop->propinfo.data_type & PTP_DATATYPE_VALUEMASK) == PTP_DATATYPE_VALUE) { - if (prop->propinfo.dts_size > size) { + if (prop->propinfo.dts_size > size) return FALSE; - } if ((prop->propinfo.data_type == PTP_DATATYPE_INT64) || (prop->propinfo.data_type == PTP_DATATYPE_UINT64) || @@ -1806,7 +1784,7 @@ mtp_bool _prop_set_current_string_val(obj_prop_val_t *pval, ptp_string_t *str) pval->current_val.str = __alloc_ptpstring(str->num_chars); #endif /* MTP_USE_VARIABLE_PTP_STRING_MALLOC */ if (pval->current_val.str != NULL) { - _prop_copy_ptpstring (pval->current_val.str, str); + _prop_copy_ptpstring(pval->current_val.str, str); return TRUE; } else return FALSE; @@ -2271,9 +2249,8 @@ mtp_uint32 _prop_pack_device_prop_desc(device_prop_desc_t *prop, slist_node_t *node = NULL; mtp_uint32 ii; - if (!buf || size < _prop_size_device_prop_desc(prop)) { + if (!buf || size < _prop_size_device_prop_desc(prop)) return 0; - } /* Pack propcode, data_type, & get_set */ bytes_to_write = sizeof(mtp_uint16); @@ -2441,9 +2418,8 @@ mtp_uint32 _prop_pack_curval_device_prop_desc(device_prop_desc_t *prop, bytes_to_write = __size_curval_device_prop(prop); - if ((!bytes_to_write) || (buf == NULL) || (size < bytes_to_write)) { + if ((!bytes_to_write) || (buf == NULL) || (size < bytes_to_write)) return 0; - } if (prop->propinfo.data_type == PTP_DATATYPE_STRING) { if (bytes_to_write != _prop_pack_ptpstring(prop->current_val.str, @@ -2489,7 +2465,7 @@ void _prop_reset_device_prop_desc(device_prop_desc_t *prop) if (NULL == prop->current_val.str) return; - _prop_copy_ptpstring (prop->current_val.str, + _prop_copy_ptpstring(prop->current_val.str, prop->propinfo.default_val.str); } else if ((prop->propinfo.data_type & PTP_DATATYPE_ARRAYMASK) == @@ -2519,9 +2495,8 @@ obj_prop_val_t * _prop_alloc_obj_propval(obj_prop_desc_t *prop) obj_prop_val_t *pval = NULL; pval = (obj_prop_val_t *)g_malloc(sizeof(obj_prop_val_t)); - if (pval != NULL) { + if (pval != NULL) __init_obj_propval(pval, prop); - } return pval; } @@ -2532,9 +2507,8 @@ static void __init_obj_propval(obj_prop_val_t *pval, obj_prop_desc_t *prop) pval->prop = prop; - for (ii = 0; ii < 16; ii++) { + for (ii = 0; ii < 16; ii++) pval->current_val.integer[ii] = 0; - } if (prop->propinfo.data_type == PTP_DATATYPE_STRING) { @@ -2545,7 +2519,7 @@ static void __init_obj_propval(obj_prop_val_t *pval, obj_prop_desc_t *prop) #endif /* MTP_USE_VARIABLE_PTP_STRING_MALLOC */ if (NULL == pval->current_val.str) return; - _prop_copy_ptpstring (pval->current_val.str, + _prop_copy_ptpstring(pval->current_val.str, prop->propinfo.default_val.str); } else if ((prop->propinfo.data_type & PTP_DATATYPE_VALUEMASK) == PTP_DATATYPE_VALUE) { @@ -2607,9 +2581,8 @@ obj_prop_val_t *_prop_get_prop_val(mtp_obj_t *obj, mtp_uint32 propcode) prop_val = (obj_prop_val_t *)node->value; if (prop_val) { - if (prop_val->prop->propinfo.prop_code == propcode) { + if (prop_val->prop->propinfo.prop_code == propcode) return prop_val; - } } } @@ -2640,9 +2613,8 @@ mtp_uint32 _prop_pack_obj_propval(obj_prop_val_t *pval, mtp_uchar *buf, { mtp_uint32 bytes_to_write = _prop_size_obj_propval(pval); - if ((!bytes_to_write) || (buf == NULL) || (size < bytes_to_write)) { + if ((!bytes_to_write) || (buf == NULL) || (size < bytes_to_write)) return 0; - } if (pval->prop->propinfo.data_type == PTP_DATATYPE_STRING) { @@ -2682,11 +2654,10 @@ mtp_uint32 _prop_size_obj_propval(obj_prop_val_t *pval) return size; if (pval->prop->propinfo.data_type == PTP_DATATYPE_STRING) { - if (pval->current_val.str == NULL) { + if (pval->current_val.str == NULL) size = 0; - } else { + else size = _prop_size_ptpstring(pval->current_val.str); - } } else if ((pval->prop->propinfo.data_type & PTP_DATATYPE_ARRAYMASK) == PTP_DATATYPE_ARRAY) { @@ -2702,9 +2673,8 @@ mtp_uint32 _prop_size_obj_propval(obj_prop_val_t *pval) void _prop_destroy_obj_propval(obj_prop_val_t *pval) { - if (pval == NULL) { + if (pval == NULL) return; - } if (pval->prop == NULL) { g_free(pval); @@ -2745,11 +2715,10 @@ static void __init_obj_prop_desc(obj_prop_desc_t *prop, mtp_uint16 propcode, prop->propinfo.form_flag = form_flag; - if (prop->propinfo.form_flag == BYTE_ARRAY_FORM) { + if (prop->propinfo.form_flag == BYTE_ARRAY_FORM) prop->propinfo.data_type = PTP_DATATYPE_AUINT8; - } else if (prop->propinfo.form_flag == LONG_STRING_FORM) { + else if (prop->propinfo.form_flag == LONG_STRING_FORM) prop->propinfo.data_type = PTP_DATATYPE_AUINT16; - } prop->group_code = group_code; @@ -2859,9 +2828,9 @@ mtp_uint32 _prop_size_obj_prop_desc(obj_prop_desc_t *prop) break; case RANGE_FORM: - if (prop->propinfo.data_type != PTP_DATATYPE_STRING) { + if (prop->propinfo.data_type != PTP_DATATYPE_STRING) size += 3 * prop->propinfo.dts_size;/* Min,Max,Step */ - } + break; case ENUM_FORM: @@ -2913,9 +2882,8 @@ mtp_uint32 _prop_pack_obj_prop_desc(obj_prop_desc_t *prop, mtp_uchar *buf, slist_node_t *node = NULL; mtp_uint16 ii; - if (!buf || size < _prop_size_obj_prop_desc(prop)) { + if (!buf || size < _prop_size_obj_prop_desc(prop)) return 0; - } /* Pack propcode, data_type, & get_set */ bytes_to_write = sizeof(mtp_uint16); @@ -3095,9 +3063,8 @@ mtp_uint32 _prop_pack_default_val_obj_prop_desc(obj_prop_desc_t *prop, bytes_to_write = __get_size_default_val_obj_prop_desc(prop); - if ((!bytes_to_write) || (buf == NULL) || (size < bytes_to_write)) { + if ((!bytes_to_write) || (buf == NULL) || (size < bytes_to_write)) return 0; - } if (prop->propinfo.data_type == PTP_DATATYPE_STRING) { if (bytes_to_write != @@ -3133,32 +3100,28 @@ obj_prop_desc_t *_prop_get_obj_prop_desc(mtp_uint32 format_code, int num_default_obj_props = 0; /*Default*/ - if (_get_oma_drm_status() == TRUE) { + if (_get_oma_drm_status() == TRUE) num_default_obj_props = NUM_OBJECT_PROP_DESC_DEFAULT; - } else { + else num_default_obj_props = NUM_OBJECT_PROP_DESC_DEFAULT - 1; - } for (i = 0; i < num_default_obj_props; i++) { - if (props_list_default[i].propinfo.prop_code == propcode) { + if (props_list_default[i].propinfo.prop_code == propcode) return &(props_list_default[i]); - } } switch (format_code) { case PTP_FMT_MP3: case PTP_FMT_WAVE: for (i = 0; i < NUM_OBJECT_PROP_DESC_MP3; i++) { - if (props_list_mp3[i].propinfo.prop_code == propcode) { + if (props_list_mp3[i].propinfo.prop_code == propcode) return &(props_list_mp3[i]); - } } break; case MTP_FMT_WMA: for (i = 0; i < NUM_OBJECT_PROP_DESC_WMA; i++) { - if (props_list_wma[i].propinfo.prop_code == propcode) { + if (props_list_wma[i].propinfo.prop_code == propcode) return &(props_list_wma[i]); - } } break; case MTP_FMT_WMV: @@ -3168,9 +3131,8 @@ obj_prop_desc_t *_prop_get_obj_prop_desc(mtp_uint32 format_code, case PTP_FMT_MPEG: case MTP_FMT_3GP: for (i = 0; i < NUM_OBJECT_PROP_DESC_WMV; i++) { - if (props_list_wmv[i].propinfo.prop_code == propcode) { + if (props_list_wmv[i].propinfo.prop_code == propcode) return &(props_list_wmv[i]); - } } break; case MTP_FMT_ABSTRACT_AUDIO_ALBUM: @@ -3179,9 +3141,8 @@ obj_prop_desc_t *_prop_get_obj_prop_desc(mtp_uint32 format_code, case PTP_FMT_IMG_BMP: case PTP_FMT_IMG_PNG: for (i = 0; i < NUM_OBJECT_PROP_DESC_ALBUM; i++) { - if (props_list_album[i].propinfo.prop_code == propcode) { + if (props_list_album[i].propinfo.prop_code == propcode) return &(props_list_album[i]); - } } break; @@ -3266,9 +3227,9 @@ mtp_uint32 _prop_size_obj_proplist(obj_proplist_t *prop_list) node = prop_list->prop_quad_list.start; for (ii = 0; ii < prop_list->prop_quad_list.nnodes; ii++) { quad = (prop_quad_t *) node->value; - if (quad) { + if (quad) size += quad->val_size; - } + node = node->link; } return size; @@ -3292,9 +3253,8 @@ mtp_uint32 _prop_get_obj_proplist(mtp_obj_t *obj, mtp_uint32 propcode, ii++, node = node->link) { propval = (obj_prop_val_t *)node->value; - if (NULL == propval) { + if (NULL == propval) continue; - } if (FALSE == __check_object_propcode(propval->prop, propcode, group_code)) { @@ -3536,9 +3496,8 @@ mtp_uint32 _prop_pack_obj_proplist(obj_proplist_t *prop_list, mtp_uchar *buf, mtp_uint32 ii; slist_node_t *node = NULL; - if (!buf || size < _prop_size_obj_proplist(prop_list)) { + if (!buf || size < _prop_size_obj_proplist(prop_list)) return 0; - } *(mtp_uint32 *) buf = prop_list->prop_quad_list.nnodes; #ifdef __BIG_ENDIAN__ @@ -3585,7 +3544,7 @@ mtp_uint32 _prop_pack_obj_proplist(obj_proplist_t *prop_list, mtp_uchar *buf, str = (ptp_string_t *) quad->pval; if (str) { temp += _prop_pack_ptpstring(str, temp, - _prop_size_ptpstring (str)); + _prop_size_ptpstring(str)); } else { /* Put in an empty string: NumOfChars = 0; */ *temp++ = 0; @@ -3683,11 +3642,10 @@ mtp_uint32 _prop_get_supp_obj_props(mtp_uint32 format_code, mtp_uint32 num_default_obj_props = 0; /*Default*/ - if (_get_oma_drm_status() == TRUE) { + if (_get_oma_drm_status() == TRUE) num_default_obj_props = NUM_OBJECT_PROP_DESC_DEFAULT; - } else { + else num_default_obj_props = NUM_OBJECT_PROP_DESC_DEFAULT - 1; - } for (i = 0; i < num_default_obj_props; i++) { _prop_append_ele_ptparray(supp_props, @@ -4799,31 +4757,26 @@ void _prop_destroy_supp_obj_props(void) mtp_uint32 i = 0; int num_default_obj_prps = 0; - for (i = 0; i < NUM_OBJECT_PROP_DESC_MP3; i++) { + for (i = 0; i < NUM_OBJECT_PROP_DESC_MP3; i++) __destroy_obj_prop_desc(&(props_list_mp3[i])); - } - for (i = 0; i < NUM_OBJECT_PROP_DESC_WMA; i++) { + for (i = 0; i < NUM_OBJECT_PROP_DESC_WMA; i++) __destroy_obj_prop_desc(&(props_list_wma[i])); - } - for (i = 0; i < NUM_OBJECT_PROP_DESC_WMV; i++) { + for (i = 0; i < NUM_OBJECT_PROP_DESC_WMV; i++) __destroy_obj_prop_desc(&(props_list_wmv[i])); - } - for (i = 0; i < NUM_OBJECT_PROP_DESC_ALBUM; i++) { + for (i = 0; i < NUM_OBJECT_PROP_DESC_ALBUM; i++) __destroy_obj_prop_desc(&(props_list_album[i])); - } - if (_get_oma_drm_status() == TRUE) { + if (_get_oma_drm_status() == TRUE) num_default_obj_prps = NUM_OBJECT_PROP_DESC_DEFAULT; - } else { + else num_default_obj_prps = NUM_OBJECT_PROP_DESC_DEFAULT - 1; - } - for (i = 0; i < num_default_obj_prps; i++) { + for (i = 0; i < num_default_obj_prps; i++) __destroy_obj_prop_desc(&(props_list_default[i])); - } + return; } @@ -4855,9 +4808,8 @@ mtp_uint32 _prop_get_size_interdep_prop(interdep_prop_config_t *prop_config) node = prop_config->propdesc_list.start; for (ii = 0; ii < prop_config->propdesc_list.nnodes; ii++) { prop = node->value; - if (prop) { + if (prop) size += _prop_size_obj_prop_desc(prop); - } } return size; } @@ -4871,9 +4823,8 @@ mtp_uint32 _prop_pack_interdep_prop(interdep_prop_config_t *prop_config, mtp_uint32 ele_size = 0; mtp_int32 ii; - if (!buf || size < _prop_get_size_interdep_prop(prop_config)) { + if (!buf || size < _prop_get_size_interdep_prop(prop_config)) return 0; - } *(mtp_uint32 *) buf = prop_config->propdesc_list.nnodes; #ifdef __BIG_ENDIAN__ diff --git a/src/entity/mtp_store.c b/src/entity/mtp_store.c index 7b9cba8..7297d8b 100755 --- a/src/entity/mtp_store.c +++ b/src/entity/mtp_store.c @@ -92,18 +92,18 @@ mtp_bool _entity_get_store_path_by_id(mtp_uint32 store_id, mtp_char *path) { char sto_path[MTP_MAX_PATHNAME_SIZE + 1] = { 0 }; - switch(store_id) { - case MTP_INTERNAL_STORE_ID : + switch (store_id) { + case MTP_INTERNAL_STORE_ID: _util_get_internal_path(sto_path); g_strlcpy(path, sto_path, MTP_MAX_PATHNAME_SIZE + 1); break; - case MTP_EXTERNAL_STORE_ID : + case MTP_EXTERNAL_STORE_ID: _util_get_external_path(sto_path); g_strlcpy(path, sto_path, MTP_MAX_PATHNAME_SIZE + 1); break; - default : + default: ERR("No valid match for the store id [0x%x]\n", store_id); return FALSE; @@ -316,9 +316,8 @@ mtp_bool _entity_add_object_to_store(mtp_store_t *store, mtp_obj_t *obj) /* references */ if (PTP_OBJECTHANDLE_ROOT != obj->obj_info->h_parent) { par_obj = _entity_get_object_from_store(store, obj->obj_info->h_parent); - if (NULL != par_obj) { + if (NULL != par_obj) _entity_add_reference_child_array(par_obj, obj->obj_handle); - } } return TRUE; @@ -337,7 +336,7 @@ mtp_obj_t *_entity_get_object_from_store(mtp_store_t *store, mtp_uint32 handle) return NULL; } - while(UTIL_CHECK_LIST_NEXT(iter) == TRUE) { + while (UTIL_CHECK_LIST_NEXT(iter) == TRUE) { obj = (mtp_obj_t *)_util_get_list_next(iter); if (obj && obj->obj_handle == handle) { @@ -366,12 +365,11 @@ mtp_obj_t *_entity_get_last_object_from_store(mtp_store_t *store, return NULL; } - while(UTIL_CHECK_LIST_NEXT(iter) == TRUE) { + while (UTIL_CHECK_LIST_NEXT(iter) == TRUE) { temp_obj = (mtp_obj_t *)_util_get_list_next(iter); - if (temp_obj && temp_obj->obj_handle == handle) { + if (temp_obj && temp_obj->obj_handle == handle) obj = temp_obj; - } } _util_deinit_list_iterator(iter); @@ -392,7 +390,7 @@ mtp_obj_t *_entity_get_object_from_store_by_path(mtp_store_t *store, return NULL; } - while(UTIL_CHECK_LIST_NEXT(iter) == TRUE) { + while (UTIL_CHECK_LIST_NEXT(iter) == TRUE) { obj = (mtp_obj_t *)_util_get_list_next(iter); if (obj == NULL) { ERR("Object is NULL"); @@ -434,7 +432,7 @@ mtp_uint32 _entity_get_objects_from_store(mtp_store_t *store, return 0; } - while(UTIL_CHECK_LIST_NEXT(iter) == TRUE) { + while (UTIL_CHECK_LIST_NEXT(iter) == TRUE) { obj = (mtp_obj_t *)_util_get_list_next(iter); if (obj == NULL) { @@ -444,7 +442,7 @@ mtp_uint32 _entity_get_objects_from_store(mtp_store_t *store, if ((fmt == obj->obj_info->obj_fmt) || (fmt == PTP_FORMATCODE_ALL) || (fmt == PTP_FORMATCODE_NOTUSED)) { - _prop_append_ele_ptparray(obj_arr, (mtp_uint32)obj); + _prop_append_ele_ptparray(obj_arr, obj->obj_handle); } } _util_deinit_list_iterator(iter); @@ -455,8 +453,6 @@ mtp_uint32 _entity_get_objects_from_store_till_depth(mtp_store_t *store, mtp_uint32 obj_handle, mtp_uint32 fmt_code, mtp_uint32 depth, ptp_array_t *obj_arr) { - mtp_obj_t *obj = NULL; - retv_if(store == NULL, 0); retv_if(obj_arr == NULL, 0); @@ -467,12 +463,9 @@ mtp_uint32 _entity_get_objects_from_store_till_depth(mtp_store_t *store, return obj_arr->num_ele; } - if (PTP_OBJECTHANDLE_ROOT != obj_handle) { - obj = _entity_get_object_from_store(store, obj_handle); - if (obj) { - _prop_append_ele_ptparray(obj_arr, (mtp_uint32)obj); - } - } + if (PTP_OBJECTHANDLE_ROOT != obj_handle) + _prop_append_ele_ptparray(obj_arr, obj_handle); + if (depth > 0) { ptp_array_t *child_arr = NULL; mtp_uint32 *ptr = NULL; @@ -515,7 +508,7 @@ mtp_uint32 _entity_get_objects_from_store_by_format(mtp_store_t *store, return 0; } - while(UTIL_CHECK_LIST_NEXT(iter) == TRUE) { + while (UTIL_CHECK_LIST_NEXT(iter) == TRUE) { obj = (mtp_obj_t *)_util_get_list_next(iter); if (obj == NULL || obj->obj_info == NULL) @@ -544,9 +537,8 @@ mtp_uint32 _entity_get_num_object_with_same_format(mtp_store_t *store, retv_if(store == NULL, 0); - if (PTP_FORMATCODE_NOTUSED == format) { + if (PTP_FORMATCODE_NOTUSED == format) return store->obj_list.nnodes; - } iter = (slist_iterator *)_util_init_list_iterator(&(store->obj_list)); if (iter == NULL) { @@ -554,7 +546,7 @@ mtp_uint32 _entity_get_num_object_with_same_format(mtp_store_t *store, return 0; } - while(UTIL_CHECK_LIST_NEXT(iter) == TRUE) { + while (UTIL_CHECK_LIST_NEXT(iter) == TRUE) { obj = (mtp_obj_t *)_util_get_list_next(iter); if (obj == NULL || obj->obj_info == NULL) @@ -586,7 +578,7 @@ mtp_uint32 _entity_get_num_children(mtp_store_t *store, mtp_uint32 h_parent, return 0; } - while(UTIL_CHECK_LIST_NEXT(iter) == TRUE) { + while (UTIL_CHECK_LIST_NEXT(iter) == TRUE) { obj = (mtp_obj_t *)_util_get_list_next(iter); if (obj == NULL || obj->obj_info == NULL) @@ -629,15 +621,14 @@ mtp_uint32 _entity_get_child_handles(mtp_store_t *store, mtp_uint32 h_parent, return 0; } - while(UTIL_CHECK_LIST_NEXT(iter) == TRUE) { + while (UTIL_CHECK_LIST_NEXT(iter) == TRUE) { obj = (mtp_obj_t *)_util_get_list_next(iter); if (obj == NULL || obj->obj_info == NULL) continue; - if (obj->obj_info->h_parent == h_parent) { + if (obj->obj_info->h_parent == h_parent) _prop_append_ele_ptparray(child_arr, obj->obj_handle); - } } _util_deinit_list_iterator(iter); @@ -659,7 +650,7 @@ mtp_uint32 _entity_get_child_handles_with_same_format(mtp_store_t *store, return 0; } - while(UTIL_CHECK_LIST_NEXT(iter) == TRUE) { + while (UTIL_CHECK_LIST_NEXT(iter) == TRUE) { obj = (mtp_obj_t *)_util_get_list_next(iter); if (obj == NULL || obj->obj_info == NULL) @@ -752,9 +743,9 @@ mtp_bool _entity_remove_object_mtp_store(mtp_store_t *store, mtp_obj_t *obj, child_obj = _entity_get_object_from_store(store, ptr32[i]); - if (NULL == child_obj) { + if (NULL == child_obj) continue; - } + if (_entity_remove_object_mtp_store(store, child_obj, format, response, atleast_one, read_only)) { @@ -803,7 +794,7 @@ mtp_bool _entity_remove_object_mtp_store(mtp_store_t *store, mtp_obj_t *obj, DBG_SECURE("Folder[%s] contains only read-only files\n", obj->file_path); all_del = FALSE; - } else if (num_of_deleted_file < num_of_file){ + } else if (num_of_deleted_file < num_of_file) { DBG("num of files[%d] is present in folder[%s]\ and number of deleted files[%d]\n", num_of_file, obj->file_path, @@ -872,7 +863,7 @@ mtp_bool _entity_remove_object_mtp_store(mtp_store_t *store, mtp_obj_t *obj, obj->obj_handle); } } - } else if(*atleast_one) { + } else if (*atleast_one) { *response = PTP_RESPONSE_PARTIAL_DELETION; return FALSE; } else { @@ -977,9 +968,9 @@ mtp_uint16 _entity_delete_obj_mtp_store(mtp_store_t *store, } } - if (all_del) { + if (all_del) response = PTP_RESPONSE_OK; - } else if (atleas_one) + else if (atleas_one) response = PTP_RESPONSE_PARTIAL_DELETION; return response; @@ -1148,9 +1139,9 @@ void _entity_store_recursive_enum_folder_objects(mtp_store_t *store, do { if (TRUE == _transport_get_usb_discon_state()) { DBG("USB is disconnected"); - if (closedir(h_dir) < 0) { + if (closedir(h_dir) < 0) ERR("Close directory Fail"); - } + return; } @@ -1183,9 +1174,9 @@ NEXT: &entry); } while (status); - if (closedir(h_dir) < 0) { + if (closedir(h_dir) < 0) ERR("close directory fail"); - } + #ifdef MTP_SUPPORT_OBJECTADDDELETE_EVENT _inoti_add_watch_for_fs_events(folder_name); #endif /*MTP_SUPPORT_OBJECTADDDELETE_EVENT*/ diff --git a/src/mtp_cmd_handler.c b/src/mtp_cmd_handler.c index 282ac32..acaa3e4 100755 --- a/src/mtp_cmd_handler.c +++ b/src/mtp_cmd_handler.c @@ -114,9 +114,8 @@ static void __finish_receiving_file_packets(mtp_char *data, mtp_int32 data_len); */ void _cmd_hdlr_reset_cmd(mtp_handler_t *hdlr) { - if (hdlr->data4_send_obj.obj != NULL) { + if (hdlr->data4_send_obj.obj != NULL) _entity_dealloc_mtp_obj(hdlr->data4_send_obj.obj); - } memset(hdlr, 0x00, sizeof(mtp_handler_t)); @@ -460,8 +459,7 @@ static void __get_storage_ids(mtp_handler_t *hdlr) _prop_init_ptparray(&ids, UINT32_TYPE); - if (_hutil_get_storage_ids(&ids) == MTP_ERROR_NONE) - { + if (_hutil_get_storage_ids(&ids) == MTP_ERROR_NONE) { _hdlr_init_data_container(&blk, hdlr->usb_cmd.code, hdlr->usb_cmd.tid); num_bytes = _prop_get_size_ptparray(&ids); @@ -563,11 +561,10 @@ static void __get_num_objects(mtp_handler_t *hdlr) resp = PTP_RESPONSE_GEN_ERROR; } - if (resp == PTP_RESPONSE_OK) { + if (resp == PTP_RESPONSE_OK) _cmd_hdlr_send_response(hdlr, resp, 1, (mtp_uint32 *)&num_obj); - } else { + else _cmd_hdlr_send_response_code(hdlr, resp); - } } static void __get_object_handles(mtp_handler_t *hdlr) @@ -701,7 +698,7 @@ static void __get_object(mtp_handler_t *hdlr) mtp_uint16 resp = PTP_RESPONSE_OK; mtp_uint32 packet_len; mtp_uint32 read_len = 0; - mtp_uint32 h_file = INVALID_FILE; + FILE* h_file = NULL; mtp_int32 error = 0; if (_hdlr_get_param_cmd_container(&(hdlr->usb_cmd), 1) || @@ -745,7 +742,7 @@ static void __get_object(mtp_handler_t *hdlr) _device_set_phase(DEVICE_PHASE_DATAIN); h_file = _util_file_open(path, MTP_FILE_READ, &error); - if (h_file == INVALID_FILE) { + if (h_file == NULL) { ERR("_util_file_open() Fail"); _device_set_phase(DEVICE_PHASE_NOTREADY); if (EACCES == error) { @@ -801,9 +798,8 @@ static void __get_object(mtp_handler_t *hdlr) sent += read_len; } - if (total_len % ((mtp_uint64)_transport_get_usb_packet_len()) == 0) { + if (total_len % ((mtp_uint64)_transport_get_usb_packet_len()) == 0) _transport_send_zlp(); - } Done: _util_file_close(h_file); @@ -825,16 +821,16 @@ static void __send_object_info(mtp_handler_t *hdlr) obj_data_t obdata = { 0 }; store_id = _hdlr_get_param_cmd_container(&(hdlr->usb_cmd), 0); - if (store_id == 0) { + if (store_id == 0) store_id = _device_get_default_store_id(); - } + h_parent = _hdlr_get_param_cmd_container(&(hdlr->usb_cmd), 1); if (_hdlr_get_param_cmd_container(&(hdlr->usb_cmd), 2)) { resp = PTP_RESPONSE_PARAM_NOTSUPPORTED; - if (_device_get_phase() != DEVICE_PHASE_NOTREADY) { + if (_device_get_phase() != DEVICE_PHASE_NOTREADY) _cmd_hdlr_send_response_code(hdlr, resp); - } + return; } @@ -1183,7 +1179,7 @@ static void __get_device_prop_desc(mtp_handler_t *hdlr) } case MTP_PROPERTYCODE_DEVICEICON: { - mtp_uint32 h_file; + FILE* h_file; mtp_uint32 bytes_read = 0; mtp_uint32 file_size = 0; struct stat buf; @@ -1197,7 +1193,7 @@ static void __get_device_prop_desc(mtp_handler_t *hdlr) } h_file = _util_file_open(MTP_DEVICE_ICON, MTP_FILE_READ, &err); - if (h_file == INVALID_FILE) { + if (h_file == NULL) { ERR("file handle is not valid"); _cmd_hdlr_send_response_code(hdlr, PTP_RESPONSE_GEN_ERROR); @@ -1291,7 +1287,7 @@ static void __get_device_prop_value(mtp_handler_t *hdlr) prop_id = _hdlr_get_param_cmd_container(&(hdlr->usb_cmd), 0); _hdlr_init_data_container(&blk, hdlr->usb_cmd.code, hdlr->usb_cmd.tid); - switch(prop_id) { + switch (prop_id) { #ifdef MTP_SUPPORT_DEVICEPROP_BATTERYLEVEL case PTP_PROPERTYCODE_BATTERYLEVEL: { mtp_int32 batt = 0; @@ -1380,7 +1376,7 @@ static void __get_device_prop_value(mtp_handler_t *hdlr) case MTP_PROPERTYCODE_DEVICEICON: { - mtp_uint32 h_file; + FILE *h_file; mtp_uint32 read_bytes = 0; mtp_uint32 file_size = 0; struct stat buf; @@ -1390,13 +1386,13 @@ static void __get_device_prop_value(mtp_handler_t *hdlr) mtp_uint32 ii; h_file = _util_file_open(MTP_DEVICE_ICON, MTP_FILE_READ, &err); - if (h_file == INVALID_FILE) { + if (h_file == NULL) { ERR("file handle is not valid"); _cmd_hdlr_send_response_code(hdlr, PTP_RESPONSE_GEN_ERROR); return; } - if (fstat(fileno((FILE *)h_file), &buf) != 0) { + if (fstat(fileno(h_file), &buf) != 0) { _util_file_close(h_file); _cmd_hdlr_send_response_code(hdlr, PTP_RESPONSE_GEN_ERROR); @@ -1425,9 +1421,8 @@ static void __get_device_prop_value(mtp_handler_t *hdlr) _prop_init_ptparray(&val_arr, UINT8_TYPE); _prop_grow_ptparray(&val_arr, read_bytes); - for (ii = 0; ii < read_bytes; ii++) { + for (ii = 0; ii < read_bytes; ii++) _prop_append_ele_ptparray(&val_arr, data[ii]); - } no_bytes = _prop_get_size_ptparray(&val_arr); ptr = _hdlr_alloc_buf_data_container(&blk, no_bytes, no_bytes); @@ -1654,7 +1649,7 @@ static void __get_object_references(mtp_handler_t *hdlr) case MTP_ERROR_NONE: resp = PTP_RESPONSE_OK; break; - default : + default: resp = PTP_RESPONSE_GEN_ERROR; } @@ -1729,9 +1724,8 @@ static void __set_object_references(mtp_handler_t *hdlr) } ptr = _hdlr_get_payload_data(&blk); - if (ptr == NULL) { + if (ptr == NULL) return; - } memcpy(&num_ref, ptr, sizeof(mtp_uint32)); #ifdef __BIG_ENDIAN__ @@ -2022,7 +2016,6 @@ static void __get_object_prop_list(mtp_handler_t *hdlr) slist_node_t *next_node = NULL; mtp_uint32 ii = 0; mtp_uint32 jj = 0; - mtp_obj_t **ptr_array = NULL; mtp_obj_t *obj = NULL; #endif /*MTP_USE_RUNTIME_GETOBJECTPROPVALUE*/ @@ -2085,13 +2078,19 @@ static void __get_object_prop_list(mtp_handler_t *hdlr) #ifdef MTP_USE_RUNTIME_GETOBJECTPROPVALUE if (resp == PTP_RESPONSE_OK && obj_arr.array_entry) { - ptr_array = obj_arr.array_entry; + mtp_uint32 *obj_handles = obj_arr.array_entry; for (ii = 0; ii < obj_arr.num_ele; ii++) { - obj = ptr_array[ii]; - if (NULL == obj || obj->propval_list.nnodes == 0) { + mtp_store_t *store = NULL; + + store = _device_get_store_containing_obj(obj_handles[ii]); + if (store == NULL) continue; - } + + obj = _entity_get_object_from_store(store, obj_handles[ii]); + if (NULL == obj || obj->propval_list.nnodes == 0) + continue; + /*Remove all the old property value, and ready to set up new */ for (jj = 0, next_node = obj->propval_list.start; jj < obj->propval_list.nnodes; jj++) { @@ -2273,7 +2272,7 @@ static void __report_acquired_content(mtp_handler_t *hdlr) mtp_uint32 num_bytes = 0; mtp_uint32 num_lines = 0; mtp_uint32 rem_modified = 0; - mtp_uint32 h_file; + FILE* h_file; time_t cur_time; time_t l_time; mtp_int32 diff_time; @@ -2295,9 +2294,9 @@ static void __report_acquired_content(mtp_handler_t *hdlr) if (tid == 0) { if (access(MTP_FILES_MODIFIED_FILES, F_OK) == 0) - if (remove(MTP_FILES_MODIFIED_FILES) < 0) { + if (remove(MTP_FILES_MODIFIED_FILES) < 0) ERR("remove(%s) Fail", MTP_FILES_MODIFIED_FILES); - } + resp = PTP_RESPONSE_OK; _prop_grow_ptparray(&guid_arr, 1); _prop_append_ele_ptparray(&guid_arr, 0); @@ -2328,7 +2327,7 @@ static void __report_acquired_content(mtp_handler_t *hdlr) } h_file = _util_file_open(MTP_FILES_MODIFIED_FILES, MTP_FILE_READ, &err); - if (h_file == INVALID_FILE) { + if (h_file == NULL) { resp = PTP_RESPONSE_GEN_ERROR; _prop_init_ptparray(&guid_arr, UINT32_TYPE); _prop_append_ele_ptparray(&guid_arr, 0); @@ -2344,7 +2343,7 @@ static void __report_acquired_content(mtp_handler_t *hdlr) max_size : num_lines - start_idx; rem_modified = (num_lines - start_idx > max_size) ? - (num_lines - start_idx- max_size) : 0; + (num_lines - start_idx - max_size) : 0; g_has_round_trip = FALSE; _prop_init_ptparray(&guid_arr, UINT32_TYPE); @@ -2354,9 +2353,9 @@ static void __report_acquired_content(mtp_handler_t *hdlr) _util_file_close(h_file); if (rem_modified == 0) { - if (remove(MTP_FILES_MODIFIED_FILES) < 0) { + if (remove(MTP_FILES_MODIFIED_FILES) < 0) ERR("remove(%s) Fail", MTP_FILES_MODIFIED_FILES); - } + g_mgr->meta_info.mod = 0; } @@ -2370,11 +2369,10 @@ DONE: _device_set_phase(DEVICE_PHASE_DATAIN); } - if (_hdlr_send_data_container(&blk)) { + if (_hdlr_send_data_container(&blk)) resp = PTP_RESPONSE_OK; - } else { + else resp = PTP_RESPONSE_GEN_ERROR; - } _prop_deinit_ptparray(&guid_arr); g_free(blk.data); @@ -2397,9 +2395,9 @@ static void __send_playback_skip(mtp_handler_t *hdlr) mtp_uint16 resp = PTP_RESPONSE_INVALIDPARAM; skip = (mtp_int32) _hdlr_get_param_cmd_container(&(hdlr->usb_cmd), 0); - if (MTP_ERROR_NONE == _hutil_get_playback_skip(skip)) { + if (MTP_ERROR_NONE == _hutil_get_playback_skip(skip)) resp = PTP_RESPONSE_OK; - } + _cmd_hdlr_send_response_code(hdlr, resp); return; } @@ -2583,11 +2581,10 @@ static void __copy_object(mtp_handler_t *hdlr) } _transport_set_mtp_operation_state(MTP_STATE_ONSERVICE); - if (resp == PTP_RESPONSE_OK) { + if (resp == PTP_RESPONSE_OK) _cmd_hdlr_send_response(hdlr, resp, 1, &new_handle); - } else { + else _cmd_hdlr_send_response_code(hdlr, resp); - } return; } @@ -2630,11 +2627,10 @@ static void __reset_device_prop_value(mtp_handler_t *hdlr) prop->current_val.str->str); _device_set_sync_partner(temp); - if (!g_strcmp0(temp, MTP_DEV_PROPERTY_NULL_SYNCPARTNER)) { + if (!g_strcmp0(temp, MTP_DEV_PROPERTY_NULL_SYNCPARTNER)) vconf_set_str(VCONFKEY_MTP_SYNC_PARTNER_STR, ""); - } else { + else vconf_set_str(VCONFKEY_MTP_SYNC_PARTNER_STR, temp); - } } _cmd_hdlr_send_response_code(hdlr, PTP_RESPONSE_OK); @@ -2745,11 +2741,10 @@ static void __send_object_prop_list(mtp_handler_t *hdlr) idx = 0; if (store_id) { - if (!h_parent) { + if (!h_parent) h_parent = _device_get_default_parent_handle(); - } else if (h_parent == 0xFFFFFFFF) { + else if (h_parent == 0xFFFFFFFF) h_parent = PTP_OBJECTHANDLE_ROOT; - } } else { store_id = _device_get_default_store_id(); if (!store_id) @@ -2874,9 +2869,8 @@ static void __send_object_prop_list(mtp_handler_t *hdlr) } if (PTP_RESPONSE_OK != resp) { - if (hdlr->data4_send_obj.obj) { + if (hdlr->data4_send_obj.obj) _entity_dealloc_mtp_obj(hdlr->data4_send_obj.obj); - } hdlr->data4_send_obj.obj = NULL; hdlr->data4_send_obj.is_valid = FALSE; @@ -2958,128 +2952,128 @@ mtp_bool _cmd_hdlr_send_response_code(mtp_handler_t *hdlr, mtp_uint16 resp) #ifdef MTP_SUPPORT_PRINT_COMMAND static void __print_command(mtp_uint16 code) { - switch(code) { - case PTP_OPCODE_GETDEVICEINFO : + switch (code) { + case PTP_OPCODE_GETDEVICEINFO: DBG("COMMAND ======== GET DEVICE INFO==========="); break; - case PTP_OPCODE_OPENSESSION : + case PTP_OPCODE_OPENSESSION: DBG("COMMAND ======== OPEN SESSION ==========="); break; - case PTP_OPCODE_CLOSESESSION : + case PTP_OPCODE_CLOSESESSION: DBG("COMMAND ======== CLOSE SESSION ==========="); break; - case PTP_OPCODE_GETSTORAGEIDS : + case PTP_OPCODE_GETSTORAGEIDS: DBG("COMMAND ======== GET STORAGE IDS ==========="); break; - case PTP_OPCODE_GETSTORAGEINFO : + case PTP_OPCODE_GETSTORAGEINFO: DBG("COMMAND ======== GET STORAGE INFO ==========="); break; - case PTP_OPCODE_GETNUMOBJECTS : + case PTP_OPCODE_GETNUMOBJECTS: DBG("COMMAND ======== GET NUM OBJECTS ==========="); break; - case PTP_OPCODE_GETOBJECTHANDLES : + case PTP_OPCODE_GETOBJECTHANDLES: DBG("COMMAND ======== GET OBJECT HANDLES ==========="); break; - case PTP_OPCODE_GETOBJECTINFO : + case PTP_OPCODE_GETOBJECTINFO: DBG("COMMAND ======== GET OBJECT INFO ==========="); break; - case PTP_OPCODE_GETOBJECT : + case PTP_OPCODE_GETOBJECT: DBG("COMMAND ======== GET OBJECT ==========="); break; - case PTP_OPCODE_DELETEOBJECT : + case PTP_OPCODE_DELETEOBJECT: DBG("COMMAND ======== DELETE OBJECT ==========="); break; - case PTP_OPCODE_SENDOBJECTINFO : + case PTP_OPCODE_SENDOBJECTINFO: DBG("COMMAND ======== SEND OBJECT INFO ==========="); break; - case PTP_OPCODE_SENDOBJECT : + case PTP_OPCODE_SENDOBJECT: DBG("COMMAND ======== SEND OBJECT ==========="); break; - case PTP_OPCODE_INITIATECAPTURE : + case PTP_OPCODE_INITIATECAPTURE: DBG("COMMAND ======== INITIATE CAPTURE ==========="); break; - case PTP_OPCODE_FORMATSTORE : + case PTP_OPCODE_FORMATSTORE: DBG("COMMAND ======== FORMAT STORE ==========="); break; - case PTP_OPCODE_RESETDEVICE : + case PTP_OPCODE_RESETDEVICE: DBG("COMMAND ======== RESET DEVICE ==========="); break; - case PTP_OPCODE_SELFTEST : + case PTP_OPCODE_SELFTEST: DBG("COMMAND ======== SELF TEST ==========="); break; - case PTP_OPCODE_SETOBJECTPROTECTION : + case PTP_OPCODE_SETOBJECTPROTECTION: DBG("COMMAND ======== SET OBJECT PROTECTION ==========="); break; - case PTP_OPCODE_POWERDOWN : + case PTP_OPCODE_POWERDOWN: DBG("COMMAND ======== POWER DOWN ==========="); break; - case PTP_OPCODE_GETDEVICEPROPDESC : + case PTP_OPCODE_GETDEVICEPROPDESC: DBG("COMMAND ======== GET DEVICE PROP DESC ==========="); break; - case PTP_OPCODE_GETDEVICEPROPVALUE : + case PTP_OPCODE_GETDEVICEPROPVALUE: DBG("COMMAND ======== GET DEVICE PROP VALUE ==========="); break; - case PTP_OPCODE_SETDEVICEPROPVALUE : + case PTP_OPCODE_SETDEVICEPROPVALUE: DBG("COMMAND ======== SET DEVICE PROP VALUE ==========="); break; - case PTP_OPCODE_RESETDEVICEPROPVALUE : + case PTP_OPCODE_RESETDEVICEPROPVALUE: DBG("COMMAND ======== RESET DEVICE PROP VALUE ==========="); break; - case PTP_OPCODE_TERMINATECAPTURE : + case PTP_OPCODE_TERMINATECAPTURE: DBG("COMMAND ======== TERMINATE CAPTURE ==========="); break; - case PTP_OPCODE_MOVEOBJECT : + case PTP_OPCODE_MOVEOBJECT: DBG("COMMAND ======== MOVE OBJECT ==========="); break; - case PTP_OPCODE_COPYOBJECT : + case PTP_OPCODE_COPYOBJECT: DBG("COMMAND ======== COPY OBJECT ==========="); break; - case PTP_OPCODE_GETPARTIALOBJECT : + case PTP_OPCODE_GETPARTIALOBJECT: DBG("COMMAND ======== GET PARTIAL OBJECT ==========="); break; - case PTP_OPCODE_INITIATEOPENCAPTURE : + case PTP_OPCODE_INITIATEOPENCAPTURE: DBG("COMMAND ======== INITIATE OPEN CAPTURE ==========="); break; - case MTP_OPCODE_WMP_UNDEFINED : + case MTP_OPCODE_WMP_UNDEFINED: DBG("COMMAND ======== WMP UNDEFINED =========="); break; - case MTP_OPCODE_WMP_REPORTACQUIREDCONTENT : + case MTP_OPCODE_WMP_REPORTACQUIREDCONTENT: DBG("COMMAND ======= REPORT ACQUIRED CONTENT ========="); break; - case MTP_OPCODE_GETOBJECTPROPSUPPORTED : + case MTP_OPCODE_GETOBJECTPROPSUPPORTED: DBG("COMMAND ======= GET OBJECT PROP SUPPORTED ========"); break; - case MTP_OPCODE_GETOBJECTPROPDESC : + case MTP_OPCODE_GETOBJECTPROPDESC: DBG("COMMAND ======== GET OBJECT PROP DESC =========="); break; - case MTP_OPCODE_GETOBJECTPROPVALUE : + case MTP_OPCODE_GETOBJECTPROPVALUE: DBG("COMMAND ======== GET OBJECT PROP VALUE =========="); break; - case MTP_OPCODE_SETOBJECTPROPVALUE : + case MTP_OPCODE_SETOBJECTPROPVALUE: DBG("COMMAND ======== SET OBJECT PROP VALUE =========="); break; - case MTP_OPCODE_GETOBJECTPROPLIST : + case MTP_OPCODE_GETOBJECTPROPLIST: DBG("COMMAND ======== GET OBJECT PROP LIST =========="); break; - case MTP_OPCODE_SETOBJECTPROPLIST : + case MTP_OPCODE_SETOBJECTPROPLIST: DBG("COMMAND ======== SET OBJECT PROP LIST =========="); break; - case MTP_OPCODE_GETINTERDEPPROPDESC : + case MTP_OPCODE_GETINTERDEPPROPDESC: DBG("COMMAND ======== GET INTERDEP PROP DESC =========="); break; - case MTP_OPCODE_SENDOBJECTPROPLIST : + case MTP_OPCODE_SENDOBJECTPROPLIST: DBG("COMMAND ======== SEND OBJECT PROP LIST =========="); break; - case MTP_OPCODE_GETOBJECTREFERENCES : + case MTP_OPCODE_GETOBJECTREFERENCES: DBG("COMMAND ======== GET OBJECT REFERENCES =========="); break; - case MTP_OPCODE_SETOBJECTREFERENCES : + case MTP_OPCODE_SETOBJECTREFERENCES: DBG("COMMAND ======== SET OBJECT REFERENCES =========="); break; - case MTP_OPCODE_PLAYBACK_SKIP : + case MTP_OPCODE_PLAYBACK_SKIP: DBG("COMMAND ======== PLAYBACK SKIP =========="); break; - default : + default: DBG("======== UNKNOWN COMMAND =========="); break; } @@ -3190,14 +3184,13 @@ void _receive_mq_data_cb(mtp_char *buffer, mtp_int32 buf_len) _transport_set_control_event(0); _transport_set_mtp_operation_state(MTP_STATE_ONSERVICE); - if (g_mgr->ftemp_st.fhandle != INVALID_FILE) { + if (g_mgr->ftemp_st.fhandle != NULL) { DBG("In Cancel Transaction fclose "); _util_file_close(g_mgr->ftemp_st.fhandle); - g_mgr->ftemp_st.fhandle = INVALID_FILE; + g_mgr->ftemp_st.fhandle = NULL; DBG("In Cancel Transaction, remove "); - if (remove(g_mgr->ftemp_st.filepath) < 0) { + if (remove(g_mgr->ftemp_st.filepath) < 0) ERR_SECURE("remove(%s) Fail", g_mgr->ftemp_st.filepath); - } } else { DBG("g_mgr->ftemp_st.fhandle is not valid, return"); } @@ -3259,16 +3252,15 @@ static mtp_bool __receive_temp_file_first_packet(mtp_char *data, mtp_int32 data_len) { mtp_char *filepath = g_mgr->ftemp_st.filepath; - mtp_uint32 *fhandle = &g_mgr->ftemp_st.fhandle; mtp_int32 error = 0; mtp_uint32 *data_sz = &g_mgr->ftemp_st.data_size; mtp_char *buffer = g_mgr->ftemp_st.temp_buff; _transport_set_mtp_operation_state(MTP_STATE_DATA_TRANSFER_DL); if (access(filepath, F_OK) == 0) { - if (*fhandle != INVALID_FILE) { - _util_file_close(*fhandle); - *fhandle = INVALID_FILE; /* initialize */ + if (g_mgr->ftemp_st.fhandle != NULL) { + _util_file_close(g_mgr->ftemp_st.fhandle); + g_mgr->ftemp_st.fhandle = NULL; /* initialize */ } if (remove(filepath) < 0) { @@ -3278,8 +3270,8 @@ static mtp_bool __receive_temp_file_first_packet(mtp_char *data, } } - *fhandle = _util_file_open(filepath, MTP_FILE_WRITE, &error); - if (*fhandle == INVALID_FILE) { + g_mgr->ftemp_st.fhandle = _util_file_open(filepath, MTP_FILE_WRITE, &error); + if (g_mgr->ftemp_st.fhandle == NULL) { ERR("First file handle is invalid!!"); __finish_receiving_file_packets(data, data_len); return FALSE; @@ -3293,14 +3285,14 @@ static mtp_bool __receive_temp_file_first_packet(mtp_char *data, /* check whether last data packet */ if (*data_sz == g_mgr->ftemp_st.file_size) { - if (_util_file_write(*fhandle, &data[sizeof(header_container_t)], + if (_util_file_write(g_mgr->ftemp_st.fhandle, &data[sizeof(header_container_t)], data_len - sizeof(header_container_t)) != data_len - sizeof(header_container_t)) { ERR("fwrite error!"); } *data_sz = 0; - _util_file_close(*fhandle); - *fhandle = INVALID_FILE; /* initialize */ + _util_file_close(g_mgr->ftemp_st.fhandle); + g_mgr->ftemp_st.fhandle = NULL; /* initialize */ __finish_receiving_file_packets(data, data_len); } else { g_mgr->ftemp_st.data_count++; @@ -3317,14 +3309,13 @@ static mtp_bool __receive_temp_file_next_packets(mtp_char *data, mtp_uint32 rx_size = _get_rx_pkt_size(); mtp_uint32 *data_sz = &g_mgr->ftemp_st.data_size; mtp_char *buffer = g_mgr->ftemp_st.temp_buff; - mtp_uint32 *fhandle = &g_mgr->ftemp_st.fhandle; g_mgr->ftemp_st.data_count++; g_mgr->ftemp_st.size_remaining += data_len; if ((*data_sz + (mtp_uint32)data_len) > g_conf.write_file_size) { /* copy oversized packet to temp file */ - if (_util_file_write(*fhandle, buffer, *data_sz) != *data_sz) + if (_util_file_write(g_mgr->ftemp_st.fhandle, buffer, *data_sz) != *data_sz) ERR("fwrite error writeSize=[%u]\n", *data_sz); *data_sz = 0; @@ -3337,12 +3328,12 @@ static mtp_bool __receive_temp_file_next_packets(mtp_char *data, if (data_len < rx_size || g_mgr->ftemp_st.size_remaining == g_mgr->ftemp_st.file_size) { - if (_util_file_write(*fhandle, buffer, *data_sz) != *data_sz) { + if (_util_file_write(g_mgr->ftemp_st.fhandle, buffer, *data_sz) != *data_sz) ERR("fwrite error write size=[%u]\n", *data_sz); - } + *data_sz = 0; - _util_file_close(*fhandle); - *fhandle = INVALID_FILE; /* initialize */ + _util_file_close(g_mgr->ftemp_st.fhandle); + g_mgr->ftemp_st.fhandle = NULL; __finish_receiving_file_packets(data, data_len); } return TRUE; diff --git a/src/mtp_cmd_handler_util.c b/src/mtp_cmd_handler_util.c index c802fcf..2e265af 100755 --- a/src/mtp_cmd_handler_util.c +++ b/src/mtp_cmd_handler_util.c @@ -80,9 +80,8 @@ mtp_err_t _hutil_get_storage_ids(ptp_array_t *store_ids) num_elem = _device_get_store_ids(store_ids); num_stores = _device_get_num_stores(); - if (num_elem == num_stores) { + if (num_elem == num_stores) return MTP_ERROR_NONE; - } ERR("get storage id Fail. num_elem[%d], num_stores[%d]\n", num_elem, num_stores); @@ -153,9 +152,8 @@ mtp_err_t _hutil_reset_device_entry(mtp_uint32 prop_id) ERR("property reference is NULL"); return MTP_ERROR_GENERAL; } - for (ii = 0; ii < NUM_DEVICE_PROPERTIES; ii++) { + for (ii = 0; ii < NUM_DEVICE_PROPERTIES; ii++) _prop_reset_device_prop_desc(&prop[ii]); - } } else { prop = _device_get_device_property(prop_id); if (prop == NULL) @@ -444,10 +442,10 @@ mtp_err_t _hutil_add_object_entry(obj_info_t *obj_info, mtp_char *file_name, obj_info->association_type != PTP_ASSOCIATIONTYPE_FOLDER) || is_made_by_mtp) { - mtp_uint32 h_abs_file = INVALID_FILE; + FILE* h_abs_file = NULL; h_abs_file = _util_file_open(new_f_path, MTP_FILE_WRITE, &error); - if (h_abs_file == INVALID_FILE) { + if (h_abs_file == NULL) { ERR("create file fail!!"); _entity_dealloc_mtp_obj(obj); return MTP_ERROR_GENERAL; @@ -532,7 +530,7 @@ mtp_err_t _hutil_remove_object_entry(mtp_uint32 obj_handle, mtp_uint32 format) resp = MTP_ERROR_ACCESS_DENIED; break; case PTP_RESPONSE_INVALID_OBJ_HANDLE: - resp =MTP_ERROR_INVALID_OBJECTHANDLE; + resp = MTP_ERROR_INVALID_OBJECTHANDLE; break; default: break; @@ -553,9 +551,8 @@ mtp_err_t _hutil_get_object_entry(mtp_uint32 obj_handle, mtp_obj_t **obj_ptr) mtp_obj_t *obj = NULL; obj = _device_get_object_with_handle(obj_handle); - if (NULL == obj || NULL == obj->obj_info) { + if (NULL == obj || NULL == obj->obj_info) return MTP_ERROR_GENERAL; - } *obj_ptr = obj; return MTP_ERROR_NONE; @@ -788,9 +785,8 @@ mtp_err_t _hutil_copy_object_entries(mtp_uint32 dst_store_id, mtp_uint32 *ptr32 = child_arr.array_entry; child_obj = _entity_get_object_from_store(src, ptr32[ii]); - if (child_obj == NULL) { + if (child_obj == NULL) continue; - } ret = _hutil_copy_object_entries(dst_store_id, src_store_id, new_obj->obj_handle, child_obj->obj_handle, @@ -1097,7 +1093,7 @@ mtp_err_t _hutil_duplicate_object_entry(mtp_uint32 dst_store_id, return MTP_ERROR_STORE_FULL; } - if((ret = _hutil_copy_object_entries(dst_store_id, src->store_id, + if ((ret = _hutil_copy_object_entries(dst_store_id, src->store_id, h_parent, obj_handle, new_handle, FALSE)) != MTP_ERROR_NONE) { return ret; } @@ -1111,11 +1107,10 @@ mtp_err_t _hutil_duplicate_object_entry(mtp_uint32 dst_store_id, return MTP_ERROR_GENERAL; } - if (new_obj->obj_info->obj_fmt == PTP_FMT_ASSOCIATION) { + if (new_obj->obj_info->obj_fmt == PTP_FMT_ASSOCIATION) _util_scan_folder_contents_in_db(new_obj->file_path); - } else { + else _util_add_file_to_db(new_obj->file_path); - } return MTP_ERROR_NONE; } @@ -1124,7 +1119,7 @@ mtp_err_t _hutil_read_file_data_from_offset(mtp_uint32 obj_handle, off_t offset, void *data, mtp_uint32 *data_sz) { mtp_obj_t *obj = NULL; - mtp_uint32 h_file = INVALID_FILE; + FILE* h_file = NULL; mtp_int32 error = 0; mtp_char fname[MTP_MAX_PATHNAME_SIZE + 1]; off_t result = 0; @@ -1145,7 +1140,7 @@ mtp_err_t _hutil_read_file_data_from_offset(mtp_uint32 obj_handle, off_t offset, g_strlcpy(fname, obj->file_path, MTP_MAX_PATHNAME_SIZE + 1); h_file = _util_file_open(fname, MTP_FILE_READ, &error); - if (h_file == INVALID_FILE) { + if (h_file == NULL) { ERR("file open Fail[%s]\n", fname); return MTP_ERROR_GENERAL; } @@ -1290,15 +1285,13 @@ mtp_err_t _hutil_set_protection(mtp_uint32 obj_handle, mtp_uint16 prot_status) return MTP_ERROR_GENERAL; } - if (MTP_FILE_ATTR_MODE_NONE == attrs.attribute) { + if (MTP_FILE_ATTR_MODE_NONE == attrs.attribute) return MTP_ERROR_GENERAL; - } - if (prot_status == PTP_PROTECTIONSTATUS_READONLY) { + if (prot_status == PTP_PROTECTIONSTATUS_READONLY) attrs.attribute |= MTP_FILE_ATTR_MODE_READ_ONLY; - } else { + else attrs.attribute &= ~MTP_FILE_ATTR_MODE_READ_ONLY; - } if (FALSE == _util_set_file_attrs(fname, attrs.attribute)) { ERR("Failed to set file[%s] attrs\n", fname); @@ -1452,11 +1445,10 @@ mtp_err_t _hutil_construct_object_entry(mtp_uint32 store_id, mtp_char file_name[MTP_MAX_FILENAME_SIZE + 1] = { 0 }; if (store_id) { - if (!h_parent) { + if (!h_parent) h_parent = _device_get_default_parent_handle(); - } else if (h_parent == 0xFFFFFFFF) { + else if (h_parent == 0xFFFFFFFF) h_parent = PTP_OBJECTHANDLE_ROOT; - } } else { store_id = _device_get_default_store_id(); @@ -1484,9 +1476,8 @@ mtp_err_t _hutil_construct_object_entry(mtp_uint32 store_id, } /* Delete and invalidate the old obj_info for send object */ - if (objdata->obj != NULL) { + if (objdata->obj != NULL) _entity_dealloc_mtp_obj(objdata->obj); - } } store = _device_get_store(store_id); @@ -1571,7 +1562,7 @@ mtp_err_t _hutil_construct_object_entry_prop_list(mtp_uint32 store_id, mtp_char alb_extn[MTP_MAX_EXTENSION_LENGTH + 1] = { 0 }; mtp_char *alb_buf = NULL; mtp_uint32 alb_sz = 0; - mtp_uint32 h_temp = INVALID_FILE; + FILE* h_temp = NULL; mtp_int32 error = 0; #endif /*MTP_SUPPORT_ALBUM_ART*/ mtp_char file_name[MTP_MAX_FILENAME_SIZE + 1] = { 0 }; @@ -1611,9 +1602,8 @@ mtp_err_t _hutil_construct_object_entry_prop_list(mtp_uint32 store_id, } obj_info->obj_fmt = format; - if (obj_info->obj_fmt == PTP_FMT_ASSOCIATION) { + if (obj_info->obj_fmt == PTP_FMT_ASSOCIATION) obj_info->association_type = PTP_ASSOCIATIONTYPE_FOLDER; - } obj_info->file_size = obj_sz; @@ -1706,9 +1696,9 @@ mtp_err_t _hutil_construct_object_entry_prop_list(mtp_uint32 store_id, /* Acquire object information related data. */ prop_val = _prop_alloc_obj_propval(prop_desc); - if (prop_val == NULL) { + if (prop_val == NULL) continue; - } + _prop_set_current_array_val(prop_val, temp, bytes_left); switch (prop_code) { case MTP_OBJ_PROPERTYCODE_WIDTH: @@ -1887,7 +1877,7 @@ mtp_err_t _hutil_construct_object_entry_prop_list(mtp_uint32 store_id, /* file write */ h_temp = _util_file_open(full_path, MTP_FILE_WRITE, &error); - if (h_temp != INVALID_FILE) { + if (h_temp != NULL) { _util_file_write(h_temp, alb_buf, sizeof(mtp_uchar) *alb_sz); _util_file_close(h_temp); @@ -1920,7 +1910,7 @@ mtp_err_t _hutil_get_object_prop_value(mtp_uint32 obj_handle, tobj = _device_get_object_with_handle(obj_handle); if (NULL == tobj) { - ERR("requested handle does not exist[0x%x]\n",obj_handle); + ERR("requested handle does not exist[0x%x]\n", obj_handle); return MTP_ERROR_INVALID_OBJECTHANDLE; } @@ -2073,9 +2063,8 @@ mtp_err_t _hutil_update_object_property(mtp_uint32 obj_handle, ERR("Propert [0x%x] is GETONLY\n", prop_code); } - if (prop_sz != NULL) { + if (prop_sz != NULL) *prop_sz = p_size; - } return MTP_ERROR_NONE; } @@ -2150,7 +2139,7 @@ mtp_err_t _hutil_get_object_prop_list(mtp_uint32 obj_handle, mtp_uint32 format, } _util_init_list(&(prop_list->prop_quad_list)); - _prop_init_ptparray(obj_arr, PTR_TYPE); + _prop_init_ptparray(obj_arr, UINT32_TYPE); if (store != NULL) { _entity_get_objects_from_store_till_depth(store, obj_handle, @@ -2164,11 +2153,10 @@ mtp_err_t _hutil_get_object_prop_list(mtp_uint32 obj_handle, mtp_uint32 format, } if (obj_arr->num_ele != 0) { - mtp_obj_t **ptr_obj; - ptr_obj = obj_arr->array_entry; + mtp_uint32 *obj_handles = obj_arr->array_entry; for (i = 0; i < obj_arr->num_ele; i++) { - obj = ptr_obj[i]; + obj = _entity_get_object_from_store(store, obj_handles[i]); if (!obj) continue; @@ -2201,9 +2189,8 @@ mtp_err_t _hutil_remove_object_reference(mtp_uint32 obj_handle, return MTP_ERROR_NONE; } - if (_entity_remove_reference_child_array(obj, ref_handle) == FALSE) { + if (_entity_remove_reference_child_array(obj, ref_handle) == FALSE) ERR("_entity_remove_reference_child_array Fail"); - } return MTP_ERROR_NONE; } @@ -2258,9 +2245,8 @@ mtp_err_t _hutil_get_object_references(mtp_uint32 obj_handle, for (idx = 0; idx < ref_arr.num_ele; idx++) { ref_obj = _device_get_object_with_handle(ref_ptr[idx]); - if (ref_obj == NULL) { + if (ref_obj == NULL) _entity_remove_reference_child_array(obj, ref_ptr[idx]); - } } *num_ele = obj->child_array.num_ele; @@ -2319,9 +2305,8 @@ mtp_err_t _hutil_get_playback_skip(mtp_int32 skip_param) return MTP_ERROR_GENERAL; } - if (obj_handle == 0x0) { + if (obj_handle == 0x0) return MTP_ERROR_NONE; - } obj = _device_get_object_with_handle(obj_handle); if (obj == NULL || obj->obj_info == NULL) { @@ -2343,13 +2328,12 @@ mtp_err_t _hutil_get_playback_skip(mtp_int32 skip_param) ref_arr = _entity_get_reference_child_array(par_obj); idx = _prop_find_ele_ptparray(ref_arr, obj_handle); if (idx != ELEMENT_NOT_FOUND) { - if (((long long)idx + (long long)skip_param) > UINT_MAX) { + if (((long long)idx + (long long)skip_param) > UINT_MAX) new_idx = ref_arr->num_ele - 1; - } else if ((idx + skip_param) >= ref_arr->num_ele) { + else if ((idx + skip_param) >= ref_arr->num_ele) new_idx = 0; - } else { + else new_idx = idx + skip_param; - } if (_prop_get_ele_ptparray(ref_arr, new_idx, (void *)(&new_hobj)) == TRUE) { @@ -2373,13 +2357,13 @@ mtp_err_t _hutil_get_playback_skip(mtp_int32 skip_param) } memcpy(&idx, dev_prop->current_val.integer, sizeof(mtp_uint32)); ref_arr = _entity_get_reference_child_array(obj); - if (((long long)idx + (long long)skip_param) > UINT_MAX) { + if (((long long)idx + (long long)skip_param) > UINT_MAX) new_idx = ref_arr->num_ele - 1; - } else if ((idx + skip_param) >= ref_arr->num_ele) { + else if ((idx + skip_param) >= ref_arr->num_ele) new_idx = 0; - } else { + else new_idx = idx + skip_param; - } + _prop_set_current_integer(dev_prop, new_idx); return MTP_ERROR_NONE; } @@ -2399,9 +2383,8 @@ mtp_err_t _hutil_format_storage(mtp_uint32 store_id, mtp_uint32 fs_format) } error = _entity_format_store(store, fs_format); - if (error == PTP_RESPONSE_OK) { + if (error == PTP_RESPONSE_OK) return MTP_ERROR_NONE; - } ERR("Format store Fail"); return error; diff --git a/src/mtp_event_handler.c b/src/mtp_event_handler.c index ccab66a..fa549c8 100755 --- a/src/mtp_event_handler.c +++ b/src/mtp_event_handler.c @@ -168,10 +168,10 @@ mtp_bool _eh_handle_usb_events(mtp_uint32 type) DBG("USB disconnected but temp file is remaind.\ It will be deleted."); - if (g_mgr->ftemp_st.fhandle != INVALID_FILE) { + if (g_mgr->ftemp_st.fhandle != NULL) { DBG("handle is found. At first close file"); _util_file_close(g_mgr->ftemp_st.fhandle); - g_mgr->ftemp_st.fhandle = INVALID_FILE; + g_mgr->ftemp_st.fhandle = NULL; } if (remove(g_mgr->ftemp_st.filepath) < 0) { ERR_SECURE("remove(%s) Fail", g_mgr->ftemp_st.filepath); @@ -261,7 +261,7 @@ static void *__thread_event_handler(void *arg) while (flag) { mtp_int32 status = 0; status = read(g_pipefd[0], &evt, sizeof(mtp_event_t)); - if(( status== -1) && errno == EINTR) { + if ((status == -1) && errno == EINTR) { ERR("read() Fail"); continue; } @@ -380,9 +380,8 @@ void _handle_lock_status_notification(keynode_t *key, void *data) previous_val = _util_get_local_lock_status(); _util_get_lock_status(¤t_val); - if (previous_val == current_val) { + if (previous_val == current_val) return; - } _util_set_local_lock_status(current_val); @@ -450,7 +449,7 @@ void _eh_send_event_req_to_eh_thread(event_code_t action, mtp_ulong param1, DBG("action[%d], param1[%ld], param2[%ld]\n", action, param1, param2); status = write(g_pipefd[1], &event, sizeof(mtp_event_t)); - if(status== -1 || errno == EINTR) { + if (status == -1 || errno == EINTR) { ERR("Event write over pipe Fail, status = [%d], pipefd = [%d], errno [%d]\n", status, g_pipefd[1], errno); } @@ -470,7 +469,7 @@ static mtp_bool __send_start_event_to_eh_thread(void) DBG("Action : START MTP OPERATION"); status = write(g_pipefd[1], &event, sizeof(mtp_event_t)); - if(status== -1 || errno == EINTR) { + if (status == -1 || errno == EINTR) { ERR("Event write over pipe Fail, status= [%d],pipefd = [%d], errno [%d]\n", status, g_pipefd[1], errno); return FALSE; diff --git a/src/mtp_init.c b/src/mtp_init.c index 981bfe4..1d79d17 100755 --- a/src/mtp_init.c +++ b/src/mtp_init.c @@ -69,9 +69,9 @@ static void __mtp_exit(void) DBG("## Terminate all threads"); if (g_eh_thrd) { _eh_send_event_req_to_eh_thread(EVENT_USB_REMOVED, 0, 0, NULL); - if (_util_thread_join(g_eh_thrd, NULL) == FALSE) { + if (_util_thread_join(g_eh_thrd, NULL) == FALSE) ERR("_util_thread_join() Fail"); - } + g_eh_thrd = 0; } @@ -87,7 +87,7 @@ static void __mtp_exit(void) return; } -static gboolean __check_internal_storage (gpointer user_data) +static gboolean __check_internal_storage(gpointer user_data) { _handle_lock_status_notification(NULL, NULL); @@ -322,9 +322,8 @@ static void __read_mtp_conf(void) *token = '\0'; token = strtok_r(buf, "=", &saveptr); - if (token == NULL) { + if (token == NULL) continue; - } if (strcasecmp(token, "mmap_threshold") == 0) { token = strtok_r(NULL, "=", &saveptr); @@ -421,11 +420,10 @@ void _features_supported_info(void) DBG("***********************************************************"); DBG("### Extension ###"); - if (_get_oma_drm_status() == TRUE) { + if (_get_oma_drm_status() == TRUE) DBG("### 2. OMADRM : [ON]"); - } else { + else DBG("### 2. OMADRM : [OFF]"); - } DBG("***********************************************************"); DBG("### Feature ###"); diff --git a/src/mtp_inoti_handler.c b/src/mtp_inoti_handler.c index 47faeaa..66980f3 100755 --- a/src/mtp_inoti_handler.c +++ b/src/mtp_inoti_handler.c @@ -100,11 +100,10 @@ void *_thread_inoti(void *arg) event = (struct inotify_event *)(&buffer[i]); __process_inoti_event(event); temp_idx = i + event->len + INOTI_EVENT_SIZE; - if (temp_idx > length) { + if (temp_idx > length) break; - } else { + else i = temp_idx; - } } } @@ -124,11 +123,10 @@ void _inoti_add_watch_for_fs_events(mtp_char *path) /* find empty cell */ for (i = 0; i < INOTI_FOLDER_COUNT_MAX; i++) { /* If not empty */ - if (g_inoti_watches[i].wd != 0) { + if (g_inoti_watches[i].wd != 0) continue; - } else { + else break; - } } if (i == INOTI_FOLDER_COUNT_MAX) { @@ -319,9 +317,8 @@ void _inoti_deinit_filesystem_events() return; } - if (_util_thread_join(g_inoti_thrd, 0) == FALSE) { + if (_util_thread_join(g_inoti_thrd, 0) == FALSE) ERR("_util_thread_join() Fail"); - } return; } @@ -331,13 +328,11 @@ static void __remove_inoti_watch(mtp_char *path) mtp_int32 i = 0; for (i = 0; i < g_cnt_watch_folder; i++) { - if (g_inoti_watches[i].forlder_name == NULL) { + if (g_inoti_watches[i].forlder_name == NULL) continue; - } - if (g_strcmp0(g_inoti_watches[i].forlder_name, path) != 0) { + if (g_strcmp0(g_inoti_watches[i].forlder_name, path) != 0) continue; - } g_free(g_inoti_watches[i].forlder_name); g_inoti_watches[i].forlder_name = NULL; @@ -399,17 +394,15 @@ static open_files_info_t *__find_file_in_inoti_open_files_list(mtp_int32 wd, static void __remove_file_from_inoti_open_files_list(open_files_info_t *node) { - if (NULL != node->previous) { + if (NULL != node->previous) node->previous->next = node->next; - } - if (NULL != node->next) { + if (NULL != node->next) node->next->previous = node->previous; - } - if (node == g_open_files_list) { + if (node == g_open_files_list) g_open_files_list = node->previous; - } + g_free(node->name); g_free(node); @@ -568,8 +561,7 @@ static void __process_object_added_event(mtp_char *fullpath, _util_get_internal_path(inter_path); if (!g_strcmp0(parent_path, inter_path) || - !g_strcmp0(parent_path, ext_path)) - { + !g_strcmp0(parent_path, ext_path)) { DBG("parent is the root folder"); h_parent = 0; } else { @@ -678,9 +670,8 @@ static void __process_object_deleted_event(mtp_char *fullpath, } } - if (TRUE == isdir) { + if (TRUE == isdir) __delete_children_from_store_inoti(store, obj); - } node = _util_delete_node(&(store->obj_list), obj); g_free(node); @@ -698,13 +689,12 @@ static void __destroy_inoti_open_files_list() ret_if(g_open_files_list == NULL); - while(g_open_files_list) { + while (g_open_files_list) { current = g_open_files_list; g_open_files_list = g_open_files_list->previous; - if (g_open_files_list) { + if (g_open_files_list) g_open_files_list->next = NULL; - } g_free(current->name); current->wd = 0; diff --git a/src/ptp_container.c b/src/ptp_container.c index d9a8aa8..5143569 100755 --- a/src/ptp_container.c +++ b/src/ptp_container.c @@ -37,9 +37,9 @@ void _hdlr_init_cmd_container(cmd_container_t *cntr) mtp_uint32 _hdlr_get_param_cmd_container(cmd_container_t *cntr, mtp_uint32 index) { - if (index < cntr->no_param) { + if (index < cntr->no_param) return cntr->params[index]; - } + return 0; } @@ -55,9 +55,9 @@ void _hdlr_copy_cmd_container_unknown_params(cmd_container_t *src, dst->no_param = (src->len - sizeof(header_container_t)) / sizeof(mtp_uint32); - for (ii = 0; ii < dst->no_param; ii++) { + for (ii = 0; ii < dst->no_param; ii++) dst->params[ii] = src->params[ii]; - } + return; } @@ -71,9 +71,8 @@ void _hdlr_copy_cmd_container(cmd_container_t *src, cmd_container_t *dst) dst->len = src->len; dst->no_param = src->no_param; - for (ii = 0; ii < dst->no_param; ii++) { + for (ii = 0; ii < dst->no_param; ii++) dst->params[ii] = src->params[ii]; - } return; } diff --git a/src/transport/mtp_transport.c b/src/transport/mtp_transport.c index 2e382c3..3eee08b 100755 --- a/src/transport/mtp_transport.c +++ b/src/transport/mtp_transport.c @@ -66,14 +66,14 @@ void _transport_save_cmd_buffer(mtp_char *buffer, mtp_uint32 size) mtp_err_t _transport_rcv_temp_file_data(mtp_byte *buffer, mtp_uint32 size, mtp_uint32 *count) { - mtp_uint32 h_file = INVALID_FILE; + FILE* h_file = NULL; mtp_int32 error = 0; mtp_uint32 data_sz; h_file = _util_file_open(g_mgr->ftemp_st.filepath, MTP_FILE_READ, &error); - if (h_file == INVALID_FILE) { + if (h_file == NULL) { DBG_SECURE("_util_file_open(%s) Fail", g_mgr->ftemp_st.filepath); return MTP_ERROR_NONE; } @@ -133,7 +133,7 @@ mtp_err_t _transport_rcv_temp_file_info(mtp_byte *buf, char *filepath, g_strlcpy(g_mgr->ftemp_st.filepath, MTP_TEMP_FILE_DEFAULT, MTP_MAX_PATHNAME_SIZE + 1); - g_mgr->ftemp_st.fhandle = INVALID_FILE; + g_mgr->ftemp_st.fhandle = NULL; g_mgr->ftemp_st.file_size = 0; return MTP_ERROR_NONE; @@ -421,14 +421,12 @@ void _transport_usb_finalize(void) } res = _util_thread_join(g_data_rcv, &th_result); - if (res == FALSE) { + if (res == FALSE) ERR("_util_thread_join(data_rcv) Fail"); - } } - if (_transport_mq_deinit(&g_usb_to_mtp_mqid, &mtp_to_usb_mqid) == FALSE) { + if (_transport_mq_deinit(&g_usb_to_mtp_mqid, &mtp_to_usb_mqid) == FALSE) ERR("_transport_mq_deinit() Fail"); - } _transport_deinit_usb_device(); @@ -442,7 +440,7 @@ static void *__transport_thread_data_rcv(void *func) mtp_uint32 pkt_len = 0; mtp_int32 flag = 1; mtp_int32 len = 0; - _cmd_handler_cb _cmd_handler_func = (_cmd_handler_cb )func; + _cmd_handler_cb _cmd_handler_func = (_cmd_handler_cb)func; while (flag) { if (_util_msgq_receive(g_usb_to_mtp_mqid, (void *)&pkt, diff --git a/src/transport/mtp_usb_driver.c b/src/transport/mtp_usb_driver.c index 91a9b73..e392bb9 100755 --- a/src/transport/mtp_usb_driver.c +++ b/src/transport/mtp_usb_driver.c @@ -337,9 +337,8 @@ static void __handle_control_request(mtp_int32 request) DBG("USB_PTPREQUEST_RESET"); _reset_mtp_device(); - if (kernel_reset == FALSE) { + if (kernel_reset == FALSE) kernel_reset = TRUE; - } status = ioctl(g_usb_fd, MTP_SEND_RESET_ACK, NULL); if (status < 0) { @@ -385,11 +384,10 @@ static void __handle_control_request(mtp_int32 request) statusreq_data.code = PTP_RESPONSE_GEN_ERROR; } - if (statusreq_data.code == PTP_RESPONSE_DEVICEBUSY) { + if (statusreq_data.code == PTP_RESPONSE_DEVICEBUSY) sent_busy = TRUE; - } else { + else sent_busy = FALSE; - } status = ioctl(g_usb_fd, MTP_SET_SETUP_DATA, &statusreq_data); if (status < 0) { @@ -431,20 +429,18 @@ mtp_bool _transport_mq_deinit(msgq_id_t *rx_mqid, msgq_id_t *tx_mqid) if (*rx_mqid) { res = _util_msgq_deinit(rx_mqid); - if (res == FALSE) { + if (res == FALSE) ERR("rx_mqid deinit Fail [%d]\n", errno); - } else { + else *rx_mqid = 0; - } } if (*tx_mqid) { res = _util_msgq_deinit(tx_mqid); - if (res == FALSE) { + if (res == FALSE) ERR("tx_mqid deinit fail [%d]\n", errno); - } else { + else *tx_mqid = 0; - } } return res; @@ -464,9 +460,8 @@ mtp_uint32 _transport_get_usb_packet_len(void) } } - if (usb_speed % MTP_MAX_PACKET_SIZE_SEND_HS) { + if (usb_speed % MTP_MAX_PACKET_SIZE_SEND_HS) return MTP_MAX_PACKET_SIZE_SEND_FS; - } return MTP_MAX_PACKET_SIZE_SEND_HS; } diff --git a/src/util/mtp_fs.c b/src/util/mtp_fs.c index ba9e3b2..b206f9b 100755 --- a/src/util/mtp_fs.c +++ b/src/util/mtp_fs.c @@ -46,7 +46,7 @@ * @return This function returns the file handle on success, or INVALID_FILE on failure */ -mtp_uint32 _util_file_open(const mtp_char *filename, file_mode_t mode, +FILE* _util_file_open(const mtp_char *filename, file_mode_t mode, mtp_int32 *error) { #ifdef __USE_STDIO__ @@ -77,7 +77,7 @@ mtp_uint32 _util_file_open(const mtp_char *filename, file_mode_t mode, default: ERR("Invalid mode : %d\n", mode); *error = EINVAL; - return INVALID_FILE; + return NULL; } fhandle = fopen(filename, fmode); @@ -85,12 +85,12 @@ mtp_uint32 _util_file_open(const mtp_char *filename, file_mode_t mode, ERR("File open Fail:mode[0x%x], errno [%d]\n", mode, errno); ERR_SECURE("filename[%s]\n", filename); *error = errno; - return INVALID_FILE; + return NULL; } fcntl(fileno(fhandle), F_SETFL, O_NOATIME); - return (mtp_uint32)fhandle; + return fhandle; #else /* __USE_STDIO__ */ @@ -125,7 +125,7 @@ mtp_uint32 _util_file_open(const mtp_char *filename, file_mode_t mode, default: ERR("Invalid mode : %d\n", mode); *error = EINVAL; - return INVALID_FILE; + return NULL; } if (perm) @@ -137,10 +137,10 @@ mtp_uint32 _util_file_open(const mtp_char *filename, file_mode_t mode, ERR("File open Fail:mode[0x%x], errno [%d]\n", mode, errno); ERR_SECURE("filename[%s]\n", filename); *error = errno; - return INVALID_FILE; + return NULL; } - return (mtp_uint32)fhandle; + return fhandle; #endif /* __USE_STDIO__ */ } @@ -156,13 +156,13 @@ mtp_uint32 _util_file_open(const mtp_char *filename, file_mode_t mode, * @param[out] preadcount Will store the actual num bytes read. * @return None */ -void _util_file_read(mtp_uint32 fhandle, void *bufptr, mtp_uint32 size, +void _util_file_read(FILE* fhandle, void *bufptr, mtp_uint32 size, mtp_uint32 *read_count) { mtp_uint32 bytes_read = 0; #ifdef __USE_STDIO__ - bytes_read = fread_unlocked(bufptr, sizeof(mtp_char), size, (FILE *)fhandle); + bytes_read = fread_unlocked(bufptr, sizeof(mtp_char), size, fhandle); #else /* __USE_STDIO__ */ bytes_read = read(fhandle, bufptr, size); #endif /* __USE_STDIO__ */ @@ -180,12 +180,12 @@ void _util_file_read(mtp_uint32 fhandle, void *bufptr, mtp_uint32 size, * @return This function returns num bytes written. */ -mtp_uint32 _util_file_write(mtp_uint32 fhandle, void *bufptr, mtp_uint32 size) +mtp_uint32 _util_file_write(FILE* fhandle, void *bufptr, mtp_uint32 size) { mtp_uint32 bytes_written = 0; #ifdef __USE_STDIO__ - bytes_written = fwrite_unlocked(bufptr, sizeof(mtp_char), size, (FILE *)fhandle); + bytes_written = fwrite_unlocked(bufptr, sizeof(mtp_char), size, fhandle); #else /* __USE_STDIO__ */ mtp_int32 ret = 0; @@ -206,10 +206,10 @@ mtp_uint32 _util_file_write(mtp_uint32 fhandle, void *bufptr, mtp_uint32 size) * @param[in] handle Specifies the handle of file to close. * @return 0 in case of success or EOF on failure. */ -mtp_int32 _util_file_close(mtp_uint32 fhandle) +mtp_int32 _util_file_close(FILE* fhandle) { #ifdef __USE_STDIO__ - return fclose((FILE *)fhandle); + return fclose(fhandle); #else /* __USE_STDIO__ */ return close(fhandle); #endif /* __USE_STDIO__ */ @@ -223,12 +223,12 @@ mtp_int32 _util_file_close(mtp_uint32 fhandle) * @param[in] whence Specifies the setting value * @return Returns TRUE in case of success or FALSE on Failure. */ -mtp_bool _util_file_seek(mtp_uint32 handle, off_t offset, mtp_int32 whence) +mtp_bool _util_file_seek(FILE* handle, off_t offset, mtp_int32 whence) { mtp_int64 ret_val = 0; #ifdef __USE_STDIO__ - ret_val = fseek((FILE *)handle, offset, whence); + ret_val = fseek(handle, offset, whence); #else /* __USE_STDIO__ */ ret_val = lseek(handle, offset, whence); if (ret_val > 0) @@ -521,7 +521,7 @@ mtp_int32 _util_remove_dir_children_recursive(const mtp_char *dirname, } if (MTP_ERROR_OBJECT_WRITE_PROTECTED == ret) { DBG("Folder[%s] contains read-only files,hence\ - folder is not deleted\n",pathname); + folder is not deleted\n", pathname); /* Read the next entry */ goto DONE; } @@ -543,7 +543,7 @@ mtp_int32 _util_remove_dir_children_recursive(const mtp_char *dirname, (S_IWGRP & entryinfo.st_mode) || (S_IWOTH & entryinfo.st_mode))) { ret = MTP_ERROR_OBJECT_WRITE_PROTECTED; - DBG("File [%s] is readOnly:Deletion Fail\n",pathname); + DBG("File [%s] is readOnly:Deletion Fail\n", pathname); goto DONE; } } @@ -722,9 +722,8 @@ mtp_bool _util_ifind_next(mtp_char *dir_name, DIR *dirp, dir_entry_t *dir_info) switch (stat_buf.st_mode & S_IFMT) { case S_IFREG: dir_info->type = MTP_FILE_TYPE; - if (!(stat_buf.st_mode & (S_IWUSR | S_IWGRP | S_IWOTH))) { + if (!(stat_buf.st_mode & (S_IWUSR | S_IWGRP | S_IWOTH))) dir_info->attrs.attribute |= MTP_FILE_ATTR_MODE_READ_ONLY; - } break; case S_IFDIR: @@ -779,9 +778,9 @@ mtp_bool _util_get_filesystem_info(mtp_char *storepath, fs_info_t *fs_info) return TRUE; } -void _util_count_num_lines(mtp_uint32 fhandle, mtp_uint32 *num_lines) +void _util_count_num_lines(FILE* fhandle, mtp_uint32 *num_lines) { - if (fhandle == INVALID_FILE) + if (fhandle == NULL) return; mtp_uint32 line_count = 0; @@ -797,8 +796,8 @@ void _util_count_num_lines(mtp_uint32 fhandle, mtp_uint32 *num_lines) } #ifdef __USE_STDIO__ - while((read_bytes = getline(&buffer, - &line_max_length, (FILE *)fhandle)) != -1) { + while ((read_bytes = getline(&buffer, + (size_t *)&line_max_length, fhandle)) != -1) { if (read_bytes > MTP_MAX_PATHNAME_SIZE + 1) continue; line_count++; @@ -809,7 +808,7 @@ void _util_count_num_lines(mtp_uint32 fhandle, mtp_uint32 *num_lines) mtp_uint32 prev_pos = -1; mtp_uint32 new_pos; mtp_uint32 filename_len = 0; - while((read_bytes = read(fhandle, buffer, LINUX_MAX_PATHNAME_LENGTH)) > 0) { + while ((read_bytes = read(fhandle, buffer, LINUX_MAX_PATHNAME_LENGTH)) > 0) { for (ii = 0; ii < read_bytes; ii++) { if (buffer[ii] != '\n') continue; @@ -820,9 +819,9 @@ void _util_count_num_lines(mtp_uint32 fhandle, mtp_uint32 *num_lines) continue; line_count++; } - if (buffer[read_bytes - 1] != '\n') { + if (buffer[read_bytes - 1] != '\n') _util_file_seek(fhandle, prev_pos + 1 - read_bytes, SEEK_CUR); - } + prev_pos = -1; } #endif /* __USE_STDIO__ */ @@ -833,7 +832,7 @@ void _util_count_num_lines(mtp_uint32 fhandle, mtp_uint32 *num_lines) } void _util_fill_guid_array(void *guidarray, mtp_uint32 start_index, - mtp_uint32 fhandle, mtp_uint32 size) + FILE* fhandle, mtp_uint32 size) { ptp_array_t *pguidarray = NULL; mtp_uint32 *guidptr = NULL; @@ -855,7 +854,7 @@ void _util_fill_guid_array(void *guidarray, mtp_uint32 start_index, } #ifdef __USE_STDIO__ - while ((len = getline(&buffer, &line_max_length, (FILE *)fhandle)) != -1 && + while ((len = getline(&buffer, (size_t *)&line_max_length, fhandle)) != -1 && (num_lines - start_index) <= size) { if (len > MTP_MAX_PATHNAME_SIZE + 1) continue; @@ -877,7 +876,7 @@ void _util_fill_guid_array(void *guidarray, mtp_uint32 start_index, mtp_char file_name[MTP_MAX_PATHNAME_SIZE + 1]; mtp_int32 read_bytes; - while ((read_bytes = read(fHandle, buffer, + while ((read_bytes = read(fhandle, buffer, LINUX_MAX_PATHNAME_LENGTH)) > 0 && (num_lines - start_index) <= size) { @@ -902,9 +901,9 @@ void _util_fill_guid_array(void *guidarray, mtp_uint32 start_index, pguidarray->num_elements += sizeof(mtp_uint32); } - if (buffer[read_bytes - 1] != '\n') { + if (buffer[read_bytes - 1] != '\n') _util_file_seek(fhandle, prev_pos + 1 - read_bytes, SEEK_CUR); - } + prev_pos = -1; } #endif /* __USE_STDIO__ */ @@ -935,9 +934,8 @@ void FLOGD(const char *fmt, ...) fp = fopen(MTP_LOG_FILE, "a+"); } - if (fp == NULL) { + if (fp == NULL) return; - } written_bytes += fprintf(fp, "%s ", __FILE__); va_start(ap, fmt); diff --git a/src/util/mtp_list.c b/src/util/mtp_list.c index 1ba7050..4bf2e15 100755 --- a/src/util/mtp_list.c +++ b/src/util/mtp_list.c @@ -67,9 +67,8 @@ slist_node_t* _util_delete_node(slist_t *l_ptr, void *data) slist_node_t *nptr = l_ptr->start; slist_node_t *temp = NULL; - if (nptr->value == data) { + if (nptr->value == data) return __util_del_first_node(l_ptr); - } while (nptr->link) { if (nptr->link->value == data) @@ -99,9 +98,8 @@ static slist_node_t *__util_del_first_node(slist_t *l_ptr) temp = l_ptr->start; l_ptr->nnodes -= 1; l_ptr->start = temp->link; - if (temp == l_ptr->end) { + if (temp == l_ptr->end) l_ptr->end = NULL; - } return temp; } diff --git a/src/util/mtp_media_info.c b/src/util/mtp_media_info.c index 0cdda55..6e7b34f 100755 --- a/src/util/mtp_media_info.c +++ b/src/util/mtp_media_info.c @@ -37,9 +37,8 @@ static bool __fill_media_id_cb(media_info_h media, void *user_data) static void __scan_folder_cb(media_content_error_e err, void *user_data) { - if (err != MEDIA_CONTENT_ERROR_NONE) { + if (err != MEDIA_CONTENT_ERROR_NONE) ERR("Scan folder callback returns error = [%d]\n", err); - } return; } @@ -115,7 +114,7 @@ mtp_bool _util_get_audio_metadata(const mtp_char *filepath, goto ERROR_EXIT; } - ret =audio_meta_get_composer(audio, &(audio_data->commonmeta.author)); + ret = audio_meta_get_composer(audio, &(audio_data->commonmeta.author)); if (ret != MEDIA_CONTENT_ERROR_NONE) { ERR("METADATA_AUTHOR Fail"); goto ERROR_EXIT; @@ -366,7 +365,7 @@ static media_info_h __util_find_media_info(mtp_char *condition) ERR("media_info_foreach_media_from_db() Fail"); break; } - }while (0); + } while (0); media_filter_destroy(filter); @@ -830,9 +829,8 @@ void _util_scan_folder_contents_in_db(const mtp_char *filepath) ret_if(filepath == NULL); ret = media_content_scan_folder(filepath, true, __scan_folder_cb, NULL); - if (ret != MEDIA_CONTENT_ERROR_NONE) { + if (ret != MEDIA_CONTENT_ERROR_NONE) ERR("media_content_scan_folder Fail : %d\n", ret); - } return; } diff --git a/src/util/mtp_msgq.c b/src/util/mtp_msgq.c index ad98fa5..aa4b5c6 100755 --- a/src/util/mtp_msgq.c +++ b/src/util/mtp_msgq.c @@ -49,11 +49,10 @@ mtp_bool _util_msgq_receive(msgq_id_t mq_id, void *buf, mtp_uint32 size, { int ret = 0; - if (flags == 1) { + if (flags == 1) ret = msgrcv(mq_id, buf, size, 0, IPC_NOWAIT); - } else { + else ret = msgrcv(mq_id, buf, size, 0, 0); - } if (ret == -1) { ERR("msgrcv() Fail"); diff --git a/src/util/mtp_support.c b/src/util/mtp_support.c index 144c2cd..83108d6 100755 --- a/src/util/mtp_support.c +++ b/src/util/mtp_support.c @@ -64,9 +64,8 @@ void _util_conv_byte_order_gen_str(void *str, mtp_int32 size, mtp_int32 elem_sz) ret_if(str == NULL); retm_if(elem_sz <= 1, "elem_sz(%d) is invalid", elem_sz); - for (idx = 0; idx < f_size; idx += elem_sz) { + for (idx = 0; idx < f_size; idx += elem_sz) _util_conv_byte_order(&(l_str[idx]), elem_sz); - } return; } @@ -145,13 +144,12 @@ void _util_wchar_cpy(mtp_wchar *dest, const mtp_wchar *src) ret_if(src == NULL); ret_if(dest == NULL); - if (!((int)dest & 0x1) && !((int)src & 0x1)){ + if (!((int)dest & 0x1) && !((int)src & 0x1)) { /* 2-byte aligned */ mtp_wchar *temp = dest; - while ((*temp++ = *src++) != '\0') { + while ((*temp++ = *src++) != '\0') ; /* DO NOTHING */ - } } else { /* not-aligned, byte to byte approach - slow */ mtp_char *pc1 = (mtp_char *)dest; @@ -187,14 +185,12 @@ void _util_wchar_ncpy(mtp_wchar *dest, const mtp_wchar *src, unsigned long n) if (!((int)dest & 0x1) && !((int)src & 0x1)) { /* 2-byte aligned */ temp = dest; - while (n && (*temp++ = *src++)) { + while (n && (*temp++ = *src++)) n--; - } if (n) { - while (--n) { + while (--n) *temp++ = 0; - } } } else { /* not-aligned, byte to byte approach - slow */ @@ -228,9 +224,8 @@ size_t _util_wchar_len(const mtp_wchar *s) if (!((int)s & 0x1)) { /* 2-byte aligned */ mtp_wchar *temp = (mtp_wchar *)s; - while (*temp++) { + while (*temp++) /* DO NOTHING */ ; - } DBG("Length : %d\n", temp - s - 1); return ((size_t)(temp - s - 1)); @@ -238,9 +233,8 @@ size_t _util_wchar_len(const mtp_wchar *s) unsigned char *temp = (unsigned char *)s; - while (*temp || *(temp + 1)) { + while (*temp || *(temp + 1)) temp += 2; - } DBG("Length : %d\n", (temp - (unsigned char *)s) / 2); return ((size_t) (temp - (unsigned char *)s) / 2); @@ -258,9 +252,9 @@ static mtp_char* __util_conv_int_to_hex_str(mtp_int32 int_val, mtp_char *str) *nstr++ = '0'; *nstr++ = 'x'; - for (val = int_val; val; val <<= 4) { + for (val = int_val; val; val <<= 4) *nstr++ = hex[(val >> (sizeof(int) * 8 - 4)) & 0xF]; - } + *nstr = '\0'; return str; } @@ -411,7 +405,7 @@ mtp_bool _util_get_file_name(const mtp_char *fullpath, mtp_char *f_name) i = strlen(fullpath); - for (j=0; i >= 0; i--) { + for (j = 0; i >= 0; i--) { if (fullpath[i] == '/') { g_strlcpy(f_name, &fullpath[i + 1], j); return TRUE; @@ -491,8 +485,7 @@ mtp_bool _util_is_path_len_valid(const mtp_char *path) root_path_len = internal_store_len; } else if (!strncmp(path, ext_path, external_store_len)) { root_path_len = external_store_len; - } - else { + } else { ERR("Unknown store's path : %s\n", path); return FALSE; } @@ -576,9 +569,8 @@ void _util_conv_wstr_to_guid(mtp_wchar *wstr, mtp_uint64 *guid) ret_if(wstr == NULL); ret_if(guid == NULL); - while (wstr[count] != 0) { + while (wstr[count] != 0) count++; - } memset(guid, 0, sizeof(temp)); skip_idx = sizeof(temp) / sizeof(mtp_wchar); @@ -587,9 +579,9 @@ void _util_conv_wstr_to_guid(mtp_wchar *wstr, mtp_uint64 *guid) memset(temp, 0, sizeof(temp)); cpy_sz = (count - cur_idx) * sizeof(mtp_wchar); - if (cpy_sz > sizeof(temp)) { + if (cpy_sz > sizeof(temp)) cpy_sz = sizeof(temp); - } + memcpy(temp, &(wstr[cur_idx]), cpy_sz); guid[0] += temp[0]; guid[1] += temp[1]; @@ -637,9 +629,8 @@ mtp_bool _util_get_unique_dir_path(const mtp_char *exist_path, while (val < max_value) { /* Including NUL and '_' */ g_snprintf(&buf[len], num_bytes + 2, "_%u", val++); - if (access(buf, F_OK) < 0) { + if (access(buf, F_OK) < 0) goto SUCCESS; - } } g_free(buf); diff --git a/src/util/mtp_thread.c b/src/util/mtp_thread.c index e1f48e3..e96d111 100755 --- a/src/util/mtp_thread.c +++ b/src/util/mtp_thread.c @@ -46,15 +46,14 @@ mtp_bool _util_thread_create(pthread_t *tid, const mtp_char *tname, error = pthread_create(tid, &attr, thread_func, arg); if (error != 0) { - ERR( "[%s] Thread creation Fail errno [%d]\n", tname, errno); + ERR("[%s] Thread creation Fail errno [%d]\n", tname, errno); pthread_attr_destroy(&attr); return FALSE; } error = pthread_attr_destroy(&attr); - if (error != 0) { + if (error != 0) ERR("pthread_attr_destroy Fail [%d] errno [%d]\n", error, errno); - } return TRUE; } diff --git a/src/util/mtp_util.c b/src/util/mtp_util.c index b9c8e18..a039945 100755 --- a/src/util/mtp_util.c +++ b/src/util/mtp_util.c @@ -51,9 +51,9 @@ mtp_int32 _util_get_battery_level(void) result = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CAPACITY, &battery_level); - if (result != 0) { + if (result != 0) ERR("VCONFKEY_SYSMAN_BATTERY_CAPACITY Fail!"); - } + return battery_level; } @@ -101,9 +101,8 @@ mtp_bool _util_get_serial(mtp_char *serial, mtp_uint32 len) gcry_md_hash_buffer(GCRY_MD_MD5, hash_value, imei_no, strlen(imei_no)); - for (i = 0; i < MD5_HASH_LEN; i++) { + for (i = 0; i < MD5_HASH_LEN; i++) g_snprintf(&serial[i*2], 3, "%02X", hash_value[i]); - } if (vconf_set_str(VCONFKEY_MTP_SERIAL_NUMBER_STR, serial) == -1) { ERR("vconf_set Fail for %s\n", @@ -209,9 +208,8 @@ void _util_gen_alt_serial(mtp_char *serial, mtp_uint32 len) g_snprintf(serial, len, "%s-%010ld-%011ld", model_name, st.tv_sec, st.tv_usec); - if (vconf_set_str(VCONFKEY_MTP_SERIAL_NUMBER_STR, serial) == -1) { + if (vconf_set_str(VCONFKEY_MTP_SERIAL_NUMBER_STR, serial) == -1) ERR("vconf_set Fail %s\n", VCONFKEY_MTP_SERIAL_NUMBER_STR); - } return; } @@ -335,11 +333,11 @@ static bool _util_device_external_supported_cb(int storage_id, storage_type_e ty { char *storage_path = (char *)user_data; - DBG("storage id: %d, path: %s", storage_id, path); + //DBG("storage id: %d, path: %s", storage_id, path); if (type == STORAGE_TYPE_EXTERNAL && path != NULL) { strncpy(storage_path, path, strlen(path)); - DBG("external storage path : %s", storage_path); + //DBG("external storage path : %s", storage_path); } return TRUE; @@ -361,17 +359,17 @@ static bool _util_device_internal_supported_cb(int storage_id, storage_type_e ty { char *storage_path = (char *)user_data; - DBG("storage id: %d, path: %s", storage_id, path); + //DBG("storage id: %d, path: %s", storage_id, path); if (type == STORAGE_TYPE_INTERNAL && path != NULL) { strncpy(storage_path, path, strlen(path)); - DBG("internal storage path : %s", storage_path); + //DBG("internal storage path : %s", storage_path); if (storage_get_root_directory(storage_id, &storage_path) != STORAGE_ERROR_NONE) { ERR("get internal storage path Fail"); return FALSE; } else { - DBG("get internal storage path : %s", storage_path); + //DBG("get internal storage path : %s", storage_path); } } |