From 2c0dfa3920ef9a2cfbd1192ed00d14d94638a8ba Mon Sep 17 00:00:00 2001 From: Bryan Ferris Date: Fri, 21 Jun 2019 10:25:17 -0700 Subject: Update libcups to v2.2.9 RESTRICT AUTOMERGE Bug: 111210196 Test: adb shell am instrument -w android.print.cts/android.support.test.runner.AndroidJUnitRunner Change-Id: Idb1ecb93551bf6f77527513ddfb3de4bfd70c092 Merged-In: Idb1ecb93551bf6f77527513ddfb3de4bfd70c092 --- config.h | 4 +- cups/Makefile | 152 ++--- cups/adminutil.c | 16 +- cups/api-array.header | 32 -- cups/api-array.shtml | 194 ------- cups/api-cups.header | 38 -- cups/api-cups.shtml | 441 --------------- cups/api-filedir.header | 34 -- cups/api-filedir.shtml | 29 - cups/api-httpipp.header | 37 -- cups/api-httpipp.shtml | 315 ----------- cups/api-ppd.shtml | 4 +- cups/auth.c | 518 ++++++++++++----- cups/backchannel.c | 12 +- cups/cups-private.h | 4 +- cups/cups.h | 57 +- cups/cupspm-icon.png | 0 cups/cupspm.md | 994 ++++++++++++++++++++++++++++++++ cups/cupspm.opacity | 0 cups/cupspm.png | 0 cups/debug-private.h | 27 +- cups/debug.c | 10 +- cups/dest-job.c | 34 +- cups/dest-localization.c | 50 +- cups/dest-options.c | 90 ++- cups/dest.c | 1408 ++++++++++++++++++++++++++++++---------------- cups/dir.c | 41 +- cups/encode.c | 6 +- cups/file-private.h | 36 +- cups/file.c | 132 +++-- cups/file.h | 12 +- cups/getputfile.c | 70 ++- cups/globals.c | 32 +- cups/hash.c | 91 ++- cups/http-addr.c | 20 +- cups/http-addrlist.c | 60 +- cups/http-private.h | 67 ++- cups/http-support.c | 195 ++++++- cups/http.c | 523 +++++++++-------- cups/http.h | 26 +- cups/ipp-support.c | 24 +- cups/ipp.c | 461 +++++++-------- cups/ipp.h | 283 +++++----- cups/language-private.h | 16 +- cups/language.c | 76 ++- cups/language.h | 2 +- cups/libcups2.def | 23 +- cups/md5.c | 170 +++--- cups/md5passwd.c | 52 +- cups/options.c | 64 ++- cups/ppd-cache.c | 413 +++++++++----- cups/ppd-conflicts.c | 5 +- cups/ppd-emit.c | 8 +- cups/ppd-localize.c | 4 +- cups/ppd-mark.c | 16 +- cups/ppd-util.c | 135 ++--- cups/ppd.c | 47 +- cups/ppd.h | 2 + cups/pwg-media.c | 1 + cups/pwg.h | 6 +- cups/raster-private.h | 14 +- cups/request.c | 70 ++- cups/sidechannel.c | 8 +- cups/snmp.c | 8 +- cups/string-private.h | 9 +- cups/string.c | 7 +- cups/tempfile.c | 52 +- cups/testarray.c | 4 +- cups/testcups.c | 47 +- cups/testdest.c | 68 ++- cups/testfile.c | 21 +- cups/testgetdests.c | 51 ++ cups/testhttp.c | 70 ++- cups/testipp.c | 164 +----- cups/testlang.c | 149 ++++- cups/testppd.c | 12 +- cups/testsnmp.c | 4 +- cups/thread-private.h | 5 +- cups/thread.c | 53 +- cups/tls-darwin.c | 121 +++- cups/tls-gnutls.c | 117 +++- cups/tls-sspi.c | 48 +- cups/tls.c | 6 +- cups/tlscheck.c | 37 +- cups/usersys.c | 90 ++- cups/util.c | 91 +-- cups/versioning.h | 303 ++++++---- filter/Makefile | 67 ++- filter/pstops.c | 9 +- filter/raster.c | 276 +++++++-- filter/rastertoepson.c | 4 +- filter/rastertolabel.c | 4 +- filter/spec-ppd.shtml | 27 +- filter/testclient.c | 960 +++++++++++++++++++++++++++++++ libcups_version | 2 +- 95 files changed, 6819 insertions(+), 3778 deletions(-) delete mode 100644 cups/api-array.header delete mode 100644 cups/api-array.shtml delete mode 100644 cups/api-cups.header delete mode 100644 cups/api-cups.shtml delete mode 100644 cups/api-filedir.header delete mode 100644 cups/api-filedir.shtml delete mode 100644 cups/api-httpipp.header delete mode 100644 cups/api-httpipp.shtml create mode 100644 cups/cupspm-icon.png create mode 100644 cups/cupspm.md create mode 100644 cups/cupspm.opacity create mode 100644 cups/cupspm.png create mode 100644 cups/testgetdests.c create mode 100644 filter/testclient.c diff --git a/config.h b/config.h index ec0f673b..bc295b3d 100644 --- a/config.h +++ b/config.h @@ -17,8 +17,8 @@ #ifndef _CUPS_CONFIG_H_ #define _CUPS_CONFIG_H_ -#define CUPS_SVERSION "CUPS v2.2.3" -#define CUPS_MINIMAL "CUPS/2.2.3" +#define CUPS_SVERSION "CUPS v2.2.9" +#define CUPS_MINIMAL "CUPS/2.2.9" #define CUPS_DEFAULT_PRINTOPERATOR_AUTH "@SYSTEM" #define CUPS_DEFAULT_LOG_LEVEL "warn" #define CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS "dnssd" diff --git a/cups/Makefile b/cups/Makefile index 1df7d855..f83c937c 100644 --- a/cups/Makefile +++ b/cups/Makefile @@ -1,8 +1,8 @@ # -# API library Makefile for CUPS. +# Library Makefile for CUPS. # -# Copyright 2007-2016 by Apple Inc. -# Copyright 1997-2006 by Easy Software Products, all rights reserved. +# Copyright © 2007-2018 by Apple Inc. +# Copyright © 1997-2006 by Easy Software Products, all rights reserved. # # These coded instructions, statements, and computer programs are the # property of Apple Inc. and are protected by Federal copyright @@ -89,6 +89,7 @@ TESTOBJS = \ testcups.o \ testdest.o \ testfile.o \ + testgetdests.o \ testhttp.o \ testi18n.o \ testipp.o \ @@ -158,6 +159,7 @@ UNITTARGETS = \ testcups \ testdest \ testfile \ + testgetdests \ testhttp \ testi18n \ testipp \ @@ -310,8 +312,9 @@ uninstall: libcups.so.2: $(LIBOBJS) echo Linking $@... - $(DSO) $(ARCHFLAGS) $(DSOFLAGS) -o $@ $(LIBOBJS) $(LIBGSSAPI) \ + $(DSO) $(ARCHFLAGS) $(LDFLAGS) $(DSOFLAGS) -o $@ $(LIBOBJS) $(LIBGSSAPI) \ $(SSLLIBS) $(DNSSDLIBS) $(COMMONLIBS) $(LIBZ) + $(CODE_SIGN) -s "$(CODE_SIGN_IDENTITY)" $@ $(RM) `basename $@ .2` $(LN) $@ `basename $@ .2` @@ -327,13 +330,14 @@ libcups.2.dylib: $(LIBOBJS) $(LIBCUPSORDER) grep -v -E -e '^(_cupsConnect|_cupsCharset|_cupsEncodingName|_cupsSetDefaults|_cupsSetHTTPError|_cupsUserDefault)$$' | \ sort >t.exp echo Linking $@... - $(DSO) $(ARCHFLAGS) $(DSOFLAGS) -o $@ \ + $(DSO) $(ARCHFLAGS) $(LDFLAGS) $(DSOFLAGS) -o $@ \ -install_name $(libdir)/$@ \ - -current_version 2.12.0 \ + -current_version 2.13.0 \ -compatibility_version 2.0.0 \ -exported_symbols_list t.exp \ $(LIBOBJS) $(LIBGSSAPI) $(SSLLIBS) $(DNSSDLIBS) \ $(COMMONLIBS) $(LIBZ) + $(CODE_SIGN) -s "$(CODE_SIGN_IDENTITY)" $@ $(RM) libcups.dylib t.exp $(LN) $@ libcups.dylib @@ -344,8 +348,8 @@ libcups.2.dylib: $(LIBOBJS) $(LIBCUPSORDER) libcups.la: $(LIBOBJS) echo Linking $@... - $(CC) $(ARCHFLAGS) $(DSOFLAGS) -o $@ $(LIBOBJS:.o=.lo) \ - -rpath $(LIBDIR) -version-info 2:12 $(LIBGSSAPI) $(SSLLIBS) \ + $(LD_CC) $(ARCHFLAGS) $(LDFLAGS) $(DSOFLAGS) -o $@ $(LIBOBJS:.o=.lo) \ + -rpath $(LIBDIR) -version-info 2:13 $(LIBGSSAPI) $(SSLLIBS) \ $(DNSSDLIBS) $(COMMONLIBS) $(LIBZ) @@ -367,12 +371,12 @@ libcups.a: $(LIBOBJS) libcups2.def: $(LIBOBJS) Makefile echo Generating $@... echo "LIBRARY libcups2" >libcups2.def - echo "VERSION 2.12" >>libcups2.def + echo "VERSION 2.13" >>libcups2.def echo "EXPORTS" >>libcups2.def (nm $(LIBOBJS) 2>/dev/null | grep "T _" | awk '{print $$3}'; \ echo __cups_strcpy; echo __cups_strlcat; echo __cups_strlcpy) | \ grep -v -E \ - -e 'cups_debug|Apple|BackChannel|Backend|FileCheck|Filter|GSSService|SetNegotiate|SideChannel' \ + -e 'cups_debug|Apple|BackChannel|Backend|FileCheck|Filter|GSSService|SetNegotiate|SideChannel|SNMP' \ -e 'Block$$' | \ sed -e '1,$$s/^_//' | sort >>libcups2.def @@ -383,8 +387,9 @@ libcups2.def: $(LIBOBJS) Makefile testadmin: testadmin.o $(LIBCUPSSTATIC) echo Linking $@... - $(CC) $(LDFLAGS) -o $@ testadmin.o $(LIBCUPSSTATIC) \ + $(LD_CC) $(LDFLAGS) -o $@ testadmin.o $(LIBCUPSSTATIC) \ $(LIBGSSAPI) $(SSLLIBS) $(DNSSDLIBS) $(COMMONLIBS) $(LIBZ) + $(CODE_SIGN) -s "$(CODE_SIGN_IDENTITY)" $@ # @@ -393,8 +398,9 @@ testadmin: testadmin.o $(LIBCUPSSTATIC) testarray: testarray.o $(LIBCUPSSTATIC) echo Linking $@... - $(CC) $(ARCHFLAGS) $(LDFLAGS) -o $@ testarray.o $(LIBCUPSSTATIC) \ + $(LD_CC) $(ARCHFLAGS) $(LDFLAGS) -o $@ testarray.o $(LIBCUPSSTATIC) \ $(LIBGSSAPI) $(SSLLIBS) $(DNSSDLIBS) $(COMMONLIBS) $(LIBZ) + $(CODE_SIGN) -s "$(CODE_SIGN_IDENTITY)" $@ echo Running array API tests... ./testarray @@ -405,8 +411,9 @@ testarray: testarray.o $(LIBCUPSSTATIC) testcache: testcache.o $(LIBCUPSSTATIC) echo Linking $@... - $(CC) $(LDFLAGS) -o $@ testcache.o $(LIBCUPSSTATIC) \ + $(LD_CC) $(LDFLAGS) -o $@ testcache.o $(LIBCUPSSTATIC) \ $(LIBGSSAPI) $(SSLLIBS) $(DNSSDLIBS) $(COMMONLIBS) $(LIBZ) + $(CODE_SIGN) -s "$(CODE_SIGN_IDENTITY)" $@ # @@ -415,8 +422,9 @@ testcache: testcache.o $(LIBCUPSSTATIC) testconflicts: testconflicts.o $(LIBCUPSSTATIC) echo Linking $@... - $(CC) $(LDFLAGS) -o $@ testconflicts.o $(LIBCUPSSTATIC) \ + $(LD_CC) $(LDFLAGS) -o $@ testconflicts.o $(LIBCUPSSTATIC) \ $(LIBGSSAPI) $(SSLLIBS) $(DNSSDLIBS) $(COMMONLIBS) $(LIBZ) + $(CODE_SIGN) -s "$(CODE_SIGN_IDENTITY)" $@ # @@ -425,8 +433,9 @@ testconflicts: testconflicts.o $(LIBCUPSSTATIC) testcreds: testcreds.o $(LIBCUPSSTATIC) echo Linking $@... - $(CC) $(ARCHFLAGS) $(LDFLAGS) -o $@ testcreds.o $(LIBCUPSSTATIC) \ + $(LD_CC) $(ARCHFLAGS) $(LDFLAGS) -o $@ testcreds.o $(LIBCUPSSTATIC) \ $(LIBGSSAPI) $(SSLLIBS) $(DNSSDLIBS) $(COMMONLIBS) $(LIBZ) + $(CODE_SIGN) -s "$(CODE_SIGN_IDENTITY)" $@ # @@ -435,8 +444,9 @@ testcreds: testcreds.o $(LIBCUPSSTATIC) testcups: testcups.o $(LIBCUPSSTATIC) echo Linking $@... - $(CC) $(LDFLAGS) -o $@ testcups.o $(LIBCUPSSTATIC) \ + $(LD_CC) $(LDFLAGS) -o $@ testcups.o $(LIBCUPSSTATIC) \ $(LIBGSSAPI) $(SSLLIBS) $(DNSSDLIBS) $(COMMONLIBS) $(LIBZ) + $(CODE_SIGN) -s "$(CODE_SIGN_IDENTITY)" $@ # @@ -445,8 +455,9 @@ testcups: testcups.o $(LIBCUPSSTATIC) testdest: testdest.o $(LIBCUPSSTATIC) echo Linking $@... - $(CC) $(LDFLAGS) -o $@ testdest.o $(LIBCUPSSTATIC) \ + $(LD_CC) $(LDFLAGS) -o $@ testdest.o $(LIBCUPSSTATIC) \ $(LIBGSSAPI) $(SSLLIBS) $(DNSSDLIBS) $(COMMONLIBS) $(LIBZ) + $(CODE_SIGN) -s "$(CODE_SIGN_IDENTITY)" $@ # @@ -455,20 +466,33 @@ testdest: testdest.o $(LIBCUPSSTATIC) testfile: testfile.o $(LIBCUPSSTATIC) echo Linking $@... - $(CC) $(ARCHFLAGS) $(LDFLAGS) -o $@ testfile.o $(LIBCUPSSTATIC) \ + $(LD_CC) $(ARCHFLAGS) $(LDFLAGS) -o $@ testfile.o $(LIBCUPSSTATIC) \ $(LIBGSSAPI) $(SSLLIBS) $(DNSSDLIBS) $(COMMONLIBS) $(LIBZ) + $(CODE_SIGN) -s "$(CODE_SIGN_IDENTITY)" $@ echo Running file API tests... ./testfile +# +# testgetdests (dependency on static CUPS library is intentional) +# + +testgetdests: testgetdests.o $(LIBCUPSSTATIC) + echo Linking $@... + $(LD_CC) $(LDFLAGS) -o $@ testgetdests.o $(LIBCUPSSTATIC) \ + $(LIBGSSAPI) $(SSLLIBS) $(DNSSDLIBS) $(COMMONLIBS) $(LIBZ) + $(CODE_SIGN) -s "$(CODE_SIGN_IDENTITY)" $@ + + # # testhttp (dependency on static CUPS library is intentional) # testhttp: testhttp.o $(LIBCUPSSTATIC) echo Linking $@... - $(CC) $(ARCHFLAGS) $(LDFLAGS) -o $@ testhttp.o $(LIBCUPSSTATIC) \ + $(LD_CC) $(ARCHFLAGS) $(LDFLAGS) -o $@ testhttp.o $(LIBCUPSSTATIC) \ $(LIBGSSAPI) $(SSLLIBS) $(DNSSDLIBS) $(COMMONLIBS) $(LIBZ) + $(CODE_SIGN) -s "$(CODE_SIGN_IDENTITY)" $@ echo Running HTTP API tests... ./testhttp @@ -479,8 +503,9 @@ testhttp: testhttp.o $(LIBCUPSSTATIC) testipp: testipp.o $(LIBCUPSSTATIC) echo Linking $@... - $(CC) $(ARCHFLAGS) $(LDFLAGS) -o $@ testipp.o $(LIBCUPSSTATIC) \ + $(LD_CC) $(ARCHFLAGS) $(LDFLAGS) -o $@ testipp.o $(LIBCUPSSTATIC) \ $(LIBGSSAPI) $(SSLLIBS) $(DNSSDLIBS) $(COMMONLIBS) $(LIBZ) + $(CODE_SIGN) -s "$(CODE_SIGN_IDENTITY)" $@ echo Running IPP API tests... ./testipp @@ -491,8 +516,9 @@ testipp: testipp.o $(LIBCUPSSTATIC) testi18n: testi18n.o $(LIBCUPSSTATIC) echo Linking $@... - $(CC) $(ARCHFLAGS) $(LDFLAGS) -o $@ testi18n.o $(LIBCUPSSTATIC) \ + $(LD_CC) $(ARCHFLAGS) $(LDFLAGS) -o $@ testi18n.o $(LIBCUPSSTATIC) \ $(LIBGSSAPI) $(SSLLIBS) $(DNSSDLIBS) $(COMMONLIBS) $(LIBZ) + $(CODE_SIGN) -s "$(CODE_SIGN_IDENTITY)" $@ echo Running internationalization API tests... ./testi18n @@ -503,10 +529,23 @@ testi18n: testi18n.o $(LIBCUPSSTATIC) testlang: testlang.o $(LIBCUPSSTATIC) echo Linking $@... - $(CC) $(ARCHFLAGS) $(LDFLAGS) -o $@ testlang.o $(LIBCUPSSTATIC) \ + $(LD_CC) $(ARCHFLAGS) $(LDFLAGS) -o $@ testlang.o $(LIBCUPSSTATIC) \ $(LIBGSSAPI) $(SSLLIBS) $(DNSSDLIBS) $(COMMONLIBS) $(LIBZ) + $(CODE_SIGN) -s "$(CODE_SIGN_IDENTITY)" $@ + echo Creating locale directory structure... + $(RM) -r locale + $(MKDIR) locale/en + echo 'msgid "No"' > locale/en/cups_en.po + echo 'msgstr "No"' >> locale/en/cups_en.po + echo 'msgid "Yes"' >> locale/en/cups_en.po + echo 'msgstr "Yes"' >> locale/en/cups_en.po + for po in ../locale/cups_*.po; do \ + lang=`basename $$po .po | sed -e '1,$$s/^cups_//'`; \ + $(MKDIR) locale/$$lang; \ + $(LN) ../../$$po locale/$$lang; \ + done echo Running language API tests... - ./testlang + LOCALEDIR=locale ./testlang # @@ -515,8 +554,9 @@ testlang: testlang.o $(LIBCUPSSTATIC) testoptions: testoptions.o $(LIBCUPSSTATIC) echo Linking $@... - $(CC) $(ARCHFLAGS) $(LDFLAGS) -o $@ testoptions.o $(LIBCUPSSTATIC) \ + $(LD_CC) $(ARCHFLAGS) $(LDFLAGS) -o $@ testoptions.o $(LIBCUPSSTATIC) \ $(LIBGSSAPI) $(SSLLIBS) $(DNSSDLIBS) $(COMMONLIBS) $(LIBZ) + $(CODE_SIGN) -s "$(CODE_SIGN_IDENTITY)" $@ echo Running option API tests... ./testoptions @@ -527,8 +567,9 @@ testoptions: testoptions.o $(LIBCUPSSTATIC) testppd: testppd.o $(LIBCUPSSTATIC) test.ppd test2.ppd echo Linking $@... - $(CC) $(ARCHFLAGS) $(LDFLAGS) -o $@ testppd.o $(LIBCUPSSTATIC) \ + $(LD_CC) $(ARCHFLAGS) $(LDFLAGS) -o $@ testppd.o $(LIBCUPSSTATIC) \ $(LIBGSSAPI) $(SSLLIBS) $(DNSSDLIBS) $(COMMONLIBS) $(LIBZ) + $(CODE_SIGN) -s "$(CODE_SIGN_IDENTITY)" $@ echo Running PPD API tests... ./testppd @@ -539,8 +580,9 @@ testppd: testppd.o $(LIBCUPSSTATIC) test.ppd test2.ppd testpwg: testpwg.o $(LIBCUPSSTATIC) test.ppd echo Linking $@... - $(CC) $(ARCHFLAGS) $(LDFLAGS) -o $@ testpwg.o $(LIBCUPSSTATIC) \ + $(LD_CC) $(ARCHFLAGS) $(LDFLAGS) -o $@ testpwg.o $(LIBCUPSSTATIC) \ $(LIBGSSAPI) $(SSLLIBS) $(DNSSDLIBS) $(COMMONLIBS) $(LIBZ) + $(CODE_SIGN) -s "$(CODE_SIGN_IDENTITY)" $@ echo Running PWG API tests... ./testpwg test.ppd @@ -551,8 +593,9 @@ testpwg: testpwg.o $(LIBCUPSSTATIC) test.ppd testsnmp: testsnmp.o $(LIBCUPSSTATIC) echo Linking $@... - $(CC) $(LDFLAGS) -o $@ testsnmp.o $(LIBCUPSSTATIC) \ + $(LD_CC) $(LDFLAGS) -o $@ testsnmp.o $(LIBCUPSSTATIC) \ $(LIBGSSAPI) $(SSLLIBS) $(DNSSDLIBS) $(COMMONLIBS) $(LIBZ) + $(CODE_SIGN) -s "$(CODE_SIGN_IDENTITY)" $@ # @@ -561,8 +604,9 @@ testsnmp: testsnmp.o $(LIBCUPSSTATIC) tlscheck: tlscheck.o $(LIBCUPSSTATIC) echo Linking $@... - $(CC) $(ARCHFLAGS) $(LDFLAGS) -o $@ tlscheck.o $(LIBCUPSSTATIC) \ + $(LD_CC) $(ARCHFLAGS) $(LDFLAGS) -o $@ tlscheck.o $(LIBCUPSSTATIC) \ $(LIBGSSAPI) $(SSLLIBS) $(DNSSDLIBS) $(COMMONLIBS) $(LIBZ) + $(CODE_SIGN) -s "$(CODE_SIGN_IDENTITY)" $@ # @@ -571,56 +615,27 @@ tlscheck: tlscheck.o $(LIBCUPSSTATIC) apihelp: echo Generating CUPS API help files... - mxmldoc --section "Programming" \ - --title "Introduction to CUPS Programming" \ - --css ../doc/cups-printable.css \ - --header api-overview.header --intro api-overview.shtml \ - >../doc/help/api-overview.html + $(RM) cupspm.xml + mxmldoc --section "Programming" --body cupspm.md \ + cupspm.xml \ + auth.c cups.h dest*.c encode.c http.h http*.c ipp.h ipp*.c \ + options.c tls-darwin.c usersys.c util.c \ + --coverimage cupspm.png \ + --epub ../doc/help/cupspm.epub + mxmldoc --section "Programming" --body cupspm.md \ + cupspm.xml > ../doc/help/cupspm.html + $(RM) cupspm.xml mxmldoc --section "Programming" --title "Administration APIs" \ --css ../doc/cups-printable.css \ --header api-admin.header --intro api-admin.shtml \ api-admin.xml \ adminutil.c adminutil.h getdevices.c >../doc/help/api-admin.html - mxmldoc --tokens help/api-admin.html api-admin.xml >../doc/help/api-admin.tokens $(RM) api-admin.xml - mxmldoc --section "Programming" --title "Array API" \ - --css ../doc/cups-printable.css \ - --header api-array.header --intro api-array.shtml \ - api-array.xml \ - array.h array.c >../doc/help/api-array.html - mxmldoc --tokens help/api-array.html api-array.xml >../doc/help/api-array.tokens - $(RM) api-array.xml - mxmldoc --section "Programming" --title "CUPS API" \ - --css ../doc/cups-printable.css \ - --header api-cups.header --intro api-cups.shtml \ - api-cups.xml \ - cups.h pwg.h adminutil.c dest*.c language.c notify.c \ - options.c pwg-media.c tempfile.c usersys.c \ - util.c >../doc/help/api-cups.html - mxmldoc --tokens help/api-cups.html api-cups.xml >../doc/help/api-cups.tokens - $(RM) api-cups.xml - mxmldoc --section "Programming" --title "File and Directory APIs" \ - --css ../doc/cups-printable.css \ - --header api-filedir.header --intro api-filedir.shtml \ - api-filedir.xml \ - file.h file.c dir.h dir.c >../doc/help/api-filedir.html - mxmldoc --tokens api-filedir.xml >../doc/help/api-filedir.tokens - $(RM) api-filedir.xml mxmldoc --section "Programming" --title "PPD API (DEPRECATED)" \ --css ../doc/cups-printable.css \ --header api-ppd.header --intro api-ppd.shtml \ api-ppd.xml ppd.h ppd-*.c >../doc/help/api-ppd.html - mxmldoc --tokens help/api-ppd.html api-ppd.xml >../doc/help/api-ppd.tokens $(RM) api-ppd.xml - mxmldoc --section "Programming" --title "HTTP and IPP APIs" \ - --css ../doc/cups-printable.css \ - --header api-httpipp.header --intro api-httpipp.shtml \ - api-httpipp.xml \ - http.h ipp.h auth.c getdevices.c getputfile.c encode.c \ - http.c http-addr.c http-support.c ipp.c ipp-support.c \ - md5passwd.c request.c >../doc/help/api-httpipp.html - mxmldoc --tokens help/api-httpipp.html api-httpipp.xml >../doc/help/api-httpipp.tokens - $(RM) api-httpipp.xml mxmldoc --section "Programming" \ --title "Filter and Backend Programming" \ --css ../doc/cups-printable.css \ @@ -628,7 +643,6 @@ apihelp: api-filter.xml \ backchannel.c backend.h backend.c sidechannel.c sidechannel.h \ >../doc/help/api-filter.html - mxmldoc --tokens help/api-filter.html api-filter.xml >../doc/help/api-filter.tokens $(RM) api-filter.xml @@ -637,8 +651,6 @@ apihelp: # sloc: - echo "libcupslite: \c" - sloccount $(LITEOBJS:.o=.c) 2>/dev/null | grep "Total Physical" | awk '{print $$9}' echo "libcups: \c" sloccount $(LIBOBJS:.o=.c) 2>/dev/null | grep "Total Physical" | awk '{print $$9}' diff --git a/cups/adminutil.c b/cups/adminutil.c index adb1f7ae..375b9054 100644 --- a/cups/adminutil.c +++ b/cups/adminutil.c @@ -22,11 +22,11 @@ #include "adminutil.h" #include #include -#ifdef WIN32 +#ifdef _WIN32 #else # include # include -#endif /* WIN32 */ +#endif /* _WIN32 */ /* @@ -2087,7 +2087,7 @@ do_samba_command(const char *command, /* I - Command to run */ const char *authfile, /* I - Samba authentication file */ FILE *logfile) /* I - Optional log file */ { -#ifdef WIN32 +#ifdef _WIN32 return (1); /* Always fail on Windows... */ #else @@ -2154,7 +2154,7 @@ do_samba_command(const char *command, /* I - Command to run */ return (WEXITSTATUS(status)); else return (-WTERMSIG(status)); -#endif /* WIN32 */ +#endif /* _WIN32 */ } @@ -2172,9 +2172,9 @@ get_cupsd_conf( int *remote) /* O - Remote file? */ { int fd; /* Temporary file descriptor */ -#ifndef WIN32 +#ifndef _WIN32 struct stat info; /* cupsd.conf file information */ -#endif /* WIN32 */ +#endif /* _WIN32 */ http_status_t status; /* Status of getting cupsd.conf */ char host[HTTP_MAX_HOST]; /* Hostname for connection */ @@ -2191,7 +2191,7 @@ get_cupsd_conf( snprintf(name, namesize, "%s/cupsd.conf", cg->cups_serverroot); *remote = 0; -#ifndef WIN32 +#ifndef _WIN32 if (!_cups_strcasecmp(host, "localhost") && !access(name, R_OK)) { /* @@ -2218,7 +2218,7 @@ get_cupsd_conf( status = HTTP_STATUS_OK; } else -#endif /* !WIN32 */ +#endif /* !_WIN32 */ { /* * Read cupsd.conf via a HTTP GET request... diff --git a/cups/api-array.header b/cups/api-array.header deleted file mode 100644 index 557833e5..00000000 --- a/cups/api-array.header +++ /dev/null @@ -1,32 +0,0 @@ - - -

