فهرست منبع

CPP interface: Added getter for full port information

To be able to query port details like SSL
Philipp Hasper 6 سال پیش
والد
کامیت
161dc25c16
2فایلهای تغییر یافته به همراه40 افزوده شده و 23 حذف شده
  1. 14 4
      include/CivetServer.h
  2. 26 19
      src/CivetServer.cpp

+ 14 - 4
include/CivetServer.h

@@ -366,18 +366,28 @@ class CIVETWEB_CXX_API CivetServer
 	 * @return A vector of ports
 	 * @return A vector of ports
 	 */
 	 */
 
 
-	std::vector<int> getListeningPorts();
+	std::vector<int> getListeningPorts();
+
+	/**
+	 * getListeningPorts()
+	 *
+	 * Variant of getListeningPorts() returning the full port information
+	 * (protocol, SSL, ...)
+	 *
+	 * @return A vector of ports
+	 */
+	std::vector<struct mg_server_ports> getListeningPortsFull();
 
 
 	/**
 	/**
 	 * getCookie(struct mg_connection *conn, const std::string &cookieName,
 	 * getCookie(struct mg_connection *conn, const std::string &cookieName,
-	 *std::string &cookieValue)
+	 * std::string &cookieValue)
 	 *
 	 *
 	 * Puts the cookie value string that matches the cookie name in the
 	 * Puts the cookie value string that matches the cookie name in the
-	 *cookieValue destinaton string.
+	 * cookieValue destination string.
 	 *
 	 *
 	 * @param conn - the connection information
 	 * @param conn - the connection information
 	 * @param cookieName - cookie name to get the value from
 	 * @param cookieName - cookie name to get the value from
-	 * @param cookieValue - cookie value is returned using thiis reference
+	 * @param cookieValue - cookie value is returned using this reference
 	 * @returns the size of the cookie value string read.
 	 * @returns the size of the cookie value string read.
 	 */
 	 */
 	static int getCookie(struct mg_connection *conn,
 	static int getCookie(struct mg_connection *conn,

+ 26 - 19
src/CivetServer.cpp

@@ -619,25 +619,32 @@ CivetServer::urlEncode(const char *src,
 	}
 	}
 }
 }
 
 
-std::vector<int>
-CivetServer::getListeningPorts()
-{
-	std::vector<int> ports(50);
-	std::vector<struct mg_server_ports> server_ports(50);
-	int size = mg_get_server_ports(context,
-	                               (int)server_ports.size(),
-	                               &server_ports[0]);
-	if (size <= 0) {
-		ports.resize(0);
-		return ports;
-	}
-	ports.resize(size);
-	server_ports.resize(size);
-	for (int i = 0; i < size; i++) {
-		ports[i] = server_ports[i].port;
-	}
-
-	return ports;
+std::vector<int>
+CivetServer::getListeningPorts()
+{
+	std::vector<struct mg_server_ports> server_ports = getListeningPortsFull();
+
+	std::vector<int> ports(server_ports.size());
+	for (size_t i = 0; i < server_ports.size(); i++) {
+		ports[i] = server_ports[i].port;
+	}
+
+	return ports;
+}
+
+std::vector<struct mg_server_ports>
+CivetServer::getListeningPortsFull()
+{
+	std::vector<struct mg_server_ports> server_ports(50);
+	int size = mg_get_server_ports(context,
+	                               (int)server_ports.size(),
+	                               &server_ports[0]);
+	if (size <= 0) {
+		server_ports.resize(0);
+		return server_ports;
+	}
+	server_ports.resize(size);
+	return server_ports;
 }
 }
 
 
 CivetServer::CivetConnection::CivetConnection()
 CivetServer::CivetConnection::CivetConnection()