"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "camlibs/ptp2/fujiptpip.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.

fujiptpip.c  (libgphoto2-2.5.26.tar.bz2):fujiptpip.c  (libgphoto2-2.5.27.tar.bz2)
skipping to change at line 45 skipping to change at line 45
* - 4: event (over event pipe) * - 4: event (over event pipe)
* *
* For JPEG pipe, also <length> <data...> blobs are sent. There is a 14 byte blo b in front of the FF D8 start. * For JPEG pipe, also <length> <data...> blobs are sent. There is a 14 byte blo b in front of the FF D8 start.
* *
* There are 3 TCP pipes: * There are 3 TCP pipes:
* - command pipe , port 55740 * - command pipe , port 55740
* - event pipe , port 55741 (camera remote port starts listen when you run "Ini tiateOpenCapture") * - event pipe , port 55741 (camera remote port starts listen when you run "Ini tiateOpenCapture")
* - jpeg pipe , port 55742 (camera remote port starts listen when you run "Init iateOpenCapture") * - jpeg pipe , port 55742 (camera remote port starts listen when you run "Init iateOpenCapture")
*/ */
#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
#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 "ptpip-private.h"
#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"
#include "ptp-private.h" #include "ptp-private.h"
#define PTPIP_VERSION_MAJOR 0x0001 #define PTPIP_VERSION_MAJOR 0x0001
#define PTPIP_VERSION_MINOR 0x0000 #define PTPIP_VERSION_MINOR 0x0000
skipping to change at line 589 skipping to change at line 592
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 = fujiptpip_initcmd_name + (strlen(hostname)+1)*2; len = fujiptpip_initcmd_name + (strlen(hostname)+1)*2;
cmdrequest = malloc(len); cmdrequest = malloc(len);
htod32a(&cmdrequest[fujiptpip_type],PTPIP_INIT_COMMAND_REQUEST); htod32a(&cmdrequest[fujiptpip_type],PTPIP_INIT_COMMAND_REQUEST);
htod32a(&cmdrequest[fujiptpip_len],len); htod32a(&cmdrequest[fujiptpip_len],len);
htod32a(&cmdrequest[fujiptpip_initcmd_protocolversion], 0x8f53e4f2); / * magic number */ htod32a(&cmdrequest[fujiptpip_initcmd_protocolversion], 0x8f53e4f2); / * magic number */
memcpy(&cmdrequest[fujiptpip_initcmd_guid], guid, 16); memcpy(&cmdrequest[fujiptpip_initcmd_guid], guid, 16);
skipping to change at line 612 skipping to change at line 617
cmdrequest[fujiptpip_initcmd_name+i*2] = hostname[i]; cmdrequest[fujiptpip_initcmd_name+i*2] = hostname[i];
cmdrequest[fujiptpip_initcmd_name+i*2+1] = 0; cmdrequest[fujiptpip_initcmd_name+i*2+1] = 0;
} }
/* /*
htod16a(&cmdrequest[fujiptpip_initcmd_name+(strlen(hostname)+1)*2],PTPIP_ VERSION_MINOR); htod16a(&cmdrequest[fujiptpip_initcmd_name+(strlen(hostname)+1)*2],PTPIP_ VERSION_MINOR);
htod16a(&cmdrequest[fujiptpip_initcmd_name+(strlen(hostname)+1)*2+2],PTPI P_VERSION_MAJOR); htod16a(&cmdrequest[fujiptpip_initcmd_name+(strlen(hostname)+1)*2+2],PTPI P_VERSION_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 653 skipping to change at line 658
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 fujiptpip_eventinit_idx 8 #define fujiptpip_eventinit_idx 8
#define fujiptpip_eventinit_size 12 #define fujiptpip_eventinit_size 12
int int
skipping to change at line 676 skipping to change at line 681
char *addr, *s, *p; char *addr, *s, *p;
int port, eventport, tries; int port, eventport, tries;
struct sockaddr_in saddr; struct sockaddr_in saddr;
memset(&saddr,0,sizeof(saddr)); memset(&saddr,0,sizeof(saddr));
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 707 skipping to change at line 711
/* 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;
} }
free (addr); free (addr);
tries = 2; tries = 2;
saddr.sin_family = AF_INET; saddr.sin_family = AF_INET;
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->evtfd); PTPSOCK_CLOSE (params->evtfd);
return GP_ERROR_IO; return GP_ERROR_IO;
} while (1); } while (1);
GP_LOG_D ("fujiptpip event connected!"); GP_LOG_D ("fujiptpip event connected!");
tries = 2; tries = 2;
saddr.sin_family = AF_INET; saddr.sin_family = AF_INET;
saddr.sin_port = htons(eventport+1); saddr.sin_port = htons(eventport+1);
do { do {
if (-1 != connect (params->jpgfd, (struct sockaddr*)&saddr, sizeo f(struct sockaddr_in))) if (PTPSOCK_ERR != connect (params->jpgfd, (struct sockaddr*)&sad dr, sizeof(struct sockaddr_in)))
break; break;
if ((errno == ECONNREFUSED) && (tries--)) { if ((errno == ECONNREFUSED) && (tries--)) {
GP_LOG_D ("jpeg connect failed, retrying after short wait "); GP_LOG_D ("jpeg connect failed, retrying after short wait ");
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->jpgfd); PTPSOCK_CLOSE (params->jpgfd);
return GP_ERROR_IO; return GP_ERROR_IO;
} while (1); } while (1);
return GP_OK; return GP_OK;
#else
GP_LOG_E ("Windows currently not supported, neeeds a winsock port.");
return GP_ERROR_NOT_SUPPORTED;
#endif
} }
/* Event handling functions */ /* Event handling functions */
/* PTP Events wait for or check mode */ /* PTP Events wait for or check mode */
#define ptpip_event_type 0 #define ptpip_event_type 0
#define ptpip_event_code 2 #define ptpip_event_code 2
#define ptpip_event_transid 4 #define ptpip_event_transid 4
#define ptpip_event_param1 8 #define ptpip_event_param1 8
#define ptpip_event_param2 12 #define ptpip_event_param2 12
#define ptpip_event_param3 16 #define ptpip_event_param3 16
#define ptpip_event_param4 20 #define ptpip_event_param4 20
static uint16_t static uint16_t
ptp_fujiptpip_event (PTPParams* params, PTPContainer* event, int wait) ptp_fujiptpip_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 815 skipping to change at line 828
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_fujiptpip_event_check_queue (PTPParams* params, PTPContainer* event) { ptp_fujiptpip_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_fujiptpip_event (params, event, PTP_EVENT_CHECK_FAST); return ptp_fujiptpip_event (params, event, PTP_EVENT_CHECK_FAST);
} }
uint16_t uint16_t
ptp_fujiptpip_event_check (PTPParams* params, PTPContainer* event) { ptp_fujiptpip_event_check (PTPParams* params, PTPContainer* event) {
skipping to change at line 840 skipping to change at line 849
} }
uint16_t uint16_t
ptp_fujiptpip_event_wait (PTPParams* params, PTPContainer* event) { ptp_fujiptpip_event_wait (PTPParams* params, PTPContainer* event) {
return ptp_fujiptpip_event (params, event, PTP_EVENT_CHECK); return ptp_fujiptpip_event (params, event, PTP_EVENT_CHECK);
} }
uint16_t uint16_t
ptp_fujiptpip_jpeg (PTPParams* params, unsigned char** xdata, unsigned int *xsiz e) ptp_fujiptpip_jpeg (PTPParams* params, unsigned char** xdata, unsigned int *xsiz e)
{ {
#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;
while (1) { while (1) {
FD_ZERO(&infds); FD_ZERO(&infds);
FD_SET(params->jpgfd, &infds); FD_SET(params->jpgfd, &infds);
timeout.tv_sec = 1; timeout.tv_sec = 1;
skipping to change at line 871 skipping to change at line 879
ret = ptp_fujiptpip_jpg_read (params, &hdr, &data); ret = ptp_fujiptpip_jpg_read (params, &hdr, &data);
if (ret != PTP_RC_OK) if (ret != PTP_RC_OK)
return ret; return ret;
*xdata = data; *xdata = data;
*xsize = hdr.length - sizeof(uint32_t); *xsize = hdr.length - sizeof(uint32_t);
break; break;
} }
return PTP_RC_OK; return PTP_RC_OK;
#else
GP_LOG_E ("not supported currently on Windows");
return PTP_RC_OK;
#endif
} }
int int
ptp_fujiptpip_connect (PTPParams* params, const char *address) { ptp_fujiptpip_connect (PTPParams* params, const char *address) {
char *addr, *s, *p; char *addr, *s, *p;
int port, eventport; int port, eventport;
struct sockaddr_in saddr; struct sockaddr_in saddr;
uint16_t ret; uint16_t ret;
memset(&saddr,0,sizeof(saddr)); memset(&saddr,0,sizeof(saddr));
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 921 skipping to change at line 924
/* 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;
} }
params->jpgfd = socket (PF_INET, SOCK_STREAM, 0); PTPSOCK_SOCKTYPE jpgfd = params->jpgfd = socket (PF_INET, SOCK_STREAM, 0)
if (params->jpgfd == -1) { ;
if (jpgfd == PTPSOCK_INVALID) {
perror ("socket jpg"); perror ("socket jpg");
close (params->evtfd); PTPSOCK_CLOSE (params->evtfd);
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_fujiptpip_init_command_request (params); ret = ptp_fujiptpip_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_fujiptpip_init_command_ack (params); ret = ptp_fujiptpip_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);
} }
GP_LOG_D ("fujiptpip connected!"); GP_LOG_D ("fujiptpip 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. 34 change blocks. 
47 lines changed or deleted 53 lines changed or added

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