Add more debugging output to getstr()

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2022-08-20 14:23:21 +02:00
parent 15942b17ce
commit da33517553
5 changed files with 13 additions and 11 deletions
+4 -3
View File
@@ -1158,7 +1158,7 @@ static bool check_domain_blocked(const char *domain, const int clientID,
// Check domain against blacklist regex filters
// Skipped when the domain is whitelisted or blocked by exact blacklist or gravity
if(in_regex(domain, dns_cache, client-> id, REGEX_BLACKLIST) == FOUND)
if(in_regex(domain, dns_cache, client-> id, REGEX_BLACKLIST))
{
// Set new status
*new_status = QUERY_REGEX;
@@ -1409,11 +1409,12 @@ static bool _FTL_check_blocking(int queryID, int domainID, int clientID, const c
domainstr = strdup(domainstr);
const char *blockedDomain = domainstr;
// Check whitelist (exact + regex) for match
// Check exact whitelist for match
query->flags.whitelisted = in_whitelist(domainstr, dns_cache, client) == FOUND;
// If not found: Check regex whitelist for match
if(!query->flags.whitelisted)
query->flags.whitelisted = in_regex(domainstr, dns_cache, client->id, REGEX_WHITELIST) == FOUND;
query->flags.whitelisted = in_regex(domainstr, dns_cache, client->id, REGEX_WHITELIST);
// Check blacklist (exact + regex) and gravity for queried domain
unsigned char new_status = QUERY_UNKNOWN;
+3 -3
View File
@@ -475,7 +475,7 @@ static int match_regex(const char *input, DNSCacheData* dns_cache, const int cli
return match_idx;
}
enum db_result in_regex(const char *domain, DNSCacheData *dns_cache, const int clientID, const enum regex_type regexid)
bool in_regex(const char *domain, DNSCacheData *dns_cache, const int clientID, const enum regex_type regexid)
{
// For performance reasons, the regex evaluations is executed only if the
// exact whitelist lookup does not deliver a positive match. This is an
@@ -487,10 +487,10 @@ enum db_result in_regex(const char *domain, DNSCacheData *dns_cache, const int c
{
// We found a match
dns_cache->domainlist_id = regex_id;
return FOUND;
return true;
}
return NOT_FOUND;
return false;
}
static void free_regex(void)
+1 -1
View File
@@ -44,7 +44,7 @@ typedef struct {
} regexData;
unsigned int get_num_regex(const enum regex_type regexid) __attribute__((pure));
enum db_result in_regex(const char *domain, DNSCacheData *dns_cache, const int clientID, const enum regex_type regexid);
bool in_regex(const char *domain, DNSCacheData *dns_cache, const int clientID, const enum regex_type regexid);
void allocate_regex_client_enabled(clientsData *client, const int clientID);
void reload_per_client_regex(clientsData *client);
void read_regex_from_database(void);
+3 -3
View File
@@ -272,14 +272,14 @@ size_t addstr(const char *input)
return (shmSettings->next_str_pos - len);
}
const char *getstr(const size_t pos)
const char *_getstr(const size_t pos, const char *func, const int line, const char *file)
{
// Only access the string memory if this memory region has already been set
if(pos < shmSettings->next_str_pos)
return &((const char*)shm_strings.ptr)[pos];
else
{
logg("WARN: Tried to access %zu but next_str_pos is %u", pos, shmSettings->next_str_pos);
logg("WARN: Tried to access %zu in %s() (%s:%i) but next_str_pos is %u", pos, func, file, line, shmSettings->next_str_pos);
return "";
}
}
@@ -337,7 +337,7 @@ static void remap_shm(void)
}
// Obtain SHMEM lock
void _lock_shm(const char* func, const int line, const char * file)
void _lock_shm(const char *func, const int line, const char *file)
{
if(config.debug & DEBUG_LOCKS)
logg("Waiting for SHM lock in %s() (%s:%i)", func, file, line);
+2 -1
View File
@@ -102,7 +102,8 @@ void _unlock_log(const char* func, const int line, const char * file);
bool init_shmem(bool create_new);
void destroy_shmem(void);
size_t addstr(const char *str);
const char *getstr(const size_t pos);
#define getstr(pos) _getstr(pos, __FUNCTION__, __LINE__, __FILE__)
const char *_getstr(const size_t pos, const char *func, const int line, const char *file);
/**
* Escapes a string by replacing special characters, such as spaces