A Port of TI's Webserver for the CC3000

Dependencies:   mbed

Committer:
dflet
Date:
Mon Sep 16 18:37:14 2013 +0000
Revision:
2:e6a185df9e4c
Parent:
0:6ad60d78b315
ADC and Leds now work on board and config.html page.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dflet 0:6ad60d78b315 1 /*****************************************************************************
dflet 0:6ad60d78b315 2 *
dflet 0:6ad60d78b315 3 * HttpDynamic.h
dflet 0:6ad60d78b315 4 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
dflet 0:6ad60d78b315 5 *
dflet 0:6ad60d78b315 6 * Redistribution and use in source and binary forms, with or without
dflet 0:6ad60d78b315 7 * modification, are permitted provided that the following conditions
dflet 0:6ad60d78b315 8 * are met:
dflet 0:6ad60d78b315 9 *
dflet 0:6ad60d78b315 10 * Redistributions of source code must retain the above copyright
dflet 0:6ad60d78b315 11 * notice, this list of conditions and the following disclaimer.
dflet 0:6ad60d78b315 12 *
dflet 0:6ad60d78b315 13 * Redistributions in binary form must reproduce the above copyright
dflet 0:6ad60d78b315 14 * notice, this list of conditions and the following disclaimer in the
dflet 0:6ad60d78b315 15 * documentation and/or other materials provided with the
dflet 0:6ad60d78b315 16 * distribution.
dflet 0:6ad60d78b315 17 *
dflet 0:6ad60d78b315 18 * Neither the name of Texas Instruments Incorporated nor the names of
dflet 0:6ad60d78b315 19 * its contributors may be used to endorse or promote products derived
dflet 0:6ad60d78b315 20 * from this software without specific prior written permission.
dflet 0:6ad60d78b315 21 *
dflet 0:6ad60d78b315 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
dflet 0:6ad60d78b315 23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
dflet 0:6ad60d78b315 24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
dflet 0:6ad60d78b315 25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
dflet 0:6ad60d78b315 26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
dflet 0:6ad60d78b315 27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
dflet 0:6ad60d78b315 28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
dflet 0:6ad60d78b315 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
dflet 0:6ad60d78b315 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
dflet 0:6ad60d78b315 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
dflet 0:6ad60d78b315 32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dflet 0:6ad60d78b315 33 *
dflet 0:6ad60d78b315 34 *****************************************************************************/
dflet 0:6ad60d78b315 35 #ifndef _HTTP_DYNAMIC_H_
dflet 0:6ad60d78b315 36 #define _HTTP_DYNAMIC_H_
dflet 0:6ad60d78b315 37
dflet 0:6ad60d78b315 38 #include "HttpConfig.h"
dflet 0:6ad60d78b315 39
dflet 0:6ad60d78b315 40 #ifdef HTTP_CORE_ENABLE_DYNAMIC
dflet 0:6ad60d78b315 41
dflet 0:6ad60d78b315 42 /**
dflet 0:6ad60d78b315 43 * @defgroup HttpDynamic Dynamic request handler module
dflet 0:6ad60d78b315 44 * This module implements dynamic content processing for HTTP requests.
dflet 0:6ad60d78b315 45 * All requests are handled by C code functions, and the response contents is returned via HttpResopnse routines
dflet 0:6ad60d78b315 46 * Note this module is only compiled if HTTP_CORE_ENABLE_DYNAMIC is defined in HttpConfig.h
dflet 0:6ad60d78b315 47 *
dflet 0:6ad60d78b315 48 * @{
dflet 0:6ad60d78b315 49 */
dflet 0:6ad60d78b315 50
dflet 0:6ad60d78b315 51 #include "HttpRequest.h"
dflet 0:6ad60d78b315 52
dflet 0:6ad60d78b315 53 #define HTTP_DYNAMIC_NUM_OF_RESOURCES 2
dflet 0:6ad60d78b315 54 #define HTTP_DYNAMIC_MAX_RESOURCE_LEN 14
dflet 0:6ad60d78b315 55 #define HTTP_DYNAMIC_LED_NUM_LEN 4
dflet 0:6ad60d78b315 56 #define HTTP_DYNAMIC_LED_ACTION_LEN 7
dflet 0:6ad60d78b315 57 #define HTTP_DYNAMIC_TEMPR_UNIT_LEN 5
dflet 0:6ad60d78b315 58 #define HTTP_DYNAMIC_CONF_PROTO_LEN 6
dflet 0:6ad60d78b315 59 #define HTTP_DYNAMIC_CONTENT_BODY_LEN 17
dflet 0:6ad60d78b315 60
dflet 0:6ad60d78b315 61
dflet 0:6ad60d78b315 62 enum HttpDynamicNumOfResources
dflet 0:6ad60d78b315 63 {
dflet 0:6ad60d78b315 64 LED,
dflet 0:6ad60d78b315 65 WHEEL,
dflet 0:6ad60d78b315 66 };
dflet 0:6ad60d78b315 67
dflet 0:6ad60d78b315 68 enum HttpDynamicLedNumber
dflet 0:6ad60d78b315 69 {
dflet 0:6ad60d78b315 70 NOLED,
dflet 0:6ad60d78b315 71 LED_1,
dflet 0:6ad60d78b315 72 LED_2,
dflet 0:6ad60d78b315 73 LED_3,
dflet 0:6ad60d78b315 74 LED_4,
dflet 0:6ad60d78b315 75 //LED_5,
dflet 0:6ad60d78b315 76 //LED_6,
dflet 0:6ad60d78b315 77 //LED_7,
dflet 0:6ad60d78b315 78 //LED_8
dflet 0:6ad60d78b315 79 };
dflet 0:6ad60d78b315 80
dflet 0:6ad60d78b315 81 enum HttpDynamicLedAction
dflet 0:6ad60d78b315 82 {
dflet 0:6ad60d78b315 83 OFF,
dflet 0:6ad60d78b315 84 ON,
dflet 0:6ad60d78b315 85 toggle,
dflet 0:6ad60d78b315 86 };
dflet 0:6ad60d78b315 87
dflet 0:6ad60d78b315 88 enum HttpDynamicWheelAction
dflet 0:6ad60d78b315 89 {
dflet 0:6ad60d78b315 90 NONE,
dflet 0:6ad60d78b315 91 GETSTATUS
dflet 0:6ad60d78b315 92 };
dflet 0:6ad60d78b315 93
dflet 0:6ad60d78b315 94
dflet 0:6ad60d78b315 95 /* input params structure */
dflet 0:6ad60d78b315 96 struct HttpDynamicLedInParam
dflet 0:6ad60d78b315 97 {
dflet 0:6ad60d78b315 98 enum HttpDynamicLedNumber uLedNumber;
dflet 0:6ad60d78b315 99 enum HttpDynamicLedAction uLedAction;
dflet 0:6ad60d78b315 100 };
dflet 0:6ad60d78b315 101
dflet 0:6ad60d78b315 102 struct HttpDynamicWheelInParam
dflet 0:6ad60d78b315 103 {
dflet 0:6ad60d78b315 104 enum HttpDynamicWheelAction uWheelAction;
dflet 0:6ad60d78b315 105 };
dflet 0:6ad60d78b315 106
dflet 0:6ad60d78b315 107
dflet 0:6ad60d78b315 108 typedef union
dflet 0:6ad60d78b315 109 {
dflet 0:6ad60d78b315 110 struct HttpDynamicLedInParam uLedParam;
dflet 0:6ad60d78b315 111 struct HttpDynamicWheelInParam uWheelParam;
dflet 0:6ad60d78b315 112 }inputParams;
dflet 0:6ad60d78b315 113
dflet 0:6ad60d78b315 114 struct HttpDynamicLedOutParam
dflet 0:6ad60d78b315 115 {
dflet 0:6ad60d78b315 116 uint8 uLedDummyOut;
dflet 0:6ad60d78b315 117 };
dflet 0:6ad60d78b315 118
dflet 0:6ad60d78b315 119 struct HttpDynamicWheelOutParam
dflet 0:6ad60d78b315 120 {
dflet 0:6ad60d78b315 121 uint8 uLedDummyOut;
dflet 0:6ad60d78b315 122 uint8 uWheelPosition;
dflet 0:6ad60d78b315 123 uint16 uWheelValue;
dflet 0:6ad60d78b315 124 };
dflet 0:6ad60d78b315 125
dflet 0:6ad60d78b315 126
dflet 0:6ad60d78b315 127 typedef union
dflet 0:6ad60d78b315 128 {
dflet 0:6ad60d78b315 129 struct HttpDynamicLedOutParam uLedParam;
dflet 0:6ad60d78b315 130 struct HttpDynamicWheelOutParam sWheelParam;
dflet 0:6ad60d78b315 131 }outputParams;
dflet 0:6ad60d78b315 132
dflet 0:6ad60d78b315 133 typedef struct
dflet 0:6ad60d78b315 134 {
dflet 0:6ad60d78b315 135 inputParams dynamicHandlerInParam;
dflet 0:6ad60d78b315 136 outputParams dynamicHandlerOutParam;
dflet 0:6ad60d78b315 137 enum HttpDynamicNumOfResources resourceType;
dflet 0:6ad60d78b315 138 void (*pDynamicHandler)(inputParams, outputParams*);
dflet 0:6ad60d78b315 139 }PerConnDynamicContent;
dflet 0:6ad60d78b315 140
dflet 0:6ad60d78b315 141
dflet 0:6ad60d78b315 142 /**
dflet 0:6ad60d78b315 143 * Initialize HttpDynamic module state for a new request, and identify the request
dflet 0:6ad60d78b315 144 * This function must examine the specified resource string and determine whether it can commit to process this request
dflet 0:6ad60d78b315 145 * Also, if the resource string includes any information that this module needs in order to process the request (such as the contents of the query string)
dflet 0:6ad60d78b315 146 * then it is the responsibility of this function to parse this information and store it in a connection-specific struct.
dflet 0:6ad60d78b315 147 * If this function returns nonzero, then the core will call HttpDynamic_ProcessRequest() with the rest of the request details.
dflet 0:6ad60d78b315 148 * @param uConnection The number of the connection. This value is guaranteed to satisfy: 0 <= uConnection < HTTP_CORE_MAX_CONNECTIONS
dflet 0:6ad60d78b315 149 * @param resource The resource part of the URL, as specified by the browser in the request, including any query string (and hash)
dflet 0:6ad60d78b315 150 * Note: The resource string exists ONLY during the call to this function. The string pointer should not be copied by this function.
dflet 0:6ad60d78b315 151 * @return nonzero if request is to be handled by this module. zero if not.
dflet 0:6ad60d78b315 152 */
dflet 0:6ad60d78b315 153 int HttpDynamic_InitRequest(uint16 uConnection, struct HttpBlob resource);
dflet 0:6ad60d78b315 154
dflet 0:6ad60d78b315 155 /**
dflet 0:6ad60d78b315 156 * Process a dynamic-content HTTP request
dflet 0:6ad60d78b315 157 * This function is only be called by the core, if HttpDynamic_InitRequest() returns nonzero.
dflet 0:6ad60d78b315 158 * This function processes the specified HTTP request, and send the response on the connection specified by request->uConnection.
dflet 0:6ad60d78b315 159 * This function must call the HttpResponse_*() functions in order to send data back to the browser.
dflet 0:6ad60d78b315 160 * Please refer to HttpResponse.h for more information.
dflet 0:6ad60d78b315 161 * @param request Pointer to all data available about the request
dflet 0:6ad60d78b315 162 */
dflet 0:6ad60d78b315 163 void HttpDynamic_ProcessRequest(struct HttpRequest* request);
dflet 0:6ad60d78b315 164
dflet 0:6ad60d78b315 165 /// @}
dflet 0:6ad60d78b315 166
dflet 0:6ad60d78b315 167 #endif // HTTP_CORE_ENABLE_DYNAMIC
dflet 0:6ad60d78b315 168
dflet 0:6ad60d78b315 169 #endif // _HTTP_DYNAMIC_H_
dflet 0:6ad60d78b315 170