Make it possible to disable conf.
Now the configure script has --disable-conf command-line argument that can be used to turn off environment variables and use of configuration files.
This commit is contained in:
parent
72b10c5d9b
commit
fd6d4db5b7
5 changed files with 33 additions and 1 deletions
11
configure.ac
11
configure.ac
|
@ -81,6 +81,17 @@ then
|
||||||
AC_DEFINE([LOG], [1], [Enable log])
|
AC_DEFINE([LOG], [1], [Enable log])
|
||||||
fi
|
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"])
|
||||||
|
|
||||||
|
if test x"$enable_conf" = "xyes"
|
||||||
|
then
|
||||||
|
AC_DEFINE([CONF], [1], [Enable conf])
|
||||||
|
fi
|
||||||
|
|
||||||
# Debug support (default:no)
|
# Debug support (default:no)
|
||||||
AC_ARG_ENABLE([debug],AS_HELP_STRING([--enable-debug],[Enable debug mode]),[enable_debug=$enableval],[enable_debug="no"])
|
AC_ARG_ENABLE([debug],AS_HELP_STRING([--enable-debug],[Enable debug mode]),[enable_debug=$enableval],[enable_debug="no"])
|
||||||
AC_MSG_CHECKING(for debug flag)
|
AC_MSG_CHECKING(for debug flag)
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
# include "config.h"
|
# include "config.h"
|
||||||
#endif // HAVE_CONFIG_H
|
#endif // HAVE_CONFIG_H
|
||||||
|
|
||||||
|
#ifdef CONF
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
@ -189,3 +190,5 @@ conf_load(nfc_context *context)
|
||||||
conf_devices_load(LIBNFC_DEVICECONFDIR, context);
|
conf_devices_load(LIBNFC_DEVICECONFDIR, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // CONF
|
||||||
|
|
||||||
|
|
|
@ -34,9 +34,13 @@
|
||||||
void
|
void
|
||||||
log_init(const nfc_context *context)
|
log_init(const nfc_context *context)
|
||||||
{
|
{
|
||||||
|
#ifdef CONF
|
||||||
char str[32];
|
char str[32];
|
||||||
sprintf(str, "%"PRIu32, context->log_level);
|
sprintf(str, "%"PRIu32, context->log_level);
|
||||||
setenv("LIBNFC_LOG_LEVEL", str, 1);
|
setenv("LIBNFC_LOG_LEVEL", str, 1);
|
||||||
|
#else
|
||||||
|
(void)context;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -47,7 +51,10 @@ log_exit(void)
|
||||||
void
|
void
|
||||||
log_put(const uint8_t group, const char *category, const uint8_t priority, const char *format, ...)
|
log_put(const uint8_t group, const char *category, const uint8_t priority, const char *format, ...)
|
||||||
{
|
{
|
||||||
char *env_log_level = getenv("LIBNFC_LOG_LEVEL");
|
char *env_log_level = NULL;
|
||||||
|
#ifdef CONF
|
||||||
|
env_log_level = getenv("LIBNFC_LOG_LEVEL");
|
||||||
|
#endif
|
||||||
uint32_t log_level;
|
uint32_t log_level;
|
||||||
if (NULL == env_log_level) {
|
if (NULL == env_log_level) {
|
||||||
// LIBNFC_LOG_LEVEL is not set
|
// LIBNFC_LOG_LEVEL is not set
|
||||||
|
|
|
@ -24,7 +24,14 @@
|
||||||
|
|
||||||
#include <nfc/nfc.h>
|
#include <nfc/nfc.h>
|
||||||
#include "nfc-internal.h"
|
#include "nfc-internal.h"
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONF
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -81,6 +88,7 @@ nfc_context_new(void)
|
||||||
}
|
}
|
||||||
res->user_defined_device_count = 0;
|
res->user_defined_device_count = 0;
|
||||||
|
|
||||||
|
#ifdef CONF
|
||||||
// Load user defined device from environment variable at first
|
// Load user defined device from environment variable at first
|
||||||
char *envvar = getenv("LIBNFC_DEFAULT_DEVICE");
|
char *envvar = getenv("LIBNFC_DEFAULT_DEVICE");
|
||||||
if (envvar) {
|
if (envvar) {
|
||||||
|
@ -102,6 +110,7 @@ nfc_context_new(void)
|
||||||
if (envvar) {
|
if (envvar) {
|
||||||
res->log_level = atoi(envvar);
|
res->log_level = atoi(envvar);
|
||||||
}
|
}
|
||||||
|
#endif // CONF
|
||||||
|
|
||||||
// Initialize log before use it...
|
// Initialize log before use it...
|
||||||
log_init(res);
|
log_init(res);
|
||||||
|
|
|
@ -294,6 +294,7 @@ nfc_list_devices(nfc_context *context, nfc_connstring connstrings[], const size_
|
||||||
{
|
{
|
||||||
size_t device_found = 0;
|
size_t device_found = 0;
|
||||||
|
|
||||||
|
#ifdef CONF
|
||||||
// Load manually configured devices (from config file and env variables)
|
// Load manually configured devices (from config file and env variables)
|
||||||
// TODO From env var...
|
// TODO From env var...
|
||||||
for (uint32_t i = 0; i < context->user_defined_device_count; i++) {
|
for (uint32_t i = 0; i < context->user_defined_device_count; i++) {
|
||||||
|
@ -334,6 +335,7 @@ nfc_list_devices(nfc_context *context, nfc_connstring connstrings[], const size_
|
||||||
return device_found;
|
return device_found;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif // CONF
|
||||||
|
|
||||||
// Device auto-detection
|
// Device auto-detection
|
||||||
if (context->allow_autoscan) {
|
if (context->allow_autoscan) {
|
||||||
|
|
Loading…
Reference in a new issue