mirror of
				https://github.com/Telecominfraproject/wlan-cloud-lib-poco.git
				synced 2025-11-03 20:18:01 +00:00 
			
		
		
		
	#2818: Add getSpecifiedPort() method to URI
This commit is contained in:
		@@ -154,6 +154,12 @@ public:
 | 
				
			|||||||
	void setPort(unsigned short port);
 | 
						void setPort(unsigned short port);
 | 
				
			||||||
		/// Sets the port number part of the URI.
 | 
							/// Sets the port number part of the URI.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						unsigned short getSpecifiedPort() const;
 | 
				
			||||||
 | 
							/// Returns the port number part of the URI.
 | 
				
			||||||
 | 
							///
 | 
				
			||||||
 | 
							/// If no explicit port number has been specified,
 | 
				
			||||||
 | 
							/// returns 0.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	std::string getAuthority() const;
 | 
						std::string getAuthority() const;
 | 
				
			||||||
		/// Returns the authority part (userInfo, host and port)
 | 
							/// Returns the authority part (userInfo, host and port)
 | 
				
			||||||
		/// of the URI.
 | 
							/// of the URI.
 | 
				
			||||||
@@ -400,6 +406,12 @@ inline const std::string& URI::getFragment() const
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					inline unsigned short URI::getSpecifiedPort() const
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return _port;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
inline void swap(URI& u1, URI& u2)
 | 
					inline void swap(URI& u1, URI& u2)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	u1.swap(u2);
 | 
						u1.swap(u2);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -55,7 +55,6 @@ URI::URI(const std::string& scheme, const std::string& pathEtc):
 | 
				
			|||||||
	_port(0)
 | 
						_port(0)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	toLowerInPlace(_scheme);
 | 
						toLowerInPlace(_scheme);
 | 
				
			||||||
	_port = getWellKnownPort();
 | 
					 | 
				
			||||||
	std::string::const_iterator beg = pathEtc.begin();
 | 
						std::string::const_iterator beg = pathEtc.begin();
 | 
				
			||||||
	std::string::const_iterator end = pathEtc.end();
 | 
						std::string::const_iterator end = pathEtc.end();
 | 
				
			||||||
	parsePathEtc(beg, end);
 | 
						parsePathEtc(beg, end);
 | 
				
			||||||
