format = param->param3;
parent_object_handle = param->param4;
+ /* loop over storages */
+ g_variant_builder_init(&b, G_VARIANT_TYPE("aa{sv}"));
+
+ if (device_id < 0 || param->mtp_ctx->device_list->device_num < device_id) {
+ MTP_LOGE("device_id : out of range");
+ result = MTP_ERROR_NO_DEVICE;
+ goto END;
+ }
+
device_info = (mtp_device_info *)param->mtp_ctx->device_list->device_info_list[device_id];
+ if (device_info == NULL) {
+ MTP_LOGE("device_info is NULL");
+ result = MTP_ERROR_NO_DEVICE;
+ goto END;
+ }
- if (device_info != NULL)
- device = (LIBMTP_mtpdevice_t *)device_info->device;
+ device = (LIBMTP_mtpdevice_t *)device_info->device;
+ if (device == NULL) {
+ MTP_LOGE("device is NULL");
+ result = MTP_ERROR_NO_DEVICE;
+ goto END;
+ }
MTP_LOGI("device_id: %d, storage id: %d, format: %d, parent: %d, device: %p",
param->param1, param->param2, param->param3, param->param4, device);
- /* loop over storages */
- g_variant_builder_init(&b, G_VARIANT_TYPE("aa{sv}"));
-
if (parent_object_handle > 0) {
MTPObjectInfo *object_info = NULL;
object_info = LIBMTP_Get_Object_Info(device, parent_object_handle);
+
+ if (object_info == NULL) {
+ MTP_LOGE("object info is NULL");
+ result = MTP_ERROR_PLUGIN_FAIL;
+ goto END;
+ }
+
if (object_info->StorageID != mtp_storage) {
MTP_LOGE("Not Equal between real object storage id and parameter");
goto END;
}
}
- if (device_info != NULL) {
- ret = LIBMTP_Get_Object_Handles(device, (uint32_t)mtp_storage,
- (uint32_t)format, (uint32_t)parent_object_handle,
- (uint32_t **)&object_list, (uint32_t *)&total_object_num);
+ ret = LIBMTP_Get_Object_Handles(device, (uint32_t)mtp_storage,
+ (uint32_t)format, (uint32_t)parent_object_handle,
+ (uint32_t **)&object_list, (uint32_t *)&total_object_num);
- if (ret < 0)
- MTP_LOGE("LIBMTP_Get_Object_Handles is failed : %d", ret);
- }
+ if (ret < 0)
+ MTP_LOGE("LIBMTP_Get_Object_Handles is failed : %d", ret);
- if (device_info != NULL) {
- mtp_daemon_db_begin(param->mtp_ctx);
+ mtp_daemon_db_begin(param->mtp_ctx);
- for (slot = 0; slot < total_object_num; slot++) {
- MTPObjectInfo *object_info = NULL;
- /*object_info = LIBMTP_Get_Object_Info(device, (uint32_t)object_list[slot]);
-
- if (object_info != NULL)
- mtp_daemon_db_insert(device_id, storage_id, object_list[slot], object_info, param->mtp_ctx);*/
-
- if (mtp_daemon_db_is_exist(device_id, mtp_storage, object_list[slot], param->mtp_ctx) == false) {
- MTP_LOGI("Objectinfo is Not stored. device_id: %d, object_list[%d]: %d",
- device_id, slot, object_list[slot]);
- object_info = LIBMTP_Get_Object_Info(device, (uint32_t)object_list[slot]);
+ for (slot = 0; slot < total_object_num; slot++) {
+ MTPObjectInfo *object_info = NULL;
- if (object_info != NULL)
- mtp_daemon_db_insert(device_id, mtp_storage, object_list[slot], object_info, param->mtp_ctx);
- } else {
- MTP_LOGI("Objectinfo is stored. device_id: %d, object_list[%d]: %d",
- device_id, slot, object_list[slot]);
- object_info = mtp_daemon_db_get_object_info(device_id, object_list[slot], param->mtp_ctx);
- }
+ if (mtp_daemon_db_is_exist(device_id, mtp_storage, object_list[slot], param->mtp_ctx) == false) {
+ MTP_LOGI("Objectinfo is Not stored. device_id: %d, object_list[%d]: %d",
+ device_id, slot, object_list[slot]);
+ object_info = LIBMTP_Get_Object_Info(device, (uint32_t)object_list[slot]);
- if (object_info != NULL) {
- /*MTP_LOGI("object id: %d, format : %d, filename : %s", object_list[slot],
- object_info->ObjectFormat, object_info->Filename);*/
+ if (object_info != NULL)
+ mtp_daemon_db_insert(device_id, mtp_storage, object_list[slot], object_info, param->mtp_ctx);
+ } else {
+ MTP_LOGI("Objectinfo is stored. device_id: %d, object_list[%d]: %d",
+ device_id, slot, object_list[slot]);
+ object_info = mtp_daemon_db_get_object_info(device_id, object_list[slot], param->mtp_ctx);
+ }
- if (format == LIBMTP_FILETYPE_ALL ||
- (format == LIBMTP_FILETYPE_ALL_IMAGE &&
- LIBMTP_FILETYPE_IS_IMAGE(object_info->ObjectFormat)) ||
- (format == object_info->ObjectFormat)) {
- MTP_LOGI("The object handle (id : %d, format : %d) will be pass to caller",
- object_list[slot],object_info->ObjectFormat);
+ if (object_info != NULL) {
+ if (format == LIBMTP_FILETYPE_ALL ||
+ (format == LIBMTP_FILETYPE_ALL_IMAGE &&
+ LIBMTP_FILETYPE_IS_IMAGE(object_info->ObjectFormat)) ||
+ (format == object_info->ObjectFormat)) {
+ MTP_LOGI("The object handle (id : %d, format : %d) will be pass to caller",
+ object_list[slot],object_info->ObjectFormat);
- g_variant_builder_open(&b, G_VARIANT_TYPE("a{sv}"));
+ g_variant_builder_open(&b, G_VARIANT_TYPE("a{sv}"));
- g_variant_builder_add(&b, "{sv}", "object_handle",
- g_variant_new_int32(object_list[slot]));
+ g_variant_builder_add(&b, "{sv}", "object_handle",
+ g_variant_new_int32(object_list[slot]));
- g_variant_builder_close(&b);
+ g_variant_builder_close(&b);
- target_object_num++;
- }
+ target_object_num++;
}
- g_free(object_info);
}
- mtp_daemon_db_commit(param->mtp_ctx);
- } else {
- MTP_LOGE("!!! no MTP device");
- result = MTP_ERROR_NO_DEVICE;
+ g_free(object_info);
}
+ mtp_daemon_db_commit(param->mtp_ctx);
+
END:
gv = g_variant_builder_end(&b);
- /*MTP_LOGI("Real object_num: %d", target_object_num);*/
+ MTP_LOGI("Real object_num: %d", target_object_num);
mtp_gdbuslib_manager_complete_get_object_handles(param->object,
param->invocation, target_object_num, gv, result);