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:
Fri Feb 18 13:15:50 2011 +0000
Revision:
2:687430e7f63a
Parent:
1:62e112d14c8f
added license

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hlipka 2:687430e7f63a 1 /*
hlipka 2:687430e7f63a 2 * WebService library
hlipka 2:687430e7f63a 3 * Copyright (c) 2010 Hendrik Lipka
hlipka 2:687430e7f63a 4 *
hlipka 2:687430e7f63a 5 * Permission is hereby granted, free of charge, to any person obtaining a copy
hlipka 2:687430e7f63a 6 * of this software and associated documentation files (the "Software"), to deal
hlipka 2:687430e7f63a 7 * in the Software without restriction, including without limitation the rights
hlipka 2:687430e7f63a 8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
hlipka 2:687430e7f63a 9 * copies of the Software, and to permit persons to whom the Software is
hlipka 2:687430e7f63a 10 * furnished to do so, subject to the following conditions:
hlipka 2:687430e7f63a 11 *
hlipka 2:687430e7f63a 12 * The above copyright notice and this permission notice shall be included in
hlipka 2:687430e7f63a 13 * all copies or substantial portions of the Software.
hlipka 2:687430e7f63a 14 *
hlipka 2:687430e7f63a 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
hlipka 2:687430e7f63a 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
hlipka 2:687430e7f63a 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
hlipka 2:687430e7f63a 18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
hlipka 2:687430e7f63a 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
hlipka 2:687430e7f63a 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
hlipka 2:687430e7f63a 21 * THE SOFTWARE.
hlipka 2:687430e7f63a 22 */
hlipka 2:687430e7f63a 23
hlipka 1:62e112d14c8f 24 #ifndef __WEBSERVICE_H__
hlipka 1:62e112d14c8f 25 #define __WEBSERVICE_H__
hlipka 1:62e112d14c8f 26
hlipka 1:62e112d14c8f 27 #include "spdomparser.hpp"
hlipka 1:62e112d14c8f 28
hlipka 1:62e112d14c8f 29 #include "url.h"
hlipka 1:62e112d14c8f 30
hlipka 1:62e112d14c8f 31 #include "tcplinestream.h"
hlipka 1:62e112d14c8f 32
hlipka 1:62e112d14c8f 33 /**
hlipka 1:62e112d14c8f 34 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.
hlipka 1:62e112d14c8f 35 Needs the NetServicesMin and DNSResolver library
hlipka 1:62e112d14c8f 36 The code for URL handling has been copied directly from the original NetServices library (Thanks to Donatien!).
hlipka 1:62e112d14c8f 37
hlipka 1:62e112d14c8f 38 */
hlipka 1:62e112d14c8f 39 class WebService
hlipka 1:62e112d14c8f 40 {
hlipka 1:62e112d14c8f 41 public:
hlipka 1:62e112d14c8f 42 /**
hlipka 1:62e112d14c8f 43 create the web service instance.
hlipka 1:62e112d14c8f 44 @params urlStr the URL to call via GET
hlipka 1:62e112d14c8f 45 */
hlipka 1:62e112d14c8f 46 WebService(const char* urlStr);
hlipka 1:62e112d14c8f 47 /**
hlipka 1:62e112d14c8f 48 Execute the web service call. Note that the caller is responsible for freeing the return parser instance.
hlipka 1:62e112d14c8f 49 @return the XML parser, or NULL if an error occured
hlipka 1:62e112d14c8f 50 */
hlipka 1:62e112d14c8f 51 SP_XmlDomParser *callService();
hlipka 1:62e112d14c8f 52 /**
hlipka 1:62e112d14c8f 53 close all resources
hlipka 1:62e112d14c8f 54 */
hlipka 1:62e112d14c8f 55 ~WebService(){close();};
hlipka 1:62e112d14c8f 56 /**
hlipka 1:62e112d14c8f 57 close all resources
hlipka 1:62e112d14c8f 58 */
hlipka 1:62e112d14c8f 59 void close();
hlipka 1:62e112d14c8f 60
hlipka 1:62e112d14c8f 61 private:
hlipka 1:62e112d14c8f 62 void init();
hlipka 1:62e112d14c8f 63
hlipka 1:62e112d14c8f 64 string _request;
hlipka 1:62e112d14c8f 65
hlipka 1:62e112d14c8f 66 TCPLineStream *_stream;
hlipka 1:62e112d14c8f 67 };
hlipka 1:62e112d14c8f 68
hlipka 1:62e112d14c8f 69
hlipka 1:62e112d14c8f 70
hlipka 0:5e8527b638e1 71 #endif