diff --git a/configure.ac b/configure.ac index a2f3738..1f0aa64 100644 --- a/configure.ac +++ b/configure.ac @@ -46,7 +46,7 @@ AC_ARG_ENABLE([log-debug], # PKG_CHECK_MODULES([DEPS], [libudev libsystemd > 219]) -PKG_CHECK_MODULES([GDHCP], [glib-2.0]) +PKG_CHECK_MODULES([GLIB], [glib-2.0]) AC_CHECK_HEADERS(readline/readline.h,, AC_MSG_ERROR(GNU readline not found)) diff --git a/src/ctl/Makefile.am b/src/ctl/Makefile.am index f02d052..ded5b45 100644 --- a/src/ctl/Makefile.am +++ b/src/ctl/Makefile.am @@ -8,7 +8,8 @@ miracle_wifictl_SOURCES = \ wifictl.c miracle_wifictl_CPPFLAGS = \ $(AM_CPPFLAGS) \ - $(DEPS_CFLAGS) + $(DEPS_CFLAGS) \ + $(GLIB_CFLAGS) miracle_wifictl_LDADD = \ ../shared/libmiracle-shared.la \ -lreadline \ @@ -24,10 +25,12 @@ miracle_sinkctl_SOURCES = \ sinkctl.c miracle_sinkctl_CPPFLAGS = \ $(AM_CPPFLAGS) \ - $(DEPS_CFLAGS) + $(DEPS_CFLAGS) \ + $(GLIB_CFLAGS) miracle_sinkctl_LDADD = \ ../shared/libmiracle-shared.la \ -lreadline \ - $(DEPS_LIBS) + $(DEPS_LIBS) \ + $(GLIB_LIBS) diff --git a/src/ctl/sinkctl.c b/src/ctl/sinkctl.c index 5514a86..844dd9c 100644 --- a/src/ctl/sinkctl.c +++ b/src/ctl/sinkctl.c @@ -38,6 +38,7 @@ #include "wfd.h" #include "shl_macro.h" #include "shl_util.h" +#include "util.h" #include "config.h" static sd_bus *bus; @@ -748,8 +749,9 @@ static int ctl_main(int argc, char *argv[]) if (r < 0) return r; - left = argc - optind; - r = ctl_interactive(argv + optind, left <= 0 ? 0 : left); + left = argc - optind; + left = left <= 0 ? 0 : left; + r = ctl_interactive(argv + optind, left); /* stop all scans */ shl_dlist_for_each(i, &wifi->links) { @@ -854,9 +856,59 @@ static int parse_argv(int argc, char *argv[]) int main(int argc, char **argv) { int r; + bool free_argv = false; setlocale(LC_ALL, ""); + GKeyFile* gkf = load_ini_file(); + + gchar** autocmds_free = NULL; + if (gkf) { + player = g_key_file_get_string (gkf, "sinkctl", "external-player", NULL); + if (player) { + external_player = true; + } + gchar* log_level; + log_level = g_key_file_get_string (gkf, "sinkctl", "log-journal-level", NULL); + if (log_level) { + log_max_sev = log_parse_arg(log_level); + g_free(log_level); + } + log_level = g_key_file_get_string (gkf, "sinkctl", "log-level", NULL); + if (log_level) { + cli_max_sev = log_parse_arg(log_level); + g_free(log_level); + } + gchar* rstp_port_str = g_key_file_get_string (gkf, "sinkctl", "rstp-port", NULL); + if (rstp_port_str) { + rstp_port = atoi(rstp_port_str); + g_free(rstp_port_str); + } + gchar* autocmd; + autocmd = g_key_file_get_string (gkf, "sinkctl", "autocmd", NULL); + if (autocmd && argc == 1) { + gchar** autocmds = g_strsplit(autocmd, " ", -1); + autocmds_free = autocmds; + while (*autocmds) { + if (strcmp(*autocmds, "") != 0) { + gchar **newv = malloc((argc + 2) * sizeof(gchar*)); + memmove(newv, argv, sizeof(gchar*) * argc); + newv[argc] = *autocmds; + newv[argc+1] = NULL; + argc++; + if (free_argv) { + free(argv); + } + argv = newv; + free_argv = true; + } + autocmds++; + } + g_free(autocmd); + } + g_key_file_free(gkf); + } + r = parse_argv(argc, argv); if (r < 0) return EXIT_FAILURE; @@ -870,6 +922,10 @@ int main(int argc, char **argv) } r = ctl_main(argc, argv); + g_strfreev(autocmds_free); + if (free_argv) { + free(argv); + } sd_bus_unref(bus); return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; diff --git a/src/ctl/wifictl.c b/src/ctl/wifictl.c index 7058d2c..d3ad7f3 100644 --- a/src/ctl/wifictl.c +++ b/src/ctl/wifictl.c @@ -31,6 +31,7 @@ #include "ctl.h" #include "shl_macro.h" #include "shl_util.h" +#include "util.h" #include "config.h" static sd_bus *bus; @@ -419,10 +420,11 @@ void cli_fn_help() printf("%s [OPTIONS...] {COMMAND} ...\n\n" "Send control command to or query the MiracleCast Wifi-Manager. If no arguments\n" "are given, an interactive command-line tool is provided.\n\n" - " -h --help Show this help\n" - " --help-commands Show avaliable commands\n" - " --version Show package version\n" - " --log-level Maximum level for log messages\n" + " -h --help Show this help\n" + " --help-commands Show avaliable commands\n" + " --version Show package version\n" + " --log-level Maximum level for log messages\n" + " --log-journal-level Maximum level for journal log messages\n" "\n" "Commands:\n" , program_invocation_short_name); @@ -498,6 +500,7 @@ static int parse_argv(int argc, char *argv[]) enum { ARG_VERSION = 0x100, ARG_LOG_LEVEL, + ARG_JOURNAL_LEVEL, ARG_HELP_COMMANDS, }; static const struct option options[] = { @@ -505,6 +508,7 @@ static int parse_argv(int argc, char *argv[]) { "help-commands", no_argument, NULL, ARG_HELP_COMMANDS }, { "version", no_argument, NULL, ARG_VERSION }, { "log-level", required_argument, NULL, ARG_LOG_LEVEL }, + { "log-journal-level", required_argument, NULL, ARG_JOURNAL_LEVEL }, {} }; int c; @@ -522,6 +526,9 @@ static int parse_argv(int argc, char *argv[]) case ARG_LOG_LEVEL: cli_max_sev = log_parse_arg(optarg); break; + case ARG_JOURNAL_LEVEL: + log_max_sev = log_parse_arg(optarg); + break; case '?': return -EINVAL; } @@ -536,6 +543,23 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); + GKeyFile* gkf = load_ini_file(); + + if (gkf) { + gchar* log_level; + log_level = g_key_file_get_string (gkf, "wifictl", "log-journal-level", NULL); + if (log_level) { + log_max_sev = log_parse_arg(log_level); + g_free(log_level); + } + log_level = g_key_file_get_string (gkf, "wifictl", "log-level", NULL); + if (log_level) { + cli_max_sev = log_parse_arg(log_level); + g_free(log_level); + } + g_key_file_free(gkf); + } + r = parse_argv(argc, argv); if (r < 0) return EXIT_FAILURE; diff --git a/src/dhcp/Makefile.am b/src/dhcp/Makefile.am index 2703f48..fb01fff 100644 --- a/src/dhcp/Makefile.am +++ b/src/dhcp/Makefile.am @@ -14,11 +14,11 @@ miracle_dhcp_SOURCES = \ miracle_dhcp_CPPFLAGS = \ $(AM_CPPFLAGS) \ $(DEPS_CFLAGS) \ - $(GDHCP_CFLAGS) + $(GLIB_CFLAGS) miracle_dhcp_LDADD = \ ../shared/libmiracle-shared.la \ $(DEPS_LIBS) \ - $(GDHCP_LIBS) + $(GLIB_LIBS) diff --git a/src/shared/Makefile.am b/src/shared/Makefile.am index e79c8ff..b98dd81 100644 --- a/src/shared/Makefile.am +++ b/src/shared/Makefile.am @@ -17,7 +17,7 @@ libmiracle_shared_la_SOURCES = \ util.h \ wpas.h \ wpas.c -libmiracle_shared_la_LIBADD = -lsystemd - - +libmiracle_shared_la_LIBADD = -lsystemd \ + $(DEPS_LIBS) \ + $(GLIB_LIBS) diff --git a/src/shared/util.h b/src/shared/util.h index 5b85742..0e0ba3c 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -31,6 +31,26 @@ #include #include #include "shl_macro.h" +#include + +static inline GKeyFile* load_ini_file() { + GKeyFile* gkf = NULL; + gchar* config_file; + + gkf = g_key_file_new(); + + config_file = g_build_filename(g_get_home_dir(), ".config", "miraclecastrc", NULL); + if (!g_key_file_load_from_file(gkf, config_file, G_KEY_FILE_NONE, NULL)) { + g_free(config_file); + config_file = g_build_filename(g_get_home_dir(), ".miraclecast", NULL); + if (!g_key_file_load_from_file(gkf, config_file, G_KEY_FILE_NONE, NULL)) { + g_key_file_free(gkf); + gkf = NULL; + } + } + g_free(config_file); + return gkf; +} static inline void cleanup_sd_bus_message(sd_bus_message **ptr) { diff --git a/src/wifi/CMakeLists.txt b/src/wifi/CMakeLists.txt index c041e34..0dd7585 100644 --- a/src/wifi/CMakeLists.txt +++ b/src/wifi/CMakeLists.txt @@ -23,8 +23,8 @@ pkg_check_modules (UDEV REQUIRED libudev) #link_directories( ${UDEV_LIBRARY_DIRS}) #include_directories( ${UDEV_INCLUDE_DIRS}) target_link_libraries(miracle-wifid ${UDEV_LIBRARIES}) -#link_directories( ${GLIB2_LIBRARY_DIRS}) -#include_directories( ${GLIB2_INCLUDE_DIRS}) +link_directories( ${GLIB2_LIBRARY_DIRS}) +include_directories( ${GLIB2_INCLUDE_DIRS}) target_link_libraries(miracle-wifid ${GLIB2_LIBRARIES}) install(TARGETS miracle-wifid DESTINATION bin) diff --git a/src/wifi/Makefile.am b/src/wifi/Makefile.am index 179d4cc..463ac17 100644 --- a/src/wifi/Makefile.am +++ b/src/wifi/Makefile.am @@ -10,8 +10,10 @@ miracle_wifid_SOURCES = \ wifid-supplicant.c miracle_wifid_CPPFLAGS = \ $(AM_CPPFLAGS) \ - $(DEPS_CFLAGS) + $(DEPS_CFLAGS) \ + $(GLIB_CFLAGS) miracle_wifid_LDADD = \ ../shared/libmiracle-shared.la \ - $(DEPS_LIBS) + $(DEPS_LIBS) \ + $(GLIB_LIBS) diff --git a/src/wifi/wifid.c b/src/wifi/wifid.c index ca7e461..09e7195 100644 --- a/src/wifi/wifid.c +++ b/src/wifi/wifid.c @@ -543,6 +543,18 @@ int main(int argc, char **argv) srand(time(NULL)); + GKeyFile* gkf = load_ini_file(); + + if (gkf) { + gchar* log_level; + log_level = g_key_file_get_string (gkf, "wifid", "log-level", NULL); + if (log_level) { + log_max_sev = log_parse_arg(log_level); + g_free(log_level); + } + g_key_file_free(gkf); + } + r = parse_argv(argc, argv); if (r < 0) return EXIT_FAILURE;