diff options
author | Luiz Augusto von Dentz <luiz.dentz@openbossa.org> | 2007-09-28 13:15:53 +0000 |
---|---|---|
committer | Luiz Augusto von Dentz <luiz.dentz@openbossa.org> | 2007-09-28 13:15:53 +0000 |
commit | 2033d8e42102bb6513e5ea71e147a8a7dcce1420 (patch) | |
tree | 5fe2c7c8bbc02c38093afcd349a94d641f0e2230 /network | |
parent | 2fb6bb97176c9e922c14584da550f3edd49f0986 (diff) |
Add support for config file.
Diffstat (limited to 'network')
-rw-r--r-- | network/connection.h | 6 | ||||
-rw-r--r-- | network/main.c | 117 | ||||
-rw-r--r-- | network/manager.c | 2 | ||||
-rw-r--r-- | network/manager.h | 11 | ||||
-rw-r--r-- | network/network.conf | 36 | ||||
-rw-r--r-- | network/server.c | 1 | ||||
-rw-r--r-- | network/server.h | 8 |
7 files changed, 178 insertions, 3 deletions
diff --git a/network/connection.h b/network/connection.h index 5561ee32..35726732 100644 --- a/network/connection.h +++ b/network/connection.h @@ -21,6 +21,12 @@ * */ +struct connection_conf { + char *panu_script; + char *gn_script; + char *nap_script; +}; + int connection_register(DBusConnection *conn, const char *path, bdaddr_t *src, bdaddr_t *dst, uint16_t id, const char *name, const char *desc); int connection_store(DBusConnection *conn, const char *path, diff --git a/network/main.c b/network/main.c index 2d9d44b6..5d1f5013 100644 --- a/network/main.c +++ b/network/main.c @@ -41,13 +41,128 @@ #include "manager.h" #include "hal.h" +#define IFACE_PREFIX "bnep%d" +#define PANU_IFACE "pan0" +#define GN_IFACE "pan1" +#define NAP_IFACE "pan2" + static GMainLoop *main_loop; +static struct network_conf conf = { + .connection_enabled = TRUE, + .server_enabled = TRUE, + .iface_prefix = NULL, + .conn.panu_script = NULL, + .conn.gn_script = NULL, + .conn.nap_script = NULL, + .server.panu_iface = NULL, + .server.gn_iface = NULL, + .server.nap_iface = NULL, + .server.disable_security = FALSE +}; + static void sig_term(int sig) { g_main_loop_quit(main_loop); } +static void read_config(const char *file) +{ + GKeyFile *keyfile; + GError *err = NULL; + + keyfile = g_key_file_new(); + + if (!g_key_file_load_from_file(keyfile, file, 0, &err)) { + error("Parsing %s failed: %s", file, err->message); + g_error_free(err); + g_key_file_free(keyfile); + return; + } + + conf.iface_prefix = g_key_file_get_string(keyfile, "Connection", + "InterfacePrefix", &err); + if (!conf.iface_prefix) + conf.iface_prefix = g_strdup(IFACE_PREFIX); + if (err) { + debug("%s: %s", file, err->message); + g_error_free(err); + err = NULL; + } + + conf.conn.panu_script = g_key_file_get_string(keyfile, "Connection", + "PANUScript", &err); + if (err) { + debug("%s: %s", file, err->message); + g_error_free(err); + err = NULL; + } + + conf.conn.gn_script = g_key_file_get_string(keyfile, "Connection", + "GNScript", &err); + if (err) { + debug("%s: %s", file, err->message); + g_error_free(err); + err = NULL; + } + + conf.conn.nap_script = g_key_file_get_string(keyfile, "Connection", + "NAPScript", &err); + if (err) { + debug("%s: %s", file, err->message); + g_error_free(err); + err = NULL; + } + + conf.server.panu_iface = g_key_file_get_string(keyfile, "Server", + "PANUInterface", &err); + if (!conf.server.panu_iface) + conf.server.panu_iface = g_strdup(PANU_IFACE); + if (err) { + debug("%s: %s", file, err->message); + g_error_free(err); + err = NULL; + } + + conf.server.gn_iface = g_key_file_get_string(keyfile, "Server", + "GNInterface", &err); + if (!conf.server.gn_iface) + conf.server.gn_iface = g_strdup(GN_IFACE); + if (err) { + debug("%s: %s", file, err->message); + g_error_free(err); + err = NULL; + } + + conf.server.nap_iface = g_key_file_get_string(keyfile, "Server", + "NAPInterface", &err); + if (!conf.server.nap_iface) + conf.server.nap_iface = g_strdup(NAP_IFACE); + if (err) { + debug("%s: %s", file, err->message); + g_error_free(err); + err = NULL; + } + + conf.server.disable_security = g_key_file_get_boolean(keyfile, "Server", + "DisableSecurity", &err); + if (err) { + debug("%s: %s", file, err->message); + g_error_free(err); + err = NULL; + } + + debug("Config options: InterfacePrefix=%s, PANUScript=%s, GNScript=%s, " + "NAPScript=%s, PANUInterface=%s, GNInterface=%s, " + "NAPInterface=%s, DisableSecurity=%s", conf.iface_prefix, + conf.conn.panu_script, conf.conn.gn_script, conf.conn.nap_script, + conf.server.panu_iface, conf.server.gn_iface, + conf.server.nap_iface, + conf.server.disable_security ? "true" : "false"); + + g_key_file_free(keyfile); +} + int main(int argc, char *argv[]) { DBusConnection *conn; @@ -67,6 +182,8 @@ int main(int argc, char *argv[]) enable_debug(); + read_config(CONFIGDIR "/network.conf"); + main_loop = g_main_loop_new(NULL, FALSE); conn = dbus_bus_system_setup_with_main_loop(NULL, NULL, NULL); diff --git a/network/manager.c b/network/manager.c index 7bc56142..2bf76e03 100644 --- a/network/manager.c +++ b/network/manager.c @@ -50,8 +50,6 @@ #include "error.h" #include "bridge.h" #include "manager.h" -#include "server.h" -#include "connection.h" #include "common.h" #define MAX_NAME_SIZE 256 diff --git a/network/manager.h b/network/manager.h index 9ad1009e..45c7ada4 100644 --- a/network/manager.h +++ b/network/manager.h @@ -21,9 +21,20 @@ * */ +#include "connection.h" +#include "server.h" + #define MAX_PATH_LENGTH 64 /* D-Bus path */ #define NETWORK_PATH "/org/bluez/network" +struct network_conf { + gboolean connection_enabled; + gboolean server_enabled; + char *iface_prefix; + struct connection_conf conn; + struct server_conf server; +}; + int network_init(DBusConnection *conn); void network_exit(void); diff --git a/network/network.conf b/network/network.conf index f3c93bad..66136002 100644 --- a/network/network.conf +++ b/network/network.conf @@ -1,2 +1,38 @@ # Configuration file for the network service +# This section contains options which are not specific to any +# particular interface +[General] + +# If we want to disable support for specific services +# Defaults to supporting all implemented services +#Disable=Connection,Server + +# Network interface name prefix for connections. default:bnep%d +# (up to 16 characters) +InterfacePrefix=bnep%d + +[Connection] + +# PAN user connection interface up script. default: +PANUScript=/usr/sbin/avahi-autoipd + +# Group Network connection interface up script. default: +GNScript=/usr/sbin/avahi-autoipd + +# Network Access Point connection interface up script. default: +NAPScript=/sbin/dhclient + +[Server] + +# Network Interface name for PAN user server. default:pan0 +PANUInterface=pan0 + +# Network Interface name for Group Network server. default:pan1 +GNInterface=pan1 + +# Network Interface name for Network Access Point server. default:pan2 +NAPInterface=pan2 + +# Disable link encryption: default=false +DisableSecurity=false diff --git a/network/server.c b/network/server.c index 5b741edd..39cb4067 100644 --- a/network/server.c +++ b/network/server.c @@ -59,7 +59,6 @@ #include "bridge.h" #include "common.h" #include "manager.h" -#include "server.h" /* Pending Authorization */ struct setup_session { diff --git a/network/server.h b/network/server.h index d96b7ecb..2b148081 100644 --- a/network/server.h +++ b/network/server.h @@ -20,6 +20,14 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * */ + +struct server_conf { + char *panu_iface; + char *gn_iface; + char *nap_iface; + gboolean disable_security; +}; + int server_init(DBusConnection *conn); void server_exit(); int server_register(const char *path, bdaddr_t *src, uint16_t id); |