httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject cvs commit: httpd-2.0/modules/proxy mod_proxy.c
Date Wed, 25 Aug 2004 09:13:09 GMT
mturk       2004/08/25 02:13:09

  Modified:    modules/proxy mod_proxy.c
  Log:
  Added ProxySet directive (can be rename to something else).
  The purpose is to be able to set the worker/balancer params
  withouth the need for very long config lines :
  <Proxy balancer://cluster>
    ProxySet stickysession=JSESSIONID
  </Proxy>
  Or...
  ProxySet balancer://cluser nofaiover=On timeout=2
  
  Revision  Changes    Path
  1.134     +89 -21    httpd-2.0/modules/proxy/mod_proxy.c
  
  Index: mod_proxy.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/modules/proxy/mod_proxy.c,v
  retrieving revision 1.133
  retrieving revision 1.134
  diff -u -r1.133 -r1.134
  --- mod_proxy.c	25 Aug 2004 08:00:27 -0000	1.133
  +++ mod_proxy.c	25 Aug 2004 09:13:09 -0000	1.134
  @@ -168,7 +168,7 @@
           worker->redirect = apr_pstrdup(p, val);
       }
       else {
  -        return "unknown parameter";
  +        return "unknown Worker parameter";
       }
       return NULL;
   }
  @@ -198,7 +198,7 @@
           balancer->timeout = apr_time_from_sec(ival);
       }
       else {
  -        return "unknown parameter";
  +        return "unknown Balancer parameter";
       }
       return NULL;
   }
  @@ -475,7 +475,7 @@
       if (p == NULL || p == url)
           return HTTP_BAD_REQUEST;
   
  -    return OK;		/* otherwise; we've done the best we can */
  +    return OK;      /* otherwise; we've done the best we can */
   }
   #endif
   /* Send a redirection if the request contains a hostname which is not */
  @@ -496,7 +496,7 @@
       /* If host does contain a dot already, or it is "localhost", decline */
       if (strchr(r->parsed_uri.hostname, '.') != NULL
        || strcasecmp(r->parsed_uri.hostname, "localhost") == 0)
  -        return DECLINED;	/* host name has a dot already */
  +        return DECLINED;    /* host name has a dot already */
   
       ref = apr_table_get(r->headers_in, "Referer");
   
  @@ -820,8 +820,8 @@
       }
       else
           if (strchr(f, ':') == NULL)
  -            ap_str_tolower(f);		/* lowercase scheme */
  -    ap_str_tolower(p + 3);		/* lowercase hostname */
  +            ap_str_tolower(f);      /* lowercase scheme */
  +    ap_str_tolower(p + 3);      /* lowercase hostname */
   
       if (port == -1) {
           port = apr_uri_port_of_scheme(scheme);
  @@ -1063,15 +1063,15 @@
           New->name = apr_pstrdup(parms->pool, arg);
           New->hostaddr = NULL;
   
  -	if (ap_proxy_is_ipaddr(New, parms->pool)) {
  +    if (ap_proxy_is_ipaddr(New, parms->pool)) {
   #if DEBUGGING
               ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
                            "Parsed addr %s", inet_ntoa(New->addr));
               ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
                            "Parsed mask %s", inet_ntoa(New->mask));
   #endif
  -	}
  -	else if (ap_proxy_is_domainname(New, parms->pool)) {
  +    }
  +    else if (ap_proxy_is_domainname(New, parms->pool)) {
               ap_str_tolower(New->name);
   #if DEBUGGING
               ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
  @@ -1303,8 +1303,8 @@
       if (!name)
           return "BalancerMember must define remote proxy server";
       
  -    ap_str_tolower(path);	/* lowercase scheme://hostname */
  -    ap_str_tolower(name);	/* lowercase scheme://hostname */
  +    ap_str_tolower(path);   /* lowercase scheme://hostname */
  +    ap_str_tolower(name);   /* lowercase scheme://hostname */
   
       /* Try to find existing worker */
       worker = ap_proxy_get_worker(cmd->temp_pool, conf, name);
  @@ -1338,10 +1338,76 @@
       return NULL;
   }
   
  +static const char *
  +    set_proxy_param(cmd_parms *cmd, void *dummy, const char *arg)
  +{
  +    server_rec *s = cmd->server;
  +    proxy_server_conf *conf =
  +    (proxy_server_conf *) ap_get_module_config(s->module_config, &proxy_module);
  +    char *name = NULL;
  +    char *word, *val;
  +    proxy_balancer *balancer = NULL;
  +    proxy_worker *worker = NULL;
  +    const char *err;
  +
  +    if (cmd->directive->parent &&
  +        strncasecmp(cmd->directive->parent->directive,
  +                    "<Proxy", 6) == 0) {
  +        const char *pargs = cmd->directive->parent->args;
  +        /* Directive inside <Proxy section
  +         * Parent directive arg is the worker/balancer name.
  +         */
  +        name = ap_getword_conf(cmd->temp_pool, &pargs);
  +        if ((word = ap_strchr_c(name, '>')))
  +            *word = '\0';
  +    }
  +    else {
  +        /* Standard set directive with worker/balancer
  +         * name as first param.
  +         */
  +        name = ap_getword_conf(cmd->temp_pool, &arg);
  +    }
  + 
  +    if (strncasecmp(name, "balancer:", 9) == 0) {
  +        balancer = ap_proxy_get_balancer(cmd->pool, conf, name);
  +        if (!balancer) {
  +            return apr_pstrcat(cmd->temp_pool, "ProxySet can not find '",
  +                               name, "' Balancer.", NULL);
  +        }        
  +    }
  +    else {
  +        worker = ap_proxy_get_worker(cmd->temp_pool, conf, name);
  +        if (!worker) {
  +            return apr_pstrcat(cmd->temp_pool, "ProxySet can not find '",
  +                               name, "' Worker.", NULL);
  +        }
  +    }
  +
  +    while (*arg) {
  +        word = ap_getword_conf(cmd->pool, &arg);
  +        val = strchr(word, '=');
  +        if (!val) {
  +            return "Invalid ProxySet parameter. Parameter must be "
  +                   "in the form 'key=value'";
  +        }
  +        else
  +            *val++ = '\0';
  +        if (worker)
  +            err = set_worker_param(cmd->pool, worker, word, val);
  +        else
  +            err = set_balancer_param(cmd->pool, balancer, word, val);
  +
  +        if (err)
  +            return apr_pstrcat(cmd->temp_pool, "ProxySet ", err, " ", word, " ", name,
NULL);
  +    }
  +
  +    return NULL;
  +}
  +
   static void ap_add_per_proxy_conf(server_rec *s, ap_conf_vector_t *dir_config)
   {
       proxy_server_conf *sconf = ap_get_module_config(s->module_config,
  -					            &proxy_module);
  +                                &proxy_module);
       void **new_space = (void **)apr_array_push(sconf->sec_proxy);
       
       *new_space = dir_config;
  @@ -1482,6 +1548,8 @@
        "A balancer name and scheme with list of params"), 
       AP_INIT_TAKE1("ProxyStatus", set_status_opt, NULL, RSRC_CONF,
        "Configure Status: proxy status to one of: on | off | full"),
  +    AP_INIT_RAW_ARGS("ProxySet", set_proxy_param, NULL, RSRC_CONF|ACCESS_CONF,
  +     "A balancer or worker name with list of params"),
       {NULL}
   };
   
  @@ -1653,17 +1721,17 @@
       STANDARD20_MODULE_STUFF,
       create_proxy_dir_config,    /* create per-directory config structure */
       merge_proxy_dir_config,     /* merge per-directory config structures */
  -    create_proxy_config,	/* create per-server config structure */
  -    merge_proxy_config,		/* merge per-server config structures */
  -    proxy_cmds,			/* command table */
  +    create_proxy_config,    /* create per-server config structure */
  +    merge_proxy_config,     /* merge per-server config structures */
  +    proxy_cmds,         /* command table */
       register_hooks
   };
   
   APR_HOOK_STRUCT(
  -	APR_HOOK_LINK(scheme_handler)
  -	APR_HOOK_LINK(canon_handler)
  -	APR_HOOK_LINK(pre_request)
  -	APR_HOOK_LINK(post_request)
  +    APR_HOOK_LINK(scheme_handler)
  +    APR_HOOK_LINK(canon_handler)
  +    APR_HOOK_LINK(pre_request)
  +    APR_HOOK_LINK(post_request)
   )
   
   APR_IMPLEMENT_EXTERNAL_HOOK_RUN_FIRST(proxy, PROXY, int, scheme_handler, 
  @@ -1689,5 +1757,5 @@
                                          proxy_server_conf *conf),(worker,
                                          balancer,r,conf),DECLINED)
   APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(proxy, PROXY, int, fixups,
  -				    (request_rec *r), (r),
  -				    OK, DECLINED)
  +                    (request_rec *r), (r),
  +                    OK, DECLINED)
  
  
  

Mime
View raw message