Skip to content

Commit 0e0d8ea

Browse files
committed
Rework processing of Contexts and Aliases
1 parent 019d1ed commit 0e0d8ea

File tree

1 file changed

+47
-66
lines changed

1 file changed

+47
-66
lines changed

native/mod_manager/mod_manager.c

Lines changed: 47 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -490,14 +490,6 @@ static const struct domain_storage_method domain_storage = {
490490
};
491491
/* clang-format on */
492492

493-
/* helper for the handling of the Alias: host1,... Context: context1,... */
494-
struct cluster_host
495-
{
496-
char *host;
497-
char *context;
498-
struct cluster_host *next;
499-
};
500-
501493
/*
502494
* cleanup logic
503495
*/
@@ -1267,13 +1259,13 @@ static int check_context_alias_length(const char *str, int limit)
12671259
* 2) during APP command
12681260
* to differenciate between the two use the last argument (true -> CONFIG, false -> APP)
12691261
*/
1270-
static char *process_context_alias(char *key, char *val, apr_pool_t *p, struct cluster_host *phost, int *errtype,
1262+
static char *process_context_alias(char *key, char *val, apr_pool_t *p, char **contexts, char **aliases, int *errtype,
12711263
int in_config)
12721264
{
12731265
if (strcasecmp(key, "Alias") == 0) {
12741266
char *tmp;
12751267

1276-
if (phost->host && !in_config) {
1268+
if (*aliases && !in_config) {
12771269
*errtype = TYPESYNTAX;
12781270
return in_config ? SALIBAD : SMULALB;
12791271
}
@@ -1289,15 +1281,15 @@ static char *process_context_alias(char *key, char *val, apr_pool_t *p, struct c
12891281
tmp++;
12901282
}
12911283

1292-
if (phost->host) {
1293-
phost->host = apr_pstrcat(p, phost->host, ",", val, NULL);
1284+
if (*aliases) {
1285+
*aliases = apr_pstrcat(p, *aliases, ",", val, NULL);
12941286
} else {
1295-
phost->host = val;
1287+
*aliases = val;
12961288
}
12971289
}
12981290

12991291
if (strcasecmp(key, "Context") == 0) {
1300-
if (phost->context && !in_config) {
1292+
if (*contexts && !in_config) {
13011293
*errtype = TYPESYNTAX;
13021294
return SMULCTB;
13031295
}
@@ -1306,10 +1298,10 @@ static char *process_context_alias(char *key, char *val, apr_pool_t *p, struct c
13061298
return SCONBIG;
13071299
}
13081300

1309-
if (phost->context) {
1310-
phost->context = apr_pstrcat(p, phost->context, ",", val, NULL);
1301+
if (*contexts) {
1302+
*contexts = apr_pstrcat(p, *contexts, ",", val, NULL);
13111303
} else {
1312-
phost->context = val;
1304+
*contexts = val;
13131305
}
13141306
}
13151307

@@ -1342,8 +1334,8 @@ static char *process_config(request_rec *r, char **ptr, int *errtype)
13421334
nodeinfo_t *node;
13431335
balancerinfo_t balancerinfo;
13441336

1345-
struct cluster_host *vhost;
1346-
struct cluster_host *phost;
1337+
char *contexts = NULL;
1338+
char *aliases = NULL;
13471339

13481340
int i = 0;
13491341
int id = -1;
@@ -1356,14 +1348,6 @@ static char *process_config(request_rec *r, char **ptr, int *errtype)
13561348
const proxy_server_conf *the_conf = NULL;
13571349
apr_status_t rv;
13581350

1359-
vhost = apr_palloc(r->pool, sizeof(struct cluster_host));
1360-
1361-
/* Map nothing by default */
1362-
vhost->host = NULL;
1363-
vhost->context = NULL;
1364-
vhost->next = NULL;
1365-
phost = vhost;
1366-
13671351
/* Fill default node values */
13681352
process_config_node_defaults(r, &nodeinfo, mconf);
13691353
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, "process_config: Start");
@@ -1389,7 +1373,7 @@ static char *process_config(request_rec *r, char **ptr, int *errtype)
13891373
return err_msg;
13901374
}
13911375
/* Optional parameters */
1392-
err_msg = process_context_alias(ptr[i], ptr[i + 1], r->pool, phost, errtype, 1);
1376+
err_msg = process_context_alias(ptr[i], ptr[i + 1], r->pool, &contexts, &aliases, errtype, 1);
13931377
if (err_msg != NULL) {
13941378
return err_msg;
13951379
}
@@ -1580,8 +1564,7 @@ static char *process_config(request_rec *r, char **ptr, int *errtype)
15801564
inc_version_node();
15811565

15821566
/* Insert the Alias and corresponding Context */
1583-
phost = vhost;
1584-
if (phost->host == NULL && phost->context == NULL) {
1567+
if (aliases == NULL && contexts == NULL) {
15851568
/* if using mod_balancer create or update the worker */
15861569
if (balancer_manage) {
15871570
apr_status_t rv = mod_manager_manage_worker(r, &nodeinfo, &balancerinfo);
@@ -1592,19 +1575,20 @@ static char *process_config(request_rec *r, char **ptr, int *errtype)
15921575
loc_unlock_nodes();
15931576
return NULL; /* Alias and Context missing */
15941577
}
1595-
while (phost) {
1596-
if (insert_update_hosts(r->server, hoststatsmem, phost->host, id, vid) != APR_SUCCESS) {
1597-
loc_unlock_nodes();
1598-
return apr_psprintf(r->pool, MHOSTUI, nodeinfo.mess.JVMRoute);
1599-
}
1600-
if (insert_update_contexts(r->server, contextstatsmem, phost->context, id, vid, STOPPED) != APR_SUCCESS) {
1601-
loc_unlock_nodes();
1602-
return apr_psprintf(r->pool, MCONTUI, nodeinfo.mess.JVMRoute);
1603-
}
1604-
phost = phost->next;
1605-
vid++;
1578+
1579+
1580+
if (insert_update_hosts(r->server, hoststatsmem, aliases, id, vid) != APR_SUCCESS) {
1581+
loc_unlock_nodes();
1582+
return apr_psprintf(r->pool, MHOSTUI, nodeinfo.mess.JVMRoute);
16061583
}
16071584

1585+
if (insert_update_contexts(r->server, contextstatsmem, contexts, id, vid, STOPPED) != APR_SUCCESS) {
1586+
loc_unlock_nodes();
1587+
return apr_psprintf(r->pool, MCONTUI, nodeinfo.mess.JVMRoute);
1588+
}
1589+
1590+
vid++;
1591+
16081592
/* if using mod_balancer create or update the worker */
16091593
if (balancer_manage) {
16101594
apr_status_t rv = mod_manager_manage_worker(r, &nodeinfo, &balancerinfo);
@@ -2098,19 +2082,16 @@ static char *process_appl_cmd(request_rec *r, char **ptr, int status, int *errty
20982082
{
20992083
nodeinfo_t nodeinfo;
21002084
nodeinfo_t *node;
2101-
struct cluster_host *vhost;
2085+
2086+
char *contexts = NULL;
2087+
char *aliases = NULL;
21022088

21032089
int i = 0;
21042090
hostinfo_t hostinfo;
21052091
hostinfo_t *host = NULL;
21062092
char *err_msg;
21072093

21082094
memset(&nodeinfo.mess, '\0', sizeof(nodeinfo.mess));
2109-
/* Map nothing by default */
2110-
vhost = apr_palloc(r->pool, sizeof(struct cluster_host));
2111-
vhost->host = NULL;
2112-
vhost->context = NULL;
2113-
vhost->next = NULL;
21142095

21152096
while (ptr[i]) {
21162097
if (strcasecmp(ptr[i], "JVMRoute") == 0) {
@@ -2121,7 +2102,7 @@ static char *process_appl_cmd(request_rec *r, char **ptr, int status, int *errty
21212102
strcpy(nodeinfo.mess.JVMRoute, ptr[i + 1]);
21222103
nodeinfo.mess.id = -1;
21232104
}
2124-
err_msg = process_context_alias(ptr[i], ptr[i + 1], r->pool, vhost, errtype, 0);
2105+
err_msg = process_context_alias(ptr[i], ptr[i + 1], r->pool, &contexts, &aliases, errtype, 0);
21252106
if (err_msg) {
21262107
return err_msg;
21272108
}
@@ -2136,16 +2117,16 @@ static char *process_appl_cmd(request_rec *r, char **ptr, int status, int *errty
21362117
}
21372118

21382119
/* Note: This applies only for non-wildcarded requests for which Alias and Context are required */
2139-
if (vhost->context == NULL && vhost->host == NULL && strcmp(r->uri, "/*") != 0) {
2120+
if (contexts == NULL && aliases == NULL && strcmp(r->uri, "/*") != 0) {
21402121
*errtype = TYPESYNTAX;
21412122
return NOCONAL;
21422123
}
21432124

2144-
if (vhost->context == NULL && vhost->host != NULL) {
2125+
if (contexts == NULL && aliases != NULL) {
21452126
*errtype = TYPESYNTAX;
21462127
return SALIBAD;
21472128
}
2148-
if (vhost->host == NULL && vhost->context != NULL) {
2129+
if (aliases == NULL && contexts != NULL) {
21492130
*errtype = TYPESYNTAX;
21502131
return SCONBAD;
21512132
}
@@ -2188,15 +2169,15 @@ static char *process_appl_cmd(request_rec *r, char **ptr, int status, int *errty
21882169
*/
21892170
hostinfo.node = node->mess.id;
21902171
hostinfo.id = 0;
2191-
if (vhost->host != NULL) {
2172+
if (aliases != NULL) {
21922173
int start = 0;
21932174
i = 0;
2194-
while (host == NULL && (unsigned)(i + start) < strlen(vhost->host)) {
2195-
while (vhost->host[start + i] != ',' && vhost->host[start + i] != '\0') {
2175+
while (host == NULL && (unsigned)(i + start) < strlen(aliases)) {
2176+
while (aliases[start + i] != ',' && aliases[start + i] != '\0') {
21962177
i++;
21972178
}
21982179

2199-
strncpy(hostinfo.host, vhost->host + start, i);
2180+
strncpy(hostinfo.host, aliases + start, i);
22002181
hostinfo.host[i] = '\0';
22012182
host = read_host(hoststatsmem, &hostinfo);
22022183
start = start + i + 1;
@@ -2233,16 +2214,16 @@ static char *process_appl_cmd(request_rec *r, char **ptr, int status, int *errty
22332214
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, "process_appl_cmd: adding vhost: %d node: %d route: %s",
22342215
vid, node->mess.id, nodeinfo.mess.JVMRoute);
22352216
/* If the Host doesn't exist yet create it */
2236-
if (insert_update_hosts(r->server, hoststatsmem, vhost->host, node->mess.id, vid) != APR_SUCCESS) {
2217+
if (insert_update_hosts(r->server, hoststatsmem, aliases, node->mess.id, vid) != APR_SUCCESS) {
22372218
loc_unlock_nodes();
22382219
*errtype = TYPEMEM;
22392220
return apr_psprintf(r->pool, MHOSTUI, nodeinfo.mess.JVMRoute);
22402221
}
22412222
hostinfo.id = 0;
22422223
hostinfo.node = node->mess.id;
22432224
hostinfo.host[0] = '\0';
2244-
if (vhost->host != NULL) {
2245-
strncpy(hostinfo.host, vhost->host, sizeof(hostinfo.host));
2225+
if (aliases != NULL) {
2226+
strncpy(hostinfo.host, aliases, sizeof(hostinfo.host));
22462227
hostinfo.host[sizeof(hostinfo.host) - 1] = '\0';
22472228
}
22482229

@@ -2264,7 +2245,7 @@ static char *process_appl_cmd(request_rec *r, char **ptr, int status, int *errty
22642245
if (get_context(contextstatsmem, &ou, id[i]) != APR_SUCCESS) {
22652246
continue;
22662247
}
2267-
if (strcmp(ou->context, vhost->context) == 0) {
2248+
if (strcmp(ou->context, contexts) == 0) {
22682249
/* There is the same context somewhere else */
22692250
nodeinfo_t *hisnode;
22702251
if (get_node(nodestatsmem, &hisnode, ou->node) != APR_SUCCESS) {
@@ -2273,22 +2254,22 @@ static char *process_appl_cmd(request_rec *r, char **ptr, int status, int *errty
22732254
if (strcmp(hisnode->mess.balancer, node->mess.balancer)) {
22742255
/* the same context would be on 2 different balancer */
22752256
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, r->server,
2276-
"process_appl_cmd: ENABLE: context %s is in balancer %s and %s", vhost->context,
2257+
"process_appl_cmd: ENABLE: context %s is in balancer %s and %s", contexts,
22772258
node->mess.balancer, hisnode->mess.balancer);
22782259
}
22792260
}
22802261
}
22812262
}
22822263

22832264
/* Now update each context from Context: part */
2284-
if (insert_update_contexts(r->server, contextstatsmem, vhost->context, node->mess.id, host->vhost, status) !=
2265+
if (insert_update_contexts(r->server, contextstatsmem, contexts, node->mess.id, host->vhost, status) !=
22852266
APR_SUCCESS) {
22862267
loc_unlock_nodes();
22872268
*errtype = TYPEMEM;
22882269
return apr_psprintf(r->pool, MCONTUI, node->mess.JVMRoute);
22892270
}
22902271

2291-
if (insert_update_hosts(r->server, hoststatsmem, vhost->host, node->mess.id, host->vhost) != APR_SUCCESS) {
2272+
if (insert_update_hosts(r->server, hoststatsmem, aliases, node->mess.id, host->vhost) != APR_SUCCESS) {
22922273
loc_unlock_nodes();
22932274
*errtype = TYPEMEM;
22942275
return apr_psprintf(r->pool, MHOSTUI, node->mess.JVMRoute);
@@ -2324,11 +2305,11 @@ static char *process_appl_cmd(request_rec *r, char **ptr, int status, int *errty
23242305
}
23252306
}
23262307
} else if (status == STOPPED) {
2327-
/* insert_update_contexts in fact makes that vhost->context corresponds only to the first context... */
2308+
/* insert_update_contexts in fact makes that contexts corresponds only to the first context... */
23282309
contextinfo_t in;
23292310
contextinfo_t *ou;
23302311
in.id = 0;
2331-
strncpy(in.context, vhost->context, CONTEXTSZ);
2312+
strncpy(in.context, contexts, CONTEXTSZ);
23322313
in.context[CONTEXTSZ] = '\0';
23332314
in.vhost = host->vhost;
23342315
in.node = node->mess.id;
@@ -2339,8 +2320,8 @@ static char *process_appl_cmd(request_rec *r, char **ptr, int status, int *errty
23392320
if (fromnode) {
23402321
ap_set_content_type(r, PLAINTEXT_CONTENT_TYPE);
23412322
ap_rprintf(r, "Type=STOP-APP-RSP&JvmRoute=%.*s&Alias=%.*s&Context=%.*s&Requests=%d",
2342-
(int)sizeof(nodeinfo.mess.JVMRoute), nodeinfo.mess.JVMRoute, (int)sizeof(vhost->host),
2343-
vhost->host, (int)sizeof(vhost->context), vhost->context, ou->nbrequests);
2323+
(int)sizeof(nodeinfo.mess.JVMRoute), nodeinfo.mess.JVMRoute, (int)sizeof(aliases),
2324+
aliases, (int)sizeof(contexts), contexts, ou->nbrequests);
23442325
ap_rprintf(r, "\n");
23452326
}
23462327
} else {

0 commit comments

Comments
 (0)