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 3 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, see <http://www.gnu.org/licenses/>.
24 #include <cups/cups.h>
25 #include <cups/language.h>
27 static SIG_ATOMIC_T gotalarm;
29 /***************************************************************
30 Signal function to tell us we timed out.
31 ****************************************************************/
33 static void gotalarm_sig(void)
38 extern userdom_struct current_user_info;
41 * 'cups_passwd_cb()' - The CUPS password callback...
44 static const char * /* O - Password or NULL */
45 cups_passwd_cb(const char *prompt) /* I - Prompt */
48 * Always return NULL to indicate that no password is available...
54 static http_t *cups_connect(void)
59 int timeout = lp_cups_connection_timeout();
64 CatchSignal(SIGALRM, SIGNAL_CAST gotalarm_sig);
68 if (lp_cups_server() != NULL && strlen(lp_cups_server()) > 0) {
69 server = smb_xstrdup(lp_cups_server());
71 server = smb_xstrdup(cupsServer());
74 p = strchr(server, ':');
82 DEBUG(10, ("connecting to cups server %s:%d\n",
85 http = httpConnect(server, port);
87 CatchSignal(SIGALRM, SIGNAL_CAST SIG_IGN);
91 DEBUG(0,("Unable to connect to CUPS server %s:%d - %s\n",
92 server, port, strerror(errno)));
99 bool cups_cache_reload(void)
101 http_t *http = NULL; /* HTTP connection to server */
102 ipp_t *request = NULL, /* IPP Request */
103 *response = NULL; /* IPP Response */
104 ipp_attribute_t *attr; /* Current attribute */
105 cups_lang_t *language = NULL; /* Default language */
106 char *name, /* printer-name attribute */
107 *info; /* printer-info attribute */
108 static const char *requested[] =/* Requested attributes */
115 DEBUG(5, ("reloading cups printcap cache\n"));
118 * Make sure we don't ask for passwords...
121 cupsSetPasswordCB(cups_passwd_cb);
124 * Try to connect to the server...
127 if ((http = cups_connect()) == NULL) {
132 * Build a CUPS_GET_PRINTERS request, which requires the following
136 * attributes-natural-language
137 * requested-attributes
142 request->request.op.operation_id = CUPS_GET_PRINTERS;
143 request->request.op.request_id = 1;
145 language = cupsLangDefault();
147 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
148 "attributes-charset", NULL, cupsLangEncoding(language));
150 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
151 "attributes-natural-language", NULL, language->language);
153 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
154 "requested-attributes",
155 (sizeof(requested) / sizeof(requested[0])),
159 * Do the request and get back a response...
162 if ((response = cupsDoRequest(http, request, "/")) == NULL) {
163 DEBUG(0,("Unable to get printer list - %s\n",
164 ippErrorString(cupsLastError())));
168 for (attr = response->attrs; attr != NULL;) {
170 * Skip leading attributes until we hit a printer...
173 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
180 * Pull the needed attributes from this printer...
186 while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) {
187 if (strcmp(attr->name, "printer-name") == 0 &&
188 attr->value_tag == IPP_TAG_NAME)
189 name = attr->values[0].string.text;
191 if (strcmp(attr->name, "printer-info") == 0 &&
192 attr->value_tag == IPP_TAG_TEXT)
193 info = attr->values[0].string.text;
199 * See if we have everything needed...
205 if (!pcap_cache_add(name, info)) {
214 * Build a CUPS_GET_CLASSES request, which requires the following
218 * attributes-natural-language
219 * requested-attributes
224 request->request.op.operation_id = CUPS_GET_CLASSES;
225 request->request.op.request_id = 1;
227 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
228 "attributes-charset", NULL, cupsLangEncoding(language));
230 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
231 "attributes-natural-language", NULL, language->language);
233 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
234 "requested-attributes",
235 (sizeof(requested) / sizeof(requested[0])),
239 * Do the request and get back a response...
242 if ((response = cupsDoRequest(http, request, "/")) == NULL) {
243 DEBUG(0,("Unable to get printer list - %s\n",
244 ippErrorString(cupsLastError())));
248 for (attr = response->attrs; attr != NULL;) {
250 * Skip leading attributes until we hit a printer...
253 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
260 * Pull the needed attributes from this printer...
266 while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) {
267 if (strcmp(attr->name, "printer-name") == 0 &&
268 attr->value_tag == IPP_TAG_NAME)
269 name = attr->values[0].string.text;
271 if (strcmp(attr->name, "printer-info") == 0 &&
272 attr->value_tag == IPP_TAG_TEXT)
273 info = attr->values[0].string.text;
279 * See if we have everything needed...
285 if (!pcap_cache_add(name, info)) {
297 cupsLangFree(language);
307 * 'cups_job_delete()' - Delete a job.
310 static int cups_job_delete(const char *sharename, const char *lprm_command, struct printjob *pjob)
312 int ret = 1; /* Return value */
313 http_t *http = NULL; /* HTTP connection to server */
314 ipp_t *request = NULL, /* IPP Request */
315 *response = NULL; /* IPP Response */
316 cups_lang_t *language = NULL; /* Default language */
317 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
320 DEBUG(5,("cups_job_delete(%s, %p (%d))\n", sharename, pjob, pjob->sysjob));
323 * Make sure we don't ask for passwords...
326 cupsSetPasswordCB(cups_passwd_cb);
329 * Try to connect to the server...
332 if ((http = cups_connect()) == NULL) {
337 * Build an IPP_CANCEL_JOB request, which requires the following
341 * attributes-natural-language
343 * requesting-user-name
348 request->request.op.operation_id = IPP_CANCEL_JOB;
349 request->request.op.request_id = 1;
351 language = cupsLangDefault();
353 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
354 "attributes-charset", NULL, cupsLangEncoding(language));
356 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
357 "attributes-natural-language", NULL, language->language);
359 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
361 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
363 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
367 * Do the request and get back a response...
370 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) {
371 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
372 DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob,
373 ippErrorString(cupsLastError())));
378 DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob,
379 ippErrorString(cupsLastError())));
387 cupsLangFree(language);
397 * 'cups_job_pause()' - Pause a job.
400 static int cups_job_pause(int snum, struct printjob *pjob)
402 int ret = 1; /* Return value */
403 http_t *http = NULL; /* HTTP connection to server */
404 ipp_t *request = NULL, /* IPP Request */
405 *response = NULL; /* IPP Response */
406 cups_lang_t *language = NULL; /* Default language */
407 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
410 DEBUG(5,("cups_job_pause(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
413 * Make sure we don't ask for passwords...
416 cupsSetPasswordCB(cups_passwd_cb);
419 * Try to connect to the server...
422 if ((http = cups_connect()) == NULL) {
427 * Build an IPP_HOLD_JOB request, which requires the following
431 * attributes-natural-language
433 * requesting-user-name
438 request->request.op.operation_id = IPP_HOLD_JOB;
439 request->request.op.request_id = 1;
441 language = cupsLangDefault();
443 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
444 "attributes-charset", NULL, cupsLangEncoding(language));
446 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
447 "attributes-natural-language", NULL, language->language);
449 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
451 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
453 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
457 * Do the request and get back a response...
460 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) {
461 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
462 DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob,
463 ippErrorString(cupsLastError())));
468 DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob,
469 ippErrorString(cupsLastError())));
477 cupsLangFree(language);
487 * 'cups_job_resume()' - Resume a paused job.
490 static int cups_job_resume(int snum, struct printjob *pjob)
492 int ret = 1; /* Return value */
493 http_t *http = NULL; /* HTTP connection to server */
494 ipp_t *request = NULL, /* IPP Request */
495 *response = NULL; /* IPP Response */
496 cups_lang_t *language = NULL; /* Default language */
497 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
500 DEBUG(5,("cups_job_resume(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
503 * Make sure we don't ask for passwords...
506 cupsSetPasswordCB(cups_passwd_cb);
509 * Try to connect to the server...
512 if ((http = cups_connect()) == NULL) {
517 * Build an IPP_RELEASE_JOB request, which requires the following
521 * attributes-natural-language
523 * requesting-user-name
528 request->request.op.operation_id = IPP_RELEASE_JOB;
529 request->request.op.request_id = 1;
531 language = cupsLangDefault();
533 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
534 "attributes-charset", NULL, cupsLangEncoding(language));
536 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
537 "attributes-natural-language", NULL, language->language);
539 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
541 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
543 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
547 * Do the request and get back a response...
550 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) {
551 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
552 DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob,
553 ippErrorString(cupsLastError())));
558 DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob,
559 ippErrorString(cupsLastError())));
567 cupsLangFree(language);
577 * 'cups_job_submit()' - Submit a job for printing.
580 static int cups_job_submit(int snum, struct printjob *pjob)
582 int ret = 1; /* Return value */
583 http_t *http = NULL; /* HTTP connection to server */
584 ipp_t *request = NULL, /* IPP Request */
585 *response = NULL; /* IPP Response */
586 cups_lang_t *language = NULL; /* Default language */
587 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
588 const char *clientname = NULL; /* hostname of client for job-originating-host attribute */
589 char *new_jobname = NULL;
591 cups_option_t *options = NULL;
592 char addr[INET6_ADDRSTRLEN];
594 DEBUG(5,("cups_job_submit(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
597 * Make sure we don't ask for passwords...
600 cupsSetPasswordCB(cups_passwd_cb);
603 * Try to connect to the server...
606 if ((http = cups_connect()) == NULL) {
611 * Build an IPP_PRINT_JOB request, which requires the following
615 * attributes-natural-language
617 * requesting-user-name
623 request->request.op.operation_id = IPP_PRINT_JOB;
624 request->request.op.request_id = 1;
626 language = cupsLangDefault();
628 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
629 "attributes-charset", NULL, cupsLangEncoding(language));
631 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
632 "attributes-natural-language", NULL, language->language);
634 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
637 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
638 "printer-uri", NULL, uri);
640 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
643 clientname = client_name(get_client_fd());
644 if (strcmp(clientname, "UNKNOWN") == 0) {
645 clientname = client_addr(get_client_fd(),addr,sizeof(addr));
648 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
649 "job-originating-host-name", NULL,
652 if (asprintf(&new_jobname,"%s%.8u %s", PRINT_SPOOL_PREFIX,
653 (unsigned int)pjob->smbjob, pjob->jobname) < 0) {
657 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "job-name", NULL,
661 * add any options defined in smb.conf
666 num_options = cupsParseOptions(lp_cups_options(snum), num_options, &options);
669 cupsEncodeOptions(request, num_options, options);
672 * Do the request and get back a response...
675 slprintf(uri, sizeof(uri) - 1, "/printers/%s", PRINTERNAME(snum));
677 if ((response = cupsDoFileRequest(http, request, uri, pjob->filename)) != NULL) {
678 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
679 DEBUG(0,("Unable to print file to %s - %s\n", PRINTERNAME(snum),
680 ippErrorString(cupsLastError())));
685 DEBUG(0,("Unable to print file to `%s' - %s\n", PRINTERNAME(snum),
686 ippErrorString(cupsLastError())));
690 unlink(pjob->filename);
691 /* else print_job_end will do it for us */
698 cupsLangFree(language);
703 SAFE_FREE(new_jobname);
709 * 'cups_queue_get()' - Get all the jobs in the print queue.
712 static int cups_queue_get(const char *sharename,
713 enum printing_types printing_type,
715 print_queue_struct **q,
716 print_status_struct *status)
719 http_t *http = NULL; /* HTTP connection to server */
720 ipp_t *request = NULL, /* IPP Request */
721 *response = NULL; /* IPP Response */
722 ipp_attribute_t *attr = NULL; /* Current attribute */
723 cups_lang_t *language = NULL; /* Default language */
724 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
725 int qcount = 0, /* Number of active queue entries */
726 qalloc = 0; /* Number of queue entries allocated */
727 print_queue_struct *queue = NULL, /* Queue entries */
728 *temp; /* Temporary pointer for queue */
729 const char *user_name, /* job-originating-user-name attribute */
730 *job_name; /* job-name attribute */
731 int job_id; /* job-id attribute */
732 int job_k_octets; /* job-k-octets attribute */
733 time_t job_time; /* time-at-creation attribute */
734 ipp_jstate_t job_status; /* job-status attribute */
735 int job_priority; /* job-priority attribute */
736 static const char *jattrs[] = /* Requested job attributes */
741 "job-originating-user-name",
746 static const char *pattrs[] = /* Requested printer attributes */
749 "printer-state-message"
754 /* HACK ALERT!!! The problem with support the 'printer name'
755 option is that we key the tdb off the sharename. So we will
756 overload the lpq_command string to pass in the printername
757 (which is basically what we do for non-cups printers ... using
758 the lpq_command to get the queue listing). */
760 fstrcpy( printername, lpq_command );
762 DEBUG(5,("cups_queue_get(%s, %p, %p)\n", printername, q, status));
765 * Make sure we don't ask for passwords...
768 cupsSetPasswordCB(cups_passwd_cb);
771 * Try to connect to the server...
774 if ((http = cups_connect()) == NULL) {
779 * Generate the printer URI...
782 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s", printername);
785 * Build an IPP_GET_JOBS request, which requires the following
789 * attributes-natural-language
790 * requested-attributes
796 request->request.op.operation_id = IPP_GET_JOBS;
797 request->request.op.request_id = 1;
799 language = cupsLangDefault();
801 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
802 "attributes-charset", NULL, cupsLangEncoding(language));
804 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
805 "attributes-natural-language", NULL, language->language);
807 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
808 "requested-attributes",
809 (sizeof(jattrs) / sizeof(jattrs[0])),
812 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
813 "printer-uri", NULL, uri);
816 * Do the request and get back a response...
819 if ((response = cupsDoRequest(http, request, "/")) == NULL) {
820 DEBUG(0,("Unable to get jobs for %s - %s\n", uri,
821 ippErrorString(cupsLastError())));
825 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
826 DEBUG(0,("Unable to get jobs for %s - %s\n", uri,
827 ippErrorString(response->request.status.status_code)));
832 * Process the jobs...
839 for (attr = response->attrs; attr != NULL; attr = attr->next) {
841 * Skip leading attributes until we hit a job...
844 while (attr != NULL && attr->group_tag != IPP_TAG_JOB)
851 * Allocate memory as needed...
853 if (qcount >= qalloc) {
856 queue = SMB_REALLOC_ARRAY(queue, print_queue_struct, qalloc);
859 DEBUG(0,("cups_queue_get: Not enough memory!"));
865 temp = queue + qcount;
866 memset(temp, 0, sizeof(print_queue_struct));
869 * Pull the needed attributes from this job...
874 job_status = IPP_JOB_PENDING;
880 while (attr != NULL && attr->group_tag == IPP_TAG_JOB) {
881 if (attr->name == NULL) {
886 if (strcmp(attr->name, "job-id") == 0 &&
887 attr->value_tag == IPP_TAG_INTEGER)
888 job_id = attr->values[0].integer;
890 if (strcmp(attr->name, "job-k-octets") == 0 &&
891 attr->value_tag == IPP_TAG_INTEGER)
892 job_k_octets = attr->values[0].integer;
894 if (strcmp(attr->name, "job-priority") == 0 &&
895 attr->value_tag == IPP_TAG_INTEGER)
896 job_priority = attr->values[0].integer;
898 if (strcmp(attr->name, "job-state") == 0 &&
899 attr->value_tag == IPP_TAG_ENUM)
900 job_status = (ipp_jstate_t)(attr->values[0].integer);
902 if (strcmp(attr->name, "time-at-creation") == 0 &&
903 attr->value_tag == IPP_TAG_INTEGER)
904 job_time = attr->values[0].integer;
906 if (strcmp(attr->name, "job-name") == 0 &&
907 attr->value_tag == IPP_TAG_NAME)
908 job_name = attr->values[0].string.text;
910 if (strcmp(attr->name, "job-originating-user-name") == 0 &&
911 attr->value_tag == IPP_TAG_NAME)
912 user_name = attr->values[0].string.text;
918 * See if we have everything needed...
921 if (user_name == NULL || job_name == NULL || job_id == 0) {
929 temp->size = job_k_octets * 1024;
930 temp->status = job_status == IPP_JOB_PENDING ? LPQ_QUEUED :
931 job_status == IPP_JOB_STOPPED ? LPQ_PAUSED :
932 job_status == IPP_JOB_HELD ? LPQ_PAUSED :
934 temp->priority = job_priority;
935 temp->time = job_time;
936 strncpy(temp->fs_user, user_name, sizeof(temp->fs_user) - 1);
937 strncpy(temp->fs_file, job_name, sizeof(temp->fs_file) - 1);
949 * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the
950 * following attributes:
953 * attributes-natural-language
954 * requested-attributes
960 request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
961 request->request.op.request_id = 1;
963 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
964 "attributes-charset", NULL, cupsLangEncoding(language));
966 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
967 "attributes-natural-language", NULL, language->language);
969 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
970 "requested-attributes",
971 (sizeof(pattrs) / sizeof(pattrs[0])),
974 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
975 "printer-uri", NULL, uri);
978 * Do the request and get back a response...
981 if ((response = cupsDoRequest(http, request, "/")) == NULL) {
982 DEBUG(0,("Unable to get printer status for %s - %s\n", printername,
983 ippErrorString(cupsLastError())));
988 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
989 DEBUG(0,("Unable to get printer status for %s - %s\n", printername,
990 ippErrorString(response->request.status.status_code)));
996 * Get the current printer status and convert it to the SAMBA values.
999 if ((attr = ippFindAttribute(response, "printer-state", IPP_TAG_ENUM)) != NULL) {
1000 if (attr->values[0].integer == IPP_PRINTER_STOPPED)
1001 status->status = LPSTAT_STOPPED;
1003 status->status = LPSTAT_OK;
1006 if ((attr = ippFindAttribute(response, "printer-state-message",
1007 IPP_TAG_TEXT)) != NULL)
1008 fstrcpy(status->message, attr->values[0].string.text);
1011 * Return the job queue...
1018 ippDelete(response);
1021 cupsLangFree(language);
1031 * 'cups_queue_pause()' - Pause a print queue.
1034 static int cups_queue_pause(int snum)
1036 int ret = 1; /* Return value */
1037 http_t *http = NULL; /* HTTP connection to server */
1038 ipp_t *request = NULL, /* IPP Request */
1039 *response = NULL; /* IPP Response */
1040 cups_lang_t *language = NULL; /* Default language */
1041 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
1044 DEBUG(5,("cups_queue_pause(%d)\n", snum));
1047 * Make sure we don't ask for passwords...
1050 cupsSetPasswordCB(cups_passwd_cb);
1053 * Try to connect to the server...
1056 if ((http = cups_connect()) == NULL) {
1061 * Build an IPP_PAUSE_PRINTER request, which requires the following
1064 * attributes-charset
1065 * attributes-natural-language
1067 * requesting-user-name
1072 request->request.op.operation_id = IPP_PAUSE_PRINTER;
1073 request->request.op.request_id = 1;
1075 language = cupsLangDefault();
1077 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1078 "attributes-charset", NULL, cupsLangEncoding(language));
1080 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1081 "attributes-natural-language", NULL, language->language);
1083 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
1086 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
1088 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
1089 NULL, current_user_info.unix_name);
1092 * Do the request and get back a response...
1095 if ((response = cupsDoRequest(http, request, "/admin/")) != NULL) {
1096 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
1097 DEBUG(0,("Unable to pause printer %s - %s\n", PRINTERNAME(snum),
1098 ippErrorString(cupsLastError())));
1103 DEBUG(0,("Unable to pause printer %s - %s\n", PRINTERNAME(snum),
1104 ippErrorString(cupsLastError())));
1109 ippDelete(response);
1112 cupsLangFree(language);
1122 * 'cups_queue_resume()' - Restart a print queue.
1125 static int cups_queue_resume(int snum)
1127 int ret = 1; /* Return value */
1128 http_t *http = NULL; /* HTTP connection to server */
1129 ipp_t *request = NULL, /* IPP Request */
1130 *response = NULL; /* IPP Response */
1131 cups_lang_t *language = NULL; /* Default language */
1132 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
1135 DEBUG(5,("cups_queue_resume(%d)\n", snum));
1138 * Make sure we don't ask for passwords...
1141 cupsSetPasswordCB(cups_passwd_cb);
1144 * Try to connect to the server...
1147 if ((http = cups_connect()) == NULL) {
1152 * Build an IPP_RESUME_PRINTER request, which requires the following
1155 * attributes-charset
1156 * attributes-natural-language
1158 * requesting-user-name
1163 request->request.op.operation_id = IPP_RESUME_PRINTER;
1164 request->request.op.request_id = 1;
1166 language = cupsLangDefault();
1168 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1169 "attributes-charset", NULL, cupsLangEncoding(language));
1171 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1172 "attributes-natural-language", NULL, language->language);
1174 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
1177 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
1179 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
1180 NULL, current_user_info.unix_name);
1183 * Do the request and get back a response...
1186 if ((response = cupsDoRequest(http, request, "/admin/")) != NULL) {
1187 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
1188 DEBUG(0,("Unable to resume printer %s - %s\n", PRINTERNAME(snum),
1189 ippErrorString(cupsLastError())));
1194 DEBUG(0,("Unable to resume printer %s - %s\n", PRINTERNAME(snum),
1195 ippErrorString(cupsLastError())));
1200 ippDelete(response);
1203 cupsLangFree(language);
1211 /*******************************************************************
1212 * CUPS printing interface definitions...
1213 ******************************************************************/
1215 struct printif cups_printif =
1227 bool cups_pull_comment_location(NT_PRINTER_INFO_LEVEL_2 *printer)
1229 http_t *http = NULL; /* HTTP connection to server */
1230 ipp_t *request = NULL, /* IPP Request */
1231 *response = NULL; /* IPP Response */
1232 ipp_attribute_t *attr; /* Current attribute */
1233 cups_lang_t *language = NULL; /* Default language */
1234 char *name, /* printer-name attribute */
1235 *info, /* printer-info attribute */
1236 *location; /* printer-location attribute */
1237 char uri[HTTP_MAX_URI];
1238 static const char *requested[] =/* Requested attributes */
1246 DEBUG(5, ("pulling %s location\n", printer->sharename));
1249 * Make sure we don't ask for passwords...
1252 cupsSetPasswordCB(cups_passwd_cb);
1255 * Try to connect to the server...
1258 if ((http = cups_connect()) == NULL) {
1264 request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
1265 request->request.op.request_id = 1;
1267 language = cupsLangDefault();
1269 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1270 "attributes-charset", NULL, cupsLangEncoding(language));
1272 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1273 "attributes-natural-language", NULL, language->language);
1275 slprintf(uri, sizeof(uri) - 1, "ipp://%s/printers/%s",
1276 lp_cups_server(), printer->sharename);
1278 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
1279 "printer-uri", NULL, uri);
1281 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
1282 "requested-attributes",
1283 (sizeof(requested) / sizeof(requested[0])),
1287 * Do the request and get back a response...
1290 if ((response = cupsDoRequest(http, request, "/")) == NULL) {
1291 DEBUG(0,("Unable to get printer attributes - %s\n",
1292 ippErrorString(cupsLastError())));
1296 for (attr = response->attrs; attr != NULL;) {
1298 * Skip leading attributes until we hit a printer...
1301 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
1308 * Pull the needed attributes from this printer...
1315 while ( attr && (attr->group_tag == IPP_TAG_PRINTER) ) {
1316 /* Grab the comment if we don't have one */
1317 if ( (strcmp(attr->name, "printer-info") == 0)
1318 && (attr->value_tag == IPP_TAG_TEXT)
1319 && !strlen(printer->comment) )
1321 DEBUG(5,("cups_pull_comment_location: Using cups comment: %s\n",
1322 attr->values[0].string.text));
1323 strlcpy(printer->comment,
1324 attr->values[0].string.text,
1325 sizeof(printer->comment));
1328 /* Grab the location if we don't have one */
1329 if ( (strcmp(attr->name, "printer-location") == 0)
1330 && (attr->value_tag == IPP_TAG_TEXT)
1331 && !strlen(printer->location) )
1333 DEBUG(5,("cups_pull_comment_location: Using cups location: %s\n",
1334 attr->values[0].string.text));
1335 fstrcpy(printer->location,attr->values[0].string.text);
1342 * See if we have everything needed...
1354 ippDelete(response);
1357 cupsLangFree(language);
1366 /* this keeps fussy compilers happy */
1367 void print_cups_dummy(void);
1368 void print_cups_dummy(void) {}
1369 #endif /* HAVE_CUPS */