diff --git a/configure.ac b/configure.ac index cc2a577..2fa04ef 100644 --- a/configure.ac +++ b/configure.ac @@ -81,15 +81,26 @@ then AC_DEFINE([LOG], [1], [Enable log]) fi -# Conf support (default:yes) -AC_ARG_ENABLE([conf],AS_HELP_STRING([--disable-conf],[Disable use of config files and environment variables]),[enable_conf=$enableval],[enable_conf="yes"]) -AC_MSG_CHECKING(for conf flag) -AC_MSG_RESULT($enable_conf) -AM_CONDITIONAL([WITH_CONF], [test "$enable_conf" != "no"]) +# Conffiles support (default:yes) +AC_ARG_ENABLE([conffiles],AS_HELP_STRING([--disable-conffiles],[Disable use of config files]),[enable_conffiles=$enableval],[enable_conffiles="yes"]) +AC_MSG_CHECKING(for conffiles flag) +AC_MSG_RESULT($enable_conffiles) +AM_CONDITIONAL([WITH_CONFFILES], [test "$enable_conffiles" != "no"]) -if test x"$enable_conf" = "xyes" +if test x"$enable_conffiles" = "xyes" then - AC_DEFINE([CONF], [1], [Enable conf]) + AC_DEFINE([CONFFILES], [1], [Enable conffiles]) +fi + +# Envvars support (default:yes) +AC_ARG_ENABLE([envvars],AS_HELP_STRING([--disable-envvars],[Disable use of environment variables]),[enable_envvars=$enableval],[enable_envvars="yes"]) +AC_MSG_CHECKING(for envvars flag) +AC_MSG_RESULT($enable_envvars) +AM_CONDITIONAL([WITH_ENVVARS], [test "$enable_envvars" != "no"]) + +if test x"$enable_envvars" = "xyes" +then + AC_DEFINE([ENVVARS], [1], [Enable envvars]) fi # Debug support (default:no) diff --git a/libnfc/conf.c b/libnfc/conf.c index 2fa744f..87aec26 100644 --- a/libnfc/conf.c +++ b/libnfc/conf.c @@ -21,7 +21,7 @@ # include "config.h" #endif // HAVE_CONFIG_H -#ifdef CONF +#ifdef CONFFILES #include #include #include @@ -190,5 +190,5 @@ conf_load(nfc_context *context) conf_devices_load(LIBNFC_DEVICECONFDIR, context); } -#endif // CONF +#endif // CONFFILES diff --git a/libnfc/log-printf.c b/libnfc/log-printf.c index d0405d5..e8ef238 100644 --- a/libnfc/log-printf.c +++ b/libnfc/log-printf.c @@ -34,7 +34,7 @@ void log_init(const nfc_context *context) { -#ifdef CONF +#ifdef ENVVARS char str[32]; sprintf(str, "%"PRIu32, context->log_level); setenv("LIBNFC_LOG_LEVEL", str, 1); @@ -52,7 +52,7 @@ void log_put(const uint8_t group, const char *category, const uint8_t priority, const char *format, ...) { char *env_log_level = NULL; -#ifdef CONF +#ifdef ENVVARS env_log_level = getenv("LIBNFC_LOG_LEVEL"); #endif uint32_t log_level; diff --git a/libnfc/nfc-internal.c b/libnfc/nfc-internal.c index 8afa5fb..5a40325 100644 --- a/libnfc/nfc-internal.c +++ b/libnfc/nfc-internal.c @@ -29,7 +29,7 @@ #include "config.h" #endif -#ifdef CONF +#ifdef CONFFILES #include "conf.h" #endif @@ -88,7 +88,7 @@ nfc_context_new(void) } res->user_defined_device_count = 0; -#ifdef CONF +#ifdef ENVVARS // Load user defined device from environment variable at first char *envvar = getenv("LIBNFC_DEFAULT_DEVICE"); if (envvar) { @@ -97,9 +97,14 @@ nfc_context_new(void) res->user_defined_device_count++; } +#endif // ENVVARS + +#ifdef CONFFILES // Load options from configuration file (ie. /etc/nfc/libnfc.conf) conf_load(res); +#endif // CONFFILES +#ifdef ENVVARS // Environment variables // Load "intrusive scan" option envvar = getenv("LIBNFC_INTRUSIVE_SCAN"); @@ -110,7 +115,7 @@ nfc_context_new(void) if (envvar) { res->log_level = atoi(envvar); } -#endif // CONF +#endif // ENVVARS // Initialize log before use it... log_init(res); diff --git a/libnfc/nfc.c b/libnfc/nfc.c index a9fe746..b3ce252 100644 --- a/libnfc/nfc.c +++ b/libnfc/nfc.c @@ -294,13 +294,15 @@ nfc_list_devices(nfc_context *context, nfc_connstring connstrings[], const size_ { size_t device_found = 0; -#ifdef CONF +#ifdef CONFFILES // Load manually configured devices (from config file and env variables) // TODO From env var... for (uint32_t i = 0; i < context->user_defined_device_count; i++) { if (context->user_defined_devices[i].optional) { // let's make sure the device exists nfc_device *pnd = NULL; + +#ifdef ENVVARS char *env_log_level = getenv("LIBNFC_LOG_LEVEL"); char *old_env_log_level = NULL; // do it silently @@ -312,13 +314,19 @@ nfc_list_devices(nfc_context *context, nfc_connstring connstrings[], const size_ strcpy(old_env_log_level, env_log_level); } setenv("LIBNFC_LOG_LEVEL", "0", 1); +#endif // ENVVARS + pnd = nfc_open(context, context->user_defined_devices[i].connstring); + +#ifdef ENVVARS if (old_env_log_level) { setenv("LIBNFC_LOG_LEVEL", old_env_log_level, 1); free(old_env_log_level); } else { unsetenv("LIBNFC_LOG_LEVEL"); } +#endif // ENVVARS + if (pnd) { nfc_close(pnd); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "User device %s found", context->user_defined_devices[i].name); @@ -335,7 +343,7 @@ nfc_list_devices(nfc_context *context, nfc_connstring connstrings[], const size_ return device_found; } } -#endif // CONF +#endif // CONFFILES // Device auto-detection if (context->allow_autoscan) {