Subversion Repositories tpanel

Rev

Rev 117 | Rev 137 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
117 andreas 1
/***************************************************************************
2
 *                    ftplib.h  -  description
3
 *                       -------------------
4
 b e*gin                : Son Jul 27 2003
5
 copyright            : (C) 2013 by magnus kulke
6
 email                : mkulke@gmail.com
7
 ***************************************************************************/
8
 
9
/***************************************************************************
10
 *                                                                         *
11
 *   This program is free software; you can redistribute it and/or modify  *
12
 *   it under the terms of the GNU Lesser General Public License as        *
13
 *   published by the Free Software Foundation; either version 2.1 of the  *
14
 *   License, or (at your option) any later version.                       *
15
 *                                                                         *
16
 ***************************************************************************/
17
 
18
/***************************************************************************
19
 * Note: ftplib, on which ftplibpp was originally based upon used to be    *
20
 * licensed as GPL 2.0 software, as of Jan. 26th 2013 its author Thomas    *
21
 * Pfau allowed the distribution of ftplib via LGPL. Thus the license of   *
22
 * ftplibpp changed aswell.                                                *
23
 ***************************************************************************/
24
 
25
#ifndef FTPLIB_H
26
#define FTPLIB_H
27
 
28
#include <unistd.h>
29
#include <sys/time.h>
30
 
31
#ifdef NOLFS
32
#define off64_t long
33
#define fseeko64 fseek
34
#define fopen64 fopen
35
#endif
36
 
37
#if defined(__APPLE__)
38
#define off64_t __darwin_off_t
39
#define fseeko64 fseeko
40
#define fopen64 fopen
41
#endif
42
 
43
//SSL
44
typedef struct ssl_st SSL;
45
typedef struct ssl_ctx_st SSL_CTX;
46
typedef struct bio_st BIO;
47
typedef struct x509_st X509;
48
 
49
#include <sys/types.h>
50
 
51
#ifndef _FTPLIB_SSL_CLIENT_METHOD_
52
#define _FTPLIB_SSL_CLIENT_METHOD_ TLSv1_2_client_method
53
#endif
54
 
55
//SSL
56
typedef struct ssl_st SSL;
57
typedef struct ssl_ctx_st SSL_CTX;
58
typedef struct bio_st BIO;
59
typedef struct x509_st X509;
60
 
61
/**
62
 * @author mkulke
63
 */
64
 
65
typedef int (*FtpCallbackXfer)(off64_t xfered, void *arg);
66
typedef int (*FtpCallbackIdle)(void *arg);
67
typedef void (*FtpCallbackLog)(char *str, void* arg, bool out);
120 andreas 68
typedef void (*FtpCallbackError)(char *str, void* arg, int err);
117 andreas 69
//SSL
70
typedef bool (*FtpCallbackCert)(void *arg, X509 *cert);
71
 
72
 
73
struct ftphandle
74
{
75
    char *cput,*cget;
76
    int handle;
77
    int cavail,cleft;
78
    char *buf;
79
    int dir;
80
    ftphandle *ctrl;
81
    int cmode;
82
    struct timeval idletime;
83
    FtpCallbackXfer xfercb;
84
    FtpCallbackIdle idlecb;
85
    FtpCallbackLog logcb;
120 andreas 86
    FtpCallbackError errorcb;
117 andreas 87
    void *cbarg;
88
    off64_t xfered;
89
    off64_t cbbytes;
90
    off64_t xfered1;
91
    char response[256];
92
    //SSL
93
    SSL* ssl;
94
    SSL_CTX* ctx;
95
    BIO* sbio;
96
    int tlsctrl;
97
    int tlsdata;
98
    FtpCallbackCert certcb;
99
 
100
    off64_t offset;
101
    bool correctpasv;
102
};
103
 
