You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Doug MacEachern <do...@opengroup.org> on 1997/10/16 03:22:45 UTC

Re: NameVirtualHost

[...]
> > Not Deans fault/problem, but mod_perl lets people stuff a pile of
> > VirtualHost definitions into a hash. When the hash is accessed by the
> > config parsing part of mod_perl the order in which things come out of
> > the hash are unpredictable. This was why I was asking about file-less
> > config parsing earlier this week/month. Perl's good at building strings.
> > 
> > Doug, since the first VirtualHost section has significance, we either
> > need a workaround (perhaps a separate <Perl> </Perl> block to define
> > the first VirtualHost will work) or change of approach.
> 
> Note that the ordering has always been important -- the last name-vhost
> used to be the "overriding" one.  Now it's the first... which matches how
> other directives (such as <Directory>) work.  (aside: uh, does mod_perl do
> the same hash thing with <Directory>s?  'cause that'd be broken too.) 

%Hashes are the best way, syntacticly, to represent <VirtualHost foo>,
etc.  We could provide another interface, but it would be kinda ugly
IMHO.  If we need order, Rob, try the patch below or grab
http://www.osf.org/~dougm/mod_perl-1.00_05.tar.gz

You'll also have to install the Tie::IxHash module - "ordered
associative arrays for Perl", where "associative arrays" == "hashes".
http://www.perl.com/CPAN/modules/by-module/Tie/Tie-IxHash-1.2.tar.gz

The patch tries to pull in the module, upon success, it will tie
%VirtualHost, %Directory, etc., to Tie::IxHash.  So, when we iterate
over the hashes, they'll come out in the same order you see them in
httpd.conf

> > With my mod_perl setup, "NameVirtualHost *" on its own didn't work
> > and multiple "<VirtualHost *>"s are not (AFAIK) possible from within
> > a <Perl>..</Perl>. Any way around this Doug ?
> 
> Ah.  Right.  Yeah the perl interface is kind of broken then, because not
> only can you specify multiple "<VirtualHost *>"s, but you could specify
> multiple "<VirtualHost 10.0.0.1>"s as I gave in my example. 

I'm not sure I follow here, can I see a full multiple use example?
BTW, I don't use virtual hosts myself, so forgive if I've not followed
the discussions.

-Doug

--- mod_perl.h	1997/09/16 00:47:48	1.33
+++ mod_perl.h	1997/10/16 00:59:38
@@ -41,7 +45,7 @@
 typedef conn_rec    * Apache__Connection;
 typedef server_rec  * Apache__Server;
 
-#define GvHV_init(gv) (void)gv_fetchpv(gv, GV_ADDMULTI, SVt_PVHV)
+#define GvHV_init(gv) gv_fetchpv(gv, GV_ADDMULTI, SVt_PVHV)
 
 #define iniHV(hv) hv = (HV*)sv_2mortal((SV*)newHV())
 #define iniAV(av) av = (AV*)sv_2mortal((SV*)newAV())
@@ -608,6 +617,7 @@
 
 /* perl_util.c */
 
+void perl_tie_hash(HV *hv, char *class);
 void perl_util_cleanup(void);
 void mod_perl_clear_rgy_endav(request_rec *r, SV *sv);
 void perl_run_rgy_endav(char *s);
--- perl_util.c	1997/09/21 21:24:12	1.11
+++ perl_util.c	1997/10/16 00:59:51
@@ -16,6 +16,31 @@
     set_ids = 0;
 }
 
+#ifdef PERL_SECTIONS
+void perl_tie_hash(HV *hv, char *class)
+{
+    dSP;
+    SV *obj, *varsv = (SV*)hv;
+    char *methname = "TIEHASH";
+    
+    ENTER;
+    SAVETMPS;
+    PUSHMARK(sp);
+    XPUSHs(sv_2mortal(newSVpv(class,0)));
+    PUTBACK;
+    perl_call_method(methname, G_EVAL | G_SCALAR);
+    SPAGAIN;
+
+    obj = POPs;
+    sv_unmagic(varsv, 'P');
+    sv_magic(varsv, obj, 'P', Nullch, 0);
+
+    PUTBACK;
+    FREETMPS;
+    LEAVE; 
+}
+#endif
+
 /* execute END blocks */
 
 void perl_run_blocks(I32 oldscope, AV *list)
