TcaEndpointID.cc

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2005-2006 University of Waterloo
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
00015  */
00016 
00017 
00018 
00019 #include "TcaEndpointID.h"
00020 #include "../../servlib/bundling/Bundle.h"
00021 
00022 
00023 namespace dtn {
00024 
00025 
00027 // class TcaEndpointID
00028 
00029 
00030 TcaEndpointID::TcaEndpointID(const std::string& str)
00031         : EndpointID(str), host_(""), app_("")
00032 {
00033     parse();
00034 }
00035 
00036 
00037 TcaEndpointID::TcaEndpointID(const std::string& host, const std::string& app)
00038         : EndpointID(), host_(host), app_(app)
00039 {
00040     assign(build(host, app));
00041 }
00042 
00043 
00044 TcaEndpointID::TcaEndpointID(const EndpointID& eid)
00045         : EndpointID(eid), host_(""), app_("")
00046 {
00047     parse();
00048 }
00049 
00050 
00051 TcaEndpointID::TcaEndpointID(const TcaEndpointID& eid)
00052         : EndpointID(eid), host_(eid.host_), app_(eid.app_)
00053 {
00054 }
00055 
00056 
00057 void
00058 TcaEndpointID::parse()
00059 {
00060     if (!valid_) return;
00061     if (scheme_str_ != "tca")
00062     {
00063         valid_ = false;
00064         return;
00065     }
00066     if (ssp_.length() <= 2)
00067     {
00068         valid_ = false;
00069         return;
00070     }
00071     if (ssp_.substr(0,2) != "//")
00072     {
00073         valid_ = false;
00074     }
00075     std::string nub = ssp_.substr(2, ssp_.length());
00076 
00077     int slash = nub.find("/");  // slash between host and app
00078     if (slash < 0) 
00079     {
00080         host_ = nub;    // if no slashes, assume the whole thing is host
00081         app_ = "";
00082         return;
00083     }
00084 
00085     host_ = nub.substr(0, slash);
00086     app_ = nub.substr(slash + 1, nub.length());
00087 }
00088 
00089 
00090 void
00091 TcaEndpointID::set_host(const std::string& host)
00092 {
00093     host_ = host;
00094     assign(build(host_, app_));
00095 }
00096     
00097 
00098 void
00099 TcaEndpointID::set_app(const std::string& app)
00100 {
00101     app_ = app;
00102     assign(build(host_, app_));
00103 }
00104 
00105 
00106 } // namespace dtn

Generated on Sat Sep 8 08:43:35 2007 for DTN Reference Implementation by  doxygen 1.5.3