summaryrefslogtreecommitdiff
path: root/frontend
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2021-02-16 18:25:42 +0100
committerJörg Frings-Fürst <debian@jff-webhosting.net>2021-02-16 18:25:42 +0100
commit64ddd1a4dfcefd11f662f5cf4bb05b590d901a97 (patch)
tree4303648095deff998ae20c2393b56db527742ac9 /frontend
parent5793a221e112fa49073de0137d6bfa750a61b0a1 (diff)
parentecaaf250cb33ff61f37a7b441f2337584a655350 (diff)
Merge branch 'feature/upstream' into develop
Diffstat (limited to 'frontend')
-rw-r--r--frontend/Makefile.am13
-rw-r--r--frontend/saned.c45
-rw-r--r--frontend/scanimage.c184
-rw-r--r--frontend/sicc.c4
-rw-r--r--frontend/sicc.h4
-rw-r--r--frontend/stiff.c4
-rw-r--r--frontend/stiff.h4
-rw-r--r--frontend/test.c4
-rw-r--r--frontend/tstbackend.c4
9 files changed, 170 insertions, 96 deletions
diff --git a/frontend/Makefile.am b/frontend/Makefile.am
index d27acf2..47c50f3 100644
--- a/frontend/Makefile.am
+++ b/frontend/Makefile.am
@@ -31,5 +31,18 @@ test_LDADD = ../lib/liblib.la ../backend/libsane.la
tstbackend_SOURCES = tstbackend.c
tstbackend_LDADD = ../lib/liblib.la ../backend/libsane.la
+if preloadable_backends_enabled
+if WITH_GENESYS_TESTS
+## Because the genesys backend is implemented in C++, programs need
+## to link against the standard C++ library. The work-around below
+## will work for the GNU C++ compiler with the GNU standard library
+## for C++. Other build scenarios may need work.
+scanimage_LDADD += -lstdc++
+saned_LDADD += -lstdc++
+test_LDADD += -lstdc++
+tstbackend_LDADD += -lstdc++
+endif
+endif
+
clean-local:
rm -f test tstbackend
diff --git a/frontend/saned.c b/frontend/saned.c
index 0317542..5b16980 100644
--- a/frontend/saned.c
+++ b/frontend/saned.c
@@ -17,8 +17,8 @@
for more details.
You should have received a copy of the GNU General Public License
- along with sane; see the file COPYING. If not, write to the Free
- Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ along with sane; see the file COPYING.
+ If not, see <https://www.gnu.org/licenses/>.
The SANE network daemon. This is the counterpart to the NET
backend.
@@ -256,6 +256,7 @@ static int run_once;
static int data_connect_timeout = 4000;
static Handle *handle;
static char *bind_addr;
+static short bind_port = -1;
static union
{
int w;
@@ -2841,6 +2842,7 @@ do_bindings_family (int family, int *nfds, struct pollfd **fds, struct addrinfo
int on = 1;
int i;
+ sane_port = bind_port;
fdp = *fds;
for (resp = res, i = 0; resp != NULL; resp = resp->ai_next, i++)
@@ -2851,12 +2853,18 @@ do_bindings_family (int family, int *nfds, struct pollfd **fds, struct addrinfo
if (resp->ai_family == AF_INET)
{
- sane_port = ntohs (((struct sockaddr_in *) resp->ai_addr)->sin_port);
+ if (sane_port != -1)
+ ((struct sockaddr_in *) resp->ai_addr)->sin_port = htons(sane_port);
+ else
+ sane_port = ntohs(((struct sockaddr_in *) resp->ai_addr)->sin_port);
}
#ifdef ENABLE_IPV6
else if (resp->ai_family == AF_INET6)
{
- sane_port = ntohs (((struct sockaddr_in6 *) resp->ai_addr)->sin6_port);
+ if (sane_port != -1)
+ ((struct sockaddr_in6 *) resp->ai_addr)->sin6_port = htons(sane_port);
+ else
+ sane_port = ntohs (((struct sockaddr_in6 *) resp->ai_addr)->sin6_port);
}
#endif /* ENABLE_IPV6 */
else
@@ -2903,6 +2911,28 @@ do_bindings_family (int family, int *nfds, struct pollfd **fds, struct addrinfo
continue;
}
+ if (sane_port == 0)
+ {
+ /* sane was asked to bind to an ephemeral port, log it */
+ socklen_t len = sizeof (*resp->ai_addr);
+ if (getsockname(fd, resp->ai_addr, &len) != -1)
+ {
+ if (resp->ai_family == AF_INET)
+ {
+ DBG (DBG_INFO, "do_bindings: [%d] selected ephemeral port: %d\n", i, ntohs(((struct sockaddr_in *) resp->ai_addr)->sin_port));
+ }
+
+#ifdef ENABLE_IPV6
+ if (resp->ai_family == AF_INET6)
+ {
+ DBG (DBG_INFO, "do_bindings: [%d] selected ephemeral port: %d\n", i, ntohs(((struct sockaddr_in6 *) resp->ai_addr)->sin6_port));
+ }
+
+#endif /* ENABLE_IPV6 */
+
+ }
+ }
+
fdp->fd = fd;
fdp->events = POLLIN;
@@ -3391,6 +3421,7 @@ static void usage(char *me, int err)
" -d, --debug=level set debug level `level' (default is 2)\n"
" -e, --stderr output to stderr\n"
" -b, --bind=addr bind address `addr' (default all interfaces)\n"
+ " -p, --port=port bind port `port` (default sane-port or 6566)\n"
" -h, --help show this help message and exit\n", me);
exit(err);
@@ -3410,6 +3441,7 @@ static struct option long_options[] =
{"debug", required_argument, 0, 'd'},
{"stderr", no_argument, 0, 'e'},
{"bind", required_argument, 0, 'b'},
+ {"port", required_argument, 0, 'p'},
{0, 0, 0, 0 }
};
@@ -3435,7 +3467,7 @@ main (int argc, char *argv[])
run_foreground = SANE_TRUE;
run_once = SANE_FALSE;
- while((c = getopt_long(argc, argv,"ha::lu:Dod:eb:", long_options, &long_index )) != -1)
+ while((c = getopt_long(argc, argv,"ha::lu:Dod:eb:p:", long_options, &long_index )) != -1)
{
switch(c) {
case 'a':
@@ -3465,6 +3497,9 @@ main (int argc, char *argv[])
case 'b':
bind_addr = optarg;
break;
+ case 'p':
+ bind_port = atoi(optarg);
+ break;
case 'h':
usage(argv[0], EXIT_SUCCESS);
break;
diff --git a/frontend/scanimage.c b/frontend/scanimage.c
index 3902092..901a7c8 100644
--- a/frontend/scanimage.c
+++ b/frontend/scanimage.c
@@ -20,8 +20,8 @@
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
#ifdef _AIX
# include "../include/lalloca.h" /* MUST come first for AIX! */
@@ -73,6 +73,7 @@ typedef struct
int height;
int x;
int y;
+ int num_channels;
}
Image;
@@ -440,88 +441,108 @@ print_option (SANE_Device * device, int opt_num, const SANE_Option_Descriptor *o
break;
case SANE_CONSTRAINT_RANGE:
- if (opt->type == SANE_TYPE_INT)
- {
- if (!strcmp (opt->name, "x"))
- {
- printf ("%d..%d",
- opt->constraint.range->min,
- opt->constraint.range->max - tl_x);
- }
- else if (!strcmp (opt->name, "y"))
- {
- printf ("%d..%d",
- opt->constraint.range->min,
- opt->constraint.range->max - tl_y);
- }
- else
- {
- printf ("%d..%d",
- opt->constraint.range->min,
- opt->constraint.range->max);
- }
- print_unit (opt->unit);
- if (opt->size > (SANE_Int) sizeof (SANE_Word))
- fputs (",...", stdout);
- if (opt->constraint.range->quant)
- printf (" (in steps of %d)", opt->constraint.range->quant);
- }
- else
- {
- if (!strcmp (opt->name, "x"))
- {
- printf ("%g..%g",
- SANE_UNFIX (opt->constraint.range->min),
- SANE_UNFIX (opt->constraint.range->max - tl_x));
- }
- else if (!strcmp (opt->name, "y"))
- {
- printf ("%g..%g",
- SANE_UNFIX (opt->constraint.range->min),
- SANE_UNFIX (opt->constraint.range->max - tl_y));
- }
- else
- {
- printf ("%g..%g",
- SANE_UNFIX (opt->constraint.range->min),
- SANE_UNFIX (opt->constraint.range->max));
- }
- print_unit (opt->unit);
- if (opt->size > (SANE_Int) sizeof (SANE_Word))
- fputs (",...", stdout);
- if (opt->constraint.range->quant)
- printf (" (in steps of %g)",
- SANE_UNFIX (opt->constraint.range->quant));
- }
- break;
+ // Check for no range - some buggy backends can miss this out.
+ if (!opt->constraint.range)
+ {
+ fputs ("{no_range}", stdout);
+ }
+ else
+ {
+ if (opt->type == SANE_TYPE_INT)
+ {
+ if (!strcmp (opt->name, "x"))
+ {
+ printf ("%d..%d", opt->constraint.range->min,
+ opt->constraint.range->max - tl_x);
+ }
+ else if (!strcmp (opt->name, "y"))
+ {
+ printf ("%d..%d", opt->constraint.range->min,
+ opt->constraint.range->max - tl_y);
+ }
+ else
+ {
+ printf ("%d..%d", opt->constraint.range->min,
+ opt->constraint.range->max);
+ }
+ print_unit (opt->unit);
+ if (opt->size > (SANE_Int) sizeof(SANE_Word))
+ fputs (",...", stdout);
+ if (opt->constraint.range->quant)
+ printf (" (in steps of %d)", opt->constraint.range->quant);
+ }
+ else
+ {
+ if (!strcmp (opt->name, "x"))
+ {
+ printf ("%g..%g", SANE_UNFIX(opt->constraint.range->min),
+ SANE_UNFIX(opt->constraint.range->max - tl_x));
+ }
+ else if (!strcmp (opt->name, "y"))
+ {
+ printf ("%g..%g", SANE_UNFIX(opt->constraint.range->min),
+ SANE_UNFIX(opt->constraint.range->max - tl_y));
+ }
+ else
+ {
+ printf ("%g..%g", SANE_UNFIX(opt->constraint.range->min),
+ SANE_UNFIX(opt->constraint.range->max));
+ }
+ print_unit (opt->unit);
+ if (opt->size > (SANE_Int) sizeof(SANE_Word))
+ fputs (",...", stdout);
+ if (opt->constraint.range->quant)
+ printf (" (in steps of %g)",
+ SANE_UNFIX(opt->constraint.range->quant));
+ }
+ }
+ break;
case SANE_CONSTRAINT_WORD_LIST:
- for (i = 0; i < opt->constraint.word_list[0]; ++i)
- {
- if (not_first)
- fputc ('|', stdout);
+ // Check no words in list or no list - - some buggy backends can miss this out.
+ // Note the check on < 1 as SANE_Int is signed.
+ if (!opt->constraint.word_list || (opt->constraint.word_list[0] < 1))
+ {
+ fputs ("{no_wordlist}", stdout);
+ }
+ else
+ {
+ for (i = 0; i < opt->constraint.word_list[0]; ++i)
+ {
+ if (not_first)
+ fputc ('|', stdout);
- not_first = SANE_TRUE;
+ not_first = SANE_TRUE;
+
+ if (opt->type == SANE_TYPE_INT)
+ printf ("%d", opt->constraint.word_list[i + 1]);
+ else
+ printf ("%g", SANE_UNFIX(opt->constraint.word_list[i + 1]));
+ }
+ }
- if (opt->type == SANE_TYPE_INT)
- printf ("%d", opt->constraint.word_list[i + 1]);
- else
- printf ("%g", SANE_UNFIX (opt->constraint.word_list[i + 1]));
- }
print_unit (opt->unit);
if (opt->size > (SANE_Int) sizeof (SANE_Word))
fputs (",...", stdout);
break;
case SANE_CONSTRAINT_STRING_LIST:
- for (i = 0; opt->constraint.string_list[i]; ++i)
- {
- if (i > 0)
- fputc ('|', stdout);
+ // Check for missing strings - some buggy backends can miss this out.
+ if (!opt->constraint.string_list || !opt->constraint.string_list[0])
+ {
+ fputs ("{no_stringlist}", stdout);
+ }
+ else
+ {
+ for (i = 0; opt->constraint.string_list[i]; ++i)
+ {
+ if (i > 0)
+ fputc ('|', stdout);
- fputs (opt->constraint.string_list[i], stdout);
- }
- break;
+ fputs (opt->constraint.string_list[i], stdout);
+ }
+ }
+ break;
}
}
@@ -1124,6 +1145,8 @@ process_backend_option (SANE_Handle device, int optnum, const char *optarg)
return;
}
set_option (device, optnum, valuep);
+ if (opt->type == SANE_TYPE_STRING && valuep)
+ free(valuep);
}
static void
@@ -1285,10 +1308,10 @@ advance (Image * image)
size_t old_size = 0, new_size;
if (image->data)
- old_size = image->height * image->width;
+ old_size = image->height * image->width * image->num_channels;
image->height += STRIP_HEIGHT;
- new_size = image->height * image->width;
+ new_size = image->height * image->width * image->num_channels;
if (image->data)
image->data = realloc (image->data, new_size);
@@ -1312,7 +1335,7 @@ scan_it (FILE *ofp)
SANE_Byte min = 0xff, max = 0;
SANE_Parameters parm;
SANE_Status status;
- Image image = { 0, 0, 0, 0, 0 };
+ Image image = { 0, 0, 0, 0, 0, 0 };
static const char *format_name[] = {
"gray", "RGB", "red", "green", "blue"
};
@@ -1382,6 +1405,7 @@ scan_it (FILE *ofp)
if (first_frame)
{
+ image.num_channels = 1;
switch (parm.format)
{
case SANE_FRAME_RED:
@@ -1390,6 +1414,7 @@ scan_it (FILE *ofp)
assert (parm.depth == 8);
must_buffer = 1;
offset = parm.format - SANE_FRAME_RED;
+ image.num_channels = 3;
break;
case SANE_FRAME_RGB:
@@ -1517,6 +1542,7 @@ scan_it (FILE *ofp)
case SANE_FRAME_RED:
case SANE_FRAME_GREEN:
case SANE_FRAME_BLUE:
+ image.num_channels = 3;
for (i = 0; i < len; ++i)
{
image.data[offset + 3 * i] = buffer[i];
@@ -1530,6 +1556,7 @@ scan_it (FILE *ofp)
break;
case SANE_FRAME_RGB:
+ image.num_channels = 1;
for (i = 0; i < len; ++i)
{
image.data[offset + i] = buffer[i];
@@ -1543,6 +1570,7 @@ scan_it (FILE *ofp)
break;
case SANE_FRAME_GRAY:
+ image.num_channels = 1;
for (i = 0; i < len; ++i)
{
image.data[offset + i] = buffer[i];
@@ -1725,7 +1753,7 @@ scan_it (FILE *ofp)
}
#endif
- fwrite (image.data, 1, image.height * image.width, ofp);
+ fwrite (image.data, 1, image.height * image.width * image.num_channels, ofp);
}
#ifdef HAVE_LIBPNG
if(output_format == OUTPUT_PNG)
@@ -1800,7 +1828,7 @@ test_it (void)
int i, len;
SANE_Parameters parm;
SANE_Status status;
- Image image = { 0, 0, 0, 0, 0 };
+ Image image = { 0, 0, 0, 0, 0, 0 };
static const char *format_name[] =
{ "gray", "RGB", "red", "green", "blue" };
diff --git a/frontend/sicc.c b/frontend/sicc.c
index c93e5c3..e6826f0 100644
--- a/frontend/sicc.c
+++ b/frontend/sicc.c
@@ -12,8 +12,8 @@
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
#include "../include/sane/config.h"
diff --git a/frontend/sicc.h b/frontend/sicc.h
index 5c225da..9251a37 100644
--- a/frontend/sicc.h
+++ b/frontend/sicc.h
@@ -12,8 +12,8 @@
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
void *
sanei_load_icc_profile (const char *path, size_t *size);
diff --git a/frontend/stiff.c b/frontend/stiff.c
index c9153e5..3f86c79 100644
--- a/frontend/stiff.c
+++ b/frontend/stiff.c
@@ -14,8 +14,8 @@
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
/* Changes:
2000-11-19, PK: Color TIFF-header: write 3 values for bits per sample
diff --git a/frontend/stiff.h b/frontend/stiff.h
index 6560ef6..f6f8df5 100644
--- a/frontend/stiff.h
+++ b/frontend/stiff.h
@@ -12,8 +12,8 @@
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
void
sanei_write_tiff_header (SANE_Frame format, int width, int height, int depth,
diff --git a/frontend/test.c b/frontend/test.c
index 3b1c4ae..9ad3a66 100644
--- a/frontend/test.c
+++ b/frontend/test.c
@@ -13,8 +13,8 @@
for more details.
You should have received a copy of the GNU General Public License
- along with sane; see the file COPYING. If not, write to the Free
- Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ along with sane; see the file COPYING.
+ If not, see <https://www.gnu.org/licenses/>.
This file implements a simple SANE frontend (well it rather is a
transport layer, but seen from libsane it is a frontend) which acts
diff --git a/frontend/tstbackend.c b/frontend/tstbackend.c
index 985684d..b41ff61 100644
--- a/frontend/tstbackend.c
+++ b/frontend/tstbackend.c
@@ -18,9 +18,7 @@
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.
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#define BUILD 19 /* 2013-03-29 */