A simple web service over HTTP library. Calls a HTTP server via GET, and returns the response wrapped in a XML parser. All calls are synchronous. Needs the NetServicesMin, DNSResolver, TcpLineStream and spxml libraries. The code for URL handling has been copied directly from the original NetServices library (Thanks to Donatien!).

Committer:
hlipka
Date:
Tue Jan 11 23:00:09 2011 +0000
Revision:
0:5e8527b638e1
initial version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hlipka 0:5e8527b638e1 1
hlipka 0:5e8527b638e1 2 /*
hlipka 0:5e8527b638e1 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
hlipka 0:5e8527b638e1 4
hlipka 0:5e8527b638e1 5 Permission is hereby granted, free of charge, to any person obtaining a copy
hlipka 0:5e8527b638e1 6 of this software and associated documentation files (the "Software"), to deal
hlipka 0:5e8527b638e1 7 in the Software without restriction, including without limitation the rights
hlipka 0:5e8527b638e1 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
hlipka 0:5e8527b638e1 9 copies of the Software, and to permit persons to whom the Software is
hlipka 0:5e8527b638e1 10 furnished to do so, subject to the following conditions:
hlipka 0:5e8527b638e1 11
hlipka 0:5e8527b638e1 12 The above copyright notice and this permission notice shall be included in
hlipka 0:5e8527b638e1 13 all copies or substantial portions of the Software.
hlipka 0:5e8527b638e1 14
hlipka 0:5e8527b638e1 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
hlipka 0:5e8527b638e1 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
hlipka 0:5e8527b638e1 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
hlipka 0:5e8527b638e1 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
hlipka 0:5e8527b638e1 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
hlipka 0:5e8527b638e1 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
hlipka 0:5e8527b638e1 21 THE SOFTWARE.
hlipka 0:5e8527b638e1 22 */
hlipka 0:5e8527b638e1 23
hlipka 0:5e8527b638e1 24 #ifndef URL_H
hlipka 0:5e8527b638e1 25 #define URL_H
hlipka 0:5e8527b638e1 26
hlipka 0:5e8527b638e1 27 #include "core/ipaddr.h"
hlipka 0:5e8527b638e1 28
hlipka 0:5e8527b638e1 29 #include <string>
hlipka 0:5e8527b638e1 30 using std::string;
hlipka 0:5e8527b638e1 31
hlipka 0:5e8527b638e1 32 #include "mbed.h"
hlipka 0:5e8527b638e1 33
hlipka 0:5e8527b638e1 34 #ifdef __cplusplus
hlipka 0:5e8527b638e1 35 extern "C" {
hlipka 0:5e8527b638e1 36 #endif
hlipka 0:5e8527b638e1 37
hlipka 0:5e8527b638e1 38 char *url_encode(char *str);
hlipka 0:5e8527b638e1 39 char *url_decode(char *str);
hlipka 0:5e8527b638e1 40
hlipka 0:5e8527b638e1 41 #ifdef __cplusplus
hlipka 0:5e8527b638e1 42 }
hlipka 0:5e8527b638e1 43 #endif
hlipka 0:5e8527b638e1 44
hlipka 0:5e8527b638e1 45 class Url
hlipka 0:5e8527b638e1 46 {
hlipka 0:5e8527b638e1 47 public:
hlipka 0:5e8527b638e1 48 static string encode(const string& url)
hlipka 0:5e8527b638e1 49 {
hlipka 0:5e8527b638e1 50 char* c_res = url_encode( (char*) url.c_str() );
hlipka 0:5e8527b638e1 51 string res(c_res);
hlipka 0:5e8527b638e1 52 free(c_res); //Alloc'ed in url_encode()
hlipka 0:5e8527b638e1 53 return res;
hlipka 0:5e8527b638e1 54 }
hlipka 0:5e8527b638e1 55
hlipka 0:5e8527b638e1 56 static string decode(const string& url)
hlipka 0:5e8527b638e1 57 {
hlipka 0:5e8527b638e1 58 char* c_res = url_decode( (char*) url.c_str() );
hlipka 0:5e8527b638e1 59 string res(c_res);
hlipka 0:5e8527b638e1 60 free(c_res); //Alloc'ed in url_decode()
hlipka 0:5e8527b638e1 61 return res;
hlipka 0:5e8527b638e1 62 }
hlipka 0:5e8527b638e1 63
hlipka 0:5e8527b638e1 64 Url();
hlipka 0:5e8527b638e1 65
hlipka 0:5e8527b638e1 66 string getProtocol();
hlipka 0:5e8527b638e1 67 string getHost();
hlipka 0:5e8527b638e1 68 bool getHostIp(IpAddr* ip); //If host is in IP form, return true & proper object by ptr
hlipka 0:5e8527b638e1 69 uint16_t getPort();
hlipka 0:5e8527b638e1 70 string getPath();
hlipka 0:5e8527b638e1 71
hlipka 0:5e8527b638e1 72 void setProtocol(string protocol);
hlipka 0:5e8527b638e1 73 void setHost(string host);
hlipka 0:5e8527b638e1 74 void setPort(uint16_t port);
hlipka 0:5e8527b638e1 75 void setPath(string path);
hlipka 0:5e8527b638e1 76
hlipka 0:5e8527b638e1 77 void fromString(string str);
hlipka 0:5e8527b638e1 78 string toString();
hlipka 0:5e8527b638e1 79
hlipka 0:5e8527b638e1 80 private:
hlipka 0:5e8527b638e1 81 string m_protocol;
hlipka 0:5e8527b638e1 82 string m_host;
hlipka 0:5e8527b638e1 83 uint16_t m_port;
hlipka 0:5e8527b638e1 84 string m_path;
hlipka 0:5e8527b638e1 85
hlipka 0:5e8527b638e1 86 };
hlipka 0:5e8527b638e1 87
hlipka 0:5e8527b638e1 88 #endif /* LWIP_UTILS_H */