| 329 | } |
| 330 | |
| 331 | bool |
| 332 | HttpProxyPort::processOptions(const char *opts) |
| 333 | { |
| 334 | bool zret = false; // found a port? |
| 335 | bool af_set_p = false; // AF explicitly specified? |
| 336 | bool host_res_set_p = false; // Host resolution order set explicitly? |
| 337 | bool sp_set_p = false; // Session protocol set explicitly? |
| 338 | bool bracket_p = false; // found an open bracket in the input? |
| 339 | const char *value; // Temp holder for value of a prefix option. |
| 340 | IpAddr ip; // temp for loading IP addresses. |
| 341 | std::vector<char *> values; // Pointers to single option values. |
| 342 | |
| 343 | // Make a copy we can modify safely. |
| 344 | size_t opts_len = strlen(opts) + 1; |
| 345 | char *text = static_cast<char *>(alloca(opts_len)); |
| 346 | memcpy(text, opts, opts_len); |
| 347 | |
| 348 | // Split the copy in to tokens. |
| 349 | char *token = nullptr; |
| 350 | for (char *spot = text; *spot; ++spot) { |
| 351 | if (bracket_p) { |
| 352 | if (']' == *spot) { |
| 353 | bracket_p = false; |
| 354 | } |
| 355 | } else if (':' == *spot) { |
| 356 | *spot = 0; |
| 357 | token = nullptr; |
| 358 | } else { |
| 359 | if (!token) { |
| 360 | token = spot; |
| 361 | values.push_back(token); |
| 362 | } |
| 363 | if ('[' == *spot) { |
| 364 | bracket_p = true; |
| 365 | } |
| 366 | } |
| 367 | } |
| 368 | if (bracket_p) { |
| 369 | Warning("Invalid port descriptor '%s' - left bracket without closing right bracket", opts); |
| 370 | return zret; |
| 371 | } |
| 372 | |
| 373 | for (auto item : values) { |
| 374 | if (item[0] == '/') { |
| 375 | m_family = AF_UNIX; |
| 376 | m_unix_path = UnAddr(item); |
| 377 | af_set_p = true; |
| 378 | zret = true; |
| 379 | } else if (isdigit(item[0])) { // leading digit -> port value |
| 380 | char *ptr; |
| 381 | int port = strtoul(item, &ptr, 10); |
| 382 | if (ptr == item) { |
| 383 | // really, this shouldn't happen, since we checked for a leading digit. |
| 384 | Warning("Mangled port value '%s' in port configuration '%s'", item, opts); |
| 385 | } else if (port <= 0 || 65536 <= port) { |
| 386 | Warning("Port value '%s' out of range (1..65535) in port configuration '%s'", item, opts); |
| 387 | } else { |
| 388 | m_port = port; |
no test coverage detected