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 
00021 
00023 // class TcaEndpointID
00024 
00025 
00026 TcaEndpointID::TcaEndpointID(const dtn_endpoint_id_t& eid)
00027         : valid_(false), host_(""), app_("")
00028 {
00029     parse(eid.uri);
00030 }
00031 
00032 
00033 TcaEndpointID::TcaEndpointID(const std::string& str)
00034         : valid_(false), host_(""), app_("")
00035 {
00036     parse(str);
00037 }
00038 
00039 
00040 TcaEndpointID::TcaEndpointID(const std::string& host, const std::string& app)
00041         : valid_(true), host_(host), app_(app)
00042 {
00043     // TODO: we should validate host and app
00044 }
00045 
00046 
00047 TcaEndpointID::TcaEndpointID(const TcaEndpointID& eid)
00048         : valid_(true), host_(eid.host_), app_(eid.app_)
00049 {
00050     // TODO: we should validate host and app
00051 }
00052 
00053 
00054 void
00055 TcaEndpointID::parse(const std::string& str)
00056 {
00057     // DK: We should use the dtn_parse_eid_string function here to check it
00058     // if (!valid_) return;
00059     if ((str.length() <= 6))
00060     {
00061         valid_ = false;
00062         return;
00063     }
00064     if (str.substr(0,6) != "tca://")
00065     {
00066         valid_ = false;
00067         return;
00068     }
00069 
00070     std::string nub = str.substr(6, str.length());
00071 
00072     int slash = nub.find("/");  // slash between host and app
00073     if (slash < 0) 
00074     {
00075         host_ = nub;    // if no slashes, assume the whole thing is host
00076         app_ = "";
00077         return;
00078     }
00079 
00080     host_ = nub.substr(0, slash);
00081     app_ = nub.substr(slash + 1, nub.length());
00082 }
00083 
00084 
00085 void
00086 TcaEndpointID::set_host(const std::string& host)
00087 {
00088     host_ = host;
00089 }
00090     
00091 
00092 void
00093 TcaEndpointID::set_app(const std::string& app)
00094 {
00095     app_ = app;
00096 }
00097 

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