Skip to content

Commit

Permalink
remove str_to_char
Browse files Browse the repository at this point in the history
  • Loading branch information
fzipi committed Mar 9, 2022
1 parent b9dbfcd commit 1758ec8
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 28 deletions.
1 change: 0 additions & 1 deletion src/ngx_http_coraza_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ extern ngx_module_t ngx_http_coraza_module;
/* ngx_http_coraza_module.c */
ngx_int_t ngx_http_coraza_process_intervention (coraza_transaction_t *transaction, ngx_http_request_t *r, ngx_int_t early_log);
ngx_http_coraza_ctx_t *ngx_http_coraza_create_ctx(ngx_http_request_t *r);
char *ngx_str_to_char(ngx_str_t a, ngx_pool_t *p);

/* ngx_http_coraza_body_filter.c */
ngx_int_t ngx_http_coraza_body_filter_init(void);
Expand Down
28 changes: 1 addition & 27 deletions src/ngx_http_coraza_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,6 @@ static char *ngx_http_coraza_merge_conf(ngx_conf_t *cf, void *parent, void *chil
static void ngx_http_coraza_cleanup_instance(void *data);
static void ngx_http_coraza_cleanup_rules(void *data);

/*
* ngx_string's are not null-terminated in common case, so we need to convert
* them into null-terminated ones before passing to CORAZA
*/
ngx_inline ngx_int_t ngx_str_to_char(ngx_str_t a, char* res, ngx_pool_t *p)
{
char *res = NULL;

if (a.len == 0)
{
return NGX_OK;
}

str = ngx_pnalloc(p, a.len + 1);
if (str == NULL)
{
dd("failed to allocate memory to convert space ngx_string to C string");
/* We already returned NULL for an empty string, so return -1 here to indicate allocation error */
return (char *)-1;
}
ngx_memcpy(str, a.data, a.len);
str[a.len] = '\0';

return str;
}

ngx_inline ngx_int_t
ngx_http_coraza_process_intervention(coraza_transaction_t *transaction, ngx_http_request_t *r, ngx_int_t early_log)
{
Expand Down Expand Up @@ -560,7 +534,7 @@ ngx_http_coraza_merge_conf(ngx_conf_t *cf, void *parent, void *child)
#if defined(CORAZA_DDEBUG) && (CORAZA_DDEBUG)
ngx_http_core_loc_conf_t *clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
dd("merging loc config [%s] - parent: '%p' child: '%p'",
ngx_str_to_char(clcf->name, cf->pool), parent,
clcf->name.data, parent,
child);
#endif
int rules;
Expand Down

0 comments on commit 1758ec8

Please sign in to comment.