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.
24 #include <cups/cups.h>
25 #include <cups/language.h>
29 * CUPS printing interface definitions...
32 static int cups_job_delete(int snum, struct printjob *pjob);
33 static int cups_job_pause(int snum, struct printjob *pjob);
34 static int cups_job_resume(int snum, struct printjob *pjob);
35 static int cups_job_submit(int snum, struct printjob *pjob);
36 static int cups_queue_get(int snum, print_queue_struct **q,
37 print_status_struct *status);
38 static int cups_queue_pause(int snum);
39 static int cups_queue_resume(int snum);
42 struct printif cups_printif =
54 * 'cups_passwd_cb()' - The CUPS password callback...
57 const char * /* O - Password or NULL */
58 cups_passwd_cb(const char *prompt) /* I - Prompt */
61 * Always return NULL to indicate that no password is available...
71 * 'cups_printer_fn()' - Call a function for every printer known to the
75 void cups_printer_fn(void (*fn)(char *, char *))
77 /* I - Function to call */
78 http_t *http; /* HTTP connection to server */
79 ipp_t *request, /* IPP Request */
80 *response; /* IPP Response */
81 ipp_attribute_t *attr; /* Current attribute */
82 cups_lang_t *language; /* Default language */
83 char *name, /* printer-name attribute */
84 *make_model, /* printer-make-and-model attribute */
85 *info; /* printer-info attribute */
86 static const char *requested[] =/* Requested attributes */
89 "printer-make-and-model",
94 DEBUG(5,("cups_printer_fn(%p)\n", fn));
97 * Make sure we don't ask for passwords...
100 cupsSetPasswordCB(cups_passwd_cb);
103 * Try to connect to the server...
106 if ((http = httpConnect(cupsServer(), ippPort())) == NULL)
108 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
109 cupsServer(), strerror(errno)));
114 * Build a CUPS_GET_PRINTERS request, which requires the following
118 * attributes-natural-language
119 * requested-attributes
124 request->request.op.operation_id = CUPS_GET_PRINTERS;
125 request->request.op.request_id = 1;
127 language = cupsLangDefault();
129 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
130 "attributes-charset", NULL, cupsLangEncoding(language));
132 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
133 "attributes-natural-language", NULL, language->language);
135 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
136 "requested-attributes",
137 (sizeof(requested) / sizeof(requested[0])),
141 * Do the request and get back a response...
144 if ((response = cupsDoRequest(http, request, "/")) == NULL)
146 DEBUG(0,("Unable to get printer list - %s\n",
147 ippErrorString(cupsLastError())));
152 for (attr = response->attrs; attr != NULL;)
155 * Skip leading attributes until we hit a printer...
158 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
165 * Pull the needed attributes from this printer...
172 while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER)
174 if (strcmp(attr->name, "printer-name") == 0 &&
175 attr->value_tag == IPP_TAG_NAME)
176 name = attr->values[0].string.text;
178 if (strcmp(attr->name, "printer-make-and-model") == 0 &&
179 attr->value_tag == IPP_TAG_TEXT)
180 make_model = attr->values[0].string.text;
182 if (strcmp(attr->name, "printer-info") == 0 &&
183 attr->value_tag == IPP_TAG_TEXT)
184 info = attr->values[0].string.text;
190 * See if we have everything needed...
196 if (info == NULL || !info[0])
197 (*fn)(name, make_model);
210 * 'cups_printername_ok()' - Provide the equivalent of pcap_printername_ok()
214 int /* O - 1 if printer name OK */
215 cups_printername_ok(char *name) /* I - Name of printer */
217 http_t *http; /* HTTP connection to server */
218 ipp_t *request, /* IPP Request */
219 *response; /* IPP Response */
220 cups_lang_t *language; /* Default language */
221 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
224 DEBUG(5,("cups_printername_ok(\"%s\")\n", name));
227 * Make sure we don't ask for passwords...
230 cupsSetPasswordCB(cups_passwd_cb);
233 * Try to connect to the server...
236 if ((http = httpConnect(cupsServer(), ippPort())) == NULL)
238 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
239 cupsServer(), strerror(errno)));
244 * Build an IPP_GET_PRINTER_ATTRS request, which requires the following
248 * attributes-natural-language
249 * requested-attributes
255 request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
256 request->request.op.request_id = 1;
258 language = cupsLangDefault();
260 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
261 "attributes-charset", NULL, cupsLangEncoding(language));
263 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
264 "attributes-natural-language", NULL, language->language);
266 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
267 "requested-attributes", NULL, "printer-uri");
269 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s", name);
271 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
272 "printer-uri", NULL, uri);
275 * Do the request and get back a response...
278 if ((response = cupsDoRequest(http, request, "/")) == NULL)
280 DEBUG(0,("Unable to get printer status for %s - %s\n", name,
281 ippErrorString(cupsLastError())));
288 if (response->request.status.status_code >= IPP_OK_CONFLICT)
290 DEBUG(0,("Unable to get printer status for %s - %s\n", name,
291 ippErrorString(response->request.status.status_code)));
304 * 'cups_job_delete()' - Delete a job.
308 cups_job_delete(int snum, struct printjob *pjob)
310 int ret; /* Return value */
311 http_t *http; /* HTTP connection to server */
312 ipp_t *request, /* IPP Request */
313 *response; /* IPP Response */
314 cups_lang_t *language; /* Default language */
315 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
318 DEBUG(5,("cups_job_delete(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
321 * Make sure we don't ask for passwords...
324 cupsSetPasswordCB(cups_passwd_cb);
327 * Try to connect to the server...
330 if ((http = httpConnect(cupsServer(), ippPort())) == NULL)
332 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
333 cupsServer(), strerror(errno)));
338 * Build an IPP_CANCEL_JOB request, which requires the following
342 * attributes-natural-language
344 * requesting-user-name
349 request->request.op.operation_id = IPP_CANCEL_JOB;
350 request->request.op.request_id = 1;
352 language = cupsLangDefault();
354 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
355 "attributes-charset", NULL, cupsLangEncoding(language));
357 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
358 "attributes-natural-language", NULL, language->language);
360 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
362 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
364 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
368 * Do the request and get back a response...
373 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL)
375 if (response->request.status.status_code >= IPP_OK_CONFLICT)
376 DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob,
377 ippErrorString(cupsLastError())));
384 DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob,
385 ippErrorString(cupsLastError())));
394 * 'cups_job_pause()' - Pause a job.
398 cups_job_pause(int snum, struct printjob *pjob)
400 int ret; /* Return value */
401 http_t *http; /* HTTP connection to server */
402 ipp_t *request, /* IPP Request */
403 *response; /* IPP Response */
404 cups_lang_t *language; /* Default language */
405 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
408 DEBUG(5,("cups_job_pause(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
411 * Make sure we don't ask for passwords...
414 cupsSetPasswordCB(cups_passwd_cb);
417 * Try to connect to the server...
420 if ((http = httpConnect(cupsServer(), ippPort())) == NULL)
422 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
423 cupsServer(), strerror(errno)));
428 * Build an IPP_HOLD_JOB request, which requires the following
432 * attributes-natural-language
434 * requesting-user-name
439 request->request.op.operation_id = IPP_HOLD_JOB;
440 request->request.op.request_id = 1;
442 language = cupsLangDefault();
444 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
445 "attributes-charset", NULL, cupsLangEncoding(language));
447 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
448 "attributes-natural-language", NULL, language->language);
450 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
452 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
454 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
458 * Do the request and get back a response...
463 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL)
465 if (response->request.status.status_code >= IPP_OK_CONFLICT)
466 DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob,
467 ippErrorString(cupsLastError())));
474 DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob,
475 ippErrorString(cupsLastError())));
484 * 'cups_job_resume()' - Resume a paused job.
488 cups_job_resume(int snum, struct printjob *pjob)
490 int ret; /* Return value */
491 http_t *http; /* HTTP connection to server */
492 ipp_t *request, /* IPP Request */
493 *response; /* IPP Response */
494 cups_lang_t *language; /* Default language */
495 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
498 DEBUG(5,("cups_job_resume(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
501 * Make sure we don't ask for passwords...
504 cupsSetPasswordCB(cups_passwd_cb);
507 * Try to connect to the server...
510 if ((http = httpConnect(cupsServer(), ippPort())) == NULL)
512 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
513 cupsServer(), strerror(errno)));
518 * Build an IPP_RELEASE_JOB request, which requires the following
522 * attributes-natural-language
524 * requesting-user-name
529 request->request.op.operation_id = IPP_RELEASE_JOB;
530 request->request.op.request_id = 1;
532 language = cupsLangDefault();
534 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
535 "attributes-charset", NULL, cupsLangEncoding(language));
537 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
538 "attributes-natural-language", NULL, language->language);
540 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
542 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
544 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
548 * Do the request and get back a response...
553 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL)
555 if (response->request.status.status_code >= IPP_OK_CONFLICT)
556 DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob,
557 ippErrorString(cupsLastError())));
564 DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob,
565 ippErrorString(cupsLastError())));
574 * 'cups_job_submit()' - Submit a job for printing.
578 cups_job_submit(int snum, struct printjob *pjob)
580 int ret; /* Return value */
581 http_t *http; /* HTTP connection to server */
582 ipp_t *request, /* IPP Request */
583 *response; /* IPP Response */
584 cups_lang_t *language; /* Default language */
585 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
588 DEBUG(5,("cups_job_submit(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
591 * Make sure we don't ask for passwords...
594 cupsSetPasswordCB(cups_passwd_cb);
597 * Try to connect to the server...
600 if ((http = httpConnect(cupsServer(), ippPort())) == NULL)
602 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
603 cupsServer(), strerror(errno)));
608 * Build an IPP_PRINT_JOB request, which requires the following
612 * attributes-natural-language
614 * requesting-user-name
620 request->request.op.operation_id = IPP_PRINT_JOB;
621 request->request.op.request_id = 1;
623 language = cupsLangDefault();
625 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
626 "attributes-charset", NULL, cupsLangEncoding(language));
628 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
629 "attributes-natural-language", NULL, language->language);
631 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
634 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
635 "printer-uri", NULL, uri);
637 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
640 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "job-name", NULL,
644 * Do the request and get back a response...
647 slprintf(uri, sizeof(uri) - 1, "/printers/%s", PRINTERNAME(snum));
650 if ((response = cupsDoFileRequest(http, request, uri,
651 pjob->filename)) != NULL)
653 if (response->request.status.status_code >= IPP_OK_CONFLICT)
654 DEBUG(0,("Unable to print file to %s - %s\n", PRINTERNAME(snum),
655 ippErrorString(cupsLastError())));
662 DEBUG(0,("Unable to print file to `%s' - %s\n", PRINTERNAME(snum),
663 ippErrorString(cupsLastError())));
668 unlink(pjob->filename);
669 /* else print_job_end will do it for us */
676 * 'cups_queue_get()' - Get all the jobs in the print queue.
680 cups_queue_get(int snum, print_queue_struct **q, print_status_struct *status)
682 http_t *http; /* HTTP connection to server */
683 ipp_t *request, /* IPP Request */
684 *response; /* IPP Response */
685 ipp_attribute_t *attr; /* Current attribute */
686 cups_lang_t *language; /* Default language */
687 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
688 int qcount, /* Number of active queue entries */
689 qalloc; /* Number of queue entries allocated */
690 print_queue_struct *queue, /* Queue entries */
691 *temp; /* Temporary pointer for queue */
692 const char *user_name, /* job-originating-user-name attribute */
693 *job_name; /* job-name attribute */
694 int job_id; /* job-id attribute */
695 int job_k_octets; /* job-k-octets attribute */
696 time_t job_time; /* time-at-creation attribute */
697 ipp_jstate_t job_status; /* job-status attribute */
698 int job_priority; /* job-priority attribute */
699 static const char *jattrs[] = /* Requested job attributes */
704 "job-originating-user-name",
709 static const char *pattrs[] = /* Requested printer attributes */
712 "printer-state-message"
716 DEBUG(5,("cups_queue_get(%d, %p, %p)\n", snum, q, status));
719 * Make sure we don't ask for passwords...
722 cupsSetPasswordCB(cups_passwd_cb);
725 * Try to connect to the server...
728 if ((http = httpConnect(cupsServer(), ippPort())) == NULL)
730 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
731 cupsServer(), strerror(errno)));
736 * Generate the printer URI...
739 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
743 * Build an IPP_GET_JOBS request, which requires the following
747 * attributes-natural-language
748 * requested-attributes
754 request->request.op.operation_id = IPP_GET_JOBS;
755 request->request.op.request_id = 1;
757 language = cupsLangDefault();
759 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
760 "attributes-charset", NULL, cupsLangEncoding(language));
762 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
763 "attributes-natural-language", NULL, language->language);
765 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
766 "requested-attributes",
767 (sizeof(jattrs) / sizeof(jattrs[0])),
770 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
771 "printer-uri", NULL, uri);
774 * Do the request and get back a response...
777 if ((response = cupsDoRequest(http, request, "/")) == NULL)
779 DEBUG(0,("Unable to get jobs for %s - %s\n", uri,
780 ippErrorString(cupsLastError())));
785 if (response->request.status.status_code >= IPP_OK_CONFLICT)
787 DEBUG(0,("Unable to get jobs for %s - %s\n", uri,
788 ippErrorString(response->request.status.status_code)));
796 * Process the jobs...
803 for (attr = response->attrs; attr != NULL; attr = attr->next)
806 * Skip leading attributes until we hit a job...
809 while (attr != NULL && attr->group_tag != IPP_TAG_JOB)
816 * Allocate memory as needed...
818 if (qcount >= qalloc)
822 temp = Realloc(queue, sizeof(print_queue_struct) * qalloc);
826 DEBUG(0,("cups_queue_get: Not enough memory!"));
837 temp = queue + qcount;
838 memset(temp, 0, sizeof(print_queue_struct));
841 * Pull the needed attributes from this job...
846 job_status = IPP_JOB_PENDING;
852 while (attr != NULL && attr->group_tag == IPP_TAG_JOB)
854 if (attr->name == NULL)
860 if (strcmp(attr->name, "job-id") == 0 &&
861 attr->value_tag == IPP_TAG_INTEGER)
862 job_id = attr->values[0].integer;
864 if (strcmp(attr->name, "job-k-octets") == 0 &&
865 attr->value_tag == IPP_TAG_INTEGER)
866 job_k_octets = attr->values[0].integer;
868 if (strcmp(attr->name, "job-priority") == 0 &&
869 attr->value_tag == IPP_TAG_INTEGER)
870 job_priority = attr->values[0].integer;
872 if (strcmp(attr->name, "job-state") == 0 &&
873 attr->value_tag == IPP_TAG_ENUM)
874 job_status = (ipp_jstate_t)(attr->values[0].integer);
876 if (strcmp(attr->name, "time-at-creation") == 0 &&
877 attr->value_tag == IPP_TAG_INTEGER)
878 job_time = attr->values[0].integer;
880 if (strcmp(attr->name, "job-name") == 0 &&
881 attr->value_tag == IPP_TAG_NAME)
882 job_name = attr->values[0].string.text;
884 if (strcmp(attr->name, "job-originating-user-name") == 0 &&
885 attr->value_tag == IPP_TAG_NAME)
886 user_name = attr->values[0].string.text;
892 * See if we have everything needed...
895 if (user_name == NULL || job_name == NULL || job_id == 0)
904 temp->size = job_k_octets * 1024;
905 temp->status = job_status == IPP_JOB_PENDING ? LPQ_QUEUED :
906 job_status == IPP_JOB_STOPPED ? LPQ_PAUSED :
907 job_status == IPP_JOB_HELD ? LPQ_PAUSED :
909 temp->priority = job_priority;
910 temp->time = job_time;
911 strncpy(temp->fs_user, user_name, sizeof(temp->fs_user) - 1);
912 strncpy(temp->fs_file, job_name, sizeof(temp->fs_file) - 1);
923 * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the
924 * following attributes:
927 * attributes-natural-language
928 * requested-attributes
934 request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
935 request->request.op.request_id = 1;
937 language = cupsLangDefault();
939 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
940 "attributes-charset", NULL, cupsLangEncoding(language));
942 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
943 "attributes-natural-language", NULL, language->language);
945 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
946 "requested-attributes",
947 (sizeof(pattrs) / sizeof(pattrs[0])),
950 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
951 "printer-uri", NULL, uri);
954 * Do the request and get back a response...
957 if ((response = cupsDoRequest(http, request, "/")) == NULL)
959 DEBUG(0,("Unable to get printer status for %s - %s\n", PRINTERNAME(snum),
960 ippErrorString(cupsLastError())));
966 if (response->request.status.status_code >= IPP_OK_CONFLICT)
968 DEBUG(0,("Unable to get printer status for %s - %s\n", PRINTERNAME(snum),
969 ippErrorString(response->request.status.status_code)));
977 * Get the current printer status and convert it to the SAMBA values.
980 if ((attr = ippFindAttribute(response, "printer-state", IPP_TAG_ENUM)) != NULL)
982 if (attr->values[0].integer == IPP_PRINTER_STOPPED)
983 status->status = LPSTAT_STOPPED;
985 status->status = LPSTAT_OK;
988 if ((attr = ippFindAttribute(response, "printer-state-message",
989 IPP_TAG_TEXT)) != NULL)
990 fstrcpy(status->message, attr->values[0].string.text);
995 * Return the job queue...
1006 * 'cups_queue_pause()' - Pause a print queue.
1010 cups_queue_pause(int snum)
1012 extern userdom_struct current_user_info;
1013 int ret; /* Return value */
1014 http_t *http; /* HTTP connection to server */
1015 ipp_t *request, /* IPP Request */
1016 *response; /* IPP Response */
1017 cups_lang_t *language; /* Default language */
1018 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
1021 DEBUG(5,("cups_queue_pause(%d)\n", snum));
1024 * Make sure we don't ask for passwords...
1027 cupsSetPasswordCB(cups_passwd_cb);
1030 * Try to connect to the server...
1033 if ((http = httpConnect(cupsServer(), ippPort())) == NULL)
1035 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
1036 cupsServer(), strerror(errno)));
1041 * Build an IPP_PAUSE_PRINTER request, which requires the following
1044 * attributes-charset
1045 * attributes-natural-language
1047 * requesting-user-name
1052 request->request.op.operation_id = IPP_PAUSE_PRINTER;
1053 request->request.op.request_id = 1;
1055 language = cupsLangDefault();
1057 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1058 "attributes-charset", NULL, cupsLangEncoding(language));
1060 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1061 "attributes-natural-language", NULL, language->language);
1063 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
1066 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
1068 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
1069 NULL, current_user_info.unix_name);
1072 * Do the request and get back a response...
1077 if ((response = cupsDoRequest(http, request, "/admin/")) != NULL)
1079 if (response->request.status.status_code >= IPP_OK_CONFLICT)
1080 DEBUG(0,("Unable to pause printer %s - %s\n", PRINTERNAME(snum),
1081 ippErrorString(cupsLastError())));
1085 ippDelete(response);
1088 DEBUG(0,("Unable to pause printer %s - %s\n", PRINTERNAME(snum),
1089 ippErrorString(cupsLastError())));
1098 * 'cups_queue_resume()' - Restart a print queue.
1102 cups_queue_resume(int snum)
1104 extern userdom_struct current_user_info;
1105 int ret; /* Return value */
1106 http_t *http; /* HTTP connection to server */
1107 ipp_t *request, /* IPP Request */
1108 *response; /* IPP Response */
1109 cups_lang_t *language; /* Default language */
1110 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
1113 DEBUG(5,("cups_queue_resume(%d)\n", snum));
1116 * Make sure we don't ask for passwords...
1119 cupsSetPasswordCB(cups_passwd_cb);
1122 * Try to connect to the server...
1125 if ((http = httpConnect(cupsServer(), ippPort())) == NULL)
1127 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
1128 cupsServer(), strerror(errno)));
1133 * Build an IPP_RESUME_PRINTER request, which requires the following
1136 * attributes-charset
1137 * attributes-natural-language
1139 * requesting-user-name
1144 request->request.op.operation_id = IPP_RESUME_PRINTER;
1145 request->request.op.request_id = 1;
1147 language = cupsLangDefault();
1149 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1150 "attributes-charset", NULL, cupsLangEncoding(language));
1152 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1153 "attributes-natural-language", NULL, language->language);
1155 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
1158 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
1160 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
1161 NULL, current_user_info.unix_name);
1164 * Do the request and get back a response...
1169 if ((response = cupsDoRequest(http, request, "/admin/")) != NULL)
1171 if (response->request.status.status_code >= IPP_OK_CONFLICT)
1172 DEBUG(0,("Unable to resume printer %s - %s\n", PRINTERNAME(snum),
1173 ippErrorString(cupsLastError())));
1177 ippDelete(response);
1180 DEBUG(0,("Unable to resume printer %s - %s\n", PRINTERNAME(snum),
1181 ippErrorString(cupsLastError())));
1190 /* this keeps fussy compilers happy */
1191 void print_cups_dummy(void) {}
1192 #endif /* HAVE_CUPS */