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-2008 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 * appleGetDefault() - Get the default printer for this location.
37 * appleGetPaperSize() - Get the default paper size.
38 * appleGetPrinter() - Get a printer from the history array.
39 * appleSetDefault() - Set the default printer for this location.
40 * appleUseLastPrinter() - Get the default printer preference value.
41 * cups_add_dest() - Add a destination to the array.
42 * cups_compare_dests() - Compare two destinations.
43 * cups_find_dest() - Find a destination using a binary search.
44 * cups_get_default() - Get the default destination from an lpoptions file.
45 * cups_get_dests() - Get destinations from a file.
46 * cups_get_sdests() - Get destinations from a server.
47 * cups_make_string() - Make a comma-separated string of values from an IPP
52 * Include necessary headers...
64 #endif /* HAVE_NOTIFY_H */
67 # include <sys/cdefs.h>
68 # include <CoreFoundation/CoreFoundation.h>
69 # include <SystemConfiguration/SystemConfiguration.h>
70 # define kDefaultPaperIDKey CFSTR("DefaultPaperID")
71 # define kLocationHistoryArrayKey CFSTR("kLocationHistoryArrayKeyTMP")
72 # define kLocationNetworkKey CFSTR("kLocationNetworkKey")
73 # define kLocationPrinterIDKey CFSTR("kLocationPrinterIDKey")
74 # define kPMPrintingPreferences CFSTR("com.apple.print.PrintingPrefs")
75 # define kUseLastPrinterAsCurrentPrinterKey CFSTR("UseLastPrinterAsCurrentPrinter")
76 #endif /* __APPLE__ */
84 static CFArrayRef
appleCopyLocations(void);
85 static CFStringRef
appleCopyNetwork(void);
86 static char *appleGetDefault(char *name
, int namesize
);
87 static char *appleGetPaperSize(char *name
, int namesize
);
88 static CFStringRef
appleGetPrinter(CFArrayRef locations
, CFStringRef network
,
90 static void appleSetDefault(const char *name
);
91 static int appleUseLastPrinter(void);
92 #endif /* __APPLE__ */
93 static cups_dest_t
*cups_add_dest(const char *name
, const char *instance
,
94 int *num_dests
, cups_dest_t
**dests
);
95 static int cups_compare_dests(cups_dest_t
*a
, cups_dest_t
*b
);
96 static int cups_find_dest(const char *name
, const char *instance
,
97 int num_dests
, cups_dest_t
*dests
, int prev
,
99 static char *cups_get_default(const char *filename
, char *namebuf
,
100 size_t namesize
, const char **instance
);
101 static int cups_get_dests(const char *filename
, const char *match_name
,
102 const char *match_inst
, int num_dests
,
103 cups_dest_t
**dests
);
104 static int cups_get_sdests(http_t
*http
, ipp_op_t op
, const char *name
,
105 int num_dests
, cups_dest_t
**dests
);
106 static char *cups_make_string(ipp_attribute_t
*attr
, char *buffer
,
111 * 'cupsAddDest()' - Add a destination to the list of destinations.
113 * This function cannot be used to add a new class or printer queue,
114 * it only adds a new container of saved options for the named
115 * destination or instance.
117 * If the named destination already exists, the destination list is
118 * returned unchanged. Adding a new instance of a destination creates
119 * a copy of that destination's options.
121 * Use the @link cupsSaveDests@ function to save the updated list of
122 * destinations to the user's lpoptions file.
125 int /* O - New number of destinations */
126 cupsAddDest(const char *name
, /* I - Destination name */
127 const char *instance
, /* I - Instance name or @code NULL@ for none/primary */
128 int num_dests
, /* I - Number of destinations */
129 cups_dest_t
**dests
) /* IO - Destinations */
131 int i
; /* Looping var */
132 cups_dest_t
*dest
; /* Destination pointer */
133 cups_dest_t
*parent
; /* Parent destination */
134 cups_option_t
*doption
, /* Current destination option */
135 *poption
; /* Current parent option */
141 if (!cupsGetDest(name
, instance
, num_dests
, *dests
))
144 (parent
= cupsGetDest(name
, NULL
, num_dests
, *dests
)) == NULL
)
147 dest
= cups_add_dest(name
, instance
, &num_dests
, dests
);
149 if (instance
&& parent
&& parent
->num_options
> 0)
152 * Copy options from parent...
155 dest
->options
= calloc(sizeof(cups_option_t
), parent
->num_options
);
159 dest
->num_options
= parent
->num_options
;
161 for (i
= dest
->num_options
, doption
= dest
->options
,
162 poption
= parent
->options
;
164 i
--, doption
++, poption
++)
166 doption
->name
= _cupsStrRetain(poption
->name
);
167 doption
->value
= _cupsStrRetain(poption
->value
);
178 * 'cupsFreeDests()' - Free the memory used by the list of destinations.
182 cupsFreeDests(int num_dests
, /* I - Number of destinations */
183 cups_dest_t
*dests
) /* I - Destinations */
185 int i
; /* Looping var */
186 cups_dest_t
*dest
; /* Current destination */
189 if (num_dests
== 0 || dests
== NULL
)
192 for (i
= num_dests
, dest
= dests
; i
> 0; i
--, dest
++)
194 _cupsStrFree(dest
->name
);
195 _cupsStrFree(dest
->instance
);
197 cupsFreeOptions(dest
->num_options
, dest
->options
);
205 * 'cupsGetDest()' - Get the named destination from the list.
207 * Use the @link cupsGetDests@ or @link cupsGetDests2@ functions to get a
208 * list of supported destinations for the current user.
211 cups_dest_t
* /* O - Destination pointer or @code NULL@ */
212 cupsGetDest(const char *name
, /* I - Destination name or @code NULL@ for the default destination */
213 const char *instance
, /* I - Instance name or @code NULL@ */
214 int num_dests
, /* I - Number of destinations */
215 cups_dest_t
*dests
) /* I - Destinations */
217 int diff
, /* Result of comparison */
218 match
; /* Matching index */
221 if (num_dests
<= 0 || !dests
)
227 * NULL name for default printer.
230 while (num_dests
> 0)
232 if (dests
->is_default
)
242 * Lookup name and optionally the instance...
245 match
= cups_find_dest(name
, instance
, num_dests
, dests
, -1, &diff
);
248 return (dests
+ match
);
256 * 'cupsGetDests()' - Get the list of destinations from the default server.
258 * Starting with CUPS 1.2, the returned list of destinations include the
259 * printer-info, printer-is-accepting-jobs, printer-is-shared,
260 * printer-make-and-model, printer-state, printer-state-change-time,
261 * printer-state-reasons, and printer-type attributes as options. CUPS 1.4
262 * adds the marker-change-time, marker-colors, marker-high-levels,
263 * marker-levels, marker-low-levels, marker-message, marker-names,
264 * marker-types, and printer-commands attributes as well.
266 * Use the @link cupsFreeDests@ function to free the destination list and
267 * the @link cupsGetDest@ function to find a particular destination.
270 int /* O - Number of destinations */
271 cupsGetDests(cups_dest_t
**dests
) /* O - Destinations */
273 return (cupsGetDests2(CUPS_HTTP_DEFAULT
, dests
));
278 * 'cupsGetDests2()' - Get the list of destinations from the specified server.
280 * Starting with CUPS 1.2, the returned list of destinations include the
281 * printer-info, printer-is-accepting-jobs, printer-is-shared,
282 * printer-make-and-model, printer-state, printer-state-change-time,
283 * printer-state-reasons, and printer-type attributes as options. CUPS 1.4
284 * adds the marker-change-time, marker-colors, marker-high-levels,
285 * marker-levels, marker-low-levels, marker-message, marker-names,
286 * marker-types, and printer-commands attributes as well.
288 * Use the @link cupsFreeDests@ function to free the destination list and
289 * the @link cupsGetDest@ function to find a particular destination.
291 * @since CUPS 1.1.21/Mac OS X 10.4@
294 int /* O - Number of destinations */
295 cupsGetDests2(http_t
*http
, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
296 cups_dest_t
**dests
) /* O - Destinations */
298 int i
; /* Looping var */
299 int num_dests
; /* Number of destinations */
300 cups_dest_t
*dest
; /* Destination pointer */
301 const char *home
; /* HOME environment variable */
302 char filename
[1024]; /* Local ~/.cups/lpoptions file */
303 const char *defprinter
; /* Default printer */
304 char name
[1024], /* Copy of printer name */
305 *instance
; /* Pointer to instance name */
306 int num_reals
; /* Number of real queues */
307 cups_dest_t
*reals
; /* Real queues */
308 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
312 * Range check the input...
317 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad NULL dests pointer"), 1);
322 * Initialize destination array...
326 *dests
= (cups_dest_t
*)0;
329 * Grab the printers and classes...
332 num_dests
= cups_get_sdests(http
, CUPS_GET_PRINTERS
, NULL
, num_dests
, dests
);
334 if (cupsLastError() >= IPP_REDIRECTION_OTHER_SITE
)
336 cupsFreeDests(num_dests
, *dests
);
337 *dests
= (cups_dest_t
*)0;
342 * Make a copy of the "real" queues for a later sanity check...
347 num_reals
= num_dests
;
348 reals
= calloc(num_reals
, sizeof(cups_dest_t
));
351 memcpy(reals
, *dests
, num_reals
* sizeof(cups_dest_t
));
362 * Grab the default destination...
366 if ((defprinter
= appleGetDefault(name
, sizeof(name
))) == NULL
)
367 #endif /* __APPLE__ */
368 defprinter
= cupsGetDefault2(http
);
373 * Grab printer and instance name...
377 if (name
!= defprinter
)
378 #endif /* __APPLE__ */
379 strlcpy(name
, defprinter
, sizeof(name
));
381 if ((instance
= strchr(name
, '/')) != NULL
)
385 * Lookup the printer and instance and make it the default...
388 if ((dest
= cupsGetDest(name
, instance
, num_dests
, *dests
)) != NULL
)
389 dest
->is_default
= 1;
394 * This initialization of "instance" is unnecessary, but avoids a
395 * compiler warning...
402 * Load the /etc/cups/lpoptions and ~/.cups/lpoptions files...
405 snprintf(filename
, sizeof(filename
), "%s/lpoptions", cg
->cups_serverroot
);
406 num_dests
= cups_get_dests(filename
, NULL
, NULL
, num_dests
, dests
);
408 if ((home
= getenv("HOME")) != NULL
)
410 snprintf(filename
, sizeof(filename
), "%s/.cups/lpoptions", home
);
411 if (access(filename
, 0))
412 snprintf(filename
, sizeof(filename
), "%s/.lpoptions", home
);
414 num_dests
= cups_get_dests(filename
, NULL
, NULL
, num_dests
, dests
);
418 * Validate the current default destination - this prevents old
419 * Default lines in /etc/cups/lpoptions and ~/.cups/lpoptions from
420 * pointing to a non-existent printer or class...
426 * See if we have a default printer...
429 if ((dest
= cupsGetDest(NULL
, NULL
, num_dests
, *dests
)) != NULL
)
432 * Have a default; see if it is real...
435 dest
= cupsGetDest(dest
->name
, NULL
, num_reals
, reals
);
439 * If dest is NULL, then no default (that exists) is set, so we
440 * need to set a default if one exists...
443 if (dest
== NULL
&& defprinter
!= NULL
)
445 for (i
= 0; i
< num_dests
; i
++)
446 (*dests
)[i
].is_default
= 0;
448 if ((dest
= cupsGetDest(name
, instance
, num_dests
, *dests
)) != NULL
)
449 dest
->is_default
= 1;
460 * Return the number of destinations...
464 _cupsSetError(IPP_OK
, NULL
, 0);
471 * 'cupsGetNamedDest()' - Get options for the named destination.
473 * This function is optimized for retrieving a single destination and should
474 * be used instead of @link cupsGetDests@ and @link cupsGetDest@ when you either
475 * know the name of the destination or want to print to the default destination.
476 * If @code NULL@ is returned, the destination does not exist or there is no
477 * default destination.
479 * If "http" is @code CUPS_HTTP_DEFAULT@, the connection to the default print
480 * server will be used.
482 * If "name" is @code NULL@, the default printer for the current user will be
485 * The returned destination must be freed using @link cupsFreeDests@ with a
486 * "num_dests" value of 1.
491 cups_dest_t
* /* O - Destination or @code NULL@ */
492 cupsGetNamedDest(http_t
*http
, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
493 const char *name
, /* I - Destination name or @code NULL@ for the default destination */
494 const char *instance
) /* I - Instance name or @code NULL@ */
496 cups_dest_t
*dest
; /* Destination */
497 char filename
[1024], /* Path to lpoptions */
498 defname
[256]; /* Default printer name */
499 const char *home
= getenv("HOME"); /* Home directory */
500 ipp_op_t op
= IPP_GET_PRINTER_ATTRIBUTES
;
501 /* IPP operation to get server ops */
502 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
506 * If "name" is NULL, find the default destination...
511 if ((name
= getenv("LPDEST")) == NULL
)
512 if ((name
= getenv("PRINTER")) != NULL
&& !strcmp(name
, "lp"))
518 * No default in the environment, try the user's lpoptions files...
521 snprintf(filename
, sizeof(filename
), "%s/.cups/lpoptions", home
);
523 if ((name
= cups_get_default(filename
, defname
, sizeof(defname
),
526 snprintf(filename
, sizeof(filename
), "%s/.lpoptions", home
);
527 name
= cups_get_default(filename
, defname
, sizeof(defname
),
535 * Still not there? Try the system lpoptions file...
538 snprintf(filename
, sizeof(filename
), "%s/lpoptions",
539 cg
->cups_serverroot
);
540 name
= cups_get_default(filename
, defname
, sizeof(defname
), &instance
);
546 * No locally-set default destination, ask the server...
549 op
= CUPS_GET_DEFAULT
;
554 * Get the printer's attributes...
557 if (!cups_get_sdests(http
, op
, name
, 0, &dest
))
561 dest
->instance
= _cupsStrAlloc(instance
);
564 * Then add local options...
567 snprintf(filename
, sizeof(filename
), "%s/lpoptions", cg
->cups_serverroot
);
568 cups_get_dests(filename
, name
, instance
, 1, &dest
);
572 snprintf(filename
, sizeof(filename
), "%s/.cups/lpoptions", home
);
574 if (access(filename
, 0))
575 snprintf(filename
, sizeof(filename
), "%s/.lpoptions", home
);
577 cups_get_dests(filename
, name
, instance
, 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
, num_temps
, &temps
);
757 * Point to user defaults...
760 if ((home
= getenv("HOME")) != NULL
)
763 * Remove the old ~/.lpoptions file...
766 snprintf(filename
, sizeof(filename
), "%s/.lpoptions", home
);
770 * Create ~/.cups subdirectory...
773 snprintf(filename
, sizeof(filename
), "%s/.cups", home
);
774 if (access(filename
, 0))
775 mkdir(filename
, 0700);
777 snprintf(filename
, sizeof(filename
), "%s/.cups/lpoptions", home
);
783 * Try to open the file...
786 if ((fp
= fopen(filename
, "w")) == NULL
)
788 cupsFreeDests(num_temps
, temps
);
794 * Set the permissions to 0644 when saving to the /etc/cups/lpoptions
799 fchmod(fileno(fp
), 0644);
803 * Write each printer; each line looks like:
805 * Dest name[/instance] options
806 * Default name[/instance] options
809 for (i
= num_dests
, dest
= dests
; i
> 0; i
--, dest
++)
810 if (dest
->instance
!= NULL
|| dest
->num_options
!= 0 || dest
->is_default
)
812 if (dest
->is_default
)
814 fprintf(fp
, "Default %s", dest
->name
);
816 fprintf(fp
, "/%s", dest
->instance
);
823 if ((temp
= cupsGetDest(dest
->name
, dest
->instance
, num_temps
, temps
)) == NULL
)
824 temp
= cupsGetDest(dest
->name
, NULL
, num_temps
, temps
);
826 for (j
= dest
->num_options
, option
= dest
->options
; j
> 0; j
--, option
++)
829 * See if this option is a printer attribute; if so, skip it...
832 if ((match
= _ippFindOption(option
->name
)) != NULL
&&
833 match
->group_tag
== IPP_TAG_PRINTER
)
837 * See if the server/global options match these; if so, don't
842 (val
= cupsGetOption(option
->name
, temp
->num_options
,
843 temp
->options
)) != NULL
&&
844 !strcasecmp(val
, option
->value
))
848 * Options don't match, write to the file...
853 fprintf(fp
, "Dest %s", dest
->name
);
855 fprintf(fp
, "/%s", dest
->instance
);
859 if (option
->value
[0])
861 if (strchr(option
->value
, ' ') ||
862 strchr(option
->value
, '\\') ||
863 strchr(option
->value
, '\"') ||
864 strchr(option
->value
, '\''))
870 fprintf(fp
, " %s=\"", option
->name
);
872 for (val
= option
->value
; *val
; val
++)
874 if (strchr("\"\'\\", *val
))
885 * Store the literal value...
888 fprintf(fp
, " %s=%s", option
->name
, option
->value
);
892 fprintf(fp
, " %s", option
->name
);
900 * Free the temporary destinations and close the file...
903 cupsFreeDests(num_temps
, temps
);
909 * Set the default printer for this location - this allows command-line
910 * and GUI applications to share the same default destination...
913 if ((dest
= cupsGetDest(NULL
, NULL
, num_dests
, dests
)) != NULL
)
914 appleSetDefault(dest
->name
);
915 #endif /* __APPLE__ */
917 #ifdef HAVE_NOTIFY_POST
919 * Send a notification so that MacOS X applications can know about the
923 notify_post("com.apple.printerListChange");
924 #endif /* HAVE_NOTIFY_POST */
932 * 'appleCopyLocations()' - Copy the location history array.
935 static CFArrayRef
/* O - Location array or NULL */
936 appleCopyLocations(void)
938 CFArrayRef locations
; /* Location array */
942 * Look up the location array in the preferences...
945 if ((locations
= CFPreferencesCopyAppValue(kLocationHistoryArrayKey
,
946 kPMPrintingPreferences
)) == NULL
)
949 if (CFGetTypeID(locations
) != CFArrayGetTypeID())
951 CFRelease(locations
);
960 * 'appleCopyNetwork()' - Get the network ID for the current location.
963 static CFStringRef
/* O - Network ID */
964 appleCopyNetwork(void)
966 SCDynamicStoreRef dynamicStore
; /* System configuration data */
967 CFStringRef key
; /* Current network configuration key */
968 CFDictionaryRef ip_dict
; /* Network configuration data */
969 CFStringRef network
= NULL
; /* Current network ID */
972 if ((dynamicStore
= SCDynamicStoreCreate(NULL
, CFSTR("Printing"), NULL
,
975 if ((key
= SCDynamicStoreKeyCreateNetworkGlobalEntity(
976 NULL
, kSCDynamicStoreDomainState
, kSCEntNetIPv4
)) != NULL
)
978 if ((ip_dict
= SCDynamicStoreCopyValue(dynamicStore
, key
)) != NULL
)
980 if ((network
= CFDictionaryGetValue(ip_dict
,
981 kSCPropNetIPv4Router
)) != NULL
)
990 CFRelease(dynamicStore
);
998 * 'appleGetDefault()' - Get the default printer for this location.
1001 static char * /* O - Name or NULL if no default */
1002 appleGetDefault(char *name
, /* I - Name buffer */
1003 int namesize
) /* I - Size of name buffer */
1005 CFStringRef network
; /* Network location */
1006 CFArrayRef locations
; /* Location array */
1007 CFStringRef locprinter
; /* Current printer */
1011 * Use location-based defaults if "use last printer" is selected in the
1012 * system preferences...
1015 if (!appleUseLastPrinter())
1017 DEBUG_puts("appleGetDefault: Not using last printer as default...");
1022 * Get the current location...
1025 if ((network
= appleCopyNetwork()) == NULL
)
1027 DEBUG_puts("appleGetDefault: Unable to get current network...");
1032 CFStringGetCString(network
, name
, namesize
, kCFStringEncodingUTF8
);
1033 DEBUG_printf(("appleGetDefault: network=\"%s\"\n", name
));
1037 * Lookup the network in the preferences...
1040 if ((locations
= appleCopyLocations()) == NULL
)
1043 * Missing or bad location array, so no location-based default...
1046 DEBUG_puts("appleGetDefault: Missing or bad location history array...");
1053 DEBUG_printf(("appleGetDefault: Got location, %d entries...\n",
1054 (int)CFArrayGetCount(locations
)));
1056 if ((locprinter
= appleGetPrinter(locations
, network
, NULL
)) != NULL
)
1057 CFStringGetCString(locprinter
, name
, namesize
, kCFStringEncodingUTF8
);
1062 CFRelease(locations
);
1064 DEBUG_printf(("appleGetDefault: Returning \"%s\"...\n", name
));
1066 return (*name
? name
: NULL
);
1071 * 'appleGetPaperSize()' - Get the default paper size.
1074 static char * /* O - Default paper size */
1075 appleGetPaperSize(char *name
, /* I - Paper size name buffer */
1076 int namesize
) /* I - Size of buffer */
1078 CFStringRef defaultPaperID
; /* Default paper ID */
1079 _cups_pwg_media_t
*pwgmedia
; /* PWG media size */
1082 defaultPaperID
= CFPreferencesCopyAppValue(kDefaultPaperIDKey
,
1083 kPMPrintingPreferences
);
1084 if (!defaultPaperID
||
1085 CFGetTypeID(defaultPaperID
) != CFStringGetTypeID() ||
1086 !CFStringGetCString(defaultPaperID
, name
, namesize
,
1087 kCFStringEncodingUTF8
))
1089 else if ((pwgmedia
= _cupsPWGMediaByLegacy(name
)) != NULL
)
1090 strlcpy(name
, pwgmedia
->pwg
, namesize
);
1093 CFRelease(defaultPaperID
);
1100 * 'appleGetPrinter()' - Get a printer from the history array.
1103 static CFStringRef
/* O - Printer name or NULL */
1104 appleGetPrinter(CFArrayRef locations
, /* I - Location array */
1105 CFStringRef network
, /* I - Network name */
1106 CFIndex
*locindex
) /* O - Index in array */
1108 CFIndex i
, /* Looping var */
1109 count
; /* Number of locations */
1110 CFDictionaryRef location
; /* Current location */
1111 CFStringRef locnetwork
, /* Current network */
1112 locprinter
; /* Current printer */
1115 for (i
= 0, count
= CFArrayGetCount(locations
); i
< count
; i
++)
1116 if ((location
= CFArrayGetValueAtIndex(locations
, i
)) != NULL
&&
1117 CFGetTypeID(location
) == CFDictionaryGetTypeID())
1119 if ((locnetwork
= CFDictionaryGetValue(location
,
1120 kLocationNetworkKey
)) != NULL
&&
1121 CFGetTypeID(locnetwork
) == CFStringGetTypeID() &&
1122 CFStringCompare(network
, locnetwork
, 0) == kCFCompareEqualTo
&&
1123 (locprinter
= CFDictionaryGetValue(location
,
1124 kLocationPrinterIDKey
)) != NULL
&&
1125 CFGetTypeID(locprinter
) == CFStringGetTypeID())
1130 return (locprinter
);
1139 * 'appleSetDefault()' - Set the default printer for this location.
1143 appleSetDefault(const char *name
) /* I - Default printer/class name */
1145 CFStringRef network
; /* Current network */
1146 CFArrayRef locations
; /* Old locations array */
1147 CFIndex locindex
; /* Index in locations array */
1148 CFStringRef locprinter
; /* Current printer */
1149 CFMutableArrayRef newlocations
; /* New locations array */
1150 CFMutableDictionaryRef newlocation
; /* New location */
1151 CFStringRef newprinter
; /* New printer */
1155 * Get the current location...
1158 if ((network
= appleCopyNetwork()) == NULL
)
1160 DEBUG_puts("appleSetDefault: Unable to get current network...");
1164 if ((newprinter
= CFStringCreateWithCString(kCFAllocatorDefault
, name
,
1165 kCFStringEncodingUTF8
)) == NULL
)
1172 * Lookup the network in the preferences...
1175 if ((locations
= appleCopyLocations()) != NULL
)
1176 locprinter
= appleGetPrinter(locations
, network
, &locindex
);
1184 CFStringCompare(locprinter
, newprinter
, 0) != kCFCompareEqualTo
)
1187 * Need to change the locations array...
1192 newlocations
= CFArrayCreateMutableCopy(kCFAllocatorDefault
, 0,
1196 CFArrayRemoveValueAtIndex(newlocations
, locindex
);
1199 newlocations
= CFArrayCreateMutable(kCFAllocatorDefault
, 0, NULL
);
1201 newlocation
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
1202 &kCFTypeDictionaryKeyCallBacks
,
1203 &kCFTypeDictionaryValueCallBacks
);
1205 if (newlocation
&& newlocations
)
1208 * Put the new location at the front of the array...
1211 CFDictionaryAddValue(newlocation
, kLocationNetworkKey
, network
);
1212 CFDictionaryAddValue(newlocation
, kLocationPrinterIDKey
, newprinter
);
1213 CFArrayInsertValueAtIndex(newlocations
, 0, newlocation
);
1216 * Limit the number of locations to 10...
1219 while (CFArrayGetCount(newlocations
) > 10)
1220 CFArrayRemoveValueAtIndex(newlocations
, 10);
1223 * Push the changes out...
1226 CFPreferencesSetAppValue(kLocationHistoryArrayKey
, newlocations
,
1227 kPMPrintingPreferences
);
1228 CFPreferencesAppSynchronize(kPMPrintingPreferences
);
1232 CFRelease(newlocations
);
1235 CFRelease(newlocation
);
1239 CFRelease(locations
);
1242 CFRelease(newprinter
);
1247 * 'appleUseLastPrinter()' - Get the default printer preference value.
1250 static int /* O - 1 to use last printer, 0 otherwise */
1251 appleUseLastPrinter(void)
1253 CFPropertyListRef uselast
; /* Use last printer preference value */
1256 if ((uselast
= CFPreferencesCopyAppValue(kUseLastPrinterAsCurrentPrinterKey
,
1257 kPMPrintingPreferences
)) != NULL
)
1261 if (uselast
== kCFBooleanFalse
)
1267 #endif /* __APPLE__ */
1271 * 'cups_add_dest()' - Add a destination to the array.
1273 * Unlike cupsAddDest(), this function does not check for duplicates.
1276 static cups_dest_t
* /* O - New destination */
1277 cups_add_dest(const char *name
, /* I - Name of destination */
1278 const char *instance
, /* I - Instance or NULL */
1279 int *num_dests
, /* IO - Number of destinations */
1280 cups_dest_t
**dests
) /* IO - Destinations */
1282 int insert
, /* Insertion point */
1283 diff
; /* Result of comparison */
1284 cups_dest_t
*dest
; /* Destination pointer */
1288 * Add new destination...
1291 if (*num_dests
== 0)
1292 dest
= malloc(sizeof(cups_dest_t
));
1294 dest
= realloc(*dests
, sizeof(cups_dest_t
) * (*num_dests
+ 1));
1302 * Find where to insert the destination...
1305 if (*num_dests
== 0)
1309 insert
= cups_find_dest(name
, instance
, *num_dests
, *dests
, *num_dests
- 1,
1317 * Move the array elements as needed...
1320 if (insert
< *num_dests
)
1321 memmove(*dests
+ insert
+ 1, *dests
+ insert
,
1322 (*num_dests
- insert
) * sizeof(cups_dest_t
));
1327 * Initialize the destination...
1330 dest
= *dests
+ insert
;
1331 dest
->name
= _cupsStrAlloc(name
);
1332 dest
->instance
= _cupsStrAlloc(instance
);
1333 dest
->is_default
= 0;
1334 dest
->num_options
= 0;
1335 dest
->options
= (cups_option_t
*)0;
1342 * 'cups_compare_dests()' - Compare two destinations.
1345 static int /* O - Result of comparison */
1346 cups_compare_dests(cups_dest_t
*a
, /* I - First destination */
1347 cups_dest_t
*b
) /* I - Second destination */
1349 int diff
; /* Difference */
1352 if ((diff
= strcasecmp(a
->name
, b
->name
)) != 0)
1354 else if (a
->instance
&& b
->instance
)
1355 return (strcasecmp(a
->instance
, b
->instance
));
1357 return ((a
->instance
&& !b
->instance
) - (!a
->instance
&& b
->instance
));
1362 * 'cups_find_dest()' - Find a destination using a binary search.
1365 static int /* O - Index of match */
1366 cups_find_dest(const char *name
, /* I - Destination name */
1367 const char *instance
, /* I - Instance or NULL */
1368 int num_dests
, /* I - Number of destinations */
1369 cups_dest_t
*dests
, /* I - Destinations */
1370 int prev
, /* I - Previous index */
1371 int *rdiff
) /* O - Difference of match */
1373 int left
, /* Low mark for binary search */
1374 right
, /* High mark for binary search */
1375 current
, /* Current index */
1376 diff
; /* Result of comparison */
1377 cups_dest_t key
; /* Search key */
1380 key
.name
= (char *)name
;
1381 key
.instance
= (char *)instance
;
1386 * Start search on either side of previous...
1389 if ((diff
= cups_compare_dests(&key
, dests
+ prev
)) == 0 ||
1390 (diff
< 0 && prev
== 0) ||
1391 (diff
> 0 && prev
== (num_dests
- 1)))
1399 * Start with previous on right side...
1408 * Start wih previous on left side...
1412 right
= num_dests
- 1;
1418 * Start search in the middle...
1422 right
= num_dests
- 1;
1427 current
= (left
+ right
) / 2;
1428 diff
= cups_compare_dests(&key
, dests
+ current
);
1437 while ((right
- left
) > 1);
1442 * Check the last 1 or 2 elements...
1445 if ((diff
= cups_compare_dests(&key
, dests
+ left
)) <= 0)
1449 diff
= cups_compare_dests(&key
, dests
+ right
);
1455 * Return the closest destination and the difference...
1465 * 'cups_get_default()' - Get the default destination from an lpoptions file.
1468 static char * /* O - Default destination or NULL */
1469 cups_get_default(const char *filename
, /* I - File to read */
1470 char *namebuf
, /* I - Name buffer */
1471 size_t namesize
, /* I - Size of name buffer */
1472 const char **instance
) /* I - Instance */
1474 cups_file_t
*fp
; /* lpoptions file */
1475 char line
[8192], /* Line from file */
1476 *value
, /* Value for line */
1477 *nameptr
; /* Pointer into name */
1478 int linenum
; /* Current line */
1483 if ((fp
= cupsFileOpen(filename
, "r")) != NULL
)
1487 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
1489 if (!strcasecmp(line
, "default") && value
)
1491 strlcpy(namebuf
, value
, namesize
);
1493 if ((nameptr
= strchr(namebuf
, ' ')) != NULL
)
1495 if ((nameptr
= strchr(namebuf
, '\t')) != NULL
)
1498 if ((nameptr
= strchr(namebuf
, '/')) != NULL
)
1501 *instance
= nameptr
;
1509 return (*namebuf
? namebuf
: NULL
);
1514 * 'cups_get_dests()' - Get destinations from a file.
1517 static int /* O - Number of destinations */
1518 cups_get_dests(const char *filename
, /* I - File to read from */
1519 const char *match_name
, /* I - Destination name we want */
1520 const char *match_inst
, /* I - Instance name we want */
1521 int num_dests
, /* I - Number of destinations */
1522 cups_dest_t
**dests
) /* IO - Destinations */
1524 int i
; /* Looping var */
1525 cups_dest_t
*dest
; /* Current destination */
1526 cups_file_t
*fp
; /* File pointer */
1527 char line
[8192], /* Line from file */
1528 *lineptr
, /* Pointer into line */
1529 *name
, /* Name of destination/option */
1530 *instance
; /* Instance of destination */
1531 int linenum
; /* Current line number */
1532 const char *printer
; /* PRINTER or LPDEST */
1535 DEBUG_printf(("cups_get_dests(filename=\"%s\", match_name=\"%s\", "
1536 "match_inst=\"%s\", num_dests=%d, dests=%p)\n", filename
,
1537 match_name
? match_name
: "(null)",
1538 match_inst
? match_inst
: "(null)", num_dests
, dests
));
1541 * Try to open the file...
1544 if ((fp
= cupsFileOpen(filename
, "r")) == NULL
)
1548 * Check environment variables...
1551 if ((printer
= getenv("LPDEST")) == NULL
)
1552 if ((printer
= getenv("PRINTER")) != NULL
)
1553 if (strcmp(printer
, "lp") == 0)
1556 DEBUG_printf(("cups_get_dests: printer=\"%s\"\n",
1557 printer
? printer
: "(null)"));
1560 * Read each printer; each line looks like:
1562 * Dest name[/instance] options
1563 * Default name[/instance] options
1568 while (cupsFileGetConf(fp
, line
, sizeof(line
), &lineptr
, &linenum
))
1571 * See what type of line it is...
1574 DEBUG_printf(("cups_get_dests: linenum=%d line=\"%s\" lineptr=\"%s\"\n",
1575 linenum
, line
, lineptr
? lineptr
: "(null)"));
1577 if ((strcasecmp(line
, "dest") && strcasecmp(line
, "default")) || !lineptr
)
1579 DEBUG_puts("cups_get_dests: Not a dest or default line...");
1586 * Search for an instance...
1589 while (!isspace(*lineptr
& 255) && *lineptr
&& *lineptr
!= '/')
1592 if (*lineptr
== '/')
1595 * Found an instance...
1602 * Search for an instance...
1605 while (!isspace(*lineptr
& 255) && *lineptr
)
1614 DEBUG_printf(("cups_get_dests: name=\"%s\", instance=\"%s\"\n", name
,
1618 * See if the primary instance of the destination exists; if not,
1619 * ignore this entry and move on...
1624 if (strcasecmp(name
, match_name
) ||
1625 (!instance
&& match_inst
) ||
1626 (instance
&& !match_inst
) ||
1627 (instance
&& strcasecmp(instance
, match_inst
)))
1632 else if (cupsGetDest(name
, NULL
, num_dests
, *dests
) == NULL
)
1634 DEBUG_puts("cups_get_dests: Not found!");
1640 * Add the destination...
1643 num_dests
= cupsAddDest(name
, instance
, num_dests
, dests
);
1645 if ((dest
= cupsGetDest(name
, instance
, num_dests
, *dests
)) == NULL
)
1651 DEBUG_puts("cups_get_dests: Out of memory!");
1657 * Add options until we hit the end of the line...
1660 dest
->num_options
= cupsParseOptions(lineptr
, dest
->num_options
,
1664 * If we found what we were looking for, stop now...
1671 * Set this as default if needed...
1674 if (!printer
&& !strcasecmp(line
, "default"))
1676 DEBUG_puts("cups_get_dests: Setting as default...");
1678 for (i
= 0; i
< num_dests
; i
++)
1679 (*dests
)[i
].is_default
= 0;
1681 dest
->is_default
= 1;
1686 * Close the file and return...
1696 * 'cups_get_sdests()' - Get destinations from a server.
1699 static int /* O - Number of destinations */
1700 cups_get_sdests(http_t
*http
, /* I - Connection to server or CUPS_HTTP_DEFAULT */
1701 ipp_op_t op
, /* I - IPP operation */
1702 const char *name
, /* I - Name of destination */
1703 int num_dests
, /* I - Number of destinations */
1704 cups_dest_t
**dests
) /* IO - Destinations */
1706 int i
; /* Looping var */
1707 cups_dest_t
*dest
; /* Current destination */
1708 ipp_t
*request
, /* IPP Request */
1709 *response
; /* IPP Response */
1710 ipp_attribute_t
*attr
; /* Current attribute */
1711 const char *printer_name
; /* printer-name attribute */
1712 char uri
[1024]; /* printer-uri value */
1713 int num_options
; /* Number of options */
1714 cups_option_t
*options
; /* Options */
1716 char media_default
[41]; /* Default paper size */
1717 #endif /* __APPLE__ */
1718 char optname
[1024], /* Option name */
1719 value
[2048], /* Option value */
1720 *ptr
; /* Pointer into name/value */
1721 static const char * const pattrs
[] = /* Attributes we're interested in */
1723 "auth-info-required",
1724 "job-sheets-default",
1725 "marker-change-time",
1727 "marker-high-levels",
1729 "marker-low-levels",
1735 #endif /* __APPLE__ */
1738 "printer-is-accepting-jobs",
1739 "printer-is-shared",
1741 "printer-make-and-model",
1744 "printer-state-change-time",
1745 "printer-state-reasons",
1753 * Get the default paper size...
1756 appleGetPaperSize(media_default
, sizeof(media_default
));
1757 #endif /* __APPLE__ */
1760 * Build a CUPS_GET_PRINTERS or IPP_GET_PRINTER_ATTRIBUTES request, which
1761 * require the following attributes:
1763 * attributes-charset
1764 * attributes-natural-language
1765 * requesting-user-name
1766 * printer-uri [for IPP_GET_PRINTER_ATTRIBUTES]
1769 request
= ippNewRequest(op
);
1771 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1772 "requested-attributes", sizeof(pattrs
) / sizeof(pattrs
[0]),
1775 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
1776 "requesting-user-name", NULL
, cupsUser());
1780 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
1781 "localhost", ippPort(), "/printers/%s", name
);
1782 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
,
1787 * Do the request and get back a response...
1790 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
1792 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
1795 * Skip leading attributes until we hit a printer...
1798 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
1805 * Pull the needed attributes from this printer...
1808 printer_name
= NULL
;
1812 for (; attr
&& attr
->group_tag
== IPP_TAG_PRINTER
; attr
= attr
->next
)
1814 if (attr
->value_tag
!= IPP_TAG_INTEGER
&&
1815 attr
->value_tag
!= IPP_TAG_ENUM
&&
1816 attr
->value_tag
!= IPP_TAG_BOOLEAN
&&
1817 attr
->value_tag
!= IPP_TAG_TEXT
&&
1818 attr
->value_tag
!= IPP_TAG_TEXTLANG
&&
1819 attr
->value_tag
!= IPP_TAG_NAME
&&
1820 attr
->value_tag
!= IPP_TAG_NAMELANG
&&
1821 attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1822 attr
->value_tag
!= IPP_TAG_RANGE
)
1825 if (!strcmp(attr
->name
, "auth-info-required") ||
1826 !strcmp(attr
->name
, "marker-change-time") ||
1827 !strcmp(attr
->name
, "marker-colors") ||
1828 !strcmp(attr
->name
, "marker-high-levels") ||
1829 !strcmp(attr
->name
, "marker-levels") ||
1830 !strcmp(attr
->name
, "marker-low-levels") ||
1831 !strcmp(attr
->name
, "marker-message") ||
1832 !strcmp(attr
->name
, "marker-names") ||
1833 !strcmp(attr
->name
, "marker-types") ||
1834 !strcmp(attr
->name
, "printer-commands") ||
1835 !strcmp(attr
->name
, "printer-info") ||
1836 !strcmp(attr
->name
, "printer-is-shared") ||
1837 !strcmp(attr
->name
, "printer-make-and-model") ||
1838 !strcmp(attr
->name
, "printer-state") ||
1839 !strcmp(attr
->name
, "printer-state-change-time") ||
1840 !strcmp(attr
->name
, "printer-type") ||
1841 !strcmp(attr
->name
, "printer-is-accepting-jobs") ||
1842 !strcmp(attr
->name
, "printer-location") ||
1843 !strcmp(attr
->name
, "printer-state-reasons"))
1846 * Add a printer description attribute...
1849 num_options
= cupsAddOption(attr
->name
,
1850 cups_make_string(attr
, value
,
1852 num_options
, &options
);
1855 else if (!strcmp(attr
->name
, "media-supported"))
1858 * See if we can set a default media size...
1861 for (i
= 0; i
< attr
->num_values
; i
++)
1862 if (!strcasecmp(media_default
, attr
->values
[i
].string
.text
))
1864 num_options
= cupsAddOption("media", media_default
, num_options
,
1869 #endif /* __APPLE__ */
1870 else if (!strcmp(attr
->name
, "printer-name") &&
1871 attr
->value_tag
== IPP_TAG_NAME
)
1872 printer_name
= attr
->values
[0].string
.text
;
1873 else if (strncmp(attr
->name
, "notify-", 7) &&
1874 (attr
->value_tag
== IPP_TAG_BOOLEAN
||
1875 attr
->value_tag
== IPP_TAG_ENUM
||
1876 attr
->value_tag
== IPP_TAG_INTEGER
||
1877 attr
->value_tag
== IPP_TAG_KEYWORD
||
1878 attr
->value_tag
== IPP_TAG_NAME
||
1879 attr
->value_tag
== IPP_TAG_RANGE
) &&
1880 (ptr
= strstr(attr
->name
, "-default")) != NULL
)
1883 * Add a default option...
1886 strlcpy(optname
, attr
->name
, sizeof(optname
));
1887 optname
[ptr
- attr
->name
] = '\0';
1889 if (strcasecmp(optname
, "media") ||
1890 !cupsGetOption("media", num_options
, options
))
1891 num_options
= cupsAddOption(optname
,
1892 cups_make_string(attr
, value
,
1894 num_options
, &options
);
1899 * See if we have everything needed...
1904 cupsFreeOptions(num_options
, options
);
1912 if ((dest
= cups_add_dest(printer_name
, NULL
, &num_dests
, dests
)) != NULL
)
1914 dest
->num_options
= num_options
;
1915 dest
->options
= options
;
1918 cupsFreeOptions(num_options
, options
);
1924 ippDelete(response
);
1928 * Return the count...
1936 * 'cups_make_string()' - Make a comma-separated string of values from an IPP
1940 static char * /* O - New string */
1942 ipp_attribute_t
*attr
, /* I - Attribute to convert */
1943 char *buffer
, /* I - Buffer */
1944 size_t bufsize
) /* I - Size of buffer */
1946 int i
; /* Looping var */
1947 char *ptr
, /* Pointer into buffer */
1948 *end
, /* Pointer to end of buffer */
1949 *valptr
; /* Pointer into string attribute */
1953 * Return quickly if we have a single string value...
1956 if (attr
->num_values
== 1 &&
1957 attr
->value_tag
!= IPP_TAG_INTEGER
&&
1958 attr
->value_tag
!= IPP_TAG_ENUM
&&
1959 attr
->value_tag
!= IPP_TAG_BOOLEAN
&&
1960 attr
->value_tag
!= IPP_TAG_RANGE
)
1961 return (attr
->values
[0].string
.text
);
1964 * Copy the values to the string, separating with commas and escaping strings
1968 end
= buffer
+ bufsize
- 1;
1970 for (i
= 0, ptr
= buffer
; i
< attr
->num_values
&& ptr
< end
; i
++)
1975 switch (attr
->value_tag
)
1977 case IPP_TAG_INTEGER
:
1979 snprintf(ptr
, end
- ptr
+ 1, "%d", attr
->values
[i
].integer
);
1982 case IPP_TAG_BOOLEAN
:
1983 if (attr
->values
[i
].boolean
)
1984 strlcpy(ptr
, "true", end
- ptr
+ 1);
1986 strlcpy(ptr
, "false", end
- ptr
+ 1);
1989 case IPP_TAG_RANGE
:
1990 if (attr
->values
[i
].range
.lower
== attr
->values
[i
].range
.upper
)
1991 snprintf(ptr
, end
- ptr
+ 1, "%d", attr
->values
[i
].range
.lower
);
1993 snprintf(ptr
, end
- ptr
+ 1, "%d-%d", attr
->values
[i
].range
.lower
,
1994 attr
->values
[i
].range
.upper
);
1998 for (valptr
= attr
->values
[i
].string
.text
;
1999 *valptr
&& ptr
< end
;)
2001 if (strchr(" \t\n\\\'\"", *valptr
))
2003 if (ptr
>= (end
- 1))
2026 * End of "$Id: dest.c 7946 2008-09-16 23:27:54Z mike $".