37 #ifdef WITH_BUNDLE_SECURITY
83 }
catch (
const std::exception&) { };
97 std::string::reverse_iterator iter = buffer.rbegin();
98 if ( (*iter) ==
'\r' ) buffer = buffer.substr(0, buffer.length() - 1);
101 if (cmd.empty())
continue;
108 if (cmd[1] ==
"endpoint")
113 if (cmd[2].length() <= 0) {
132 else if (cmd[1] ==
"encoding")
156 else if (cmd[0] ==
"endpoint")
167 if (cmd[2].length() <= 0)
180 else if (cmd[1] ==
"del")
187 if (cmd[2].length() <= 0)
199 if(_endpoint == del_endpoint)
208 else if (cmd[1] ==
"get")
219 else if (cmd[0] ==
"registration")
241 else if (cmd[1] ==
"del")
256 if(_endpoint == endpoint)
265 else if (cmd[1] ==
"list")
271 for (std::set<dtn::data::EID>::const_iterator iter = list.begin(); iter != list.end(); ++iter)
273 _stream << (*iter).getString() << std::endl;
277 else if (cmd[1] ==
"save")
282 std::stringstream ss(cmd[2]);
293 else if (cmd[1] ==
"load")
297 const std::string handle = cmd[2];
311 Sender *old_sender = _sender;
313 _sender =
new Sender(*
this);
315 catch (
const std::bad_alloc &ex)
317 _sender = old_sender;
343 else if (cmd[0] ==
"neighbor")
347 if (cmd[1] ==
"list")
353 for (std::set<dtn::core::Node>::const_iterator iter = nlist.begin(); iter != nlist.end(); ++iter)
355 _stream << (*iter).getEID().getString() << std::endl;
365 else if (cmd[0] ==
"bundle")
379 else if (cmd[2] ==
"binary")
384 else if (cmd[2] ==
"plain")
389 else if (cmd[2] ==
"xml")
398 else if (cmd[1] ==
"put")
407 else if (cmd[2] ==
"plain")
414 }
catch (
const std::exception &ex) {
420 else if (cmd[2] ==
"binary")
427 }
catch (
const std::exception &ex) {
437 else if (cmd[1] ==
"load")
443 if (cmd[2] ==
"queue")
450 id = readBundleID(cmd, 2);
467 else if (cmd[1] ==
"clear")
474 else if (cmd[1] ==
"free")
486 else if (cmd[1] ==
"delivered")
505 else if (cmd[1] ==
"store")
517 else if (cmd[1] ==
"send")
525 else if (cmd[1] ==
"info")
533 else if (cmd[1] ==
"block")
545 istringstream ss(cmd[3]);
550 if (static_cast<dtn::data::Size>(offset) >= _bundle_reg.
size())
587 else if (cmd[2] ==
"del")
592 istringstream ss(cmd[3]);
598 std::advance(it, offset);
599 _bundle_reg.
erase(it);
616 else if (cmd[0] ==
"payload")
626 size_t cmd_index = 1;
629 std::stringstream ss(cmd[1]);
636 std::advance(block_it, block_offset);
646 if (block_it == _bundle_reg.
end()) {
653 size_t cmd_remaining = cmd.size() - (cmd_index + 1);
654 if (cmd[cmd_index] ==
"get")
662 if (cmd_remaining > 0)
664 size_t payload_offset = 0;
668 ss.clear(); ss.str(cmd[cmd_index+1]); ss >> payload_offset;
670 if (cmd_remaining > 1)
672 ss.clear(); ss.str(cmd[cmd_index+2]); ss >> length;
683 if (static_cast<std::streamsize>(payload_offset) >= stream.
size())
686 size_t remaining = stream.
size() - payload_offset;
688 if ((length > 0) && (remaining > length)) {
693 (*stream).ignore(payload_offset);
702 }
catch (
const std::bad_cast&) {
716 }
catch (
const std::exception &ex) {
720 else if (cmd[cmd_index] ==
"put")
731 size_t payload_offset = 0;
732 if (cmd_remaining > 0)
735 ss.clear(); ss.str(cmd[cmd_index+1]); ss >> payload_offset;
743 if (static_cast<std::streamsize>(payload_offset) < stream.
size()) {
745 (*stream).seekp(payload_offset, ios_base::beg);
746 }
else if (payload_offset > 0) {
748 (*stream).seekp(0, ios_base::end);
755 }
catch (std::bad_cast&) {
757 }
catch (
const std::exception&) {
761 else if (cmd[cmd_index] ==
"append")
777 (*stream).seekp(0, ios_base::end);
783 }
catch (std::bad_cast&) {
785 }
catch (
const std::exception&) {
789 else if (cmd[cmd_index] ==
"clear")
804 }
catch (std::bad_cast&) {
808 else if (cmd[cmd_index] ==
"length")
815 else if (cmd[0] ==
"nodename")
825 }
catch (
const std::exception&) {
837 ExtendedApiHandler::Sender::~Sender()
842 void ExtendedApiHandler::Sender::__cancellation() throw ()
845 _handler._client.getRegistration().abort();
848 void ExtendedApiHandler::Sender::finally() throw ()
852 void ExtendedApiHandler::Sender::run() throw ()
854 Registration ® = _handler._client.getRegistration();
856 while(_handler.good()){
862 _handler.notifyAdministrativeRecord(
id);
865 _handler._client.getRegistration().delivered(
id);
868 _handler.notifyBundle(
id);
871 reg.wait_for_bundle();
883 }
catch (
const std::exception &ex) {
898 _bundle_queue.
push(bundle);
924 report.
read(payload);
981 custody.
read(payload);
1024 stream <<
id.timestamp.toString() <<
" " <<
id.sequencenumber.toString() <<
" ";
1026 if (
id.isFragment())
1028 stream <<
id.fragmentoffset.toString() <<
" ";
1029 stream <<
id.getPayloadLength() <<
" ";
1032 stream <<
id.source.getString();
1035 dtn::data::BundleID ExtendedApiHandler::readBundleID(
const std::vector<std::string> &data,
const size_t start)
1038 std::stringstream ss;
1041 if ((data.size() - start) < 3)
1047 ss.clear(); ss.str(data[start]);
1048 id.timestamp.read(ss);
1056 ss.clear(); ss.str(data[start+1]);
1057 id.sequencenumber.read(ss);
1065 if ((data.size() - start) > 3)
1067 id.setFragment(
true);
1070 ss.clear(); ss.str(data[start+2]);
1071 id.fragmentoffset.read(ss);
1074 ss.clear(); ss.str(data[start+3]);
1077 id.setPayloadLength(len);