~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/xpinstall/wizard/libxpnet/src/nsFTPConn.h

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 
2
/*
 
3
 * The contents of this file are subject to the Netscape Public
 
4
 * License Version 1.1 (the "License"); you may not use this file
 
5
 * except in compliance with the License. You may obtain a copy of
 
6
 * the License at http://www.mozilla.org/NPL/
 
7
 *
 
8
 * Software distributed under the License is distributed on an "AS
 
9
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 
10
 * implied. See the License for the specific language governing
 
11
 * rights and limitations under the License.
 
12
 *
 
13
 * The Original Code is Mozilla Communicator client code, 
 
14
 * released March 31, 1998. 
 
15
 *
 
16
 * The Initial Developer of the Original Code is Netscape Communications 
 
17
 * Corporation.  Portions created by Netscape are
 
18
 * Copyright (C) 1998 Netscape Communications Corporation. All
 
19
 * Rights Reserved.
 
20
 *
 
21
 * Contributor(s): 
 
22
 *     Samir Gehani <sgehani@netscape.com>
 
23
 */
 
24
 
 
25
#ifndef _NS_FTPCONN_H_
 
26
#define _NS_FTPCONN_H_
 
27
 
 
28
class nsSocket; 
 
29
 
 
30
typedef int (*FTPGetCB)(int aBytesRd, int aTotal);
 
31
 
 
32
class nsFTPConn
 
33
{
 
34
public:
 
35
    nsFTPConn(char *aHost);
 
36
    nsFTPConn(char *aHost, int (*aEventPumpCB)(void));
 
37
    ~nsFTPConn();
 
38
 
 
39
    /* ftp type */
 
40
    enum
 
41
    {
 
42
        ASCII = 0,
 
43
        BINARY
 
44
    };
 
45
 
 
46
    /* connection state */
 
47
    enum
 
48
    {
 
49
        OPEN = 0,
 
50
        GETTING,
 
51
        CLOSED
 
52
    };
 
53
 
 
54
    int     Open();
 
55
    int     Open(char *aHost);
 
56
    int     ResumeOrGet(char *aSrvPath, char *aLoclPath, int aType, 
 
57
                int aOvWrite, FTPGetCB aCBFunc);
 
58
    int     Get(char *aSrvPath, char *aLoclPath, int aType, 
 
59
                int aOvWrite, FTPGetCB aCBFunc);
 
60
    int     Get(char *aSrvPath, char *aLoclPath, int aType, int aResumePos,
 
61
                int aOvWrite, FTPGetCB aCBFunc);
 
62
    int     Close();
 
63
 
 
64
/*--------------------------------------------------------------------* 
 
65
 *  Errors 
 
66
 *--------------------------------------------------------------------*/
 
67
    enum
 
68
    {
 
69
        OK                  = 0,
 
70
        E_MEM               = -801, /* out of memory */
 
71
        E_PARAM             = -802, /* parameter null or incorrect */
 
72
        E_ALREADY_OPEN      = -803, /* connection already established */
 
73
        E_NOT_OPEN          = -804, /* connection not established, can't use */
 
74
        E_CMD_ERR           = -805, /* ftp command error */
 
75
        E_CMD_FAIL          = -806, /* ftp command failed */
 
76
        E_CMD_UNEXPECTED    = -807, /* ftp command unexpected response */
 
77
        E_WRITE             = -808, /* write to socket/fd failed */
 
78
        E_READ              = -809, /* read on socket/fd failed */
 
79
        E_SMALL_BUF         = -810, /* buffer too small, provide bigger one */
 
80
        E_CANT_OVWRITE      = -811, /* cannot overwrite existing file */
 
81
        E_LOCL_INIT         = -812, /* local file open/init failed */
 
82
        E_USER_CANCEL       = -813, /* user canceled the download */
 
83
        E_INVALID_ADDR      = -814  /* couldn't parse address/port */
 
84
    };
 
85
 
 
86
private:
 
87
    int         FlushCntlSock(nsSocket *aSock, int bailOnTimeOut = 1);
 
88
    int         IssueCmd(const char *aCmd, char *aResp, int aRespSize, 
 
89
                         nsSocket *aSock);
 
90
    int         ParseAddr(char *aBuf, char **aHost, int *aPort);
 
91
    int         DataInit(char *aHost, int aPort, nsSocket **aSock); 
 
92
 
 
93
    int         (*mEventPumpCB)(void);
 
94
    char        *mHost;
 
95
    int         mState;
 
96
    int         mPassive;
 
97
    nsSocket    *mCntlSock;
 
98
    nsSocket    *mDataSock;
 
99
};
 
100
 
 
101
#ifndef NULL
 
102
#define NULL 0
 
103
#endif
 
104
 
 
105
#ifndef TRUE
 
106
#define TRUE 1
 
107
#endif
 
108
 
 
109
#ifndef FALSE
 
110
#define FALSE 0
 
111
#endif
 
112
 
 
113
#ifdef DUMP
 
114
#undef DUMP
 
115
#endif 
 
116
 
 
117
#if defined(DEBUG) || defined(DEBUG_sgehani)
 
118
#define DUMP(_msg) printf("%s %d: %s\n", __FILE__, __LINE__, _msg);
 
119
#else
 
120
#define DUMP(_msg)  
 
121
#endif /* DEBUG */
 
122
 
 
123
#ifndef ERR_CHECK
 
124
#define ERR_CHECK(_func)                                            \
 
125
do {                                                                \
 
126
    err = _func;                                                    \
 
127
    if (err != OK)                                                  \
 
128
        goto BAIL;                                                  \
 
129
} while(0);
 
130
 
 
131
#endif
 
132
 
 
133
#endif /* _NS_FTPCONN_H_ */
 
134