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...
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 *appleGetDefault(char *name
, int namesize
);
86 static char *appleGetPaperSize(char *name
, int namesize
);
87 static CFStringRef
appleGetPrinter(CFArrayRef locations
, CFStringRef network
,
89 static void appleSetDefault(const char *name
);
90 static int appleUseLastPrinter(void);
91 #endif /* __APPLE__ */
92 static cups_dest_t
*cups_add_dest(const char *name
, const char *instance
,
93 int *num_dests
, cups_dest_t
**dests
);
94 static int cups_compare_dests(cups_dest_t
*a
, cups_dest_t
*b
);
95 static int cups_find_dest(const char *name
, const char *instance
,
96 int num_dests
, cups_dest_t
*dests
, int prev
,
98 static char *cups_get_default(const char *filename
, char *namebuf
,
99 size_t namesize
, const char **instance
);
100 static int cups_get_dests(const char *filename
, const char *match_name
,
101 const char *match_inst
, int num_dests
,
102 cups_dest_t
**dests
);
103 static int cups_get_sdests(http_t
*http
, ipp_op_t op
, const char *name
,
104 int num_dests
, cups_dest_t
**dests
);
105 static char *cups_make_string(ipp_attribute_t
*attr
, char *buffer
,
110 * 'cupsAddDest()' - Add a destination to the list of destinations.
112 * This function cannot be used to add a new class or printer queue,
113 * it only adds a new container of saved options for the named
114 * destination or instance.
116 * If the named destination already exists, the destination list is
117 * returned unchanged. Adding a new instance of a destination creates
118 * a copy of that destination's options.
120 * Use the @link cupsSaveDests@ function to save the updated list of
121 * destinations to the user's lpoptions file.
124 int /* O - New number of destinations */
125 cupsAddDest(const char *name
, /* I - Destination name */
126 const char *instance
, /* I - Instance name or @code NULL@ for none/primary */
127 int num_dests
, /* I - Number of destinations */
128 cups_dest_t
**dests
) /* IO - Destinations */
130 int i
; /* Looping var */
131 cups_dest_t
*dest
; /* Destination pointer */
132 cups_dest_t
*parent
; /* Parent destination */
133 cups_option_t
*doption
, /* Current destination option */
134 *poption
; /* Current parent option */
140 if (!cupsGetDest(name
, instance
, num_dests
, *dests
))
143 (parent
= cupsGetDest(name
, NULL
, num_dests
, *dests
)) == NULL
)
146 dest
= cups_add_dest(name
, instance
, &num_dests
, dests
);
148 if (instance
&& parent
&& parent
->num_options
> 0)
151 * Copy options from parent...
154 dest
->options
= calloc(sizeof(cups_option_t
), parent
->num_options
);
158 dest
->num_options
= parent
->num_options
;
160 for (i
= dest
->num_options
, doption
= dest
->options
,
161 poption
= parent
->options
;
163 i
--, doption
++, poption
++)
165 doption
->name
= _cupsStrRetain(poption
->name
);
166 doption
->value
= _cupsStrRetain(poption
->value
);
177 * 'cupsFreeDests()' - Free the memory used by the list of destinations.
181 cupsFreeDests(int num_dests
, /* I - Number of destinations */
182 cups_dest_t
*dests
) /* I - Destinations */
184 int i
; /* Looping var */
185 cups_dest_t
*dest
; /* Current destination */
188 if (num_dests
== 0 || dests
== NULL
)
191 for (i
= num_dests
, dest
= dests
; i
> 0; i
--, dest
++)
193 _cupsStrFree(dest
->name
);
194 _cupsStrFree(dest
->instance
);
196 cupsFreeOptions(dest
->num_options
, dest
->options
);
204 * 'cupsGetDest()' - Get the named destination from the list.
206 * Use the @link cupsGetDests@ or @link cupsGetDests2@ functions to get a
207 * list of supported destinations for the current user.
210 cups_dest_t
* /* O - Destination pointer or @code NULL@ */
211 cupsGetDest(const char *name
, /* I - Destination name or @code NULL@ for the default destination */
212 const char *instance
, /* I - Instance name or @code NULL@ */
213 int num_dests
, /* I - Number of destinations */
214 cups_dest_t
*dests
) /* I - Destinations */
216 int diff
, /* Result of comparison */
217 match
; /* Matching index */
220 if (num_dests
<= 0 || !dests
)
226 * NULL name for default printer.
229 while (num_dests
> 0)
231 if (dests
->is_default
)
241 * Lookup name and optionally the instance...
244 match
= cups_find_dest(name
, instance
, num_dests
, dests
, -1, &diff
);
247 return (dests
+ match
);
255 * 'cupsGetDests()' - Get the list of destinations from the default server.
257 * Starting with CUPS 1.2, the returned list of destinations include the
258 * printer-info, printer-is-accepting-jobs, printer-is-shared,
259 * printer-make-and-model, printer-state, printer-state-change-time,
260 * printer-state-reasons, and printer-type attributes as options. CUPS 1.4
261 * adds the marker-change-time, marker-colors, marker-high-levels,
262 * marker-levels, marker-low-levels, marker-message, marker-names,
263 * marker-types, and printer-commands attributes as well.
265 * Use the @link cupsFreeDests@ function to free the destination list and
266 * the @link cupsGetDest@ function to find a particular destination.
269 int /* O - Number of destinations */
270 cupsGetDests(cups_dest_t
**dests
) /* O - Destinations */
272 return (cupsGetDests2(CUPS_HTTP_DEFAULT
, dests
));
277 * 'cupsGetDests2()' - Get the list of destinations from the specified server.
279 * Starting with CUPS 1.2, the returned list of destinations include the
280 * printer-info, printer-is-accepting-jobs, printer-is-shared,
281 * printer-make-and-model, printer-state, printer-state-change-time,
282 * printer-state-reasons, and printer-type attributes as options. CUPS 1.4
283 * adds the marker-change-time, marker-colors, marker-high-levels,
284 * marker-levels, marker-low-levels, marker-message, marker-names,
285 * marker-types, and printer-commands attributes as well.
287 * Use the @link cupsFreeDests@ function to free the destination list and
288 * the @link cupsGetDest@ function to find a particular destination.
290 * @since CUPS 1.1.21/Mac OS X 10.4@
293 int /* O - Number of destinations */
294 cupsGetDests2(http_t
*http
, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
295 cups_dest_t
**dests
) /* O - Destinations */
297 int i
; /* Looping var */
298 int num_dests
; /* Number of destinations */
299 cups_dest_t
*dest
; /* Destination pointer */
300 const char *home
; /* HOME environment variable */
301 char filename
[1024]; /* Local ~/.cups/lpoptions file */
302 const char *defprinter
; /* Default printer */
303 char name
[1024], /* Copy of printer name */
304 *instance
; /* Pointer to instance name */
305 int num_reals
; /* Number of real queues */
306 cups_dest_t
*reals
; /* Real queues */
307 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
311 * Range check the input...
316 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad NULL dests pointer"), 1);
321 * Initialize destination array...
325 *dests
= (cups_dest_t
*)0;
328 * Grab the printers and classes...
331 num_dests
= cups_get_sdests(http
, CUPS_GET_PRINTERS
, NULL
, num_dests
, dests
);
333 if (cupsLastError() >= IPP_REDIRECTION_OTHER_SITE
)
335 cupsFreeDests(num_dests
, *dests
);
336 *dests
= (cups_dest_t
*)0;
341 * Make a copy of the "real" queues for a later sanity check...
346 num_reals
= num_dests
;
347 reals
= calloc(num_reals
, sizeof(cups_dest_t
));
350 memcpy(reals
, *dests
, num_reals
* sizeof(cups_dest_t
));
361 * Grab the default destination...
365 if ((defprinter
= appleGetDefault(name
, sizeof(name
))) == NULL
)
366 #endif /* __APPLE__ */
367 defprinter
= cupsGetDefault2(http
);
372 * Grab printer and instance name...
376 if (name
!= defprinter
)
377 #endif /* __APPLE__ */
378 strlcpy(name
, defprinter
, sizeof(name
));
380 if ((instance
= strchr(name
, '/')) != NULL
)
384 * Lookup the printer and instance and make it the default...
387 if ((dest
= cupsGetDest(name
, instance
, num_dests
, *dests
)) != NULL
)
388 dest
->is_default
= 1;
393 * This initialization of "instance" is unnecessary, but avoids a
394 * compiler warning...
401 * Load the /etc/cups/lpoptions and ~/.cups/lpoptions files...
404 snprintf(filename
, sizeof(filename
), "%s/lpoptions", cg
->cups_serverroot
);
405 num_dests
= cups_get_dests(filename
, NULL
, NULL
, num_dests
, dests
);
407 if ((home
= getenv("HOME")) != NULL
)
409 snprintf(filename
, sizeof(filename
), "%s/.cups/lpoptions", home
);
410 if (access(filename
, 0))
411 snprintf(filename
, sizeof(filename
), "%s/.lpoptions", home
);
413 num_dests
= cups_get_dests(filename
, NULL
, NULL
, num_dests
, dests
);
417 * Validate the current default destination - this prevents old
418 * Default lines in /etc/cups/lpoptions and ~/.cups/lpoptions from
419 * pointing to a non-existent printer or class...
425 * See if we have a default printer...
428 if ((dest
= cupsGetDest(NULL
, NULL
, num_dests
, *dests
)) != NULL
)
431 * Have a default; see if it is real...
434 dest
= cupsGetDest(dest
->name
, NULL
, num_reals
, reals
);
438 * If dest is NULL, then no default (that exists) is set, so we
439 * need to set a default if one exists...
442 if (dest
== NULL
&& defprinter
!= NULL
)
444 for (i
= 0; i
< num_dests
; i
++)
445 (*dests
)[i
].is_default
= 0;
447 if ((dest
= cupsGetDest(name
, instance
, num_dests
, *dests
)) != NULL
)
448 dest
->is_default
= 1;
459 * Return the number of destinations...
463 _cupsSetError(IPP_OK
, NULL
, 0);
470 * 'cupsGetNamedDest()' - Get options for the named destination.
472 * This function is optimized for retrieving a single destination and should
473 * be used instead of @link cupsGetDests@ and @link cupsGetDest@ when you either
474 * know the name of the destination or want to print to the default destination.
475 * If @code NULL@ is returned, the destination does not exist or there is no
476 * default destination.
478 * If "http" is @code CUPS_HTTP_DEFAULT@, the connection to the default print
479 * server will be used.
481 * If "name" is @code NULL@, the default printer for the current user will be
484 * The returned destination must be freed using @link cupsFreeDests@ with a
485 * "num_dests" value of 1.
490 cups_dest_t
* /* O - Destination or @code NULL@ */
491 cupsGetNamedDest(http_t
*http
, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
492 const char *name
, /* I - Destination name or @code NULL@ for the default destination */
493 const char *instance
) /* I - Instance name or @code NULL@ */
495 cups_dest_t
*dest
; /* Destination */
496 char filename
[1024], /* Path to lpoptions */
497 defname
[256]; /* Default printer name */
498 const char *home
= getenv("HOME"); /* Home directory */
499 ipp_op_t op
= IPP_GET_PRINTER_ATTRIBUTES
;
500 /* IPP operation to get server ops */
501 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
505 * If "name" is NULL, find the default destination...
510 if ((name
= getenv("LPDEST")) == NULL
)
511 if ((name
= getenv("PRINTER")) != NULL
&& !strcmp(name
, "lp"))
517 * No default in the environment, try the user's lpoptions files...
520 snprintf(filename
, sizeof(filename
), "%s/.cups/lpoptions", home
);
522 if ((name
= cups_get_default(filename
, defname
, sizeof(defname
),
525 snprintf(filename
, sizeof(filename
), "%s/.lpoptions", home
);
526 name
= cups_get_default(filename
, defname
, sizeof(defname
),
534 * Still not there? Try the system lpoptions file...
537 snprintf(filename
, sizeof(filename
), "%s/lpoptions",
538 cg
->cups_serverroot
);
539 name
= cups_get_default(filename
, defname
, sizeof(defname
), &instance
);
545 * No locally-set default destination, ask the server...
548 op
= CUPS_GET_DEFAULT
;
553 * Get the printer's attributes...
556 if (!cups_get_sdests(http
, op
, name
, 0, &dest
))
560 dest
->instance
= _cupsStrAlloc(instance
);
563 * Then add local options...
566 snprintf(filename
, sizeof(filename
), "%s/lpoptions", cg
->cups_serverroot
);
567 cups_get_dests(filename
, name
, instance
, 1, &dest
);
571 snprintf(filename
, sizeof(filename
), "%s/.cups/lpoptions", home
);
573 if (access(filename
, 0))
574 snprintf(filename
, sizeof(filename
), "%s/.lpoptions", home
);
576 cups_get_dests(filename
, name
, instance
, 1, &dest
);
580 * Return the result...
588 * 'cupsRemoveDest()' - Remove a destination from the destination list.
590 * Removing a destination/instance does not delete the class or printer
591 * queue, merely the lpoptions for that destination/instance. Use the
592 * @link cupsSetDests@ or @link cupsSetDests2@ functions to save the new
593 * options for the user.
595 * @since CUPS 1.3/Mac OS X 10.5@
598 int /* O - New number of destinations */
599 cupsRemoveDest(const char *name
, /* I - Destination name */
600 const char *instance
, /* I - Instance name or @code NULL@ */
601 int num_dests
, /* I - Number of destinations */
602 cups_dest_t
**dests
) /* IO - Destinations */
604 int i
; /* Index into destinations */
605 cups_dest_t
*dest
; /* Pointer to destination */
609 * Find the destination...
612 if ((dest
= cupsGetDest(name
, instance
, num_dests
, *dests
)) == NULL
)
619 _cupsStrFree(dest
->name
);
620 _cupsStrFree(dest
->instance
);
621 cupsFreeOptions(dest
->num_options
, dest
->options
);
624 * Remove the destination from the array...
632 memmove(dest
, dest
+ 1, (num_dests
- i
) * sizeof(cups_dest_t
));
639 * 'cupsSetDefaultDest()' - Set the default destination.
641 * @since CUPS 1.3/Mac OS X 10.5@
646 const char *name
, /* I - Destination name */
647 const char *instance
, /* I - Instance name or @code NULL@ */
648 int num_dests
, /* I - Number of destinations */
649 cups_dest_t
*dests
) /* I - Destinations */
651 int i
; /* Looping var */
652 cups_dest_t
*dest
; /* Current destination */
656 * Range check input...
659 if (!name
|| num_dests
<= 0 || !dests
)
663 * Loop through the array and set the "is_default" flag for the matching
667 for (i
= num_dests
, dest
= dests
; i
> 0; i
--, dest
++)
668 dest
->is_default
= !strcasecmp(name
, dest
->name
) &&
669 ((!instance
&& !dest
->instance
) ||
670 (instance
&& dest
->instance
&&
671 !strcasecmp(instance
, dest
->instance
)));
676 * 'cupsSetDests()' - Save the list of destinations for the default server.
678 * This function saves the destinations to /etc/cups/lpoptions when run
679 * as root and ~/.cups/lpoptions when run as a normal user.
683 cupsSetDests(int num_dests
, /* I - Number of destinations */
684 cups_dest_t
*dests
) /* I - Destinations */
686 cupsSetDests2(CUPS_HTTP_DEFAULT
, num_dests
, dests
);
691 * 'cupsSetDests2()' - Save the list of destinations for the specified server.
693 * This function saves the destinations to /etc/cups/lpoptions when run
694 * as root and ~/.cups/lpoptions when run as a normal user.
696 * @since CUPS 1.1.21/Mac OS X 10.4@
699 int /* O - 0 on success, -1 on error */
700 cupsSetDests2(http_t
*http
, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
701 int num_dests
, /* I - Number of destinations */
702 cups_dest_t
*dests
) /* I - Destinations */
704 int i
, j
; /* Looping vars */
705 int wrote
; /* Wrote definition? */
706 cups_dest_t
*dest
; /* Current destination */
707 cups_option_t
*option
; /* Current option */
708 _ipp_option_t
*match
; /* Matching attribute for option */
709 FILE *fp
; /* File pointer */
711 const char *home
; /* HOME environment variable */
713 char filename
[1024]; /* lpoptions file */
714 int num_temps
; /* Number of temporary destinations */
715 cups_dest_t
*temps
, /* Temporary destinations */
716 *temp
; /* Current temporary dest */
717 const char *val
; /* Value of temporary option */
718 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
722 * Range check the input...
725 if (!num_dests
|| !dests
)
729 * Get the server destinations...
732 num_temps
= cups_get_sdests(http
, CUPS_GET_PRINTERS
, NULL
, 0, &temps
);
734 if (cupsLastError() >= IPP_REDIRECTION_OTHER_SITE
)
736 cupsFreeDests(num_temps
, temps
);
741 * Figure out which file to write to...
744 snprintf(filename
, sizeof(filename
), "%s/lpoptions", cg
->cups_serverroot
);
750 * Merge in server defaults...
753 num_temps
= cups_get_dests(filename
, NULL
, NULL
, num_temps
, &temps
);
756 * Point to user defaults...
759 if ((home
= getenv("HOME")) != NULL
)
762 * Remove the old ~/.lpoptions file...
765 snprintf(filename
, sizeof(filename
), "%s/.lpoptions", home
);
769 * Create ~/.cups subdirectory...
772 snprintf(filename
, sizeof(filename
), "%s/.cups", home
);
773 if (access(filename
, 0))
774 mkdir(filename
, 0700);
776 snprintf(filename
, sizeof(filename
), "%s/.cups/lpoptions", home
);
782 * Try to open the file...
785 if ((fp
= fopen(filename
, "w")) == NULL
)
787 cupsFreeDests(num_temps
, temps
);
793 * Set the permissions to 0644 when saving to the /etc/cups/lpoptions
798 fchmod(fileno(fp
), 0644);
802 * Write each printer; each line looks like:
804 * Dest name[/instance] options
805 * Default name[/instance] options
808 for (i
= num_dests
, dest
= dests
; i
> 0; i
--, dest
++)
809 if (dest
->instance
!= NULL
|| dest
->num_options
!= 0 || dest
->is_default
)
811 if (dest
->is_default
)
813 fprintf(fp
, "Default %s", dest
->name
);
815 fprintf(fp
, "/%s", dest
->instance
);
822 if ((temp
= cupsGetDest(dest
->name
, dest
->instance
, num_temps
, temps
)) == NULL
)
823 temp
= cupsGetDest(dest
->name
, NULL
, num_temps
, temps
);
825 for (j
= dest
->num_options
, option
= dest
->options
; j
> 0; j
--, option
++)
828 * See if this option is a printer attribute; if so, skip it...
831 if ((match
= _ippFindOption(option
->name
)) != NULL
&&
832 match
->group_tag
== IPP_TAG_PRINTER
)
836 * See if the server/global options match these; if so, don't
841 (val
= cupsGetOption(option
->name
, temp
->num_options
,
842 temp
->options
)) != NULL
&&
843 !strcasecmp(val
, option
->value
))
847 * Options don't match, write to the file...
852 fprintf(fp
, "Dest %s", dest
->name
);
854 fprintf(fp
, "/%s", dest
->instance
);
858 if (option
->value
[0])
860 if (strchr(option
->value
, ' ') ||
861 strchr(option
->value
, '\\') ||
862 strchr(option
->value
, '\"') ||
863 strchr(option
->value
, '\''))
869 fprintf(fp
, " %s=\"", option
->name
);
871 for (val
= option
->value
; *val
; val
++)
873 if (strchr("\"\'\\", *val
))
884 * Store the literal value...
887 fprintf(fp
, " %s=%s", option
->name
, option
->value
);
891 fprintf(fp
, " %s", option
->name
);
899 * Free the temporary destinations and close the file...
902 cupsFreeDests(num_temps
, temps
);
908 * Set the default printer for this location - this allows command-line
909 * and GUI applications to share the same default destination...
912 if ((dest
= cupsGetDest(NULL
, NULL
, num_dests
, dests
)) != NULL
)
913 appleSetDefault(dest
->name
);
914 #endif /* __APPLE__ */
916 #ifdef HAVE_NOTIFY_POST
918 * Send a notification so that MacOS X applications can know about the
922 notify_post("com.apple.printerListChange");
923 #endif /* HAVE_NOTIFY_POST */
931 * 'appleCopyLocations()' - Copy the location history array.
934 static CFArrayRef
/* O - Location array or NULL */
935 appleCopyLocations(void)
937 CFArrayRef locations
; /* Location array */
941 * Look up the location array in the preferences...
944 if ((locations
= CFPreferencesCopyAppValue(kLocationHistoryArrayKey
,
945 kPMPrintingPreferences
)) == NULL
)
948 if (CFGetTypeID(locations
) != CFArrayGetTypeID())
950 CFRelease(locations
);
959 * 'appleCopyNetwork()' - Get the network ID for the current location.
962 static CFStringRef
/* O - Network ID */
963 appleCopyNetwork(void)
965 SCDynamicStoreRef dynamicStore
; /* System configuration data */
966 CFStringRef key
; /* Current network configuration key */
967 CFDictionaryRef ip_dict
; /* Network configuration data */
968 CFStringRef network
= NULL
; /* Current network ID */
971 if ((dynamicStore
= SCDynamicStoreCreate(NULL
, CFSTR("Printing"), NULL
,
974 if ((key
= SCDynamicStoreKeyCreateNetworkGlobalEntity(
975 NULL
, kSCDynamicStoreDomainState
, kSCEntNetIPv4
)) != NULL
)
977 if ((ip_dict
= SCDynamicStoreCopyValue(dynamicStore
, key
)) != NULL
)
979 if ((network
= CFDictionaryGetValue(ip_dict
,
980 kSCPropNetIPv4Router
)) != NULL
)
989 CFRelease(dynamicStore
);
997 * 'appleGetDefault()' - Get the default printer for this location.
1000 static char * /* O - Name or NULL if no default */
1001 appleGetDefault(char *name
, /* I - Name buffer */
1002 int namesize
) /* I - Size of name buffer */
1004 CFStringRef network
; /* Network location */
1005 CFArrayRef locations
; /* Location array */
1006 CFStringRef locprinter
; /* Current printer */
1010 * Use location-based defaults if "use last printer" is selected in the
1011 * system preferences...
1014 if (!appleUseLastPrinter())
1016 DEBUG_puts("appleGetDefault: Not using last printer as default...");
1021 * Get the current location...
1024 if ((network
= appleCopyNetwork()) == NULL
)
1026 DEBUG_puts("appleGetDefault: Unable to get current network...");
1031 CFStringGetCString(network
, name
, namesize
, kCFStringEncodingUTF8
);
1032 DEBUG_printf(("appleGetDefault: network=\"%s\"\n", name
));
1036 * Lookup the network in the preferences...
1039 if ((locations
= appleCopyLocations()) == NULL
)
1042 * Missing or bad location array, so no location-based default...
1045 DEBUG_puts("appleGetDefault: Missing or bad location history array...");
1052 DEBUG_printf(("appleGetDefault: Got location, %d entries...\n",
1053 (int)CFArrayGetCount(locations
)));
1055 if ((locprinter
= appleGetPrinter(locations
, network
, NULL
)) != NULL
)
1056 CFStringGetCString(locprinter
, name
, namesize
, kCFStringEncodingUTF8
);
1061 CFRelease(locations
);
1063 DEBUG_printf(("appleGetDefault: Returning \"%s\"...\n", name
));
1065 return (*name
? name
: NULL
);
1070 * 'appleGetPaperSize()' - Get the default paper size.
1073 static char * /* O - Default paper size */
1074 appleGetPaperSize(char *name
, /* I - Paper size name buffer */
1075 int namesize
) /* I - Size of buffer */
1077 CFStringRef defaultPaperID
; /* Default paper ID */
1080 defaultPaperID
= CFPreferencesCopyAppValue(kDefaultPaperIDKey
,
1081 kPMPrintingPreferences
);
1082 if (!defaultPaperID
||
1083 !CFStringGetCString(defaultPaperID
, name
, namesize
,
1084 kCFStringEncodingUTF8
))
1086 else if (!strncmp(name
, "na-", 3))
1087 _cups_strcpy(name
, name
+ 3);
1088 else if (!strncmp(name
, "iso-", 4))
1089 _cups_strcpy(name
, name
+ 4);
1092 CFRelease(defaultPaperID
);
1099 * 'appleGetPrinter()' - Get a printer from the history array.
1102 static CFStringRef
/* O - Printer name or NULL */
1103 appleGetPrinter(CFArrayRef locations
, /* I - Location array */
1104 CFStringRef network
, /* I - Network name */
1105 CFIndex
*locindex
) /* O - Index in array */
1107 CFIndex i
, /* Looping var */
1108 count
; /* Number of locations */
1109 CFDictionaryRef location
; /* Current location */
1110 CFStringRef locnetwork
, /* Current network */
1111 locprinter
; /* Current printer */
1114 for (i
= 0, count
= CFArrayGetCount(locations
); i
< count
; i
++)
1115 if ((location
= CFArrayGetValueAtIndex(locations
, i
)) != NULL
&&
1116 CFGetTypeID(location
) == CFDictionaryGetTypeID())
1118 if ((locnetwork
= CFDictionaryGetValue(location
,
1119 kLocationNetworkKey
)) != NULL
&&
1120 CFGetTypeID(locnetwork
) == CFStringGetTypeID() &&
1121 CFStringCompare(network
, locnetwork
, 0) == kCFCompareEqualTo
&&
1122 (locprinter
= CFDictionaryGetValue(location
,
1123 kLocationPrinterIDKey
)) != NULL
&&
1124 CFGetTypeID(locprinter
) == CFStringGetTypeID())
1129 return (locprinter
);
1138 * 'appleSetDefault()' - Set the default printer for this location.
1142 appleSetDefault(const char *name
) /* I - Default printer/class name */
1144 CFStringRef network
; /* Current network */
1145 CFArrayRef locations
; /* Old locations array */
1146 CFIndex locindex
; /* Index in locations array */
1147 CFStringRef locprinter
; /* Current printer */
1148 CFMutableArrayRef newlocations
; /* New locations array */
1149 CFMutableDictionaryRef newlocation
; /* New location */
1150 CFStringRef newprinter
; /* New printer */
1154 * Get the current location...
1157 if ((network
= appleCopyNetwork()) == NULL
)
1159 DEBUG_puts("appleSetDefault: Unable to get current network...");
1163 if ((newprinter
= CFStringCreateWithCString(kCFAllocatorDefault
, name
,
1164 kCFStringEncodingUTF8
)) == NULL
)
1171 * Lookup the network in the preferences...
1174 if ((locations
= appleCopyLocations()) != NULL
)
1175 locprinter
= appleGetPrinter(locations
, network
, &locindex
);
1183 CFStringCompare(locprinter
, newprinter
, 0) != kCFCompareEqualTo
)
1186 * Need to change the locations array...
1191 newlocations
= CFArrayCreateMutableCopy(kCFAllocatorDefault
, 0,
1195 CFArrayRemoveValueAtIndex(newlocations
, locindex
);
1198 newlocations
= CFArrayCreateMutable(kCFAllocatorDefault
, 0, NULL
);
1200 newlocation
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
1201 &kCFTypeDictionaryKeyCallBacks
,
1202 &kCFTypeDictionaryValueCallBacks
);
1204 if (newlocation
&& newlocations
)
1207 * Put the new location at the front of the array...
1210 CFDictionaryAddValue(newlocation
, kLocationNetworkKey
, network
);
1211 CFDictionaryAddValue(newlocation
, kLocationPrinterIDKey
, newprinter
);
1212 CFArrayInsertValueAtIndex(newlocations
, 0, newlocation
);
1215 * Limit the number of locations to 10...
1218 while (CFArrayGetCount(newlocations
) > 10)
1219 CFArrayRemoveValueAtIndex(newlocations
, 10);
1222 * Push the changes out...
1225 CFPreferencesSetAppValue(kLocationHistoryArrayKey
, newlocations
,
1226 kPMPrintingPreferences
);
1227 CFPreferencesAppSynchronize(kPMPrintingPreferences
);
1231 CFRelease(newlocations
);
1234 CFRelease(newlocation
);
1238 CFRelease(locations
);
1241 CFRelease(newprinter
);
1246 * 'appleUseLastPrinter()' - Get the default printer preference value.
1249 static int /* O - 1 to use last printer, 0 otherwise */
1250 appleUseLastPrinter(void)
1252 CFPropertyListRef uselast
; /* Use last printer preference value */
1255 if ((uselast
= CFPreferencesCopyAppValue(kUseLastPrinterAsCurrentPrinterKey
,
1256 kPMPrintingPreferences
)) != NULL
)
1260 if (uselast
== kCFBooleanFalse
)
1266 #endif /* __APPLE__ */
1270 * 'cups_add_dest()' - Add a destination to the array.
1272 * Unlike cupsAddDest(), this function does not check for duplicates.
1275 static cups_dest_t
* /* O - New destination */
1276 cups_add_dest(const char *name
, /* I - Name of destination */
1277 const char *instance
, /* I - Instance or NULL */
1278 int *num_dests
, /* IO - Number of destinations */
1279 cups_dest_t
**dests
) /* IO - Destinations */
1281 int insert
, /* Insertion point */
1282 diff
; /* Result of comparison */
1283 cups_dest_t
*dest
; /* Destination pointer */
1287 * Add new destination...
1290 if (*num_dests
== 0)
1291 dest
= malloc(sizeof(cups_dest_t
));
1293 dest
= realloc(*dests
, sizeof(cups_dest_t
) * (*num_dests
+ 1));
1301 * Find where to insert the destination...
1304 if (*num_dests
== 0)
1308 insert
= cups_find_dest(name
, instance
, *num_dests
, *dests
, *num_dests
- 1,
1316 * Move the array elements as needed...
1319 if (insert
< *num_dests
)
1320 memmove(*dests
+ insert
+ 1, *dests
+ insert
,
1321 (*num_dests
- insert
) * sizeof(cups_dest_t
));
1326 * Initialize the destination...
1329 dest
= *dests
+ insert
;
1330 dest
->name
= _cupsStrAlloc(name
);
1331 dest
->instance
= _cupsStrAlloc(instance
);
1332 dest
->is_default
= 0;
1333 dest
->num_options
= 0;
1334 dest
->options
= (cups_option_t
*)0;
1341 * 'cups_compare_dests()' - Compare two destinations.
1344 static int /* O - Result of comparison */
1345 cups_compare_dests(cups_dest_t
*a
, /* I - First destination */
1346 cups_dest_t
*b
) /* I - Second destination */
1348 int diff
; /* Difference */
1351 if ((diff
= strcasecmp(a
->name
, b
->name
)) != 0)
1353 else if (a
->instance
&& b
->instance
)
1354 return (strcasecmp(a
->instance
, b
->instance
));
1356 return ((a
->instance
&& !b
->instance
) - (!a
->instance
&& b
->instance
));
1361 * 'cups_find_dest()' - Find a destination using a binary search.
1364 static int /* O - Index of match */
1365 cups_find_dest(const char *name
, /* I - Destination name */
1366 const char *instance
, /* I - Instance or NULL */
1367 int num_dests
, /* I - Number of destinations */
1368 cups_dest_t
*dests
, /* I - Destinations */
1369 int prev
, /* I - Previous index */
1370 int *rdiff
) /* O - Difference of match */
1372 int left
, /* Low mark for binary search */
1373 right
, /* High mark for binary search */
1374 current
, /* Current index */
1375 diff
; /* Result of comparison */
1376 cups_dest_t key
; /* Search key */
1379 key
.name
= (char *)name
;
1380 key
.instance
= (char *)instance
;
1385 * Start search on either side of previous...
1388 if ((diff
= cups_compare_dests(&key
, dests
+ prev
)) == 0 ||
1389 (diff
< 0 && prev
== 0) ||
1390 (diff
> 0 && prev
== (num_dests
- 1)))
1398 * Start with previous on right side...
1407 * Start wih previous on left side...
1411 right
= num_dests
- 1;
1417 * Start search in the middle...
1421 right
= num_dests
- 1;
1426 current
= (left
+ right
) / 2;
1427 diff
= cups_compare_dests(&key
, dests
+ current
);
1436 while ((right
- left
) > 1);
1441 * Check the last 1 or 2 elements...
1444 if ((diff
= cups_compare_dests(&key
, dests
+ left
)) <= 0)
1448 diff
= cups_compare_dests(&key
, dests
+ right
);
1454 * Return the closest destination and the difference...
1464 * 'cups_get_default()' - Get the default destination from an lpoptions file.
1467 static char * /* O - Default destination or NULL */
1468 cups_get_default(const char *filename
, /* I - File to read */
1469 char *namebuf
, /* I - Name buffer */
1470 size_t namesize
, /* I - Size of name buffer */
1471 const char **instance
) /* I - Instance */
1473 cups_file_t
*fp
; /* lpoptions file */
1474 char line
[8192], /* Line from file */
1475 *value
, /* Value for line */
1476 *nameptr
; /* Pointer into name */
1477 int linenum
; /* Current line */
1482 if ((fp
= cupsFileOpen(filename
, "r")) != NULL
)
1486 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
1488 if (!strcasecmp(line
, "default") && value
)
1490 strlcpy(namebuf
, value
, namesize
);
1492 if ((nameptr
= strchr(namebuf
, ' ')) != NULL
)
1494 if ((nameptr
= strchr(namebuf
, '\t')) != NULL
)
1497 if ((nameptr
= strchr(namebuf
, '/')) != NULL
)
1500 *instance
= nameptr
;
1508 return (*namebuf
? namebuf
: NULL
);
1513 * 'cups_get_dests()' - Get destinations from a file.
1516 static int /* O - Number of destinations */
1517 cups_get_dests(const char *filename
, /* I - File to read from */
1518 const char *match_name
, /* I - Destination name we want */
1519 const char *match_inst
, /* I - Instance name we want */
1520 int num_dests
, /* I - Number of destinations */
1521 cups_dest_t
**dests
) /* IO - Destinations */
1523 int i
; /* Looping var */
1524 cups_dest_t
*dest
; /* Current destination */
1525 cups_file_t
*fp
; /* File pointer */
1526 char line
[8192], /* Line from file */
1527 *lineptr
, /* Pointer into line */
1528 *name
, /* Name of destination/option */
1529 *instance
; /* Instance of destination */
1530 int linenum
; /* Current line number */
1531 const char *printer
; /* PRINTER or LPDEST */
1534 DEBUG_printf(("cups_get_dests(filename=\"%s\", match_name=\"%s\", "
1535 "match_inst=\"%s\", num_dests=%d, dests=%p)\n", filename
,
1536 match_name
? match_name
: "(null)",
1537 match_inst
? match_inst
: "(null)", num_dests
, dests
));
1540 * Try to open the file...
1543 if ((fp
= cupsFileOpen(filename
, "r")) == NULL
)
1547 * Check environment variables...
1550 if ((printer
= getenv("LPDEST")) == NULL
)
1551 if ((printer
= getenv("PRINTER")) != NULL
)
1552 if (strcmp(printer
, "lp") == 0)
1555 DEBUG_printf(("cups_get_dests: printer=\"%s\"\n",
1556 printer
? printer
: "(null)"));
1559 * Read each printer; each line looks like:
1561 * Dest name[/instance] options
1562 * Default name[/instance] options
1567 while (cupsFileGetConf(fp
, line
, sizeof(line
), &lineptr
, &linenum
))
1570 * See what type of line it is...
1573 DEBUG_printf(("cups_get_dests: linenum=%d line=\"%s\" lineptr=\"%s\"\n",
1574 linenum
, line
, lineptr
? lineptr
: "(null)"));
1576 if ((strcasecmp(line
, "dest") && strcasecmp(line
, "default")) || !lineptr
)
1578 DEBUG_puts("cups_get_dests: Not a dest or default line...");
1585 * Search for an instance...
1588 while (!isspace(*lineptr
& 255) && *lineptr
&& *lineptr
!= '/')
1591 if (*lineptr
== '/')
1594 * Found an instance...
1601 * Search for an instance...
1604 while (!isspace(*lineptr
& 255) && *lineptr
)
1613 DEBUG_printf(("cups_get_dests: name=\"%s\", instance=\"%s\"\n", name
,
1617 * See if the primary instance of the destination exists; if not,
1618 * ignore this entry and move on...
1623 if (strcasecmp(name
, match_name
) ||
1624 (!instance
&& match_inst
) ||
1625 (instance
&& !match_inst
) ||
1626 (instance
&& strcasecmp(instance
, match_inst
)))
1631 else if (cupsGetDest(name
, NULL
, num_dests
, *dests
) == NULL
)
1633 DEBUG_puts("cups_get_dests: Not found!");
1639 * Add the destination...
1642 num_dests
= cupsAddDest(name
, instance
, num_dests
, dests
);
1644 if ((dest
= cupsGetDest(name
, instance
, num_dests
, *dests
)) == NULL
)
1650 DEBUG_puts("cups_get_dests: Out of memory!");
1656 * Add options until we hit the end of the line...
1659 dest
->num_options
= cupsParseOptions(lineptr
, dest
->num_options
,
1663 * If we found what we were looking for, stop now...
1670 * Set this as default if needed...
1673 if (!printer
&& !strcasecmp(line
, "default"))
1675 DEBUG_puts("cups_get_dests: Setting as default...");
1677 for (i
= 0; i
< num_dests
; i
++)
1678 (*dests
)[i
].is_default
= 0;
1680 dest
->is_default
= 1;
1685 * Close the file and return...
1695 * 'cups_get_sdests()' - Get destinations from a server.
1698 static int /* O - Number of destinations */
1699 cups_get_sdests(http_t
*http
, /* I - Connection to server or CUPS_HTTP_DEFAULT */
1700 ipp_op_t op
, /* I - IPP operation */
1701 const char *name
, /* I - Name of destination */
1702 int num_dests
, /* I - Number of destinations */
1703 cups_dest_t
**dests
) /* IO - Destinations */
1705 int i
; /* Looping var */
1706 cups_dest_t
*dest
; /* Current destination */
1707 ipp_t
*request
, /* IPP Request */
1708 *response
; /* IPP Response */
1709 ipp_attribute_t
*attr
; /* Current attribute */
1710 const char *printer_name
; /* printer-name attribute */
1711 char uri
[1024]; /* printer-uri value */
1712 int num_options
; /* Number of options */
1713 cups_option_t
*options
; /* Options */
1715 char media_default
[41]; /* Default paper size */
1716 #endif /* __APPLE__ */
1717 char optname
[1024], /* Option name */
1718 value
[2048], /* Option value */
1719 *ptr
; /* Pointer into name/value */
1720 static const char * const pattrs
[] = /* Attributes we're interested in */
1722 "auth-info-required",
1723 "job-sheets-default",
1724 "marker-change-time",
1726 "marker-high-levels",
1728 "marker-low-levels",
1734 #endif /* __APPLE__ */
1737 "printer-is-accepting-jobs",
1738 "printer-is-shared",
1740 "printer-make-and-model",
1743 "printer-state-change-time",
1744 "printer-state-reasons",
1752 * Get the default paper size...
1755 appleGetPaperSize(media_default
, sizeof(media_default
));
1756 #endif /* __APPLE__ */
1759 * Build a CUPS_GET_PRINTERS or IPP_GET_PRINTER_ATTRIBUTES request, which
1760 * require the following attributes:
1762 * attributes-charset
1763 * attributes-natural-language
1764 * requesting-user-name
1765 * printer-uri [for IPP_GET_PRINTER_ATTRIBUTES]
1768 request
= ippNewRequest(op
);
1770 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1771 "requested-attributes", sizeof(pattrs
) / sizeof(pattrs
[0]),
1774 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
1775 "requesting-user-name", NULL
, cupsUser());
1779 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
1780 "localhost", ippPort(), "/printers/%s", name
);
1781 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
,
1786 * Do the request and get back a response...
1789 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
1791 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
1794 * Skip leading attributes until we hit a printer...
1797 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
1804 * Pull the needed attributes from this printer...
1807 printer_name
= NULL
;
1811 for (; attr
&& attr
->group_tag
== IPP_TAG_PRINTER
; attr
= attr
->next
)
1813 if (attr
->value_tag
!= IPP_TAG_INTEGER
&&
1814 attr
->value_tag
!= IPP_TAG_ENUM
&&
1815 attr
->value_tag
!= IPP_TAG_BOOLEAN
&&
1816 attr
->value_tag
!= IPP_TAG_TEXT
&&
1817 attr
->value_tag
!= IPP_TAG_TEXTLANG
&&
1818 attr
->value_tag
!= IPP_TAG_NAME
&&
1819 attr
->value_tag
!= IPP_TAG_NAMELANG
&&
1820 attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1821 attr
->value_tag
!= IPP_TAG_RANGE
)
1824 if (!strcmp(attr
->name
, "auth-info-required") ||
1825 !strcmp(attr
->name
, "marker-change-time") ||
1826 !strcmp(attr
->name
, "marker-colors") ||
1827 !strcmp(attr
->name
, "marker-high-levels") ||
1828 !strcmp(attr
->name
, "marker-levels") ||
1829 !strcmp(attr
->name
, "marker-low-levels") ||
1830 !strcmp(attr
->name
, "marker-message") ||
1831 !strcmp(attr
->name
, "marker-names") ||
1832 !strcmp(attr
->name
, "marker-types") ||
1833 !strcmp(attr
->name
, "printer-commands") ||
1834 !strcmp(attr
->name
, "printer-info") ||
1835 !strcmp(attr
->name
, "printer-is-shared") ||
1836 !strcmp(attr
->name
, "printer-make-and-model") ||
1837 !strcmp(attr
->name
, "printer-state") ||
1838 !strcmp(attr
->name
, "printer-state-change-time") ||
1839 !strcmp(attr
->name
, "printer-type") ||
1840 !strcmp(attr
->name
, "printer-is-accepting-jobs") ||
1841 !strcmp(attr
->name
, "printer-location") ||
1842 !strcmp(attr
->name
, "printer-state-reasons"))
1845 * Add a printer description attribute...
1848 num_options
= cupsAddOption(attr
->name
,
1849 cups_make_string(attr
, value
,
1851 num_options
, &options
);
1853 else if (!strcmp(attr
->name
, "media-supported"))
1856 * See if we can set a default media size...
1859 for (i
= 0; i
< attr
->num_values
; i
++)
1860 if (!strcasecmp(media_default
, attr
->values
[i
].string
.text
))
1862 num_options
= cupsAddOption("media", media_default
, num_options
,
1867 else if (!strcmp(attr
->name
, "printer-name") &&
1868 attr
->value_tag
== IPP_TAG_NAME
)
1869 printer_name
= attr
->values
[0].string
.text
;
1870 else if (strncmp(attr
->name
, "notify-", 7) &&
1871 (attr
->value_tag
== IPP_TAG_BOOLEAN
||
1872 attr
->value_tag
== IPP_TAG_ENUM
||
1873 attr
->value_tag
== IPP_TAG_INTEGER
||
1874 attr
->value_tag
== IPP_TAG_KEYWORD
||
1875 attr
->value_tag
== IPP_TAG_NAME
||
1876 attr
->value_tag
== IPP_TAG_RANGE
) &&
1877 (ptr
= strstr(attr
->name
, "-default")) != NULL
)
1880 * Add a default option...
1883 strlcpy(optname
, attr
->name
, sizeof(optname
));
1884 optname
[ptr
- attr
->name
] = '\0';
1886 if (strcasecmp(optname
, "media") ||
1887 !cupsGetOption("media", num_options
, options
))
1888 num_options
= cupsAddOption(optname
,
1889 cups_make_string(attr
, value
,
1891 num_options
, &options
);
1896 * See if we have everything needed...
1901 cupsFreeOptions(num_options
, options
);
1909 if ((dest
= cups_add_dest(printer_name
, NULL
, &num_dests
, dests
)) != NULL
)
1911 dest
->num_options
= num_options
;
1912 dest
->options
= options
;
1915 cupsFreeOptions(num_options
, options
);
1921 ippDelete(response
);
1925 * Return the count...
1933 * 'cups_make_string()' - Make a comma-separated string of values from an IPP
1937 static char * /* O - New string */
1939 ipp_attribute_t
*attr
, /* I - Attribute to convert */
1940 char *buffer
, /* I - Buffer */
1941 size_t bufsize
) /* I - Size of buffer */
1943 int i
; /* Looping var */
1944 char *ptr
, /* Pointer into buffer */
1945 *end
, /* Pointer to end of buffer */
1946 *valptr
; /* Pointer into string attribute */
1950 * Return quickly if we have a single string value...
1953 if (attr
->num_values
== 1 &&
1954 attr
->value_tag
!= IPP_TAG_INTEGER
&&
1955 attr
->value_tag
!= IPP_TAG_ENUM
&&
1956 attr
->value_tag
!= IPP_TAG_BOOLEAN
&&
1957 attr
->value_tag
!= IPP_TAG_RANGE
)
1958 return (attr
->values
[0].string
.text
);
1961 * Copy the values to the string, separating with commas and escaping strings
1965 end
= buffer
+ bufsize
- 1;
1967 for (i
= 0, ptr
= buffer
; i
< attr
->num_values
&& ptr
< end
; i
++)
1972 switch (attr
->value_tag
)
1974 case IPP_TAG_INTEGER
:
1976 snprintf(ptr
, end
- ptr
+ 1, "%d", attr
->values
[i
].integer
);
1979 case IPP_TAG_BOOLEAN
:
1980 if (attr
->values
[i
].boolean
)
1981 strlcpy(ptr
, "true", end
- ptr
+ 1);
1983 strlcpy(ptr
, "false", end
- ptr
+ 1);
1986 case IPP_TAG_RANGE
:
1987 if (attr
->values
[i
].range
.lower
== attr
->values
[i
].range
.upper
)
1988 snprintf(ptr
, end
- ptr
+ 1, "%d", attr
->values
[i
].range
.lower
);
1990 snprintf(ptr
, end
- ptr
+ 1, "%d-%d", attr
->values
[i
].range
.lower
,
1991 attr
->values
[i
].range
.upper
);
1995 for (valptr
= attr
->values
[i
].string
.text
;
1996 *valptr
&& ptr
< end
;)
1998 if (strchr(" \t\n\\\'\"", *valptr
))
2000 if (ptr
>= (end
- 1))
2023 * End of "$Id: dest.c 7946 2008-09-16 23:27:54Z mike $".