Skip to content

Commit 907eab2

Browse files
committed
Rename all methods to ensure uniqueness
1 parent f13c26a commit 907eab2

10 files changed

+36
-37
lines changed

ngx_http_bot_verifier_address_tools.h

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#ifndef __NGX_HTTP_BOT_VERIFIER_ADDRESS_TOOLS_H__
22
#define __NGX_HTTP_BOT_VERIFIER_ADDRESS_TOOLS_H__
33

4-
ngx_int_t remote_address(ngx_http_request_t *r, char *xff_header, char *address);
54
ngx_int_t ngx_http_bot_verifier_module_determine_address(ngx_http_request_t *r, char *address);
65

76
#endif

ngx_http_bot_verifier_cache.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "ngx_http_bot_verifier_cache.h"
99

1010
ngx_int_t
11-
check_connection(redisContext *context) {
11+
ngx_http_bot_verifier_module_check_connection(redisContext *context) {
1212
if (context == NULL || context->err) {
1313
return NGX_ERROR;
1414
}
@@ -29,7 +29,7 @@ check_connection(redisContext *context) {
2929
}
3030

3131
void
32-
cleanup_connection(ngx_http_bot_verifier_module_loc_conf_t *loc_conf)
32+
ngx_http_bot_verifier_module_cleanup_connection(ngx_http_bot_verifier_module_loc_conf_t *loc_conf)
3333
{
3434
if (loc_conf->redis.connection != NULL) {
3535
redisFree(loc_conf->redis.connection);
@@ -38,9 +38,9 @@ cleanup_connection(ngx_http_bot_verifier_module_loc_conf_t *loc_conf)
3838
}
3939

4040
ngx_int_t
41-
reset_connection(ngx_http_bot_verifier_module_loc_conf_t *loc_conf)
41+
ngx_http_bot_verifier_module_reset_connection(ngx_http_bot_verifier_module_loc_conf_t *loc_conf)
4242
{
43-
cleanup_connection(loc_conf);
43+
ngx_http_bot_verifier_module_cleanup_connection(loc_conf);
4444
const char *host = (const char *)loc_conf->redis.host.data;
4545
int port = loc_conf->redis.port;
4646
int connection_timeout = loc_conf->redis.connection_timeout;
@@ -63,7 +63,7 @@ reset_connection(ngx_http_bot_verifier_module_loc_conf_t *loc_conf)
6363
}
6464

6565
ngx_int_t
66-
lookup_verification_status(redisContext *context, char *address)
66+
ngx_http_bot_verifier_module_lookup_verification_status(redisContext *context, char *address)
6767
{
6868
redisReply *reply;
6969

@@ -93,7 +93,7 @@ lookup_verification_status(redisContext *context, char *address)
9393
}
9494

9595
ngx_int_t
96-
persist_verification_status(ngx_http_bot_verifier_module_loc_conf_t *loc_conf, char *address, ngx_int_t status)
96+
ngx_http_bot_verifier_module_persist_verification_status(ngx_http_bot_verifier_module_loc_conf_t *loc_conf, char *address, ngx_int_t status)
9797
{
9898
redisReply *reply = NULL;
9999

ngx_http_bot_verifier_cache.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#ifndef __NGX_HTTP_BOT_VERIFIER_CACHE_H__
22
#define __NGX_HTTP_BOT_VERIFIER_CACHE_H__
33

4-
ngx_int_t check_connection(redisContext *context);
5-
void cleanup_connection(ngx_http_bot_verifier_module_loc_conf_t *loc_conf);
6-
ngx_int_t reset_connection(ngx_http_bot_verifier_module_loc_conf_t *loc_conf);
7-
ngx_int_t lookup_verification_status(redisContext *context, char *address);
8-
ngx_int_t persist_verification_status(ngx_http_bot_verifier_module_loc_conf_t *loc_conf, char *address, ngx_int_t status);
4+
ngx_int_t ngx_http_bot_verifier_module_check_connection(redisContext *context);
5+
void ngx_http_bot_verifier_module_cleanup_connection(ngx_http_bot_verifier_module_loc_conf_t *loc_conf);
6+
ngx_int_t ngx_http_bot_verifier_module_reset_connection(ngx_http_bot_verifier_module_loc_conf_t *loc_conf);
7+
ngx_int_t ngx_http_bot_verifier_module_lookup_verification_status(redisContext *context, char *address);
8+
ngx_int_t ngx_http_bot_verifier_module_persist_verification_status(ngx_http_bot_verifier_module_loc_conf_t *loc_conf, char *address, ngx_int_t status);
99

1010
#endif

ngx_http_bot_verifier_module.c

+14-14
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,22 @@ ngx_http_bot_verifier_module_handler(ngx_http_request_t *r)
2727
return NGX_DECLINED;
2828
}
2929

30-
ngx_int_t connection_status = check_connection(loc_conf->redis.connection);
30+
ngx_int_t connection_status = ngx_http_bot_verifier_module_check_connection(loc_conf->redis.connection);
3131
if (connection_status == NGX_ERROR) {
3232
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "No cache connection, creating new connection");
3333

3434
if (loc_conf->redis.connection != NULL) {
3535
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "Cache connection error: %s", loc_conf->redis.connection->errstr);
3636
}
3737

38-
connection_status = reset_connection(loc_conf);
38+
connection_status = ngx_http_bot_verifier_module_reset_connection(loc_conf);
3939

4040
if (connection_status == NGX_ERROR) {
4141
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "Unable to establish cache connection, bypassing");
4242

4343
if (loc_conf->redis.connection != NULL) {
4444
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "Cache connection error: %s", loc_conf->redis.connection->errstr);
45-
cleanup_connection(loc_conf);
45+
ngx_http_bot_verifier_module_cleanup_connection(loc_conf);
4646
}
4747

4848
return NGX_DECLINED;
@@ -58,7 +58,7 @@ ngx_http_bot_verifier_module_handler(ngx_http_request_t *r)
5858
return NGX_DECLINED;
5959
}
6060

