|
|
|
@ -29,6 +29,8 @@
|
|
|
|
|
#include <splitstr.h> |
|
|
|
|
#include <libmtp.h> |
|
|
|
|
|
|
|
|
|
#include <xmem.h> |
|
|
|
|
|
|
|
|
|
#define MTP_ROOT_FOLDER_ID 0xFFFFFFFF |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -210,19 +212,13 @@ split_path(const char *path, char **dirname)
|
|
|
|
|
char *last_slash, *filename; |
|
|
|
|
|
|
|
|
|
if ( (last_slash = strrchr(path, '/')) ) { |
|
|
|
|
filename = strdup(last_slash + 1); |
|
|
|
|
|
|
|
|
|
if ( dirname ) { |
|
|
|
|
size_t len; |
|
|
|
|
filename = xstrdup(last_slash + 1); |
|
|
|
|
|
|
|
|
|
len = last_slash - path; |
|
|
|
|
*dirname = malloc(last_slash - path + 1); |
|
|
|
|
strncpy(*dirname, path, len); |
|
|
|
|
(*dirname)[len] = '\0'; |
|
|
|
|
} |
|
|
|
|
if ( dirname ) |
|
|
|
|
*dirname = xstrndup(path, last_slash - path); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
filename = strdup(path); |
|
|
|
|
filename = xstrdup(path); |
|
|
|
|
if ( dirname ) |
|
|
|
|
*dirname = NULL; |
|
|
|
|
} |
|
|
|
@ -286,20 +282,19 @@ gfsec_scheme_libmtp_get_file(gfsec_scheme_t scheme,
|
|
|
|
|
long file_id; |
|
|
|
|
|
|
|
|
|
if ( (file_id = find_mtp_file(device, 0, path, len)) != -1 ) { |
|
|
|
|
if ( (*buffer = malloc(*len)) ) { |
|
|
|
|
cb_data.buffer = *buffer; |
|
|
|
|
cb_data.written = 0; |
|
|
|
|
cb_data.expected = *len; |
|
|
|
|
|
|
|
|
|
if ( LIBMTP_Get_File_To_Handler(device, file_id, |
|
|
|
|
getfile_cb, &cb_data, NULL, NULL) != 0 ) { |
|
|
|
|
free(*buffer); |
|
|
|
|
*buffer = NULL; |
|
|
|
|
rc = GFSEC_SCHEME_STATUS_ERROR; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
rc = GFSEC_SCHEME_STATUS_SUCCESS; |
|
|
|
|
*buffer = xmalloc(*len); |
|
|
|
|
cb_data.buffer = *buffer; |
|
|
|
|
cb_data.written = 0; |
|
|
|
|
cb_data.expected = *len; |
|
|
|
|
|
|
|
|
|
if ( LIBMTP_Get_File_To_Handler(device, file_id, |
|
|
|
|
getfile_cb, &cb_data, NULL, NULL) != 0 ) { |
|
|
|
|
free(*buffer); |
|
|
|
|
*buffer = NULL; |
|
|
|
|
rc = GFSEC_SCHEME_STATUS_ERROR; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
rc = GFSEC_SCHEME_STATUS_SUCCESS; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
LIBMTP_Release_Device(device); |
|
|
|
|