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 = NULL; /* HTTP connection to server */
58 ipp_t *request = NULL, /* IPP Request */
59 *response = NULL; /* IPP Response */
60 ipp_attribute_t *attr; /* Current attribute */
61 cups_lang_t *language = NULL; /* 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) {
84 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
85 cups_server(), strerror(errno)));
90 * Build a CUPS_GET_PRINTERS request, which requires the following
94 * attributes-natural-language
95 * requested-attributes
100 request->request.op.operation_id = CUPS_GET_PRINTERS;
101 request->request.op.request_id = 1;
103 language = cupsLangDefault();
105 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
106 "attributes-charset", NULL, cupsLangEncoding(language));
108 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
109 "attributes-natural-language", NULL, language->language);
111 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
112 "requested-attributes",
113 (sizeof(requested) / sizeof(requested[0])),
117 * Do the request and get back a response...
120 if ((response = cupsDoRequest(http, request, "/")) == NULL) {
121 DEBUG(0,("Unable to get printer list - %s\n",
122 ippErrorString(cupsLastError())));
126 for (attr = response->attrs; attr != NULL;) {
128 * Skip leading attributes until we hit a printer...
131 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
138 * Pull the needed attributes from this printer...
144 while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) {
145 if (strcmp(attr->name, "printer-name") == 0 &&
146 attr->value_tag == IPP_TAG_NAME)
147 name = attr->values[0].string.text;
149 if (strcmp(attr->name, "printer-info") == 0 &&
150 attr->value_tag == IPP_TAG_TEXT)
151 info = attr->values[0].string.text;
157 * See if we have everything needed...
163 if (!pcap_cache_add(name, info)) {
172 * Build a CUPS_GET_CLASSES request, which requires the following
176 * attributes-natural-language
177 * requested-attributes
182 request->request.op.operation_id = CUPS_GET_CLASSES;
183 request->request.op.request_id = 1;
185 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
186 "attributes-charset", NULL, cupsLangEncoding(language));
188 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
189 "attributes-natural-language", NULL, language->language);
191 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
192 "requested-attributes",
193 (sizeof(requested) / sizeof(requested[0])),
197 * Do the request and get back a response...
200 if ((response = cupsDoRequest(http, request, "/")) == NULL) {
201 DEBUG(0,("Unable to get printer list - %s\n",
202 ippErrorString(cupsLastError())));
206 for (attr = response->attrs; attr != NULL;) {
208 * Skip leading attributes until we hit a printer...
211 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
218 * Pull the needed attributes from this printer...
224 while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) {
225 if (strcmp(attr->name, "printer-name") == 0 &&
226 attr->value_tag == IPP_TAG_NAME)
227 name = attr->values[0].string.text;
229 if (strcmp(attr->name, "printer-info") == 0 &&
230 attr->value_tag == IPP_TAG_TEXT)
231 info = attr->values[0].string.text;
237 * See if we have everything needed...
243 if (!pcap_cache_add(name, info)) {
255 cupsLangFree(language);
265 * 'cups_job_delete()' - Delete a job.
268 static int cups_job_delete(int snum, struct printjob *pjob)
270 int ret = 1; /* Return value */
271 http_t *http = NULL; /* HTTP connection to server */
272 ipp_t *request = NULL, /* IPP Request */
273 *response = NULL; /* IPP Response */
274 cups_lang_t *language = NULL; /* Default language */
275 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
278 DEBUG(5,("cups_job_delete(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
281 * Make sure we don't ask for passwords...
284 cupsSetPasswordCB(cups_passwd_cb);
287 * Try to connect to the server...
290 if ((http = httpConnect(cups_server(), ippPort())) == NULL) {
291 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
292 cups_server(), strerror(errno)));
297 * Build an IPP_CANCEL_JOB request, which requires the following
301 * attributes-natural-language
303 * requesting-user-name
308 request->request.op.operation_id = IPP_CANCEL_JOB;
309 request->request.op.request_id = 1;
311 language = cupsLangDefault();
313 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
314 "attributes-charset", NULL, cupsLangEncoding(language));
316 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
317 "attributes-natural-language", NULL, language->language);
319 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
321 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
323 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
327 * Do the request and get back a response...
330 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) {
331 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
332 DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob,
333 ippErrorString(cupsLastError())));
338 DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob,
339 ippErrorString(cupsLastError())));
347 cupsLangFree(language);
357 * 'cups_job_pause()' - Pause a job.
360 static int cups_job_pause(int snum, struct printjob *pjob)
362 int ret = 1; /* Return value */
363 http_t *http = NULL; /* HTTP connection to server */
364 ipp_t *request = NULL, /* IPP Request */
365 *response = NULL; /* IPP Response */
366 cups_lang_t *language = NULL; /* Default language */
367 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
370 DEBUG(5,("cups_job_pause(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
373 * Make sure we don't ask for passwords...
376 cupsSetPasswordCB(cups_passwd_cb);
379 * Try to connect to the server...
382 if ((http = httpConnect(cups_server(), ippPort())) == NULL) {
383 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
384 cups_server(), strerror(errno)));
389 * Build an IPP_HOLD_JOB request, which requires the following
393 * attributes-natural-language
395 * requesting-user-name
400 request->request.op.operation_id = IPP_HOLD_JOB;
401 request->request.op.request_id = 1;
403 language = cupsLangDefault();
405 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
406 "attributes-charset", NULL, cupsLangEncoding(language));
408 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
409 "attributes-natural-language", NULL, language->language);
411 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
413 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
415 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
419 * Do the request and get back a response...
422 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) {
423 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
424 DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob,
425 ippErrorString(cupsLastError())));
430 DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob,
431 ippErrorString(cupsLastError())));
439 cupsLangFree(language);
449 * 'cups_job_resume()' - Resume a paused job.
452 static int cups_job_resume(int snum, struct printjob *pjob)
454 int ret = 1; /* Return value */
455 http_t *http = NULL; /* HTTP connection to server */
456 ipp_t *request = NULL, /* IPP Request */
457 *response = NULL; /* IPP Response */
458 cups_lang_t *language = NULL; /* Default language */
459 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
462 DEBUG(5,("cups_job_resume(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
465 * Make sure we don't ask for passwords...
468 cupsSetPasswordCB(cups_passwd_cb);
471 * Try to connect to the server...
474 if ((http = httpConnect(cups_server(), ippPort())) == NULL) {
475 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
476 cups_server(), strerror(errno)));
481 * Build an IPP_RELEASE_JOB request, which requires the following
485 * attributes-natural-language
487 * requesting-user-name
492 request->request.op.operation_id = IPP_RELEASE_JOB;
493 request->request.op.request_id = 1;
495 language = cupsLangDefault();
497 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
498 "attributes-charset", NULL, cupsLangEncoding(language));
500 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
501 "attributes-natural-language", NULL, language->language);
503 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
505 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
507 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
511 * Do the request and get back a response...
514 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) {
515 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
516 DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob,
517 ippErrorString(cupsLastError())));
522 DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob,
523 ippErrorString(cupsLastError())));
531 cupsLangFree(language);
541 * 'cups_job_submit()' - Submit a job for printing.
544 static int cups_job_submit(int snum, struct printjob *pjob)
546 int ret = 1; /* Return value */
547 http_t *http = NULL; /* HTTP connection to server */
548 ipp_t *request = NULL, /* IPP Request */
549 *response = NULL; /* IPP Response */
550 cups_lang_t *language = NULL; /* Default language */
551 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
552 char *clientname = NULL; /* hostname of client for job-originating-host attribute */
555 cups_option_t *options = NULL;
557 DEBUG(5,("cups_job_submit(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
560 * Make sure we don't ask for passwords...
563 cupsSetPasswordCB(cups_passwd_cb);
566 * Try to connect to the server...
569 if ((http = httpConnect(cups_server(), ippPort())) == NULL) {
570 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
571 cups_server(), strerror(errno)));
576 * Build an IPP_PRINT_JOB request, which requires the following
580 * attributes-natural-language
582 * requesting-user-name
588 request->request.op.operation_id = IPP_PRINT_JOB;
589 request->request.op.request_id = 1;
591 language = cupsLangDefault();
593 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
594 "attributes-charset", NULL, cupsLangEncoding(language));
596 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
597 "attributes-natural-language", NULL, language->language);
599 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
602 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
603 "printer-uri", NULL, uri);
605 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
608 clientname = client_name();
609 if (strcmp(clientname, "UNKNOWN") == 0) {
610 clientname = client_addr();
613 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
614 "job-originating-host-name", NULL,
617 pstr_sprintf(new_jobname,"%s%.8u %s", PRINT_SPOOL_PREFIX,
618 (unsigned int)pjob->smbjob, pjob->jobname);
620 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "job-name", NULL,
624 * add any options defined in smb.conf
629 num_options = cupsParseOptions(lp_cups_options(snum), num_options, &options);
632 cupsEncodeOptions(request, num_options, options);
635 * Do the request and get back a response...
638 slprintf(uri, sizeof(uri) - 1, "/printers/%s", PRINTERNAME(snum));
640 if ((response = cupsDoFileRequest(http, request, uri, pjob->filename)) != NULL) {
641 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
642 DEBUG(0,("Unable to print file to %s - %s\n", PRINTERNAME(snum),
643 ippErrorString(cupsLastError())));
648 DEBUG(0,("Unable to print file to `%s' - %s\n", PRINTERNAME(snum),
649 ippErrorString(cupsLastError())));
653 unlink(pjob->filename);
654 /* else print_job_end will do it for us */
661 cupsLangFree(language);
670 * 'cups_queue_get()' - Get all the jobs in the print queue.
673 static int cups_queue_get(const char *printer_name,
674 enum printing_types printing_type,
676 print_queue_struct **q,
677 print_status_struct *status)
679 http_t *http = NULL; /* HTTP connection to server */
680 ipp_t *request = NULL, /* IPP Request */
681 *response = NULL; /* IPP Response */
682 ipp_attribute_t *attr = NULL; /* Current attribute */
683 cups_lang_t *language = NULL; /* Default language */
684 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
685 int qcount = 0, /* Number of active queue entries */
686 qalloc = 0; /* Number of queue entries allocated */
687 print_queue_struct *queue = NULL, /* 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"
714 DEBUG(5,("cups_queue_get(%s, %p, %p)\n", printer_name, q, status));
717 * Make sure we don't ask for passwords...
720 cupsSetPasswordCB(cups_passwd_cb);
723 * Try to connect to the server...
726 if ((http = httpConnect(cups_server(), ippPort())) == NULL) {
727 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
728 cups_server(), strerror(errno)));
733 * Generate the printer URI...
736 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s", printer_name);
739 * Build an IPP_GET_JOBS request, which requires the following
743 * attributes-natural-language
744 * requested-attributes
750 request->request.op.operation_id = IPP_GET_JOBS;
751 request->request.op.request_id = 1;
753 language = cupsLangDefault();
755 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
756 "attributes-charset", NULL, cupsLangEncoding(language));
758 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
759 "attributes-natural-language", NULL, language->language);
761 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
762 "requested-attributes",
763 (sizeof(jattrs) / sizeof(jattrs[0])),
766 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
767 "printer-uri", NULL, uri);
770 * Do the request and get back a response...
773 if ((response = cupsDoRequest(http, request, "/")) == NULL) {
774 DEBUG(0,("Unable to get jobs for %s - %s\n", uri,
775 ippErrorString(cupsLastError())));
779 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
780 DEBUG(0,("Unable to get jobs for %s - %s\n", uri,
781 ippErrorString(response->request.status.status_code)));
786 * Process the jobs...
793 for (attr = response->attrs; attr != NULL; attr = attr->next) {
795 * Skip leading attributes until we hit a job...
798 while (attr != NULL && attr->group_tag != IPP_TAG_JOB)
805 * Allocate memory as needed...
807 if (qcount >= qalloc) {
810 temp = SMB_REALLOC_ARRAY(queue, print_queue_struct, qalloc);
813 DEBUG(0,("cups_queue_get: Not enough memory!"));
822 temp = queue + qcount;
823 memset(temp, 0, sizeof(print_queue_struct));
826 * Pull the needed attributes from this job...
831 job_status = IPP_JOB_PENDING;
837 while (attr != NULL && attr->group_tag == IPP_TAG_JOB) {
838 if (attr->name == NULL) {
843 if (strcmp(attr->name, "job-id") == 0 &&
844 attr->value_tag == IPP_TAG_INTEGER)
845 job_id = attr->values[0].integer;
847 if (strcmp(attr->name, "job-k-octets") == 0 &&
848 attr->value_tag == IPP_TAG_INTEGER)
849 job_k_octets = attr->values[0].integer;
851 if (strcmp(attr->name, "job-priority") == 0 &&
852 attr->value_tag == IPP_TAG_INTEGER)
853 job_priority = attr->values[0].integer;
855 if (strcmp(attr->name, "job-state") == 0 &&
856 attr->value_tag == IPP_TAG_ENUM)
857 job_status = (ipp_jstate_t)(attr->values[0].integer);
859 if (strcmp(attr->name, "time-at-creation") == 0 &&
860 attr->value_tag == IPP_TAG_INTEGER)
861 job_time = attr->values[0].integer;
863 if (strcmp(attr->name, "job-name") == 0 &&
864 attr->value_tag == IPP_TAG_NAME)
865 job_name = attr->values[0].string.text;
867 if (strcmp(attr->name, "job-originating-user-name") == 0 &&
868 attr->value_tag == IPP_TAG_NAME)
869 user_name = attr->values[0].string.text;
875 * See if we have everything needed...
878 if (user_name == NULL || job_name == NULL || job_id == 0) {
886 temp->size = job_k_octets * 1024;
887 temp->status = job_status == IPP_JOB_PENDING ? LPQ_QUEUED :
888 job_status == IPP_JOB_STOPPED ? LPQ_PAUSED :
889 job_status == IPP_JOB_HELD ? LPQ_PAUSED :
891 temp->priority = job_priority;
892 temp->time = job_time;
893 strncpy(temp->fs_user, user_name, sizeof(temp->fs_user) - 1);
894 strncpy(temp->fs_file, job_name, sizeof(temp->fs_file) - 1);
906 * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the
907 * following attributes:
910 * attributes-natural-language
911 * requested-attributes
915 request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
916 request->request.op.request_id = 1;
918 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
919 "attributes-charset", NULL, cupsLangEncoding(language));
921 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
922 "attributes-natural-language", NULL, language->language);
924 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
925 "requested-attributes",
926 (sizeof(pattrs) / sizeof(pattrs[0])),
929 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
930 "printer-uri", NULL, uri);
933 * Do the request and get back a response...
936 if ((response = cupsDoRequest(http, request, "/")) == NULL) {
937 DEBUG(0,("Unable to get printer status for %s - %s\n", printer_name,
938 ippErrorString(cupsLastError())));
943 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
944 DEBUG(0,("Unable to get printer status for %s - %s\n", printer_name,
945 ippErrorString(response->request.status.status_code)));
951 * Get the current printer status and convert it to the SAMBA values.
954 if ((attr = ippFindAttribute(response, "printer-state", IPP_TAG_ENUM)) != NULL) {
955 if (attr->values[0].integer == IPP_PRINTER_STOPPED)
956 status->status = LPSTAT_STOPPED;
958 status->status = LPSTAT_OK;
961 if ((attr = ippFindAttribute(response, "printer-state-message",
962 IPP_TAG_TEXT)) != NULL)
963 fstrcpy(status->message, attr->values[0].string.text);
966 * Return the job queue...
976 cupsLangFree(language);
986 * 'cups_queue_pause()' - Pause a print queue.
989 static int cups_queue_pause(int snum)
991 extern userdom_struct current_user_info;
992 int ret = 1; /* Return value */
993 http_t *http = NULL; /* HTTP connection to server */
994 ipp_t *request = NULL, /* IPP Request */
995 *response = NULL; /* IPP Response */
996 cups_lang_t *language = NULL; /* Default language */
997 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
1000 DEBUG(5,("cups_queue_pause(%d)\n", snum));
1003 * Make sure we don't ask for passwords...
1006 cupsSetPasswordCB(cups_passwd_cb);
1009 * Try to connect to the server...
1012 if ((http = httpConnect(cups_server(), ippPort())) == NULL) {
1013 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
1014 cups_server(), strerror(errno)));
1019 * Build an IPP_PAUSE_PRINTER request, which requires the following
1022 * attributes-charset
1023 * attributes-natural-language
1025 * requesting-user-name
1030 request->request.op.operation_id = IPP_PAUSE_PRINTER;
1031 request->request.op.request_id = 1;
1033 language = cupsLangDefault();
1035 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1036 "attributes-charset", NULL, cupsLangEncoding(language));
1038 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1039 "attributes-natural-language", NULL, language->language);
1041 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
1044 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
1046 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
1047 NULL, current_user_info.unix_name);
1050 * Do the request and get back a response...
1053 if ((response = cupsDoRequest(http, request, "/admin/")) != NULL) {
1054 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
1055 DEBUG(0,("Unable to pause printer %s - %s\n", PRINTERNAME(snum),
1056 ippErrorString(cupsLastError())));
1061 DEBUG(0,("Unable to pause printer %s - %s\n", PRINTERNAME(snum),
1062 ippErrorString(cupsLastError())));
1067 ippDelete(response);
1070 cupsLangFree(language);
1080 * 'cups_queue_resume()' - Restart a print queue.
1083 static int cups_queue_resume(int snum)
1085 extern userdom_struct current_user_info;
1086 int ret = 1; /* Return value */
1087 http_t *http = NULL; /* HTTP connection to server */
1088 ipp_t *request = NULL, /* IPP Request */
1089 *response = NULL; /* IPP Response */
1090 cups_lang_t *language = NULL; /* Default language */
1091 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
1094 DEBUG(5,("cups_queue_resume(%d)\n", snum));
1097 * Make sure we don't ask for passwords...
1100 cupsSetPasswordCB(cups_passwd_cb);
1103 * Try to connect to the server...
1106 if ((http = httpConnect(cups_server(), ippPort())) == NULL) {
1107 DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
1108 cups_server(), strerror(errno)));
1113 * Build an IPP_RESUME_PRINTER request, which requires the following
1116 * attributes-charset
1117 * attributes-natural-language
1119 * requesting-user-name
1124 request->request.op.operation_id = IPP_RESUME_PRINTER;
1125 request->request.op.request_id = 1;
1127 language = cupsLangDefault();
1129 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1130 "attributes-charset", NULL, cupsLangEncoding(language));
1132 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1133 "attributes-natural-language", NULL, language->language);
1135 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
1138 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
1140 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
1141 NULL, current_user_info.unix_name);
1144 * Do the request and get back a response...
1147 if ((response = cupsDoRequest(http, request, "/admin/")) != NULL) {
1148 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
1149 DEBUG(0,("Unable to resume printer %s - %s\n", PRINTERNAME(snum),
1150 ippErrorString(cupsLastError())));
1155 DEBUG(0,("Unable to resume printer %s - %s\n", PRINTERNAME(snum),
1156 ippErrorString(cupsLastError())));
1161 ippDelete(response);
1164 cupsLangFree(language);
1172 /*******************************************************************
1173 * CUPS printing interface definitions...
1174 ******************************************************************/
1176 struct printif cups_printif =
1189 /* this keeps fussy compilers happy */
1190 void print_cups_dummy(void) {}
1191 #endif /* HAVE_CUPS */