~ubuntu-branches/ubuntu/quantal/ncbi-tools6/quantal

« back to all changes in this revision

Viewing changes to connect/ncbi_ftp_connector.c

Tags: upstream-6.1.20081116a
ImportĀ upstreamĀ versionĀ 6.1.20081116a

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*  $Id: ncbi_ftp_connector.c,v 1.21 2007/10/17 15:25:43 kazimird Exp $
 
1
/* $Id: ncbi_ftp_connector.c,v 1.24 2008/10/16 18:55:44 kazimird Exp $
2
2
 * ===========================================================================
3
3
 *
4
4
 *                            PUBLIC DOMAIN NOTICE
38
38
#include "ncbi_ansi_ext.h"
39
39
#include "ncbi_assert.h"
40
40
#include "ncbi_priv.h"
41
 
#include <connect/ncbi_buffer.h>
42
41
#include <connect/ncbi_ftp_connector.h>
43
42
#include <connect/ncbi_socket.h>
44
43
#include <ctype.h>
45
44
#include <stdio.h>
46
45
#include <stdlib.h>
47
46
 
48
 
 
49
47
#define NCBI_USE_ERRCODE_X   Connect_FTP
50
48
 
51
49
 
53
51
 *  INTERNAL -- Auxiliary types and static functions
54
52
 ***********************************************************************/
55
53
 
56
 
 
57
54
typedef enum {
58
 
    eFtpFeature_None = 0,
59
 
    eFtpFeature_MDTM = 1,
60
 
    eFtpFeature_SIZE = 2
61
 
} EFtpFeature;
62
 
typedef unsigned int TFtpFeatures; /* bitwise OR of individual EFtpFeature's */
 
55
    fFtpFeature_MDTM = 1,
 
56
    fFtpFeature_SIZE = 2
 
57
} EFTP_Feature;
 
58
typedef unsigned int TFTP_Features; /* bitwise OR of individual EFtpFeature's */
63
59
 
64
60
 
65
61
/* All internal data necessary to perform the (re)connect and i/o
71
67
    const char*    pass;
72
68
    const char*    path;
73
69
    const char*    name;
74
 
    TFtpFeatures   feat;
 
70
    TFTP_Features  feat;
75
71
    TFCDC_Flags    flag;
76
72
    SOCK           cntl;  /* control connection */
77
73
    SOCK           data;  /* data    connection */
311
307
        else {
312
308
            if (status == eIO_Timeout) {
313
309
                CORE_LOG_X(1, eLOG_Warning,
314
 
                         "[FTP]  Timed out on data connection abort");
 
310
                           "[FTP]  Timed out on data connection abort");
315
311
            }
316
312
            SOCK_Abort(xxx->data);
317
313
        }
361
357
    port = (unsigned short) i;
362
358
    if (SOCK_ntoa(host, buf, sizeof(buf)) == 0  &&
363
359
        SOCK_CreateEx(buf, port, &instant, &xxx->data, 0, 0,
364
 
                      xxx->flag & eFCDC_LogData ? eOn : eDefault)
 
360
                      xxx->flag & fFCDC_LogData
 
361
                      ? fSOCK_LogOn
 
362
                      : fSOCK_LogDefault)
365
363
        == eIO_Success) {
366
364
        return eIO_Success;
367
365
    }
423
421
            s[size] = '\0';
424
422
        if (!(c = strchr(s, ' ')))
425
423
            c = s + strlen(s);
426
 
        if (!(size = (size_t)(c - s))) {
 
424
        if (!(size = (size_t)(c - s))  ||  size < 3  ||  size > 4) {
427
425
            status = eIO_Unknown;
428
 
        } else if (strncasecmp(s, "CWD",  size) == 0) {
 
426
        } else if (size == 3  &&  strncasecmp(s, "CWD",  3) == 0) {
429
427
            status = s_FTPChdir(xxx, s);
430
 
        } else if (strncasecmp(s, "LIST", size) == 0  ||
431
 
                   strncasecmp(s, "NLST", size) == 0  ||
432
 
                   strncasecmp(s, "RETR", size) == 0) {
 
428
        } else if (size == 4  && (strncasecmp(s, "LIST", 4) == 0  ||
 
429
                                  strncasecmp(s, "NLST", 4) == 0  ||
 
430
                                  strncasecmp(s, "RETR", 4) == 0)) {
433
431
            status = s_FTPRetrieve(xxx, s);
434
 
        } else if (strncasecmp(s, "REST", size) == 0) {
 
432
        } else if (size == 4  &&  strncasecmp(s, "REST", 4) == 0) {
435
433
            status = s_FTPCommand(xxx, s, 0);
436
434
            if (status == eIO_Success) {
437
435
                int code;
507
505
 
508
506
    assert(!xxx->data  &&  !xxx->cntl);
509
507
    status = SOCK_CreateEx(xxx->host, xxx->port, timeout, &xxx->cntl, 0, 0,
510
 
                           xxx->flag & eFCDC_LogControl ? eOn : eDefault);
 
508
                           xxx->flag & fFCDC_LogControl
 
509
                           ? fSOCK_LogOn : fSOCK_LogDefault);
511
510
    if (status == eIO_Success)
512
511
        status = s_FTPLogin(xxx, timeout);
513
512
    if (status == eIO_Success)
721
720
    CONNECTOR      ccc = (SConnector*)    malloc(sizeof(SConnector));
722
721
    SFTPConnector* xxx = (SFTPConnector*) malloc(sizeof(*xxx));
723
722
 
724
 
    assert(!(flag & ~eFCDC_LogAll));
 
723
    assert(!(flag & ~fFCDC_LogAll));
725
724
 
726
725
    xxx->data    = 0;
727
726
    xxx->cntl    = 0;