From 6be689f5cdfa5d4c16c71a314616023e4ce5617a Mon Sep 17 00:00:00 2001 From: Dealer_WeARE Date: Sun, 28 Apr 2019 17:21:32 +0200 Subject: [PATCH] Use forward declaration for ssl. --- ftplib.cpp | 27 +++++++++++++++++++++++---- ftplib.h | 40 ++++++++++++++++++++++++---------------- sample/Readme.md | 23 ++++++++++++++--------- sample/sample.cpp | 4 ++-- 4 files changed, 63 insertions(+), 31 deletions(-) diff --git a/ftplib.cpp b/ftplib.cpp index 924ed9a..2febcf2 100755 --- a/ftplib.cpp +++ b/ftplib.cpp @@ -5,8 +5,16 @@ #define _LARGEFILE64_SOURCE #endif +#ifndef NOSSL +#include +#endif + #include "ftplib.h" +#ifndef NOSSL +#include +#endif + #if defined(_WIN32) #include #include @@ -1527,9 +1535,13 @@ int ftplib::Fxp(ftplib* src, ftplib* dst, const char *pathSrc, const char *pathD return retval; } -#ifndef NOSSL + int ftplib::SetDataEncryption(dataencryption enc) { +#ifdef NOSSL + (void)enc; + return 0; +#else if (!mp_ftphandle->tlsctrl) return 0; if (!FtpSendCmd("PBSZ 0",'2',mp_ftphandle)) return 0; switch(enc) @@ -1546,10 +1558,14 @@ int ftplib::SetDataEncryption(dataencryption enc) return 0; } return 1; +#endif } int ftplib::NegotiateEncryption() { +#ifdef NOSSL + return 0; +#else int ret; if (!FtpSendCmd("AUTH TLS",'2',mp_ftphandle)) return 0; @@ -1569,14 +1585,17 @@ int ftplib::NegotiateEncryption() if (ret < 1) return 0; return 1; +#endif } void ftplib::SetCallbackCertFunction(FtpCallbackCert pointer) { - mp_ftphandle->certcb = pointer; -} - +#ifdef NOSSL + (void)pointer; +#else + mp_ftphandle->certcb = pointer; #endif +} void ftplib::SetCallbackIdleFunction(FtpCallbackIdle pointer) { diff --git a/ftplib.h b/ftplib.h index 45a7e84..a77d792 100755 --- a/ftplib.h +++ b/ftplib.h @@ -53,16 +53,26 @@ #define fopen64 fopen #endif -#ifndef NOSSL -#include -#endif +//SSL +typedef struct ssl_st SSL; +typedef struct ssl_ctx_st SSL_CTX; +typedef struct bio_st BIO; +typedef struct x509_st X509; + +#include #ifndef _FTPLIB_SSL_CLIENT_METHOD_ #define _FTPLIB_SSL_CLIENT_METHOD_ TLSv1_2_client_method -#endif//_FTPLIB_SSL_CLIENT_METHOD_ +#endif using namespace std; +//SSL +typedef struct ssl_st SSL; +typedef struct ssl_ctx_st SSL_CTX; +typedef struct bio_st BIO; +typedef struct x509_st X509; + /** *@author mkulke */ @@ -70,10 +80,9 @@ using namespace std; typedef int (*FtpCallbackXfer)(off64_t xfered, void *arg); typedef int (*FtpCallbackIdle)(void *arg); typedef void (*FtpCallbackLog)(char *str, void* arg, bool out); - -#ifndef NOSSL +//SSL typedef bool (*FtpCallbackCert)(void *arg, X509 *cert); -#endif + struct ftphandle { char *cput,*cget; @@ -92,14 +101,14 @@ struct ftphandle { off64_t cbbytes; off64_t xfered1; char response[256]; -#ifndef NOSSL + //SSL SSL* ssl; SSL_CTX* ctx; BIO* sbio; int tlsctrl; int tlsdata; FtpCallbackCert certcb; -#endif + off64_t offset; bool correctpasv; }; @@ -136,8 +145,8 @@ class ftplib { enum fxpmethod { defaultfxp = 0, - alternativefxp - }; + alternativefxp + }; enum dataencryption { @@ -166,11 +175,6 @@ class ftplib { 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); @@ -185,6 +189,10 @@ class ftplib { int RawClose(ftphandle* handle); int RawWrite(void* buf, int len, ftphandle* handle); int RawRead(void* buf, int max, ftphandle* handle); + // SSL + int SetDataEncryption(dataencryption enc); + int NegotiateEncryption(); + void SetCallbackCertFunction(FtpCallbackCert pointer); private: ftphandle* mp_ftphandle; diff --git a/sample/Readme.md b/sample/Readme.md index 55fd85c..0c73e49 100644 --- a/sample/Readme.md +++ b/sample/Readme.md @@ -1,13 +1,18 @@ -Sample Project -=== +# Sample Project - g++ -I.. -c sample.cpp - g++ -L.. -o sample sample.o -lftp++ +``` +g++ -I.. -c sample.cpp +g++ -L.. -o sample sample.o -lftp++ +``` -OSX: - - DYLD_LIBRARY_PATH=.. ./sample +## MacOs -LINUX: +``` +DYLD_LIBRARY_PATH=.. ./sample +``` - LD_LIBRARY_PATH=.. ./sample +## Linux + +``` +LD_LIBRARY_PATH=.. ./sample +``` diff --git a/sample/sample.cpp b/sample/sample.cpp index 7025191..f96e6d6 100644 --- a/sample/sample.cpp +++ b/sample/sample.cpp @@ -2,10 +2,10 @@ int main(void) { - ftplib *ftp = new ftplib::ftplib(); + ftplib *ftp = new ftplib(); ftp->Connect("ftp.gwdg.de:21"); ftp->Login("anonymous", ""); - ftp->Dir(NULL, "/ftp/pub"); + ftp->Dir(NULL, "/pub/linux/apache"); ftp->Quit(); return 0; }