Ensure subscribed list type is (re)stored to/from database table

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER 2023-07-06 21:17:40 +02:00 committed by Christian König
parent f8b8e63044
commit 444fd4c5c9
No known key found for this signature in database
2 changed files with 8 additions and 6 deletions

View File

@ -238,7 +238,7 @@ static int api_list_write(struct ftl_conn *api,
}
json_type = cJSON_GetObjectItemCaseSensitive(api->payload.json, "type");
if(cJSON_IsString(json_type) && strlen(json_type->valuestring) > 0)
row.type_int = strcasecmp(json_type->valuestring, "block") == 0 ? ADLIST_BLOCK: ADLIST_ALLOW;
row.type_int = strcasecmp(json_type->valuestring, "allow") == 0 ? ADLIST_ALLOW : ADLIST_BLOCK;
else
{
return send_json_error(api, 400,

View File

@ -1576,7 +1576,7 @@ bool gravityDB_addToTable(const enum gravity_list_type listtype, tablerow *row,
}
else if(listtype == GRAVITY_ADLISTS)
{
querystr = "INSERT INTO adlist (address,enabled,comment) VALUES (:item,:enabled,:comment);";
querystr = "INSERT INTO adlist (address,enabled,comment,type) VALUES (:item,:enabled,:comment,:type);";
}
else if(listtype == GRAVITY_CLIENTS)
{
@ -1607,10 +1607,9 @@ bool gravityDB_addToTable(const enum gravity_list_type listtype, tablerow *row,
"WHERE name = :item";
}
else if(listtype == GRAVITY_ADLISTS)
querystr = "REPLACE INTO adlist (address,enabled,comment,id,type,date_added,date_updated,number,invalid_domains,status,abp_entries) "
"VALUES (:item,:enabled,:comment,"
querystr = "REPLACE INTO adlist (address,enabled,comment,type,id,date_added,date_updated,number,invalid_domains,status,abp_entries) "
"VALUES (:item,:enabled,:comment,:type,"
"(SELECT id FROM adlist WHERE address = :item),"
"(SELECT type FROM adlist WHERE address = :item),"
"(SELECT date_added FROM adlist WHERE address = :item),"
"(SELECT date_updated FROM adlist WHERE address = :item),"
"(SELECT number FROM adlist WHERE address = :item),"
@ -2199,7 +2198,10 @@ bool gravityDB_readTableGetRow(tablerow *row, const char **message)
else if(strcasecmp(cname, "type") == 0)
{
switch(sqlite3_column_int(read_stmt, c))
// Get raw type
row->type_int = sqlite3_column_int(read_stmt, c);
// Convert to string (only applicable for domainlist)
switch(row->type_int)
{
case 0:
row->type = "allow";