sane-project-website/old-archive/2000-01/0251.html

716 wiersze
15 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>
<TITLE>sane-devel: Re: dll backend: aliased &amp; hidden device names</TITLE>
<META NAME="Author" CONTENT="Ingo Wilken (Ingo.Wilken@Informatik.Uni-Oldenburg.DE)">
<META NAME="Subject" CONTENT="Re: dll backend: aliased &amp; hidden device names">
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Re: dll backend: aliased &amp; hidden device names</H1>
<!-- received="Wed Jan 26 14:37:50 2000" -->
<!-- isoreceived="20000126223750" -->
<!-- sent="Wed, 26 Jan 2000 23:40:31 +0100 (MET)" -->
<!-- isosent="20000126224031" -->
<!-- name="Ingo Wilken" -->
<!-- email="Ingo.Wilken@Informatik.Uni-Oldenburg.DE" -->
<!-- subject="Re: dll backend: aliased &amp; hidden device names" -->
<!-- id="m12Db71-000ILSC@petersfehn.Informatik.Uni-Oldenburg.DE" -->
<!-- inreplyto="200001260400.MAA14244@minerva.ee.uwa.edu.au" -->
<STRONG>From:</STRONG> Ingo Wilken (<A HREF="mailto:Ingo.Wilken@Informatik.Uni-Oldenburg.DE?Subject=Re:%20dll%20backend:%20aliased%20&amp;%20hidden%20device%20names&In-Reply-To=&lt;m12Db71-000ILSC@petersfehn.Informatik.Uni-Oldenburg.DE&gt;"><EM>Ingo.Wilken@Informatik.Uni-Oldenburg.DE</EM></A>)<BR>
<STRONG>Date:</STRONG> Wed Jan 26 2000 - 14:40:31 PST
<P>
<!-- next="start" -->
<LI><STRONG>Next message:</STRONG> <A HREF="0252.html">jes@presto.med.upenn.edu: "Re: Semi OT: SCSI termination question"</A>
<UL>
<LI><STRONG>Previous message:</STRONG> <A HREF="0250.html">Jonathan Buzzard: "Re: Update: Linux USB and Scanners"</A>
<!-- nextthread="start" -->
<!-- reply="end" -->
<LI><STRONG>Messages sorted by:</STRONG>
<A HREF="date.html#251">[ date ]</A>
<A HREF="index.html#251">[ thread ]</A>
<A HREF="subject.html#251">[ subject ]</A>
<A HREF="author.html#251">[ author ]</A>
</UL>
<HR NOSHADE><P>
<!-- body="start" -->
<P>
Hi
<BR>
<P><EM>&gt; I'm currently collecting SANE patches, and was planning to test your
</EM><BR>
<EM>&gt; dll alias patch. Unfortunately, the only version I have available is
</EM><BR>
<EM>&gt; &lt;URL:<A HREF="http://www.mostang.com/mail-archive/sane-devel/1999-07/0007.html">http://www.mostang.com/mail-archive/sane-devel/1999-07/0007.html</A>&gt;,
</EM><BR>
<EM>&gt; which is filled with HTML tags. :-(
</EM><BR>
<EM>&gt; Could you send me the latest version of you patch, possibly relative
</EM><BR>
<EM>&gt; to the latest SANE CVS snapshot,
</EM><BR>
<EM>&gt; &lt;URL:<A HREF="http://www.student.uit.no/~pere/linux/sane/sane-devel-20000123.tar.gz">http://www.student.uit.no/~pere/linux/sane/sane-devel-20000123.tar.gz</A>&gt;?
</EM><BR>
<P>I did no further work on the aliases/hidden stuff. The old patch is
<BR>
appended below. I'll create a new patch relative to the CVS snapshot
<BR>
when I get it to my home machine (possibly next week - I'm currently only
<BR>
reading mail via a dead slow modem link and long distance call, so I'm not
<BR>
going to download anything larger than a few KB).
<BR>
<P>For best results, there should be a modification to the SANE API so programs
<BR>
(and special backends like the net backend) can request unaliased device
<BR>
names in sane_get_devices(). It's a minor modification:
<BR>
&nbsp;SANE_Status sane_get_devices(const SANE_Device ***dev, SANE_Bool local_only)
<BR>
would become something like
<BR>
&nbsp;SANE_Status sane_get_devices(const SANE_Device ***dev, SANE_Flags flags)
<BR>
with two possible flags:
<BR>
&nbsp;#define SANEF_LOCAL_ONLY 0x01
<BR>
&nbsp;#define SANEF_UNALIASED 0x02
<BR>
<P>Regards,
<BR>
Ingo
<BR>
<P>--- my old mail with the patch: ---
<BR>
This is a first attempt to add device names aliases and hidden
<BR>
devices to the dll backend. It works ok here, so I'm releasing
<BR>
the patches and ask for your comments.
<BR>
<P>Aliases are defined in the new config file &quot;dll.aliases&quot;.
<BR>
This can contain entries of the form
<BR>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alias SomeName SaneDeviceName
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alias &quot;Some Name&quot; SaneDeviceName
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hide SaneDeviceName
<BR>
<P>For example:
<BR>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alias Epson net:somehost:epson:/dev/sgX
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alias &quot;Siemens ST400&quot; st400:/dev/sgY
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hide net:somehost:pnm:0
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hide net:somehost:pnm:1
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alias &quot;Read from file&quot; pnm:0
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hide pnm:1
<BR>
<P>Aliased device names are automatically hidden.
<BR>
<P>The idea is that users don't have to deal with complicated device
<BR>
names (especially for networked devices), and to hide other exported
<BR>
devices which might confuse them. Note that a hidden device can still
<BR>
be accessed if the device name is known, it just doesn't appear on
<BR>
the list.
<BR>
<P>Regards,
<BR>
Ingo
<BR>
<P><P>*** dll.c.orig Tue Apr 27 06:35:12 1999
<BR>
--- dll.c Fri Jul 2 19:24:42 1999
<BR>
***************
<BR>
*** 91,96 ****
<BR>
--- 91,97 ----
<BR>
&nbsp;&nbsp;
<BR>
&nbsp;&nbsp;#include &lt;sane/sanei_config.h&gt;
<BR>
&nbsp;&nbsp;#define DLL_CONFIG_FILE &quot;dll.conf&quot;
<BR>
+ #define DLL_ALIASES_FILE &quot;dll.aliases&quot;
<BR>
&nbsp;&nbsp;
<BR>
&nbsp;&nbsp;enum SANE_Ops
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;{
<BR>
***************
<BR>
*** 170,175 ****
<BR>
--- 171,184 ----
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SANE_Handle handle;
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;};
<BR>
&nbsp;&nbsp;
<BR>
+ struct alias
<BR>
+ {
<BR>
+ struct alias *next;
<BR>
+ char *oldname;
<BR>
+ char *newname;
<BR>
+ };
<BR>
+
<BR>
+ static struct alias *first_alias;
<BR>
&nbsp;&nbsp;static SANE_Auth_Callback auth_callback;
<BR>
&nbsp;&nbsp;static struct backend *first_backend;
<BR>
&nbsp;&nbsp;static const char *op_name[] =
<BR>
***************
<BR>
*** 302,308 ****
<BR>
--- 311,321 ----
<BR>
&nbsp;&nbsp;#endif /* HAVE_DLOPEN */
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;if (!be-&gt;handle)
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<BR>
+ #ifdef HAVE_DLOPEN
<BR>
+ DBG(2, &quot;dlopen() failed (%s)\n&quot;, dlerror ());
<BR>
+ #else
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DBG(2, &quot;dlopen() failed (%s)\n&quot;, strerror (errno));
<BR>
+ #endif /* HAVE_DLOPEN */
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return SANE_STATUS_INVAL;
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<BR>
&nbsp;&nbsp;
<BR>
***************
<BR>
*** 379,384 ****
<BR>
--- 392,478 ----
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;return SANE_STATUS_GOOD;
<BR>
&nbsp;&nbsp;}
<BR>
&nbsp;&nbsp;
<BR>
+
<BR>
+ static void
<BR>
+ add_alias (char *line)
<BR>
+ {
<BR>
+ const char *command;
<BR>
+ enum { CMD_ALIAS, CMD_HIDE } cmd;
<BR>
+ const char *oldname, *oldend, *newname, *newend;
<BR>
+ size_t oldlen, newlen;
<BR>
+ struct alias *alias;
<BR>
+
<BR>
+ command = sanei_config_skip_whitespace(line);
<BR>
+ if( !*command )
<BR>
+ return;
<BR>
+ line = strpbrk(command, &quot; \t&quot;);
<BR>
+ if( !line )
<BR>
+ return;
<BR>
+ *line++ = '\0';
<BR>
+
<BR>
+ if( strcmp(command, &quot;alias&quot;) == 0 )
<BR>
+ cmd = CMD_ALIAS;
<BR>
+ else
<BR>
+ if( strcmp(command, &quot;hide&quot;) == 0 )
<BR>
+ cmd = CMD_HIDE;
<BR>
+ else
<BR>
+ return;
<BR>
+
<BR>
+ newlen = 0;
<BR>
+ newname = NULL;
<BR>
+ if( cmd == CMD_ALIAS )
<BR>
+ {
<BR>
+ newname = sanei_config_skip_whitespace(line);
<BR>
+ if( !*newname )
<BR>
+ return;
<BR>
+ if( *newname == '\&quot;' )
<BR>
+ {
<BR>
+ ++newname;
<BR>
+ newend = strchr(newname, '\&quot;');
<BR>
+ }
<BR>
+ else
<BR>
+ newend = strpbrk(newname, &quot; \t&quot;);
<BR>
+ if( !newend )
<BR>
+ return;
<BR>
+
<BR>
+ newlen = newend - newname;
<BR>
+ line = (char*)(newend+1);
<BR>
+ }
<BR>
+
<BR>
+ oldname = sanei_config_skip_whitespace(line);
<BR>
+ if( !*oldname )
<BR>
+ return;
<BR>
+ oldend = oldname + strcspn(oldname, &quot; \t&quot;);
<BR>
+
<BR>
+ oldlen = oldend - oldname;
<BR>
+
<BR>
+ alias = malloc(sizeof(struct alias));
<BR>
+ if( alias )
<BR>
+ {
<BR>
+ alias-&gt;oldname = malloc(oldlen + newlen + 2);
<BR>
+ if( alias-&gt;oldname )
<BR>
+ {
<BR>
+ strncpy(alias-&gt;oldname, oldname, oldlen);
<BR>
+ alias-&gt;oldname[oldlen] = '\0';
<BR>
+ if( cmd == CMD_ALIAS )
<BR>
+ {
<BR>
+ alias-&gt;newname = alias-&gt;oldname + oldlen + 1;
<BR>
+ strncpy(alias-&gt;newname, newname, newlen);
<BR>
+ alias-&gt;newname[newlen] = '\0';
<BR>
+ }
<BR>
+ else
<BR>
+ alias-&gt;newname = NULL;
<BR>
+
<BR>
+ alias-&gt;next = first_alias;
<BR>
+ first_alias = alias;
<BR>
+ return;
<BR>
+ }
<BR>
+ free(alias);
<BR>
+ }
<BR>
+ return;
<BR>
+ }
<BR>
+
<BR>
+
<BR>
&nbsp;&nbsp;SANE_Status
<BR>
&nbsp;&nbsp;sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize)
<BR>
&nbsp;&nbsp;{
<BR>
***************
<BR>
*** 422,427 ****
<BR>
--- 516,539 ----
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;fclose (fp);
<BR>
&nbsp;&nbsp;
<BR>
+ fp = sanei_config_open (DLL_ALIASES_FILE);
<BR>
+ if (!fp)
<BR>
+ return SANE_STATUS_GOOD; /* don't insist on aliases file */
<BR>
+
<BR>
+ while (fgets (backend_name, sizeof (backend_name), fp))
<BR>
+ {
<BR>
+ if (backend_name[0] == '#') /* ignore line comments */
<BR>
+ continue;
<BR>
+ len = strlen (backend_name);
<BR>
+ if (backend_name[len - 1] == '\n')
<BR>
+ backend_name[--len] = '\0';
<BR>
+
<BR>
+ if (!len)
<BR>
+ continue; /* ignore empty lines */
<BR>
+
<BR>
+ add_alias (backend_name);
<BR>
+ }
<BR>
+ fclose (fp);
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;return SANE_STATUS_GOOD;
<BR>
&nbsp;&nbsp;}
<BR>
&nbsp;&nbsp;
<BR>
***************
<BR>
*** 429,434 ****
<BR>
--- 541,547 ----
<BR>
&nbsp;&nbsp;sane_exit (void)
<BR>
&nbsp;&nbsp;{
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;struct backend *be, *next;
<BR>
+ struct alias *alias;
<BR>
&nbsp;&nbsp;
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;DBG(1, &quot;exiting\n&quot;);
<BR>
&nbsp;&nbsp;
<BR>
***************
<BR>
*** 461,466 ****
<BR>
--- 574,586 ----
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;first_backend = 0;
<BR>
+
<BR>
+ while( (alias = first_alias) != NULL )
<BR>
+ {
<BR>
+ first_alias = first_alias-&gt;next;
<BR>
+ free(alias-&gt;oldname);
<BR>
+ free(alias);
<BR>
+ }
<BR>
&nbsp;&nbsp;}
<BR>
&nbsp;&nbsp;
<BR>
&nbsp;&nbsp;/* Note that a call to get_devices() implies that we'll have to load
<BR>
***************
<BR>
*** 517,535 ****
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SANE_Device *dev;
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;char *mem;
<BR>
&nbsp;&nbsp;
<BR>
! /* create a new device entry with a device name that is the
<BR>
! sum of the backend name a colon and the backend's device
<BR>
! name: */
<BR>
! len = strlen (be-&gt;name) + 1 + strlen (be_list[i]-&gt;name);
<BR>
! mem = malloc (sizeof (*dev) + len + 1);
<BR>
! if (!mem)
<BR>
! return SANE_STATUS_NO_MEM;
<BR>
!
<BR>
! full_name = mem + sizeof (*dev);
<BR>
! strcpy (full_name, be-&gt;name);
<BR>
! strcat (full_name, &quot;:&quot;);
<BR>
! strcat (full_name, be_list[i]-&gt;name);
<BR>
&nbsp;&nbsp;
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dev = (SANE_Device *) mem;
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dev-&gt;name = full_name;
<BR>
--- 637,683 ----
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SANE_Device *dev;
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;char *mem;
<BR>
+ struct alias *alias;
<BR>
&nbsp;&nbsp;
<BR>
! for(alias = first_alias; alias != NULL; alias = alias-&gt;next)
<BR>
! {
<BR>
! len = strlen(be-&gt;name);
<BR>
! if( strlen(alias-&gt;oldname) &lt;= len )
<BR>
! continue;
<BR>
! if( strncmp(alias-&gt;oldname, be-&gt;name, len) == 0
<BR>
! &amp;&amp; alias-&gt;oldname[len] == ':'
<BR>
! &amp;&amp; strcmp(&amp;alias-&gt;oldname[len+1], be_list[i]-&gt;name) == 0 )
<BR>
! break;
<BR>
! }
<BR>
!
<BR>
! if( alias )
<BR>
! {
<BR>
! if( !alias-&gt;newname ) /* hidden device */
<BR>
! continue;
<BR>
!
<BR>
! len = strlen(alias-&gt;newname);
<BR>
! mem = malloc(sizeof(*dev) + len + 1);
<BR>
! if( !mem )
<BR>
! return SANE_STATUS_NO_MEM;
<BR>
!
<BR>
! full_name = mem + sizeof(*dev);
<BR>
! strcpy(full_name, alias-&gt;newname);
<BR>
! }
<BR>
! else
<BR>
! {
<BR>
! /* create a new device entry with a device name that is the
<BR>
! sum of the backend name a colon and the backend's device
<BR>
! name: */
<BR>
! len = strlen (be-&gt;name) + 1 + strlen (be_list[i]-&gt;name);
<BR>
! mem = malloc (sizeof (*dev) + len + 1);
<BR>
! if (!mem)
<BR>
! return SANE_STATUS_NO_MEM;
<BR>
!
<BR>
! full_name = mem + sizeof (*dev);
<BR>
! strcpy (full_name, be-&gt;name);
<BR>
! strcat (full_name, &quot;:&quot;);
<BR>
! strcat (full_name, be_list[i]-&gt;name);
<BR>
! }
<BR>
&nbsp;&nbsp;
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dev = (SANE_Device *) mem;
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dev-&gt;name = full_name;
<BR>
***************
<BR>
*** 557,562 ****
<BR>
--- 705,722 ----
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;SANE_Handle *handle;
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;struct backend *be;
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;SANE_Status status;
<BR>
+ struct alias *alias;
<BR>
+
<BR>
+ for( alias = first_alias; alias != NULL; alias = alias-&gt;next )
<BR>
+ {
<BR>
+ if( !alias-&gt;newname )
<BR>
+ continue;
<BR>
+ if( strcmp(alias-&gt;newname, full_name) == 0 )
<BR>
+ {
<BR>
+ full_name = alias-&gt;oldname;
<BR>
+ break;
<BR>
+ }
<BR>
+ }
<BR>
&nbsp;&nbsp;
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;dev_name = strchr (full_name, ':');
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;if (dev_name)
<BR>
<P><P><P><PRE>
--
Source code, list archive, and docs: <A HREF="http://www.mostang.com/sane/">http://www.mostang.com/sane/</A>
To unsubscribe: echo unsubscribe sane-devel | mail <A HREF="mailto:majordomo@mostang.com?Subject=Re:%20dll%20backend:%20aliased%20&amp;%20hidden%20device%20names&In-Reply-To=&lt;m12Db71-000ILSC@petersfehn.Informatik.Uni-Oldenburg.DE&gt;">majordomo@mostang.com</A>
</PRE>
<P><!-- body="end" -->
<HR NOSHADE>
<UL>
<!-- next="start" -->
<LI><STRONG>Next message:</STRONG> <A HREF="0252.html">jes@presto.med.upenn.edu: "Re: Semi OT: SCSI termination question"</A>
<LI><STRONG>Previous message:</STRONG> <A HREF="0250.html">Jonathan Buzzard: "Re: Update: Linux USB and Scanners"</A>
<!-- nextthread="start" -->
<!-- reply="end" -->
<LI><STRONG>Messages sorted by:</STRONG>
<A HREF="date.html#251">[ date ]</A>
<A HREF="index.html#251">[ thread ]</A>
<A HREF="subject.html#251">[ subject ]</A>
<A HREF="author.html#251">[ author ]</A>
</UL>
<!-- trailer="footer" -->
<HR NOSHADE>
<P>
<SMALL>
<EM>
This archive was generated by <A HREF="http://www.hypermail.org/">hypermail 2b29</A>
: <EM>Wed Jan 26 2000 - 14:39:38 PST</EM>
</EM>
</SMALL>
</BODY>
</HTML>