2 Commits

10 changed files with 17810 additions and 16694 deletions

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

6680
debug.log

File diff suppressed because it is too large Load Diff

View File

@@ -181,16 +181,23 @@ cJSON* admin_cmd_config_query(cJSON* args) {
return response; return response;
} }
// Check if specific keys were requested (args[1] should be array of keys or null for all) // Check if specific keys were requested (args[1] should be array of keys, null, or "all" for all)
cJSON* keys_array = NULL; cJSON* keys_array = NULL;
if (cJSON_GetArraySize(args) >= 2) { if (cJSON_GetArraySize(args) >= 2) {
keys_array = cJSON_GetArrayItem(args, 1); keys_array = cJSON_GetArrayItem(args, 1);
// Accept array, null, or string "all" for querying all configs
if (!cJSON_IsArray(keys_array) && !cJSON_IsNull(keys_array)) { if (!cJSON_IsArray(keys_array) && !cJSON_IsNull(keys_array)) {
cJSON_AddStringToObject(response, "status", "error"); // Check if it's the string "all"
cJSON_AddStringToObject(response, "error", "Keys parameter must be array or null"); if (cJSON_IsString(keys_array) && strcmp(keys_array->valuestring, "all") == 0) {
cJSON_AddNumberToObject(response, "timestamp", (double)time(NULL)); // Treat "all" as null (query all configs)
sqlite3_close(db); keys_array = NULL;
return response; } else {
cJSON_AddStringToObject(response, "status", "error");
cJSON_AddStringToObject(response, "error", "Keys parameter must be array, null, or \"all\"");
cJSON_AddNumberToObject(response, "timestamp", (double)time(NULL));
sqlite3_close(db);
return response;
}
} }
} }
@@ -273,18 +280,18 @@ cJSON* admin_cmd_config_update(cJSON* args) {
cJSON* response = cJSON_CreateObject(); cJSON* response = cJSON_CreateObject();
cJSON_AddStringToObject(response, "query_type", "config_update"); cJSON_AddStringToObject(response, "query_type", "config_update");
// Expected format: ["config_update", {"key1": "value1", "key2": "value2"}] // Expected format: ["config_update", [{key: "x", value: "y", data_type: "z", category: "w"}]]
if (cJSON_GetArraySize(args) < 2) { if (cJSON_GetArraySize(args) < 2) {
cJSON_AddStringToObject(response, "status", "error"); cJSON_AddStringToObject(response, "status", "error");
cJSON_AddStringToObject(response, "error", "Missing config updates object"); cJSON_AddStringToObject(response, "error", "Missing config updates array");
cJSON_AddNumberToObject(response, "timestamp", (double)time(NULL)); cJSON_AddNumberToObject(response, "timestamp", (double)time(NULL));
return response; return response;
} }
cJSON* updates = cJSON_GetArrayItem(args, 1); cJSON* updates = cJSON_GetArrayItem(args, 1);
if (!cJSON_IsObject(updates)) { if (!cJSON_IsArray(updates)) {
cJSON_AddStringToObject(response, "status", "error"); cJSON_AddStringToObject(response, "status", "error");
cJSON_AddStringToObject(response, "error", "Updates must be an object"); cJSON_AddStringToObject(response, "error", "Updates must be an array of config objects");
cJSON_AddNumberToObject(response, "timestamp", (double)time(NULL)); cJSON_AddNumberToObject(response, "timestamp", (double)time(NULL));
return response; return response;
} }
@@ -311,50 +318,66 @@ cJSON* admin_cmd_config_update(cJSON* args) {
return response; return response;
} }
// Process each update // Process each update - expecting array of config objects
cJSON* updated_keys = cJSON_CreateArray(); cJSON* data_array = cJSON_CreateArray();
cJSON* failed_keys = cJSON_CreateArray();
int success_count = 0; int success_count = 0;
int fail_count = 0; int fail_count = 0;
cJSON* item = NULL; cJSON* config_obj = NULL;
cJSON_ArrayForEach(item, updates) { cJSON_ArrayForEach(config_obj, updates) {
const char* key = item->string; if (!cJSON_IsObject(config_obj)) {
const char* value = cJSON_GetStringValue(item);
if (!value) {
cJSON_AddItemToArray(failed_keys, cJSON_CreateString(key));
fail_count++; fail_count++;
continue; continue;
} }
cJSON* key_item = cJSON_GetObjectItem(config_obj, "key");
cJSON* value_item = cJSON_GetObjectItem(config_obj, "value");
if (!cJSON_IsString(key_item) || !cJSON_IsString(value_item)) {
fail_count++;
continue;
}
const char* key = key_item->valuestring;
const char* value = value_item->valuestring;
sqlite3_reset(stmt); sqlite3_reset(stmt);
sqlite3_bind_text(stmt, 1, value, -1, SQLITE_TRANSIENT); sqlite3_bind_text(stmt, 1, value, -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt, 2, key, -1, SQLITE_TRANSIENT); sqlite3_bind_text(stmt, 2, key, -1, SQLITE_TRANSIENT);
rc = sqlite3_step(stmt); rc = sqlite3_step(stmt);
// Create result object for this config update
cJSON* result_obj = cJSON_CreateObject();
cJSON_AddStringToObject(result_obj, "key", key);
if (rc == SQLITE_DONE && sqlite3_changes(db) > 0) { if (rc == SQLITE_DONE && sqlite3_changes(db) > 0) {
cJSON_AddItemToArray(updated_keys, cJSON_CreateString(key)); cJSON_AddStringToObject(result_obj, "status", "success");
cJSON_AddStringToObject(result_obj, "value", value);
// Add optional fields if present
cJSON* data_type_item = cJSON_GetObjectItem(config_obj, "data_type");
if (cJSON_IsString(data_type_item)) {
cJSON_AddStringToObject(result_obj, "data_type", data_type_item->valuestring);
}
success_count++; success_count++;
app_log(LOG_INFO, "Updated config key: %s", key); app_log(LOG_INFO, "Updated config key: %s = %s", key, value);
} else { } else {
cJSON_AddItemToArray(failed_keys, cJSON_CreateString(key)); cJSON_AddStringToObject(result_obj, "status", "error");
cJSON_AddStringToObject(result_obj, "error", "Failed to update");
fail_count++; fail_count++;
} }
cJSON_AddItemToArray(data_array, result_obj);
} }
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
sqlite3_close(db); sqlite3_close(db);
cJSON_AddStringToObject(response, "status", "success"); cJSON_AddStringToObject(response, "status", success_count > 0 ? "success" : "error");
cJSON_AddNumberToObject(response, "updated_count", success_count); cJSON_AddNumberToObject(response, "updates_applied", success_count);
cJSON_AddNumberToObject(response, "failed_count", fail_count); cJSON_AddItemToObject(response, "data", data_array);
cJSON_AddItemToObject(response, "updated_keys", updated_keys);
if (fail_count > 0) {
cJSON_AddItemToObject(response, "failed_keys", failed_keys);
} else {
cJSON_Delete(failed_keys);
}
cJSON_AddNumberToObject(response, "timestamp", (double)time(NULL)); cJSON_AddNumberToObject(response, "timestamp", (double)time(NULL));
return response; return response;

File diff suppressed because it is too large Load Diff

View File

@@ -10,8 +10,8 @@
// Version information (auto-updated by build system) // Version information (auto-updated by build system)
#define VERSION_MAJOR 0 #define VERSION_MAJOR 0
#define VERSION_MINOR 1 #define VERSION_MINOR 1
#define VERSION_PATCH 20 #define VERSION_PATCH 22
#define VERSION "v0.1.20" #define VERSION "v0.1.22"
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>