--- perl_config.c	1997/09/16 00:47:48	1.16
+++ perl_config.c	1997/10/16 01:03:08
@@ -438,6 +458,7 @@
     (void)hv_iterinit(hv); \
     while ((val = hv_iternextsv(hv, (char **) &key, &klen))) { \
 	HV *tab; \
+	if(SvMAGICAL(val)) mg_get(val); \
 	if((tab = (HV *)SvRV(val))) { 
 
 #define dSECiter_stop \
@@ -776,13 +807,19 @@
 }
 #endif
 
+void perl_section_hash_init(char *name, I32 dotie)
+{
+    GV *gv = GvHV_init(name);
+    if(dotie) perl_tie_hash(GvHV(gv), "Tie::IxHash");
+}
+
 CHAR_P perl_section (cmd_parms *cmd, void *dummy, const char *arg)
 {
     CHAR_P errmsg;
     SV *code = newSV(0), *val;
     HV *symtab;
     char *key;
-    I32 klen;
+    I32 klen, dotie=FALSE;
     char line[MAX_STRING_LEN];
 
     if(!PERL_RUNNING()) perl_startup(cmd->server, cmd->pool); 
@@ -795,11 +832,14 @@
 	return NULL;
     }
 
-    GvHV_init("ApacheReadConfig::Location");
-    GvHV_init("ApacheReadConfig::VirtualHost");
-    GvHV_init("ApacheReadConfig::Directory");
-    GvHV_init("ApacheReadConfig::Files");
-    GvHV_init("ApacheReadConfig::Limit");
+    if((perl_require_module("Tie::IxHash", cmd->server) == OK))
+	dotie = TRUE;
+
+    perl_section_hash_init("ApacheReadConfig::Location", dotie);
+    perl_section_hash_init("ApacheReadConfig::VirtualHost", dotie);
+    perl_section_hash_init("ApacheReadConfig::Directory", dotie);
+    perl_section_hash_init("ApacheReadConfig::Files", dotie);
+    perl_section_hash_init("ApacheReadConfig::Limit", dotie);
 
     perl_eval_sv(code, G_DISCARD);
     if(SvTRUE(GvSV(errgv))) {


Re: NameVirtualHost

Posted by Dean Gaudet <dg...@arctic.org>.

On Wed, 15 Oct 1997, Doug MacEachern wrote:

> I'm not sure I follow here, can I see a full multiple use example?
> BTW, I don't use virtual hosts myself, so forgive if I've not followed
> the discussions.

My example in the previous message included such an example.  But here's a
simple one again:

    NameVirtualHost 10.0.0.1
    <VirtualHost 10.0.0.1>
	ServerName www.client1.com
	...
    </VirtualHost>

    <VirtualHost 10.0.0.1>
	ServerName www.client2.com
	...
    </VirtualHost>

Note that during a migration period, say when client1 is migrating from a
name-vhost to an ip-vhost (upgrading their service) the following config
is also valid:

    NameVirtualHost 10.0.0.1
    <VirtualHost 10.0.0.1 10.0.1.1>
	ServerName www.client1.com
	...
    </VirtualHost>

    <VirtualHost 10.0.0.1>
	ServerName www.client2.com
	...
    </VirtualHost>

And so is the following:

    NameVirtualHost 10.0.0.1
    <VirtualHost 10.0.0.1>
	ServerName www.client1.com
	...
    </VirtualHost>

    <VirtualHost 10.0.0.1>
	ServerName www.client2.com
	...
    </VirtualHost>

    <VirtualHost 10.0.1.1>
	ServerName www.client1.com
	...
    </VirtualHost>

Dean