You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Jean-Luc Drouot <jl...@lussy.net> on 2001/12/29 03:13:13 UTC
mod_webapp WebAppAlias directive
I was looking for a way to map a single servlet context on different
URIs (so as to be able to use relative URLs in the HTML outputs - for
internationalization and customization purposes).
I finally made a patch on mod_webapp (Apache-1.3) that adds the
directive WebAppAlias (Usage: WebAppAlias <uri-dest> <uri-alias>).
My httpd.conf now looks like:
[.../...]
WebAppConnection warpConnection warp localhost:8008
WebAppDeploy . warpConnection /servlet/
WebAppAlias /servlet/ /neostyle/us/servlet/
WebAppAlias /servlet/ /oldstyle/fr/servlet/
[.../...]
The request [http://<MYSERVER>/oldstyle/fr/servlet/HelloWorld] is then
totally equivalent to [http://<MYSERVER>/servlet/HelloWorld], since I
replace [/oldstyle/fr/servlet/] by [/servlet/] in wam_match method.
In case it is usefull to s.o., here is the patch I made:
Index: webapp/apache-1.3/mod_webapp.c
===================================================================
RCS file:
/home/cvspublic/jakarta-tomcat-connectors/webapp/apache-1.3/mod_webapp.c,v
retrieving revision 1.29
diff -u -r1.29 mod_webapp.c
--- webapp/apache-1.3/mod_webapp.c 1 Nov 2001 22:20:51 -0000 1.29
+++ webapp/apache-1.3/mod_webapp.c 29 Dec 2001 01:46:25 -0000
@@ -69,6 +69,15 @@
#include <util_script.h>
#include <wa.h>
+
+typedef struct wa_aliases wa_aliases;
+struct wa_aliases {
+ const char *dest;
+ const char *alias;
+ /** The pointer to the next aliases structure or <b>NULL</b>. */
+ wa_aliases *next;
+};
+
/*
************************************************************************* */
/* GENERIC DECLARATIONS
*/
/*
************************************************************************* */
@@ -81,6 +90,8 @@
static wa_chain *wam_connections=NULL;
/* The main server using for logging error not related to requests */
static server_rec *server=NULL;
+/* Aliases (JLD) */
+static wa_aliases *wam_aliases=NULL;
/*
************************************************************************* */
/* MODULE AND LIBRARY INITIALIZATION AND DESTRUCTION
*/
@@ -177,6 +188,22 @@
return(NULL);
}
+/* Process the WebAppAlias directive */
+static const char *wam_directive_alias(cmd_parms *cmd, void *mconfig,
+ const char *dest, const char
*alias) {
+ wa_aliases *elem=NULL;
+
+ if (dest==NULL) return("Invalid alias destination");
+ if (alias==NULL) return("Invalid alias name");
+
+ elem=apr_palloc(wa_pool,sizeof(wa_aliases));
+ elem->dest=apr_pstrdup(wa_pool,dest);
+ elem->alias=apr_pstrdup(wa_pool,alias);
+ elem->next=wam_aliases;
+ wam_aliases=elem;
+ return(NULL);
+}
+
/* Process the WebAppDeploy directive */
static const char *wam_directive_deploy(cmd_parms *cmd, void *mconfig,
char *name, char *cnam, char
*path) {
@@ -250,6 +277,13 @@
RSRC_CONF, /* where available */
TAKE3, /* arguments */
"<name> <connection> <uri-path>"
+ }, {
+ "WebAppAlias", /* directive name */
+ wam_directive_alias, /* config action routine */
+ NULL, /* argument to include in call */
+ RSRC_CONF, /* where available */
+ TAKE2, /* arguments */
+ "<uri-dest> <uri-alias>"
}, {NULL}
};
@@ -386,6 +420,8 @@
wa_virtualhost *host=NULL;
wa_application *appl=NULL;
wa_chain *elem=NULL;
+ wa_aliases *alias=NULL;
+ char *newuri=NULL;
/* Paranoid check */
if (!wam_initialized) return(DECLINED);
@@ -399,6 +435,20 @@
while(elem!=NULL) {
appl=(wa_application *)elem->curr;
if (strncmp(appl->rpth,r->uri,strlen(appl->rpth))==0) break;
+ // Check the aliases (JLD)
+ alias=wam_aliases;
+ while(alias!=NULL) {
+ if ((strcmp(alias->dest,appl->rpth)==0) &&
+ (strncmp(alias->alias,r->uri,strlen(alias->alias))==0)) {
+ newuri=ap_palloc(r->pool, strlen(appl->rpth) +
strlen(r->uri) - strlen(alias->alias));
+ strcpy(newuri, appl->rpth);
+ strcat(newuri, r->uri + strlen(alias->alias));
+ r->uri=newuri;
+ break;
+ }
+ alias=alias->next;
+ }
+ if (newuri!=NULL) break;
appl=NULL;
elem=elem->next;
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>