2 * "$Id: util.c 7850 2008-08-20 00:07:25Z mike $"
4 * Printing utilities for CUPS.
6 * Copyright 2007-2012 by Apple Inc.
7 * Copyright 1997-2006 by Easy Software Products.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
15 * This file is subject to the Apple OS-Developed Software exception.
19 * cupsCancelJob() - Cancel a print job on the default server.
20 * cupsCancelJob2() - Cancel or purge a print job.
21 * cupsCreateJob() - Create an empty job for streaming.
22 * cupsFinishDocument() - Finish sending a document.
23 * cupsFreeJobs() - Free memory used by job data.
24 * cupsGetClasses() - Get a list of printer classes from the default
26 * cupsGetDefault() - Get the default printer or class for the default
28 * cupsGetDefault2() - Get the default printer or class for the specified
30 * cupsGetJobs() - Get the jobs from the default server.
31 * cupsGetJobs2() - Get the jobs from the specified server.
32 * cupsGetPPD() - Get the PPD file for a printer on the default
34 * cupsGetPPD2() - Get the PPD file for a printer from the specified
36 * cupsGetPPD3() - Get the PPD file for a printer on the specified
37 * server if it has changed.
38 * cupsGetPrinters() - Get a list of printers from the default server.
39 * cupsGetServerPPD() - Get an available PPD file from the server.
40 * cupsPrintFile() - Print a file to a printer or class on the default
42 * cupsPrintFile2() - Print a file to a printer or class on the
44 * cupsPrintFiles() - Print one or more files to a printer or class on
46 * cupsPrintFiles2() - Print one or more files to a printer or class on
47 * the specified server.
48 * cupsStartDocument() - Add a document to a job created with
50 * cups_get_printer_uri() - Get the printer-uri-supported attribute for the
51 * first printer in a class.
55 * Include necessary headers...
58 #include "cups-private.h"
61 #if defined(WIN32) || defined(__EMX__)
65 #endif /* WIN32 || __EMX__ */
72 static int cups_get_printer_uri(http_t
*http
, const char *name
,
73 char *host
, int hostsize
, int *port
,
74 char *resource
, int resourcesize
,
79 * 'cupsCancelJob()' - Cancel a print job on the default server.
81 * Pass @code CUPS_JOBID_ALL@ to cancel all jobs or @code CUPS_JOBID_CURRENT@
82 * to cancel the current job on the named destination.
84 * Use the @link cupsLastError@ and @link cupsLastErrorString@ functions to get
85 * the cause of any failure.
88 int /* O - 1 on success, 0 on failure */
89 cupsCancelJob(const char *name
, /* I - Name of printer or class */
90 int job_id
) /* I - Job ID, @code CUPS_JOBID_CURRENT@ for the current job, or @code CUPS_JOBID_ALL@ for all jobs */
92 return (cupsCancelJob2(CUPS_HTTP_DEFAULT
, name
, job_id
, 0)
93 < IPP_REDIRECTION_OTHER_SITE
);
98 * 'cupsCancelJob2()' - Cancel or purge a print job.
100 * Canceled jobs remain in the job history while purged jobs are removed
101 * from the job history.
103 * Pass @code CUPS_JOBID_ALL@ to cancel all jobs or @code CUPS_JOBID_CURRENT@
104 * to cancel the current job on the named destination.
106 * Use the @link cupsLastError@ and @link cupsLastErrorString@ functions to get
107 * the cause of any failure.
109 * @since CUPS 1.4/OS X 10.6@
112 ipp_status_t
/* O - IPP status */
113 cupsCancelJob2(http_t
*http
, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
114 const char *name
, /* I - Name of printer or class */
115 int job_id
, /* I - Job ID, @code CUPS_JOBID_CURRENT@ for the current job, or @code CUPS_JOBID_ALL@ for all jobs */
116 int purge
) /* I - 1 to purge, 0 to cancel */
118 char uri
[HTTP_MAX_URI
]; /* Job/printer URI */
119 ipp_t
*request
; /* IPP request */
123 * Range check input...
126 if (job_id
< -1 || (!name
&& job_id
== 0))
128 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(EINVAL
), 0);
133 * Connect to the default server as needed...
137 if ((http
= _cupsConnect()) == NULL
)
138 return (IPP_SERVICE_UNAVAILABLE
);
141 * Build an IPP_CANCEL_JOB or IPP_PURGE_JOBS request, which requires the following
145 * attributes-natural-language
146 * job-uri or printer-uri + job-id
147 * requesting-user-name
148 * [purge-job] or [purge-jobs]
151 request
= ippNewRequest(job_id
< 0 ? IPP_PURGE_JOBS
: IPP_CANCEL_JOB
);
155 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
156 "localhost", ippPort(), "/printers/%s", name
);
158 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
,
160 ippAddInteger(request
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
, "job-id",
165 snprintf(uri
, sizeof(uri
), "ipp://localhost/jobs/%d", job_id
);
167 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "job-uri", NULL
, uri
);
170 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
173 if (purge
&& job_id
>= 0)
174 ippAddBoolean(request
, IPP_TAG_OPERATION
, "purge-job", 1);
175 else if (!purge
&& job_id
< 0)
176 ippAddBoolean(request
, IPP_TAG_OPERATION
, "purge-jobs", 0);
182 ippDelete(cupsDoRequest(http
, request
, "/jobs/"));
184 return (cupsLastError());
189 * 'cupsCreateJob()' - Create an empty job for streaming.
191 * Use this function when you want to stream print data using the
192 * @link cupsStartDocument@, @link cupsWriteRequestData@, and
193 * @link cupsFinishDocument@ functions. If you have one or more files to
194 * print, use the @link cupsPrintFile2@ or @link cupsPrintFiles2@ function
197 * @since CUPS 1.4/OS X 10.6@
200 int /* O - Job ID or 0 on error */
202 http_t
*http
, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
203 const char *name
, /* I - Destination name */
204 const char *title
, /* I - Title of job */
205 int num_options
, /* I - Number of options */
206 cups_option_t
*options
) /* I - Options */
208 char printer_uri
[1024], /* Printer URI */
209 resource
[1024]; /* Printer resource */
210 ipp_t
*request
, /* Create-Job request */
211 *response
; /* Create-Job response */
212 ipp_attribute_t
*attr
; /* job-id attribute */
213 int job_id
= 0; /* job-id value */
216 DEBUG_printf(("cupsCreateJob(http=%p, name=\"%s\", title=\"%s\", "
217 "num_options=%d, options=%p)",
218 http
, name
, title
, num_options
, options
));
221 * Range check input...
226 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(EINVAL
), 0);
231 * Build a Create-Job request...
234 if ((request
= ippNewRequest(IPP_CREATE_JOB
)) == NULL
)
236 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(ENOMEM
), 0);
240 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
), "ipp",
241 NULL
, "localhost", ippPort(), "/printers/%s", name
);
242 snprintf(resource
, sizeof(resource
), "/printers/%s", name
);
244 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
246 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
249 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "job-name", NULL
,
251 cupsEncodeOptions2(request
, num_options
, options
, IPP_TAG_OPERATION
);
252 cupsEncodeOptions2(request
, num_options
, options
, IPP_TAG_JOB
);
253 cupsEncodeOptions2(request
, num_options
, options
, IPP_TAG_SUBSCRIPTION
);
256 * Send the request and get the job-id...
259 response
= cupsDoRequest(http
, request
, resource
);
261 if ((attr
= ippFindAttribute(response
, "job-id", IPP_TAG_INTEGER
)) != NULL
)
262 job_id
= attr
->values
[0].integer
;
275 * 'cupsFinishDocument()' - Finish sending a document.
277 * The document must have been started using @link cupsStartDocument@.
279 * @since CUPS 1.4/OS X 10.6@
282 ipp_status_t
/* O - Status of document submission */
283 cupsFinishDocument(http_t
*http
, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
284 const char *name
) /* I - Destination name */
286 char resource
[1024]; /* Printer resource */
289 snprintf(resource
, sizeof(resource
), "/printers/%s", name
);
291 ippDelete(cupsGetResponse(http
, resource
));
293 return (cupsLastError());
298 * 'cupsFreeJobs()' - Free memory used by job data.
302 cupsFreeJobs(int num_jobs
, /* I - Number of jobs */
303 cups_job_t
*jobs
) /* I - Jobs */
305 int i
; /* Looping var */
306 cups_job_t
*job
; /* Current job */
309 if (num_jobs
<= 0 || !jobs
)
312 for (i
= num_jobs
, job
= jobs
; i
> 0; i
--, job
++)
314 _cupsStrFree(job
->dest
);
315 _cupsStrFree(job
->user
);
316 _cupsStrFree(job
->format
);
317 _cupsStrFree(job
->title
);
325 * 'cupsGetClasses()' - Get a list of printer classes from the default server.
327 * This function is deprecated - use @link cupsGetDests@ instead.
332 int /* O - Number of classes */
333 cupsGetClasses(char ***classes
) /* O - Classes */
335 int n
; /* Number of classes */
336 ipp_t
*request
, /* IPP Request */
337 *response
; /* IPP Response */
338 ipp_attribute_t
*attr
; /* Current attribute */
339 char **temp
; /* Temporary pointer */
340 http_t
*http
; /* Connection to server */
345 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(EINVAL
), 0);
352 if ((http
= _cupsConnect()) == NULL
)
356 * Build a CUPS_GET_CLASSES request, which requires the following
360 * attributes-natural-language
361 * requested-attributes
364 request
= ippNewRequest(CUPS_GET_CLASSES
);
366 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
367 "requested-attributes", NULL
, "printer-name");
370 * Do the request and get back a response...
375 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
377 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
378 if (attr
->name
!= NULL
&&
379 _cups_strcasecmp(attr
->name
, "printer-name") == 0 &&
380 attr
->value_tag
== IPP_TAG_NAME
)
383 temp
= malloc(sizeof(char *));
385 temp
= realloc(*classes
, sizeof(char *) * (n
+ 1));
405 temp
[n
] = strdup(attr
->values
[0].string
.text
);
417 * 'cupsGetDefault()' - Get the default printer or class for the default server.
419 * This function returns the default printer or class as defined by
420 * the LPDEST or PRINTER environment variables. If these environment
421 * variables are not set, the server default destination is returned.
422 * Applications should use the @link cupsGetDests@ and @link cupsGetDest@
423 * functions to get the user-defined default printer, as this function does
424 * not support the lpoptions-defined default printer.
427 const char * /* O - Default printer or @code NULL@ */
431 * Return the default printer...
434 return (cupsGetDefault2(CUPS_HTTP_DEFAULT
));
439 * 'cupsGetDefault2()' - Get the default printer or class for the specified server.
441 * This function returns the default printer or class as defined by
442 * the LPDEST or PRINTER environment variables. If these environment
443 * variables are not set, the server default destination is returned.
444 * Applications should use the @link cupsGetDests@ and @link cupsGetDest@
445 * functions to get the user-defined default printer, as this function does
446 * not support the lpoptions-defined default printer.
448 * @since CUPS 1.1.21/OS X 10.4@
451 const char * /* O - Default printer or @code NULL@ */
452 cupsGetDefault2(http_t
*http
) /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
454 ipp_t
*request
, /* IPP Request */
455 *response
; /* IPP Response */
456 ipp_attribute_t
*attr
; /* Current attribute */
457 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
461 * See if we have a user default printer set...
464 if (_cupsUserDefault(cg
->def_printer
, sizeof(cg
->def_printer
)))
465 return (cg
->def_printer
);
468 * Connect to the server as needed...
472 if ((http
= _cupsConnect()) == NULL
)
476 * Build a CUPS_GET_DEFAULT request, which requires the following
480 * attributes-natural-language
483 request
= ippNewRequest(CUPS_GET_DEFAULT
);
486 * Do the request and get back a response...
489 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
491 if ((attr
= ippFindAttribute(response
, "printer-name",
492 IPP_TAG_NAME
)) != NULL
)
494 strlcpy(cg
->def_printer
, attr
->values
[0].string
.text
,
495 sizeof(cg
->def_printer
));
497 return (cg
->def_printer
);
508 * 'cupsGetJobs()' - Get the jobs from the default server.
510 * A "whichjobs" value of @code CUPS_WHICHJOBS_ALL@ returns all jobs regardless
511 * of state, while @code CUPS_WHICHJOBS_ACTIVE@ returns jobs that are
512 * pending, processing, or held and @code CUPS_WHICHJOBS_COMPLETED@ returns
513 * jobs that are stopped, canceled, aborted, or completed.
516 int /* O - Number of jobs */
517 cupsGetJobs(cups_job_t
**jobs
, /* O - Job data */
518 const char *name
, /* I - @code NULL@ = all destinations, otherwise show jobs for named destination */
519 int myjobs
, /* I - 0 = all users, 1 = mine */
520 int whichjobs
) /* I - @code CUPS_WHICHJOBS_ALL@, @code CUPS_WHICHJOBS_ACTIVE@, or @code CUPS_WHICHJOBS_COMPLETED@ */
526 return (cupsGetJobs2(CUPS_HTTP_DEFAULT
, jobs
, name
, myjobs
, whichjobs
));
532 * 'cupsGetJobs2()' - Get the jobs from the specified server.
534 * A "whichjobs" value of @code CUPS_WHICHJOBS_ALL@ returns all jobs regardless
535 * of state, while @code CUPS_WHICHJOBS_ACTIVE@ returns jobs that are
536 * pending, processing, or held and @code CUPS_WHICHJOBS_COMPLETED@ returns
537 * jobs that are stopped, canceled, aborted, or completed.
539 * @since CUPS 1.1.21/OS X 10.4@
542 int /* O - Number of jobs */
543 cupsGetJobs2(http_t
*http
, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
544 cups_job_t
**jobs
, /* O - Job data */
545 const char *name
, /* I - @code NULL@ = all destinations, otherwise show jobs for named destination */
546 int myjobs
, /* I - 0 = all users, 1 = mine */
547 int whichjobs
) /* I - @code CUPS_WHICHJOBS_ALL@, @code CUPS_WHICHJOBS_ACTIVE@, or @code CUPS_WHICHJOBS_COMPLETED@ */
549 int n
; /* Number of jobs */
550 ipp_t
*request
, /* IPP Request */
551 *response
; /* IPP Response */
552 ipp_attribute_t
*attr
; /* Current attribute */
553 cups_job_t
*temp
; /* Temporary pointer */
555 priority
, /* job-priority */
556 size
; /* job-k-octets */
557 ipp_jstate_t state
; /* job-state */
558 time_t completed_time
, /* time-at-completed */
559 creation_time
, /* time-at-creation */
560 processing_time
; /* time-at-processing */
561 const char *dest
, /* job-printer-uri */
562 *format
, /* document-format */
563 *title
, /* job-name */
564 *user
; /* job-originating-user-name */
565 char uri
[HTTP_MAX_URI
]; /* URI for jobs */
566 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
567 static const char * const attrs
[] = /* Requested attributes */
573 "job-originating-user-name",
584 * Range check input...
589 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(EINVAL
), 0);
595 * Get the right URI...
600 if (httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
601 "localhost", 0, "/printers/%s", name
) != HTTP_URI_OK
)
603 _cupsSetError(IPP_INTERNAL_ERROR
, _("Unable to create printer-uri"), 1);
609 strlcpy(uri
, "ipp://localhost/", sizeof(uri
));
612 if ((http
= _cupsConnect()) == NULL
)
616 * Build an IPP_GET_JOBS request, which requires the following
620 * attributes-natural-language
622 * requesting-user-name
625 * requested-attributes
628 request
= ippNewRequest(IPP_GET_JOBS
);
630 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
631 "printer-uri", NULL
, uri
);
633 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
634 "requesting-user-name", NULL
, cupsUser());
637 ippAddBoolean(request
, IPP_TAG_OPERATION
, "my-jobs", 1);
639 if (whichjobs
== CUPS_WHICHJOBS_COMPLETED
)
640 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
641 "which-jobs", NULL
, "completed");
642 else if (whichjobs
== CUPS_WHICHJOBS_ALL
)
643 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
644 "which-jobs", NULL
, "all");
646 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
647 "requested-attributes", sizeof(attrs
) / sizeof(attrs
[0]),
651 * Do the request and get back a response...
657 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
659 for (attr
= response
->attrs
; attr
; attr
= attr
->next
)
662 * Skip leading attributes until we hit a job...
665 while (attr
&& attr
->group_tag
!= IPP_TAG_JOB
)
672 * Pull the needed attributes from this job...
678 state
= IPP_JOB_PENDING
;
681 format
= "application/octet-stream";
687 while (attr
&& attr
->group_tag
== IPP_TAG_JOB
)
689 if (!strcmp(attr
->name
, "job-id") &&
690 attr
->value_tag
== IPP_TAG_INTEGER
)
691 id
= attr
->values
[0].integer
;
692 else if (!strcmp(attr
->name
, "job-state") &&
693 attr
->value_tag
== IPP_TAG_ENUM
)
694 state
= (ipp_jstate_t
)attr
->values
[0].integer
;
695 else if (!strcmp(attr
->name
, "job-priority") &&
696 attr
->value_tag
== IPP_TAG_INTEGER
)
697 priority
= attr
->values
[0].integer
;
698 else if (!strcmp(attr
->name
, "job-k-octets") &&
699 attr
->value_tag
== IPP_TAG_INTEGER
)
700 size
= attr
->values
[0].integer
;
701 else if (!strcmp(attr
->name
, "time-at-completed") &&
702 attr
->value_tag
== IPP_TAG_INTEGER
)
703 completed_time
= attr
->values
[0].integer
;
704 else if (!strcmp(attr
->name
, "time-at-creation") &&
705 attr
->value_tag
== IPP_TAG_INTEGER
)
706 creation_time
= attr
->values
[0].integer
;
707 else if (!strcmp(attr
->name
, "time-at-processing") &&
708 attr
->value_tag
== IPP_TAG_INTEGER
)
709 processing_time
= attr
->values
[0].integer
;
710 else if (!strcmp(attr
->name
, "job-printer-uri") &&
711 attr
->value_tag
== IPP_TAG_URI
)
713 if ((dest
= strrchr(attr
->values
[0].string
.text
, '/')) != NULL
)
716 else if (!strcmp(attr
->name
, "job-originating-user-name") &&
717 attr
->value_tag
== IPP_TAG_NAME
)
718 user
= attr
->values
[0].string
.text
;
719 else if (!strcmp(attr
->name
, "document-format") &&
720 attr
->value_tag
== IPP_TAG_MIMETYPE
)
721 format
= attr
->values
[0].string
.text
;
722 else if (!strcmp(attr
->name
, "job-name") &&
723 (attr
->value_tag
== IPP_TAG_TEXT
||
724 attr
->value_tag
== IPP_TAG_NAME
))
725 title
= attr
->values
[0].string
.text
;
731 * See if we have everything needed...
743 * Allocate memory for the job...
747 temp
= malloc(sizeof(cups_job_t
));
749 temp
= realloc(*jobs
, sizeof(cups_job_t
) * (n
+ 1));
757 _cupsSetError(IPP_INTERNAL_ERROR
, NULL
, 0);
759 cupsFreeJobs(n
, *jobs
);
772 * Copy the data over...
775 temp
->dest
= _cupsStrAlloc(dest
);
776 temp
->user
= _cupsStrAlloc(user
);
777 temp
->format
= _cupsStrAlloc(format
);
778 temp
->title
= _cupsStrAlloc(title
);
780 temp
->priority
= priority
;
783 temp
->completed_time
= completed_time
;
784 temp
->creation_time
= creation_time
;
785 temp
->processing_time
= processing_time
;
794 if (n
== 0 && cg
->last_error
>= IPP_BAD_REQUEST
)
802 * 'cupsGetPPD()' - Get the PPD file for a printer on the default server.
804 * For classes, @code cupsGetPPD@ returns the PPD file for the first printer
807 * The returned filename is stored in a static buffer and is overwritten with
808 * each call to @code cupsGetPPD@ or @link cupsGetPPD2@. The caller "owns" the
809 * file that is created and must @code unlink@ the returned filename.
812 const char * /* O - Filename for PPD file */
813 cupsGetPPD(const char *name
) /* I - Destination name */
815 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
816 time_t modtime
= 0; /* Modification time */
820 * Return the PPD file...
823 cg
->ppd_filename
[0] = '\0';
825 if (cupsGetPPD3(CUPS_HTTP_DEFAULT
, name
, &modtime
, cg
->ppd_filename
,
826 sizeof(cg
->ppd_filename
)) == HTTP_OK
)
827 return (cg
->ppd_filename
);
834 * 'cupsGetPPD2()' - Get the PPD file for a printer from the specified server.
836 * For classes, @code cupsGetPPD2@ returns the PPD file for the first printer
839 * The returned filename is stored in a static buffer and is overwritten with
840 * each call to @link cupsGetPPD@ or @code cupsGetPPD2@. The caller "owns" the
841 * file that is created and must @code unlink@ the returned filename.
843 * @since CUPS 1.1.21/OS X 10.4@
846 const char * /* O - Filename for PPD file */
847 cupsGetPPD2(http_t
*http
, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
848 const char *name
) /* I - Destination name */
850 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
851 time_t modtime
= 0; /* Modification time */
854 cg
->ppd_filename
[0] = '\0';
856 if (cupsGetPPD3(http
, name
, &modtime
, cg
->ppd_filename
,
857 sizeof(cg
->ppd_filename
)) == HTTP_OK
)
858 return (cg
->ppd_filename
);
865 * 'cupsGetPPD3()' - Get the PPD file for a printer on the specified
866 * server if it has changed.
868 * The "modtime" parameter contains the modification time of any
869 * locally-cached content and is updated with the time from the PPD file on
872 * The "buffer" parameter contains the local PPD filename. If it contains
873 * the empty string, a new temporary file is created, otherwise the existing
874 * file will be overwritten as needed. The caller "owns" the file that is
875 * created and must @code unlink@ the returned filename.
877 * On success, @code HTTP_OK@ is returned for a new PPD file and
878 * @code HTTP_NOT_MODIFIED@ if the existing PPD file is up-to-date. Any other
879 * status is an error.
881 * For classes, @code cupsGetPPD3@ returns the PPD file for the first printer
884 * @since CUPS 1.4/OS X 10.6@
887 http_status_t
/* O - HTTP status */
888 cupsGetPPD3(http_t
*http
, /* I - HTTP connection or @code CUPS_HTTP_DEFAULT@ */
889 const char *name
, /* I - Destination name */
890 time_t *modtime
, /* IO - Modification time */
891 char *buffer
, /* I - Filename buffer */
892 size_t bufsize
) /* I - Size of filename buffer */
894 int http_port
; /* Port number */
895 char http_hostname
[HTTP_MAX_HOST
];
896 /* Hostname associated with connection */
897 http_t
*http2
; /* Alternate HTTP connection */
898 int fd
; /* PPD file */
899 char localhost
[HTTP_MAX_URI
],/* Local hostname */
900 hostname
[HTTP_MAX_URI
], /* Hostname */
901 resource
[HTTP_MAX_URI
]; /* Resource name */
902 int port
; /* Port number */
903 http_status_t status
; /* HTTP status from server */
904 char tempfile
[1024] = ""; /* Temporary filename */
905 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
909 * Range check input...
912 DEBUG_printf(("cupsGetPPD3(http=%p, name=\"%s\", modtime=%p(%d), buffer=%p, "
913 "bufsize=%d)", http
, name
, modtime
,
914 modtime
? (int)*modtime
: 0, buffer
, (int)bufsize
));
918 _cupsSetError(IPP_INTERNAL_ERROR
, _("No printer name"), 1);
919 return (HTTP_NOT_ACCEPTABLE
);
924 _cupsSetError(IPP_INTERNAL_ERROR
, _("No modification time"), 1);
925 return (HTTP_NOT_ACCEPTABLE
);
928 if (!buffer
|| bufsize
<= 1)
930 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad filename buffer"), 1);
931 return (HTTP_NOT_ACCEPTABLE
);
936 * See if the PPD file is available locally...
939 if (!cg
->servername
[0])
942 if (!_cups_strcasecmp(cg
->servername
, "localhost"))
944 char ppdname
[1024]; /* PPD filename */
945 struct stat ppdinfo
; /* PPD file information */
948 snprintf(ppdname
, sizeof(ppdname
), "%s/ppd/%s.ppd", cg
->cups_serverroot
,
950 if (!stat(ppdname
, &ppdinfo
))
953 * OK, the file exists, use it!
960 if (symlink(ppdname
, buffer
) && errno
!= EEXIST
)
962 _cupsSetError(IPP_INTERNAL_ERROR
, NULL
, 0);
964 return (HTTP_SERVER_ERROR
);
969 int tries
; /* Number of tries */
970 const char *tmpdir
; /* TMPDIR environment variable */
971 struct timeval curtime
; /* Current time */
974 * Previously we put root temporary files in the default CUPS temporary
975 * directory under /var/spool/cups. However, since the scheduler cleans
976 * out temporary files there and runs independently of the user apps, we
977 * don't want to use it unless specifically told to by cupsd.
980 if ((tmpdir
= getenv("TMPDIR")) == NULL
)
982 tmpdir
= "/private/tmp"; /* /tmp is a symlink to /private/tmp */
985 # endif /* __APPLE__ */
988 * Make the temporary name using the specified directory...
996 * Get the current time of day...
999 gettimeofday(&curtime
, NULL
);
1002 * Format a string using the hex time values...
1005 snprintf(buffer
, bufsize
, "%s/%08lx%05lx", tmpdir
,
1006 (unsigned long)curtime
.tv_sec
,
1007 (unsigned long)curtime
.tv_usec
);
1010 * Try to make a symlink...
1013 if (!symlink(ppdname
, buffer
))
1018 while (tries
< 1000);
1022 _cupsSetError(IPP_INTERNAL_ERROR
, NULL
, 0);
1024 return (HTTP_SERVER_ERROR
);
1028 if (*modtime
>= ppdinfo
.st_mtime
)
1029 return (HTTP_NOT_MODIFIED
);
1032 *modtime
= ppdinfo
.st_mtime
;
1040 * Try finding a printer URI for this printer...
1044 if ((http
= _cupsConnect()) == NULL
)
1045 return (HTTP_SERVICE_UNAVAILABLE
);
1047 if (!cups_get_printer_uri(http
, name
, hostname
, sizeof(hostname
), &port
,
1048 resource
, sizeof(resource
), 0))
1049 return (HTTP_NOT_FOUND
);
1051 DEBUG_printf(("2cupsGetPPD3: Printer hostname=\"%s\", port=%d", hostname
,
1055 * Remap local hostname to localhost...
1058 httpGetHostname(NULL
, localhost
, sizeof(localhost
));
1060 DEBUG_printf(("2cupsGetPPD3: Local hostname=\"%s\"", localhost
));
1062 if (!_cups_strcasecmp(localhost
, hostname
))
1063 strlcpy(hostname
, "localhost", sizeof(hostname
));
1066 * Get the hostname and port number we are connected to...
1069 httpGetHostname(http
, http_hostname
, sizeof(http_hostname
));
1070 http_port
= httpAddrPort(http
->hostaddr
);
1072 DEBUG_printf(("2cupsGetPPD3: Connection hostname=\"%s\", port=%d",
1073 http_hostname
, http_port
));
1076 * Reconnect to the correct server as needed...
1079 if (!_cups_strcasecmp(http_hostname
, hostname
) && port
== http_port
)
1081 else if ((http2
= httpConnectEncrypt(hostname
, port
,
1082 cupsEncryption())) == NULL
)
1084 DEBUG_puts("1cupsGetPPD3: Unable to connect to server");
1086 return (HTTP_SERVICE_UNAVAILABLE
);
1090 * Get a temp file...
1094 fd
= open(buffer
, O_CREAT
| O_TRUNC
| O_WRONLY
, 0600);
1096 fd
= cupsTempFd(tempfile
, sizeof(tempfile
));
1101 * Can't open file; close the server connection and return NULL...
1104 _cupsSetError(IPP_INTERNAL_ERROR
, NULL
, 0);
1109 return (HTTP_SERVER_ERROR
);
1113 * And send a request to the HTTP server...
1116 strlcat(resource
, ".ppd", sizeof(resource
));
1119 httpSetField(http2
, HTTP_FIELD_IF_MODIFIED_SINCE
,
1120 httpGetDateString(*modtime
));
1122 status
= cupsGetFd(http2
, resource
, fd
);
1127 * See if we actually got the file or an error...
1130 if (status
== HTTP_OK
)
1132 *modtime
= httpGetDateTime(httpGetField(http2
, HTTP_FIELD_DATE
));
1135 strlcpy(buffer
, tempfile
, bufsize
);
1137 else if (status
!= HTTP_NOT_MODIFIED
)
1139 _cupsSetHTTPError(status
);
1143 else if (tempfile
[0])
1146 else if (tempfile
[0])
1153 * Return the PPD file...
1156 DEBUG_printf(("1cupsGetPPD3: Returning status %d", status
));
1163 * 'cupsGetPrinters()' - Get a list of printers from the default server.
1165 * This function is deprecated - use @link cupsGetDests@ instead.
1170 int /* O - Number of printers */
1171 cupsGetPrinters(char ***printers
) /* O - Printers */
1173 int n
; /* Number of printers */
1174 ipp_t
*request
, /* IPP Request */
1175 *response
; /* IPP Response */
1176 ipp_attribute_t
*attr
; /* Current attribute */
1177 char **temp
; /* Temporary pointer */
1178 http_t
*http
; /* Connection to server */
1182 * Range check input...
1187 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(EINVAL
), 0);
1195 * Try to connect to the server...
1198 if ((http
= _cupsConnect()) == NULL
)
1202 * Build a CUPS_GET_PRINTERS request, which requires the following
1205 * attributes-charset
1206 * attributes-natural-language
1207 * requested-attributes
1210 request
= ippNewRequest(CUPS_GET_PRINTERS
);
1212 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1213 "requested-attributes", NULL
, "printer-name");
1215 ippAddInteger(request
, IPP_TAG_OPERATION
, IPP_TAG_ENUM
,
1218 ippAddInteger(request
, IPP_TAG_OPERATION
, IPP_TAG_ENUM
,
1219 "printer-type-mask", CUPS_PRINTER_CLASS
);
1222 * Do the request and get back a response...
1227 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
1229 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
1230 if (attr
->name
!= NULL
&&
1231 _cups_strcasecmp(attr
->name
, "printer-name") == 0 &&
1232 attr
->value_tag
== IPP_TAG_NAME
)
1235 temp
= malloc(sizeof(char *));
1237 temp
= realloc(*printers
, sizeof(char *) * (n
+ 1));
1242 * Ran out of memory!
1248 free((*printers
)[n
]);
1252 ippDelete(response
);
1257 temp
[n
] = strdup(attr
->values
[0].string
.text
);
1261 ippDelete(response
);
1269 * 'cupsGetServerPPD()' - Get an available PPD file from the server.
1271 * This function returns the named PPD file from the server. The
1272 * list of available PPDs is provided by the IPP @code CUPS_GET_PPDS@
1275 * You must remove (unlink) the PPD file when you are finished with
1276 * it. The PPD filename is stored in a static location that will be
1277 * overwritten on the next call to @link cupsGetPPD@, @link cupsGetPPD2@,
1278 * or @link cupsGetServerPPD@.
1280 * @since CUPS 1.3/OS X 10.5@
1283 char * /* O - Name of PPD file or @code NULL@ on error */
1284 cupsGetServerPPD(http_t
*http
, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
1285 const char *name
) /* I - Name of PPD file ("ppd-name") */
1287 int fd
; /* PPD file descriptor */
1288 ipp_t
*request
; /* IPP request */
1289 _cups_globals_t
*cg
= _cupsGlobals();
1290 /* Pointer to library globals */
1294 * Range check input...
1299 _cupsSetError(IPP_INTERNAL_ERROR
, _("No PPD name"), 1);
1305 if ((http
= _cupsConnect()) == NULL
)
1309 * Get a temp file...
1312 if ((fd
= cupsTempFd(cg
->ppd_filename
, sizeof(cg
->ppd_filename
))) < 0)
1315 * Can't open file; close the server connection and return NULL...
1318 _cupsSetError(IPP_INTERNAL_ERROR
, NULL
, 0);
1324 * Get the PPD file...
1327 request
= ippNewRequest(CUPS_GET_PPD
);
1328 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "ppd-name", NULL
,
1331 ippDelete(cupsDoIORequest(http
, request
, "/", -1, fd
));
1335 if (cupsLastError() != IPP_OK
)
1337 unlink(cg
->ppd_filename
);
1341 return (cg
->ppd_filename
);
1346 * 'cupsPrintFile()' - Print a file to a printer or class on the default server.
1349 int /* O - Job ID or 0 on error */
1350 cupsPrintFile(const char *name
, /* I - Destination name */
1351 const char *filename
, /* I - File to print */
1352 const char *title
, /* I - Title of job */
1353 int num_options
,/* I - Number of options */
1354 cups_option_t
*options
) /* I - Options */
1356 DEBUG_printf(("cupsPrintFile(name=\"%s\", filename=\"%s\", "
1357 "title=\"%s\", num_options=%d, options=%p)",
1358 name
, filename
, title
, num_options
, options
));
1360 return (cupsPrintFiles2(CUPS_HTTP_DEFAULT
, name
, 1, &filename
, title
,
1361 num_options
, options
));
1366 * 'cupsPrintFile2()' - Print a file to a printer or class on the specified
1369 * @since CUPS 1.1.21/OS X 10.4@
1372 int /* O - Job ID or 0 on error */
1374 http_t
*http
, /* I - Connection to server */
1375 const char *name
, /* I - Destination name */
1376 const char *filename
, /* I - File to print */
1377 const char *title
, /* I - Title of job */
1378 int num_options
, /* I - Number of options */
1379 cups_option_t
*options
) /* I - Options */
1381 DEBUG_printf(("cupsPrintFile2(http=%p, name=\"%s\", filename=\"%s\", "
1382 "title=\"%s\", num_options=%d, options=%p)",
1383 http
, name
, filename
, title
, num_options
, options
));
1385 return (cupsPrintFiles2(http
, name
, 1, &filename
, title
, num_options
,
1391 * 'cupsPrintFiles()' - Print one or more files to a printer or class on the
1395 int /* O - Job ID or 0 on error */
1397 const char *name
, /* I - Destination name */
1398 int num_files
, /* I - Number of files */
1399 const char **files
, /* I - File(s) to print */
1400 const char *title
, /* I - Title of job */
1401 int num_options
, /* I - Number of options */
1402 cups_option_t
*options
) /* I - Options */
1404 DEBUG_printf(("cupsPrintFiles(name=\"%s\", num_files=%d, "
1405 "files=%p, title=\"%s\", num_options=%d, options=%p)",
1406 name
, num_files
, files
, title
, num_options
, options
));
1409 * Print the file(s)...
1412 return (cupsPrintFiles2(CUPS_HTTP_DEFAULT
, name
, num_files
, files
, title
,
1413 num_options
, options
));
1418 * 'cupsPrintFiles2()' - Print one or more files to a printer or class on the
1421 * @since CUPS 1.1.21/OS X 10.4@
1424 int /* O - Job ID or 0 on error */
1426 http_t
*http
, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
1427 const char *name
, /* I - Destination name */
1428 int num_files
, /* I - Number of files */
1429 const char **files
, /* I - File(s) to print */
1430 const char *title
, /* I - Title of job */
1431 int num_options
, /* I - Number of options */
1432 cups_option_t
*options
) /* I - Options */
1434 int i
; /* Looping var */
1435 int job_id
; /* New job ID */
1436 const char *docname
; /* Basename of current filename */
1437 const char *format
; /* Document format */
1438 cups_file_t
*fp
; /* Current file */
1439 char buffer
[8192]; /* Copy buffer */
1440 ssize_t bytes
; /* Bytes in buffer */
1441 http_status_t status
; /* Status of write */
1442 _cups_globals_t
*cg
= _cupsGlobals(); /* Global data */
1443 ipp_status_t cancel_status
; /* Status code to preserve */
1444 char *cancel_message
; /* Error message to preserve */
1447 DEBUG_printf(("cupsPrintFiles2(http=%p, name=\"%s\", num_files=%d, "
1448 "files=%p, title=\"%s\", num_options=%d, options=%p)",
1449 http
, name
, num_files
, files
, title
, num_options
, options
));
1452 * Range check input...
1455 if (!name
|| num_files
< 1 || !files
)
1457 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(EINVAL
), 0);
1463 * Create the print job...
1466 if ((job_id
= cupsCreateJob(http
, name
, title
, num_options
, options
)) == 0)
1470 * Send each of the files...
1473 if (cupsGetOption("raw", num_options
, options
))
1474 format
= CUPS_FORMAT_RAW
;
1475 else if ((format
= cupsGetOption("document-format", num_options
,
1477 format
= CUPS_FORMAT_AUTO
;
1479 for (i
= 0; i
< num_files
; i
++)
1482 * Start the next file...
1485 if ((docname
= strrchr(files
[i
], '/')) != NULL
)
1490 if ((fp
= cupsFileOpen(files
[i
], "rb")) == NULL
)
1493 * Unable to open print file, cancel the job and return...
1496 _cupsSetError(IPP_DOCUMENT_ACCESS_ERROR
, NULL
, 0);
1500 status
= cupsStartDocument(http
, name
, job_id
, docname
, format
,
1501 i
== (num_files
- 1));
1503 while (status
== HTTP_CONTINUE
&&
1504 (bytes
= cupsFileRead(fp
, buffer
, sizeof(buffer
))) > 0)
1505 status
= cupsWriteRequestData(http
, buffer
, bytes
);
1509 if (status
!= HTTP_CONTINUE
|| cupsFinishDocument(http
, name
) != IPP_OK
)
1512 * Unable to queue, cancel the job and return...
1522 * If we get here, something happened while sending the print job so we need
1523 * to cancel the job without setting the last error (since we need to preserve
1524 * the current error...
1529 cancel_status
= cg
->last_error
;
1530 cancel_message
= cg
->last_status_message
?
1531 _cupsStrRetain(cg
->last_status_message
) : NULL
;
1533 cupsCancelJob2(http
, name
, job_id
, 0);
1535 cg
->last_error
= cancel_status
;
1536 cg
->last_status_message
= cancel_message
;
1543 * 'cupsStartDocument()' - Add a document to a job created with cupsCreateJob().
1545 * Use @link cupsWriteRequestData@ to write data for the document and
1546 * @link cupsFinishDocument@ to finish the document and get the submission status.
1548 * The MIME type constants @code CUPS_FORMAT_AUTO@, @code CUPS_FORMAT_PDF@,
1549 * @code CUPS_FORMAT_POSTSCRIPT@, @code CUPS_FORMAT_RAW@, and
1550 * @code CUPS_FORMAT_TEXT@ are provided for the "format" argument, although
1551 * any supported MIME type string can be supplied.
1553 * @since CUPS 1.4/OS X 10.6@
1556 http_status_t
/* O - HTTP status of request */
1558 http_t
*http
, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
1559 const char *name
, /* I - Destination name */
1560 int job_id
, /* I - Job ID from @link cupsCreateJob@ */
1561 const char *docname
, /* I - Name of document */
1562 const char *format
, /* I - MIME type or @code CUPS_FORMAT_foo@ */
1563 int last_document
) /* I - 1 for last document in job, 0 otherwise */
1565 char resource
[1024], /* Resource for destinatio */
1566 printer_uri
[1024]; /* Printer URI */
1567 ipp_t
*request
; /* Send-Document request */
1568 http_status_t status
; /* HTTP status */
1572 * Create a Send-Document request...
1575 if ((request
= ippNewRequest(IPP_SEND_DOCUMENT
)) == NULL
)
1577 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(ENOMEM
), 0);
1578 return (HTTP_ERROR
);
1581 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
), "ipp",
1582 NULL
, "localhost", ippPort(), "/printers/%s", name
);
1583 snprintf(resource
, sizeof(resource
), "/printers/%s", name
);
1585 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
1587 ippAddInteger(request
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
, "job-id", job_id
);
1588 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
1591 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "document-name",
1594 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_MIMETYPE
,
1595 "document-format", NULL
, format
);
1596 ippAddBoolean(request
, IPP_TAG_OPERATION
, "last-document", last_document
);
1599 * Send and delete the request, then return the status...
1602 status
= cupsSendRequest(http
, request
, resource
, CUPS_LENGTH_VARIABLE
);
1611 * 'cups_get_printer_uri()' - Get the printer-uri-supported attribute for the
1612 * first printer in a class.
1615 static int /* O - 1 on success, 0 on failure */
1616 cups_get_printer_uri(
1617 http_t
*http
, /* I - Connection to server */
1618 const char *name
, /* I - Name of printer or class */
1619 char *host
, /* I - Hostname buffer */
1620 int hostsize
, /* I - Size of hostname buffer */
1621 int *port
, /* O - Port number */
1622 char *resource
, /* I - Resource buffer */
1623 int resourcesize
, /* I - Size of resource buffer */
1624 int depth
) /* I - Depth of query */
1626 int i
; /* Looping var */
1627 int http_port
; /* Port number */
1628 http_t
*http2
; /* Alternate HTTP connection */
1629 ipp_t
*request
, /* IPP request */
1630 *response
; /* IPP response */
1631 ipp_attribute_t
*attr
; /* Current attribute */
1632 char uri
[HTTP_MAX_URI
], /* printer-uri attribute */
1633 scheme
[HTTP_MAX_URI
], /* Scheme name */
1634 username
[HTTP_MAX_URI
], /* Username:password */
1635 classname
[255], /* Temporary class name */
1636 http_hostname
[HTTP_MAX_HOST
];
1637 /* Hostname associated with connection */
1638 static const char * const requested_attrs
[] =
1639 { /* Requested attributes */
1642 "printer-uri-supported",
1647 DEBUG_printf(("7cups_get_printer_uri(http=%p, name=\"%s\", host=%p, "
1648 "hostsize=%d, resource=%p, resourcesize=%d, depth=%d)",
1649 http
, name
, host
, hostsize
, resource
, resourcesize
, depth
));
1652 * Setup the printer URI...
1655 if (httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
1656 "localhost", 0, "/printers/%s", name
) != HTTP_URI_OK
)
1658 _cupsSetError(IPP_INTERNAL_ERROR
, _("Unable to create printer-uri"), 1);
1666 DEBUG_printf(("9cups_get_printer_uri: printer-uri=\"%s\"", uri
));
1669 * Get the hostname and port number we are connected to...
1672 httpGetHostname(http
, http_hostname
, sizeof(http_hostname
));
1673 http_port
= httpAddrPort(http
->hostaddr
);
1676 * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the following
1679 * attributes-charset
1680 * attributes-natural-language
1682 * requested-attributes
1685 request
= ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES
);
1687 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
1690 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
1691 "requested-attributes",
1692 sizeof(requested_attrs
) / sizeof(requested_attrs
[0]),
1693 NULL
, requested_attrs
);
1696 * Do the request and get back a response...
1699 snprintf(resource
, resourcesize
, "/printers/%s", name
);
1701 if ((response
= cupsDoRequest(http
, request
, resource
)) != NULL
)
1703 const char *device_uri
= NULL
; /* device-uri value */
1705 if ((attr
= ippFindAttribute(response
, "device-uri",
1706 IPP_TAG_URI
)) != NULL
)
1707 device_uri
= attr
->values
[0].string
.text
;
1710 ((strstr(device_uri
, "._ipp.") != NULL
||
1711 strstr(device_uri
, "._ipps.") != NULL
) &&
1712 !strcmp(device_uri
+ strlen(device_uri
) - 5, "/cups")))
1715 * Statically-configured Bonjour shared printer.
1718 httpSeparateURI(HTTP_URI_CODING_ALL
,
1719 _httpResolveURI(device_uri
, uri
, sizeof(uri
),
1720 _HTTP_RESOLVE_DEFAULT
, NULL
, NULL
),
1721 scheme
, sizeof(scheme
), username
, sizeof(username
),
1722 host
, hostsize
, port
, resource
, resourcesize
);
1723 ippDelete(response
);
1727 else if ((attr
= ippFindAttribute(response
, "member-uris",
1728 IPP_TAG_URI
)) != NULL
)
1731 * Get the first actual printer name in the class...
1734 for (i
= 0; i
< attr
->num_values
; i
++)
1736 httpSeparateURI(HTTP_URI_CODING_ALL
, attr
->values
[i
].string
.text
,
1737 scheme
, sizeof(scheme
), username
, sizeof(username
),
1738 host
, hostsize
, port
, resource
, resourcesize
);
1739 if (!strncmp(resource
, "/printers/", 10))
1745 ippDelete(response
);
1752 * No printers in this class - try recursively looking for a printer,
1753 * but not more than 3 levels deep...
1758 for (i
= 0; i
< attr
->num_values
; i
++)
1760 httpSeparateURI(HTTP_URI_CODING_ALL
, attr
->values
[i
].string
.text
,
1761 scheme
, sizeof(scheme
), username
, sizeof(username
),
1762 host
, hostsize
, port
, resource
, resourcesize
);
1763 if (!strncmp(resource
, "/classes/", 9))
1766 * Found a class! Connect to the right server...
1769 if (!_cups_strcasecmp(http_hostname
, host
) && *port
== http_port
)
1771 else if ((http2
= httpConnectEncrypt(host
, *port
,
1772 cupsEncryption())) == NULL
)
1774 DEBUG_puts("8cups_get_printer_uri: Unable to connect to server");
1780 * Look up printers on that server...
1783 strlcpy(classname
, resource
+ 9, sizeof(classname
));
1785 cups_get_printer_uri(http2
, classname
, host
, hostsize
, port
,
1786 resource
, resourcesize
, depth
+ 1);
1789 * Close the connection as needed...
1801 else if ((attr
= ippFindAttribute(response
, "printer-uri-supported",
1802 IPP_TAG_URI
)) != NULL
)
1804 httpSeparateURI(HTTP_URI_CODING_ALL
,
1805 _httpResolveURI(attr
->values
[0].string
.text
, uri
,
1806 sizeof(uri
), _HTTP_RESOLVE_DEFAULT
,
1808 scheme
, sizeof(scheme
), username
, sizeof(username
),
1809 host
, hostsize
, port
, resource
, resourcesize
);
1810 ippDelete(response
);
1812 if (!strncmp(resource
, "/classes/", 9))
1814 _cupsSetError(IPP_INTERNAL_ERROR
,
1815 _("No printer-uri found for class"), 1);
1826 ippDelete(response
);
1829 if (cupsLastError() != IPP_NOT_FOUND
)
1830 _cupsSetError(IPP_INTERNAL_ERROR
, _("No printer-uri found"), 1);
1840 * End of "$Id: util.c 7850 2008-08-20 00:07:25Z mike $".