[PATCH] concatenating socket backend
Helge Blischke
H.Blischke at srz-berlin.de
Thu Nov 11 04:45:41 PST 2004
David,
as PostScript jobs that are somewhat ill-behaved may fail
(or at least produce results that are not quite the expected ones),
I'd suggest to use the alternate pstops filter and the
banner-pages option it supports.
Helge
David Decotigny wrote:
>
> Hi,
>
> In our environment, we have a cups server for all the Unix clients, and
> multiple windows machines printing directly to the printers that cups
> manages (blah blah "historical" reasons blah blah...). So, of course,
> when the Unix clients print their banner + document, a document from the
> windows machines might insert itself between the unix banner and the
> unix document...
>
> Here is a quick and dirty hack against cups 1.1.22 that changes the
> socket backend so that the banner + the document are concatenated before
> being sent to the printer in one single TCP connection. If you find this
> useful, tell me, maybe I'll make it nicer. It works well on our HP
> postscript and Tektronix/Xerox postscript printers. I'm pretty convinced
> it does NOT work on any other non-postscript printer !
>
> To test it, re-compile cups entirely cups, either make install or
> replace your running cupsd with the one compiled, this would normally
> not hurt your system unless you are not already running cups 1.1.22.
> HOWEVER I suggest you keep your old version of the "socket" backend
> installed, and that you copy the binary "socket" produced by the
> compilation, as "sockcat" in the backend/ directory of the cups
> installation. Afterwards, to explicitely tell cups to use it in place of
> the old, working, "socket" backend, replace "socket://" with
> "sockcat://" in /etc/cups/printers.conf (the web interface won't allow
> to do that).
>
> I'm quite convinced that http://cups.org/links.php?V124 is really the
> best thing to do for that. But unfortunately I was not good at
> postscript enough to investigate why it could not print any raster
> images (eg png) while all the more "textual" postscript docs would be
> correctly printed...
>
> Regards,
>
> --
> David Decotigny -- LLR -- http://polywww.in2p3.fr
>
> ---------------------------------------------------------------
> diff -ru cups-1.1.22/backend/socket.c MY-cups-1.1.22/backend/socket.c
> --- cups-1.1.22/backend/socket.c 2004-05-13 17:13:42.000000000 +0200
> +++ MY-cups-1.1.22/backend/socket.c 2004-11-10 18:29:59.000000000 +0100
> @@ -159,6 +159,85 @@
> copies = atoi(argv[4]);
> }
>
> +
> + /*
> + * If we can concatenate the files together
> + */
> + if (getenv("CUPS_FILE_ID") != NULL)
> + {
> + const char *strval = getenv("CUPS_FILE_ID");
> + int cur_file, num_files;
> + int fd;
> + const char *tmpdir;
> + int id_copy;
> + char dest_fname[1024];
> +
> +
> + if (getenv("TMPDIR"))
> + tmpdir = getenv("TMPDIR");
> + else
> + tmpdir = "/tmp";
> +
> +
> + if (! getenv("PRINTER"))
> + {
> + fprintf(stderr, "ERROR: invalid PRINTER env variable");
> + return (1);
> + }
> +
> +
> + snprintf(dest_fname, sizeof(dest_fname),
> + "%s/sock-%s-%s.raw", tmpdir, getenv("PRINTER"), argv[1]);
> +
> + if (sscanf(strval, "%d/%d", & cur_file, & num_files) != 2)
> + {
> + fprintf(stderr, "ERROR: CUPS_FILE_ID incorrect");
> + return (1);
> + }
> +
> + fd = open(dest_fname, O_CREAT | O_RDWR | O_APPEND, 0600);
> + if (fd < 0)
> + {
> + syslog(LOG_ERR, "d2: cannot open session file <%s>", dest_fname);
> + perror("open (session file)");
> + return (1);
> + }
> +
> + for (id_copy = 0 ; id_copy < copies ; id_copy ++)
> + {
> + char buffer[1024];
> + int nread;
> +
> + lseek(fp, 0, SEEK_SET);
> + while (1)
> + {
> + nread = read(fp, buffer, sizeof(buffer));
> + if (nread <= 0)
> + break;
> +
> + write(fd, buffer, nread);
> + }
> + // write(fd, "\n", 1);
> + }
> +
> + if (cur_file < num_files-1)
> + {
> + fprintf(stderr, "INFO: intermediary file stored. Waiting for next file");
> + close(fp);
> + close(fd);
> + return 0;
> + }
> + else
> + {
> + unlink(dest_fname);
> + }
> +
> + lseek(fd, 0, SEEK_SET);
> + fp = fd;
> + }
> +
> +
> +
> /*
> * Extract the hostname and port number from the URI...
> */
> diff -ru cups-1.1.22/scheduler/job.c MY-cups-1.1.22/scheduler/job.c
> --- cups-1.1.22/scheduler/job.c 2004-10-08 22:18:02.000000000 +0200
> +++ MY-cups-1.1.22/scheduler/job.c 2004-11-10 17:50:08.000000000 +0100
> @@ -1216,6 +1216,8 @@
> nlspath[1024], /* NLSPATH environment variable */
> datadir[1024], /* CUPS_DATADIR environment variable */
> fontpath[1050], /* CUPS_FONTPATH environment variable */
> + fileid[256], /* CUPS_FILE_ID environment variable */
> +
> vg_args[1024], /* VG_ARGS environment variable */
> ld_assume_kernel[1024]; /* LD_ASSUME_KERNEL environment variable */
> static char *options = NULL; /* Full list of options */
> @@ -1704,7 +1706,9 @@
> snprintf(tmpdir, sizeof(tmpdir), "TMPDIR=%s", TempDir);
> snprintf(datadir, sizeof(datadir), "CUPS_DATADIR=%s", DataDir);
> snprintf(fontpath, sizeof(fontpath), "CUPS_FONTPATH=%s", FontPath);
> - sprintf(ipp_port, "IPP_PORT=%d", LocalPort);
> + snprintf(ipp_port, sizeof(ipp_port), "IPP_PORT=%d", LocalPort);
> + snprintf(fileid, sizeof(fileid), "CUPS_FILE_ID=%d/%d",
> + current->current_file, current->num_files);
>
> envc = 0;
>
> @@ -1726,6 +1730,7 @@
> envp[envc ++] = fontpath;
> envp[envc ++] = "CUPS_SERVER=localhost";
> envp[envc ++] = ipp_port;
> + envp[envc ++] = fileid;
>
> if (getenv("VG_ARGS") != NULL)
> {
--
Helge Blischke
Softwareentwicklung
SRZ Berlin | Firmengruppe besscom
http://www.srz.de
tel: +49 30 75301-360
H.Blischke at srz-berlin.de
H.Blischke at srz-berlin.com
H.Blischke at acm.org
More information about the cups
mailing list