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 "net.h"
RodColeman 0:850eacf3e945 25
RodColeman 0:850eacf3e945 26 #include "host.h"
RodColeman 0:850eacf3e945 27 #include "ipaddr.h"
RodColeman 0:850eacf3e945 28 #include "netservice.h"
RodColeman 0:850eacf3e945 29 #include "if/net/netif.h"
RodColeman 0:850eacf3e945 30 #include "if/net/nettcpsocket.h"
RodColeman 0:850eacf3e945 31 #include "if/net/netudpsocket.h"
RodColeman 0:850eacf3e945 32 #include "if/net/netdnsrequest.h"
RodColeman 0:850eacf3e945 33
RodColeman 0:850eacf3e945 34 //#define __DEBUG
RodColeman 0:850eacf3e945 35 #include "dbg/dbg.h"
RodColeman 0:850eacf3e945 36
RodColeman 0:850eacf3e945 37 Net::Net() : m_defaultIf(NULL), m_lpIf(), m_lpNetTcpSocket(), m_lpNetUdpSocket()
RodColeman 0:850eacf3e945 38 {
RodColeman 0:850eacf3e945 39
RodColeman 0:850eacf3e945 40 }
RodColeman 0:850eacf3e945 41
RodColeman 0:850eacf3e945 42 Net::~Net()
RodColeman 0:850eacf3e945 43 {
RodColeman 0:850eacf3e945 44
RodColeman 0:850eacf3e945 45 }
RodColeman 0:850eacf3e945 46
RodColeman 0:850eacf3e945 47
RodColeman 0:850eacf3e945 48 void Net::poll()
RodColeman 0:850eacf3e945 49 {
RodColeman 0:850eacf3e945 50 //DBG("\r\nNet : Services polling\r\n");
RodColeman 0:850eacf3e945 51
RodColeman 0:850eacf3e945 52 //Poll Services
RodColeman 0:850eacf3e945 53 NetService::servicesPoll();
RodColeman 0:850eacf3e945 54
RodColeman 0:850eacf3e945 55 //DBG("\r\nNet : Interfaces polling\r\n");
RodColeman 0:850eacf3e945 56
RodColeman 0:850eacf3e945 57 //Poll Interfaces
RodColeman 0:850eacf3e945 58 list<NetIf*>::iterator pIfIt;
RodColeman 0:850eacf3e945 59
RodColeman 0:850eacf3e945 60 for ( pIfIt = net().m_lpIf.begin() ; pIfIt != net().m_lpIf.end(); pIfIt++ )
RodColeman 0:850eacf3e945 61 {
RodColeman 0:850eacf3e945 62 (*pIfIt)->poll();
RodColeman 0:850eacf3e945 63 }
RodColeman 0:850eacf3e945 64
RodColeman 0:850eacf3e945 65 //DBG("\r\nNet : Sockets polling\r\n");
RodColeman 0:850eacf3e945 66
RodColeman 0:850eacf3e945 67 //Poll Tcp Sockets
RodColeman 0:850eacf3e945 68 list<NetTcpSocket*>::iterator pNetTcpSocketIt;
RodColeman 0:850eacf3e945 69
RodColeman 0:850eacf3e945 70 for ( pNetTcpSocketIt = net().m_lpNetTcpSocket.begin() ; pNetTcpSocketIt != net().m_lpNetTcpSocket.end(); )
RodColeman 0:850eacf3e945 71 {
RodColeman 0:850eacf3e945 72 (*pNetTcpSocketIt)->poll();
RodColeman 0:850eacf3e945 73
RodColeman 0:850eacf3e945 74 if( (*pNetTcpSocketIt)->m_closed && !((*pNetTcpSocketIt)->m_refs) )
RodColeman 0:850eacf3e945 75 {
RodColeman 0:850eacf3e945 76 (*pNetTcpSocketIt)->m_removed = true;
RodColeman 0:850eacf3e945 77 delete (*pNetTcpSocketIt);
RodColeman 0:850eacf3e945 78 (*pNetTcpSocketIt) = NULL;
RodColeman 0:850eacf3e945 79 pNetTcpSocketIt = net().m_lpNetTcpSocket.erase(pNetTcpSocketIt);
RodColeman 0:850eacf3e945 80 }
RodColeman 0:850eacf3e945 81 else
RodColeman 0:850eacf3e945 82 {
RodColeman 0:850eacf3e945 83 pNetTcpSocketIt++;
RodColeman 0:850eacf3e945 84 }
RodColeman 0:850eacf3e945 85 }
RodColeman 0:850eacf3e945 86
RodColeman 0:850eacf3e945 87 //Poll Udp Sockets
RodColeman 0:850eacf3e945 88 list<NetUdpSocket*>::iterator pNetUdpSocketIt;
RodColeman 0:850eacf3e945 89
RodColeman 0:850eacf3e945 90 for ( pNetUdpSocketIt = net().m_lpNetUdpSocket.begin() ; pNetUdpSocketIt != net().m_lpNetUdpSocket.end(); )
RodColeman 0:850eacf3e945 91 {
RodColeman 0:850eacf3e945 92 (*pNetUdpSocketIt)->poll();
RodColeman 0:850eacf3e945 93
RodColeman 0:850eacf3e945 94 if( (*pNetUdpSocketIt)->m_closed && !((*pNetUdpSocketIt)->m_refs) )
RodColeman 0:850eacf3e945 95 {
RodColeman 0:850eacf3e945 96 (*pNetUdpSocketIt)->m_removed = true;
RodColeman 0:850eacf3e945 97 delete (*pNetUdpSocketIt);
RodColeman 0:850eacf3e945 98 (*pNetUdpSocketIt) = NULL;
RodColeman 0:850eacf3e945 99 pNetUdpSocketIt = net().m_lpNetUdpSocket.erase(pNetUdpSocketIt);
RodColeman 0:850eacf3e945 100 }
RodColeman 0:850eacf3e945 101 else
RodColeman 0:850eacf3e945 102 {
RodColeman 0:850eacf3e945 103 pNetUdpSocketIt++;
RodColeman 0:850eacf3e945 104 }
RodColeman 0:850eacf3e945 105 }
RodColeman 0:850eacf3e945 106
RodColeman 0:850eacf3e945 107
RodColeman 0:850eacf3e945 108 }
RodColeman 0:850eacf3e945 109
RodColeman 0:850eacf3e945 110 NetTcpSocket* Net::tcpSocket(NetIf& netif) {
RodColeman 0:850eacf3e945 111 NetTcpSocket* pNetTcpSocket = netif.tcpSocket();
RodColeman 0:850eacf3e945 112 pNetTcpSocket->m_refs++;
RodColeman 0:850eacf3e945 113 return pNetTcpSocket;
RodColeman 0:850eacf3e945 114 }
RodColeman 0:850eacf3e945 115
RodColeman 0:850eacf3e945 116 NetTcpSocket* Net::tcpSocket() { //NetTcpSocket on default if
RodColeman 0:850eacf3e945 117 if ( net().m_defaultIf == NULL )
RodColeman 0:850eacf3e945 118 return NULL;
RodColeman 0:850eacf3e945 119 NetTcpSocket* pNetTcpSocket = net().m_defaultIf->tcpSocket();
RodColeman 0:850eacf3e945 120 pNetTcpSocket->m_refs++;
RodColeman 0:850eacf3e945 121 return pNetTcpSocket;
RodColeman 0:850eacf3e945 122 }
RodColeman 0:850eacf3e945 123
RodColeman 0:850eacf3e945 124 void Net::releaseTcpSocket(NetTcpSocket* pNetTcpSocket)
RodColeman 0:850eacf3e945 125 {
RodColeman 0:850eacf3e945 126 pNetTcpSocket->m_refs--;
RodColeman 0:850eacf3e945 127 if(!pNetTcpSocket->m_closed && !pNetTcpSocket->m_refs)
RodColeman 0:850eacf3e945 128 pNetTcpSocket->close();
RodColeman 0:850eacf3e945 129 }
RodColeman 0:850eacf3e945 130
RodColeman 0:850eacf3e945 131 NetUdpSocket* Net::udpSocket(NetIf& netif) {
RodColeman 0:850eacf3e945 132 NetUdpSocket* pNetUdpSocket = netif.udpSocket();
RodColeman 0:850eacf3e945 133 pNetUdpSocket->m_refs++;
RodColeman 0:850eacf3e945 134 return pNetUdpSocket;
RodColeman 0:850eacf3e945 135 }
RodColeman 0:850eacf3e945 136
RodColeman 0:850eacf3e945 137 NetUdpSocket* Net::udpSocket() { //NetTcpSocket on default if
RodColeman 0:850eacf3e945 138 if ( net().m_defaultIf == NULL )
RodColeman 0:850eacf3e945 139 return NULL;
RodColeman 0:850eacf3e945 140 NetUdpSocket* pNetUdpSocket = net().m_defaultIf->udpSocket();
RodColeman 0:850eacf3e945 141 pNetUdpSocket->m_refs++;
RodColeman 0:850eacf3e945 142 return pNetUdpSocket;
RodColeman 0:850eacf3e945 143 }
RodColeman 0:850eacf3e945 144
RodColeman 0:850eacf3e945 145 void Net::releaseUdpSocket(NetUdpSocket* pNetUdpSocket)
RodColeman 0:850eacf3e945 146 {
RodColeman 0:850eacf3e945 147 pNetUdpSocket->m_refs--;
RodColeman 0:850eacf3e945 148 if(!pNetUdpSocket->m_closed && !pNetUdpSocket->m_refs)
RodColeman 0:850eacf3e945 149 pNetUdpSocket->close();
RodColeman 0:850eacf3e945 150 }
RodColeman 0:850eacf3e945 151
RodColeman 0:850eacf3e945 152 NetDnsRequest* Net::dnsRequest(const char* hostname, NetIf& netif) {
RodColeman 0:850eacf3e945 153 return netif.dnsRequest(hostname);
RodColeman 0:850eacf3e945 154 }
RodColeman 0:850eacf3e945 155
RodColeman 0:850eacf3e945 156 NetDnsRequest* Net::dnsRequest(const char* hostname) { //Create a new NetDnsRequest object from default if
RodColeman 0:850eacf3e945 157 if ( net().m_defaultIf == NULL )
RodColeman 0:850eacf3e945 158 return NULL;
RodColeman 0:850eacf3e945 159 return net().m_defaultIf->dnsRequest(hostname);
RodColeman 0:850eacf3e945 160 }
RodColeman 0:850eacf3e945 161
RodColeman 0:850eacf3e945 162 NetDnsRequest* Net::dnsRequest(Host* pHost, NetIf& netif)
RodColeman 0:850eacf3e945 163 {
RodColeman 0:850eacf3e945 164 return netif.dnsRequest(pHost);
RodColeman 0:850eacf3e945 165 }
RodColeman 0:850eacf3e945 166
RodColeman 0:850eacf3e945 167 NetDnsRequest* Net::dnsRequest(Host* pHost) //Creats a new NetDnsRequest object from default if
RodColeman 0:850eacf3e945 168 {
RodColeman 0:850eacf3e945 169 if ( net().m_defaultIf == NULL )
RodColeman 0:850eacf3e945 170 return NULL;
RodColeman 0:850eacf3e945 171 return net().m_defaultIf->dnsRequest(pHost);
RodColeman 0:850eacf3e945 172 }
RodColeman 0:850eacf3e945 173
RodColeman 0:850eacf3e945 174 void Net::setDefaultIf(NetIf& netif) {
RodColeman 0:850eacf3e945 175 net().m_defaultIf = &netif;
RodColeman 0:850eacf3e945 176 }
RodColeman 0:850eacf3e945 177
RodColeman 0:850eacf3e945 178 void Net::setDefaultIf(NetIf* pIf)
RodColeman 0:850eacf3e945 179 {
RodColeman 0:850eacf3e945 180 net().m_defaultIf = pIf;
RodColeman 0:850eacf3e945 181 }
RodColeman 0:850eacf3e945 182
RodColeman 0:850eacf3e945 183 NetIf* Net::getDefaultIf() {
RodColeman 0:850eacf3e945 184 return net().m_defaultIf;
RodColeman 0:850eacf3e945 185 }
RodColeman 0:850eacf3e945 186
RodColeman 0:850eacf3e945 187 void Net::registerIf(NetIf* pIf)
RodColeman 0:850eacf3e945 188 {
RodColeman 0:850eacf3e945 189 net().m_lpIf.push_back(pIf);
RodColeman 0:850eacf3e945 190 }
RodColeman 0:850eacf3e945 191
RodColeman 0:850eacf3e945 192 void Net::unregisterIf(NetIf* pIf)
RodColeman 0:850eacf3e945 193 {
RodColeman 0:850eacf3e945 194 if( net().m_defaultIf == pIf )
RodColeman 0:850eacf3e945 195 net().m_defaultIf = NULL;
RodColeman 0:850eacf3e945 196 net().m_lpIf.remove(pIf);
RodColeman 0:850eacf3e945 197 }
RodColeman 0:850eacf3e945 198
RodColeman 0:850eacf3e945 199 void Net::registerNetTcpSocket(NetTcpSocket* pNetTcpSocket)
RodColeman 0:850eacf3e945 200 {
RodColeman 0:850eacf3e945 201 net().m_lpNetTcpSocket.push_back(pNetTcpSocket);
RodColeman 0:850eacf3e945 202 DBG("\r\nNetTcpSocket [ + %p ] %d\r\n", (void*)pNetTcpSocket, net().m_lpNetTcpSocket.size());
RodColeman 0:850eacf3e945 203 }
RodColeman 0:850eacf3e945 204
RodColeman 0:850eacf3e945 205 void Net::unregisterNetTcpSocket(NetTcpSocket* pNetTcpSocket)
RodColeman 0:850eacf3e945 206 {
RodColeman 0:850eacf3e945 207 DBG("\r\nNetTcpSocket [ - %p ] %d\r\n", (void*)pNetTcpSocket, net().m_lpNetTcpSocket.size() - 1);
RodColeman 0:850eacf3e945 208 if(!pNetTcpSocket->m_removed)
RodColeman 0:850eacf3e945 209 net().m_lpNetTcpSocket.remove(pNetTcpSocket);
RodColeman 0:850eacf3e945 210 }
RodColeman 0:850eacf3e945 211
RodColeman 0:850eacf3e945 212 void Net::registerNetUdpSocket(NetUdpSocket* pNetUdpSocket)
RodColeman 0:850eacf3e945 213 {
RodColeman 0:850eacf3e945 214 net().m_lpNetUdpSocket.push_back(pNetUdpSocket);
RodColeman 0:850eacf3e945 215 DBG("\r\nNetUdpSocket [ + %p ] %d\r\n", (void*)pNetUdpSocket, net().m_lpNetUdpSocket.size());
RodColeman 0:850eacf3e945 216 }
RodColeman 0:850eacf3e945 217
RodColeman 0:850eacf3e945 218 void Net::unregisterNetUdpSocket(NetUdpSocket* pNetUdpSocket)
RodColeman 0:850eacf3e945 219 {
RodColeman 0:850eacf3e945 220 DBG("\r\nNetUdpSocket [ - %p ] %d\r\n", (void*)pNetUdpSocket, net().m_lpNetUdpSocket.size() - 1);
RodColeman 0:850eacf3e945 221 if(!pNetUdpSocket->m_removed)
RodColeman 0:850eacf3e945 222 net().m_lpNetUdpSocket.remove(pNetUdpSocket);
RodColeman 0:850eacf3e945 223 }
RodColeman 0:850eacf3e945 224
RodColeman 0:850eacf3e945 225 Net& Net::net()
RodColeman 0:850eacf3e945 226 {
RodColeman 0:850eacf3e945 227 static Net* pInst = new Net(); //Called only once
RodColeman 0:850eacf3e945 228 return *pInst;
RodColeman 0:850eacf3e945 229 }