2 * FreeRTOS+TCP V2.0.1
\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://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
29 Some code which is common to TCP servers like HTTP and FTP
\r
32 #ifndef FREERTOS_SERVER_PRIVATE_H
\r
33 #define FREERTOS_SERVER_PRIVATE_H
\r
35 #define FREERTOS_NO_SOCKET NULL
\r
38 #include "ff_stdio.h"
\r
40 /* Each HTTP server has 1, at most 2 sockets */
\r
41 #define HTTP_SOCKET_COUNT 2
\r
44 * ipconfigTCP_COMMAND_BUFFER_SIZE sets the size of:
\r
45 * pcCommandBuffer': a buffer to receive and send TCP commands
\r
47 * ipconfigTCP_FILE_BUFFER_SIZE sets the size of:
\r
48 * pcFileBuffer' : a buffer to access the file system: read or write data.
\r
50 * The buffers are both used for FTP as well as HTTP.
\r
53 #ifndef ipconfigTCP_COMMAND_BUFFER_SIZE
\r
54 #define ipconfigTCP_COMMAND_BUFFER_SIZE ( 2048 )
\r
57 #ifndef ipconfigTCP_FILE_BUFFER_SIZE
\r
58 #define ipconfigTCP_FILE_BUFFER_SIZE ( 2048 )
\r
63 typedef BaseType_t ( * FTCPWorkFunction ) ( struct xTCP_CLIENT * /* pxClient */ );
\r
64 typedef void ( * FTCPDeleteFunction ) ( struct xTCP_CLIENT * /* pxClient */ );
\r
66 #define TCP_CLIENT_FIELDS \
\r
67 enum eSERVER_TYPE eType; \
\r
68 struct xTCP_SERVER *pxParent; \
\r
70 const char *pcRootDir; \
\r
71 FTCPWorkFunction fWorkFunction; \
\r
72 FTCPDeleteFunction fDeleteFunction; \
\r
73 struct xTCP_CLIENT *pxNextClient
\r
75 typedef struct xTCP_CLIENT
\r
77 /* This define contains fields which must come first within each of the client structs */
\r
79 /* --- Keep at the top --- */
\r
85 /* This define contains fields which must come first within each of the client structs */
\r
87 /* --- Keep at the top --- */
\r
89 const char *pcUrlData;
\r
90 const char *pcRestData;
\r
91 char pcCurrentFilename[ ffconfigMAX_FILENAME ];
\r
93 FF_FILE *pxFileHandle;
\r
103 typedef struct xHTTP_CLIENT HTTPClient_t;
\r
107 /* This define contains fields which must come first within each of the client structs */
\r
109 /* --- Keep at the top --- */
\r
111 uint32_t ulRestartOffset;
\r
112 uint32_t ulRecvBytes;
\r
113 size_t uxBytesLeft; /* Bytes left to send */
\r
114 uint32_t ulClientIP;
\r
115 TickType_t xStartTime;
\r
116 uint16_t usClientPort;
\r
117 Socket_t xTransferSocket;
\r
118 BaseType_t xTransType;
\r
119 BaseType_t xDirCount;
\r
120 FF_FindData_t xFindData;
\r
121 FF_FILE *pxReadHandle;
\r
122 FF_FILE *pxWriteHandle;
\r
123 char pcCurrentDir[ ffconfigMAX_FILENAME ];
\r
124 char pcFileName[ ffconfigMAX_FILENAME ];
\r
125 char pcConnectionAck[ 128 ];
\r
126 char pcClientAck[ 128 ];
\r
136 uint32_t ulFTPFlags;
\r
141 bIsListen : 1, /* pdTRUE for passive data connections (using list()). */
\r
142 bDirHasEntry : 1, /* pdTRUE if ff_findfirst() was successful. */
\r
143 bClientConnected : 1, /* pdTRUE after connect() or accept() has succeeded. */
\r
144 bEmptyFile : 1, /* pdTRUE if a connection-without-data was received. */
\r
145 bHadError : 1; /* pdTRUE if a transfer got aborted because of an error. */
\r
147 uint32_t ulConnFlags;
\r
151 typedef struct xFTP_CLIENT FTPClient_t;
\r
153 BaseType_t xHTTPClientWork( TCPClient_t *pxClient );
\r
154 BaseType_t xFTPClientWork( TCPClient_t *pxClient );
\r
156 void vHTTPClientDelete( TCPClient_t *pxClient );
\r
157 void vFTPClientDelete( TCPClient_t *pxClient );
\r
159 BaseType_t xMakeAbsolute( struct xFTP_CLIENT *pxClient, char *pcBuffer, BaseType_t xBufferLength, const char *pcFileName );
\r
160 BaseType_t xMakeRelative( FTPClient_t *pxClient, char *pcBuffer, BaseType_t xBufferLength, const char *pcFileName );
\r
164 SocketSet_t xSocketSet;
\r
165 /* A buffer to receive and send TCP commands, either HTTP of FTP. */
\r
166 char pcCommandBuffer[ ipconfigTCP_COMMAND_BUFFER_SIZE ];
\r
167 /* A buffer to access the file system: read or write data. */
\r
168 char pcFileBuffer[ ipconfigTCP_FILE_BUFFER_SIZE ];
\r
170 #if( ipconfigUSE_FTP != 0 )
\r
171 char pcNewDir[ ffconfigMAX_FILENAME ];
\r
173 #if( ipconfigUSE_HTTP != 0 )
\r
174 char pcContentsType[40]; /* Space for the msg: "text/javascript" */
\r
175 char pcExtraContents[40]; /* Space for the msg: "Content-Length: 346500" */
\r
177 BaseType_t xServerCount;
\r
178 TCPClient_t *pxClients;
\r
181 enum eSERVER_TYPE eType; /* eSERVER_HTTP | eSERVER_FTP */
\r
182 const char *pcRootDir;
\r
187 #endif /* FREERTOS_SERVER_PRIVATE_H */
\r