Author: jfrederic.clere(a)jboss.com
Date: 2009-04-23 05:09:15 -0400 (Thu, 23 Apr 2009)
New Revision: 2403
Modified:
trunk/mod_cluster/native/mod_manager/mod_manager.c
Log:
Simplify the disable/enable individual apps logic.
Modified: trunk/mod_cluster/native/mod_manager/mod_manager.c
===================================================================
--- trunk/mod_cluster/native/mod_manager/mod_manager.c 2009-04-23 07:36:35 UTC (rev 2402)
+++ trunk/mod_cluster/native/mod_manager/mod_manager.c 2009-04-23 09:09:15 UTC (rev 2403)
@@ -585,7 +585,7 @@
* Context corresponding to the applications.
* Context: <context list>
*/
-static char * process_config(request_rec *r, char *buff, int *errtype)
+static char * process_config(request_rec *r, char **ptr, int *errtype)
{
/* Process the node/balancer description */
nodeinfo_t nodeinfo;
@@ -600,11 +600,6 @@
int id;
int vid = 1; /* zero and "" is empty */
- char **ptr = process_buff(r, buff);
- if (ptr == NULL) {
- *errtype = TYPESYNTAX;
- return SMESPAR;
- }
vhost = apr_palloc(r->pool, sizeof(struct cluster_host));
/* Map nothing by default */
@@ -824,7 +819,7 @@
/*
* Process a DUMP command.
*/
-static char * process_dump(request_rec *r, char *buff, int *errtype)
+static char * process_dump(request_rec *r, char **ptr, int *errtype)
{
int size, i;
int *id;
@@ -887,7 +882,7 @@
* Process a INFO command.
* Statics informations ;-)
*/
-static char * process_info(request_rec *r, char *buff, int *errtype)
+static char * process_info(request_rec *r, char **ptr, int *errtype)
{
int size, i;
int *id;
@@ -1020,7 +1015,7 @@
}
/* Process an enable/disable/stop/remove application message */
-static char * process_appl_cmd(request_rec *r, char *buff, int status, int *errtype, int
global)
+static char * process_appl_cmd(request_rec *r, char **ptr, int status, int *errtype, int
global)
{
nodeinfo_t nodeinfo;
nodeinfo_t *node;
@@ -1030,13 +1025,6 @@
hostinfo_t hostinfo;
hostinfo_t *host;
-
- char **ptr = process_buff(r, buff);
- if (ptr == NULL) {
- *errtype = TYPESYNTAX;
- return SMESPAR;
- }
-
memset(&nodeinfo.mess, '\0', sizeof(nodeinfo.mess));
/* Map nothing by default */
vhost = apr_palloc(r->pool, sizeof(struct cluster_host));
@@ -1153,21 +1141,21 @@
}
return NULL;
}
-static char * process_enable(request_rec *r, char *buff, int *errtype, int global)
+static char * process_enable(request_rec *r, char **ptr, int *errtype, int global)
{
- return process_appl_cmd(r, buff, ENABLED, errtype, global);
+ return process_appl_cmd(r, ptr, ENABLED, errtype, global);
}
-static char * process_disable(request_rec *r, char *buff, int *errtype, int global)
+static char * process_disable(request_rec *r, char **ptr, int *errtype, int global)
{
- return process_appl_cmd(r, buff, DISABLED, errtype, global);
+ return process_appl_cmd(r, ptr, DISABLED, errtype, global);
}
-static char * process_stop(request_rec *r, char *buff, int *errtype, int global)
+static char * process_stop(request_rec *r, char **ptr, int *errtype, int global)
{
- return process_appl_cmd(r, buff, STOPPED, errtype, global);
+ return process_appl_cmd(r, ptr, STOPPED, errtype, global);
}
-static char * process_remove(request_rec *r, char *buff, int *errtype, int global)
+static char * process_remove(request_rec *r, char **ptr, int *errtype, int global)
{
- return process_appl_cmd(r, buff, REMOVE, errtype, global);
+ return process_appl_cmd(r, ptr, REMOVE, errtype, global);
}
/*
@@ -1187,7 +1175,7 @@
* Load 0 : Standby.
* Load 1-100 : Load factor.
*/
-static char * process_status(request_rec *r, char *buff, int *errtype)
+static char * process_status(request_rec *r, char **ptr, int *errtype)
{
int Load = -1;
nodeinfo_t nodeinfo;
@@ -1195,12 +1183,6 @@
int i = 0;
- char **ptr = process_buff(r, buff);
- if (ptr == NULL) {
- *errtype = TYPESYNTAX;
- return SMESPAR;
- }
-
while (ptr[i]) {
if (strcasecmp(ptr[i], "JVMRoute") == 0) {
if (strlen(ptr[i+1])>=sizeof(nodeinfo.mess.JVMRoute)) {
@@ -1386,16 +1368,16 @@
/* Create the commands that are possible on the context */
static char*context_string(request_rec *r, contextinfo_t *ou, char *Alias, char
*JVMRoute)
{
- char *raw = apr_pstrcat(r->pool, "JVMRoute%3d", JVMRoute,
"%26Alias%3d", Alias, "%26Context%3d", ou->context);
+ char *raw = apr_pstrcat(r->pool, "JVMRoute=", JVMRoute,
"&Alias=", Alias, "&Context=", ou->context);
return raw;
}
static void context_command_string(request_rec *r, contextinfo_t *ou, char *Alias, char
*JVMRoute)
{
if (ou->status == DISABLED)
- ap_rprintf(r, "<a
href=\"%s?nonce=%s&Cmd=ENABLE-APP&Range=CONTEXT&String=%s\">Enable</a>
",
+ ap_rprintf(r, "<a
href=\"%s?nonce=%s&Cmd=ENABLE-APP&Range=CONTEXT&%s\">Enable</a>
",
r->uri, balancer_nonce, context_string(r, ou, Alias, JVMRoute));
if (ou->status == ENABLED)
- ap_rprintf(r, "<a
href=\"%s?nonce=%s&Cmd=DISABLE-APP&Range=CONTEXT&String=%s\">Disable</a>",
+ ap_rprintf(r, "<a
href=\"%s?nonce=%s&Cmd=DISABLE-APP&Range=CONTEXT&%s\">Disable</a>",
r->uri, balancer_nonce, context_string(r, ou, Alias, JVMRoute));
}
@@ -1545,7 +1527,7 @@
* Special case: contexts contain path information
*/
if ((access_status = ap_unescape_url(val)) != OK)
- if (strcmp(args, "String") || (access_status !=
HTTP_NOT_FOUND))
+ if (strcmp(args, "Context") || (access_status !=
HTTP_NOT_FOUND))
return access_status;
apr_table_setn(params, args, val);
args = tok;
@@ -1569,28 +1551,39 @@
const char *val = apr_table_get(params, "Refresh");
const char *cmd = apr_table_get(params, "Cmd");
const char *typ = apr_table_get(params, "Range");
- const char *string = apr_table_get(params, "String");
/* Process the Refresh parameter */
if (val) {
long t = atol(val);
apr_table_set(r->headers_out, "Refresh", apr_ltoa(r->pool,t
< 1 ? 10 : t));
}
/* Process command if any */
- if (cmd != NULL && typ !=NULL && string != NULL) {
+ if (cmd != NULL && typ !=NULL) {
int global = 0;
char *errstring = NULL;
int errtype = 0;
- char *buff = apr_pstrdup(r->pool, string);
+ int i;
+ char **ptr;
+ const apr_array_header_t *arr = apr_table_elts(params);
+ const apr_table_entry_t *elts = (const apr_table_entry_t *)arr->elts;
+
+ ptr = apr_palloc(r->pool, sizeof(char *) * (arr->nelts + 1) * 2);
+ for (i = 0; i < arr->nelts; i++) {
+ ptr[i*2] = elts[i].key;
+ ptr[i*2+1] = elts[i].val;
+ }
+ ptr[arr->nelts*2] = NULL;
+ ptr[arr->nelts*2+1] = NULL;
+
if (strcasecmp(typ,"NODE")==0)
global = 1;
if (strcasecmp(cmd, "ENABLE-APP") == 0)
- errstring = process_enable(r, buff, &errtype, global);
+ errstring = process_enable(r, ptr, &errtype, global);
else if (strcasecmp(cmd, "DISABLE-APP") == 0)
- errstring = process_disable(r, buff, &errtype, global);
+ errstring = process_disable(r, ptr, &errtype, global);
else if (strcasecmp(cmd, "STOP-APP") == 0)
- errstring = process_stop(r, buff, &errtype, global);
+ errstring = process_stop(r, ptr, &errtype, global);
else if (strcasecmp(cmd, "REMOVE-APP") == 0)
- errstring = process_remove(r, buff, &errtype, global);
+ errstring = process_remove(r, ptr, &errtype, global);
else {
errstring = SCMDUNS;
errtype = TYPESYNTAX;
@@ -1670,6 +1663,7 @@
apr_size_t bufsiz=MAXMESSSIZE;
apr_status_t status;
int global = 0;
+ char **ptr;
if (strcmp(r->handler, "mod_cluster-manager") == 0) {
/* Display the nodes information */
@@ -1701,27 +1695,34 @@
/* XXX: Size limit it? */
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
"manager_handler %s (%s) processing: \"%s\"",
r->method, r->filename, buff);
+
decodeenc(buff);
+ ptr = process_buff(r, buff);
+ if (ptr == NULL) {
+ process_error(r, SMESPAR, TYPESYNTAX);
+ return 500;
+ }
if (strstr(r->filename, NODE_COMMAND))
global = 1;
+
if (strcasecmp(r->method, "CONFIG") == 0)
- errstring = process_config(r, buff, &errtype);
+ errstring = process_config(r, ptr, &errtype);
/* Application handling */
else if (strcasecmp(r->method, "ENABLE-APP") == 0)
- errstring = process_enable(r, buff, &errtype, global);
+ errstring = process_enable(r, ptr, &errtype, global);
else if (strcasecmp(r->method, "DISABLE-APP") == 0)
- errstring = process_disable(r, buff, &errtype, global);
+ errstring = process_disable(r, ptr, &errtype, global);
else if (strcasecmp(r->method, "STOP-APP") == 0)
- errstring = process_stop(r, buff, &errtype, global);
+ errstring = process_stop(r, ptr, &errtype, global);
else if (strcasecmp(r->method, "REMOVE-APP") == 0)
- errstring = process_remove(r, buff, &errtype, global);
+ errstring = process_remove(r, ptr, &errtype, global);
/* Status handling */
else if (strcasecmp(r->method, "STATUS") == 0)
- errstring = process_status(r, buff, &errtype);
+ errstring = process_status(r, ptr, &errtype);
else if (strcasecmp(r->method, "DUMP") == 0)
- errstring = process_dump(r, buff, &errtype);
+ errstring = process_dump(r, ptr, &errtype);
else if (strcasecmp(r->method, "INFO") == 0)
- errstring = process_info(r, buff, &errtype);
+ errstring = process_info(r, ptr, &errtype);
else {
errstring = SCMDUNS;
errtype = TYPESYNTAX;