Subversion Repositories tpanel

Rev

Rev 370 | Rev 391 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 370 Rev 380
Line -... Line 1...
-
 
1
/***************************************************************************
-
 
2
 *                    ftplib.cpp  -  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
 ***************************************************************************/
1
#ifndef NOLFS
24
#ifndef NOLFS
2
#define _LARGEFILE_SOURCE
25
#define _LARGEFILE_SOURCE
3
#define _LARGEFILE64_SOURCE
26
#define _LARGEFILE64_SOURCE
4
#endif
27
#endif
5
 
28
 
Line 171... Line 194...
171
        {
194
        {
172
            x = (max >= ctl->cavail) ? ctl->cavail : max - 1;
195
            x = (max >= ctl->cavail) ? ctl->cavail : max - 1;
173
            end = static_cast<char*>(memccpy(bp, ctl->cget, '\n', x));
196
            end = static_cast<char*>(memccpy(bp, ctl->cget, '\n', x));
174
 
197
 
175
            if (end != NULL)
198
            if (end != NULL)
176
                x = (int)(end - bp);
199
                x = end - bp;
177
 
200
 
178
            retval += x;
201
            retval += x;
179
            bp += x;
202
            bp += x;
180
            *bp = '\0';
203
            *bp = '\0';
181
            max -= x;
204
            max -= x;
Line 227... Line 250...
227
        else
250
        else
228
        {
251
        {
229
            if (ctl->tlsctrl)
252
            if (ctl->tlsctrl)
230
                x = SSL_read(ctl->ssl, ctl->cput, ctl->cleft);
253
                x = SSL_read(ctl->ssl, ctl->cput, ctl->cleft);
231
            else
254
            else
232
                x = (int)read(ctl->handle, ctl->cput, ctl->cleft);
255
                x = read(ctl->handle, ctl->cput, ctl->cleft);
233
        }
256
        }
234
 
257
 
235
#else
258
#else
236
        x = read(ctl->handle, ctl->cput, ctl->cleft);
259
        x = read(ctl->handle, ctl->cput, ctl->cleft);
237
#endif
260
#endif
Line 291... Line 314...
291
#ifndef NOSSL
314
#ifndef NOSSL
292
 
315
 
293
                if (nData->tlsctrl)
316
                if (nData->tlsctrl)
294
                    w = SSL_write(nData->ssl, nbp, FTPLIB_BUFSIZ);
317
                    w = SSL_write(nData->ssl, nbp, FTPLIB_BUFSIZ);
295
                else
318
                else
296
                    w = (int)write(nData->handle, nbp, FTPLIB_BUFSIZ);
319
                    w = write(nData->handle, nbp, FTPLIB_BUFSIZ);
297
 
320
 
298
#else
321
#else
299
                w = write(nData->handle, nbp, FTPLIB_BUFSIZ);
322
                w = write(nData->handle, nbp, FTPLIB_BUFSIZ);
300
#endif
323
#endif
301
 
324
 
Line 320... Line 343...
320
#ifndef NOSSL
343
#ifndef NOSSL
321
 
344
 
322
            if (nData->tlsctrl)
345
            if (nData->tlsctrl)
323
                w = SSL_write(nData->ssl, nbp, FTPLIB_BUFSIZ);
346
                w = SSL_write(nData->ssl, nbp, FTPLIB_BUFSIZ);
324
            else
347
            else
325
                w = (int)write(nData->handle, nbp, FTPLIB_BUFSIZ);
348
                w = write(nData->handle, nbp, FTPLIB_BUFSIZ);
326
 
349
 
327
#else
350
#else
328
            w = write(nData->handle, nbp, FTPLIB_BUFSIZ);
351
            w = write(nData->handle, nbp, FTPLIB_BUFSIZ);
329
#endif
352
#endif
330
 
353
 
Line 346... Line 369...
346
        if (!socket_wait(nData))
369
        if (!socket_wait(nData))
347
            return x;
370
            return x;
348
 
371
 
349
#ifndef NOSSL
372
#ifndef NOSSL
350
 
373
 
351
        if (nData->tlsctrl)
-
 
352
            w = SSL_write(nData->ssl, nbp, nb);
374
        if (nData->tlsctrl) w = SSL_write(nData->ssl, nbp, nb);
353
        else
-
 
354
            w = (int)write(nData->handle, nbp, nb);
375
        else w = write(nData->handle, nbp, nb);
355
 
376
 
356
#else
377
#else
357
        w = write(nData->handle, nbp, nb);
378
        w = write(nData->handle, nbp, nb);
358
#endif
379
#endif
359
 
380
 
Line 543... Line 564...
543
 
564
 
544
    snprintf(buf, sizeof(buf), "%s\r\n", cmd);
565
    snprintf(buf, sizeof(buf), "%s\r\n", cmd);
545
 
566
 
546
#ifndef NOSSL
567
#ifndef NOSSL
547
    if (nControl->tlsctrl)
568
    if (nControl->tlsctrl)
548
        x = SSL_write(nControl->ssl, buf, (int)strlen(buf));
569
        x = SSL_write(nControl->ssl, buf, strlen(buf));
549
    else
570
    else
550
        x = (int)write(nControl->handle, buf, (int)strlen(buf));
571
        x = write(nControl->handle, buf, strlen(buf));
551
 
572
 
552
#else
573
#else
553
    x = write(nControl->handle, buf, strlen(buf));
574
    x = write(nControl->handle, buf, strlen(buf));
554
#endif
575
#endif
555
 
576
 
Line 731... Line 752...
731
        buf[i++] = ' ';
752
        buf[i++] = ' ';
732
 
753
 
733
        if ((strlen(path) + i) >= sizeof(buf))
754
        if ((strlen(path) + i) >= sizeof(buf))
734
            return 0;
755
            return 0;
735
 
756
 
736
        strncpy(&buf[i], path, sizeof(buf));
757
        strcpy(&buf[i], path);
737
    }
758
    }