Array API

- -
- - - - - - - - - - - - - - - - -
Headercups/array.h
Library-lcups
See AlsoProgramming: Introduction to CUPS Programming
diff --git a/cups/api-array.shtml b/cups/api-array.shtml deleted file mode 100644 index 374ef5bf..00000000 --- a/cups/api-array.shtml +++ /dev/null @@ -1,194 +0,0 @@ - - -

Overview

- -

The CUPS array API provides a high-performance generic array container. -The contents of the array container can be sorted and the container itself is -designed for optimal speed and memory usage under a wide variety of conditions. -Sorted arrays use a binary search algorithm from the last found or inserted -element to quickly find matching elements in the array. Arrays created with the -optional hash function can often find elements with a single lookup. The -cups_array_t type is used when -referring to a CUPS array.

- -

The CUPS scheduler (cupsd) and many of the CUPS API -functions use the array API to efficiently manage large lists of -data.

- -

Managing Arrays

- -

Arrays are created using either the -cupsArrayNew, -cupsArrayNew2, or -cupsArrayNew3 functions. The -first function creates a new array with the specified callback function -and user data pointer:

- -
-#include <cups/array.h>
-
-static int compare_func(void *first, void *second, void *user_data);
-
-void *user_data;
-cups_array_t *array = cupsArrayNew(compare_func, user_data);
-
- -

