From: msweet Date: Thu, 11 Dec 2008 01:40:30 +0000 (+0000) Subject: Merge changes from CUPS 1.4svn-r8177 (tentative CUPS 1.4b2) X-Git-Tag: release-1.6.3~124 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=426c6a595994436a6780205e27098a8eef94d786;p=thirdparty%2Fcups.git Merge changes from CUPS 1.4svn-r8177 (tentative CUPS 1.4b2) git-svn-id: svn+ssh://src.apple.com/svn/cups/easysw/current@1090 a1ca3aef-8c08-0410-bb20-df032aa958be --- diff --git a/CHANGES.txt b/CHANGES.txt index 7bf8ca79d4..a1190f7c75 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,9 +1,17 @@ -CHANGES.txt - 2008-12-08 +CHANGES.txt - 2008-12-10 ------------------------ CHANGES IN CUPS V1.4b2 - Documentation updates (STR #2983, STR #2998, STR #3021) + - The cupsGetPPD* APIs now create symlinks to local PPD files + rather than copying them whenever possible. + - Various performance optimizations in the string pool, dests, and + options implementations. + - The cupsGetDests* APIs now return the marker and printer-commands + attributes. + - Side-channel SNMP lookups would not work when cupsSNMPSupplies + was set to False in the PPD file. - Localized the device descriptions for the SCSI, serial, and network backends (STR #3014) - Added a Spanish localization (STR #3015) diff --git a/backend/ipp.c b/backend/ipp.c index b06aba7755..78b3ddb3bb 100644 --- a/backend/ipp.c +++ b/backend/ipp.c @@ -102,7 +102,8 @@ main(int argc, /* I - Number of command-line args */ sep; /* Separator character */ int snmp_fd, /* SNMP socket */ start_count, /* Page count via SNMP at start */ - page_count; /* Page count via SNMP */ + page_count, /* Page count via SNMP */ + have_supplies; /* Printer supports supply levels? */ int num_files; /* Number of files to print */ char **files, /* Files to print */ *filename; /* Pointer to single filename */ @@ -630,19 +631,10 @@ main(int argc, /* I - Number of command-line args */ */ if ((snmp_fd = _cupsSNMPOpen(http->hostaddr->addr.sa_family)) >= 0) - { - if (backendSNMPSupplies(snmp_fd, http->hostaddr, &start_count, NULL)) - { - /* - * No, close it... - */ - - _cupsSNMPClose(snmp_fd); - snmp_fd = -1; - } - } + have_supplies = !backendSNMPSupplies(snmp_fd, http->hostaddr, &start_count, + NULL); else - start_count = 0; + have_supplies = start_count = 0; /* * Build a URI for the printer and fill the standard IPP attributes for @@ -1258,7 +1250,7 @@ main(int argc, /* I - Number of command-line args */ * Collect the final page count as needed... */ - if (snmp_fd >= 0 && + if (have_supplies && !backendSNMPSupplies(snmp_fd, http->hostaddr, &page_count, NULL) && page_count > start_count) fprintf(stderr, "PAGE: total %d\n", page_count - start_count); diff --git a/backend/lpd.c b/backend/lpd.c index 4f9b06f87e..b39394c611 100644 --- a/backend/lpd.c +++ b/backend/lpd.c @@ -637,7 +637,8 @@ lpd_queue(const char *hostname, /* I - Host to connect to */ char addrname[256]; /* Address name */ http_addrlist_t *addrlist, /* Address list */ *addr; /* Socket address */ - int snmp_fd; /* SNMP socket */ + int snmp_fd, /* SNMP socket */ + have_supplies; /* Printer supports supply levels? */ int copy; /* Copies written */ time_t start_time; /* Time of first connect */ int recoverable; /* Recoverable error shown? */ @@ -884,17 +885,9 @@ lpd_queue(const char *hostname, /* I - Host to connect to */ */ if ((snmp_fd = _cupsSNMPOpen(addr->addr.addr.sa_family)) >= 0) - { - if (backendSNMPSupplies(snmp_fd, &(addr->addr), NULL, NULL)) - { - /* - * No, close it... - */ - - _cupsSNMPClose(snmp_fd); - snmp_fd = -1; - } - } + have_supplies = !backendSNMPSupplies(snmp_fd, &(addr->addr), NULL, NULL); + else + have_supplies = 0; /* * Check for side-channel requests... @@ -1186,7 +1179,7 @@ lpd_queue(const char *hostname, /* I - Host to connect to */ * Collect the final supply levels as needed... */ - if (snmp_fd >= 0) + if (have_supplies) backendSNMPSupplies(snmp_fd, &(addr->addr), NULL, NULL); /* diff --git a/backend/socket.c b/backend/socket.c index ec6368d942..09137f9580 100644 --- a/backend/socket.c +++ b/backend/socket.c @@ -88,7 +88,8 @@ main(int argc, /* I - Number of command-line arguments (6 or 7) */ char addrname[256]; /* Address name */ int snmp_fd, /* SNMP socket */ start_count, /* Page count via SNMP at start */ - page_count; /* Page count via SNMP */ + page_count, /* Page count via SNMP */ + have_supplies; /* Printer supports supply levels? */ ssize_t tbytes; /* Total number of bytes written */ #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET) struct sigaction action; /* Actions for POSIX signals */ @@ -372,18 +373,11 @@ main(int argc, /* I - Number of command-line arguments (6 or 7) */ if ((snmp_fd = _cupsSNMPOpen(addr->addr.addr.sa_family)) >= 0) { - if (backendSNMPSupplies(snmp_fd, &(addr->addr), &start_count, NULL)) - { - /* - * No, close it... - */ - - _cupsSNMPClose(snmp_fd); - snmp_fd = -1; - } + have_supplies = !backendSNMPSupplies(snmp_fd, &(addr->addr), &start_count, + NULL); } else - start_count = 0; + have_supplies = start_count = 0; /* * Print everything... @@ -441,7 +435,7 @@ main(int argc, /* I - Number of command-line arguments (6 or 7) */ * Collect the final page count as needed... */ - if (snmp_fd >= 0 && + if (have_supplies && !backendSNMPSupplies(snmp_fd, &(addr->addr), &page_count, NULL) && page_count > start_count) fprintf(stderr, "PAGE: total %d\n", page_count - start_count); diff --git a/cups/Makefile b/cups/Makefile index 9a0a80638e..8674389640 100644 --- a/cups/Makefile +++ b/cups/Makefile @@ -544,7 +544,7 @@ apihelp: mxmldoc --section "Programming" --title "CUPS API" \ --css ../doc/cups-printable.css \ --header api-cups.header --intro api-cups.shtml \ - cups.h dest.c language.c notify.c \ + cups.h adminutil.c dest.c language.c notify.c \ options.c tempfile.c usersys.c \ util.c >../doc/help/api-cups.html mxmldoc --section "Programming" --title "File and Directory APIs" \ @@ -585,7 +585,7 @@ framedhelp: --section "Programming" --title "CUPS API" \ --css ../doc/cups-printable.css \ --header api-cups.header --intro api-cups.shtml \ - cups.h dest.c language.c notify.c \ + cups.h adminutil.c dest.c language.c notify.c \ options.c tempfile.c usersys.c \ util.c mxmldoc --framed api-filedir \ @@ -626,7 +626,7 @@ docsets: ../tools/makedocset --docset org.cups.cups.docset \ --title "CUPS API" \ --header api-cups.header --intro api-cups.shtml \ - cups.h dest.c language.c notify.c \ + cups.h adminutil.c dest.c language.c notify.c \ options.c tempfile.c usersys.c \ util.c ../tools/makedocset --docset org.cups.filedir.docset \ diff --git a/cups/adminutil.c b/cups/adminutil.c index 4d4eba8f1d..8ef12ad5bb 100644 --- a/cups/adminutil.c +++ b/cups/adminutil.c @@ -75,6 +75,8 @@ static void write_option(cups_file_t *dstfp, int order, /* * 'cupsAdminCreateWindowsPPD()' - Create the Windows PPD file for a printer. + * + * @since CUPS 1.2/Mac OS X 10.5@ */ char * /* O - PPD file or NULL */ @@ -401,6 +403,8 @@ cupsAdminCreateWindowsPPD( /* * 'cupsAdminExportSamba()' - Export a printer to Samba. + * + * @since CUPS 1.2/Mac OS X 10.5@ */ int /* O - 1 on success, 0 on failure */ @@ -850,7 +854,7 @@ cupsAdminExportSamba( * The returned settings should be freed with cupsFreeOptions() when * you are done with them. * - * @since CUPS 1.3@ + * @since CUPS 1.3/Mac OS X 10.5@ */ int /* O - 1 on success, 0 on failure */ @@ -1193,7 +1197,7 @@ _cupsAdminGetServerSettings( /* * 'cupsAdminSetServerSettings()' - Set settings on the server. * - * @since CUPS 1.3@ + * @since CUPS 1.3/Mac OS X 10.5@ */ int /* O - 1 on success, 0 on failure */ diff --git a/cups/array.c b/cups/array.c index ae45eeba09..4f40d7f4a3 100644 --- a/cups/array.c +++ b/cups/array.c @@ -102,7 +102,7 @@ static int cups_array_find(cups_array_t *a, void *e, int prev, int *rdiff); * appended at the end of the run of identical elements. For unsorted arrays, * the element is appended to the end of the array. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ int /* O - 1 on success, 0 on failure */ @@ -136,7 +136,7 @@ cupsArrayAdd(cups_array_t *a, /* I - Array */ * The caller is responsible for freeing the memory used by the * elements themselves. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ void @@ -165,7 +165,7 @@ cupsArrayClear(cups_array_t *a) /* I - Array */ /* * 'cupsArrayCount()' - Get the number of elements in the array. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ int /* O - Number of elements */ @@ -192,7 +192,7 @@ cupsArrayCount(cups_array_t *a) /* I - Array */ * The current element is undefined until you call @link cupsArrayFind@, * @link cupsArrayFirst@, or @link cupsArrayIndex@, or @link cupsArrayLast@. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ void * /* O - Element */ @@ -222,7 +222,7 @@ cupsArrayCurrent(cups_array_t *a) /* I - Array */ * The caller is responsible for freeing the memory used by the * elements themselves. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ void @@ -253,7 +253,7 @@ cupsArrayDelete(cups_array_t *a) /* I - Array */ /* * 'cupsArrayDup()' - Duplicate the array. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ cups_array_t * /* O - Duplicate array */ @@ -319,7 +319,7 @@ cupsArrayDup(cups_array_t *a) /* I - Array */ /* * 'cupsArrayFind()' - Find an element in the array. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ void * /* O - Element found or @code NULL@ */ @@ -414,7 +414,7 @@ cupsArrayFind(cups_array_t *a, /* I - Array */ /* * 'cupsArrayFirst()' - Get the first element in the array. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ void * /* O - First element or @code NULL@ if the array is empty */ @@ -443,7 +443,7 @@ cupsArrayFirst(cups_array_t *a) /* I - Array */ * The current element is undefined until you call @link cupsArrayFind@, * @link cupsArrayFirst@, or @link cupsArrayIndex@, or @link cupsArrayLast@. * - * @since CUPS 1.3@ + * @since CUPS 1.3/Mac OS X 10.5@ */ int /* O - Index of the current element, starting at 0 */ @@ -459,7 +459,7 @@ cupsArrayGetIndex(cups_array_t *a) /* I - Array */ /* * 'cupsArrayGetInsert()' - Get the index of the last inserted element. * - * @since CUPS 1.3@ + * @since CUPS 1.3/Mac OS X 10.5@ */ int /* O - Index of the last inserted element, starting at 0 */ @@ -475,7 +475,7 @@ cupsArrayGetInsert(cups_array_t *a) /* I - Array */ /* * 'cupsArrayIndex()' - Get the N-th element in the array. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ void * /* O - N-th element or @code NULL@ */ @@ -498,7 +498,7 @@ cupsArrayIndex(cups_array_t *a, /* I - Array */ * inserted at the beginning of the run of identical elements. For unsorted * arrays, the element is inserted at the beginning of the array. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ int /* O - 0 on failure, 1 on success */ @@ -528,7 +528,7 @@ cupsArrayInsert(cups_array_t *a, /* I - Array */ /* * 'cupsArrayLast()' - Get the last element in the array. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ void * /* O - Last element or @code NULL@ if the array is empty */ @@ -559,7 +559,7 @@ cupsArrayLast(cups_array_t *a) /* I - Array */ * data pointer argument can safely be omitted when not required so functions * like @code strcmp@ can be used for sorted string arrays. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ cups_array_t * /* O - Array */ @@ -581,7 +581,7 @@ cupsArrayNew(cups_array_func_t f, /* I - Comparison function or @code NULL@ for * The hash function ("h") is used to implement cached lookups with the * specified hash size ("hsize"). * - * @since CUPS 1.3@ + * @since CUPS 1.3/Mac OS X 10.5@ */ cups_array_t * /* O - Array */ @@ -636,7 +636,7 @@ cupsArrayNew2(cups_array_func_t f, /* I - Comparison function or @code NULL@ fo * @link cupsArrayFirst@, or @link cupsArrayIndex@, or @link cupsArrayLast@ * to set the current element. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ void * /* O - Next element or @code NULL@ */ @@ -669,7 +669,7 @@ cupsArrayNext(cups_array_t *a) /* I - Array */ * @link cupsArrayFirst@, or @link cupsArrayIndex@, or @link cupsArrayLast@ * to set the current element. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ void * /* O - Previous element or @code NULL@ */ @@ -702,7 +702,7 @@ cupsArrayPrev(cups_array_t *a) /* I - Array */ * The caller is responsible for freeing the memory used by the * removed element. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ int /* O - 1 on success, 0 on failure */ @@ -764,7 +764,7 @@ cupsArrayRemove(cups_array_t *a, /* I - Array */ /* * 'cupsArrayRestore()' - Reset the current element to the last @link cupsArraySave@. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ void * /* O - New current element */ @@ -795,7 +795,7 @@ cupsArrayRestore(cups_array_t *a) /* I - Array */ * * The save/restore stack is guaranteed to be at least 32 elements deep. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ int /* O - 1 on success, 0 on failure */ @@ -817,7 +817,7 @@ cupsArraySave(cups_array_t *a) /* I - Array */ /* * 'cupsArrayUserData()' - Return the user data for an array. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ void * /* O - User data */ @@ -833,7 +833,7 @@ cupsArrayUserData(cups_array_t *a) /* I - Array */ /* * 'cups_array_add()' - Insert or append an element to the array... * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ static int /* O - 1 on success, 0 on failure */ @@ -1003,8 +1003,6 @@ cups_array_add(cups_array_t *a, /* I - Array */ /* * 'cups_array_find()' - Find an element in the array... - * - * @since CUPS 1.2@ */ static int /* O - Index of match */ diff --git a/cups/attr.c b/cups/attr.c index 903e4970d7..f7b1a76b82 100644 --- a/cups/attr.c +++ b/cups/attr.c @@ -32,7 +32,7 @@ /* * 'ppdFindAttr()' - Find the first matching attribute. * - * @since CUPS 1.1.19@ + * @since CUPS 1.1.19/Mac OS X 10.3@ */ ppd_attr_t * /* O - Attribute or @code NULL@ if not found */ @@ -89,7 +89,7 @@ ppdFindAttr(ppd_file_t *ppd, /* I - PPD file data */ /* * 'ppdFindNextAttr()' - Find the next matching attribute. * - * @since CUPS 1.1.19@ + * @since CUPS 1.1.19/Mac OS X 10.3@ */ ppd_attr_t * /* O - Attribute or @code NULL@ if not found */ diff --git a/cups/auth.c b/cups/auth.c index d97029e137..332301c816 100644 --- a/cups/auth.c +++ b/cups/auth.c @@ -79,7 +79,7 @@ static int cups_local_auth(http_t *http); * This function should be called in response to a @code HTTP_UNAUTHORIZED@ * status, prior to resubmitting your request. * - * @since CUPS 1.1.20@ + * @since CUPS 1.1.20/Mac OS X 10.4@ */ int /* O - 0 on success, -1 on error */ diff --git a/cups/backchannel.c b/cups/backchannel.c index c2b53bb493..23caace808 100644 --- a/cups/backchannel.c +++ b/cups/backchannel.c @@ -50,7 +50,7 @@ static void cups_setup(fd_set *set, struct timeval *tval, * parameter controls how many seconds to wait for the data - use 0.0 to * return immediately if there is no data, -1.0 to wait for data indefinitely. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ ssize_t /* O - Bytes read or -1 on error */ @@ -101,7 +101,7 @@ cupsBackChannelRead(char *buffer, /* I - Buffer to read into */ * 0.0 to return immediately if the data cannot be written, -1.0 to wait * indefinitely. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ ssize_t /* O - Bytes written or -1 on error */ diff --git a/cups/backend.c b/cups/backend.c index ca4fad2f3c..fa7d056458 100644 --- a/cups/backend.c +++ b/cups/backend.c @@ -44,6 +44,8 @@ static void quote_string(const char *s); * function returns the device URI passed in the DEVICE_URI environment * variable or the device URI passed in argv[0], whichever is found * first. + * + * @since CUPS 1.2/Mac OS X 10.5@ */ const char * /* O - Device URI or @code NULL@ */ @@ -72,6 +74,8 @@ cupsBackendDeviceURI(char **argv) /* I - Command-line arguments */ * This function writes a single device line to stdout for a backend. * It handles quoting of special characters in the device-make-and-model, * device-info, device-id, and device-location strings. + * + * @since CUPS 1.4@ */ void diff --git a/cups/cups.h b/cups/cups.h index 03ca440546..6d3ca29a46 100644 --- a/cups/cups.h +++ b/cups/cups.h @@ -59,7 +59,7 @@ extern "C" { * Constants... */ -# define CUPS_VERSION 1.0399 +# define CUPS_VERSION 1.0400 # define CUPS_VERSION_MAJOR 1 # define CUPS_VERSION_MINOR 4 # define CUPS_VERSION_PATCH -1 @@ -112,11 +112,11 @@ enum cups_ptype_e /**** Printer type/capability bit constants ****/ CUPS_PRINTER_DEFAULT = 0x20000, /* Default printer on network */ CUPS_PRINTER_FAX = 0x40000, /* Fax queue */ CUPS_PRINTER_REJECTING = 0x80000, /* Printer is rejecting jobs */ - CUPS_PRINTER_DELETE = 0x100000, /* Delete printer @since CUPS 1.2@ */ - CUPS_PRINTER_NOT_SHARED = 0x200000, /* Printer is not shared @since CUPS 1.2@ */ - CUPS_PRINTER_AUTHENTICATED = 0x400000,/* Printer requires authentication @since CUPS 1.2@ */ - CUPS_PRINTER_COMMANDS = 0x800000, /* Printer supports maintenance commands @since CUPS 1.2@ */ - CUPS_PRINTER_DISCOVERED = 0x1000000, /* Printer was automatically discovered and added @since CUPS 1.3@ */ + CUPS_PRINTER_DELETE = 0x100000, /* Delete printer @since CUPS 1.2/Mac OS X 10.5@ */ + CUPS_PRINTER_NOT_SHARED = 0x200000, /* Printer is not shared @since CUPS 1.2/Mac OS X 10.5@ */ + CUPS_PRINTER_AUTHENTICATED = 0x400000,/* Printer requires authentication @since CUPS 1.2/Mac OS X 10.5@ */ + CUPS_PRINTER_COMMANDS = 0x800000, /* Printer supports maintenance commands @since CUPS 1.2/Mac OS X 10.5@ */ + CUPS_PRINTER_DISCOVERED = 0x1000000, /* Printer was automatically discovered and added @since CUPS 1.3/Mac OS X 10.5@ */ CUPS_PRINTER_OPTIONS = 0x6fffc /* ~(CLASS | REMOTE | IMPLICIT | DEFAULT | FAX | REJECTING | DELETE | NOT_SHARED | AUTHENTICATED | COMMANDS | DISCOVERED) @private@ */ }; diff --git a/cups/custom.c b/cups/custom.c index 92bdcdc905..7ca3a900ad 100644 --- a/cups/custom.c +++ b/cups/custom.c @@ -42,7 +42,7 @@ /* * 'ppdFindCustomOption()' - Find a custom option. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ ppd_coption_t * /* O - Custom option or NULL */ @@ -63,7 +63,7 @@ ppdFindCustomOption(ppd_file_t *ppd, /* I - PPD file */ /* * 'ppdFindCustomParam()' - Find a parameter for a custom option. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ ppd_cparam_t * /* O - Custom parameter or NULL */ @@ -84,7 +84,7 @@ ppdFindCustomParam(ppd_coption_t *opt, /* I - Custom option */ /* * 'ppdFirstCustomParam()' - Return the first parameter for a custom option. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ ppd_cparam_t * /* O - Custom parameter or NULL */ @@ -100,7 +100,7 @@ ppdFirstCustomParam(ppd_coption_t *opt) /* I - Custom option */ /* * 'ppdNextCustomParam()' - Return the next parameter for a custom option. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ ppd_cparam_t * /* O - Custom parameter or NULL */ diff --git a/cups/dest.c b/cups/dest.c index 75513d87a3..5cdf5975d5 100644 --- a/cups/dest.c +++ b/cups/dest.c @@ -31,15 +31,21 @@ * server. * cupsSetDests2() - Save the list of destinations for the specified * server. - * appleCopyLocations() - Get the location history array. + * appleCopyLocations() - Copy the location history array. * appleCopyNetwork() - Get the network ID for the current location. * appleGetDefault() - Get the default printer for this location. + * appleGetPaperSize() - Get the default paper size. * appleGetPrinter() - Get a printer from the history array. * appleSetDefault() - Set the default printer for this location. * appleUseLastPrinter() - Get the default printer preference value. + * cups_add_dest() - Add a destination to the array. + * cups_compare_dests() - Compare two destinations. + * cups_find_dest() - Find a destination using a binary search. * cups_get_default() - Get the default destination from an lpoptions file. * cups_get_dests() - Get destinations from a file. * cups_get_sdests() - Get destinations from a server. + * cups_make_string() - Make a comma-separated string of values from an IPP + * attribute. */ /* @@ -60,6 +66,7 @@ # include # include # include +# define kDefaultPaperIDKey CFSTR("DefaultPaperID") # define kLocationHistoryArrayKey CFSTR("kLocationHistoryArrayKeyTMP") # define kLocationNetworkKey CFSTR("kLocationNetworkKey") # define kLocationPrinterIDKey CFSTR("kLocationPrinterIDKey") @@ -76,18 +83,27 @@ static CFArrayRef appleCopyLocations(void); static CFStringRef appleCopyNetwork(void); static char *appleGetDefault(char *name, int namesize); +static char *appleGetPaperSize(char *name, int namesize); static CFStringRef appleGetPrinter(CFArrayRef locations, CFStringRef network, CFIndex *locindex); static void appleSetDefault(const char *name); static int appleUseLastPrinter(void); #endif /* __APPLE__ */ +static cups_dest_t *cups_add_dest(const char *name, const char *instance, + int *num_dests, cups_dest_t **dests); +static int cups_compare_dests(cups_dest_t *a, cups_dest_t *b); +static int cups_find_dest(const char *name, const char *instance, + int num_dests, cups_dest_t *dests, int prev, + int *rdiff); static char *cups_get_default(const char *filename, char *namebuf, - size_t namesize, const char **instance); + size_t namesize, const char **instance); static int cups_get_dests(const char *filename, const char *match_name, const char *match_inst, int num_dests, cups_dest_t **dests); static int cups_get_sdests(http_t *http, ipp_op_t op, const char *name, int num_dests, cups_dest_t **dests); +static char *cups_make_string(ipp_attribute_t *attr, char *buffer, + size_t bufsize); /* @@ -114,77 +130,46 @@ cupsAddDest(const char *name, /* I - Destination name */ int i; /* Looping var */ cups_dest_t *dest; /* Destination pointer */ cups_dest_t *parent; /* Parent destination */ - cups_option_t *option; /* Current option */ + cups_option_t *doption, /* Current destination option */ + *poption; /* Current parent option */ if (!name || !dests) return (0); - if (cupsGetDest(name, instance, num_dests, *dests)) - return (num_dests); - - /* - * Add new destination... - */ - - if (num_dests == 0) - dest = malloc(sizeof(cups_dest_t)); - else - dest = realloc(*dests, sizeof(cups_dest_t) * (num_dests + 1)); - - if (dest == NULL) - return (num_dests); - - *dests = dest; - - /* - * Find where to insert the destination... - */ - - for (i = num_dests; i > 0; i --, dest ++) - if (strcasecmp(name, dest->name) < 0) - break; - else if (!instance && dest->instance) - break; - else if (!strcasecmp(name, dest->name) && - instance && dest->instance && - strcasecmp(instance, dest->instance) < 0) - break; - - if (i > 0) - memmove(dest + 1, dest, i * sizeof(cups_dest_t)); + if (!cupsGetDest(name, instance, num_dests, *dests)) + { + if (instance && + (parent = cupsGetDest(name, NULL, num_dests, *dests)) == NULL) + return (num_dests); - /* - * Initialize the destination... - */ + dest = cups_add_dest(name, instance, &num_dests, dests); - dest->name = _cupsStrAlloc(name); - dest->is_default = 0; - dest->num_options = 0; - dest->options = (cups_option_t *)0; + if (instance && parent && parent->num_options > 0) + { + /* + * Copy options from parent... + */ - if (!instance) - dest->instance = NULL; - else - { - /* - * Copy options from the primary instance... - */ + dest->options = calloc(sizeof(cups_option_t), parent->num_options); - dest->instance = _cupsStrAlloc(instance); + if (dest->options) + { + dest->num_options = parent->num_options; - if ((parent = cupsGetDest(name, NULL, num_dests + 1, *dests)) != NULL) - { - for (i = parent->num_options, option = parent->options; - i > 0; - i --, option ++) - dest->num_options = cupsAddOption(option->name, option->value, - dest->num_options, - &(dest->options)); + for (i = dest->num_options, doption = dest->options, + poption = parent->options; + i > 0; + i --, doption ++, poption ++) + { + doption->name = _cupsStrRetain(poption->name); + doption->value = _cupsStrRetain(poption->value); + } + } } } - return (num_dests + 1); + return (num_dests); } @@ -228,7 +213,8 @@ cupsGetDest(const char *name, /* I - Destination name or @code NULL@ for the d int num_dests, /* I - Number of destinations */ cups_dest_t *dests) /* I - Destinations */ { - int comp; /* Result of comparison */ + int diff, /* Result of comparison */ + match; /* Matching index */ if (num_dests <= 0 || !dests) @@ -255,21 +241,10 @@ cupsGetDest(const char *name, /* I - Destination name or @code NULL@ for the d * Lookup name and optionally the instance... */ - while (num_dests > 0) - { - if ((comp = strcasecmp(name, dests->name)) < 0) - return (NULL); - else if (comp == 0) - { - if ((!instance && !dests->instance) || - (instance != NULL && dests->instance != NULL && - !strcasecmp(instance, dests->instance))) - return (dests); - } + match = cups_find_dest(name, instance, num_dests, dests, -1, &diff); - num_dests --; - dests ++; - } + if (!diff) + return (dests + match); } return (NULL); @@ -282,7 +257,10 @@ cupsGetDest(const char *name, /* I - Destination name or @code NULL@ for the d * Starting with CUPS 1.2, the returned list of destinations include the * printer-info, printer-is-accepting-jobs, printer-is-shared, * printer-make-and-model, printer-state, printer-state-change-time, - * printer-state-reasons, and printer-type attributes as options. + * printer-state-reasons, and printer-type attributes as options. CUPS 1.4 + * adds the marker-change-time, marker-colors, marker-high-levels, + * marker-levels, marker-low-levels, marker-message, marker-names, + * marker-types, and printer-commands attributes as well. * * Use the @link cupsFreeDests@ function to free the destination list and * the @link cupsGetDest@ function to find a particular destination. @@ -301,12 +279,15 @@ cupsGetDests(cups_dest_t **dests) /* O - Destinations */ * Starting with CUPS 1.2, the returned list of destinations include the * printer-info, printer-is-accepting-jobs, printer-is-shared, * printer-make-and-model, printer-state, printer-state-change-time, - * printer-state-reasons, and printer-type attributes as options. + * printer-state-reasons, and printer-type attributes as options. CUPS 1.4 + * adds the marker-change-time, marker-colors, marker-high-levels, + * marker-levels, marker-low-levels, marker-message, marker-names, + * marker-types, and printer-commands attributes as well. * * Use the @link cupsFreeDests@ function to free the destination list and * the @link cupsGetDest@ function to find a particular destination. * - * @since CUPS 1.1.21@ + * @since CUPS 1.1.21/Mac OS X 10.4@ */ int /* O - Number of destinations */ @@ -348,8 +329,6 @@ cupsGetDests2(http_t *http, /* I - Connection to server or @code CUPS_HTTP_ */ num_dests = cups_get_sdests(http, CUPS_GET_PRINTERS, NULL, num_dests, dests); - if (cupsLastError() < IPP_REDIRECTION_OTHER_SITE) - num_dests = cups_get_sdests(http, CUPS_GET_CLASSES, NULL, num_dests, dests); if (cupsLastError() >= IPP_REDIRECTION_OTHER_SITE) { @@ -613,7 +592,7 @@ cupsGetNamedDest(http_t *http, /* I - Connection to server or @code CUPS_HTT * @link cupsSetDests@ or @link cupsSetDests2@ functions to save the new * options for the user. * - * @since CUPS 1.3@ + * @since CUPS 1.3/Mac OS X 10.5@ */ int /* O - New number of destinations */ @@ -659,7 +638,7 @@ cupsRemoveDest(const char *name, /* I - Destination name */ /* * 'cupsSetDefaultDest()' - Set the default destination. * - * @since CUPS 1.3@ + * @since CUPS 1.3/Mac OS X 10.5@ */ void @@ -714,7 +693,7 @@ cupsSetDests(int num_dests, /* I - Number of destinations */ * This function saves the destinations to /etc/cups/lpoptions when run * as root and ~/.cups/lpoptions when run as a normal user. * - * @since CUPS 1.1.21@ + * @since CUPS 1.1.21/Mac OS X 10.4@ */ int /* O - 0 on success, -1 on error */ @@ -751,7 +730,12 @@ cupsSetDests2(http_t *http, /* I - Connection to server or @code CUPS_HTTP_ */ num_temps = cups_get_sdests(http, CUPS_GET_PRINTERS, NULL, 0, &temps); - num_temps = cups_get_sdests(http, CUPS_GET_CLASSES, NULL, num_temps, &temps); + + if (cupsLastError() >= IPP_REDIRECTION_OTHER_SITE) + { + cupsFreeDests(num_temps, temps); + return (-1); + } /* * Figure out which file to write to... @@ -1082,6 +1066,35 @@ appleGetDefault(char *name, /* I - Name buffer */ } +/* + * 'appleGetPaperSize()' - Get the default paper size. + */ + +static char * /* O - Default paper size */ +appleGetPaperSize(char *name, /* I - Paper size name buffer */ + int namesize) /* I - Size of buffer */ +{ + CFStringRef defaultPaperID; /* Default paper ID */ + + + defaultPaperID = CFPreferencesCopyAppValue(kDefaultPaperIDKey, + kPMPrintingPreferences); + if (!defaultPaperID || + !CFStringGetCString(defaultPaperID, name, namesize, + kCFStringEncodingUTF8)) + name[0] = '\0'; + else if (!strncmp(name, "na-", 3)) + _cups_strcpy(name, name + 3); + else if (!strncmp(name, "iso-", 4)) + _cups_strcpy(name, name + 4); + + if (defaultPaperID) + CFRelease(defaultPaperID); + + return (name); +} + + /* * 'appleGetPrinter()' - Get a printer from the history array. */ @@ -1253,6 +1266,200 @@ appleUseLastPrinter(void) #endif /* __APPLE__ */ +/* + * 'cups_add_dest()' - Add a destination to the array. + * + * Unlike cupsAddDest(), this function does not check for duplicates. + */ + +static cups_dest_t * /* O - New destination */ +cups_add_dest(const char *name, /* I - Name of destination */ + const char *instance, /* I - Instance or NULL */ + int *num_dests, /* IO - Number of destinations */ + cups_dest_t **dests) /* IO - Destinations */ +{ + int insert, /* Insertion point */ + diff; /* Result of comparison */ + cups_dest_t *dest; /* Destination pointer */ + + + /* + * Add new destination... + */ + + if (*num_dests == 0) + dest = malloc(sizeof(cups_dest_t)); + else + dest = realloc(*dests, sizeof(cups_dest_t) * (*num_dests + 1)); + + if (!dest) + return (NULL); + + *dests = dest; + + /* + * Find where to insert the destination... + */ + + if (*num_dests == 0) + insert = 0; + else + { + insert = cups_find_dest(name, instance, *num_dests, *dests, *num_dests - 1, + &diff); + + if (diff > 0) + insert ++; + } + + /* + * Move the array elements as needed... + */ + + if (insert < *num_dests) + memmove(*dests + insert + 1, *dests + insert, + (*num_dests - insert) * sizeof(cups_dest_t)); + + (*num_dests) ++; + + /* + * Initialize the destination... + */ + + dest = *dests + insert; + dest->name = _cupsStrAlloc(name); + dest->instance = _cupsStrAlloc(instance); + dest->is_default = 0; + dest->num_options = 0; + dest->options = (cups_option_t *)0; + + return (dest); +} + + +/* + * 'cups_compare_dests()' - Compare two destinations. + */ + +static int /* O - Result of comparison */ +cups_compare_dests(cups_dest_t *a, /* I - First destination */ + cups_dest_t *b) /* I - Second destination */ +{ + int diff; /* Difference */ + + + if ((diff = strcasecmp(a->name, b->name)) != 0) + return (diff); + else if (a->instance && b->instance) + return (strcasecmp(a->instance, b->instance)); + else + return ((a->instance && !b->instance) - (!a->instance && b->instance)); +} + + +/* + * 'cups_find_dest()' - Find a destination using a binary search. + */ + +static int /* O - Index of match */ +cups_find_dest(const char *name, /* I - Destination name */ + const char *instance, /* I - Instance or NULL */ + int num_dests, /* I - Number of destinations */ + cups_dest_t *dests, /* I - Destinations */ + int prev, /* I - Previous index */ + int *rdiff) /* O - Difference of match */ +{ + int left, /* Low mark for binary search */ + right, /* High mark for binary search */ + current, /* Current index */ + diff; /* Result of comparison */ + cups_dest_t key; /* Search key */ + + + key.name = (char *)name; + key.instance = (char *)instance; + + if (prev >= 0) + { + /* + * Start search on either side of previous... + */ + + if ((diff = cups_compare_dests(&key, dests + prev)) == 0 || + (diff < 0 && prev == 0) || + (diff > 0 && prev == (num_dests - 1))) + { + *rdiff = diff; + return (prev); + } + else if (diff < 0) + { + /* + * Start with previous on right side... + */ + + left = 0; + right = prev; + } + else + { + /* + * Start wih previous on left side... + */ + + left = prev; + right = num_dests - 1; + } + } + else + { + /* + * Start search in the middle... + */ + + left = 0; + right = num_dests - 1; + } + + do + { + current = (left + right) / 2; + diff = cups_compare_dests(&key, dests + current); + + if (diff == 0) + break; + else if (diff < 0) + right = current; + else + left = current; + } + while ((right - left) > 1); + + if (diff != 0) + { + /* + * Check the last 1 or 2 elements... + */ + + if ((diff = cups_compare_dests(&key, dests + left)) <= 0) + current = left; + else + { + diff = cups_compare_dests(&key, dests + right); + current = right; + } + } + + /* + * Return the closest destination and the difference... + */ + + *rdiff = diff; + + return (current); +} + + /* * 'cups_get_default()' - Get the default destination from an lpoptions file. */ @@ -1500,21 +1707,13 @@ cups_get_sdests(http_t *http, /* I - Connection to server or CUPS_HTTP_DEFA ipp_t *request, /* IPP Request */ *response; /* IPP Response */ ipp_attribute_t *attr; /* Current attribute */ - int accepting, /* printer-is-accepting-jobs attribute */ - shared, /* printer-is-shared attribute */ - state, /* printer-state attribute */ - change_time, /* printer-state-change-time attribute */ - type; /* printer-type attribute */ - const char *info, /* printer-info attribute */ - *location, /* printer-location attribute */ - *make_model, /* printer-make-and-model attribute */ - *printer_name; /* printer-name attribute */ - char uri[1024], /* printer-uri value */ - job_sheets[1024], /* job-sheets-default attribute */ - auth_info_req[1024], /* auth-info-required attribute */ - reasons[1024]; /* printer-state-reasons attribute */ + const char *printer_name; /* printer-name attribute */ + char uri[1024]; /* printer-uri value */ int num_options; /* Number of options */ cups_option_t *options; /* Options */ +#ifdef __APPLE__ + char media_default[41]; /* Default paper size */ +#endif /* __APPLE__ */ char optname[1024], /* Option name */ value[2048], /* Option value */ *ptr; /* Pointer into name/value */ @@ -1522,6 +1721,18 @@ cups_get_sdests(http_t *http, /* I - Connection to server or CUPS_HTTP_DEFA { "auth-info-required", "job-sheets-default", + "marker-change-time", + "marker-colors", + "marker-high-levels", + "marker-levels", + "marker-low-levels", + "marker-message", + "marker-names", + "marker-types", +#ifdef __APPLE__ + "media-supported", +#endif /* __APPLE__ */ + "printer-commands", "printer-info", "printer-is-accepting-jobs", "printer-is-shared", @@ -1536,13 +1747,22 @@ cups_get_sdests(http_t *http, /* I - Connection to server or CUPS_HTTP_DEFA }; +#ifdef __APPLE__ + /* + * Get the default paper size... + */ + + appleGetPaperSize(media_default, sizeof(media_default)); +#endif /* __APPLE__ */ + /* - * Build a CUPS_GET_PRINTERS or CUPS_GET_CLASSES request, which require - * the following attributes: + * Build a CUPS_GET_PRINTERS or IPP_GET_PRINTER_ATTRIBUTES request, which + * require the following attributes: * * attributes-charset * attributes-natural-language * requesting-user-name + * printer-uri [for IPP_GET_PRINTER_ATTRIBUTES] */ request = ippNewRequest(op); @@ -1584,90 +1804,69 @@ cups_get_sdests(http_t *http, /* I - Connection to server or CUPS_HTTP_DEFA * Pull the needed attributes from this printer... */ - accepting = 0; - change_time = 0; - info = NULL; - location = NULL; - make_model = NULL; printer_name = NULL; num_options = 0; options = NULL; - shared = 1; - state = IPP_PRINTER_IDLE; - type = CUPS_PRINTER_LOCAL; - auth_info_req[0] = '\0'; - job_sheets[0] = '\0'; - reasons[0] = '\0'; - - while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) + for (; attr && attr->group_tag == IPP_TAG_PRINTER; attr = attr->next) { - if (!strcmp(attr->name, "auth-info-required") && - attr->value_tag == IPP_TAG_KEYWORD) - { - strlcpy(auth_info_req, attr->values[0].string.text, - sizeof(auth_info_req)); + if (attr->value_tag != IPP_TAG_INTEGER && + attr->value_tag != IPP_TAG_ENUM && + attr->value_tag != IPP_TAG_BOOLEAN && + attr->value_tag != IPP_TAG_TEXT && + attr->value_tag != IPP_TAG_TEXTLANG && + attr->value_tag != IPP_TAG_NAME && + attr->value_tag != IPP_TAG_NAMELANG && + attr->value_tag != IPP_TAG_KEYWORD && + attr->value_tag != IPP_TAG_RANGE) + continue; - for (i = 1, ptr = auth_info_req + strlen(auth_info_req); - i < attr->num_values; - i ++) - { - snprintf(ptr, sizeof(auth_info_req) - (ptr - auth_info_req), ",%s", - attr->values[i].string.text); - ptr += strlen(ptr); - } - } - else if (!strcmp(attr->name, "job-sheets-default") && - (attr->value_tag == IPP_TAG_KEYWORD || - attr->value_tag == IPP_TAG_NAME)) + if (!strcmp(attr->name, "auth-info-required") || + !strcmp(attr->name, "marker-change-time") || + !strcmp(attr->name, "marker-colors") || + !strcmp(attr->name, "marker-high-levels") || + !strcmp(attr->name, "marker-levels") || + !strcmp(attr->name, "marker-low-levels") || + !strcmp(attr->name, "marker-message") || + !strcmp(attr->name, "marker-names") || + !strcmp(attr->name, "marker-types") || + !strcmp(attr->name, "printer-commands") || + !strcmp(attr->name, "printer-info") || + !strcmp(attr->name, "printer-is-shared") || + !strcmp(attr->name, "printer-make-and-model") || + !strcmp(attr->name, "printer-state") || + !strcmp(attr->name, "printer-state-change-time") || + !strcmp(attr->name, "printer-type") || + !strcmp(attr->name, "printer-is-accepting-jobs") || + !strcmp(attr->name, "printer-location") || + !strcmp(attr->name, "printer-state-reasons")) { - if (attr->num_values == 2) - snprintf(job_sheets, sizeof(job_sheets), "%s,%s", - attr->values[0].string.text, attr->values[1].string.text); - else - strlcpy(job_sheets, attr->values[0].string.text, - sizeof(job_sheets)); - } - else if (!strcmp(attr->name, "printer-info") && - attr->value_tag == IPP_TAG_TEXT) - info = attr->values[0].string.text; - else if (!strcmp(attr->name, "printer-is-accepting-jobs") && - attr->value_tag == IPP_TAG_BOOLEAN) - accepting = attr->values[0].boolean; - else if (!strcmp(attr->name, "printer-is-shared") && - attr->value_tag == IPP_TAG_BOOLEAN) - shared = attr->values[0].boolean; - else if (!strcmp(attr->name, "printer-location") && - attr->value_tag == IPP_TAG_TEXT) - location = attr->values[0].string.text; - else if (!strcmp(attr->name, "printer-make-and-model") && - attr->value_tag == IPP_TAG_TEXT) - make_model = attr->values[0].string.text; + /* + * Add a printer description attribute... + */ + + num_options = cupsAddOption(attr->name, + cups_make_string(attr, value, + sizeof(value)), + num_options, &options); + } + else if (!strcmp(attr->name, "media-supported")) + { + /* + * See if we can set a default media size... + */ + + for (i = 0; i < attr->num_values; i ++) + if (!strcasecmp(media_default, attr->values[i].string.text)) + { + num_options = cupsAddOption("media", media_default, num_options, + &options); + break; + } + } else if (!strcmp(attr->name, "printer-name") && attr->value_tag == IPP_TAG_NAME) printer_name = attr->values[0].string.text; - else if (!strcmp(attr->name, "printer-state") && - attr->value_tag == IPP_TAG_ENUM) - state = attr->values[0].integer; - else if (!strcmp(attr->name, "printer-state-change-time") && - attr->value_tag == IPP_TAG_INTEGER) - change_time = attr->values[0].integer; - else if (!strcmp(attr->name, "printer-state-reasons") && - attr->value_tag == IPP_TAG_KEYWORD) - { - strlcpy(reasons, attr->values[0].string.text, sizeof(reasons)); - for (i = 1, ptr = reasons + strlen(reasons); - i < attr->num_values; - i ++) - { - snprintf(ptr, sizeof(reasons) - (ptr - reasons), ",%s", - attr->values[i].string.text); - ptr += strlen(ptr); - } - } - else if (!strcmp(attr->name, "printer-type") && - attr->value_tag == IPP_TAG_ENUM) - type = attr->values[0].integer; else if (strncmp(attr->name, "notify-", 7) && (attr->value_tag == IPP_TAG_BOOLEAN || attr->value_tag == IPP_TAG_ENUM || @@ -1675,75 +1874,22 @@ cups_get_sdests(http_t *http, /* I - Connection to server or CUPS_HTTP_DEFA attr->value_tag == IPP_TAG_KEYWORD || attr->value_tag == IPP_TAG_NAME || attr->value_tag == IPP_TAG_RANGE) && - strstr(attr->name, "-default")) + (ptr = strstr(attr->name, "-default")) != NULL) { - char *valptr; /* Pointer into attribute value */ - - /* * Add a default option... */ strlcpy(optname, attr->name, sizeof(optname)); - if ((ptr = strstr(optname, "-default")) != NULL) - *ptr = '\0'; - - value[0] = '\0'; - for (i = 0, ptr = value; i < attr->num_values; i ++) - { - if (ptr >= (value + sizeof(value) - 1)) - break; - - if (i) - *ptr++ = ','; - - switch (attr->value_tag) - { - case IPP_TAG_INTEGER : - case IPP_TAG_ENUM : - snprintf(ptr, sizeof(value) - (ptr - value), "%d", - attr->values[i].integer); - break; - - case IPP_TAG_BOOLEAN : - if (attr->values[i].boolean) - strlcpy(ptr, "true", sizeof(value) - (ptr - value)); - else - strlcpy(ptr, "false", sizeof(value) - (ptr - value)); - break; - - case IPP_TAG_RANGE : - if (attr->values[i].range.lower == - attr->values[i].range.upper) - snprintf(ptr, sizeof(value) - (ptr - value), "%d", - attr->values[i].range.lower); - else - snprintf(ptr, sizeof(value) - (ptr - value), "%d-%d", - attr->values[i].range.lower, - attr->values[i].range.upper); - break; - - default : - for (valptr = attr->values[i].string.text; - *valptr && ptr < (value + sizeof(value) - 2);) - { - if (strchr(" \t\n\\\'\"", *valptr)) - *ptr++ = '\\'; - - *ptr++ = *valptr++; - } - - *ptr = '\0'; - break; - } - - ptr += strlen(ptr); - } - - num_options = cupsAddOption(optname, value, num_options, &options); + optname[ptr - attr->name] = '\0'; + + if (strcasecmp(optname, "media") || + !cupsGetOption("media", num_options, options)) + num_options = cupsAddOption(optname, + cups_make_string(attr, value, + sizeof(value)), + num_options, &options); } - - attr = attr->next; } /* @@ -1760,76 +1906,13 @@ cups_get_sdests(http_t *http, /* I - Connection to server or CUPS_HTTP_DEFA continue; } - num_dests = cupsAddDest(printer_name, NULL, num_dests, dests); - - if ((dest = cupsGetDest(printer_name, NULL, num_dests, *dests)) != NULL) + if ((dest = cups_add_dest(printer_name, NULL, &num_dests, dests)) != NULL) { dest->num_options = num_options; dest->options = options; - - num_options = 0; - options = NULL; - - if (auth_info_req[0]) - dest->num_options = cupsAddOption("auth-info-required", auth_info_req, - dest->num_options, - &(dest->options)); - - if (job_sheets[0]) - dest->num_options = cupsAddOption("job-sheets", job_sheets, - dest->num_options, - &(dest->options)); - - if (info) - dest->num_options = cupsAddOption("printer-info", info, - dest->num_options, - &(dest->options)); - - sprintf(value, "%d", accepting); - dest->num_options = cupsAddOption("printer-is-accepting-jobs", value, - dest->num_options, - &(dest->options)); - - sprintf(value, "%d", shared); - dest->num_options = cupsAddOption("printer-is-shared", value, - dest->num_options, - &(dest->options)); - - if (location) - dest->num_options = cupsAddOption("printer-location", - location, dest->num_options, - &(dest->options)); - - if (make_model) - dest->num_options = cupsAddOption("printer-make-and-model", - make_model, dest->num_options, - &(dest->options)); - - sprintf(value, "%d", state); - dest->num_options = cupsAddOption("printer-state", value, - dest->num_options, - &(dest->options)); - - if (change_time) - { - sprintf(value, "%d", change_time); - dest->num_options = cupsAddOption("printer-state-change-time", value, - dest->num_options, - &(dest->options)); - } - - if (reasons[0]) - dest->num_options = cupsAddOption("printer-state-reasons", reasons, - dest->num_options, - &(dest->options)); - - sprintf(value, "%d", type); - dest->num_options = cupsAddOption("printer-type", value, - dest->num_options, - &(dest->options)); } - - cupsFreeOptions(num_options, options); + else + cupsFreeOptions(num_options, options); if (attr == NULL) break; @@ -1846,6 +1929,96 @@ cups_get_sdests(http_t *http, /* I - Connection to server or CUPS_HTTP_DEFA } +/* + * 'cups_make_string()' - Make a comma-separated string of values from an IPP + * attribute. + */ + +static char * /* O - New string */ +cups_make_string( + ipp_attribute_t *attr, /* I - Attribute to convert */ + char *buffer, /* I - Buffer */ + size_t bufsize) /* I - Size of buffer */ +{ + int i; /* Looping var */ + char *ptr, /* Pointer into buffer */ + *end, /* Pointer to end of buffer */ + *valptr; /* Pointer into string attribute */ + + + /* + * Return quickly if we have a single string value... + */ + + if (attr->num_values == 1 && + attr->value_tag != IPP_TAG_INTEGER && + attr->value_tag != IPP_TAG_ENUM && + attr->value_tag != IPP_TAG_BOOLEAN && + attr->value_tag != IPP_TAG_RANGE) + return (attr->values[0].string.text); + + /* + * Copy the values to the string, separating with commas and escaping strings + * as needed... + */ + + end = buffer + bufsize - 1; + + for (i = 0, ptr = buffer; i < attr->num_values && ptr < end; i ++) + { + if (i) + *ptr++ = ','; + + switch (attr->value_tag) + { + case IPP_TAG_INTEGER : + case IPP_TAG_ENUM : + snprintf(ptr, end - ptr + 1, "%d", attr->values[i].integer); + break; + + case IPP_TAG_BOOLEAN : + if (attr->values[i].boolean) + strlcpy(ptr, "true", end - ptr + 1); + else + strlcpy(ptr, "false", end - ptr + 1); + break; + + case IPP_TAG_RANGE : + if (attr->values[i].range.lower == attr->values[i].range.upper) + snprintf(ptr, end - ptr + 1, "%d", attr->values[i].range.lower); + else + snprintf(ptr, end - ptr + 1, "%d-%d", attr->values[i].range.lower, + attr->values[i].range.upper); + break; + + default : + for (valptr = attr->values[i].string.text; + *valptr && ptr < end;) + { + if (strchr(" \t\n\\\'\"", *valptr)) + { + if (ptr >= (end - 1)) + break; + + *ptr++ = '\\'; + } + + *ptr++ = *valptr++; + } + + *ptr = '\0'; + break; + } + + ptr += strlen(ptr); + } + + *ptr = '\0'; + + return (buffer); +} + + /* * End of "$Id: dest.c 7946 2008-09-16 23:27:54Z mike $". */ diff --git a/cups/dir.c b/cups/dir.c index b55cfc8c61..319908f1f5 100644 --- a/cups/dir.c +++ b/cups/dir.c @@ -81,7 +81,7 @@ _cups_dir_time(FILETIME ft) /* I - File time */ /* * 'cupsDirClose()' - Close a directory. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ void @@ -112,7 +112,7 @@ cupsDirClose(cups_dir_t *dp) /* I - Directory pointer */ /* * 'cupsDirOpen()' - Open a directory. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ cups_dir_t * /* O - Directory pointer or @code NULL@ if the directory could not be opened. */ @@ -155,7 +155,7 @@ cupsDirOpen(const char *directory) /* I - Directory name */ /* * 'cupsDirRead()' - Read the next directory entry. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ cups_dentry_t * /* O - Directory entry or @code NULL@ if there are no more */ @@ -215,7 +215,7 @@ cupsDirRead(cups_dir_t *dp) /* I - Directory pointer */ /* * 'cupsDirRewind()' - Rewind to the start of the directory. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ void @@ -265,7 +265,7 @@ struct _cups_dir_s /**** Directory data structure ****/ /* * 'cupsDirClose()' - Close a directory. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ void @@ -292,7 +292,7 @@ cupsDirClose(cups_dir_t *dp) /* I - Directory pointer */ /* * 'cupsDirOpen()' - Open a directory. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ cups_dir_t * /* O - Directory pointer or @code NULL@ if the directory could not be opened. */ @@ -346,7 +346,7 @@ cupsDirOpen(const char *directory) /* I - Directory name */ /* * 'cupsDirRead()' - Read the next directory entry. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ cups_dentry_t * /* O - Directory entry or @code NULL@ when there are no more */ @@ -443,7 +443,7 @@ cupsDirRead(cups_dir_t *dp) /* I - Directory pointer */ /* * 'cupsDirRewind()' - Rewind to the start of the directory. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ void diff --git a/cups/emit.c b/cups/emit.c index f3b32e666b..9b1aeb3aa5 100644 --- a/cups/emit.c +++ b/cups/emit.c @@ -92,7 +92,7 @@ ppdCollect(ppd_file_t *ppd, /* I - PPD file data */ * The choices array should be freed using @code free@ when you are * finished with it. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ int /* O - Number of options marked */ @@ -265,7 +265,7 @@ ppdEmit(ppd_file_t *ppd, /* I - PPD file record */ * * When "limit" is zero, this function is identical to ppdEmit(). * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ int /* O - 0 on success, -1 on failure */ @@ -511,7 +511,7 @@ ppdEmitJCL(ppd_file_t *ppd, /* I - PPD file record */ /* * 'ppdEmitJCLEnd()' - Emit JCLEnd code to a file. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ int /* O - 0 on success, -1 on failure */ @@ -570,7 +570,7 @@ ppdEmitJCLEnd(ppd_file_t *ppd, /* I - PPD file record */ * The return string is allocated on the heap and should be freed using * @code free@ when you are done with it. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ char * /* O - String containing option code or @code NULL@ if there is no option code */ diff --git a/cups/encode.c b/cups/encode.c index 3b737aebd8..19e6aa4e06 100644 --- a/cups/encode.c +++ b/cups/encode.c @@ -77,6 +77,14 @@ static const _ipp_option_t ipp_options[] = { 1, "job-sheets-default", IPP_TAG_NAME, IPP_TAG_PRINTER }, { 0, "job-uuid", IPP_TAG_URI, IPP_TAG_JOB }, { 0, "landscape", IPP_TAG_BOOLEAN, IPP_TAG_JOB }, + { 1, "marker-change-time", IPP_TAG_INTEGER, IPP_TAG_PRINTER }, + { 1, "marker-colors", IPP_TAG_NAME, IPP_TAG_PRINTER }, + { 1, "marker-high-levels", IPP_TAG_INTEGER, IPP_TAG_PRINTER }, + { 1, "marker-levels", IPP_TAG_INTEGER, IPP_TAG_PRINTER }, + { 1, "marker-low-levels", IPP_TAG_INTEGER, IPP_TAG_PRINTER }, + { 0, "marker-message", IPP_TAG_TEXT, IPP_TAG_PRINTER }, + { 1, "marker-names", IPP_TAG_NAME, IPP_TAG_PRINTER }, + { 1, "marker-types", IPP_TAG_KEYWORD, IPP_TAG_PRINTER }, { 1, "media", IPP_TAG_KEYWORD, IPP_TAG_JOB }, { 0, "mirror", IPP_TAG_BOOLEAN, IPP_TAG_JOB }, { 0, "mirror-default", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER }, @@ -115,6 +123,7 @@ static const _ipp_option_t ipp_options[] = { 0, "prettyprint-default", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER }, { 0, "print-quality", IPP_TAG_ENUM, IPP_TAG_JOB }, { 0, "print-quality-default", IPP_TAG_ENUM, IPP_TAG_PRINTER }, + { 1, "printer-commands", IPP_TAG_KEYWORD, IPP_TAG_PRINTER }, { 0, "printer-error-policy", IPP_TAG_NAME, IPP_TAG_PRINTER }, { 0, "printer-info", IPP_TAG_TEXT, IPP_TAG_PRINTER }, { 0, "printer-is-accepting-jobs", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER }, @@ -186,7 +195,7 @@ cupsEncodeOptions(ipp_t *ipp, /* I - Request to add to */ * function multiple times for each group, or use cupsEncodeOptions() * to add the standard groups. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ void @@ -345,15 +354,7 @@ cupsEncodeOptions2( * Copy the name over... */ - if ((attr->name = _cupsStrAlloc(option->name)) == NULL) - { - /* - * Ran out of memory! - */ - - DEBUG_puts("cupsEncodeOptions2: Ran out of memory for name!"); - return; - } + attr->name = _cupsStrRetain(option->name); if (count > 1) { @@ -534,7 +535,9 @@ cupsEncodeOptions2( break; default : - if ((attr->values[j].string.text = _cupsStrAlloc(val)) == NULL) + if (count == 1) + attr->values[0].string.text = _cupsStrRetain(val); + else if ((attr->values[j].string.text = _cupsStrAlloc(val)) == NULL) { /* * Ran out of memory! diff --git a/cups/file.c b/cups/file.c index bbaac6fe0a..0fb212d1f8 100644 --- a/cups/file.c +++ b/cups/file.c @@ -140,7 +140,7 @@ static ssize_t cups_write(cups_file_t *fp, const char *buf, size_t bytes); /* * 'cupsFileClose()' - Close a CUPS file. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ int /* O - 0 on success, -1 on error */ @@ -272,7 +272,7 @@ cupsFileClose(cups_file_t *fp) /* I - CUPS file */ /* * 'cupsFileCompression()' - Return whether a file is compressed. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ int /* O - @code CUPS_FILE_NONE@ or @code CUPS_FILE_GZIP@ */ @@ -285,7 +285,7 @@ cupsFileCompression(cups_file_t *fp) /* I - CUPS file */ /* * 'cupsFileEOF()' - Return the end-of-file status. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ int /* O - 1 on end of file, 0 otherwise */ @@ -304,7 +304,7 @@ cupsFileEOF(cups_file_t *fp) /* I - CUPS file */ * the supplied paths, @code NULL@ is returned. A @code NULL@ path only * matches the current directory. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ const char * /* O - Full path to file or @code NULL@ if not found */ @@ -403,7 +403,7 @@ cupsFileFind(const char *filename, /* I - File to find */ /* * 'cupsFileFlush()' - Flush pending output. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ int /* O - 0 on success, -1 on error */ @@ -451,7 +451,7 @@ cupsFileFlush(cups_file_t *fp) /* I - CUPS file */ /* * 'cupsFileGetChar()' - Get a single character from a file. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ int /* O - Character or -1 on end of file */ @@ -497,7 +497,7 @@ cupsFileGetChar(cups_file_t *fp) /* I - CUPS file */ /* * 'cupsFileGetConf()' - Get a line from a configuration file... * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ char * /* O - Line read or @code NULL@ on end of file or error */ @@ -641,7 +641,7 @@ cupsFileGetConf(cups_file_t *fp, /* I - CUPS file */ * nul-terminated, however you should use the returned length to determine * the number of bytes on the line. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ size_t /* O - Number of bytes on line or 0 on end of file */ @@ -716,7 +716,7 @@ cupsFileGetLine(cups_file_t *fp, /* I - File to read from */ /* * 'cupsFileGets()' - Get a CR and/or LF-terminated line. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ char * /* O - Line read or @code NULL@ on end of file or error */ @@ -798,7 +798,7 @@ cupsFileGets(cups_file_t *fp, /* I - CUPS file */ /* * 'cupsFileLock()' - Temporarily lock access to a file. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ int /* O - 0 on success, -1 on error */ @@ -827,7 +827,7 @@ cupsFileLock(cups_file_t *fp, /* I - CUPS file */ /* * 'cupsFileNumber()' - Return the file descriptor associated with a CUPS file. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ int /* O - File descriptor */ @@ -856,7 +856,7 @@ cupsFileNumber(cups_file_t *fp) /* I - CUPS file */ * connection as needed, generally preferring IPv6 connections when there is * a choice. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ cups_file_t * /* O - CUPS file or @code NULL@ if the file or socket cannot be opened */ @@ -963,7 +963,7 @@ cupsFileOpen(const char *filename, /* I - Name of file */ * supplied which enables Flate compression of the file. Compression is * not supported for the "a" (append) mode. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ cups_file_t * /* O - CUPS file or @code NULL@ if the file could not be opened */ @@ -1075,7 +1075,7 @@ cupsFileOpenFd(int fd, /* I - File descriptor */ /* * 'cupsFilePeekChar()' - Peek at the next character from a file. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ int /* O - Character or -1 on end of file */ @@ -1107,7 +1107,7 @@ cupsFilePeekChar(cups_file_t *fp) /* I - CUPS file */ /* * 'cupsFilePrintf()' - Write a formatted string. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ int /* O - Number of bytes written or -1 on error */ @@ -1204,7 +1204,7 @@ cupsFilePrintf(cups_file_t *fp, /* I - CUPS file */ /* * 'cupsFilePutChar()' - Write a character. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ int /* O - 0 on success, -1 on error */ @@ -1319,7 +1319,7 @@ cupsFilePutConf(cups_file_t *fp, /* I - CUPS file */ * * Like the @code fputs@ function, no newline is appended to the string. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ int /* O - Number of bytes written or -1 on error */ @@ -1383,7 +1383,7 @@ cupsFilePuts(cups_file_t *fp, /* I - CUPS file */ /* * 'cupsFileRead()' - Read from a file. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ ssize_t /* O - Number of bytes read or -1 on error */ @@ -1460,7 +1460,7 @@ cupsFileRead(cups_file_t *fp, /* I - CUPS file */ * 'cupsFileRewind()' - Set the current file position to the beginning of the * file. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ off_t /* O - New file position or -1 on error */ @@ -1532,7 +1532,7 @@ cupsFileRewind(cups_file_t *fp) /* I - CUPS file */ /* * 'cupsFileSeek()' - Seek in a file. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ off_t /* O - New file position or -1 on error */ @@ -1685,7 +1685,7 @@ cupsFileSeek(cups_file_t *fp, /* I - CUPS file */ /* * 'cupsFileStderr()' - Return a CUPS file associated with stderr. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ cups_file_t * /* O - CUPS file */ @@ -1721,7 +1721,7 @@ cupsFileStderr(void) /* * 'cupsFileStdin()' - Return a CUPS file associated with stdin. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ cups_file_t * /* O - CUPS file */ @@ -1751,7 +1751,7 @@ cupsFileStdin(void) /* * 'cupsFileStdout()' - Return a CUPS file associated with stdout. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ cups_file_t * /* O - CUPS file */ @@ -1787,7 +1787,7 @@ cupsFileStdout(void) /* * 'cupsFileTell()' - Return the current file position. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ off_t /* O - File position */ @@ -1803,7 +1803,7 @@ cupsFileTell(cups_file_t *fp) /* I - CUPS file */ /* * 'cupsFileUnlock()' - Unlock access to a file. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ int /* O - 0 on success, -1 on error */ @@ -1833,7 +1833,7 @@ cupsFileUnlock(cups_file_t *fp) /* I - CUPS file */ /* * 'cupsFileWrite()' - Write to a file. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ ssize_t /* O - Number of bytes written or -1 on error */ diff --git a/cups/getputfile.c b/cups/getputfile.c index 31dde6ca7e..c61da916b8 100644 --- a/cups/getputfile.c +++ b/cups/getputfile.c @@ -47,7 +47,7 @@ * * This function returns @code HTTP_OK@ when the file is successfully retrieved. * - * @since CUPS 1.1.20@ + * @since CUPS 1.1.20/Mac OS X 10.4@ */ http_status_t /* O - HTTP status */ @@ -188,7 +188,7 @@ cupsGetFd(http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFA * * This function returns @code HTTP_OK@ when the file is successfully retrieved. * - * @since CUPS 1.1.20@ + * @since CUPS 1.1.20/Mac OS X 10.4@ */ http_status_t /* O - HTTP status */ @@ -256,7 +256,7 @@ cupsGetFile(http_t *http, /* I - Connection to server or @code CUPS_HTTP_DE * This function returns @code HTTP_CREATED@ when the file is stored * successfully. * - * @since CUPS 1.1.20@ + * @since CUPS 1.1.20/Mac OS X 10.4@ */ http_status_t /* O - HTTP status */ @@ -442,7 +442,7 @@ cupsPutFd(http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFA * This function returns @code HTTP_CREATED@ when the file is stored * successfully. * - * @since CUPS 1.1.20@ + * @since CUPS 1.1.20/Mac OS X 10.4@ */ http_status_t /* O - HTTP status */ diff --git a/cups/http-addr.c b/cups/http-addr.c index d25692f622..9a39292eb0 100644 --- a/cups/http-addr.c +++ b/cups/http-addr.c @@ -42,7 +42,7 @@ /* * 'httpAddrAny()' - Check for the "any" address. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ int /* O - 1 if "any", 0 otherwise */ @@ -68,7 +68,7 @@ httpAddrAny(const http_addr_t *addr) /* I - Address to check */ /* * 'httpAddrEqual()' - Compare two addresses. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ int /* O - 1 if equal, 0 if not */ @@ -101,7 +101,7 @@ httpAddrEqual(const http_addr_t *addr1, /* I - First address */ /* * 'httpAddrLength()' - Return the length of the address in bytes. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ int /* O - Length in bytes */ @@ -132,7 +132,7 @@ httpAddrLength(const http_addr_t *addr) /* I - Address */ /* * 'httpAddrLocalhost()' - Check for the local loopback address. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ int /* O - 1 if local host, 0 otherwise */ @@ -171,7 +171,7 @@ httpAddrLocalhost( /* * 'httpAddrLookup()' - Lookup the hostname associated with the address. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ char * /* O - Host name */ @@ -306,7 +306,7 @@ _httpAddrPort(http_addr_t *addr) /* I - Address */ /* * 'httpAddrString()' - Convert an address to a numeric string. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ char * /* O - Numeric address string */ @@ -564,7 +564,7 @@ httpGetHostByName(const char *name) /* I - Hostname or IP address */ * Otherwise, return the FQDN for the local system using both gethostname() * and gethostbyname() to get the local hostname with domain. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ const char * /* O - FQDN for connection or system */ diff --git a/cups/http-addrlist.c b/cups/http-addrlist.c index cee5017d79..b44acc6368 100644 --- a/cups/http-addrlist.c +++ b/cups/http-addrlist.c @@ -36,7 +36,7 @@ /* * 'httpAddrConnect()' - Connect to any of the addresses in the list. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ http_addrlist_t * /* O - Connected address or NULL on failure */ @@ -165,7 +165,7 @@ httpAddrConnect( /* * 'httpAddrFreeList()' - Free an address list. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ void @@ -193,7 +193,7 @@ httpAddrFreeList( /* * 'httpAddrGetList()' - Get a list of addresses for a hostname. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ http_addrlist_t * /* O - List of addresses or NULL */ diff --git a/cups/http-private.h b/cups/http-private.h index ec3f6a84e8..8ffe5a281f 100644 --- a/cups/http-private.h +++ b/cups/http-private.h @@ -3,7 +3,7 @@ * * Private HTTP definitions for the Common UNIX Printing System (CUPS). * - * Copyright 2007 by Apple Inc. + * Copyright 2007-2008 by Apple Inc. * Copyright 1997-2007 by Easy Software Products, all rights reserved. * * These coded instructions, statements, and computer programs are the diff --git a/cups/http-support.c b/cups/http-support.c index 063756926e..a2d227e531 100644 --- a/cups/http-support.c +++ b/cups/http-support.c @@ -129,7 +129,7 @@ static void resolve_callback(DNSServiceRef sdRef, * place of traditional string functions whenever you need to create a * URI string. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ http_uri_status_t /* O - URI status */ @@ -379,7 +379,7 @@ httpAssembleURI( * this function in place of traditional string functions whenever * you need to create a URI string. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ http_uri_status_t /* O - URI status */ @@ -459,7 +459,7 @@ httpDecode64(char *out, /* I - String to write to */ /* * 'httpDecode64_2()' - Base64-decode a string. * - * @since CUPS 1.1.21@ + * @since CUPS 1.1.21/Mac OS X 10.4@ */ char * /* O - Decoded string */ @@ -578,7 +578,7 @@ httpEncode64(char *out, /* I - String to write to */ /* * 'httpEncode64_2()' - Base64-encode a string. * - * @since CUPS 1.1.21@ + * @since CUPS 1.1.21/Mac OS X 10.4@ */ char * /* O - Encoded string */ @@ -687,7 +687,7 @@ httpGetDateString(time_t t) /* I - UNIX time */ /* * 'httpGetDateString2()' - Get a formatted date/time string from a time value. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ const char * /* O - Date/time string */ @@ -804,7 +804,7 @@ httpSeparate(const char *uri, /* I - Universal Resource Identifier */ * * This function is deprecated; use the httpSeparateURI() function instead. * - * @since CUPS 1.1.21@ + * @since CUPS 1.1.21/Mac OS X 10.4@ * @deprecated@ */ @@ -829,7 +829,7 @@ httpSeparate2(const char *uri, /* I - Universal Resource Identifier */ * 'httpSeparateURI()' - Separate a Universal Resource Identifier into its * components. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ http_uri_status_t /* O - Result of separation */ diff --git a/cups/http.c b/cups/http.c index 5c11435a26..439f180f30 100644 --- a/cups/http.c +++ b/cups/http.c @@ -247,7 +247,7 @@ httpCheck(http_t *http) /* I - Connection to server */ /* * 'httpClearCookie()' - Clear the cookie value(s). * - * @since CUPS 1.1.19@ + * @since CUPS 1.1.19/Mac OS X 10.3@ */ void @@ -592,7 +592,7 @@ httpFlush(http_t *http) /* I - Connection to server */ /* * 'httpFlushWrite()' - Flush data in write buffer. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ int /* O - Bytes written or -1 on error */ @@ -637,7 +637,7 @@ httpGet(http_t *http, /* I - Connection to server */ * string to use with httpSetField() for the HTTP_FIELD_AUTHORIZATION * value. * - * @since CUPS 1.3@ + * @since CUPS 1.3/Mac OS X 10.5@ */ char * /* O - Authorization string */ @@ -653,7 +653,7 @@ httpGetAuthString(http_t *http) /* I - Connection to server */ /* * 'httpGetBlocking()' - Get the blocking/non-block state of a connection. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ int /* O - 1 if blocking, 0 if non-blocking */ @@ -666,7 +666,7 @@ httpGetBlocking(http_t *http) /* I - Connection to server */ /* * 'httpGetCookie()' - Get any cookie data from the response. * - * @since CUPS 1.1.19@ + * @since CUPS 1.1.19/Mac OS X 10.3@ */ const char * /* O - Cookie data or NULL */ @@ -679,7 +679,7 @@ httpGetCookie(http_t *http) /* I - HTTP connecion */ /* * 'httpGetFd()' - Get the file descriptor associated with a connection. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ int /* O - File descriptor or -1 if none */ @@ -749,7 +749,7 @@ httpGetLength(http_t *http) /* I - Connection to server */ * This function returns the complete content length, even for * content larger than 2^31 - 1. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ off_t /* O - Content length */ @@ -811,7 +811,7 @@ httpGetLength2(http_t *http) /* I - Connection to server */ /* * 'httpGetStatus()' - Get the status of the last HTTP request. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ http_status_t /* O - HTTP status */ @@ -840,7 +840,7 @@ httpGetSubField(http_t *http, /* I - Connection to server */ /* * 'httpGetSubField2()' - Get a sub-field value. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ char * /* O - Value or NULL */ @@ -1300,7 +1300,7 @@ httpRead(http_t *http, /* I - Connection to server */ /* * 'httpRead2()' - Read data from a HTTP connection. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ ssize_t /* O - Number of bytes read */ @@ -1732,7 +1732,7 @@ httpReconnect(http_t *http) /* I - Connection to server */ * HTTP_FIELD_AUTHORIZATION prior to issuing a HTTP request using httpGet(), * httpHead(), httpOptions(), httpPost, or httpPut(). * - * @since CUPS 1.3@ + * @since CUPS 1.3/Mac OS X 10.5@ */ void @@ -1788,7 +1788,7 @@ httpSetAuthString(http_t *http, /* I - Connection to server */ /* * 'httpSetCookie()' - Set the cookie value(s)... * - * @since CUPS 1.1.19@ + * @since CUPS 1.1.19/Mac OS X 10.3@ */ void @@ -1813,7 +1813,7 @@ httpSetCookie(http_t *http, /* I - Connection */ * * Currently only HTTP_CONTINUE is supported for the "expect" argument. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ void @@ -1860,7 +1860,7 @@ httpSetField(http_t *http, /* I - Connection to server */ /* * 'httpSetLength()' - Set the content-length and content-encoding. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ void @@ -2077,7 +2077,7 @@ httpUpdate(http_t *http) /* I - Connection to server */ /* * 'httpWait()' - Wait for data available on a connection. * - * @since CUPS 1.1.19@ + * @since CUPS 1.1.19/Mac OS X 10.3@ */ int /* O - 1 if data is available, 0 otherwise */ @@ -2133,7 +2133,7 @@ httpWrite(http_t *http, /* I - Connection to server */ /* * 'httpWrite2()' - Write data to a HTTP connection. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ ssize_t /* O - Number of bytes written */ diff --git a/cups/http.h b/cups/http.h index 169a1575c8..0c51578d73 100644 --- a/cups/http.h +++ b/cups/http.h @@ -124,7 +124,7 @@ typedef enum http_auth_e /**** HTTP authentication types ****/ HTTP_AUTH_MD5_SESS, /* MD5-session authentication in use */ HTTP_AUTH_MD5_INT, /* Digest authentication in use for body */ HTTP_AUTH_MD5_SESS_INT, /* MD5-session authentication in use for body */ - HTTP_AUTH_NEGOTIATE /* GSSAPI authentication in use @since CUPS 1.3@ */ + HTTP_AUTH_NEGOTIATE /* GSSAPI authentication in use @since CUPS 1.3/Mac OS X 10.5@ */ } http_auth_t; typedef enum http_encoding_e /**** HTTP transfer encoding values ****/ @@ -288,7 +288,7 @@ typedef enum http_version_e /**** HTTP version numbers ****/ typedef union _http_addr_u /**** Socket address union, which **** makes using IPv6 and other **** address types easier and - **** more portable. @since CUPS 1.2@ + **** more portable. @since CUPS 1.2/Mac OS X 10.5@ ****/ { struct sockaddr addr; /* Base structure for family value */ @@ -305,7 +305,7 @@ typedef union _http_addr_u /**** Socket address union, which typedef struct http_addrlist_s /**** Socket address list, which is **** used to enumerate all of the **** addresses that are associated - **** with a hostname. @since CUPS 1.2@ + **** with a hostname. @since CUPS 1.2/Mac OS X 10.5@ ****/ { struct http_addrlist_s *next; /* Pointer to next address in list */ diff --git a/cups/ipp-support.c b/cups/ipp-support.c index ca1111b856..8553a488e2 100644 --- a/cups/ipp-support.c +++ b/cups/ipp-support.c @@ -281,7 +281,7 @@ ippErrorString(ipp_status_t error) /* I - Error status */ /* * 'ippErrorValue()' - Return a status code for the given name. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ ipp_status_t /* O - IPP status code */ @@ -315,7 +315,7 @@ ippErrorValue(const char *name) /* I - Name */ /* * 'ippOpString()' - Return a name for the given operation id. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ const char * /* O - Name */ @@ -350,7 +350,7 @@ ippOpString(ipp_op_t op) /* I - Operation ID */ /* * 'ippOpValue()' - Return an operation id for the given name. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ ipp_op_t /* O - Operation ID */ diff --git a/cups/ipp.c b/cups/ipp.c index f9bbb5c96f..1f932403d4 100644 --- a/cups/ipp.c +++ b/cups/ipp.c @@ -160,7 +160,7 @@ ippAddBooleans(ipp_t *ipp, /* I - IPP message */ /* * 'ippAddCollection()' - Add a collection value. * - * @since CUPS 1.1.19@ + * @since CUPS 1.1.19/Mac OS X 10.3@ */ ipp_attribute_t * /* O - New attribute */ @@ -193,7 +193,7 @@ ippAddCollection(ipp_t *ipp, /* I - IPP message */ /* * 'ippAddCollections()' - Add an array of collection values. * - * @since CUPS 1.1.19@ + * @since CUPS 1.1.19/Mac OS X 10.3@ */ ipp_attribute_t * /* O - New attribute */ @@ -342,7 +342,7 @@ ippAddIntegers(ipp_t *ipp, /* I - IPP message */ /* * 'ippAddOctetString()' - Add an octetString value to an IPP message. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ ipp_attribute_t * /* O - New attribute */ @@ -789,7 +789,7 @@ ippDelete(ipp_t *ipp) /* I - IPP message */ /* * 'ippDeleteAttribute()' - Delete a single attribute in an IPP message. * - * @since CUPS 1.1.19@ + * @since CUPS 1.1.19/Mac OS X 10.3@ */ void @@ -964,7 +964,7 @@ ippNew(void) * attributes-natural-language attributes added. The * attributes-natural-language value is derived from the current locale. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ ipp_t * /* O - IPP request message */ @@ -1039,7 +1039,7 @@ ippRead(http_t *http, /* I - HTTP connection */ /* * 'ippReadFile()' - Read data for an IPP message from a file. * - * @since CUPS 1.1.19@ + * @since CUPS 1.1.19/Mac OS X 10.3@ */ ipp_state_t /* O - Current state */ @@ -1055,7 +1055,7 @@ ippReadFile(int fd, /* I - HTTP data */ /* * 'ippReadIO()' - Read data for an IPP message. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ ipp_state_t /* O - Current state */ @@ -1798,7 +1798,7 @@ ippWrite(http_t *http, /* I - HTTP connection */ /* * 'ippWriteFile()' - Write data for an IPP message to a file. * - * @since CUPS 1.1.19@ + * @since CUPS 1.1.19/Mac OS X 10.3@ */ ipp_state_t /* O - Current state */ @@ -1816,7 +1816,7 @@ ippWriteFile(int fd, /* I - HTTP data */ /* * 'ippWriteIO()' - Write data for an IPP message. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ ipp_state_t /* O - Current state */ diff --git a/cups/ipp.h b/cups/ipp.h index 1e6fadaf9b..6d182bd474 100644 --- a/cups/ipp.h +++ b/cups/ipp.h @@ -4,7 +4,7 @@ * Internet Printing Protocol definitions for the Common UNIX Printing * System (CUPS). * - * Copyright 2007 by Apple Inc. + * Copyright 2007-2008 by Apple Inc. * Copyright 1997-2006 by Easy Software Products. * * These coded instructions, statements, and computer programs are the @@ -207,13 +207,13 @@ typedef enum ipp_op_e /**** IPP operations... ****/ IPP_SET_PRINTER_ATTRIBUTES, /* Set printer attributes @private@ */ IPP_SET_JOB_ATTRIBUTES, /* Set job attributes */ IPP_GET_PRINTER_SUPPORTED_VALUES, /* Get supported attribute values */ - IPP_CREATE_PRINTER_SUBSCRIPTION, /* Create a printer subscription @since CUPS 1.2@ */ - IPP_CREATE_JOB_SUBSCRIPTION, /* Create a job subscription @since CUPS 1.2@ */ - IPP_GET_SUBSCRIPTION_ATTRIBUTES, /* Get subscription attributes @since CUPS 1.2@ */ - IPP_GET_SUBSCRIPTIONS, /* Get list of subscriptions @since CUPS 1.2@ */ - IPP_RENEW_SUBSCRIPTION, /* Renew a printer subscription @since CUPS 1.2@ */ - IPP_CANCEL_SUBSCRIPTION, /* Cancel a subscription @since CUPS 1.2@ */ - IPP_GET_NOTIFICATIONS, /* Get notification events @since CUPS 1.2@ */ + IPP_CREATE_PRINTER_SUBSCRIPTION, /* Create a printer subscription @since CUPS 1.2/Mac OS X 10.5@ */ + IPP_CREATE_JOB_SUBSCRIPTION, /* Create a job subscription @since CUPS 1.2/Mac OS X 10.5@ */ + IPP_GET_SUBSCRIPTION_ATTRIBUTES, /* Get subscription attributes @since CUPS 1.2/Mac OS X 10.5@ */ + IPP_GET_SUBSCRIPTIONS, /* Get list of subscriptions @since CUPS 1.2/Mac OS X 10.5@ */ + IPP_RENEW_SUBSCRIPTION, /* Renew a printer subscription @since CUPS 1.2/Mac OS X 10.5@ */ + IPP_CANCEL_SUBSCRIPTION, /* Cancel a subscription @since CUPS 1.2/Mac OS X 10.5@ */ + IPP_GET_NOTIFICATIONS, /* Get notification events @since CUPS 1.2/Mac OS X 10.5@ */ IPP_SEND_NOTIFICATIONS, /* Send notification events @private@ */ IPP_GET_PRINT_SUPPORT_FILES = 0x0021, /* Get printer support files @private@ */ IPP_ENABLE_PRINTER, /* Start a printer */ @@ -246,8 +246,8 @@ typedef enum ipp_op_e /**** IPP operations... ****/ CUPS_GET_DEVICES, /* Get a list of supported devices */ CUPS_GET_PPDS, /* Get a list of supported drivers */ CUPS_MOVE_JOB, /* Move a job to a different printer */ - CUPS_AUTHENTICATE_JOB, /* Authenticate a job @since CUPS 1.2@ */ - CUPS_GET_PPD, /* Get a PPD file @since CUPS 1.3@ */ + CUPS_AUTHENTICATE_JOB, /* Authenticate a job @since CUPS 1.2/Mac OS X 10.5@ */ + CUPS_GET_PPD, /* Get a PPD file @since CUPS 1.3/Mac OS X 10.5@ */ CUPS_GET_DOCUMENT = 0x4027 /* Get a document file @since CUPS 1.4@ */ } ipp_op_t; @@ -310,7 +310,7 @@ typedef unsigned char ipp_uchar_t; /**** Unsigned 8-bit integer/character ****/ /**** New in CUPS 1.2 ****/ typedef ssize_t (*ipp_iocb_t)(void *, ipp_uchar_t *, size_t); - /**** IPP IO Callback Function @since CUPS 1.2@ ****/ + /**** IPP IO Callback Function @since CUPS 1.2/Mac OS X 10.5@ ****/ typedef union ipp_request_u /**** Request Header ****/ { @@ -336,7 +336,7 @@ typedef union ipp_request_u /**** Request Header ****/ } status; /**** New in CUPS 1.1.19 ****/ - struct /* Event Header */ + struct /* Event Header @since CUPS 1.1.19/Mac OS X 10.3@ */ { ipp_uchar_t version[2]; /* Protocol version number */ ipp_status_t status_code; /* Status code */ @@ -381,7 +381,7 @@ typedef union ipp_value_u /**** Attribute Value ****/ } unknown; /* Unknown attribute type */ /**** New in CUPS 1.1.19 ****/ - ipp_t *collection; /* Collection value */ + ipp_t *collection; /* Collection value @since CUPS 1.1.19/Mac OS X 10.3@ */ } ipp_value_t; typedef struct ipp_attribute_s /**** Attribute ****/ @@ -404,7 +404,7 @@ struct ipp_s /**** IPP Request/Response/Notification ****/ ipp_tag_t curtag; /* Current attribute group tag */ /**** New in CUPS 1.2 ****/ - ipp_attribute_t *prev; /* Previous attribute (for read) */ + ipp_attribute_t *prev; /* Previous attribute (for read) @since CUPS 1.2/Mac OS X 10.5@ */ }; diff --git a/cups/language.h b/cups/language.h index 403b4933f4..e8075744af 100644 --- a/cups/language.h +++ b/cups/language.h @@ -3,7 +3,7 @@ * * Multi-language support for the Common UNIX Printing System (CUPS). * - * Copyright 2007 by Apple Inc. + * Copyright 2007-2008 by Apple Inc. * Copyright 1997-2006 by Easy Software Products. * * These coded instructions, statements, and computer programs are the diff --git a/cups/libcups.exp b/cups/libcups.exp index 92d2f9c91d..c67afed84a 100644 --- a/cups/libcups.exp +++ b/cups/libcups.exp @@ -39,6 +39,7 @@ __cupsStrAlloc __cupsStrFlush __cupsStrFormatd __cupsStrFree +__cupsStrRetain __cupsStrScand __cupsStrStatistics __httpAddrPort diff --git a/cups/libcups_s.exp b/cups/libcups_s.exp index 97aa9c0463..d46e979119 100644 --- a/cups/libcups_s.exp +++ b/cups/libcups_s.exp @@ -34,6 +34,7 @@ _cupsStrAlloc _cupsStrFlush _cupsStrFormatd _cupsStrFree +_cupsStrRetain _cupsStrScand _cupsStrStatistics _cups_getifaddrs diff --git a/cups/localize.c b/cups/localize.c index 7a98607de1..19a03e26c7 100644 --- a/cups/localize.c +++ b/cups/localize.c @@ -62,7 +62,7 @@ static void ppd_ll_CC(char *ll_CC, int ll_CC_size); * descriptions, printer presets, and custom option parameters. Each * localized string uses the UTF-8 character encoding. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ int /* O - 0 on success, -1 on error */ @@ -246,7 +246,7 @@ ppdLocalizeAttr(ppd_file_t *ppd, /* I - PPD file */ * * If no value of the requested scheme can be found, NULL is returned. * - * @since CUPS 1.3@ + * @since CUPS 1.3/Mac OS X 10.5@ */ const char * /* O - Value or NULL if not found */ diff --git a/cups/mark.c b/cups/mark.c index 878ace885d..ffbc436ecf 100644 --- a/cups/mark.c +++ b/cups/mark.c @@ -551,7 +551,7 @@ ppdMarkOption(ppd_file_t *ppd, /* I - PPD file record */ * * Options are returned from all groups in ascending alphanumeric order. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ ppd_option_t * /* O - First option or @code NULL@ */ @@ -569,7 +569,7 @@ ppdFirstOption(ppd_file_t *ppd) /* I - PPD file */ * * Options are returned from all groups in ascending alphanumeric order. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ ppd_option_t * /* O - Next option or @code NULL@ */ @@ -931,7 +931,7 @@ ppd_mark_option(ppd_file_t *ppd, /* I - PPD file */ if (cparam->current.custom_string) _cupsStrFree(cparam->current.custom_string); - cparam->current.custom_string = _cupsStrAlloc(val->value); + cparam->current.custom_string = _cupsStrRetain(val->value); break; } } diff --git a/cups/notify.c b/cups/notify.c index cbfe5f0703..3cb07a5afd 100644 --- a/cups/notify.c +++ b/cups/notify.c @@ -33,7 +33,7 @@ * * The returned string must be freed by the caller using @code free@. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ char * /* O - Subject string or @code NULL@ */ @@ -164,7 +164,7 @@ cupsNotifySubject(cups_lang_t *lang, /* I - Language data */ * * The returned string must be freed by the caller using @code free@. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ char * /* O - Message text or @code NULL@ */ diff --git a/cups/options.c b/cups/options.c index a5b757da1c..b1476a49aa 100644 --- a/cups/options.c +++ b/cups/options.c @@ -1,5 +1,5 @@ /* - * "$Id: options.c 7819 2008-08-01 00:27:24Z mike $" + * "$Id: options.c 8181 2008-12-10 17:29:57Z mike $" * * Option routines for the Common UNIX Printing System (CUPS). * @@ -34,6 +34,15 @@ #include "debug.h" +/* + * Local functions... + */ + +static int cups_compare_options(cups_option_t *a, cups_option_t *b); +static int cups_find_option(const char *name, int num_options, + cups_option_t *option, int prev, int *rdiff); + + /* * 'cupsAddOption()' - Add an option to an option array. * @@ -47,8 +56,9 @@ cupsAddOption(const char *name, /* I - Name of option */ int num_options,/* I - Number of options */ cups_option_t **options) /* IO - Pointer to options */ { - int i; /* Looping var */ cups_option_t *temp; /* Pointer to new option */ + int insert, /* Insertion point */ + diff; /* Result of search */ DEBUG_printf(("cupsAddOption(name=\"%s\", value=\"%s\", num_options=%d, " @@ -64,17 +74,28 @@ cupsAddOption(const char *name, /* I - Name of option */ * Look for an existing option with the same name... */ - for (i = 0, temp = *options; i < num_options; i ++, temp ++) - if (!strcasecmp(temp->name, name)) - break; + if (num_options == 0) + { + insert = 0; + diff = 1; + } + else + { + insert = cups_find_option(name, num_options, *options, num_options - 1, + &diff); - if (i >= num_options) + if (diff > 0) + insert ++; + } + + if (diff) { /* * No matching option name... */ - DEBUG_puts("cupsAddOption: New option..."); + DEBUG_printf(("cupsAddOption: New option inserted at index %d...\n", + insert)); if (num_options == 0) temp = (cups_option_t *)malloc(sizeof(cups_option_t)); @@ -88,8 +109,17 @@ cupsAddOption(const char *name, /* I - Name of option */ return (0); } - *options = temp; - temp += num_options; + *options = temp; + + if (insert < num_options) + { + DEBUG_printf(("cupsAddOption: Shifting %d options...\n", + (int)(num_options - insert))); + memmove(temp + insert + 1, temp + insert, + (num_options - insert) * sizeof(cups_option_t)); + } + + temp += insert; temp->name = _cupsStrAlloc(name); num_options ++; } @@ -99,7 +129,10 @@ cupsAddOption(const char *name, /* I - Name of option */ * Match found; free the old value... */ - DEBUG_puts("cupsAddOption: Option already exists..."); + DEBUG_printf(("cupsAddOption: Option already exists at index %d...\n", + insert)); + + temp = *options + insert; _cupsStrFree(temp->value); } @@ -148,7 +181,8 @@ cupsGetOption(const char *name, /* I - Name of option */ int num_options,/* I - Number of options */ cups_option_t *options) /* I - Options */ { - int i; /* Looping var */ + int diff, /* Result of comparison */ + match; /* Matching index */ DEBUG_printf(("cupsGetOption(name=\"%s\", num_options=%d, options=%p)\n", @@ -160,12 +194,13 @@ cupsGetOption(const char *name, /* I - Name of option */ return (NULL); } - for (i = 0; i < num_options; i ++) - if (!strcasecmp(options[i].name, name)) - { - DEBUG_printf(("cupsGetOption: Returning \"%s\"\n", options[i].value)); - return (options[i].value); - } + match = cups_find_option(name, num_options, options, -1, &diff); + + if (!diff) + { + DEBUG_printf(("cupsGetOption: Returning \"%s\"\n", options[match].value)); + return (options[match].value); + } DEBUG_puts("cupsGetOption: Returning NULL"); return (NULL); @@ -192,6 +227,7 @@ cupsParseOptions( *ptr, /* Pointer into string */ *name, /* Pointer to name */ *value, /* Pointer to value */ + sep, /* Separator character */ quote; /* Quote character */ @@ -277,9 +313,12 @@ cupsParseOptions( while (isspace(*ptr & 255)) *ptr++ = '\0'; + if ((sep = *ptr) == '=') + *ptr++ = '\0'; + DEBUG_printf(("cupsParseOptions: name=\"%s\"\n", name)); - if (*ptr != '=') + if (sep != '=') { /* * Boolean option... @@ -298,8 +337,7 @@ cupsParseOptions( * Remove = and parse the value... */ - *ptr++ = '\0'; - value = ptr; + value = ptr; while (*ptr && !isspace(*ptr & 255)) { @@ -401,7 +439,7 @@ cupsParseOptions( /* * 'cupsRemoveOption()' - Remove an option from an option array. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ int /* O - New number of options */ @@ -463,5 +501,129 @@ cupsRemoveOption( /* - * End of "$Id: options.c 7819 2008-08-01 00:27:24Z mike $". + * 'cups_compare_options()' - Compare two options. + */ + +static int /* O - Result of comparison */ +cups_compare_options(cups_option_t *a, /* I - First option */ + cups_option_t *b) /* I - Second option */ +{ + return (strcasecmp(a->name, b->name)); +} + + +/* + * 'cups_find_option()' - Find an option using a binary search. + */ + +static int /* O - Index of match */ +cups_find_option( + const char *name, /* I - Option name */ + int num_options, /* I - Number of options */ + cups_option_t *options, /* I - Options */ + int prev, /* I - Previous index */ + int *rdiff) /* O - Difference of match */ +{ + int left, /* Low mark for binary search */ + right, /* High mark for binary search */ + current, /* Current index */ + diff; /* Result of comparison */ + cups_option_t key; /* Search key */ + + + DEBUG_printf(("cups_find_option(name=\"%s\", num_options=%d, options=%p, " + "prev=%d, rdiff=%p)\n", name, num_options, options, prev, + rdiff)); + +#ifdef DEBUG + for (left = 0; left < num_options; left ++) + DEBUG_printf(("cups_find_option: options[%d].name=\"%s\", .value=\"%s\"\n", + left, options[left].name, options[left].value)); +#endif /* DEBUG */ + + key.name = (char *)name; + + if (prev >= 0) + { + /* + * Start search on either side of previous... + */ + + if ((diff = cups_compare_options(&key, options + prev)) == 0 || + (diff < 0 && prev == 0) || + (diff > 0 && prev == (num_options - 1))) + { + *rdiff = diff; + return (prev); + } + else if (diff < 0) + { + /* + * Start with previous on right side... + */ + + left = 0; + right = prev; + } + else + { + /* + * Start wih previous on left side... + */ + + left = prev; + right = num_options - 1; + } + } + else + { + /* + * Start search in the middle... + */ + + left = 0; + right = num_options - 1; + } + + do + { + current = (left + right) / 2; + diff = cups_compare_options(&key, options + current); + + if (diff == 0) + break; + else if (diff < 0) + right = current; + else + left = current; + } + while ((right - left) > 1); + + if (diff != 0) + { + /* + * Check the last 1 or 2 elements... + */ + + if ((diff = cups_compare_options(&key, options + left)) <= 0) + current = left; + else + { + diff = cups_compare_options(&key, options + right); + current = right; + } + } + + /* + * Return the closest destination and the difference... + */ + + *rdiff = diff; + + return (current); +} + + +/* + * End of "$Id: options.c 8181 2008-12-10 17:29:57Z mike $". */ diff --git a/cups/page.c b/cups/page.c index 8c7b0e2abd..2b59c1e728 100644 --- a/cups/page.c +++ b/cups/page.c @@ -3,7 +3,7 @@ * * Page size functions for the Common UNIX Printing System (CUPS). * - * Copyright 2007 by Apple Inc. + * Copyright 2007-2008 by Apple Inc. * Copyright 1997-2007 by Easy Software Products, all rights reserved. * * These coded instructions, statements, and computer programs are the diff --git a/cups/ppd.c b/cups/ppd.c index 4804c04f27..bdb0f2ddc0 100644 --- a/cups/ppd.c +++ b/cups/ppd.c @@ -323,7 +323,7 @@ ppdClose(ppd_file_t *ppd) /* I - PPD file record */ /* * 'ppdErrorString()' - Returns the text assocated with a status. * - * @since CUPS 1.1.19@ + * @since CUPS 1.1.19/Mac OS X 10.3@ */ const char * /* O - Status string */ @@ -390,7 +390,7 @@ _ppdGetEncoding(const char *name) /* I - LanguageEncoding string */ /* * 'ppdLastError()' - Return the status from the last ppdOpen*(). * - * @since CUPS 1.1.19@ + * @since CUPS 1.1.19/Mac OS X 10.3@ */ ppd_status_t /* O - Status code */ @@ -444,7 +444,7 @@ ppdOpen(FILE *fp) /* I - File to read from */ /* * 'ppdOpen2()' - Read a PPD file into memory. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ ppd_file_t * /* O - PPD file record or @code NULL@ if the PPD file could not be opened. */ @@ -1321,7 +1321,7 @@ ppdOpen2(cups_file_t *fp) /* I - File to read from */ strlcpy(choice->text, custom_attr->text[0] ? custom_attr->text : _("Custom"), sizeof(choice->text)); - choice->code = _cupsStrAlloc(custom_attr->value); + choice->code = _cupsStrRetain(custom_attr->value); } } else if (!strcmp(keyword, "JCLOpenUI")) @@ -1424,7 +1424,7 @@ ppdOpen2(cups_file_t *fp) /* I - File to read from */ strlcpy(choice->text, custom_attr->text[0] ? custom_attr->text : _("Custom"), sizeof(choice->text)); - choice->code = _cupsStrAlloc(custom_attr->value); + choice->code = _cupsStrRetain(custom_attr->value); } } else if (!strcmp(keyword, "CloseUI") || !strcmp(keyword, "JCLCloseUI")) @@ -2073,7 +2073,7 @@ ppdOpenFile(const char *filename) /* I - File to read from */ /* * 'ppdSetConformance()' - Set the conformance level for PPD files. * - * @since CUPS 1.1.20@ + * @since CUPS 1.1.20/Mac OS X 10.4@ */ void diff --git a/cups/ppd.h b/cups/ppd.h index 3f59b77634..1a5f34db1a 100644 --- a/cups/ppd.h +++ b/cups/ppd.h @@ -93,7 +93,7 @@ typedef enum ppd_cs_e /**** Colorspaces ****/ PPD_CS_N /* DeviceN colorspace */ } ppd_cs_t; -typedef enum ppd_status_e /**** Status Codes @since CUPS 1.1.19@ ****/ +typedef enum ppd_status_e /**** Status Codes @since CUPS 1.1.19/Mac OS X 10.3@ ****/ { PPD_OK = 0, /* OK */ PPD_FILE_OPEN_ERROR, /* Unable to open PPD file */ @@ -118,16 +118,16 @@ typedef enum ppd_status_e /**** Status Codes @since CUPS 1.1.19@ ****/ PPD_BAD_CUSTOM_PARAM /* Bad custom parameter */ } ppd_status_t; -enum ppd_conform_e /**** Conformance Levels @since CUPS 1.1.19@ ****/ +enum ppd_conform_e /**** Conformance Levels @since CUPS 1.1.19/Mac OS X 10.3@ ****/ { PPD_CONFORM_RELAXED, /* Relax whitespace and control char */ PPD_CONFORM_STRICT /* Require strict conformance */ }; typedef enum ppd_conform_e ppd_conform_t; - /**** Conformance Levels @since CUPS 1.1.19@ ****/ + /**** Conformance Levels @since CUPS 1.1.19/Mac OS X 10.3@ ****/ -typedef struct ppd_attr_s /**** PPD Attribute Structure @since CUPS 1.1.19@ ****/ +typedef struct ppd_attr_s /**** PPD Attribute Structure @since CUPS 1.1.19/Mac OS X 10.3@ ****/ { char name[PPD_MAX_NAME]; /* Name of attribute (cupsXYZ) */ char spec[PPD_MAX_NAME]; /* Specifier string, if any */ @@ -168,7 +168,7 @@ typedef struct ppd_group_s /**** Groups ****/ ****/ char text[PPD_MAX_TEXT - PPD_MAX_NAME]; /* Human-readable group name */ - char name[PPD_MAX_NAME]; /* Group name @since CUPS 1.1.18@ */ + char name[PPD_MAX_NAME]; /* Group name @since CUPS 1.1.18/Mac OS X 10.3@ */ int num_options; /* Number of options */ ppd_option_t *options; /* Options */ int num_subgroups; /* Number of sub-groups */ @@ -214,7 +214,7 @@ typedef struct ppd_profile_s /**** sRGB Color Profiles ****/ } ppd_profile_t; /**** New in CUPS 1.2 ****/ -typedef enum ppd_cptype_e /**** Custom Parameter Type @since CUPS 1.2@ ****/ +typedef enum ppd_cptype_e /**** Custom Parameter Type @since CUPS 1.2/Mac OS X 10.5@ ****/ { PPD_CUSTOM_CURVE, /* Curve value for f(x) = x^value */ PPD_CUSTOM_INT, /* Integer number value */ @@ -226,7 +226,7 @@ typedef enum ppd_cptype_e /**** Custom Parameter Type @since CUPS 1.2@ ****/ PPD_CUSTOM_STRING /* String of characters */ } ppd_cptype_t; -typedef union ppd_cplimit_u /**** Custom Parameter Limit @since CUPS 1.2@ ****/ +typedef union ppd_cplimit_u /**** Custom Parameter Limit @since CUPS 1.2/Mac OS X 10.5@ ****/ { float custom_curve; /* Gamma value */ int custom_int; /* Integer value */ @@ -238,7 +238,7 @@ typedef union ppd_cplimit_u /**** Custom Parameter Limit @since CUPS 1.2@ ****/ int custom_string; /* String length */ } ppd_cplimit_t; -typedef union ppd_cpvalue_u /**** Custom Parameter Value @since CUPS 1.2@ ****/ +typedef union ppd_cpvalue_u /**** Custom Parameter Value @since CUPS 1.2/Mac OS X 10.5@ ****/ { float custom_curve; /* Gamma value */ int custom_int; /* Integer value */ @@ -250,7 +250,7 @@ typedef union ppd_cpvalue_u /**** Custom Parameter Value @since CUPS 1.2@ ****/ char *custom_string; /* String value */ } ppd_cpvalue_t; -typedef struct ppd_cparam_s /**** Custom Parameter @since CUPS 1.2@ ****/ +typedef struct ppd_cparam_s /**** Custom Parameter @since CUPS 1.2/Mac OS X 10.5@ ****/ { char name[PPD_MAX_NAME]; /* Parameter name */ char text[PPD_MAX_TEXT]; /* Human-readable text */ @@ -261,7 +261,7 @@ typedef struct ppd_cparam_s /**** Custom Parameter @since CUPS 1.2@ ****/ ppd_cpvalue_t current; /* Current value */ } ppd_cparam_t; -typedef struct ppd_coption_s /**** Custom Option @since CUPS 1.2@ ****/ +typedef struct ppd_coption_s /**** Custom Option @since CUPS 1.2/Mac OS X 10.5@ ****/ { char keyword[PPD_MAX_NAME]; /* Name of option that is being extended... */ ppd_option_t *option; /* Option that is being extended... */ @@ -315,19 +315,19 @@ typedef struct ppd_file_s /**** PPD File ****/ int flip_duplex; /* 1 = Flip page for back sides @deprecated@ */ /**** New in CUPS 1.1.19 ****/ - char *protocols; /* Protocols (BCP, TBCP) string @since CUPS 1.1.19@ */ - char *pcfilename; /* PCFileName string @since CUPS 1.1.19@ */ - int num_attrs; /* Number of attributes @since CUPS 1.1.19@ @private@ */ - int cur_attr; /* Current attribute @since CUPS 1.1.19@ @private@ */ - ppd_attr_t **attrs; /* Attributes @since CUPS 1.1.19@ @private@ */ + char *protocols; /* Protocols (BCP, TBCP) string @since CUPS 1.1.19/Mac OS X 10.3@ */ + char *pcfilename; /* PCFileName string @since CUPS 1.1.19/Mac OS X 10.3@ */ + int num_attrs; /* Number of attributes @since CUPS 1.1.19/Mac OS X 10.3@ @private@ */ + int cur_attr; /* Current attribute @since CUPS 1.1.19/Mac OS X 10.3@ @private@ */ + ppd_attr_t **attrs; /* Attributes @since CUPS 1.1.19/Mac OS X 10.3@ @private@ */ /**** New in CUPS 1.2 ****/ - cups_array_t *sorted_attrs; /* Attribute lookup array @since CUPS 1.2@ @private@ */ - cups_array_t *options; /* Option lookup array @since CUPS 1.2@ @private@ */ - cups_array_t *coptions; /* Custom options array @since CUPS 1.2@ @private@ */ + cups_array_t *sorted_attrs; /* Attribute lookup array @since CUPS 1.2/Mac OS X 10.5@ @private@ */ + cups_array_t *options; /* Option lookup array @since CUPS 1.2/Mac OS X 10.5@ @private@ */ + cups_array_t *coptions; /* Custom options array @since CUPS 1.2/Mac OS X 10.5@ @private@ */ /**** New in CUPS 1.3 ****/ - cups_array_t *marked; /* Marked choices @since CUPS 1.3@ @private@ */ + cups_array_t *marked; /* Marked choices @since CUPS 1.3/Mac OS X 10.5@ @private@ */ /**** New in CUPS 1.4 ****/ cups_array_t *cups_uiconstraints; /* cupsUIConstraints @since CUPS 1.4@ @private@ */ diff --git a/cups/raster.h b/cups/raster.h index 20f362bb71..86d4a255c1 100644 --- a/cups/raster.h +++ b/cups/raster.h @@ -101,25 +101,25 @@ typedef enum cups_cspace_e /**** cupsColorSpace attribute values ****/ CUPS_CSPACE_GOLD = 13, /* Gold foil */ CUPS_CSPACE_SILVER = 14, /* Silver foil */ - CUPS_CSPACE_CIEXYZ = 15, /* CIE XYZ @since CUPS 1.1.19@ */ - CUPS_CSPACE_CIELab = 16, /* CIE Lab @since CUPS 1.1.19@ */ + CUPS_CSPACE_CIEXYZ = 15, /* CIE XYZ @since CUPS 1.1.19/Mac OS X 10.3@ */ + CUPS_CSPACE_CIELab = 16, /* CIE Lab @since CUPS 1.1.19/Mac OS X 10.3@ */ CUPS_CSPACE_RGBW = 17, /* Red, green, blue, white @since CUPS 1.2/Mac OS X 10.5@ */ - CUPS_CSPACE_ICC1 = 32, /* ICC-based, 1 color @since CUPS 1.1.19@ */ - CUPS_CSPACE_ICC2 = 33, /* ICC-based, 2 colors @since CUPS 1.1.19@ */ - CUPS_CSPACE_ICC3 = 34, /* ICC-based, 3 colors @since CUPS 1.1.19@ */ - CUPS_CSPACE_ICC4 = 35, /* ICC-based, 4 colors @since CUPS 1.1.19@ */ - CUPS_CSPACE_ICC5 = 36, /* ICC-based, 5 colors @since CUPS 1.1.19@ */ - CUPS_CSPACE_ICC6 = 37, /* ICC-based, 6 colors @since CUPS 1.1.19@ */ - CUPS_CSPACE_ICC7 = 38, /* ICC-based, 7 colors @since CUPS 1.1.19@ */ - CUPS_CSPACE_ICC8 = 39, /* ICC-based, 8 colors @since CUPS 1.1.19@ */ - CUPS_CSPACE_ICC9 = 40, /* ICC-based, 9 colors @since CUPS 1.1.19@ */ - CUPS_CSPACE_ICCA = 41, /* ICC-based, 10 colors @since CUPS 1.1.19@ */ - CUPS_CSPACE_ICCB = 42, /* ICC-based, 11 colors @since CUPS 1.1.19@ */ - CUPS_CSPACE_ICCC = 43, /* ICC-based, 12 colors @since CUPS 1.1.19@ */ - CUPS_CSPACE_ICCD = 44, /* ICC-based, 13 colors @since CUPS 1.1.19@ */ - CUPS_CSPACE_ICCE = 45, /* ICC-based, 14 colors @since CUPS 1.1.19@ */ - CUPS_CSPACE_ICCF = 46 /* ICC-based, 15 colors @since CUPS 1.1.19@ */ + CUPS_CSPACE_ICC1 = 32, /* ICC-based, 1 color @since CUPS 1.1.19/Mac OS X 10.3@ */ + CUPS_CSPACE_ICC2 = 33, /* ICC-based, 2 colors @since CUPS 1.1.19/Mac OS X 10.3@ */ + CUPS_CSPACE_ICC3 = 34, /* ICC-based, 3 colors @since CUPS 1.1.19/Mac OS X 10.3@ */ + CUPS_CSPACE_ICC4 = 35, /* ICC-based, 4 colors @since CUPS 1.1.19/Mac OS X 10.3@ */ + CUPS_CSPACE_ICC5 = 36, /* ICC-based, 5 colors @since CUPS 1.1.19/Mac OS X 10.3@ */ + CUPS_CSPACE_ICC6 = 37, /* ICC-based, 6 colors @since CUPS 1.1.19/Mac OS X 10.3@ */ + CUPS_CSPACE_ICC7 = 38, /* ICC-based, 7 colors @since CUPS 1.1.19/Mac OS X 10.3@ */ + CUPS_CSPACE_ICC8 = 39, /* ICC-based, 8 colors @since CUPS 1.1.19/Mac OS X 10.3@ */ + CUPS_CSPACE_ICC9 = 40, /* ICC-based, 9 colors @since CUPS 1.1.19/Mac OS X 10.3@ */ + CUPS_CSPACE_ICCA = 41, /* ICC-based, 10 colors @since CUPS 1.1.19/Mac OS X 10.3@ */ + CUPS_CSPACE_ICCB = 42, /* ICC-based, 11 colors @since CUPS 1.1.19/Mac OS X 10.3@ */ + CUPS_CSPACE_ICCC = 43, /* ICC-based, 12 colors @since CUPS 1.1.19/Mac OS X 10.3@ */ + CUPS_CSPACE_ICCD = 44, /* ICC-based, 13 colors @since CUPS 1.1.19/Mac OS X 10.3@ */ + CUPS_CSPACE_ICCE = 45, /* ICC-based, 14 colors @since CUPS 1.1.19/Mac OS X 10.3@ */ + CUPS_CSPACE_ICCF = 46 /* ICC-based, 15 colors @since CUPS 1.1.19/Mac OS X 10.3@ */ } cups_cspace_t; typedef enum cups_cut_e /**** CutMedia attribute values ****/ @@ -151,7 +151,7 @@ enum cups_mode_e /**** cupsRasterOpen modes ****/ { CUPS_RASTER_READ = 0, /* Open stream for reading */ CUPS_RASTER_WRITE = 1, /* Open stream for writing */ - CUPS_RASTER_WRITE_COMPRESSED = 2 /* Open stream for compressed writing @since CUPS 1.3@ */ + CUPS_RASTER_WRITE_COMPRESSED = 2 /* Open stream for compressed writing @since CUPS 1.3/Mac OS X 10.5@ */ }; typedef enum cups_mode_e cups_mode_t; /**** cupsRasterOpen modes ****/ diff --git a/cups/request.c b/cups/request.c index 20f3b2f751..5169267299 100644 --- a/cups/request.c +++ b/cups/request.c @@ -112,7 +112,7 @@ cupsDoFileRequest(http_t *http, /* I - Connection to server or @code CUPS_HT * If "outfile" is a valid file descriptor, cupsDoIORequest() copies * all of the data after the IPP response message to the file. * - * @since CUPS 1.3@ + * @since CUPS 1.3/Mac OS X 10.5@ */ ipp_t * /* O - Response data */ diff --git a/cups/sidechannel.c b/cups/sidechannel.c index 0b79f8b013..ccf1d19045 100644 --- a/cups/sidechannel.c +++ b/cups/sidechannel.c @@ -59,7 +59,7 @@ * pointed to by the "data" parameter. cupsSideChannelDoRequest() will * update the value to contain the number of data bytes in the buffer. * - * @since CUPS 1.3@ + * @since CUPS 1.3/Mac OS X 10.5@ */ cups_sc_status_t /* O - Status of command */ @@ -98,7 +98,7 @@ cupsSideChannelDoRequest( * pointed to by the "data" parameter. cupsSideChannelDoRequest() will * update the value to contain the number of data bytes in the buffer. * - * @since CUPS 1.3@ + * @since CUPS 1.3/Mac OS X 10.5@ */ int /* O - 0 on success, -1 on error */ @@ -455,7 +455,7 @@ cupsSideChannelSNMPWalk( * This function is normally only called by backend programs to send * responses to a filter, driver, or port monitor program. * - * @since CUPS 1.3@ + * @since CUPS 1.3/Mac OS X 10.5@ */ int /* O - 0 on success, -1 on error */ diff --git a/cups/snmp.c b/cups/snmp.c index 943e8ed90b..69a91ac51e 100644 --- a/cups/snmp.c +++ b/cups/snmp.c @@ -111,8 +111,6 @@ static void snmp_set_error(cups_snmp_t *packet, /* * '_cupsSNMPClose()' - Close a SNMP socket. - * - * @since CUPS 1.4@ */ void @@ -132,8 +130,6 @@ _cupsSNMPClose(int fd) /* I - SNMP socket file descriptor */ * '_cupsSNMPCopyOID()' - Copy an OID. * * The array pointed to by "src" is terminated by the value -1. - * - * @since CUPS 1.4@ */ int * /* O - New OID */ @@ -161,8 +157,6 @@ _cupsSNMPCopyOID(int *dst, /* I - Destination OID */ * * The default community name is the first community name found in the * snmp.conf file. If no community name is defined there, "public" is used. - * - * @since CUPS 1.4@ */ const char * /* O - Default community name */ @@ -207,8 +201,6 @@ _cupsSNMPDefaultCommunity(void) * '_cupsSNMPIsOID()' - Test whether a SNMP response contains the specified OID. * * The array pointed to by "oid" is terminated by the value -1. - * - * @since CUPS 1.4@ */ int /* O - 1 if equal, 0 if not equal */ @@ -257,8 +249,6 @@ _cupsSNMPIsOID(cups_snmp_t *packet, /* I - Response packet */ * OID prefix. * * The array pointed to by "prefix" is terminated by the value -1. - * - * @since CUPS 1.4@ */ int /* O - 1 if prefixed, 0 if not prefixed */ @@ -306,8 +296,6 @@ _cupsSNMPIsOIDPrefixed( /* * '_cupsSNMPOIDToString()' - Convert an OID to a string. - * - * @since CUPS 1.4@ */ @@ -348,8 +336,6 @@ _cupsSNMPOIDToString(const int *src, /* I - OID */ /* * '_cupsSNMPOpen()' - Open a SNMP socket. - * - * @since CUPS 1.4@ */ int /* O - SNMP socket file descriptor */ @@ -398,8 +384,6 @@ _cupsSNMPOpen(int family) /* I - Address family - @code AF_INET@ or @code AF_IN * * If "timeout" is negative, @code _cupsSNMPRead@ will wait for a response * indefinitely. - * - * @since CUPS 1.4@ */ cups_snmp_t * /* O - SNMP packet or @code NULL@ if none */ @@ -513,8 +497,6 @@ _cupsSNMPRead(int fd, /* I - SNMP socket file descriptor */ /* * '_cupsSNMPSetDebug()' - Enable/disable debug logging to stderr. - * - * @since CUPS 1.4@ */ void @@ -537,8 +519,6 @@ _cupsSNMPSetDebug(int level) /* I - 1 to enable debug output, 0 otherwise */ * * @code NULL@ is returned if the array is not large enough or the string is * not a valid OID number. - * - * @since CUPS 1.4@ */ int * /* O - Pointer to OID array or @code NULL@ on error */ @@ -609,8 +589,6 @@ _cupsSNMPStringToOID(const char *src, /* I - OID string */ * * If "timeout" is negative, @code _cupsSNMPWalk@ will wait for a response * indefinitely. - * - * @since CUPS 1.4@ */ int /* O - Number of OIDs found or -1 on error */ @@ -696,8 +674,6 @@ _cupsSNMPWalk(int fd, /* I - SNMP socket */ * '_cupsSNMPWrite()' - Send an SNMP query packet. * * The array pointed to by "oid" is terminated by the value -1. - * - * @since CUPS 1.4@ */ int /* O - 1 on success, 0 on error */ diff --git a/cups/string.c b/cups/string.c index bd7d9cc160..632b2cc5bc 100644 --- a/cups/string.c +++ b/cups/string.c @@ -3,7 +3,7 @@ * * String functions for the Common UNIX Printing System (CUPS). * - * Copyright 2007 by Apple Inc. + * Copyright 2007-2008 by Apple Inc. * Copyright 1997-2007 by Easy Software Products. * * These coded instructions, statements, and computer programs are the @@ -16,19 +16,20 @@ * * Contents: * - * _cupsStrAlloc() - Allocate/reference a string. - * _cupsStrFlush() - Flush the string pool... - * _cupsStrFormatd() - Format a floating-point number. - * _cupsStrFree() - Free/dereference a string. - * _cupsStrScand() - Scan a string for a floating-point number. - * _cupsStrStatistics() - Return allocation statistics for string pool. - * _cups_strcpy() - Copy a string allowing for overlapping strings. - * _cups_strdup() - Duplicate a string. - * _cups_strcasecmp() - Do a case-insensitive comparison. - * _cups_strncasecmp() - Do a case-insensitive comparison on up to N chars. - * _cups_strlcat() - Safely concatenate two strings. - * _cups_strlcpy() - Safely copy two strings. - * compare_sp_items() - Compare two string pool items... + * _cupsStrAlloc() - Allocate/reference a string. + * _cupsStrFlush() - Flush the string pool. + * _cupsStrFormatd() - Format a floating-point number. + * _cupsStrFree() - Free/dereference a string. + * _cupsStrRetain() - Increment the reference count of a string. + * _cupsStrScand() - Scan a string for a floating-point number. + * _cupsStrStatistics() - Return allocation statistics for string pool. + * _cups_strcpy() - Copy a string allowing for overlapping strings. + * _cups_strdup() - Duplicate a string. + * _cups_strcasecmp() - Do a case-insensitive comparison. + * _cups_strncasecmp() - Do a case-insensitive comparison on up to N chars. + * _cups_strlcat() - Safely concatenate two strings. + * _cups_strlcpy() - Safely copy two strings. + * compare_sp_items() - Compare two string pool items... */ /* @@ -72,7 +73,7 @@ char * /* O - String pointer */ _cupsStrAlloc(const char *s) /* I - String */ { _cups_sp_item_t *item, /* String pool item */ - key; /* Search key */ + *key; /* Search key */ /* @@ -106,9 +107,9 @@ _cupsStrAlloc(const char *s) /* I - String */ * See if the string is already in the pool... */ - key.str = (char *)s; + key = (_cups_sp_item_t *)(s - sizeof(unsigned int)); - if ((item = (_cups_sp_item_t *)cupsArrayFind(stringpool, &key)) != NULL) + if ((item = (_cups_sp_item_t *)cupsArrayFind(stringpool, key)) != NULL) { /* * Found it, return the cached string... @@ -127,7 +128,7 @@ _cupsStrAlloc(const char *s) /* I - String */ * Not found, so allocate a new one... */ - item = (_cups_sp_item_t *)calloc(1, sizeof(_cups_sp_item_t)); + item = (_cups_sp_item_t *)calloc(1, sizeof(_cups_sp_item_t) + strlen(s)); if (!item) { #ifdef HAVE_PTHREAD_H @@ -138,18 +139,7 @@ _cupsStrAlloc(const char *s) /* I - String */ } item->ref_count = 1; - item->str = strdup(s); - - if (!item->str) - { - free(item); - -#ifdef HAVE_PTHREAD_H - pthread_mutex_unlock(&sp_mutex); -#endif /* HAVE_PTHREAD_H */ - - return (NULL); - } + strcpy(item->str, s); /* * Add the string to the pool and return it... @@ -166,7 +156,7 @@ _cupsStrAlloc(const char *s) /* I - String */ /* - * '_cupsStrFlush()' - Flush the string pool... + * '_cupsStrFlush()' - Flush the string pool. */ void @@ -185,10 +175,7 @@ _cupsStrFlush(void) for (item = (_cups_sp_item_t *)cupsArrayFirst(stringpool); item; item = (_cups_sp_item_t *)cupsArrayNext(stringpool)) - { - free(item->str); free(item); - } cupsArrayDelete(stringpool); stringpool = NULL; @@ -287,7 +274,7 @@ void _cupsStrFree(const char *s) /* I - String to free */ { _cups_sp_item_t *item, /* String pool item */ - key; /* Search key */ + *key; /* Search key */ /* @@ -316,10 +303,10 @@ _cupsStrFree(const char *s) /* I - String to free */ pthread_mutex_lock(&sp_mutex); #endif /* HAVE_PTHREAD_H */ - key.str = (char *)s; + key = (_cups_sp_item_t *)(s - sizeof(unsigned int)); - if ((item = (_cups_sp_item_t *)cupsArrayFind(stringpool, &key)) != NULL && - item->str == s) + if ((item = (_cups_sp_item_t *)cupsArrayFind(stringpool, key)) != NULL && + item == key) { /* * Found it, dereference... @@ -335,7 +322,6 @@ _cupsStrFree(const char *s) /* I - String to free */ cupsArrayRemove(stringpool, item); - free(item->str); free(item); } } @@ -346,6 +332,39 @@ _cupsStrFree(const char *s) /* I - String to free */ } +/* + * '_cupsStrRetain()' - Increment the reference count of a string. + * + * Note: This function does not verify that the passed pointer is in the + * string pool, so any calls to it MUST know they are passing in a + * good pointer. + */ + +char * /* O - Pointer to string */ +_cupsStrRetain(char *s) /* I - String to retain */ +{ + _cups_sp_item_t *item; /* Pointer to string pool item */ + + + if (s) + { + item = (_cups_sp_item_t *)(s - sizeof(unsigned int)); + +#ifdef HAVE_PTHREAD_H + pthread_mutex_lock(&sp_mutex); +#endif /* HAVE_PTHREAD_H */ + + item->ref_count ++; + +#ifdef HAVE_PTHREAD_H + pthread_mutex_unlock(&sp_mutex); +#endif /* HAVE_PTHREAD_H */ + } + + return (s); +} + + /* * '_cupsStrScand()' - Scan a string for a floating-point number. * diff --git a/cups/string.h b/cups/string.h index e0cd0e49b2..e9a44ee8c3 100644 --- a/cups/string.h +++ b/cups/string.h @@ -68,8 +68,8 @@ extern "C" { typedef struct _cups_sp_item_s /**** String Pool Item ****/ { - char *str; /* String */ unsigned int ref_count; /* Reference count */ + char str[1]; /* String */ } _cups_sp_item_t; @@ -125,6 +125,7 @@ extern int _cups_vsnprintf(char *, size_t, const char *, va_list); extern char *_cupsStrAlloc(const char *s); extern void _cupsStrFlush(void); extern void _cupsStrFree(const char *s); +extern char *_cupsStrRetain(char *s); extern size_t _cupsStrStatistics(size_t *alloc_bytes, size_t *total_bytes); diff --git a/cups/tempfile.c b/cups/tempfile.c index 6dea52b100..664b915f8d 100644 --- a/cups/tempfile.c +++ b/cups/tempfile.c @@ -206,7 +206,7 @@ cupsTempFile(char *filename, /* I - Pointer to buffer */ * The temporary filename is returned in the filename buffer. * The temporary file is opened for writing. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ cups_file_t * /* O - CUPS file or @code NULL@ on error */ diff --git a/cups/testadmin.c b/cups/testadmin.c index e7603ec91d..09aaa324c9 100644 --- a/cups/testadmin.c +++ b/cups/testadmin.c @@ -3,7 +3,7 @@ * * Admin function test program for the Common UNIX Printing System (CUPS). * - * Copyright 2007 by Apple Inc. + * Copyright 2007-2008 by Apple Inc. * Copyright 2006 by Easy Software Products. * * These coded instructions, statements, and computer programs are the diff --git a/cups/testcups.c b/cups/testcups.c index 087ed4310f..834e08a90b 100644 --- a/cups/testcups.c +++ b/cups/testcups.c @@ -197,10 +197,10 @@ main(int argc, /* I - Number of command-line arguments */ fputs("cupsPrintFile: ", stdout); fflush(stdout); - if (cupsPrintFile(dest->name, "../data/testprint.ps", "Test Page", + if (cupsPrintFile(dest->name, "../data/testprint", "Test Page", dest->num_options, dest->options) <= 0) { - puts("FAIL"); + printf("FAIL (%s)\n", cupsLastErrorString()); return (1); } else diff --git a/cups/util.c b/cups/util.c index d03542cb9c..30c0f54906 100644 --- a/cups/util.c +++ b/cups/util.c @@ -449,7 +449,7 @@ cupsGetDefault(void) * functions to get the user-defined default printer, as this function does * not support the lpoptions-defined default printer. * - * @since CUPS 1.1.21@ + * @since CUPS 1.1.21/Mac OS X 10.4@ */ const char * /* O - Default printer or @code NULL@ */ @@ -546,7 +546,7 @@ cupsGetJobs(cups_job_t **jobs, /* O - Job data */ * pending, processing, or held and @code CUPS_WHICHJOBS_COMPLETED@ returns * jobs that are stopped, canceled, aborted, or completed. * - * @since CUPS 1.1.21@ + * @since CUPS 1.1.21/Mac OS X 10.4@ */ int /* O - Number of jobs */ @@ -848,7 +848,7 @@ cupsGetPPD(const char *name) /* I - Destination name */ * The returned filename is stored in a static buffer and is overwritten with * each call to @link cupsGetPPD@ or @code cupsGetPPD2@. * - * @since CUPS 1.1.21@ + * @since CUPS 1.1.21/Mac OS X 10.4@ */ const char * /* O - Filename for PPD file */ @@ -937,6 +937,110 @@ cupsGetPPD3(http_t *http, /* I - HTTP connection or @code CUPS_HTTP_DEFAUL return (HTTP_NOT_ACCEPTABLE); } +#ifndef WIN32 + /* + * See if the PPD file is available locally... + */ + + if (!cg->servername[0]) + cupsServer(); + + if (!strcasecmp(cg->servername, "localhost")) + { + char ppdname[1024]; /* PPD filename */ + struct stat ppdinfo; /* PPD file information */ + + + snprintf(ppdname, sizeof(ppdname), "%s/%s.ppd", cg->cups_serverroot, name); + if (!stat(ppdname, &ppdinfo)) + { + /* + * OK, the file exists, use it! + */ + + if (buffer[0]) + { + unlink(buffer); + + if (symlink(ppdname, buffer) && errno != EEXIST) + { + _cupsSetError(IPP_INTERNAL_ERROR, NULL, 0); + + return (HTTP_SERVER_ERROR); + } + } + else + { + int tries; /* Number of tries */ + const char *tmpdir; /* TMPDIR environment variable */ + struct timeval curtime; /* Current time */ + + /* + * Previously we put root temporary files in the default CUPS temporary + * directory under /var/spool/cups. However, since the scheduler cleans + * out temporary files there and runs independently of the user apps, we + * don't want to use it unless specifically told to by cupsd. + */ + + if ((tmpdir = getenv("TMPDIR")) == NULL) +# ifdef __APPLE__ + tmpdir = "/private/tmp"; /* /tmp is a symlink to /private/tmp */ +# else + tmpdir = "/tmp"; +# endif /* __APPLE__ */ + + /* + * Make the temporary name using the specified directory... + */ + + tries = 0; + + do + { + /* + * Get the current time of day... + */ + + gettimeofday(&curtime, NULL); + + /* + * Format a string using the hex time values... + */ + + snprintf(buffer, bufsize, "%s/%08lx%05lx", tmpdir, + (unsigned long)curtime.tv_sec, + (unsigned long)curtime.tv_usec); + + /* + * Try to make a symlink... + */ + + if (!symlink(ppdname, buffer)) + break; + + tries ++; + } + while (tries < 1000); + + if (tries >= 1000) + { + _cupsSetError(IPP_INTERNAL_ERROR, NULL, 0); + + return (HTTP_SERVER_ERROR); + } + } + + if (*modtime <= ppdinfo.st_mtime) + return (HTTP_NOT_MODIFIED); + else + { + *modtime = ppdinfo.st_mtime; + return (HTTP_OK); + } + } + } +#endif /* !WIN32 */ + /* * Try finding a printer URI for this printer... */ @@ -1181,7 +1285,7 @@ cupsGetPrinters(char ***printers) /* O - Printers */ * overwritten on the next call to @link cupsGetPPD@, @link cupsGetPPD2@, * or @link cupsGetServerPPD@. * - * @since CUPS 1.3@ + * @since CUPS 1.3/Mac OS X 10.5@ */ char * /* O - Name of PPD file or @code NULL@ on error */ @@ -1260,7 +1364,7 @@ cupsLastError(void) /* * 'cupsLastErrorString()' - Return the last IPP status-message. * - * @since CUPS 1.2@ + * @since CUPS 1.2/Mac OS X 10.5@ */ const char * /* O - status-message text from last request */ @@ -1294,7 +1398,7 @@ cupsPrintFile(const char *name, /* I - Destination name */ * 'cupsPrintFile2()' - Print a file to a printer or class on the specified * server. * - * @since CUPS 1.1.21@ + * @since CUPS 1.1.21/Mac OS X 10.4@ */ int /* O - Job ID or 0 on error */ @@ -1347,7 +1451,7 @@ cupsPrintFiles( * 'cupsPrintFiles2()' - Print one or more files to a printer or class on the * specified server. * - * @since CUPS 1.1.21@ + * @since CUPS 1.1.21/Mac OS X 10.4@ */ int /* O - Job ID or 0 on error */ diff --git a/doc/help/api-array.html b/doc/help/api-array.html index 300f41df5d..f7373e3b69 100644 --- a/doc/help/api-array.html +++ b/doc/help/api-array.html @@ -364,6 +364,7 @@ div.contents ul.subcontents li {

Contents