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
23 #include <simgear/structure/exception.hxx>
24 #include <simgear/io/HTTPMemoryRequest.hxx>
25 class RemoteXMLRequest:
26 public simgear::HTTP::MemoryRequest
29 SGPropertyNode_ptr _complete;
30 SGPropertyNode_ptr _status;
31 SGPropertyNode_ptr _failed;
32 SGPropertyNode_ptr _target;
34 RemoteXMLRequest(const std::string& url, SGPropertyNode* targetNode) :
35 simgear::HTTP::MemoryRequest(url),
40 void setCompletionProp(SGPropertyNode_ptr p)
45 void setStatusProp(SGPropertyNode_ptr p)
50 void setFailedProp(SGPropertyNode_ptr p)
59 SG_LOG(SG_IO, SG_INFO, "network level failure in RemoteXMLRequest");
61 _failed->setBoolValue(true);
67 int response = responseCode();
69 if (response == 200) {
71 const char* buffer = responseBody().c_str();
72 readProperties(buffer, responseBody().size(), _target, true);
73 } catch (const sg_exception &e) {
74 SG_LOG(SG_IO, SG_WARN, "parsing XML from remote, failed: " << e.getFormattedMessage());
76 response = 406; // 'not acceptable', anything better?
81 // now the response data is output, signal Nasal / listeners
82 if (_complete) _complete->setBoolValue(true);
83 if (_status) _status->setIntValue(response);
84 if (_failed && failed) _failed->setBoolValue(true);
89 #endif //REMOTEXMLREQUEST_HXXH