| 96 | } |
| 97 | |
| 98 | int |
| 99 | URLparser::getPort(std::string &fullURL, int &port_ptr, int &port_len) |
| 100 | { |
| 101 | url_matcher matcher; |
| 102 | int n_port = -1; |
| 103 | int u_pos = -1; |
| 104 | |
| 105 | if (fullURL.find("https") == 0) { |
| 106 | u_pos = 8; |
| 107 | n_port = 443; |
| 108 | } else if (fullURL.find("http") == 0) { |
| 109 | u_pos = 7; |
| 110 | n_port = 80; |
| 111 | } |
| 112 | if (u_pos != -1) { |
| 113 | fullURL.insert(u_pos, ":@"); |
| 114 | swoc::TextView url(fullURL.data(), static_cast<int>(fullURL.size())); |
| 115 | |
| 116 | url += 9; |
| 117 | |
| 118 | swoc::TextView hostPort = url.take_prefix_at(':'); |
| 119 | if (!hostPort.empty()) // i.e. port is present |
| 120 | { |
| 121 | swoc::TextView port = url.take_prefix_at('/'); |
| 122 | if (port.empty()) { // i.e. backslash is not present, then the rest of the url must be just port |
| 123 | port = url; |
| 124 | } |
| 125 | if (matcher.portmatch(port.data(), port.size())) { |
| 126 | swoc::TextView text; |
| 127 | n_port = svtoi(port, &text); |
| 128 | if (text == port) { |
| 129 | port_ptr = fullURL.find(':', 9); |
| 130 | port_len = port.size(); |
| 131 | return n_port; |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | return n_port; |
| 136 | } else { |
| 137 | std::cout << "No scheme provided for: " << fullURL << std::endl; |
| 138 | return -1; |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | uint32_t |
| 143 | Doc::prefix_len() |