]> granicus.if.org Git - apache/commitdiff
Add ap_vhost_iterate_given_conn() as I had previously mentioned on the mailing list.
authorPaul Querna <pquerna@apache.org>
Mon, 25 Apr 2005 05:23:18 +0000 (05:23 +0000)
committerPaul Querna <pquerna@apache.org>
Mon, 25 Apr 2005 05:23:18 +0000 (05:23 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@164538 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
include/ap_mmn.h
include/http_vhost.h
server/vhost.c

diff --git a/CHANGES b/CHANGES
index 25bf81e233eade121e059de020e05ade4e96ee40..931dee0dad51b300640c884878afada27ab9ccb8 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,10 @@ Changes with Apache 2.1.5
 
   [Remove entries to the current 2.0 section below, when backported]
   
+  *) Add the ap_vhost_iterate_given_conn function to expose the information
+     used in Name Based Virtual Hosting. (minor MMN bump)
+     [Paul Querna]
+
   *) Remove the never working ap_method_list_do and ap_method_list_vdo.
      [Paul Querna]
 
index 18da7e7b0c93846c2edbc036ff4295cf71e94a10..53de508b667bca349759279d7c694fe0273ae2aa 100644 (file)
@@ -93,6 +93,7 @@
  *                        symbols from the public sector, and decorated real_exit_code
  *                        with ap_ in the win32 os.h.
  * 20050305.0 (2.1.4-dev) added pid and generation fields to worker_score
+ * 20050305.1 (2.1.5-dev) added ap_vhost_iterate_given_conn.
  */
 
 #define MODULE_MAGIC_COOKIE 0x41503230UL /* "AP20" */
 #ifndef MODULE_MAGIC_NUMBER_MAJOR
 #define MODULE_MAGIC_NUMBER_MAJOR 20050305
 #endif
-#define MODULE_MAGIC_NUMBER_MINOR 0                     /* 0...n */
+#define MODULE_MAGIC_NUMBER_MINOR 1                     /* 0...n */
 
 /**
  * Determine if the server's current MODULE_MAGIC_NUMBER is at least a
index ffd2a89a9747d1dbd3be3d0592328b3c11ad9be6..14594412468799b6dce0a4a6ee54920eb88833be 100644 (file)
@@ -52,6 +52,30 @@ const char *ap_parse_vhost_addrs(apr_pool_t *p, const char *hostname, server_rec
 const char *ap_set_name_virtual_host (cmd_parms *cmd, void *dummy,
                                      const char *arg);
 
+/**
+ * Callback function for every Name Based Virtual Host.
+ * @param baton Opaque user object
+ * @param conn The current Connection
+ * @param s The current Server
+ * @see ap_vhost_iterate_given_conn
+ * @return 0 on success, any non-zero return will stop the iteration.
+ */
+typedef int(*ap_vhost_iterate_conn_cb)(void* baton, conn_rec* conn, server_rec* s);
+                
+/**
+ * For every virtual host on this connection, call func_cb.
+ * @param conn The current connection
+ * @param func_cb Function called for every Name Based Virtual Host for this 
+ *                connection.
+ * @param baton Opaque object passed to func_cb.
+ * @return The return value from func_cb.
+ * @note If func_cb returns non-zero, the function will return at this point, 
+ *       and not continue iterating the virtual hosts.
+ */
+AP_DECLARE(int) ap_vhost_iterate_given_conn(conn_rec *conn,
+                                            ap_vhost_iterate_conn_cb func_cb,
+                                            void* baton);
+
 /**
  * given an ip address only, give our best guess as to what vhost it is 
  * @param conn The current connection
index 199465de9e11c8c08a1e9242d1a2c6723a66eb19..6bb27bd80ae89269545e37d3573b2c81452f2eb3 100644 (file)
@@ -977,6 +977,56 @@ AP_DECLARE(void) ap_update_vhost_from_headers(request_rec *r)
     }
 }
 
+/**
+ * For every virtual host on this connection, call func_cb.
+ */
+AP_DECLARE(int) ap_vhost_iterate_given_conn(conn_rec *conn, 
+                                            ap_vhost_iterate_conn_cb func_cb,
+                                            void* baton)
+{
+    server_rec *s;
+    server_rec *last_s;
+    name_chain *src;
+    apr_port_t port;
+    int rv = 0;
+
+    if (conn->vhost_lookup_data) {
+        last_s = NULL;
+        port = conn->local_addr->port;
+
+        for (src = conn->vhost_lookup_data; src; src = src->next) {
+            server_addr_rec *sar;
+
+            /* We only consider addresses on the name_chain which have a 
+             * matching port.
+             */
+            sar = src->sar;
+            if (sar->host_port != 0 && port != sar->host_port) {
+                continue;
+            }
+
+            s = src->server;
+
+            if (s == last_s) {
+                /* we've already done a callback for this vhost. */
+                continue;
+            }
+
+            last_s = s;
+
+            rv = func_cb(baton, conn, s);
+
+            if (rv != 0) {
+                break;
+            }
+        }
+    }
+    else {
+        rv = func_cb(baton, conn, conn->base_server);
+    }
+
+    return rv;
+}
 
 /* Called for a new connection which has a known local_addr.  Note that the
  * new connection is assumed to have conn->server == main server.