~ubuntu-branches/ubuntu/utopic/pgadmin3/utopic-proposed

« back to all changes in this revision

Viewing changes to pgadmin/include/libssh2/sftp.h

  • Committer: Package Import Robot
  • Author(s): Christoph Berg
  • Date: 2013-09-10 16:16:38 UTC
  • mfrom: (1.3.4)
  • Revision ID: package-import@ubuntu.com-20130910161638-wwup1q553ylww7dr
Tags: 1.18.0-1
* New upstream release.
* Don't install /usr/bin/png2c anymore.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef _LIBSSH2_SFTP_H
 
2
#define _LIBSSH2_SFTP_H
 
3
/*
 
4
 * Copyright (C) 2010 - 2012 by Daniel Stenberg
 
5
 * Author: Daniel Stenberg <daniel@haxx.se>
 
6
 *
 
7
 * Redistribution and use in source and binary forms,
 
8
 * with or without modification, are permitted provided
 
9
 * that the following conditions are met:
 
10
 *
 
11
 *   Redistributions of source code must retain the above
 
12
 *   copyright notice, this list of conditions and the
 
13
 *   following disclaimer.
 
14
 *
 
15
 *   Redistributions in binary form must reproduce the above
 
16
 *   copyright notice, this list of conditions and the following
 
17
 *   disclaimer in the documentation and/or other materials
 
18
 *   provided with the distribution.
 
19
 *
 
20
 *   Neither the name of the copyright holder nor the names
 
21
 *   of any other contributors may be used to endorse or
 
22
 *   promote products derived from this software without
 
23
 *   specific prior written permission.
 
24
 *
 
25
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
 
26
 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 
27
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 
28
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
29
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 
30
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
31
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 
32
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 
33
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 
34
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 
35
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 
36
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
 
37
 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
 
38
 * OF SUCH DAMAGE.
 
39
 *
 
40
 */
 
41
 
 
42
/*
 
43
 * MAX_SFTP_OUTGOING_SIZE MUST not be larger than 32500 or so. This is the
 
44
 * amount of data sent in each FXP_WRITE packet
 
45
 */
 
46
#define MAX_SFTP_OUTGOING_SIZE 30000
 
47
 
 
48
/* MAX_SFTP_READ_SIZE is how much data is asked for at max in each FXP_READ
 
49
 * packets.
 
50
 */
 
51
#define MAX_SFTP_READ_SIZE 2000
 
52
 
 
53
struct sftp_pipeline_chunk {
 
54
    struct list_node node;
 
55
    size_t len; /* WRITE: size of the data to write
 
56
                   READ: how many bytes that was asked for */
 
57
    size_t sent;
 
58
    ssize_t lefttosend; /* if 0, the entire packet has been sent off */
 
59
    uint32_t request_id;
 
60
    unsigned char packet[1]; /* data */
 
61
};
 
62
 
 
63
struct sftp_zombie_requests {
 
64
    struct list_node node;
 
65
    uint32_t request_id;
 
66
};
 
67
 
 
68
#ifndef MIN
 
69
#define MIN(x,y) ((x)<(y)?(x):(y))
 
70
#endif
 
71
 
 
72
struct _LIBSSH2_SFTP_PACKET
 
73
{
 
74
    struct list_node node;   /* linked list header */
 
75
    uint32_t request_id;
 
76
    unsigned char *data;
 
77
    size_t data_len;              /* payload size */
 
78
};
 
79
 
 
80
typedef struct _LIBSSH2_SFTP_PACKET LIBSSH2_SFTP_PACKET;
 
81
 
 
82
#define SFTP_HANDLE_MAXLEN 256 /* according to spec! */
 
83
 
 
84
struct _LIBSSH2_SFTP_HANDLE
 
85
{
 
86
    struct list_node node;
 
87
 
 
88
    LIBSSH2_SFTP *sftp;
 
89
 
 
90
    char handle[SFTP_HANDLE_MAXLEN];
 
91
    size_t handle_len;
 
92
 
 
93
    enum {
 
94
        LIBSSH2_SFTP_HANDLE_FILE,
 
95
        LIBSSH2_SFTP_HANDLE_DIR
 
96
    } handle_type;
 
97
 
 
98
    union _libssh2_sftp_handle_data
 
99
    {
 
100
        struct _libssh2_sftp_handle_file_data
 
101
        {
 
102
            libssh2_uint64_t offset;
 
103
            libssh2_uint64_t offset_sent;
 
104
            size_t acked; /* container for acked data that hasn't been
 
105
                             returned to caller yet, used for sftp_write */
 
106
 
 
107
            /* 'data' is used by sftp_read() and is allocated data that has
 
108
               been received already from the server but wasn't returned to
 
109
               the caller yet. It is of size 'data_len' and 'data_left is the
 
110
               number of bytes not yet returned, counted from the end of the
 
111
               buffer. */
 
112
            unsigned char *data;
 
113
            size_t data_len;
 
114
            size_t data_left;
 
115
 
 
116
            char eof; /* we have read to the end */
 
117
        } file;
 
118
        struct _libssh2_sftp_handle_dir_data
 
119
        {
 
120
            uint32_t names_left;
 
121
            void *names_packet;
 
122
            char *next_name;
 
123
        } dir;
 
124
    } u;
 
125
 
 
126
    /* State variables used in libssh2_sftp_close_handle() */
 
127
    libssh2_nonblocking_states close_state;
 
128
    uint32_t close_request_id;
 
129
    unsigned char *close_packet;
 
130
 
 
131
    /* list of outstanding packets sent to server */
 
132
    struct list_head packet_list;
 
133
 
 
134
};
 
