This programme Sets a web server using light weigh ip (using Donatien Garnier's server code) which reads a voltage and saves it value in an htm file to be displayed on local page. Server 2 2nd edition Two issues here 1 ) the compiler throws a warning about assignment in RPCHandler.cpp and 2) the local .htm file created on the mbed flash memory is always date stamped with the default date 01/01/2008 11:00

Dependencies:   EthernetNetIf NTPClient_NetServices mbed

Committer:
pmr1
Date:
Sun Aug 08 22:00:39 2010 +0000
Revision:
0:03e1db2fe866

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pmr1 0:03e1db2fe866 1
pmr1 0:03e1db2fe866 2 /*
pmr1 0:03e1db2fe866 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
pmr1 0:03e1db2fe866 4
pmr1 0:03e1db2fe866 5 Permission is hereby granted, free of charge, to any person obtaining a copy
pmr1 0:03e1db2fe866 6 of this software and associated documentation files (the "Software"), to deal
pmr1 0:03e1db2fe866 7 in the Software without restriction, including without limitation the rights
pmr1 0:03e1db2fe866 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
pmr1 0:03e1db2fe866 9 copies of the Software, and to permit persons to whom the Software is
pmr1 0:03e1db2fe866 10 furnished to do so, subject to the following conditions:
pmr1 0:03e1db2fe866 11
pmr1 0:03e1db2fe866 12 The above copyright notice and this permission notice shall be included in
pmr1 0:03e1db2fe866 13 all copies or substantial portions of the Software.
pmr1 0:03e1db2fe866 14
pmr1 0:03e1db2fe866 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
pmr1 0:03e1db2fe866 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
pmr1 0:03e1db2fe866 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
pmr1 0:03e1db2fe866 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
pmr1 0:03e1db2fe866 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
pmr1 0:03e1db2fe866 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
pmr1 0:03e1db2fe866 21 THE SOFTWARE.
pmr1 0:03e1db2fe866 22 */
pmr1 0:03e1db2fe866 23
pmr1 0:03e1db2fe866 24 #include "RPCHandler.h"
pmr1 0:03e1db2fe866 25 #include "rpc.h"
pmr1 0:03e1db2fe866 26
pmr1 0:03e1db2fe866 27 //#define __DEBUG
pmr1 0:03e1db2fe866 28 #include "dbg/dbg.h"
pmr1 0:03e1db2fe866 29
pmr1 0:03e1db2fe866 30 #define RPC_DATA_LEN 128
pmr1 0:03e1db2fe866 31
pmr1 0:03e1db2fe866 32 RPCHandler::RPCHandler(const char* rootPath, const char* path, TCPSocket* pTCPSocket) : HTTPRequestHandler(rootPath, path, pTCPSocket)
pmr1 0:03e1db2fe866 33 {}
pmr1 0:03e1db2fe866 34
pmr1 0:03e1db2fe866 35 RPCHandler::~RPCHandler()
pmr1 0:03e1db2fe866 36 {
pmr1 0:03e1db2fe866 37 DBG("\r\nHandler destroyed\r\n");
pmr1 0:03e1db2fe866 38 }
pmr1 0:03e1db2fe866 39
pmr1 0:03e1db2fe866 40 void RPCHandler::doGet()
pmr1 0:03e1db2fe866 41 {
pmr1 0:03e1db2fe866 42 DBG("\r\nIn RPCHandler::doGet()\r\n");
pmr1 0:03e1db2fe866 43 char resp[RPC_DATA_LEN] = {0};
pmr1 0:03e1db2fe866 44 char req[RPC_DATA_LEN] = {0};
pmr1 0:03e1db2fe866 45
pmr1 0:03e1db2fe866 46 DBG("\r\nPath : %s\r\n", path().c_str());
pmr1 0:03e1db2fe866 47 DBG("\r\nRoot Path : %s\r\n", rootPath().c_str());
pmr1 0:03e1db2fe866 48
pmr1 0:03e1db2fe866 49 //Remove path
pmr1 0:03e1db2fe866 50 strncpy(req, path().c_str(), RPC_DATA_LEN-1);
pmr1 0:03e1db2fe866 51 DBG("\r\nRPC req : %s\r\n", req);
pmr1 0:03e1db2fe866 52
pmr1 0:03e1db2fe866 53 //Remove %20, +, from req
pmr1 0:03e1db2fe866 54 cleanReq(req);
pmr1 0:03e1db2fe866 55 DBG("\r\nRPC req : %s\r\n", req);
pmr1 0:03e1db2fe866 56
pmr1 0:03e1db2fe866 57 //Do RPC Call
pmr1 0:03e1db2fe866 58 mbed::rpc(req, resp); //FIXME: Use bool result
pmr1 0:03e1db2fe866 59
pmr1 0:03e1db2fe866 60 //Response
pmr1 0:03e1db2fe866 61 setContentLen( strlen(resp) );
pmr1 0:03e1db2fe866 62
pmr1 0:03e1db2fe866 63 //Make sure that the browser won't cache this request
pmr1 0:03e1db2fe866 64 respHeaders()["Cache-control"]="no-cache;no-store";
pmr1 0:03e1db2fe866 65 // respHeaders()["Cache-control"]="no-store";
pmr1 0:03e1db2fe866 66 respHeaders()["Pragma"]="no-cache";
pmr1 0:03e1db2fe866 67 respHeaders()["Expires"]="0";
pmr1 0:03e1db2fe866 68
pmr1 0:03e1db2fe866 69 //Write data
pmr1 0:03e1db2fe866 70 respHeaders()["Connection"] = "close";
pmr1 0:03e1db2fe866 71 writeData(resp, strlen(resp));
pmr1 0:03e1db2fe866 72 DBG("\r\nExit RPCHandler::doGet()\r\n");
pmr1 0:03e1db2fe866 73 }
pmr1 0:03e1db2fe866 74
pmr1 0:03e1db2fe866 75 void RPCHandler::doPost()
pmr1 0:03e1db2fe866 76 {
pmr1 0:03e1db2fe866 77
pmr1 0:03e1db2fe866 78 }
pmr1 0:03e1db2fe866 79
pmr1 0:03e1db2fe866 80 void RPCHandler::doHead()
pmr1 0:03e1db2fe866 81 {
pmr1 0:03e1db2fe866 82
pmr1 0:03e1db2fe866 83 }
pmr1 0:03e1db2fe866 84
pmr1 0:03e1db2fe866 85
pmr1 0:03e1db2fe866 86 void RPCHandler::onReadable() //Data has been read
pmr1 0:03e1db2fe866 87 {
pmr1 0:03e1db2fe866 88
pmr1 0:03e1db2fe866 89 }
pmr1 0:03e1db2fe866 90
pmr1 0:03e1db2fe866 91 void RPCHandler::onWriteable() //Data has been written & buf is free
pmr1 0:03e1db2fe866 92 {
pmr1 0:03e1db2fe866 93 DBG("\r\nRPCHandler::onWriteable() event\r\n");
pmr1 0:03e1db2fe866 94 close(); //Data written, we can close the connection
pmr1 0:03e1db2fe866 95 }
pmr1 0:03e1db2fe866 96
pmr1 0:03e1db2fe866 97 void RPCHandler::onClose() //Connection is closing
pmr1 0:03e1db2fe866 98 {
pmr1 0:03e1db2fe866 99 //Nothing to do
pmr1 0:03e1db2fe866 100 }
pmr1 0:03e1db2fe866 101
pmr1 0:03e1db2fe866 102 void RPCHandler::cleanReq(char* data)
pmr1 0:03e1db2fe866 103 {
pmr1 0:03e1db2fe866 104 char* p;
pmr1 0:03e1db2fe866 105 static const char* lGarbage[2] = {"%20", "+"};
pmr1 0:03e1db2fe866 106 for(int i = 0; i < 2; i++)
pmr1 0:03e1db2fe866 107 {
pmr1 0:03e1db2fe866 108 while( p = strstr(data, lGarbage[i]) )
pmr1 0:03e1db2fe866 109 {
pmr1 0:03e1db2fe866 110 memset((void*) p, ' ', strlen(lGarbage[i]));
pmr1 0:03e1db2fe866 111 }
pmr1 0:03e1db2fe866 112 }
pmr1 0:03e1db2fe866 113 }
pmr1 0:03e1db2fe866 114
pmr1 0:03e1db2fe866 115