OLD | NEW |
(Empty) | |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2013 University of New Brunswick |
| 4 * |
| 5 * This program is free software; you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 2 as |
| 7 * published by the Free Software Foundation; |
| 8 * |
| 9 * This program is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * You should have received a copy of the GNU General Public License |
| 15 * along with this program; if not, write to the Free Software |
| 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 * |
| 18 * Author: Dizhi Zhou <dizhi.zhou@gmail.com> |
| 19 */ |
| 20 |
| 21 #include<string> |
| 22 #include "ns3/log.h" |
| 23 #include "ns3/names.h" |
| 24 #include "bp-endpoint-id.h" |
| 25 |
| 26 NS_LOG_COMPONENT_DEFINE ("BpEndpointId");· |
| 27 |
| 28 namespace ns3 { |
| 29 |
| 30 |
| 31 BpEndpointId::BpEndpointId (const std::string scheme, const std::string ssp) |
| 32 : m_uri ("") |
| 33 { |
| 34 ParseComponent (scheme, ssp); |
| 35 m_uri = scheme + ":" + ssp; |
| 36 } |
| 37 |
| 38 BpEndpointId::BpEndpointId (const std::string uri) |
| 39 : m_uri ("") |
| 40 { |
| 41 ParseUri (uri); |
| 42 m_uri = uri; |
| 43 } |
| 44 |
| 45 void· |
| 46 BpEndpointId::ParseComponent (const std::string &scheme, const std::string &ssp) |
| 47 { |
| 48 std::string schemeStr = scheme; |
| 49 std::string sspStr = ssp; |
| 50 |
| 51 size_t schemeLen = schemeStr.length (); |
| 52 size_t sspLen = sspStr.length (); |
| 53 |
| 54 if (schemeLen == 0 || sspLen == 0) |
| 55 { |
| 56 NS_LOG_WARN ("BpEndpointId::BuildUri (), both scheme and ssp cannot be emp
ty"); |
| 57 schemeStr = "dtn"; |
| 58 sspStr = "none"; |
| 59 schemeLen = schemeStr.length (); |
| 60 sspLen = sspStr.length (); |
| 61 } |
| 62 |
| 63 // section 4.4 of RFC 5050 |
| 64 if (schemeLen * sizeof (schemeStr.at (0)) > 1023 / sizeof (char) ||· |
| 65 sspLen * sizeof (sspStr.at (0)) > 1023 / sizeof (char) ) |
| 66 { |
| 67 NS_LOG_WARN ("BpEndpointId::BuildUri (), both scheme and ssp lengths canno
t exceed 1023 bytes"); |
| 68 schemeStr = schemeStr.substr (0, 1023); |
| 69 sspStr = sspStr.substr (0,1023); |
| 70 schemeLen = schemeStr.length (); |
| 71 sspLen = sspStr.length (); |
| 72 } |
| 73 |
| 74 // build URI |
| 75 m_scheme.offset = 0; |
| 76 m_scheme.length = schemeLen; |
| 77 m_ssp.offset = schemeLen + 1;· |
| 78 m_ssp.length = m_uri.length () - m_ssp.offset; |
| 79 |
| 80 } |
| 81 |
| 82 void· |
| 83 BpEndpointId::ParseUri (const std::string uri) |
| 84 { |
| 85 std::string uriStr = uri; |
| 86 size_t uriLen = uriStr.length (); |
| 87 |
| 88 if (uriLen == 0) |
| 89 { |
| 90 NS_LOG_WARN ("BpEndpointId::BuildUri (), uri cannot be empty"); |
| 91 uriStr = "dtn:none"; |
| 92 uriLen = uriStr.length (); |
| 93 } |
| 94 |
| 95 size_t semicolon_pos = 0;· |
| 96 if((semicolon_pos = uri.find(':')) == std::string::npos) |
| 97 { |
| 98 NS_LOG_WARN ("BpEndpointId::BuildUri (), uri must include semicolon ':'"); |
| 99 uriStr = "dtn:none"; |
| 100 uriLen = uriStr.length (); |
| 101 } |
| 102 |
| 103 std::string scheme = uriStr.substr(0, semicolon_pos); |
| 104 std::string ssp = uriStr.substr(semicolon_pos, uriLen - semicolon_pos); |
| 105 |
| 106 ParseComponent (scheme, ssp); |
| 107 } |
| 108 |
| 109 std::string |
| 110 BpEndpointId::Scheme () const |
| 111 { |
| 112 return m_uri.substr(m_scheme.offset, m_scheme.length); |
| 113 } |
| 114 |
| 115 std::string |
| 116 BpEndpointId::Ssp () const |
| 117 { |
| 118 return m_uri.substr(m_ssp.offset, m_ssp.length); |
| 119 } |
| 120 |
| 121 std::string· |
| 122 BpEndpointId::Uri () const |
| 123 { |
| 124 return m_uri; |
| 125 } |
| 126 |
| 127 } // namespace ns3 |
OLD | NEW |