135
 
 
136
struct _LIBSSH2_SFTP
 
137
{
 
138
    LIBSSH2_CHANNEL *channel;
 
139
 
 
140
    uint32_t request_id, version;
 
141
 
 
142
    struct list_head packets;
 
143
 
 
144
    /* List of FXP_READ responses to ignore because EOF already received. */
 
145
    struct list_head zombie_requests;
 
146
 
 
147
    /* a list of _LIBSSH2_SFTP_HANDLE structs */
 
148
    struct list_head sftp_handles;
 
149
 
 
150
    uint32_t last_errno;
 
151
 
 
152
    /* Holder for partial packet, use in libssh2_sftp_packet_read() */
 
153
    unsigned char partial_size[4];      /* buffer for size field   */
 
154
    size_t partial_size_len;            /* size field length       */
 
155
    unsigned char *partial_packet;      /* The data                */
 
156
    uint32_t partial_len;               /* Desired number of bytes */
 
157
    size_t partial_received;            /* Bytes received so far   */
 
158
 
 
159
    /* Time that libssh2_sftp_packet_requirev() started reading */
 
160
    time_t requirev_start;
 
161
 
 
162
    /* State variables used in libssh2_sftp_open_ex() */
 
163
    libssh2_nonblocking_states open_state;
 
164
    unsigned char *open_packet;
 
165
    uint32_t open_packet_len; /* 32 bit on the wire */
 
166
    size_t open_packet_sent;
 
167
    uint32_t open_request_id;
 
168
 
 
169
    /* State variable used in sftp_read() */
 
170
    libssh2_nonblocking_states read_state;
 
171
 
 
172
    /* State variable used in sftp_packet_read() */
 
173
    libssh2_nonblocking_states packet_state;
 
174
 
 
175
    /* State variable used in sftp_write() */
 
176
    libssh2_nonblocking_states write_state;
 
177
 
 
178
    /* State variables used in libssh2_sftp_readdir() */
 
179
    libssh2_nonblocking_states readdir_state;
 
180
    unsigned char *readdir_packet;
 
181
    uint32_t readdir_request_id;
 
182
 
 
183
    /* State variables used in libssh2_sftp_fstat_ex() */
 
184
    libssh2_nonblocking_states fstat_state;
 
185
    unsigned char *fstat_packet;
 
186
    uint32_t fstat_request_id;
 
187
 
 
188
    /* State variables used in libssh2_sftp_unlink_ex() */
 
189
    libssh2_nonblocking_states unlink_state;
 
190
    unsigned char *unlink_packet;
 
191
    uint32_t unlink_request_id;
 
192
 
 
193
    /* State variables used in libssh2_sftp_rename_ex() */
 
194
    libssh2_nonblocking_states rename_state;
 
195
    unsigned char *rename_packet;
 
196
    unsigned char *rename_s;
 
197
    uint32_t rename_request_id;
 
198
 
 
199
    /* State variables used in libssh2_sftp_fstatvfs() */
 
200
    libssh2_nonblocking_states fstatvfs_state;
 
201
    unsigned char *fstatvfs_packet;
 
202
    uint32_t fstatvfs_request_id;
 
203
 
 
204
    /* State variables used in libssh2_sftp_statvfs() */
 
205
    libssh2_nonblocking_states statvfs_state;
 
206
    unsigned char *statvfs_packet;
 
207
    uint32_t statvfs_request_id;
 
208
 
 
209
    /* State variables used in libssh2_sftp_mkdir() */
 
210
    libssh2_nonblocking_states mkdir_state;
 
211
    unsigned char *mkdir_packet;
 
212
    uint32_t mkdir_request_id;
 
213
 
 
214
    /* State variables used in libssh2_sftp_rmdir() */
 
215
    libssh2_nonblocking_states rmdir_state;
 
216
    unsigned char *rmdir_packet;
 
217
    uint32_t rmdir_request_id;
 
218
 
 
219
    /* State variables used in libssh2_sftp_stat() */
 
220
    libssh2_nonblocking_states stat_state;
 
221
    unsigned char *stat_packet;
 
222
    uint32_t stat_request_id;
 
223
 
 
224
    /* State variables used in libssh2_sftp_symlink() */
 
225
    libssh2_nonblocking_states symlink_state;
 
226
    unsigned char *symlink_packet;
 
227
    uint32_t symlink_request_id;
 
228
};
 
229
 
 
230
#endif