2 * FreeRTOS+TCP V2.0.3
\r
3 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://aws.amazon.com/freertos
\r
23 * http://www.FreeRTOS.org
\r
27 Some code which is common to TCP servers like HTTP and FTP
\r
30 #ifndef FREERTOS_SERVER_PRIVATE_H
\r
31 #define FREERTOS_SERVER_PRIVATE_H
\r
33 #define FREERTOS_NO_SOCKET NULL
\r
36 #include "ff_stdio.h"
\r
38 /* Each HTTP server has 1, at most 2 sockets */
\r
39 #define HTTP_SOCKET_COUNT 2
\r
42 * ipconfigTCP_COMMAND_BUFFER_SIZE sets the size of:
\r
43 * pcCommandBuffer': a buffer to receive and send TCP commands
\r
45 * ipconfigTCP_FILE_BUFFER_SIZE sets the size of:
\r
46 * pcFileBuffer' : a buffer to access the file system: read or write data.
\r
48 * The buffers are both used for FTP as well as HTTP.
\r
51 #ifndef ipconfigTCP_COMMAND_BUFFER_SIZE
\r
52 #define ipconfigTCP_COMMAND_BUFFER_SIZE ( 2048 )
\r
55 #ifndef ipconfigTCP_FILE_BUFFER_SIZE
\r
56 #define ipconfigTCP_FILE_BUFFER_SIZE ( 2048 )
\r
61 typedef BaseType_t ( * FTCPWorkFunction ) ( struct xTCP_CLIENT * /* pxClient */ );
\r
62 typedef void ( * FTCPDeleteFunction ) ( struct xTCP_CLIENT * /* pxClient */ );
\r
64 #define TCP_CLIENT_FIELDS \
\r
65 enum eSERVER_TYPE eType; \
\r
66 struct xTCP_SERVER *pxParent; \
\r
68 const char *pcRootDir; \
\r
69 FTCPWorkFunction fWorkFunction; \
\r
70 FTCPDeleteFunction fDeleteFunction; \
\r
71 struct xTCP_CLIENT *pxNextClient
\r
73 typedef struct xTCP_CLIENT
\r
75 /* This define contains fields which must come first within each of the client structs */
\r
77 /* --- Keep at the top --- */
\r
83 /* This define contains fields which must come first within each of the client structs */
\r
85 /* --- Keep at the top --- */
\r
87 const char *pcUrlData;
\r
88 const char *pcRestData;
\r
89 char pcCurrentFilename[ ffconfigMAX_FILENAME ];
\r
91 FF_FILE *pxFileHandle;
\r
101 typedef struct xHTTP_CLIENT HTTPClient_t;
\r
105 /* This define contains fields which must come first within each of the client structs */
\r
107 /* --- Keep at the top --- */
\r
109 uint32_t ulRestartOffset;
\r
110 uint32_t ulRecvBytes;
\r
111 size_t uxBytesLeft; /* Bytes left to send */
\r
112 uint32_t ulClientIP;
\r
113 TickType_t xStartTime;
\r
114 uint16_t usClientPort;
\r
115 Socket_t xTransferSocket;
\r
116 BaseType_t xTransType;
\r
117 BaseType_t xDirCount;
\r
118 FF_FindData_t xFindData;
\r
119 FF_FILE *pxReadHandle;
\r
120 FF_FILE *pxWriteHandle;
\r
121 char pcCurrentDir[ ffconfigMAX_FILENAME ];
\r
122 char pcFileName[ ffconfigMAX_FILENAME ];
\r
123 char pcConnectionAck[ 128 ];
\r
124 char pcClientAck[ 128 ];
\r
134 uint32_t ulFTPFlags;
\r
139 bIsListen : 1, /* pdTRUE for passive data connections (using list()). */
\r
140 bDirHasEntry : 1, /* pdTRUE if ff_findfirst() was successful. */
\r
141 bClientConnected : 1, /* pdTRUE after connect() or accept() has succeeded. */
\r
142 bEmptyFile : 1, /* pdTRUE if a connection-without-data was received. */
\r
143 bHadError : 1; /* pdTRUE if a transfer got aborted because of an error. */
\r
145 uint32_t ulConnFlags;
\r
149 typedef struct xFTP_CLIENT FTPClient_t;
\r
151 BaseType_t xHTTPClientWork( TCPClient_t *pxClient );
\r
152 BaseType_t xFTPClientWork( TCPClient_t *pxClient );
\r
154 void vHTTPClientDelete( TCPClient_t *pxClient );
\r
155 void vFTPClientDelete( TCPClient_t *pxClient );
\r
157 BaseType_t xMakeAbsolute( struct xFTP_CLIENT *pxClient, char *pcBuffer, BaseType_t xBufferLength, const char *pcFileName );
\r
158 BaseType_t xMakeRelative( FTPClient_t *pxClient, char *pcBuffer, BaseType_t xBufferLength, const char *pcFileName );
\r
162 SocketSet_t xSocketSet;
\r
163 /* A buffer to receive and send TCP commands, either HTTP of FTP. */
\r
164 char pcCommandBuffer[ ipconfigTCP_COMMAND_BUFFER_SIZE ];
\r
165 /* A buffer to access the file system: read or write data. */
\r
166 char pcFileBuffer[ ipconfigTCP_FILE_BUFFER_SIZE ];
\r
168 #if( ipconfigUSE_FTP != 0 )
\r
169 char pcNewDir[ ffconfigMAX_FILENAME ];
\r
171 #if( ipconfigUSE_HTTP != 0 )
\r
172 char pcContentsType[40]; /* Space for the msg: "text/javascript" */
\r
173 char pcExtraContents[40]; /* Space for the msg: "Content-Length: 346500" */
\r
175 BaseType_t xServerCount;
\r
176 TCPClient_t *pxClients;
\r
179 enum eSERVER_TYPE eType; /* eSERVER_HTTP | eSERVER_FTP */
\r
180 const char *pcRootDir;
\r
185 #endif /* FREERTOS_SERVER_PRIVATE_H */
\r