29 #include <openssl/md5.h>
40 EID::cbhe_map& EID::getApplicationMap()
42 static cbhe_map app_map;
45 if (app_map.empty()) {
47 app_map[
"debugger"] = 2;
48 app_map[
"bundle-in-bundle"] = 5;
50 app_map[
"routing"] = 50;
51 app_map[
"dtntp"] = 60;
74 else if (
"ipn" == s) {
82 void EID::extractCBHE(
const std::string &ssp,
Number &node,
Number &app)
84 char delimiter =
'\0';
89 std::stringstream ss(ssp);
95 if (delimiter ==
'.') {
103 void EID::extractDTN(
const std::string &ssp, std::string &node, std::string &application)
105 size_t first_char = 0;
106 const char delimiter =
'/';
109 first_char = ssp.find_first_not_of(delimiter);
112 if (first_char == std::string::npos) {
119 size_t application_start = ssp.find_first_of(delimiter, first_char);
122 if (application_start == std::string::npos) {
129 node = ssp.substr(0, application_start);
132 application = ssp.substr(application_start + 1, ssp.length() - application_start - 1);
138 if (app.empty())
return 0;
141 std::string::const_iterator char_it = app.begin();
142 while (char_it != app.end() && std::isdigit(*char_it)) ++char_it;
144 if (char_it == app.end()) {
149 std::stringstream ss(app);
156 const cbhe_map &m = getApplicationMap();
159 cbhe_map::const_iterator it = m.find(app);
169 std::vector<unsigned char> hash(MD5_DIGEST_LENGTH);
170 MD5((
unsigned char*)app.c_str(), app.length(), &hash[0]);
176 number |= 0x80000000;
185 : _scheme_type(SCHEME_DTN), _scheme(), _ssp(
"none"), _application(), _cbhe_node(0), _cbhe_application(0)
189 EID::EID(
const Scheme scheme_type,
const std::string &scheme,
const std::string &ssp,
const std::string &application)
190 : _scheme_type(scheme_type), _scheme(scheme), _ssp(ssp), _application(application), _cbhe_node(0), _cbhe_application(0)
197 EID::EID(
const std::string &scheme,
const std::string &ssp)
198 : _scheme_type(SCHEME_EXTENDED), _scheme(), _ssp(ssp), _application(), _cbhe_node(0), _cbhe_application(0)
203 switch (_scheme_type) {
206 extractCBHE(ssp, _cbhe_node, _cbhe_application);
207 if (_cbhe_node == 0) {
214 extractDTN(ssp, _ssp, _application);
224 : _scheme_type(SCHEME_DTN), _scheme(), _ssp(
"none"), _application(), _cbhe_node(0), _cbhe_application(0)
227 if (orig_value.length() == 0) {
231 std::string value = orig_value;
235 const size_t delimiter = value.find_first_of(
":");
238 if (delimiter == std::string::npos)
242 const std::string scheme = value.substr(0, delimiter);
245 const size_t startofssp = delimiter + 1;
246 const std::string ssp = value.substr(startofssp, value.length() - delimiter + 1);
249 if (scheme.length() == 0) {
253 if (ssp.length() == 0) {
260 switch (_scheme_type) {
263 extractCBHE(ssp, _cbhe_node, _cbhe_application);
268 extractDTN(ssp, _ssp, _application);
276 }
catch (
const std::exception&) {
283 : _scheme_type(SCHEME_CBHE), _scheme(), _ssp(), _application(), _cbhe_node(node), _cbhe_application(application)
298 if (_scheme_type != other._scheme_type)
return false;
300 switch (_scheme_type) {
302 return (_cbhe_node == other._cbhe_node) && (_cbhe_application == other._cbhe_application);
305 return (_ssp == other._ssp) && (_application == other._application);
308 return (_scheme == other._scheme) && (_ssp == other._ssp);
314 return ((*
this) ==
EID(other));
319 return !((*this) == other);
329 if (_scheme_type != other._scheme_type)
return false;
331 switch (_scheme_type) {
333 return _cbhe_node == other._cbhe_node;
336 return _ssp == other._ssp;
339 return (_scheme == other._scheme) && (_ssp == other._ssp);
345 if (_scheme_type < other._scheme_type)
return true;
346 if (_scheme_type != other._scheme_type)
return false;
348 switch (_scheme_type) {
350 if (_cbhe_node < other._cbhe_node)
return true;
351 if (_cbhe_node != other._cbhe_node)
return false;
353 return (_cbhe_application < other._cbhe_application);
356 if (_ssp < other._ssp)
return true;
357 if (_ssp != other._ssp)
return false;
359 return (_application < other._application);
362 if (_scheme < other._scheme)
return true;
363 if (_scheme != other._scheme)
return false;
365 return (_ssp < other._ssp);
371 return other < (*this);
376 std::stringstream ss;
378 switch (_scheme_type) {
382 if (_cbhe_application > 0) {
383 ss <<
"." << _cbhe_application.
get<
size_t>();
390 if (_application.length() > 0) {
391 ss <<
"/" << _application;
396 ss << _scheme <<
":" << _ssp;
405 switch (_scheme_type) {
407 _cbhe_application = app;
422 switch (_scheme_type) {
440 switch (_scheme_type) {
442 if (_cbhe_application > 0) {
443 return _cbhe_application.
toString();
457 if (_scheme_type != SCHEME_CBHE)
return false;
458 return (_cbhe_application == app);
463 switch (_scheme_type) {
465 return (_cbhe_application == getApplicationNumber(app));
468 return (_application == app);
471 return (app == _ssp);
477 switch (_scheme_type) {
489 switch (_scheme_type) {
501 switch (_scheme_type) {
504 std::stringstream ss;
505 ss << _cbhe_node.
get<
size_t>();
507 if (_cbhe_application > 0) {
508 ss <<
"." << _cbhe_application.
get<
size_t>();
515 if (_application.length() > 0) {
516 std::stringstream ss;
517 ss << _ssp <<
"/" << _application;
530 switch (_scheme_type) {
532 return EID(_cbhe_node, 0);
534 return EID(_scheme_type,
"", _ssp,
"");
536 return EID(_scheme_type, _scheme, _ssp,
"");
542 switch (_scheme_type) {
544 return (_cbhe_application > 0);
546 return _application !=
"";
559 return (_scheme_type ==
SCHEME_DTN) && (_ssp ==
"none");
575 return make_pair(_cbhe_node, _cbhe_application);
578 return make_pair(0, 0);