|
39 | 39 | ConditionStatus::initialize(Parser &p) |
40 | 40 | { |
41 | 41 | Condition::initialize(p); |
42 | | - MatcherType *match = new MatcherType(_cond_op); |
| 42 | + auto *match = new MatcherType(_cond_op); |
43 | 43 |
|
44 | | - match->set(static_cast<TSHttpStatus>(strtol(p.get_arg().c_str(), nullptr, 10)), mods()); |
| 44 | + match->set(p.get_arg(), mods(), [](const std::string &s) -> DataType { |
| 45 | + auto status = Parser::parseNumeric<DataType>(s); |
| 46 | + if (status > 999) { |
| 47 | + throw std::runtime_error("Invalid status code: " + s); |
| 48 | + } |
| 49 | + return status; |
| 50 | + }); |
45 | 51 | _matcher = match; |
46 | 52 |
|
47 | 53 | require_resources(RSRC_SERVER_RESPONSE_HEADERS); |
|
60 | 66 | ConditionStatus::eval(const Resources &res) |
61 | 67 | { |
62 | 68 | Dbg(pi_dbg_ctl, "Evaluating STATUS()"); |
| 69 | + |
63 | 70 | return static_cast<MatcherType *>(_matcher)->test(res.resp_status, res); |
64 | 71 | } |
65 | 72 |
|
|
75 | 82 | ConditionMethod::initialize(Parser &p) |
76 | 83 | { |
77 | 84 | Condition::initialize(p); |
78 | | - MatcherType *match = new MatcherType(_cond_op); |
| 85 | + auto *match = new MatcherType(_cond_op); |
79 | 86 |
|
80 | 87 | match->set(p.get_arg(), mods()); |
81 | 88 | _matcher = match; |
@@ -117,13 +124,13 @@ ConditionRandom::initialize(Parser &p) |
117 | 124 | { |
118 | 125 | struct timeval tv; |
119 | 126 | Condition::initialize(p); |
120 | | - MatcherType *match = new MatcherType(_cond_op); |
| 127 | + auto *match = new MatcherType(_cond_op); |
121 | 128 |
|
122 | 129 | gettimeofday(&tv, nullptr); |
123 | 130 | _seed = getpid() * tv.tv_usec; |
124 | 131 | _max = strtol(_qualifier.c_str(), nullptr, 10); |
125 | 132 |
|
126 | | - match->set(static_cast<unsigned int>(strtol(p.get_arg().c_str(), nullptr, 10)), mods()); |
| 133 | + match->set(p.get_arg(), mods(), [](const std::string &s) -> DataType { return Parser::parseNumeric<DataType>(s); }); |
127 | 134 | _matcher = match; |
128 | 135 | } |
129 | 136 |
|
|
190 | 197 | ConditionHeader::initialize(Parser &p) |
191 | 198 | { |
192 | 199 | Condition::initialize(p); |
193 | | - MatcherType *match = new MatcherType(_cond_op); |
| 200 | + auto *match = new MatcherType(_cond_op); |
194 | 201 |
|
195 | 202 | match->set(p.get_arg(), mods()); |
196 | 203 | _matcher = match; |
@@ -255,7 +262,7 @@ ConditionUrl::initialize(Parser &p) |
255 | 262 | { |
256 | 263 | Condition::initialize(p); |
257 | 264 |
|
258 | | - MatcherType *match = new MatcherType(_cond_op); |
| 265 | + auto *match = new MatcherType(_cond_op); |
259 | 266 | match->set(p.get_arg(), mods()); |
260 | 267 | _matcher = match; |
261 | 268 | } |
@@ -369,7 +376,7 @@ ConditionDBM::initialize(Parser &p) |
369 | 376 | { |
370 | 377 | Condition::initialize(p); |
371 | 378 |
|
372 | | - MatcherType *match = new MatcherType(_cond_op); |
| 379 | + auto *match = new MatcherType(_cond_op); |
373 | 380 | match->set(p.get_arg(), mods()); |
374 | 381 | _matcher = match; |
375 | 382 |
|
@@ -433,7 +440,7 @@ ConditionCookie::initialize(Parser &p) |
433 | 440 | { |
434 | 441 | Condition::initialize(p); |
435 | 442 |
|
436 | | - MatcherType *match = new MatcherType(_cond_op); |
| 443 | + auto *match = new MatcherType(_cond_op); |
437 | 444 |
|
438 | 445 | match->set(p.get_arg(), mods()); |
439 | 446 | _matcher = match; |
@@ -512,13 +519,13 @@ ConditionIp::initialize(Parser &p) |
512 | 519 | { |
513 | 520 | Condition::initialize(p); |
514 | 521 |
|
515 | | - if (_cond_op == MATCH_IP_RANGES) { // Special hack for IP ranges for now ... |
| 522 | + if (_cond_op == MATCH_IP_RANGES) { // Special hack for IP ranges |
516 | 523 | MatcherTypeIp *match = new MatcherTypeIp(_cond_op); |
517 | 524 |
|
518 | | - match->set(p.get_arg()); |
| 525 | + match->set(p.get_arg(), mods(), [](const std::string & /*s*/) { return static_cast<const sockaddr *>(nullptr); }); |
519 | 526 | _matcher = match; |
520 | 527 | } else { |
521 | | - MatcherType *match = new MatcherType(_cond_op); |
| 528 | + auto *match = new MatcherType(_cond_op); |
522 | 529 |
|
523 | 530 | match->set(p.get_arg(), mods()); |
524 | 531 | _matcher = match; |
@@ -615,10 +622,9 @@ void |
615 | 622 | ConditionTransactCount::initialize(Parser &p) |
616 | 623 | { |
617 | 624 | Condition::initialize(p); |
618 | | - MatcherType *match = new MatcherType(_cond_op); |
619 | | - std::string const &arg = p.get_arg(); |
| 625 | + auto *match = new MatcherType(_cond_op); |
620 | 626 |
|
621 | | - match->set(strtol(arg.c_str(), nullptr, 10), mods()); |
| 627 | + match->set(p.get_arg(), mods(), [](const std::string &s) -> DataType { return Parser::parseNumeric<DataType>(s); }); |
622 | 628 | _matcher = match; |
623 | 629 | } |
624 | 630 |
|
@@ -706,9 +712,9 @@ ConditionNow::initialize(Parser &p) |
706 | 712 | { |
707 | 713 | Condition::initialize(p); |
708 | 714 |
|
709 | | - MatcherType *match = new MatcherType(_cond_op); |
| 715 | + auto *match = new MatcherType(_cond_op); |
710 | 716 |
|
711 | | - match->set(static_cast<int64_t>(strtol(p.get_arg().c_str(), nullptr, 10)), mods()); |
| 717 | + match->set(p.get_arg(), mods(), [](const std::string &s) -> DataType { return Parser::parseNumeric<DataType>(s); }); |
712 | 718 | _matcher = match; |
713 | 719 | } |
714 | 720 |
|
@@ -776,9 +782,9 @@ ConditionGeo::initialize(Parser &p) |
776 | 782 | Condition::initialize(p); |
777 | 783 |
|
778 | 784 | if (is_int_type()) { |
779 | | - Matchers<int64_t> *match = new Matchers<int64_t>(_cond_op); |
| 785 | + auto *match = new Matchers<int64_t>(_cond_op); |
780 | 786 |
|
781 | | - match->set(static_cast<int64_t>(strtol(p.get_arg().c_str(), nullptr, 10)), mods()); |
| 787 | + match->set(p.get_arg(), mods(), [](const std::string &s) -> int64_t { return Parser::parseNumeric<int64_t>(s); }); |
782 | 788 | _matcher = match; |
783 | 789 | } else { |
784 | 790 | // The default is to have a string matcher |
@@ -854,9 +860,9 @@ ConditionId::initialize(Parser &p) |
854 | 860 | Condition::initialize(p); |
855 | 861 |
|
856 | 862 | if (_id_qual == ID_QUAL_REQUEST) { |
857 | | - Matchers<uint64_t> *match = new Matchers<uint64_t>(_cond_op); |
| 863 | + auto *match = new Matchers<uint64_t>(_cond_op); |
858 | 864 |
|
859 | | - match->set(static_cast<uint64_t>(strtol(p.get_arg().c_str(), nullptr, 10)), mods()); |
| 865 | + match->set(p.get_arg(), mods(), [](const std::string &s) -> uint64_t { return Parser::parseNumeric<uint64_t>(s); }); |
860 | 866 | _matcher = match; |
861 | 867 | } else { |
862 | 868 | // The default is to have a string matcher |
@@ -934,7 +940,7 @@ ConditionCidr::initialize(Parser &p) |
934 | 940 | { |
935 | 941 | Condition::initialize(p); |
936 | 942 |
|
937 | | - MatcherType *match = new MatcherType(_cond_op); |
| 943 | + auto *match = new MatcherType(_cond_op); |
938 | 944 |
|
939 | 945 | match->set(p.get_arg(), mods()); |
940 | 946 | _matcher = match; |
@@ -1040,10 +1046,10 @@ ConditionInbound::initialize(Parser &p) |
1040 | 1046 | if (_cond_op == MATCH_IP_RANGES) { // Special hack for IP ranges for now ... |
1041 | 1047 | MatcherTypeIp *match = new MatcherTypeIp(_cond_op); |
1042 | 1048 |
|
1043 | | - match->set(p.get_arg()); |
| 1049 | + match->set(p.get_arg(), mods(), [](const std::string & /* s */) { return static_cast<const sockaddr *>(nullptr); }); |
1044 | 1050 | _matcher = match; |
1045 | 1051 | } else { |
1046 | | - MatcherType *match = new MatcherType(_cond_op); |
| 1052 | + auto *match = new MatcherType(_cond_op); |
1047 | 1053 |
|
1048 | 1054 | match->set(p.get_arg(), mods()); |
1049 | 1055 | _matcher = match; |
@@ -1212,10 +1218,9 @@ void |
1212 | 1218 | ConditionSessionTransactCount::initialize(Parser &p) |
1213 | 1219 | { |
1214 | 1220 | Condition::initialize(p); |
1215 | | - MatcherType *match = new MatcherType(_cond_op); |
1216 | | - std::string const &arg = p.get_arg(); |
| 1221 | + auto *match = new MatcherType(_cond_op); |
1217 | 1222 |
|
1218 | | - match->set(strtol(arg.c_str(), nullptr, 10), mods()); |
| 1223 | + match->set(p.get_arg(), mods(), [](const std::string &s) -> DataType { return Parser::parseNumeric<DataType>(s); }); |
1219 | 1224 | _matcher = match; |
1220 | 1225 | } |
1221 | 1226 |
|
@@ -1246,10 +1251,9 @@ ConditionTcpInfo::initialize(Parser &p) |
1246 | 1251 | { |
1247 | 1252 | Condition::initialize(p); |
1248 | 1253 | Dbg(pi_dbg_ctl, "Initializing TCP Info"); |
1249 | | - MatcherType *match = new MatcherType(_cond_op); |
1250 | | - std::string const &arg = p.get_arg(); |
| 1254 | + auto *match = new MatcherType(_cond_op); |
1251 | 1255 |
|
1252 | | - match->set(strtol(arg.c_str(), nullptr, 10), mods()); |
| 1256 | + match->set(p.get_arg(), mods(), [](const std::string &s) -> DataType { return Parser::parseNumeric<DataType>(s); }); |
1253 | 1257 | _matcher = match; |
1254 | 1258 | } |
1255 | 1259 |
|
@@ -1318,7 +1322,7 @@ void |
1318 | 1322 | ConditionCache::initialize(Parser &p) |
1319 | 1323 | { |
1320 | 1324 | Condition::initialize(p); |
1321 | | - MatcherType *match = new MatcherType(_cond_op); |
| 1325 | + auto *match = new MatcherType(_cond_op); |
1322 | 1326 |
|
1323 | 1327 | match->set(p.get_arg(), mods()); |
1324 | 1328 | _matcher = match; |
@@ -1367,7 +1371,7 @@ ConditionNextHop::initialize(Parser &p) |
1367 | 1371 | { |
1368 | 1372 | Condition::initialize(p); |
1369 | 1373 |
|
1370 | | - MatcherType *match = new MatcherType(_cond_op); |
| 1374 | + auto *match = new MatcherType(_cond_op); |
1371 | 1375 | match->set(p.get_arg(), mods()); |
1372 | 1376 | _matcher = match; |
1373 | 1377 | } |
@@ -1475,9 +1479,9 @@ void |
1475 | 1479 | ConditionStateInt8::initialize(Parser &p) |
1476 | 1480 | { |
1477 | 1481 | Condition::initialize(p); |
1478 | | - MatcherType *match = new MatcherType(_cond_op); |
| 1482 | + auto *match = new MatcherType(_cond_op); |
1479 | 1483 |
|
1480 | | - match->set(static_cast<uint8_t>(strtol(p.get_arg().c_str(), nullptr, 10)), mods()); |
| 1484 | + match->set(p.get_arg(), mods(), [](const std::string &s) -> DataType { return Parser::parseNumeric<DataType>(s); }); |
1481 | 1485 | _matcher = match; |
1482 | 1486 | } |
1483 | 1487 |
|
@@ -1519,9 +1523,9 @@ void |
1519 | 1523 | ConditionStateInt16::initialize(Parser &p) |
1520 | 1524 | { |
1521 | 1525 | Condition::initialize(p); |
1522 | | - MatcherType *match = new MatcherType(_cond_op); |
| 1526 | + auto *match = new MatcherType(_cond_op); |
1523 | 1527 |
|
1524 | | - match->set(static_cast<uint16_t>(strtol(p.get_arg().c_str(), nullptr, 10)), mods()); |
| 1528 | + match->set(p.get_arg(), mods(), [](const std::string &s) -> DataType { return Parser::parseNumeric<DataType>(s); }); |
1525 | 1529 | _matcher = match; |
1526 | 1530 | } |
1527 | 1531 |
|
|
0 commit comments