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_JOB
);
252 cupsEncodeOptions2(request
, num_options
, options
, IPP_TAG_SUBSCRIPTION
);
255 * Send the request and get the job-id...
258 response
= cupsDoRequest(http
, request
, resource
);
260 if ((attr
= ippFindAttribute(response
, "job-id", IPP_TAG_INTEGER
)) != NULL
)
261 job_id
= attr
->values
[0].integer
;
274 * 'cupsFinishDocument()' - Finish sending a document.
276 * The document must have been started using @link cupsStartDocument@.
278 * @since CUPS 1.4/OS X 10.6@
281 ipp_status_t
/* O - Status of document submission */
282 cupsFinishDocument(http_t
*http
, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
283 const char *name
) /* I - Destination name */
285 char resource
[1024]; /* Printer resource */
288 snprintf(resource
, sizeof(resource
), "/printers/%s", name
);
290 ippDelete(cupsGetResponse(http
, resource
));
292 return (cupsLastError());
297 * 'cupsFreeJobs()' - Free memory used by job data.
301 cupsFreeJobs(int num_jobs
, /* I - Number of jobs */
302 cups_job_t
*jobs
) /* I - Jobs */
304 int i
; /* Looping var */
305 cups_job_t
*job
; /* Current job */
308 if (num_jobs
<= 0 || !jobs
)
311 for (i
= num_jobs
, job
= jobs
; i
> 0; i
--, job
++)
313 _cupsStrFree(job
->dest
);
314 _cupsStrFree(job
->user
);
315 _cupsStrFree(job
->format
);
316 _cupsStrFree(job
->title
);
324 * 'cupsGetClasses()' - Get a list of printer classes from the default server.
326 * This function is deprecated - use @link cupsGetDests@ instead.
331 int /* O - Number of classes */
332 cupsGetClasses(char ***classes
) /* O - Classes */
334 int n
; /* Number of classes */
335 ipp_t
*request
, /* IPP Request */
336 *response
; /* IPP Response */
337 ipp_attribute_t
*attr
; /* Current attribute */
338 char **temp
; /* Temporary pointer */
339 http_t
*http
; /* Connection to server */
344 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(EINVAL
), 0);
351 if ((http
= _cupsConnect()) == NULL
)
355 * Build a CUPS_GET_CLASSES request, which requires the following
359 * attributes-natural-language
360 * requested-attributes
363 request
= ippNewRequest(CUPS_GET_CLASSES
);
365 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
366 "requested-attributes", NULL
, "printer-name");
369 * Do the request and get back a response...
374 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
376 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
377 if (attr
->name
!= NULL
&&
378 _cups_strcasecmp(attr
->name
, "printer-name") == 0 &&
379 attr
->value_tag
== IPP_TAG_NAME
)
382 temp
= malloc(sizeof(char *));
384 temp
= realloc(*classes
, sizeof(char *) * (n
+ 1));
404 temp
[n
] = strdup(attr
->values
[0].string
.text
);
416 * 'cupsGetDefault()' - Get the default printer or class for the default server.
418 * This function returns the default printer or class as defined by
419 * the LPDEST or PRINTER environment variables. If these environment
420 * variables are not set, the server default destination is returned.
421 * Applications should use the @link cupsGetDests@ and @link cupsGetDest@
422 * functions to get the user-defined default printer, as this function does
423 * not support the lpoptions-defined default printer.
426 const char * /* O - Default printer or @code NULL@ */
430 * Return the default printer...
433 return (cupsGetDefault2(CUPS_HTTP_DEFAULT
));
438 * 'cupsGetDefault2()' - Get the default printer or class for the specified server.
440 * This function returns the default printer or class as defined by
441 * the LPDEST or PRINTER environment variables. If these environment
442 * variables are not set, the server default destination is returned.
443 * Applications should use the @link cupsGetDests@ and @link cupsGetDest@
444 * functions to get the user-defined default printer, as this function does
445 * not support the lpoptions-defined default printer.
447 * @since CUPS 1.1.21/OS X 10.4@
450 const char * /* O - Default printer or @code NULL@ */
451 cupsGetDefault2(http_t
*http
) /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
453 ipp_t
*request
, /* IPP Request */
454 *response
; /* IPP Response */
455 ipp_attribute_t
*attr
; /* Current attribute */
456 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
460 * See if we have a user default printer set...
463 if (_cupsUserDefault(cg
->def_printer
, sizeof(cg
->def_printer
)))
464 return (cg
->def_printer
);
467 * Connect to the server as needed...
471 if ((http
= _cupsConnect()) == NULL
)
475 * Build a CUPS_GET_DEFAULT request, which requires the following
479 * attributes-natural-language
482 request
= ippNewRequest(CUPS_GET_DEFAULT
);
485 * Do the request and get back a response...
488 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
490 if ((attr
= ippFindAttribute(response
, "printer-name",
491 IPP_TAG_NAME
)) != NULL
)
493 strlcpy(cg
->def_printer
, attr
->values
[0].string
.text
,
494 sizeof(cg
->def_printer
));
496 return (cg
->def_printer
);
507 * 'cupsGetJobs()' - Get the jobs from the default server.
509 * A "whichjobs" value of @code CUPS_WHICHJOBS_ALL@ returns all jobs regardless
510 * of state, while @code CUPS_WHICHJOBS_ACTIVE@ returns jobs that are
511 * pending, processing, or held and @code CUPS_WHICHJOBS_COMPLETED@ returns
512 * jobs that are stopped, canceled, aborted, or completed.
515 int /* O - Number of jobs */
516 cupsGetJobs(cups_job_t
**jobs
, /* O - Job data */
517 const char *name
, /* I - @code NULL@ = all destinations, otherwise show jobs for named destination */
518 int myjobs
, /* I - 0 = all users, 1 = mine */
519 int whichjobs
) /* I - @code CUPS_WHICHJOBS_ALL@, @code CUPS_WHICHJOBS_ACTIVE@, or @code CUPS_WHICHJOBS_COMPLETED@ */
525 return (cupsGetJobs2(CUPS_HTTP_DEFAULT
, jobs
, name
, myjobs
, whichjobs
));
531 * 'cupsGetJobs2()' - Get the jobs from the specified server.
533 * A "whichjobs" value of @code CUPS_WHICHJOBS_ALL@ returns all jobs regardless
534 * of state, while @code CUPS_WHICHJOBS_ACTIVE@ returns jobs that are
535 * pending, processing, or held and @code CUPS_WHICHJOBS_COMPLETED@ returns
536 * jobs that are stopped, canceled, aborted, or completed.
538 * @since CUPS 1.1.21/OS X 10.4@
541 int /* O - Number of jobs */
542 cupsGetJobs2(http_t
*http
, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
543 cups_job_t
**jobs
, /* O - Job data */
544 const char *name
, /* I - @code NULL@ = all destinations, otherwise show jobs for named destination */
545 int myjobs
, /* I - 0 = all users, 1 = mine */
546 int whichjobs
) /* I - @code CUPS_WHICHJOBS_ALL@, @code CUPS_WHICHJOBS_ACTIVE@, or @code CUPS_WHICHJOBS_COMPLETED@ */
548 int n
; /* Number of jobs */
549 ipp_t
*request
, /* IPP Request */
550 *response
; /* IPP Response */
551 ipp_attribute_t
*attr
; /* Current attribute */
552 cups_job_t
*temp
; /* Temporary pointer */
554 priority
, /* job-priority */
555 size
; /* job-k-octets */
556 ipp_jstate_t state
; /* job-state */
557 time_t completed_time
, /* time-at-completed */
558 creation_time
, /* time-at-creation */
559 processing_time
; /* time-at-processing */
560 const char *dest
, /* job-printer-uri */
561 *format
, /* document-format */
562 *title
, /* job-name */
563 *user
; /* job-originating-user-name */
564 char uri
[HTTP_MAX_URI
]; /* URI for jobs */
565 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
566 static const char * const attrs
[] = /* Requested attributes */
572 "job-originating-user-name",
583 * Range check input...
588 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(EINVAL
), 0);
594 * Get the right URI...
599 if (httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
600 "localhost", 0, "/printers/%s", name
) != HTTP_URI_OK
)
602 _cupsSetError(IPP_INTERNAL_ERROR
, _("Unable to create printer-uri"), 1);
608 strlcpy(uri
, "ipp://localhost/", sizeof(uri
));
611 if ((http
= _cupsConnect()) == NULL
)
615 * Build an IPP_GET_JOBS request, which requires the following
619 * attributes-natural-language
621 * requesting-user-name
624 * requested-attributes
627 request
= ippNewRequest(IPP_GET_JOBS
);
629 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
630 "printer-uri", NULL
, uri
);
632 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
633 "requesting-user-name", NULL
, cupsUser());
636 ippAddBoolean(request
, IPP_TAG_OPERATION
, "my-jobs", 1);
638 if (whichjobs
== CUPS_WHICHJOBS_COMPLETED
)
639 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
640 "which-jobs", NULL
, "completed");
641 else if (whichjobs
== CUPS_WHICHJOBS_ALL
)
642 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
643 "which-jobs", NULL
, "all");
645 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
646 "requested-attributes", sizeof(attrs
) / sizeof(attrs
[0]),
650 * Do the request and get back a response...
656 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
658 for (attr
= response
->attrs
; attr
; attr
= attr
->next
)
661 * Skip leading attributes until we hit a job...
664 while (attr
&& attr
->group_tag
!= IPP_TAG_JOB
)
671 * Pull the needed attributes from this job...
677 state
= IPP_JOB_PENDING
;
680 format
= "application/octet-stream";
686 while (attr
&& attr
->group_tag
== IPP_TAG_JOB
)
688 if (!strcmp(attr
->name
, "job-id") &&
689 attr
->value_tag
== IPP_TAG_INTEGER
)
690 id
= attr
->values
[0].integer
;
691 else if (!strcmp(attr
->name
, "job-state") &&
692 attr
->value_tag
== IPP_TAG_ENUM
)
693 state
= (ipp_jstate_t
)attr
->values
[0].integer
;
694 else if (!strcmp(attr
->name
, "job-priority") &&
695 attr
->value_tag
== IPP_TAG_INTEGER
)
696 priority
= attr
->values
[0].integer
;
697 else if (!strcmp(attr
->name
, "job-k-octets") &&
698 attr
->value_tag
== IPP_TAG_INTEGER
)
699 size
= attr
->values
[0].integer
;
700 else if (!strcmp(attr
->name
, "time-at-completed") &&
701 attr
->value_tag
== IPP_TAG_INTEGER
)
702 completed_time
= attr
->values
[0].integer
;
703 else if (!strcmp(attr
->name
, "time-at-creation") &&
704 attr
->value_tag
== IPP_TAG_INTEGER
)
705 creation_time
= attr
->values
[0].integer
;
706 else if (!strcmp(attr
->name
, "time-at-processing") &&
707 attr
->value_tag
== IPP_TAG_INTEGER
)
708 processing_time
= attr
->values
[0].integer
;
709 else if (!strcmp(attr
->name
, "job-printer-uri") &&
710 attr
->value_tag
== IPP_TAG_URI
)
712 if ((dest
= strrchr(attr
->values
[0].string
.text
, '/')) != NULL
)
715 else if (!strcmp(attr
->name
, "job-originating-user-name") &&
716 attr
->value_tag
== IPP_TAG_NAME
)
717 user
= attr
->values
[0].string
.text
;
718 else if (!strcmp(attr
->name
, "document-format") &&
719 attr
->value_tag
== IPP_TAG_MIMETYPE
)
720 format
= attr
->values
[0].string
.text
;
721 else if (!strcmp(attr
->name
, "job-name") &&
722 (attr
->value_tag
== IPP_TAG_TEXT
||
723 attr
->value_tag
== IPP_TAG_NAME
))
724 title
= attr
->values
[0].string
.text
;
730 * See if we have everything needed...
742 * Allocate memory for the job...
746 temp
= malloc(sizeof(cups_job_t
));
748 temp
= realloc(*jobs
, sizeof(cups_job_t
) * (n
+ 1));
756 _cupsSetError(IPP_INTERNAL_ERROR
, NULL
, 0);
758 cupsFreeJobs(n
, *jobs
);
771 * Copy the data over...
774 temp
->dest
= _cupsStrAlloc(dest
);
775 temp
->user
= _cupsStrAlloc(user
);
776 temp
->format
= _cupsStrAlloc(format
);
777 temp
->title
= _cupsStrAlloc(title
);
779 temp
->priority
= priority
;
782 temp
->completed_time
= completed_time
;
783 temp
->creation_time
= creation_time
;
784 temp
->processing_time
= processing_time
;
793 if (n
== 0 && cg
->last_error
>= IPP_BAD_REQUEST
)
801 * 'cupsGetPPD()' - Get the PPD file for a printer on the default server.
803 * For classes, @code cupsGetPPD@ returns the PPD file for the first printer
806 * The returned filename is stored in a static buffer and is overwritten with
807 * each call to @code cupsGetPPD@ or @link cupsGetPPD2@. The caller "owns" the
808 * file that is created and must @code unlink@ the returned filename.
811 const char * /* O - Filename for PPD file */
812 cupsGetPPD(const char *name
) /* I - Destination name */
814 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
815 time_t modtime
= 0; /* Modification time */
819 * Return the PPD file...
822 cg
->ppd_filename
[0] = '\0';
824 if (cupsGetPPD3(CUPS_HTTP_DEFAULT
, name
, &modtime
, cg
->ppd_filename
,
825 sizeof(cg
->ppd_filename
)) == HTTP_OK
)
826 return (cg
->ppd_filename
);
833 * 'cupsGetPPD2()' - Get the PPD file for a printer from the specified server.
835 * For classes, @code cupsGetPPD2@ returns the PPD file for the first printer
838 * The returned filename is stored in a static buffer and is overwritten with
839 * each call to @link cupsGetPPD@ or @code cupsGetPPD2@. The caller "owns" the
840 * file that is created and must @code unlink@ the returned filename.
842 * @since CUPS 1.1.21/OS X 10.4@
845 const char * /* O - Filename for PPD file */
846 cupsGetPPD2(http_t
*http
, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
847 const char *name
) /* I - Destination name */
849 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
850 time_t modtime
= 0; /* Modification time */
853 cg
->ppd_filename
[0] = '\0';
855 if (cupsGetPPD3(http
, name
, &modtime
, cg
->ppd_filename
,
856 sizeof(cg
->ppd_filename
)) == HTTP_OK
)
857 return (cg
->ppd_filename
);
864 * 'cupsGetPPD3()' - Get the PPD file for a printer on the specified
865 * server if it has changed.
867 * The "modtime" parameter contains the modification time of any
868 * locally-cached content and is updated with the time from the PPD file on
871 * The "buffer" parameter contains the local PPD filename. If it contains
872 * the empty string, a new temporary file is created, otherwise the existing
873 * file will be overwritten as needed. The caller "owns" the file that is
874 * created and must @code unlink@ the returned filename.
876 * On success, @code HTTP_OK@ is returned for a new PPD file and
877 * @code HTTP_NOT_MODIFIED@ if the existing PPD file is up-to-date. Any other
878 * status is an error.
880 * For classes, @code cupsGetPPD3@ returns the PPD file for the first printer
883 * @since CUPS 1.4/OS X 10.6@
886 http_status_t
/* O - HTTP status */
887 cupsGetPPD3(http_t
*http
, /* I - HTTP connection or @code CUPS_HTTP_DEFAULT@ */
888 const char *name
, /* I - Destination name */
889 time_t *modtime
, /* IO - Modification time */
890 char *buffer
, /* I - Filename buffer */
891 size_t bufsize
) /* I - Size of filename buffer */
893 int http_port
; /* Port number */
894 char http_hostname
[HTTP_MAX_HOST
];
895 /* Hostname associated with connection */
896 http_t
*http2
; /* Alternate HTTP connection */
897 int fd
; /* PPD file */
898 char localhost
[HTTP_MAX_URI
],/* Local hostname */
899 hostname
[HTTP_MAX_URI
], /* Hostname */
900 resource
[HTTP_MAX_URI
]; /* Resource name */
901 int port
; /* Port number */
902 http_status_t status
; /* HTTP status from server */
903 char tempfile
[1024] = ""; /* Temporary filename */
904 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
908 * Range check input...
911 DEBUG_printf(("cupsGetPPD3(http=%p, name=\"%s\", modtime=%p(%d), buffer=%p, "
912 "bufsize=%d)", http
, name
, modtime
,
913 modtime
? (int)*modtime
: 0, buffer
, (int)bufsize
));
917 _cupsSetError(IPP_INTERNAL_ERROR
, _("No printer name"), 1);
918 return (HTTP_NOT_ACCEPTABLE
);
923 _cupsSetError(IPP_INTERNAL_ERROR
, _("No modification time"), 1);
924 return (HTTP_NOT_ACCEPTABLE
);
927 if (!buffer
|| bufsize
<= 1)
929 _cupsSetError(IPP_INTERNAL_ERROR
, _("Bad filename buffer"), 1);
930 return (HTTP_NOT_ACCEPTABLE
);
935 * See if the PPD file is available locally...
938 if (!cg
->servername
[0])
941 if (!_cups_strcasecmp(cg
->servername
, "localhost"))
943 char ppdname
[1024]; /* PPD filename */
944 struct stat ppdinfo
; /* PPD file information */
947 snprintf(ppdname
, sizeof(ppdname
), "%s/ppd/%s.ppd", cg
->cups_serverroot
,
949 if (!stat(ppdname
, &ppdinfo
))
952 * OK, the file exists, use it!
959 if (symlink(ppdname
, buffer
) && errno
!= EEXIST
)
961 _cupsSetError(IPP_INTERNAL_ERROR
, NULL
, 0);
963 return (HTTP_SERVER_ERROR
);
968 int tries
; /* Number of tries */
969 const char *tmpdir
; /* TMPDIR environment variable */
970 struct timeval curtime
; /* Current time */
973 * Previously we put root temporary files in the default CUPS temporary
974 * directory under /var/spool/cups. However, since the scheduler cleans
975 * out temporary files there and runs independently of the user apps, we
976 * don't want to use it unless specifically told to by cupsd.
979 if ((tmpdir
= getenv("TMPDIR")) == NULL
)
981 tmpdir
= "/private/tmp"; /* /tmp is a symlink to /private/tmp */
984 # endif /* __APPLE__ */
987 * Make the temporary name using the specified directory...
995 * Get the current time of day...
998 gettimeofday(&curtime
, NULL
);
1001 * Format a string using the hex time values...
1004 snprintf(buffer
, bufsize
, "%s/%08lx%05lx", tmpdir
,
1005 (unsigned long)curtime
.tv_sec
,
1006 (unsigned long)curtime
.tv_usec
);
1009 * Try to make a symlink...
1012 if (!symlink(ppdname
, buffer
))
1017 while (tries
< 1000);
1021 _cupsSetError(IPP_INTERNAL_ERROR
, NULL
, 0);
1023 return (HTTP_SERVER_ERROR
);
1027 if (*modtime
>= ppdinfo
.st_mtime
)
1028 return (HTTP_NOT_MODIFIED
);
1031 *modtime
= ppdinfo
.st_mtime
;
1039 * Try finding a printer URI for this printer...
1043 if ((http
= _cupsConnect()) == NULL
)
1044 return (HTTP_SERVICE_UNAVAILABLE
);
1046 if (!cups_get_printer_uri(http
, name
, hostname
, sizeof(hostname
), &port
,
1047 resource
, sizeof(resource
), 0))
1048 return (HTTP_NOT_FOUND
);
1050 DEBUG_printf(("2cupsGetPPD3: Printer hostname=\"%s\", port=%d", hostname
,
1054 * Remap local hostname to localhost...
1057 httpGetHostname(NULL
, localhost
, sizeof(localhost
));
1059 DEBUG_printf(("2cupsGetPPD3: Local hostname=\"%s\"", localhost
));
1061 if (!_cups_strcasecmp(localhost
, hostname
))
1062 strlcpy(hostname
, "localhost", sizeof(hostname
));
1065 * Get the hostname and port number we are connected to...
1068 httpGetHostname(http
, http_hostname
, sizeof(http_hostname
));
1069 http_port
= _httpAddrPort(http
->hostaddr
);
1071 DEBUG_printf(("2cupsGetPPD3: Connection hostname=\"%s\", port=%d",
1072 http_hostname
, http_port
));
1075 * Reconnect to the correct server as needed...
1078 if (!_cups_strcasecmp(http_hostname
, hostname
) && port
== http_port
)
1080 else if ((http2
= httpConnectEncrypt(hostname
, port
,
1081 cupsEncryption())) == NULL
)
1083 DEBUG_puts("1cupsGetPPD3: Unable to connect to server");
1085 return (HTTP_SERVICE_UNAVAILABLE
);
1089 * Get a temp file...
1093 fd
= open(buffer
, O_CREAT
| O_TRUNC
| O_WRONLY
, 0600);
1095 fd
= cupsTempFd(tempfile
, sizeof(tempfile
));
1100 * Can't open file; close the server connection and return NULL...
1103 _cupsSetError(IPP_INTERNAL_ERROR
, NULL
, 0);
1108 return (HTTP_SERVER_ERROR
);
1112 * And send a request to the HTTP server...
1115 strlcat(resource
, ".ppd", sizeof(resource
));
1118 httpSetField(http2
, HTTP_FIELD_IF_MODIFIED_SINCE
,
1119 httpGetDateString(*modtime
));
1121 status
= cupsGetFd(http2
, resource
, fd
);
1126 * See if we actually got the file or an error...
1129 if (status
== HTTP_OK
)
1131 *modtime
= httpGetDateTime(httpGetField(http2
, HTTP_FIELD_DATE
));
1134 strlcpy(buffer
, tempfile
, bufsize
);
1136 else if (status
!= HTTP_NOT_MODIFIED
)
1138 _cupsSetHTTPError(status
);
1142 else if (tempfile
[0])
1145 else if (tempfile
[0])
1152 * Return the PPD file...
1155 DEBUG_printf(("1cupsGetPPD3: Returning status %d", status
));
1162 * 'cupsGetPrinters()' - Get a list of printers from the default server.
1164 * This function is deprecated - use @link cupsGetDests@ instead.
1169 int /* O - Number of printers */
1170 cupsGetPrinters(char ***printers
) /* O - Printers */
1172 int n
; /* Number of printers */
1173 ipp_t
*request
, /* IPP Request */
1174 *response
; /* IPP Response */
1175 ipp_attribute_t
*attr
; /* Current attribute */
1176 char **temp
; /* Temporary pointer */
1177 http_t
*http
; /* Connection to server */
1181 * Range check input...
1186 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(EINVAL
), 0);
1194 * Try to connect to the server...
1197 if ((http
= _cupsConnect()) == NULL
)
1201 * Build a CUPS_GET_PRINTERS request, which requires the following
1204 * attributes-charset
1205 * attributes-natural-language
1206 * requested-attributes
1209 request
= ippNewRequest(CUPS_GET_PRINTERS
);
1211 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1212 "requested-attributes", NULL
, "printer-name");
1214 ippAddInteger(request
, IPP_TAG_OPERATION
, IPP_TAG_ENUM
,
1217 ippAddInteger(request
, IPP_TAG_OPERATION
, IPP_TAG_ENUM
,
1218 "printer-type-mask", CUPS_PRINTER_CLASS
);
1221 * Do the request and get back a response...
1226 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
1228 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
1229 if (attr
->name
!= NULL
&&
1230 _cups_strcasecmp(attr
->name
, "printer-name") == 0 &&
1231 attr
->value_tag
== IPP_TAG_NAME
)
1234 temp
= malloc(sizeof(char *));
1236 temp
= realloc(*printers
, sizeof(char *) * (n
+ 1));
1241 * Ran out of memory!
1247 free((*printers
)[n
]);
1251 ippDelete(response
);
1256 temp
[n
] = strdup(attr
->values
[0].string
.text
);
1260 ippDelete(response
);
1268 * 'cupsGetServerPPD()' - Get an available PPD file from the server.
1270 * This function returns the named PPD file from the server. The
1271 * list of available PPDs is provided by the IPP @code CUPS_GET_PPDS@
1274 * You must remove (unlink) the PPD file when you are finished with
1275 * it. The PPD filename is stored in a static location that will be
1276 * overwritten on the next call to @link cupsGetPPD@, @link cupsGetPPD2@,
1277 * or @link cupsGetServerPPD@.
1279 * @since CUPS 1.3/OS X 10.5@
1282 char * /* O - Name of PPD file or @code NULL@ on error */
1283 cupsGetServerPPD(http_t
*http
, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
1284 const char *name
) /* I - Name of PPD file ("ppd-name") */
1286 int fd
; /* PPD file descriptor */
1287 ipp_t
*request
; /* IPP request */
1288 _cups_globals_t
*cg
= _cupsGlobals();
1289 /* Pointer to library globals */
1293 * Range check input...
1298 _cupsSetError(IPP_INTERNAL_ERROR
, _("No PPD name"), 1);
1304 if ((http
= _cupsConnect()) == NULL
)
1308 * Get a temp file...
1311 if ((fd
= cupsTempFd(cg
->ppd_filename
, sizeof(cg
->ppd_filename
))) < 0)
1314 * Can't open file; close the server connection and return NULL...
1317 _cupsSetError(IPP_INTERNAL_ERROR
, NULL
, 0);
1323 * Get the PPD file...
1326 request
= ippNewRequest(CUPS_GET_PPD
);
1327 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "ppd-name", NULL
,
1330 ippDelete(cupsDoIORequest(http
, request
, "/", -1, fd
));
1334 if (cupsLastError() != IPP_OK
)
1336 unlink(cg
->ppd_filename
);
1340 return (cg
->ppd_filename
);
1345 * 'cupsPrintFile()' - Print a file to a printer or class on the default server.
1348 int /* O - Job ID or 0 on error */
1349 cupsPrintFile(const char *name
, /* I - Destination name */
1350 const char *filename
, /* I - File to print */
1351 const char *title
, /* I - Title of job */
1352 int num_options
,/* I - Number of options */
1353 cups_option_t
*options
) /* I - Options */
1355 DEBUG_printf(("cupsPrintFile(name=\"%s\", filename=\"%s\", "
1356 "title=\"%s\", num_options=%d, options=%p)",
1357 name
, filename
, title
, num_options
, options
));
1359 return (cupsPrintFiles2(CUPS_HTTP_DEFAULT
, name
, 1, &filename
, title
,
1360 num_options
, options
));
1365 * 'cupsPrintFile2()' - Print a file to a printer or class on the specified
1368 * @since CUPS 1.1.21/OS X 10.4@
1371 int /* O - Job ID or 0 on error */
1373 http_t
*http
, /* I - Connection to server */
1374 const char *name
, /* I - Destination name */
1375 const char *filename
, /* I - File to print */
1376 const char *title
, /* I - Title of job */
1377 int num_options
, /* I - Number of options */
1378 cups_option_t
*options
) /* I - Options */
1380 DEBUG_printf(("cupsPrintFile2(http=%p, name=\"%s\", filename=\"%s\", "
1381 "title=\"%s\", num_options=%d, options=%p)",
1382 http
, name
, filename
, title
, num_options
, options
));
1384 return (cupsPrintFiles2(http
, name
, 1, &filename
, title
, num_options
,
1390 * 'cupsPrintFiles()' - Print one or more files to a printer or class on the
1394 int /* O - Job ID or 0 on error */
1396 const char *name
, /* I - Destination name */
1397 int num_files
, /* I - Number of files */
1398 const char **files
, /* I - File(s) to print */
1399 const char *title
, /* I - Title of job */
1400 int num_options
, /* I - Number of options */
1401 cups_option_t
*options
) /* I - Options */
1403 DEBUG_printf(("cupsPrintFiles(name=\"%s\", num_files=%d, "
1404 "files=%p, title=\"%s\", num_options=%d, options=%p)",
1405 name
, num_files
, files
, title
, num_options
, options
));
1408 * Print the file(s)...
1411 return (cupsPrintFiles2(CUPS_HTTP_DEFAULT
, name
, num_files
, files
, title
,
1412 num_options
, options
));
1417 * 'cupsPrintFiles2()' - Print one or more files to a printer or class on the
1420 * @since CUPS 1.1.21/OS X 10.4@
1423 int /* O - Job ID or 0 on error */
1425 http_t
*http
, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
1426 const char *name
, /* I - Destination name */
1427 int num_files
, /* I - Number of files */
1428 const char **files
, /* I - File(s) to print */
1429 const char *title
, /* I - Title of job */
1430 int num_options
, /* I - Number of options */
1431 cups_option_t
*options
) /* I - Options */
1433 int i
; /* Looping var */
1434 int job_id
; /* New job ID */
1435 const char *docname
; /* Basename of current filename */
1436 const char *format
; /* Document format */
1437 cups_file_t
*fp
; /* Current file */
1438 char buffer
[8192]; /* Copy buffer */
1439 ssize_t bytes
; /* Bytes in buffer */
1440 http_status_t status
; /* Status of write */
1441 _cups_globals_t
*cg
= _cupsGlobals(); /* Global data */
1442 ipp_status_t cancel_status
; /* Status code to preserve */
1443 char *cancel_message
; /* Error message to preserve */
1446 DEBUG_printf(("cupsPrintFiles2(http=%p, name=\"%s\", num_files=%d, "
1447 "files=%p, title=\"%s\", num_options=%d, options=%p)",
1448 http
, name
, num_files
, files
, title
, num_options
, options
));
1451 * Range check input...
1454 if (!name
|| num_files
< 1 || !files
)
1456 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(EINVAL
), 0);
1462 * Create the print job...
1465 if ((job_id
= cupsCreateJob(http
, name
, title
, num_options
, options
)) == 0)
1469 * Send each of the files...
1472 if (cupsGetOption("raw", num_options
, options
))
1473 format
= CUPS_FORMAT_RAW
;
1474 else if ((format
= cupsGetOption("document-format", num_options
,
1476 format
= CUPS_FORMAT_AUTO
;
1478 for (i
= 0; i
< num_files
; i
++)
1481 * Start the next file...
1484 if ((docname
= strrchr(files
[i
], '/')) != NULL
)
1489 if ((fp
= cupsFileOpen(files
[i
], "rb")) == NULL
)
1492 * Unable to open print file, cancel the job and return...
1495 _cupsSetError(IPP_DOCUMENT_ACCESS_ERROR
, NULL
, 0);
1499 status
= cupsStartDocument(http
, name
, job_id
, docname
, format
,
1500 i
== (num_files
- 1));
1502 while (status
== HTTP_CONTINUE
&&
1503 (bytes
= cupsFileRead(fp
, buffer
, sizeof(buffer
))) > 0)
1504 status
= cupsWriteRequestData(http
, buffer
, bytes
);
1508 if (status
!= HTTP_CONTINUE
|| cupsFinishDocument(http
, name
) != IPP_OK
)
1511 * Unable to queue, cancel the job and return...
1521 * If we get here, something happened while sending the print job so we need
1522 * to cancel the job without setting the last error (since we need to preserve
1523 * the current error...
1528 cancel_status
= cg
->last_error
;
1529 cancel_message
= cg
->last_status_message
?
1530 _cupsStrRetain(cg
->last_status_message
) : NULL
;
1532 cupsCancelJob2(http
, name
, job_id
, 0);
1534 cg
->last_error
= cancel_status
;
1535 cg
->last_status_message
= cancel_message
;
1542 * 'cupsStartDocument()' - Add a document to a job created with cupsCreateJob().
1544 * Use @link cupsWriteRequestData@ to write data for the document and
1545 * @link cupsFinishDocument@ to finish the document and get the submission status.
1547 * The MIME type constants @code CUPS_FORMAT_AUTO@, @code CUPS_FORMAT_PDF@,
1548 * @code CUPS_FORMAT_POSTSCRIPT@, @code CUPS_FORMAT_RAW@, and
1549 * @code CUPS_FORMAT_TEXT@ are provided for the "format" argument, although
1550 * any supported MIME type string can be supplied.
1552 * @since CUPS 1.4/OS X 10.6@
1555 http_status_t
/* O - HTTP status of request */
1557 http_t
*http
, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
1558 const char *name
, /* I - Destination name */
1559 int job_id
, /* I - Job ID from @link cupsCreateJob@ */
1560 const char *docname
, /* I - Name of document */
1561 const char *format
, /* I - MIME type or @code CUPS_FORMAT_foo@ */
1562 int last_document
) /* I - 1 for last document in job, 0 otherwise */
1564 char resource
[1024], /* Resource for destinatio */
1565 printer_uri
[1024]; /* Printer URI */
1566 ipp_t
*request
; /* Send-Document request */
1567 http_status_t status
; /* HTTP status */
1571 * Create a Send-Document request...
1574 if ((request
= ippNewRequest(IPP_SEND_DOCUMENT
)) == NULL
)
1576 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(ENOMEM
), 0);
1577 return (HTTP_ERROR
);
1580 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
), "ipp",
1581 NULL
, "localhost", ippPort(), "/printers/%s", name
);
1582 snprintf(resource
, sizeof(resource
), "/printers/%s", name
);
1584 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
1586 ippAddInteger(request
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
, "job-id", job_id
);
1587 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
1590 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "document-name",
1593 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_MIMETYPE
,
1594 "document-format", NULL
, format
);
1595 ippAddBoolean(request
, IPP_TAG_OPERATION
, "last-document", last_document
);
1598 * Send and delete the request, then return the status...
1601 status
= cupsSendRequest(http
, request
, resource
, CUPS_LENGTH_VARIABLE
);
1610 * 'cups_get_printer_uri()' - Get the printer-uri-supported attribute for the
1611 * first printer in a class.
1614 static int /* O - 1 on success, 0 on failure */
1615 cups_get_printer_uri(
1616 http_t
*http
, /* I - Connection to server */
1617 const char *name
, /* I - Name of printer or class */
1618 char *host
, /* I - Hostname buffer */
1619 int hostsize
, /* I - Size of hostname buffer */
1620 int *port
, /* O - Port number */
1621 char *resource
, /* I - Resource buffer */
1622 int resourcesize
, /* I - Size of resource buffer */
1623 int depth
) /* I - Depth of query */
1625 int i
; /* Looping var */
1626 int http_port
; /* Port number */
1627 http_t
*http2
; /* Alternate HTTP connection */
1628 ipp_t
*request
, /* IPP request */
1629 *response
; /* IPP response */
1630 ipp_attribute_t
*attr
; /* Current attribute */
1631 char uri
[HTTP_MAX_URI
], /* printer-uri attribute */
1632 scheme
[HTTP_MAX_URI
], /* Scheme name */
1633 username
[HTTP_MAX_URI
], /* Username:password */
1634 classname
[255], /* Temporary class name */
1635 http_hostname
[HTTP_MAX_HOST
];
1636 /* Hostname associated with connection */
1637 static const char * const requested_attrs
[] =
1638 { /* Requested attributes */
1641 "printer-uri-supported",
1646 DEBUG_printf(("7cups_get_printer_uri(http=%p, name=\"%s\", host=%p, "
1647 "hostsize=%d, resource=%p, resourcesize=%d, depth=%d)",
1648 http
, name
, host
, hostsize
, resource
, resourcesize
, depth
));
1651 * Setup the printer URI...
1654 if (httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
1655 "localhost", 0, "/printers/%s", name
) != HTTP_URI_OK
)
1657 _cupsSetError(IPP_INTERNAL_ERROR
, _("Unable to create printer-uri"), 1);
1665 DEBUG_printf(("9cups_get_printer_uri: printer-uri=\"%s\"", uri
));
1668 * Get the hostname and port number we are connected to...
1671 httpGetHostname(http
, http_hostname
, sizeof(http_hostname
));
1672 http_port
= _httpAddrPort(http
->hostaddr
);
1675 * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the following
1678 * attributes-charset
1679 * attributes-natural-language
1681 * requested-attributes
1684 request
= ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES
);
1686 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
1689 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
1690 "requested-attributes",
1691 sizeof(requested_attrs
) / sizeof(requested_attrs
[0]),
1692 NULL
, requested_attrs
);
1695 * Do the request and get back a response...
1698 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
1700 const char *device_uri
= NULL
; /* device-uri value */
1702 if ((attr
= ippFindAttribute(response
, "device-uri",
1703 IPP_TAG_URI
)) != NULL
)
1704 device_uri
= attr
->values
[0].string
.text
;
1707 ((strstr(device_uri
, "._ipp.") != NULL
||
1708 strstr(device_uri
, "._ipps.") != NULL
) &&
1709 !strcmp(device_uri
+ strlen(device_uri
) - 5, "/cups")))
1712 * Statically-configured Bonjour shared printer.
1715 httpSeparateURI(HTTP_URI_CODING_ALL
,
1716 _httpResolveURI(device_uri
, uri
, sizeof(uri
),
1717 _HTTP_RESOLVE_DEFAULT
, NULL
, NULL
),
1718 scheme
, sizeof(scheme
), username
, sizeof(username
),
1719 host
, hostsize
, port
, resource
, resourcesize
);
1720 ippDelete(response
);
1724 else if ((attr
= ippFindAttribute(response
, "member-uris",
1725 IPP_TAG_URI
)) != NULL
)
1728 * Get the first actual printer name in the class...
1731 for (i
= 0; i
< attr
->num_values
; i
++)
1733 httpSeparateURI(HTTP_URI_CODING_ALL
, attr
->values
[i
].string
.text
,
1734 scheme
, sizeof(scheme
), username
, sizeof(username
),
1735 host
, hostsize
, port
, resource
, resourcesize
);
1736 if (!strncmp(resource
, "/printers/", 10))
1742 ippDelete(response
);
1749 * No printers in this class - try recursively looking for a printer,
1750 * but not more than 3 levels deep...
1755 for (i
= 0; i
< attr
->num_values
; i
++)
1757 httpSeparateURI(HTTP_URI_CODING_ALL
, attr
->values
[i
].string
.text
,
1758 scheme
, sizeof(scheme
), username
, sizeof(username
),
1759 host
, hostsize
, port
, resource
, resourcesize
);
1760 if (!strncmp(resource
, "/classes/", 9))
1763 * Found a class! Connect to the right server...
1766 if (!_cups_strcasecmp(http_hostname
, host
) && *port
== http_port
)
1768 else if ((http2
= httpConnectEncrypt(host
, *port
,
1769 cupsEncryption())) == NULL
)
1771 DEBUG_puts("8cups_get_printer_uri: Unable to connect to server");
1777 * Look up printers on that server...
1780 strlcpy(classname
, resource
+ 9, sizeof(classname
));
1782 cups_get_printer_uri(http2
, classname
, host
, hostsize
, port
,
1783 resource
, resourcesize
, depth
+ 1);
1786 * Close the connection as needed...
1798 else if ((attr
= ippFindAttribute(response
, "printer-uri-supported",
1799 IPP_TAG_URI
)) != NULL
)
1801 httpSeparateURI(HTTP_URI_CODING_ALL
,
1802 _httpResolveURI(attr
->values
[0].string
.text
, uri
,
1803 sizeof(uri
), _HTTP_RESOLVE_DEFAULT
,
1805 scheme
, sizeof(scheme
), username
, sizeof(username
),
1806 host
, hostsize
, port
, resource
, resourcesize
);
1807 ippDelete(response
);
1809 if (!strncmp(resource
, "/classes/", 9))
1811 _cupsSetError(IPP_INTERNAL_ERROR
,
1812 _("No printer-uri found for class"), 1);
1823 ippDelete(response
);
1826 if (cupsLastError() != IPP_NOT_FOUND
)
1827 _cupsSetError(IPP_INTERNAL_ERROR
, _("No printer-uri found"), 1);
1837 * End of "$Id: util.c 7850 2008-08-20 00:07:25Z mike $".