Skip to content

Commit

Permalink
Disentangle info/ftl : ftl.database.domains from newly added ftl.data…
Browse files Browse the repository at this point in the history
…base.regex

Signed-off-by: DL6ER <[email protected]>
  • Loading branch information
DL6ER committed Sep 25, 2024
1 parent 361e0ce commit 92e2590
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 16 deletions.
11 changes: 11 additions & 0 deletions src/api/docs/content/specs/info.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,17 @@ components:
type: integer
description: Number of denied domains
example: 3
regex:
type: object
properties:
allowed:
type: integer
description: Number of allowed regex filters
example: 4
denied:
type: integer
description: Number of denied regex filters
example: 2
privacy_level:
type: integer
description: Currently used privacy level
Expand Down
15 changes: 11 additions & 4 deletions src/api/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,10 @@ static int get_ftl_obj(struct ftl_conn *api, cJSON *ftl)
const int db_groups = counters->database.groups;
const int db_lists = counters->database.lists;
const int db_clients = counters->database.clients;
const int db_allowed = counters->database.domains.allowed;
const int db_denied = counters->database.domains.denied;
const int db_allowed_exact = counters->database.domains.allowed.exact;
const int db_denied_exact = counters->database.domains.denied.exact;
const int db_allowed_regex = counters->database.domains.allowed.regex;
const int db_denied_regex = counters->database.domains.denied.regex;
const int clients_total = counters->clients;
const int privacylevel = config.misc.privacylevel.v.privacy_level;
const double qps = get_qps();
Expand All @@ -570,9 +572,14 @@ static int get_ftl_obj(struct ftl_conn *api, cJSON *ftl)
JSON_ADD_NUMBER_TO_OBJECT(database, "clients", db_clients);

cJSON *domains = JSON_NEW_OBJECT();
JSON_ADD_NUMBER_TO_OBJECT(domains, "allowed", db_allowed);
JSON_ADD_NUMBER_TO_OBJECT(domains, "denied", db_denied);
JSON_ADD_NUMBER_TO_OBJECT(domains, "allowed", db_allowed_exact);
JSON_ADD_NUMBER_TO_OBJECT(domains, "denied", db_denied_exact);
JSON_ADD_ITEM_TO_OBJECT(database, "domains", domains);

cJSON *regex = JSON_NEW_OBJECT();
JSON_ADD_NUMBER_TO_OBJECT(regex, "allowed", db_allowed_regex);
JSON_ADD_NUMBER_TO_OBJECT(regex, "denied", db_denied_regex);
JSON_ADD_ITEM_TO_OBJECT(database, "regex", regex);
JSON_ADD_ITEM_TO_OBJECT(ftl, "database", database);

JSON_ADD_NUMBER_TO_OBJECT(ftl, "privacy_level", privacylevel);
Expand Down
6 changes: 0 additions & 6 deletions src/database/gravity-db.c
Original file line number Diff line number Diff line change
Expand Up @@ -1112,12 +1112,6 @@ int gravityDB_count(const enum gravity_tables list)
case ADLISTS_TABLE:
querystr = "SELECT COUNT(1) FROM adlist WHERE enabled != 0";
break;
case DENIED_DOMAINS_TABLE:
querystr = "SELECT COUNT(1) FROM domainlist WHERE (type = 0 OR type = 2) AND enabled != 0";
break;
case ALLOWED_DOMAINS_TABLE:
querystr = "SELECT COUNT(1) FROM domainlist WHERE (type = 1 OR type = 3) AND enabled != 0";
break;
case UNKNOWN_TABLE:
log_err("List type %u unknown!", list);
gravityDB_close();
Expand Down
6 changes: 4 additions & 2 deletions src/datastructure.c
Original file line number Diff line number Diff line change
Expand Up @@ -594,8 +594,10 @@ void FTL_reload_all_domainlists(void)
counters->database.groups = gravityDB_count(GROUPS_TABLE);
counters->database.clients = gravityDB_count(CLIENTS_TABLE);
counters->database.lists = gravityDB_count(ADLISTS_TABLE);
counters->database.domains.allowed = gravityDB_count(DENIED_DOMAINS_TABLE);
counters->database.domains.denied = gravityDB_count(ALLOWED_DOMAINS_TABLE);
counters->database.domains.allowed.exact = gravityDB_count(EXACT_WHITELIST_TABLE);
counters->database.domains.denied.exact = gravityDB_count(EXACT_BLACKLIST_TABLE);
counters->database.domains.allowed.regex = gravityDB_count(REGEX_ALLOW_TABLE);
counters->database.domains.denied.regex = gravityDB_count(REGEX_DENY_TABLE);

// Read and compile possible regex filters
// only after having called gravityDB_reopen()
Expand Down
2 changes: 0 additions & 2 deletions src/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,6 @@ enum gravity_tables {
CLIENTS_TABLE,
GROUPS_TABLE,
ADLISTS_TABLE,
DENIED_DOMAINS_TABLE,
ALLOWED_DOMAINS_TABLE,
UNKNOWN_TABLE
} __attribute__ ((packed));

Expand Down
10 changes: 8 additions & 2 deletions src/shmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,14 @@ typedef struct {
int groups;
int lists;
struct {
int allowed;
int denied;
struct {
int exact;
int regex;
} allowed;
struct {
int exact;
int regex;
} denied;
} domains;
} database;
int querytype[TYPE_MAX];
Expand Down

0 comments on commit 92e2590

Please sign in to comment.