1 /**************************************************************************/ 2 /* */ 3 /* Copyright (c) Microsoft Corporation. All rights reserved. */ 4 /* */ 5 /* This software is licensed under the Microsoft Software License */ 6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */ 7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ 8 /* and in the root directory of this software. */ 9 /* */ 10 /**************************************************************************/ 11 12 13 /**************************************************************************/ 14 /**************************************************************************/ 15 /** */ 16 /** NetX Component */ 17 /** */ 18 /** Hypertext Transfer Protocol (HTTP) */ 19 /** */ 20 /**************************************************************************/ 21 /**************************************************************************/ 22 23 24 /**************************************************************************/ 25 /* */ 26 /* APPLICATION INTERFACE DEFINITION RELEASE */ 27 /* */ 28 /* nx_web_http_common.h PORTABLE C */ 29 /* 6.1.6 */ 30 /* AUTHOR */ 31 /* */ 32 /* Yuxin Zhou, Microsoft Corporation */ 33 /* */ 34 /* DESCRIPTION */ 35 /* */ 36 /* This file defines the NetX Web Hypertext Transfer Protocol (HTTP) */ 37 /* component, including all data types and external references. */ 38 /* It is assumed that nx_api.h and nx_port.h have already been */ 39 /* included, along with fx_api.h and fx_port.h. If HTTPS is being used */ 40 /* then nx_secure_tls_api.h must also be included. */ 41 /* */ 42 /* RELEASE HISTORY */ 43 /* */ 44 /* DATE NAME DESCRIPTION */ 45 /* */ 46 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ 47 /* 09-30-2020 Yuxin Zhou Modified comment(s), */ 48 /* resulting in version 6.1 */ 49 /* 04-02-2021 Yuxin Zhou Modified comment(s), and */ 50 /* improved the logic of */ 51 /* parsing base64, */ 52 /* resulting in version 6.1.6 */ 53 /* */ 54 /**************************************************************************/ 55 56 #ifndef NX_WEB_HTTP_COMMON_H 57 #define NX_WEB_HTTP_COMMON_H 58 59 /* Determine if a C++ compiler is being used. If so, ensure that standard 60 C is used to process the API information. */ 61 62 #ifdef __cplusplus 63 64 /* Yes, C++ compiler is present. Use standard C. */ 65 extern "C" { 66 67 #endif 68 69 /* Define the HTTP version. */ 70 #define NX_WEB_HTTP_VERSION "HTTP/1.1" 71 72 /* Define HTTP TCP socket create options. */ 73 74 #ifndef NX_WEB_HTTP_TYPE_OF_SERVICE 75 #define NX_WEB_HTTP_TYPE_OF_SERVICE NX_IP_NORMAL 76 #endif 77 78 #ifndef NX_WEB_HTTP_FRAGMENT_OPTION 79 #define NX_WEB_HTTP_FRAGMENT_OPTION NX_DONT_FRAGMENT 80 #endif 81 82 #ifndef NX_WEB_HTTP_TIME_TO_LIVE 83 #define NX_WEB_HTTP_TIME_TO_LIVE 0x80 84 #endif 85 86 #ifndef NX_WEB_HTTP_MAX_RESOURCE 87 #define NX_WEB_HTTP_MAX_RESOURCE 40 88 #endif 89 90 #ifndef NX_WEB_HTTP_MAX_NAME 91 #define NX_WEB_HTTP_MAX_NAME 20 92 #endif 93 94 #ifndef NX_WEB_HTTP_MAX_PASSWORD 95 #define NX_WEB_HTTP_MAX_PASSWORD 20 96 #endif 97 98 /* To enabled HTTPS, define this symbol 99 #define NX_WEB_HTTPS_ENABLE 100 */ 101 102 /* To enable MD5 digest authentication, define this symbol 103 #define NX_WEB_HTTP_DIGEST_ENABLE 104 */ 105 106 #ifndef NX_PHYSICAL_TRAILER 107 #define NX_PHYSICAL_TRAILER 4 108 #endif 109 110 /* NX_WEB_HTTP_MAX_STRING is base64 of "name:password" and plus 1 if an extra conversion is needed and plus 2 pad if needed.. */ 111 #define NX_WEB_HTTP_MAX_STRING ((NX_WEB_HTTP_MAX_NAME + NX_WEB_HTTP_MAX_PASSWORD + 1 ) * 4 / 3 + 1 + 2) 112 113 #define NX_WEB_HTTP_MAX_BINARY_MD5 16 114 #define NX_WEB_HTTP_MAX_ASCII_MD5 32 115 116 117 /* Define return code constants. */ 118 #define NX_WEB_HTTP_ERROR 0x30000 /* HTTP internal error */ 119 #define NX_WEB_HTTP_TIMEOUT 0x30001 /* HTTP timeout occurred */ 120 #define NX_WEB_HTTP_FAILED 0x30002 /* HTTP error */ 121 #define NX_WEB_HTTP_DONT_AUTHENTICATE 0x30003 /* HTTP authentication not needed */ 122 #define NX_WEB_HTTP_BASIC_AUTHENTICATE 0x30004 /* HTTP basic authentication requested */ 123 #define NX_WEB_HTTP_DIGEST_AUTHENTICATE 0x30005 /* HTTP digest authentication requested */ 124 #define NX_WEB_HTTP_NOT_FOUND 0x30006 /* HTTP request not found */ 125 #define NX_WEB_HTTP_DATA_END 0x30007 /* HTTP end of content area */ 126 #define NX_WEB_HTTP_CALLBACK_COMPLETED 0x30008 /* HTTP user callback completed the processing */ 127 #define NX_WEB_HTTP_POOL_ERROR 0x30009 /* HTTP supplied pool payload is too small */ 128 #define NX_WEB_HTTP_NOT_READY 0x3000A /* HTTP client not ready for operation */ 129 #define NX_WEB_HTTP_GET_DONE 0x3000C /* HTTP client get is complete */ 130 #define NX_WEB_HTTP_BAD_PACKET_LENGTH 0x3000D /* Invalid packet received - length incorrect */ 131 #define NX_WEB_HTTP_REQUEST_UNSUCCESSFUL_CODE 0x3000E /* Received an error code instead of 2xx from server */ 132 #define NX_WEB_HTTP_INCOMPLETE_PUT_ERROR 0x3000F /* Server responds before PUT is complete */ 133 #define NX_WEB_HTTP_PASSWORD_TOO_LONG 0x30011 /* Password exceeded expected length */ 134 #define NX_WEB_HTTP_USERNAME_TOO_LONG 0x30012 /* Username exceeded expected length */ 135 #define NX_WEB_HTTP_NO_QUERY_PARSED 0x30013 /* Server unable to find query in client request */ 136 #define NX_WEB_HTTP_METHOD_ERROR 0x30014 /* Client method (e.g. GET, POST) was missing required information. */ 137 #define NX_WEB_HTTP_IMPROPERLY_TERMINATED_PARAM 0x30015 /* Client request parameter not properly terminated */ 138 #define NX_WEB_HTTP_BOUNDARY_ALREADY_FOUND 0x30016 /* Boundary is already found. */ 139 #define NX_WEB_HTTP_MISSING_CONTENT_LENGTH 0x30017 /* The Content-Length header was not found. */ 140 #define NX_WEB_HTTP_EXTENSION_NOT_FOUND 0x30018 /* A searched-for HTTP type extension was not found. */ 141 #define NX_WEB_HTTP_EXTENSION_MIME_DEFAULT 0x30019 /* No matching extension found, return default. */ 142 #define NX_WEB_HTTP_STATUS_CODE_CONTINUE 0x3001A /* "100 Continue" */ 143 #define NX_WEB_HTTP_STATUS_CODE_SWITCHING_PROTOCOLS 0x3001B /* "101 Switching Protocols" */ 144 #define NX_WEB_HTTP_STATUS_CODE_CREATED 0x3001C /* "201 Created" */ 145 #define NX_WEB_HTTP_STATUS_CODE_ACCEPTED 0x3001D /* "202 Accepted" */ 146 #define NX_WEB_HTTP_STATUS_CODE_NON_AUTH_INFO 0x3001E /* "203 Non-Authoritative Information" */ 147 #define NX_WEB_HTTP_STATUS_CODE_NO_CONTENT 0x3001F /* "204 No Content" */ 148 #define NX_WEB_HTTP_STATUS_CODE_RESET_CONTENT 0x30020 /* "205 Reset Content" */ 149 #define NX_WEB_HTTP_STATUS_CODE_PARTIAL_CONTENT 0x30021 /* "206 Partial Content" */ 150 #define NX_WEB_HTTP_STATUS_CODE_MULTIPLE_CHOICES 0x30022 /* "300 Multiple Choices" */ 151 #define NX_WEB_HTTP_STATUS_CODE_MOVED_PERMANETLY 0x30023 /* "301 Moved Permanently" */ 152 #define NX_WEB_HTTP_STATUS_CODE_FOUND 0x30024 /* "302 Found" */ 153 #define NX_WEB_HTTP_STATUS_CODE_SEE_OTHER 0x30025 /* "303 See Other" */ 154 #define NX_WEB_HTTP_STATUS_CODE_NOT_MODIFIED 0x30026 /* "304 Not Modified" */ 155 #define NX_WEB_HTTP_STATUS_CODE_USE_PROXY 0x30027 /* "305 Use Proxy" */ 156 #define NX_WEB_HTTP_STATUS_CODE_TEMPORARY_REDIRECT 0x30028 /* "307 Temporary Redirect" */ 157 #define NX_WEB_HTTP_STATUS_CODE_BAD_REQUEST 0x30029 /* "400 Bad Request" */ 158 #define NX_WEB_HTTP_STATUS_CODE_UNAUTHORIZED 0x3002A /* "401 Unauthorized" */ 159 #define NX_WEB_HTTP_STATUS_CODE_PAYMENT_REQUIRED 0x3002B /* "402 Payment Required" */ 160 #define NX_WEB_HTTP_STATUS_CODE_FORBIDDEN 0x3002C /* "403 Forbidden" */ 161 #define NX_WEB_HTTP_STATUS_CODE_NOT_FOUND 0x3002D /* "404 Not Found" */ 162 #define NX_WEB_HTTP_STATUS_CODE_METHOD_NOT_ALLOWED 0x3002E /* "405 Method Not Allowed" */ 163 #define NX_WEB_HTTP_STATUS_CODE_NOT_ACCEPTABLE 0x3002F /* "406 Not Acceptable" */ 164 #define NX_WEB_HTTP_STATUS_CODE_PROXY_AUTH_REQUIRED 0x30030 /* "407 Proxy Authentication Required" */ 165 #define NX_WEB_HTTP_STATUS_CODE_REQUEST_TIMEOUT 0x30031 /* "408 Request Time-out" */ 166 #define NX_WEB_HTTP_STATUS_CODE_CONFLICT 0x30032 /* "409 Conflict" */ 167 #define NX_WEB_HTTP_STATUS_CODE_GONE 0x30033 /* "410 Gone" */ 168 #define NX_WEB_HTTP_STATUS_CODE_LENGTH_REQUIRED 0x30034 /* "411 Length Required" */ 169 #define NX_WEB_HTTP_STATUS_CODE_PRECONDITION_FAILED 0x30035 /* "412 Precondition Failed" */ 170 #define NX_WEB_HTTP_STATUS_CODE_ENTITY_TOO_LARGE 0x30036 /* "413 Request Entity Too Large" */ 171 #define NX_WEB_HTTP_STATUS_CODE_URL_TOO_LARGE 0x30037 /* "414 Request-URL Too Large" */ 172 #define NX_WEB_HTTP_STATUS_CODE_UNSUPPORTED_MEDIA 0x30038 /* "415 Unsupported Media Type" */ 173 #define NX_WEB_HTTP_STATUS_CODE_RANGE_NOT_SATISFY 0x30039 /* "416 Requested range not satisfiable" */ 174 #define NX_WEB_HTTP_STATUS_CODE_EXPECTATION_FAILED 0x3003A /* "417 Expectation Failed" */ 175 #define NX_WEB_HTTP_STATUS_CODE_INTERNAL_ERROR 0x3003B /* "500 Internal Server Error" */ 176 #define NX_WEB_HTTP_STATUS_CODE_NOT_IMPLEMENTED 0x3003C /* "501 Not Implemented" */ 177 #define NX_WEB_HTTP_STATUS_CODE_BAD_GATEWAY 0x3003D /* "502 Bad Gateway" */ 178 #define NX_WEB_HTTP_STATUS_CODE_SERVICE_UNAVAILABLE 0x3003E /* "503 Service Unavailable" */ 179 #define NX_WEB_HTTP_STATUS_CODE_GATEWAY_TIMEOUT 0x3003F /* "504 Gateway Time-out" */ 180 #define NX_WEB_HTTP_STATUS_CODE_VERSION_ERROR 0x30040 /* "505 HTTP Version not supported" */ 181 #define NX_WEB_HTTP_AUTHENTICATION_ERROR NX_WEB_HTTP_STATUS_CODE_UNAUTHORIZED /* HTTP client authentication failed */ 182 183 /* Define the HTTP Server TCP port number */ 184 185 #define NX_WEB_HTTP_SERVER_PORT 80 /* Port for HTTP server */ 186 #define NX_WEB_HTTPS_SERVER_PORT 443 /* Port for HTTPS server. */ 187 188 /* Define constants for the various HTTP methods supported. */ 189 #define NX_WEB_HTTP_METHOD_NONE 0x0 190 #define NX_WEB_HTTP_METHOD_GET 0x1 191 #define NX_WEB_HTTP_METHOD_PUT 0x2 192 #define NX_WEB_HTTP_METHOD_POST 0x3 193 #define NX_WEB_HTTP_METHOD_DELETE 0x4 194 #define NX_WEB_HTTP_METHOD_HEAD 0x5 195 196 /* Define status codes. */ 197 #define NX_WEB_HTTP_STATUS_CONTINUE "100 Continue" 198 #define NX_WEB_HTTP_STATUS_SWITCHING_PROTOCOLS "101 Switching Protocols" 199 #define NX_WEB_HTTP_STATUS_OK "200 OK" 200 #define NX_WEB_HTTP_STATUS_CREATED "201 Created" 201 #define NX_WEB_HTTP_STATUS_ACCEPTED "202 Accepted" 202 #define NX_WEB_HTTP_STATUS_NON_AUTH_INFO "203 Non-Authoritative Information" 203 #define NX_WEB_HTTP_STATUS_NO_CONTENT "204 No Content" 204 #define NX_WEB_HTTP_STATUS_RESET_CONTENT "205 Reset Content" 205 #define NX_WEB_HTTP_STATUS_PARTIAL_CONTENT "206 Partial Content" 206 #define NX_WEB_HTTP_STATUS_MULTIPLE_CHOICES "300 Multiple Choices" 207 #define NX_WEB_HTTP_STATUS_MOVED_PERMANETLY "301 Moved Permanently" 208 #define NX_WEB_HTTP_STATUS_FOUND "302 Found" 209 #define NX_WEB_HTTP_STATUS_SEE_OTHER "303 See Other" 210 #define NX_WEB_HTTP_STATUS_NOT_MODIFIED "304 Not Modified" 211 #define NX_WEB_HTTP_STATUS_USE_PROXY "305 Use Proxy" 212 #define NX_WEB_HTTP_STATUS_TEMPORARY_REDIRECT "307 Temporary Redirect" 213 #define NX_WEB_HTTP_STATUS_BAD_REQUEST "400 Bad Request" 214 #define NX_WEB_HTTP_STATUS_UNAUTHORIZED "401 Unauthorized" 215 #define NX_WEB_HTTP_STATUS_PAYMENT_REQUIRED "402 Payment Required" 216 #define NX_WEB_HTTP_STATUS_FORBIDDEN "403 Forbidden" 217 #define NX_WEB_HTTP_STATUS_NOT_FOUND "404 Not Found" 218 #define NX_WEB_HTTP_STATUS_METHOD_NOT_ALLOWED "405 Method Not Allowed" 219 #define NX_WEB_HTTP_STATUS_NOT_ACCEPTABLE "406 Not Acceptable" 220 #define NX_WEB_HTTP_STATUS_PROXY_AUTH_REQUIRED "407 Proxy Authentication Required" 221 #define NX_WEB_HTTP_STATUS_REQUEST_TIMEOUT "408 Request Time-out" 222 #define NX_WEB_HTTP_STATUS_CONFLICT "409 Conflict" 223 #define NX_WEB_HTTP_STATUS_GONE "410 Gone" 224 #define NX_WEB_HTTP_STATUS_LENGTH_REQUIRED "411 Length Required" 225 #define NX_WEB_HTTP_STATUS_PRECONDITION_FAILED "412 Precondition Failed" 226 #define NX_WEB_HTTP_STATUS_ENTITY_TOO_LARGE "413 Request Entity Too Large" 227 #define NX_WEB_HTTP_STATUS_URL_TOO_LARGE "414 Request-URL Too Large" 228 #define NX_WEB_HTTP_STATUS_UNSUPPORTED_MEDIA "415 Unsupported Media Type" 229 #define NX_WEB_HTTP_STATUS_RANGE_NOT_SATISFY "416 Requested range not satisfiable" 230 #define NX_WEB_HTTP_STATUS_EXPECTATION_FAILED "417 Expectation Failed" 231 #define NX_WEB_HTTP_STATUS_INTERNAL_ERROR "500 Internal Server Error" 232 #define NX_WEB_HTTP_STATUS_NOT_IMPLEMENTED "501 Not Implemented" 233 #define NX_WEB_HTTP_STATUS_BAD_GATEWAY "502 Bad Gateway" 234 #define NX_WEB_HTTP_STATUS_SERVICE_UNAVAILABLE "503 Service Unavailable" 235 #define NX_WEB_HTTP_STATUS_GATEWAY_TIMEOUT "504 Gateway Time-out" 236 #define NX_WEB_HTTP_STATUS_VERSION_ERROR "505 HTTP Version not supported" 237 238 239 /* Define the max length of header field. */ 240 241 #ifndef NX_WEB_HTTP_MAX_HEADER_FIELD 242 #define NX_WEB_HTTP_MAX_HEADER_FIELD 256 243 #endif 244 245 /* Determine if a C++ compiler is being used. If so, complete the standard 246 C conditional started above. */ 247 #ifdef __cplusplus 248 } 249 #endif 250 251 #endif /* NX_WEB_HTTP_COMMON_H */ 252