TI's CC3100 websocket camera demo with Arducam mini ov5642 and freertos. Should work with other M3's. Work in progress test demo.
http/server/HttpResponse.h@1:e448e81c416f, 2015-09-11 (annotated)
- Committer:
- dflet
- Date:
- Fri Sep 11 15:38:33 2015 +0000
- Revision:
- 1:e448e81c416f
- Parent:
- 0:400d8e75a8d0
Removed some debud.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dflet | 0:400d8e75a8d0 | 1 | //***************************************************************************** |
dflet | 0:400d8e75a8d0 | 2 | // Copyright (C) 2014 Texas Instruments Incorporated |
dflet | 0:400d8e75a8d0 | 3 | // |
dflet | 0:400d8e75a8d0 | 4 | // All rights reserved. Property of Texas Instruments Incorporated. |
dflet | 0:400d8e75a8d0 | 5 | // Restricted rights to use, duplicate or disclose this code are |
dflet | 0:400d8e75a8d0 | 6 | // granted through contract. |
dflet | 0:400d8e75a8d0 | 7 | // The program may not be used without the written permission of |
dflet | 0:400d8e75a8d0 | 8 | // Texas Instruments Incorporated or against the terms and conditions |
dflet | 0:400d8e75a8d0 | 9 | // stipulated in the agreement under which this program has been supplied, |
dflet | 0:400d8e75a8d0 | 10 | // and under no circumstances can it be used with non-TI connectivity device. |
dflet | 0:400d8e75a8d0 | 11 | // |
dflet | 0:400d8e75a8d0 | 12 | //***************************************************************************** |
dflet | 0:400d8e75a8d0 | 13 | |
dflet | 0:400d8e75a8d0 | 14 | #ifndef _HTTP_RESPONSE_H_ |
dflet | 0:400d8e75a8d0 | 15 | #define _HTTP_RESPONSE_H_ |
dflet | 0:400d8e75a8d0 | 16 | |
dflet | 0:400d8e75a8d0 | 17 | #include "datatypes.h" |
dflet | 0:400d8e75a8d0 | 18 | #include "HttpString.h" |
dflet | 0:400d8e75a8d0 | 19 | |
dflet | 0:400d8e75a8d0 | 20 | /** |
dflet | 0:400d8e75a8d0 | 21 | * @defgroup HttpResponse HTTP and WebSocket Response modules |
dflet | 0:400d8e75a8d0 | 22 | * This module implements routines to allow content handler modules to build and send HTTP responses back to the client. |
dflet | 0:400d8e75a8d0 | 23 | * There are two layers in this module: |
dflet | 0:400d8e75a8d0 | 24 | * - The lower layer consists of HttpResponse_Headers() and HttpResponse_Content(). These routines allow the caller to specify all details of the response. |
dflet | 0:400d8e75a8d0 | 25 | * - The higher layer consists of HttpResponse_Canned*(). These routines emit canned (pre-made) responses, such as redirects and errors, which are useful in many situations. |
dflet | 0:400d8e75a8d0 | 26 | * |
dflet | 0:400d8e75a8d0 | 27 | * @{ |
dflet | 0:400d8e75a8d0 | 28 | */ |
dflet | 0:400d8e75a8d0 | 29 | |
dflet | 0:400d8e75a8d0 | 30 | #define HTTP_STATUS_OK 200 |
dflet | 0:400d8e75a8d0 | 31 | #define HTTP_STATUS_REDIRECT_PERMANENT 301 |
dflet | 0:400d8e75a8d0 | 32 | #define HTTP_STATUS_REDIRECT_TEMPORARY 302 |
dflet | 0:400d8e75a8d0 | 33 | #define HTTP_STATUS_ERROR_UNAUTHORIZED 401 |
dflet | 0:400d8e75a8d0 | 34 | #define HTTP_STATUS_ERROR_NOT_FOUND 404 |
dflet | 0:400d8e75a8d0 | 35 | #define HTTP_STATUS_ERROR_NOT_ACCEPTED 406 |
dflet | 0:400d8e75a8d0 | 36 | #define HTTP_STATUS_ERROR_INTERNAL 500 |
dflet | 0:400d8e75a8d0 | 37 | |
dflet | 0:400d8e75a8d0 | 38 | |
dflet | 0:400d8e75a8d0 | 39 | /// The response data is gzip-compressed. Implies the header Content-Encoding: gzip |
dflet | 0:400d8e75a8d0 | 40 | #define HTTP_RESPONSE_FLAG_COMPRESSED (1 << 0) |
dflet | 0:400d8e75a8d0 | 41 | |
dflet | 0:400d8e75a8d0 | 42 | #define WS_STATUS_OK 1000 // Purpose of connection has been fulfilled |
dflet | 0:400d8e75a8d0 | 43 | #define WS_STATUS_GOING_AWAY 1001 //Server going going down or browser re-navigating |
dflet | 0:400d8e75a8d0 | 44 | #define WS_STATUS_ERROR_PROTOCOL 1002 //Protocol error |
dflet | 0:400d8e75a8d0 | 45 | #define WS_STATUS_ERROR_DATATYPE 1003 //Text frame or binary sent not supported by the application |
dflet | 0:400d8e75a8d0 | 46 | #define WS_STATUS_ERROR_ENCODING 1007 //Type not consistent with the rest of the message |
dflet | 0:400d8e75a8d0 | 47 | #define WS_STATUS_ERROR_POLICY 1008 //Policy violation for server |
dflet | 0:400d8e75a8d0 | 48 | #define WS_STATUS_ERROR_OVERFLOW 1009 //Data too large for buffer |
dflet | 0:400d8e75a8d0 | 49 | #define WS_STATUS_ERROR_UNEXPECTED 1011 //Unexpected event |
dflet | 0:400d8e75a8d0 | 50 | |
dflet | 0:400d8e75a8d0 | 51 | #ifdef __cplusplus |
dflet | 0:400d8e75a8d0 | 52 | extern "C" { |
dflet | 0:400d8e75a8d0 | 53 | #endif |
dflet | 0:400d8e75a8d0 | 54 | |
dflet | 0:400d8e75a8d0 | 55 | |
dflet | 0:400d8e75a8d0 | 56 | /** |
dflet | 0:400d8e75a8d0 | 57 | * Respond with the specified HTTP status and headers |
dflet | 0:400d8e75a8d0 | 58 | * @param uConnection The connection number, as it appears in the HttpRequest structure |
dflet | 0:400d8e75a8d0 | 59 | * @param uHttpStatus The HTTP status number to response with. Must be one of HTTP_STATUS_* |
dflet | 0:400d8e75a8d0 | 60 | * @param uFlags Flags which are manifested in the response headers. See HTTP_RESPONSE_FLAG_* |
dflet | 0:400d8e75a8d0 | 61 | * @param uContentLength The total length of content which will be sent via HttpResponse_Content() |
dflet | 0:400d8e75a8d0 | 62 | * @param contentType The content type string, or NULL to omit the content type |
dflet | 0:400d8e75a8d0 | 63 | * @param location A string which will be used for the Location header, or NULL to omit the Location header |
dflet | 0:400d8e75a8d0 | 64 | */ |
dflet | 0:400d8e75a8d0 | 65 | int HttpResponse_Headers(UINT16 uConnection, UINT16 uHttpStatus, UINT16 uFlags, UINT32 uContentLength, struct HttpBlob contentType, struct HttpBlob location); |
dflet | 0:400d8e75a8d0 | 66 | |
dflet | 0:400d8e75a8d0 | 67 | /** |
dflet | 0:400d8e75a8d0 | 68 | * Retrieves the pointer and size of the packet-send buffer |
dflet | 0:400d8e75a8d0 | 69 | * This function should be called by content handlers that wish to use the already-allocated packet-send buffer in calls to HttpResponse_Content() |
dflet | 0:400d8e75a8d0 | 70 | * @param[out] pPacketSendBuffer Returns the pointer and size of the packet-send buffer |
dflet | 0:400d8e75a8d0 | 71 | */ |
dflet | 0:400d8e75a8d0 | 72 | void HttpResponse_GetPacketSendBuffer(struct HttpBlob* pPacketSendBuffer); |
dflet | 0:400d8e75a8d0 | 73 | |
dflet | 0:400d8e75a8d0 | 74 | /** |
dflet | 0:400d8e75a8d0 | 75 | * Send response content to the client. |
dflet | 0:400d8e75a8d0 | 76 | * This function may be called more than once, until all the content is sent. |
dflet | 0:400d8e75a8d0 | 77 | * @param uConnection The connection number, as it appears in the HttpRequest structure |
dflet | 0:400d8e75a8d0 | 78 | * @param content Content blob to send to the client. |
dflet | 0:400d8e75a8d0 | 79 | */ |
dflet | 0:400d8e75a8d0 | 80 | int HttpResponse_Content(UINT16 uConnection, struct HttpBlob content); |
dflet | 0:400d8e75a8d0 | 81 | |
dflet | 0:400d8e75a8d0 | 82 | /** |
dflet | 0:400d8e75a8d0 | 83 | * Sends a canned response, with an HTTP redirect |
dflet | 0:400d8e75a8d0 | 84 | * This function should be called *instead* of HttpResponse_Status(), HttpResponse_Headers() and HttpResponse_Content() |
dflet | 0:400d8e75a8d0 | 85 | * @param uConnection The connection number, as it appears in the HttpRequest structure |
dflet | 0:400d8e75a8d0 | 86 | * @param pLocation The redirect URL |
dflet | 0:400d8e75a8d0 | 87 | * @param bPermanent zero for temporary redirect, nonzero for permanent redirect |
dflet | 0:400d8e75a8d0 | 88 | */ |
dflet | 0:400d8e75a8d0 | 89 | int HttpResponse_CannedRedirect(UINT16 uConnection, struct HttpBlob location, UINT16 bPermanent); |
dflet | 0:400d8e75a8d0 | 90 | |
dflet | 0:400d8e75a8d0 | 91 | /** |
dflet | 0:400d8e75a8d0 | 92 | * Sends a canned response, with an error message |
dflet | 0:400d8e75a8d0 | 93 | * This function should be called *instead* of HttpResponse_Status(), HttpResponse_Headers() and HttpResponse_Content() |
dflet | 0:400d8e75a8d0 | 94 | * @param uConnection The connection number, as it appears in the HttpRequest structure |
dflet | 0:400d8e75a8d0 | 95 | * @param uHttpStatus The HTTP error status. Must be one of HTTP_STATUS_ERROR_* |
dflet | 0:400d8e75a8d0 | 96 | */ |
dflet | 0:400d8e75a8d0 | 97 | int HttpResponse_CannedError(UINT16 uConnection, UINT16 uHttpStatus); |
dflet | 0:400d8e75a8d0 | 98 | |
dflet | 0:400d8e75a8d0 | 99 | /// @} |
dflet | 0:400d8e75a8d0 | 100 | #ifdef __cplusplus |
dflet | 0:400d8e75a8d0 | 101 | } |
dflet | 0:400d8e75a8d0 | 102 | #endif /* __cplusplus */ |
dflet | 0:400d8e75a8d0 | 103 | #endif //_HTTP_RESPONSE_H_ |
dflet | 0:400d8e75a8d0 | 104 |