32 #include <ibrcommon/Logger.h>
34 #include <ibrcommon/link/LinkManager.h>
41 :
_client(client), _stream(stream)
49 : _srv(srv), _registration(®istration), _stream(conn), _endpoint(dtn::core::
BundleCore::local), _handler(NULL)
60 return *_registration;
70 _registration->
abort();
89 while (_stream->good())
105 getline(*_stream, buffer);
108 std::string::reverse_iterator iter = buffer.rbegin();
109 if ( (*iter) ==
'\r' ) buffer = buffer.substr(0, buffer.length() - 1);
112 if (cmd.empty())
continue;
115 if (cmd[0] ==
"protocol")
117 if (cmd.size() < 2)
throw ibrcommon::Exception(
"not enough parameters");
119 if (cmd[1] ==
"tcpcl")
125 else if (cmd[1] ==
"management")
131 else if (cmd[1] ==
"event")
137 else if (cmd[1] ==
"extended")
143 else if (cmd[1] ==
"streaming")
149 else if (cmd[1] ==
"p2p_extension")
151 if (cmd.size() < 3) {
156 if (cmd[2] ==
"wifi") {
160 }
else if (cmd[2] ==
"bt") {
179 }
catch (
const std::exception&) {
183 }
catch (
const ibrcommon::socket_exception &ex) {
184 IBRCOMMON_LOGGER_TAG(
"ClientHandler", error) << ex.what() << IBRCOMMON_LOGGER_ENDL;
188 void ClientHandler::error(STATUS_CODES code,
const std::string &msg)
190 ibrcommon::MutexLock l(_write_lock);
191 (*_stream) << code <<
" " << msg << std::endl;
202 IBRCOMMON_LOGGER_DEBUG_TAG(
"ClientHandler", 60) <<
"ApiConnection down" << IBRCOMMON_LOGGER_ENDL;
207 _registration->
abort();
214 void ClientHandler::processCommand(
const std::vector<std::string> &cmd)
226 virtual bool shouldAdd(
const dtn::data::MetaBundle&)
const throw (dtn::storage::BundleSelectorException)
235 if (cmd.size() < 2)
throw ibrcommon::Exception(
"not enough parameters");
237 if (cmd[1] ==
"endpoint")
239 if (cmd.size() < 3)
throw ibrcommon::Exception(
"not enough parameters");
241 ibrcommon::MutexLock l(_write_lock);
242 if (cmd[2].length() <= 0) {
261 ibrcommon::MutexLock l(_write_lock);
265 else if (cmd[0] ==
"registration")
267 if (cmd.size() < 2)
throw ibrcommon::Exception(
"not enough parameters");
271 if (cmd.size() < 3)
throw ibrcommon::Exception(
"not enough parameters");
273 ibrcommon::MutexLock l(_write_lock);
287 else if (cmd[1] ==
"del")
289 if (cmd.size() < 3)
throw ibrcommon::Exception(
"not enough parameters");
291 ibrcommon::MutexLock l(_write_lock);
305 else if (cmd[1] ==
"list")
307 ibrcommon::MutexLock l(_write_lock);
310 (*_stream) <<
API_STATUS_OK <<
" REGISTRATION LIST" << std::endl;
311 for (std::set<dtn::data::EID>::const_iterator iter = list.begin(); iter != list.end(); ++iter)
313 (*_stream) << (*iter).getString() << std::endl;
315 (*_stream) << std::endl;
319 ibrcommon::MutexLock l(_write_lock);
325 ibrcommon::MutexLock l(_write_lock);
328 }
catch (
const std::exception&) {
329 ibrcommon::MutexLock l(_write_lock);
void subscribe(const dtn::data::EID &endpoint)
void setApplication(const dtn::data::Number &app)
virtual void freeRegistration(Registration ®)=0
ApiServerInterface & getAPIServer()
dtn::api::Client * _client
Registration & getRegistration()
ProtocolHandler(ClientHandler &client, ibrcommon::socketstream &stream)
void unsubscribe(const dtn::data::EID &endpoint)
const std::set< dtn::data::EID > getSubscriptions()
void switchRegistration(Registration ®)
virtual void connectionUp(ClientHandler *conn)=0
virtual void connectionDown(ClientHandler *conn)=0
ClientHandler(ApiServerInterface &srv, Registration ®istration, ibrcommon::socketstream *conn)
static std::vector< std::string > tokenize(const std::string &token, const std::string &data, const std::string::size_type max=std::string::npos)
virtual ~ProtocolHandler()=0