00001 /* 00002 * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By 00003 * downloading, copying, installing or using the software you agree to 00004 * this license. If you do not agree to this license, do not download, 00005 * install, copy or use the software. 00006 * 00007 * University of Waterloo Open Source License 00008 * 00009 * Copyright (c) 2005 University of Waterloo. All rights reserved. 00010 * 00011 * Redistribution and use in source and binary forms, with or without 00012 * modification, are permitted provided that the following conditions are 00013 * met: 00014 * 00015 * Redistributions of source code must retain the above copyright 00016 * notice, this list of conditions and the following disclaimer. 00017 * 00018 * Redistributions in binary form must reproduce the above copyright 00019 * notice, this list of conditions and the following disclaimer in the 00020 * documentation and/or other materials provided with the distribution. 00021 * 00022 * Neither the name of the University of Waterloo nor the names of its 00023 * contributors may be used to endorse or promote products derived from 00024 * this software without specific prior written permission. 00025 * 00026 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00027 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00028 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00029 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY 00030 * OF WATERLOO OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00031 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00032 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 00033 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00034 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 00035 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00036 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00037 */ 00038 00039 00040 #include "TcaEndpointID.h" 00041 #include "../../servlib/bundling/Bundle.h" 00042 00043 00044 namespace dtn { 00045 00046 00048 // class TcaEndpointID 00049 00050 00051 TcaEndpointID::TcaEndpointID(const std::string& str) 00052 : EndpointID(str), host_(""), app_("") 00053 { 00054 parse(); 00055 } 00056 00057 00058 TcaEndpointID::TcaEndpointID(const std::string& host, const std::string& app) 00059 : EndpointID(), host_(host), app_(app) 00060 { 00061 assign(build(host, app)); 00062 } 00063 00064 00065 TcaEndpointID::TcaEndpointID(const EndpointID& eid) 00066 : EndpointID(eid), host_(""), app_("") 00067 { 00068 parse(); 00069 } 00070 00071 00072 TcaEndpointID::TcaEndpointID(const TcaEndpointID& eid) 00073 : EndpointID(eid), host_(eid.host_), app_(eid.app_) 00074 { 00075 } 00076 00077 00078 void 00079 TcaEndpointID::parse() 00080 { 00081 if (!valid_) return; 00082 if (scheme_str_ != "tca") 00083 { 00084 valid_ = false; 00085 return; 00086 } 00087 if (ssp_.length() <= 2) 00088 { 00089 valid_ = false; 00090 return; 00091 } 00092 if (ssp_.substr(0,2) != "//") 00093 { 00094 valid_ = false; 00095 } 00096 std::string nub = ssp_.substr(2, ssp_.length()); 00097 00098 int slash = nub.find("/"); // slash between host and app 00099 if (slash < 0) 00100 { 00101 host_ = nub; // if no slashes, assume the whole thing is host 00102 app_ = ""; 00103 return; 00104 } 00105 00106 host_ = nub.substr(0, slash); 00107 app_ = nub.substr(slash + 1, nub.length()); 00108 } 00109 00110 00111 void 00112 TcaEndpointID::set_host(const std::string& host) 00113 { 00114 host_ = host; 00115 assign(build(host_, app_)); 00116 } 00117 00118 00119 void 00120 TcaEndpointID::set_app(const std::string& app) 00121 { 00122 app_ = app; 00123 assign(build(host_, app_)); 00124 } 00125 00126 00127 } // namespace dtn