cupsPrintFile() has no streaming equivalent?

mike dizaemon at hotmail.com
Thu Feb 22 12:23:55 PST 2007


> mike wrote:
> > from what i can tell from both the API documentation as well as the
> > source of cups/util.c and cups/request.c, cups provides no method of
> > streaming a file to the print server.  i hope that i am merely
> > overlooking something and the cups API is not crippled in this way.
>
> CUPS is not "crippled" this way, but does not provide a convenience
> API to handle streamed printing.  File a feature request with the
> kind of API you'd like to see...

i didn't say cups was, i said its API was ;)

> If you look at the cupsDoFileRequest code in cups/request.c, you'll
> see how to use the lower-level HTTP and IPP APIs to stream your
> content to the CUPS server.

i did look at that.  quite a bit of hairy code of which i know nothing about.  i'm currently mucking around in cups/util.c, writing a cupsPrintStream.  there are a few different convenience functions that could be added, all variants of a streaming ideology.

i see _cupsGlobals for returning the default http connection.  cupsPrintFile() is a convenience wrapper around cupsPrintFiles() and cupsPrintFiles2().  should convenience functions for printing streams allow overriding *http?

rough draft:

int                                          /* O - Job ID */
cupsPrintStream(http_t        *http,         /* I - HTTP connection */
                const char    *name,         /* I - Printer/class name*/
                char          *buf,          /* I - buffer */
                int           len,           /* I - buffer length */
                int           (*fp)(void *), /* I - function pointer */
                const char    *title,        /* I - Title of job */
                int           num_options,   /* I - Number of options */
                cups_option_t *options)      /* I - Options */

this one could have two operating modes: direct and loop.  with direct, you pass buf, len is > 0, and fp is NULL.  it just takes the buffer and runs with it.  in the other mode, fp is not NULL and len is ignored.  fp() is repeatedly called until it returns 0 (or -1, indicating error), accumulating the contents of buf into its own buffer by using the return value as the indication of number of bytes in the buffer to pull.

int                                    /* O - Job ID */
cupsPrintFd(http_t        *http,       /* I - HTTP connection */
            const char    *name,       /* I - Printer or class name */
            int           fd,          /* I - File descriptor */
            const char    *title,      /* I - Title of job */
            int           num_options, /* I - Number of options */
            cups_option_t *options)    /* I - Options */

this function would simply continue reading fd until EOF by wrapping cupsPrintStream.

if this sounds acceptable, i'll go ahead and write the code and submit a patch.

> > if i can pipe to lpr, i should be able to able to stream content to
> > cups for printing.
>
> lpr (and lp) copy to a temporary file and then send the file.

that's what i was afraid of.

-mike





More information about the cups-devel mailing list