1
#ifndef _LIBSSH2_SFTP_H
2
#define _LIBSSH2_SFTP_H
4
* Copyright (C) 2010 - 2012 by Daniel Stenberg
5
* Author: Daniel Stenberg <daniel@haxx.se>
7
* Redistribution and use in source and binary forms,
8
* with or without modification, are permitted provided
9
* that the following conditions are met:
11
* Redistributions of source code must retain the above
12
* copyright notice, this list of conditions and the
13
* following disclaimer.
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.
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.
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
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
46
#define MAX_SFTP_OUTGOING_SIZE 30000
48
/* MAX_SFTP_READ_SIZE is how much data is asked for at max in each FXP_READ
51
#define MAX_SFTP_READ_SIZE 2000
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 */
58
ssize_t lefttosend; /* if 0, the entire packet has been sent off */
60
unsigned char packet[1]; /* data */
63
struct sftp_zombie_requests {
64
struct list_node node;
69
#define MIN(x,y) ((x)<(y)?(x):(y))
72
struct _LIBSSH2_SFTP_PACKET
74
struct list_node node; /* linked list header */
77
size_t data_len; /* payload size */
80
typedef struct _LIBSSH2_SFTP_PACKET LIBSSH2_SFTP_PACKET;
82
#define SFTP_HANDLE_MAXLEN 256 /* according to spec! */
84
struct _LIBSSH2_SFTP_HANDLE
86
struct list_node node;
90
char handle[SFTP_HANDLE_MAXLEN];
94
LIBSSH2_SFTP_HANDLE_FILE,
95
LIBSSH2_SFTP_HANDLE_DIR
98
union _libssh2_sftp_handle_data
100
struct _libssh2_sftp_handle_file_data
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 */
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
116
char eof; /* we have read to the end */
118
struct _libssh2_sftp_handle_dir_data
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;
131
/* list of outstanding packets sent to server */
132
struct list_head packet_list;
138
LIBSSH2_CHANNEL *channel;
140
uint32_t request_id, version;
142
struct list_head packets;
144
/* List of FXP_READ responses to ignore because EOF already received. */
145
struct list_head zombie_requests;
147
/* a list of _LIBSSH2_SFTP_HANDLE structs */
148
struct list_head sftp_handles;
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 */
159
/* Time that libssh2_sftp_packet_requirev() started reading */
160
time_t requirev_start;
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;
169
/* State variable used in sftp_read() */
170
libssh2_nonblocking_states read_state;
172
/* State variable used in sftp_packet_read() */
173
libssh2_nonblocking_states packet_state;
175
/* State variable used in sftp_write() */
176
libssh2_nonblocking_states write_state;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;