The comparison function (type -cups_arrayfunc_t) is called -whenever an element is added to the array and can be NULL to -create an unsorted array. The function returns -1 if the first element should -come before the second, 0 if the first and second elements should have the same -ordering, and 1 if the first element should come after the second.

- -

The "user_data" pointer is passed to your comparison function. Pass -NULL if you do not need to associate the elements in your array -with additional information.

- -

The cupsArrayNew2 function adds -two more arguments to support hashed lookups, which can potentially provide -instantaneous ("O(1)") lookups in your array:

- -
-#include <cups/array.h>
-
-#define HASH_SIZE 512 /* Size of hash table */
-
-static int compare_func(void *first, void *second, void *user_data);
-static int hash_func(void *element, void *user_data);
-
-void *user_data;
-cups_array_t *hash_array = cupsArrayNew2(compare_func, user_data, hash_func, HASH_SIZE);
-
- -

The hash function (type -cups_ahash_func_t) should return a -number from 0 to (hash_size-1) that (hopefully) uniquely identifies the -element and is called whenever you look up an element in the array with -cupsArrayFind. The hash size is -only limited by available memory, but generally should not be larger than -16384 to realize any performance improvement.

- -

The cupsArrayNew3 function adds -copy and free callbacks to support basic memory management of elements:

