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()));
55 BOOL cups_cache_reload(void)
57 http_t *http; /* HTTP connection to server */
58 ipp_t *request, /* IPP Request */
59 *response; /* IPP Response */
60 ipp_attribute_t *attr; /* Current attribute */
61 cups_lang_t *language; /* Default language */
62 char *name, /* printer-name attribute */
63 *info; /* printer-info attribute */
64 static const char *requested[] =/* Requested attributes */
71 DEBUG(5, ("reloading cups printcap cache\n"));
74 * Make sure we don't ask for passwords...
77 cupsSetPasswordCB(cups_passwd_cb);
80 * Try to connect to the server...
83 if ((http = httpConnect(cups_server(), ippPort())) == NULL)
85 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
86 cups_server(), strerror(errno)));
91 * Build a CUPS_GET_PRINTERS request, which requires the following
95 * attributes-natural-language
96 * requested-attributes
101 request->request.op.operation_id = CUPS_GET_PRINTERS;
102 request->request.op.request_id = 1;
104 language = cupsLangDefault();
106 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
107 "attributes-charset", NULL, cupsLangEncoding(language));
109 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
110 "attributes-natural-language", NULL, language->language);
112 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
113 "requested-attributes",
114 (sizeof(requested) / sizeof(requested[0])),
118 * Do the request and get back a response...
121 if ((response = cupsDoRequest(http, request, "/")) == NULL)
123 DEBUG(0,("Unable to get printer list - %s\n",
124 ippErrorString(cupsLastError())));
129 for (attr = response->attrs; attr != NULL;)
132 * Skip leading attributes until we hit a printer...
135 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
142 * Pull the needed attributes from this printer...
148 while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER)
150 if (strcmp(attr->name, "printer-name") == 0 &&
151 attr->value_tag == IPP_TAG_NAME)
152 name = attr->values[0].string.text;
154 if (strcmp(attr->name, "printer-info") == 0 &&
155 attr->value_tag == IPP_TAG_TEXT)
156 info = attr->values[0].string.text;
162 * See if we have everything needed...
168 if (!pcap_cache_add(name, info)) {
179 * Build a CUPS_GET_CLASSES request, which requires the following
183 * attributes-natural-language
184 * requested-attributes
189 request->request.op.operation_id = CUPS_GET_CLASSES;
190 request->request.op.request_id = 1;
192 language = cupsLangDefault();
194 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
195 "attributes-charset", NULL, cupsLangEncoding(language));
197 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
198 "attributes-natural-language", NULL, language->language);
200 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
201 "requested-attributes",
202 (sizeof(requested) / sizeof(requested[0])),
206 * Do the request and get back a response...
209 if ((response = cupsDoRequest(http, request, "/")) == NULL)
211 DEBUG(0,("Unable to get printer list - %s\n",
212 ippErrorString(cupsLastError())));
217 for (attr = response->attrs; attr != NULL;)
220 * Skip leading attributes until we hit a printer...
223 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
230 * Pull the needed attributes from this printer...
236 while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER)
238 if (strcmp(attr->name, "printer-name") == 0 &&
239 attr->value_tag == IPP_TAG_NAME)
240 name = attr->values[0].string.text;
242 if (strcmp(attr->name, "printer-info") == 0 &&
243 attr->value_tag == IPP_TAG_TEXT)
244 info = attr->values[0].string.text;
250 * See if we have everything needed...
256 if (!pcap_cache_add(name, info)) {
266 * Close the connection to the server...
275 * 'cups_job_delete()' - Delete a job.
279 cups_job_delete(int snum, struct printjob *pjob)
281 int ret; /* Return value */
282 http_t *http; /* HTTP connection to server */
283 ipp_t *request, /* IPP Request */
284 *response; /* IPP Response */
285 cups_lang_t *language; /* Default language */
286 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
289 DEBUG(5,("cups_job_delete(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
292 * Make sure we don't ask for passwords...
295 cupsSetPasswordCB(cups_passwd_cb);
298 * Try to connect to the server...
301 if ((http = httpConnect(cups_server(), ippPort())) == NULL)
303 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
304 cups_server(), strerror(errno)));
309 * Build an IPP_CANCEL_JOB request, which requires the following
313 * attributes-natural-language
315 * requesting-user-name
320 request->request.op.operation_id = IPP_CANCEL_JOB;
321 request->request.op.request_id = 1;
323 language = cupsLangDefault();
325 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
326 "attributes-charset", NULL, cupsLangEncoding(language));
328 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
329 "attributes-natural-language", NULL, language->language);
331 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
333 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
335 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
339 * Do the request and get back a response...
344 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL)
346 if (response->request.status.status_code >= IPP_OK_CONFLICT)
347 DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob,
348 ippErrorString(cupsLastError())));
355 DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob,
356 ippErrorString(cupsLastError())));
365 * 'cups_job_pause()' - Pause a job.
369 cups_job_pause(int snum, struct printjob *pjob)
371 int ret; /* Return value */
372 http_t *http; /* HTTP connection to server */
373 ipp_t *request, /* IPP Request */
374 *response; /* IPP Response */
375 cups_lang_t *language; /* Default language */
376 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
379 DEBUG(5,("cups_job_pause(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
382 * Make sure we don't ask for passwords...
385 cupsSetPasswordCB(cups_passwd_cb);
388 * Try to connect to the server...
391 if ((http = httpConnect(cups_server(), ippPort())) == NULL)
393 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
394 cups_server(), strerror(errno)));
399 * Build an IPP_HOLD_JOB request, which requires the following
403 * attributes-natural-language
405 * requesting-user-name
410 request->request.op.operation_id = IPP_HOLD_JOB;
411 request->request.op.request_id = 1;
413 language = cupsLangDefault();
415 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
416 "attributes-charset", NULL, cupsLangEncoding(language));
418 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
419 "attributes-natural-language", NULL, language->language);
421 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
423 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
425 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
429 * Do the request and get back a response...
434 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL)
436 if (response->request.status.status_code >= IPP_OK_CONFLICT)
437 DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob,
438 ippErrorString(cupsLastError())));
445 DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob,
446 ippErrorString(cupsLastError())));
455 * 'cups_job_resume()' - Resume a paused job.
459 cups_job_resume(int snum, struct printjob *pjob)
461 int ret; /* Return value */
462 http_t *http; /* HTTP connection to server */
463 ipp_t *request, /* IPP Request */
464 *response; /* IPP Response */
465 cups_lang_t *language; /* Default language */
466 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
469 DEBUG(5,("cups_job_resume(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
472 * Make sure we don't ask for passwords...
475 cupsSetPasswordCB(cups_passwd_cb);
478 * Try to connect to the server...
481 if ((http = httpConnect(cups_server(), ippPort())) == NULL)
483 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
484 cups_server(), strerror(errno)));
489 * Build an IPP_RELEASE_JOB request, which requires the following
493 * attributes-natural-language
495 * requesting-user-name
500 request->request.op.operation_id = IPP_RELEASE_JOB;
501 request->request.op.request_id = 1;
503 language = cupsLangDefault();
505 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
506 "attributes-charset", NULL, cupsLangEncoding(language));
508 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
509 "attributes-natural-language", NULL, language->language);
511 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
513 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
515 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
519 * Do the request and get back a response...
524 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL)
526 if (response->request.status.status_code >= IPP_OK_CONFLICT)
527 DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob,
528 ippErrorString(cupsLastError())));
535 DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob,
536 ippErrorString(cupsLastError())));
545 * 'cups_job_submit()' - Submit a job for printing.
549 cups_job_submit(int snum, struct printjob *pjob)
551 int ret; /* Return value */
552 http_t *http; /* HTTP connection to server */
553 ipp_t *request, /* IPP Request */
554 *response; /* IPP Response */
555 cups_lang_t *language; /* Default language */
556 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
557 char *clientname; /* hostname of client for job-originating-host attribute */
560 cups_option_t *options;
562 DEBUG(5,("cups_job_submit(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
565 * Make sure we don't ask for passwords...
568 cupsSetPasswordCB(cups_passwd_cb);
571 * Try to connect to the server...
574 if ((http = httpConnect(cups_server(), ippPort())) == NULL)
576 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
577 cups_server(), strerror(errno)));
582 * Build an IPP_PRINT_JOB request, which requires the following
586 * attributes-natural-language
588 * requesting-user-name
594 request->request.op.operation_id = IPP_PRINT_JOB;
595 request->request.op.request_id = 1;
597 language = cupsLangDefault();
599 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
600 "attributes-charset", NULL, cupsLangEncoding(language));
602 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
603 "attributes-natural-language", NULL, language->language);
605 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
608 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
609 "printer-uri", NULL, uri);
611 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
614 clientname = client_name();
615 if (strcmp(clientname, "UNKNOWN") == 0) {
616 clientname = client_addr();
619 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
620 "job-originating-host-name", NULL,
623 pstr_sprintf(new_jobname,"%s%.8u %s", PRINT_SPOOL_PREFIX,
624 (unsigned int)pjob->smbjob, pjob->jobname);
626 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "job-name", NULL,
630 * add any options defined in smb.conf
635 num_options = cupsParseOptions(lp_cups_options(snum), num_options, &options);
638 cupsEncodeOptions(request, num_options, options);
641 * Do the request and get back a response...
644 slprintf(uri, sizeof(uri) - 1, "/printers/%s", PRINTERNAME(snum));
647 if ((response = cupsDoFileRequest(http, request, uri,
648 pjob->filename)) != NULL)
650 if (response->request.status.status_code >= IPP_OK_CONFLICT)
651 DEBUG(0,("Unable to print file to %s - %s\n", PRINTERNAME(snum),
652 ippErrorString(cupsLastError())));
659 DEBUG(0,("Unable to print file to `%s' - %s\n", PRINTERNAME(snum),
660 ippErrorString(cupsLastError())));
665 unlink(pjob->filename);
666 /* else print_job_end will do it for us */
672 * 'cups_queue_get()' - Get all the jobs in the print queue.
676 cups_queue_get(const char *printer_name,
677 enum printing_types printing_type,
679 print_queue_struct **q,
680 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(%s, %p, %p)\n", printer_name, 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(cups_server(), ippPort())) == NULL)
730 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
731 cups_server(), strerror(errno)));
736 * Generate the printer URI...
739 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s", printer_name);
742 * Build an IPP_GET_JOBS request, which requires the following
746 * attributes-natural-language
747 * requested-attributes
753 request->request.op.operation_id = IPP_GET_JOBS;
754 request->request.op.request_id = 1;
756 language = cupsLangDefault();
758 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
759 "attributes-charset", NULL, cupsLangEncoding(language));
761 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
762 "attributes-natural-language", NULL, language->language);
764 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
765 "requested-attributes",
766 (sizeof(jattrs) / sizeof(jattrs[0])),
769 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
770 "printer-uri", NULL, uri);
773 * Do the request and get back a response...
776 if ((response = cupsDoRequest(http, request, "/")) == NULL)
778 DEBUG(0,("Unable to get jobs for %s - %s\n", uri,
779 ippErrorString(cupsLastError())));
784 if (response->request.status.status_code >= IPP_OK_CONFLICT)
786 DEBUG(0,("Unable to get jobs for %s - %s\n", uri,
787 ippErrorString(response->request.status.status_code)));
795 * Process the jobs...
802 for (attr = response->attrs; attr != NULL; attr = attr->next)
805 * Skip leading attributes until we hit a job...
808 while (attr != NULL && attr->group_tag != IPP_TAG_JOB)
815 * Allocate memory as needed...
817 if (qcount >= qalloc)
821 temp = SMB_REALLOC_ARRAY(queue, print_queue_struct, qalloc);
825 DEBUG(0,("cups_queue_get: Not enough memory!"));
836 temp = queue + qcount;
837 memset(temp, 0, sizeof(print_queue_struct));
840 * Pull the needed attributes from this job...
845 job_status = IPP_JOB_PENDING;
851 while (attr != NULL && attr->group_tag == IPP_TAG_JOB)
853 if (attr->name == NULL)
859 if (strcmp(attr->name, "job-id") == 0 &&
860 attr->value_tag == IPP_TAG_INTEGER)
861 job_id = attr->values[0].integer;
863 if (strcmp(attr->name, "job-k-octets") == 0 &&
864 attr->value_tag == IPP_TAG_INTEGER)
865 job_k_octets = attr->values[0].integer;
867 if (strcmp(attr->name, "job-priority") == 0 &&
868 attr->value_tag == IPP_TAG_INTEGER)
869 job_priority = attr->values[0].integer;
871 if (strcmp(attr->name, "job-state") == 0 &&
872 attr->value_tag == IPP_TAG_ENUM)
873 job_status = (ipp_jstate_t)(attr->values[0].integer);
875 if (strcmp(attr->name, "time-at-creation") == 0 &&
876 attr->value_tag == IPP_TAG_INTEGER)
877 job_time = attr->values[0].integer;
879 if (strcmp(attr->name, "job-name") == 0 &&
880 attr->value_tag == IPP_TAG_NAME)
881 job_name = attr->values[0].string.text;
883 if (strcmp(attr->name, "job-originating-user-name") == 0 &&
884 attr->value_tag == IPP_TAG_NAME)
885 user_name = attr->values[0].string.text;
891 * See if we have everything needed...
894 if (user_name == NULL || job_name == NULL || job_id == 0)
903 temp->size = job_k_octets * 1024;
904 temp->status = job_status == IPP_JOB_PENDING ? LPQ_QUEUED :
905 job_status == IPP_JOB_STOPPED ? LPQ_PAUSED :
906 job_status == IPP_JOB_HELD ? LPQ_PAUSED :
908 temp->priority = job_priority;
909 temp->time = job_time;
910 strncpy(temp->fs_user, user_name, sizeof(temp->fs_user) - 1);
911 strncpy(temp->fs_file, job_name, sizeof(temp->fs_file) - 1);
922 * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the
923 * following attributes:
926 * attributes-natural-language
927 * requested-attributes
933 request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
934 request->request.op.request_id = 1;
936 language = cupsLangDefault();
938 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
939 "attributes-charset", NULL, cupsLangEncoding(language));
941 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
942 "attributes-natural-language", NULL, language->language);
944 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
945 "requested-attributes",
946 (sizeof(pattrs) / sizeof(pattrs[0])),
949 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
950 "printer-uri", NULL, uri);
953 * Do the request and get back a response...
956 if ((response = cupsDoRequest(http, request, "/")) == NULL)
958 DEBUG(0,("Unable to get printer status for %s - %s\n", printer_name,
959 ippErrorString(cupsLastError())));
965 if (response->request.status.status_code >= IPP_OK_CONFLICT)
967 DEBUG(0,("Unable to get printer status for %s - %s\n", printer_name,
968 ippErrorString(response->request.status.status_code)));
976 * Get the current printer status and convert it to the SAMBA values.
979 if ((attr = ippFindAttribute(response, "printer-state", IPP_TAG_ENUM)) != NULL)
981 if (attr->values[0].integer == IPP_PRINTER_STOPPED)
982 status->status = LPSTAT_STOPPED;
984 status->status = LPSTAT_OK;
987 if ((attr = ippFindAttribute(response, "printer-state-message",
988 IPP_TAG_TEXT)) != NULL)
989 fstrcpy(status->message, attr->values[0].string.text);
994 * Return the job queue...
1005 * 'cups_queue_pause()' - Pause a print queue.
1009 cups_queue_pause(int snum)
1011 extern userdom_struct current_user_info;
1012 int ret; /* Return value */
1013 http_t *http; /* HTTP connection to server */
1014 ipp_t *request, /* IPP Request */
1015 *response; /* IPP Response */
1016 cups_lang_t *language; /* Default language */
1017 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
1020 DEBUG(5,("cups_queue_pause(%d)\n", snum));
1023 * Make sure we don't ask for passwords...
1026 cupsSetPasswordCB(cups_passwd_cb);
1029 * Try to connect to the server...
1032 if ((http = httpConnect(cups_server(), ippPort())) == NULL)
1034 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
1035 cups_server(), strerror(errno)));
1040 * Build an IPP_PAUSE_PRINTER request, which requires the following
1043 * attributes-charset
1044 * attributes-natural-language
1046 * requesting-user-name
1051 request->request.op.operation_id = IPP_PAUSE_PRINTER;
1052 request->request.op.request_id = 1;
1054 language = cupsLangDefault();
1056 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1057 "attributes-charset", NULL, cupsLangEncoding(language));
1059 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1060 "attributes-natural-language", NULL, language->language);
1062 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
1065 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
1067 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
1068 NULL, current_user_info.unix_name);
1071 * Do the request and get back a response...
1076 if ((response = cupsDoRequest(http, request, "/admin/")) != NULL)
1078 if (response->request.status.status_code >= IPP_OK_CONFLICT)
1079 DEBUG(0,("Unable to pause printer %s - %s\n", PRINTERNAME(snum),
1080 ippErrorString(cupsLastError())));
1084 ippDelete(response);
1087 DEBUG(0,("Unable to pause printer %s - %s\n", PRINTERNAME(snum),
1088 ippErrorString(cupsLastError())));
1097 * 'cups_queue_resume()' - Restart a print queue.
1101 cups_queue_resume(int snum)
1103 extern userdom_struct current_user_info;
1104 int ret; /* Return value */
1105 http_t *http; /* HTTP connection to server */
1106 ipp_t *request, /* IPP Request */
1107 *response; /* IPP Response */
1108 cups_lang_t *language; /* Default language */
1109 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
1112 DEBUG(5,("cups_queue_resume(%d)\n", snum));
1115 * Make sure we don't ask for passwords...
1118 cupsSetPasswordCB(cups_passwd_cb);
1121 * Try to connect to the server...
1124 if ((http = httpConnect(cups_server(), ippPort())) == NULL)
1126 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
1127 cups_server(), strerror(errno)));
1132 * Build an IPP_RESUME_PRINTER request, which requires the following
1135 * attributes-charset
1136 * attributes-natural-language
1138 * requesting-user-name
1143 request->request.op.operation_id = IPP_RESUME_PRINTER;
1144 request->request.op.request_id = 1;
1146 language = cupsLangDefault();
1148 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1149 "attributes-charset", NULL, cupsLangEncoding(language));
1151 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1152 "attributes-natural-language", NULL, language->language);
1154 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
1157 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
1159 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
1160 NULL, current_user_info.unix_name);
1163 * Do the request and get back a response...
1168 if ((response = cupsDoRequest(http, request, "/admin/")) != NULL)
1170 if (response->request.status.status_code >= IPP_OK_CONFLICT)
1171 DEBUG(0,("Unable to resume printer %s - %s\n", PRINTERNAME(snum),
1172 ippErrorString(cupsLastError())));
1176 ippDelete(response);
1179 DEBUG(0,("Unable to resume printer %s - %s\n", PRINTERNAME(snum),
1180 ippErrorString(cupsLastError())));
1187 /*******************************************************************
1188 * CUPS printing interface definitions...
1189 ******************************************************************/
1191 struct printif cups_printif =
1204 /* this keeps fussy compilers happy */
1205 void print_cups_dummy(void) {}
1206 #endif /* HAVE_CUPS */