1999-08-09 18:06:01 +00:00
|
|
|
/* sane - Scanner Access Now Easy.
|
|
|
|
Copyright (C) 1996, 1997 David Mosberger-Tang
|
|
|
|
This file is part of the SANE package.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License as
|
|
|
|
published by the Free Software Foundation; either version 2 of the
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
|
|
|
MA 02111-1307, USA.
|
|
|
|
|
|
|
|
As a special exception, the authors of SANE give permission for
|
|
|
|
additional uses of the libraries contained in this release of SANE.
|
|
|
|
|
|
|
|
The exception is that, if you link a SANE library with other files
|
|
|
|
to produce an executable, this does not by itself cause the
|
|
|
|
resulting executable to be covered by the GNU General Public
|
|
|
|
License. Your use of that executable is in no way restricted on
|
|
|
|
account of linking the SANE library code into it.
|
|
|
|
|
|
|
|
This exception does not, however, invalidate any other reasons why
|
|
|
|
the executable file might be covered by the GNU General Public
|
|
|
|
License.
|
|
|
|
|
|
|
|
If you submit changes to SANE to the maintainers to be included in
|
|
|
|
a subsequent release, you agree by submitting the changes that
|
|
|
|
those changes may be distributed with this exception intact.
|
|
|
|
|
|
|
|
If you write modifications of your own for SANE, it is your choice
|
|
|
|
whether to permit this exception to apply to your modifications.
|
|
|
|
If you do not wish that, delete this exception notice.
|
|
|
|
|
|
|
|
This file implements a dynamic linking based SANE meta backend. It
|
|
|
|
allows managing an arbitrary number of SANE backends by using
|
|
|
|
dynamic linking to load backends on demand. */
|
|
|
|
|
2001-04-16 12:21:41 +00:00
|
|
|
/* Please increase version number with every change
|
|
|
|
(don't forget to update dll.desc) */
|
2010-09-18 08:35:35 +00:00
|
|
|
#define DLL_VERSION "1.0.13"
|
2001-04-13 17:04:51 +00:00
|
|
|
|
1999-08-09 18:06:01 +00:00
|
|
|
#ifdef _AIX
|
2002-12-04 20:30:48 +00:00
|
|
|
# include "lalloca.h" /* MUST come first for AIX! */
|
1999-08-09 18:06:01 +00:00
|
|
|
#endif
|
|
|
|
|
2005-07-15 21:59:25 +00:00
|
|
|
#ifdef __BEOS__
|
|
|
|
#include <kernel/OS.h>
|
|
|
|
#include <storage/FindDirectory.h>
|
|
|
|
#include <kernel/image.h>
|
|
|
|
#include <posix/dirent.h>
|
|
|
|
#endif
|
|
|
|
|
2009-05-08 03:06:20 +00:00
|
|
|
#include "../include/sane/config.h"
|
2000-08-12 15:11:46 +00:00
|
|
|
#include "lalloca.h"
|
1999-08-09 18:06:01 +00:00
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#if defined(HAVE_DLOPEN) && defined(HAVE_DLFCN_H)
|
|
|
|
# include <dlfcn.h>
|
|
|
|
|
|
|
|
/* Older versions of dlopen() don't define RTLD_NOW and RTLD_LAZY.
|
|
|
|
They all seem to use a mode of 1 to indicate RTLD_NOW and some do
|
|
|
|
not support RTLD_LAZY at all. Hence, unless defined, we define
|
|
|
|
both macros as 1 to play it safe. */
|
|
|
|
# ifndef RTLD_NOW
|
2000-08-12 15:11:46 +00:00
|
|
|
# define RTLD_NOW 1
|
1999-08-09 18:06:01 +00:00
|
|
|
# endif
|
|
|
|
# ifndef RTLD_LAZY
|
2000-08-12 15:11:46 +00:00
|
|
|
# define RTLD_LAZY 1
|
1999-08-09 18:06:01 +00:00
|
|
|
# endif
|
|
|
|
# define HAVE_DLL
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* HP/UX DLL support */
|
|
|
|
#if defined (HAVE_SHL_LOAD) && defined(HAVE_DL_H)
|
|
|
|
# include <dl.h>
|
|
|
|
# define HAVE_DLL
|
|
|
|
#endif
|
|
|
|
|
2002-12-01 12:42:01 +00:00
|
|
|
/* Mac OS X/Darwin support */
|
|
|
|
#if defined (HAVE_NSLINKMODULE) && defined(HAVE_MACH_O_DYLD_H)
|
|
|
|
# include <mach-o/dyld.h>
|
|
|
|
# define HAVE_DLL
|
|
|
|
#endif
|
|
|
|
|
1999-08-09 18:06:01 +00:00
|
|
|
#include <sys/types.h>
|
2008-05-07 17:04:40 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <dirent.h>
|
1999-08-09 18:06:01 +00:00
|
|
|
|
2009-05-08 03:06:20 +00:00
|
|
|
#include "../include/sane/sane.h"
|
|
|
|
#include "../include/sane/sanei.h"
|
1999-08-09 18:06:01 +00:00
|
|
|
|
|
|
|
#define BACKEND_NAME dll
|
2009-05-08 03:06:20 +00:00
|
|
|
#include "../include/sane/sanei_backend.h"
|
1999-08-09 18:06:01 +00:00
|
|
|
|
|
|
|
#ifndef PATH_MAX
|
2000-08-12 15:11:46 +00:00
|
|
|
# define PATH_MAX 1024
|
1999-08-09 18:06:01 +00:00
|
|
|
#endif
|
|
|
|
|
2012-01-15 13:13:50 +00:00
|
|
|
#if defined(_WIN32) || defined(HAVE_OS2_H)
|
2004-05-16 22:08:03 +00:00
|
|
|
# define DIR_SEP ";"
|
|
|
|
#else
|
|
|
|
# define DIR_SEP ":"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2009-05-08 03:06:20 +00:00
|
|
|
#include "../include/sane/sanei_config.h"
|
1999-08-09 18:06:01 +00:00
|
|
|
#define DLL_CONFIG_FILE "dll.conf"
|
2000-03-05 13:57:25 +00:00
|
|
|
#define DLL_ALIASES_FILE "dll.aliases"
|
1999-08-09 18:06:01 +00:00
|
|
|
|
|
|
|
enum SANE_Ops
|
2002-12-04 20:30:48 +00:00
|
|
|
{
|
|
|
|
OP_INIT = 0,
|
|
|
|
OP_EXIT,
|
|
|
|
OP_GET_DEVS,
|
|
|
|
OP_OPEN,
|
|
|
|
OP_CLOSE,
|
|
|
|
OP_GET_OPTION_DESC,
|
|
|
|
OP_CTL_OPTION,
|
|
|
|
OP_GET_PARAMS,
|
|
|
|
OP_START,
|
|
|
|
OP_READ,
|
|
|
|
OP_CANCEL,
|
|
|
|
OP_SET_IO_MODE,
|
|
|
|
OP_GET_SELECT_FD,
|
|
|
|
NUM_OPS
|
|
|
|
};
|
1999-08-09 18:06:01 +00:00
|
|
|
|
2003-04-13 13:25:15 +00:00
|
|
|
typedef SANE_Status (*op_init_t) (SANE_Int *, SANE_Auth_Callback);
|
|
|
|
typedef void (*op_exit_t) (void);
|
|
|
|
typedef SANE_Status (*op_get_devs_t) (const SANE_Device ***, SANE_Bool);
|
|
|
|
typedef SANE_Status (*op_open_t) (SANE_String_Const, SANE_Handle *);
|
|
|
|
typedef void (*op_close_t) (SANE_Handle);
|
|
|
|
typedef const SANE_Option_Descriptor * (*op_get_option_desc_t) (SANE_Handle,
|
|
|
|
SANE_Int);
|
|
|
|
typedef SANE_Status (*op_ctl_option_t) (SANE_Handle, SANE_Int, SANE_Action,
|
|
|
|
void *, SANE_Int *);
|
|
|
|
typedef SANE_Status (*op_get_params_t) (SANE_Handle, SANE_Parameters *);
|
|
|
|
typedef SANE_Status (*op_start_t) (SANE_Handle);
|
|
|
|
typedef SANE_Status (*op_read_t) (SANE_Handle, SANE_Byte *, SANE_Int,
|
|
|
|
SANE_Int *);
|
|
|
|
typedef void (*op_cancel_t) (SANE_Handle);
|
|
|
|
typedef SANE_Status (*op_set_io_mode_t) (SANE_Handle, SANE_Bool);
|
|
|
|
typedef SANE_Status (*op_get_select_fd_t) (SANE_Handle, SANE_Int *);
|
|
|
|
|
1999-08-09 18:06:01 +00:00
|
|
|
struct backend
|
2002-12-04 20:30:48 +00:00
|
|
|
{
|
|
|
|
struct backend *next;
|
2003-04-13 13:25:15 +00:00
|
|
|
char *name;
|
2002-12-04 20:30:48 +00:00
|
|
|
u_int permanent:1; /* is the backend preloaded? */
|
|
|
|
u_int loaded:1; /* are the functions available? */
|
|
|
|
u_int inited:1; /* has the backend been initialized? */
|
|
|
|
void *handle; /* handle returned by dlopen() */
|
2007-01-20 23:02:53 +00:00
|
|
|
void *(*op[NUM_OPS]) (void);
|
2002-12-04 20:30:48 +00:00
|
|
|
};
|
1999-08-09 18:06:01 +00:00
|
|
|
|
2000-08-12 15:11:46 +00:00
|
|
|
#define BE_ENTRY(be,func) sane_##be##_##func
|
|
|
|
|
2003-04-13 13:25:15 +00:00
|
|
|
#define PRELOAD_DECL(name) \
|
2012-08-08 01:57:44 +00:00
|
|
|
extern SANE_Status BE_ENTRY(name,init) (SANE_Int *, SANE_Auth_Callback); \
|
|
|
|
extern void BE_ENTRY(name,exit) (void); \
|
|
|
|
extern SANE_Status BE_ENTRY(name,get_devices) (const SANE_Device ***, SANE_Bool); \
|
|
|
|
extern SANE_Status BE_ENTRY(name,open) (SANE_String_Const, SANE_Handle *); \
|
|
|
|
extern void BE_ENTRY(name,close) (SANE_Handle); \
|
|
|
|
extern const SANE_Option_Descriptor *BE_ENTRY(name,get_option_descriptor) (SANE_Handle, SANE_Int); \
|
|
|
|
extern SANE_Status BE_ENTRY(name,control_option) (SANE_Handle, SANE_Int, SANE_Action, void *, SANE_Int *); \
|
|
|
|
extern SANE_Status BE_ENTRY(name,get_parameters) (SANE_Handle, SANE_Parameters *); \
|
|
|
|
extern SANE_Status BE_ENTRY(name,start) (SANE_Handle); \
|
|
|
|
extern SANE_Status BE_ENTRY(name,read) (SANE_Handle, SANE_Byte *, SANE_Int, SANE_Int *); \
|
|
|
|
extern void BE_ENTRY(name,cancel) (SANE_Handle); \
|
|
|
|
extern SANE_Status BE_ENTRY(name,set_io_mode) (SANE_Handle, SANE_Bool); \
|
|
|
|
extern SANE_Status BE_ENTRY(name,get_select_fd) (SANE_Handle, SANE_Int *);
|
1999-08-09 18:06:01 +00:00
|
|
|
|
2000-08-12 15:11:46 +00:00
|
|
|
#define PRELOAD_DEFN(name) \
|
|
|
|
{ \
|
|
|
|
0 /* next */, #name, \
|
|
|
|
1 /* permanent */, \
|
|
|
|
1 /* loaded */, \
|
|
|
|
0 /* inited */, \
|
|
|
|
0 /* handle */, \
|
|
|
|
{ \
|
|
|
|
BE_ENTRY(name,init), \
|
|
|
|
BE_ENTRY(name,exit), \
|
|
|
|
BE_ENTRY(name,get_devices), \
|
|
|
|
BE_ENTRY(name,open), \
|
|
|
|
BE_ENTRY(name,close), \
|
|
|
|
BE_ENTRY(name,get_option_descriptor), \
|
|
|
|
BE_ENTRY(name,control_option), \
|
|
|
|
BE_ENTRY(name,get_parameters), \
|
|
|
|
BE_ENTRY(name,start), \
|
|
|
|
BE_ENTRY(name,read), \
|
|
|
|
BE_ENTRY(name,cancel), \
|
|
|
|
BE_ENTRY(name,set_io_mode), \
|
|
|
|
BE_ENTRY(name,get_select_fd) \
|
|
|
|
} \
|
1999-08-09 18:06:01 +00:00
|
|
|
}
|
|
|
|
|
2005-07-15 21:59:25 +00:00
|
|
|
#ifndef __BEOS__
|
2011-11-06 22:39:06 +00:00
|
|
|
#ifdef ENABLE_PRELOAD
|
* acinclude.m4, configure.in: Put all libraries into their
own *_LIB variables instead of $LIB so that we do not have to
link in the world to all executables. Modified SANE_CHECK_U_TYPES
to be a little more portable to platforms that use #define
for u_* types. Create SANE_CHECK_BACKENDS macro so that
PRELOADABLE_BACKENDS can also be valided. Auto-populated
PRELAODABLE_BACKENDS when detect dlopen() won't work.
Various protability cleanups.
* backend/dll.c: Make dll-preload.c a .h since its an include and
not compilable byitself.
* frontend/Makefile.in, frontend/scanimage.c, include/laaloca.h,
lib/Makefile.am, lib/alloca.c, strcasestr.c, tools/Makefile.in,
tools/sane-desc.c: Convert lib/ to automake. Create a liblib.la
for everyone to use and a libfelib.la for only frontend programs.
Make all internal programs be prefixed with sanei_ as not to conflict
with other programs libsane is linked in with that will also most
likely create similar internal utils on problem platforms.
* include/getopt.h, lib/getopt.c, lib/getopt1.c: Always compile
and link in getopt_long() but prefix it with sanei_. Its
easier to always use internal version then try to figure out what
platforms support getopt_long() and what header files to use.
* backend/Makefile.am: Convert backend makefile to automake.
Initial version that is feature parity with original but uses
specific rules instead of wildcards and only links in libraries/objs
really required. Room for more cleanup of whats linked in once
all makefiles have been converted to automake.
2009-01-31 03:12:18 +00:00
|
|
|
#include "dll-preload.h"
|
2011-11-06 22:39:06 +00:00
|
|
|
#else
|
|
|
|
static struct backend preloaded_backends[] = {
|
|
|
|
{ 0, 0, 0, 0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }}
|
|
|
|
};
|
|
|
|
#endif
|
2005-07-15 21:59:25 +00:00
|
|
|
#endif
|
1999-08-09 18:06:01 +00:00
|
|
|
|
|
|
|
struct meta_scanner
|
2002-12-04 20:30:48 +00:00
|
|
|
{
|
|
|
|
struct backend *be;
|
|
|
|
SANE_Handle handle;
|
|
|
|
};
|
1999-08-09 18:06:01 +00:00
|
|
|
|
2000-03-05 13:57:25 +00:00
|
|
|
struct alias
|
2002-12-04 20:30:48 +00:00
|
|
|
{
|
|
|
|
struct alias *next;
|
|
|
|
char *oldname;
|
|
|
|
char *newname;
|
|
|
|
};
|
2000-03-05 13:57:25 +00:00
|
|
|
|
2001-02-12 19:31:01 +00:00
|
|
|
/*
|
|
|
|
* List of available devices, allocated by sane_get_devices, released
|
|
|
|
* by sane_exit()
|
|
|
|
*/
|
2003-04-13 13:25:15 +00:00
|
|
|
static SANE_Device **devlist = NULL;
|
2001-02-12 19:31:01 +00:00
|
|
|
static int devlist_size = 0, devlist_len = 0;
|
|
|
|
|
2000-03-05 13:57:25 +00:00
|
|
|
static struct alias *first_alias;
|
1999-08-09 18:06:01 +00:00
|
|
|
static SANE_Auth_Callback auth_callback;
|
|
|
|
static struct backend *first_backend;
|
2005-07-15 21:59:25 +00:00
|
|
|
|
|
|
|
#ifndef __BEOS__
|
2002-12-04 20:30:48 +00:00
|
|
|
static const char *op_name[] = {
|
1999-08-09 18:06:01 +00:00
|
|
|
"init", "exit", "get_devices", "open", "close", "get_option_descriptor",
|
|
|
|
"control_option", "get_parameters", "start", "read", "cancel",
|
|
|
|
"set_io_mode", "get_select_fd"
|
|
|
|
};
|
2005-07-15 21:59:25 +00:00
|
|
|
#else
|
|
|
|
static const char *op_name[] = {
|
|
|
|
"sane_init", "sane_exit", "sane_get_devices", "sane_open", "sane_close", "sane_get_option_descriptor",
|
|
|
|
"sane_control_option", "sane_get_parameters", "sane_start", "sane_read", "sane_cancel",
|
|
|
|
"sane_set_io_mode", "sane_get_select_fd"
|
|
|
|
};
|
|
|
|
#endif /* __BEOS__ */
|
1999-08-09 18:06:01 +00:00
|
|
|
|
|
|
|
static void *
|
|
|
|
op_unsupported (void)
|
|
|
|
{
|
2002-12-04 20:30:48 +00:00
|
|
|
DBG (1, "op_unsupported: call to unsupported backend operation\n");
|
1999-08-09 18:06:01 +00:00
|
|
|
return (void *) (long) SANE_STATUS_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static SANE_Status
|
|
|
|
add_backend (const char *name, struct backend **bep)
|
|
|
|
{
|
|
|
|
struct backend *be, *prev;
|
|
|
|
|
2002-12-04 20:30:48 +00:00
|
|
|
DBG (3, "add_backend: adding backend `%s'\n", name);
|
1999-08-09 18:06:01 +00:00
|
|
|
|
2002-12-04 20:30:48 +00:00
|
|
|
if (strcmp (name, "dll") == 0)
|
2000-10-23 15:03:08 +00:00
|
|
|
{
|
2002-12-04 20:30:48 +00:00
|
|
|
DBG (0, "add_backend: remove the dll-backend from your dll.conf!\n");
|
2000-10-23 15:03:08 +00:00
|
|
|
return SANE_STATUS_GOOD;
|
|
|
|
}
|
|
|
|
|
1999-08-09 18:06:01 +00:00
|
|
|
for (prev = 0, be = first_backend; be; prev = be, be = be->next)
|
|
|
|
if (strcmp (be->name, name) == 0)
|
|
|
|
{
|
2002-12-04 20:30:48 +00:00
|
|
|
DBG (1, "add_backend: `%s' is already there\n", name);
|
|
|
|
/* move to front so we preserve order that we'd get with
|
|
|
|
dynamic loading: */
|
|
|
|
if (prev)
|
|
|
|
{
|
|
|
|
prev->next = be->next;
|
|
|
|
be->next = first_backend;
|
|
|
|
first_backend = be;
|
|
|
|
}
|
|
|
|
if (bep)
|
|
|
|
*bep = be;
|
|
|
|
return SANE_STATUS_GOOD;
|
1999-08-09 18:06:01 +00:00
|
|
|
}
|
|
|
|
|
2000-03-05 13:57:25 +00:00
|
|
|
be = calloc (1, sizeof (*be));
|
1999-08-09 18:06:01 +00:00
|
|
|
if (!be)
|
|
|
|
return SANE_STATUS_NO_MEM;
|
|
|
|
|
|
|
|
be->name = strdup (name);
|
|
|
|
if (!be->name)
|
|
|
|
return SANE_STATUS_NO_MEM;
|
|
|
|
be->next = first_backend;
|
|
|
|
first_backend = be;
|
|
|
|
if (bep)
|
|
|
|
*bep = be;
|
|
|
|
return SANE_STATUS_GOOD;
|
|
|
|
}
|
|
|
|
|
2002-12-01 12:42:01 +00:00
|
|
|
#if defined(HAVE_NSLINKMODULE)
|
|
|
|
static const char *dyld_get_error_str ();
|
|
|
|
|
2002-12-04 20:30:48 +00:00
|
|
|
static const char *
|
|
|
|
dyld_get_error_str ()
|
2002-12-01 12:42:01 +00:00
|
|
|
{
|
|
|
|
NSLinkEditErrors c;
|
|
|
|
int errorNumber;
|
|
|
|
const char *fileName;
|
|
|
|
const char *errorString;
|
|
|
|
|
|
|
|
NSLinkEditError (&c, &errorNumber, &fileName, &errorString);
|
|
|
|
return errorString;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-07-15 21:59:25 +00:00
|
|
|
#ifdef __BEOS__
|
|
|
|
#include <FindDirectory.h>
|
|
|
|
|
|
|
|
static SANE_Status
|
|
|
|
load (struct backend *be)
|
|
|
|
{
|
2006-01-22 09:04:41 +00:00
|
|
|
/* use BeOS kernel function to load scanner addons from ~/config/add-ons/SANE */
|
2005-07-15 21:59:25 +00:00
|
|
|
char path[PATH_MAX];
|
|
|
|
image_id id = -1;
|
|
|
|
int i, w;
|
|
|
|
directory_which which[3] = { B_USER_ADDONS_DIRECTORY, B_COMMON_ADDONS_DIRECTORY, B_BEOS_ADDONS_DIRECTORY };
|
|
|
|
|
2006-01-22 09:04:41 +00:00
|
|
|
/* look for config files in SANE/conf */
|
2005-07-15 21:59:25 +00:00
|
|
|
for (w = 0; (w < 3) && (id < 0) && (find_directory(which[w],0,true,path,PATH_MAX) == 0); w++)
|
|
|
|
{
|
|
|
|
strcat(path,"/SANE/");
|
|
|
|
strcat(path,be->name);
|
|
|
|
DBG(1, "loading backend %s\n", be->name);
|
|
|
|
|
|
|
|
/* initialize all ops to "unsupported" so we can "use" the backend
|
|
|
|
even if the stuff later in this function fails */
|
|
|
|
be->loaded = 1;
|
|
|
|
be->handle = 0;
|
|
|
|
for (i = 0; i < NUM_OPS; ++i) be->op[i] = op_unsupported;
|
|
|
|
DBG(2, "dlopen()ing `%s'\n", path);
|
|
|
|
id=load_add_on(path);
|
|
|
|
if (id < 0)
|
|
|
|
{
|
|
|
|
continue; /* try next path */
|
|
|
|
}
|
|
|
|
be->handle=(void *)id;
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_OPS; ++i)
|
|
|
|
{
|
|
|
|
void *(*op) ();
|
|
|
|
op = NULL;
|
|
|
|
/* Look for the symbol */
|
|
|
|
if ((get_image_symbol(id, op_name[i],B_SYMBOL_TYPE_TEXT,(void **)&op) < 0) || !op)
|
|
|
|
DBG(2, "unable to find %s\n", op_name[i]);
|
|
|
|
else be->op[i]=op;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (id < 0)
|
|
|
|
{
|
|
|
|
DBG(2, "load: couldn't find %s\n",path);
|
|
|
|
return SANE_STATUS_INVAL;
|
|
|
|
}
|
|
|
|
return SANE_STATUS_GOOD;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
1999-08-09 18:06:01 +00:00
|
|
|
static SANE_Status
|
|
|
|
load (struct backend *be)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_DLL
|
|
|
|
int mode = 0;
|
2002-04-21 14:02:58 +00:00
|
|
|
char *funcname, *src, *orig_src = 0, *dir, *path = 0;
|
1999-08-09 18:06:01 +00:00
|
|
|
char libname[PATH_MAX];
|
|
|
|
int i;
|
2002-04-21 14:02:58 +00:00
|
|
|
int src_len;
|
1999-08-09 18:06:01 +00:00
|
|
|
FILE *fp = 0;
|
|
|
|
|
|
|
|
#if defined(HAVE_DLOPEN)
|
|
|
|
# define PREFIX "libsane-"
|
2001-10-02 20:35:08 +00:00
|
|
|
# ifdef __hpux
|
|
|
|
# define POSTFIX ".sl.%u"
|
2005-12-20 17:15:39 +00:00
|
|
|
# define ALT_POSTFIX ".so.%u"
|
2007-11-10 11:35:34 +00:00
|
|
|
# elif defined (HAVE_WINDOWS_H)
|
2003-09-24 03:41:48 +00:00
|
|
|
# undef PREFIX
|
|
|
|
# define PREFIX "cygsane-"
|
|
|
|
# define POSTFIX "-%u.dll"
|
2007-11-10 11:35:34 +00:00
|
|
|
# elif defined (HAVE_OS2_H)
|
2004-04-23 15:21:14 +00:00
|
|
|
# undef PREFIX
|
|
|
|
# define PREFIX ""
|
|
|
|
# define POSTFIX ".dll"
|
2007-11-10 11:35:34 +00:00
|
|
|
# elif defined (__APPLE__) && defined (__MACH__)
|
|
|
|
# define POSTFIX ".%u.so"
|
2001-10-02 20:35:08 +00:00
|
|
|
# else
|
|
|
|
# define POSTFIX ".so.%u"
|
|
|
|
# endif
|
1999-08-09 18:06:01 +00:00
|
|
|
mode = getenv ("LD_BIND_NOW") ? RTLD_NOW : RTLD_LAZY;
|
|
|
|
#elif defined(HAVE_SHL_LOAD)
|
|
|
|
# define PREFIX "libsane-"
|
|
|
|
# define POSTFIX ".sl.%u"
|
|
|
|
mode = BIND_DEFERRED;
|
2002-12-01 12:42:01 +00:00
|
|
|
#elif defined(HAVE_NSLINKMODULE)
|
|
|
|
# define PREFIX "libsane-"
|
|
|
|
# define POSTFIX ".%u.so"
|
2002-12-04 20:30:48 +00:00
|
|
|
mode = NSLINKMODULE_OPTION_RETURN_ON_ERROR + NSLINKMODULE_OPTION_PRIVATE;
|
1999-08-09 18:06:01 +00:00
|
|
|
#else
|
|
|
|
# error "Tried to compile unsupported DLL."
|
|
|
|
#endif /* HAVE_DLOPEN */
|
|
|
|
|
|
|
|
/* initialize all ops to "unsupported" so we can "use" the backend
|
|
|
|
even if the stuff later in this function fails */
|
|
|
|
be->loaded = 1;
|
|
|
|
be->handle = 0;
|
|
|
|
for (i = 0; i < NUM_OPS; ++i)
|
|
|
|
be->op[i] = op_unsupported;
|
|
|
|
|
2002-04-21 14:02:58 +00:00
|
|
|
path = getenv ("LD_LIBRARY_PATH");
|
|
|
|
if (!path)
|
2002-12-04 20:30:48 +00:00
|
|
|
path = getenv ("SHLIB_PATH"); /* for HP-UX */
|
2002-04-21 14:02:58 +00:00
|
|
|
if (!path)
|
2002-12-04 20:30:48 +00:00
|
|
|
path = getenv ("LIBPATH"); /* for AIX */
|
2002-04-21 14:02:58 +00:00
|
|
|
|
|
|
|
if (path)
|
|
|
|
{
|
2002-12-04 20:30:48 +00:00
|
|
|
src_len = strlen (path) + strlen (STRINGIFY (LIBDIR)) + 1 + 1;
|
2002-04-21 14:02:58 +00:00
|
|
|
src = malloc (src_len);
|
|
|
|
if (!src)
|
|
|
|
{
|
2002-12-04 20:30:48 +00:00
|
|
|
DBG (1, "load: malloc failed: %s\n", strerror (errno));
|
2002-04-21 14:02:58 +00:00
|
|
|
return SANE_STATUS_NO_MEM;
|
|
|
|
}
|
|
|
|
orig_src = src;
|
2002-12-04 20:30:48 +00:00
|
|
|
snprintf (src, src_len, "%s:%s", path, STRINGIFY (LIBDIR));
|
2002-04-21 14:02:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-12-04 20:30:48 +00:00
|
|
|
src = STRINGIFY (LIBDIR);
|
2002-04-21 14:02:58 +00:00
|
|
|
src = strdup (src);
|
|
|
|
if (!src)
|
|
|
|
{
|
2002-12-04 20:30:48 +00:00
|
|
|
DBG (1, "load: strdup failed: %s\n", strerror (errno));
|
2002-04-21 14:02:58 +00:00
|
|
|
return SANE_STATUS_NO_MEM;
|
|
|
|
}
|
|
|
|
}
|
2002-12-04 20:30:48 +00:00
|
|
|
DBG (3, "load: searching backend `%s' in `%s'\n", be->name, src);
|
2002-04-21 14:02:58 +00:00
|
|
|
|
2004-05-16 22:08:03 +00:00
|
|
|
dir = strsep (&src, DIR_SEP);
|
2002-04-21 14:02:58 +00:00
|
|
|
|
1999-08-09 18:06:01 +00:00
|
|
|
while (dir)
|
|
|
|
{
|
2005-06-30 08:18:29 +00:00
|
|
|
#ifdef HAVE_OS2_H /* only max 7.3 names work with dlopen() for DLLs on OS/2 */
|
|
|
|
snprintf (libname, sizeof (libname), "%s/" PREFIX "%.2s%.5s" POSTFIX,
|
|
|
|
dir, be->name, strlen(be->name)>7 ? (be->name)+strlen(be->name)-5 :
|
2004-05-24 19:16:41 +00:00
|
|
|
(be->name)+2, V_MAJOR);
|
|
|
|
#else
|
2002-12-04 20:30:48 +00:00
|
|
|
snprintf (libname, sizeof (libname), "%s/" PREFIX "%s" POSTFIX,
|
|
|
|
dir, be->name, V_MAJOR);
|
2004-05-24 19:16:41 +00:00
|
|
|
#endif
|
2002-12-04 20:30:48 +00:00
|
|
|
DBG (4, "load: trying to load `%s'\n", libname);
|
1999-08-09 18:06:01 +00:00
|
|
|
fp = fopen (libname, "r");
|
|
|
|
if (fp)
|
2002-12-04 20:30:48 +00:00
|
|
|
break;
|
|
|
|
DBG (4, "load: couldn't open `%s' (%s)\n", libname, strerror (errno));
|
1999-08-09 18:06:01 +00:00
|
|
|
|
2005-12-20 17:15:39 +00:00
|
|
|
#ifdef ALT_POSTFIX
|
|
|
|
/* Some platforms have two ways of storing their libraries, try both
|
|
|
|
postfixes */
|
|
|
|
snprintf (libname, sizeof (libname), "%s/" PREFIX "%s" ALT_POSTFIX,
|
|
|
|
dir, be->name, V_MAJOR);
|
|
|
|
DBG (4, "load: trying to load `%s'\n", libname);
|
|
|
|
fp = fopen (libname, "r");
|
|
|
|
if (fp)
|
|
|
|
break;
|
|
|
|
DBG (4, "load: couldn't open `%s' (%s)\n", libname, strerror (errno));
|
|
|
|
#endif
|
|
|
|
|
2004-05-16 22:08:03 +00:00
|
|
|
dir = strsep (&src, DIR_SEP);
|
1999-08-09 18:06:01 +00:00
|
|
|
}
|
2002-04-21 14:02:58 +00:00
|
|
|
if (orig_src)
|
|
|
|
free (orig_src);
|
1999-08-09 18:06:01 +00:00
|
|
|
if (!fp)
|
|
|
|
{
|
2002-12-04 20:30:48 +00:00
|
|
|
DBG (1, "load: couldn't find backend `%s' (%s)\n",
|
|
|
|
be->name, strerror (errno));
|
1999-08-09 18:06:01 +00:00
|
|
|
return SANE_STATUS_INVAL;
|
|
|
|
}
|
2001-04-22 20:01:30 +00:00
|
|
|
fclose (fp);
|
2002-12-04 20:30:48 +00:00
|
|
|
DBG (3, "load: dlopen()ing `%s'\n", libname);
|
1999-08-09 18:06:01 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_DLOPEN
|
|
|
|
be->handle = dlopen (libname, mode);
|
|
|
|
#elif defined(HAVE_SHL_LOAD)
|
2002-12-04 20:30:48 +00:00
|
|
|
be->handle = (shl_t) shl_load (libname, mode, 0L);
|
2002-12-01 12:42:01 +00:00
|
|
|
#elif defined(HAVE_NSLINKMODULE)
|
|
|
|
{
|
|
|
|
NSObjectFileImage objectfile_img = NULL;
|
2002-12-04 20:30:48 +00:00
|
|
|
if (NSCreateObjectFileImageFromFile (libname, &objectfile_img)
|
2002-12-01 12:42:01 +00:00
|
|
|
== NSObjectFileImageSuccess)
|
|
|
|
{
|
|
|
|
be->handle = NSLinkModule (objectfile_img, libname, mode);
|
|
|
|
NSDestroyObjectFileImage (objectfile_img);
|
2002-12-04 20:30:48 +00:00
|
|
|
}
|
2002-12-01 12:42:01 +00:00
|
|
|
}
|
1999-08-09 18:06:01 +00:00
|
|
|
#else
|
|
|
|
# error "Tried to compile unsupported DLL."
|
|
|
|
#endif /* HAVE_DLOPEN */
|
|
|
|
if (!be->handle)
|
|
|
|
{
|
2000-03-05 13:57:25 +00:00
|
|
|
#ifdef HAVE_DLOPEN
|
2002-12-04 20:30:48 +00:00
|
|
|
DBG (1, "load: dlopen() failed (%s)\n", dlerror ());
|
2002-12-01 12:42:01 +00:00
|
|
|
#elif defined(HAVE_NSLINKMODULE)
|
2002-12-04 20:30:48 +00:00
|
|
|
DBG (1, "load: dyld error (%s)\n", dyld_get_error_str ());
|
2000-03-05 13:57:25 +00:00
|
|
|
#else
|
2002-12-04 20:30:48 +00:00
|
|
|
DBG (1, "load: dlopen() failed (%s)\n", strerror (errno));
|
2000-03-05 13:57:25 +00:00
|
|
|
#endif
|
1999-08-09 18:06:01 +00:00
|
|
|
return SANE_STATUS_INVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* all is dandy---lookup and fill in backend ops: */
|
|
|
|
funcname = alloca (strlen (be->name) + 64);
|
|
|
|
for (i = 0; i < NUM_OPS; ++i)
|
|
|
|
{
|
2001-11-11 19:55:49 +00:00
|
|
|
void *(*op) (void);
|
1999-08-09 18:06:01 +00:00
|
|
|
|
|
|
|
sprintf (funcname, "_sane_%s_%s", be->name, op_name[i]);
|
|
|
|
|
|
|
|
/* First try looking up the symbol without a leading underscore. */
|
|
|
|
#ifdef HAVE_DLOPEN
|
2001-11-11 19:55:49 +00:00
|
|
|
op = (void *(*)(void)) dlsym (be->handle, funcname + 1);
|
1999-08-09 18:06:01 +00:00
|
|
|
#elif defined(HAVE_SHL_LOAD)
|
2002-12-04 20:30:48 +00:00
|
|
|
shl_findsym ((shl_t *) & (be->handle), funcname + 1, TYPE_UNDEFINED,
|
|
|
|
&op);
|
2002-12-01 12:42:01 +00:00
|
|
|
#elif defined(HAVE_NSLINKMODULE)
|
|
|
|
{
|
2002-12-04 20:30:48 +00:00
|
|
|
NSSymbol *nssym = NSLookupSymbolInModule (be->handle, funcname);
|
|
|
|
if (!nssym)
|
2002-12-01 12:42:01 +00:00
|
|
|
{
|
2002-12-04 20:30:48 +00:00
|
|
|
DBG (15, "dyld error: %s\n", dyld_get_error_str ());
|
|
|
|
}
|
|
|
|
else
|
2002-12-01 12:42:01 +00:00
|
|
|
{
|
|
|
|
op = (void *(*)(void)) NSAddressOfSymbol (nssym);
|
2002-12-04 20:30:48 +00:00
|
|
|
}
|
|
|
|
}
|
1999-08-09 18:06:01 +00:00
|
|
|
#else
|
|
|
|
# error "Tried to compile unsupported DLL."
|
|
|
|
#endif /* HAVE_DLOPEN */
|
|
|
|
if (op)
|
2002-12-04 20:30:48 +00:00
|
|
|
be->op[i] = op;
|
1999-08-09 18:06:01 +00:00
|
|
|
else
|
2002-12-04 20:30:48 +00:00
|
|
|
{
|
|
|
|
/* Try again, with an underscore prepended. */
|
1999-08-09 18:06:01 +00:00
|
|
|
#ifdef HAVE_DLOPEN
|
2002-12-04 20:30:48 +00:00
|
|
|
op = (void *(*)(void)) dlsym (be->handle, funcname);
|
1999-08-09 18:06:01 +00:00
|
|
|
#elif defined(HAVE_SHL_LOAD)
|
2002-12-04 20:30:48 +00:00
|
|
|
shl_findsym (be->handle, funcname, TYPE_UNDEFINED, &op);
|
2002-12-01 12:42:01 +00:00
|
|
|
#elif defined(HAVE_NSLINKMODULE)
|
|
|
|
{
|
2002-12-04 20:30:48 +00:00
|
|
|
NSSymbol *nssym = NSLookupSymbolInModule (be->handle, funcname);
|
|
|
|
if (!nssym)
|
|
|
|
{
|
|
|
|
DBG (15, "dyld error: %s\n", dyld_get_error_str ());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
op = (void *(*)(void)) NSAddressOfSymbol (nssym);
|
|
|
|
}
|
|
|
|
}
|
1999-08-09 18:06:01 +00:00
|
|
|
#else
|
|
|
|
# error "Tried to compile unsupported DLL."
|
|
|
|
#endif /* HAVE_DLOPEN */
|
2002-12-04 20:30:48 +00:00
|
|
|
if (op)
|
|
|
|
be->op[i] = op;
|
|
|
|
}
|
1999-08-09 18:06:01 +00:00
|
|
|
if (NULL == op)
|
2002-12-04 20:30:48 +00:00
|
|
|
DBG (1, "load: unable to find %s\n", funcname);
|
1999-08-09 18:06:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return SANE_STATUS_GOOD;
|
|
|
|
|
|
|
|
# undef PREFIX
|
|
|
|
# undef POSTFIX
|
|
|
|
#else /* HAVE_DLL */
|
2002-12-04 20:30:48 +00:00
|
|
|
DBG (1,
|
|
|
|
"load: ignoring attempt to load `%s'; compiled without dl support\n",
|
|
|
|
be->name);
|
1999-08-09 18:06:01 +00:00
|
|
|
return SANE_STATUS_UNSUPPORTED;
|
|
|
|
#endif /* HAVE_DLL */
|
|
|
|
}
|
2005-07-15 21:59:25 +00:00
|
|
|
#endif /* __BEOS__ */
|
1999-08-09 18:06:01 +00:00
|
|
|
|
|
|
|
static SANE_Status
|
|
|
|
init (struct backend *be)
|
|
|
|
{
|
|
|
|
SANE_Status status;
|
|
|
|
SANE_Int version;
|
|
|
|
|
|
|
|
if (!be->loaded)
|
|
|
|
{
|
|
|
|
status = load (be);
|
|
|
|
if (status != SANE_STATUS_GOOD)
|
2002-12-04 20:30:48 +00:00
|
|
|
return status;
|
1999-08-09 18:06:01 +00:00
|
|
|
}
|
|
|
|
|
2002-12-04 20:30:48 +00:00
|
|
|
DBG (3, "init: initializing backend `%s'\n", be->name);
|
1999-08-09 18:06:01 +00:00
|
|
|
|
2003-04-13 13:25:15 +00:00
|
|
|
status = (*(op_init_t)be->op[OP_INIT]) (&version, auth_callback);
|
1999-08-09 18:06:01 +00:00
|
|
|
if (status != SANE_STATUS_GOOD)
|
|
|
|
return status;
|
|
|
|
|
2008-11-26 21:21:31 +00:00
|
|
|
if (SANE_VERSION_MAJOR (version) != SANE_CURRENT_MAJOR)
|
2001-04-13 17:04:51 +00:00
|
|
|
{
|
2002-12-04 20:30:48 +00:00
|
|
|
DBG (1,
|
|
|
|
"init: backend `%s' has a wrong major version (%d instead of %d)\n",
|
2008-11-26 21:21:31 +00:00
|
|
|
be->name, SANE_VERSION_MAJOR (version), SANE_CURRENT_MAJOR);
|
2001-04-13 17:04:51 +00:00
|
|
|
return SANE_STATUS_INVAL;
|
|
|
|
}
|
2002-12-04 20:30:48 +00:00
|
|
|
DBG (4, "init: backend `%s' is version %d.%d.%d\n", be->name,
|
|
|
|
SANE_VERSION_MAJOR (version), SANE_VERSION_MINOR (version),
|
|
|
|
SANE_VERSION_BUILD (version));
|
1999-08-09 18:06:01 +00:00
|
|
|
|
|
|
|
be->inited = 1;
|
|
|
|
|
|
|
|
return SANE_STATUS_GOOD;
|
|
|
|
}
|
|
|
|
|
2000-03-05 13:57:25 +00:00
|
|
|
|
|
|
|
static void
|
2002-11-19 05:06:08 +00:00
|
|
|
add_alias (const char *line_param)
|
2000-03-05 13:57:25 +00:00
|
|
|
{
|
2005-07-15 21:59:25 +00:00
|
|
|
#ifndef __BEOS__
|
2000-03-05 13:57:25 +00:00
|
|
|
const char *command;
|
2002-12-04 20:30:48 +00:00
|
|
|
enum
|
|
|
|
{ CMD_ALIAS, CMD_HIDE }
|
|
|
|
cmd;
|
2002-11-19 05:06:08 +00:00
|
|
|
const char *oldname, *oldend, *newname;
|
2000-03-05 13:57:25 +00:00
|
|
|
size_t oldlen, newlen;
|
|
|
|
struct alias *alias;
|
2002-11-19 05:06:08 +00:00
|
|
|
char *line;
|
2000-03-05 13:57:25 +00:00
|
|
|
|
2002-12-04 20:30:48 +00:00
|
|
|
command = sanei_config_skip_whitespace (line_param);
|
|
|
|
if (!*command)
|
2000-03-05 13:57:25 +00:00
|
|
|
return;
|
2002-12-04 20:25:13 +00:00
|
|
|
|
|
|
|
line = strchr (command, '#');
|
|
|
|
if (line)
|
|
|
|
*line = '\0';
|
|
|
|
|
2002-12-04 20:30:48 +00:00
|
|
|
line = strpbrk (command, " \t");
|
|
|
|
if (!line)
|
2000-03-05 13:57:25 +00:00
|
|
|
return;
|
|
|
|
*line++ = '\0';
|
|
|
|
|
2002-12-04 20:30:48 +00:00
|
|
|
if (strcmp (command, "alias") == 0)
|
2000-03-05 13:57:25 +00:00
|
|
|
cmd = CMD_ALIAS;
|
2002-12-04 20:30:48 +00:00
|
|
|
else if (strcmp (command, "hide") == 0)
|
2000-03-05 13:57:25 +00:00
|
|
|
cmd = CMD_HIDE;
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
|
|
|
newlen = 0;
|
|
|
|
newname = NULL;
|
2002-12-04 20:30:48 +00:00
|
|
|
if (cmd == CMD_ALIAS)
|
2000-03-05 13:57:25 +00:00
|
|
|
{
|
2002-12-04 20:30:48 +00:00
|
|
|
char *newend;
|
|
|
|
|
|
|
|
newname = sanei_config_skip_whitespace (line);
|
|
|
|
if (!*newname)
|
|
|
|
return;
|
|
|
|
if (*newname == '\"')
|
|
|
|
{
|
|
|
|
++newname;
|
|
|
|
newend = strchr (newname, '\"');
|
|
|
|
}
|
2000-03-05 13:57:25 +00:00
|
|
|
else
|
2002-12-04 20:30:48 +00:00
|
|
|
newend = strpbrk (newname, " \t");
|
|
|
|
if (!newend)
|
|
|
|
return;
|
2000-03-05 13:57:25 +00:00
|
|
|
|
|
|
|
newlen = newend - newname;
|
2002-12-04 20:30:48 +00:00
|
|
|
line = (char *) (newend + 1);
|
2000-03-05 13:57:25 +00:00
|
|
|
}
|
|
|
|
|
2002-12-04 20:30:48 +00:00
|
|
|
oldname = sanei_config_skip_whitespace (line);
|
|
|
|
if (!*oldname)
|
2000-03-05 13:57:25 +00:00
|
|
|
return;
|
2002-12-04 20:30:48 +00:00
|
|
|
oldend = oldname + strcspn (oldname, " \t");
|
2000-03-05 13:57:25 +00:00
|
|
|
|
|
|
|
oldlen = oldend - oldname;
|
|
|
|
|
2002-12-04 20:30:48 +00:00
|
|
|
alias = malloc (sizeof (struct alias));
|
|
|
|
if (alias)
|
2000-03-05 13:57:25 +00:00
|
|
|
{
|
2002-12-04 20:30:48 +00:00
|
|
|
alias->oldname = malloc (oldlen + newlen + 2);
|
|
|
|
if (alias->oldname)
|
|
|
|
{
|
|
|
|
strncpy (alias->oldname, oldname, oldlen);
|
|
|
|
alias->oldname[oldlen] = '\0';
|
|
|
|
if (cmd == CMD_ALIAS)
|
|
|
|
{
|
|
|
|
alias->newname = alias->oldname + oldlen + 1;
|
|
|
|
strncpy (alias->newname, newname, newlen);
|
|
|
|
alias->newname[newlen] = '\0';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
alias->newname = NULL;
|
|
|
|
|
|
|
|
alias->next = first_alias;
|
|
|
|
first_alias = alias;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
free (alias);
|
2000-03-05 13:57:25 +00:00
|
|
|
}
|
|
|
|
return;
|
2005-07-15 21:59:25 +00:00
|
|
|
#endif
|
2000-03-05 13:57:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-07 17:04:40 +00:00
|
|
|
static void
|
|
|
|
read_config (const char *conffile)
|
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
char config_line[PATH_MAX];
|
|
|
|
char *backend_name;
|
|
|
|
|
|
|
|
fp = sanei_config_open (conffile);
|
|
|
|
if (!fp)
|
|
|
|
{
|
|
|
|
DBG (1, "sane_init/read_config: Couldn't open config file (%s): %s\n",
|
|
|
|
conffile, strerror (errno));
|
|
|
|
return; /* don't insist on config file */
|
|
|
|
}
|
|
|
|
|
|
|
|
DBG (5, "sane_init/read_config: reading %s\n", conffile);
|
|
|
|
while (sanei_config_read (config_line, sizeof (config_line), fp))
|
|
|
|
{
|
|
|
|
char *comment;
|
|
|
|
SANE_String_Const cp;
|
|
|
|
|
|
|
|
cp = sanei_config_get_string (config_line, &backend_name);
|
|
|
|
/* ignore empty lines */
|
|
|
|
if (!backend_name || cp == config_line)
|
|
|
|
{
|
|
|
|
if (backend_name)
|
|
|
|
free (backend_name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* ignore line comments */
|
|
|
|
if (backend_name[0] == '#')
|
|
|
|
{
|
|
|
|
free (backend_name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* ignore comments after backend names */
|
|
|
|
comment = strchr (backend_name, '#');
|
|
|
|
if (comment)
|
|
|
|
*comment = '\0';
|
|
|
|
add_backend (backend_name, 0);
|
|
|
|
free (backend_name);
|
|
|
|
}
|
|
|
|
fclose (fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
read_dlld (void)
|
|
|
|
{
|
|
|
|
DIR *dlld;
|
|
|
|
struct dirent *dllconf;
|
|
|
|
struct stat st;
|
2010-09-18 08:35:35 +00:00
|
|
|
char conffile[PATH_MAX], dlldir[PATH_MAX];
|
2008-05-07 17:04:40 +00:00
|
|
|
size_t len, plen;
|
2010-09-18 08:35:35 +00:00
|
|
|
const char *dir_list;
|
|
|
|
char *copy, *next, *dir;
|
2008-05-07 17:04:40 +00:00
|
|
|
|
2010-09-18 08:35:35 +00:00
|
|
|
dir_list = sanei_config_get_paths ();
|
|
|
|
if (!dir_list)
|
|
|
|
{
|
|
|
|
DBG(2, "sane_init/read_dlld: Unable to detect configuration directories\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
copy = strdup (dir_list);
|
|
|
|
|
|
|
|
for (next = copy; (dir = strsep (&next, DIR_SEP)) != NULL;)
|
|
|
|
{
|
|
|
|
snprintf (dlldir, sizeof (dlldir), "%s%s", dir, "/dll.d");
|
2008-05-07 17:04:40 +00:00
|
|
|
|
2010-09-18 08:35:35 +00:00
|
|
|
DBG(4, "sane_init/read_dlld: attempting to open directory `%s'\n", dlldir);
|
|
|
|
|
|
|
|
dlld = opendir (dlldir);
|
|
|
|
if (dlld)
|
|
|
|
{
|
|
|
|
/* length of path to parent dir of dll.d/ */
|
|
|
|
plen = strlen (dir) + 1;
|
|
|
|
|
|
|
|
DBG(3, "sane_init/read_dlld: using config directory `%s'\n", dlldir);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free (copy);
|
2008-05-07 17:04:40 +00:00
|
|
|
|
|
|
|
if (dlld == NULL)
|
|
|
|
{
|
|
|
|
DBG (1, "sane_init/read_dlld: opendir failed: %s\n",
|
|
|
|
strerror (errno));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((dllconf = readdir (dlld)) != NULL)
|
|
|
|
{
|
|
|
|
/* dotfile (or directory) */
|
|
|
|
if (dllconf->d_name[0] == '.')
|
|
|
|
continue;
|
|
|
|
|
|
|
|
len = strlen (dllconf->d_name);
|
|
|
|
|
|
|
|
/* backup files */
|
|
|
|
if ((dllconf->d_name[len-1] == '~')
|
|
|
|
|| (dllconf->d_name[len-1] == '#'))
|
|
|
|
continue;
|
|
|
|
|
2010-09-18 08:35:35 +00:00
|
|
|
snprintf (conffile, PATH_MAX, "%s/%s", dlldir, dllconf->d_name);
|
2008-05-07 17:04:40 +00:00
|
|
|
|
|
|
|
DBG (5, "sane_init/read_dlld: considering %s\n", conffile);
|
|
|
|
|
2010-07-09 16:56:51 +00:00
|
|
|
if (stat (conffile, &st) != 0)
|
2008-05-07 17:04:40 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!S_ISREG (st.st_mode))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* expects a path relative to PATH_SANE_CONFIG_DIR */
|
|
|
|
read_config (conffile+plen);
|
|
|
|
}
|
|
|
|
|
|
|
|
closedir (dlld);
|
|
|
|
|
|
|
|
DBG (5, "sane_init/read_dlld: done.\n");
|
|
|
|
}
|
|
|
|
|
1999-08-09 18:06:01 +00:00
|
|
|
SANE_Status
|
|
|
|
sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize)
|
|
|
|
{
|
2005-07-15 21:59:25 +00:00
|
|
|
#ifndef __BEOS__
|
2002-12-04 20:25:13 +00:00
|
|
|
char config_line[PATH_MAX];
|
1999-08-09 18:06:01 +00:00
|
|
|
size_t len;
|
|
|
|
FILE *fp;
|
|
|
|
int i;
|
2005-07-15 21:59:25 +00:00
|
|
|
#else
|
|
|
|
DIR *dir;
|
|
|
|
struct dirent *dirent;
|
|
|
|
char path[1024];
|
|
|
|
directory_which which[3] = { B_USER_ADDONS_DIRECTORY, B_COMMON_ADDONS_DIRECTORY, B_BEOS_ADDONS_DIRECTORY };
|
|
|
|
int i;
|
|
|
|
#endif
|
1999-08-09 18:06:01 +00:00
|
|
|
|
2002-12-04 20:30:48 +00:00
|
|
|
DBG_INIT ();
|
1999-08-09 18:06:01 +00:00
|
|
|
|
|
|
|
auth_callback = authorize;
|
|
|
|
|
2002-12-04 20:30:48 +00:00
|
|
|
DBG (1, "sane_init: SANE dll backend version %s from %s\n", DLL_VERSION,
|
|
|
|
PACKAGE_STRING);
|
2001-04-13 17:04:51 +00:00
|
|
|
|
2005-07-15 21:59:25 +00:00
|
|
|
#ifndef __BEOS__
|
1999-08-09 18:06:01 +00:00
|
|
|
/* chain preloaded backends together: */
|
2002-12-04 20:30:48 +00:00
|
|
|
for (i = 0; i < NELEMS (preloaded_backends); ++i)
|
1999-08-09 18:06:01 +00:00
|
|
|
{
|
|
|
|
if (!preloaded_backends[i].name)
|
2002-12-04 20:30:48 +00:00
|
|
|
continue;
|
2003-04-04 10:26:20 +00:00
|
|
|
DBG (3, "sane_init: adding backend `%s' (preloaded)\n", preloaded_backends[i].name);
|
1999-08-09 18:06:01 +00:00
|
|
|
preloaded_backends[i].next = first_backend;
|
|
|
|
first_backend = &preloaded_backends[i];
|
|
|
|
}
|
|
|
|
|
2001-04-22 20:01:30 +00:00
|
|
|
/* Return the version number of the sane-backends package to allow
|
|
|
|
the frontend to print them. This is done only for net and dll,
|
|
|
|
because these backends are usually called by the frontend. */
|
1999-08-09 18:06:01 +00:00
|
|
|
if (version_code)
|
2001-04-16 12:21:41 +00:00
|
|
|
*version_code = SANE_VERSION_CODE (SANE_DLL_V_MAJOR, SANE_DLL_V_MINOR,
|
|
|
|
SANE_DLL_V_BUILD);
|
1999-08-09 18:06:01 +00:00
|
|
|
|
2008-05-07 17:04:40 +00:00
|
|
|
/*
|
|
|
|
* Read dll.conf & dll.d
|
|
|
|
* Read dll.d first, so that the extras backends will be tried last
|
|
|
|
*/
|
|
|
|
read_dlld ();
|
|
|
|
read_config (DLL_CONFIG_FILE);
|
1999-08-09 18:06:01 +00:00
|
|
|
|
2000-03-05 13:57:25 +00:00
|
|
|
fp = sanei_config_open (DLL_ALIASES_FILE);
|
|
|
|
if (!fp)
|
2002-12-04 20:30:48 +00:00
|
|
|
return SANE_STATUS_GOOD; /* don't insist on aliases file */
|
2000-03-05 13:57:25 +00:00
|
|
|
|
2003-04-04 10:26:20 +00:00
|
|
|
DBG (5, "sane_init: reading %s\n", DLL_ALIASES_FILE);
|
2002-12-04 20:25:13 +00:00
|
|
|
while (sanei_config_read (config_line, sizeof (config_line), fp))
|
2000-03-05 13:57:25 +00:00
|
|
|
{
|
2002-12-04 20:30:48 +00:00
|
|
|
if (config_line[0] == '#') /* ignore line comments */
|
|
|
|
continue;
|
2000-03-05 13:57:25 +00:00
|
|
|
|
2002-12-04 20:25:13 +00:00
|
|
|
len = strlen (config_line);
|
2000-03-05 13:57:25 +00:00
|
|
|
if (!len)
|
2002-12-04 20:30:48 +00:00
|
|
|
continue; /* ignore empty lines */
|
2000-03-05 13:57:25 +00:00
|
|
|
|
2002-12-04 20:25:13 +00:00
|
|
|
add_alias (config_line);
|
2000-03-05 13:57:25 +00:00
|
|
|
}
|
|
|
|
fclose (fp);
|
2005-07-15 21:59:25 +00:00
|
|
|
|
|
|
|
#else
|
2006-01-22 09:04:41 +00:00
|
|
|
/* no ugly config files, just get scanners from their ~/config/add-ons/SANE */
|
|
|
|
/* look for drivers */
|
2005-07-15 21:59:25 +00:00
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
if (find_directory(which[i],0,true,path,1024) < B_OK)
|
|
|
|
continue;
|
|
|
|
strcat(path,"/SANE/");
|
|
|
|
dir=opendir(path);
|
|
|
|
if(!dir) continue;
|
|
|
|
|
|
|
|
while((dirent=readdir(dir)))
|
|
|
|
{
|
|
|
|
if((strcmp(dirent->d_name,".")==0) || (strcmp(dirent->d_name,"..")==0)) continue;
|
|
|
|
if((strcmp(dirent->d_name,"dll")==0)) continue;
|
|
|
|
add_backend(dirent->d_name,0);
|
|
|
|
}
|
|
|
|
closedir(dir);
|
|
|
|
}
|
|
|
|
#endif /* __BEOS__ */
|
|
|
|
|
1999-08-09 18:06:01 +00:00
|
|
|
return SANE_STATUS_GOOD;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sane_exit (void)
|
|
|
|
{
|
|
|
|
struct backend *be, *next;
|
2000-03-05 13:57:25 +00:00
|
|
|
struct alias *alias;
|
1999-08-09 18:06:01 +00:00
|
|
|
|
2002-12-04 20:30:48 +00:00
|
|
|
DBG (2, "sane_exit: exiting\n");
|
1999-08-09 18:06:01 +00:00
|
|
|
|
|
|
|
for (be = first_backend; be; be = next)
|
|
|
|
{
|
|
|
|
next = be->next;
|
|
|
|
if (be->loaded)
|
2002-12-04 20:30:48 +00:00
|
|
|
{
|
2002-04-21 14:02:58 +00:00
|
|
|
if (be->inited)
|
|
|
|
{
|
2002-12-04 20:30:48 +00:00
|
|
|
DBG (3, "sane_exit: calling backend `%s's exit function\n",
|
|
|
|
be->name);
|
2003-04-13 13:25:15 +00:00
|
|
|
(*(op_exit_t)be->op[OP_EXIT]) ();
|
2002-04-21 14:02:58 +00:00
|
|
|
}
|
2005-07-15 21:59:25 +00:00
|
|
|
#ifdef __BEOS__
|
2006-01-22 09:04:41 +00:00
|
|
|
/* use BeOS kernel functions to unload add-ons */
|
|
|
|
if(be->handle) unload_add_on((image_id)be->handle);
|
2005-07-15 21:59:25 +00:00
|
|
|
#else
|
1999-08-09 18:06:01 +00:00
|
|
|
#ifdef HAVE_DLL
|
|
|
|
|
|
|
|
#ifdef HAVE_DLOPEN
|
2002-12-04 20:30:48 +00:00
|
|
|
if (be->handle)
|
|
|
|
dlclose (be->handle);
|
1999-08-09 18:06:01 +00:00
|
|
|
#elif defined(HAVE_SHL_LOAD)
|
2002-12-04 20:30:48 +00:00
|
|
|
if (be->handle)
|
|
|
|
shl_unload (be->handle);
|
2002-12-01 12:42:01 +00:00
|
|
|
#elif defined(HAVE_NSLINKMODULE)
|
2002-12-04 20:30:48 +00:00
|
|
|
if (be->handle)
|
|
|
|
NSUnLinkModule (be->handle, NSUNLINKMODULE_OPTION_NONE
|
2002-12-01 12:42:01 +00:00
|
|
|
# ifdef __ppc__
|
2002-12-04 20:30:48 +00:00
|
|
|
| NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES
|
|
|
|
# endif
|
|
|
|
);
|
1999-08-09 18:06:01 +00:00
|
|
|
#else
|
|
|
|
# error "Tried to compile unsupported DLL."
|
|
|
|
#endif /* HAVE_DLOPEN */
|
|
|
|
|
|
|
|
#endif /* HAVE_DLL */
|
2005-07-15 21:59:25 +00:00
|
|
|
#endif /* __BEOS__ */
|
2002-12-04 20:30:48 +00:00
|
|
|
}
|
1999-08-09 18:06:01 +00:00
|
|
|
if (!be->permanent)
|
2002-12-04 20:30:48 +00:00
|
|
|
{
|
|
|
|
if (be->name)
|
|
|
|
free ((void *) be->name);
|
|
|
|
free (be);
|
|
|
|
}
|
2002-04-21 14:02:58 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
be->inited = 0;
|
|
|
|
}
|
1999-08-09 18:06:01 +00:00
|
|
|
}
|
|
|
|
first_backend = 0;
|
2000-03-05 13:57:25 +00:00
|
|
|
|
2002-12-04 20:30:48 +00:00
|
|
|
while ((alias = first_alias) != NULL)
|
2000-03-05 13:57:25 +00:00
|
|
|
{
|
|
|
|
first_alias = first_alias->next;
|
2002-12-04 20:30:48 +00:00
|
|
|
free (alias->oldname);
|
|
|
|
free (alias);
|
2000-03-05 13:57:25 +00:00
|
|
|
}
|
2001-02-12 19:31:01 +00:00
|
|
|
|
|
|
|
if (NULL != devlist)
|
2002-12-04 20:30:48 +00:00
|
|
|
{ /* Release memory allocated by sane_get_devices(). */
|
2001-02-12 19:31:01 +00:00
|
|
|
int i = 0;
|
|
|
|
while (devlist[i])
|
2002-12-04 20:30:48 +00:00
|
|
|
free (devlist[i++]);
|
|
|
|
free (devlist);
|
2001-02-12 19:31:01 +00:00
|
|
|
|
|
|
|
devlist = NULL;
|
|
|
|
devlist_size = 0;
|
|
|
|
devlist_len = 0;
|
|
|
|
}
|
2002-12-04 20:30:48 +00:00
|
|
|
DBG (3, "sane_exit: finished\n");
|
1999-08-09 18:06:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Note that a call to get_devices() implies that we'll have to load
|
|
|
|
all backends. To avoid this, you can call sane_open() directly
|
|
|
|
(assuming you know the name of the backend/device). This is
|
|
|
|
appropriate for the command-line interface of SANE, for example.
|
|
|
|
*/
|
|
|
|
SANE_Status
|
|
|
|
sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only)
|
|
|
|
{
|
|
|
|
const SANE_Device **be_list;
|
|
|
|
struct backend *be;
|
|
|
|
SANE_Status status;
|
|
|
|
char *full_name;
|
|
|
|
int i, num_devs;
|
|
|
|
size_t len;
|
2000-08-12 15:11:46 +00:00
|
|
|
#define ASSERT_SPACE(n) \
|
|
|
|
{ \
|
|
|
|
if (devlist_len + (n) > devlist_size) \
|
|
|
|
{ \
|
|
|
|
devlist_size += (n) + 15; \
|
|
|
|
if (devlist) \
|
|
|
|
devlist = realloc (devlist, devlist_size * sizeof (devlist[0])); \
|
|
|
|
else \
|
|
|
|
devlist = malloc (devlist_size * sizeof (devlist[0])); \
|
|
|
|
if (!devlist) \
|
|
|
|
return SANE_STATUS_NO_MEM; \
|
|
|
|
} \
|
1999-08-09 18:06:01 +00:00
|
|
|
}
|
|
|
|
|
2003-04-04 10:26:20 +00:00
|
|
|
DBG (3, "sane_get_devices\n");
|
|
|
|
|
1999-08-09 18:06:01 +00:00
|
|
|
if (devlist)
|
|
|
|
for (i = 0; i < devlist_len; ++i)
|
|
|
|
free ((void *) devlist[i]);
|
|
|
|
devlist_len = 0;
|
|
|
|
|
|
|
|
for (be = first_backend; be; be = be->next)
|
|
|
|
{
|
|
|
|
if (!be->inited)
|
2002-12-04 20:30:48 +00:00
|
|
|
if (init (be) != SANE_STATUS_GOOD)
|
|
|
|
continue;
|
1999-08-09 18:06:01 +00:00
|
|
|
|
2003-04-13 13:25:15 +00:00
|
|
|
status = (*(op_get_devs_t)be->op[OP_GET_DEVS]) (&be_list, local_only);
|
1999-08-09 18:06:01 +00:00
|
|
|
if (status != SANE_STATUS_GOOD || !be_list)
|
2002-12-04 20:30:48 +00:00
|
|
|
continue;
|
1999-08-09 18:06:01 +00:00
|
|
|
|
|
|
|
/* count the number of devices for this backend: */
|
|
|
|
for (num_devs = 0; be_list[num_devs]; ++num_devs);
|
|
|
|
|
|
|
|
ASSERT_SPACE (num_devs);
|
|
|
|
|
|
|
|
for (i = 0; i < num_devs; ++i)
|
2002-12-04 20:30:48 +00:00
|
|
|
{
|
|
|
|
SANE_Device *dev;
|
|
|
|
char *mem;
|
|
|
|
struct alias *alias;
|
|
|
|
|
|
|
|
for (alias = first_alias; alias != NULL; alias = alias->next)
|
|
|
|
{
|
|
|
|
len = strlen (be->name);
|
|
|
|
if (strlen (alias->oldname) <= len)
|
|
|
|
continue;
|
|
|
|
if (strncmp (alias->oldname, be->name, len) == 0
|
|
|
|
&& alias->oldname[len] == ':'
|
|
|
|
&& strcmp (&alias->oldname[len + 1], be_list[i]->name) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (alias)
|
|
|
|
{
|
|
|
|
if (!alias->newname) /* hidden device */
|
|
|
|
continue;
|
|
|
|
|
|
|
|
len = strlen (alias->newname);
|
|
|
|
mem = malloc (sizeof (*dev) + len + 1);
|
|
|
|
if (!mem)
|
|
|
|
return SANE_STATUS_NO_MEM;
|
|
|
|
|
|
|
|
full_name = mem + sizeof (*dev);
|
|
|
|
strcpy (full_name, alias->newname);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* create a new device entry with a device name that is the
|
|
|
|
sum of the backend name a colon and the backend's device
|
|
|
|
name: */
|
|
|
|
len = strlen (be->name) + 1 + strlen (be_list[i]->name);
|
|
|
|
mem = malloc (sizeof (*dev) + len + 1);
|
|
|
|
if (!mem)
|
|
|
|
return SANE_STATUS_NO_MEM;
|
|
|
|
|
|
|
|
full_name = mem + sizeof (*dev);
|
|
|
|
strcpy (full_name, be->name);
|
|
|
|
strcat (full_name, ":");
|
|
|
|
strcat (full_name, be_list[i]->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
dev = (SANE_Device *) mem;
|
|
|
|
dev->name = full_name;
|
|
|
|
dev->vendor = be_list[i]->vendor;
|
|
|
|
dev->model = be_list[i]->model;
|
|
|
|
dev->type = be_list[i]->type;
|
|
|
|
|
|
|
|
devlist[devlist_len++] = dev;
|
|
|
|
}
|
1999-08-09 18:06:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* terminate device list with NULL entry: */
|
|
|
|
ASSERT_SPACE (1);
|
|
|
|
devlist[devlist_len++] = 0;
|
|
|
|
|
2003-04-13 13:25:15 +00:00
|
|
|
*device_list = (const SANE_Device **) devlist;
|
2003-04-04 10:26:20 +00:00
|
|
|
DBG (3, "sane_get_devices: found %d devices\n", devlist_len - 1);
|
1999-08-09 18:06:01 +00:00
|
|
|
return SANE_STATUS_GOOD;
|
|
|
|
}
|
|
|
|
|
|
|
|
SANE_Status
|
|
|
|
sane_open (SANE_String_Const full_name, SANE_Handle * meta_handle)
|
|
|
|
{
|
|
|
|
const char *be_name, *dev_name;
|
|
|
|
struct meta_scanner *s;
|
2003-04-13 13:25:15 +00:00
|
|
|
SANE_Handle handle;
|
1999-08-09 18:06:01 +00:00
|
|
|
struct backend *be;
|
|
|
|
SANE_Status status;
|
2000-03-05 13:57:25 +00:00
|
|
|
struct alias *alias;
|
|
|
|
|
2003-04-04 10:26:20 +00:00
|
|
|
DBG (3, "sane_open: trying to open `%s'\n", full_name);
|
|
|
|
|
2002-12-04 20:30:48 +00:00
|
|
|
for (alias = first_alias; alias != NULL; alias = alias->next)
|
2000-03-05 13:57:25 +00:00
|
|
|
{
|
2002-12-04 20:30:48 +00:00
|
|
|
if (!alias->newname)
|
|
|
|
continue;
|
|
|
|
if (strcmp (alias->newname, full_name) == 0)
|
|
|
|
{
|
|
|
|
full_name = alias->oldname;
|
|
|
|
break;
|
|
|
|
}
|
2000-03-05 13:57:25 +00:00
|
|
|
}
|
1999-08-09 18:06:01 +00:00
|
|
|
|
|
|
|
dev_name = strchr (full_name, ':');
|
|
|
|
if (dev_name)
|
|
|
|
{
|
|
|
|
#ifdef strndupa
|
|
|
|
be_name = strndupa (full_name, dev_name - full_name);
|
|
|
|
#else
|
|
|
|
char *tmp;
|
|
|
|
|
|
|
|
tmp = alloca (dev_name - full_name + 1);
|
|
|
|
memcpy (tmp, full_name, dev_name - full_name);
|
|
|
|
tmp[dev_name - full_name] = '\0';
|
|
|
|
be_name = tmp;
|
|
|
|
#endif
|
2002-12-04 20:30:48 +00:00
|
|
|
++dev_name; /* skip colon */
|
1999-08-09 18:06:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* if no colon interpret full_name as the backend name; an empty
|
|
|
|
backend device name will cause us to open the first device of
|
|
|
|
that backend. */
|
|
|
|
be_name = full_name;
|
|
|
|
dev_name = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!be_name[0])
|
|
|
|
be = first_backend;
|
|
|
|
else
|
|
|
|
for (be = first_backend; be; be = be->next)
|
|
|
|
if (strcmp (be->name, be_name) == 0)
|
2002-12-04 20:30:48 +00:00
|
|
|
break;
|
1999-08-09 18:06:01 +00:00
|
|
|
|
|
|
|
if (!be)
|
|
|
|
{
|
|
|
|
status = add_backend (be_name, &be);
|
|
|
|
if (status != SANE_STATUS_GOOD)
|
2002-12-04 20:30:48 +00:00
|
|
|
return status;
|
1999-08-09 18:06:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!be->inited)
|
|
|
|
{
|
|
|
|
status = init (be);
|
|
|
|
if (status != SANE_STATUS_GOOD)
|
2002-12-04 20:30:48 +00:00
|
|
|
return status;
|
1999-08-09 18:06:01 +00:00
|
|
|
}
|
|
|
|
|
2003-04-13 13:25:15 +00:00
|
|
|
status = (*(op_open_t)be->op[OP_OPEN]) (dev_name, &handle);
|
1999-08-09 18:06:01 +00:00
|
|
|
if (status != SANE_STATUS_GOOD)
|
|
|
|
return status;
|
|
|
|
|
2000-03-05 13:57:25 +00:00
|
|
|
s = calloc (1, sizeof (*s));
|
1999-08-09 18:06:01 +00:00
|
|
|
if (!s)
|
|
|
|
return SANE_STATUS_NO_MEM;
|
|
|
|
|
|
|
|
s->be = be;
|
|
|
|
s->handle = handle;
|
|
|
|
*meta_handle = s;
|
|
|
|
|
2003-04-04 10:26:20 +00:00
|
|
|
DBG (3, "sane_open: open successful\n");
|
1999-08-09 18:06:01 +00:00
|
|
|
return SANE_STATUS_GOOD;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sane_close (SANE_Handle handle)
|
|
|
|
{
|
|
|
|
struct meta_scanner *s = handle;
|
|
|
|
|
2002-12-04 20:30:48 +00:00
|
|
|
DBG (3, "sane_close(handle=%p)\n", handle);
|
2003-04-13 13:25:15 +00:00
|
|
|
(*(op_close_t)s->be->op[OP_CLOSE]) (s->handle);
|
1999-08-09 18:06:01 +00:00
|
|
|
free (s);
|
|
|
|
}
|
|
|
|
|
|
|
|
const SANE_Option_Descriptor *
|
|
|
|
sane_get_option_descriptor (SANE_Handle handle, SANE_Int option)
|
|
|
|
{
|
|
|
|
struct meta_scanner *s = handle;
|
|
|
|
|
2002-12-04 20:30:48 +00:00
|
|
|
DBG (3, "sane_get_option_descriptor(handle=%p,option=%d)\n", handle,
|
|
|
|
option);
|
2003-04-13 13:25:15 +00:00
|
|
|
return (*(op_get_option_desc_t)s->be->op[OP_GET_OPTION_DESC]) (s->handle, option);
|
1999-08-09 18:06:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SANE_Status
|
|
|
|
sane_control_option (SANE_Handle handle, SANE_Int option,
|
2002-12-04 20:30:48 +00:00
|
|
|
SANE_Action action, void *value, SANE_Word * info)
|
1999-08-09 18:06:01 +00:00
|
|
|
{
|
|
|
|
struct meta_scanner *s = handle;
|
|
|
|
|
2002-12-04 20:30:48 +00:00
|
|
|
DBG (3,
|
|
|
|
"sane_control_option(handle=%p,option=%d,action=%d,value=%p,info=%p)\n",
|
2003-12-27 17:48:39 +00:00
|
|
|
handle, option, action, value, (void *) info);
|
2003-04-13 13:25:15 +00:00
|
|
|
return (*(op_ctl_option_t)s->be->op[OP_CTL_OPTION]) (s->handle, option, action, value,
|
2002-12-04 20:30:48 +00:00
|
|
|
info);
|
1999-08-09 18:06:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SANE_Status
|
|
|
|
sane_get_parameters (SANE_Handle handle, SANE_Parameters * params)
|
|
|
|
{
|
|
|
|
struct meta_scanner *s = handle;
|
|
|
|
|
2003-12-27 17:48:39 +00:00
|
|
|
DBG (3, "sane_get_parameters(handle=%p,params=%p)\n", handle, (void *) params);
|
2003-04-13 13:25:15 +00:00
|
|
|
return (*(op_get_params_t)s->be->op[OP_GET_PARAMS]) (s->handle, params);
|
1999-08-09 18:06:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SANE_Status
|
|
|
|
sane_start (SANE_Handle handle)
|
|
|
|
{
|
|
|
|
struct meta_scanner *s = handle;
|
|
|
|
|
2002-12-04 20:30:48 +00:00
|
|
|
DBG (3, "sane_start(handle=%p)\n", handle);
|
2003-04-13 13:25:15 +00:00
|
|
|
return (*(op_start_t)s->be->op[OP_START]) (s->handle);
|
1999-08-09 18:06:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SANE_Status
|
|
|
|
sane_read (SANE_Handle handle, SANE_Byte * data, SANE_Int max_length,
|
2002-12-04 20:30:48 +00:00
|
|
|
SANE_Int * length)
|
1999-08-09 18:06:01 +00:00
|
|
|
{
|
|
|
|
struct meta_scanner *s = handle;
|
|
|
|
|
2002-12-04 20:30:48 +00:00
|
|
|
DBG (3, "sane_read(handle=%p,data=%p,maxlen=%d,lenp=%p)\n",
|
2003-12-27 17:48:39 +00:00
|
|
|
handle, data, max_length, (void *) length);
|
2003-04-13 13:25:15 +00:00
|
|
|
return (*(op_read_t)s->be->op[OP_READ]) (s->handle, data, max_length, length);
|
1999-08-09 18:06:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sane_cancel (SANE_Handle handle)
|
|
|
|
{
|
|
|
|
struct meta_scanner *s = handle;
|
|
|
|
|
2002-12-04 20:30:48 +00:00
|
|
|
DBG (3, "sane_cancel(handle=%p)\n", handle);
|
2003-04-13 13:25:15 +00:00
|
|
|
(*(op_cancel_t)s->be->op[OP_CANCEL]) (s->handle);
|
1999-08-09 18:06:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SANE_Status
|
|
|
|
sane_set_io_mode (SANE_Handle handle, SANE_Bool non_blocking)
|
|
|
|
{
|
|
|
|
struct meta_scanner *s = handle;
|
|
|
|
|
2002-12-04 20:30:48 +00:00
|
|
|
DBG (3, "sane_set_io_mode(handle=%p,nonblocking=%d)\n", handle,
|
|
|
|
non_blocking);
|
2003-04-13 13:25:15 +00:00
|
|
|
return (*(op_set_io_mode_t)s->be->op[OP_SET_IO_MODE]) (s->handle, non_blocking);
|
1999-08-09 18:06:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SANE_Status
|
|
|
|
sane_get_select_fd (SANE_Handle handle, SANE_Int * fd)
|
|
|
|
{
|
|
|
|
struct meta_scanner *s = handle;
|
|
|
|
|
2003-12-27 17:48:39 +00:00
|
|
|
DBG (3, "sane_get_select_fd(handle=%p,fdp=%p)\n", handle, (void *) fd);
|
2003-04-13 13:25:15 +00:00
|
|
|
return (*(op_get_select_fd_t)s->be->op[OP_GET_SELECT_FD]) (s->handle, fd);
|
1999-08-09 18:06:01 +00:00
|
|
|
}
|