Netservices modded to read fragmented HTTP respsonse/payload from special purpose server - 180 bytes only

Committer:
RodColeman
Date:
Thu Sep 08 10:41:36 2011 +0000
Revision:
0:8f5825f330b0
setDataLen hacked to 180bytes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RodColeman 0:8f5825f330b0 1
RodColeman 0:8f5825f330b0 2 /*
RodColeman 0:8f5825f330b0 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
RodColeman 0:8f5825f330b0 4
RodColeman 0:8f5825f330b0 5 Permission is hereby granted, free of charge, to any person obtaining a copy
RodColeman 0:8f5825f330b0 6 of this software and associated documentation files (the "Software"), to deal
RodColeman 0:8f5825f330b0 7 in the Software without restriction, including without limitation the rights
RodColeman 0:8f5825f330b0 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
RodColeman 0:8f5825f330b0 9 copies of the Software, and to permit persons to whom the Software is
RodColeman 0:8f5825f330b0 10 furnished to do so, subject to the following conditions:
RodColeman 0:8f5825f330b0 11
RodColeman 0:8f5825f330b0 12 The above copyright notice and this permission notice shall be included in
RodColeman 0:8f5825f330b0 13 all copies or substantial portions of the Software.
RodColeman 0:8f5825f330b0 14
RodColeman 0:8f5825f330b0 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
RodColeman 0:8f5825f330b0 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
RodColeman 0:8f5825f330b0 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
RodColeman 0:8f5825f330b0 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
RodColeman 0:8f5825f330b0 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
RodColeman 0:8f5825f330b0 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
RodColeman 0:8f5825f330b0 21 THE SOFTWARE.
RodColeman 0:8f5825f330b0 22 */
RodColeman 0:8f5825f330b0 23
RodColeman 0:8f5825f330b0 24 #include "lwipNetDnsRequest.h"
RodColeman 0:8f5825f330b0 25 #include "lwip/err.h" //err_t, ERR_xxx
RodColeman 0:8f5825f330b0 26 #include "lwip/dns.h"
RodColeman 0:8f5825f330b0 27
RodColeman 0:8f5825f330b0 28 #include "netCfg.h"
RodColeman 0:8f5825f330b0 29 #if NET_LWIP_STACK
RodColeman 0:8f5825f330b0 30
RodColeman 0:8f5825f330b0 31 //#define __DEBUG
RodColeman 0:8f5825f330b0 32 #include "dbg/dbg.h"
RodColeman 0:8f5825f330b0 33
RodColeman 0:8f5825f330b0 34 LwipNetDnsRequest::LwipNetDnsRequest(const char* hostname) : NetDnsRequest(hostname), m_state(LWIPNETDNS_START), m_cbFired(false), m_closing(false)
RodColeman 0:8f5825f330b0 35 {
RodColeman 0:8f5825f330b0 36 DBG("New LwipNetDnsRequest %p\n", this);
RodColeman 0:8f5825f330b0 37 }
RodColeman 0:8f5825f330b0 38
RodColeman 0:8f5825f330b0 39 LwipNetDnsRequest::LwipNetDnsRequest(Host* pHost) : NetDnsRequest(pHost), m_state(LWIPNETDNS_START), m_cbFired(false), m_closing(false)
RodColeman 0:8f5825f330b0 40 {
RodColeman 0:8f5825f330b0 41 DBG("New LwipNetDnsRequest %p\n", this);
RodColeman 0:8f5825f330b0 42 }
RodColeman 0:8f5825f330b0 43
RodColeman 0:8f5825f330b0 44 LwipNetDnsRequest::~LwipNetDnsRequest()
RodColeman 0:8f5825f330b0 45 {
RodColeman 0:8f5825f330b0 46 DBG("LwipNetDnsRequest %p destroyed\n", this);
RodColeman 0:8f5825f330b0 47 }
RodColeman 0:8f5825f330b0 48
RodColeman 0:8f5825f330b0 49 /*
RodColeman 0:8f5825f330b0 50 Main useful function here (see lwip/dns.h):
RodColeman 0:8f5825f330b0 51 err_t dns_gethostbyname(const char *hostname, ip_addr_t *addr,
RodColeman 0:8f5825f330b0 52 dns_found_callback found, void *callback_arg);
RodColeman 0:8f5825f330b0 53 */
RodColeman 0:8f5825f330b0 54
RodColeman 0:8f5825f330b0 55 //Execute request & return OK if found, NOTFOUND or ERROR on error, or PROCESSING if the request has not completed yet
RodColeman 0:8f5825f330b0 56 void LwipNetDnsRequest::poll()
RodColeman 0:8f5825f330b0 57 {
RodColeman 0:8f5825f330b0 58 err_t err;
RodColeman 0:8f5825f330b0 59 switch(m_state)
RodColeman 0:8f5825f330b0 60 {
RodColeman 0:8f5825f330b0 61 case LWIPNETDNS_START: //First req, let's call dns_gethostbyname
RodColeman 0:8f5825f330b0 62 ip_addr_t ipStruct;
RodColeman 0:8f5825f330b0 63 err = dns_gethostbyname(m_hostname, &ipStruct, LwipNetDnsRequest::sFoundCb, (void*) this );
RodColeman 0:8f5825f330b0 64 if( err == ERR_OK )
RodColeman 0:8f5825f330b0 65 {
RodColeman 0:8f5825f330b0 66 m_ip = IpAddr(&ipStruct);
RodColeman 0:8f5825f330b0 67 m_state = LWIPNETDNS_OK;
RodColeman 0:8f5825f330b0 68 DBG("DNS: Ip found in cache.\n");
RodColeman 0:8f5825f330b0 69 }
RodColeman 0:8f5825f330b0 70 else if( err == ERR_INPROGRESS)
RodColeman 0:8f5825f330b0 71 {
RodColeman 0:8f5825f330b0 72 DBG("DNS: Processing.\n");
RodColeman 0:8f5825f330b0 73 m_state = LWIPNETDNS_PROCESSING;
RodColeman 0:8f5825f330b0 74 }
RodColeman 0:8f5825f330b0 75 else //Likely ERR_VAL
RodColeman 0:8f5825f330b0 76 {
RodColeman 0:8f5825f330b0 77 DBG("DNS: Error on init.\n");
RodColeman 0:8f5825f330b0 78 m_state = LWIPNETDNS_ERROR;
RodColeman 0:8f5825f330b0 79 }
RodColeman 0:8f5825f330b0 80 break;
RodColeman 0:8f5825f330b0 81 case LWIPNETDNS_PROCESSING:
RodColeman 0:8f5825f330b0 82 break; //Nothing to do, DNS is polled on interrupt
RodColeman 0:8f5825f330b0 83 case LWIPNETDNS_OK:
RodColeman 0:8f5825f330b0 84 if(!m_cbFired)
RodColeman 0:8f5825f330b0 85 {
RodColeman 0:8f5825f330b0 86 DBG("DNS: Ip found.\n");
RodColeman 0:8f5825f330b0 87 m_cbFired = true;
RodColeman 0:8f5825f330b0 88 onReply(NETDNS_FOUND); //Raise callback
RodColeman 0:8f5825f330b0 89 }
RodColeman 0:8f5825f330b0 90 break;
RodColeman 0:8f5825f330b0 91 case LWIPNETDNS_NOTFOUND:
RodColeman 0:8f5825f330b0 92 if(!m_cbFired)
RodColeman 0:8f5825f330b0 93 {
RodColeman 0:8f5825f330b0 94 DBG("DNS: could not be resolved.\n");
RodColeman 0:8f5825f330b0 95 m_cbFired = true;
RodColeman 0:8f5825f330b0 96 onReply(NETDNS_NOTFOUND); //Raise callback
RodColeman 0:8f5825f330b0 97 }
RodColeman 0:8f5825f330b0 98 break;
RodColeman 0:8f5825f330b0 99 case LWIPNETDNS_ERROR:
RodColeman 0:8f5825f330b0 100 default:
RodColeman 0:8f5825f330b0 101 if(!m_cbFired)
RodColeman 0:8f5825f330b0 102 {
RodColeman 0:8f5825f330b0 103 DBG("DNS: Error.\n");
RodColeman 0:8f5825f330b0 104 m_cbFired = true;
RodColeman 0:8f5825f330b0 105 onReply(NETDNS_ERROR); //Raise callback
RodColeman 0:8f5825f330b0 106 }
RodColeman 0:8f5825f330b0 107 break;
RodColeman 0:8f5825f330b0 108 }
RodColeman 0:8f5825f330b0 109 if(m_closing && (m_state!=LWIPNETDNS_PROCESSING)) //Check wether the closure has been reqd
RodColeman 0:8f5825f330b0 110 {
RodColeman 0:8f5825f330b0 111 DBG("LwipNetDnsRequest: Closing in poll()\n");
RodColeman 0:8f5825f330b0 112 NetDnsRequest::close();
RodColeman 0:8f5825f330b0 113 }
RodColeman 0:8f5825f330b0 114 }
RodColeman 0:8f5825f330b0 115
RodColeman 0:8f5825f330b0 116 void LwipNetDnsRequest::close()
RodColeman 0:8f5825f330b0 117 {
RodColeman 0:8f5825f330b0 118 DBG("LwipNetDnsRequest: Close req\n");
RodColeman 0:8f5825f330b0 119 if(m_state!=LWIPNETDNS_PROCESSING)
RodColeman 0:8f5825f330b0 120 {
RodColeman 0:8f5825f330b0 121 DBG("LwipNetDnsRequest: Closing in close()\n");
RodColeman 0:8f5825f330b0 122 NetDnsRequest::close();
RodColeman 0:8f5825f330b0 123 }
RodColeman 0:8f5825f330b0 124 else //Cannot close rightaway, waiting for callback from underlying layer
RodColeman 0:8f5825f330b0 125 {
RodColeman 0:8f5825f330b0 126 m_closing = true;
RodColeman 0:8f5825f330b0 127 }
RodColeman 0:8f5825f330b0 128 }
RodColeman 0:8f5825f330b0 129
RodColeman 0:8f5825f330b0 130 void LwipNetDnsRequest::foundCb(const char *name, ip_addr_t *ipaddr)
RodColeman 0:8f5825f330b0 131 {
RodColeman 0:8f5825f330b0 132 if( ipaddr == NULL )
RodColeman 0:8f5825f330b0 133 {
RodColeman 0:8f5825f330b0 134 DBG("LwipNetDnsRequest: Callback: Name not found\n");
RodColeman 0:8f5825f330b0 135 m_state = LWIPNETDNS_NOTFOUND;
RodColeman 0:8f5825f330b0 136 return;
RodColeman 0:8f5825f330b0 137 }
RodColeman 0:8f5825f330b0 138 DBG("LwipNetDnsRequest: Callback: Resolved\n");
RodColeman 0:8f5825f330b0 139 m_ip = IpAddr(ipaddr);
RodColeman 0:8f5825f330b0 140 m_state = LWIPNETDNS_OK;
RodColeman 0:8f5825f330b0 141 }
RodColeman 0:8f5825f330b0 142
RodColeman 0:8f5825f330b0 143
RodColeman 0:8f5825f330b0 144 void LwipNetDnsRequest::sFoundCb(const char *name, ip_addr_t *ipaddr, void *arg)
RodColeman 0:8f5825f330b0 145 {
RodColeman 0:8f5825f330b0 146 DBG("LwipNetDnsRequest: Static callback\n");
RodColeman 0:8f5825f330b0 147 LwipNetDnsRequest* pMe = (LwipNetDnsRequest*) arg;
RodColeman 0:8f5825f330b0 148 return pMe->foundCb( name, ipaddr );
RodColeman 0:8f5825f330b0 149 }
RodColeman 0:8f5825f330b0 150
RodColeman 0:8f5825f330b0 151 #endif
RodColeman 0:8f5825f330b0 152