37 #ifdef WITH_COMPRESSION
41 #ifdef WITH_BUNDLE_SECURITY
87 }
catch (
const std::exception&) { };
101 std::string::reverse_iterator iter = buffer.rbegin();
102 if ( (*iter) ==
'\r' ) buffer = buffer.substr(0, buffer.length() - 1);
105 if (cmd.empty())
continue;
112 if (cmd[1] ==
"endpoint")
130 _endpoint = new_endpoint;
134 else if (cmd[1] ==
"encoding")
158 else if (cmd[0] ==
"endpoint")
180 else if (cmd[1] ==
"del")
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")
528 else if (cmd[1] ==
"info")
536 else if (cmd[1] ==
"block")
548 istringstream ss(cmd[3]);
553 if (static_cast<dtn::data::Size>(offset) >= _bundle_reg.
size())
590 else if (cmd[2] ==
"del")
595 istringstream ss(cmd[3]);
601 std::advance(it, offset);
602 _bundle_reg.
erase(it);
619 else if (cmd[0] ==
"payload")
629 size_t cmd_index = 1;
632 std::stringstream ss(cmd[1]);
639 std::advance(block_it, block_offset);
649 if (block_it == _bundle_reg.
end()) {
656 size_t cmd_remaining = cmd.size() - (cmd_index + 1);
657 if (cmd[cmd_index] ==
"get")
665 if (cmd_remaining > 0)
667 size_t payload_offset = 0;
671 ss.clear(); ss.str(cmd[cmd_index+1]); ss >> payload_offset;
673 if (cmd_remaining > 1)
675 ss.clear(); ss.str(cmd[cmd_index+2]); ss >> length;
686 if (static_cast<std::streamsize>(payload_offset) >= stream.
size())
689 size_t remaining = stream.
size() - payload_offset;
691 if ((length > 0) && (remaining > length)) {
696 (*stream).ignore(payload_offset);
705 }
catch (
const std::bad_cast&) {
719 }
catch (
const std::exception &ex) {
723 else if (cmd[cmd_index] ==
"put")
734 size_t payload_offset = 0;
735 if (cmd_remaining > 0)
738 ss.clear(); ss.str(cmd[cmd_index+1]); ss >> payload_offset;
746 if (static_cast<std::streamsize>(payload_offset) < stream.
size()) {
748 (*stream).seekp(payload_offset, ios_base::beg);
749 }
else if (payload_offset > 0) {
751 (*stream).seekp(0, ios_base::end);
758 }
catch (std::bad_cast&) {
760 }
catch (
const std::exception&) {
764 else if (cmd[cmd_index] ==
"append")
780 (*stream).seekp(0, ios_base::end);
786 }
catch (std::bad_cast&) {
788 }
catch (
const std::exception&) {
792 else if (cmd[cmd_index] ==
"clear")
807 }
catch (std::bad_cast&) {
811 else if (cmd[cmd_index] ==
"length")
818 else if (cmd[0] ==
"nodename")
828 }
catch (
const std::exception&) {
840 ExtendedApiHandler::Sender::~Sender()
845 void ExtendedApiHandler::Sender::__cancellation() throw ()
848 _handler._client.getRegistration().abort();
851 void ExtendedApiHandler::Sender::finally() throw ()
855 void ExtendedApiHandler::Sender::run() throw ()
857 Registration ® = _handler._client.getRegistration();
859 while(_handler.good()){
865 _handler.notifyAdministrativeRecord(
id);
868 _handler._client.getRegistration().delivered(
id);
871 _handler.notifyBundle(
id);
874 reg.wait_for_bundle();
886 }
catch (
const std::exception &ex) {
901 _bundle_queue.
push(bundle);
927 report.
read(payload);
984 custody.
read(payload);
1027 stream <<
id.timestamp.toString() <<
" " <<
id.sequencenumber.toString() <<
" ";
1031 stream <<
id.offset.toString() <<
" ";
1034 stream <<
id.source.getString();
1037 dtn::data::BundleID ExtendedApiHandler::readBundleID(
const std::vector<std::string> &data,
const size_t start)
1040 std::stringstream ss;
1043 bool fragment =
false;
1046 if ((data.size() - start) < 3)
1052 ss.clear(); ss.str(data[start]);
1061 ss.clear(); ss.str(data[start+1]);
1062 sequencenumber.
read(ss);
1070 if ((data.size() - start) > 3)
1075 ss.clear(); ss.str(data[start+2]);