Skip to content

Commit

Permalink
Removed some compiler warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
mkulke committed Apr 28, 2019
1 parent 868547e commit 6e7cd45
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 84 deletions.
1 change: 1 addition & 0 deletions CREDITS
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Thomas Pfau (ftplib author)
Eli Moulton (bugfix)
wangxi19 (bugfix)
Fojtik (bugfix)
30 changes: 14 additions & 16 deletions ftplib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,6 @@ typedef int socklen_t;
#define strdup _strdup
#endif

#ifndef NOLFS
#define _fseek fseek
#define _fopen fopen
#else
#define _fseek fseeko64
#define _fopen fopen64
#endif

using namespace std;

/* socket values */
Expand Down Expand Up @@ -139,6 +131,14 @@ ftplib::~ftplib()
free(mp_ftphandle);
}

void ftplib::sprint_rest(char *buf, off64_t offset) {
#if defined(__APPLE__)
sprintf(buf,"REST %lld",offset);
#else
sprintf(buf,"REST %ld",offset);
#endif
}

/*
* socket_wait - wait for socket to receive or flush data
*
Expand Down Expand Up @@ -627,7 +627,7 @@ int ftplib::FtpAcceptConnection(ftphandle *nData, ftphandle *nControl)
int ftplib::FtpAccess(const char *path, accesstype type, transfermode mode, ftphandle *nControl, ftphandle **nData)
{
char buf[256];
int dir, ret;
int dir;

if ((path == NULL) && ((type == ftplib::filewrite)
|| (type == ftplib::fileread)
Expand Down Expand Up @@ -788,7 +788,7 @@ int ftplib::FtpOpenPort(ftphandle *nControl, ftphandle **nData, transfermode mod
if (mp_ftphandle->offset != 0)
{
char buf[256];
sprintf(buf,"REST %lld", mp_ftphandle->offset);
sprint_rest(buf, mp_ftphandle->offset);
if (!FtpSendCmd(buf,'3',nControl))
{
net_close(sData);
Expand Down Expand Up @@ -892,7 +892,7 @@ int ftplib::FtpOpenPasv(ftphandle *nControl, ftphandle **nData, transfermode mod
if (mp_ftphandle->offset != 0)
{
char buf[256];
sprintf(buf,"REST %lld",mp_ftphandle->offset);
sprint_rest(buf, mp_ftphandle->offset);
if (!FtpSendCmd(buf,'3',nControl)) return 0;
}

Expand Down Expand Up @@ -1187,7 +1187,7 @@ int ftplib::Pwd(char *path, int max)
if (s == NULL) return 0;
s++;
while ((--l) && (*s) && (*s != '"')) *b++ = *s++;
*b++ = '\0';
*b = '\0';
return 1;
}

Expand All @@ -1202,7 +1202,6 @@ int ftplib::FtpXfer(const char *localfile, const char *path, ftphandle *nControl
char *dbuf;
FILE *local = NULL;
ftphandle *nData;
int rv=1; // 3.1-1

if (localfile != NULL)
{
Expand All @@ -1214,13 +1213,13 @@ int ftplib::FtpXfer(const char *localfile, const char *path, ftphandle *nControl
if (type == ftplib::filewrite) { ac[0] = 'r'; ac[1] = '\0'; }
if (mode == ftplib::image) ac[1] = 'b';

local = _fopen(localfile, ac);
local = fopen64(localfile, ac);
if (local == NULL)
{
strncpy(nControl->response, strerror(errno), sizeof(nControl->response));
return 0;
}
if (type == ftplib::filewriteappend) _fseek(local,mp_ftphandle->offset,SEEK_SET);
if (type == ftplib::filewriteappend) fseeko64(local,mp_ftphandle->offset,SEEK_SET);
}
if (local == NULL) local = ((type == ftplib::filewrite)
|| (type == ftplib::filewriteappend)) ? stdin : stdout;
Expand All @@ -1237,7 +1236,6 @@ int ftplib::FtpXfer(const char *localfile, const char *path, ftphandle *nControl
if ((c = FtpWrite(dbuf, l, nData)) < l)
{
printf("short write: passed %d, wrote %d\n", l, c);
rv = 0;
break;
}
}
Expand Down
136 changes: 68 additions & 68 deletions ftplib.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@

#ifdef NOLFS
#define off64_t long
#define fseeko64 fseek
#define fopen64 fopen
#endif

#if defined(__APPLE__)
Expand Down Expand Up @@ -102,7 +104,7 @@ struct ftphandle {
bool correctpasv;
};

#if defined(_WIN32)
#if defined(_WIN32)
class DLLIMPORT ftplib {
#else
class ftplib {
Expand All @@ -117,7 +119,7 @@ class ftplib {
filewrite,
filereadappend,
filewriteappend
};
};

enum transfermode
{
Expand All @@ -137,74 +139,72 @@ class ftplib {
alternativefxp
};

enum dataencryption
{
unencrypted = 0,
secure
};

ftplib();
~ftplib();
char* LastResponse();
int Connect(const char *host);
int Login(const char *user, const char *pass);
int Site(const char *cmd);
int Raw(const char *cmd);
int SysType(char *buf, int max);
int Mkdir(const char *path);
int Chdir(const char *path);
int Cdup();
int Rmdir(const char *path);
int Pwd(char *path, int max);
int Nlst(const char *outputfile, const char *path);
int Dir(const char *outputfile, const char *path);
int Size(const char *path, int *size, transfermode mode);
int ModDate(const char *path, char *dt, int max);
int Get(const char *outputfile, const char *path, transfermode mode, off64_t offset = 0);
int Put(const char *inputfile, const char *path, transfermode mode, off64_t offset = 0);
int Rename(const char *src, const char *dst);
int Delete(const char *path);
#ifndef NOSSL
int SetDataEncryption(dataencryption enc);
int NegotiateEncryption();
void SetCallbackCertFunction(FtpCallbackCert pointer);
enum dataencryption
{
unencrypted = 0,
secure
};

ftplib();
~ftplib();
char* LastResponse();
int Connect(const char *host);
int Login(const char *user, const char *pass);
int Site(const char *cmd);
int Raw(const char *cmd);
int SysType(char *buf, int max);
int Mkdir(const char *path);
int Chdir(const char *path);
int Cdup();
int Rmdir(const char *path);
int Pwd(char *path, int max);
int Nlst(const char *outputfile, const char *path);
int Dir(const char *outputfile, const char *path);
int Size(const char *path, int *size, transfermode mode);
int ModDate(const char *path, char *dt, int max);
int Get(const char *outputfile, const char *path, transfermode mode, off64_t offset = 0);
int Put(const char *inputfile, const char *path, transfermode mode, off64_t offset = 0);
int Rename(const char *src, const char *dst);
int Delete(const char *path);
#ifndef NOSSL
int SetDataEncryption(dataencryption enc);
int NegotiateEncryption();
void SetCallbackCertFunction(FtpCallbackCert pointer);
#endif
int Quit();
void SetCallbackIdleFunction(FtpCallbackIdle pointer);
void SetCallbackLogFunction(FtpCallbackLog pointer);
void SetCallbackXferFunction(FtpCallbackXfer pointer);
void SetCallbackArg(void *arg);
void SetCallbackBytes(off64_t bytes);
void SetCorrectPasv(bool b) { mp_ftphandle->correctpasv = b; };
void SetCallbackIdletime(int time);
void SetConnmode(connmode mode);
static int Fxp(ftplib* src, ftplib* dst, const char *pathSrc, const char *pathDst, transfermode mode, fxpmethod method);

ftphandle* RawOpen(const char *path, accesstype type, transfermode mode);
int RawClose(ftphandle* handle);
int RawWrite(void* buf, int len, ftphandle* handle);
int RawRead(void* buf, int max, ftphandle* handle);
int Quit();
void SetCallbackIdleFunction(FtpCallbackIdle pointer);
void SetCallbackLogFunction(FtpCallbackLog pointer);
void SetCallbackXferFunction(FtpCallbackXfer pointer);
void SetCallbackArg(void *arg);
void SetCallbackBytes(off64_t bytes);
void SetCorrectPasv(bool b) { mp_ftphandle->correctpasv = b; };
void SetCallbackIdletime(int time);
void SetConnmode(connmode mode);
static int Fxp(ftplib* src, ftplib* dst, const char *pathSrc, const char *pathDst, transfermode mode, fxpmethod method);
ftphandle* RawOpen(const char *path, accesstype type, transfermode mode);
int RawClose(ftphandle* handle);
int RawWrite(void* buf, int len, ftphandle* handle);
int RawRead(void* buf, int max, ftphandle* handle);

private:
ftphandle* mp_ftphandle;

int FtpXfer(const char *localfile, const char *path, ftphandle *nControl, accesstype type, transfermode mode);
int FtpOpenPasv(ftphandle *nControl, ftphandle **nData, transfermode mode, int dir, char *cmd);
int FtpSendCmd(const char *cmd, char expresp, ftphandle *nControl);
int FtpAcceptConnection(ftphandle *nData, ftphandle *nControl);
int FtpOpenPort(ftphandle *nControl, ftphandle **nData, transfermode mode, int dir, char *cmd);
int FtpRead(void *buf, int max, ftphandle *nData);
int FtpWrite(void *buf, int len, ftphandle *nData);
int FtpAccess(const char *path, accesstype type, transfermode mode, ftphandle *nControl, ftphandle **nData);
int FtpClose(ftphandle *nData);

int socket_wait(ftphandle *ctl);
int readline(char *buf,int max,ftphandle *ctl);
int writeline(char *buf, int len, ftphandle *nData);
int readresp(char c, ftphandle *nControl);

void ClearHandle();
int CorrectPasvResponse(unsigned char *v);
ftphandle* mp_ftphandle;

int FtpXfer(const char *localfile, const char *path, ftphandle *nControl, accesstype type, transfermode mode);
int FtpOpenPasv(ftphandle *nControl, ftphandle **nData, transfermode mode, int dir, char *cmd);
int FtpSendCmd(const char *cmd, char expresp, ftphandle *nControl);
int FtpAcceptConnection(ftphandle *nData, ftphandle *nControl);
int FtpOpenPort(ftphandle *nControl, ftphandle **nData, transfermode mode, int dir, char *cmd);
int FtpRead(void *buf, int max, ftphandle *nData);
int FtpWrite(void *buf, int len, ftphandle *nData);
int FtpAccess(const char *path, accesstype type, transfermode mode, ftphandle *nControl, ftphandle **nData);
int FtpClose(ftphandle *nData);
int socket_wait(ftphandle *ctl);
int readline(char *buf,int max,ftphandle *ctl);
int writeline(char *buf, int len, ftphandle *nData);
int readresp(char c, ftphandle *nControl);
void sprint_rest(char *buf, off64_t offset);
void ClearHandle();
int CorrectPasvResponse(unsigned char *v);
};

#endif
#endif

0 comments on commit 6e7cd45

Please sign in to comment.