Webserver+3d print

Dependents:   Nucleo

Committer:
Sergunb
Date:
Sat Feb 04 18:15:49 2017 +0000
Revision:
0:8918a71cdbe9
nothing else

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Sergunb 0:8918a71cdbe9 1 /**
Sergunb 0:8918a71cdbe9 2 * @file ftp_client.h
Sergunb 0:8918a71cdbe9 3 * @brief FTP client (File Transfer Protocol)
Sergunb 0:8918a71cdbe9 4 *
Sergunb 0:8918a71cdbe9 5 * @section License
Sergunb 0:8918a71cdbe9 6 *
Sergunb 0:8918a71cdbe9 7 * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved.
Sergunb 0:8918a71cdbe9 8 *
Sergunb 0:8918a71cdbe9 9 * This file is part of CycloneTCP Open.
Sergunb 0:8918a71cdbe9 10 *
Sergunb 0:8918a71cdbe9 11 * This program is free software; you can redistribute it and/or
Sergunb 0:8918a71cdbe9 12 * modify it under the terms of the GNU General Public License
Sergunb 0:8918a71cdbe9 13 * as published by the Free Software Foundation; either version 2
Sergunb 0:8918a71cdbe9 14 * of the License, or (at your option) any later version.
Sergunb 0:8918a71cdbe9 15 *
Sergunb 0:8918a71cdbe9 16 * This program is distributed in the hope that it will be useful,
Sergunb 0:8918a71cdbe9 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Sergunb 0:8918a71cdbe9 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Sergunb 0:8918a71cdbe9 19 * GNU General Public License for more details.
Sergunb 0:8918a71cdbe9 20 *
Sergunb 0:8918a71cdbe9 21 * You should have received a copy of the GNU General Public License
Sergunb 0:8918a71cdbe9 22 * along with this program; if not, write to the Free Software Foundation,
Sergunb 0:8918a71cdbe9 23 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Sergunb 0:8918a71cdbe9 24 *
Sergunb 0:8918a71cdbe9 25 * @author Oryx Embedded SARL (www.oryx-embedded.com)
Sergunb 0:8918a71cdbe9 26 * @version 1.7.6
Sergunb 0:8918a71cdbe9 27 **/
Sergunb 0:8918a71cdbe9 28
Sergunb 0:8918a71cdbe9 29 #ifndef _FTP_CLIENT_H
Sergunb 0:8918a71cdbe9 30 #define _FTP_CLIENT_H
Sergunb 0:8918a71cdbe9 31
Sergunb 0:8918a71cdbe9 32 //Dependencies
Sergunb 0:8918a71cdbe9 33 #include "core/net.h"
Sergunb 0:8918a71cdbe9 34 #include "core/socket.h"
Sergunb 0:8918a71cdbe9 35
Sergunb 0:8918a71cdbe9 36 //FTP client support
Sergunb 0:8918a71cdbe9 37 #ifndef FTP_CLIENT_SUPPORT
Sergunb 0:8918a71cdbe9 38 #define FTP_CLIENT_SUPPORT ENABLED
Sergunb 0:8918a71cdbe9 39 #elif (FTP_CLIENT_SUPPORT != ENABLED && FTP_CLIENT_SUPPORT != DISABLED)
Sergunb 0:8918a71cdbe9 40 #error FTP_CLIENT_SUPPORT parameter is not valid
Sergunb 0:8918a71cdbe9 41 #endif
Sergunb 0:8918a71cdbe9 42
Sergunb 0:8918a71cdbe9 43 //FTP over SSL/TLS
Sergunb 0:8918a71cdbe9 44 #ifndef FTP_CLIENT_TLS_SUPPORT
Sergunb 0:8918a71cdbe9 45 #define FTP_CLIENT_TLS_SUPPORT DISABLED
Sergunb 0:8918a71cdbe9 46 #elif (FTP_CLIENT_TLS_SUPPORT != ENABLED && FTP_CLIENT_TLS_SUPPORT != DISABLED)
Sergunb 0:8918a71cdbe9 47 #error FTP_CLIENT_TLS_SUPPORT parameter is not valid
Sergunb 0:8918a71cdbe9 48 #endif
Sergunb 0:8918a71cdbe9 49
Sergunb 0:8918a71cdbe9 50 //Default timeout
Sergunb 0:8918a71cdbe9 51 #ifndef FTP_CLIENT_DEFAULT_TIMEOUT
Sergunb 0:8918a71cdbe9 52 #define FTP_CLIENT_DEFAULT_TIMEOUT 20000
Sergunb 0:8918a71cdbe9 53 #elif (FTP_CLIENT_DEFAULT_TIMEOUT < 1000)
Sergunb 0:8918a71cdbe9 54 #error FTP_CLIENT_DEFAULT_TIMEOUT parameter is not valid
Sergunb 0:8918a71cdbe9 55 #endif
Sergunb 0:8918a71cdbe9 56
Sergunb 0:8918a71cdbe9 57 //Size of the buffer for input/output operations
Sergunb 0:8918a71cdbe9 58 #ifndef FTP_CLIENT_BUFFER_SIZE
Sergunb 0:8918a71cdbe9 59 #define FTP_CLIENT_BUFFER_SIZE 512
Sergunb 0:8918a71cdbe9 60 #elif (FTP_CLIENT_BUFFER_SIZE < 64)
Sergunb 0:8918a71cdbe9 61 #error FTP_CLIENT_BUFFER_SIZE parameter is not valid
Sergunb 0:8918a71cdbe9 62 #endif
Sergunb 0:8918a71cdbe9 63
Sergunb 0:8918a71cdbe9 64 //Minimum TX buffer size for FTP sockets
Sergunb 0:8918a71cdbe9 65 #ifndef FTP_CLIENT_SOCKET_MIN_TX_BUFFER_SIZE
Sergunb 0:8918a71cdbe9 66 #define FTP_CLIENT_SOCKET_MIN_TX_BUFFER_SIZE 1430
Sergunb 0:8918a71cdbe9 67 #elif (FTP_CLIENT_SOCKET_MIN_TX_BUFFER_SIZE < 1)
Sergunb 0:8918a71cdbe9 68 #error FTP_CLIENT_SOCKET_MIN_TX_BUFFER_SIZE parameter is not valid
Sergunb 0:8918a71cdbe9 69 #endif
Sergunb 0:8918a71cdbe9 70
Sergunb 0:8918a71cdbe9 71 //Minimum RX buffer size for FTP sockets
Sergunb 0:8918a71cdbe9 72 #ifndef FTP_CLIENT_SOCKET_MIN_RX_BUFFER_SIZE
Sergunb 0:8918a71cdbe9 73 #define FTP_CLIENT_SOCKET_MIN_RX_BUFFER_SIZE 1430
Sergunb 0:8918a71cdbe9 74 #elif (FTP_CLIENT_SOCKET_MIN_RX_BUFFER_SIZE < 1)
Sergunb 0:8918a71cdbe9 75 #error FTP_CLIENT_SOCKET_MIN_RX_BUFFER_SIZE parameter is not valid
Sergunb 0:8918a71cdbe9 76 #endif
Sergunb 0:8918a71cdbe9 77
Sergunb 0:8918a71cdbe9 78 //Maximum TX buffer size for FTP sockets
Sergunb 0:8918a71cdbe9 79 #ifndef FTP_CLIENT_SOCKET_MAX_TX_BUFFER_SIZE
Sergunb 0:8918a71cdbe9 80 #define FTP_CLIENT_SOCKET_MAX_TX_BUFFER_SIZE 2860
Sergunb 0:8918a71cdbe9 81 #elif (FTP_CLIENT_SOCKET_MAX_TX_BUFFER_SIZE < 1)
Sergunb 0:8918a71cdbe9 82 #error FTP_CLIENT_SOCKET_MAX_TX_BUFFER_SIZE parameter is not valid
Sergunb 0:8918a71cdbe9 83 #endif
Sergunb 0:8918a71cdbe9 84
Sergunb 0:8918a71cdbe9 85 //Maximum RX buffer size for FTP sockets
Sergunb 0:8918a71cdbe9 86 #ifndef FTP_CLIENT_SOCKET_MAX_RX_BUFFER_SIZE
Sergunb 0:8918a71cdbe9 87 #define FTP_CLIENT_SOCKET_MAX_RX_BUFFER_SIZE 2860
Sergunb 0:8918a71cdbe9 88 #elif (FTP_CLIENT_SOCKET_MAX_RX_BUFFER_SIZE < 1)
Sergunb 0:8918a71cdbe9 89 #error FTP_CLIENT_SOCKET_MAX_RX_BUFFER_SIZE parameter is not valid
Sergunb 0:8918a71cdbe9 90 #endif
Sergunb 0:8918a71cdbe9 91
Sergunb 0:8918a71cdbe9 92 //SSL/TLS supported?
Sergunb 0:8918a71cdbe9 93 #if (FTP_CLIENT_TLS_SUPPORT == ENABLED)
Sergunb 0:8918a71cdbe9 94 #include "crypto.h"
Sergunb 0:8918a71cdbe9 95 #include "tls.h"
Sergunb 0:8918a71cdbe9 96 #endif
Sergunb 0:8918a71cdbe9 97
Sergunb 0:8918a71cdbe9 98 //Test macros for FTP response codes
Sergunb 0:8918a71cdbe9 99 #define FTP_REPLY_CODE_1YZ(code) ((code) >= 100 && (code) < 200)
Sergunb 0:8918a71cdbe9 100 #define FTP_REPLY_CODE_2YZ(code) ((code) >= 200 && (code) < 300)
Sergunb 0:8918a71cdbe9 101 #define FTP_REPLY_CODE_3YZ(code) ((code) >= 300 && (code) < 400)
Sergunb 0:8918a71cdbe9 102 #define FTP_REPLY_CODE_4YZ(code) ((code) >= 400 && (code) < 500)
Sergunb 0:8918a71cdbe9 103 #define FTP_REPLY_CODE_5YZ(code) ((code) >= 500 && (code) < 600)
Sergunb 0:8918a71cdbe9 104
Sergunb 0:8918a71cdbe9 105 //Forward declaration of FtpClientContext structure
Sergunb 0:8918a71cdbe9 106 struct _FtpClientContext;
Sergunb 0:8918a71cdbe9 107 #define FtpClientContext struct _FtpClientContext
Sergunb 0:8918a71cdbe9 108
Sergunb 0:8918a71cdbe9 109
Sergunb 0:8918a71cdbe9 110 /**
Sergunb 0:8918a71cdbe9 111 * @brief Connection options
Sergunb 0:8918a71cdbe9 112 **/
Sergunb 0:8918a71cdbe9 113
Sergunb 0:8918a71cdbe9 114 typedef enum
Sergunb 0:8918a71cdbe9 115 {
Sergunb 0:8918a71cdbe9 116 FTP_NO_SECURITY = 0,
Sergunb 0:8918a71cdbe9 117 FTP_IMPLICIT_SECURITY = 1,
Sergunb 0:8918a71cdbe9 118 FTP_EXPLICIT_SECURITY = 2,
Sergunb 0:8918a71cdbe9 119 FTP_ACTIVE_MODE = 0,
Sergunb 0:8918a71cdbe9 120 FTP_PASSIVE_MODE = 4
Sergunb 0:8918a71cdbe9 121 } FtpConnectionFlags;
Sergunb 0:8918a71cdbe9 122
Sergunb 0:8918a71cdbe9 123
Sergunb 0:8918a71cdbe9 124 /**
Sergunb 0:8918a71cdbe9 125 * @brief File opening options
Sergunb 0:8918a71cdbe9 126 **/
Sergunb 0:8918a71cdbe9 127
Sergunb 0:8918a71cdbe9 128 typedef enum
Sergunb 0:8918a71cdbe9 129 {
Sergunb 0:8918a71cdbe9 130 FTP_FOR_READING = 0,
Sergunb 0:8918a71cdbe9 131 FTP_FOR_WRITING = 1,
Sergunb 0:8918a71cdbe9 132 FTP_FOR_APPENDING = 2,
Sergunb 0:8918a71cdbe9 133 FTP_BINARY_TYPE = 0,
Sergunb 0:8918a71cdbe9 134 FTP_TEXT_TYPE = 4
Sergunb 0:8918a71cdbe9 135 } FtpFileOpeningFlags;
Sergunb 0:8918a71cdbe9 136
Sergunb 0:8918a71cdbe9 137
Sergunb 0:8918a71cdbe9 138 /**
Sergunb 0:8918a71cdbe9 139 * @brief Flags used by I/O functions
Sergunb 0:8918a71cdbe9 140 **/
Sergunb 0:8918a71cdbe9 141
Sergunb 0:8918a71cdbe9 142 typedef enum
Sergunb 0:8918a71cdbe9 143 {
Sergunb 0:8918a71cdbe9 144 FTP_FLAG_PEEK = 0x0200,
Sergunb 0:8918a71cdbe9 145 FTP_FLAG_WAIT_ALL = 0x0800,
Sergunb 0:8918a71cdbe9 146 FTP_FLAG_BREAK_CHAR = 0x1000,
Sergunb 0:8918a71cdbe9 147 FTP_FLAG_BREAK_CRLF = 0x100A,
Sergunb 0:8918a71cdbe9 148 FTP_FLAG_WAIT_ACK = 0x2000
Sergunb 0:8918a71cdbe9 149 } FtpFlags;
Sergunb 0:8918a71cdbe9 150
Sergunb 0:8918a71cdbe9 151
Sergunb 0:8918a71cdbe9 152 //SSL/TLS supported?
Sergunb 0:8918a71cdbe9 153 #if (FTP_CLIENT_TLS_SUPPORT == ENABLED)
Sergunb 0:8918a71cdbe9 154
Sergunb 0:8918a71cdbe9 155 /**
Sergunb 0:8918a71cdbe9 156 * @brief SSL initialization callback function
Sergunb 0:8918a71cdbe9 157 **/
Sergunb 0:8918a71cdbe9 158
Sergunb 0:8918a71cdbe9 159 typedef error_t (*FtpClientTlsInitCallback)(FtpClientContext *context,
Sergunb 0:8918a71cdbe9 160 TlsContext *tlsContext);
Sergunb 0:8918a71cdbe9 161
Sergunb 0:8918a71cdbe9 162 #endif
Sergunb 0:8918a71cdbe9 163
Sergunb 0:8918a71cdbe9 164
Sergunb 0:8918a71cdbe9 165 /**
Sergunb 0:8918a71cdbe9 166 * @brief FTP client context
Sergunb 0:8918a71cdbe9 167 **/
Sergunb 0:8918a71cdbe9 168
Sergunb 0:8918a71cdbe9 169 struct _FtpClientContext
Sergunb 0:8918a71cdbe9 170 {
Sergunb 0:8918a71cdbe9 171 NetInterface *interface; ///<Underlying network interface
Sergunb 0:8918a71cdbe9 172 IpAddr serverIpAddr; ///<IP address of the FTP server
Sergunb 0:8918a71cdbe9 173 bool_t passiveMode; ///<Passive mode
Sergunb 0:8918a71cdbe9 174 Socket *controlSocket; ///<Control connection socket
Sergunb 0:8918a71cdbe9 175 Socket *dataSocket; ///<Data connection socket
Sergunb 0:8918a71cdbe9 176 char_t buffer[FTP_CLIENT_BUFFER_SIZE]; ///<Memory buffer for input/output operations
Sergunb 0:8918a71cdbe9 177 #if (FTP_CLIENT_TLS_SUPPORT == ENABLED)
Sergunb 0:8918a71cdbe9 178 TlsContext *controlTlsContext; ///<SSL context (control connection)
Sergunb 0:8918a71cdbe9 179 TlsContext *dataTlsContext; ///<SSL context (data connection)
Sergunb 0:8918a71cdbe9 180 TlsSession tlsSession; ///<SSL session
Sergunb 0:8918a71cdbe9 181 FtpClientTlsInitCallback tlsInitCallback; ///<SSL initialization callback function
Sergunb 0:8918a71cdbe9 182 #endif
Sergunb 0:8918a71cdbe9 183 };
Sergunb 0:8918a71cdbe9 184
Sergunb 0:8918a71cdbe9 185
Sergunb 0:8918a71cdbe9 186 //FTP client related functions
Sergunb 0:8918a71cdbe9 187 error_t ftpConnect(FtpClientContext *context, NetInterface *interface,
Sergunb 0:8918a71cdbe9 188 const IpAddr *serverIpAddr, uint16_t serverPort, uint_t flags);
Sergunb 0:8918a71cdbe9 189
Sergunb 0:8918a71cdbe9 190 error_t ftpAuth(FtpClientContext *context);
Sergunb 0:8918a71cdbe9 191
Sergunb 0:8918a71cdbe9 192 error_t ftpLogin(FtpClientContext *context, const char_t *username,
Sergunb 0:8918a71cdbe9 193 const char_t *password, const char_t *account);
Sergunb 0:8918a71cdbe9 194
Sergunb 0:8918a71cdbe9 195 error_t ftpGetWorkingDir(FtpClientContext *context, char_t *path, size_t size);
Sergunb 0:8918a71cdbe9 196 error_t ftpChangeWorkingDir(FtpClientContext *context, const char_t *path);
Sergunb 0:8918a71cdbe9 197 error_t ftpChangeToParentDir(FtpClientContext *context);
Sergunb 0:8918a71cdbe9 198
Sergunb 0:8918a71cdbe9 199 error_t ftpMakeDir(FtpClientContext *context, const char_t *path);
Sergunb 0:8918a71cdbe9 200 error_t ftpRemoveDir(FtpClientContext *context, const char_t *path);
Sergunb 0:8918a71cdbe9 201
Sergunb 0:8918a71cdbe9 202 error_t ftpOpenFile(FtpClientContext *context, const char_t *path, uint_t flags);
Sergunb 0:8918a71cdbe9 203
Sergunb 0:8918a71cdbe9 204 error_t ftpWriteFile(FtpClientContext *context,
Sergunb 0:8918a71cdbe9 205 const void *data, size_t length, uint_t flags);
Sergunb 0:8918a71cdbe9 206
Sergunb 0:8918a71cdbe9 207 error_t ftpReadFile(FtpClientContext *context,
Sergunb 0:8918a71cdbe9 208 void *data, size_t size, size_t *length, uint_t flags);
Sergunb 0:8918a71cdbe9 209
Sergunb 0:8918a71cdbe9 210 error_t ftpCloseFile(FtpClientContext *context);
Sergunb 0:8918a71cdbe9 211
Sergunb 0:8918a71cdbe9 212 error_t ftpRenameFile(FtpClientContext *context,
Sergunb 0:8918a71cdbe9 213 const char_t *oldName, const char_t *newName);
Sergunb 0:8918a71cdbe9 214
Sergunb 0:8918a71cdbe9 215 error_t ftpDeleteFile(FtpClientContext *context, const char_t *path);
Sergunb 0:8918a71cdbe9 216
Sergunb 0:8918a71cdbe9 217 error_t ftpClose(FtpClientContext *context);
Sergunb 0:8918a71cdbe9 218
Sergunb 0:8918a71cdbe9 219 error_t ftpSendCommand(FtpClientContext *context,
Sergunb 0:8918a71cdbe9 220 const char_t *command, uint_t *replyCode);
Sergunb 0:8918a71cdbe9 221
Sergunb 0:8918a71cdbe9 222 #if (FTP_CLIENT_TLS_SUPPORT == ENABLED)
Sergunb 0:8918a71cdbe9 223
Sergunb 0:8918a71cdbe9 224 error_t ftpRegisterTlsInitCallback(FtpClientContext *context,
Sergunb 0:8918a71cdbe9 225 FtpClientTlsInitCallback callback);
Sergunb 0:8918a71cdbe9 226
Sergunb 0:8918a71cdbe9 227 error_t ftpInitControlTlsContext(FtpClientContext *context);
Sergunb 0:8918a71cdbe9 228 error_t ftpInitDataTlsContext(FtpClientContext *context);
Sergunb 0:8918a71cdbe9 229
Sergunb 0:8918a71cdbe9 230 #endif
Sergunb 0:8918a71cdbe9 231
Sergunb 0:8918a71cdbe9 232 #endif
Sergunb 0:8918a71cdbe9 233