1 From bf549a028a5da122b7a4206529711b969c2ecd48 Mon Sep 17 00:00:00 2001
2 From: Jan Tojnar <jtojnar@gmail.com>
3 Date: Fri, 1 Sep 2017 13:49:06 +0200
4 Subject: [PATCH] Search connectors in DLEYNA_CONNECTOR_PATH
6 Previously, the connectors would only be looked for in a single
7 directory, specified during compilation. This patch allows to
8 traverse a list of directories provided by an environment variable.
10 libdleyna/core/connector-mgr.c | 63 ++++++++++++++++++++++++++++--------------
11 1 file changed, 42 insertions(+), 21 deletions(-)
13 diff --git a/libdleyna/core/connector-mgr.c b/libdleyna/core/connector-mgr.c
14 index eafb16c..8041c67 100644
15 --- a/libdleyna/core/connector-mgr.c
16 +++ b/libdleyna/core/connector-mgr.c
17 @@ -34,33 +34,54 @@ const dleyna_connector_t *dleyna_connector_mgr_load(const gchar *name)
18 const dleyna_connector_t *connector;
19 dleyna_connector_get_interface_t get_interface;
21 + const gchar *connector_path;
22 + gchar **connector_path_list;
25 DLEYNA_LOG_DEBUG("Enter");
27 - path = g_strdup_printf("%s/%s%s.so", CONNECTOR_DIR,
28 - DLEYNA_CONNECTOR_LIB_PATTERN, name);
29 - module = g_module_open(path, G_MODULE_BIND_LAZY);
31 + connector_path = g_getenv ("DLEYNA_CONNECTOR_PATH");
32 + if (!connector_path) {
33 + DLEYNA_LOG_DEBUG ("DLEYNA_CONNECTOR_PATH not set");
34 + connector_path = CONNECTOR_DIR;
36 + DLEYNA_LOG_DEBUG ("DLEYNA_CONNECTOR_PATH set to %s", connector_path);
39 + connector_path_list = g_strsplit (connector_path, G_SEARCHPATH_SEPARATOR_S, 0);
41 + for (i = 0; connector_path_list[i]; i++) {
42 + path = g_strdup_printf("%s/%s%s.so", connector_path_list[i],
43 + DLEYNA_CONNECTOR_LIB_PATTERN, name);
44 + module = g_module_open(path, G_MODULE_BIND_LAZY);
49 + g_connectors = g_hash_table_new(g_direct_hash,
52 + if (g_module_symbol(module, "dleyna_connector_get_interface",
53 + (gpointer *)&get_interface)) {
54 + connector = get_interface();
55 + g_hash_table_insert(g_connectors, (gpointer)connector,
61 + g_module_close(module);
62 + DLEYNA_LOG_CRITICAL(
63 + "Connector '%s' entry point not found",
69 - g_connectors = g_hash_table_new(g_direct_hash,
72 - if (g_module_symbol(module, "dleyna_connector_get_interface",
73 - (gpointer *)&get_interface)) {
74 - connector = get_interface();
75 - g_hash_table_insert(g_connectors, (gpointer)connector,
79 - g_module_close(module);
80 - DLEYNA_LOG_CRITICAL(
81 - "Connector '%s' entry point not found",
87 + g_strfreev (connector_path_list);
91 DLEYNA_LOG_CRITICAL("Connector '%s' not found", name);