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 *info; /* printer-info attribute */
70 static const char *requested[] =/* Requested attributes */
77 DEBUG(5,("cups_printer_fn(%p)\n", fn));
80 * Make sure we don't ask for passwords...
83 cupsSetPasswordCB(cups_passwd_cb);
86 * Try to connect to the server...
89 if ((http = httpConnect(cups_server(), ippPort())) == NULL)
91 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
92 cups_server(), strerror(errno)));
97 * Build a CUPS_GET_PRINTERS request, which requires the following
101 * attributes-natural-language
102 * requested-attributes
107 request->request.op.operation_id = CUPS_GET_PRINTERS;
108 request->request.op.request_id = 1;
110 language = cupsLangDefault();
112 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
113 "attributes-charset", NULL, cupsLangEncoding(language));
115 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
116 "attributes-natural-language", NULL, language->language);
118 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
119 "requested-attributes",
120 (sizeof(requested) / sizeof(requested[0])),
124 * Do the request and get back a response...
127 if ((response = cupsDoRequest(http, request, "/")) == NULL)
129 DEBUG(0,("Unable to get printer list - %s\n",
130 ippErrorString(cupsLastError())));
135 for (attr = response->attrs; attr != NULL;)
138 * Skip leading attributes until we hit a printer...
141 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
148 * Pull the needed attributes from this printer...
154 while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER)
156 if (strcmp(attr->name, "printer-name") == 0 &&
157 attr->value_tag == IPP_TAG_NAME)
158 name = attr->values[0].string.text;
160 if (strcmp(attr->name, "printer-info") == 0 &&
161 attr->value_tag == IPP_TAG_TEXT)
162 info = attr->values[0].string.text;
168 * See if we have everything needed...
181 * Build a CUPS_GET_CLASSES request, which requires the following
185 * attributes-natural-language
186 * requested-attributes
191 request->request.op.operation_id = CUPS_GET_CLASSES;
192 request->request.op.request_id = 1;
194 language = cupsLangDefault();
196 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
197 "attributes-charset", NULL, cupsLangEncoding(language));
199 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
200 "attributes-natural-language", NULL, language->language);
202 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
203 "requested-attributes",
204 (sizeof(requested) / sizeof(requested[0])),
208 * Do the request and get back a response...
211 if ((response = cupsDoRequest(http, request, "/")) == NULL)
213 DEBUG(0,("Unable to get printer list - %s\n",
214 ippErrorString(cupsLastError())));
219 for (attr = response->attrs; attr != NULL;)
222 * Skip leading attributes until we hit a printer...
225 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
232 * Pull the needed attributes from this printer...
238 while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER)
240 if (strcmp(attr->name, "printer-name") == 0 &&
241 attr->value_tag == IPP_TAG_NAME)
242 name = attr->values[0].string.text;
244 if (strcmp(attr->name, "printer-info") == 0 &&
245 attr->value_tag == IPP_TAG_TEXT)
246 info = attr->values[0].string.text;
252 * See if we have everything needed...
264 * Close the connection to the server...
272 * 'cups_printername_ok()' - Provide the equivalent of pcap_printername_ok()
274 * O - 1 if printer name OK
275 * I - Name of printer
277 int cups_printername_ok(const char *name)
279 http_t *http; /* HTTP connection to server */
280 ipp_t *request, /* IPP Request */
281 *response; /* IPP Response */
282 cups_lang_t *language; /* Default language */
283 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
286 DEBUG(5,("cups_printername_ok(\"%s\")\n", name));
289 * Make sure we don't ask for passwords...
292 cupsSetPasswordCB(cups_passwd_cb);
295 * Try to connect to the server...
298 if ((http = httpConnect(cups_server(), ippPort())) == NULL)
300 DEBUG(3,("Unable to connect to CUPS server %s - %s\n",
301 cups_server(), strerror(errno)));
306 * Build an IPP_GET_PRINTER_ATTRS request, which requires the following
310 * attributes-natural-language
311 * requested-attributes
317 request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
318 request->request.op.request_id = 1;
320 language = cupsLangDefault();
322 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
323 "attributes-charset", NULL, cupsLangEncoding(language));
325 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
326 "attributes-natural-language", NULL, language->language);
328 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
329 "requested-attributes", NULL, "printer-uri");
331 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s", name);
333 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
334 "printer-uri", NULL, uri);
337 * Do the request and get back a response...
340 if ((response = cupsDoRequest(http, request, "/")) == NULL)
342 DEBUG(3,("Unable to get printer status for %s - %s\n", name,
343 ippErrorString(cupsLastError())));
350 if (response->request.status.status_code >= IPP_OK_CONFLICT)
352 DEBUG(3,("Unable to get printer status for %s - %s\n", name,
353 ippErrorString(response->request.status.status_code)));
366 * 'cups_job_delete()' - Delete a job.
370 cups_job_delete(int snum, struct printjob *pjob)
372 int ret; /* Return value */
373 http_t *http; /* HTTP connection to server */
374 ipp_t *request, /* IPP Request */
375 *response; /* IPP Response */
376 cups_lang_t *language; /* Default language */
377 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
380 DEBUG(5,("cups_job_delete(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
383 * Make sure we don't ask for passwords...
386 cupsSetPasswordCB(cups_passwd_cb);
389 * Try to connect to the server...
392 if ((http = httpConnect(cups_server(), ippPort())) == NULL)
394 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
395 cups_server(), strerror(errno)));
400 * Build an IPP_CANCEL_JOB request, which requires the following
404 * attributes-natural-language
406 * requesting-user-name
411 request->request.op.operation_id = IPP_CANCEL_JOB;
412 request->request.op.request_id = 1;
414 language = cupsLangDefault();
416 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
417 "attributes-charset", NULL, cupsLangEncoding(language));
419 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
420 "attributes-natural-language", NULL, language->language);
422 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
424 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
426 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
430 * Do the request and get back a response...
435 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL)
437 if (response->request.status.status_code >= IPP_OK_CONFLICT)
438 DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob,
439 ippErrorString(cupsLastError())));
446 DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob,
447 ippErrorString(cupsLastError())));
456 * 'cups_job_pause()' - Pause a job.
460 cups_job_pause(int snum, struct printjob *pjob)
462 int ret; /* Return value */
463 http_t *http; /* HTTP connection to server */
464 ipp_t *request, /* IPP Request */
465 *response; /* IPP Response */
466 cups_lang_t *language; /* Default language */
467 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
470 DEBUG(5,("cups_job_pause(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
473 * Make sure we don't ask for passwords...
476 cupsSetPasswordCB(cups_passwd_cb);
479 * Try to connect to the server...
482 if ((http = httpConnect(cups_server(), ippPort())) == NULL)
484 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
485 cups_server(), strerror(errno)));
490 * Build an IPP_HOLD_JOB request, which requires the following
494 * attributes-natural-language
496 * requesting-user-name
501 request->request.op.operation_id = IPP_HOLD_JOB;
502 request->request.op.request_id = 1;
504 language = cupsLangDefault();
506 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
507 "attributes-charset", NULL, cupsLangEncoding(language));
509 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
510 "attributes-natural-language", NULL, language->language);
512 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
514 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
516 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
520 * Do the request and get back a response...
525 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL)
527 if (response->request.status.status_code >= IPP_OK_CONFLICT)
528 DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob,
529 ippErrorString(cupsLastError())));
536 DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob,
537 ippErrorString(cupsLastError())));
546 * 'cups_job_resume()' - Resume a paused job.
550 cups_job_resume(int snum, struct printjob *pjob)
552 int ret; /* Return value */
553 http_t *http; /* HTTP connection to server */
554 ipp_t *request, /* IPP Request */
555 *response; /* IPP Response */
556 cups_lang_t *language; /* Default language */
557 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
560 DEBUG(5,("cups_job_resume(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
563 * Make sure we don't ask for passwords...
566 cupsSetPasswordCB(cups_passwd_cb);
569 * Try to connect to the server...
572 if ((http = httpConnect(cups_server(), ippPort())) == NULL)
574 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
575 cups_server(), strerror(errno)));
580 * Build an IPP_RELEASE_JOB request, which requires the following
584 * attributes-natural-language
586 * requesting-user-name
591 request->request.op.operation_id = IPP_RELEASE_JOB;
592 request->request.op.request_id = 1;
594 language = cupsLangDefault();
596 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
597 "attributes-charset", NULL, cupsLangEncoding(language));
599 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
600 "attributes-natural-language", NULL, language->language);
602 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
604 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
606 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
610 * Do the request and get back a response...
615 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL)
617 if (response->request.status.status_code >= IPP_OK_CONFLICT)
618 DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob,
619 ippErrorString(cupsLastError())));
626 DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob,
627 ippErrorString(cupsLastError())));
636 * 'cups_job_submit()' - Submit a job for printing.
640 cups_job_submit(int snum, struct printjob *pjob)
642 int ret; /* Return value */
643 http_t *http; /* HTTP connection to server */
644 ipp_t *request, /* IPP Request */
645 *response; /* IPP Response */
646 cups_lang_t *language; /* Default language */
647 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
648 char *clientname; /* hostname of client for job-originating-host attribute */
651 cups_option_t *options;
653 DEBUG(5,("cups_job_submit(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
656 * Make sure we don't ask for passwords...
659 cupsSetPasswordCB(cups_passwd_cb);
662 * Try to connect to the server...
665 if ((http = httpConnect(cups_server(), ippPort())) == NULL)
667 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
668 cups_server(), strerror(errno)));
673 * Build an IPP_PRINT_JOB request, which requires the following
677 * attributes-natural-language
679 * requesting-user-name
685 request->request.op.operation_id = IPP_PRINT_JOB;
686 request->request.op.request_id = 1;
688 language = cupsLangDefault();
690 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
691 "attributes-charset", NULL, cupsLangEncoding(language));
693 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
694 "attributes-natural-language", NULL, language->language);
696 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
699 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
700 "printer-uri", NULL, uri);
702 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
705 clientname = client_name();
706 if (strcmp(clientname, "UNKNOWN") == 0) {
707 clientname = client_addr();
710 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
711 "job-originating-host-name", NULL,
714 pstr_sprintf(new_jobname,"%s%.8u %s", PRINT_SPOOL_PREFIX,
715 (unsigned int)pjob->smbjob, pjob->jobname);
717 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "job-name", NULL,
721 * add any options defined in smb.conf
726 num_options = cupsParseOptions(lp_cups_options(snum), num_options, &options);
729 cupsEncodeOptions(request, num_options, options);
732 * Do the request and get back a response...
735 slprintf(uri, sizeof(uri) - 1, "/printers/%s", PRINTERNAME(snum));
738 if ((response = cupsDoFileRequest(http, request, uri,
739 pjob->filename)) != NULL)
741 if (response->request.status.status_code >= IPP_OK_CONFLICT)
742 DEBUG(0,("Unable to print file to %s - %s\n", PRINTERNAME(snum),
743 ippErrorString(cupsLastError())));
750 DEBUG(0,("Unable to print file to `%s' - %s\n", PRINTERNAME(snum),
751 ippErrorString(cupsLastError())));
756 unlink(pjob->filename);
757 /* else print_job_end will do it for us */
763 * 'cups_queue_get()' - Get all the jobs in the print queue.
767 cups_queue_get(const char *printer_name,
768 enum printing_types printing_type,
770 print_queue_struct **q,
771 print_status_struct *status)
773 http_t *http; /* HTTP connection to server */
774 ipp_t *request, /* IPP Request */
775 *response; /* IPP Response */
776 ipp_attribute_t *attr; /* Current attribute */
777 cups_lang_t *language; /* Default language */
778 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
779 int qcount, /* Number of active queue entries */
780 qalloc; /* Number of queue entries allocated */
781 print_queue_struct *queue, /* Queue entries */
782 *temp; /* Temporary pointer for queue */
783 const char *user_name, /* job-originating-user-name attribute */
784 *job_name; /* job-name attribute */
785 int job_id; /* job-id attribute */
786 int job_k_octets; /* job-k-octets attribute */
787 time_t job_time; /* time-at-creation attribute */
788 ipp_jstate_t job_status; /* job-status attribute */
789 int job_priority; /* job-priority attribute */
790 static const char *jattrs[] = /* Requested job attributes */
795 "job-originating-user-name",
800 static const char *pattrs[] = /* Requested printer attributes */
803 "printer-state-message"
807 DEBUG(5,("cups_queue_get(%s, %p, %p)\n", printer_name, q, status));
810 * Make sure we don't ask for passwords...
813 cupsSetPasswordCB(cups_passwd_cb);
816 * Try to connect to the server...
819 if ((http = httpConnect(cups_server(), ippPort())) == NULL)
821 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
822 cups_server(), strerror(errno)));
827 * Generate the printer URI...
830 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s", printer_name);
833 * Build an IPP_GET_JOBS request, which requires the following
837 * attributes-natural-language
838 * requested-attributes
844 request->request.op.operation_id = IPP_GET_JOBS;
845 request->request.op.request_id = 1;
847 language = cupsLangDefault();
849 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
850 "attributes-charset", NULL, cupsLangEncoding(language));
852 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
853 "attributes-natural-language", NULL, language->language);
855 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
856 "requested-attributes",
857 (sizeof(jattrs) / sizeof(jattrs[0])),
860 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
861 "printer-uri", NULL, uri);
864 * Do the request and get back a response...
867 if ((response = cupsDoRequest(http, request, "/")) == NULL)
869 DEBUG(0,("Unable to get jobs for %s - %s\n", uri,
870 ippErrorString(cupsLastError())));
875 if (response->request.status.status_code >= IPP_OK_CONFLICT)
877 DEBUG(0,("Unable to get jobs for %s - %s\n", uri,
878 ippErrorString(response->request.status.status_code)));
886 * Process the jobs...
893 for (attr = response->attrs; attr != NULL; attr = attr->next)
896 * Skip leading attributes until we hit a job...
899 while (attr != NULL && attr->group_tag != IPP_TAG_JOB)
906 * Allocate memory as needed...
908 if (qcount >= qalloc)
912 temp = Realloc(queue, sizeof(print_queue_struct) * qalloc);
916 DEBUG(0,("cups_queue_get: Not enough memory!"));
927 temp = queue + qcount;
928 memset(temp, 0, sizeof(print_queue_struct));
931 * Pull the needed attributes from this job...
936 job_status = IPP_JOB_PENDING;
942 while (attr != NULL && attr->group_tag == IPP_TAG_JOB)
944 if (attr->name == NULL)
950 if (strcmp(attr->name, "job-id") == 0 &&
951 attr->value_tag == IPP_TAG_INTEGER)
952 job_id = attr->values[0].integer;
954 if (strcmp(attr->name, "job-k-octets") == 0 &&
955 attr->value_tag == IPP_TAG_INTEGER)
956 job_k_octets = attr->values[0].integer;
958 if (strcmp(attr->name, "job-priority") == 0 &&
959 attr->value_tag == IPP_TAG_INTEGER)
960 job_priority = attr->values[0].integer;
962 if (strcmp(attr->name, "job-state") == 0 &&
963 attr->value_tag == IPP_TAG_ENUM)
964 job_status = (ipp_jstate_t)(attr->values[0].integer);
966 if (strcmp(attr->name, "time-at-creation") == 0 &&
967 attr->value_tag == IPP_TAG_INTEGER)
968 job_time = attr->values[0].integer;
970 if (strcmp(attr->name, "job-name") == 0 &&
971 attr->value_tag == IPP_TAG_NAME)
972 job_name = attr->values[0].string.text;
974 if (strcmp(attr->name, "job-originating-user-name") == 0 &&
975 attr->value_tag == IPP_TAG_NAME)
976 user_name = attr->values[0].string.text;
982 * See if we have everything needed...
985 if (user_name == NULL || job_name == NULL || job_id == 0)
994 temp->size = job_k_octets * 1024;
995 temp->status = job_status == IPP_JOB_PENDING ? LPQ_QUEUED :
996 job_status == IPP_JOB_STOPPED ? LPQ_PAUSED :
997 job_status == IPP_JOB_HELD ? LPQ_PAUSED :
999 temp->priority = job_priority;
1000 temp->time = job_time;
1001 strncpy(temp->fs_user, user_name, sizeof(temp->fs_user) - 1);
1002 strncpy(temp->fs_file, job_name, sizeof(temp->fs_file) - 1);
1010 ippDelete(response);
1013 * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the
1014 * following attributes:
1016 * attributes-charset
1017 * attributes-natural-language
1018 * requested-attributes
1024 request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
1025 request->request.op.request_id = 1;
1027 language = cupsLangDefault();
1029 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1030 "attributes-charset", NULL, cupsLangEncoding(language));
1032 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1033 "attributes-natural-language", NULL, language->language);
1035 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
1036 "requested-attributes",
1037 (sizeof(pattrs) / sizeof(pattrs[0])),
1040 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
1041 "printer-uri", NULL, uri);
1044 * Do the request and get back a response...
1047 if ((response = cupsDoRequest(http, request, "/")) == NULL)
1049 DEBUG(0,("Unable to get printer status for %s - %s\n", printer_name,
1050 ippErrorString(cupsLastError())));
1056 if (response->request.status.status_code >= IPP_OK_CONFLICT)
1058 DEBUG(0,("Unable to get printer status for %s - %s\n", printer_name,
1059 ippErrorString(response->request.status.status_code)));
1060 ippDelete(response);
1067 * Get the current printer status and convert it to the SAMBA values.
1070 if ((attr = ippFindAttribute(response, "printer-state", IPP_TAG_ENUM)) != NULL)
1072 if (attr->values[0].integer == IPP_PRINTER_STOPPED)
1073 status->status = LPSTAT_STOPPED;
1075 status->status = LPSTAT_OK;
1078 if ((attr = ippFindAttribute(response, "printer-state-message",
1079 IPP_TAG_TEXT)) != NULL)
1080 fstrcpy(status->message, attr->values[0].string.text);
1082 ippDelete(response);
1085 * Return the job queue...
1096 * 'cups_queue_pause()' - Pause a print queue.
1100 cups_queue_pause(int snum)
1102 extern userdom_struct current_user_info;
1103 int ret; /* Return value */
1104 http_t *http; /* HTTP connection to server */
1105 ipp_t *request, /* IPP Request */
1106 *response; /* IPP Response */
1107 cups_lang_t *language; /* Default language */
1108 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
1111 DEBUG(5,("cups_queue_pause(%d)\n", snum));
1114 * Make sure we don't ask for passwords...
1117 cupsSetPasswordCB(cups_passwd_cb);
1120 * Try to connect to the server...
1123 if ((http = httpConnect(cups_server(), ippPort())) == NULL)
1125 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
1126 cups_server(), strerror(errno)));
1131 * Build an IPP_PAUSE_PRINTER request, which requires the following
1134 * attributes-charset
1135 * attributes-natural-language
1137 * requesting-user-name
1142 request->request.op.operation_id = IPP_PAUSE_PRINTER;
1143 request->request.op.request_id = 1;
1145 language = cupsLangDefault();
1147 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1148 "attributes-charset", NULL, cupsLangEncoding(language));
1150 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1151 "attributes-natural-language", NULL, language->language);
1153 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
1156 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
1158 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
1159 NULL, current_user_info.unix_name);
1162 * Do the request and get back a response...
1167 if ((response = cupsDoRequest(http, request, "/admin/")) != NULL)
1169 if (response->request.status.status_code >= IPP_OK_CONFLICT)
1170 DEBUG(0,("Unable to pause printer %s - %s\n", PRINTERNAME(snum),
1171 ippErrorString(cupsLastError())));
1175 ippDelete(response);
1178 DEBUG(0,("Unable to pause printer %s - %s\n", PRINTERNAME(snum),
1179 ippErrorString(cupsLastError())));
1188 * 'cups_queue_resume()' - Restart a print queue.
1192 cups_queue_resume(int snum)
1194 extern userdom_struct current_user_info;
1195 int ret; /* Return value */
1196 http_t *http; /* HTTP connection to server */
1197 ipp_t *request, /* IPP Request */
1198 *response; /* IPP Response */
1199 cups_lang_t *language; /* Default language */
1200 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
1203 DEBUG(5,("cups_queue_resume(%d)\n", snum));
1206 * Make sure we don't ask for passwords...
1209 cupsSetPasswordCB(cups_passwd_cb);
1212 * Try to connect to the server...
1215 if ((http = httpConnect(cups_server(), ippPort())) == NULL)
1217 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
1218 cups_server(), strerror(errno)));
1223 * Build an IPP_RESUME_PRINTER request, which requires the following
1226 * attributes-charset
1227 * attributes-natural-language
1229 * requesting-user-name
1234 request->request.op.operation_id = IPP_RESUME_PRINTER;
1235 request->request.op.request_id = 1;
1237 language = cupsLangDefault();
1239 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1240 "attributes-charset", NULL, cupsLangEncoding(language));
1242 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1243 "attributes-natural-language", NULL, language->language);
1245 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
1248 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
1250 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
1251 NULL, current_user_info.unix_name);
1254 * Do the request and get back a response...
1259 if ((response = cupsDoRequest(http, request, "/admin/")) != NULL)
1261 if (response->request.status.status_code >= IPP_OK_CONFLICT)
1262 DEBUG(0,("Unable to resume printer %s - %s\n", PRINTERNAME(snum),
1263 ippErrorString(cupsLastError())));
1267 ippDelete(response);
1270 DEBUG(0,("Unable to resume printer %s - %s\n", PRINTERNAME(snum),
1271 ippErrorString(cupsLastError())));
1278 /*******************************************************************
1279 * CUPS printing interface definitions...
1280 ******************************************************************/
1282 struct printif cups_printif =
1295 /* this keeps fussy compilers happy */
1296 void print_cups_dummy(void) {}
1297 #endif /* HAVE_CUPS */