summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Sommerseth <dazo@users.sourceforge.net>2009-09-13 21:46:38 +0200
committerDavid Sommerseth <dazo@users.sourceforge.net>2009-09-13 21:46:38 +0200
commit5d0772225abdff04580a14128b8a86d2dc4f4fd4 (patch)
treebdf7a7c33a2bcb11b50fafde750481a70ce680a3
parent76e216dd61168b2e75435ff67f26fe02bdc93187 (diff)
downloadeurephia-5d0772225abdff04580a14128b8a86d2dc4f4fd4.tar.gz
eurephia-5d0772225abdff04580a14128b8a86d2dc4f4fd4.tar.xz
eurephia-5d0772225abdff04580a14128b8a86d2dc4f4fd4.zip
Moved eDBadminConfigSet() and eDBadminConfigDelete() into its own file
-rw-r--r--database/sqlite/CMakeLists.txt1
-rw-r--r--database/sqlite/administration.c68
-rw-r--r--database/sqlite/administration/configuration.c110
3 files changed, 111 insertions, 68 deletions
diff --git a/database/sqlite/CMakeLists.txt b/database/sqlite/CMakeLists.txt
index c366f67..9875b5b 100644
--- a/database/sqlite/CMakeLists.txt
+++ b/database/sqlite/CMakeLists.txt
@@ -52,6 +52,7 @@ IF(ADMIN_ENABLED)
administration/attempts.c
administration/blacklist.c
administration/usercerts.c
+ administration/configuration.c
)
ENDIF(ADMIN_ENABLED)
diff --git a/database/sqlite/administration.c b/database/sqlite/administration.c
index 92d7b93..e460e6e 100644
--- a/database/sqlite/administration.c
+++ b/database/sqlite/administration.c
@@ -392,74 +392,6 @@ int eDBadminLogout(eurephiaCTX *ctx, const char *sessionkey) {
/**
- * @copydoc eDBadminConfigSet()
- */
-int eDBadminConfigSet(eurephiaCTX *ctx, const char *key, const char *val) {
- dbresult *res = NULL;
- int found = 0;
-
- DEBUG(ctx, 20, "Function call: eDBadminConfigSet(ctx, '%s', '%s')", key, val);
- assert((ctx != NULL) && (ctx->dbc != NULL));
-
- if( (ctx->context_type != ECTX_ADMIN_CONSOLE) && (ctx->context_type != ECTX_ADMIN_WEB) ) {
- eurephia_log(ctx, LOG_CRITICAL, 0,
- "eurephia admin function call attempted with wrong context type");
- return 0;
- }
-
- res = sqlite_query(ctx, "SELECT count(*) FROM openvpn_config WHERE datakey = '%q'", key);
- if( !res ) {
- eurephia_log(ctx, LOG_ERROR, 0, "Could not query configuration table");
- return 0;
- }
- found = atoi_nullsafe(sqlite_get_value(res, 0, 0));
- sqlite_free_results(res);
-
- if( found == 0 ) {
- res = sqlite_query(ctx,
- "INSERT INTO openvpn_config (datakey, dataval) VALUES ('%q','%q')",
- key, val);
- } else {
- res = sqlite_query(ctx, "UPDATE openvpn_config SET dataval = '%q' WHERE datakey = '%q'",
- val, key);
- }
-
- if( res == NULL ) {
- eurephia_log(ctx, LOG_ERROR, 0, "Could not register configuration entry (%s = '%s'", key, val);
- return 0;
- }
- sqlite_free_results(res);
- eAdd_value(ctx, ctx->dbc->config, key, val);
- return 1;
-}
-
-
-/**
- * @copydoc eDBadminConfigDelete()
- */
-int eDBadminConfigDelete(eurephiaCTX *ctx, const char *key) {
- dbresult *res = NULL;
-
- DEBUG(ctx, 20, "Function call: eDBadminConfigDelete(ctx, '%s') ", key);
- assert((ctx != NULL) && (ctx->dbc != NULL));
-
- if( (ctx->context_type != ECTX_ADMIN_CONSOLE) && (ctx->context_type != ECTX_ADMIN_WEB) ) {
- eurephia_log(ctx, LOG_CRITICAL, 0,
- "eurephia admin function call attempted with wrong context type");
- return 0;
- }
-
- res = sqlite_query(ctx, "DELETE FROM openvpn_config WHERE datakey = '%q'", key);
- if( !res ) {
- eurephia_log(ctx, LOG_ERROR, 0, "Could delete config configuration entry (%s)", key);
- return 0;
- }
- sqlite_free_results(res);
- return 1;
-}
-
-
-/**
* @copydoc eDBadminGetUserList()
*/
xmlDoc *eDBadminGetUserList(eurephiaCTX *ctx, const char *sortkeys) {
diff --git a/database/sqlite/administration/configuration.c b/database/sqlite/administration/configuration.c
new file mode 100644
index 0000000..d2837f0
--- /dev/null
+++ b/database/sqlite/administration/configuration.c
@@ -0,0 +1,110 @@
+/* administration.c -- Functions for setting and deleting
+ * configuration parameters in the database
+ *
+ * GPLv2 only - Copyright (C) 2008, 2009
+ * David Sommerseth <dazo@users.sourceforge.net>
+ *
+ * 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; version 2
+ * of the License.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+/**
+ * @file configuration.c
+ * @author David Sommerseth <dazo@users.sourceforge.net>
+ * @date 2009-09-13
+ *
+ * @brief Functions for setting and deleting configuration
+ * parameters in the database
+ *
+ */
+
+#include <string.h>
+#include <unistd.h>
+#include <assert.h>
+#include <sqlite3.h>
+
+#include <eurephia_nullsafe.h>
+#include <eurephia_context.h>
+#include <eurephia_log.h>
+#include <eurephia_values.h>
+
+#include "../sqlite.h"
+
+/**
+ * @copydoc eDBadminConfigSet()
+ */
+int eDBadminConfigSet(eurephiaCTX *ctx, const char *key, const char *val) {
+ dbresult *res = NULL;
+ int found = 0;
+
+ DEBUG(ctx, 20, "Function call: eDBadminConfigSet(ctx, '%s', '%s')", key, val);
+ assert((ctx != NULL) && (ctx->dbc != NULL));
+
+ if( (ctx->context_type != ECTX_ADMIN_CONSOLE) && (ctx->context_type != ECTX_ADMIN_WEB) ) {
+ eurephia_log(ctx, LOG_CRITICAL, 0,
+ "eurephia admin function call attempted with wrong context type");
+ return 0;
+ }
+
+ res = sqlite_query(ctx, "SELECT count(*) FROM openvpn_config WHERE datakey = '%q'", key);
+ if( !res ) {
+ eurephia_log(ctx, LOG_ERROR, 0, "Could not query configuration table");
+ return 0;
+ }
+ found = atoi_nullsafe(sqlite_get_value(res, 0, 0));
+ sqlite_free_results(res);
+
+ if( found == 0 ) {
+ res = sqlite_query(ctx,
+ "INSERT INTO openvpn_config (datakey, dataval) VALUES ('%q','%q')",
+ key, val);
+ } else {
+ res = sqlite_query(ctx, "UPDATE openvpn_config SET dataval = '%q' WHERE datakey = '%q'",
+ val, key);
+ }
+
+ if( res == NULL ) {
+ eurephia_log(ctx, LOG_ERROR, 0, "Could not register configuration entry (%s = '%s'", key, val);
+ return 0;
+ }
+ sqlite_free_results(res);
+ eAdd_value(ctx, ctx->dbc->config, key, val);
+ return 1;
+}
+
+
+/**
+ * @copydoc eDBadminConfigDelete()
+ */
+int eDBadminConfigDelete(eurephiaCTX *ctx, const char *key) {
+ dbresult *res = NULL;
+
+ DEBUG(ctx, 20, "Function call: eDBadminConfigDelete(ctx, '%s') ", key);
+ assert((ctx != NULL) && (ctx->dbc != NULL));
+
+ if( (ctx->context_type != ECTX_ADMIN_CONSOLE) && (ctx->context_type != ECTX_ADMIN_WEB) ) {
+ eurephia_log(ctx, LOG_CRITICAL, 0,
+ "eurephia admin function call attempted with wrong context type");
+ return 0;
+ }
+
+ res = sqlite_query(ctx, "DELETE FROM openvpn_config WHERE datakey = '%q'", key);
+ if( !res ) {
+ eurephia_log(ctx, LOG_ERROR, 0, "Could delete config configuration entry (%s)", key);
+ return 0;
+ }
+ sqlite_free_results(res);
+ return 1;
+}