- -
-#include <cups/array.h>
-
-#define HASH_SIZE 512 /* Size of hash table */
-
-static int compare_func(void *first, void *second, void *user_data);
-static void *copy_func(void *element, void *user_data);
-static void free_func(void *element, void *user_data);
-static int hash_func(void *element, void *user_data);
-
-void *user_data;
-cups_array_t *array = cupsArrayNew3(compare_func, user_data, NULL, 0, copy_func, free_func);
-
-cups_array_t *hash_array = cupsArrayNew3(compare_func, user_data, hash_func, HASH_SIZE, copy_func, free_func);
-
- -

Once you have created the array, you add elements using the -cupsArrayAdd -cupsArrayInsert functions. -The first function adds an element to the array, adding the new element -after any elements that have the same order, while the second inserts the -element before others with the same order. For unsorted arrays, -cupsArrayAdd appends the element to -the end of the array while -cupsArrayInsert inserts the -element at the beginning of the array. For example, the following code -creates a sorted array of character strings:

- -
-#include <cups/array.h>
-
-/* Use strcmp() to compare strings - it will ignore the user_data pointer */
-cups_array_t *array = cupsArrayNew((cups_array_func_t)strcmp, NULL);
-
-/* Add four strings to the array */
-cupsArrayAdd(array, "One Fish");
-cupsArrayAdd(array, "Two Fish");
-cupsArrayAdd(array, "Red Fish");
-cupsArrayAdd(array, "Blue Fish");
-
- -

