Hi guys im trying to build a module for nginx and need to match a substring here is what im using to try and match
int match_chan(ngx_http_request_t *r, ngx_pool_t *temp_pool, ngx_str_t *body, ngx_str_t *channel) {
u_char errstr[NGX_MAX_CONF_ERRSTR];
ngx_regex_compile_t *rc;
int captures[2];
if ((rc = ngx_pcalloc(temp_pool, sizeof(ngx_regex_compile_t))) == NULL) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "unable to allocate memory to compile agent patterns");
return 0;
}
//ngx_memzero(rc, sizeof(ngx_regex_compile_t));
ngx_str_t pat = ngx_string("test(:|%3[Aa])([a-zA-Z0-9]+)");
rc->pattern = pat;
rc->pool = temp_pool;
rc->err.len = NGX_MAX_CONF_ERRSTR;
rc->err.data = errstr;
if (ngx_regex_compile(rc) != NGX_OK) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "unable to compile regex pattern %V", rc->pattern);
return 0;
}
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "%V, %V", &pat, body);
if (ngx_regex_exec(rc->regex, body, captures, 2) >= 0) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "It Matched");
//ngx_memcpy(channel->data, body->data + captures[0], body->len);
return 1;
}
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "It did not match");
return 0;
}
ngx_str_t *channel = NULL;
if(match_chan(r, temp_pool, aux, channel)) {
//ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, " match: %c", match);
}
and the message that is passed looks like this
2014/07/04 13:28:49 [error] 10695#0: *38 test:([a-z0-9]+), MSG%0Atest%3Ahello%0A%0A%0Awins%00
2014/07/04 13:28:49 [error] 10695#0: *38 It did not match
taken from nginx log
ive tested the regex in a pure C app and that worked fine i thought nginx was similar but i guess it has its differences
ive looked all over google and ive tried looking at nginx modules with still no luck please help me :)
Thanks Dave