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!).
webservice.h@0:5e8527b638e1, 2011-01-11 (annotated)
- Committer:
- hlipka
- Date:
- Tue Jan 11 23:00:09 2011 +0000
- Revision:
- 0:5e8527b638e1
- Child:
- 1:62e112d14c8f
initial version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hlipka | 0:5e8527b638e1 | 1 | #ifndef __WEBSERVICE_H__ |
hlipka | 0:5e8527b638e1 | 2 | #define __WEBSERVICE_H__ |
hlipka | 0:5e8527b638e1 | 3 | |
hlipka | 0:5e8527b638e1 | 4 | #include "spdomparser.hpp" |
hlipka | 0:5e8527b638e1 | 5 | |
hlipka | 0:5e8527b638e1 | 6 | #include "TCPSocket.h" |
hlipka | 0:5e8527b638e1 | 7 | |
hlipka | 0:5e8527b638e1 | 8 | #include "url.h" |
hlipka | 0:5e8527b638e1 | 9 | |
hlipka | 0:5e8527b638e1 | 10 | #define BUFSIZE 256 |
hlipka | 0:5e8527b638e1 | 11 | |
hlipka | 0:5e8527b638e1 | 12 | /** |
hlipka | 0:5e8527b638e1 | 13 | 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 | 0:5e8527b638e1 | 14 | Needs the NetServicesMin and DNSResolver library |
hlipka | 0:5e8527b638e1 | 15 | The code for URL handling has been copied directly from the original NetServices library (Thanks to Donatien!). |
hlipka | 0:5e8527b638e1 | 16 | |
hlipka | 0:5e8527b638e1 | 17 | */ |
hlipka | 0:5e8527b638e1 | 18 | class WebService |
hlipka | 0:5e8527b638e1 | 19 | { |
hlipka | 0:5e8527b638e1 | 20 | public: |
hlipka | 0:5e8527b638e1 | 21 | /** |
hlipka | 0:5e8527b638e1 | 22 | create the web service instance. |
hlipka | 0:5e8527b638e1 | 23 | @params url the URL to call via GET |
hlipka | 0:5e8527b638e1 | 24 | */ |
hlipka | 0:5e8527b638e1 | 25 | WebService(const char* url); |
hlipka | 0:5e8527b638e1 | 26 | /** |
hlipka | 0:5e8527b638e1 | 27 | Execute the web service call. Note that the caller is responsible for freeing the return parser instance. |
hlipka | 0:5e8527b638e1 | 28 | @return the XML parser, or NULL if an error occured |
hlipka | 0:5e8527b638e1 | 29 | */ |
hlipka | 0:5e8527b638e1 | 30 | SP_XmlDomParser *callService(); |
hlipka | 0:5e8527b638e1 | 31 | /** |
hlipka | 0:5e8527b638e1 | 32 | close all resources |
hlipka | 0:5e8527b638e1 | 33 | */ |
hlipka | 0:5e8527b638e1 | 34 | ~WebService(){close();}; |
hlipka | 0:5e8527b638e1 | 35 | /** |
hlipka | 0:5e8527b638e1 | 36 | close all resources |
hlipka | 0:5e8527b638e1 | 37 | */ |
hlipka | 0:5e8527b638e1 | 38 | void close(); |
hlipka | 0:5e8527b638e1 | 39 | |
hlipka | 0:5e8527b638e1 | 40 | private: |
hlipka | 0:5e8527b638e1 | 41 | void onTCPSocketEvent(TCPSocketEvent e); |
hlipka | 0:5e8527b638e1 | 42 | string readResponseLine(); |
hlipka | 0:5e8527b638e1 | 43 | |
hlipka | 0:5e8527b638e1 | 44 | const char* _url; |
hlipka | 0:5e8527b638e1 | 45 | bool _connecting; |
hlipka | 0:5e8527b638e1 | 46 | bool _connected; |
hlipka | 0:5e8527b638e1 | 47 | bool _closed; |
hlipka | 0:5e8527b638e1 | 48 | TCPSocket _socket; |
hlipka | 0:5e8527b638e1 | 49 | |
hlipka | 0:5e8527b638e1 | 50 | char _readbuf[BUFSIZE]; |
hlipka | 0:5e8527b638e1 | 51 | int _readpos; |
hlipka | 0:5e8527b638e1 | 52 | int _readlen; |
hlipka | 0:5e8527b638e1 | 53 | |
hlipka | 0:5e8527b638e1 | 54 | }; |
hlipka | 0:5e8527b638e1 | 55 | |
hlipka | 0:5e8527b638e1 | 56 | |
hlipka | 0:5e8527b638e1 | 57 | |
hlipka | 0:5e8527b638e1 | 58 | #endif |