Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions doc/admin-guide/plugins/regex_remap.en.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ be used to modify the plugin instance behavior ::

@pparam=[no-]method [default: off]
@pparam=[no-]query-string [default: on]
@pparam=[no-]matrix-parameters [default: off]
@pparam=[no-]host [default: off]

If you wish to match on the HTTP method used (e.g. "``GET``\ "),
Expand All @@ -92,11 +91,6 @@ again, to turn this off use the option 'no-query-string', e.g. ::

... @pparam=maps.reg @pparam=no-query-string

You can also include the matrix parameters in the string, using
the option 'matrix-parameters', e.g. ::

... @pparam=maps.reg @pparam=matrix-parameters

Finally, to match on the host as well, use the option 'host', e.g. ::

... @pparam=maps.reg @pparam=host
Expand Down
62 changes: 19 additions & 43 deletions plugins/regex_remap/regex_remap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ static const int MAX_SUBS = 32; // No more than 32 substitution variables in th

// Substitutions other than regex matches
enum ExtraSubstitutions {
SUB_HOST = 11,
SUB_FROM_HOST = 12,
SUB_TO_HOST = 13,
SUB_PORT = 14,
SUB_SCHEME = 15,
SUB_PATH = 16,
SUB_QUERY = 17,
SUB_MATRIX = 18,
SUB_HOST = 11,
SUB_FROM_HOST = 12,
SUB_TO_HOST = 13,
SUB_PORT = 14,
SUB_SCHEME = 15,
SUB_PATH = 16,
SUB_QUERY = 17,
// 18 is unused, used to be matrix parameters
SUB_CLIENT_IP = 19,
SUB_LOWER_PATH = 20,
};
Expand All @@ -87,24 +87,21 @@ struct UrlComponents {
host = TSUrlHostGet(bufp, url, &host_len);
path = TSUrlPathGet(bufp, url, &path_len);
query = TSUrlHttpQueryGet(bufp, url, &query_len);
matrix = TSUrlHttpParamsGet(bufp, url, &matrix_len);
port = TSUrlPortGet(bufp, url);

url_len = scheme_len + host_len + path_len + query_len + matrix_len + 32;
url_len = scheme_len + host_len + path_len + query_len + 32;
}

const char *scheme = nullptr;
const char *host = nullptr;
const char *path = nullptr;
const char *query = nullptr;
const char *matrix = nullptr;
int port = 0;

int scheme_len = 0;
int host_len = 0;
int path_len = 0;
int query_len = 0;
int matrix_len = 0;

int url_len = 0; // Full length, of all components
};
Expand Down Expand Up @@ -442,9 +439,6 @@ RemapRegex::compile(const char *&error, int &erroffset)
case 'q':
ix = SUB_QUERY;
break;
case 'm':
ix = SUB_MATRIX;
break;
case 'i':
ix = SUB_CLIENT_IP;
break;
Expand Down Expand Up @@ -515,9 +509,6 @@ RemapRegex::get_lengths(const int ovector[], int lengths[], TSRemapRequestInfo *
case SUB_QUERY:
len += req_url->query_len;
break;
case SUB_MATRIX:
len += req_url->matrix_len;
break;
case SUB_CLIENT_IP:
len += INET6_ADDRSTRLEN;
break;
Expand Down Expand Up @@ -583,10 +574,6 @@ RemapRegex::substitute(char dest[], const char *src, const int ovector[], const
str = req_url->query;
len = req_url->query_len;
break;
case SUB_MATRIX:
str = req_url->matrix;
len = req_url->matrix_len;
break;
case SUB_CLIENT_IP:
str = ats_ip_ntop(TSHttpTxnClientAddrGet(txnp), buff, INET6_ADDRSTRLEN);
len = strlen(str);
Expand Down Expand Up @@ -627,17 +614,16 @@ RemapRegex::substitute(char dest[], const char *src, const int ovector[], const
struct RemapInstance {
RemapInstance() : filename("unknown") {}

RemapRegex *first = nullptr;
RemapRegex *last = nullptr;
bool pristine_url = false;
bool profile = false;
bool method = false;
bool query_string = true;
bool matrix_params = false;
bool host = false;
int hits = 0;
int misses = 0;
int failures = 0;
RemapRegex *first = nullptr;
RemapRegex *last = nullptr;
bool pristine_url = false;
bool profile = false;
bool method = false;
bool query_string = true;
bool host = false;
int hits = 0;
int misses = 0;
int failures = 0;
std::string filename;
};

Expand Down Expand Up @@ -689,10 +675,6 @@ TSRemapNewInstance(int argc, char *argv[], void **ih, char * /* errbuf ATS_UNUSE
ri->query_string = true;
} else if (strncmp(argv[i], "no-query-string", 15) == 0) {
ri->query_string = false;
} else if (strncmp(argv[i], "matrix-parameters", 17) == 0) {
ri->matrix_params = true;
} else if (strncmp(argv[i], "no-matrix-parameters", 20) == 0) {
ri->matrix_params = false;
} else if (strncmp(argv[i], "host", 4) == 0) {
ri->host = true;
} else if (strncmp(argv[i], "no-host", 7) == 0) {
Expand Down Expand Up @@ -957,12 +939,6 @@ TSRemapDoRemap(void *ih, TSHttpTxn txnp, TSRemapRequestInfo *rri)
match_len += (req_url.path_len);
}

if (ri->matrix_params && req_url.matrix && req_url.matrix_len > 0) {
*(match_buf + match_len) = ';';
memcpy(match_buf + match_len + 1, req_url.matrix, req_url.matrix_len);
match_len += (req_url.matrix_len + 1);
}

if (ri->query_string && req_url.query && req_url.query_len > 0) {
*(match_buf + match_len) = '?';
memcpy(match_buf + match_len + 1, req_url.query, req_url.query_len);
Expand Down