2 * FreeRTOS+TCP V2.0.0
\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. If you wish to use our Amazon
\r
14 * FreeRTOS name, please do so in a fair use way that does not cause confusion.
\r
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
18 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
19 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
23 * http://www.FreeRTOS.org
\r
24 * http://aws.amazon.com/freertos
\r
26 * 1 tab == 4 spaces!
\r
30 Some code which is common to TCP servers like HTTP and FTP
\r
33 #ifndef FREERTOS_SERVER_PRIVATE_H
\r
34 #define FREERTOS_SERVER_PRIVATE_H
\r
36 #define FREERTOS_NO_SOCKET NULL
\r
39 #include "ff_stdio.h"
\r
41 /* Each HTTP server has 1, at most 2 sockets */
\r
42 #define HTTP_SOCKET_COUNT 2
\r
45 * ipconfigTCP_COMMAND_BUFFER_SIZE sets the size of:
\r
46 * pcCommandBuffer': a buffer to receive and send TCP commands
\r
48 * ipconfigTCP_FILE_BUFFER_SIZE sets the size of:
\r
49 * pcFileBuffer' : a buffer to access the file system: read or write data.
\r
51 * The buffers are both used for FTP as well as HTTP.
\r
54 #ifndef ipconfigTCP_COMMAND_BUFFER_SIZE
\r
55 #define ipconfigTCP_COMMAND_BUFFER_SIZE ( 2048 )
\r
58 #ifndef ipconfigTCP_FILE_BUFFER_SIZE
\r
59 #define ipconfigTCP_FILE_BUFFER_SIZE ( 2048 )
\r
64 typedef BaseType_t ( * FTCPWorkFunction ) ( struct xTCP_CLIENT * /* pxClient */ );
\r
65 typedef void ( * FTCPDeleteFunction ) ( struct xTCP_CLIENT * /* pxClient */ );
\r
67 #define TCP_CLIENT_FIELDS \
\r
68 enum eSERVER_TYPE eType; \
\r
69 struct xTCP_SERVER *pxParent; \
\r
71 const char *pcRootDir; \
\r
72 FTCPWorkFunction fWorkFunction; \
\r
73 FTCPDeleteFunction fDeleteFunction; \
\r
74 struct xTCP_CLIENT *pxNextClient
\r
76 typedef struct xTCP_CLIENT
\r
78 /* This define contains fields which must come first within each of the client structs */
\r
80 /* --- Keep at the top --- */
\r
86 /* This define contains fields which must come first within each of the client structs */
\r
88 /* --- Keep at the top --- */
\r
90 const char *pcUrlData;
\r
91 const char *pcRestData;
\r
92 char pcCurrentFilename[ ffconfigMAX_FILENAME ];
\r
94 FF_FILE *pxFileHandle;
\r
104 typedef struct xHTTP_CLIENT HTTPClient_t;
\r
108 /* This define contains fields which must come first within each of the client structs */
\r
110 /* --- Keep at the top --- */
\r
112 uint32_t ulRestartOffset;
\r
113 uint32_t ulRecvBytes;
\r
114 size_t uxBytesLeft; /* Bytes left to send */
\r
115 uint32_t ulClientIP;
\r
116 TickType_t xStartTime;
\r
117 uint16_t usClientPort;
\r
118 Socket_t xTransferSocket;
\r
119 BaseType_t xTransType;
\r
120 BaseType_t xDirCount;
\r
121 FF_FindData_t xFindData;
\r
122 FF_FILE *pxReadHandle;
\r
123 FF_FILE *pxWriteHandle;
\r
124 char pcCurrentDir[ ffconfigMAX_FILENAME ];
\r
125 char pcFileName[ ffconfigMAX_FILENAME ];
\r
126 char pcConnectionAck[ 128 ];
\r
127 char pcClientAck[ 128 ];
\r
137 uint32_t ulFTPFlags;
\r
142 bIsListen : 1, /* pdTRUE for passive data connections (using list()). */
\r
143 bDirHasEntry : 1, /* pdTRUE if ff_findfirst() was successful. */
\r
144 bClientConnected : 1, /* pdTRUE after connect() or accept() has succeeded. */
\r
145 bEmptyFile : 1, /* pdTRUE if a connection-without-data was received. */
\r
146 bHadError : 1; /* pdTRUE if a transfer got aborted because of an error. */
\r
148 uint32_t ulConnFlags;
\r
152 typedef struct xFTP_CLIENT FTPClient_t;
\r
154 BaseType_t xHTTPClientWork( TCPClient_t *pxClient );
\r
155 BaseType_t xFTPClientWork( TCPClient_t *pxClient );
\r
157 void vHTTPClientDelete( TCPClient_t *pxClient );
\r
158 void vFTPClientDelete( TCPClient_t *pxClient );
\r
160 BaseType_t xMakeAbsolute( struct xFTP_CLIENT *pxClient, char *pcBuffer, BaseType_t xBufferLength, const char *pcFileName );
\r
161 BaseType_t xMakeRelative( FTPClient_t *pxClient, char *pcBuffer, BaseType_t xBufferLength, const char *pcFileName );
\r
165 SocketSet_t xSocketSet;
\r
166 /* A buffer to receive and send TCP commands, either HTTP of FTP. */
\r
167 char pcCommandBuffer[ ipconfigTCP_COMMAND_BUFFER_SIZE ];
\r
168 /* A buffer to access the file system: read or write data. */
\r
169 char pcFileBuffer[ ipconfigTCP_FILE_BUFFER_SIZE ];
\r
171 #if( ipconfigUSE_FTP != 0 )
\r
172 char pcNewDir[ ffconfigMAX_FILENAME ];
\r
174 #if( ipconfigUSE_HTTP != 0 )
\r
175 char pcContentsType[40]; /* Space for the msg: "text/javascript" */
\r
176 char pcExtraContents[40]; /* Space for the msg: "Content-Length: 346500" */
\r
178 BaseType_t xServerCount;
\r
179 TCPClient_t *pxClients;
\r
182 enum eSERVER_TYPE eType; /* eSERVER_HTTP | eSERVER_FTP */
\r
183 const char *pcRootDir;
\r
188 #endif /* FREERTOS_SERVER_PRIVATE_H */
\r