mirror of
https://github.com/haiwen/seafile-server.git
synced 2025-09-01 15:36:37 +00:00
Remove trailing spaces from values when reading config file.
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include "seafile-session.h"
|
||||
#include "seaf-utils.h"
|
||||
#include "seaf-db.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -24,8 +25,6 @@ seafile_session_get_tmp_file_path (SeafileSession *session,
|
||||
return path;
|
||||
}
|
||||
|
||||
#ifdef SEAFILE_SERVER
|
||||
|
||||
#define SQLITE_DB_NAME "seafile.db"
|
||||
|
||||
#define DEFAULT_MAX_CONNECTIONS 100
|
||||
@@ -65,7 +64,7 @@ mysql_db_start (SeafileSession *session)
|
||||
int max_connections = 0;
|
||||
GError *error = NULL;
|
||||
|
||||
host = g_key_file_get_string (session->config, "database", "host", &error);
|
||||
host = seaf_key_file_get_string (session->config, "database", "host", &error);
|
||||
if (!host) {
|
||||
seaf_warning ("DB host not set in config.\n");
|
||||
return -1;
|
||||
@@ -76,31 +75,31 @@ mysql_db_start (SeafileSession *session)
|
||||
port = MYSQL_DEFAULT_PORT;
|
||||
}
|
||||
|
||||
user = g_key_file_get_string (session->config, "database", "user", &error);
|
||||
user = seaf_key_file_get_string (session->config, "database", "user", &error);
|
||||
if (!user) {
|
||||
seaf_warning ("DB user not set in config.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
passwd = g_key_file_get_string (session->config, "database", "password", &error);
|
||||
passwd = seaf_key_file_get_string (session->config, "database", "password", &error);
|
||||
if (!passwd) {
|
||||
seaf_warning ("DB passwd not set in config.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
db = g_key_file_get_string (session->config, "database", "db_name", &error);
|
||||
db = seaf_key_file_get_string (session->config, "database", "db_name", &error);
|
||||
if (!db) {
|
||||
seaf_warning ("DB name not set in config.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
unix_socket = g_key_file_get_string (session->config,
|
||||
unix_socket = seaf_key_file_get_string (session->config,
|
||||
"database", "unix_socket", NULL);
|
||||
|
||||
use_ssl = g_key_file_get_boolean (session->config,
|
||||
"database", "use_ssl", NULL);
|
||||
|
||||
charset = g_key_file_get_string (session->config,
|
||||
charset = seaf_key_file_get_string (session->config,
|
||||
"database", "connection_charset", NULL);
|
||||
|
||||
max_connections = g_key_file_get_integer (session->config,
|
||||
@@ -137,31 +136,31 @@ pgsql_db_start (SeafileSession *session)
|
||||
char *host, *user, *passwd, *db, *unix_socket;
|
||||
GError *error = NULL;
|
||||
|
||||
host = g_key_file_get_string (session->config, "database", "host", &error);
|
||||
host = seaf_key_file_get_string (session->config, "database", "host", &error);
|
||||
if (!host) {
|
||||
seaf_warning ("DB host not set in config.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
user = g_key_file_get_string (session->config, "database", "user", &error);
|
||||
user = seaf_key_file_get_string (session->config, "database", "user", &error);
|
||||
if (!user) {
|
||||
seaf_warning ("DB user not set in config.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
passwd = g_key_file_get_string (session->config, "database", "password", &error);
|
||||
passwd = seaf_key_file_get_string (session->config, "database", "password", &error);
|
||||
if (!passwd) {
|
||||
seaf_warning ("DB passwd not set in config.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
db = g_key_file_get_string (session->config, "database", "db_name", &error);
|
||||
db = seaf_key_file_get_string (session->config, "database", "db_name", &error);
|
||||
if (!db) {
|
||||
seaf_warning ("DB name not set in config.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
unix_socket = g_key_file_get_string (session->config,
|
||||
unix_socket = seaf_key_file_get_string (session->config,
|
||||
"database", "unix_socket", &error);
|
||||
|
||||
session->db = seaf_db_new_pgsql (host, user, passwd, db, unix_socket,
|
||||
@@ -189,7 +188,7 @@ load_database_config (SeafileSession *session)
|
||||
GError *error = NULL;
|
||||
int ret = 0;
|
||||
|
||||
type = g_key_file_get_string (session->config, "database", "type", &error);
|
||||
type = seaf_key_file_get_string (session->config, "database", "type", &error);
|
||||
/* Default to use sqlite if not set. */
|
||||
if (!type || strcasecmp (type, "sqlite") == 0) {
|
||||
ret = sqlite_db_start (session);
|
||||
@@ -213,5 +212,3 @@ load_database_config (SeafileSession *session)
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -9,9 +9,7 @@ seafile_session_get_tmp_file_path (struct _SeafileSession *session,
|
||||
const char *basename,
|
||||
char path[]);
|
||||
|
||||
#ifdef SEAFILE_SERVER
|
||||
int
|
||||
load_database_config (struct _SeafileSession *session);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@@ -827,7 +827,7 @@ read_seafdav_config()
|
||||
}
|
||||
|
||||
/* host */
|
||||
char *host = g_key_file_get_string (key_file, "WEBDAV", "host", &error);
|
||||
char *host = seaf_key_file_get_string (key_file, "WEBDAV", "host", &error);
|
||||
if (error != NULL) {
|
||||
g_clear_error(&error);
|
||||
ctl->seafdav_config.host = g_strdup(ctl->seafdav_config.fastcgi ? "localhost" : "0.0.0.0");
|
||||
|
39
lib/utils.c
39
lib/utils.c
@@ -1226,28 +1226,6 @@ void parse_key_value_pairs2 (char *string, KeyValueFunc2 func, void *data)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* handle the empty string problem.
|
||||
*/
|
||||
gchar*
|
||||
ccnet_key_file_get_string (GKeyFile *keyf,
|
||||
const char *category,
|
||||
const char *key)
|
||||
{
|
||||
gchar *v;
|
||||
|
||||
if (!g_key_file_has_key (keyf, category, key, NULL))
|
||||
return NULL;
|
||||
|
||||
v = g_key_file_get_string (keyf, category, key, NULL);
|
||||
if (v != NULL && v[0] == '\0') {
|
||||
g_free(v);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
/**
|
||||
* string_list_is_exists:
|
||||
* @str_list:
|
||||
@@ -2483,3 +2461,20 @@ is_permission_valid (const char *perm)
|
||||
|
||||
return strcmp (perm, "r") == 0 || strcmp (perm, "rw") == 0;
|
||||
}
|
||||
|
||||
char *
|
||||
seaf_key_file_get_string (GKeyFile *key_file,
|
||||
const char *group,
|
||||
const char *key,
|
||||
GError **error)
|
||||
{
|
||||
char *v;
|
||||
|
||||
v = g_key_file_get_string (key_file, group, key, error);
|
||||
if (!v || v[0] == '\0') {
|
||||
g_free (v);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return g_strchomp(v);
|
||||
}
|
||||
|
11
lib/utils.h
11
lib/utils.h
@@ -211,11 +211,6 @@ typedef gboolean (*KeyValueFunc2) (void *data, const char *key,
|
||||
const char *value);
|
||||
void parse_key_value_pairs2 (char *string, KeyValueFunc2 func, void *data);
|
||||
|
||||
gchar* ccnet_key_file_get_string (GKeyFile *keyf,
|
||||
const char *category,
|
||||
const char *key);
|
||||
|
||||
|
||||
GList *string_list_append (GList *str_list, const char *string);
|
||||
GList *string_list_append_sorted (GList *str_list, const char *string);
|
||||
GList *string_list_remove (GList *str_list, const char *string);
|
||||
@@ -402,4 +397,10 @@ is_empty_string (const char *str);
|
||||
gboolean
|
||||
is_permission_valid (const char *perm);
|
||||
|
||||
char *
|
||||
seaf_key_file_get_string (GKeyFile *key_file,
|
||||
const char *group,
|
||||
const char *key,
|
||||
GError **error);
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user