"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "camlibs/ptp2/ptpip.c" between
libgphoto2-2.5.26.tar.bz2 and libgphoto2-2.5.27.tar.bz2

About: libgphoto2 is a library that can be used by applications to access various digital cameras.

ptpip.c  (libgphoto2-2.5.26.tar.bz2):ptpip.c  (libgphoto2-2.5.27.tar.bz2)
skipping to change at line 32 skipping to change at line 32
* - Event handling not finished. * - Event handling not finished.
* - Some configure checking magic missing for the special header files * - Some configure checking magic missing for the special header files
* and functions. * and functions.
* - Not everything implementation correctly cross checked. * - Not everything implementation correctly cross checked.
* - Coolpix P3 does not give transfer status (image 000x/000y), and reports an * - Coolpix P3 does not give transfer status (image 000x/000y), and reports an
* error when transfers finish correctly. * error when transfers finish correctly.
* *
* Nikon WU-1* adapters might use 0011223344556677 as GUID always... * Nikon WU-1* adapters might use 0011223344556677 as GUID always...
*/ */
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#define _DARWIN_C_SOURCE
#include "config.h" #include "config.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>
#include <errno.h> #include <errno.h>
#include <sys/types.h> #include <sys/types.h>
#ifdef HAVE_SYS_SELECT_H #ifdef HAVE_SYS_SELECT_H
#include <sys/select.h> #include <sys/select.h>
#endif #endif
#include "ptpip-private.h"
#ifdef WIN32 #ifdef WIN32
# include <winsock.h> # include <winsock2.h>
# include <ws2tcpip.h>
#else #else
# include <sys/socket.h> # include <sys/socket.h>
# include <netinet/in.h> # include <netinet/in.h>
#endif #endif
#include <gphoto2/gphoto2-library.h> #include <gphoto2/gphoto2-library.h>
#include <gphoto2/gphoto2-port-log.h> #include <gphoto2/gphoto2-port-log.h>
#include <gphoto2/gphoto2-setting.h> #include <gphoto2/gphoto2-setting.h>
#include "ptp.h" #include "ptp.h"
skipping to change at line 145 skipping to change at line 149
case 5: htod32a(&request[ptpip_cmd_param5],req->Param5);/* fallthrough */ case 5: htod32a(&request[ptpip_cmd_param5],req->Param5);/* fallthrough */
case 4: htod32a(&request[ptpip_cmd_param4],req->Param4);/* fallthrough */ case 4: htod32a(&request[ptpip_cmd_param4],req->Param4);/* fallthrough */
case 3: htod32a(&request[ptpip_cmd_param3],req->Param3);/* fallthrough */ case 3: htod32a(&request[ptpip_cmd_param3],req->Param3);/* fallthrough */
case 2: htod32a(&request[ptpip_cmd_param2],req->Param2);/* fallthrough */ case 2: htod32a(&request[ptpip_cmd_param2],req->Param2);/* fallthrough */
case 1: htod32a(&request[ptpip_cmd_param1],req->Param1);/* fallthrough */ case 1: htod32a(&request[ptpip_cmd_param1],req->Param1);/* fallthrough */
case 0: case 0:
default: default:
break; break;
} }
GP_LOG_DATA ( (char*)request, len, "ptpip/oprequest data:"); GP_LOG_DATA ( (char*)request, len, "ptpip/oprequest data:");
ret = write (params->cmdfd, request, len); ret = PTPSOCK_WRITE(params->cmdfd, request, len);
free (request); free (request);
if (ret == -1) if (ret == PTPSOCK_ERR) {
perror ("sendreq/write to cmdfd"); perror ("sendreq/write to cmdfd");
return GP_ERROR_IO;
}
if (ret != len) { if (ret != len) {
GP_LOG_E ("ptp_ptpip_sendreq() len =%d but ret=%d", len, ret); GP_LOG_E ("ptp_ptpip_sendreq() len =%d but ret=%d", len, ret);
return PTP_RC_OK; return PTP_RC_OK;
} }
return PTP_RC_OK; return PTP_RC_OK;
} }
static uint16_t static uint16_t
ptp_ptpip_generic_read (PTPParams *params, int fd, PTPIPHeader *hdr, unsigned ch ar**data) { ptp_ptpip_generic_read (PTPParams *params, int fd, PTPIPHeader *hdr, unsigned ch ar**data) {
int ret, len, curread; int ret, len, curread;
unsigned char *xhdr; unsigned char *xhdr;
xhdr = (unsigned char*)hdr; curread = 0; len = sizeof (PTPIPHeader); xhdr = (unsigned char*)hdr; curread = 0; len = sizeof (PTPIPHeader);
while (curread < len) { while (curread < len) {
ret = read (fd, xhdr + curread, len - curread); ret = PTPSOCK_READ (fd, xhdr + curread, len - curread);
if (ret == -1) { if (ret == PTPSOCK_ERR) {
perror ("read PTPIPHeader"); perror ("read PTPIPHeader");
return PTP_RC_GeneralError; return PTP_RC_GeneralError;
} }
GP_LOG_DATA ((char*)xhdr+curread, ret, "ptpip/generic_read header :"); GP_LOG_DATA ((char*)xhdr+curread, ret, "ptpip/generic_read header :");
curread += ret; curread += ret;
if (ret == 0) { if (ret == 0) {
GP_LOG_E ("End of stream after reading %d bytes of ptpiph eader", ret); GP_LOG_E ("End of stream after reading %d bytes of ptpiph eader", ret);
return PTP_RC_GeneralError; return PTP_RC_GeneralError;
} }
} }
skipping to change at line 187 skipping to change at line 193
GP_LOG_E ("len < 0, %d?", len); GP_LOG_E ("len < 0, %d?", len);
return PTP_RC_GeneralError; return PTP_RC_GeneralError;
} }
*data = malloc (len); *data = malloc (len);
if (!*data) { if (!*data) {
GP_LOG_E ("malloc failed."); GP_LOG_E ("malloc failed.");
return PTP_RC_GeneralError; return PTP_RC_GeneralError;
} }
curread = 0; curread = 0;
while (curread < len) { while (curread < len) {
ret = read (fd, (*data)+curread, len-curread); ret = PTPSOCK_READ (fd, (*data)+curread, len-curread);
if (ret == -1) { if (ret == PTPSOCK_ERR) {
GP_LOG_E ("error %d in reading PTPIP data", errno); GP_LOG_E ("error %d in reading PTPIP data", errno);
free (*data);*data = NULL; free (*data);*data = NULL;
return PTP_RC_GeneralError; return PTP_RC_GeneralError;
} else { } else {
GP_LOG_DATA ((char*)((*data)+curread), ret, "ptpip/generi c_read data:"); GP_LOG_DATA ((char*)((*data)+curread), ret, "ptpip/generi c_read data:");
} }
if (ret == 0) if (ret == 0)
break; break;
curread += ret; curread += ret;
} }
skipping to change at line 255 skipping to change at line 261
int ret; int ret;
unsigned char* xdata; unsigned char* xdata;
GP_LOG_D ("Sending PTP_OC 0x%0x (%s) data...", ptp->Code, ptp_get_opcode_ name(params, ptp->Code)); GP_LOG_D ("Sending PTP_OC 0x%0x (%s) data...", ptp->Code, ptp_get_opcode_ name(params, ptp->Code));
htod32a(&request[ptpip_type],PTPIP_START_DATA_PACKET); htod32a(&request[ptpip_type],PTPIP_START_DATA_PACKET);
htod32a(&request[ptpip_len],sizeof(request)); htod32a(&request[ptpip_len],sizeof(request));
htod32a(&request[ptpip_startdata_transid + 8],ptp->Transaction_ID); htod32a(&request[ptpip_startdata_transid + 8],ptp->Transaction_ID);
htod32a(&request[ptpip_startdata_totallen + 8],size); htod32a(&request[ptpip_startdata_totallen + 8],size);
htod32a(&request[ptpip_startdata_unknown + 8],0); htod32a(&request[ptpip_startdata_unknown + 8],0);
GP_LOG_DATA ((char*)request, sizeof(request), "ptpip/senddata header:"); GP_LOG_DATA ((char*)request, sizeof(request), "ptpip/senddata header:");
ret = write (params->cmdfd, request, sizeof(request)); ret = PTPSOCK_WRITE (params->cmdfd, request, sizeof(request));
if (ret == -1) if (ret == PTPSOCK_ERR) {
perror ("sendreq/write to cmdfd"); perror ("sendreq/write to cmdfd");
return GP_ERROR_IO;
}
if (ret != sizeof(request)) { if (ret != sizeof(request)) {
GP_LOG_E ("ptp_ptpip_senddata() len=%d but ret=%d", (int)sizeof(r equest), ret); GP_LOG_E ("ptp_ptpip_senddata() len=%d but ret=%d", (int)sizeof(r equest), ret);
return PTP_RC_GeneralError; return PTP_RC_GeneralError;
} }
xdata = malloc(WRITE_BLOCKSIZE+8+4); xdata = malloc(WRITE_BLOCKSIZE+8+4);
if (!xdata) return PTP_RC_GeneralError; if (!xdata) return PTP_RC_GeneralError;
curwrite = 0; curwrite = 0;
while (curwrite < size) { while (curwrite < size) {
unsigned long type, written, towrite2, xtowrite; unsigned long type, written, towrite2, xtowrite;
skipping to change at line 290 skipping to change at line 298
free (xdata); free (xdata);
return PTP_RC_GeneralError; return PTP_RC_GeneralError;
} }
towrite2 = xtowrite + 12; towrite2 = xtowrite + 12;
htod32a(&xdata[ptpip_type], type); htod32a(&xdata[ptpip_type], type);
htod32a(&xdata[ptpip_len], towrite2); htod32a(&xdata[ptpip_len], towrite2);
htod32a(&xdata[ptpip_data_transid+8], ptp->Transaction_ID); htod32a(&xdata[ptpip_data_transid+8], ptp->Transaction_ID);
GP_LOG_DATA ((char*)xdata, towrite2, "ptpip/senddata data:"); GP_LOG_DATA ((char*)xdata, towrite2, "ptpip/senddata data:");
written = 0; written = 0;
while (written < towrite2) { while (written < towrite2) {
ret = write (params->cmdfd, xdata+written, towrite2-writt ret = PTPSOCK_WRITE (params->cmdfd, xdata+written, towrit
en); e2-written);
if (ret == -1) { if (ret == PTPSOCK_ERR) {
perror ("write in senddata failed"); perror ("write in senddata failed");
free (xdata); free (xdata);
return PTP_RC_GeneralError; return PTP_RC_GeneralError;
} }
written += ret; written += ret;
} }
curwrite += towrite; curwrite += towrite;
} }
free (xdata); free (xdata);
return PTP_RC_OK; return PTP_RC_OK;
skipping to change at line 401 skipping to change at line 409
int n; int n;
GP_LOG_D ("Reading PTP_OC 0x%0x (%s) response...", resp->Code, ptp_get_op code_name(params, resp->Code)); GP_LOG_D ("Reading PTP_OC 0x%0x (%s) response...", resp->Code, ptp_get_op code_name(params, resp->Code));
retry: retry:
ret = ptp_ptpip_cmd_read (params, &hdr, &data); ret = ptp_ptpip_cmd_read (params, &hdr, &data);
if (ret != PTP_RC_OK) if (ret != PTP_RC_OK)
return ret; return ret;
switch (dtoh32(hdr.type)) { switch (dtoh32(hdr.type)) {
case PTPIP_END_DATA_PACKET: case PTPIP_END_DATA_PACKET:
GP_LOG_D("PTPIP_END_DATA_PACKET");
resp->Transaction_ID = dtoh32a(&data[0]); resp->Transaction_ID = dtoh32a(&data[0]);
GP_LOG_D("PTPIP_END_DATA_PACKET (tid = 0x%08x)", resp->Transactio n_ID);
free (data); free (data);
data = NULL; data = NULL;
goto retry; goto retry;
case PTPIP_CMD_RESPONSE: case PTPIP_CMD_RESPONSE:
GP_LOG_D("PTPIP_CMD_RESPONSE");
resp->Code = dtoh16a(&data[ptpip_resp_code]); resp->Code = dtoh16a(&data[ptpip_resp_code]);
resp->Transaction_ID = dtoh32a(&data[ptpip_resp_transid]); resp->Transaction_ID = dtoh32a(&data[ptpip_resp_transid]);
GP_LOG_D("PTPIP_CMD_RESPONSE (result=0x%04x, tid=0x%08x)", resp-> Code, resp->Transaction_ID);
n = (dtoh32(hdr.length) - sizeof(hdr) - ptpip_resp_param1)/sizeof (uint32_t); n = (dtoh32(hdr.length) - sizeof(hdr) - ptpip_resp_param1)/sizeof (uint32_t);
switch (n) { switch (n) {
case 5: resp->Param5 = dtoh32a(&data[ptpip_resp_param5]);/* fallt hrough */ case 5: resp->Param5 = dtoh32a(&data[ptpip_resp_param5]);/* fallt hrough */
case 4: resp->Param4 = dtoh32a(&data[ptpip_resp_param4]);/* fallt hrough */ case 4: resp->Param4 = dtoh32a(&data[ptpip_resp_param4]);/* fallt hrough */
case 3: resp->Param3 = dtoh32a(&data[ptpip_resp_param3]);/* fallt hrough */ case 3: resp->Param3 = dtoh32a(&data[ptpip_resp_param3]);/* fallt hrough */
case 2: resp->Param2 = dtoh32a(&data[ptpip_resp_param2]);/* fallt hrough */ case 2: resp->Param2 = dtoh32a(&data[ptpip_resp_param2]);/* fallt hrough */
case 1: resp->Param1 = dtoh32a(&data[ptpip_resp_param1]);/* fallt hrough */ case 1: resp->Param1 = dtoh32a(&data[ptpip_resp_param1]);/* fallt hrough */
case 0: break; case 0: break;
default: default:
GP_LOG_E ("response got %d parameters?", n); GP_LOG_E ("response got %d parameters?", n);
skipping to change at line 448 skipping to change at line 456
unsigned char* cmdrequest; unsigned char* cmdrequest;
unsigned int i; unsigned int i;
int len, ret; int len, ret;
unsigned char guid[16]; unsigned char guid[16];
ptp_nikon_getptpipguid(guid); ptp_nikon_getptpipguid(guid);
#if !defined (WIN32) #if !defined (WIN32)
if (gethostname (hostname, sizeof(hostname))) if (gethostname (hostname, sizeof(hostname)))
return PTP_RC_GeneralError; return PTP_RC_GeneralError;
#else #else
strcpy (hostname, "gpwindows"); DWORD hostname_size = (DWORD)sizeof(hostname);
if (!GetComputerNameA(hostname, &hostname_size))
return PTP_RC_GeneralError;
#endif #endif
len = ptpip_initcmd_name + (strlen(hostname)+1)*2 + 4; len = ptpip_initcmd_name + (strlen(hostname)+1)*2 + 4;
cmdrequest = malloc(len); cmdrequest = malloc(len);
htod32a(&cmdrequest[ptpip_type],PTPIP_INIT_COMMAND_REQUEST); htod32a(&cmdrequest[ptpip_type],PTPIP_INIT_COMMAND_REQUEST);
htod32a(&cmdrequest[ptpip_len],len); htod32a(&cmdrequest[ptpip_len],len);
memcpy(&cmdrequest[ptpip_initcmd_guid], guid, 16); memcpy(&cmdrequest[ptpip_initcmd_guid], guid, 16);
for (i=0;i<strlen(hostname)+1;i++) { for (i=0;i<strlen(hostname)+1;i++) {
/* -> ucs-2 in little endian */ /* -> ucs-2 in little endian */
cmdrequest[ptpip_initcmd_name+i*2] = hostname[i]; cmdrequest[ptpip_initcmd_name+i*2] = hostname[i];
cmdrequest[ptpip_initcmd_name+i*2+1] = 0; cmdrequest[ptpip_initcmd_name+i*2+1] = 0;
} }
htod16a(&cmdrequest[ptpip_initcmd_name+(strlen(hostname)+1)*2],PTPIP_VERS ION_MINOR); htod16a(&cmdrequest[ptpip_initcmd_name+(strlen(hostname)+1)*2],PTPIP_VERS ION_MINOR);
htod16a(&cmdrequest[ptpip_initcmd_name+(strlen(hostname)+1)*2+2],PTPIP_VE RSION_MAJOR); htod16a(&cmdrequest[ptpip_initcmd_name+(strlen(hostname)+1)*2+2],PTPIP_VE RSION_MAJOR);
GP_LOG_DATA ((char*)cmdrequest, len, "ptpip/init_cmd data:"); GP_LOG_DATA ((char*)cmdrequest, len, "ptpip/init_cmd data:");
ret = write (params->cmdfd, cmdrequest, len); ret = PTPSOCK_WRITE (params->cmdfd, cmdrequest, len);
free (cmdrequest); free (cmdrequest);
if (ret == -1) { if (ret == PTPSOCK_ERR) {
perror("write init cmd request"); perror("write init cmd request");
return PTP_RC_GeneralError; return PTP_RC_GeneralError;
} }
GP_LOG_E ("return %d / len %d", ret, len); GP_LOG_E ("return %d / len %d", ret, len);
if (ret != len) { if (ret != len) {
GP_LOG_E ("return %d vs len %d", ret, len); GP_LOG_E ("return %d vs len %d", ret, len);
return PTP_RC_GeneralError; return PTP_RC_GeneralError;
} }
return PTP_RC_OK; return PTP_RC_OK;
} }
skipping to change at line 507 skipping to change at line 517
GP_LOG_E ("bad type returned %d", htod32(hdr.type)); GP_LOG_E ("bad type returned %d", htod32(hdr.type));
free (data); free (data);
if (hdr.type == PTPIP_INIT_FAIL) /* likely reason is permission d enied */ if (hdr.type == PTPIP_INIT_FAIL) /* likely reason is permission d enied */
return PTP_RC_AccessDenied; return PTP_RC_AccessDenied;
return PTP_RC_GeneralError; return PTP_RC_GeneralError;
} }
params->eventpipeid = dtoh32a(&data[ptpip_cmdack_idx]); params->eventpipeid = dtoh32a(&data[ptpip_cmdack_idx]);
memcpy (params->cameraguid, &data[ptpip_cmdack_guid], 16); memcpy (params->cameraguid, &data[ptpip_cmdack_guid], 16);
name = (unsigned short*)&data[ptpip_cmdack_name]; name = (unsigned short*)&data[ptpip_cmdack_name];
for (i=0;name[i];i++) /* EMPTY */; for (i=0;name[i];i++) /* EMPTY */;
params->cameraname = malloc((i+1)*sizeof(uint16_t)); params->cameraname = calloc((i+1),sizeof(uint16_t));
for (i=0;name[i];i++) for (i=0;name[i];i++)
params->cameraname[i] = name[i]; params->cameraname[i] = name[i];
free (data); free (data);
return PTP_RC_OK; return PTP_RC_OK;
} }
#define ptpip_eventinit_idx 8 #define ptpip_eventinit_idx 8
#define ptpip_eventinit_size 12 #define ptpip_eventinit_size 12
static uint16_t static uint16_t
ptp_ptpip_init_event_request (PTPParams* params) ptp_ptpip_init_event_request (PTPParams* params)
{ {
unsigned char evtrequest[ptpip_eventinit_size]; unsigned char evtrequest[ptpip_eventinit_size];
int ret; int ret;
htod32a(&evtrequest[ptpip_type],PTPIP_INIT_EVENT_REQUEST); htod32a(&evtrequest[ptpip_type],PTPIP_INIT_EVENT_REQUEST);
htod32a(&evtrequest[ptpip_len],ptpip_eventinit_size); htod32a(&evtrequest[ptpip_len],ptpip_eventinit_size);
htod32a(&evtrequest[ptpip_eventinit_idx],params->eventpipeid); htod32a(&evtrequest[ptpip_eventinit_idx],params->eventpipeid);
GP_LOG_DATA ((char*)evtrequest, ptpip_eventinit_size, "ptpip/init_event d ata:"); GP_LOG_DATA ((char*)evtrequest, ptpip_eventinit_size, "ptpip/init_event d ata:");
ret = write (params->evtfd, evtrequest, ptpip_eventinit_size); ret = PTPSOCK_WRITE (params->evtfd, evtrequest, ptpip_eventinit_size);
if (ret == -1) { if (ret == PTPSOCK_ERR) {
perror("write init evt request"); perror("write init evt request");
return PTP_RC_GeneralError; return PTP_RC_GeneralError;
} }
if (ret != ptpip_eventinit_size) { if (ret != ptpip_eventinit_size) {
GP_LOG_E ("unexpected retsize %d, expected %d", ret, ptpip_eventi nit_size); GP_LOG_E ("unexpected retsize %d, expected %d", ret, ptpip_eventi nit_size);
return PTP_RC_GeneralError; return PTP_RC_GeneralError;
} }
return PTP_RC_OK; return PTP_RC_OK;
} }
skipping to change at line 570 skipping to change at line 580
#define ptpip_event_code 0 #define ptpip_event_code 0
#define ptpip_event_transid 2 #define ptpip_event_transid 2
#define ptpip_event_param1 6 #define ptpip_event_param1 6
#define ptpip_event_param2 10 #define ptpip_event_param2 10
#define ptpip_event_param3 14 #define ptpip_event_param3 14
static uint16_t static uint16_t
ptp_ptpip_event (PTPParams* params, PTPContainer* event, int wait) ptp_ptpip_event (PTPParams* params, PTPContainer* event, int wait)
{ {
#ifndef WIN32
fd_set infds; fd_set infds;
struct timeval timeout; struct timeval timeout;
int ret; int ret;
unsigned char* data = NULL; unsigned char* data = NULL;
PTPIPHeader hdr; PTPIPHeader hdr;
int n; int n;
while (1) { while (1) {
FD_ZERO(&infds); FD_ZERO(&infds);
FD_SET(params->evtfd, &infds); FD_SET(params->evtfd, &infds);
skipping to change at line 625 skipping to change at line 634
case 3: event->Param3 = dtoh32a(&data[ptpip_event_param3]);/* fallthrough */ case 3: event->Param3 = dtoh32a(&data[ptpip_event_param3]);/* fallthrough */
case 2: event->Param2 = dtoh32a(&data[ptpip_event_param2]);/* fallthrough */ case 2: event->Param2 = dtoh32a(&data[ptpip_event_param2]);/* fallthrough */
case 1: event->Param1 = dtoh32a(&data[ptpip_event_param1]);/* fallthrough */ case 1: event->Param1 = dtoh32a(&data[ptpip_event_param1]);/* fallthrough */
case 0: break; case 0: break;
default: default:
GP_LOG_E ("response got %d parameters?", n); GP_LOG_E ("response got %d parameters?", n);
break; break;
} }
free (data); free (data);
return PTP_RC_OK; return PTP_RC_OK;
#else
GP_LOG_E ("not supported currently on Windows");
return PTP_RC_OK;
#endif
} }
uint16_t uint16_t
ptp_ptpip_event_check_queue (PTPParams* params, PTPContainer* event) { ptp_ptpip_event_check_queue (PTPParams* params, PTPContainer* event) {
/* the fast check just takes 1ms, so lets keep it */ /* the fast check just takes 1ms, so lets keep it */
return ptp_ptpip_event (params, event, PTP_EVENT_CHECK_FAST); return ptp_ptpip_event (params, event, PTP_EVENT_CHECK_FAST);
} }
uint16_t uint16_t
ptp_ptpip_event_check (PTPParams* params, PTPContainer* event) { ptp_ptpip_event_check (PTPParams* params, PTPContainer* event) {
skipping to change at line 718 skipping to change at line 723
ptp_ptpip_connect (PTPParams* params, const char *address) { ptp_ptpip_connect (PTPParams* params, const char *address) {
char *addr, *s, *p; char *addr, *s, *p;
int port, eventport, tries; int port, eventport, tries;
struct sockaddr_in saddr; struct sockaddr_in saddr;
uint16_t ret; uint16_t ret;
GP_LOG_D ("connecting to %s.", address); GP_LOG_D ("connecting to %s.", address);
if (NULL == strchr (address,':')) if (NULL == strchr (address,':'))
return GP_ERROR_BAD_PARAMETERS; return GP_ERROR_BAD_PARAMETERS;
#ifdef HAVE_INET_ATON
addr = strdup (address); addr = strdup (address);
if (!addr) if (!addr)
return GP_ERROR_NO_MEMORY; return GP_ERROR_NO_MEMORY;
s = strchr (addr,':'); s = strchr (addr,':');
if (!s) { if (!s) {
GP_LOG_E ("addr %s should contain a :", address); GP_LOG_E ("addr %s should contain a :", address);
free (addr); free (addr);
return GP_ERROR_BAD_PARAMETERS; return GP_ERROR_BAD_PARAMETERS;
} }
*s = '\0'; *s = '\0';
skipping to change at line 748 skipping to change at line 752
/* different event port ? */ /* different event port ? */
p = strchr (p+1,':'); p = strchr (p+1,':');
if (p) { if (p) {
if (!sscanf (p+1,"%d",&eventport)) { if (!sscanf (p+1,"%d",&eventport)) {
fprintf(stderr,"failed to scan for eventport in % s\n", p+1); fprintf(stderr,"failed to scan for eventport in % s\n", p+1);
free (addr); free (addr);
return GP_ERROR_BAD_PARAMETERS; return GP_ERROR_BAD_PARAMETERS;
} }
} }
} }
#ifdef HAVE_INET_ATON
if (!inet_aton (s+1, &saddr.sin_addr)) { if (!inet_aton (s+1, &saddr.sin_addr)) {
#else
if (inet_pton(AF_INET, s+1, &saddr.sin_addr) != 1) {
#endif
fprintf(stderr,"failed to scan for addr in %s\n", s+1); fprintf(stderr,"failed to scan for addr in %s\n", s+1);
free (addr); free (addr);
return GP_ERROR_BAD_PARAMETERS; return GP_ERROR_BAD_PARAMETERS;
} }
saddr.sin_port = htons(port); saddr.sin_port = htons(port);
saddr.sin_family = AF_INET; saddr.sin_family = AF_INET;
free (addr); free (addr);
params->cmdfd = socket (PF_INET, SOCK_STREAM, 0); PTPSOCK_SOCKTYPE cmdfd = params->cmdfd = socket (PF_INET, SOCK_STREAM, PT
if (params->cmdfd == -1) { PSOCK_PROTO);
if (cmdfd == PTPSOCK_INVALID) {
perror ("socket cmd"); perror ("socket cmd");
return GP_ERROR_BAD_PARAMETERS; return GP_ERROR_BAD_PARAMETERS;
} }
params->evtfd = socket (PF_INET, SOCK_STREAM, 0); PTPSOCK_SOCKTYPE evtfd = params->evtfd = socket (PF_INET, SOCK_STREAM, PT
if (params->evtfd == -1) { PSOCK_PROTO);
if (evtfd == PTPSOCK_INVALID) {
perror ("socket evt"); perror ("socket evt");
close (params->cmdfd); PTPSOCK_CLOSE (params->cmdfd);
return GP_ERROR_BAD_PARAMETERS; return GP_ERROR_BAD_PARAMETERS;
} }
if (-1 == connect (params->cmdfd, (struct sockaddr*)&saddr, sizeof(struct sockaddr_in))) { if (PTPSOCK_ERR == connect (params->cmdfd, (struct sockaddr*)&saddr, size of(struct sockaddr_in))) {
perror ("connect cmd"); perror ("connect cmd");
close (params->cmdfd); PTPSOCK_CLOSE (params->cmdfd);
close (params->evtfd); PTPSOCK_CLOSE (params->evtfd);
return GP_ERROR_IO; return GP_ERROR_IO;
} }
ret = ptp_ptpip_init_command_request (params); ret = ptp_ptpip_init_command_request (params);
if (ret != PTP_RC_OK) { if (ret != PTP_RC_OK) {
close (params->cmdfd); PTPSOCK_CLOSE (params->cmdfd);
close (params->evtfd); PTPSOCK_CLOSE (params->evtfd);
return translate_ptp_result (ret); return translate_ptp_result (ret);
} }
ret = ptp_ptpip_init_command_ack (params); ret = ptp_ptpip_init_command_ack (params);
if (ret != PTP_RC_OK) { if (ret != PTP_RC_OK) {
close (params->cmdfd); PTPSOCK_CLOSE (params->cmdfd);
close (params->evtfd); PTPSOCK_CLOSE (params->evtfd);
return translate_ptp_result (ret); return translate_ptp_result (ret);
} }
/* seen on Ricoh Theta, camera is not immediately ready. try again two ti mes. */ /* seen on Ricoh Theta, camera is not immediately ready. try again two ti mes. */
tries = 2; tries = 2;
saddr.sin_port = htons(eventport); saddr.sin_port = htons(eventport);
do { do {
if (-1 != connect (params->evtfd, (struct sockaddr*)&saddr, sizeo f(struct sockaddr_in))) if (PTPSOCK_ERR != connect (params->evtfd, (struct sockaddr*)&sad dr, sizeof(struct sockaddr_in)))
break; break;
if ((errno == ECONNREFUSED) && (tries--)) { if ((errno == ECONNREFUSED) && (tries--)) {
GP_LOG_D ("event connect failed, retrying after short wai t"); GP_LOG_D ("event connect failed, retrying after short wai t");
usleep(100*1000); int sleep_ms = 100;
#ifdef WIN32
Sleep(sleep_ms);
#else
usleep(sleep_ms*1000);
#endif
continue; continue;
} }
GP_LOG_E ("could not connect event"); GP_LOG_E ("could not connect event");
close (params->cmdfd); PTPSOCK_CLOSE (params->cmdfd);
close (params->evtfd); PTPSOCK_CLOSE (params->evtfd);
return GP_ERROR_IO; return GP_ERROR_IO;
} while (1); } while (1);
ret = ptp_ptpip_init_event_request (params); ret = ptp_ptpip_init_event_request (params);
if (ret != PTP_RC_OK) if (ret != PTP_RC_OK)
return translate_ptp_result (ret); return translate_ptp_result (ret);
ret = ptp_ptpip_init_event_ack (params); ret = ptp_ptpip_init_event_ack (params);
if (ret != PTP_RC_OK) if (ret != PTP_RC_OK)
return translate_ptp_result (ret); return translate_ptp_result (ret);
GP_LOG_D ("ptpip connected!"); GP_LOG_D ("ptpip connected!");
return GP_OK; return GP_OK;
#else
GP_LOG_E ("Windows currently not supported, neeeds a winsock port.");
return GP_ERROR_NOT_SUPPORTED;
#endif
} }
 End of changes. 36 change blocks. 
46 lines changed or deleted 57 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)