Skip to content

Commit

Permalink
Use configuration pool for provider objects
Browse files Browse the repository at this point in the history
  • Loading branch information
abedra committed Jul 12, 2019
1 parent 3dee620 commit c23bb55
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
10 changes: 5 additions & 5 deletions ngx_http_bot_verifier_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,23 +197,23 @@ ngx_http_bot_verifier_module_create_loc_conf(ngx_conf_t *cf)

char *google_domains[2] = {"google.com", "googlebot.com"};
len = sizeof(google_domains) / sizeof(google_domains[0]);
ngx_http_bot_verifier_module_provider_t *google = ngx_http_bot_verifier_module_make_provider("Google", google_domains, len);
ngx_http_bot_verifier_module_provider_t *google = ngx_http_bot_verifier_module_make_provider(cf->pool, "Google", google_domains, len);

char *bing_domains[1] = {"search.msn.com"};
len = sizeof(bing_domains) / sizeof(bing_domains[0]);
ngx_http_bot_verifier_module_provider_t *bing = ngx_http_bot_verifier_module_make_provider("Bing", bing_domains, len);
ngx_http_bot_verifier_module_provider_t *bing = ngx_http_bot_verifier_module_make_provider(cf->pool, "Bing", bing_domains, len);

char *yahoo_domains[1] = {"yahoo.com"};
len = sizeof(yahoo_domains) / sizeof(yahoo_domains[0]);
ngx_http_bot_verifier_module_provider_t *yahoo = ngx_http_bot_verifier_module_make_provider("Yahoo", yahoo_domains, len);
ngx_http_bot_verifier_module_provider_t *yahoo = ngx_http_bot_verifier_module_make_provider(cf->pool, "Yahoo", yahoo_domains, len);

char *baidu_domains[1] = {"crawl.baidu.com"};
len = sizeof(baidu_domains) / sizeof(baidu_domains[0]);
ngx_http_bot_verifier_module_provider_t *baidu = ngx_http_bot_verifier_module_make_provider("Baidu", baidu_domains, len);
ngx_http_bot_verifier_module_provider_t *baidu = ngx_http_bot_verifier_module_make_provider(cf->pool, "Baidu", baidu_domains, len);

char *yandex_domains[3] = {"yandex.com", "yandex.net", "yandex.ru"};
len = sizeof(yandex_domains) / sizeof(yandex_domains[0]);
ngx_http_bot_verifier_module_provider_t *yandex = ngx_http_bot_verifier_module_make_provider("Yandex", yandex_domains, len);
ngx_http_bot_verifier_module_provider_t *yandex = ngx_http_bot_verifier_module_make_provider(cf->pool, "Yandex", yandex_domains, len);

conf->provider_len = 5;
conf->providers = ngx_pcalloc(cf->pool, sizeof(ngx_http_bot_verifier_module_provider_t**) + conf->provider_len * sizeof(ngx_http_bot_verifier_module_provider_t*));
Expand Down
5 changes: 3 additions & 2 deletions ngx_http_bot_verifier_provider.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

#include "ngx_http_bot_verifier_provider.h"

ngx_http_bot_verifier_module_provider_t *ngx_http_bot_verifier_module_make_provider(char *name, char *valid_domains[], size_t len) {
ngx_http_bot_verifier_module_provider_t *provider = (ngx_http_bot_verifier_module_provider_t*) malloc(sizeof(ngx_http_bot_verifier_module_provider_t) + sizeof(char*) * len);
ngx_http_bot_verifier_module_provider_t
*ngx_http_bot_verifier_module_make_provider(ngx_pool_t *pool, char *name, char *valid_domains[], size_t len) {
ngx_http_bot_verifier_module_provider_t *provider = (ngx_http_bot_verifier_module_provider_t*) ngx_palloc(pool, sizeof(ngx_http_bot_verifier_module_provider_t) + sizeof(char*) * len);
provider->name = name;
provider->len = len;

Expand Down
4 changes: 3 additions & 1 deletion ngx_http_bot_verifier_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
#define __NGX_HTTP_BOT_VERIFIER_PROVIDER_H__

#include <stdlib.h>
#include <ngx_core.h>

typedef struct {
size_t len;
const char *name;
const char *valid_domains[];
} ngx_http_bot_verifier_module_provider_t;

ngx_http_bot_verifier_module_provider_t *ngx_http_bot_verifier_module_make_provider(char *name, char *valid_domains[], size_t len);
ngx_http_bot_verifier_module_provider_t
*ngx_http_bot_verifier_module_make_provider(ngx_pool_t *pool, char *name, char *valid_domains[], size_t len);

#endif

0 comments on commit c23bb55

Please sign in to comment.