2 * "$Id: dest.c 7946 2008-09-16 23:27:54Z mike $"
4 * User-defined destination (and option) support for the Common UNIX
5 * Printing System (CUPS).
7 * Copyright 2007-2010 by Apple Inc.
8 * Copyright 1997-2007 by Easy Software Products.
10 * These coded instructions, statements, and computer programs are the
11 * property of Apple Inc. and are protected by Federal copyright
12 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
13 * which should have been included with this file. If this file is
14 * file is missing or damaged, see the license at "http://www.cups.org/".
16 * This file is subject to the Apple OS-Developed Software exception.
20 * cupsAddDest() - Add a destination to the list of destinations.
21 * cupsFreeDests() - Free the memory used by the list of destinations.
22 * cupsGetDest() - Get the named destination from the list.
23 * cupsGetDests() - Get the list of destinations from the default
25 * cupsGetDests2() - Get the list of destinations from the specified
27 * cupsGetNamedDest() - Get options for the named destination.
28 * cupsRemoveDest() - Remove a destination from the destination list.
29 * cupsSetDefaultDest() - Set the default destination.
30 * cupsSetDests() - Save the list of destinations for the default
32 * cupsSetDests2() - Save the list of destinations for the specified
34 * appleCopyLocations() - Copy the location history array.
35 * appleCopyNetwork() - Get the network ID for the current location.
36 * appleGetPaperSize() - Get the default paper size.
37 * appleGetPrinter() - Get a printer from the history array.
38 * appleSetDefault() - Set the default printer for this location.
39 * appleUseLastPrinter() - Get the default printer preference value.
40 * cups_add_dest() - Add a destination to the array.
41 * cups_compare_dests() - Compare two destinations.
42 * cups_find_dest() - Find a destination using a binary search.
43 * cups_get_default() - Get the default destination from an lpoptions file.
44 * cups_get_dests() - Get destinations from a file.
45 * cups_get_sdests() - Get destinations from a server.
46 * cups_make_string() - Make a comma-separated string of values from an IPP
51 * Include necessary headers...
56 #include "pwg-private.h"
63 #endif /* HAVE_NOTIFY_H */
66 # include <sys/cdefs.h>
67 # include <CoreFoundation/CoreFoundation.h>
68 # include <SystemConfiguration/SystemConfiguration.h>
69 # define kDefaultPaperIDKey CFSTR("DefaultPaperID")
70 # define kLocationHistoryArrayKey CFSTR("kLocationHistoryArrayKeyTMP")
71 # define kLocationNetworkKey CFSTR("kLocationNetworkKey")
72 # define kLocationPrinterIDKey CFSTR("kLocationPrinterIDKey")
73 # define kPMPrintingPreferences CFSTR("com.apple.print.PrintingPrefs")
74 # define kUseLastPrinterAsCurrentPrinterKey CFSTR("UseLastPrinterAsCurrentPrinter")
75 #endif /* __APPLE__ */
83 static CFArrayRef
appleCopyLocations(void);
84 static CFStringRef
appleCopyNetwork(void);
85 static char *appleGetPaperSize(char *name
, int namesize
);
86 static CFStringRef
appleGetPrinter(CFArrayRef locations
, CFStringRef network
,
88 static void appleSetDefault(const char *name
);
89 static int appleUseLastPrinter(void);
90 #endif /* __APPLE__ */
91 static cups_dest_t
*cups_add_dest(const char *name
, const char *instance
,
92 int *num_dests
, cups_dest_t
**dests
);
93 static int cups_compare_dests(cups_dest_t
*a
, cups_dest_t
*b
);
94 static int cups_find_dest(const char *name
, const char *instance
,
95 int num_dests
, cups_dest_t
*dests
, int prev
,
97 static char *cups_get_default(const char *filename
, char *namebuf
,
98 size_t namesize
, const char **instance
);
99 static int cups_get_dests(const char *filename
, const char *match_name
,
100 const char *match_inst
, int user_default_set
,
101 int num_dests
, cups_dest_t
**dests
);
102 static int cups_get_sdests(http_t
*http
, ipp_op_t op
, const char *name
,
103 int num_dests
, cups_dest_t
**dests
);
104 static char *cups_make_string(ipp_attribute_t
*attr
, char *buffer
,
109 * 'cupsAddDest()' - Add a destination to the list of destinations.
111 * This function cannot be used to add a new class or printer queue,
112 * it only adds a new container of saved options for the named
113 * destination or instance.
115 * If the named destination already exists, the destination list is
116 * returned unchanged. Adding a new instance of a destination creates
117 * a copy of that destination's options.
119 * Use the @link cupsSaveDests@ function to save the updated list of
120 * destinations to the user's lpoptions file.
123 int /* O - New number of destinations */
124 cupsAddDest(const char *name
, /* I - Destination name */
125 const char *instance
, /* I - Instance name or @code NULL@ for none/primary */
126 int num_dests
, /* I - Number of destinations */
127 cups_dest_t
**dests
) /* IO - Destinations */
129 int i
; /* Looping var */
130 cups_dest_t
*dest
; /* Destination pointer */
131 cups_dest_t
*parent
= NULL
; /* Parent destination */
132 cups_option_t
*doption
, /* Current destination option */
133 *poption
; /* Current parent option */
139 if (!cupsGetDest(name
, instance
, num_dests
, *dests
))
141 if (instance
&& !cupsGetDest(name
, NULL
, num_dests
, *dests
))
144 dest
= cups_add_dest(name
, instance
, &num_dests
, dests
);
147 * Find the base dest again now the array has been realloc'd.
150 parent
= cupsGetDest(name
, NULL
, num_dests
, *dests
);
152 if (instance
&& parent
&& parent
->num_options
> 0)
155 * Copy options from parent...
158 dest
->options
= calloc(sizeof(cups_option_t
), parent
->num_options
);
162 dest
->num_options
= parent
->num_options
;
164 for (i
= dest
->num_options
, doption
= dest
->options
,
165 poption
= parent
->options
;
167 i
--, doption
++, poption
++)
169 doption
->name
= _cupsStrRetain(poption
->name
);
170 doption
->value
= _cupsStrRetain(poption
->value
);
181 * 'cupsFreeDests()' - Free the memory used by the list of destinations.
185 cupsFreeDests(int num_dests
, /* I - Number of destinations */
186 cups_dest_t
*dests
) /* I - Destinations */
188 int i
; /* Looping var */
189 cups_dest_t
*dest
; /* Current destination */
192 if (num_dests
== 0 || dests
== NULL
)
195 for (i
= num_dests
, dest
= dests
; i
> 0; i
--, dest
++)
197 _cupsStrFree(dest
->name
);
198 _cupsStrFree(dest
->instance
);
200 cupsFreeOptions(dest
->num_options
, dest
->options
);
208 * 'cupsGetDest()' - Get the named destination from the list.
210 * Use the @link cupsGetDests@ or @link cupsGetDests2@ functions to get a
211 * list of supported destinations for the current user.
214 cups_dest_t
* /* O - Destination pointer or @code NULL@ */
215 cupsGetDest(const char *name
, /* I - Destination name or @code NULL@ for the default destination */
216 const char *instance
, /* I - Instance name or @code NULL@ */
217 int num_dests
, /* I - Number of destinations */
218 cups_dest_t
*dests
) /* I - Destinations */
220 int diff
, /* Result of comparison */
221 match
; /* Matching index */
224 if (num_dests
<= 0 || !dests
)
230 * NULL name for default printer.
233 while (num_dests
> 0)
235 if (dests
->is_default
)
245 * Lookup name and optionally the instance...
248 match
= cups_find_dest(name
, instance
, num_dests
, dests
, -1, &diff
);
251 return (dests
+ match
);
259 * 'cupsGetDests()' - Get the list of destinations from the default server.
261 * Starting with CUPS 1.2, the returned list of destinations include the
262 * printer-info, printer-is-accepting-jobs, printer-is-shared,
263 * printer-make-and-model, printer-state, printer-state-change-time,
264 * printer-state-reasons, and printer-type attributes as options. CUPS 1.4
265 * adds the marker-change-time, marker-colors, marker-high-levels,
266 * marker-levels, marker-low-levels, marker-message, marker-names,
267 * marker-types, and printer-commands attributes as well.
269 * Use the @link cupsFreeDests@ function to free the destination list and
270 * the @link cupsGetDest@ function to find a particular destination.
273 int /* O - Number of destinations */
274 cupsGetDests(cups_dest_t
**dests
) /* O - Destinations */
276 return (cupsGetDests2(CUPS_HTTP_DEFAULT
, dests
));
281 * 'cupsGetDests2()' - Get the list of destinations from the specified server.
283 * Starting with CUPS 1.2, the returned list of destinations include the
284 * printer-info, printer-is-accepting-jobs, printer-is-shared,
285 * printer-make-and-model, printer-state, printer-state-change-time,
286 * printer-state-reasons, and printer-type attributes as options. CUPS 1.4
287 * adds the marker-change-time, marker-colors, marker-high-levels,
288 * marker-levels, marker-low-levels, marker-message, marker-names,
289 * marker-types, and printer-commands attributes as well.
291 * Use the @link cupsFreeDests@ function to free the destination list and
292 * the @link cupsGetDest@ function to find a particular destination.
294 * @since CUPS 1.1.21/Mac OS X 10.4@
297 int /* O - Number of destinations */
298 cupsGetDests2(http_t
*http
, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
299 cups_dest_t
**dests
) /* O - Destinations */
301 int i
; /* Looping var */
302 int num_dests
; /* Number of destinations */
303 cups_dest_t
*dest
; /* Destination pointer */
304 const char *home
; /* HOME environment variable */
305 char filename
[1024]; /* Local ~/.cups/lpoptions file */
306 const char *defprinter
; /* Default printer */
307 char name
[1024], /* Copy of printer name */
308 *instance
, /* Pointer to instance name */
309 *user_default
; /* User default printer */
310 int num_reals
; /* Number of real queues */
311 cups_dest_t
*reals
; /* Real queues */
312 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
316 * Range check the input...
321 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad NULL dests pointer"), 1);
326 * Initialize destination array...
330 *dests
= (cups_dest_t
*)0;
333 * Grab the printers and classes...
336 num_dests
= cups_get_sdests(http
, CUPS_GET_PRINTERS
, NULL
, num_dests
, dests
);
338 if (cupsLastError() >= IPP_REDIRECTION_OTHER_SITE
)
340 cupsFreeDests(num_dests
, *dests
);
341 *dests
= (cups_dest_t
*)0;
346 * Make a copy of the "real" queues for a later sanity check...
351 num_reals
= num_dests
;
352 reals
= calloc(num_reals
, sizeof(cups_dest_t
));
355 memcpy(reals
, *dests
, num_reals
* sizeof(cups_dest_t
));
366 * Grab the default destination...
369 if ((user_default
= _cupsUserDefault(name
, sizeof(name
))) != NULL
)
371 else if ((defprinter
= cupsGetDefault2(http
)) != NULL
)
373 strlcpy(name
, defprinter
, sizeof(name
));
380 * Separate printer and instance name...
383 if ((instance
= strchr(name
, '/')) != NULL
)
387 * Lookup the printer and instance and make it the default...
390 if ((dest
= cupsGetDest(name
, instance
, num_dests
, *dests
)) != NULL
)
391 dest
->is_default
= 1;
397 * Load the /etc/cups/lpoptions and ~/.cups/lpoptions files...
400 snprintf(filename
, sizeof(filename
), "%s/lpoptions", cg
->cups_serverroot
);
401 num_dests
= cups_get_dests(filename
, NULL
, NULL
, user_default
!= NULL
,
404 if ((home
= getenv("HOME")) != NULL
)
406 snprintf(filename
, sizeof(filename
), "%s/.cups/lpoptions", home
);
408 num_dests
= cups_get_dests(filename
, NULL
, NULL
, user_default
!= NULL
,
413 * Validate the current default destination - this prevents old
414 * Default lines in /etc/cups/lpoptions and ~/.cups/lpoptions from
415 * pointing to a non-existent printer or class...
421 * See if we have a default printer...
424 if ((dest
= cupsGetDest(NULL
, NULL
, num_dests
, *dests
)) != NULL
)
427 * Have a default; see if it is real...
430 dest
= cupsGetDest(dest
->name
, NULL
, num_reals
, reals
);
434 * If dest is NULL, then no default (that exists) is set, so we
435 * need to set a default if one exists...
438 if (dest
== NULL
&& defprinter
!= NULL
)
440 for (i
= 0; i
< num_dests
; i
++)
441 (*dests
)[i
].is_default
= 0;
443 if ((dest
= cupsGetDest(name
, instance
, num_dests
, *dests
)) != NULL
)
444 dest
->is_default
= 1;
455 * Return the number of destinations...
459 _cupsSetError(IPP_OK
, NULL
, 0);
466 * 'cupsGetNamedDest()' - Get options for the named destination.
468 * This function is optimized for retrieving a single destination and should
469 * be used instead of @link cupsGetDests@ and @link cupsGetDest@ when you either
470 * know the name of the destination or want to print to the default destination.
471 * If @code NULL@ is returned, the destination does not exist or there is no
472 * default destination.
474 * If "http" is @code CUPS_HTTP_DEFAULT@, the connection to the default print
475 * server will be used.
477 * If "name" is @code NULL@, the default printer for the current user will be
480 * The returned destination must be freed using @link cupsFreeDests@ with a
481 * "num_dests" value of 1.
483 * @since CUPS 1.4/Mac OS X 10.6@
486 cups_dest_t
* /* O - Destination or @code NULL@ */
487 cupsGetNamedDest(http_t
*http
, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
488 const char *name
, /* I - Destination name or @code NULL@ for the default destination */
489 const char *instance
) /* I - Instance name or @code NULL@ */
491 cups_dest_t
*dest
; /* Destination */
492 char filename
[1024], /* Path to lpoptions */
493 defname
[256]; /* Default printer name */
494 const char *home
= getenv("HOME"); /* Home directory */
495 int set_as_default
= 0; /* Set returned destination as default */
496 ipp_op_t op
= IPP_GET_PRINTER_ATTRIBUTES
;
497 /* IPP operation to get server ops */
498 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
502 * If "name" is NULL, find the default destination...
508 name
= _cupsUserDefault(defname
, sizeof(defname
));
513 * No default in the environment, try the user's lpoptions files...
516 snprintf(filename
, sizeof(filename
), "%s/.cups/lpoptions", home
);
518 name
= cups_get_default(filename
, defname
, sizeof(defname
), &instance
);
524 * Still not there? Try the system lpoptions file...
527 snprintf(filename
, sizeof(filename
), "%s/lpoptions",
528 cg
->cups_serverroot
);
529 name
= cups_get_default(filename
, defname
, sizeof(defname
), &instance
);
535 * No locally-set default destination, ask the server...
538 op
= CUPS_GET_DEFAULT
;
543 * Get the printer's attributes...
546 if (!cups_get_sdests(http
, op
, name
, 0, &dest
))
548 if (op
== CUPS_GET_DEFAULT
|| (name
&& !set_as_default
))
552 * The default printer from environment variables or from a
553 * configuration file does not exist. Find out the real default.
556 if (!cups_get_sdests(http
, CUPS_GET_DEFAULT
, NULL
, 0, &dest
))
561 dest
->instance
= _cupsStrAlloc(instance
);
564 dest
->is_default
= 1;
567 * Then add local options...
570 snprintf(filename
, sizeof(filename
), "%s/lpoptions", cg
->cups_serverroot
);
571 cups_get_dests(filename
, name
, instance
, 1, 1, &dest
);
575 snprintf(filename
, sizeof(filename
), "%s/.cups/lpoptions", home
);
577 cups_get_dests(filename
, name
, instance
, 1, 1, &dest
);
581 * Return the result...
589 * 'cupsRemoveDest()' - Remove a destination from the destination list.
591 * Removing a destination/instance does not delete the class or printer
592 * queue, merely the lpoptions for that destination/instance. Use the
593 * @link cupsSetDests@ or @link cupsSetDests2@ functions to save the new
594 * options for the user.
596 * @since CUPS 1.3/Mac OS X 10.5@
599 int /* O - New number of destinations */
600 cupsRemoveDest(const char *name
, /* I - Destination name */
601 const char *instance
, /* I - Instance name or @code NULL@ */
602 int num_dests
, /* I - Number of destinations */
603 cups_dest_t
**dests
) /* IO - Destinations */
605 int i
; /* Index into destinations */
606 cups_dest_t
*dest
; /* Pointer to destination */
610 * Find the destination...
613 if ((dest
= cupsGetDest(name
, instance
, num_dests
, *dests
)) == NULL
)
620 _cupsStrFree(dest
->name
);
621 _cupsStrFree(dest
->instance
);
622 cupsFreeOptions(dest
->num_options
, dest
->options
);
625 * Remove the destination from the array...
633 memmove(dest
, dest
+ 1, (num_dests
- i
) * sizeof(cups_dest_t
));
640 * 'cupsSetDefaultDest()' - Set the default destination.
642 * @since CUPS 1.3/Mac OS X 10.5@
647 const char *name
, /* I - Destination name */
648 const char *instance
, /* I - Instance name or @code NULL@ */
649 int num_dests
, /* I - Number of destinations */
650 cups_dest_t
*dests
) /* I - Destinations */
652 int i
; /* Looping var */
653 cups_dest_t
*dest
; /* Current destination */
657 * Range check input...
660 if (!name
|| num_dests
<= 0 || !dests
)
664 * Loop through the array and set the "is_default" flag for the matching
668 for (i
= num_dests
, dest
= dests
; i
> 0; i
--, dest
++)
669 dest
->is_default
= !strcasecmp(name
, dest
->name
) &&
670 ((!instance
&& !dest
->instance
) ||
671 (instance
&& dest
->instance
&&
672 !strcasecmp(instance
, dest
->instance
)));
677 * 'cupsSetDests()' - Save the list of destinations for the default server.
679 * This function saves the destinations to /etc/cups/lpoptions when run
680 * as root and ~/.cups/lpoptions when run as a normal user.
684 cupsSetDests(int num_dests
, /* I - Number of destinations */
685 cups_dest_t
*dests
) /* I - Destinations */
687 cupsSetDests2(CUPS_HTTP_DEFAULT
, num_dests
, dests
);
692 * 'cupsSetDests2()' - Save the list of destinations for the specified server.
694 * This function saves the destinations to /etc/cups/lpoptions when run
695 * as root and ~/.cups/lpoptions when run as a normal user.
697 * @since CUPS 1.1.21/Mac OS X 10.4@
700 int /* O - 0 on success, -1 on error */
701 cupsSetDests2(http_t
*http
, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
702 int num_dests
, /* I - Number of destinations */
703 cups_dest_t
*dests
) /* I - Destinations */
705 int i
, j
; /* Looping vars */
706 int wrote
; /* Wrote definition? */
707 cups_dest_t
*dest
; /* Current destination */
708 cups_option_t
*option
; /* Current option */
709 _ipp_option_t
*match
; /* Matching attribute for option */
710 FILE *fp
; /* File pointer */
712 const char *home
; /* HOME environment variable */
714 char filename
[1024]; /* lpoptions file */
715 int num_temps
; /* Number of temporary destinations */
716 cups_dest_t
*temps
, /* Temporary destinations */
717 *temp
; /* Current temporary dest */
718 const char *val
; /* Value of temporary option */
719 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
723 * Range check the input...
726 if (!num_dests
|| !dests
)
730 * Get the server destinations...
733 num_temps
= cups_get_sdests(http
, CUPS_GET_PRINTERS
, NULL
, 0, &temps
);
735 if (cupsLastError() >= IPP_REDIRECTION_OTHER_SITE
)
737 cupsFreeDests(num_temps
, temps
);
742 * Figure out which file to write to...
745 snprintf(filename
, sizeof(filename
), "%s/lpoptions", cg
->cups_serverroot
);
751 * Merge in server defaults...
754 num_temps
= cups_get_dests(filename
, NULL
, NULL
, 0, num_temps
, &temps
);
757 * Point to user defaults...
760 if ((home
= getenv("HOME")) != NULL
)
763 * Create ~/.cups subdirectory...
766 snprintf(filename
, sizeof(filename
), "%s/.cups", home
);
767 if (access(filename
, 0))
768 mkdir(filename
, 0700);
770 snprintf(filename
, sizeof(filename
), "%s/.cups/lpoptions", home
);
776 * Try to open the file...
779 if ((fp
= fopen(filename
, "w")) == NULL
)
781 cupsFreeDests(num_temps
, temps
);
787 * Set the permissions to 0644 when saving to the /etc/cups/lpoptions
792 fchmod(fileno(fp
), 0644);
796 * Write each printer; each line looks like:
798 * Dest name[/instance] options
799 * Default name[/instance] options
802 for (i
= num_dests
, dest
= dests
; i
> 0; i
--, dest
++)
803 if (dest
->instance
!= NULL
|| dest
->num_options
!= 0 || dest
->is_default
)
805 if (dest
->is_default
)
807 fprintf(fp
, "Default %s", dest
->name
);
809 fprintf(fp
, "/%s", dest
->instance
);
816 if ((temp
= cupsGetDest(dest
->name
, dest
->instance
, num_temps
, temps
)) == NULL
)
817 temp
= cupsGetDest(dest
->name
, NULL
, num_temps
, temps
);
819 for (j
= dest
->num_options
, option
= dest
->options
; j
> 0; j
--, option
++)
822 * See if this option is a printer attribute; if so, skip it...
825 if ((match
= _ippFindOption(option
->name
)) != NULL
&&
826 match
->group_tag
== IPP_TAG_PRINTER
)
830 * See if the server/global options match these; if so, don't
835 (val
= cupsGetOption(option
->name
, temp
->num_options
,
836 temp
->options
)) != NULL
&&
837 !strcasecmp(val
, option
->value
))
841 * Options don't match, write to the file...
846 fprintf(fp
, "Dest %s", dest
->name
);
848 fprintf(fp
, "/%s", dest
->instance
);
852 if (option
->value
[0])
854 if (strchr(option
->value
, ' ') ||
855 strchr(option
->value
, '\\') ||
856 strchr(option
->value
, '\"') ||
857 strchr(option
->value
, '\''))
863 fprintf(fp
, " %s=\"", option
->name
);
865 for (val
= option
->value
; *val
; val
++)
867 if (strchr("\"\'\\", *val
))
878 * Store the literal value...
881 fprintf(fp
, " %s=%s", option
->name
, option
->value
);
885 fprintf(fp
, " %s", option
->name
);
893 * Free the temporary destinations and close the file...
896 cupsFreeDests(num_temps
, temps
);
902 * Set the default printer for this location - this allows command-line
903 * and GUI applications to share the same default destination...
906 if ((dest
= cupsGetDest(NULL
, NULL
, num_dests
, dests
)) != NULL
)
907 appleSetDefault(dest
->name
);
908 #endif /* __APPLE__ */
910 #ifdef HAVE_NOTIFY_POST
912 * Send a notification so that MacOS X applications can know about the
916 notify_post("com.apple.printerListChange");
917 #endif /* HAVE_NOTIFY_POST */
924 * '_cupsUserDefault()' - Get the user default printer from environment
925 * variables and location information.
928 char * /* O - Default printer or NULL */
929 _cupsUserDefault(char *name
, /* I - Name buffer */
930 size_t namesize
) /* I - Size of name buffer */
932 const char *env
; /* LPDEST or PRINTER env variable */
934 CFStringRef network
; /* Network location */
935 CFArrayRef locations
; /* Location array */
936 CFStringRef locprinter
; /* Current printer */
937 #endif /* __APPLE__ */
940 if ((env
= getenv("LPDEST")) == NULL
)
941 if ((env
= getenv("PRINTER")) != NULL
&& !strcmp(env
, "lp"))
946 strlcpy(name
, env
, namesize
);
952 * Use location-based defaults if "use last printer" is selected in the
953 * system preferences...
956 if (!appleUseLastPrinter())
958 DEBUG_puts("1_cupsUserDefault: Not using last printer as default...");
964 * Get the current location...
967 if ((network
= appleCopyNetwork()) == NULL
)
969 DEBUG_puts("1_cupsUserDefault: Unable to get current network...");
975 CFStringGetCString(network
, name
, namesize
, kCFStringEncodingUTF8
);
976 DEBUG_printf(("2_cupsUserDefault: network=\"%s\"", name
));
980 * Lookup the network in the preferences...
983 if ((locations
= appleCopyLocations()) == NULL
)
986 * Missing or bad location array, so no location-based default...
989 DEBUG_puts("1_cupsUserDefault: Missing or bad location history array...");
997 DEBUG_printf(("2_cupsUserDefault: Got location, %d entries...",
998 (int)CFArrayGetCount(locations
)));
1000 if ((locprinter
= appleGetPrinter(locations
, network
, NULL
)) != NULL
)
1001 CFStringGetCString(locprinter
, name
, namesize
, kCFStringEncodingUTF8
);
1006 CFRelease(locations
);
1008 DEBUG_printf(("1_cupsUserDefault: Returning \"%s\"...", name
));
1010 return (*name
? name
: NULL
);
1014 * No location-based defaults on this platform...
1019 #endif /* __APPLE__ */
1025 * 'appleCopyLocations()' - Copy the location history array.
1028 static CFArrayRef
/* O - Location array or NULL */
1029 appleCopyLocations(void)
1031 CFArrayRef locations
; /* Location array */
1035 * Look up the location array in the preferences...
1038 if ((locations
= CFPreferencesCopyAppValue(kLocationHistoryArrayKey
,
1039 kPMPrintingPreferences
)) == NULL
)
1042 if (CFGetTypeID(locations
) != CFArrayGetTypeID())
1044 CFRelease(locations
);
1053 * 'appleCopyNetwork()' - Get the network ID for the current location.
1056 static CFStringRef
/* O - Network ID */
1057 appleCopyNetwork(void)
1059 SCDynamicStoreRef dynamicStore
; /* System configuration data */
1060 CFStringRef key
; /* Current network configuration key */
1061 CFDictionaryRef ip_dict
; /* Network configuration data */
1062 CFStringRef network
= NULL
; /* Current network ID */
1065 if ((dynamicStore
= SCDynamicStoreCreate(NULL
, CFSTR("Printing"), NULL
,
1068 if ((key
= SCDynamicStoreKeyCreateNetworkGlobalEntity(
1069 NULL
, kSCDynamicStoreDomainState
, kSCEntNetIPv4
)) != NULL
)
1071 if ((ip_dict
= SCDynamicStoreCopyValue(dynamicStore
, key
)) != NULL
)
1073 if ((network
= CFDictionaryGetValue(ip_dict
,
1074 kSCPropNetIPv4Router
)) != NULL
)
1083 CFRelease(dynamicStore
);
1091 * 'appleGetPaperSize()' - Get the default paper size.
1094 static char * /* O - Default paper size */
1095 appleGetPaperSize(char *name
, /* I - Paper size name buffer */
1096 int namesize
) /* I - Size of buffer */
1098 CFStringRef defaultPaperID
; /* Default paper ID */
1099 _pwg_media_t
*pwgmedia
; /* PWG media size */
1102 defaultPaperID
= CFPreferencesCopyAppValue(kDefaultPaperIDKey
,
1103 kPMPrintingPreferences
);
1104 if (!defaultPaperID
||
1105 CFGetTypeID(defaultPaperID
) != CFStringGetTypeID() ||
1106 !CFStringGetCString(defaultPaperID
, name
, namesize
,
1107 kCFStringEncodingUTF8
))
1109 else if ((pwgmedia
= _pwgMediaForLegacy(name
)) != NULL
)
1110 strlcpy(name
, pwgmedia
->pwg
, namesize
);
1113 CFRelease(defaultPaperID
);
1120 * 'appleGetPrinter()' - Get a printer from the history array.
1123 static CFStringRef
/* O - Printer name or NULL */
1124 appleGetPrinter(CFArrayRef locations
, /* I - Location array */
1125 CFStringRef network
, /* I - Network name */
1126 CFIndex
*locindex
) /* O - Index in array */
1128 CFIndex i
, /* Looping var */
1129 count
; /* Number of locations */
1130 CFDictionaryRef location
; /* Current location */
1131 CFStringRef locnetwork
, /* Current network */
1132 locprinter
; /* Current printer */
1135 for (i
= 0, count
= CFArrayGetCount(locations
); i
< count
; i
++)
1136 if ((location
= CFArrayGetValueAtIndex(locations
, i
)) != NULL
&&
1137 CFGetTypeID(location
) == CFDictionaryGetTypeID())
1139 if ((locnetwork
= CFDictionaryGetValue(location
,
1140 kLocationNetworkKey
)) != NULL
&&
1141 CFGetTypeID(locnetwork
) == CFStringGetTypeID() &&
1142 CFStringCompare(network
, locnetwork
, 0) == kCFCompareEqualTo
&&
1143 (locprinter
= CFDictionaryGetValue(location
,
1144 kLocationPrinterIDKey
)) != NULL
&&
1145 CFGetTypeID(locprinter
) == CFStringGetTypeID())
1150 return (locprinter
);
1159 * 'appleSetDefault()' - Set the default printer for this location.
1163 appleSetDefault(const char *name
) /* I - Default printer/class name */
1165 CFStringRef network
; /* Current network */
1166 CFArrayRef locations
; /* Old locations array */
1167 CFIndex locindex
; /* Index in locations array */
1168 CFStringRef locprinter
; /* Current printer */
1169 CFMutableArrayRef newlocations
; /* New locations array */
1170 CFMutableDictionaryRef newlocation
; /* New location */
1171 CFStringRef newprinter
; /* New printer */
1175 * Get the current location...
1178 if ((network
= appleCopyNetwork()) == NULL
)
1180 DEBUG_puts("1appleSetDefault: Unable to get current network...");
1184 if ((newprinter
= CFStringCreateWithCString(kCFAllocatorDefault
, name
,
1185 kCFStringEncodingUTF8
)) == NULL
)
1192 * Lookup the network in the preferences...
1195 if ((locations
= appleCopyLocations()) != NULL
)
1196 locprinter
= appleGetPrinter(locations
, network
, &locindex
);
1204 CFStringCompare(locprinter
, newprinter
, 0) != kCFCompareEqualTo
)
1207 * Need to change the locations array...
1212 newlocations
= CFArrayCreateMutableCopy(kCFAllocatorDefault
, 0,
1216 CFArrayRemoveValueAtIndex(newlocations
, locindex
);
1219 newlocations
= CFArrayCreateMutable(kCFAllocatorDefault
, 0, NULL
);
1221 newlocation
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
1222 &kCFTypeDictionaryKeyCallBacks
,
1223 &kCFTypeDictionaryValueCallBacks
);
1225 if (newlocation
&& newlocations
)
1228 * Put the new location at the front of the array...
1231 CFDictionaryAddValue(newlocation
, kLocationNetworkKey
, network
);
1232 CFDictionaryAddValue(newlocation
, kLocationPrinterIDKey
, newprinter
);
1233 CFArrayInsertValueAtIndex(newlocations
, 0, newlocation
);
1236 * Limit the number of locations to 10...
1239 while (CFArrayGetCount(newlocations
) > 10)
1240 CFArrayRemoveValueAtIndex(newlocations
, 10);
1243 * Push the changes out...
1246 CFPreferencesSetAppValue(kLocationHistoryArrayKey
, newlocations
,
1247 kPMPrintingPreferences
);
1248 CFPreferencesAppSynchronize(kPMPrintingPreferences
);
1249 notify_post("com.apple.printerPrefsChange");
1253 CFRelease(newlocations
);
1256 CFRelease(newlocation
);
1260 CFRelease(locations
);
1263 CFRelease(newprinter
);
1268 * 'appleUseLastPrinter()' - Get the default printer preference value.
1271 static int /* O - 1 to use last printer, 0 otherwise */
1272 appleUseLastPrinter(void)
1274 CFPropertyListRef uselast
; /* Use last printer preference value */
1277 if (getenv("CUPS_DISABLE_APPLE_DEFAULT"))
1280 if ((uselast
= CFPreferencesCopyAppValue(kUseLastPrinterAsCurrentPrinterKey
,
1281 kPMPrintingPreferences
)) != NULL
)
1285 if (uselast
== kCFBooleanFalse
)
1291 #endif /* __APPLE__ */
1295 * 'cups_add_dest()' - Add a destination to the array.
1297 * Unlike cupsAddDest(), this function does not check for duplicates.
1300 static cups_dest_t
* /* O - New destination */
1301 cups_add_dest(const char *name
, /* I - Name of destination */
1302 const char *instance
, /* I - Instance or NULL */
1303 int *num_dests
, /* IO - Number of destinations */
1304 cups_dest_t
**dests
) /* IO - Destinations */
1306 int insert
, /* Insertion point */
1307 diff
; /* Result of comparison */
1308 cups_dest_t
*dest
; /* Destination pointer */
1312 * Add new destination...
1315 if (*num_dests
== 0)
1316 dest
= malloc(sizeof(cups_dest_t
));
1318 dest
= realloc(*dests
, sizeof(cups_dest_t
) * (*num_dests
+ 1));
1326 * Find where to insert the destination...
1329 if (*num_dests
== 0)
1333 insert
= cups_find_dest(name
, instance
, *num_dests
, *dests
, *num_dests
- 1,
1341 * Move the array elements as needed...
1344 if (insert
< *num_dests
)
1345 memmove(*dests
+ insert
+ 1, *dests
+ insert
,
1346 (*num_dests
- insert
) * sizeof(cups_dest_t
));
1351 * Initialize the destination...
1354 dest
= *dests
+ insert
;
1355 dest
->name
= _cupsStrAlloc(name
);
1356 dest
->instance
= _cupsStrAlloc(instance
);
1357 dest
->is_default
= 0;
1358 dest
->num_options
= 0;
1359 dest
->options
= (cups_option_t
*)0;
1366 * 'cups_compare_dests()' - Compare two destinations.
1369 static int /* O - Result of comparison */
1370 cups_compare_dests(cups_dest_t
*a
, /* I - First destination */
1371 cups_dest_t
*b
) /* I - Second destination */
1373 int diff
; /* Difference */
1376 if ((diff
= strcasecmp(a
->name
, b
->name
)) != 0)
1378 else if (a
->instance
&& b
->instance
)
1379 return (strcasecmp(a
->instance
, b
->instance
));
1381 return ((a
->instance
&& !b
->instance
) - (!a
->instance
&& b
->instance
));
1386 * 'cups_find_dest()' - Find a destination using a binary search.
1389 static int /* O - Index of match */
1390 cups_find_dest(const char *name
, /* I - Destination name */
1391 const char *instance
, /* I - Instance or NULL */
1392 int num_dests
, /* I - Number of destinations */
1393 cups_dest_t
*dests
, /* I - Destinations */
1394 int prev
, /* I - Previous index */
1395 int *rdiff
) /* O - Difference of match */
1397 int left
, /* Low mark for binary search */
1398 right
, /* High mark for binary search */
1399 current
, /* Current index */
1400 diff
; /* Result of comparison */
1401 cups_dest_t key
; /* Search key */
1404 key
.name
= (char *)name
;
1405 key
.instance
= (char *)instance
;
1410 * Start search on either side of previous...
1413 if ((diff
= cups_compare_dests(&key
, dests
+ prev
)) == 0 ||
1414 (diff
< 0 && prev
== 0) ||
1415 (diff
> 0 && prev
== (num_dests
- 1)))
1423 * Start with previous on right side...
1432 * Start wih previous on left side...
1436 right
= num_dests
- 1;
1442 * Start search in the middle...
1446 right
= num_dests
- 1;
1451 current
= (left
+ right
) / 2;
1452 diff
= cups_compare_dests(&key
, dests
+ current
);
1461 while ((right
- left
) > 1);
1466 * Check the last 1 or 2 elements...
1469 if ((diff
= cups_compare_dests(&key
, dests
+ left
)) <= 0)
1473 diff
= cups_compare_dests(&key
, dests
+ right
);
1479 * Return the closest destination and the difference...
1489 * 'cups_get_default()' - Get the default destination from an lpoptions file.
1492 static char * /* O - Default destination or NULL */
1493 cups_get_default(const char *filename
, /* I - File to read */
1494 char *namebuf
, /* I - Name buffer */
1495 size_t namesize
, /* I - Size of name buffer */
1496 const char **instance
) /* I - Instance */
1498 cups_file_t
*fp
; /* lpoptions file */
1499 char line
[8192], /* Line from file */
1500 *value
, /* Value for line */
1501 *nameptr
; /* Pointer into name */
1502 int linenum
; /* Current line */
1507 if ((fp
= cupsFileOpen(filename
, "r")) != NULL
)
1511 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
1513 if (!strcasecmp(line
, "default") && value
)
1515 strlcpy(namebuf
, value
, namesize
);
1517 if ((nameptr
= strchr(namebuf
, ' ')) != NULL
)
1519 if ((nameptr
= strchr(namebuf
, '\t')) != NULL
)
1522 if ((nameptr
= strchr(namebuf
, '/')) != NULL
)
1525 *instance
= nameptr
;
1533 return (*namebuf
? namebuf
: NULL
);
1538 * 'cups_get_dests()' - Get destinations from a file.
1541 static int /* O - Number of destinations */
1543 const char *filename
, /* I - File to read from */
1544 const char *match_name
, /* I - Destination name we want */
1545 const char *match_inst
, /* I - Instance name we want */
1546 int user_default_set
, /* I - User default printer set? */
1547 int num_dests
, /* I - Number of destinations */
1548 cups_dest_t
**dests
) /* IO - Destinations */
1550 int i
; /* Looping var */
1551 cups_dest_t
*dest
; /* Current destination */
1552 cups_file_t
*fp
; /* File pointer */
1553 char line
[8192], /* Line from file */
1554 *lineptr
, /* Pointer into line */
1555 *name
, /* Name of destination/option */
1556 *instance
; /* Instance of destination */
1557 int linenum
; /* Current line number */
1560 DEBUG_printf(("7cups_get_dests(filename=\"%s\", match_name=\"%s\", "
1561 "match_inst=\"%s\", user_default_set=%d, num_dests=%d, "
1562 "dests=%p)", filename
, match_name
, match_inst
,
1563 user_default_set
, num_dests
, dests
));
1566 * Try to open the file...
1569 if ((fp
= cupsFileOpen(filename
, "r")) == NULL
)
1573 * Read each printer; each line looks like:
1575 * Dest name[/instance] options
1576 * Default name[/instance] options
1581 while (cupsFileGetConf(fp
, line
, sizeof(line
), &lineptr
, &linenum
))
1584 * See what type of line it is...
1587 DEBUG_printf(("9cups_get_dests: linenum=%d line=\"%s\" lineptr=\"%s\"",
1588 linenum
, line
, lineptr
));
1590 if ((strcasecmp(line
, "dest") && strcasecmp(line
, "default")) || !lineptr
)
1592 DEBUG_puts("9cups_get_dests: Not a dest or default line...");
1599 * Search for an instance...
1602 while (!isspace(*lineptr
& 255) && *lineptr
&& *lineptr
!= '/')
1605 if (*lineptr
== '/')
1608 * Found an instance...
1615 * Search for an instance...
1618 while (!isspace(*lineptr
& 255) && *lineptr
)
1627 DEBUG_printf(("9cups_get_dests: name=\"%s\", instance=\"%s\"", name
,
1631 * See if the primary instance of the destination exists; if not,
1632 * ignore this entry and move on...
1637 if (strcasecmp(name
, match_name
) ||
1638 (!instance
&& match_inst
) ||
1639 (instance
&& !match_inst
) ||
1640 (instance
&& strcasecmp(instance
, match_inst
)))
1645 else if (cupsGetDest(name
, NULL
, num_dests
, *dests
) == NULL
)
1647 DEBUG_puts("9cups_get_dests: Not found!");
1653 * Add the destination...
1656 num_dests
= cupsAddDest(name
, instance
, num_dests
, dests
);
1658 if ((dest
= cupsGetDest(name
, instance
, num_dests
, *dests
)) == NULL
)
1664 DEBUG_puts("9cups_get_dests: Out of memory!");
1670 * Add options until we hit the end of the line...
1673 dest
->num_options
= cupsParseOptions(lineptr
, dest
->num_options
,
1677 * If we found what we were looking for, stop now...
1684 * Set this as default if needed...
1687 if (!user_default_set
&& !strcasecmp(line
, "default"))
1689 DEBUG_puts("9cups_get_dests: Setting as default...");
1691 for (i
= 0; i
< num_dests
; i
++)
1692 (*dests
)[i
].is_default
= 0;
1694 dest
->is_default
= 1;
1699 * Close the file and return...
1709 * 'cups_get_sdests()' - Get destinations from a server.
1712 static int /* O - Number of destinations */
1713 cups_get_sdests(http_t
*http
, /* I - Connection to server or CUPS_HTTP_DEFAULT */
1714 ipp_op_t op
, /* I - IPP operation */
1715 const char *name
, /* I - Name of destination */
1716 int num_dests
, /* I - Number of destinations */
1717 cups_dest_t
**dests
) /* IO - Destinations */
1719 cups_dest_t
*dest
; /* Current destination */
1720 ipp_t
*request
, /* IPP Request */
1721 *response
; /* IPP Response */
1722 ipp_attribute_t
*attr
; /* Current attribute */
1723 const char *printer_name
; /* printer-name attribute */
1724 char uri
[1024]; /* printer-uri value */
1725 int num_options
; /* Number of options */
1726 cups_option_t
*options
; /* Options */
1728 char media_default
[41]; /* Default paper size */
1729 #endif /* __APPLE__ */
1730 char optname
[1024], /* Option name */
1731 value
[2048], /* Option value */
1732 *ptr
; /* Pointer into name/value */
1733 static const char * const pattrs
[] = /* Attributes we're interested in */
1735 "auth-info-required",
1737 "job-sheets-default",
1738 "marker-change-time",
1740 "marker-high-levels",
1742 "marker-low-levels",
1748 #endif /* __APPLE__ */
1752 "printer-is-accepting-jobs",
1753 "printer-is-shared",
1755 "printer-make-and-model",
1758 "printer-state-change-time",
1759 "printer-state-reasons",
1761 "printer-uri-supported"
1767 * Get the default paper size...
1770 appleGetPaperSize(media_default
, sizeof(media_default
));
1771 #endif /* __APPLE__ */
1774 * Build a CUPS_GET_PRINTERS or IPP_GET_PRINTER_ATTRIBUTES request, which
1775 * require the following attributes:
1777 * attributes-charset
1778 * attributes-natural-language
1779 * requesting-user-name
1780 * printer-uri [for IPP_GET_PRINTER_ATTRIBUTES]
1783 request
= ippNewRequest(op
);
1785 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1786 "requested-attributes", sizeof(pattrs
) / sizeof(pattrs
[0]),
1789 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
1790 "requesting-user-name", NULL
, cupsUser());
1792 if (name
&& op
!= CUPS_GET_DEFAULT
)
1794 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
1795 "localhost", ippPort(), "/printers/%s", name
);
1796 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
,
1801 * Do the request and get back a response...
1804 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
1806 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
1809 * Skip leading attributes until we hit a printer...
1812 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
1819 * Pull the needed attributes from this printer...
1822 printer_name
= NULL
;
1826 for (; attr
&& attr
->group_tag
== IPP_TAG_PRINTER
; attr
= attr
->next
)
1828 if (attr
->value_tag
!= IPP_TAG_INTEGER
&&
1829 attr
->value_tag
!= IPP_TAG_ENUM
&&
1830 attr
->value_tag
!= IPP_TAG_BOOLEAN
&&
1831 attr
->value_tag
!= IPP_TAG_TEXT
&&
1832 attr
->value_tag
!= IPP_TAG_TEXTLANG
&&
1833 attr
->value_tag
!= IPP_TAG_NAME
&&
1834 attr
->value_tag
!= IPP_TAG_NAMELANG
&&
1835 attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1836 attr
->value_tag
!= IPP_TAG_RANGE
&&
1837 attr
->value_tag
!= IPP_TAG_URI
)
1840 if (!strcmp(attr
->name
, "auth-info-required") ||
1841 !strcmp(attr
->name
, "device-uri") ||
1842 !strcmp(attr
->name
, "marker-change-time") ||
1843 !strcmp(attr
->name
, "marker-colors") ||
1844 !strcmp(attr
->name
, "marker-high-levels") ||
1845 !strcmp(attr
->name
, "marker-levels") ||
1846 !strcmp(attr
->name
, "marker-low-levels") ||
1847 !strcmp(attr
->name
, "marker-message") ||
1848 !strcmp(attr
->name
, "marker-names") ||
1849 !strcmp(attr
->name
, "marker-types") ||
1850 !strcmp(attr
->name
, "printer-commands") ||
1851 !strcmp(attr
->name
, "printer-info") ||
1852 !strcmp(attr
->name
, "printer-is-shared") ||
1853 !strcmp(attr
->name
, "printer-make-and-model") ||
1854 !strcmp(attr
->name
, "printer-state") ||
1855 !strcmp(attr
->name
, "printer-state-change-time") ||
1856 !strcmp(attr
->name
, "printer-type") ||
1857 !strcmp(attr
->name
, "printer-is-accepting-jobs") ||
1858 !strcmp(attr
->name
, "printer-location") ||
1859 !strcmp(attr
->name
, "printer-state-reasons") ||
1860 !strcmp(attr
->name
, "printer-uri-supported"))
1863 * Add a printer description attribute...
1866 num_options
= cupsAddOption(attr
->name
,
1867 cups_make_string(attr
, value
,
1869 num_options
, &options
);
1872 else if (!strcmp(attr
->name
, "media-supported"))
1875 * See if we can set a default media size...
1878 int i
; /* Looping var */
1880 for (i
= 0; i
< attr
->num_values
; i
++)
1881 if (!strcasecmp(media_default
, attr
->values
[i
].string
.text
))
1883 num_options
= cupsAddOption("media", media_default
, num_options
,
1888 #endif /* __APPLE__ */
1889 else if (!strcmp(attr
->name
, "printer-name") &&
1890 attr
->value_tag
== IPP_TAG_NAME
)
1891 printer_name
= attr
->values
[0].string
.text
;
1892 else if (strncmp(attr
->name
, "notify-", 7) &&
1893 (attr
->value_tag
== IPP_TAG_BOOLEAN
||
1894 attr
->value_tag
== IPP_TAG_ENUM
||
1895 attr
->value_tag
== IPP_TAG_INTEGER
||
1896 attr
->value_tag
== IPP_TAG_KEYWORD
||
1897 attr
->value_tag
== IPP_TAG_NAME
||
1898 attr
->value_tag
== IPP_TAG_RANGE
) &&
1899 (ptr
= strstr(attr
->name
, "-default")) != NULL
)
1902 * Add a default option...
1905 strlcpy(optname
, attr
->name
, sizeof(optname
));
1906 optname
[ptr
- attr
->name
] = '\0';
1908 if (strcasecmp(optname
, "media") ||
1909 !cupsGetOption("media", num_options
, options
))
1910 num_options
= cupsAddOption(optname
,
1911 cups_make_string(attr
, value
,
1913 num_options
, &options
);
1918 * See if we have everything needed...
1923 cupsFreeOptions(num_options
, options
);
1931 if ((dest
= cups_add_dest(printer_name
, NULL
, &num_dests
, dests
)) != NULL
)
1933 dest
->num_options
= num_options
;
1934 dest
->options
= options
;
1937 cupsFreeOptions(num_options
, options
);
1943 ippDelete(response
);
1947 * Return the count...
1955 * 'cups_make_string()' - Make a comma-separated string of values from an IPP
1959 static char * /* O - New string */
1961 ipp_attribute_t
*attr
, /* I - Attribute to convert */
1962 char *buffer
, /* I - Buffer */
1963 size_t bufsize
) /* I - Size of buffer */
1965 int i
; /* Looping var */
1966 char *ptr
, /* Pointer into buffer */
1967 *end
, /* Pointer to end of buffer */
1968 *valptr
; /* Pointer into string attribute */
1972 * Return quickly if we have a single string value...
1975 if (attr
->num_values
== 1 &&
1976 attr
->value_tag
!= IPP_TAG_INTEGER
&&
1977 attr
->value_tag
!= IPP_TAG_ENUM
&&
1978 attr
->value_tag
!= IPP_TAG_BOOLEAN
&&
1979 attr
->value_tag
!= IPP_TAG_RANGE
)
1980 return (attr
->values
[0].string
.text
);
1983 * Copy the values to the string, separating with commas and escaping strings
1987 end
= buffer
+ bufsize
- 1;
1989 for (i
= 0, ptr
= buffer
; i
< attr
->num_values
&& ptr
< end
; i
++)
1994 switch (attr
->value_tag
)
1996 case IPP_TAG_INTEGER
:
1998 snprintf(ptr
, end
- ptr
+ 1, "%d", attr
->values
[i
].integer
);
2001 case IPP_TAG_BOOLEAN
:
2002 if (attr
->values
[i
].boolean
)
2003 strlcpy(ptr
, "true", end
- ptr
+ 1);
2005 strlcpy(ptr
, "false", end
- ptr
+ 1);
2008 case IPP_TAG_RANGE
:
2009 if (attr
->values
[i
].range
.lower
== attr
->values
[i
].range
.upper
)
2010 snprintf(ptr
, end
- ptr
+ 1, "%d", attr
->values
[i
].range
.lower
);
2012 snprintf(ptr
, end
- ptr
+ 1, "%d-%d", attr
->values
[i
].range
.lower
,
2013 attr
->values
[i
].range
.upper
);
2017 for (valptr
= attr
->values
[i
].string
.text
;
2018 *valptr
&& ptr
< end
;)
2020 if (strchr(" \t\n\\\'\"", *valptr
))
2022 if (ptr
>= (end
- 1))
2045 * End of "$Id: dest.c 7946 2008-09-16 23:27:54Z mike $".