00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifdef HAVE_CONFIG_H
00018 # include <dtn-config.h>
00019 #endif
00020
00021 #include <ctype.h>
00022
00023 #include <oasys/debug/Log.h>
00024 #include <oasys/util/Glob.h>
00025
00026 #include "applib/dtn_types.h"
00027 #include "EndpointID.h"
00028 #include "Scheme.h"
00029 #include "SchemeTable.h"
00030 #include "bundling/BundleDaemon.h"
00031
00032 namespace dtn {
00033
00034
00035 EndpointID GlobalEndpointIDs::null_eid_;
00036 EndpointIDPattern GlobalEndpointIDs::wildcard_eid_;
00037
00038 EndpointID::singleton_info_t
00039 EndpointID::is_singleton_default_ = EndpointID::MULTINODE;
00040 bool EndpointID::glob_unknown_schemes_ = true;
00041
00042
00043 bool
00044 EndpointID::validate()
00045 {
00046 static const char* log = "/dtn/naming/endpoint/";
00047 (void)log;
00048
00049 scheme_ = NULL;
00050 valid_ = false;
00051
00052 if (!uri_.valid()) {
00053 log_debug_p(log, "EndpointID::validate: invalid URI");
00054 return false;
00055 }
00056
00057 if (scheme_str().length() > MAX_EID_PART_LENGTH) {
00058 log_err_p(log, "scheme name is too large (>%zu)", MAX_EID_PART_LENGTH);
00059 valid_ = false;
00060 return false;
00061 }
00062
00063 if (ssp().length() > MAX_EID_PART_LENGTH) {
00064 log_err_p(log, "ssp is too large (>%zu)", MAX_EID_PART_LENGTH);
00065 valid_ = false;
00066 return false;
00067 }
00068
00069 valid_ = true;
00070
00071 if ((scheme_ = SchemeTable::instance()->lookup(uri_.scheme())) != NULL) {
00072 valid_ = scheme_->validate(uri_, is_pattern_);
00073 }
00074
00075 return valid_;
00076 }
00077
00078
00079 bool
00080 EndpointID::append_service_tag(const char* tag)
00081 {
00082 if (!scheme_)
00083 return false;
00084
00085 bool ok = scheme_->append_service_tag(&uri_, tag);
00086 if (!ok)
00087 return false;
00088
00089
00090 if (!uri_.valid()) {
00091 log_err_p("/dtn/naming/endpoint/",
00092 "EndpointID::append_service_tag: "
00093 "failed to format appended URI");
00094
00095
00096
00097 return false;
00098 }
00099
00100 return true;
00101 }
00102
00103
00104 bool
00105 EndpointID::append_service_wildcard()
00106 {
00107 if (!scheme_)
00108 return false;
00109
00110 bool ok = scheme_->append_service_wildcard(&uri_);
00111 if (!ok)
00112 return false;
00113
00114
00115 if (!uri_.valid()) {
00116 log_err_p("/dtn/naming/endpoint/",
00117 "EndpointID::append_service_wildcard: "
00118 "failed to format appended URI");
00119
00120
00121
00122 return false;
00123 }
00124
00125 return true;
00126 }
00127
00128
00129 bool
00130 EndpointID::remove_service_tag()
00131 {
00132 if (! scheme_)
00133 return false;
00134
00135 bool ok = scheme_->remove_service_tag(&uri_);
00136 if (!ok)
00137 return false;
00138
00139
00140 if (!uri_.valid()) {
00141 log_err_p("/dtn/naming/endpoint/",
00142 "EndpointID::remove_service_tag: "
00143 "failed to format reduced URI");
00144
00145
00146 return false;
00147 }
00148
00149 return true;
00150 }
00151
00152
00153 EndpointID::singleton_info_t
00154 EndpointID::is_singleton() const
00155 {
00156 if (! known_scheme()) {
00157 singleton_info_t ret = is_singleton_default_;
00158 log_warn_p("/dtn/naming/endpoint/",
00159 "returning is_singleton=%s for unknown scheme %s",
00160 ret == SINGLETON ? "true" :
00161 ret == MULTINODE ? "false" :
00162 "unknown",
00163 scheme_str().c_str());
00164 return ret;
00165 }
00166 return scheme_->is_singleton(uri_);
00167 }
00168
00169
00170 bool
00171 EndpointID::assign(const dtn_endpoint_id_t* eid)
00172 {
00173 uri_.assign(std::string(eid->uri));
00174 return validate();
00175 }
00176
00177
00178 void
00179 EndpointID::copyto(dtn_endpoint_id_t* eid) const
00180 {
00181 ASSERT(uri_.uri().length() <= DTN_MAX_ENDPOINT_ID + 1);
00182 strcpy(eid->uri, uri_.uri().c_str());
00183 }
00184
00185
00186 void
00187 EndpointID::serialize(oasys::SerializeAction* a)
00188 {
00189 a->process("uri", &uri_);
00190 if (a->action_code() == oasys::Serialize::UNMARSHAL) {
00191 validate();
00192 }
00193 }
00194
00195
00196 bool
00197 EndpointIDPattern::match(const EndpointID& eid) const
00198 {
00199
00200 if (!uri_.valid()) {
00201 log_warn_p("/dtn/naming/endpoint",
00202 "match error: pattern '%s' not a valid uri",
00203 uri_.c_str());
00204 return false;
00205 }
00206
00207
00208 if (!eid.uri().valid()) {
00209 log_warn_p("/dtn/naming/endpoint",
00210 "match error: eid '%s' not a valid uri",
00211 eid.c_str());
00212 return false;
00213 }
00214
00215 if (known_scheme()) {
00216 return scheme()->match(*this, eid);
00217
00218 } else if (glob_unknown_schemes_) {
00219 return oasys::Glob::fixed_glob(uri_.c_str(), eid.c_str());
00220
00221 } else {
00222 return (*this == eid);
00223 }
00224
00225 }
00226
00227
00228 }