2 * Support code for the Common UNIX Printing System ("CUPS")
4 * Copyright 1999-2001 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 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...
72 * 'cups_printer_fn()' - Call a function for every printer known to the
77 cups_printer_fn(void (*fn)(char *, char *)) /* I - Function to call */
79 http_t *http; /* HTTP connection to server */
80 ipp_t *request, /* IPP Request */
81 *response; /* IPP Response */
82 ipp_attribute_t *attr; /* Current attribute */
83 cups_lang_t *language; /* Default language */
84 char *name, /* printer-name attribute */
85 *make_model, /* printer-make-and-model attribute */
86 *info; /* printer-info attribute */
87 static const char *requested[] =/* Requested attributes */
90 "printer-make-and-model",
95 DEBUG(5,("cups_printer_fn(%p)\n", fn));
98 * Make sure we don't ask for passwords...
101 cupsSetPasswordCB(cups_passwd_cb);
104 * Try to connect to the server...
107 if ((http = httpConnect(cupsServer(), ippPort())) == NULL)
109 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
110 cupsServer(), strerror(errno)));
115 * Build a CUPS_GET_PRINTERS request, which requires the following
119 * attributes-natural-language
120 * requested-attributes
125 request->request.op.operation_id = CUPS_GET_PRINTERS;
126 request->request.op.request_id = 1;
128 language = cupsLangDefault();
130 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
131 "attributes-charset", NULL, cupsLangEncoding(language));
133 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
134 "attributes-natural-language", NULL, language->language);
136 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
137 "requested-attributes",
138 (sizeof(requested) / sizeof(requested[0])),
142 * Do the request and get back a response...
145 if ((response = cupsDoRequest(http, request, "/")) == NULL)
147 DEBUG(0,("Unable to get printer list - %s\n",
148 ippErrorString(cupsLastError())));
153 for (attr = response->attrs; attr != NULL;)
156 * Skip leading attributes until we hit a printer...
159 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
166 * Pull the needed attributes from this printer...
173 while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER)
175 if (strcmp(attr->name, "printer-name") == 0 &&
176 attr->value_tag == IPP_TAG_NAME)
177 name = attr->values[0].string.text;
179 if (strcmp(attr->name, "printer-make-and-model") == 0 &&
180 attr->value_tag == IPP_TAG_TEXT)
181 make_model = attr->values[0].string.text;
183 if (strcmp(attr->name, "printer-info") == 0 &&
184 attr->value_tag == IPP_TAG_TEXT)
185 info = attr->values[0].string.text;
191 * See if we have everything needed...
197 if (info == NULL || !info[0])
198 (*fn)(name, make_model);
211 * 'cups_printername_ok()' - Provide the equivalent of pcap_printername_ok()
215 int /* O - 1 if printer name OK */
216 cups_printername_ok(char *name) /* I - Name of printer */
218 http_t *http; /* HTTP connection to server */
219 ipp_t *request, /* IPP Request */
220 *response; /* IPP Response */
221 cups_lang_t *language; /* Default language */
222 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
225 DEBUG(5,("cups_printername_ok(\"%s\")\n", name));
228 * Make sure we don't ask for passwords...
231 cupsSetPasswordCB(cups_passwd_cb);
234 * Try to connect to the server...
237 if ((http = httpConnect(cupsServer(), ippPort())) == NULL)
239 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
240 cupsServer(), strerror(errno)));
245 * Build an IPP_GET_PRINTER_ATTRS request, which requires the following
249 * attributes-natural-language
250 * requested-attributes
256 request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
257 request->request.op.request_id = 1;
259 language = cupsLangDefault();
261 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
262 "attributes-charset", NULL, cupsLangEncoding(language));
264 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
265 "attributes-natural-language", NULL, language->language);
267 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
268 "requested-attributes", NULL, "printer-uri");
270 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s", name);
272 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
273 "printer-uri", NULL, uri);
276 * Do the request and get back a response...
279 if ((response = cupsDoRequest(http, request, "/")) == NULL)
281 DEBUG(0,("Unable to get printer status for %s - %s\n", name,
282 ippErrorString(cupsLastError())));
289 if (response->request.status.status_code >= IPP_OK_CONFLICT)
291 DEBUG(0,("Unable to get printer status for %s - %s\n", name,
292 ippErrorString(response->request.status.status_code)));
305 * 'cups_job_delete()' - Delete a job.
309 cups_job_delete(int snum, struct printjob *pjob)
311 int ret; /* Return value */
312 http_t *http; /* HTTP connection to server */
313 ipp_t *request, /* IPP Request */
314 *response; /* IPP Response */
315 cups_lang_t *language; /* Default language */
316 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
319 DEBUG(5,("cups_job_delete(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
322 * Make sure we don't ask for passwords...
325 cupsSetPasswordCB(cups_passwd_cb);
328 * Try to connect to the server...
331 if ((http = httpConnect(cupsServer(), ippPort())) == NULL)
333 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
334 cupsServer(), strerror(errno)));
339 * Build an IPP_CANCEL_JOB request, which requires the following
343 * attributes-natural-language
345 * requesting-user-name
350 request->request.op.operation_id = IPP_CANCEL_JOB;
351 request->request.op.request_id = 1;
353 language = cupsLangDefault();
355 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
356 "attributes-charset", NULL, cupsLangEncoding(language));
358 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
359 "attributes-natural-language", NULL, language->language);
361 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
363 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
365 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
369 * Do the request and get back a response...
374 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL)
376 if (response->request.status.status_code >= IPP_OK_CONFLICT)
377 DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob,
378 ippErrorString(cupsLastError())));
385 DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob,
386 ippErrorString(cupsLastError())));
395 * 'cups_job_pause()' - Pause a job.
399 cups_job_pause(int snum, struct printjob *pjob)
401 int ret; /* Return value */
402 http_t *http; /* HTTP connection to server */
403 ipp_t *request, /* IPP Request */
404 *response; /* IPP Response */
405 cups_lang_t *language; /* Default language */
406 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
409 DEBUG(5,("cups_job_pause(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
412 * Make sure we don't ask for passwords...
415 cupsSetPasswordCB(cups_passwd_cb);
418 * Try to connect to the server...
421 if ((http = httpConnect(cupsServer(), ippPort())) == NULL)
423 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
424 cupsServer(), strerror(errno)));
429 * Build an IPP_HOLD_JOB request, which requires the following
433 * attributes-natural-language
435 * requesting-user-name
440 request->request.op.operation_id = IPP_HOLD_JOB;
441 request->request.op.request_id = 1;
443 language = cupsLangDefault();
445 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
446 "attributes-charset", NULL, cupsLangEncoding(language));
448 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
449 "attributes-natural-language", NULL, language->language);
451 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
453 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
455 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
459 * Do the request and get back a response...
464 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL)
466 if (response->request.status.status_code >= IPP_OK_CONFLICT)
467 DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob,
468 ippErrorString(cupsLastError())));
475 DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob,
476 ippErrorString(cupsLastError())));
485 * 'cups_job_resume()' - Resume a paused job.
489 cups_job_resume(int snum, struct printjob *pjob)
491 int ret; /* Return value */
492 http_t *http; /* HTTP connection to server */
493 ipp_t *request, /* IPP Request */
494 *response; /* IPP Response */
495 cups_lang_t *language; /* Default language */
496 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
499 DEBUG(5,("cups_job_resume(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
502 * Make sure we don't ask for passwords...
505 cupsSetPasswordCB(cups_passwd_cb);
508 * Try to connect to the server...
511 if ((http = httpConnect(cupsServer(), ippPort())) == NULL)
513 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
514 cupsServer(), strerror(errno)));
519 * Build an IPP_RELEASE_JOB request, which requires the following
523 * attributes-natural-language
525 * requesting-user-name
530 request->request.op.operation_id = IPP_RELEASE_JOB;
531 request->request.op.request_id = 1;
533 language = cupsLangDefault();
535 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
536 "attributes-charset", NULL, cupsLangEncoding(language));
538 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
539 "attributes-natural-language", NULL, language->language);
541 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
543 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
545 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
549 * Do the request and get back a response...
554 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL)
556 if (response->request.status.status_code >= IPP_OK_CONFLICT)
557 DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob,
558 ippErrorString(cupsLastError())));
565 DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob,
566 ippErrorString(cupsLastError())));
575 * 'cups_job_submit()' - Submit a job for printing.
579 cups_job_submit(int snum, struct printjob *pjob)
581 int ret; /* Return value */
582 http_t *http; /* HTTP connection to server */
583 ipp_t *request, /* IPP Request */
584 *response; /* IPP Response */
585 cups_lang_t *language; /* Default language */
586 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
589 DEBUG(5,("cups_job_submit(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
592 * Make sure we don't ask for passwords...
595 cupsSetPasswordCB(cups_passwd_cb);
598 * Try to connect to the server...
601 if ((http = httpConnect(cupsServer(), ippPort())) == NULL)
603 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
604 cupsServer(), strerror(errno)));
609 * Build an IPP_PRINT_JOB request, which requires the following
613 * attributes-natural-language
615 * requesting-user-name
621 request->request.op.operation_id = IPP_PRINT_JOB;
622 request->request.op.request_id = 1;
624 language = cupsLangDefault();
626 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
627 "attributes-charset", NULL, cupsLangEncoding(language));
629 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
630 "attributes-natural-language", NULL, language->language);
632 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
635 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
636 "printer-uri", NULL, uri);
638 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
641 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "job-name", NULL,
645 * Do the request and get back a response...
648 slprintf(uri, sizeof(uri) - 1, "/printers/%s", PRINTERNAME(snum));
651 if ((response = cupsDoFileRequest(http, request, uri,
652 pjob->filename)) != NULL)
654 if (response->request.status.status_code >= IPP_OK_CONFLICT)
655 DEBUG(0,("Unable to print file to %s - %s\n", PRINTERNAME(snum),
656 ippErrorString(cupsLastError())));
663 DEBUG(0,("Unable to print file to `%s' - %s\n", PRINTERNAME(snum),
664 ippErrorString(cupsLastError())));
673 * 'cups_queue_get()' - Get all the jobs in the print queue.
677 cups_queue_get(int snum, print_queue_struct **q, print_status_struct *status)
679 http_t *http; /* HTTP connection to server */
680 ipp_t *request, /* IPP Request */
681 *response; /* IPP Response */
682 ipp_attribute_t *attr; /* Current attribute */
683 cups_lang_t *language; /* Default language */
684 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
685 int qcount, /* Number of active queue entries */
686 qalloc; /* Number of queue entries allocated */
687 print_queue_struct *queue, /* Queue entries */
688 *temp; /* Temporary pointer for queue */
689 const char *user_name, /* job-originating-user-name attribute */
690 *job_name; /* job-name attribute */
691 int job_id; /* job-id attribute */
692 int job_k_octets; /* job-k-octets attribute */
693 time_t job_time; /* time-at-creation attribute */
694 ipp_jstate_t job_status; /* job-status attribute */
695 int job_priority; /* job-priority attribute */
696 static const char *jattrs[] = /* Requested job attributes */
701 "job-originating-user-name",
706 static const char *pattrs[] = /* Requested printer attributes */
709 "printer-state-message"
713 DEBUG(5,("cups_queue_get(%d, %p, %p)\n", snum, q, status));
716 * Make sure we don't ask for passwords...
719 cupsSetPasswordCB(cups_passwd_cb);
722 * Try to connect to the server...
725 if ((http = httpConnect(cupsServer(), ippPort())) == NULL)
727 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
728 cupsServer(), strerror(errno)));
733 * Generate the printer URI...
736 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
740 * Build an IPP_GET_JOBS request, which requires the following
744 * attributes-natural-language
745 * requested-attributes
751 request->request.op.operation_id = IPP_GET_JOBS;
752 request->request.op.request_id = 1;
754 language = cupsLangDefault();
756 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
757 "attributes-charset", NULL, cupsLangEncoding(language));
759 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
760 "attributes-natural-language", NULL, language->language);
762 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
763 "requested-attributes",
764 (sizeof(jattrs) / sizeof(jattrs[0])),
767 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
768 "printer-uri", NULL, uri);
771 * Do the request and get back a response...
774 if ((response = cupsDoRequest(http, request, "/")) == NULL)
776 DEBUG(0,("Unable to get jobs for %s - %s\n", uri,
777 ippErrorString(cupsLastError())));
782 if (response->request.status.status_code >= IPP_OK_CONFLICT)
784 DEBUG(0,("Unable to get jobs for %s - %s\n", uri,
785 ippErrorString(response->request.status.status_code)));
793 * Process the jobs...
800 for (attr = response->attrs; attr != NULL; attr = attr->next)
803 * Skip leading attributes until we hit a job...
806 while (attr != NULL && attr->group_tag != IPP_TAG_JOB)
813 * Allocate memory as needed...
815 if (qcount >= qalloc)
819 temp = Realloc(queue, sizeof(print_queue_struct) * qalloc);
823 DEBUG(0,("cups_queue_get: Not enough memory!"));
834 temp = queue + qcount;
835 memset(temp, 0, sizeof(print_queue_struct));
838 * Pull the needed attributes from this job...
843 job_status = IPP_JOB_PENDING;
849 while (attr != NULL && attr->group_tag == IPP_TAG_JOB)
851 if (attr->name == NULL)
857 if (strcmp(attr->name, "job-id") == 0 &&
858 attr->value_tag == IPP_TAG_INTEGER)
859 job_id = attr->values[0].integer;
861 if (strcmp(attr->name, "job-k-octets") == 0 &&
862 attr->value_tag == IPP_TAG_INTEGER)
863 job_k_octets = attr->values[0].integer;
865 if (strcmp(attr->name, "job-priority") == 0 &&
866 attr->value_tag == IPP_TAG_INTEGER)
867 job_priority = attr->values[0].integer;
869 if (strcmp(attr->name, "job-state") == 0 &&
870 attr->value_tag == IPP_TAG_ENUM)
871 job_status = (ipp_jstate_t)(attr->values[0].integer);
873 if (strcmp(attr->name, "time-at-creation") == 0 &&
874 attr->value_tag == IPP_TAG_INTEGER)
875 job_time = attr->values[0].integer;
877 if (strcmp(attr->name, "job-name") == 0 &&
878 attr->value_tag == IPP_TAG_NAME)
879 job_name = attr->values[0].string.text;
881 if (strcmp(attr->name, "job-originating-user-name") == 0 &&
882 attr->value_tag == IPP_TAG_NAME)
883 user_name = attr->values[0].string.text;
889 * See if we have everything needed...
892 if (user_name == NULL || job_name == NULL || job_id == 0)
901 temp->size = job_k_octets * 1024;
902 temp->status = job_status == IPP_JOB_PENDING ? LPQ_QUEUED :
903 job_status == IPP_JOB_STOPPED ? LPQ_PAUSED :
904 job_status == IPP_JOB_HELD ? LPQ_PAUSED :
906 temp->priority = job_priority;
907 temp->time = job_time;
908 strncpy(temp->user, user_name, sizeof(temp->user) - 1);
909 strncpy(temp->file, job_name, sizeof(temp->file) - 1);
920 * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the
921 * following attributes:
924 * attributes-natural-language
925 * requested-attributes
931 request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
932 request->request.op.request_id = 1;
934 language = cupsLangDefault();
936 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
937 "attributes-charset", NULL, cupsLangEncoding(language));
939 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
940 "attributes-natural-language", NULL, language->language);
942 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
943 "requested-attributes",
944 (sizeof(pattrs) / sizeof(pattrs[0])),
947 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
948 "printer-uri", NULL, uri);
951 * Do the request and get back a response...
954 if ((response = cupsDoRequest(http, request, "/")) == NULL)
956 DEBUG(0,("Unable to get printer status for %s - %s\n", PRINTERNAME(snum),
957 ippErrorString(cupsLastError())));
963 if (response->request.status.status_code >= IPP_OK_CONFLICT)
965 DEBUG(0,("Unable to get printer status for %s - %s\n", PRINTERNAME(snum),
966 ippErrorString(response->request.status.status_code)));
974 * Get the current printer status and convert it to the SAMBA values.
977 if ((attr = ippFindAttribute(response, "printer-state", IPP_TAG_ENUM)) != NULL)
979 if (attr->values[0].integer == IPP_PRINTER_STOPPED)
980 status->status = LPSTAT_STOPPED;
982 status->status = LPSTAT_OK;
985 if ((attr = ippFindAttribute(response, "printer-state-message",
986 IPP_TAG_TEXT)) != NULL)
987 fstrcpy(status->message, attr->values[0].string.text);
992 * Return the job queue...
1003 * 'cups_queue_pause()' - Pause a print queue.
1007 cups_queue_pause(int snum)
1009 extern userdom_struct current_user_info;
1010 int ret; /* Return value */
1011 http_t *http; /* HTTP connection to server */
1012 ipp_t *request, /* IPP Request */
1013 *response; /* IPP Response */
1014 cups_lang_t *language; /* Default language */
1015 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
1018 DEBUG(5,("cups_queue_pause(%d)\n", snum));
1021 * Make sure we don't ask for passwords...
1024 cupsSetPasswordCB(cups_passwd_cb);
1027 * Try to connect to the server...
1030 if ((http = httpConnect(cupsServer(), ippPort())) == NULL)
1032 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
1033 cupsServer(), strerror(errno)));
1038 * Build an IPP_PAUSE_PRINTER request, which requires the following
1041 * attributes-charset
1042 * attributes-natural-language
1044 * requesting-user-name
1049 request->request.op.operation_id = IPP_PAUSE_PRINTER;
1050 request->request.op.request_id = 1;
1052 language = cupsLangDefault();
1054 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1055 "attributes-charset", NULL, cupsLangEncoding(language));
1057 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1058 "attributes-natural-language", NULL, language->language);
1060 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
1063 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
1065 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
1066 NULL, current_user_info.unix_name);
1069 * Do the request and get back a response...
1074 if ((response = cupsDoRequest(http, request, "/admin/")) != NULL)
1076 if (response->request.status.status_code >= IPP_OK_CONFLICT)
1077 DEBUG(0,("Unable to pause printer %s - %s\n", PRINTERNAME(snum),
1078 ippErrorString(cupsLastError())));
1082 ippDelete(response);
1085 DEBUG(0,("Unable to pause printer %s - %s\n", PRINTERNAME(snum),
1086 ippErrorString(cupsLastError())));
1095 * 'cups_queue_resume()' - Restart a print queue.
1099 cups_queue_resume(int snum)
1101 extern userdom_struct current_user_info;
1102 int ret; /* Return value */
1103 http_t *http; /* HTTP connection to server */
1104 ipp_t *request, /* IPP Request */
1105 *response; /* IPP Response */
1106 cups_lang_t *language; /* Default language */
1107 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
1110 DEBUG(5,("cups_queue_resume(%d)\n", snum));
1113 * Make sure we don't ask for passwords...
1116 cupsSetPasswordCB(cups_passwd_cb);
1119 * Try to connect to the server...
1122 if ((http = httpConnect(cupsServer(), ippPort())) == NULL)
1124 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
1125 cupsServer(), strerror(errno)));
1130 * Build an IPP_RESUME_PRINTER request, which requires the following
1133 * attributes-charset
1134 * attributes-natural-language
1136 * requesting-user-name
1141 request->request.op.operation_id = IPP_RESUME_PRINTER;
1142 request->request.op.request_id = 1;
1144 language = cupsLangDefault();
1146 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1147 "attributes-charset", NULL, cupsLangEncoding(language));
1149 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1150 "attributes-natural-language", NULL, language->language);
1152 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
1155 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
1157 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
1158 NULL, current_user_info.unix_name);
1161 * Do the request and get back a response...
1166 if ((response = cupsDoRequest(http, request, "/admin/")) != NULL)
1168 if (response->request.status.status_code >= IPP_OK_CONFLICT)
1169 DEBUG(0,("Unable to resume printer %s - %s\n", PRINTERNAME(snum),
1170 ippErrorString(cupsLastError())));
1174 ippDelete(response);
1177 DEBUG(0,("Unable to resume printer %s - %s\n", PRINTERNAME(snum),
1178 ippErrorString(cupsLastError())));
1187 /* this keeps fussy compilers happy */
1188 void print_cups_dummy(void) {}
1189 #endif /* HAVE_CUPS */