]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/dest.c
2 * "$Id: dest.c 6943 2007-09-10 23:00:33Z mike $"
4 * User-defined destination (and option) support for the Common UNIX
5 * Printing System (CUPS).
7 * Copyright 2007 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
23 * cupsGetDest() - Get the named destination from the list.
24 * cupsGetDests() - Get the list of destinations from the default
26 * cupsGetDests2() - Get the list of destinations from the
28 * cupsRemoveDest() - Remove a destination from the destination list.
29 * cupsDestSetDefaultDest() - Set the default destination.
30 * cupsSetDests() - Set the list of destinations for the default
32 * cupsSetDests2() - Set the list of destinations for the specified
34 * cups_get_dests() - Get destinations from a file.
35 * cups_get_sdests() - Get destinations from a server.
39 * Include necessary headers...
49 #endif /* HAVE_NOTIFY_H */
56 static int cups_get_dests(const char *filename
, int num_dests
,
58 static int cups_get_sdests(http_t
*http
, ipp_op_t op
, int num_dests
,
63 * 'cupsAddDest()' - Add a destination to the list of destinations.
65 * This function cannot be used to add a new class or printer queue,
66 * it only adds a new container of saved options for the named
67 * destination or instance.
69 * If the named destination already exists, the destination list is
70 * returned unchanged. Adding a new instance of a destination creates
71 * a copy of that destination's options.
73 * Use the cupsSaveDests() function to save the updated list of
74 * destinations to the user's lpoptions file.
77 int /* O - New number of destinations */
78 cupsAddDest(const char *name
, /* I - Destination name */
79 const char *instance
, /* I - Instance name or NULL for none/primary */
80 int num_dests
, /* I - Number of destinations */
81 cups_dest_t
**dests
) /* IO - Destinations */
83 int i
; /* Looping var */
84 cups_dest_t
*dest
; /* Destination pointer */
85 cups_dest_t
*parent
; /* Parent destination */
86 cups_option_t
*option
; /* Current option */
92 if ((dest
= cupsGetDest(name
, instance
, num_dests
, *dests
)) != NULL
)
96 * Add new destination...
100 dest
= malloc(sizeof(cups_dest_t
));
102 dest
= realloc(*dests
, sizeof(cups_dest_t
) * (num_dests
+ 1));
110 * Find where to insert the destination...
113 for (i
= num_dests
; i
> 0; i
--, dest
++)
114 if (strcasecmp(name
, dest
->name
) < 0)
116 else if (!instance
&& dest
->instance
)
118 else if (!strcasecmp(name
, dest
->name
) &&
119 instance
&& dest
->instance
&&
120 strcasecmp(instance
, dest
->instance
) < 0)
124 memmove(dest
+ 1, dest
, i
* sizeof(cups_dest_t
));
127 * Initialize the destination...
130 dest
->name
= _cupsStrAlloc(name
);
131 dest
->is_default
= 0;
132 dest
->num_options
= 0;
133 dest
->options
= (cups_option_t
*)0;
136 dest
->instance
= NULL
;
140 * Copy options from the primary instance...
143 dest
->instance
= _cupsStrAlloc(instance
);
145 if ((parent
= cupsGetDest(name
, NULL
, num_dests
+ 1, *dests
)) != NULL
)
147 for (i
= parent
->num_options
, option
= parent
->options
;
150 dest
->num_options
= cupsAddOption(option
->name
, option
->value
,
156 return (num_dests
+ 1);
161 * 'cupsFreeDests()' - Free the memory used by the list of destinations.
165 cupsFreeDests(int num_dests
, /* I - Number of destinations */
166 cups_dest_t
*dests
) /* I - Destinations */
168 int i
; /* Looping var */
169 cups_dest_t
*dest
; /* Current destination */
172 if (num_dests
== 0 || dests
== NULL
)
175 for (i
= num_dests
, dest
= dests
; i
> 0; i
--, dest
++)
177 _cupsStrFree(dest
->name
);
178 _cupsStrFree(dest
->instance
);
180 cupsFreeOptions(dest
->num_options
, dest
->options
);
188 * 'cupsGetDest()' - Get the named destination from the list.
190 * Use the cupsGetDests() or cupsGetDests2() functions to get a
191 * list of supported destinations for the current user.
194 cups_dest_t
* /* O - Destination pointer or NULL */
195 cupsGetDest(const char *name
, /* I - Destination name or NULL for the default destination */
196 const char *instance
, /* I - Instance name or NULL */
197 int num_dests
, /* I - Number of destinations */
198 cups_dest_t
*dests
) /* I - Destinations */
200 int comp
; /* Result of comparison */
203 if (num_dests
<= 0 || !dests
)
209 * NULL name for default printer.
212 while (num_dests
> 0)
214 if (dests
->is_default
)
224 * Lookup name and optionally the instance...
227 while (num_dests
> 0)
229 if ((comp
= strcasecmp(name
, dests
->name
)) < 0)
233 if ((!instance
&& !dests
->instance
) ||
234 (instance
!= NULL
&& dests
->instance
!= NULL
&&
235 !strcasecmp(instance
, dests
->instance
)))
249 * 'cupsGetDests()' - Get the list of destinations from the default server.
251 * Starting with CUPS 1.2, the returned list of destinations include the
252 * printer-info, printer-is-accepting-jobs, printer-is-shared,
253 * printer-make-and-model, printer-state, printer-state-change-time,
254 * printer-state-reasons, and printer-type attributes as options.
256 * Use the cupsFreeDests() function to free the destination list and
257 * the cupsGetDest() function to find a particular destination.
260 int /* O - Number of destinations */
261 cupsGetDests(cups_dest_t
**dests
) /* O - Destinations */
263 int num_dests
; /* Number of destinations */
264 http_t
*http
; /* HTTP connection */
268 * Connect to the CUPS server and get the destination list and options...
271 http
= httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption());
273 num_dests
= cupsGetDests2(http
, dests
);
283 * 'cupsGetDests2()' - Get the list of destinations from the specified server.
285 * Starting with CUPS 1.2, the returned list of destinations include the
286 * printer-info, printer-is-accepting-jobs, printer-is-shared,
287 * printer-make-and-model, printer-state, printer-state-change-time,
288 * printer-state-reasons, and printer-type attributes as options.
290 * Use the cupsFreeDests() function to free the destination list and
291 * the cupsGetDest() function to find a particular destination.
293 * @since CUPS 1.1.21@
296 int /* O - Number of destinations */
297 cupsGetDests2(http_t
*http
, /* I - HTTP connection */
298 cups_dest_t
**dests
) /* O - Destinations */
300 int i
; /* Looping var */
301 int num_dests
; /* Number of destinations */
302 cups_dest_t
*dest
; /* Destination pointer */
303 const char *home
; /* HOME environment variable */
304 char filename
[1024]; /* Local ~/.cups/lpoptions file */
305 const char *defprinter
; /* Default printer */
306 char name
[1024], /* Copy of printer name */
307 *instance
; /* Pointer to instance name */
308 int num_reals
; /* Number of real queues */
309 cups_dest_t
*reals
; /* Real queues */
310 _cups_globals_t
*cg
= _cupsGlobals(); /* Global data */
314 * Range check the input...
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
, num_dests
, dests
);
332 num_dests
= cups_get_sdests(http
, CUPS_GET_CLASSES
, num_dests
, dests
);
335 * Make a copy of the "real" queues for a later sanity check...
340 num_reals
= num_dests
;
341 reals
= calloc(num_reals
, sizeof(cups_dest_t
));
344 memcpy(reals
, *dests
, num_reals
* sizeof(cups_dest_t
));
355 * Grab the default destination...
358 if ((defprinter
= cupsGetDefault2(http
)) != NULL
)
361 * Grab printer and instance name...
364 strlcpy(name
, defprinter
, sizeof(name
));
366 if ((instance
= strchr(name
, '/')) != NULL
)
370 * Lookup the printer and instance and make it the default...
373 if ((dest
= cupsGetDest(name
, instance
, num_dests
, *dests
)) != NULL
)
374 dest
->is_default
= 1;
379 * This initialization of "instance" is unnecessary, but avoids a
380 * compiler warning...
387 * Load the /etc/cups/lpoptions and ~/.cups/lpoptions files...
390 snprintf(filename
, sizeof(filename
), "%s/lpoptions", cg
->cups_serverroot
);
391 num_dests
= cups_get_dests(filename
, num_dests
, dests
);
393 if ((home
= getenv("HOME")) != NULL
)
395 snprintf(filename
, sizeof(filename
), "%s/.cups/lpoptions", home
);
396 if (access(filename
, 0))
397 snprintf(filename
, sizeof(filename
), "%s/.lpoptions", home
);
399 num_dests
= cups_get_dests(filename
, num_dests
, dests
);
403 * Validate the current default destination - this prevents old
404 * Default lines in /etc/cups/lpoptions and ~/.cups/lpoptions from
405 * pointing to a non-existent printer or class...
411 * See if we have a default printer...
414 if ((dest
= cupsGetDest(NULL
, NULL
, num_dests
, *dests
)) != NULL
)
417 * Have a default; see if it is real...
420 dest
= cupsGetDest(dest
->name
, NULL
, num_reals
, reals
);
424 * If dest is NULL, then no default (that exists) is set, so we
425 * need to set a default if one exists...
428 if (dest
== NULL
&& defprinter
!= NULL
)
430 for (i
= 0; i
< num_dests
; i
++)
431 (*dests
)[i
].is_default
= 0;
433 if ((dest
= cupsGetDest(name
, instance
, num_dests
, *dests
)) != NULL
)
434 dest
->is_default
= 1;
445 * Return the number of destinations...
453 * 'cupsRemoveDest()' - Remove a destination from the destination list.
455 * Removing a destination/instance does not delete the class or printer
456 * queue, merely the lpoptions for that destination/instance. Use the
457 * cupsSetDests() or cupsSetDests2() functions to save the new options
463 int /* O - New number of destinations */
464 cupsRemoveDest(const char *name
, /* I - Destination name */
465 const char *instance
, /* I - Instance name or NULL */
466 int num_dests
, /* I - Number of destinations */
467 cups_dest_t
**dests
) /* IO - Destinations */
469 int i
; /* Index into destinations */
470 cups_dest_t
*dest
; /* Pointer to destination */
474 * Find the destination...
477 if ((dest
= cupsGetDest(name
, instance
, num_dests
, *dests
)) == NULL
)
484 _cupsStrFree(dest
->name
);
485 _cupsStrFree(dest
->instance
);
486 cupsFreeOptions(dest
->num_options
, dest
->options
);
489 * Remove the destination from the array...
497 memmove(dest
, dest
+ 1, (num_dests
- i
) * sizeof(cups_dest_t
));
504 * 'cupsDestSetDefaultDest()' - Set the default destination.
511 const char *name
, /* I - Destination name */
512 const char *instance
, /* I - Instance name or NULL */
513 int num_dests
, /* I - Number of destinations */
514 cups_dest_t
*dests
) /* I - Destinations */
516 int i
; /* Looping var */
517 cups_dest_t
*dest
; /* Current destination */
521 * Range check input...
524 if (!name
|| num_dests
<= 0 || !dests
)
528 * Loop through the array and set the "is_default" flag for the matching
532 for (i
= num_dests
, dest
= dests
; i
> 0; i
--, dest
++)
533 dest
->is_default
= !strcasecmp(name
, dest
->name
) &&
534 ((!instance
&& !dest
->instance
) ||
535 (instance
&& dest
->instance
&&
536 !strcasecmp(instance
, dest
->instance
)));
541 * 'cupsSetDests()' - Save the list of destinations for the default server.
543 * This function saves the destinations to /etc/cups/lpoptions when run
544 * as root and ~/.cups/lpoptions when run as a normal user.
548 cupsSetDests(int num_dests
, /* I - Number of destinations */
549 cups_dest_t
*dests
) /* I - Destinations */
551 http_t
*http
; /* HTTP connection */
555 * Connect to the CUPS server and save the destination list and options...
558 http
= httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption());
560 cupsSetDests2(http
, num_dests
, dests
);
568 * 'cupsSetDests2()' - Save the list of destinations for the specified server.
570 * This function saves the destinations to /etc/cups/lpoptions when run
571 * as root and ~/.cups/lpoptions when run as a normal user.
573 * @since CUPS 1.1.21@
576 int /* O - 0 on success, -1 on error */
577 cupsSetDests2(http_t
*http
, /* I - HTTP connection */
578 int num_dests
, /* I - Number of destinations */
579 cups_dest_t
*dests
) /* I - Destinations */
581 int i
, j
; /* Looping vars */
582 int wrote
; /* Wrote definition? */
583 cups_dest_t
*dest
; /* Current destination */
584 cups_option_t
*option
; /* Current option */
585 _ipp_option_t
*match
; /* Matching attribute for option */
586 FILE *fp
; /* File pointer */
588 const char *home
; /* HOME environment variable */
590 char filename
[1024]; /* lpoptions file */
591 int num_temps
; /* Number of temporary destinations */
592 cups_dest_t
*temps
, /* Temporary destinations */
593 *temp
; /* Current temporary dest */
594 const char *val
; /* Value of temporary option */
595 _cups_globals_t
*cg
= _cupsGlobals(); /* Global data */
599 * Range check the input...
602 if (!http
|| !num_dests
|| !dests
)
606 * Get the server destinations...
609 num_temps
= cups_get_sdests(http
, CUPS_GET_PRINTERS
, 0, &temps
);
610 num_temps
= cups_get_sdests(http
, CUPS_GET_CLASSES
, num_temps
, &temps
);
613 * Figure out which file to write to...
616 snprintf(filename
, sizeof(filename
), "%s/lpoptions", cg
->cups_serverroot
);
622 * Merge in server defaults...
625 num_temps
= cups_get_dests(filename
, num_temps
, &temps
);
628 * Point to user defaults...
631 if ((home
= getenv("HOME")) != NULL
)
634 * Remove the old ~/.lpoptions file...
637 snprintf(filename
, sizeof(filename
), "%s/.lpoptions", home
);
641 * Create ~/.cups subdirectory...
644 snprintf(filename
, sizeof(filename
), "%s/.cups", home
);
645 if (access(filename
, 0))
646 mkdir(filename
, 0700);
648 snprintf(filename
, sizeof(filename
), "%s/.cups/lpoptions", home
);
654 * Try to open the file...
657 if ((fp
= fopen(filename
, "w")) == NULL
)
659 cupsFreeDests(num_temps
, temps
);
665 * Set the permissions to 0644 when saving to the /etc/cups/lpoptions
670 fchmod(fileno(fp
), 0644);
674 * Write each printer; each line looks like:
676 * Dest name[/instance] options
677 * Default name[/instance] options
680 for (i
= num_dests
, dest
= dests
; i
> 0; i
--, dest
++)
681 if (dest
->instance
!= NULL
|| dest
->num_options
!= 0 || dest
->is_default
)
683 if (dest
->is_default
)
685 fprintf(fp
, "Default %s", dest
->name
);
687 fprintf(fp
, "/%s", dest
->instance
);
694 if ((temp
= cupsGetDest(dest
->name
, dest
->instance
, num_temps
, temps
)) == NULL
)
695 temp
= cupsGetDest(dest
->name
, NULL
, num_temps
, temps
);
697 for (j
= dest
->num_options
, option
= dest
->options
; j
> 0; j
--, option
++)
700 * See if this option is a printer attribute; if so, skip it...
703 if ((match
= _ippFindOption(option
->name
)) != NULL
&&
704 match
->group_tag
== IPP_TAG_PRINTER
)
708 * See if the server/global options match these; if so, don't
713 (val
= cupsGetOption(option
->name
, temp
->num_options
,
714 temp
->options
)) != NULL
&&
715 !strcasecmp(val
, option
->value
))
719 * Options don't match, write to the file...
724 fprintf(fp
, "Dest %s", dest
->name
);
726 fprintf(fp
, "/%s", dest
->instance
);
730 if (option
->value
[0])
732 if (strchr(option
->value
, ' ') ||
733 strchr(option
->value
, '\\') ||
734 strchr(option
->value
, '\"') ||
735 strchr(option
->value
, '\''))
741 fprintf(fp
, " %s=\"", option
->name
);
743 for (val
= option
->value
; *val
; val
++)
745 if (strchr("\"\'\\", *val
))
756 * Store the literal value...
759 fprintf(fp
, " %s=%s", option
->name
, option
->value
);
763 fprintf(fp
, " %s", option
->name
);
771 * Free the temporary destinations and close the file...
774 cupsFreeDests(num_temps
, temps
);
778 #ifdef HAVE_NOTIFY_POST
780 * Send a notification so that MacOS X applications can know about the
784 notify_post("com.apple.printerListChange");
785 #endif /* HAVE_NOTIFY_POST */
792 * 'cups_get_dests()' - Get destinations from a file.
795 static int /* O - Number of destinations */
796 cups_get_dests(const char *filename
, /* I - File to read from */
797 int num_dests
, /* I - Number of destinations */
798 cups_dest_t
**dests
) /* IO - Destinations */
800 int i
; /* Looping var */
801 cups_dest_t
*dest
; /* Current destination */
802 FILE *fp
; /* File pointer */
803 char line
[8192], /* Line from file */
804 *lineptr
, /* Pointer into line */
805 *name
, /* Name of destination/option */
806 *instance
; /* Instance of destination */
807 const char *printer
; /* PRINTER or LPDEST */
811 * Check environment variables...
814 if ((printer
= getenv("LPDEST")) == NULL
)
815 if ((printer
= getenv("PRINTER")) != NULL
)
816 if (strcmp(printer
, "lp") == 0)
820 * Try to open the file...
823 if ((fp
= fopen(filename
, "r")) == NULL
)
827 * Read each printer; each line looks like:
829 * Dest name[/instance] options
830 * Default name[/instance] options
833 while (fgets(line
, sizeof(line
), fp
) != NULL
)
836 * See what type of line it is...
839 if (strncasecmp(line
, "dest", 4) == 0 && isspace(line
[4] & 255))
841 else if (strncasecmp(line
, "default", 7) == 0 && isspace(line
[7] & 255))
847 * Skip leading whitespace...
850 while (isspace(*lineptr
& 255))
859 * Search for an instance...
862 while (!isspace(*lineptr
& 255) && *lineptr
&& *lineptr
!= '/')
871 * Found an instance...
878 * Search for an instance...
881 while (!isspace(*lineptr
& 255) && *lineptr
)
890 * See if the primary instance of the destination exists; if not,
891 * ignore this entry and move on...
894 if (cupsGetDest(name
, NULL
, num_dests
, *dests
) == NULL
)
898 * Add the destination...
901 num_dests
= cupsAddDest(name
, instance
, num_dests
, dests
);
903 if ((dest
= cupsGetDest(name
, instance
, num_dests
, *dests
)) == NULL
)
914 * Add options until we hit the end of the line...
917 dest
->num_options
= cupsParseOptions(lineptr
, dest
->num_options
,
921 * Set this as default if needed...
924 if (strncasecmp(line
, "default", 7) == 0 && printer
== NULL
)
926 for (i
= 0; i
< num_dests
; i
++)
927 (*dests
)[i
].is_default
= 0;
929 dest
->is_default
= 1;
934 * Close the file and return...
944 * 'cups_get_sdests()' - Get destinations from a server.
947 static int /* O - Number of destinations */
948 cups_get_sdests(http_t
*http
, /* I - HTTP connection */
949 ipp_op_t op
, /* I - get-printers or get-classes */
950 int num_dests
, /* I - Number of destinations */
951 cups_dest_t
**dests
) /* IO - Destinations */
953 int i
; /* Looping var */
954 cups_dest_t
*dest
; /* Current destination */
955 ipp_t
*request
, /* IPP Request */
956 *response
; /* IPP Response */
957 ipp_attribute_t
*attr
; /* Current attribute */
958 int accepting
, /* printer-is-accepting-jobs attribute */
959 shared
, /* printer-is-shared attribute */
960 state
, /* printer-state attribute */
961 change_time
, /* printer-state-change-time attribute */
962 type
; /* printer-type attribute */
963 const char *info
, /* printer-info attribute */
964 *location
, /* printer-location attribute */
965 *make_model
, /* printer-make-and-model attribute */
966 *name
; /* printer-name attribute */
967 char job_sheets
[1024], /* job-sheets-default attribute */
968 auth_info_req
[1024], /* auth-info-required attribute */
969 reasons
[1024]; /* printer-state-reasons attribute */
970 int num_options
; /* Number of options */
971 cups_option_t
*options
; /* Options */
972 char optname
[1024], /* Option name */
973 value
[2048], /* Option value */
974 *ptr
; /* Pointer into name/value */
975 static const char * const pattrs
[] = /* Attributes we're interested in */
977 "auth-info-required",
978 "job-sheets-default",
980 "printer-is-accepting-jobs",
983 "printer-make-and-model",
986 "printer-state-change-time",
987 "printer-state-reasons",
994 * Build a CUPS_GET_PRINTERS or CUPS_GET_CLASSES request, which require
995 * the following attributes:
998 * attributes-natural-language
999 * requesting-user-name
1002 request
= ippNewRequest(op
);
1004 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1005 "requested-attributes", sizeof(pattrs
) / sizeof(pattrs
[0]),
1008 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
1009 "requesting-user-name", NULL
, cupsUser());
1012 * Do the request and get back a response...
1015 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
1017 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
1020 * Skip leading attributes until we hit a printer...
1023 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
1030 * Pull the needed attributes from this printer...
1042 state
= IPP_PRINTER_IDLE
;
1043 type
= CUPS_PRINTER_LOCAL
;
1045 auth_info_req
[0] = '\0';
1046 job_sheets
[0] = '\0';
1049 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
1051 if (!strcmp(attr
->name
, "auth-info-required") &&
1052 attr
->value_tag
== IPP_TAG_KEYWORD
)
1054 strlcpy(auth_info_req
, attr
->values
[0].string
.text
,
1055 sizeof(auth_info_req
));
1057 for (i
= 1, ptr
= auth_info_req
+ strlen(auth_info_req
);
1058 i
< attr
->num_values
;
1061 snprintf(ptr
, sizeof(auth_info_req
) - (ptr
- auth_info_req
), ",%s",
1062 attr
->values
[i
].string
.text
);
1066 else if (!strcmp(attr
->name
, "job-sheets-default") &&
1067 (attr
->value_tag
== IPP_TAG_KEYWORD
||
1068 attr
->value_tag
== IPP_TAG_NAME
))
1070 if (attr
->num_values
== 2)
1071 snprintf(job_sheets
, sizeof(job_sheets
), "%s,%s",
1072 attr
->values
[0].string
.text
, attr
->values
[1].string
.text
);
1074 strlcpy(job_sheets
, attr
->values
[0].string
.text
,
1075 sizeof(job_sheets
));
1077 else if (!strcmp(attr
->name
, "printer-info") &&
1078 attr
->value_tag
== IPP_TAG_TEXT
)
1079 info
= attr
->values
[0].string
.text
;
1080 else if (!strcmp(attr
->name
, "printer-is-accepting-jobs") &&
1081 attr
->value_tag
== IPP_TAG_BOOLEAN
)
1082 accepting
= attr
->values
[0].boolean
;
1083 else if (!strcmp(attr
->name
, "printer-is-shared") &&
1084 attr
->value_tag
== IPP_TAG_BOOLEAN
)
1085 shared
= attr
->values
[0].boolean
;
1086 else if (!strcmp(attr
->name
, "printer-location") &&
1087 attr
->value_tag
== IPP_TAG_TEXT
)
1088 location
= attr
->values
[0].string
.text
;
1089 else if (!strcmp(attr
->name
, "printer-make-and-model") &&
1090 attr
->value_tag
== IPP_TAG_TEXT
)
1091 make_model
= attr
->values
[0].string
.text
;
1092 else if (!strcmp(attr
->name
, "printer-name") &&
1093 attr
->value_tag
== IPP_TAG_NAME
)
1094 name
= attr
->values
[0].string
.text
;
1095 else if (!strcmp(attr
->name
, "printer-state") &&
1096 attr
->value_tag
== IPP_TAG_ENUM
)
1097 state
= attr
->values
[0].integer
;
1098 else if (!strcmp(attr
->name
, "printer-state-change-time") &&
1099 attr
->value_tag
== IPP_TAG_INTEGER
)
1100 change_time
= attr
->values
[0].integer
;
1101 else if (!strcmp(attr
->name
, "printer-state-reasons") &&
1102 attr
->value_tag
== IPP_TAG_KEYWORD
)
1104 strlcpy(reasons
, attr
->values
[0].string
.text
, sizeof(reasons
));
1105 for (i
= 1, ptr
= reasons
+ strlen(reasons
);
1106 i
< attr
->num_values
;
1109 snprintf(ptr
, sizeof(reasons
) - (ptr
- reasons
), ",%s",
1110 attr
->values
[i
].string
.text
);
1114 else if (!strcmp(attr
->name
, "printer-type") &&
1115 attr
->value_tag
== IPP_TAG_ENUM
)
1116 type
= attr
->values
[0].integer
;
1117 else if (strncmp(attr
->name
, "notify-", 7) &&
1118 (attr
->value_tag
== IPP_TAG_BOOLEAN
||
1119 attr
->value_tag
== IPP_TAG_ENUM
||
1120 attr
->value_tag
== IPP_TAG_INTEGER
||
1121 attr
->value_tag
== IPP_TAG_KEYWORD
||
1122 attr
->value_tag
== IPP_TAG_NAME
||
1123 attr
->value_tag
== IPP_TAG_RANGE
) &&
1124 strstr(attr
->name
, "-default"))
1126 char *valptr
; /* Pointer into attribute value */
1130 * Add a default option...
1133 strlcpy(optname
, attr
->name
, sizeof(optname
));
1134 if ((ptr
= strstr(optname
, "-default")) != NULL
)
1138 for (i
= 0, ptr
= value
; i
< attr
->num_values
; i
++)
1140 if (ptr
>= (value
+ sizeof(value
) - 1))
1146 switch (attr
->value_tag
)
1148 case IPP_TAG_INTEGER
:
1150 snprintf(ptr
, sizeof(value
) - (ptr
- value
), "%d",
1151 attr
->values
[i
].integer
);
1154 case IPP_TAG_BOOLEAN
:
1155 if (attr
->values
[i
].boolean
)
1156 strlcpy(ptr
, "true", sizeof(value
) - (ptr
- value
));
1158 strlcpy(ptr
, "false", sizeof(value
) - (ptr
- value
));
1161 case IPP_TAG_RANGE
:
1162 if (attr
->values
[i
].range
.lower
==
1163 attr
->values
[i
].range
.upper
)
1164 snprintf(ptr
, sizeof(value
) - (ptr
- value
), "%d",
1165 attr
->values
[i
].range
.lower
);
1167 snprintf(ptr
, sizeof(value
) - (ptr
- value
), "%d-%d",
1168 attr
->values
[i
].range
.lower
,
1169 attr
->values
[i
].range
.upper
);
1173 for (valptr
= attr
->values
[i
].string
.text
;
1174 *valptr
&& ptr
< (value
+ sizeof(value
) - 2);)
1176 if (strchr(" \t\n\\\'\"", *valptr
))
1189 num_options
= cupsAddOption(optname
, value
, num_options
, &options
);
1196 * See if we have everything needed...
1201 cupsFreeOptions(num_options
, options
);
1209 num_dests
= cupsAddDest(name
, NULL
, num_dests
, dests
);
1211 if ((dest
= cupsGetDest(name
, NULL
, num_dests
, *dests
)) != NULL
)
1213 dest
->num_options
= num_options
;
1214 dest
->options
= options
;
1219 if (auth_info_req
[0])
1220 dest
->num_options
= cupsAddOption("auth-info-required", auth_info_req
,
1225 dest
->num_options
= cupsAddOption("job-sheets", job_sheets
,
1230 dest
->num_options
= cupsAddOption("printer-info", info
,
1234 sprintf(value
, "%d", accepting
);
1235 dest
->num_options
= cupsAddOption("printer-is-accepting-jobs", value
,
1239 sprintf(value
, "%d", shared
);
1240 dest
->num_options
= cupsAddOption("printer-is-shared", value
,
1245 dest
->num_options
= cupsAddOption("printer-location",
1246 location
, dest
->num_options
,
1250 dest
->num_options
= cupsAddOption("printer-make-and-model",
1251 make_model
, dest
->num_options
,
1254 sprintf(value
, "%d", state
);
1255 dest
->num_options
= cupsAddOption("printer-state", value
,
1261 sprintf(value
, "%d", change_time
);
1262 dest
->num_options
= cupsAddOption("printer-state-change-time", value
,
1268 dest
->num_options
= cupsAddOption("printer-state-reasons", reasons
,
1272 sprintf(value
, "%d", type
);
1273 dest
->num_options
= cupsAddOption("printer-type", value
,
1278 cupsFreeOptions(num_options
, options
);
1284 ippDelete(response
);
1288 * Return the count...
1296 * End of "$Id: dest.c 6943 2007-09-10 23:00:33Z mike $".