Skip to content

Commit b6675dd

Browse files
authored
Merge pull request #287 from jajik/issue-285
Fix and improve handling boolean parameters
2 parents fa9c80d + fee47c5 commit b6675dd

File tree

1 file changed

+36
-51
lines changed

1 file changed

+36
-51
lines changed

native/mod_manager/mod_manager.c

Lines changed: 36 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,23 @@ static int proxy_node_get_free_id(request_rec *r, int node_table_size)
986986
return -1;
987987
}
988988

989+
/*
990+
* Parse boolean parameter where Yes/On are true and No/Off are false.
991+
* @return true iff an input was recognized, false otherwise
992+
*/
993+
static int process_boolean_parameter(const char *val, int *parameter)
994+
{
995+
if (strcasecmp(val, "yes") == 0 || strcasecmp(val, "on") == 0) {
996+
*parameter = 1;
997+
return 1;
998+
} else if (strcasecmp(val, "no") == 0 || strcasecmp(val, "off") == 0) {
999+
*parameter = 0;
1000+
return 1;
1001+
}
1002+
1003+
return 0;
1004+
}
1005+
9891006
static void process_config_balancer_defaults(request_rec *r, balancerinfo_t *balancerinfo, mod_manager_config *mconf)
9901007
{
9911008
memset(balancerinfo, '\0', sizeof(*balancerinfo));
@@ -1048,9 +1065,7 @@ static char *process_config_balancer(const request_rec *r, const char *key, char
10481065
balancerinfo->balancer[sizeof(balancerinfo->balancer) - 1] = '\0';
10491066
}
10501067
if (strcasecmp(key, "StickySession") == 0) {
1051-
if (strcasecmp(val, "no") == 0) {
1052-
balancerinfo->StickySession = 0;
1053-
}
1068+
process_boolean_parameter(val, &balancerinfo->StickySession);
10541069
}
10551070
if (strcasecmp(key, "StickySessionCookie") == 0) {
10561071
if (strlen(val) >= sizeof(balancerinfo->StickySessionCookie)) {
@@ -1067,15 +1082,11 @@ static char *process_config_balancer(const request_rec *r, const char *key, char
10671082
strcpy(balancerinfo->StickySessionPath, val);
10681083
}
10691084
if (strcasecmp(key, "StickySessionRemove") == 0) {
1070-
if (strcasecmp(val, "yes") == 0) {
1071-
balancerinfo->StickySessionRemove = 1;
1072-
}
1085+
process_boolean_parameter(val, &balancerinfo->StickySessionRemove);
10731086
}
10741087
/* The java part assumes default = yes and sents only StickySessionForce=No */
10751088
if (strcasecmp(key, "StickySessionForce") == 0) {
1076-
if (strcasecmp(val, "no") == 0) {
1077-
balancerinfo->StickySessionForce = 0;
1078-
}
1089+
process_boolean_parameter(val, &balancerinfo->StickySessionForce);
10791090
}
10801091
/* Note that it is workerTimeout (set/getWorkerTimeout in java code) */
10811092
if (strcasecmp(key, "WaitWorker") == 0) {
@@ -1141,15 +1152,13 @@ static char *process_config_node(const char *key, char *val, nodeinfo_t *nodeinf
11411152
strcpy(nodeinfo->mess.Type, val);
11421153
}
11431154
if (strcasecmp(key, "Reversed") == 0) {
1144-
if (strcasecmp(val, "yes") == 0) {
1145-
nodeinfo->mess.reversed = 1;
1146-
}
1155+
process_boolean_parameter(val, &nodeinfo->mess.reversed);
11471156
}
11481157
if (strcasecmp(key, "flushpackets") == 0) {
1149-
if (strcasecmp(val, "on") == 0) {
1150-
nodeinfo->mess.flushpackets = flush_on;
1151-
} else if (strcasecmp(val, "auto") == 0) {
1152-
nodeinfo->mess.flushpackets = flush_auto;
1158+
if (!process_boolean_parameter(val, (int *)&nodeinfo->mess.flushpackets)) {
1159+
if (strcasecmp(val, "auto") == 0) {
1160+
nodeinfo->mess.flushpackets = flush_auto;
1161+
}
11531162
}
11541163
}
11551164
if (strcasecmp(key, "flushwait") == 0) {
@@ -3668,13 +3677,9 @@ static const char *cmd_manager_pers(cmd_parms *cmd, void *dummy, const char *arg
36683677
if (err != NULL) {
36693678
return err;
36703679
}
3671-
if (strcasecmp(arg, "Off") == 0) {
3672-
mconf->persistent = 0;
3673-
} else if (strcasecmp(arg, "On") == 0) {
3674-
mconf->persistent = AP_SLOTMEM_TYPE_PERSIST;
3675-
} else {
3676-
return "PersistSlots must be one of: "
3677-
"off | on";
3680+
3681+
if (!process_boolean_parameter(arg, &mconf->persistent)) {
3682+
return "PersistSlots must be one of: off | on";
36783683
}
36793684

36803685
return NULL;
@@ -3685,13 +3690,8 @@ static const char *cmd_manager_nonce(cmd_parms *cmd, void *dummy, const char *ar
36853690
mod_manager_config *mconf = ap_get_module_config(cmd->server->module_config, &manager_module);
36863691
(void)dummy;
36873692

3688-
if (strcasecmp(arg, "Off") == 0) {
3689-
mconf->nonce = 0;
3690-
} else if (strcasecmp(arg, "On") == 0) {
3691-
mconf->nonce = -1;
3692-
} else {
3693-
return "CheckNonce must be one of: "
3694-
"off | on";
3693+
if (!process_boolean_parameter(arg, &mconf->nonce)) {
3694+
return "CheckNonce must be one of: off | on";
36953695
}
36963696

36973697
return NULL;
@@ -3702,13 +3702,8 @@ static const char *cmd_manager_allow_display(cmd_parms *cmd, void *dummy, const
37023702
mod_manager_config *mconf = ap_get_module_config(cmd->server->module_config, &manager_module);
37033703
(void)dummy;
37043704

3705-
if (strcasecmp(arg, "Off") == 0) {
3706-
mconf->allow_display = 0;
3707-
} else if (strcasecmp(arg, "On") == 0) {
3708-
mconf->allow_display = -1;
3709-
} else {
3710-
return "AllowDisplay must be one of: "
3711-
"off | on";
3705+
if (!process_boolean_parameter(arg, &mconf->allow_display)) {
3706+
return "AllowDisplay must be one of: off | on";
37123707
}
37133708

37143709
return NULL;
@@ -3719,13 +3714,8 @@ static const char *cmd_manager_allow_cmd(cmd_parms *cmd, void *dummy, const char
37193714
mod_manager_config *mconf = ap_get_module_config(cmd->server->module_config, &manager_module);
37203715
(void)dummy;
37213716

3722-
if (strcasecmp(arg, "Off") == 0) {
3723-
mconf->allow_cmd = 0;
3724-
} else if (strcasecmp(arg, "On") == 0) {
3725-
mconf->allow_cmd = -1;
3726-
} else {
3727-
return "AllowCmd must be one of: "
3728-
"off | on";
3717+
if (!process_boolean_parameter(arg, &mconf->allow_cmd)) {
3718+
return "AllowCmd must be one of: off | on";
37293719
}
37303720

37313721
return NULL;
@@ -3736,13 +3726,8 @@ static const char *cmd_manager_reduce_display(cmd_parms *cmd, void *dummy, const
37363726
mod_manager_config *mconf = ap_get_module_config(cmd->server->module_config, &manager_module);
37373727
(void)dummy;
37383728

3739-
if (strcasecmp(arg, "Off") == 0) {
3740-
mconf->reduce_display = 0;
3741-
} else if (strcasecmp(arg, "On") == 0) {
3742-
mconf->reduce_display = 1;
3743-
} else {
3744-
return "ReduceDisplay must be one of: "
3745-
"off | on";
3729+
if (!process_boolean_parameter(arg, &mconf->reduce_display)) {
3730+
return "ReduceDisplay must be one of: off | on";
37463731
}
37473732

37483733
return NULL;

0 commit comments

Comments
 (0)