2 * Support code for the Common UNIX Printing System ("CUPS")
4 * Copyright 1999-2003 by Michael R Sweet.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include <cups/cups.h>
26 #include <cups/language.h>
30 * 'cups_passwd_cb()' - The CUPS password callback...
33 static const char * /* O - Password or NULL */
34 cups_passwd_cb(const char *prompt) /* I - Prompt */
37 * Always return NULL to indicate that no password is available...
43 static const char *cups_server(void)
45 if ((lp_cups_server() != NULL) && (strlen(lp_cups_server()) > 0)) {
46 DEBUG(10, ("cups server explicitly set to %s\n",
48 return lp_cups_server();
51 DEBUG(10, ("cups server left to default %s\n", cupsServer()));
56 * 'cups_printer_fn()' - Call a function for every printer known to the
60 void cups_printer_fn(void (*fn)(char *, char *))
62 /* I - Function to call */
63 http_t *http; /* HTTP connection to server */
64 ipp_t *request, /* IPP Request */
65 *response; /* IPP Response */
66 ipp_attribute_t *attr; /* Current attribute */
67 cups_lang_t *language; /* Default language */
68 char *name, /* printer-name attribute */
69 *make_model, /* printer-make-and-model attribute */
70 *info; /* printer-info attribute */
71 static const char *requested[] =/* Requested attributes */
74 "printer-make-and-model",
79 DEBUG(5,("cups_printer_fn(%p)\n", fn));
82 * Make sure we don't ask for passwords...
85 cupsSetPasswordCB(cups_passwd_cb);
88 * Try to connect to the server...
91 if ((http = httpConnect(cups_server(), ippPort())) == NULL)
93 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
94 cups_server(), strerror(errno)));
99 * Build a CUPS_GET_PRINTERS request, which requires the following
103 * attributes-natural-language
104 * requested-attributes
109 request->request.op.operation_id = CUPS_GET_PRINTERS;
110 request->request.op.request_id = 1;
112 language = cupsLangDefault();
114 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
115 "attributes-charset", NULL, cupsLangEncoding(language));
117 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
118 "attributes-natural-language", NULL, language->language);
120 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
121 "requested-attributes",
122 (sizeof(requested) / sizeof(requested[0])),
126 * Do the request and get back a response...
129 if ((response = cupsDoRequest(http, request, "/")) == NULL)
131 DEBUG(0,("Unable to get printer list - %s\n",
132 ippErrorString(cupsLastError())));
137 for (attr = response->attrs; attr != NULL;)
140 * Skip leading attributes until we hit a printer...
143 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
150 * Pull the needed attributes from this printer...
157 while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER)
159 if (strcmp(attr->name, "printer-name") == 0 &&
160 attr->value_tag == IPP_TAG_NAME)
161 name = attr->values[0].string.text;
163 if (strcmp(attr->name, "printer-make-and-model") == 0 &&
164 attr->value_tag == IPP_TAG_TEXT)
165 make_model = attr->values[0].string.text;
167 if (strcmp(attr->name, "printer-info") == 0 &&
168 attr->value_tag == IPP_TAG_TEXT)
169 info = attr->values[0].string.text;
175 * See if we have everything needed...
181 if (info == NULL || !info[0])
182 (*fn)(name, make_model);
193 * Build a CUPS_GET_CLASSES request, which requires the following
197 * attributes-natural-language
198 * requested-attributes
203 request->request.op.operation_id = CUPS_GET_CLASSES;
204 request->request.op.request_id = 1;
206 language = cupsLangDefault();
208 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
209 "attributes-charset", NULL, cupsLangEncoding(language));
211 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
212 "attributes-natural-language", NULL, language->language);
214 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
215 "requested-attributes",
216 (sizeof(requested) / sizeof(requested[0])),
220 * Do the request and get back a response...
223 if ((response = cupsDoRequest(http, request, "/")) == NULL)
225 DEBUG(0,("Unable to get printer list - %s\n",
226 ippErrorString(cupsLastError())));
231 for (attr = response->attrs; attr != NULL;)
234 * Skip leading attributes until we hit a printer...
237 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
244 * Pull the needed attributes from this printer...
251 while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER)
253 if (strcmp(attr->name, "printer-name") == 0 &&
254 attr->value_tag == IPP_TAG_NAME)
255 name = attr->values[0].string.text;
257 if (strcmp(attr->name, "printer-make-and-model") == 0 &&
258 attr->value_tag == IPP_TAG_TEXT)
259 make_model = attr->values[0].string.text;
261 if (strcmp(attr->name, "printer-info") == 0 &&
262 attr->value_tag == IPP_TAG_TEXT)
263 info = attr->values[0].string.text;
269 * See if we have everything needed...
275 if (info == NULL || !info[0])
276 (*fn)(name, make_model);
286 * Close the connection to the server...
294 * 'cups_printername_ok()' - Provide the equivalent of pcap_printername_ok()
296 * O - 1 if printer name OK
297 * I - Name of printer
299 int cups_printername_ok(const char *name)
301 http_t *http; /* HTTP connection to server */
302 ipp_t *request, /* IPP Request */
303 *response; /* IPP Response */
304 cups_lang_t *language; /* Default language */
305 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
308 DEBUG(5,("cups_printername_ok(\"%s\")\n", name));
311 * Make sure we don't ask for passwords...
314 cupsSetPasswordCB(cups_passwd_cb);
317 * Try to connect to the server...
320 if ((http = httpConnect(cups_server(), ippPort())) == NULL)
322 DEBUG(3,("Unable to connect to CUPS server %s - %s\n",
323 cups_server(), strerror(errno)));
328 * Build an IPP_GET_PRINTER_ATTRS request, which requires the following
332 * attributes-natural-language
333 * requested-attributes
339 request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
340 request->request.op.request_id = 1;
342 language = cupsLangDefault();
344 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
345 "attributes-charset", NULL, cupsLangEncoding(language));
347 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
348 "attributes-natural-language", NULL, language->language);
350 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
351 "requested-attributes", NULL, "printer-uri");
353 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s", name);
355 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
356 "printer-uri", NULL, uri);
359 * Do the request and get back a response...
362 if ((response = cupsDoRequest(http, request, "/")) == NULL)
364 DEBUG(3,("Unable to get printer status for %s - %s\n", name,
365 ippErrorString(cupsLastError())));
372 if (response->request.status.status_code >= IPP_OK_CONFLICT)
374 DEBUG(3,("Unable to get printer status for %s - %s\n", name,
375 ippErrorString(response->request.status.status_code)));
388 * 'cups_job_delete()' - Delete a job.
392 cups_job_delete(int snum, struct printjob *pjob)
394 int ret; /* Return value */
395 http_t *http; /* HTTP connection to server */
396 ipp_t *request, /* IPP Request */
397 *response; /* IPP Response */
398 cups_lang_t *language; /* Default language */
399 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
402 DEBUG(5,("cups_job_delete(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
405 * Make sure we don't ask for passwords...
408 cupsSetPasswordCB(cups_passwd_cb);
411 * Try to connect to the server...
414 if ((http = httpConnect(cups_server(), ippPort())) == NULL)
416 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
417 cups_server(), strerror(errno)));
422 * Build an IPP_CANCEL_JOB request, which requires the following
426 * attributes-natural-language
428 * requesting-user-name
433 request->request.op.operation_id = IPP_CANCEL_JOB;
434 request->request.op.request_id = 1;
436 language = cupsLangDefault();
438 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
439 "attributes-charset", NULL, cupsLangEncoding(language));
441 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
442 "attributes-natural-language", NULL, language->language);
444 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
446 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
448 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
452 * Do the request and get back a response...
457 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL)
459 if (response->request.status.status_code >= IPP_OK_CONFLICT)
460 DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob,
461 ippErrorString(cupsLastError())));
468 DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob,
469 ippErrorString(cupsLastError())));
478 * 'cups_job_pause()' - Pause a job.
482 cups_job_pause(int snum, struct printjob *pjob)
484 int ret; /* Return value */
485 http_t *http; /* HTTP connection to server */
486 ipp_t *request, /* IPP Request */
487 *response; /* IPP Response */
488 cups_lang_t *language; /* Default language */
489 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
492 DEBUG(5,("cups_job_pause(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
495 * Make sure we don't ask for passwords...
498 cupsSetPasswordCB(cups_passwd_cb);
501 * Try to connect to the server...
504 if ((http = httpConnect(cups_server(), ippPort())) == NULL)
506 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
507 cups_server(), strerror(errno)));
512 * Build an IPP_HOLD_JOB request, which requires the following
516 * attributes-natural-language
518 * requesting-user-name
523 request->request.op.operation_id = IPP_HOLD_JOB;
524 request->request.op.request_id = 1;
526 language = cupsLangDefault();
528 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
529 "attributes-charset", NULL, cupsLangEncoding(language));
531 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
532 "attributes-natural-language", NULL, language->language);
534 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
536 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
538 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
542 * Do the request and get back a response...
547 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL)
549 if (response->request.status.status_code >= IPP_OK_CONFLICT)
550 DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob,
551 ippErrorString(cupsLastError())));
558 DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob,
559 ippErrorString(cupsLastError())));
568 * 'cups_job_resume()' - Resume a paused job.
572 cups_job_resume(int snum, struct printjob *pjob)
574 int ret; /* Return value */
575 http_t *http; /* HTTP connection to server */
576 ipp_t *request, /* IPP Request */
577 *response; /* IPP Response */
578 cups_lang_t *language; /* Default language */
579 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
582 DEBUG(5,("cups_job_resume(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
585 * Make sure we don't ask for passwords...
588 cupsSetPasswordCB(cups_passwd_cb);
591 * Try to connect to the server...
594 if ((http = httpConnect(cups_server(), ippPort())) == NULL)
596 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
597 cups_server(), strerror(errno)));
602 * Build an IPP_RELEASE_JOB request, which requires the following
606 * attributes-natural-language
608 * requesting-user-name
613 request->request.op.operation_id = IPP_RELEASE_JOB;
614 request->request.op.request_id = 1;
616 language = cupsLangDefault();
618 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
619 "attributes-charset", NULL, cupsLangEncoding(language));
621 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
622 "attributes-natural-language", NULL, language->language);
624 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
626 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
628 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
632 * Do the request and get back a response...
637 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL)
639 if (response->request.status.status_code >= IPP_OK_CONFLICT)
640 DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob,
641 ippErrorString(cupsLastError())));
648 DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob,
649 ippErrorString(cupsLastError())));
658 * 'cups_job_submit()' - Submit a job for printing.
662 cups_job_submit(int snum, struct printjob *pjob)
664 int ret; /* Return value */
665 http_t *http; /* HTTP connection to server */
666 ipp_t *request, /* IPP Request */
667 *response; /* IPP Response */
668 cups_lang_t *language; /* Default language */
669 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
670 char *clientname; /* hostname of client for job-originating-host attribute */
673 cups_option_t *options;
675 DEBUG(5,("cups_job_submit(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
678 * Make sure we don't ask for passwords...
681 cupsSetPasswordCB(cups_passwd_cb);
684 * Try to connect to the server...
687 if ((http = httpConnect(cups_server(), ippPort())) == NULL)
689 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
690 cups_server(), strerror(errno)));
695 * Build an IPP_PRINT_JOB request, which requires the following
699 * attributes-natural-language
701 * requesting-user-name
707 request->request.op.operation_id = IPP_PRINT_JOB;
708 request->request.op.request_id = 1;
710 language = cupsLangDefault();
712 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
713 "attributes-charset", NULL, cupsLangEncoding(language));
715 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
716 "attributes-natural-language", NULL, language->language);
718 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
721 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
722 "printer-uri", NULL, uri);
724 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
727 clientname = client_name();
728 if (strcmp(clientname, "UNKNOWN") == 0) {
729 clientname = client_addr();
732 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
733 "job-originating-host-name", NULL,
736 pstr_sprintf(new_jobname,"%s%.8u %s", PRINT_SPOOL_PREFIX,
737 (unsigned int)pjob->smbjob, pjob->jobname);
739 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "job-name", NULL,
743 * add any options defined in smb.conf
748 num_options = cupsParseOptions(lp_cups_options(snum), num_options, &options);
751 cupsEncodeOptions(request, num_options, options);
754 * Do the request and get back a response...
757 slprintf(uri, sizeof(uri) - 1, "/printers/%s", PRINTERNAME(snum));
760 if ((response = cupsDoFileRequest(http, request, uri,
761 pjob->filename)) != NULL)
763 if (response->request.status.status_code >= IPP_OK_CONFLICT)
764 DEBUG(0,("Unable to print file to %s - %s\n", PRINTERNAME(snum),
765 ippErrorString(cupsLastError())));
772 DEBUG(0,("Unable to print file to `%s' - %s\n", PRINTERNAME(snum),
773 ippErrorString(cupsLastError())));
778 unlink(pjob->filename);
779 /* else print_job_end will do it for us */
785 * 'cups_queue_get()' - Get all the jobs in the print queue.
789 cups_queue_get(const char *printer_name,
790 enum printing_types printing_type,
792 print_queue_struct **q,
793 print_status_struct *status)
795 http_t *http; /* HTTP connection to server */
796 ipp_t *request, /* IPP Request */
797 *response; /* IPP Response */
798 ipp_attribute_t *attr; /* Current attribute */
799 cups_lang_t *language; /* Default language */
800 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
801 int qcount, /* Number of active queue entries */
802 qalloc; /* Number of queue entries allocated */
803 print_queue_struct *queue, /* Queue entries */
804 *temp; /* Temporary pointer for queue */
805 const char *user_name, /* job-originating-user-name attribute */
806 *job_name; /* job-name attribute */
807 int job_id; /* job-id attribute */
808 int job_k_octets; /* job-k-octets attribute */
809 time_t job_time; /* time-at-creation attribute */
810 ipp_jstate_t job_status; /* job-status attribute */
811 int job_priority; /* job-priority attribute */
812 static const char *jattrs[] = /* Requested job attributes */
817 "job-originating-user-name",
822 static const char *pattrs[] = /* Requested printer attributes */
825 "printer-state-message"
829 DEBUG(5,("cups_queue_get(%s, %p, %p)\n", printer_name, q, status));
832 * Make sure we don't ask for passwords...
835 cupsSetPasswordCB(cups_passwd_cb);
838 * Try to connect to the server...
841 if ((http = httpConnect(cups_server(), ippPort())) == NULL)
843 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
844 cups_server(), strerror(errno)));
849 * Generate the printer URI...
852 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s", printer_name);
855 * Build an IPP_GET_JOBS request, which requires the following
859 * attributes-natural-language
860 * requested-attributes
866 request->request.op.operation_id = IPP_GET_JOBS;
867 request->request.op.request_id = 1;
869 language = cupsLangDefault();
871 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
872 "attributes-charset", NULL, cupsLangEncoding(language));
874 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
875 "attributes-natural-language", NULL, language->language);
877 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
878 "requested-attributes",
879 (sizeof(jattrs) / sizeof(jattrs[0])),
882 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
883 "printer-uri", NULL, uri);
886 * Do the request and get back a response...
889 if ((response = cupsDoRequest(http, request, "/")) == NULL)
891 DEBUG(0,("Unable to get jobs for %s - %s\n", uri,
892 ippErrorString(cupsLastError())));
897 if (response->request.status.status_code >= IPP_OK_CONFLICT)
899 DEBUG(0,("Unable to get jobs for %s - %s\n", uri,
900 ippErrorString(response->request.status.status_code)));
908 * Process the jobs...
915 for (attr = response->attrs; attr != NULL; attr = attr->next)
918 * Skip leading attributes until we hit a job...
921 while (attr != NULL && attr->group_tag != IPP_TAG_JOB)
928 * Allocate memory as needed...
930 if (qcount >= qalloc)
934 temp = Realloc(queue, sizeof(print_queue_struct) * qalloc);
938 DEBUG(0,("cups_queue_get: Not enough memory!"));
949 temp = queue + qcount;
950 memset(temp, 0, sizeof(print_queue_struct));
953 * Pull the needed attributes from this job...
958 job_status = IPP_JOB_PENDING;
964 while (attr != NULL && attr->group_tag == IPP_TAG_JOB)
966 if (attr->name == NULL)
972 if (strcmp(attr->name, "job-id") == 0 &&
973 attr->value_tag == IPP_TAG_INTEGER)
974 job_id = attr->values[0].integer;
976 if (strcmp(attr->name, "job-k-octets") == 0 &&
977 attr->value_tag == IPP_TAG_INTEGER)
978 job_k_octets = attr->values[0].integer;
980 if (strcmp(attr->name, "job-priority") == 0 &&
981 attr->value_tag == IPP_TAG_INTEGER)
982 job_priority = attr->values[0].integer;
984 if (strcmp(attr->name, "job-state") == 0 &&
985 attr->value_tag == IPP_TAG_ENUM)
986 job_status = (ipp_jstate_t)(attr->values[0].integer);
988 if (strcmp(attr->name, "time-at-creation") == 0 &&
989 attr->value_tag == IPP_TAG_INTEGER)
990 job_time = attr->values[0].integer;
992 if (strcmp(attr->name, "job-name") == 0 &&
993 attr->value_tag == IPP_TAG_NAME)
994 job_name = attr->values[0].string.text;
996 if (strcmp(attr->name, "job-originating-user-name") == 0 &&
997 attr->value_tag == IPP_TAG_NAME)
998 user_name = attr->values[0].string.text;
1004 * See if we have everything needed...
1007 if (user_name == NULL || job_name == NULL || job_id == 0)
1016 temp->size = job_k_octets * 1024;
1017 temp->status = job_status == IPP_JOB_PENDING ? LPQ_QUEUED :
1018 job_status == IPP_JOB_STOPPED ? LPQ_PAUSED :
1019 job_status == IPP_JOB_HELD ? LPQ_PAUSED :
1021 temp->priority = job_priority;
1022 temp->time = job_time;
1023 strncpy(temp->fs_user, user_name, sizeof(temp->fs_user) - 1);
1024 strncpy(temp->fs_file, job_name, sizeof(temp->fs_file) - 1);
1032 ippDelete(response);
1035 * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the
1036 * following attributes:
1038 * attributes-charset
1039 * attributes-natural-language
1040 * requested-attributes
1046 request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
1047 request->request.op.request_id = 1;
1049 language = cupsLangDefault();
1051 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1052 "attributes-charset", NULL, cupsLangEncoding(language));
1054 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1055 "attributes-natural-language", NULL, language->language);
1057 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
1058 "requested-attributes",
1059 (sizeof(pattrs) / sizeof(pattrs[0])),
1062 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
1063 "printer-uri", NULL, uri);
1066 * Do the request and get back a response...
1069 if ((response = cupsDoRequest(http, request, "/")) == NULL)
1071 DEBUG(0,("Unable to get printer status for %s - %s\n", printer_name,
1072 ippErrorString(cupsLastError())));
1078 if (response->request.status.status_code >= IPP_OK_CONFLICT)
1080 DEBUG(0,("Unable to get printer status for %s - %s\n", printer_name,
1081 ippErrorString(response->request.status.status_code)));
1082 ippDelete(response);
1089 * Get the current printer status and convert it to the SAMBA values.
1092 if ((attr = ippFindAttribute(response, "printer-state", IPP_TAG_ENUM)) != NULL)
1094 if (attr->values[0].integer == IPP_PRINTER_STOPPED)
1095 status->status = LPSTAT_STOPPED;
1097 status->status = LPSTAT_OK;
1100 if ((attr = ippFindAttribute(response, "printer-state-message",
1101 IPP_TAG_TEXT)) != NULL)
1102 fstrcpy(status->message, attr->values[0].string.text);
1104 ippDelete(response);
1107 * Return the job queue...
1118 * 'cups_queue_pause()' - Pause a print queue.
1122 cups_queue_pause(int snum)
1124 extern userdom_struct current_user_info;
1125 int ret; /* Return value */
1126 http_t *http; /* HTTP connection to server */
1127 ipp_t *request, /* IPP Request */
1128 *response; /* IPP Response */
1129 cups_lang_t *language; /* Default language */
1130 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
1133 DEBUG(5,("cups_queue_pause(%d)\n", snum));
1136 * Make sure we don't ask for passwords...
1139 cupsSetPasswordCB(cups_passwd_cb);
1142 * Try to connect to the server...
1145 if ((http = httpConnect(cups_server(), ippPort())) == NULL)
1147 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
1148 cups_server(), strerror(errno)));
1153 * Build an IPP_PAUSE_PRINTER request, which requires the following
1156 * attributes-charset
1157 * attributes-natural-language
1159 * requesting-user-name
1164 request->request.op.operation_id = IPP_PAUSE_PRINTER;
1165 request->request.op.request_id = 1;
1167 language = cupsLangDefault();
1169 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1170 "attributes-charset", NULL, cupsLangEncoding(language));
1172 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1173 "attributes-natural-language", NULL, language->language);
1175 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
1178 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
1180 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
1181 NULL, current_user_info.unix_name);
1184 * Do the request and get back a response...
1189 if ((response = cupsDoRequest(http, request, "/admin/")) != NULL)
1191 if (response->request.status.status_code >= IPP_OK_CONFLICT)
1192 DEBUG(0,("Unable to pause printer %s - %s\n", PRINTERNAME(snum),
1193 ippErrorString(cupsLastError())));
1197 ippDelete(response);
1200 DEBUG(0,("Unable to pause printer %s - %s\n", PRINTERNAME(snum),
1201 ippErrorString(cupsLastError())));
1210 * 'cups_queue_resume()' - Restart a print queue.
1214 cups_queue_resume(int snum)
1216 extern userdom_struct current_user_info;
1217 int ret; /* Return value */
1218 http_t *http; /* HTTP connection to server */
1219 ipp_t *request, /* IPP Request */
1220 *response; /* IPP Response */
1221 cups_lang_t *language; /* Default language */
1222 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
1225 DEBUG(5,("cups_queue_resume(%d)\n", snum));
1228 * Make sure we don't ask for passwords...
1231 cupsSetPasswordCB(cups_passwd_cb);
1234 * Try to connect to the server...
1237 if ((http = httpConnect(cups_server(), ippPort())) == NULL)
1239 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
1240 cups_server(), strerror(errno)));
1245 * Build an IPP_RESUME_PRINTER request, which requires the following
1248 * attributes-charset
1249 * attributes-natural-language
1251 * requesting-user-name
1256 request->request.op.operation_id = IPP_RESUME_PRINTER;
1257 request->request.op.request_id = 1;
1259 language = cupsLangDefault();
1261 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1262 "attributes-charset", NULL, cupsLangEncoding(language));
1264 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1265 "attributes-natural-language", NULL, language->language);
1267 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
1270 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
1272 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
1273 NULL, current_user_info.unix_name);
1276 * Do the request and get back a response...
1281 if ((response = cupsDoRequest(http, request, "/admin/")) != NULL)
1283 if (response->request.status.status_code >= IPP_OK_CONFLICT)
1284 DEBUG(0,("Unable to resume printer %s - %s\n", PRINTERNAME(snum),
1285 ippErrorString(cupsLastError())));
1289 ippDelete(response);
1292 DEBUG(0,("Unable to resume printer %s - %s\n", PRINTERNAME(snum),
1293 ippErrorString(cupsLastError())));
1300 /*******************************************************************
1301 * CUPS printing interface definitions...
1302 ******************************************************************/
1304 struct printif cups_printif =
1317 /* this keeps fussy compilers happy */
1318 void print_cups_dummy(void) {}
1319 #endif /* HAVE_CUPS */