61-
ngx_int_t verification_status = lookup_verification_status(loc_conf->redis.connection, address);
61+
ngx_int_t verification_status = ngx_http_bot_verifier_module_lookup_verification_status(loc_conf->redis.connection, address);
6262
if (verification_status == NGX_ERROR) {
6363
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "Unable to lookup verification status, bypassing");
6464
return NGX_DECLINED;
@@ -85,10 +85,10 @@ ngx_http_bot_verifier_module_handler(ngx_http_request_t *r)
8585
ret = ngx_http_bot_verifier_module_verify_bot(r, loc_conf, address);
8686
if (ret == NGX_OK) {
8787
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "Verification successful, allowing request");
88-
persist_verification_status(loc_conf, address, ret);
88+
ngx_http_bot_verifier_module_persist_verification_status(loc_conf, address, ret);
8989
} else if (ret == NGX_DECLINED) {
9090
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "Verification failed, blocking request");
91-
persist_verification_status(loc_conf, address, ret);
91+
ngx_http_bot_verifier_module_persist_verification_status(loc_conf, address, ret);
9292
return NGX_HTTP_FORBIDDEN;
9393
}
9494
}
@@ -197,38 +197,38 @@ ngx_http_bot_verifier_module_create_loc_conf(ngx_conf_t *cf)
197197

198198
char *google_domains[2] = {"google.com", "googlebot.com"};
199199
len = sizeof(google_domains) / sizeof(google_domains[0]);
200-
provider_t *google = make_provider("Google", google_domains, len);
200+
ngx_http_bot_verifier_module_provider_t *google = ngx_http_bot_verifier_module_make_provider("Google", google_domains, len);
201201

202202
char *bing_domains[1] = {"search.msn.com"};
203203
len = sizeof(bing_domains) / sizeof(bing_domains[0]);
204-
provider_t *bing = make_provider("Bing", bing_domains, len);
204+
ngx_http_bot_verifier_module_provider_t *bing = ngx_http_bot_verifier_module_make_provider("Bing", bing_domains, len);
205205

206206
char *yahoo_domains[1] = {"yahoo.com"};
207207
len = sizeof(yahoo_domains) / sizeof(yahoo_domains[0]);
208-
provider_t *yahoo = make_provider("Yahoo", yahoo_domains, len);
208+
ngx_http_bot_verifier_module_provider_t *yahoo = ngx_http_bot_verifier_module_make_provider("Yahoo", yahoo_domains, len);
209209

210210
char *baidu_domains[1] = {"crawl.baidu.com"};
211211
len = sizeof(baidu_domains) / sizeof(baidu_domains[0]);
212-
provider_t *baidu = make_provider("Baidu", baidu_domains, len);
212+
ngx_http_bot_verifier_module_provider_t *baidu = ngx_http_bot_verifier_module_make_provider("Baidu", baidu_domains, len);
213213

214214
char *yandex_domains[3] = {"yandex.com", "yandex.net", "yandex.ru"};
215215
len = sizeof(yandex_domains) / sizeof(yandex_domains[0]);
216-
provider_t *yandex = make_provider("Yandex", yandex_domains, len);
216+
ngx_http_bot_verifier_module_provider_t *yandex = ngx_http_bot_verifier_module_make_provider("Yandex", yandex_domains, len);
217217

218218
conf->provider_len = 5;
219-
conf->providers = ngx_pcalloc(cf->pool, sizeof(provider_t**) + conf->provider_len * sizeof(provider_t*));
219+
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*));
220220
conf->providers[0] = google;
221221
conf->providers[1] = yahoo;
222222
conf->providers[2] = bing;
223223
conf->providers[3] = baidu;
224224
conf->providers[4] = yandex;
225225

