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