mirror of https://git.48k.eu/ogserver
#988 Add DB port option to ogserver.json config file
This patch provides functionality to select a database port. It also adds a default IP for the database.master
parent
a8eccba706
commit
0631b0e8e6
|
@ -5,6 +5,8 @@
|
|||
"api_token": "5a5ca1172136299640a9f47469237e0a"
|
||||
},
|
||||
"database" : {
|
||||
"ip": "127.0.0.1",
|
||||
"port": 3306,
|
||||
"name" : "opengnsys",
|
||||
"user" : "mysql",
|
||||
"pass" : "mysql"
|
||||
|
|
|
@ -57,6 +57,9 @@ static int parse_json_db(struct og_server_cfg *cfg, json_t *element)
|
|||
} else if (!strcmp(key, "name")) {
|
||||
if (og_json_parse_string(value, &cfg->db.name) < 0)
|
||||
return -1;
|
||||
} else if (!strcmp(key, "port")) {
|
||||
if (og_json_parse_uint(value, &cfg->db.port) < 0)
|
||||
return -1;
|
||||
} else {
|
||||
syslog(LOG_ERR, "unknown key `%s' in db\n", key);
|
||||
return -1;
|
||||
|
@ -162,4 +165,5 @@ void from_json_to_legacy(struct og_server_cfg *cfg)
|
|||
snprintf(catalog, sizeof(catalog), cfg->db.name);
|
||||
snprintf(interface, sizeof(interface), cfg->wol.interface);
|
||||
snprintf(auth_token, sizeof(auth_token), cfg->rest.api_token);
|
||||
snprintf(db_port, sizeof(db_port), "%u", cfg->db.port);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ struct og_server_cfg {
|
|||
const char *user;
|
||||
const char *pass;
|
||||
const char *ip;
|
||||
unsigned int port;
|
||||
const char *name;
|
||||
} db;
|
||||
struct {
|
||||
|
|
|
@ -24,6 +24,7 @@ struct og_dbi *og_dbi_open(struct og_dbi_config *config)
|
|||
}
|
||||
|
||||
dbi_conn_set_option(dbi->conn, "host", config->host);
|
||||
dbi_conn_set_option(dbi->conn, "port", config->port);
|
||||
dbi_conn_set_option(dbi->conn, "username", config->user);
|
||||
dbi_conn_set_option(dbi->conn, "password", config->passwd);
|
||||
dbi_conn_set_option(dbi->conn, "dbname", config->database);
|
||||
|
|
|
@ -7,6 +7,7 @@ struct og_dbi_config {
|
|||
const char *user;
|
||||
const char *passwd;
|
||||
const char *host;
|
||||
const char *port;
|
||||
const char *database;
|
||||
};
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ char interface[4096]; // Interface name
|
|||
char auth_token[4096]; // API token
|
||||
char servidoradm[4096]; // Dirección IP del servidor de administración
|
||||
char puerto[4096]; // Puerto de comunicación
|
||||
char db_port[4096];
|
||||
|
||||
SOCKETCL tbsockets[MAXIMOS_CLIENTES];
|
||||
|
||||
|
@ -38,6 +39,7 @@ struct og_dbi_config dbi_config = {
|
|||
.user = usuario,
|
||||
.passwd = pasguor,
|
||||
.host = datasource,
|
||||
.port = db_port,
|
||||
.database = catalog,
|
||||
};
|
||||
|
||||
|
@ -101,6 +103,9 @@ bool tomaConfiguracion(const char *filecfg)
|
|||
line = fgets(buf, sizeof(buf), fcfg);
|
||||
}
|
||||
|
||||
/* Default value to preserve legacy config file support */
|
||||
snprintf(db_port, sizeof(db_port), "3306");
|
||||
|
||||
fclose(fcfg);
|
||||
|
||||
if (!servidoradm[0]) {
|
||||
|
|
|
@ -29,6 +29,7 @@ extern char interface[4096];
|
|||
extern char api_token[4096];
|
||||
extern char servidoradm[4096];
|
||||
extern char puerto[4096];
|
||||
extern char db_port[4096];
|
||||
|
||||
struct og_client;
|
||||
|
||||
|
|
Loading…
Reference in New Issue