diff --git a/Makefile.am b/Makefile.am index b33808691..f5c060e53 100644 --- a/Makefile.am +++ b/Makefile.am @@ -167,6 +167,8 @@ libcupsfilters_la_SOURCES = \ cupsfilters/imagetopdf.c \ cupsfilters/imagetoraster.c \ cupsfilters/ipp.c \ + cupsfilters/libcups2.c \ + cupsfilters/libcups2-private.h \ cupsfilters/lut.c \ cupsfilters/mupdftopwg.c \ cupsfilters/pack.c \ @@ -234,7 +236,7 @@ libcupsfilters_la_LDFLAGS = \ -version-info 2 if BUILD_DBUS libcupsfilters_la_CFLAGS += $(DBUS_CFLAGS) -DHAVE_DBUS -libcupsfilters_CXXFLAGS = -std=c++0x $(libcupsfilters_CFLAGS) # -std=c++11 +libcupsfilters_la_CXXFLAGS = -std=c++11 $(libcupsfilters_la_CFLAGS) # -std=c++11 libcupsfilters_la_LIBADD += $(DBUS_LIBS) endif diff --git a/configure.ac b/configure.ac index bdba43dc5..7288e3de2 100644 --- a/configure.ac +++ b/configure.ac @@ -59,52 +59,102 @@ AC_PROG_INSTALL AC_PROG_LN_S AC_PROG_MAKE_SET LT_INIT + +# ========== +# pkg-config +# ========== PKG_PROG_PKG_CONFIG([0.20]) +AC_PATH_TOOL([PKGCONFIG], [pkg-config]) AM_GNU_GETTEXT_VERSION([0.18.3]) AM_GNU_GETTEXT([external]) -# ================================ -# Find CUPS internals (no pc file) -# ================================ -AC_ARG_WITH([cups-config], - [AS_HELP_STRING([--with-cups-config=path], [Specify path to cups-config executable.])], - [with_cups_config="$withval"], - [with_cups_config=system] -) - -AS_IF([test "x$with_cups_config" != "xsystem"], [ - CUPSCONFIG=$with_cups_config +# ==== +# CUPS +# ==== +AC_MSG_CHECKING([for CUPS library v3.0 or higher]) +AS_IF([$PKGCONFIG --exists cups3], [ + CUPS_VERSION="$($PKGCONFIG --modversion cups3)" + AC_MSG_RESULT([yes, v$CUPS_VERSION]) + + CUPS_CFLAGS="$($PKGCONFIG --cflags cups3)" + CUPS_LIBS="$LIBS $($PKGCONFIG --libs cups3)" + AC_SUBST(CUPS_CFLAGS) + AC_SUBST(CUPS_LIBS) + + CUPS_DATADIR="$($PKGCONFIG --variable=prefix cups3)/share/cups" + AC_DEFINE_UNQUOTED(CUPS_DATADIR, "$CUPS_DATADIR", [CUPS datadir]) + AC_SUBST(CUPS_DATADIR) + + AS_IF([test x$host_os_name = xdarwin], [ + CUPS_SERVERROOT="/private/etc/cups" + ], [ + AS_IF([test "x$($PKGCONFIG --variable=prefix cups3)" = x/usr], [ + CUPS_SERVERROOT="/etc/cups" + ], [ + CUPS_SERVERROOT="$($PKGCONFIG --variable=prefix cups3)/etc/cups" + ]) + ]) + AC_DEFINE_UNQUOTED(CUPS_SERVERROOT, "$CUPS_SERVERROOT", [CUPS serverroot]) + AC_SUBST(CUPS_SERVERROOT) + + CUPS_FONTPATH="$CUPS_DATADIR/fonts" + AC_DEFINE_UNQUOTED(CUPS_FONTPATH, "$CUPS_FONTPATH", + [Path to CUPS fonts dir]) + AC_SUBST(CUPS_FONTPATH) + + CUPS_SERVERBIN="$($PKGCONFIG --variable=prefix cups3)/lib/cups" + AC_DEFINE_UNQUOTED(CUPS_SERVERBIN, "$CUPS_SERVERBIN", + [Path to CUPS binaries dir]) + AC_SUBST(CUPS_SERVERBIN) ], [ + AC_MSG_RESULT(no) + AC_ARG_WITH([cups-config], + [AS_HELP_STRING([--with-cups-config=path], [Specify path to cups-config executable.])], + [with_cups_config="$withval"], + [with_cups_config=system]) + AS_IF([test "x$with_cups_config" != "xsystem"], [ + CUPSCONFIG=$with_cups_config + ], [ AC_PATH_TOOL(CUPSCONFIG, [cups-config]) - AS_IF([test -z "$CUPSCONFIG"], [ - AC_MSG_ERROR([Required cups-config is missing. Please install CUPS developer packages.]) - ]) + ]) + AC_MSG_CHECKING([for CUPS library v2.x]) + AS_IF([test -n "$CUPSCONFIG"], [ + CUPS_VERSION=`$CUPSCONFIG --version` + AC_MSG_RESULT([yes, v$CUPS_VERSION]) + + AC_DEFINE([HAVE_LIBCUPS2], [1], [Use libcups2]) + + CUPS_CFLAGS=`$CUPSCONFIG --cflags` + CUPS_LIBS=`$CUPSCONFIG --image --libs` + AC_SUBST(CUPS_CFLAGS) + AC_SUBST(CUPS_LIBS) + + CUPS_DATADIR="`$CUPSCONFIG --datadir`" + AC_DEFINE_UNQUOTED(CUPS_DATADIR, "$CUPS_DATADIR", [CUPS datadir]) + AC_SUBST(CUPS_DATADIR) + + CUPS_SERVERROOT="`$CUPSCONFIG --serverroot`" + AC_DEFINE_UNQUOTED(CUPS_SERVERROOT, "$CUPS_SERVERROOT", + [CUPS serverroot]) + AC_SUBST(CUPS_SERVERROOT) + + CUPS_FONTPATH="$CUPS_DATADIR/fonts" + AC_DEFINE_UNQUOTED(CUPS_FONTPATH, "$CUPS_FONTPATH", + [Path to CUPS fonts dir]) + AC_SUBST(CUPS_FONTPATH) + + CUPS_SERVERBIN="`$CUPSCONFIG --serverbin`" + AC_DEFINE_UNQUOTED(CUPS_SERVERBIN, "$CUPS_SERVERBIN", + [Path to CUPS binaries dir]) + AC_SUBST(CUPS_SERVERBIN) + ], [ + AC_MSG_RESULT(no) + AC_MSG_ERROR([Required cups-config is missing. Please install CUPS developer packages.]) + ]) ]) -CUPS_CFLAGS=`$CUPSCONFIG --cflags` -CUPS_LIBS=`$CUPSCONFIG --image --libs` -CUPS_VERSION=`$CUPSCONFIG --version` -AC_SUBST(CUPS_CFLAGS) -AC_SUBST(CUPS_LIBS) - -CUPS_DATADIR="`$CUPSCONFIG --datadir`" -AC_DEFINE_UNQUOTED(CUPS_DATADIR, "$CUPS_DATADIR", [CUPS datadir]) -AC_SUBST(CUPS_DATADIR) -CUPS_SERVERROOT="`$CUPSCONFIG --serverroot`" -AC_DEFINE_UNQUOTED(CUPS_SERVERROOT, "$CUPS_SERVERROOT", [CUPS serverroot]) -AC_SUBST(CUPS_SERVERROOT) - -CUPS_FONTPATH="$CUPS_DATADIR/fonts" -AC_DEFINE_UNQUOTED(CUPS_FONTPATH, "$CUPS_FONTPATH", [Path to CUPS fonts dir]) -AC_SUBST(CUPS_FONTPATH) - -CUPS_SERVERBIN="`$CUPSCONFIG --serverbin`" -AC_DEFINE_UNQUOTED(CUPS_SERVERBIN, "$CUPS_SERVERBIN", [Path to CUPS binaries dir]) -AC_SUBST(CUPS_SERVERBIN) - -AC_DEFINE(PDFTOPDF, [1], [Needed for pdftopdf filter compilation]) -AC_DEFINE_DIR(BANNERTOPDF_DATADIR, "{CUPS_DATADIR}/data", [Directory where bannertopdf finds its data files (PDF templates)]) +AC_DEFINE_UNQUOTED(CUPS_SERVERROOT, "$CUPS_SERVERROOT", [Location of CUPS config files]) # Transient run-time state dir of CUPS CUPS_STATEDIR="" @@ -372,6 +422,12 @@ AS_IF([test "x$with_ippfind_path" != "xsystem"], [ ]) AC_DEFINE_UNQUOTED([CUPS_IPPFIND], "$CUPS_IPPFIND", [ippfind binary to use.]) +# ====================================== +# Further needs for the filter functions +# ====================================== +AC_DEFINE(PDFTOPDF, [1], [Needed for pdftopdf filter compilation]) +AC_DEFINE_DIR(BANNERTOPDF_DATADIR, "{CUPS_DATADIR}/data", [Directory where bannertopdf finds its data files (PDF templates)]) + # ========= # Test Font # ========= @@ -427,6 +483,7 @@ Environment settings: CXXFLAGS: ${CXXFLAGS} LDFLAGS: ${LDFLAGS} Build configuration: + libcups: ${CUPS_VERSION} cups-config: ${with_cups_config} poppler: ${enable_poppler} ghostscript: ${enable_ghostscript} diff --git a/cupsfilters/bannertopdf.c b/cupsfilters/bannertopdf.c index 9510f3eb1..eb9020d60 100644 --- a/cupsfilters/bannertopdf.c +++ b/cupsfilters/bannertopdf.c @@ -13,9 +13,11 @@ #include #include #include -#include "ipp.h" -#include "ipp.h" -#include "raster.h" +#include +#include +#include +#include +#include #ifndef HAVE_OPEN_MEMSTREAM #include @@ -26,8 +28,6 @@ #include #include -#include "filter.h" -#include "pdf.h" typedef enum banner_info_e { @@ -914,7 +914,7 @@ cfFilterBannerToPDF(int inputfd, // I - File descriptor input stream // Copy the input data stream into a temporary file... // - if ((tempfd = cupsTempFd(tempfile, sizeof(tempfile))) < 0) + if ((tempfd = cupsCreateTempFd(NULL, NULL, tempfile, sizeof(tempfile))) < 0) { if (log) log(ld, CF_LOGLEVEL_ERROR, "cfFilterBannerToPDF: Unable to copy input file: %s", diff --git a/cupsfilters/catalog.c b/cupsfilters/catalog.c index 01676e66f..439bc18c3 100644 --- a/cupsfilters/catalog.c +++ b/cupsfilters/catalog.c @@ -23,6 +23,7 @@ #include #include #include +#include int // O - 1 on success, 0 on failure @@ -52,12 +53,12 @@ cfGetURI(const char *url, // I - URL to get else encryption = HTTP_ENCRYPTION_IF_REQUESTED; - http = httpConnect2(host, port, NULL, AF_UNSPEC, encryption, 1, 5000, NULL); + http = httpConnect(host, port, NULL, AF_UNSPEC, encryption, 1, 5000, NULL); if (!http) return (0); - if ((fd = cupsTempFd(name, (int)namesize)) < 0) + if ((fd = cupsCreateTempFd(NULL, NULL, name, (int)namesize)) < 0) return (0); status = cupsGetFd(http, resource, fd); @@ -366,7 +367,7 @@ cfCatalogFreeOptionStrings(void* entry, cups_array_t * cfCatalogOptionArrayNew() { - return (cupsArrayNew3(compare_options, NULL, NULL, 0, + return (cupsArrayNew(compare_options, NULL, NULL, 0, NULL, cfCatalogFreeOptionStrings)); } @@ -415,7 +416,7 @@ cfCatalogAddOption(char *name, if (!opt) return (NULL); opt->human_readable = NULL; - opt->choices = cupsArrayNew3(compare_choices, NULL, NULL, 0, + opt->choices = cupsArrayNew(compare_choices, NULL, NULL, 0, NULL, cfCatalogFreeChoiceStrings); if (!opt->choices) { diff --git a/cupsfilters/filter.c b/cupsfilters/filter.c index ed5bdbbf4..a54470404 100644 --- a/cupsfilters/filter.c +++ b/cupsfilters/filter.c @@ -21,6 +21,8 @@ #include #include #include +#include + extern char **environ; @@ -128,9 +130,9 @@ get_filter_data_ext_entry(cups_array_t *ext_array, if (!ext_array || !name) return (NULL); - for (entry = (cf_filter_data_ext_t *)cupsArrayFirst(ext_array); + for (entry = (cf_filter_data_ext_t *)cupsArrayGetFirst(ext_array); entry; - entry = (cf_filter_data_ext_t *)cupsArrayNext(ext_array)) + entry = (cf_filter_data_ext_t *)cupsArrayGetNext(ext_array)) if (strcmp(entry->name, name) == 0) break; @@ -157,7 +159,7 @@ cfFilterDataAddExt(cf_filter_data_t *data, // I - Filter data record return (NULL); if (data->extension == NULL) - data->extension = cupsArrayNew(NULL, NULL); + data->extension = cupsArrayNew(NULL, NULL, NULL, 0, NULL, NULL); if (data->extension == NULL) return (NULL); @@ -214,7 +216,7 @@ cfFilterDataRemoveExt(cf_filter_data_t *data, cupsArrayRemove(data->extension, entry); free(entry->name); free(entry); - if (cupsArrayCount(data->extension) == 0) + if (cupsArrayGetCount(data->extension) == 0) { cupsArrayDelete(data->extension); data->extension = NULL; @@ -649,9 +651,9 @@ cfFilterChain(int inputfd, // I - File descriptor input stream // Remove NULL filters... // - for (filter = (cf_filter_filter_in_chain_t *)cupsArrayFirst(filter_chain); + for (filter = (cf_filter_filter_in_chain_t *)cupsArrayGetFirst(filter_chain); filter; - filter = (cf_filter_filter_in_chain_t *)cupsArrayNext(filter_chain)) + filter = (cf_filter_filter_in_chain_t *)cupsArrayGetNext(filter_chain)) { if (!filter->function) { @@ -670,7 +672,7 @@ cfFilterChain(int inputfd, // I - File descriptor input stream // Empty filter chain -> Pass through the data unchanged // - if (cupsArrayCount(filter_chain) == 0) + if (cupsArrayGetCount(filter_chain) == 0) { if (log) log(ld, CF_LOGLEVEL_INFO, "cfFilterChain: No filter at all in chain, passing through the data."); @@ -698,18 +700,19 @@ cfFilterChain(int inputfd, // I - File descriptor input stream // Execute all of the filters... // - pids = cupsArrayNew((cups_array_func_t)compare_filter_pids, NULL); + pids = cupsArrayNew((cups_array_cb_t)compare_filter_pids, NULL, + NULL, 0, NULL, NULL); current = 0; filterfds[0][0] = inputfd; filterfds[0][1] = -1; filterfds[1][0] = -1; filterfds[1][1] = -1; - for (filter = (cf_filter_filter_in_chain_t *)cupsArrayFirst(filter_chain); + for (filter = (cf_filter_filter_in_chain_t *)cupsArrayGetFirst(filter_chain); filter; filter = next, current = 1 - current) { - next = (cf_filter_filter_in_chain_t *)cupsArrayNext(filter_chain); + next = (cf_filter_filter_in_chain_t *)cupsArrayGetNext(filter_chain); if (filterfds[1 - current][0] > 1) { @@ -816,7 +819,7 @@ cfFilterChain(int inputfd, // I - File descriptor input stream retval = 0; - while (cupsArrayCount(pids) > 0) + while (cupsArrayGetCount(pids) > 0) { if ((pid = wait(&status)) < 0) { @@ -824,9 +827,9 @@ cfFilterChain(int inputfd, // I - File descriptor input stream { if (log) log(ld, CF_LOGLEVEL_DEBUG, "cfFilterChain: Job canceled, killing filters ..."); - for (pid_entry = (filter_function_pid_t *)cupsArrayFirst(pids); + for (pid_entry = (filter_function_pid_t *)cupsArrayGetFirst(pids); pid_entry; - pid_entry = (filter_function_pid_t *)cupsArrayNext(pids)) + pid_entry = (filter_function_pid_t *)cupsArrayGetNext(pids)) { kill(pid_entry->pid, SIGTERM); free(pid_entry); @@ -1102,7 +1105,7 @@ cfFilterExternal(int inputfd, // I - File descriptor input stream // argument, not via stdin argv = (char **)calloc(8, sizeof(char *)); - fd = cupsTempFd(tmp_name, sizeof(tmp_name)); + fd = cupsCreateTempFd(NULL, NULL, tmp_name, sizeof(tmp_name)); if (fd < 0) { if (log) log(ld, CF_LOGLEVEL_ERROR, diff --git a/cupsfilters/filter.h b/cupsfilters/filter.h index 6476dc393..c9a66923f 100644 --- a/cupsfilters/filter.h +++ b/cupsfilters/filter.h @@ -37,6 +37,15 @@ extern "C" { # include +// +// Renamed CUPS type in API +// + +# if CUPS_VERSION_MAJOR < 3 +# define cups_page_header_t cups_page_header2_t +# endif + + // // Types and structures... // @@ -58,7 +67,7 @@ typedef struct cf_filter_data_s ipp_t *job_attrs; // IPP attributes passed along with the job ipp_t *printer_attrs; // Printer capabilities in IPP format // (what is answered to get-printer-attributes - cups_page_header2_t *header; + cups_page_header_t *header; // CUPS/PWG Raster header (optional) int num_options; cups_option_t *options; // Job options as key/value pairs diff --git a/cupsfilters/ghostscript.c b/cupsfilters/ghostscript.c index 9f16290a1..1f8c21362 100644 --- a/cupsfilters/ghostscript.c +++ b/cupsfilters/ghostscript.c @@ -24,12 +24,13 @@ #include #include #include +#include +#include +#include #include #include #include #include -#include "filter.h" -#include "pdf.h" #define PDF_MAX_CHECK_COMMENT_LINES 20 @@ -41,11 +42,7 @@ typedef enum gs_doc_e GS_DOC_TYPE_UNKNOWN } gs_doc_t; -#ifdef CUPS_RASTER_SYNCv1 -typedef cups_page_header2_t gs_page_header; -#else typedef cups_page_header_t gs_page_header; -#endif // CUPS_RASTER_SYNCv1 static gs_doc_t parse_doc_type(FILE *fp) @@ -459,10 +456,10 @@ gs_spawn (const char *filename, // Put Ghostscript command line argument into an array for the "exec()" // call - numargs = cupsArrayCount(gs_args); + numargs = cupsArrayGetCount(gs_args); gsargv = calloc(numargs + 1, sizeof(char *)); - for (argument = (char *)cupsArrayFirst(gs_args), i = 0; argument; - argument = (char *)cupsArrayNext(gs_args), i++) + for (argument = (char *)cupsArrayGetFirst(gs_args), i = 0; argument; + argument = (char *)cupsArrayGetNext(gs_args), i++) gsargv[i] = argument; gsargv[i] = NULL; @@ -938,7 +935,7 @@ cfFilterGhostscript(int inputfd, // I - File descriptor input if (!inputseekable || doc_type == GS_DOC_TYPE_PS) { - if ((fd = cupsTempFd(tempfile, sizeof(tempfile))) < 0) + if ((fd = cupsCreateTempFd(NULL, NULL, tempfile, sizeof(tempfile))) < 0) { if (log) log(ld, CF_LOGLEVEL_ERROR, "cfFilterGhostscript: Unable to copy PDF file: %s", @@ -1090,7 +1087,7 @@ cfFilterGhostscript(int inputfd, // I - File descriptor input } // Ghostscript parameters - gs_args = cupsArrayNew(NULL, NULL); + gs_args = cupsArrayNew(NULL, NULL, NULL, 0, NULL, NULL); if (!gs_args) { if (log) log(ld, CF_LOGLEVEL_ERROR, @@ -1685,7 +1682,7 @@ cfFilterGhostscript(int inputfd, // I - File descriptor input unlink(filename); if (gs_args) { - while ((tmp = cupsArrayFirst(gs_args)) != NULL) + while ((tmp = cupsArrayGetFirst(gs_args)) != NULL) { cupsArrayRemove(gs_args, tmp); free(tmp); diff --git a/cupsfilters/image-private.h b/cupsfilters/image-private.h index 97337d279..6a2e798b4 100644 --- a/cupsfilters/image-private.h +++ b/cupsfilters/image-private.h @@ -18,7 +18,9 @@ // # include -# include "image.h" + +# include +# include # include # define DEBUG_printf(x) # define DEBUG_puts(x) diff --git a/cupsfilters/image.c b/cupsfilters/image.c index 6337f00b7..1ba0d5e67 100644 --- a/cupsfilters/image.c +++ b/cupsfilters/image.c @@ -685,7 +685,7 @@ flush_tile(cf_image_t *img) // I - Image if (img->cachefile < 0) { - if ((img->cachefile = cupsTempFd(img->cachename, + if ((img->cachefile = cupsCreateTempFd(NULL, NULL, img->cachename, sizeof(img->cachename))) < 0) { tile->ic = NULL; diff --git a/cupsfilters/imagetopdf.c b/cupsfilters/imagetopdf.c index 7871d8daf..3ad72c433 100644 --- a/cupsfilters/imagetopdf.c +++ b/cupsfilters/imagetopdf.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -589,7 +590,7 @@ cfFilterImageToPDF(int inputfd, // I - File descriptor input stream // (unused) { imagetopdf_doc_t doc; // Document information - cups_page_header2_t h; // CUPS Raster page header, to + cups_page_header_t h; // CUPS Raster page header, to // accommodate results of command // line and IPP parsing int num_options = 0; // Number of print options @@ -677,7 +678,7 @@ cfFilterImageToPDF(int inputfd, // I - File descriptor input stream if (!inputseekable) { - if ((fd = cupsTempFd(tempfile, sizeof(tempfile))) < 0) + if ((fd = cupsCreateTempFd(NULL, NULL, tempfile, sizeof(tempfile))) < 0) { if (log) log(ld, CF_LOGLEVEL_ERROR, "cfFilterImageToPDF: Unable to copy input: %s", diff --git a/cupsfilters/imagetoraster.c b/cupsfilters/imagetoraster.c index fb7f57e42..0cb94506d 100644 --- a/cupsfilters/imagetoraster.c +++ b/cupsfilters/imagetoraster.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -131,42 +132,42 @@ int Floyd4x4[4][4] = // Local functions... // -static void blank_line(cups_page_header2_t *header, unsigned char *row); +static void blank_line(cups_page_header_t *header, unsigned char *row); static void format_cmy(imagetoraster_doc_t *doc, - cups_page_header2_t *header, unsigned char *row, + cups_page_header_t *header, unsigned char *row, int y, int z, int xsize, int ysize, int yerr0, int yerr1, cf_ib_t *r0, cf_ib_t *r1); static void format_cmyk(imagetoraster_doc_t *doc, - cups_page_header2_t *header, unsigned char *row, + cups_page_header_t *header, unsigned char *row, int y, int z, int xsize, int ysize, int yerr0, int yerr1, cf_ib_t *r0, cf_ib_t *r1); static void format_K(imagetoraster_doc_t *doc, - cups_page_header2_t *header, unsigned char *row, + cups_page_header_t *header, unsigned char *row, int y, int z, int xsize, int ysize, int yerr0, int yerr1, cf_ib_t *r0, cf_ib_t *r1); static void format_kcmycm(imagetoraster_doc_t *doc, - cups_page_header2_t *header, unsigned char *row, + cups_page_header_t *header, unsigned char *row, int y, int z, int xsize, int ysize, int yerr0, int yerr1, cf_ib_t *r0, cf_ib_t *r1); static void format_kcmy(imagetoraster_doc_t *doc, - cups_page_header2_t *header, unsigned char *row, + cups_page_header_t *header, unsigned char *row, int y, int z, int xsize, int ysize, int yerr0, int yerr1, cf_ib_t *r0, cf_ib_t *r1); #define format_RGB format_cmy static void format_rgba(imagetoraster_doc_t *doc, - cups_page_header2_t *header, unsigned char *row, + cups_page_header_t *header, unsigned char *row, int y, int z, int xsize, int ysize, int yerr0, int yerr1, cf_ib_t *r0, cf_ib_t *r1); static void format_w(imagetoraster_doc_t *doc, - cups_page_header2_t *header, unsigned char *row, + cups_page_header_t *header, unsigned char *row, int y, int z, int xsize, int ysize, int yerr0, int yerr1, cf_ib_t *r0, cf_ib_t *r1); static void format_ymc(imagetoraster_doc_t *doc, - cups_page_header2_t *header, unsigned char *row, + cups_page_header_t *header, unsigned char *row, int y, int z, int xsize, int ysize, int yerr0, int yerr1, cf_ib_t *r0, cf_ib_t *r1); static void format_ymck(imagetoraster_doc_t *doc, - cups_page_header2_t *header, unsigned char *row, + cups_page_header_t *header, unsigned char *row, int y, int z, int xsize, int ysize, int yerr0, int yerr1, cf_ib_t *r0, cf_ib_t *r1); static void make_lut(cf_ib_t *, int, float, float); @@ -210,7 +211,7 @@ cfFilterImageToRaster(int inputfd, // I - File descriptor input stream xc1, yc1; cups_cspace_t cspace = -1; // CUPS color space cups_raster_t *ras; // Raster stream - cups_page_header2_t header; // Page header + cups_page_header_t header; // Page header int num_options = 0;// Number of print options cups_option_t *options = NULL;// Print options const char *val; // Option value @@ -360,7 +361,7 @@ cfFilterImageToRaster(int inputfd, // I - File descriptor input stream if (!inputseekable) { - if ((fd = cupsTempFd(tempfile, sizeof(tempfile))) < 0) + if ((fd = cupsCreateTempFd(NULL, NULL, tempfile, sizeof(tempfile))) < 0) { if (log) log(ld, CF_LOGLEVEL_ERROR, "cfFilterImageToRaster: Unable to copy input: %s", @@ -1666,7 +1667,7 @@ cfFilterImageToRaster(int inputfd, // I - File descriptor input stream ytemp = header.HWResolution[1] * yprint; } - cupsRasterWriteHeader2(ras, &header); + cupsRasterWriteHeader(ras, &header); for (plane = 0; plane < num_planes; plane ++) { @@ -1879,7 +1880,7 @@ cfFilterImageToRaster(int inputfd, // I - File descriptor input stream // static void -blank_line(cups_page_header2_t *header, // I - Page header +blank_line(cups_page_header_t *header, // I - Page header unsigned char *row) // I - Row buffer { int count; // Remaining bytes @@ -1952,7 +1953,7 @@ blank_line(cups_page_header2_t *header, // I - Page header static void format_cmy(imagetoraster_doc_t *doc, - cups_page_header2_t *header, // I - Page header + cups_page_header_t *header, // I - Page header unsigned char *row, // IO - Bitmap data for device int y, // I - Current row int z, // I - Current plane @@ -2397,7 +2398,7 @@ format_cmy(imagetoraster_doc_t *doc, static void format_cmyk(imagetoraster_doc_t *doc, - cups_page_header2_t *header,// I - Page header + cups_page_header_t *header,// I - Page header unsigned char *row, // IO - Bitmap data for device int y, // I - Current row int z, // I - Current plane @@ -2873,7 +2874,7 @@ format_cmyk(imagetoraster_doc_t *doc, static void format_K(imagetoraster_doc_t *doc, - cups_page_header2_t *header, // I - Page header + cups_page_header_t *header, // I - Page header unsigned char *row, // IO - Bitmap data for device int y, // I - Current row int z, // I - Current plane @@ -3009,7 +3010,7 @@ format_K(imagetoraster_doc_t *doc, static void format_kcmy(imagetoraster_doc_t *doc, - cups_page_header2_t *header,// I - Page header + cups_page_header_t *header,// I - Page header unsigned char *row, // IO - Bitmap data for device int y, // I - Current row int z, // I - Current plane @@ -3557,7 +3558,7 @@ format_kcmy(imagetoraster_doc_t *doc, static void format_kcmycm( imagetoraster_doc_t *doc, - cups_page_header2_t *header, // I - Page header + cups_page_header_t *header, // I - Page header unsigned char *row, // IO - Bitmap data for device int y, // I - Current row int z, // I - Current plane @@ -3734,7 +3735,7 @@ format_kcmycm( static void format_rgba(imagetoraster_doc_t *doc, - cups_page_header2_t *header,// I - Page header + cups_page_header_t *header,// I - Page header unsigned char *row, // IO - Bitmap data for device int y, // I - Current row int z, // I - Current plane @@ -4229,7 +4230,7 @@ format_rgba(imagetoraster_doc_t *doc, static void format_w(imagetoraster_doc_t *doc, - cups_page_header2_t *header, // I - Page header + cups_page_header_t *header, // I - Page header unsigned char *row, // IO - Bitmap data for device int y, // I - Current row int z, // I - Current plane @@ -4365,7 +4366,7 @@ format_w(imagetoraster_doc_t *doc, static void format_ymc(imagetoraster_doc_t *doc, - cups_page_header2_t *header, // I - Page header + cups_page_header_t *header, // I - Page header unsigned char *row, // IO - Bitmap data for device int y, // I - Current row int z, // I - Current plane @@ -4848,7 +4849,7 @@ format_ymc(imagetoraster_doc_t *doc, static void format_ymck(imagetoraster_doc_t *doc, - cups_page_header2_t *header,// I - Page header + cups_page_header_t *header,// I - Page header unsigned char *row, // IO - Bitmap data for device int y, // I - Current row int z, // I - Current plane diff --git a/cupsfilters/ipp.c b/cupsfilters/ipp.c index 34c763a77..8d6a9b3d9 100644 --- a/cupsfilters/ipp.c +++ b/cupsfilters/ipp.c @@ -25,26 +25,34 @@ #include #include #include -#include #include #include #include #include +#include #include #include +#include -char cf_get_printer_attributes_log[CF_GET_PRINTER_ATTRIBUTES_LOGSIZE]; - -static int -convert_to_port(char *a) +typedef struct cf_size_s // **** Media Size (cups_size_t of libcups2) **** { - int port = 0; - for (int i = 0; i < strlen(a); i ++) - port = port*10 + (a[i] - '0'); + char media[128]; // Media name to use + int width, // Width in hundredths of millimeters + length, // Length in hundredths of + // millimeters + bottom, // Bottom margin in hundredths of + // millimeters + left, // Left margin in hundredths of + // millimeters + right, // Right margin in hundredths of + // millimeters + top; // Top margin in hundredths of + // millimeters +} cf_size_t; - return (port); -} + +char cf_get_printer_attributes_log[CF_GET_PRINTER_ATTRIBUTES_LOGSIZE]; static void log_printf(char *log, @@ -62,63 +70,7 @@ log_printf(char *log, char * cfResolveURI(const char *raw_uri) { - char *pseudo_argv[2]; - const char *uri; - int fd1, fd2; - char *save_device_uri_var, *save_ppd_var; - - // Eliminate any output to stderr, to get rid of the CUPS-backend-specific - // output of the cupsBackendDeviceURI() function - fd1 = dup(2); - fd2 = open("/dev/null", O_WRONLY); - dup2(fd2, 2); - close(fd2); - - // If set, save the DEVICE_URI environment and then unset it, so that - // if we are running under CUPS (as filter or backend) our raw_uri gets - // resolved and not whatever URI is set in DEVICE_URI - if ((save_device_uri_var = getenv("DEVICE_URI")) != NULL) - { - save_device_uri_var = strdup(save_device_uri_var); - unsetenv("DEVICE_URI"); - } - - // Same for PPD, to make the cupsBackendDeviceURI() call in this - // function not do uncontrolled switches between print and fax URI - // dependent on the PPD file the variable is pointing to. This makes - // this function always return the print URI, to make the libcups2 - // and libcups3 builds of libcupsfilters behave the same. - if ((save_ppd_var = getenv("PPD")) != NULL) - { - save_ppd_var = strdup(save_ppd_var); - unsetenv("PPD"); - } - - // Use the URI resolver of libcups to support DNS-SD-service-name-based - // URIs. The function returns the corresponding host-name-based URI - pseudo_argv[0] = (char *)raw_uri; - pseudo_argv[1] = NULL; - uri = cupsBackendDeviceURI(pseudo_argv); - - // Restore DEVICE_URI environment variable if we had unset it - if (save_device_uri_var) - { - setenv("DEVICE_URI", save_device_uri_var, 1); - free(save_device_uri_var); - } - - // Restore PPD environment variable if we had unset it - if (save_ppd_var) - { - setenv("PPD", save_ppd_var, 1); - free(save_ppd_var); - } - - // Re-activate stderr output - dup2(fd1, 2); - close(fd1); - - return (uri ? strdup(uri) : NULL); + return (cfResolveURI2(raw_uri, 0)); } // Check how the driverless support is provided @@ -182,8 +134,8 @@ cfGetPrinterAttributes3(http_t *http_printer, driverless_info, 0)); } -// Get attributes of a printer or fax specified only by URI and given -// info about fax-support +// Get attributes of a printer specified only by URI and given info about +// fax-support ipp_t *cfGetPrinterAttributes4(const char* raw_uri, const char* const pattrs[], int pattrs_size, @@ -197,9 +149,9 @@ ipp_t *cfGetPrinterAttributes4(const char* raw_uri, is_fax)); } -// Get attributes of a printer or fax specified by URI and under a -// given HTTP connection, for example via a domain socket, and give -// info about used fallbacks +// Get attributes of a printer specified by URI and under a given HTTP +// connection, for example via a domain socket, and give info about used +// fallbacks ipp_t * cfGetPrinterAttributes5(http_t *http_printer, const char* raw_uri, @@ -308,8 +260,8 @@ cfGetPrinterAttributes5(http_t *http_printer, { have_http = 0; if ((http_printer = - httpConnect2 (host_name, host_port, NULL, AF_UNSPEC, - encryption, 1, 3000, NULL)) == NULL) + httpConnect(host_name, host_port, NULL, AF_UNSPEC, + encryption, 1, 3000, NULL)) == NULL) { log_printf(cf_get_printer_attributes_log, "get-printer-attributes: Cannot connect to printer with URI %s.\n", @@ -359,7 +311,7 @@ cfGetPrinterAttributes5(http_t *http_printer, NULL, pattrs); response = cupsDoRequest(http_printer, request, resource); - ipp_status = cupsLastError(); + ipp_status = cupsGetError(); if (response) { @@ -370,7 +322,7 @@ cfGetPrinterAttributes5(http_t *http_printer, if (debug) log_printf(cf_get_printer_attributes_log, "Full list of all IPP attributes:\n"); - attr = ippFirstAttribute(response); + attr = ippGetFirstAttribute(response); while (attr) { total_attrs ++; @@ -385,7 +337,7 @@ cfGetPrinterAttributes5(http_t *http_printer, if ((kw = ippGetString(attr, i, NULL)) != NULL) log_printf(cf_get_printer_attributes_log, " Keyword: %s\n", kw); } - attr = ippNextAttribute(response); + attr = ippGetNextAttribute(response); } // Check whether the IPP response contains the required attributes @@ -437,7 +389,7 @@ cfGetPrinterAttributes5(http_t *http_printer, ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "requested-attributes", NULL, "media-col-database"); response2 = cupsDoRequest(http_printer, request, resource); - ipp_status = cupsLastError(); + ipp_status = cupsGetError(); if (response2) { if ((attr = ippFindAttribute(response2, "media-col-database", @@ -461,7 +413,7 @@ cfGetPrinterAttributes5(http_t *http_printer, { log_printf(cf_get_printer_attributes_log, "Request for IPP attributes (get-printer-attributes) for printer with URI %s failed: %s\n", - uri, cupsLastErrorString()); + uri, cupsGetErrorString()); log_printf(cf_get_printer_attributes_log, "get-printer-attributes IPP request failed:\n"); log_printf(cf_get_printer_attributes_log, " - No response\n"); } @@ -493,246 +445,24 @@ cfGetPrinterAttributes5(http_t *http_printer, return (NULL); } + +#ifndef HAVE_LIBCUPS2 char* -cfResolveURI2 (const char *uri, int is_fax) +cfResolveURI2(const char *raw_uri, int is_fax) { - int ippfind_pid = 0, // Process ID of ippfind for IPP - post_proc_pipe[2], // Pipe to post-processing for IPP - wait_children, // Number of child processes left - wait_pid, // Process ID from wait() - wait_status, // Status from child - exit_status = 0, // Exit status - bytes, - port, - i, - output_of_fax_uri = 0, - is_local; - char *ippfind_argv[100], // Arguments for ippfind - *ptr_to_port = NULL, - *reg_type, - *resolved_uri = NULL, // Buffer for resolved URI - *resource_field = NULL, - *service_hostname = NULL, - // URI components... - scheme[32], - userpass[256], - hostname[1024], - resource[1024], - *buffer = NULL, // Copy buffer - *ptr; // Pointer into string; - cups_file_t *fp; // Post-processing input file - int status; // Status of GET request - - status = httpSeparateURI(HTTP_URI_CODING_ALL, uri, scheme, sizeof(scheme), - userpass, sizeof(userpass), - hostname, sizeof(hostname), &port, resource, - sizeof(resource)); - if (status < HTTP_URI_STATUS_OK) - // Invalid URI - goto error; - - // URI is not DNS-SD-based, so do not resolve - if ((reg_type = strstr(hostname, "._tcp")) == NULL) - return (strdup(uri)); - - resolved_uri = - (char *)malloc(CF_GET_PRINTER_ATTRIBUTES_MAX_URI_LEN * (sizeof(char))); - if (resolved_uri == NULL) - goto error; - memset(resolved_uri, 0, CF_GET_PRINTER_ATTRIBUTES_MAX_URI_LEN); - - reg_type --; - while (reg_type >= hostname && *reg_type != '.') - reg_type --; - if (reg_type < hostname) - goto error; - *reg_type++ = '\0'; - - i = 0; - ippfind_argv[i++] = "ippfind"; - ippfind_argv[i++] = reg_type; // list IPP(S) entries - ippfind_argv[i++] = "-T"; // DNS-SD poll timeout - ippfind_argv[i++] = "0"; // Minimum time required - if (is_fax == 1) - { - ippfind_argv[i++] = "--txt"; - ippfind_argv[i++] = "rfo"; - } - ippfind_argv[i++] = "-N"; - ippfind_argv[i++] = hostname; - ippfind_argv[i++] = "-x"; - ippfind_argv[i++] = "echo"; // Output the needed data fields - ippfind_argv[i++] = "-en"; // separated by tab characters - if(is_fax == 1) - ippfind_argv[i++] = "\n{service_hostname}\t{txt_rfo}\t{service_port}\t"; - else - ippfind_argv[i++] = "\n{service_hostname}\t{txt_rp}\t{service_port}\t"; - ippfind_argv[i++] = ";"; - ippfind_argv[i++] = "--local"; // Rest only if local service - ippfind_argv[i++] = "-x"; - ippfind_argv[i++] = "echo"; // Output an 'L' at the end of the - ippfind_argv[i++] = "-en"; // line - ippfind_argv[i++] = "L"; - ippfind_argv[i++] = ";"; - ippfind_argv[i++] = NULL; - - // - // Create a pipe for passing the ippfind output to post-processing - // - - if (pipe(post_proc_pipe)) - goto error; - - if ((ippfind_pid = fork()) == 0) - { - // - // Child comes here... - // - - dup2(post_proc_pipe[1], 1); - close(post_proc_pipe[0]); - close(post_proc_pipe[1]); - - execvp(CUPS_IPPFIND, ippfind_argv); - - exit(1); - } - else if (ippfind_pid < 0) - { - // - // Unable to fork! - // - - goto error; - } - - close(post_proc_pipe[1]); - - fp = cupsFileOpenFd(post_proc_pipe[0], "r"); - - buffer = - (char*)malloc(CF_GET_PRINTER_ATTRIBUTES_MAX_OUTPUT_LEN * sizeof(char)); - if (buffer == NULL) - goto error; - memset(buffer, 0, CF_GET_PRINTER_ATTRIBUTES_MAX_OUTPUT_LEN); - - while ((bytes = - cupsFileGetLine(fp, buffer, - CF_GET_PRINTER_ATTRIBUTES_MAX_OUTPUT_LEN)) > 0) - { - // Mark all the fields of the output of ippfind - ptr = buffer; - - // ignore new lines - if (bytes < 3) - goto read_error; - - // First, build the DNS-SD-service-name-based URI ... - while (ptr && !isalnum(*ptr & 255)) ptr ++; - - service_hostname = ptr; - ptr = memchr(ptr, '\t', - CF_GET_PRINTER_ATTRIBUTES_MAX_OUTPUT_LEN - (ptr - buffer)); - if (!ptr) goto read_error; - *ptr = '\0'; - ptr ++; - - resource_field = ptr; - ptr = memchr(ptr, '\t', - CF_GET_PRINTER_ATTRIBUTES_MAX_OUTPUT_LEN - (ptr - buffer)); - if (!ptr) goto read_error; - *ptr = '\0'; - ptr ++; - - ptr_to_port = ptr; - ptr = memchr(ptr, '\t', - CF_GET_PRINTER_ATTRIBUTES_MAX_OUTPUT_LEN - (ptr - buffer)); - if (!ptr) goto read_error; - *ptr = '\0'; - ptr ++; - - // Do we have a local service so that we have to set the host name to - // "localhost"? - is_local = (*ptr == 'L'); - - ptr = strchr(reg_type, '.'); - if (!ptr) goto read_error; - *ptr = '\0'; - - port = convert_to_port(ptr_to_port); - - httpAssembleURIf(HTTP_URI_CODING_ALL, resolved_uri, - 2047, reg_type + 1, NULL, - (is_local ? "localhost" : service_hostname), port, "/%s", - resource_field); - - if (is_fax == 1) - output_of_fax_uri = 1; // fax-uri requested from fax-capable device - - read_error: - memset(buffer, 0, CF_GET_PRINTER_ATTRIBUTES_MAX_OUTPUT_LEN); - } - - cupsFileClose(fp); - - if (buffer != NULL) - free(buffer); - - // - // Wait for the child processes to exit... - // - - wait_children = 1; - - while (wait_children > 0) - { - // - // Wait until we get a valid process ID or the job is canceled... - // - - while ((wait_pid = wait(&wait_status)) < 0 && errno == EINTR); - - if (wait_pid < 0) - break; - - wait_children --; - - // - // Report child status... - // - - if (wait_status) - { - if (WIFEXITED(wait_status)) - { - exit_status = WEXITSTATUS(wait_status); - if (wait_pid == ippfind_pid && exit_status <= 2) - exit_status = 0; - } - else if (WTERMSIG(wait_status) == SIGTERM) - { - // All OK, no error - } - else - { - exit_status = WTERMSIG(wait_status); - } - } - } - if (is_fax == 1 && !output_of_fax_uri) - goto error; - - return (resolved_uri); + int options = HTTP_RESOLVE_DEFAULT; + const char* auth_info_required = getenv("AUTH_INFO_REQUIRED"); + char buf[1024]; - // - // Exit... - // + if ((auth_info_required) != NULL && !strcmp(auth_info_required, "negotiate")) + {options |= HTTP_RESOLVE_FQDN;} + if (is_fax) + {options |= HTTP_RESOLVE_FAXOUT;} - error: - if (resolved_uri != NULL) - free(resolved_uri); - return (NULL); + return (strdup(httpResolveURI(raw_uri, buf, sizeof(buf), options, NULL, + NULL))); } +#endif // !HAVE_LIBCUPS2 const char* // O - Attribute value as string @@ -972,7 +702,8 @@ cfIPPReverseOutput(ipp_t *printer_attrs, ipp_attribute_t *attr1, *attr2; const char *val1, *val2; char buf[1024]; - int length; + cups_len_t length; + // Figure out the right default output order from the IPP attributes... if ((val1 = cfIPPAttrEnumValForPrinter(printer_attrs, job_attrs, @@ -1276,8 +1007,8 @@ cfJoinJobOptionsAndAttrs(cf_filter_data_t* data, // I - Filter data for (i = 0, opt = data->options; i < data->num_options; i ++, opt ++) num_options = cupsAddOption(opt->name, opt->value, num_options, options); - for (ipp_attr = ippFirstAttribute(job_attrs); ipp_attr; - ipp_attr = ippNextAttribute(job_attrs)) + for (ipp_attr = ippGetFirstAttribute(job_attrs); ipp_attr; + ipp_attr = ippGetNextAttribute(job_attrs)) { ippAttributeString(ipp_attr, buf, sizeof(buf)); num_options = cupsAddOption(ippGetName(ipp_attr), buf, @@ -1456,7 +1187,7 @@ cfFreeResolution(void *resolution, cups_array_t * cfNewResolutionArray() { - return (cupsArrayNew3(cfCompareResolutions, NULL, NULL, 0, + return (cupsArrayNew(cfCompareResolutions, NULL, NULL, 0, cfCopyResolution, cfFreeResolution)); } @@ -1532,7 +1263,7 @@ cfIPPAttrToResolutionArray(ipp_attribute_t *attr) cfFreeResolution(res, NULL); } } - if (cupsArrayCount(res_array) == 0) + if (cupsArrayGetCount(res_array) == 0) { cupsArrayDelete(res_array); res_array = NULL; @@ -1569,7 +1300,7 @@ cfJoinResolutionArrays(cups_array_t **current, int retval; if (current == NULL || new_arr == NULL || *new_arr == NULL || - cupsArrayCount(*new_arr) == 0) + cupsArrayGetCount(*new_arr) == 0) { retval = 0; goto finish; @@ -1588,7 +1319,7 @@ cfJoinResolutionArrays(cups_array_t **current, } return 1; } - else if (cupsArrayCount(*current) == 0) + else if (cupsArrayGetCount(*current) == 0) { retval = 1; goto finish; @@ -1596,8 +1327,8 @@ cfJoinResolutionArrays(cups_array_t **current, // Dry run: Check whether the two arrays have at least one resolution // in common, if not, do not touch the original array - for (res = cupsArrayFirst(*current); - res; res = cupsArrayNext(*current)) + for (res = cupsArrayGetFirst(*current); + res; res = cupsArrayGetNext(*current)) if (cupsArrayFind(*new_arr, res)) break; @@ -1606,8 +1337,8 @@ cfJoinResolutionArrays(cups_array_t **current, // Reduce the original array to the resolutions which are in both // the original and the new array, at least one resolution will // remain. - for (res = cupsArrayFirst(*current); - res; res = cupsArrayNext(*current)) + for (res = cupsArrayGetFirst(*current); + res; res = cupsArrayGetNext(*current)) if (!cupsArrayFind(*new_arr, res)) cupsArrayRemove(*current, res); if (current_default) @@ -1651,8 +1382,8 @@ cfJoinResolutionArrays(cups_array_t **current, // static int // O - Result of comparison -pwg_compare_sizes(cups_size_t *a, // I - First media size - cups_size_t *b) // I - Second media size +pwg_compare_sizes(cf_size_t *a, // I - First media size + cf_size_t *b) // I - Second media size { return (strcmp(a->media, b->media)); } @@ -1662,14 +1393,14 @@ pwg_compare_sizes(cups_size_t *a, // I - First media size // 'pwg_copy_size()' - Copy a media size. // -static cups_size_t * // O - New media size -pwg_copy_size(cups_size_t *size) // I - Media size to copy +static cf_size_t * // O - New media size +pwg_copy_size(cf_size_t *size) // I - Media size to copy { - cups_size_t *newsize = (cups_size_t *)calloc(1, sizeof(cups_size_t)); + cf_size_t *newsize = (cf_size_t *)calloc(1, sizeof(cf_size_t)); // New media size if (newsize) - memcpy(newsize, size, sizeof(cups_size_t)); + memcpy(newsize, size, sizeof(cf_size_t)); return (newsize); } @@ -1684,7 +1415,7 @@ cfGetPageDimensions(ipp_t *printer_attrs, // I - Printer attributes ipp_t *job_attrs, // I - Job attributes int num_options, // I - Number of options cups_option_t *options, // I - Options - cups_page_header2_t *header, // I - Raster page header + cups_page_header_t *header, // I - Raster page header int transverse_fit, // I - Accept transverse fit? float *width, // O - Width (in pt, 1/72 inches) float *height, // O - Height @@ -2439,9 +2170,9 @@ cfGenerateSizes(ipp_t *response, return; if (sizes) - *sizes = cupsArrayNew3((cups_array_func_t)pwg_compare_sizes, NULL, NULL, 0, - (cups_acopy_func_t)pwg_copy_size, - (cups_afree_func_t)free); + *sizes = cupsArrayNew((cups_array_cb_t)pwg_compare_sizes, NULL, NULL, 0, + (cups_acopy_cb_t)pwg_copy_size, + (cups_afree_cb_t)free); // Go through all attributes which are lists of media-col structures for (j = 0; j < sizeof(col_attrs) / sizeof(col_attrs[0]); j ++) @@ -2450,7 +2181,7 @@ cfGenerateSizes(ipp_t *response, { for (i = 0, count = ippGetCount(attr); i < count; i ++) { - cups_size_t temp, temp_by_name; // Current size + cf_size_t temp, temp_by_name; // Current size media_col = ippGetCollection(attr, i); media_size = @@ -2669,7 +2400,7 @@ cfGenerateSizes(ipp_t *response, { for (i = 0, count = ippGetCount(attr); i < count; i ++) { - cups_size_t temp; // Current size + cf_size_t temp; // Current size media_size = ippGetCollection(attr, i); x_dim = ippFindAttribute(media_size, "x-dimension", IPP_TAG_ZERO); @@ -2774,7 +2505,7 @@ cfGenerateSizes(ipp_t *response, { const char *pwg_size = ippGetString(attr, i, NULL); // PWG size name - cups_size_t temp, *temp2; // Current size, found size + cf_size_t temp, *temp2; // Current size, found size if ((pwg = pwgMediaForPWG(pwg_size)) != NULL) { diff --git a/cupsfilters/ipp.h b/cupsfilters/ipp.h index 20beeec33..25e585690 100644 --- a/cupsfilters/ipp.h +++ b/cupsfilters/ipp.h @@ -16,7 +16,7 @@ extern "C" { // Include necessary headers... // -#include "filter.h" +#include #include #include #include @@ -33,6 +33,16 @@ extern "C" { #include #include + +// +// Renamed CUPS type in API +// + +#if CUPS_VERSION_MAJOR < 3 +# define cups_page_header_t cups_page_header2_t +#endif + + #define CF_GET_PRINTER_ATTRIBUTES_LOGSIZE 4 * 65536 #define CF_GET_PRINTER_ATTRIBUTES_MAX_OUTPUT_LEN 8192 #define CF_GET_PRINTER_ATTRIBUTES_MAX_URI_LEN 2048 @@ -164,7 +174,7 @@ int cfGetPageDimensions(ipp_t *printer_attrs, ipp_t *job_attrs, int num_options, cups_option_t *options, - cups_page_header2_t *header, + cups_page_header_t *header, int transverse_fit, float *width, float *height, diff --git a/cupsfilters/libcups2-private.h b/cupsfilters/libcups2-private.h new file mode 100644 index 000000000..8b82b5c87 --- /dev/null +++ b/cupsfilters/libcups2-private.h @@ -0,0 +1,75 @@ +// +// Libcups2 header file for libcupsfilters. +// +// Copyright 2020-2022 by Till Kamppeter. +// +// Licensed under Apache License v2.0. See the file "LICENSE" for more +// information. +// + +#ifndef _LIBCUPS2_PRIVATE_H_ +# define _LIBCUPS2_PRIVATE_H_ + +# include + +# ifdef HAVE_LIBCUPS2 + +// These CUPS headers need to get applied before applying the +// renaming "#define"s. Otherwise we get conflicting duplicate +// declarations. + +# include "cups/http.h" +# include "cups/array.h" +# include "cups/cups.h" +# include "cups/ipp.h" +# include "cups/raster.h" + +// Functions renamed in libcups3 + +# define cupsArrayGetCount cupsArrayCount +# define cupsArrayGetFirst cupsArrayFirst +# define cupsArrayGetNext cupsArrayNext +# define cupsArrayGetElement cupsArrayIndex +# define cupsArrayNew cupsArrayNew3 +# define cupsGetDests cupsGetDests2 +# define cupsGetError cupsLastError +# define cupsGetErrorString cupsLastErrorString +# define cupsRasterReadHeader cupsRasterReadHeader2 +# define cupsRasterWriteHeader cupsRasterWriteHeader2 +# define httpConnect httpConnect2 +# define ippGetFirstAttribute ippFirstAttribute +# define ippGetNextAttribute ippNextAttribute + +// Function replaced by a different function in libcups3 + +# define cupsCreateTempFd(prefix,suffix,buffer,bufsize) cupsTempFd(buffer,bufsize) + +// Data types renamed in libcups3 + +# define cups_acopy_cb_t cups_acopy_func_t +# define cups_afree_cb_t cups_afree_func_t +# define cups_array_cb_t cups_array_func_t +# define cups_page_header_t cups_page_header2_t + +// For some functions' parameters in libcups3 size_t is used while +// int was used in libcups2. We use this type in such a case. + +# define cups_len_t int + +// Data type newly introduced in libcups3 + +enum http_resolve_e // @link httpResolveURI@ options bit values +{ + HTTP_RESOLVE_DEFAULT = 0, // Resolve with default options + HTTP_RESOLVE_FQDN = 1, // Resolve to a FQDN + HTTP_RESOLVE_FAXOUT = 2 // Resolve FaxOut service instead of Print +}; +typedef unsigned http_resolve_t; // @link httpResolveURI@ options bitfield + +# else + +# define cups_len_t size_t + +# endif // HAVE_LIBCUPS2 + +#endif // !_LIBCUPS2_PRIVATE_H_ diff --git a/cupsfilters/libcups2.c b/cupsfilters/libcups2.c new file mode 100644 index 000000000..ad131ef66 --- /dev/null +++ b/cupsfilters/libcups2.c @@ -0,0 +1,280 @@ +// +// Wrapper function for ipp.c for libcups2. +// +// Copyright 2020-2022 by Till Kamppeter. +// +// Licensed under Apache License v2.0. See the file "LICENSE" for more +// information. +// +// +// Include necessary headers... +// + + +#include + +#ifdef HAVE_LIBCUPS2 + +#include +#include +#include +#include +#include +#include +#include + +static int +convert_to_port(char *a) +{ + int port = 0; + + for (int i = 0; i < strlen(a); i ++) + port = port*10 + (a[i] - '0'); + + return (port); +} + + +char * +cfResolveURI2(const char *uri, + int is_fax) +{ + int ippfind_pid = 0, // Process ID of ippfind for IPP + post_proc_pipe[2], // Pipe to post-processing for IPP + wait_children, // Number of child processes left + wait_pid, // Process ID from wait() + wait_status, // Status from child + exit_status = 0, // Exit status + bytes, + port, + i, + output_of_fax_uri = 0, + is_local; + char *ippfind_argv[100], // Arguments for ippfind + *ptr_to_port = NULL, + *reg_type, + *resolved_uri = NULL, // Buffer for resolved URI + *resource_field = NULL, + *service_hostname = NULL, + // URI components... + scheme[32], + userpass[256], + hostname[1024], + resource[1024], + *buffer = NULL, // Copy buffer + *ptr; // Pointer into string; + cups_file_t *fp; // Post-processing input file + int status; // Status of GET request + + status = httpSeparateURI(HTTP_URI_CODING_ALL, uri, scheme, sizeof(scheme), + userpass, sizeof(userpass), + hostname, sizeof(hostname), &port, resource, + sizeof(resource)); + if (status < HTTP_URI_STATUS_OK) + // Invalid URI + goto error; + + // URI is not DNS-SD-based, so do not resolve + if ((reg_type = strstr(hostname, "._tcp")) == NULL) + return (strdup(uri)); + + resolved_uri = + (char *)malloc(CF_GET_PRINTER_ATTRIBUTES_MAX_URI_LEN * (sizeof(char))); + if (resolved_uri == NULL) + goto error; + memset(resolved_uri, 0, CF_GET_PRINTER_ATTRIBUTES_MAX_URI_LEN); + + reg_type --; + while (reg_type >= hostname && *reg_type != '.') + reg_type --; + if (reg_type < hostname) + goto error; + *reg_type++ = '\0'; + + i = 0; + ippfind_argv[i++] = "ippfind"; + ippfind_argv[i++] = reg_type; // list IPP(S) entries + ippfind_argv[i++] = "-T"; // DNS-SD poll timeout + ippfind_argv[i++] = "0"; // Minimum time required + if (is_fax) + { + ippfind_argv[i++] = "--txt"; + ippfind_argv[i++] = "rfo"; + } + ippfind_argv[i++] = "-N"; + ippfind_argv[i++] = hostname; + ippfind_argv[i++] = "-x"; + ippfind_argv[i++] = "echo"; // Output the needed data fields + ippfind_argv[i++] = "-en"; // separated by tab characters + if(is_fax) + ippfind_argv[i++] = "\n{service_hostname}\t{txt_rfo}\t{service_port}\t"; + else + ippfind_argv[i++] = "\n{service_hostname}\t{txt_rp}\t{service_port}\t"; + ippfind_argv[i++] = ";"; + ippfind_argv[i++] = "--local"; // Rest only if local service + ippfind_argv[i++] = "-x"; + ippfind_argv[i++] = "echo"; // Output an 'L' at the end of the + ippfind_argv[i++] = "-en"; // line + ippfind_argv[i++] = "L"; + ippfind_argv[i++] = ";"; + ippfind_argv[i++] = NULL; + + // + // Create a pipe for passing the ippfind output to post-processing + // + + if (pipe(post_proc_pipe)) + goto error; + + if ((ippfind_pid = fork()) == 0) + { + // + // Child comes here... + // + + dup2(post_proc_pipe[1], 1); + close(post_proc_pipe[0]); + close(post_proc_pipe[1]); + + execvp(CUPS_IPPFIND, ippfind_argv); + + exit(1); + } + else if (ippfind_pid < 0) + { + // + // Unable to fork! + // + + goto error; + } + + close(post_proc_pipe[1]); + + fp = cupsFileOpenFd(post_proc_pipe[0], "r"); + + buffer = + (char*)malloc(CF_GET_PRINTER_ATTRIBUTES_MAX_OUTPUT_LEN * sizeof(char)); + if (buffer == NULL) + goto error; + memset(buffer, 0, CF_GET_PRINTER_ATTRIBUTES_MAX_OUTPUT_LEN); + + while ((bytes = + cupsFileGetLine(fp, buffer, + CF_GET_PRINTER_ATTRIBUTES_MAX_OUTPUT_LEN)) > 0) + { + // Mark all the fields of the output of ippfind + ptr = buffer; + + // ignore new lines + if (bytes < 3) + goto read_error; + + // First, build the DNS-SD-service-name-based URI ... + while (ptr && !isalnum(*ptr & 255)) ptr ++; + + service_hostname = ptr; + ptr = memchr(ptr, '\t', + CF_GET_PRINTER_ATTRIBUTES_MAX_OUTPUT_LEN - (ptr - buffer)); + if (!ptr) goto read_error; + *ptr = '\0'; + ptr ++; + + resource_field = ptr; + ptr = memchr(ptr, '\t', + CF_GET_PRINTER_ATTRIBUTES_MAX_OUTPUT_LEN - (ptr - buffer)); + if (!ptr) goto read_error; + *ptr = '\0'; + ptr ++; + + ptr_to_port = ptr; + ptr = memchr(ptr, '\t', + CF_GET_PRINTER_ATTRIBUTES_MAX_OUTPUT_LEN - (ptr - buffer)); + if (!ptr) goto read_error; + *ptr = '\0'; + ptr ++; + + // Do we have a local service so that we have to set the host name to + // "localhost"? + is_local = (*ptr == 'L'); + + ptr = strchr(reg_type, '.'); + if (!ptr) goto read_error; + *ptr = '\0'; + + port = convert_to_port(ptr_to_port); + + httpAssembleURIf(HTTP_URI_CODING_ALL, resolved_uri, + 2047, reg_type + 1, NULL, + (is_local ? "localhost" : service_hostname), port, "/%s", + resource_field); + + if (is_fax) + output_of_fax_uri = 1; // fax-uri requested from fax-capable device + + read_error: + memset(buffer, 0, CF_GET_PRINTER_ATTRIBUTES_MAX_OUTPUT_LEN); + } + + cupsFileClose(fp); + + if (buffer != NULL) + free(buffer); + + // + // Wait for the child processes to exit... + // + + wait_children = 1; + + while (wait_children > 0) + { + // + // Wait until we get a valid process ID or the job is canceled... + // + + while ((wait_pid = wait(&wait_status)) < 0 && errno == EINTR); + + if (wait_pid < 0) + break; + + wait_children --; + + // + // Report child status... + // + + if (wait_status) + { + if (WIFEXITED(wait_status)) + { + exit_status = WEXITSTATUS(wait_status); + if (wait_pid == ippfind_pid && exit_status <= 2) + exit_status = 0; + } + else if (WTERMSIG(wait_status) == SIGTERM) + { + // All OK, no error + } + else + { + exit_status = WTERMSIG(wait_status); + } + } + } + if (is_fax && !output_of_fax_uri) + goto error; + + return (resolved_uri); + + // + // Exit... + // + + error: + if (resolved_uri != NULL) + free(resolved_uri); + return (NULL); +} + +#endif // HAVE_LIBCUPS2 diff --git a/cupsfilters/mupdftopwg.c b/cupsfilters/mupdftopwg.c index d7dd59e4c..f15d1fd68 100644 --- a/cupsfilters/mupdftopwg.c +++ b/cupsfilters/mupdftopwg.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -33,11 +34,7 @@ #define CUPS_IPTEMPFILE "/tmp/ip-XXXXXX" #define CUPS_OPTEMPFILE "/tmp/op-XXXXXX" -#ifdef CUPS_RASTER_SYNCv1 -typedef cups_page_header2_t mupdf_page_header; -#else typedef cups_page_header_t mupdf_page_header; -#endif // CUPS_RASTER_SYNCv1 static int @@ -189,10 +186,10 @@ mutool_spawn(const char *filename, // Put mutool command line argument into an array for the "exec()" // call - numargs = cupsArrayCount(mutool_args); + numargs = cupsArrayGetCount(mutool_args); mutoolargv = calloc(numargs + 1, sizeof(char *)); - for (argument = (char *)cupsArrayFirst(mutool_args), i = 0; argument; - argument = (char *)cupsArrayNext(mutool_args), i++) + for (argument = (char *)cupsArrayGetFirst(mutool_args), i = 0; argument; + argument = (char *)cupsArrayGetNext(mutool_args), i++) mutoolargv[i] = argument; mutoolargv[i] = NULL; @@ -469,7 +466,7 @@ cfFilterMuPDFToPWG(int inputfd, // I - File descriptor input stream sa.sa_handler = SIG_IGN; sigaction(SIGPIPE, &sa, NULL); - fd = cupsTempFd(infilename, 1024); + fd = cupsCreateTempFd(NULL, NULL, infilename, 1024); if (fd < 0) { if (log) log(ld, CF_LOGLEVEL_ERROR, @@ -525,7 +522,7 @@ cfFilterMuPDFToPWG(int inputfd, // I - File descriptor input stream goto out; // mutool parameters - mupdf_args = cupsArrayNew(NULL, NULL); + mupdf_args = cupsArrayNew(NULL, NULL, NULL, 0, NULL, NULL); if (!mupdf_args) { if (log) log(ld, CF_LOGLEVEL_ERROR, diff --git a/cupsfilters/pclmtoraster.cxx b/cupsfilters/pclmtoraster.cxx index af55d700e..a04913712 100644 --- a/cupsfilters/pclmtoraster.cxx +++ b/cupsfilters/pclmtoraster.cxx @@ -11,17 +11,17 @@ // Include necessary headers... // -#include "filter.h" +#include +#include +#include +#include +#include +#include #include #include #include #include #include -#include "image.h" -#include "bitmap.h" -#include "raster.h" -#include "filter.h" -#include "ipp.h" #define MAX_BYTES_PER_PIXEL 32 @@ -32,7 +32,7 @@ typedef struct pclmtoraster_data_s cf_filter_out_format_t outformat = CF_FILTER_OUT_FORMAT_PWG_RASTER; int numcolors = 0; int rowsize = 0; - cups_page_header2_t header; + cups_page_header_t header; char pageSizeRequested[64]; int bi_level = 0; // image swapping @@ -81,7 +81,7 @@ parse_opts(cf_filter_data_t *data, const char *val; cf_logfunc_t log = data->logfunc; void *ld = data->logdata; - cups_page_header2_t *header = &(pclmtoraster_data->header); + cups_page_header_t *header = &(pclmtoraster_data->header); cups_cspace_t cspace = (cups_cspace_t)(-1); @@ -691,7 +691,7 @@ select_convert_func(int pgno, // I - Page number pclm_conversion_function_t *convert)// I - Conversion function { // Set rowsize and numcolors based on colorspace of raster data - cups_page_header2_t header = data->header; + cups_page_header_t header = data->header; std::string colorspace = data->colorspace; if (colorspace == "/DeviceRGB") { @@ -970,7 +970,7 @@ out_page(cups_raster_t* raster, // I - Raster stream if (data->header.cupsColorOrder == CUPS_ORDER_BANDED) data->header.cupsBytesPerLine *= data->header.cupsNumColors; - if (!cupsRasterWriteHeader2(raster, &(data->header))) + if (!cupsRasterWriteHeader(raster, &(data->header))) { if (log) log(ld, CF_LOGLEVEL_ERROR, "cfFilterPCLmToRaster: Can't write page %d header", pgno + 1); @@ -1115,7 +1115,7 @@ cfFilterPCLmToRaster(int inputfd, // I - File descriptor input stream return (1); } - if ((fd = cupsTempFd(tempfile, sizeof(tempfile))) < 0) + if ((fd = cupsCreateTempFd(NULL, NULL, tempfile, sizeof(tempfile))) < 0) { if (log) log(ld, CF_LOGLEVEL_ERROR, "cfFilterPCLmToRaster: Unable to copy PDF file: %s", diff --git a/cupsfilters/pdftopdf/pdftopdf.cxx b/cupsfilters/pdftopdf/pdftopdf.cxx index 6d2f9971c..bdf2475d7 100644 --- a/cupsfilters/pdftopdf/pdftopdf.cxx +++ b/cupsfilters/pdftopdf/pdftopdf.cxx @@ -8,9 +8,13 @@ // #include + #include #include -#include "cupsfilters/debug-internal.h" +#include +#include +#include +#include #include #include #include @@ -21,9 +25,6 @@ #include #include #include "pdftopdf-private.h" -#include "cupsfilters/raster.h" -#include "cupsfilters/ipp.h" -#include "cupsfilters/ipp.h" #include "pdftopdf-processor-private.h" #include @@ -791,7 +792,7 @@ copy_fd_to_temp(int infd, int n; // FIXME: what does >buf mean here? - int outfd = cupsTempFd(buf, sizeof(buf)); + int outfd = cupsCreateTempFd(NULL, NULL, buf, sizeof(buf)); if (outfd < 0) { if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR, diff --git a/cupsfilters/pdftoraster.cxx b/cupsfilters/pdftoraster.cxx index 5738e62f9..008d03c2c 100644 --- a/cupsfilters/pdftoraster.cxx +++ b/cupsfilters/pdftoraster.cxx @@ -11,11 +11,12 @@ // #include -#include "filter.h" +#include +#include #ifdef HAVE_POPPLER -#include "colormanager.h" -#include "image.h" -#include "ipp.h" +#include +#include +#include #include #define USE_CMS @@ -98,7 +99,7 @@ typedef struct pdftoraster_doc_s unsigned int popplerNumColors; unsigned int bitmapoffset[2]; poppler::document *poppler_doc; - cups_page_header2_t header; + cups_page_header_t header; cf_logfunc_t logfunc; // Logging function, NULL for no // logging void *logdata; // User data for logging function, can @@ -1781,7 +1782,7 @@ out_page(pdftoraster_doc_t *doc, pageNo, doc->header.cupsWidth, doc->header.cupsHeight, doc->bitmapoffset[0], doc->bitmapoffset[1]); - if (!cupsRasterWriteHeader2(raster, &(doc->header))) + if (!cupsRasterWriteHeader(raster, &(doc->header))) { if (log) log(ld,CF_LOGLEVEL_ERROR, "cfFilterPDFToRaster: Cannot write page %d header", pageNo); @@ -1987,7 +1988,7 @@ cfFilterPDFToRaster(int inputfd, // I - File descriptor input stream char buf[BUFSIZ]; int n; - fd = cupsTempFd(name, sizeof(name)); + fd = cupsCreateTempFd(NULL, NULL, name, sizeof(name)); if (fd < 0) { if (log) log(ld, CF_LOGLEVEL_ERROR, diff --git a/cupsfilters/pwgtopdf.cxx b/cupsfilters/pwgtopdf.cxx index 1d62dda39..06a215651 100644 --- a/cupsfilters/pwgtopdf.cxx +++ b/cupsfilters/pwgtopdf.cxx @@ -11,8 +11,8 @@ // -#include "filter.h" #include + #include #include #include @@ -25,9 +25,11 @@ #include #include #include +#include #include #include #include +#include #include // ntohl @@ -1512,7 +1514,7 @@ cfFilterPWGToPDF(int inputfd, // I - File descriptor input stream cf_filter_data_t *data, // I - Job and printer data void *parameters) // I - Filter-specific parameters (outformat) { - int i; + cups_len_t i; char *t; pwgtopdf_doc_t doc; // Document information FILE *outputfp; // Output data stream @@ -1522,7 +1524,7 @@ cfFilterPWGToPDF(int inputfd, // I - File descriptor input stream // ("on" or "off") struct pdf_info pdf; cups_raster_t *ras; // Raster stream for printing - cups_page_header2_t header; // Page header from file + cups_page_header_t header; // Page header from file ipp_t *printer_attrs = data->printer_attrs; // Printer attributes from // printer data ipp_attribute_t *ipp_attr; // Printer attribute @@ -1616,7 +1618,7 @@ cfFilterPWGToPDF(int inputfd, // I - File descriptor input stream { log(ld, CF_LOGLEVEL_DEBUG, "PCLm-related printer IPP attributes:"); total_attrs = 0; - ipp_attr = ippFirstAttribute(printer_attrs); + ipp_attr = ippGetFirstAttribute(printer_attrs); while (ipp_attr) { if (strncmp(ippGetName(ipp_attr), "pclm-", 5) == 0) @@ -1629,7 +1631,7 @@ cfFilterPWGToPDF(int inputfd, // I - File descriptor input stream if ((kw = ippGetString(ipp_attr, i, NULL)) != NULL) log(ld, CF_LOGLEVEL_DEBUG, " Keyword: %s", kw); } - ipp_attr = ippNextAttribute(printer_attrs); + ipp_attr = ippGetNextAttribute(printer_attrs); } log(ld, CF_LOGLEVEL_DEBUG, " %d attributes", total_attrs); } @@ -1654,7 +1656,7 @@ cfFilterPWGToPDF(int inputfd, // I - File descriptor input stream "cfFilterPWGToPDF: Printer PCLm attribute \"%s\"", attr_name); pdf.pclm_strip_height_supported.clear(); // remove default value = 16 - for (int i = 0; i < ippGetCount(ipp_attr); i ++) + for (i = 0; i < ippGetCount(ipp_attr); i ++) pdf.pclm_strip_height_supported.push_back(ippGetInteger(ipp_attr, i)); } @@ -1740,7 +1742,7 @@ cfFilterPWGToPDF(int inputfd, // I - File descriptor input stream } } - while (cupsRasterReadHeader2(ras, &header)) + while (cupsRasterReadHeader(ras, &header)) { if (iscanceled && iscanceled(icd)) { diff --git a/cupsfilters/pwgtoraster.c b/cupsfilters/pwgtoraster.c index 020d2ea64..7cdbb32f3 100644 --- a/cupsfilters/pwgtoraster.c +++ b/cupsfilters/pwgtoraster.c @@ -10,13 +10,15 @@ // information. // -#include "colormanager.h" -#include "image.h" -#include "bitmap.h" -#include "filter.h" -#include "ipp.h" #include -#include + +#include +#include +#include +#include +#include +#include +#include #define USE_CMS @@ -25,11 +27,8 @@ #include #include #include +#include #include -#include -#include -#include -#include #include #include #ifdef USE_LCMS1 @@ -89,8 +88,8 @@ typedef struct pwgtoraster_doc_s unsigned int bitspercolor; unsigned int outputNumColors; unsigned int bitmapoffset[2]; - cups_page_header2_t inheader; - cups_page_header2_t outheader; + cups_page_header_t inheader; + cups_page_header_t outheader; cups_file_t *inputfp; // Temporary file, if any FILE *outputfp; // Temporary file, if any // margin swapping @@ -1331,7 +1330,7 @@ out_page(pwgtoraster_doc_t *doc, return (false); } - if (!cupsRasterReadHeader2(inras, &(doc->inheader))) + if (!cupsRasterReadHeader(inras, &(doc->inheader))) { // Done log(ld, CF_LOGLEVEL_DEBUG, @@ -1482,7 +1481,7 @@ out_page(pwgtoraster_doc_t *doc, if (doc->outheader.cupsColorOrder == CUPS_ORDER_BANDED) doc->outheader.cupsBytesPerLine *= doc->outheader.cupsNumColors; - if (!cupsRasterWriteHeader2(outras, &(doc->outheader))) + if (!cupsRasterWriteHeader(outras, &(doc->outheader))) { if (log) log(ld,CF_LOGLEVEL_ERROR, "cfFilterPWGToRaster: Can't write page %d header", pageNo); diff --git a/cupsfilters/raster.c b/cupsfilters/raster.c index 67a20bdcc..32a8b8074 100644 --- a/cupsfilters/raster.c +++ b/cupsfilters/raster.c @@ -27,13 +27,14 @@ #include #include #include +#include #include // // Local functions // -static int raster_base_header(cups_page_header2_t *h, cf_filter_data_t *data, +static int raster_base_header(cups_page_header_t *h, cf_filter_data_t *data, int pwg_raster); // @@ -172,7 +173,7 @@ cfRasterColorSpaceString(cups_cspace_t cspace) // I - cupsColorSpace value int // O - 0 on success, // -1 on error -cfRasterPrepareHeader(cups_page_header2_t *h, // I - Raster header +cfRasterPrepareHeader(cups_page_header_t *h, // I - Raster header cf_filter_data_t *data, // I - Job and printer data cf_filter_out_format_t final_outformat, // I - Job output format @@ -554,7 +555,7 @@ cfRasterPrepareHeader(cups_page_header2_t *h, // I - Raster header int // O - 0 on success, // -1 on error -cfRasterSetColorSpace(cups_page_header2_t *h, // I - Raster header +cfRasterSetColorSpace(cups_page_header_t *h, // I - Raster header const char *available, // I - Available color spaces // from IPP attribute // urf-supported or @@ -791,7 +792,7 @@ cfRasterSetColorSpace(cups_page_header2_t *h, // I - Raster header static int // O - -1 on error, 0 on success -raster_base_header(cups_page_header2_t *h, // O - Raster header +raster_base_header(cups_page_header_t *h, // O - Raster header cf_filter_data_t *data, // I - Filter data int pwg_raster) // I - 1 if PWG/Apple Raster { @@ -890,7 +891,7 @@ raster_base_header(cups_page_header2_t *h, // O - Raster header // Initialize header // - memset(h, 0, sizeof(cups_page_header2_t)); + memset(h, 0, sizeof(cups_page_header_t)); // // Fill in the items using printer and job IPP attributes and options diff --git a/cupsfilters/raster.h b/cupsfilters/raster.h index 9c987258d..b9a832a2b 100644 --- a/cupsfilters/raster.h +++ b/cupsfilters/raster.h @@ -19,7 +19,7 @@ extern "C" { // Include necessary headers... // -# include "filter.h" +# include # include # include # include @@ -36,12 +36,21 @@ extern "C" { # include +// +// Renamed CUPS type in API +// + +#if CUPS_VERSION_MAJOR < 3 +# define cups_page_header_t cups_page_header2_t +#endif + + // // Prototypes... // extern const char *cfRasterColorSpaceString(cups_cspace_t cspace); -extern int cfRasterPrepareHeader(cups_page_header2_t *h, +extern int cfRasterPrepareHeader(cups_page_header_t *h, cf_filter_data_t *data, cf_filter_out_format_t final_outformat, @@ -49,7 +58,7 @@ extern int cfRasterPrepareHeader(cups_page_header2_t *h, header_outformat, int no_high_depth, cups_cspace_t *cspace); -extern int cfRasterSetColorSpace(cups_page_header2_t *h, +extern int cfRasterSetColorSpace(cups_page_header_t *h, const char *available, const char *color_mode, cups_cspace_t *cspace, diff --git a/cupsfilters/rastertopwg.c b/cupsfilters/rastertopwg.c index 298a13228..4971a01a9 100644 --- a/cupsfilters/rastertopwg.c +++ b/cupsfilters/rastertopwg.c @@ -11,9 +11,10 @@ // Include necessary headers... -#include "filter.h" -#include "raster.h" -#include "ipp.h" +#include +#include +#include +#include #include #include #include @@ -35,7 +36,7 @@ cfFilterRasterToPWG(int inputfd, // I - File descriptor input stream { cups_raster_t *inras; // Input raster stream cups_raster_t *outras; // Output raster stream - cups_page_header2_t inheader, // Input raster page header + cups_page_header_t inheader, // Input raster page header outheader; // Output raster page header unsigned y; // Current line unsigned char *line; // Line buffer @@ -97,7 +98,7 @@ cfFilterRasterToPWG(int inputfd, // I - File descriptor input stream inras = cupsRasterOpen(inputfd, CUPS_RASTER_READ); - while (cupsRasterReadHeader2(inras, &inheader)) + while (cupsRasterReadHeader(inras, &inheader)) { if (iscanceled && iscanceled(icd)) { @@ -514,7 +515,7 @@ cfFilterRasterToPWG(int inputfd, // I - File descriptor input stream // ImageBoxBottom } - if (!cupsRasterWriteHeader2(outras, &outheader)) + if (!cupsRasterWriteHeader(outras, &outheader)) { if (log) log(ld, CF_LOGLEVEL_ERROR, "cfFilterRasterToPWG: Error sending raster data."); diff --git a/cupsfilters/texttopdf.c b/cupsfilters/texttopdf.c index aaece9716..cd79800e2 100644 --- a/cupsfilters/texttopdf.c +++ b/cupsfilters/texttopdf.c @@ -14,11 +14,13 @@ // #include -#include "pdfutils-private.h" -#include "debug-internal.h" -#include "filter.h" -#include "raster.h" -#include "fontembed-private.h" + +#include +#include +#include +#include +#include +#include #include #include #include "fontconfig/fontconfig.h" @@ -489,7 +491,7 @@ typedef struct texttopdf_doc_s float FontScaleX, FontScaleY; // The font matrix lchar_t *Title, *Date; // The title and date strings - cups_page_header2_t h; // CUPS Raster page header, to + cups_page_header_t h; // CUPS Raster page header, to // accommodate results of command // line/IPP attribute parsing cf_filter_texttopdf_parameter_t env_vars; diff --git a/cupsfilters/texttotext.c b/cupsfilters/texttotext.c index 022a277f5..0c241174c 100644 --- a/cupsfilters/texttotext.c +++ b/cupsfilters/texttotext.c @@ -29,9 +29,10 @@ #include #include #include +#include +#include #include -#include "ipp.h" -#include "filter.h" +#include // @@ -809,7 +810,7 @@ cfFilterTextToText(int inputfd, // I - File descriptor input stream if (pagination && ((num_copies != 1 && collate) || reverse_order)) // Create page array - page_array = cupsArrayNew(NULL, NULL); + page_array = cupsArrayNew(NULL, NULL, NULL, 0, NULL, NULL); // Main loop for reading the input file, converting the encoding, formatting // the output, and printing the pages @@ -1121,14 +1122,14 @@ cfFilterTextToText(int inputfd, // I - File descriptor input stream (reverse_order ? (page >= 1) : (page <= num_pages)); page += (reverse_order ? -1 : 1)) { - p = (char *)cupsArrayIndex(page_array, page - 1); + p = (char *)cupsArrayGetElement(page_array, page - 1); if (log) log(ld, CF_LOGLEVEL_INFO, "cfFilterTextToText: %d %d", page, (collate ? 1 : num_copies)); } // Clean up for (page = 0; page < num_pages; page ++) { - p = (char *)cupsArrayIndex(page_array, page); + p = (char *)cupsArrayGetElement(page_array, page); free(p); } cupsArrayDelete(page_array); diff --git a/cupsfilters/universal.c b/cupsfilters/universal.c index 7218af622..dd4c0b795 100644 --- a/cupsfilters/universal.c +++ b/cupsfilters/universal.c @@ -11,8 +11,10 @@ // information. // -#include "config.h" -#include "filter.h" +#include + +#include +#include #include #include #include @@ -85,7 +87,7 @@ cfFilterUniversal(int inputfd, // I - File descriptor input stream sscanf(output, "%15[^/]/%255s", output_super, output_type); cups_array_t *filter_chain; - filter_chain = cupsArrayNew(NULL, NULL); + filter_chain = cupsArrayNew(NULL, NULL, NULL, 0, NULL, NULL); if (!strcasecmp(input_super, "image") && strcasecmp(input_type, "urf") && strcasecmp(input_type, "pwg-raster")) @@ -340,10 +342,10 @@ cfFilterUniversal(int inputfd, // I - File descriptor input stream // Do the dirty work ... ret = cfFilterChain(inputfd, outputfd, inputseekable, data, filter_chain); - for (filter = (cf_filter_filter_in_chain_t *)cupsArrayFirst(filter_chain); + for (filter = (cf_filter_filter_in_chain_t *)cupsArrayGetFirst(filter_chain); filter; filter = next) { - next = (cf_filter_filter_in_chain_t *)cupsArrayNext(filter_chain); + next = (cf_filter_filter_in_chain_t *)cupsArrayGetNext(filter_chain); free(filter->parameters); free(filter); }