Elements are removed using the -cupsArrayRemove function, for -example:

- -
-#include <cups/array.h>
-
-/* Use strcmp() to compare strings - it will ignore the user_data pointer */
-cups_array_t *array = cupsArrayNew((cups_array_func_t)strcmp, NULL);
-
-/* Add four strings to the array */
-cupsArrayAdd(array, "One Fish");
-cupsArrayAdd(array, "Two Fish");
-cupsArrayAdd(array, "Red Fish");
-cupsArrayAdd(array, "Blue Fish");
-
-/* Remove "Red Fish" */
-cupsArrayRemove(array, "Red Fish");
-
- -

Finally, you free the memory used by the array using the -cupsArrayDelete function. All -of the memory for the array and hash table (if any) is freed, however CUPS -does not free the elements unless you provide copy and free functions.

- -

Finding and Enumerating Elements

- -

CUPS provides several functions to find and enumerate elements in an -array. Each one sets or updates a "current index" into the array, such that -future lookups will start where the last one left off:

- -
-
cupsArrayFind
-
Returns the first matching element.
-
cupsArrayFirst
-
Returns the first element in the array.
-
cupsArrayIndex
-
Returns the Nth element in the array, starting at 0.
-
cupsArrayLast
-
Returns the last element in the array.
-
cupsArrayNext
-
Returns the next element in the array.
-
cupsArrayPrev
-
Returns the previous element in the array.
-
- -

Each of these functions returns NULL when there is no -corresponding element. For example, a simple for loop using the -cupsArrayFirst and -cupsArrayNext functions will -enumerate all of the strings in our previous example:

- -
-#include <cups/array.h>
-
-/* Use strcmp() to compare strings - it will ignore the user_data pointer */
-cups_array_t *array = cupsArrayNew((cups_array_func_t)strcmp, NULL);
-
-/* Add four strings to the array */
-cupsArrayAdd(array, "One Fish");
-cupsArrayAdd(array, "Two Fish");
-cupsArrayAdd(array, "Red Fish");
-cupsArrayAdd(array, "Blue Fish");
-
-/* Show all of the strings in the array */
-char *s;
-for (s = (char *)cupsArrayFirst(array); s != NULL; s = (char *)cupsArrayNext(array))
-  puts(s);
-
diff --git a/cups/api-cups.header b/cups/api-cups.header deleted file mode 100644 index 23b3794d..00000000 --- a/cups/api-cups.header +++ /dev/null @@ -1,38 +0,0 @@ - - -

CUPS API

- -
- - - - - - - - - - - - - - - - -
Headercups/cups.h
Library-lcups
See AlsoProgramming: Introduction to CUPS Programming
- Programming: Array API
- Programming: File and Directory APIs
- Programming: Filter and Backend Programming
- Programming: HTTP and IPP APIs
- Programming: PPD API
- Programming: Raster API
diff --git a/cups/api-cups.shtml b/cups/api-cups.shtml deleted file mode 100644 index 918efe77..00000000 --- a/cups/api-cups.shtml +++ /dev/null @@ -1,441 +0,0 @@ - - -

Overview

- -

The CUPS API provides the convenience functions needed to support -applications, filters, printer drivers, and backends that need to interface -with the CUPS scheduler.

- -

Clients and Servers

- -

CUPS is based on the Internet Printing Protocol ("IPP"), which allows -clients (applications) to communicate with a server (the scheduler) to get a -list of printers, send print jobs, and so forth. You identify which server -you want to communicate with using a pointer to the opaque structure -http_t. All of the examples in this document use the -CUPS_HTTP_DEFAULT constant, referring to the default connection -to the scheduler. The HTTP and IPP -APIs document provides more information on server connections.

- -

Printers and Classes

- -

Printers and classes (collections of printers) are accessed through -the cups_dest_t structure which -includes the name (name), instance (instance - -a way of selecting certain saved options/settings), and the options and -attributes associated with that destination (num_options and -options). Destinations are created using the -cupsGetDests function and freed -using the cupsFreeDests function. -The cupsGetDest function finds a -specific destination for printing:

