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 printing interface definitions...
33 static int cups_job_delete(int snum, struct printjob *pjob);
34 static int cups_job_pause(int snum, struct printjob *pjob);
35 static int cups_job_resume(int snum, struct printjob *pjob);
36 static int cups_job_submit(int snum, struct printjob *pjob);
37 static int cups_queue_get(int snum, print_queue_struct **q,
38 print_status_struct *status);
39 static int cups_queue_pause(int snum);
40 static int cups_queue_resume(int snum);
43 struct printif cups_printif =
55 * 'cups_passwd_cb()' - The CUPS password callback...
58 static const char * /* O - Password or NULL */
59 cups_passwd_cb(const char *prompt) /* I - Prompt */
62 * Always return NULL to indicate that no password is available...
70 * 'cups_printer_fn()' - Call a function for every printer known to the
74 void cups_printer_fn(void (*fn)(char *, char *))
76 /* I - Function to call */
77 http_t *http; /* HTTP connection to server */
78 ipp_t *request, /* IPP Request */
79 *response; /* IPP Response */
80 ipp_attribute_t *attr; /* Current attribute */
81 cups_lang_t *language; /* Default language */
82 char *name, /* printer-name attribute */
83 *make_model, /* printer-make-and-model attribute */
84 *info; /* printer-info attribute */
85 static const char *requested[] =/* Requested attributes */
88 "printer-make-and-model",
93 DEBUG(5,("cups_printer_fn(%p)\n", fn));
96 * Make sure we don't ask for passwords...
99 cupsSetPasswordCB(cups_passwd_cb);
102 * Try to connect to the server...
105 if ((http = httpConnect(cupsServer(), ippPort())) == NULL)
107 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
108 cupsServer(), strerror(errno)));
113 * Build a CUPS_GET_PRINTERS request, which requires the following
117 * attributes-natural-language
118 * requested-attributes
123 request->request.op.operation_id = CUPS_GET_PRINTERS;
124 request->request.op.request_id = 1;
126 language = cupsLangDefault();
128 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
129 "attributes-charset", NULL, cupsLangEncoding(language));
131 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
132 "attributes-natural-language", NULL, language->language);
134 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
135 "requested-attributes",
136 (sizeof(requested) / sizeof(requested[0])),
140 * Do the request and get back a response...
143 if ((response = cupsDoRequest(http, request, "/")) == NULL)
145 DEBUG(0,("Unable to get printer list - %s\n",
146 ippErrorString(cupsLastError())));
151 for (attr = response->attrs; attr != NULL;)
154 * Skip leading attributes until we hit a printer...
157 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
164 * Pull the needed attributes from this printer...
171 while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER)
173 if (strcmp(attr->name, "printer-name") == 0 &&
174 attr->value_tag == IPP_TAG_NAME)
175 name = attr->values[0].string.text;
177 if (strcmp(attr->name, "printer-make-and-model") == 0 &&
178 attr->value_tag == IPP_TAG_TEXT)
179 make_model = attr->values[0].string.text;
181 if (strcmp(attr->name, "printer-info") == 0 &&
182 attr->value_tag == IPP_TAG_TEXT)
183 info = attr->values[0].string.text;
189 * See if we have everything needed...
195 if (info == NULL || !info[0])
196 (*fn)(name, make_model);
207 * Build a CUPS_GET_CLASSES request, which requires the following
211 * attributes-natural-language
212 * requested-attributes
217 request->request.op.operation_id = CUPS_GET_CLASSES;
218 request->request.op.request_id = 1;
220 language = cupsLangDefault();
222 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
223 "attributes-charset", NULL, cupsLangEncoding(language));
225 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
226 "attributes-natural-language", NULL, language->language);
228 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
229 "requested-attributes",
230 (sizeof(requested) / sizeof(requested[0])),
234 * Do the request and get back a response...
237 if ((response = cupsDoRequest(http, request, "/")) == NULL)
239 DEBUG(0,("Unable to get printer list - %s\n",
240 ippErrorString(cupsLastError())));
245 for (attr = response->attrs; attr != NULL;)
248 * Skip leading attributes until we hit a printer...
251 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
258 * Pull the needed attributes from this printer...
265 while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER)
267 if (strcmp(attr->name, "printer-name") == 0 &&
268 attr->value_tag == IPP_TAG_NAME)
269 name = attr->values[0].string.text;
271 if (strcmp(attr->name, "printer-make-and-model") == 0 &&
272 attr->value_tag == IPP_TAG_TEXT)
273 make_model = attr->values[0].string.text;
275 if (strcmp(attr->name, "printer-info") == 0 &&
276 attr->value_tag == IPP_TAG_TEXT)
277 info = attr->values[0].string.text;
283 * See if we have everything needed...
289 if (info == NULL || !info[0])
290 (*fn)(name, make_model);
300 * Close the connection to the server...
308 * 'cups_printername_ok()' - Provide the equivalent of pcap_printername_ok()
310 * O - 1 if printer name OK
311 * I - Name of printer
313 int cups_printername_ok(const char *name)
315 http_t *http; /* HTTP connection to server */
316 ipp_t *request, /* IPP Request */
317 *response; /* IPP Response */
318 cups_lang_t *language; /* Default language */
319 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
322 DEBUG(5,("cups_printername_ok(\"%s\")\n", name));
325 * Make sure we don't ask for passwords...
328 cupsSetPasswordCB(cups_passwd_cb);
331 * Try to connect to the server...
334 if ((http = httpConnect(cupsServer(), ippPort())) == NULL)
336 DEBUG(3,("Unable to connect to CUPS server %s - %s\n",
337 cupsServer(), strerror(errno)));
342 * Build an IPP_GET_PRINTER_ATTRS request, which requires the following
346 * attributes-natural-language
347 * requested-attributes
353 request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
354 request->request.op.request_id = 1;
356 language = cupsLangDefault();
358 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
359 "attributes-charset", NULL, cupsLangEncoding(language));
361 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
362 "attributes-natural-language", NULL, language->language);
364 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
365 "requested-attributes", NULL, "printer-uri");
367 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s", name);
369 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
370 "printer-uri", NULL, uri);
373 * Do the request and get back a response...
376 if ((response = cupsDoRequest(http, request, "/")) == NULL)
378 DEBUG(3,("Unable to get printer status for %s - %s\n", name,
379 ippErrorString(cupsLastError())));
386 if (response->request.status.status_code >= IPP_OK_CONFLICT)
388 DEBUG(3,("Unable to get printer status for %s - %s\n", name,
389 ippErrorString(response->request.status.status_code)));
402 * 'cups_job_delete()' - Delete a job.
406 cups_job_delete(int snum, struct printjob *pjob)
408 int ret; /* Return value */
409 http_t *http; /* HTTP connection to server */
410 ipp_t *request, /* IPP Request */
411 *response; /* IPP Response */
412 cups_lang_t *language; /* Default language */
413 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
416 DEBUG(5,("cups_job_delete(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
419 * Make sure we don't ask for passwords...
422 cupsSetPasswordCB(cups_passwd_cb);
425 * Try to connect to the server...
428 if ((http = httpConnect(cupsServer(), ippPort())) == NULL)
430 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
431 cupsServer(), strerror(errno)));
436 * Build an IPP_CANCEL_JOB request, which requires the following
440 * attributes-natural-language
442 * requesting-user-name
447 request->request.op.operation_id = IPP_CANCEL_JOB;
448 request->request.op.request_id = 1;
450 language = cupsLangDefault();
452 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
453 "attributes-charset", NULL, cupsLangEncoding(language));
455 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
456 "attributes-natural-language", NULL, language->language);
458 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
460 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
462 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
466 * Do the request and get back a response...
471 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL)
473 if (response->request.status.status_code >= IPP_OK_CONFLICT)
474 DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob,
475 ippErrorString(cupsLastError())));
482 DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob,
483 ippErrorString(cupsLastError())));
492 * 'cups_job_pause()' - Pause a job.
496 cups_job_pause(int snum, struct printjob *pjob)
498 int ret; /* Return value */
499 http_t *http; /* HTTP connection to server */
500 ipp_t *request, /* IPP Request */
501 *response; /* IPP Response */
502 cups_lang_t *language; /* Default language */
503 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
506 DEBUG(5,("cups_job_pause(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
509 * Make sure we don't ask for passwords...
512 cupsSetPasswordCB(cups_passwd_cb);
515 * Try to connect to the server...
518 if ((http = httpConnect(cupsServer(), ippPort())) == NULL)
520 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
521 cupsServer(), strerror(errno)));
526 * Build an IPP_HOLD_JOB request, which requires the following
530 * attributes-natural-language
532 * requesting-user-name
537 request->request.op.operation_id = IPP_HOLD_JOB;
538 request->request.op.request_id = 1;
540 language = cupsLangDefault();
542 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
543 "attributes-charset", NULL, cupsLangEncoding(language));
545 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
546 "attributes-natural-language", NULL, language->language);
548 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
550 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
552 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
556 * Do the request and get back a response...
561 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL)
563 if (response->request.status.status_code >= IPP_OK_CONFLICT)
564 DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob,
565 ippErrorString(cupsLastError())));
572 DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob,
573 ippErrorString(cupsLastError())));
582 * 'cups_job_resume()' - Resume a paused job.
586 cups_job_resume(int snum, struct printjob *pjob)
588 int ret; /* Return value */
589 http_t *http; /* HTTP connection to server */
590 ipp_t *request, /* IPP Request */
591 *response; /* IPP Response */
592 cups_lang_t *language; /* Default language */
593 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
596 DEBUG(5,("cups_job_resume(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
599 * Make sure we don't ask for passwords...
602 cupsSetPasswordCB(cups_passwd_cb);
605 * Try to connect to the server...
608 if ((http = httpConnect(cupsServer(), ippPort())) == NULL)
610 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
611 cupsServer(), strerror(errno)));
616 * Build an IPP_RELEASE_JOB request, which requires the following
620 * attributes-natural-language
622 * requesting-user-name
627 request->request.op.operation_id = IPP_RELEASE_JOB;
628 request->request.op.request_id = 1;
630 language = cupsLangDefault();
632 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
633 "attributes-charset", NULL, cupsLangEncoding(language));
635 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
636 "attributes-natural-language", NULL, language->language);
638 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
640 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
642 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
646 * Do the request and get back a response...
651 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL)
653 if (response->request.status.status_code >= IPP_OK_CONFLICT)
654 DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob,
655 ippErrorString(cupsLastError())));
662 DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob,
663 ippErrorString(cupsLastError())));
672 * 'cups_job_submit()' - Submit a job for printing.
676 cups_job_submit(int snum, struct printjob *pjob)
678 int ret; /* Return value */
679 http_t *http; /* HTTP connection to server */
680 ipp_t *request, /* IPP Request */
681 *response; /* IPP Response */
682 cups_lang_t *language; /* Default language */
683 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
686 DEBUG(5,("cups_job_submit(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
689 * Make sure we don't ask for passwords...
692 cupsSetPasswordCB(cups_passwd_cb);
695 * Try to connect to the server...
698 if ((http = httpConnect(cupsServer(), ippPort())) == NULL)
700 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
701 cupsServer(), strerror(errno)));
706 * Build an IPP_PRINT_JOB request, which requires the following
710 * attributes-natural-language
712 * requesting-user-name
718 request->request.op.operation_id = IPP_PRINT_JOB;
719 request->request.op.request_id = 1;
721 language = cupsLangDefault();
723 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
724 "attributes-charset", NULL, cupsLangEncoding(language));
726 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
727 "attributes-natural-language", NULL, language->language);
729 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
732 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
733 "printer-uri", NULL, uri);
735 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
738 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
739 "job-originating-host-name", NULL,
740 get_remote_machine_name());
742 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "job-name", NULL,
746 * Do the request and get back a response...
749 slprintf(uri, sizeof(uri) - 1, "/printers/%s", PRINTERNAME(snum));
752 if ((response = cupsDoFileRequest(http, request, uri,
753 pjob->filename)) != NULL)
755 if (response->request.status.status_code >= IPP_OK_CONFLICT)
756 DEBUG(0,("Unable to print file to %s - %s\n", PRINTERNAME(snum),
757 ippErrorString(cupsLastError())));
764 DEBUG(0,("Unable to print file to `%s' - %s\n", PRINTERNAME(snum),
765 ippErrorString(cupsLastError())));
770 unlink(pjob->filename);
771 /* else print_job_end will do it for us */
778 * 'cups_queue_get()' - Get all the jobs in the print queue.
782 cups_queue_get(int snum, print_queue_struct **q, print_status_struct *status)
784 http_t *http; /* HTTP connection to server */
785 ipp_t *request, /* IPP Request */
786 *response; /* IPP Response */
787 ipp_attribute_t *attr; /* Current attribute */
788 cups_lang_t *language; /* Default language */
789 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
790 int qcount, /* Number of active queue entries */
791 qalloc; /* Number of queue entries allocated */
792 print_queue_struct *queue, /* Queue entries */
793 *temp; /* Temporary pointer for queue */
794 const char *user_name, /* job-originating-user-name attribute */
795 *job_name; /* job-name attribute */
796 int job_id; /* job-id attribute */
797 int job_k_octets; /* job-k-octets attribute */
798 time_t job_time; /* time-at-creation attribute */
799 ipp_jstate_t job_status; /* job-status attribute */
800 int job_priority; /* job-priority attribute */
801 static const char *jattrs[] = /* Requested job attributes */
806 "job-originating-user-name",
811 static const char *pattrs[] = /* Requested printer attributes */
814 "printer-state-message"
818 DEBUG(5,("cups_queue_get(%d, %p, %p)\n", snum, q, status));
821 * Make sure we don't ask for passwords...
824 cupsSetPasswordCB(cups_passwd_cb);
827 * Try to connect to the server...
830 if ((http = httpConnect(cupsServer(), ippPort())) == NULL)
832 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
833 cupsServer(), strerror(errno)));
838 * Generate the printer URI...
841 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
845 * Build an IPP_GET_JOBS request, which requires the following
849 * attributes-natural-language
850 * requested-attributes
856 request->request.op.operation_id = IPP_GET_JOBS;
857 request->request.op.request_id = 1;
859 language = cupsLangDefault();
861 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
862 "attributes-charset", NULL, cupsLangEncoding(language));
864 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
865 "attributes-natural-language", NULL, language->language);
867 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
868 "requested-attributes",
869 (sizeof(jattrs) / sizeof(jattrs[0])),
872 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
873 "printer-uri", NULL, uri);
876 * Do the request and get back a response...
879 if ((response = cupsDoRequest(http, request, "/")) == NULL)
881 DEBUG(0,("Unable to get jobs for %s - %s\n", uri,
882 ippErrorString(cupsLastError())));
887 if (response->request.status.status_code >= IPP_OK_CONFLICT)
889 DEBUG(0,("Unable to get jobs for %s - %s\n", uri,
890 ippErrorString(response->request.status.status_code)));
898 * Process the jobs...
905 for (attr = response->attrs; attr != NULL; attr = attr->next)
908 * Skip leading attributes until we hit a job...
911 while (attr != NULL && attr->group_tag != IPP_TAG_JOB)
918 * Allocate memory as needed...
920 if (qcount >= qalloc)
924 temp = Realloc(queue, sizeof(print_queue_struct) * qalloc);
928 DEBUG(0,("cups_queue_get: Not enough memory!"));
939 temp = queue + qcount;
940 memset(temp, 0, sizeof(print_queue_struct));
943 * Pull the needed attributes from this job...
948 job_status = IPP_JOB_PENDING;
954 while (attr != NULL && attr->group_tag == IPP_TAG_JOB)
956 if (attr->name == NULL)
962 if (strcmp(attr->name, "job-id") == 0 &&
963 attr->value_tag == IPP_TAG_INTEGER)
964 job_id = attr->values[0].integer;
966 if (strcmp(attr->name, "job-k-octets") == 0 &&
967 attr->value_tag == IPP_TAG_INTEGER)
968 job_k_octets = attr->values[0].integer;
970 if (strcmp(attr->name, "job-priority") == 0 &&
971 attr->value_tag == IPP_TAG_INTEGER)
972 job_priority = attr->values[0].integer;
974 if (strcmp(attr->name, "job-state") == 0 &&
975 attr->value_tag == IPP_TAG_ENUM)
976 job_status = (ipp_jstate_t)(attr->values[0].integer);
978 if (strcmp(attr->name, "time-at-creation") == 0 &&
979 attr->value_tag == IPP_TAG_INTEGER)
980 job_time = attr->values[0].integer;
982 if (strcmp(attr->name, "job-name") == 0 &&
983 attr->value_tag == IPP_TAG_NAME)
984 job_name = attr->values[0].string.text;
986 if (strcmp(attr->name, "job-originating-user-name") == 0 &&
987 attr->value_tag == IPP_TAG_NAME)
988 user_name = attr->values[0].string.text;
994 * See if we have everything needed...
997 if (user_name == NULL || job_name == NULL || job_id == 0)
1006 temp->size = job_k_octets * 1024;
1007 temp->status = job_status == IPP_JOB_PENDING ? LPQ_QUEUED :
1008 job_status == IPP_JOB_STOPPED ? LPQ_PAUSED :
1009 job_status == IPP_JOB_HELD ? LPQ_PAUSED :
1011 temp->priority = job_priority;
1012 temp->time = job_time;
1013 strncpy(temp->fs_user, user_name, sizeof(temp->fs_user) - 1);
1014 strncpy(temp->fs_file, job_name, sizeof(temp->fs_file) - 1);
1022 ippDelete(response);
1025 * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the
1026 * following attributes:
1028 * attributes-charset
1029 * attributes-natural-language
1030 * requested-attributes
1036 request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
1037 request->request.op.request_id = 1;
1039 language = cupsLangDefault();
1041 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1042 "attributes-charset", NULL, cupsLangEncoding(language));
1044 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1045 "attributes-natural-language", NULL, language->language);
1047 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
1048 "requested-attributes",
1049 (sizeof(pattrs) / sizeof(pattrs[0])),
1052 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
1053 "printer-uri", NULL, uri);
1056 * Do the request and get back a response...
1059 if ((response = cupsDoRequest(http, request, "/")) == NULL)
1061 DEBUG(0,("Unable to get printer status for %s - %s\n", PRINTERNAME(snum),
1062 ippErrorString(cupsLastError())));
1068 if (response->request.status.status_code >= IPP_OK_CONFLICT)
1070 DEBUG(0,("Unable to get printer status for %s - %s\n", PRINTERNAME(snum),
1071 ippErrorString(response->request.status.status_code)));
1072 ippDelete(response);
1079 * Get the current printer status and convert it to the SAMBA values.
1082 if ((attr = ippFindAttribute(response, "printer-state", IPP_TAG_ENUM)) != NULL)
1084 if (attr->values[0].integer == IPP_PRINTER_STOPPED)
1085 status->status = LPSTAT_STOPPED;
1087 status->status = LPSTAT_OK;
1090 if ((attr = ippFindAttribute(response, "printer-state-message",
1091 IPP_TAG_TEXT)) != NULL)
1092 fstrcpy(status->message, attr->values[0].string.text);
1094 ippDelete(response);
1097 * Return the job queue...
1108 * 'cups_queue_pause()' - Pause a print queue.
1112 cups_queue_pause(int snum)
1114 extern userdom_struct current_user_info;
1115 int ret; /* Return value */
1116 http_t *http; /* HTTP connection to server */
1117 ipp_t *request, /* IPP Request */
1118 *response; /* IPP Response */
1119 cups_lang_t *language; /* Default language */
1120 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
1123 DEBUG(5,("cups_queue_pause(%d)\n", snum));
1126 * Make sure we don't ask for passwords...
1129 cupsSetPasswordCB(cups_passwd_cb);
1132 * Try to connect to the server...
1135 if ((http = httpConnect(cupsServer(), ippPort())) == NULL)
1137 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
1138 cupsServer(), strerror(errno)));
1143 * Build an IPP_PAUSE_PRINTER request, which requires the following
1146 * attributes-charset
1147 * attributes-natural-language
1149 * requesting-user-name
1154 request->request.op.operation_id = IPP_PAUSE_PRINTER;
1155 request->request.op.request_id = 1;
1157 language = cupsLangDefault();
1159 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1160 "attributes-charset", NULL, cupsLangEncoding(language));
1162 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1163 "attributes-natural-language", NULL, language->language);
1165 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
1168 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
1170 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
1171 NULL, current_user_info.unix_name);
1174 * Do the request and get back a response...
1179 if ((response = cupsDoRequest(http, request, "/admin/")) != NULL)
1181 if (response->request.status.status_code >= IPP_OK_CONFLICT)
1182 DEBUG(0,("Unable to pause printer %s - %s\n", PRINTERNAME(snum),
1183 ippErrorString(cupsLastError())));
1187 ippDelete(response);
1190 DEBUG(0,("Unable to pause printer %s - %s\n", PRINTERNAME(snum),
1191 ippErrorString(cupsLastError())));
1200 * 'cups_queue_resume()' - Restart a print queue.
1204 cups_queue_resume(int snum)
1206 extern userdom_struct current_user_info;
1207 int ret; /* Return value */
1208 http_t *http; /* HTTP connection to server */
1209 ipp_t *request, /* IPP Request */
1210 *response; /* IPP Response */
1211 cups_lang_t *language; /* Default language */
1212 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
1215 DEBUG(5,("cups_queue_resume(%d)\n", snum));
1218 * Make sure we don't ask for passwords...
1221 cupsSetPasswordCB(cups_passwd_cb);
1224 * Try to connect to the server...
1227 if ((http = httpConnect(cupsServer(), ippPort())) == NULL)
1229 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
1230 cupsServer(), strerror(errno)));
1235 * Build an IPP_RESUME_PRINTER request, which requires the following
1238 * attributes-charset
1239 * attributes-natural-language
1241 * requesting-user-name
1246 request->request.op.operation_id = IPP_RESUME_PRINTER;
1247 request->request.op.request_id = 1;
1249 language = cupsLangDefault();
1251 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1252 "attributes-charset", NULL, cupsLangEncoding(language));
1254 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1255 "attributes-natural-language", NULL, language->language);
1257 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
1260 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
1262 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
1263 NULL, current_user_info.unix_name);
1266 * Do the request and get back a response...
1271 if ((response = cupsDoRequest(http, request, "/admin/")) != NULL)
1273 if (response->request.status.status_code >= IPP_OK_CONFLICT)
1274 DEBUG(0,("Unable to resume printer %s - %s\n", PRINTERNAME(snum),
1275 ippErrorString(cupsLastError())));
1279 ippDelete(response);
1282 DEBUG(0,("Unable to resume printer %s - %s\n", PRINTERNAME(snum),
1283 ippErrorString(cupsLastError())));
1292 /* this keeps fussy compilers happy */
1293 void print_cups_dummy(void) {}
1294 #endif /* HAVE_CUPS */