738
 
759
 
739
    if (nControl->cmode == ftplib::pasv)
760
    if (nControl->cmode == ftplib::pasv)
740
    {
761
    {
741
        if (FtpOpenPasv(nControl, nData, mode, dir, buf) == -1)
762
        if (FtpOpenPasv(nControl, nData, mode, dir, buf) == -1)
Line 1034... Line 1055...
1034
 
1055
 
1035
    memcpy(cmd + strlen(cmd), "\r\n\0", 3);
1056
    memcpy(cmd + strlen(cmd), "\r\n\0", 3);
1036
#ifndef NOSSL
1057
#ifndef NOSSL
1037
 
1058
 
1038
    if (nControl->tlsctrl)
1059
    if (nControl->tlsctrl)
1039
        ret = SSL_write(nControl->ssl, cmd, (int)strlen(cmd));
1060
        ret = SSL_write(nControl->ssl, cmd, strlen(cmd));
1040
    else
1061
    else
1041
        ret = (int)write(nControl->handle, cmd, (int)strlen(cmd));
1062
        ret = write(nControl->handle, cmd, strlen(cmd));
1042
 
1063
 
1043
#else
1064
#else
1044
    ret = write(nControl->handle, cmd, strlen(cmd));
1065
    ret = write(nControl->handle, cmd, strlen(cmd));
1045
#endif
1066
#endif
1046
 
1067
 
Line 1109... Line 1130...
1109
 */
1130
 */
1110
int ftplib::FtpClose(ftphandle *nData)
1131
int ftplib::FtpClose(ftphandle *nData)
1111
{
1132
{
1112
    ftphandle *ctrl;
1133
    ftphandle *ctrl;
1113
 
1134
 
1114
    if (!nData)
-
 
1115
        return 0;
-
 
1116
 
-
 
1117
    if (nData->dir == FTPLIB_WRITE)
1135
    if (nData->dir == FTPLIB_WRITE)
1118
    {
1136
    {
1119
        if (nData->buf != NULL)
1137
        if (nData->buf != NULL)
1120
            writeline(NULL, 0, nData);
1138
            writeline(NULL, 0, nData);
1121
    }
1139
    }
Line 1161... Line 1179...
1161
 
1179
 
1162
#ifndef NOSSL
1180
#ifndef NOSSL
1163
        if (nData->tlsdata)
1181
        if (nData->tlsdata)
1164
            i = SSL_read(nData->ssl, buf, max);
1182
            i = SSL_read(nData->ssl, buf, max);
1165
        else
1183
        else
1166
            i = (int)read(nData->handle, buf, max);
1184
            i = read(nData->handle, buf, max);
1167
 
1185
 
1168
#else
1186
#else
1169
        i = read(nData->handle, buf, max);
1187
        i = read(nData->handle, buf, max);
1170
#endif
1188
#endif
1171
    }
1189
    }
Line 1208... Line 1226...
1208
#ifndef NOSSL
1226
#ifndef NOSSL
1209
 
1227
 
1210
        if (nData->tlsdata)
1228
        if (nData->tlsdata)
1211
            i = SSL_write(nData->ssl, buf, len);
1229
            i = SSL_write(nData->ssl, buf, len);
1212
        else
1230
        else
1213
            i = (int)write(nData->handle, buf, len);
1231
            i = write(nData->handle, buf, len);
1214
 
1232
 
1215
#else
1233
#else
1216
        i = write(nData->handle, buf, len);
1234
        i = write(nData->handle, buf, len);
1217
#endif
1235
#endif
1218
    }
1236
    }
Line 1484... Line 1502...
1484
 
1502
 
1485
    dbuf = static_cast<char*>(malloc(FTPLIB_BUFSIZ));
1503
    dbuf = static_cast<char*>(malloc(FTPLIB_BUFSIZ));
1486
 
1504
 
1487
    if ((type == ftplib::filewrite) || (type == ftplib::filewriteappend))
1505
    if ((type == ftplib::filewrite) || (type == ftplib::filewriteappend))
1488
    {
1506
    {
1489
        while ((l = (int)fread(dbuf, 1, FTPLIB_BUFSIZ, local)) > 0)
1507
        while ((l = fread(dbuf, 1, FTPLIB_BUFSIZ, local)) > 0)
1490
        {
1508
        {
1491
            if ((c = FtpWrite(dbuf, l, nData)) < l)
1509
            if ((c = FtpWrite(dbuf, l, nData)) < l)
1492
            {
1510
            {
1493
                std::string msg = string("short write: passed ") + std::to_string(l) + ", wrote " + std::to_string(c);
1511
                std::string msg = string("short write: passed ") + std::to_string(l) + ", wrote " + std::to_string(c);
1494
                errorHandler(msg.c_str(), 0, 0);
1512
                errorHandler(msg.c_str(), 0, 0);
Line 1735... Line 1753...
1735
 
1753
 
1736
        strcpy(buf, "RETR");
1754
        strcpy(buf, "RETR");
1737
 
1755
 
1738
        if (pathSrc != NULL)
1756
        if (pathSrc != NULL)
1739
        {
1757
        {
1740
            int i = (int)strlen(buf);
1758
            int i = strlen(buf);
1741
            buf[i++] = ' ';
1759
            buf[i++] = ' ';
1742
 
1760
 
1743
            if ((strlen(pathSrc) + i) >= sizeof(buf))
1761
            if ((strlen(pathSrc) + i) >= sizeof(buf))
1744
                return 0;
1762
                return 0;
1745
 
1763