- -
-#include <cups/cups.h>
-
-cups_dest_t *dests;
-int num_dests = cupsGetDests(&dests);
-cups_dest_t *dest = cupsGetDest("name", NULL, num_dests, dests);
-
-/* do something with dest */
-
-cupsFreeDests(num_dests, dests);
-
- -

Passing NULL to -cupsGetDest for the destination name -will return the default destination. Similarly, passing a NULL -instance will return the default instance for that destination.

- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Table 1: Printer Attributes
Attribute NameDescription
"auth-info-required"The type of authentication required for printing to this - destination: "none", "username,password", "domain,username,password", - or "negotiate" (Kerberos)
"printer-info"The human-readable description of the destination such as "My - Laser Printer".
"printer-is-accepting-jobs""true" if the destination is accepting new jobs, "false" if - not.
"printer-is-shared""true" if the destination is being shared with other computers, - "false" if not.
"printer-location"The human-readable location of the destination such as "Lab 4".
"printer-make-and-model"The human-readable make and model of the destination such as "HP - LaserJet 4000 Series".
"printer-state""3" if the destination is idle, "4" if the destination is printing - a job, and "5" if the destination is stopped.
"printer-state-change-time"The UNIX time when the destination entered the current state.
"printer-state-reasons"Additional comma-delimited state keywords for the destination - such as "media-tray-empty-error" and "toner-low-warning".
"printer-type"The cups_printer_t - value associated with the destination.
- -

Options

- -

Options are stored in arrays of -cups_option_t structures. Each -option has a name (name) and value (value) -associated with it. The cups_dest_t -num_options and options members contain the -default options for a particular destination, along with several informational -attributes about the destination as shown in Table 1. -The cupsGetOption function gets -the value for the named option. For example, the following code lists the -available destinations and their human-readable descriptions:

- -
-#include <cups/cups.h>
-
-cups_dest_t *dests;
-int num_dests = cupsGetDests(&dests);
-cups_dest_t *dest;
-int i;
-const char *value;
-
-for (i = num_dests, dest = dests; i > 0; i --, dest ++)
-  if (dest->instance == NULL)
-  {
-    value = cupsGetOption("printer-info", dest->num_options, dest->options);
-    printf("%s (%s)\n", dest->name, value ? value : "no description");
-  }
-
-cupsFreeDests(num_dests, dests);
-
- -

You can create your own option arrays using the -cupsAddOption function, which -adds a single named option to an array:

- -
-#include <cups/cups.h>
-
-int num_options = 0;
-cups_option_t *options = NULL;
-
-/* The returned num_options value is updated as needed */
-num_options = cupsAddOption("first", "value", num_options, &options);
-
-/* This adds a second option value */
-num_options = cupsAddOption("second", "value", num_options, &options);
-
-/* This replaces the first option we added */
-num_options = cupsAddOption("first", "new value", num_options, &options);
-
- -

Use a for loop to copy the options from a destination:

- -
-#include <cups/cups.h>
-
-int i;
-int num_options = 0;
-cups_option_t *options = NULL;
-cups_dest_t *dest;
-
-for (i = 0; i < dest->num_options; i ++)
-  num_options = cupsAddOption(dest->options[i].name, dest->options[i].value,
-                              num_options, &options);
-
- -

Use the cupsFreeOptions -function to free the options array when you are done using it:

- -
-cupsFreeOptions(num_options, options);
-
- -

Print Jobs

- -

Print jobs are identified by a locally-unique job ID number from 1 to -231-1 and have options and one or more files for printing to a -single destination. The cupsPrintFile -function creates a new job with one file. The following code prints the CUPS -test page file:

- -
-#include <cups/cups.h>
-
-cups_dest_t *dest;
-int num_options;
-cups_option_t *options;
-int job_id;
-
-/* Print a single file */
-job_id = cupsPrintFile(dest->name, "/usr/share/cups/data/testprint.ps",
-                        "Test Print", num_options, options);
-
- -

The cupsPrintFiles function -creates a job with multiple files. The files are provided in a -char * array:

- -
-#include <cups/cups.h>
-
-cups_dest_t *dest;
-int num_options;
-cups_option_t *options;
-int job_id;
-char *files[3] = { "file1.pdf", "file2.pdf", "file3.pdf" };
-
-/* Print three files */
-job_id = cupsPrintFiles(dest->name, 3, files, "Test Print", num_options, options);
-
- -

Finally, the cupsCreateJob -function creates a new job with no files in it. Files are added using the -cupsStartDocument, -cupsWriteRequestData, -and cupsFinishDocument functions. -The following example creates a job with 10 text files for printing:

- -
-#include <cups/cups.h>
-
-cups_dest_t *dest;
-int num_options;
-cups_option_t *options;
-int job_id;
-int i;
-char buffer[1024];
-
-/* Create the job */
-job_id = cupsCreateJob(CUPS_HTTP_DEFAULT, dest->name, "10 Text Files",
-                       num_options, options);
-
-/* If the job is created, add 10 files */
-if (job_id > 0)
-{
-  for (i = 1; i <= 10; i ++)
-  {
-    snprintf(buffer, sizeof(buffer), "file%d.txt", i);
-
-    cupsStartDocument(CUPS_HTTP_DEFAULT, dest->name, job_id, buffer,
-                      CUPS_FORMAT_TEXT, i == 10);
-
-    snprintf(buffer, sizeof(buffer),
-             "File %d\n"
-             "\n"
-             "One fish,\n"
-             "Two fish,\n
-             "Red fish,\n
-             "Blue fish\n", i);
-
-    /* cupsWriteRequestData can be called as many times as needed */
-    cupsWriteRequestData(CUPS_HTTP_DEFAULT, buffer, strlen(buffer));
-
-    cupsFinishDocument(CUPS_HTTP_DEFAULT, dest->name);
-  }
-}
-
- -

Once you have created a job, you can monitor its status using the -cupsGetJobs function, which returns -an array of cups_job_t structures. -Each contains the job ID (id), destination name -(dest), title (title), and other information -associated with the job. The job array is freed using the -cupsFreeJobs function. The following -example monitors a specific job ID, showing the current job state once every -5 seconds until the job is completed:

- -
-#include <cups/cups.h>
-
-cups_dest_t *dest;
-int job_id;
-int num_jobs;
-cups_job_t *jobs;
-int i;
-ipp_jstate_t job_state = IPP_JOB_PENDING;
-
-while (job_state < IPP_JOB_STOPPED)
-{
-  /* Get my jobs (1) with any state (-1) */
-  num_jobs = cupsGetJobs(&jobs, dest->name, 1, -1);
-
-  /* Loop to find my job */
-  job_state = IPP_JOB_COMPLETED;
-
-  for (i = 0; i < num_jobs; i ++)
-    if (jobs[i].id == job_id)
-    {
-      job_state = jobs[i].state;
-      break;
-    }
-
-  /* Free the job array */
-  cupsFreeJobs(num_jobs, jobs);
-
-  /* Show the current state */
-  switch (job_state)
-  {
-    case IPP_JOB_PENDING :
-        printf("Job %d is pending.\n", job_id);
-        break;
-    case IPP_JOB_HELD :
-        printf("Job %d is held.\n", job_id);
-        break;
-    case IPP_JOB_PROCESSING :
-        printf("Job %d is processing.\n", job_id);
-        break;
-    case IPP_JOB_STOPPED :
-        printf("Job %d is stopped.\n", job_id);
-        break;
-    case IPP_JOB_CANCELED :
-        printf("Job %d is canceled.\n", job_id);
-        break;
-    case IPP_JOB_ABORTED :
-        printf("Job %d is aborted.\n", job_id);
-        break;
-    case IPP_JOB_COMPLETED :
-        printf("Job %d is completed.\n", job_id);
-        break;
-  }
-
-  /* Sleep if the job is not finished */
-  if (job_state < IPP_JOB_STOPPED)
-    sleep(5);
-}
-
- -

