Files
Alexander Pevzner 07ebd85003 Added SANE_AIRSCAN_DEVICE environment variable
This variable, if set, overrides all devices, manually configured
in the log files and disables auto discovery.

Examples:

    SANE_AIRSCAN_DEVICE="escl:Kyocera eSCL:http://192.168.1.102:9095/eSCL"
    SANE_AIRSCAN_DEVICE="wsd:Kyocera WSD:http://192.168.1.102:5358/WSDScanner"

Formal syntax:

    "PROTO:DEVICE NAME:URL"

    Where:

	- PROTO` is either `escl` or `wsd`.
	- DEVICE NAME will appear in the list of devices.
	- URL is the device URL, using `http:` or `https:` schemes.

The primary purpose of this variable is the automated testing
of the `sane-airscan` backend.
2025-04-29 12:16:41 +03:00

101 lines
2.0 KiB
C

/* AirScan (a.k.a. eSCL) backend for SANE
*
* Copyright (C) 2019 and up by Alexander Pevzner (pzz@apevzner.com)
* See LICENSE for license terms and conditions
*
* Initialization/cleanup
*/
#include "airscan.h"
/* Saved init flags
*/
static AIRSCAN_INIT_FLAGS airscan_init_flags;
/* Initialize airscan
*/
SANE_Status
airscan_init (AIRSCAN_INIT_FLAGS flags, const char *log_msg)
{
SANE_Status status;
/* Save init flags */
airscan_init_flags = flags;
/* Initialize logging -- do it early */
log_init();
trace_init();
if (log_msg != NULL) {
log_debug(NULL, "%s", log_msg);
}
if ((flags & AIRSCAN_INIT_NO_CONF) == 0) {
conf_load();
}
log_configure(); /* As soon, as configuration is available */
/* Initialize all parts */
status = eloop_init();
if (status == SANE_STATUS_GOOD) {
status = rand_init();
}
if (status == SANE_STATUS_GOOD) {
status = http_init();
}
if (status == SANE_STATUS_GOOD) {
status = netif_init();
}
if (status == SANE_STATUS_GOOD) {
status = zeroconf_init();
}
if (status == SANE_STATUS_GOOD) {
status = mdns_init();
}
if (status == SANE_STATUS_GOOD) {
status = wsdd_init();
}
if (status != SANE_STATUS_GOOD) {
airscan_cleanup(NULL);
} else if ((flags & AIRSCAN_INIT_NO_THREAD) == 0) {
eloop_thread_start();
}
return status;
}
/* Cleanup airscan
* If log_msg is not NULL, it is written to the log as late as possible
*/
void
airscan_cleanup (const char *log_msg)
{
mdns_cleanup();
wsdd_cleanup();
zeroconf_cleanup();
netif_cleanup();
http_cleanup();
rand_cleanup();
eloop_cleanup();
if (log_msg != NULL) {
log_debug(NULL, "%s", log_msg);
}
conf_unload();
trace_cleanup();
log_cleanup(); /* Must be the last thing to do */
}
/* Get init flags from the airscan_init call
*/
AIRSCAN_INIT_FLAGS
airscan_get_init_flags (void)
{
return airscan_init_flags;
}
/* vim:ts=8:sw=4:et
*/