apps/tca_admin/TcaEndpointID.cc
changeset 0 2b3e5ec03512
equal deleted inserted replaced
-1:000000000000 0:2b3e5ec03512
       
     1 /*
       
     2  *    Copyright 2005-2006 University of Waterloo
       
     3  * 
       
     4  *    Licensed under the Apache License, Version 2.0 (the "License");
       
     5  *    you may not use this file except in compliance with the License.
       
     6  *    You may obtain a copy of the License at
       
     7  * 
       
     8  *        http://www.apache.org/licenses/LICENSE-2.0
       
     9  * 
       
    10  *    Unless required by applicable law or agreed to in writing, software
       
    11  *    distributed under the License is distributed on an "AS IS" BASIS,
       
    12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    13  *    See the License for the specific language governing permissions and
       
    14  *    limitations under the License.
       
    15  */
       
    16 
       
    17 #ifdef HAVE_CONFIG_H
       
    18 #  include <dtn-config.h>
       
    19 #endif
       
    20 
       
    21 #include "TcaEndpointID.h"
       
    22 
       
    23 
       
    24 ///////////////////////////////////////////////////////////////////////////////
       
    25 // class TcaEndpointID
       
    26 
       
    27 
       
    28 TcaEndpointID::TcaEndpointID(const dtn_endpoint_id_t& eid)
       
    29         : valid_(false), host_(""), app_("")
       
    30 {
       
    31     parse(eid.uri);
       
    32 }
       
    33 
       
    34 
       
    35 TcaEndpointID::TcaEndpointID(const std::string& str)
       
    36         : valid_(false), host_(""), app_("")
       
    37 {
       
    38     parse(str);
       
    39 }
       
    40 
       
    41 
       
    42 TcaEndpointID::TcaEndpointID(const std::string& host, const std::string& app)
       
    43         : valid_(true), host_(host), app_(app)
       
    44 {
       
    45     // TODO: we should validate host and app
       
    46 }
       
    47 
       
    48 
       
    49 TcaEndpointID::TcaEndpointID(const TcaEndpointID& eid)
       
    50         : valid_(true), host_(eid.host_), app_(eid.app_)
       
    51 {
       
    52     // TODO: we should validate host and app
       
    53 }
       
    54 
       
    55 
       
    56 void
       
    57 TcaEndpointID::parse(const std::string& str)
       
    58 {
       
    59     // DK: We should use the dtn_parse_eid_string function here to check it
       
    60     // if (!valid_) return;
       
    61     if ((str.length() <= 6))
       
    62     {
       
    63         valid_ = false;
       
    64         return;
       
    65     }
       
    66     if (str.substr(0,6) != "tca://")
       
    67     {
       
    68         valid_ = false;
       
    69         return;
       
    70     }
       
    71 
       
    72     std::string nub = str.substr(6, str.length());
       
    73 
       
    74     int slash = nub.find("/");  // slash between host and app
       
    75     if (slash < 0) 
       
    76     {
       
    77         host_ = nub;    // if no slashes, assume the whole thing is host
       
    78         app_ = "";
       
    79         return;
       
    80     }
       
    81 
       
    82     host_ = nub.substr(0, slash);
       
    83     app_ = nub.substr(slash + 1, nub.length());
       
    84 }
       
    85 
       
    86 
       
    87 void
       
    88 TcaEndpointID::set_host(const std::string& host)
       
    89 {
       
    90     host_ = host;
       
    91 }
       
    92     
       
    93 
       
    94 void
       
    95 TcaEndpointID::set_app(const std::string& app)
       
    96 {
       
    97     app_ = app;
       
    98 }
       
    99