| 1202 | #define PROXY_UNSET_NONCE '\n' |
| 1203 | |
| 1204 | PROXY_DECLARE(char *) ap_proxy_define_balancer(apr_pool_t *p, |
| 1205 | proxy_balancer **balancer, |
| 1206 | proxy_server_conf *conf, |
| 1207 | const char *url, |
| 1208 | const char *alias, |
| 1209 | int do_malloc) |
| 1210 | { |
| 1211 | proxy_balancer_method *lbmethod; |
| 1212 | proxy_balancer_shared *bshared; |
| 1213 | char *c, *q, *uri = apr_pstrdup(p, url); |
| 1214 | const char *sname; |
| 1215 | |
| 1216 | /* We should never get here without a valid BALANCER_PREFIX... */ |
| 1217 | |
| 1218 | c = strchr(uri, ':'); |
| 1219 | if (c == NULL || c[1] != '/' || c[2] != '/' || c[3] == '\0') |
| 1220 | return apr_psprintf(p, "Bad syntax for a balancer name (%s)", uri); |
| 1221 | /* remove path from uri */ |
| 1222 | if ((q = strchr(c + 3, '/'))) |
| 1223 | *q = '\0'; |
| 1224 | |
| 1225 | ap_str_tolower(uri); |
| 1226 | *balancer = apr_array_push(conf->balancers); |
| 1227 | memset(*balancer, 0, sizeof(proxy_balancer)); |
| 1228 | |
| 1229 | /* |
| 1230 | * NOTE: The default method is byrequests - if it doesn't |
| 1231 | * exist, that's OK at this time. We check when we share and sync |
| 1232 | */ |
| 1233 | lbmethod = ap_lookup_provider(PROXY_LBMETHOD, "byrequests", "0"); |
| 1234 | (*balancer)->lbmethod = lbmethod; |
| 1235 | |
| 1236 | (*balancer)->workers = apr_array_make(p, 5, sizeof(proxy_worker *)); |
| 1237 | #if APR_HAS_THREADS |
| 1238 | (*balancer)->gmutex = NULL; |
| 1239 | (*balancer)->tmutex = NULL; |
| 1240 | #endif |
| 1241 | |
| 1242 | if (do_malloc) |
| 1243 | bshared = ap_malloc(sizeof(proxy_balancer_shared)); |
| 1244 | else |
| 1245 | bshared = apr_palloc(p, sizeof(proxy_balancer_shared)); |
| 1246 | |
| 1247 | memset(bshared, 0, sizeof(proxy_balancer_shared)); |
| 1248 | |
| 1249 | bshared->was_malloced = (do_malloc != 0); |
| 1250 | PROXY_STRNCPY(bshared->lbpname, "byrequests"); |
| 1251 | if (PROXY_STRNCPY(bshared->name, uri) != APR_SUCCESS) { |
| 1252 | if (do_malloc) free(bshared); |
| 1253 | return apr_psprintf(p, "balancer name (%s) too long", uri); |
| 1254 | } |
| 1255 | (*balancer)->lbmethod_set = 1; |
| 1256 | |
| 1257 | /* |
| 1258 | * We do the below for verification. The real sname will be |
| 1259 | * done post_config |
| 1260 | */ |
| 1261 | ap_pstr2_alnum(p, bshared->name + sizeof(BALANCER_PREFIX) - 1, |
no test coverage detected