> Actually, such defines might need to be a little more dynamic, but either
> <IfDefine AP_MPM_THREADED> would be good, or if we absolutely
> needed too, we could add <IfFeature FOO> where features could be
> registered, by the core or by a loaded module.

to that end, here's a preliminary and rough patch for

<IfServerIs !threaded>

(substitute 'IfServerIs' for whatever you please - I'm not so good with names).

I couldn't think of anything else to implement other than threadedness right
now, but I guess we're discussing the concept at the moment so that's ok.  I
did almost start on

<IfServerIs >= 2.1>

but I thought that the new container semantics probably wouldn't go over
well (and I wasn't entirely convinced that was a worthy thing to test at
config time).

--Geoff
Index: server/core.c
===================================================================
RCS file: /home/cvspublic/httpd-2.0/server/core.c,v
retrieving revision 1.252
diff -u -r1.252 core.c
--- server/core.c       21 Nov 2003 15:02:04 -0000      1.252
+++ server/core.c       4 Dec 2003 19:57:35 -0000
@@ -90,6 +90,7 @@
 #include "mod_core.h"
 #include "mod_proxy.h"
 #include "ap_listen.h"
+#include "ap_mpm.h"
 
 /* LimitXMLRequestBody handling */
 #define AP_LIMIT_UNSET                  ((long) -1)
@@ -1928,6 +1929,60 @@
     }
 }
 
+static const char *start_ifserver(cmd_parms *cmd, void *mconfig, 
+                                  const char *arg)
+{
+    const char *endp = ap_strrchr_c(arg, '>');
+    int not          = 0;
+    int soak         = 1;
+
+    if (endp == NULL) {
+        return unclosed_directive(cmd);
+    }
+
+    arg = apr_pstrndup(cmd->pool, arg, endp - arg);
+
+    if (arg[0] == '!') {
+        not = 1;
+        arg++;
+    }
+
+    /* custom server properties - expand at will
+     * currently supports:
+     *   "threaded" (true if MPM is threaded)
+     */   
+
+    if (strcasecmp(arg, "threaded") == 0) {
+        int mpm_query_info;
+
+        apr_status_t retval = ap_mpm_query(AP_MPMQ_IS_THREADED, &mpm_query_info);
+
+        if (retval != APR_SUCCESS) {
+            return apr_pstrcat(cmd->pool, "<IfServerIs> could not query ",
+                               ap_show_mpm(), " MPM for threads", NULL);
+        }
+
+        if ((!not && mpm_query_info) || (not && !mpm_query_info)) {
+            soak = 0;
+        }
+    }
+         
+    if (soak) {
+        *(ap_directive_t **)mconfig = NULL;
+        return ap_soak_end_container(cmd, "<IfServerIs");
+    }
+    else {
+        ap_directive_t *parent = NULL;
+        ap_directive_t *current = NULL;
+        const char *retval;
+
+        retval = ap_build_cont_config(cmd->pool, cmd->temp_pool, cmd,
+                                      &current, &parent, "<IfServerIs");
+        *(ap_directive_t **)mconfig = current;
+        return retval;
+    }
+}
+
 /* httpd.conf commands... beginning with the <VirtualHost> business */
 
 static const char *virtualhost_section(cmd_parms *cmd, void *dummy,
@@ -3073,6 +3128,8 @@
   "Container for directives based on existance of specified modules"),
 AP_INIT_TAKE1("<IfDefine", start_ifdefine, NULL, EXEC_ON_READ | OR_ALL,
   "Container for directives based on existance of command line defines"),
+AP_INIT_TAKE1("<IfServerIs", start_ifserver, NULL, EXEC_ON_READ | OR_ALL,
+  "Container for directives based on existance of a various server properties"),
 AP_INIT_RAW_ARGS("<DirectoryMatch", dirsection, (void*)1, RSRC_CONF,
   "Container for directives affecting resources located in the "
   "specified directories"),

Reply via email to