]> git.sur5r.net Git - freertos/blob - FreeRTOS-Labs/Demo/Common/Demo_IP_Protocols/include/FreeRTOS_TCP_server.h
Add the Labs projects provided in the V10.2.1_191129 zip file.
[freertos] / FreeRTOS-Labs / Demo / Common / Demo_IP_Protocols / include / FreeRTOS_TCP_server.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 en FTP\r
28 */\r
29 \r
30 #ifndef FREERTOS_TCP_SERVER_H\r
31 #define FREERTOS_TCP_SERVER_H\r
32 \r
33 #ifdef __cplusplus\r
34 extern "C" {\r
35 #endif\r
36 \r
37 #ifndef FTP_SERVER_USES_RELATIVE_DIRECTORY\r
38         #define FTP_SERVER_USES_RELATIVE_DIRECTORY              0\r
39 #endif\r
40 \r
41 enum eSERVER_TYPE\r
42 {\r
43         eSERVER_NONE,\r
44         eSERVER_HTTP,\r
45         eSERVER_FTP,\r
46 };\r
47 \r
48 struct xFTP_CLIENT;\r
49 \r
50 #if( ipconfigFTP_HAS_RECEIVED_HOOK != 0 )\r
51         extern void vApplicationFTPReceivedHook( const char *pcFileName, uint32_t ulSize, struct xFTP_CLIENT *pxFTPClient );\r
52         extern void vFTPReplyMessage( struct xFTP_CLIENT *pxFTPClient, const char *pcMessage );\r
53 #endif /* ipconfigFTP_HAS_RECEIVED_HOOK != 0 */\r
54 \r
55 #if( ipconfigFTP_HAS_USER_PASSWORD_HOOK != 0 )\r
56         /*\r
57          * Function is called when a user name has been submitted.\r
58          * The function may return a string such as: "331 Please enter your password"\r
59          * or return NULL to use the default reply.\r
60          */\r
61         extern const char *pcApplicationFTPUserHook( const char *pcUserName );\r
62 #endif /* ipconfigFTP_HAS_USER_PASSWORD_HOOK */\r
63 \r
64 #if( ipconfigFTP_HAS_USER_PASSWORD_HOOK != 0 )\r
65         /*\r
66          * Function is called when a password was received.\r
67          * Return positive value to allow the user\r
68          */\r
69         extern BaseType_t xApplicationFTPPasswordHook( const char *pcUserName, const char *pcPassword );\r
70 #endif /* ipconfigFTP_HAS_USER_PASSWORD_HOOK */\r
71 \r
72 #if( ipconfigFTP_HAS_USER_PROPERTIES_HOOK != 0 )\r
73         /*\r
74          * The FTP server is asking for user-specific properties\r
75          */\r
76         typedef struct\r
77         {\r
78                 uint16_t usPortNumber;  /* For reference only. Host-endian. */\r
79                 const char *pcRootDir;\r
80                 BaseType_t xReadOnly;\r
81         }\r
82         FTPUserProperties_t;\r
83         extern void vApplicationFTPUserPropertiesHook( const char *pcUserName, FTPUserProperties_t *pxProperties );\r
84 #endif /* ipconfigFTP_HAS_USER_PASSWORD_HOOK */\r
85 \r
86 #if( ipconfigHTTP_HAS_HANDLE_REQUEST_HOOK != 0 )\r
87         /*\r
88          * A GET request is received containing a special character,\r
89          * usually a question mark.\r
90          * const char *pcURLData;       // A request, e.g. "/request?limit=75"\r
91          * char *pcBuffer;                      // Here the answer can be written\r
92          * size_t uxBufferLength;       // Size of the buffer\r
93          *\r
94          */\r
95         extern size_t uxApplicationHTTPHandleRequestHook( const char *pcURLData, char *pcBuffer, size_t uxBufferLength );\r
96 #endif /* ipconfigHTTP_HAS_HANDLE_REQUEST_HOOK */\r
97 \r
98 struct xSERVER_CONFIG\r
99 {\r
100         enum eSERVER_TYPE eType;                /* eSERVER_HTTP | eSERVER_FTP */\r
101         BaseType_t xPortNumber;                 /* e.g. 80, 8080, 21 */\r
102         BaseType_t xBackLog;                    /* e.g. 10, maximum number of connected TCP clients */\r
103         const char * const pcRootDir;   /* Treat this directory as the root directory */\r
104 };\r
105 \r
106 struct xTCP_SERVER;\r
107 typedef struct xTCP_SERVER TCPServer_t;\r
108 \r
109 TCPServer_t *FreeRTOS_CreateTCPServer( const struct xSERVER_CONFIG *pxConfigs, BaseType_t xCount );\r
110 void FreeRTOS_TCPServerWork( TCPServer_t *pxServer, TickType_t xBlockingTime );\r
111 \r
112 #if( ipconfigSUPPORT_SIGNALS != 0 )\r
113         /* FreeRTOS_TCPServerWork() calls select().\r
114         The two functions below provide a possibility to interrupt\r
115         the call to select(). After the interruption, resume\r
116         by calling FreeRTOS_TCPServerWork() again. */\r
117         BaseType_t FreeRTOS_TCPServerSignal( TCPServer_t *pxServer );\r
118         BaseType_t FreeRTOS_TCPServerSignalFromISR( TCPServer_t *pxServer, BaseType_t *pxHigherPriorityTaskWoken );\r
119 #endif\r
120 \r
121 #ifdef __cplusplus\r
122 } /* extern "C" */\r
123 #endif\r
124 \r
125 #endif /* FREERTOS_TCP_SERVER_H */\r