Commit fd6d4db5 authored by Ahti Legonkov's avatar Ahti Legonkov Committed by Philippe Teuwen

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.
parent 72b10c5d
......@@ -81,6 +81,17 @@ 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"])
if test x"$enable_conf" = "xyes"
then
AC_DEFINE([CONF], [1], [Enable conf])
fi
# Debug support (default: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)
......
......@@ -21,6 +21,7 @@
# include "config.h"
#endif // HAVE_CONFIG_H
#ifdef CONF
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
......@@ -189,3 +190,5 @@ conf_load(nfc_context *context)
conf_devices_load(LIBNFC_DEVICECONFDIR, context);
}
#endif // CONF
......@@ -34,9 +34,13 @@
void
log_init(const nfc_context *context)
{
#ifdef CONF
char str[32];
sprintf(str, "%"PRIu32, context->log_level);
setenv("LIBNFC_LOG_LEVEL", str, 1);
#else
(void)context;
#endif
}
void
......@@ -47,7 +51,10 @@ log_exit(void)
void
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;
if (NULL == env_log_level) {
// LIBNFC_LOG_LEVEL is not set
......
......@@ -24,7 +24,14 @@
#include <nfc/nfc.h>
#include "nfc-internal.h"
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef CONF
#include "conf.h"
#endif
#include <stdlib.h>
#include <string.h>
......@@ -81,6 +88,7 @@ nfc_context_new(void)
}
res->user_defined_device_count = 0;
#ifdef CONF
// Load user defined device from environment variable at first
char *envvar = getenv("LIBNFC_DEFAULT_DEVICE");
if (envvar) {
......@@ -102,6 +110,7 @@ nfc_context_new(void)
if (envvar) {
res->log_level = atoi(envvar);
}
#endif // CONF
// Initialize log before use it...
log_init(res);
......
......@@ -294,6 +294,7 @@ nfc_list_devices(nfc_context *context, nfc_connstring connstrings[], const size_
{
size_t device_found = 0;
#ifdef CONF
// 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++) {
......@@ -334,6 +335,7 @@ nfc_list_devices(nfc_context *context, nfc_connstring connstrings[], const size_
return device_found;
}
}
#endif // CONF
// Device auto-detection
if (context->allow_autoscan) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment