25 #include <ibrcommon/net/socket.h>
26 #include <ibrcommon/data/File.h>
27 #include <ibrcommon/thread/SignalHandler.h>
38 ibrcommon::socketstream *
_conn = NULL;
52 cout <<
"-- dtntrigger (IBR-DTN) --" << endl;
53 cout <<
"Syntax: dtntrigger [options] <name> <shell> [trigger-script]" << endl;
54 cout <<
"<name> The application name" << endl;
55 cout <<
"<shell> Shell to execute the trigger script" << endl;
56 cout <<
"[trigger-script] The trigger script to execute on incoming bundle (optional)" << endl << endl;
57 cout <<
"* optional parameters *" << endl;
58 cout <<
" -h Display this text" << endl;
59 cout <<
" -g <group> Join a group" << endl;
60 cout <<
" -w Temporary work directory" << endl;
61 cout <<
" -s Process signed bundles only" << endl;
64 int init(
int argc,
char** argv)
71 while ((c = getopt (argc, argv,
"hw:g:s")) != -1)
79 group = std::string(optarg);
84 fprintf (stderr,
"Option -%c requires an argument.\n", optopt);
85 else if (isprint (optopt))
86 fprintf (stderr,
"Unknown option `-%c'.\n", optopt);
89 "Unknown option character `\\x%x'.\n",
103 for (index = optind; index < argc; ++index)
108 _appname = std::string(argv[index]);
112 _shell = std::string(argv[index]);
116 _script = std::string(argv[index]);
129 ibrcommon::BLOB::changeProvider(
new ibrcommon::FileBLOBProvider(
blob_path));
147 int main(
int argc,
char** argv)
150 ibrcommon::SignalHandler sighandler(
term);
151 sighandler.handle(SIGINT);
152 sighandler.handle(SIGTERM);
155 if (
init(argc, argv) > 0)
157 return (EXIT_FAILURE);
161 sighandler.initialize();
164 unsigned int backoff = 2;
171 ibrcommon::vaddress addr(
"localhost", 4550);
172 ibrcommon::socketstream conn(
new ibrcommon::tcpsocket(addr));
200 ibrcommon::TemporaryFile file(
blob_path,
"bundle");
204 std::fstream out(file.getPath().c_str(), ios::out|ios::binary|ios::trunc);
205 out.exceptions(std::ios::badbit | std::ios::eofbit);
206 out << ref.iostream()->rdbuf();
211 ::system(cmd.c_str());
215 }
catch (
const ios_base::failure&) {
228 }
catch (
const ibrcommon::socket_exception&) {
234 cout <<
"Connection to bundle daemon failed. Retry in " << backoff <<
" seconds." << endl;
235 ibrcommon::Thread::sleep(backoff * 1000);
241 backoff = backoff * 2;
244 }
catch (
const ibrcommon::IOException &ex) {
250 cout <<
"Connection to bundle daemon failed. Retry in " << backoff <<
" seconds." << endl;
251 ibrcommon::Thread::sleep(backoff * 1000);
257 backoff = backoff * 2;
260 }
catch (
const std::exception&) {
266 return (EXIT_SUCCESS);
ibrcommon::socketstream * _conn
int main(int argc, char **argv)
bool get(FLAGS flag) const
dtn::data::Bundle getBundle(const dtn::data::Timeout timeout=0)
int init(int argc, char **argv)
ibrcommon::File blob_path("/tmp")
std::string getString() const
iterator find(block_t blocktype)