mirror of
https://github.com/haiwen/seafile-server.git
synced 2025-09-02 07:54:27 +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 "seafile-session.h"
|
||||||
#include "seaf-utils.h"
|
#include "seaf-utils.h"
|
||||||
#include "seaf-db.h"
|
#include "seaf-db.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -24,8 +25,6 @@ seafile_session_get_tmp_file_path (SeafileSession *session,
|
|||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SEAFILE_SERVER
|
|
||||||
|
|
||||||
#define SQLITE_DB_NAME "seafile.db"
|
#define SQLITE_DB_NAME "seafile.db"
|
||||||
|
|
||||||
#define DEFAULT_MAX_CONNECTIONS 100
|
#define DEFAULT_MAX_CONNECTIONS 100
|
||||||
@@ -65,7 +64,7 @@ mysql_db_start (SeafileSession *session)
|
|||||||
int max_connections = 0;
|
int max_connections = 0;
|
||||||
GError *error = NULL;
|
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) {
|
if (!host) {
|
||||||
seaf_warning ("DB host not set in config.\n");
|
seaf_warning ("DB host not set in config.\n");
|
||||||
return -1;
|
return -1;
|
||||||
@@ -76,31 +75,31 @@ mysql_db_start (SeafileSession *session)
|
|||||||
port = MYSQL_DEFAULT_PORT;
|
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) {
|
if (!user) {
|
||||||
seaf_warning ("DB user not set in config.\n");
|
seaf_warning ("DB user not set in config.\n");
|
||||||
return -1;
|
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) {
|
if (!passwd) {
|
||||||
seaf_warning ("DB passwd not set in config.\n");
|
seaf_warning ("DB passwd not set in config.\n");
|
||||||
return -1;
|
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) {
|
if (!db) {
|
||||||
seaf_warning ("DB name not set in config.\n");
|
seaf_warning ("DB name not set in config.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
unix_socket = g_key_file_get_string (session->config,
|
unix_socket = seaf_key_file_get_string (session->config,
|
||||||
"database", "unix_socket", NULL);
|
"database", "unix_socket", NULL);
|
||||||
|
|
||||||
use_ssl = g_key_file_get_boolean (session->config,
|
use_ssl = g_key_file_get_boolean (session->config,
|
||||||
"database", "use_ssl", NULL);
|
"database", "use_ssl", NULL);
|
||||||
|
|
||||||
charset = g_key_file_get_string (session->config,
|
charset = seaf_key_file_get_string (session->config,
|
||||||
"database", "connection_charset", NULL);
|
"database", "connection_charset", NULL);
|
||||||
|
|
||||||
max_connections = g_key_file_get_integer (session->config,
|
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;
|
char *host, *user, *passwd, *db, *unix_socket;
|
||||||
GError *error = NULL;
|
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) {
|
if (!host) {
|
||||||
seaf_warning ("DB host not set in config.\n");
|
seaf_warning ("DB host not set in config.\n");
|
||||||
return -1;
|
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) {
|
if (!user) {
|
||||||
seaf_warning ("DB user not set in config.\n");
|
seaf_warning ("DB user not set in config.\n");
|
||||||
return -1;
|
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) {
|
if (!passwd) {
|
||||||
seaf_warning ("DB passwd not set in config.\n");
|
seaf_warning ("DB passwd not set in config.\n");
|
||||||
return -1;
|
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) {
|
if (!db) {
|
||||||
seaf_warning ("DB name not set in config.\n");
|
seaf_warning ("DB name not set in config.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
unix_socket = g_key_file_get_string (session->config,
|
unix_socket = seaf_key_file_get_string (session->config,
|
||||||
"database", "unix_socket", &error);
|
"database", "unix_socket", &error);
|
||||||
|
|
||||||
session->db = seaf_db_new_pgsql (host, user, passwd, db, unix_socket,
|
session->db = seaf_db_new_pgsql (host, user, passwd, db, unix_socket,
|
||||||
@@ -189,7 +188,7 @@ load_database_config (SeafileSession *session)
|
|||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
int ret = 0;
|
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. */
|
/* Default to use sqlite if not set. */
|
||||||
if (!type || strcasecmp (type, "sqlite") == 0) {
|
if (!type || strcasecmp (type, "sqlite") == 0) {
|
||||||
ret = sqlite_db_start (session);
|
ret = sqlite_db_start (session);
|
||||||
@@ -213,5 +212,3 @@ load_database_config (SeafileSession *session)
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@@ -9,9 +9,7 @@ seafile_session_get_tmp_file_path (struct _SeafileSession *session,
|
|||||||
const char *basename,
|
const char *basename,
|
||||||
char path[]);
|
char path[]);
|
||||||
|
|
||||||
#ifdef SEAFILE_SERVER
|
|
||||||
int
|
int
|
||||||
load_database_config (struct _SeafileSession *session);
|
load_database_config (struct _SeafileSession *session);
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -827,7 +827,7 @@ read_seafdav_config()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* host */
|
/* 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) {
|
if (error != NULL) {
|
||||||
g_clear_error(&error);
|
g_clear_error(&error);
|
||||||
ctl->seafdav_config.host = g_strdup(ctl->seafdav_config.fastcgi ? "localhost" : "0.0.0.0");
|
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:
|
* string_list_is_exists:
|
||||||
* @str_list:
|
* @str_list:
|
||||||
@@ -2483,3 +2461,20 @@ is_permission_valid (const char *perm)
|
|||||||
|
|
||||||
return strcmp (perm, "r") == 0 || strcmp (perm, "rw") == 0;
|
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);
|
const char *value);
|
||||||
void parse_key_value_pairs2 (char *string, KeyValueFunc2 func, void *data);
|
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 (GList *str_list, const char *string);
|
||||||
GList *string_list_append_sorted (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);
|
GList *string_list_remove (GList *str_list, const char *string);
|
||||||
@@ -402,4 +397,10 @@ is_empty_string (const char *str);
|
|||||||
gboolean
|
gboolean
|
||||||
is_permission_valid (const char *perm);
|
is_permission_valid (const char *perm);
|
||||||
|
|
||||||
|
char *
|
||||||
|
seaf_key_file_get_string (GKeyFile *key_file,
|
||||||
|
const char *group,
|
||||||
|
const char *key,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user