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 "TcaEndpointID.h"
00022 #include "../../servlib/bundling/Bundle.h"
00023
00024
00025 namespace dtn {
00026
00027
00029
00030
00031
00032 TcaEndpointID::TcaEndpointID(const std::string& str)
00033 : EndpointID(str), host_(""), app_("")
00034 {
00035 parse();
00036 }
00037
00038
00039 TcaEndpointID::TcaEndpointID(const std::string& host, const std::string& app)
00040 : EndpointID(), host_(host), app_(app)
00041 {
00042 assign(build(host, app));
00043 }
00044
00045
00046 TcaEndpointID::TcaEndpointID(const EndpointID& eid)
00047 : EndpointID(eid), host_(""), app_("")
00048 {
00049 parse();
00050 }
00051
00052
00053 TcaEndpointID::TcaEndpointID(const TcaEndpointID& eid)
00054 : EndpointID(eid), host_(eid.host_), app_(eid.app_)
00055 {
00056 }
00057
00058
00059 void
00060 TcaEndpointID::parse()
00061 {
00062 if (!valid_) return;
00063 if (scheme_str() != "tca")
00064 {
00065 valid_ = false;
00066 return;
00067 }
00068 if (ssp().length() <= 2)
00069 {
00070 valid_ = false;
00071 return;
00072 }
00073 if (ssp().substr(0,2) != "//")
00074 {
00075 valid_ = false;
00076 }
00077 std::string nub = ssp().substr(2, ssp().length());
00078
00079 int slash = nub.find("/");
00080 if (slash < 0)
00081 {
00082 host_ = nub;
00083 app_ = "";
00084 return;
00085 }
00086
00087 host_ = nub.substr(0, slash);
00088 app_ = nub.substr(slash + 1, nub.length());
00089 }
00090
00091
00092 void
00093 TcaEndpointID::set_host(const std::string& host)
00094 {
00095 host_ = host;
00096 assign(build(host_, app_));
00097 }
00098
00099
00100 void
00101 TcaEndpointID::set_app(const std::string& app)
00102 {
00103 app_ = app;
00104 assign(build(host_, app_));
00105 }
00106
00107
00108 }