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