Add database configuration options to main config file

ulab-next-nosound
Timothy Pearson 12 years ago committed by Timothy Pearson
parent 18efbc17c2
commit 1978692fae

@ -1,6 +1,21 @@
// (c) 2012 Timothy Pearson
// (c) 2012 Raptor Engineering
// ALL RIGHTS RESERVED
/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
(c) 2012 Timothy Pearson
(c) 2012 Raptor Engineering
*/
#define _GNU_SOURCE
@ -19,8 +34,11 @@
#include <grp.h>
#include <time.h>
#define list_delete mysql_list_delete
#include <mysql/mysql.h>
#undef list_delete
#include "list.h"
#include "libraptorsmiface.h"
#define STATISTICS_SERVER_START_EVENT 0
@ -29,10 +47,15 @@
#define STATISTICS_CONNECTION_STATUS_EVENT 3
#define STATISTICS_DISCONNECTION_EVENT 4
//char *server = "localhost";
char *server = "freyja.starlink.edu";
#define RAPTORSMIFACE_CFG_DATABASE "Database"
#define RAPTORSMIFACE_CFG_DATABASE_SERVER "Server"
#define RAPTORSMIFACE_CFG_DATABASE_NAME "Database"
#define RAPTORSMIFACE_CFG_DATABASE_USER "User"
#define RAPTORSMIFACE_CFG_DATABASE_PASSWORD "Password"
char *server = "localhost";
char *user = "remotelab";
char *password = "rlpass123"; /* set me first */
char *password = "";
char *database = "remotelab_sm";
void dprint(const char *fmt, ...)
@ -56,8 +79,73 @@ void dprint(const char *fmt, ...)
va_end(argp);
}
void raptorsmiface_config_read_database(int file, struct list* param_n, struct list* param_v) {
int i;
char* buf;
char* temp_buf;
list_clear(param_v);
list_clear(param_n);
file_read_section(file, RAPTORSMIFACE_CFG_DATABASE, param_n, param_v);
for (i = 0; i < param_n->count; i++) {
buf = (char*)list_get_item(param_n, i);
if (0 == g_strcasecmp(buf, RAPTORSMIFACE_CFG_DATABASE_SERVER)) {
server = g_strdup((char*)list_get_item(param_v, i));
}
if (0 == g_strcasecmp(buf, RAPTORSMIFACE_CFG_DATABASE_NAME)) {
database = g_strdup((char*)list_get_item(param_v, i));
}
if (0 == g_strcasecmp(buf, RAPTORSMIFACE_CFG_DATABASE_USER)) {
user = g_strdup((char*)list_get_item(param_v, i));
}
if (0 == g_strcasecmp(buf, RAPTORSMIFACE_CFG_DATABASE_PASSWORD)) {
password = g_strdup((char*)list_get_item(param_v, i));
}
}
g_printf("raptorsmiface configuration:\r\n");
g_printf("\tServer: %s\r\n", server);
g_printf("\tDatabase: %s\r\n", database);
g_printf("\tUser: %s\r\n", user);
}
void read_ini_configuration() {
int fd;
struct list* sec;
struct list* param_n;
struct list* param_v;
char cfg_file[256];
g_snprintf(cfg_file, 255, "%s/xrdp.ini", XRDP_CFG_PATH);
fd = g_file_open(cfg_file);
if (-1 == fd) {
dprint("[ERROR] Unable to open configuration file [%s]", cfg_file);
return;
}
sec = list_create();
sec->auto_free = 1;
file_read_sections(fd, sec);
param_n = list_create();
param_n->auto_free = 1;
param_v = list_create();
param_v->auto_free = 1;
/* read database config */
raptorsmiface_config_read_database(fd, param_n, param_v);
/* cleanup */
list_delete(sec);
list_delete(param_v);
list_delete(param_n);
g_file_close(fd);
}
MYSQL * connect_if_needed() {
MYSQL *conn = mysql_init(NULL);
read_ini_configuration();
if (!mysql_real_connect(conn, server, user, password, database, 0, NULL, 0)) {
dprint("[ERROR] MySQL connection FAILED [%s]\n\r", mysql_error(conn));
conn = 0;

@ -1,6 +1,21 @@
// (c) 2012 Timothy Pearson
// (c) 2012 Raptor Engineering
// ALL RIGHTS RESERVED
/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
(c) 2012 Timothy Pearson
(c) 2012 Raptor Engineering
*/
#include <unistd.h>

Loading…
Cancel
Save