104
class ftplib
105
{
106
    public:
107
        enum accesstype
108
        {
109
            dir = 1,
110
            dirverbose,
111
            fileread,
112
            filewrite,
113
            filereadappend,
114
            filewriteappend
115
        };
116
 
117
        enum transfermode
118
        {
119
            ascii = 'A',
120
            image = 'I'
121
        };
122
 
123
        enum connmode
124
        {
125
            pasv = 1,
126
            port
127
        };
128
 
129
        enum fxpmethod
130
        {
131
            defaultfxp = 0,
132
            alternativefxp
133
        };
134
 
135
        enum dataencryption
136
        {
137
            unencrypted = 0,
138
            secure
139
        };
140
 
141
        ftplib();
142
        ~ftplib();
143
        char* LastResponse();
144
        int Connect(const char *host);
145
        int Login(const char *user, const char *pass);
146
        int Site(const char *cmd);
147
        int Raw(const char *cmd);
148
        int SysType(char *buf, int max);
149
        int Mkdir(const char *path);
150
        int Chdir(const char *path);
151
        int Cdup();
152
        int Rmdir(const char *path);
153
        int Pwd(char *path, int max);
154
        int Nlst(const char *outputfile, const char *path);
155
        int Dir(const char *outputfile, const char *path);
156
        int Size(const char *path, int *size, transfermode mode);
157
        int ModDate(const char *path, char *dt, int max);
158
        int Get(const char *outputfile, const char *path, transfermode mode, off64_t offset = 0);
159
        int Put(const char *inputfile, const char *path, transfermode mode, off64_t offset = 0);
160
        int Rename(const char *src, const char *dst);
161
        int Delete(const char *path);
162
        int Quit();
163
        void SetCallbackIdleFunction(FtpCallbackIdle pointer);
164
        void SetCallbackLogFunction(FtpCallbackLog pointer);
120 andreas 165
        void SetCallbackErrorFunction(FtpCallbackError pointer);
117 andreas 166
        void SetCallbackXferFunction(FtpCallbackXfer pointer);
167
        void SetCallbackArg(void *arg);
168
        void SetCallbackBytes(off64_t bytes);
169
        void SetCorrectPasv(bool b) { mp_ftphandle->correctpasv = b; };
170
        void SetCallbackIdletime(int time);
171
        void SetConnmode(connmode mode);
172
        static int Fxp(ftplib* src, ftplib* dst, const char *pathSrc, const char *pathDst, transfermode mode, fxpmethod method);
173
        ftphandle* RawOpen(const char *path, accesstype type, transfermode mode);
174
        int RawClose(ftphandle* handle);
175
        int RawWrite(void* buf, int len, ftphandle* handle);
176
        int RawRead(void* buf, int max, ftphandle* handle);
177
        // SSL
178
        int SetDataEncryption(dataencryption enc);
179
        int NegotiateEncryption();
180
        void SetCallbackCertFunction(FtpCallbackCert pointer);
181
 
182
    private:
183
        ftphandle* mp_ftphandle;
184
 
185
        int FtpXfer(const char *localfile, const char *path, ftphandle *nControl, accesstype type, transfermode mode);
186
        int FtpOpenPasv(ftphandle *nControl, ftphandle **nData, transfermode mode, int dir, char *cmd);
187
        int FtpSendCmd(const char *cmd, char expresp, ftphandle *nControl);
188
        int FtpAcceptConnection(ftphandle *nData, ftphandle *nControl);
189
        int FtpOpenPort(ftphandle *nControl, ftphandle **nData, transfermode mode, int dir, char *cmd);
190
        int FtpRead(void *buf, int max, ftphandle *nData);
191
        int FtpWrite(void *buf, int len, ftphandle *nData);
192
        int FtpAccess(const char *path, accesstype type, transfermode mode, ftphandle *nControl, ftphandle **nData);
193
        int FtpClose(ftphandle *nData);
194
        int socket_wait(ftphandle *ctl);
195
        int readline(char *buf,int max,ftphandle *ctl);
196
        int writeline(char *buf, int len, ftphandle *nData);
197
        int readresp(char c, ftphandle *nControl);
198
        void sprint_rest(char *buf, off64_t offset);
199
        void ClearHandle();
200
        int CorrectPasvResponse(unsigned char *v);
120 andreas 201
        void errorHandler(const char *stub, int err, int line);
117 andreas 202
    };
203
 
204
#endif