summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Wagner <daniel.wagner@bmw-carit.de>2012-08-13 10:40:23 +0200
committerPatrik Flykt <patrik.flykt@linux.intel.com>2012-08-30 13:01:49 +0300
commitc7cd2709d524d8e5d7ee2f6ec1eff2166b4f1239 (patch)
treeee15ed8f7b2a5b994c627504ebaefeb68d389826
parent3754e3487c99d2ddd5a5bd672daeca150fda1398 (diff)
downloadconnman-c7cd2709d524d8e5d7ee2f6ec1eff2166b4f1239.tar.gz
connman-c7cd2709d524d8e5d7ee2f6ec1eff2166b4f1239.tar.bz2
connman-c7cd2709d524d8e5d7ee2f6ec1eff2166b4f1239.zip
session: Add configuration plugin
-rw-r--r--Makefile.am3
-rw-r--r--Makefile.plugins3
-rw-r--r--configure.ac6
-rw-r--r--include/session.h52
-rw-r--r--plugins/session_default.c76
-rw-r--r--src/session.c95
6 files changed, 234 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am
index ca0cf0bb..f31ebdf5 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -7,7 +7,8 @@ include_HEADERS = include/types.h include/log.h include/plugin.h \
include/notifier.h include/service.h \
include/resolver.h include/ipconfig.h \
include/device.h include/network.h include/inet.h \
- include/storage.h include/provision.h
+ include/storage.h include/provision.h \
+ include/session.h
nodist_include_HEADERS = include/version.h
diff --git a/Makefile.plugins b/Makefile.plugins
index f959152c..263cb208 100644
--- a/Makefile.plugins
+++ b/Makefile.plugins
@@ -223,6 +223,9 @@ plugins_tist_la_LDFLAGS = $(plugin_ldflags)
endif
endif
+builtin_modules += @SESSION_CONFIG_PLUGIN@
+builtin_sources += plugins/@SESSION_CONFIG_PLUGIN@.c
+
EXTRA_DIST += plugins/polkit.policy
plugins/net.connman.policy: plugins/polkit.policy
diff --git a/configure.ac b/configure.ac
index 826b3e68..f43b2517 100644
--- a/configure.ac
+++ b/configure.ac
@@ -252,6 +252,12 @@ AC_ARG_ENABLE(tist,
AM_CONDITIONAL(TIST, test "${enable_tist}" != "no")
AM_CONDITIONAL(TIST_BUILTIN, test "${enable_tist}" = "builtin")
+AC_ARG_WITH(configplugin, AC_HELP_STRING([--with-configplugin=PLUGIN],
+ [session config plugin]), [configplugin=${withval}],
+ [configplugin="session_default"])
+SESSION_CONFIG_PLUGIN="$configplugin"
+AC_SUBST(SESSION_CONFIG_PLUGIN)
+
AC_ARG_WITH(stats-max-file-size, AC_HELP_STRING([--with-stats-max-file-size=SIZE],
[Maximal size of a statistics round robin file]),
[stats_max_file_size=${withval}])
diff --git a/include/session.h b/include/session.h
new file mode 100644
index 00000000..5aa3e5e4
--- /dev/null
+++ b/include/session.h
@@ -0,0 +1,52 @@
+/*
+ *
+ * Connection Manager
+ *
+ * Copyright (C) 2012 BMW Car IT GbmH. 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 version 2 as
+ * published by the Free Software Foundation.
+ *
+ * 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 St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifndef __CONNMAN_SESSION_H
+#define __CONNMAN_SESSION_H
+
+#include <connman/types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * The session are identified through the pid is only a temporary solution
+ */
+struct connman_session_config {
+ const char *name;
+ int (*get_bool) (const char *id, const char *key, connman_bool_t *val);
+ int (*get_string) (const char *id, const char *key, char **val);
+};
+
+int connman_session_config_register(struct connman_session_config *config);
+void connman_session_config_unregister(struct connman_session_config *config);
+
+int connman_session_update_bool(const char *id, const char *key,
+ connman_bool_t val);
+int connman_session_update_string(const char *id, const char *key,
+ const char *val);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMAN_SESSION_H */
diff --git a/plugins/session_default.c b/plugins/session_default.c
new file mode 100644
index 00000000..0c01139e
--- /dev/null
+++ b/plugins/session_default.c
@@ -0,0 +1,76 @@
+/*
+ *
+ * Connection Manager
+ *
+ * Copyright (C) 2012 BMW Car IT GbmH. 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 version 2 as
+ * published by the Free Software Foundation.
+ *
+ * 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 St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <errno.h>
+#include <string.h>
+
+#define CONNMAN_API_SUBJECT_TO_CHANGE
+#include <connman/plugin.h>
+#include <connman/log.h>
+#include <connman/session.h>
+
+static int config_get_bool(const char *id, const char *key, connman_bool_t *val)
+{
+ DBG("id %s key %s", id, key);
+
+ *val = FALSE;
+
+ return -EINVAL;
+}
+
+static int config_get_string(const char *id, const char *key, char **val)
+{
+ DBG("id %s key %s", id, key);
+
+ *val = NULL;
+
+ return -EINVAL;
+}
+
+static struct connman_session_config session_config = {
+ .name = "session default configuration",
+ .get_bool = config_get_bool,
+ .get_string = config_get_string,
+};
+
+static int session_config_init(void)
+{
+ int err;
+
+ err = connman_session_config_register(&session_config);
+ if (err < 0)
+ return err;
+
+ return 0;
+}
+
+static void session_config_exit(void)
+{
+ connman_session_config_unregister(&session_config);
+}
+
+CONNMAN_PLUGIN_DEFINE(session_default, "Session default configuration plugin",
+ VERSION, CONNMAN_PLUGIN_PRIORITY_DEFAULT,
+ session_config_init, session_config_exit)
diff --git a/src/session.c b/src/session.c
index 64e18b46..a1341d78 100644
--- a/src/session.c
+++ b/src/session.c
@@ -28,12 +28,15 @@
#include <gdbus.h>
+#include <connman/session.h>
+
#include "connman.h"
static DBusConnection *connection;
static GHashTable *session_hash;
static connman_bool_t sessionmode;
static struct session_info *ecall_info;
+static struct connman_session_config *session_config;
enum connman_session_trigger {
CONNMAN_SESSION_TRIGGER_UNKNOWN = 0,
@@ -1898,6 +1901,98 @@ static struct connman_notifier session_notifier = {
.ipconfig_changed = ipconfig_changed,
};
+static struct connman_session *session_lookup_by_id(const char *id)
+{
+ struct connman_session *session;
+ GHashTableIter iter;
+ gpointer key, value;
+
+ DBG("id %s", id);
+
+ g_hash_table_iter_init(&iter, session_hash);
+
+ while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
+ session = value;
+
+ if (g_strcmp0(session->owner, id) == FALSE)
+ continue;
+
+ return session;
+ }
+
+ DBG("No session found by id %s", id);
+
+ return NULL;
+}
+
+int connman_session_update_bool(const char *id, const char *key,
+ connman_bool_t val)
+{
+ struct connman_session *session;
+ struct session_info *info;
+
+ session = session_lookup_by_id(id);
+ if (session == NULL)
+ return -EINVAL;
+
+ info = session->info;
+ if (info == NULL)
+ return 0;
+
+ DBG("%s %d", key, val);
+
+ return -EINVAL;
+}
+
+int connman_session_update_string(const char *id, const char *key,
+ const char *val)
+{
+ struct connman_session *session;
+ struct session_info *info;
+
+ session = session_lookup_by_id(id);
+ if (session == NULL)
+ return -EINVAL;
+
+ info = session->info;
+ if (info == NULL)
+ return 0;
+
+ DBG("%s %s", key, val);
+
+ return -EINVAL;
+}
+
+int connman_session_config_register(struct connman_session_config *config)
+{
+ DBG("name %s", config->name);
+
+ if (session_config != NULL) {
+ connman_warn("A session configuration plugin '%s' is "
+ "already registerd. Skipping registration "
+ "of plugin '%s'",
+ session_config->name, config->name);
+ return -EALREADY;
+ }
+
+ session_config = config;
+
+ return 0;
+}
+
+void connman_session_config_unregister(struct connman_session_config *config)
+{
+ DBG("name %s", config->name);
+
+ if (config != session_config) {
+ connman_warn("Trying to unregister session configuration "
+ "plugin '%s'", config->name);
+ return;
+ }
+
+ session_config = NULL;
+}
+
int __connman_session_init(void)
{
int err;