To cancel a job, use the -cupsCancelJob function with the -job ID:

- -
-#include <cups/cups.h>
-
-cups_dest_t *dest;
-int job_id;
-
-cupsCancelJob(dest->name, job_id);
-
- -

Error Handling

- -

If any of the CUPS API printing functions returns an error, the reason for -that error can be found by calling the -cupsLastError and -cupsLastErrorString functions. -cupsLastError returns the last IPP -error code -(ipp_status_t) -that was encountered, while -cupsLastErrorString returns -a (localized) human-readable string that can be shown to the user. For example, -if any of the job creation functions returns a job ID of 0, you can use -cupsLastErrorString to show -the reason why the job could not be created:

- -
-#include <cups/cups.h>
-
-int job_id;
-
-if (job_id == 0)
-  puts(cupsLastErrorString());
-
- -

Passwords and Authentication

- -

CUPS supports authentication of any request, including submission of print -jobs. The default mechanism for getting the username and password is to use the -login user and a password from the console.

- -

To support other types of applications, in particular Graphical User -Interfaces ("GUIs"), the CUPS API provides functions to set the default -username and to register a callback function that returns a password string.

- -

The cupsSetPasswordCB -function is used to set a password callback in your program. Only one -function can be used at any time.

- -

The cupsSetUser function sets the -current username for authentication. This function can be called by your -password callback function to change the current username as needed.

- -

The following example shows a simple password callback that gets a -username and password from the user:

- -
-#include <cups/cups.h>
-
-const char *
-my_password_cb(const char *prompt)
-{
-  char	user[65];
-
-
-  puts(prompt);
-
-  /* Get a username from the user */
-  printf("Username: ");
-  if (fgets(user, sizeof(user), stdin) == NULL)
-    return (NULL);
-
-  /* Strip the newline from the string and set the user */
-  user[strlen(user) - 1] = '\0';
-
-  cupsSetUser(user);
-
-  /* Use getpass() to ask for the password... */
-  return (getpass("Password: "));
-}
-
-cupsSetPasswordCB(my_password_cb);
-
- -

Similarly, a GUI could display the prompt string in a window with input -fields for the username and password. The username should default to the -string returned by the cupsUser -function.

diff --git a/cups/api-filedir.header b/cups/api-filedir.header deleted file mode 100644 index 87744eed..00000000 --- a/cups/api-filedir.header +++ /dev/null @@ -1,34 +0,0 @@ - - -

File and Directory APIs

- -
- - - - - - - - - - - - - - - - -
Headerscups/file.h
- cups/dir.h
Library-lcups
See AlsoProgramming: Introduction to CUPS Programming
- Programming: CUPS API
diff --git a/cups/api-filedir.shtml b/cups/api-filedir.shtml deleted file mode 100644 index 8fdbee64..00000000 --- a/cups/api-filedir.shtml +++ /dev/null @@ -1,29 +0,0 @@ - - -

Overview

- -

The CUPS file and directory APIs provide portable interfaces -for manipulating files and listing files and directories. Unlike -stdio FILE streams, the cupsFile functions -allow you to open more than 256 files at any given time. They -also manage the platform-specific details of locking, large file -support, line endings (CR, LF, or CR LF), and reading and writing -files using Flate ("gzip") compression. Finally, you can also -connect, read from, and write to network connections using the -cupsFile functions.

- -

The cupsDir functions manage the platform-specific -details of directory access/listing and provide a convenient way -to get both a list of files and the information (permissions, -size, timestamp, etc.) for each of those files.

diff --git a/cups/api-httpipp.header b/cups/api-httpipp.header deleted file mode 100644 index cbede8f6..00000000 --- a/cups/api-httpipp.header +++ /dev/null @@ -1,37 +0,0 @@ - - -

HTTP and IPP APIs

- -
- - - - - - - - - - - - - - - - -
Headerscups/cups.h
- cups/http.h
- cups/ipp.h
Library-lcups
See AlsoProgramming: Introduction to CUPS Programming
- Programming: CUPS API
- References: CUPS Implementation of IPP
diff --git a/cups/api-httpipp.shtml b/cups/api-httpipp.shtml deleted file mode 100644 index 33bf5ad3..00000000 --- a/cups/api-httpipp.shtml +++ /dev/null @@ -1,315 +0,0 @@ - - -

Overview

- -

The CUPS HTTP and IPP APIs provide low-level access to the HTTP and IPP -protocols and CUPS scheduler. They are typically used by monitoring and -administration programs to perform specific functions not supported by the -high-level CUPS API functions.

- -

The HTTP APIs use an opaque structure called -http_t to manage connections to -a particular HTTP or IPP server. The -httpConnectEncrypt function is -used to create an instance of this structure for a particular server. -The constant CUPS_HTTP_DEFAULT can be used with all of the -cups functions to refer to the default CUPS server - the functions -create a per-thread http_t as needed.

- -

The IPP APIs use two opaque structures for requests (messages sent to the CUPS scheduler) and responses (messages sent back to your application from the scheduler). The ipp_t type holds a complete request or response and is allocated using the ippNew or ippNewRequest functions and freed using the ippDelete function.

- -

The second opaque structure is called ipp_attribute_t and holds a single IPP attribute which consists of a group tag (ippGetGroupTag), a value type tag (ippGetValueTag), the attribute name (ippGetName), and 1 or more values (ippGetCount, ippGetBoolean, ippGetCollection, ippGetDate, ippGetInteger, ippGetRange, ippGetResolution, and ippGetString). Attributes are added to an ipp_t pointer using one of the ippAdd functions. For example, use ippAddString to add the "printer-uri" and "requesting-user-name" string attributes to a request:

- -
-ipp_t *request = ippNewRequest(IPP_GET_JOBS);
-
-ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
-             NULL, "ipp://localhost/printers/");
-ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
-             NULL, cupsUser());
-
- -

Once you have created an IPP request, use the cups functions to send the request to and read the response from the server. For example, the cupsDoRequest function can be used for simple query operations that do not involve files:

- -
-#include <cups/cups.h>
-
-
-ipp_t *get_jobs(void)
-{
-  ipp_t *request = ippNewRequest(IPP_GET_JOBS);
-
-  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
-               NULL, "ipp://localhost/printers/");
-  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
-               NULL, cupsUser());
-
-  return (cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/"));
-}
-
- -

The cupsDoRequest function frees the request and returns an IPP response or NULL pointer if the request could not be sent to the server. Once you have a response from the server, you can either use the ippFindAttribute and ippFindNextAttribute functions to find specific attributes, for example:

- -
-ipp_t *response;
-ipp_attribute_t *attr;
-
-attr = ippFindAttribute(response, "printer-state", IPP_TAG_ENUM);
-
- -

You can also walk the list of attributes with a simple for loop like this:

- -
-ipp_t *response;
-ipp_attribute_t *attr;
-
-for (attr = ippFirstAttribute(response); attr != NULL; attr = ippNextAttribute(response))
-  if (ippGetName(attr) == NULL)
-    puts("--SEPARATOR--");
-  else
-    puts(ippGetName(attr));
-
- -

The for loop approach is normally used when collecting attributes for multiple objects (jobs, printers, etc.) in a response. Attributes with NULL names indicate a separator between the attributes of each object. For example, the following code will list the jobs returned from our previous get_jobs example code:

