mirror of
https://github.com/pi-hole/FTL.git
synced 2024-10-26 16:52:18 +02:00
Rename routes.{c,g} -> api.{c,h} and reduce locking where this is not needed to gain more speed for the API
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
@@ -161,7 +161,7 @@ extern pthread_t DNSclientthread;
|
||||
extern pthread_t timerthread;
|
||||
|
||||
// Intentionally ignore result of function declared warn_unused_result
|
||||
#define igr(x) {__typeof__(x) __attribute__((unused)) d=(x);}
|
||||
#define igr(x) {__typeof__(x) __attribute__((unused)) d=(x);}
|
||||
|
||||
#define max(a,b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a > _b ? _a : _b; })
|
||||
#define min(a,b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a < _b ? _a : _b; })
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
# Please see LICENSE file for your rights under this license.
|
||||
|
||||
set(sources
|
||||
api.h
|
||||
api.c
|
||||
auth.c
|
||||
dns.c
|
||||
dns.h
|
||||
@@ -16,8 +18,6 @@ set(sources
|
||||
history.c
|
||||
list.c
|
||||
network.c
|
||||
routes.c
|
||||
routes.h
|
||||
settings.c
|
||||
stats_database.c
|
||||
stats.c
|
||||
|
||||
@@ -13,17 +13,12 @@
|
||||
#include "../civetweb/civetweb.h"
|
||||
#include "../webserver/http-common.h"
|
||||
#include "../webserver/json_macros.h"
|
||||
#include "routes.h"
|
||||
#include "../shmem.h"
|
||||
#include "api.h"
|
||||
#include "../config.h"
|
||||
#include "../shmem.h"
|
||||
|
||||
int api_handler(struct mg_connection *conn, void *ignored)
|
||||
{
|
||||
// Lock during API access
|
||||
lock_shm();
|
||||
|
||||
int ret = 0;
|
||||
|
||||
// Prepare API info struct
|
||||
struct ftl_conn api = {
|
||||
conn,
|
||||
@@ -41,47 +36,58 @@ int api_handler(struct mg_connection *conn, void *ignored)
|
||||
api.request->local_uri,
|
||||
api.request->query_string);
|
||||
|
||||
int ret = 0;
|
||||
/******************************** /api/dns ********************************/
|
||||
if(startsWith("/api/dns/blocking", &api))
|
||||
{
|
||||
// Locks handled internally
|
||||
ret = api_dns_blocking(&api);
|
||||
}
|
||||
else if(startsWith("/api/dns/cache", &api))
|
||||
{
|
||||
// Locks handled internally
|
||||
ret = api_dns_cache(&api);
|
||||
}
|
||||
/************ /api/domains, /api/groups, /api/lists, /api/clients ********/
|
||||
else if(startsWith("/api/domains", &api))
|
||||
{
|
||||
// Locks handled internally
|
||||
ret = api_list(&api);
|
||||
}
|
||||
else if(startsWith("/api/groups", &api))
|
||||
{
|
||||
// Locks handled internally
|
||||
ret = api_list(&api);
|
||||
}
|
||||
else if(startsWith("/api/lists", &api))
|
||||
{
|
||||
// Locks handled internally
|
||||
ret = api_list(&api);
|
||||
}
|
||||
else if(startsWith("/api/clients", &api))
|
||||
{
|
||||
// Locks handled internally
|
||||
ret = api_list(&api);
|
||||
}
|
||||
/******************************** /api/ftl ****************************/
|
||||
else if(startsWith("/api/ftl/client", &api))
|
||||
{
|
||||
// Locks not needed
|
||||
ret = api_ftl_client(&api);
|
||||
}
|
||||
else if(startsWith("/api/ftl/logs/dns", &api))
|
||||
{
|
||||
// Locks handled internally
|
||||
ret = api_ftl_logs_dns(&api);
|
||||
}
|
||||
else if(startsWith("/api/ftl/sysinfo", &api))
|
||||
{
|
||||
// Locks not needed
|
||||
ret = api_ftl_sysinfo(&api);
|
||||
}
|
||||
else if(startsWith("/api/ftl/dbinfo", &api))
|
||||
{
|
||||
// Locks not needed
|
||||
ret = api_ftl_dbinfo(&api);
|
||||
}
|
||||
/******************************** /api/network ****************************/
|
||||
@@ -92,99 +98,133 @@ int api_handler(struct mg_connection *conn, void *ignored)
|
||||
/******************************** /api/history **************************/
|
||||
else if(startsWith("/api/history/clients", &api))
|
||||
{
|
||||
lock_shm();
|
||||
ret = api_history_clients(&api);
|
||||
unlock_shm();
|
||||
}
|
||||
else if(startsWith("/api/history/queries", &api))
|
||||
{
|
||||
lock_shm();
|
||||
ret = api_history_queries(&api);
|
||||
unlock_shm();
|
||||
}
|
||||
else if(startsWith("/api/history", &api))
|
||||
{
|
||||
lock_shm();
|
||||
ret = api_history(&api);
|
||||
unlock_shm();
|
||||
}
|
||||
/******************************** /api/stats **************************/
|
||||
else if(startsWith("/api/stats/summary", &api))
|
||||
{
|
||||
lock_shm();
|
||||
ret = api_stats_summary(&api);
|
||||
unlock_shm();
|
||||
}
|
||||
else if(startsWith("/api/stats/query_types", &api))
|
||||
{
|
||||
lock_shm();
|
||||
ret = api_stats_query_types(&api);
|
||||
unlock_shm();
|
||||
}
|
||||
else if(startsWith("/api/stats/upstreams", &api))
|
||||
{
|
||||
lock_shm();
|
||||
ret = api_stats_upstreams(&api);
|
||||
unlock_shm();
|
||||
}
|
||||
else if(startsWith("/api/stats/top_domains", &api))
|
||||
{
|
||||
lock_shm();
|
||||
ret = api_stats_top_domains(false, &api);
|
||||
unlock_shm();
|
||||
}
|
||||
else if(startsWith("/api/stats/top_blocked", &api))
|
||||
{
|
||||
lock_shm();
|
||||
ret = api_stats_top_domains(true, &api);
|
||||
unlock_shm();
|
||||
}
|
||||
else if(startsWith("/api/stats/top_clients", &api))
|
||||
{
|
||||
lock_shm();
|
||||
ret = api_stats_top_clients(false, &api);
|
||||
unlock_shm();
|
||||
}
|
||||
else if(startsWith("/api/stats/top_blocked_clients", &api))
|
||||
{
|
||||
lock_shm();
|
||||
ret = api_stats_top_clients(true, &api);
|
||||
unlock_shm();
|
||||
}
|
||||
else if(startsWith("/api/stats/recent_blocked", &api))
|
||||
{
|
||||
lock_shm();
|
||||
ret = api_stats_recentblocked(&api);
|
||||
unlock_shm();
|
||||
}
|
||||
else if(startsWith("/api/stats/database/overTime/history", &api))
|
||||
{
|
||||
// Locks not needed
|
||||
ret = api_stats_database_overTime_history(&api);
|
||||
}
|
||||
else if(startsWith("/api/stats/database/top_domains", &api))
|
||||
{
|
||||
// Locks not needed
|
||||
ret = api_stats_database_top_items(false, true, &api);
|
||||
}
|
||||
else if(startsWith("/api/stats/database/top_blocked", &api))
|
||||
{
|
||||
// Locks not needed
|
||||
ret = api_stats_database_top_items(true, true, &api);
|
||||
}
|
||||
else if(startsWith("/api/stats/database/top_clients", &api))
|
||||
{
|
||||
// Locks not needed
|
||||
ret = api_stats_database_top_items(false, false, &api);
|
||||
}
|
||||
else if(startsWith("/api/stats/database/summary", &api))
|
||||
{
|
||||
// Locks not needed
|
||||
ret = api_stats_database_summary(&api);
|
||||
}
|
||||
else if(startsWith("/api/stats/database/overTime/clients", &api))
|
||||
{
|
||||
// Locks not needed
|
||||
ret = api_stats_database_overTime_clients(&api);
|
||||
}
|
||||
else if(startsWith("/api/stats/database/query_types", &api))
|
||||
{
|
||||
// Locks not needed
|
||||
ret = api_stats_database_query_types(&api);
|
||||
}
|
||||
else if(startsWith("/api/stats/database/upstreams", &api))
|
||||
{
|
||||
// Locks not needed
|
||||
ret = api_stats_database_upstreams(&api);
|
||||
}
|
||||
/******************************** /api/version ****************************/
|
||||
else if(startsWith("/api/version", &api))
|
||||
{
|
||||
// Locks not needed
|
||||
ret = api_version(&api);
|
||||
}
|
||||
/******************************** /api/auth ****************************/
|
||||
else if(startsWith("/api/auth", &api))
|
||||
{
|
||||
// Locks not needed
|
||||
ret = api_auth(&api);
|
||||
}
|
||||
/******************************** /api/settings ****************************/
|
||||
else if(startsWith("/api/settings/web", &api))
|
||||
{
|
||||
// Locks not needed
|
||||
ret = api_settings_web(&api);
|
||||
}
|
||||
/******************************** /api/settings ****************************/
|
||||
else if((api.item = startsWith("/api/docs", &api)) != NULL)
|
||||
{
|
||||
// Locks not needed
|
||||
ret = api_docs(&api);
|
||||
}
|
||||
/******************************** not found or invalid request**************/
|
||||
@@ -210,8 +250,5 @@ int api_handler(struct mg_connection *conn, void *ignored)
|
||||
api.action_path = NULL;
|
||||
}
|
||||
|
||||
// Unlock after API access
|
||||
unlock_shm();
|
||||
|
||||
return ret;
|
||||
}
|
||||
+1
-1
@@ -11,7 +11,7 @@
|
||||
#include "../FTL.h"
|
||||
#include "../webserver/http-common.h"
|
||||
#include "../webserver/json_macros.h"
|
||||
#include "routes.h"
|
||||
#include "api.h"
|
||||
#include "../log.h"
|
||||
#include "../config.h"
|
||||
// read_setupVarsconf()
|
||||
|
||||
+10
-3
@@ -12,11 +12,12 @@
|
||||
#include "dns.h"
|
||||
#include "../webserver/http-common.h"
|
||||
#include "../webserver/json_macros.h"
|
||||
#include "routes.h"
|
||||
#include "api.h"
|
||||
// {s,g}et_blockingstatus()
|
||||
#include "../setupVars.h"
|
||||
// set_blockingmode_timer()
|
||||
#include "../timers.h"
|
||||
#include "../shmem.h"
|
||||
|
||||
static int get_blocking(struct ftl_conn *api)
|
||||
{
|
||||
@@ -97,11 +98,17 @@ int api_dns_blocking(struct ftl_conn *api)
|
||||
{
|
||||
if(api->method == HTTP_GET)
|
||||
{
|
||||
return get_blocking(api);
|
||||
lock_shm();
|
||||
const int ret = get_blocking(api);
|
||||
unlock_shm();
|
||||
return ret;
|
||||
}
|
||||
else if(api->method == HTTP_POST)
|
||||
{
|
||||
return set_blocking(api);
|
||||
lock_shm();
|
||||
const int ret = set_blocking(api);
|
||||
unlock_shm();
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
#include "../../civetweb/civetweb.h"
|
||||
#include "../../webserver/http-common.h"
|
||||
#include "../../webserver/json_macros.h"
|
||||
#include "../routes.h"
|
||||
#include "../api.h"
|
||||
|
||||
static const char index_html[] = {
|
||||
#include "hex/index.html"
|
||||
|
||||
+28
-15
@@ -11,7 +11,7 @@
|
||||
#include "../FTL.h"
|
||||
#include "../webserver/http-common.h"
|
||||
#include "../webserver/json_macros.h"
|
||||
#include "routes.h"
|
||||
#include "api.h"
|
||||
// struct fifologData
|
||||
#include "../fifo.h"
|
||||
// sysinfo()
|
||||
@@ -299,7 +299,7 @@ int get_system_obj(struct ftl_conn *api, cJSON *system)
|
||||
// option is to use the MemAvailable (as opposed to MemFree) entry in
|
||||
// /proc/meminfo instead.
|
||||
long mem_total = -1, mem_used = -1, mem_free = -1, mem_avail = -1;
|
||||
GetRamInKB(&mem_total, &mem_used, &mem_free, &mem_avail);
|
||||
GetRamInKB(&mem_total, &mem_used, &mem_free, &mem_avail);
|
||||
// Total usable main memory size
|
||||
JSON_OBJ_ADD_NUMBER(ram, "total", mem_total);
|
||||
// Free memory size
|
||||
@@ -312,7 +312,7 @@ int get_system_obj(struct ftl_conn *api, cJSON *system)
|
||||
// says: "Many programs check /proc/meminfo to estimate how much free
|
||||
// memory is available. They generally do this by adding up "free" and
|
||||
// "cached", which was fine ten years ago, but is pretty much guaranteed
|
||||
// to be wrong today."
|
||||
// to be wrong today."
|
||||
JSON_OBJ_ADD_NUMBER(ram, "available", mem_avail);
|
||||
JSON_OBJ_ADD_ITEM(memory, "ram", ram);
|
||||
|
||||
@@ -390,18 +390,17 @@ int get_system_obj(struct ftl_conn *api, cJSON *system)
|
||||
int get_ftl_obj(struct ftl_conn *api, cJSON *ftl)
|
||||
{
|
||||
cJSON *database = JSON_NEW_OBJ();
|
||||
JSON_OBJ_ADD_NUMBER(database, "gravity", counters->database.gravity);
|
||||
JSON_OBJ_ADD_NUMBER(database, "groups", counters->database.groups);
|
||||
JSON_OBJ_ADD_NUMBER(database, "lists", counters->database.lists);
|
||||
JSON_OBJ_ADD_NUMBER(database, "clients", counters->database.clients);
|
||||
|
||||
cJSON *domains = JSON_NEW_OBJ();
|
||||
JSON_OBJ_ADD_NUMBER(domains, "allowed", counters->database.domains.allowed);
|
||||
JSON_OBJ_ADD_NUMBER(domains, "denied", counters->database.domains.denied);
|
||||
JSON_OBJ_ADD_ITEM(database, "domains", domains);
|
||||
JSON_OBJ_ADD_ITEM(ftl, "database", database);
|
||||
|
||||
JSON_OBJ_ADD_NUMBER(ftl, "privacy_level", config.privacylevel);
|
||||
// Source from shared objects within lock
|
||||
lock_shm();
|
||||
const int db_gravity = counters->database.gravity;
|
||||
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 clients_total = counters->clients;
|
||||
const int privacylevel = config.privacylevel;
|
||||
|
||||
// unique_clients: count only clients that have been active within the most recent 24 hours
|
||||
int activeclients = 0;
|
||||
@@ -415,9 +414,23 @@ int get_ftl_obj(struct ftl_conn *api, cJSON *ftl)
|
||||
if(client->count > 0)
|
||||
activeclients++;
|
||||
}
|
||||
unlock_shm();
|
||||
|
||||
JSON_OBJ_ADD_NUMBER(database, "gravity", db_gravity);
|
||||
JSON_OBJ_ADD_NUMBER(database, "groups", db_groups);
|
||||
JSON_OBJ_ADD_NUMBER(database, "lists", db_lists);
|
||||
JSON_OBJ_ADD_NUMBER(database, "clients", db_clients);
|
||||
|
||||
cJSON *domains = JSON_NEW_OBJ();
|
||||
JSON_OBJ_ADD_NUMBER(domains, "allowed", db_allowed);
|
||||
JSON_OBJ_ADD_NUMBER(domains, "denied", db_denied);
|
||||
JSON_OBJ_ADD_ITEM(database, "domains", domains);
|
||||
JSON_OBJ_ADD_ITEM(ftl, "database", database);
|
||||
|
||||
JSON_OBJ_ADD_NUMBER(ftl, "privacy_level", privacylevel);
|
||||
|
||||
cJSON *clients = JSON_NEW_OBJ();
|
||||
JSON_OBJ_ADD_NUMBER(clients, "total", counters->clients);
|
||||
JSON_OBJ_ADD_NUMBER(clients, "total",clients_total);
|
||||
JSON_OBJ_ADD_NUMBER(clients, "active", activeclients);
|
||||
JSON_OBJ_ADD_ITEM(ftl, "clients", clients);
|
||||
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@
|
||||
#include "../FTL.h"
|
||||
#include "../webserver/http-common.h"
|
||||
#include "../webserver/json_macros.h"
|
||||
#include "routes.h"
|
||||
#include "api.h"
|
||||
#include "../shmem.h"
|
||||
#include "../datastructure.h"
|
||||
// overTime data
|
||||
|
||||
+34
-5
@@ -11,9 +11,10 @@
|
||||
#include "../FTL.h"
|
||||
#include "../webserver/http-common.h"
|
||||
#include "../webserver/json_macros.h"
|
||||
#include "routes.h"
|
||||
#include "api.h"
|
||||
#include "../database/gravity-db.h"
|
||||
#include "../events.h"
|
||||
#include "../shmem.h"
|
||||
// getNameFromIP()
|
||||
#include "../database/network-table.h"
|
||||
|
||||
@@ -415,7 +416,13 @@ int api_list(struct ftl_conn *api)
|
||||
if(api->method == HTTP_GET)
|
||||
{
|
||||
// Read list item identified by URI (or read them all)
|
||||
return api_list_read(api, 200, listtype, api->item);
|
||||
// We would not actually need the SHM lock here, however, we do
|
||||
// this for simplicity to ensure nobody else is editing the
|
||||
// lists while we're doing this here
|
||||
lock_shm();
|
||||
const int ret = api_list_read(api, 200, listtype, api->item);
|
||||
unlock_shm();
|
||||
return ret;
|
||||
}
|
||||
else if(can_modify && api->method == HTTP_PUT)
|
||||
{
|
||||
@@ -428,7 +435,15 @@ int api_list(struct ftl_conn *api)
|
||||
NULL);
|
||||
}
|
||||
else
|
||||
return api_list_write(api, listtype, api->item, payload);
|
||||
{
|
||||
// We would not actually need the SHM lock here,
|
||||
// however, we do this for simplicity to ensure nobody
|
||||
// else is editing the lists while we're doing this here
|
||||
lock_shm();
|
||||
const int ret = api_list_write(api, listtype, api->item, payload);
|
||||
unlock_shm();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
else if(can_modify && api->method == HTTP_POST)
|
||||
{
|
||||
@@ -441,12 +456,26 @@ int api_list(struct ftl_conn *api)
|
||||
NULL);
|
||||
}
|
||||
else
|
||||
return api_list_write(api, listtype, api->item, payload);
|
||||
{
|
||||
// We would not actually need the SHM lock here,
|
||||
// however, we do this for simplicity to ensure nobody
|
||||
// else is editing the lists while we're doing this here
|
||||
lock_shm();
|
||||
const int ret = api_list_write(api, listtype, api->item, payload);
|
||||
unlock_shm();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
else if(can_modify && api->method == HTTP_DELETE)
|
||||
{
|
||||
// Delete item from list
|
||||
return api_list_remove(api, listtype, api->item);
|
||||
// We would not actually need the SHM lock here, however, we do
|
||||
// this for simplicity to ensure nobody else is editing the
|
||||
// lists while we're doing this here
|
||||
lock_shm();
|
||||
const int ret = api_list_remove(api, listtype, api->item);
|
||||
unlock_shm();
|
||||
return ret;
|
||||
}
|
||||
else if(!can_modify)
|
||||
{
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@
|
||||
#include "../FTL.h"
|
||||
#include "../webserver/http-common.h"
|
||||
#include "../webserver/json_macros.h"
|
||||
#include "routes.h"
|
||||
#include "api.h"
|
||||
// networkrecord
|
||||
#include "../database/network-table.h"
|
||||
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@
|
||||
#include "../FTL.h"
|
||||
#include "../webserver/http-common.h"
|
||||
#include "../webserver/json_macros.h"
|
||||
#include "routes.h"
|
||||
#include "api.h"
|
||||
|
||||
int api_settings_web(struct ftl_conn *api)
|
||||
{
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@
|
||||
#include "../FTL.h"
|
||||
#include "../webserver/http-common.h"
|
||||
#include "../webserver/json_macros.h"
|
||||
#include "routes.h"
|
||||
#include "api.h"
|
||||
#include "../shmem.h"
|
||||
#include "../datastructure.h"
|
||||
// read_setupVarsconf()
|
||||
|
||||
@@ -11,8 +11,7 @@
|
||||
#include "../FTL.h"
|
||||
#include "../webserver/http-common.h"
|
||||
#include "../webserver/json_macros.h"
|
||||
#include "routes.h"
|
||||
#include "../shmem.h"
|
||||
#include "api.h"
|
||||
// querytypes[]
|
||||
#include "../datastructure.h"
|
||||
// logg()
|
||||
@@ -39,9 +38,6 @@ int api_stats_database_overTime_history(struct ftl_conn *api)
|
||||
NULL);
|
||||
}
|
||||
|
||||
// Unlock shared memory (DNS resolver can continue to work while we're preforming database queries)
|
||||
unlock_shm();
|
||||
|
||||
// Open the database (this also locks the database)
|
||||
dbopen();
|
||||
|
||||
@@ -69,9 +65,6 @@ int api_stats_database_overTime_history(struct ftl_conn *api)
|
||||
sqlite3_finalize(stmt);
|
||||
dbclose();
|
||||
|
||||
// Relock shared memory
|
||||
lock_shm();
|
||||
|
||||
return send_json_error(api, 500,
|
||||
"internal_error",
|
||||
"Failed to bind interval",
|
||||
@@ -87,9 +80,6 @@ int api_stats_database_overTime_history(struct ftl_conn *api)
|
||||
sqlite3_finalize(stmt);
|
||||
dbclose();
|
||||
|
||||
// Relock shared memory
|
||||
lock_shm();
|
||||
|
||||
return send_json_error(api, 500,
|
||||
"internal_error",
|
||||
"Failed to bind from",
|
||||
@@ -105,9 +95,6 @@ int api_stats_database_overTime_history(struct ftl_conn *api)
|
||||
sqlite3_finalize(stmt);
|
||||
dbclose();
|
||||
|
||||
// Relock shared memory
|
||||
lock_shm();
|
||||
|
||||
return send_json_error(api, 500,
|
||||
"internal_error",
|
||||
"Failed to bind until",
|
||||
@@ -164,8 +151,6 @@ int api_stats_database_overTime_history(struct ftl_conn *api)
|
||||
sqlite3_finalize(stmt);
|
||||
dbclose();
|
||||
|
||||
// Re-lock shared memory before returning back to router subroutine
|
||||
lock_shm();
|
||||
JSON_SEND_OBJECT(json);
|
||||
}
|
||||
|
||||
@@ -196,9 +181,6 @@ int api_stats_database_top_items(bool blocked, bool domains, struct ftl_conn *ap
|
||||
NULL);
|
||||
}
|
||||
|
||||
// Unlock shared memory (DNS resolver can continue to work while we're preforming database queries)
|
||||
unlock_shm();
|
||||
|
||||
// Open the database (this also locks the database)
|
||||
dbopen();
|
||||
|
||||
@@ -253,9 +235,6 @@ int api_stats_database_top_items(bool blocked, bool domains, struct ftl_conn *ap
|
||||
|
||||
dbclose();
|
||||
|
||||
// Relock shared memory
|
||||
lock_shm();
|
||||
|
||||
return send_json_error(api, 500,
|
||||
"internal_error",
|
||||
"Failed to prepare query string",
|
||||
@@ -271,9 +250,6 @@ int api_stats_database_top_items(bool blocked, bool domains, struct ftl_conn *ap
|
||||
sqlite3_finalize(stmt);
|
||||
dbclose();
|
||||
|
||||
// Relock shared memory
|
||||
lock_shm();
|
||||
|
||||
return send_json_error(api, 500,
|
||||
"internal_error",
|
||||
"Failed to bind from",
|
||||
@@ -289,9 +265,6 @@ int api_stats_database_top_items(bool blocked, bool domains, struct ftl_conn *ap
|
||||
sqlite3_finalize(stmt);
|
||||
dbclose();
|
||||
|
||||
// Relock shared memory
|
||||
lock_shm();
|
||||
|
||||
return send_json_error(api, 500,
|
||||
"internal_error",
|
||||
"Failed to bind until",
|
||||
@@ -307,9 +280,6 @@ int api_stats_database_top_items(bool blocked, bool domains, struct ftl_conn *ap
|
||||
sqlite3_finalize(stmt);
|
||||
dbclose();
|
||||
|
||||
// Relock shared memory
|
||||
lock_shm();
|
||||
|
||||
return send_json_error(api, 500,
|
||||
"internal_error",
|
||||
"Failed to bind show",
|
||||
@@ -339,9 +309,6 @@ int api_stats_database_top_items(bool blocked, bool domains, struct ftl_conn *ap
|
||||
sqlite3_finalize(stmt);
|
||||
dbclose();
|
||||
|
||||
// Re-lock shared memory before returning back to router subroutine
|
||||
lock_shm();
|
||||
|
||||
cJSON *json = JSON_NEW_OBJ();
|
||||
JSON_OBJ_ADD_ITEM(json, (domains ? "top_domains" : "top_clients"), top_items);
|
||||
JSON_OBJ_ADD_NUMBER(json, (blocked ? "blocked_queries" : "total_queries"), total);
|
||||
@@ -366,9 +333,6 @@ int api_stats_database_summary(struct ftl_conn *api)
|
||||
NULL);
|
||||
}
|
||||
|
||||
// Unlock shared memory (DNS resolver can continue to work while we're preforming database queries)
|
||||
unlock_shm();
|
||||
|
||||
// Open the database (this also locks the database)
|
||||
dbopen();
|
||||
|
||||
@@ -395,9 +359,6 @@ int api_stats_database_summary(struct ftl_conn *api)
|
||||
// Close (= unlock) database connection
|
||||
dbclose();
|
||||
|
||||
// Relock shared memory
|
||||
lock_shm();
|
||||
|
||||
return send_json_error(api, 500,
|
||||
"internal_error",
|
||||
"Internal server error",
|
||||
@@ -415,9 +376,6 @@ int api_stats_database_summary(struct ftl_conn *api)
|
||||
// Close (= unlock) database connection
|
||||
dbclose();
|
||||
|
||||
// Re-lock shared memory before returning back to router subroutine
|
||||
lock_shm();
|
||||
|
||||
// Send JSON object
|
||||
JSON_SEND_OBJECT(json);
|
||||
}
|
||||
@@ -441,9 +399,6 @@ int api_stats_database_overTime_clients(struct ftl_conn *api)
|
||||
NULL);
|
||||
}
|
||||
|
||||
// Unlock shared memory (DNS resolver can continue to work while we're preforming database queries)
|
||||
unlock_shm();
|
||||
|
||||
// Open the database (this also locks the database)
|
||||
dbopen();
|
||||
|
||||
@@ -458,9 +413,6 @@ int api_stats_database_overTime_clients(struct ftl_conn *api)
|
||||
logg("api_stats_database_overTime_clients() - SQL error prepare outer (%i): %s",
|
||||
rc, sqlite3_errmsg(FTL_db));
|
||||
|
||||
// Relock shared memory
|
||||
lock_shm();
|
||||
|
||||
return send_json_error(api, 500,
|
||||
"internal_error",
|
||||
"Failed to prepare outer statement",
|
||||
@@ -476,9 +428,6 @@ int api_stats_database_overTime_clients(struct ftl_conn *api)
|
||||
sqlite3_finalize(stmt);
|
||||
dbclose();
|
||||
|
||||
// Relock shared memory
|
||||
lock_shm();
|
||||
|
||||
return send_json_error(api, 500,
|
||||
"internal_error",
|
||||
"Failed to bind from",
|
||||
@@ -494,9 +443,6 @@ int api_stats_database_overTime_clients(struct ftl_conn *api)
|
||||
sqlite3_finalize(stmt);
|
||||
dbclose();
|
||||
|
||||
// Relock shared memory
|
||||
lock_shm();
|
||||
|
||||
return send_json_error(api, 500,
|
||||
"internal_error",
|
||||
"Failed to bind until",
|
||||
@@ -528,9 +474,6 @@ int api_stats_database_overTime_clients(struct ftl_conn *api)
|
||||
logg("api_stats_database_overTime_clients() - SQL error prepare (%i): %s",
|
||||
rc, sqlite3_errmsg(FTL_db));
|
||||
|
||||
// Relock shared memory
|
||||
lock_shm();
|
||||
|
||||
return send_json_error(api, 500,
|
||||
"internal_error",
|
||||
"Failed to prepare inner statement",
|
||||
@@ -546,9 +489,6 @@ int api_stats_database_overTime_clients(struct ftl_conn *api)
|
||||
sqlite3_finalize(stmt);
|
||||
dbclose();
|
||||
|
||||
// Relock shared memory
|
||||
lock_shm();
|
||||
|
||||
return send_json_error(api, 500,
|
||||
"internal_error",
|
||||
"Failed to bind interval",
|
||||
@@ -564,9 +504,6 @@ int api_stats_database_overTime_clients(struct ftl_conn *api)
|
||||
sqlite3_finalize(stmt);
|
||||
dbclose();
|
||||
|
||||
// Relock shared memory
|
||||
lock_shm();
|
||||
|
||||
return send_json_error(api, 500,
|
||||
"internal_error",
|
||||
"Failed to bind from",
|
||||
@@ -582,9 +519,6 @@ int api_stats_database_overTime_clients(struct ftl_conn *api)
|
||||
sqlite3_finalize(stmt);
|
||||
dbclose();
|
||||
|
||||
// Relock shared memory
|
||||
lock_shm();
|
||||
|
||||
return send_json_error(api, 500,
|
||||
"internal_error",
|
||||
"Failed to bind until",
|
||||
@@ -650,8 +584,6 @@ int api_stats_database_overTime_clients(struct ftl_conn *api)
|
||||
sqlite3_finalize(stmt);
|
||||
dbclose();
|
||||
|
||||
// Re-lock shared memory before returning back to router subroutine
|
||||
lock_shm();
|
||||
cJSON *json = JSON_NEW_OBJ();
|
||||
JSON_OBJ_ADD_ITEM(json, "over_time", over_time);
|
||||
JSON_OBJ_ADD_ITEM(json, "clients", clients);
|
||||
@@ -676,9 +608,6 @@ int api_stats_database_query_types(struct ftl_conn *api)
|
||||
NULL);
|
||||
}
|
||||
|
||||
// Unlock shared memory (DNS resolver can continue to work while we're preforming database queries)
|
||||
unlock_shm();
|
||||
|
||||
// Open the database (this also locks the database)
|
||||
dbopen();
|
||||
|
||||
@@ -699,9 +628,6 @@ int api_stats_database_query_types(struct ftl_conn *api)
|
||||
// Close (= unlock) database connection
|
||||
dbclose();
|
||||
|
||||
// Re-lock shared memory before returning back to router subroutine
|
||||
lock_shm();
|
||||
|
||||
// Send JSON object
|
||||
cJSON *json = JSON_NEW_OBJ();
|
||||
JSON_OBJ_ADD_ITEM(json, "types", types);
|
||||
@@ -727,9 +653,6 @@ int api_stats_database_upstreams(struct ftl_conn *api)
|
||||
NULL);
|
||||
}
|
||||
|
||||
// Unlock shared memory (DNS resolver can continue to work while we're preforming database queries)
|
||||
unlock_shm();
|
||||
|
||||
// Open the database (this also locks the database)
|
||||
dbopen();
|
||||
|
||||
@@ -760,9 +683,6 @@ int api_stats_database_upstreams(struct ftl_conn *api)
|
||||
logg("api_stats_database_overTime_clients() - SQL error prepare (%i): %s",
|
||||
rc, sqlite3_errmsg(FTL_db));
|
||||
|
||||
// Relock shared memory
|
||||
lock_shm();
|
||||
|
||||
return send_json_error(api, 500,
|
||||
"internal_error",
|
||||
"Failed to prepare statement",
|
||||
@@ -778,9 +698,6 @@ int api_stats_database_upstreams(struct ftl_conn *api)
|
||||
sqlite3_finalize(stmt);
|
||||
dbclose();
|
||||
|
||||
// Relock shared memory
|
||||
lock_shm();
|
||||
|
||||
return send_json_error(api, 500,
|
||||
"internal_error",
|
||||
"Failed to bind from",
|
||||
@@ -796,9 +713,6 @@ int api_stats_database_upstreams(struct ftl_conn *api)
|
||||
sqlite3_finalize(stmt);
|
||||
dbclose();
|
||||
|
||||
// Relock shared memory
|
||||
lock_shm();
|
||||
|
||||
return send_json_error(api, 500,
|
||||
"internal_error",
|
||||
"Failed to bind until",
|
||||
@@ -840,9 +754,6 @@ int api_stats_database_upstreams(struct ftl_conn *api)
|
||||
// Close (= unlock) database connection
|
||||
dbclose();
|
||||
|
||||
// Re-lock shared memory before returning back to router subroutine
|
||||
lock_shm();
|
||||
|
||||
// Send JSON object
|
||||
cJSON *json = JSON_NEW_OBJ();
|
||||
JSON_OBJ_ADD_ITEM(json, "upstreams", upstreams);
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@
|
||||
#include "../FTL.h"
|
||||
#include "../webserver/http-common.h"
|
||||
#include "../webserver/json_macros.h"
|
||||
#include "routes.h"
|
||||
#include "api.h"
|
||||
// get_FTL_version()
|
||||
#include "../log.h"
|
||||
#include "../version.h"
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
// enum privacy_level
|
||||
#include "enums.h"
|
||||
|
||||
// assert_sizeof
|
||||
#include "static_assert.h"
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
* Please see LICENSE file for your rights under this license. */
|
||||
|
||||
#include "../FTL.h"
|
||||
#include "../api/routes.h"
|
||||
#include "../api/api.h"
|
||||
// send_http()
|
||||
#include "http-common.h"
|
||||
// struct httpsettings
|
||||
|
||||
Reference in New Issue
Block a user