1
0
Fork 0
mirror of https://github.com/albfan/miraclecast.git synced 2025-03-09 23:38:56 +00:00

Ini files for miracle-wifid

Honor ~/.miraclecast or ~/.config/miraclecastrc

Properties avaliable:
- wifid: log-level
- sinkctl: external-player, rstp-port, log-level, log-journal-level, autocmd
- wifictl: log-level, journal-log-level

Command line has always higher priority over ini files

fixes #113
This commit is contained in:
albfan 2017-03-27 03:13:47 +02:00 committed by Alberto Fanjul
parent 1bc0648f4b
commit 04a1ec8aa3
10 changed files with 136 additions and 19 deletions

View file

@ -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))

View file

@ -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)

View file

@ -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;
@ -749,7 +750,8 @@ static int ctl_main(int argc, char *argv[])
return r;
left = argc - optind;
r = ctl_interactive(argv + optind, left <= 0 ? 0 : left);
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;

View file

@ -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;
@ -423,6 +424,7 @@ void cli_fn_help()
" --help-commands Show avaliable commands\n"
" --version Show package version\n"
" --log-level <lvl> Maximum level for log messages\n"
" --log-journal-level <lvl> 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;

View file

@ -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)

View file

@ -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)

View file

@ -31,6 +31,26 @@
#include <systemd/sd-bus.h>
#include <time.h>
#include "shl_macro.h"
#include <glib.h>
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)
{

View file

@ -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)

View file

@ -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)

View file

@ -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;