]> git.sur5r.net Git - freertos/blob - FreeRTOS-Labs/Demo/Common/Demo_IP_Protocols/include/FreeRTOS_server_private.h
Add the Labs projects provided in the V10.2.1_191129 zip file.
[freertos] / FreeRTOS-Labs / Demo / Common / Demo_IP_Protocols / include / FreeRTOS_server_private.h
1 /*\r
2  * FreeRTOS+TCP V2.0.3\r
3  * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\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
11  *\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
14  *\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
21  *\r
22  * http://aws.amazon.com/freertos\r
23  * http://www.FreeRTOS.org\r
24  */\r
25 \r
26  /*\r
27         Some code which is common to TCP servers like HTTP and FTP\r
28 */\r
29 \r
30 #ifndef FREERTOS_SERVER_PRIVATE_H\r
31 #define FREERTOS_SERVER_PRIVATE_H\r
32 \r
33 #define FREERTOS_NO_SOCKET              NULL\r
34 \r
35 /* FreeRTOS+FAT */\r
36 #include "ff_stdio.h"\r
37 \r
38 /* Each HTTP server has 1, at most 2 sockets */\r
39 #define HTTP_SOCKET_COUNT       2\r
40 \r
41 /*\r
42  * ipconfigTCP_COMMAND_BUFFER_SIZE sets the size of:\r
43  *     pcCommandBuffer': a buffer to receive and send TCP commands\r
44  *\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
47  *\r
48  * The buffers are both used for FTP as well as HTTP.\r
49  */\r
50 \r
51 #ifndef ipconfigTCP_COMMAND_BUFFER_SIZE\r
52         #define ipconfigTCP_COMMAND_BUFFER_SIZE ( 2048 )\r
53 #endif\r
54 \r
55 #ifndef ipconfigTCP_FILE_BUFFER_SIZE\r
56         #define ipconfigTCP_FILE_BUFFER_SIZE    ( 2048 )\r
57 #endif\r
58 \r
59 struct xTCP_CLIENT;\r
60 \r
61 typedef BaseType_t ( * FTCPWorkFunction ) ( struct xTCP_CLIENT * /* pxClient */ );\r
62 typedef void ( * FTCPDeleteFunction ) ( struct xTCP_CLIENT * /* pxClient */ );\r
63 \r
64 #define TCP_CLIENT_FIELDS \\r
65         enum eSERVER_TYPE eType; \\r
66         struct xTCP_SERVER *pxParent; \\r
67         Socket_t xSocket; \\r
68         const char *pcRootDir; \\r
69         FTCPWorkFunction fWorkFunction; \\r
70         FTCPDeleteFunction fDeleteFunction; \\r
71         struct xTCP_CLIENT *pxNextClient\r
72 \r
73 typedef struct xTCP_CLIENT\r
74 {\r
75         /* This define contains fields which must come first within each of the client structs */\r
76         TCP_CLIENT_FIELDS;\r
77         /* --- Keep at the top  --- */\r
78 \r
79 } TCPClient_t;\r
80 \r
81 struct xHTTP_CLIENT\r
82 {\r
83         /* This define contains fields which must come first within each of the client structs */\r
84         TCP_CLIENT_FIELDS;\r
85         /* --- Keep at the top  --- */\r
86 \r
87         const char *pcUrlData;\r
88         const char *pcRestData;\r
89         char pcCurrentFilename[ ffconfigMAX_FILENAME ];\r
90         size_t uxBytesLeft;\r
91         FF_FILE *pxFileHandle;\r
92         union {\r
93                 struct {\r
94                         uint32_t\r
95                                 bReplySent : 1;\r
96                 };\r
97                 uint32_t ulFlags;\r
98         } bits;\r
99 };\r
100 \r
101 typedef struct xHTTP_CLIENT HTTPClient_t;\r
102 \r
103 struct xFTP_CLIENT\r
104 {\r
105         /* This define contains fields which must come first within each of the client structs */\r
106         TCP_CLIENT_FIELDS;\r
107         /* --- Keep at the top  --- */\r
108 \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
125         union {\r
126                 struct {\r
127                         uint32_t\r
128                                 bHelloSent : 1,\r
129                                 bLoggedIn : 1,\r
130                                 bStatusUser : 1,\r
131                                 bInRename : 1,\r
132                                 bReadOnly : 1;\r
133                 };\r
134                 uint32_t ulFTPFlags;\r
135         } bits;\r
136         union {\r
137                 struct {\r
138                         uint32_t\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
144                 };\r
145                 uint32_t ulConnFlags;\r
146         } bits1;\r
147 };\r
148 \r
149 typedef struct xFTP_CLIENT FTPClient_t;\r
150 \r
151 BaseType_t xHTTPClientWork( TCPClient_t *pxClient );\r
152 BaseType_t xFTPClientWork( TCPClient_t *pxClient );\r
153 \r
154 void vHTTPClientDelete( TCPClient_t *pxClient );\r
155 void vFTPClientDelete( TCPClient_t *pxClient );\r
156 \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
159 \r
160 struct xTCP_SERVER\r
161 {\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
167 \r
168         #if( ipconfigUSE_FTP != 0 )\r
169                 char pcNewDir[ ffconfigMAX_FILENAME ];\r
170         #endif\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
174         #endif\r
175         BaseType_t xServerCount;\r
176         TCPClient_t *pxClients;\r
177         struct xSERVER\r
178         {\r
179                 enum eSERVER_TYPE eType;                /* eSERVER_HTTP | eSERVER_FTP */\r
180                 const char *pcRootDir;\r
181                 Socket_t xSocket;\r
182         } xServers[ 1 ];\r
183 };\r
184 \r
185 #endif /* FREERTOS_SERVER_PRIVATE_H */\r