From de43df6ec27d98c0fb8b46fe4d02edb0abc70de0 Mon Sep 17 00:00:00 2001 From: Marcus Meissner Date: Sat, 1 Mar 2008 21:37:31 +0000 Subject: [PATCH] in ptp_mtpgetobjectreferences handle the case where no DATA is returned at all. git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@10973 67ed7778-7388-44ab-90cf-0a291f65f57c --- camlibs/ptp2/ChangeLog | 7 +++++++ camlibs/ptp2/ptp.c | 14 ++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/camlibs/ptp2/ChangeLog b/camlibs/ptp2/ChangeLog index aeddfb955..e035672d6 100644 --- a/camlibs/ptp2/ChangeLog +++ b/camlibs/ptp2/ChangeLog @@ -1,3 +1,10 @@ +2008-03-01 Marcus Meissner + + * ptp.c: MTP GetObjectReferences on Sansa MTP device + can skip the dataphase, but return OK as response. + + Handle this strange case here. + 2008-02-22 Marcus Meissner * library.c, ptp.h: diff --git a/camlibs/ptp2/ptp.c b/camlibs/ptp2/ptp.c index 561f57eee..25d38ae92 100644 --- a/camlibs/ptp2/ptp.c +++ b/camlibs/ptp2/ptp.c @@ -2797,13 +2797,23 @@ ptp_mtp_getobjectreferences (PTPParams* params, uint32_t handle, uint32_t** ohAr PTPContainer ptp; uint16_t ret; unsigned char* dpv=NULL; + unsigned int dpvlen = 0; PTP_CNT_INIT(ptp); ptp.Code=PTP_OC_MTP_GetObjectReferences; ptp.Param1=handle; ptp.Nparam=1; - ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &dpv, NULL); - if (ret == PTP_RC_OK) *arraylen = ptp_unpack_uint32_t_array(params, dpv, 0, ohArray); + ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &dpv, &dpvlen); + if (ret == PTP_RC_OK) { + /* Sandisk Sansa skips the DATA phase, but returns OK as response. + * this will gives us a NULL here. Handle it. -Marcus */ + if ((dpv == NULL) || (dpvlen == 0)) { + *arraylen = 0; + *ohArray = NULL; + } else { + *arraylen = ptp_unpack_uint32_t_array(params, dpv, 0, ohArray); + } + } free(dpv); return ret; }