226226
ngx_str_t identifier_pattern = ngx_string("google|bing|yahoo|baidu|yandex");
227-
conf->identifier_regex = make_regex(cf->pool, &identifier_pattern);
227+
conf->identifier_regex = ngx_http_bot_verifier_module_make_regex(cf->pool, &identifier_pattern);
228228

229229
ngx_str_t domain_pattern = ngx_string("[^.]*\\.[^.]{2,3}(?:\\.[^.]{2,3})?$");
230230
// ngx_str_t domain_pattern = ngx_string("\\.(.*)");
231-
conf->domain_regex = make_regex(cf->pool, &domain_pattern);
231+
conf->domain_regex = ngx_http_bot_verifier_module_make_regex(cf->pool, &domain_pattern);
232232

233233
return conf;
234234
}

ngx_http_bot_verifier_module.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ typedef struct {
1818
ngx_uint_t read_timeout;
1919
ngx_uint_t expiry;
2020
redisContext *connection;
21-
} redis_t;
21+
} ngx_http_bot_verifier_module_redis_t;
2222

2323
typedef struct {
2424
ngx_flag_t enabled;
2525
ngx_flag_t repsheet_enabled;
26-
redis_t redis;
26+
ngx_http_bot_verifier_module_redis_t redis;
2727
size_t provider_len;
28-
provider_t **providers;
28+
ngx_http_bot_verifier_module_provider_t **providers;
2929
ngx_regex_compile_t *identifier_regex;
3030
ngx_regex_compile_t *domain_regex;
3131
} ngx_http_bot_verifier_module_loc_conf_t;

ngx_http_bot_verifier_provider.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
#include "ngx_http_bot_verifier_provider.h"
44

5-
provider_t *make_provider(char *name, char *valid_domains[], size_t len) {
6-
provider_t *provider = (provider_t*) malloc(sizeof(provider_t) + sizeof(char*) * len);
5+
ngx_http_bot_verifier_module_provider_t *ngx_http_bot_verifier_module_make_provider(char *name, char *valid_domains[], size_t len) {
6+
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);
77
provider->name = name;
88
provider->len = len;
99

ngx_http_bot_verifier_provider.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ typedef struct {
77
size_t len;
88
const char *name;
99
const char *valid_domains[];
10-
} provider_t;
10+
} ngx_http_bot_verifier_module_provider_t;
1111

12-
provider_t *make_provider(char *name, char *valid_domains[], size_t len);
12+
ngx_http_bot_verifier_module_provider_t *ngx_http_bot_verifier_module_make_provider(char *name, char *valid_domains[], size_t len);
1313

1414
#endif

ngx_http_bot_verifier_regex.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "ngx_http_bot_verifier_module.h"
22
#include "ngx_http_bot_verifier_regex.h"
33

4-
ngx_regex_compile_t *make_regex(ngx_pool_t *pool, ngx_str_t *pattern) {
4+
ngx_regex_compile_t *ngx_http_bot_verifier_module_make_regex(ngx_pool_t *pool, ngx_str_t *pattern) {
55
ngx_regex_compile_t *rc = ngx_pcalloc(pool, sizeof(ngx_regex_compile_t));
66
u_char errstr[NGX_MAX_CONF_ERRSTR];
77

ngx_http_bot_verifier_regex.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

44
#include <ngx_core.h>
55

6-
ngx_regex_compile_t *make_regex(ngx_pool_t *pool, ngx_str_t *pattern);
6+
ngx_regex_compile_t *ngx_http_bot_verifier_module_make_regex(ngx_pool_t *pool, ngx_str_t *pattern);
77

88
#endif

ngx_http_bot_verifier_verifier.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "ngx_http_bot_verifier_provider.h"
99

1010
ngx_int_t
11-
hostname_matches_provider_domain(ngx_http_request_t *r, char *hostname, ngx_http_bot_verifier_module_loc_conf_t *loc_conf)
11+
ngx_http_bot_verifier_module_hostname_matches_provider_domain(ngx_http_request_t *r, char *hostname, ngx_http_bot_verifier_module_loc_conf_t *loc_conf)
1212
{
1313
ngx_regex_t *re = loc_conf->domain_regex->regex;
1414
ngx_regex_compile_t rc = *loc_conf->domain_regex;
@@ -59,7 +59,7 @@ ngx_http_bot_verifier_module_verify_bot(ngx_http_request_t *r, ngx_http_bot_veri
5959
return NGX_DECLINED;
6060
}
6161

62-
ngx_int_t match_result = hostname_matches_provider_domain(r, hostname, loc_conf);
62+
ngx_int_t match_result = ngx_http_bot_verifier_module_hostname_matches_provider_domain(r, hostname, loc_conf);
6363

6464
if (match_result == NGX_DECLINED) {
6565
return match_result;

0 commit comments

Comments
 (0)