Добавлена секция [chatserver] в конфиг — объединяет активацию чата и настройки в одной секции
This commit is contained in:
1 parent
712d1b53df
commit
c22991f7d9
3 files changed
+26
-15
No files matched your search
+12
-13
@@ -48,11 +48,10 @@ typedef enum {
|
||||
SECTION_NAT,
|
||||
SECTION_TCP_PROXY_CLIENT,
|
||||
SECTION_TCP_PROXY_SERVER,
|
||||
SECTION_CHATSERVER,
|
||||
SECTION_NETWORK,
|
||||
SECTION_GUI,
|
||||
SECTION_CHAT,
|
||||
SECTION_NTP,
|
||||
SECTION_CHATSERVER,
|
||||
SECTION_LOG_UDP
|
||||
} section_type_t;
|
||||
|
||||
@@ -760,7 +759,7 @@ static int parse_chatserver(const char *key, const char *value, struct global_co
|
||||
global->chatserver_storage_unit_size = sz;
|
||||
return 0;
|
||||
}
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "%s:%d: Unknown chatserver option '%s'. Valid: join_policy, join_password, allowed_groups, storage_total_size, storage_unit_size", filename, line_num, key);
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "%s:%d: Unknown chatserver option '%s'. Valid: db_path, join_password, allowed_groups, storage_total_size, storage_unit_size, storage_autoload, storage_autoload_maxsize_mb, storage_maxsize_gb, opus_codec_preset, compressor_enabled, compressor_max_gain_db, compressor_rise_rate, media_download_max_peers", filename, line_num, key);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -801,10 +800,12 @@ static section_type_t parse_section_header(const char *line, char *name, size_t
|
||||
if (strcasecmp(section, "nat") == 0) return SECTION_NAT;
|
||||
if (strcasecmp(section, "tcp_proxy_client") == 0) return SECTION_TCP_PROXY_CLIENT;
|
||||
if (strcasecmp(section, "tcp_proxy_server") == 0) return SECTION_TCP_PROXY_SERVER;
|
||||
if (strcasecmp(section, "chatserver") == 0) return SECTION_CHATSERVER;
|
||||
if (strcasecmp(section, "ntp") == 0) return SECTION_NTP;
|
||||
if (strcasecmp(section, "gui") == 0) return SECTION_GUI;
|
||||
if (strcasecmp(section, "chat") == 0) return SECTION_CHAT;
|
||||
if (strcasecmp(section, "chatserver") == 0) return SECTION_CHATSERVER;
|
||||
if (strcasecmp(section, "ntp") == 0) return SECTION_NTP;
|
||||
if (strcasecmp(section, "gui") == 0) return SECTION_GUI;
|
||||
if (strcasecmp(section, "log_udp") == 0) return SECTION_LOG_UDP;
|
||||
|
||||
char *colon = strchr(section, ':');
|
||||
@@ -1040,15 +1041,14 @@ static struct utun_config* parse_config_internal(FILE *fp, const char *filename)
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "%s:%d: Unknown ntp option '%s'. Valid: enabled, server, interval", filename, line_num, key);
|
||||
}
|
||||
break;
|
||||
case SECTION_CHAT:
|
||||
if (chat_setting_set(key, value) < 0) {
|
||||
/* chat_setting_set уже напечатал ошибку */
|
||||
}
|
||||
break;
|
||||
case SECTION_CHATSERVER:
|
||||
cfg->global.chatserver_enabled = 1;
|
||||
if (parse_chatserver(key, value, &cfg->global, filename, line_num) < 0) {
|
||||
/* parse_chatserver already printed the error */
|
||||
cfg->global.db_sync_enabled = 1;
|
||||
if (strcmp(key, "db_path") == 0) {
|
||||
assign_string(cfg->global.db_path, sizeof(cfg->global.db_path), value);
|
||||
} else if (parse_chatserver(key, value, &cfg->global, filename, line_num) < 0 &&
|
||||
chat_setting_set(key, value) < 0) {
|
||||
/* both failed — errors already printed */
|
||||
}
|
||||
break;
|
||||
case SECTION_GUI:
|
||||
@@ -1179,8 +1179,7 @@ struct utun_config* parse_config_from_buf(const char *buf, size_t len, const cha
|
||||
case SECTION_TCP_PROXY_SERVER: cfg->global.tcp_proxy_server_enabled = 1; if (strcmp(key, "tcp_recv_buf") == 0) cfg->global.tcp_recv_buf = atoi(value); break;
|
||||
case SECTION_NETWORK: if (cur_network) parse_network(key, value, cur_network, filename, line_num); break;
|
||||
case SECTION_NTP: if (strcmp(key, "enabled") == 0) cfg->global.ntp_enabled = strcasecmp(value, "yes") == 0 || strcasecmp(value, "1") == 0 || strcasecmp(value, "true") == 0; else if (strcmp(key, "server") == 0) { struct CFG_NTP_SERVER *ns = u_calloc(1, sizeof(struct CFG_NTP_SERVER)); if (ns) { strncpy(ns->name, value, sizeof(ns->name) - 1); ns->name[sizeof(ns->name) - 1] = '\0'; ns->next = cfg->global.ntp_servers; cfg->global.ntp_servers = ns; cfg->global.ntp_server_count++; } } else if (strcmp(key, "interval") == 0) { cfg->global.ntp_resync_interval = atoi(value); if (cfg->global.ntp_resync_interval < 60) cfg->global.ntp_resync_interval = 60; } else DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "%s:%d: Unknown ntp option '%s'", filename, line_num, key); break;
|
||||
case SECTION_CHAT: chat_setting_set(key, value); break;
|
||||
case SECTION_CHATSERVER: cfg->global.chatserver_enabled = 1; parse_chatserver(key, value, &cfg->global, filename, line_num); break;
|
||||
case SECTION_CHATSERVER: cfg->global.chatserver_enabled = 1; cfg->global.db_sync_enabled = 1; if (strcmp(key, "db_path") == 0) assign_string(cfg->global.db_path, sizeof(cfg->global.db_path), value); else if (parse_chatserver(key, value, &cfg->global, filename, line_num) < 0) chat_setting_set(key, value); break;
|
||||
case SECTION_GUI: break;
|
||||
case SECTION_LOG_UDP:
|
||||
if (strcmp(key, "ip") == 0) strncpy(cfg->global.log_udp_ip, value, sizeof(cfg->global.log_udp_ip) - 1);
|
||||
|
||||
+1
-1
@@ -119,6 +119,7 @@ struct global_config {
|
||||
char log_file[256]; // Path to log file (empty = stdout)
|
||||
char db_path[256]; // Path to SQLite database (empty = disabled)
|
||||
int db_sync_enabled; // 1 = enable distributed DB sync (default: 0)
|
||||
int chatserver_enabled; // 1 = chat server mode (set by [chatserver] section presence)
|
||||
uint32_t db_sync_ttl; // TTL for unsent records in seconds (default: 86400)
|
||||
// UDP log target
|
||||
char log_udp_ip[64];
|
||||
@@ -196,7 +197,6 @@ struct global_config {
|
||||
int ntp_resync_interval; // seconds, default 3600
|
||||
|
||||
// Chatserver configuration ([chatserver] section)
|
||||
int chatserver_enabled; // 1 = section present
|
||||
char chatserver_join_password[128]; // пароль для входа в группу
|
||||
char chatserver_allowed_groups[1024]; // "all" или hex-ID через запятую
|
||||
uint64_t chatserver_storage_total_size; // bytes, общий лимит хранилища (0 = безлимит)
|
||||
|
||||
+13
-1
@@ -635,6 +635,15 @@ void utun_instance_stop(struct UTUN_INSTANCE *instance) {
|
||||
|
||||
}
|
||||
|
||||
static int mkdir_recursive(const char *path) {
|
||||
char tmp[512]; int len = snprintf(tmp, sizeof(tmp), "%s", path);
|
||||
if (len <= 0 || (size_t)len >= sizeof(tmp)) return -1;
|
||||
for (char *p = tmp + 1; *p; p++) {
|
||||
if (*p == '/') { *p = '\0'; utun_mkdir(tmp, 0755); *p = '/'; }
|
||||
}
|
||||
return utun_mkdir(tmp, 0755);
|
||||
}
|
||||
|
||||
int utun_instance_init(struct UTUN_INSTANCE *instance) {
|
||||
if (!instance) return -1;
|
||||
|
||||
@@ -642,7 +651,10 @@ int utun_instance_init(struct UTUN_INSTANCE *instance) {
|
||||
db_sync_init(instance);
|
||||
|
||||
// chat — сообщения, каналы, P2P-синхронизация
|
||||
if (instance->config->global.db_path[0] && instance->config->global.db_sync_enabled) {
|
||||
if (instance->config->global.chatserver_enabled) {
|
||||
if (!instance->config->global.db_path[0])
|
||||
snprintf(instance->config->global.db_path, sizeof(instance->config->global.db_path), "/var/lib/utun");
|
||||
mkdir_recursive(instance->config->global.db_path);
|
||||
char db_file[512];
|
||||
snprintf(db_file, sizeof(db_file), "%s/chats.db", instance->config->global.db_path);
|
||||
if (chat_core_init(instance, db_file) == 0)
|
||||
|
||||
Reference in new issue
Block a user