I have a problem getting this to work. Server only recieves half of the data being sent. Whats wrong

Dependencies:   mbed

Committer:
tax
Date:
Tue Mar 29 13:20:15 2011 +0000
Revision:
0:66300c77c6e9

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tax 0:66300c77c6e9 1
tax 0:66300c77c6e9 2 /*
tax 0:66300c77c6e9 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
tax 0:66300c77c6e9 4
tax 0:66300c77c6e9 5 Permission is hereby granted, free of charge, to any person obtaining a copy
tax 0:66300c77c6e9 6 of this software and associated documentation files (the "Software"), to deal
tax 0:66300c77c6e9 7 in the Software without restriction, including without limitation the rights
tax 0:66300c77c6e9 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
tax 0:66300c77c6e9 9 copies of the Software, and to permit persons to whom the Software is
tax 0:66300c77c6e9 10 furnished to do so, subject to the following conditions:
tax 0:66300c77c6e9 11
tax 0:66300c77c6e9 12 The above copyright notice and this permission notice shall be included in
tax 0:66300c77c6e9 13 all copies or substantial portions of the Software.
tax 0:66300c77c6e9 14
tax 0:66300c77c6e9 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
tax 0:66300c77c6e9 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
tax 0:66300c77c6e9 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
tax 0:66300c77c6e9 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
tax 0:66300c77c6e9 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
tax 0:66300c77c6e9 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
tax 0:66300c77c6e9 21 THE SOFTWARE.
tax 0:66300c77c6e9 22 */
tax 0:66300c77c6e9 23
tax 0:66300c77c6e9 24 #include "url.h"
tax 0:66300c77c6e9 25
tax 0:66300c77c6e9 26 Url::Url() : m_port(0)
tax 0:66300c77c6e9 27 {
tax 0:66300c77c6e9 28
tax 0:66300c77c6e9 29 }
tax 0:66300c77c6e9 30
tax 0:66300c77c6e9 31 string Url::getProtocol()
tax 0:66300c77c6e9 32 {
tax 0:66300c77c6e9 33 return m_protocol;
tax 0:66300c77c6e9 34 }
tax 0:66300c77c6e9 35
tax 0:66300c77c6e9 36 string Url::getHost()
tax 0:66300c77c6e9 37 {
tax 0:66300c77c6e9 38 return m_host;
tax 0:66300c77c6e9 39 }
tax 0:66300c77c6e9 40
tax 0:66300c77c6e9 41 bool Url::getHostIp(IpAddr* ip)
tax 0:66300c77c6e9 42 {
tax 0:66300c77c6e9 43 unsigned int ipArr[4] = {0};
tax 0:66300c77c6e9 44 if ( sscanf(m_host.c_str(), "%u.%u.%u.%u", &ipArr[0], &ipArr[1], &ipArr[2], &ipArr[3]) != 4 )
tax 0:66300c77c6e9 45 {
tax 0:66300c77c6e9 46 return false;
tax 0:66300c77c6e9 47 }
tax 0:66300c77c6e9 48 *ip = IpAddr(ipArr[0], ipArr[1], ipArr[2], ipArr[3]);
tax 0:66300c77c6e9 49 return true;
tax 0:66300c77c6e9 50 }
tax 0:66300c77c6e9 51
tax 0:66300c77c6e9 52 uint16_t Url::getPort()
tax 0:66300c77c6e9 53 {
tax 0:66300c77c6e9 54 return m_port;
tax 0:66300c77c6e9 55 }
tax 0:66300c77c6e9 56
tax 0:66300c77c6e9 57 string Url::getPath()
tax 0:66300c77c6e9 58 {
tax 0:66300c77c6e9 59 return m_path;
tax 0:66300c77c6e9 60 }
tax 0:66300c77c6e9 61
tax 0:66300c77c6e9 62 void Url::setProtocol(string protocol)
tax 0:66300c77c6e9 63 {
tax 0:66300c77c6e9 64 m_protocol = protocol;
tax 0:66300c77c6e9 65 }
tax 0:66300c77c6e9 66
tax 0:66300c77c6e9 67 void Url::setHost(string host)
tax 0:66300c77c6e9 68 {
tax 0:66300c77c6e9 69 m_host = host;
tax 0:66300c77c6e9 70 }
tax 0:66300c77c6e9 71
tax 0:66300c77c6e9 72 void Url::setPort(uint16_t port)
tax 0:66300c77c6e9 73 {
tax 0:66300c77c6e9 74 m_port = port;
tax 0:66300c77c6e9 75 }
tax 0:66300c77c6e9 76
tax 0:66300c77c6e9 77 void Url::setPath(string path)
tax 0:66300c77c6e9 78 {
tax 0:66300c77c6e9 79 m_path = path;
tax 0:66300c77c6e9 80 }
tax 0:66300c77c6e9 81
tax 0:66300c77c6e9 82 void Url::fromString(string str)
tax 0:66300c77c6e9 83 {
tax 0:66300c77c6e9 84 //URI form [protocol://]host[:port]/path
tax 0:66300c77c6e9 85 int pos = 0;
tax 0:66300c77c6e9 86 int len = str.find("://");
tax 0:66300c77c6e9 87 if( len > 0)
tax 0:66300c77c6e9 88 {
tax 0:66300c77c6e9 89 m_protocol = str.substr(0, len);
tax 0:66300c77c6e9 90 pos += len + 3;
tax 0:66300c77c6e9 91 }
tax 0:66300c77c6e9 92 else
tax 0:66300c77c6e9 93 {
tax 0:66300c77c6e9 94 m_protocol = "";
tax 0:66300c77c6e9 95 }
tax 0:66300c77c6e9 96
tax 0:66300c77c6e9 97 bool isPort = false;
tax 0:66300c77c6e9 98 int cln_pos = str.find(":", pos);
tax 0:66300c77c6e9 99 int slash_pos = str.find("/", pos);
tax 0:66300c77c6e9 100 if( slash_pos == -1 )
tax 0:66300c77c6e9 101 {
tax 0:66300c77c6e9 102 slash_pos = str.length();
tax 0:66300c77c6e9 103 }
tax 0:66300c77c6e9 104 if( (cln_pos != -1) && (cln_pos < slash_pos) )
tax 0:66300c77c6e9 105 {
tax 0:66300c77c6e9 106 isPort = true;
tax 0:66300c77c6e9 107 len = cln_pos - pos;
tax 0:66300c77c6e9 108 }
tax 0:66300c77c6e9 109 else
tax 0:66300c77c6e9 110 {
tax 0:66300c77c6e9 111 len = slash_pos - pos;
tax 0:66300c77c6e9 112 }
tax 0:66300c77c6e9 113
tax 0:66300c77c6e9 114 m_host = str.substr(pos, len);
tax 0:66300c77c6e9 115
tax 0:66300c77c6e9 116 pos += len;
tax 0:66300c77c6e9 117 if( isPort )
tax 0:66300c77c6e9 118 {
tax 0:66300c77c6e9 119 pos+=1; //Do not keep :
tax 0:66300c77c6e9 120 unsigned int port = 0;
tax 0:66300c77c6e9 121 sscanf(str.substr(pos, cln_pos-pos).c_str(),"%u", &port);
tax 0:66300c77c6e9 122 m_port = (uint16_t)port;
tax 0:66300c77c6e9 123 pos = slash_pos;
tax 0:66300c77c6e9 124 }
tax 0:66300c77c6e9 125
tax 0:66300c77c6e9 126 m_path = str.substr(pos);
tax 0:66300c77c6e9 127 }
tax 0:66300c77c6e9 128
tax 0:66300c77c6e9 129 string Url::toString()
tax 0:66300c77c6e9 130 {
tax 0:66300c77c6e9 131 string url;
tax 0:66300c77c6e9 132 if( !m_protocol.empty() )
tax 0:66300c77c6e9 133 {
tax 0:66300c77c6e9 134 url.append(m_protocol);
tax 0:66300c77c6e9 135 url.append("://");
tax 0:66300c77c6e9 136 }
tax 0:66300c77c6e9 137 url.append(m_host);
tax 0:66300c77c6e9 138 if( m_port )
tax 0:66300c77c6e9 139 {
tax 0:66300c77c6e9 140 char c_port[6] = {0};
tax 0:66300c77c6e9 141 sprintf(c_port, "%d", m_port);
tax 0:66300c77c6e9 142 url.append(":");
tax 0:66300c77c6e9 143 url.append(c_port);
tax 0:66300c77c6e9 144 }
tax 0:66300c77c6e9 145 if(m_path[0]!='/')
tax 0:66300c77c6e9 146 {
tax 0:66300c77c6e9 147 url.append("/");
tax 0:66300c77c6e9 148 }
tax 0:66300c77c6e9 149 url.append(m_path);
tax 0:66300c77c6e9 150 return url;
tax 0:66300c77c6e9 151 }