1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
typedef struct {
gchar *server, *user, *password, *database;
gint port;
} Settings;
using namespace std;
void readConfigFile(char *cfgfile, char*& server, char*& username, char*& password, char*& database, int& port) {
Settings *conf;
GKeyFile *keyfile;
GKeyFileFlags flags;
GError *error = NULL;
gsize length;
keyfile = g_key_file_new ();
//flags = G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS;
cout << "Looking for config file " << cfgfile << endl;
if (!g_key_file_load_from_file (keyfile, cfgfile, flags, &error)) {
g_error (error->message);
} else {
cout << "config file loaded." << endl;
conf = g_slice_new (Settings);
conf->server = g_key_file_get_string(keyfile, "mysql", "host", NULL);
server = conf->server;
conf->user = g_key_file_get_string(keyfile, "mysql", "username", NULL);
username = conf->user;
conf->password = g_key_file_get_string(keyfile, "mysql", "password", NULL);
password = conf->password;
conf->database = g_key_file_get_string(keyfile, "mysql", "database", NULL);
database = conf->database;
conf->port = g_key_file_get_integer(keyfile, "mysql", "port", NULL);
port = conf->port;
}
}
|