@@ -268,8 +267,6 @@ void URI::setScheme(const std::string& scheme)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	_scheme = scheme;
 | 
						_scheme = scheme;
 | 
				
			||||||
	toLowerInPlace(_scheme);
 | 
						toLowerInPlace(_scheme);
 | 
				
			||||||
	if (_port == 0)
 | 
					 | 
				
			||||||
		_port = getWellKnownPort();
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -842,9 +839,9 @@ void URI::parseHostAndPort(std::string::const_iterator& it, const std::string::c
 | 
				
			|||||||
			else
 | 
								else
 | 
				
			||||||
				throw URISyntaxException("bad or invalid port number", port);
 | 
									throw URISyntaxException("bad or invalid port number", port);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		else _port = getWellKnownPort();
 | 
							else _port = 0;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	else _port = getWellKnownPort();
 | 
						else _port = 0;
 | 
				
			||||||
	_host = host;
 | 
						_host = host;
 | 
				
			||||||
	toLowerInPlace(_host);
 | 
						toLowerInPlace(_host);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -51,11 +51,13 @@ void URITest::testConstruction()
 | 
				
			|||||||
	uri.setAuthority("www.appinf.com");
 | 
						uri.setAuthority("www.appinf.com");
 | 
				
			||||||
	assertTrue (uri.getAuthority() == "www.appinf.com");
 | 
						assertTrue (uri.getAuthority() == "www.appinf.com");
 | 
				
			||||||
	assertTrue (uri.getPort() == 80);
 | 
						assertTrue (uri.getPort() == 80);
 | 
				
			||||||
 | 
						assertTrue (uri.getSpecifiedPort() == 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	uri.setAuthority("user@services.appinf.com:8000");
 | 
						uri.setAuthority("user@services.appinf.com:8000");
 | 
				
			||||||
	assertTrue (uri.getUserInfo() == "user");
 | 
						assertTrue (uri.getUserInfo() == "user");
 | 
				
			||||||
	assertTrue (uri.getHost() == "services.appinf.com");
 | 
						assertTrue (uri.getHost() == "services.appinf.com");
 | 
				
			||||||
	assertTrue (uri.getPort() == 8000);
 | 
						assertTrue (uri.getPort() == 8000);
 | 
				
			||||||
 | 
						assertTrue (uri.getSpecifiedPort() == 8000);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	uri.setPath("/index.html");
 | 
						uri.setPath("/index.html");
 | 
				
			||||||
	assertTrue (uri.getPath() == "/index.html");
 | 
						assertTrue (uri.getPath() == "/index.html");
 | 
				
			||||||
@@ -110,6 +112,7 @@ void URITest::testConstruction()
 | 
				
			|||||||
	assertTrue (uri6.getUserInfo() == "user");
 | 
						assertTrue (uri6.getUserInfo() == "user");
 | 
				
			||||||
	assertTrue (uri6.getHost() == "www.appinf.com");
 | 
						assertTrue (uri6.getHost() == "www.appinf.com");
 | 
				
			||||||
	assertTrue (uri6.getPort() == 80);
 | 
						assertTrue (uri6.getPort() == 80);
 | 
				
			||||||
 | 
						assertTrue (uri6.getSpecifiedPort() == 80);
 | 
				
			||||||
	assertTrue (uri6.getAuthority() == "user@www.appinf.com");
 | 
						assertTrue (uri6.getAuthority() == "user@www.appinf.com");
 | 
				
			||||||
	assertTrue (uri6.getPath() == "/index.html");
 | 
						assertTrue (uri6.getPath() == "/index.html");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -118,6 +121,7 @@ void URITest::testConstruction()
 | 
				
			|||||||
	assertTrue (uri7.getUserInfo() == "user");
 | 
						assertTrue (uri7.getUserInfo() == "user");
 | 
				
			||||||
	assertTrue (uri7.getHost() == "www.appinf.com");
 | 
						assertTrue (uri7.getHost() == "www.appinf.com");
 | 
				
			||||||
	assertTrue (uri7.getPort() == 80);
 | 
						assertTrue (uri7.getPort() == 80);
 | 
				
			||||||
 | 
						assertTrue (uri7.getSpecifiedPort() == 0);
 | 
				
			||||||
	assertTrue (uri7.getAuthority() == "user@www.appinf.com");
 | 
						assertTrue (uri7.getAuthority() == "user@www.appinf.com");
 | 
				
			||||||
	assertTrue (uri7.getPath() == "/index.html");
 | 
						assertTrue (uri7.getPath() == "/index.html");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -150,6 +154,7 @@ void URITest::testConstruction()
 | 
				
			|||||||
	assertTrue (uri10.getUserInfo().empty());
 | 
						assertTrue (uri10.getUserInfo().empty());
 | 
				
			||||||
	assertTrue (uri10.getHost() == "2001:db8::7");
 | 
						assertTrue (uri10.getHost() == "2001:db8::7");
 | 
				
			||||||
	assertTrue (uri10.getPort() == 389);
 | 
						assertTrue (uri10.getPort() == 389);
 | 
				
			||||||
 | 
						assertTrue (uri10.getSpecifiedPort() == 0);
 | 
				
			||||||
	assertTrue (uri10.getAuthority() == "[2001:db8::7]");
 | 
						assertTrue (uri10.getAuthority() == "[2001:db8::7]");
 | 
				
			||||||
	assertTrue (uri10.getPathEtc() == "/c=GB?objectClass?one");
 | 
						assertTrue (uri10.getPathEtc() == "/c=GB?objectClass?one");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user