v0.2.4 - Clean up config issues
This commit is contained in:
@@ -721,7 +721,6 @@ cJSON* create_config_nostr_event(const char* privkey_hex) {
|
||||
|
||||
static const default_config_t defaults[] = {
|
||||
// Administrative settings
|
||||
{"admin_pubkey", ""},
|
||||
{"admin_enabled", "false"},
|
||||
|
||||
// Server core settings
|
||||
@@ -734,7 +733,7 @@ cJSON* create_config_nostr_event(const char* privkey_hex) {
|
||||
{"relay_description", "High-performance C Nostr relay with SQLite storage"},
|
||||
{"relay_contact", ""},
|
||||
{"relay_pubkey", ""},
|
||||
{"relay_software", "https://github.com/teknari/c-relay"},
|
||||
{"relay_software", "https://git.laantungir.net/laantungir/c-relay.git"},
|
||||
{"relay_version", "0.2.0"},
|
||||
|
||||
// NIP-13 Proof of Work
|
||||
@@ -776,7 +775,8 @@ cJSON* create_config_nostr_event(const char* privkey_hex) {
|
||||
const char* key = (const char*)sqlite3_column_text(stmt, 0);
|
||||
const char* value = (const char*)sqlite3_column_text(stmt, 1);
|
||||
|
||||
if (key && value) {
|
||||
// Skip admin_pubkey since it's redundant (already in event.pubkey)
|
||||
if (key && value && strcmp(key, "admin_pubkey") != 0) {
|
||||
cJSON* tag = cJSON_CreateArray();
|
||||
cJSON_AddItemToArray(tag, cJSON_CreateString(key));
|
||||
cJSON_AddItemToArray(tag, cJSON_CreateString(value));
|
||||
@@ -978,7 +978,7 @@ int generate_config_file_if_missing(void) {
|
||||
cJSON* pubkey_obj = cJSON_GetObjectItem(event, "pubkey");
|
||||
if (pubkey_obj && cJSON_IsString(pubkey_obj)) {
|
||||
const char* admin_pubkey = cJSON_GetStringValue(pubkey_obj);
|
||||
if (set_database_config("relay_admin_pubkey", admin_pubkey, "system") == 0) {
|
||||
if (set_database_config("admin_pubkey", admin_pubkey, "system") == 0) {
|
||||
log_info("Stored admin public key in configuration database");
|
||||
printf(" Admin Public Key: %s\n", admin_pubkey);
|
||||
} else {
|
||||
|
||||
@@ -26,9 +26,9 @@
|
||||
#define RELAY_URL_MAX_LENGTH 256
|
||||
#define RELAY_CONTACT_MAX_LENGTH 128
|
||||
#define RELAY_PUBKEY_MAX_LENGTH 65
|
||||
#define DATABASE_PATH "db/c_nostr_relay.db"
|
||||
|
||||
// Default configuration values (used as fallbacks if database config fails)
|
||||
#define DEFAULT_DATABASE_PATH "db/c_nostr_relay.db"
|
||||
#define DEFAULT_PORT 8888
|
||||
#define DEFAULT_HOST "127.0.0.1"
|
||||
#define MAX_CLIENTS 100
|
||||
|
||||
14
src/main.c
14
src/main.c
@@ -1306,7 +1306,7 @@ void init_relay_info() {
|
||||
if (relay_software) {
|
||||
strncpy(g_relay_info.software, relay_software, sizeof(g_relay_info.software) - 1);
|
||||
} else {
|
||||
strncpy(g_relay_info.software, "https://github.com/laantungir/c-relay", sizeof(g_relay_info.software) - 1);
|
||||
strncpy(g_relay_info.software, "https://git.laantungir.net/laantungir/c-relay.git", sizeof(g_relay_info.software) - 1);
|
||||
}
|
||||
|
||||
const char* relay_version = get_config_value("relay_version");
|
||||
@@ -1940,13 +1940,21 @@ int validate_event_expiration(cJSON* event, char* error_message, size_t error_si
|
||||
|
||||
// Initialize database connection
|
||||
int init_database() {
|
||||
int rc = sqlite3_open(DATABASE_PATH, &g_db);
|
||||
// Use configurable database path, falling back to default
|
||||
const char* db_path = get_config_value("database_path");
|
||||
if (!db_path) {
|
||||
db_path = DEFAULT_DATABASE_PATH;
|
||||
}
|
||||
|
||||
int rc = sqlite3_open(db_path, &g_db);
|
||||
if (rc != SQLITE_OK) {
|
||||
log_error("Cannot open database");
|
||||
return -1;
|
||||
}
|
||||
|
||||
log_success("Database connection established");
|
||||
char success_msg[256];
|
||||
snprintf(success_msg, sizeof(success_msg), "Database connection established: %s", db_path);
|
||||
log_success(success_msg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user