- -
-ipp_t *response = get_jobs();
-
-if (response != NULL)
-{
-  ipp_attribute_t *attr;
-  const char *attrname;
-  int job_id = 0;
-  const char *job_name = NULL;
-  const char *job_originating_user_name = NULL;
-
-  puts("Job ID  Owner             Title");
-  puts("------  ----------------  ---------------------------------");
-
-  for (attr = ippFirstAttribute(response); attr != NULL; attr = ippNextAttribute(response))
-  {
-   /* Attributes without names are separators between jobs */
-    attrname = ippGetName(attr);
-    if (attrname == NULL)
-    {
-      if (job_id > 0)
-      {
-        if (job_name == NULL)
-          job_name = "(withheld)";
-
-        if (job_originating_user_name == NULL)
-          job_originating_user_name = "(withheld)";
-
-        printf("%5d  %-16s  %s\n", job_id, job_originating_user_name, job_name);
-      }
-
-      job_id = 0;
-      job_name = NULL;
-      job_originating_user_name = NULL;
-      continue;
-    }
-    else if (!strcmp(attrname, "job-id") && ippGetValueTag(attr) == IPP_TAG_INTEGER)
-      job_id = ippGetInteger(attr, 0);
-    else if (!strcmp(attrname, "job-name") && ippGetValueTag(attr) == IPP_TAG_NAME)
-      job_name = ippGetString(attr, 0, NULL);
-    else if (!strcmp(attrname, "job-originating-user-name") &&
-             ippGetValueTag(attr) == IPP_TAG_NAME)
-      job_originating_user_name = ippGetString(attr, 0, NULL);
-  }
-
-  if (job_id > 0)
-  {
-    if (job_name == NULL)
-      job_name = "(withheld)";
-
-    if (job_originating_user_name == NULL)
-      job_originating_user_name = "(withheld)";
-
-    printf("%5d  %-16s  %s\n", job_id, job_originating_user_name, job_name);
-  }
-}
-
- -

Creating URI Strings

- -

To ensure proper encoding, the -httpAssembleURIf function must be -used to format a "printer-uri" string for all printer-based requests:

- -
-const char *name = "Foo";
-char uri[1024];
-ipp_t *request;
-
-httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL, cupsServer(),
-                 ippPort(), "/printers/%s", name);
-ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
-
- -

Sending Requests with Files

- -

The cupsDoFileRequest and -cupsDoIORequest functions are -used for requests involving files. The -cupsDoFileRequest function -attaches the named file to a request and is typically used when sending a print -file or changing a printer's PPD file:

- -
-const char *filename = "/usr/share/cups/data/testprint.ps";
-const char *name = "Foo";
-char uri[1024];
-char resource[1024];
-ipp_t *request = ippNewRequest(IPP_PRINT_JOB);
-ipp_t *response;
-
-/* Use httpAssembleURIf for the printer-uri string */
-httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL, cupsServer(),
-                 ippPort(), "/printers/%s", name);
-ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
-ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
-             NULL, cupsUser());
-ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "job-name",
-             NULL, "testprint.ps");
-
-/* Use snprintf for the resource path */
-snprintf(resource, sizeof(resource), "/printers/%s", name);
-
-response = cupsDoFileRequest(CUPS_HTTP_DEFAULT, request, resource, filename);
-
- -

The cupsDoIORequest function -optionally attaches a file to the request and optionally saves a file in the -response from the server. It is used when using a pipe for the request -attachment or when using a request that returns a file, currently only -CUPS_GET_DOCUMENT and CUPS_GET_PPD. For example, -the following code will download the PPD file for the sample HP LaserJet -printer driver:

- -
-char tempfile[1024];
-int tempfd;
-ipp_t *request = ippNewRequest(CUPS_GET_PPD);
-ipp_t *response;
-
-ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "ppd-name",
-             NULL, "laserjet.ppd");
-
-tempfd = cupsTempFd(tempfile, sizeof(tempfile));
-
-response = cupsDoIORequest(CUPS_HTTP_DEFAULT, request, "/", -1, tempfd);
-
- -

The example passes -1 for the input file descriptor to specify -that no file is to be attached to the request. The PPD file attached to the -response is written to the temporary file descriptor we created using the -cupsTempFd function.

- -

Asynchronous Request Processing

- -

The cupsSendRequest and -cupsGetResponse support -asynchronous communications with the server. Unlike the other request -functions, the IPP request is not automatically freed, so remember to -free your request with the ippDelete -function.

- -

File data is attached to the request using the -cupsWriteRequestData -function, while file data returned from the server is read using the -cupsReadResponseData -function. We can rewrite the previous CUPS_GET_PPD example -to use the asynchronous functions quite easily:

- -
-char tempfile[1024];
-int tempfd;
-ipp_t *request = ippNewRequest(CUPS_GET_PPD);
-ipp_t *response;
-
-ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "ppd-name",
-             NULL, "laserjet.ppd");
-
-tempfd = cupsTempFd(tempfile, sizeof(tempfile));
-
-if (cupsSendRequest(CUPS_HTTP_DEFAULT, request, "/") == HTTP_CONTINUE)
-{
-  response = cupsGetResponse(CUPS_HTTP_DEFAULT, "/");
-
-  if (response != NULL)
-  {
-    ssize_t bytes;
-    char buffer[8192];
-
-    while ((bytes = cupsReadResponseData(CUPS_HTTP_DEFAULT, buffer, sizeof(buffer))) > 0)
-      write(tempfd, buffer, bytes);
-  }
-}
-
-/* Free the request! */
-ippDelete(request);
-
- -

The cupsSendRequest function -returns the initial HTTP request status, typically either -HTTP_CONTINUE or HTTP_UNAUTHORIZED. The latter status -is returned when the request requires authentication of some sort. The -cupsDoAuthentication function -must be called when your see HTTP_UNAUTHORIZED and the request -re-sent. We can add authentication support to our example code by using a -do ... while loop:

- -
-char tempfile[1024];
-int tempfd;
-ipp_t *request = ippNewRequest(CUPS_GET_PPD);
-ipp_t *response;
-http_status_t status;
-
-ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "ppd-name",
-             NULL, "laserjet.ppd");
-
-tempfd = cupsTempFd(tempfile, sizeof(tempfile));
-
-/* Loop for authentication */
-do
-{
-  status = cupsSendRequest(CUPS_HTTP_DEFAULT, request, "/");
-
-  if (status == HTTP_UNAUTHORIZED)
-  {
-    /* Try to authenticate, break out of the loop if that fails */
-    if (cupsDoAuthentication(CUPS_HTTP_DEFAULT, "POST", "/"))
-      break;
-  }
-}
-while (status != HTTP_CONTINUE && status != HTTP_UNAUTHORIZED);
-
-if (status == HTTP_CONTINUE)
-{
-  response = cupsGetResponse(CUPS_HTTP_DEFAULT, "/");
-
-  if (response != NULL)
-  {
-    ssize_t bytes;
-    char buffer[8192];
-
-    while ((bytes = cupsReadResponseData(CUPS_HTTP_DEFAULT, buffer, sizeof(buffer))) > 0)
-      write(tempfd, buffer, bytes);
-  }
-}
-
-/* Free the request! */
-ippDelete(request);
-
diff --git a/cups/api-ppd.shtml b/cups/api-ppd.shtml index 50c48500..49409462 100644 --- a/cups/api-ppd.shtml +++ b/cups/api-ppd.shtml @@ -1,7 +1,7 @@