You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

36 lines
1.7 KiB

// config_updater.h — Universal INI config file updater (like insert_or_replace_option in utun)
#ifndef CONFIG_UPDATER_H
#define CONFIG_UPDATER_H
#include <QString>
#include <QStringList>
#include <QList>
enum ConfigUpdateFlag {
CONFIG_UPDATE_REPLACE = 0, // replace existing param (single value)
CONFIG_UPDATE_APPEND = 1 // add new param even if exists (multi-value)
};
/* Один listen-сокет = секция [server:name]. */
struct ConfigServer {
QString name; // суффикс секции: "lan", "lan6"
QString addr; // "0.0.0.0:1333" | "[::]:1333"
QString transport; // "udp" | "tcp"
QString type; // "public" | "nat" | "private" | "local"
QString netif; // "" = не привязывать к интерфейсу
};
// Batch update — for callers that read/write the file once (e.g. NodeConfig::save)
bool config_update_in_lines(QStringList& lines, const QString& section,
const QString& key, const QString& value, bool replace);
// File-level wrapper — reads, updates, writes
bool config_update_option(const QString& filePath, const QString& section,
const QString& param, const QString& value,
int flags = CONFIG_UPDATE_REPLACE);
// Полностью заменяет секции [server:*]: удаляет старые, вставляет новые после [global].
// Внутри секции без пустых строк, между секциями ровно одна пустая строка.
bool config_rewrite_servers(const QString& filePath, const QList<ConfigServer>& servers);
#endif // CONFIG_UPDATER_H