1 // RemoteXMLRequest.hxx -- xml http requests
3 // Written by James Turner
5 // Copyright (C) 2012 James Turner
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #ifndef REMOTEXMLREQUEST_HXXH
22 #define REMOTEXMLREQUEST_HXXH
24 #include <simgear/structure/exception.hxx>
25 #include <simgear/io/HTTPMemoryRequest.hxx>
26 #include <simgear/props/props_io.hxx>
28 class RemoteXMLRequest:
29 public simgear::HTTP::MemoryRequest
32 SGPropertyNode_ptr _complete;
33 SGPropertyNode_ptr _status;
34 SGPropertyNode_ptr _failed;
35 SGPropertyNode_ptr _target;
37 RemoteXMLRequest(const std::string& url, SGPropertyNode* targetNode) :
38 simgear::HTTP::MemoryRequest(url),
43 void setCompletionProp(SGPropertyNode_ptr p)
48 void setStatusProp(SGPropertyNode_ptr p)
53 void setFailedProp(SGPropertyNode_ptr p)
62 SG_LOG(SG_IO, SG_INFO, "network level failure in RemoteXMLRequest");
64 _failed->setBoolValue(true);
70 int response = responseCode();
72 if (response == 200) {
74 const char* buffer = responseBody().c_str();
75 readProperties(buffer, responseBody().size(), _target, true);
76 } catch (const sg_exception &e) {
77 SG_LOG(SG_IO, SG_WARN, "parsing XML from remote, failed: " << e.getFormattedMessage());
79 response = 406; // 'not acceptable', anything better?
84 // now the response data is output, signal Nasal / listeners
85 if (_complete) _complete->setBoolValue(true);
86 if (_status) _status->setIntValue(response);
87 if (_failed && failed) _failed->setBoolValue(true);
92 #endif //REMOTEXMLREQUEST_HXXH