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

Committer:
RodColeman
Date:
Thu Sep 08 10:48:09 2011 +0000
Revision:
0:850eacf3e945
revised fixed length to 178 bytes

Who changed what in which revision?

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