Allow data flow to be debugged and only log on error. All seems ok now.
[Samba.git] / source / printing / print_cups.c
blob6086bb858b0169d87e8ab8e860e5199572d97100
1 /*
2 * Support code for the Common UNIX Printing System ("CUPS")
4 * Copyright 1999-2003 by Michael R Sweet.
5 * Copyright 2008 Jeremy Allison.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
22 * JRA. Converted to utf8 pull/push.
25 #include "includes.h"
26 #include "printing.h"
28 #ifdef HAVE_CUPS
29 #include <cups/cups.h>
30 #include <cups/language.h>
32 static SIG_ATOMIC_T gotalarm;
34 /***************************************************************
35 Signal function to tell us we timed out.
36 ****************************************************************/
38 static void gotalarm_sig(void)
40 gotalarm = 1;
43 extern userdom_struct current_user_info;
46 * 'cups_passwd_cb()' - The CUPS password callback...
49 static const char * /* O - Password or NULL */
50 cups_passwd_cb(const char *prompt) /* I - Prompt */
53 * Always return NULL to indicate that no password is available...
56 return (NULL);
59 static http_t *cups_connect(TALLOC_CTX *frame)
61 http_t *http = NULL;
62 char *server = NULL, *p = NULL;
63 int port;
64 int timeout = lp_cups_connection_timeout();
65 size_t size;
67 if (lp_cups_server() != NULL && strlen(lp_cups_server()) > 0) {
68 if (!push_utf8_talloc(frame, &server, lp_cups_server(), &size)) {
69 return NULL;
71 } else {
72 server = talloc_strdup(frame,cupsServer());
74 if (!server) {
75 return NULL;
78 p = strchr(server, ':');
79 if (p) {
80 port = atoi(p+1);
81 *p = '\0';
82 } else {
83 port = ippPort();
86 DEBUG(10, ("connecting to cups server %s:%d\n",
87 server, port));
89 gotalarm = 0;
91 if (timeout) {
92 CatchSignal(SIGALRM, SIGNAL_CAST gotalarm_sig);
93 alarm(timeout);
96 http = httpConnect(server, port);
98 CatchSignal(SIGALRM, SIGNAL_CAST SIG_IGN);
99 alarm(0);
101 if (http == NULL) {
102 DEBUG(0,("Unable to connect to CUPS server %s:%d - %s\n",
103 server, port, strerror(errno)));
106 return http;
109 static void send_pcap_info(const char *name, const char *info, void *pd)
111 int fd = *(int *)pd;
112 size_t namelen = name ? strlen(name)+1 : 0;
113 size_t infolen = info ? strlen(info)+1 : 0;
115 DEBUG(11,("send_pcap_info: writing namelen %u\n", (unsigned int)namelen));
116 if (sys_write(fd, &namelen, sizeof(namelen)) != sizeof(namelen)) {
117 DEBUG(10,("send_pcap_info: namelen write failed %s\n",
118 strerror(errno)));
119 return;
121 DEBUG(11,("send_pcap_info: writing infolen %u\n", (unsigned int)infolen));
122 if (sys_write(fd, &infolen, sizeof(infolen)) != sizeof(infolen)) {
123 DEBUG(10,("send_pcap_info: infolen write failed %s\n",
124 strerror(errno)));
125 return;
127 if (namelen) {
128 DEBUG(11,("send_pcap_info: writing name %s\n", name));
129 if (sys_write(fd, name, namelen) != namelen) {
130 DEBUG(10,("send_pcap_info: name write failed %s\n",
131 strerror(errno)));
132 return;
135 if (infolen) {
136 DEBUG(11,("send_pcap_info: writing info %s\n", info));
137 if (sys_write(fd, info, infolen) != infolen) {
138 DEBUG(10,("send_pcap_info: info write failed %s\n",
139 strerror(errno)));
140 return;
145 static bool cups_cache_reload_async(int fd)
147 TALLOC_CTX *frame = talloc_stackframe();
148 struct pcap_cache *tmp_pcap_cache = NULL;
149 http_t *http = NULL; /* HTTP connection to server */
150 ipp_t *request = NULL, /* IPP Request */
151 *response = NULL; /* IPP Response */
152 ipp_attribute_t *attr; /* Current attribute */
153 cups_lang_t *language = NULL; /* Default language */
154 char *name, /* printer-name attribute */
155 *info; /* printer-info attribute */
156 static const char *requested[] =/* Requested attributes */
158 "printer-name",
159 "printer-info"
161 bool ret = False;
162 size_t size;
164 DEBUG(5, ("reloading cups printcap cache\n"));
167 * Make sure we don't ask for passwords...
170 cupsSetPasswordCB(cups_passwd_cb);
173 * Try to connect to the server...
176 if ((http = cups_connect(frame)) == NULL) {
177 goto out;
181 * Build a CUPS_GET_PRINTERS request, which requires the following
182 * attributes:
184 * attributes-charset
185 * attributes-natural-language
186 * requested-attributes
189 request = ippNew();
191 request->request.op.operation_id = CUPS_GET_PRINTERS;
192 request->request.op.request_id = 1;
194 language = cupsLangDefault();
196 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
197 "attributes-charset", NULL, "utf-8");
199 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
200 "attributes-natural-language", NULL, language->language);
202 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
203 "requested-attributes",
204 (sizeof(requested) / sizeof(requested[0])),
205 NULL, requested);
208 * Do the request and get back a response...
211 if ((response = cupsDoRequest(http, request, "/")) == NULL) {
212 DEBUG(0,("Unable to get printer list - %s\n",
213 ippErrorString(cupsLastError())));
214 goto out;
217 for (attr = response->attrs; attr != NULL;) {
219 * Skip leading attributes until we hit a printer...
222 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
223 attr = attr->next;
225 if (attr == NULL)
226 break;
229 * Pull the needed attributes from this printer...
232 name = NULL;
233 info = NULL;
235 while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) {
236 if (strcmp(attr->name, "printer-name") == 0 &&
237 attr->value_tag == IPP_TAG_NAME) {
238 if (!pull_utf8_talloc(frame,
239 &name,
240 attr->values[0].string.text,
241 &size)) {
242 goto out;
246 if (strcmp(attr->name, "printer-info") == 0 &&
247 attr->value_tag == IPP_TAG_TEXT) {
248 if (!pull_utf8_talloc(frame,
249 &info,
250 attr->values[0].string.text,
251 &size)) {
252 goto out;
256 attr = attr->next;
260 * See if we have everything needed...
263 if (name == NULL)
264 break;
266 if (!pcap_cache_add_specific(&tmp_pcap_cache, name, info)) {
267 goto out;
271 ippDelete(response);
272 response = NULL;
275 * Build a CUPS_GET_CLASSES request, which requires the following
276 * attributes:
278 * attributes-charset
279 * attributes-natural-language
280 * requested-attributes
283 request = ippNew();
285 request->request.op.operation_id = CUPS_GET_CLASSES;
286 request->request.op.request_id = 1;
288 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
289 "attributes-charset", NULL, "utf-8");
291 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
292 "attributes-natural-language", NULL, language->language);
294 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
295 "requested-attributes",
296 (sizeof(requested) / sizeof(requested[0])),
297 NULL, requested);
300 * Do the request and get back a response...
303 if ((response = cupsDoRequest(http, request, "/")) == NULL) {
304 DEBUG(0,("Unable to get printer list - %s\n",
305 ippErrorString(cupsLastError())));
306 goto out;
309 for (attr = response->attrs; attr != NULL;) {
311 * Skip leading attributes until we hit a printer...
314 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
315 attr = attr->next;
317 if (attr == NULL)
318 break;
321 * Pull the needed attributes from this printer...
324 name = NULL;
325 info = NULL;
327 while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) {
328 if (strcmp(attr->name, "printer-name") == 0 &&
329 attr->value_tag == IPP_TAG_NAME) {
330 if (!pull_utf8_talloc(frame,
331 &name,
332 attr->values[0].string.text,
333 &size)) {
334 goto out;
338 if (strcmp(attr->name, "printer-info") == 0 &&
339 attr->value_tag == IPP_TAG_TEXT) {
340 if (!pull_utf8_talloc(frame,
341 &info,
342 attr->values[0].string.text,
343 &size)) {
344 goto out;
348 attr = attr->next;
352 * See if we have everything needed...
355 if (name == NULL)
356 break;
358 if (!pcap_cache_add_specific(&tmp_pcap_cache, name, info)) {
359 goto out;
363 ret = True;
365 out:
366 if (response)
367 ippDelete(response);
369 if (language)
370 cupsLangFree(language);
372 if (http)
373 httpClose(http);
375 /* Send all the entries up the pipe. */
376 if (tmp_pcap_cache) {
377 pcap_printer_fn_specific(tmp_pcap_cache,
378 send_pcap_info,
379 (void *)&fd);
381 pcap_cache_destroy_specific(&tmp_pcap_cache);
383 TALLOC_FREE(frame);
384 return ret;
387 static struct pcap_cache *local_pcap_copy;
388 struct fd_event *cache_fd_event;
390 static bool cups_pcap_load_async(int *pfd)
392 int fds[2];
393 pid_t pid;
395 *pfd = -1;
397 if (cache_fd_event) {
398 DEBUG(3,("cups_pcap_load_async: already waiting for "
399 "a refresh event\n" ));
400 return false;
403 DEBUG(5,("cups_pcap_load_async: asynchronously loading cups printers\n"));
405 if (pipe(fds) == -1) {
406 return false;
409 pid = sys_fork();
410 if (pid == (pid_t)-1) {
411 DEBUG(10,("cups_pcap_load_async: fork failed %s\n",
412 strerror(errno) ));
413 close(fds[0]);
414 close(fds[1]);
415 return false;
418 if (pid) {
419 DEBUG(10,("cups_pcap_load_async: child pid = %u\n",
420 (unsigned int)pid ));
421 /* Parent. */
422 close(fds[1]);
423 *pfd = fds[0];
424 return true;
427 /* Child. */
428 close(fds[0]);
429 cups_cache_reload_async(fds[1]);
430 close(fds[1]);
431 _exit(0);
434 static void cups_async_callback(struct event_context *event_ctx,
435 struct fd_event *event,
436 uint16 flags,
437 void *p)
439 TALLOC_CTX *frame = talloc_stackframe();
440 int fd = *(int *)p;
441 struct pcap_cache *tmp_pcap_cache = NULL;
443 DEBUG(5,("cups_async_callback: callback received for printer data. "
444 "fd = %d\n", fd));
446 while (1) {
447 char *name = NULL, *info = NULL;
448 size_t namelen = 0, infolen = 0;
449 ssize_t ret = -1;
451 ret = sys_read(fd, &namelen, sizeof(namelen));
452 if (ret == 0) {
453 /* EOF */
454 break;
456 if (ret != sizeof(namelen)) {
457 DEBUG(10,("cups_async_callback: namelen read failed %d %s\n",
458 errno, strerror(errno)));
459 break;
462 DEBUG(11,("cups_async_callback: read namelen %u\n",
463 (unsigned int)namelen));
465 ret = sys_read(fd, &infolen, sizeof(infolen));
466 if (ret == 0) {
467 /* EOF */
468 break;
470 if (ret != sizeof(infolen)) {
471 DEBUG(10,("cups_async_callback: infolen read failed %s\n",
472 strerror(errno)));
473 break;
476 DEBUG(11,("cups_async_callback: read infolen %u\n",
477 (unsigned int)infolen));
479 if (namelen) {
480 name = TALLOC_ARRAY(frame, char, namelen);
481 if (!name) {
482 break;
484 ret = sys_read(fd, name, namelen);
485 if (ret == 0) {
486 /* EOF */
487 break;
489 if (ret != namelen) {
490 DEBUG(10,("cups_async_callback: name read failed %s\n",
491 strerror(errno)));
492 break;
494 DEBUG(11,("cups_async_callback: read name %s\n",
495 name));
496 } else {
497 name = NULL;
499 if (infolen) {
500 info = TALLOC_ARRAY(frame, char, infolen);
501 if (!info) {
502 break;
504 ret = sys_read(fd, info, infolen);
505 if (ret == 0) {
506 /* EOF */
507 break;
509 if (ret != infolen) {
510 DEBUG(10,("cups_async_callback: info read failed %s\n",
511 strerror(errno)));
512 break;
514 DEBUG(11,("cups_async_callback: read info %s\n",
515 info));
516 } else {
517 info = NULL;
520 /* Add to our local pcap cache. */
521 pcap_cache_add_specific(&tmp_pcap_cache, name, info);
522 TALLOC_FREE(name);
523 TALLOC_FREE(info);
526 TALLOC_FREE(frame);
527 if (tmp_pcap_cache) {
528 /* We got a namelist, replace our local cache. */
529 pcap_cache_destroy_specific(&local_pcap_copy);
530 local_pcap_copy = tmp_pcap_cache;
532 /* And the systemwide pcap cache. */
533 pcap_cache_replace(local_pcap_copy);
534 } else {
535 DEBUG(2,("cups_async_callback: failed to read a new "
536 "printer list\n"));
538 close(fd);
539 TALLOC_FREE(p);
540 TALLOC_FREE(cache_fd_event);
543 bool cups_cache_reload(void)
545 int *p_pipe_fd = TALLOC_P(NULL, int);
547 if (!p_pipe_fd) {
548 return false;
551 /* Set up an async refresh. */
552 if (!cups_pcap_load_async(p_pipe_fd)) {
553 return false;
555 if (!local_pcap_copy) {
556 /* We have no local cache, wait directly for
557 * async refresh to complete.
559 DEBUG(10,("cups_cache_reload: sync read on fd %d\n",
560 *p_pipe_fd ));
562 cups_async_callback(smbd_event_context(),
563 NULL,
564 EVENT_FD_READ,
565 (void *)p_pipe_fd);
566 if (!local_pcap_copy) {
567 return false;
569 } else {
570 /* Replace the system cache with our
571 * local copy. */
572 pcap_cache_replace(local_pcap_copy);
574 DEBUG(10,("cups_cache_reload: async read on fd %d\n",
575 *p_pipe_fd ));
577 /* Trigger an event when the pipe can be read. */
578 cache_fd_event = event_add_fd(smbd_event_context(),
579 NULL, *p_pipe_fd,
580 EVENT_FD_READ,
581 cups_async_callback,
582 (void *)p_pipe_fd);
583 if (!cache_fd_event) {
584 close(*p_pipe_fd);
585 TALLOC_FREE(p_pipe_fd);
586 return false;
589 return true;
593 * 'cups_job_delete()' - Delete a job.
596 static int cups_job_delete(const char *sharename, const char *lprm_command, struct printjob *pjob)
598 TALLOC_CTX *frame = talloc_stackframe();
599 int ret = 1; /* Return value */
600 http_t *http = NULL; /* HTTP connection to server */
601 ipp_t *request = NULL, /* IPP Request */
602 *response = NULL; /* IPP Response */
603 cups_lang_t *language = NULL; /* Default language */
604 char *user = NULL;
605 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
606 size_t size;
608 DEBUG(5,("cups_job_delete(%s, %p (%d))\n", sharename, pjob, pjob->sysjob));
611 * Make sure we don't ask for passwords...
614 cupsSetPasswordCB(cups_passwd_cb);
617 * Try to connect to the server...
620 if ((http = cups_connect(frame)) == NULL) {
621 goto out;
625 * Build an IPP_CANCEL_JOB request, which requires the following
626 * attributes:
628 * attributes-charset
629 * attributes-natural-language
630 * job-uri
631 * requesting-user-name
634 request = ippNew();
636 request->request.op.operation_id = IPP_CANCEL_JOB;
637 request->request.op.request_id = 1;
639 language = cupsLangDefault();
641 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
642 "attributes-charset", NULL, "utf-8");
644 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
645 "attributes-natural-language", NULL, language->language);
647 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
649 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
651 if (!push_utf8_talloc(frame, &user, pjob->user, &size)) {
652 goto out;
655 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
656 NULL, user);
659 * Do the request and get back a response...
662 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) {
663 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
664 DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob,
665 ippErrorString(cupsLastError())));
666 } else {
667 ret = 0;
669 } else {
670 DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob,
671 ippErrorString(cupsLastError())));
674 out:
675 if (response)
676 ippDelete(response);
678 if (language)
679 cupsLangFree(language);
681 if (http)
682 httpClose(http);
684 TALLOC_FREE(frame);
685 return ret;
690 * 'cups_job_pause()' - Pause a job.
693 static int cups_job_pause(int snum, struct printjob *pjob)
695 TALLOC_CTX *frame = talloc_stackframe();
696 int ret = 1; /* Return value */
697 http_t *http = NULL; /* HTTP connection to server */
698 ipp_t *request = NULL, /* IPP Request */
699 *response = NULL; /* IPP Response */
700 cups_lang_t *language = NULL; /* Default language */
701 char *user = NULL;
702 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
703 size_t size;
705 DEBUG(5,("cups_job_pause(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
708 * Make sure we don't ask for passwords...
711 cupsSetPasswordCB(cups_passwd_cb);
714 * Try to connect to the server...
717 if ((http = cups_connect(frame)) == NULL) {
718 goto out;
722 * Build an IPP_HOLD_JOB request, which requires the following
723 * attributes:
725 * attributes-charset
726 * attributes-natural-language
727 * job-uri
728 * requesting-user-name
731 request = ippNew();
733 request->request.op.operation_id = IPP_HOLD_JOB;
734 request->request.op.request_id = 1;
736 language = cupsLangDefault();
738 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
739 "attributes-charset", NULL, "utf-8");
741 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
742 "attributes-natural-language", NULL, language->language);
744 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
746 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
748 if (!push_utf8_talloc(frame, &user, pjob->user, &size)) {
749 goto out;
751 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
752 NULL, user);
755 * Do the request and get back a response...
758 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) {
759 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
760 DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob,
761 ippErrorString(cupsLastError())));
762 } else {
763 ret = 0;
765 } else {
766 DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob,
767 ippErrorString(cupsLastError())));
770 out:
771 if (response)
772 ippDelete(response);
774 if (language)
775 cupsLangFree(language);
777 if (http)
778 httpClose(http);
780 TALLOC_FREE(frame);
781 return ret;
786 * 'cups_job_resume()' - Resume a paused job.
789 static int cups_job_resume(int snum, struct printjob *pjob)
791 TALLOC_CTX *frame = talloc_stackframe();
792 int ret = 1; /* Return value */
793 http_t *http = NULL; /* HTTP connection to server */
794 ipp_t *request = NULL, /* IPP Request */
795 *response = NULL; /* IPP Response */
796 cups_lang_t *language = NULL; /* Default language */
797 char *user = NULL;
798 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
799 size_t size;
801 DEBUG(5,("cups_job_resume(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
804 * Make sure we don't ask for passwords...
807 cupsSetPasswordCB(cups_passwd_cb);
810 * Try to connect to the server...
813 if ((http = cups_connect(frame)) == NULL) {
814 goto out;
818 * Build an IPP_RELEASE_JOB request, which requires the following
819 * attributes:
821 * attributes-charset
822 * attributes-natural-language
823 * job-uri
824 * requesting-user-name
827 request = ippNew();
829 request->request.op.operation_id = IPP_RELEASE_JOB;
830 request->request.op.request_id = 1;
832 language = cupsLangDefault();
834 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
835 "attributes-charset", NULL, "utf-8");
837 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
838 "attributes-natural-language", NULL, language->language);
840 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
842 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
844 if (!push_utf8_talloc(frame, &user, pjob->user, &size)) {
845 goto out;
847 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
848 NULL, user);
851 * Do the request and get back a response...
854 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) {
855 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
856 DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob,
857 ippErrorString(cupsLastError())));
858 } else {
859 ret = 0;
861 } else {
862 DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob,
863 ippErrorString(cupsLastError())));
866 out:
867 if (response)
868 ippDelete(response);
870 if (language)
871 cupsLangFree(language);
873 if (http)
874 httpClose(http);
876 TALLOC_FREE(frame);
877 return ret;
882 * 'cups_job_submit()' - Submit a job for printing.
885 static int cups_job_submit(int snum, struct printjob *pjob)
887 TALLOC_CTX *frame = talloc_stackframe();
888 int ret = 1; /* Return value */
889 http_t *http = NULL; /* HTTP connection to server */
890 ipp_t *request = NULL, /* IPP Request */
891 *response = NULL; /* IPP Response */
892 cups_lang_t *language = NULL; /* Default language */
893 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
894 const char *clientname = NULL; /* hostname of client for job-originating-host attribute */
895 char *new_jobname = NULL;
896 int num_options = 0;
897 cups_option_t *options = NULL;
898 char *printername = NULL;
899 char *user = NULL;
900 char *jobname = NULL;
901 char *cupsoptions = NULL;
902 char *filename = NULL;
903 size_t size;
904 char addr[INET6_ADDRSTRLEN];
906 DEBUG(5,("cups_job_submit(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
909 * Make sure we don't ask for passwords...
912 cupsSetPasswordCB(cups_passwd_cb);
915 * Try to connect to the server...
918 if ((http = cups_connect(frame)) == NULL) {
919 goto out;
923 * Build an IPP_PRINT_JOB request, which requires the following
924 * attributes:
926 * attributes-charset
927 * attributes-natural-language
928 * printer-uri
929 * requesting-user-name
930 * [document-data]
933 request = ippNew();
935 request->request.op.operation_id = IPP_PRINT_JOB;
936 request->request.op.request_id = 1;
938 language = cupsLangDefault();
940 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
941 "attributes-charset", NULL, "utf-8");
943 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
944 "attributes-natural-language", NULL, language->language);
946 if (!push_utf8_talloc(frame, &printername, PRINTERNAME(snum), &size)) {
947 goto out;
949 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
950 printername);
952 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
953 "printer-uri", NULL, uri);
955 if (!push_utf8_talloc(frame, &user, pjob->user, &size)) {
956 goto out;
958 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
959 NULL, user);
961 clientname = client_name(get_client_fd());
962 if (strcmp(clientname, "UNKNOWN") == 0) {
963 clientname = client_addr(get_client_fd(),addr,sizeof(addr));
966 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
967 "job-originating-host-name", NULL,
968 clientname);
970 if (!push_utf8_talloc(frame, &jobname, pjob->jobname, &size)) {
971 goto out;
973 new_jobname = talloc_asprintf(frame,
974 "%s%.8u %s", PRINT_SPOOL_PREFIX,
975 (unsigned int)pjob->smbjob,
976 jobname);
977 if (new_jobname == NULL) {
978 goto out;
981 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "job-name", NULL,
982 new_jobname);
985 * add any options defined in smb.conf
988 if (!push_utf8_talloc(frame, &cupsoptions, lp_cups_options(snum), &size)) {
989 goto out;
991 num_options = 0;
992 options = NULL;
993 num_options = cupsParseOptions(cupsoptions, num_options, &options);
995 if ( num_options )
996 cupsEncodeOptions(request, num_options, options);
999 * Do the request and get back a response...
1002 slprintf(uri, sizeof(uri) - 1, "/printers/%s", printername);
1004 if (!push_utf8_talloc(frame, &filename, pjob->filename, &size)) {
1005 goto out;
1007 if ((response = cupsDoFileRequest(http, request, uri, pjob->filename)) != NULL) {
1008 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
1009 DEBUG(0,("Unable to print file to %s - %s\n", PRINTERNAME(snum),
1010 ippErrorString(cupsLastError())));
1011 } else {
1012 ret = 0;
1014 } else {
1015 DEBUG(0,("Unable to print file to `%s' - %s\n", PRINTERNAME(snum),
1016 ippErrorString(cupsLastError())));
1019 if ( ret == 0 )
1020 unlink(pjob->filename);
1021 /* else print_job_end will do it for us */
1023 out:
1024 if (response)
1025 ippDelete(response);
1027 if (language)
1028 cupsLangFree(language);
1030 if (http)
1031 httpClose(http);
1033 TALLOC_FREE(frame);
1035 return ret;
1039 * 'cups_queue_get()' - Get all the jobs in the print queue.
1042 static int cups_queue_get(const char *sharename,
1043 enum printing_types printing_type,
1044 char *lpq_command,
1045 print_queue_struct **q,
1046 print_status_struct *status)
1048 TALLOC_CTX *frame = talloc_stackframe();
1049 char *printername = NULL;
1050 http_t *http = NULL; /* HTTP connection to server */
1051 ipp_t *request = NULL, /* IPP Request */
1052 *response = NULL; /* IPP Response */
1053 ipp_attribute_t *attr = NULL; /* Current attribute */
1054 cups_lang_t *language = NULL; /* Default language */
1055 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
1056 int qcount = 0, /* Number of active queue entries */
1057 qalloc = 0; /* Number of queue entries allocated */
1058 print_queue_struct *queue = NULL, /* Queue entries */
1059 *temp; /* Temporary pointer for queue */
1060 char *user_name = NULL, /* job-originating-user-name attribute */
1061 *job_name = NULL; /* job-name attribute */
1062 int job_id; /* job-id attribute */
1063 int job_k_octets; /* job-k-octets attribute */
1064 time_t job_time; /* time-at-creation attribute */
1065 ipp_jstate_t job_status; /* job-status attribute */
1066 int job_priority; /* job-priority attribute */
1067 size_t size;
1068 static const char *jattrs[] = /* Requested job attributes */
1070 "job-id",
1071 "job-k-octets",
1072 "job-name",
1073 "job-originating-user-name",
1074 "job-priority",
1075 "job-state",
1076 "time-at-creation",
1078 static const char *pattrs[] = /* Requested printer attributes */
1080 "printer-state",
1081 "printer-state-message"
1084 *q = NULL;
1086 /* HACK ALERT!!! The problem with support the 'printer name'
1087 option is that we key the tdb off the sharename. So we will
1088 overload the lpq_command string to pass in the printername
1089 (which is basically what we do for non-cups printers ... using
1090 the lpq_command to get the queue listing). */
1092 if (!push_utf8_talloc(frame, &printername, lpq_command, &size)) {
1093 goto out;
1095 DEBUG(5,("cups_queue_get(%s, %p, %p)\n", lpq_command, q, status));
1098 * Make sure we don't ask for passwords...
1101 cupsSetPasswordCB(cups_passwd_cb);
1104 * Try to connect to the server...
1107 if ((http = cups_connect(frame)) == NULL) {
1108 goto out;
1112 * Generate the printer URI...
1115 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s", printername);
1118 * Build an IPP_GET_JOBS request, which requires the following
1119 * attributes:
1121 * attributes-charset
1122 * attributes-natural-language
1123 * requested-attributes
1124 * printer-uri
1127 request = ippNew();
1129 request->request.op.operation_id = IPP_GET_JOBS;
1130 request->request.op.request_id = 1;
1132 language = cupsLangDefault();
1134 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1135 "attributes-charset", NULL, "utf-8");
1137 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1138 "attributes-natural-language", NULL, language->language);
1140 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
1141 "requested-attributes",
1142 (sizeof(jattrs) / sizeof(jattrs[0])),
1143 NULL, jattrs);
1145 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
1146 "printer-uri", NULL, uri);
1149 * Do the request and get back a response...
1152 if ((response = cupsDoRequest(http, request, "/")) == NULL) {
1153 DEBUG(0,("Unable to get jobs for %s - %s\n", uri,
1154 ippErrorString(cupsLastError())));
1155 goto out;
1158 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
1159 DEBUG(0,("Unable to get jobs for %s - %s\n", uri,
1160 ippErrorString(response->request.status.status_code)));
1161 goto out;
1165 * Process the jobs...
1168 qcount = 0;
1169 qalloc = 0;
1170 queue = NULL;
1172 for (attr = response->attrs; attr != NULL; attr = attr->next) {
1174 * Skip leading attributes until we hit a job...
1177 while (attr != NULL && attr->group_tag != IPP_TAG_JOB)
1178 attr = attr->next;
1180 if (attr == NULL)
1181 break;
1184 * Allocate memory as needed...
1186 if (qcount >= qalloc) {
1187 qalloc += 16;
1189 queue = SMB_REALLOC_ARRAY(queue, print_queue_struct, qalloc);
1191 if (queue == NULL) {
1192 DEBUG(0,("cups_queue_get: Not enough memory!"));
1193 qcount = 0;
1194 goto out;
1198 temp = queue + qcount;
1199 memset(temp, 0, sizeof(print_queue_struct));
1202 * Pull the needed attributes from this job...
1205 job_id = 0;
1206 job_priority = 50;
1207 job_status = IPP_JOB_PENDING;
1208 job_time = 0;
1209 job_k_octets = 0;
1210 user_name = NULL;
1211 job_name = NULL;
1213 while (attr != NULL && attr->group_tag == IPP_TAG_JOB) {
1214 if (attr->name == NULL) {
1215 attr = attr->next;
1216 break;
1219 if (strcmp(attr->name, "job-id") == 0 &&
1220 attr->value_tag == IPP_TAG_INTEGER)
1221 job_id = attr->values[0].integer;
1223 if (strcmp(attr->name, "job-k-octets") == 0 &&
1224 attr->value_tag == IPP_TAG_INTEGER)
1225 job_k_octets = attr->values[0].integer;
1227 if (strcmp(attr->name, "job-priority") == 0 &&
1228 attr->value_tag == IPP_TAG_INTEGER)
1229 job_priority = attr->values[0].integer;
1231 if (strcmp(attr->name, "job-state") == 0 &&
1232 attr->value_tag == IPP_TAG_ENUM)
1233 job_status = (ipp_jstate_t)(attr->values[0].integer);
1235 if (strcmp(attr->name, "time-at-creation") == 0 &&
1236 attr->value_tag == IPP_TAG_INTEGER)
1237 job_time = attr->values[0].integer;
1239 if (strcmp(attr->name, "job-name") == 0 &&
1240 attr->value_tag == IPP_TAG_NAME) {
1241 if (!pull_utf8_talloc(frame,
1242 &job_name,
1243 attr->values[0].string.text,
1244 &size)) {
1245 goto out;
1249 if (strcmp(attr->name, "job-originating-user-name") == 0 &&
1250 attr->value_tag == IPP_TAG_NAME) {
1251 if (!pull_utf8_talloc(frame,
1252 &user_name,
1253 attr->values[0].string.text,
1254 &size)) {
1255 goto out;
1259 attr = attr->next;
1263 * See if we have everything needed...
1266 if (user_name == NULL || job_name == NULL || job_id == 0) {
1267 if (attr == NULL)
1268 break;
1269 else
1270 continue;
1273 temp->job = job_id;
1274 temp->size = job_k_octets * 1024;
1275 temp->status = job_status == IPP_JOB_PENDING ? LPQ_QUEUED :
1276 job_status == IPP_JOB_STOPPED ? LPQ_PAUSED :
1277 job_status == IPP_JOB_HELD ? LPQ_PAUSED :
1278 LPQ_PRINTING;
1279 temp->priority = job_priority;
1280 temp->time = job_time;
1281 strlcpy(temp->fs_user, user_name, sizeof(temp->fs_user));
1282 strlcpy(temp->fs_file, job_name, sizeof(temp->fs_file));
1284 qcount ++;
1286 if (attr == NULL)
1287 break;
1290 ippDelete(response);
1291 response = NULL;
1294 * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the
1295 * following attributes:
1297 * attributes-charset
1298 * attributes-natural-language
1299 * requested-attributes
1300 * printer-uri
1303 request = ippNew();
1305 request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
1306 request->request.op.request_id = 1;
1308 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1309 "attributes-charset", NULL, "utf-8");
1311 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1312 "attributes-natural-language", NULL, language->language);
1314 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
1315 "requested-attributes",
1316 (sizeof(pattrs) / sizeof(pattrs[0])),
1317 NULL, pattrs);
1319 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
1320 "printer-uri", NULL, uri);
1323 * Do the request and get back a response...
1326 if ((response = cupsDoRequest(http, request, "/")) == NULL) {
1327 DEBUG(0,("Unable to get printer status for %s - %s\n", printername,
1328 ippErrorString(cupsLastError())));
1329 *q = queue;
1330 goto out;
1333 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
1334 DEBUG(0,("Unable to get printer status for %s - %s\n", printername,
1335 ippErrorString(response->request.status.status_code)));
1336 *q = queue;
1337 goto out;
1341 * Get the current printer status and convert it to the SAMBA values.
1344 if ((attr = ippFindAttribute(response, "printer-state", IPP_TAG_ENUM)) != NULL) {
1345 if (attr->values[0].integer == IPP_PRINTER_STOPPED)
1346 status->status = LPSTAT_STOPPED;
1347 else
1348 status->status = LPSTAT_OK;
1351 if ((attr = ippFindAttribute(response, "printer-state-message",
1352 IPP_TAG_TEXT)) != NULL) {
1353 char *msg = NULL;
1354 if (!pull_utf8_talloc(frame, &msg,
1355 attr->values[0].string.text,
1356 &size)) {
1357 goto out;
1359 fstrcpy(status->message, msg);
1363 * Return the job queue...
1366 *q = queue;
1368 out:
1369 if (response)
1370 ippDelete(response);
1372 if (language)
1373 cupsLangFree(language);
1375 if (http)
1376 httpClose(http);
1378 TALLOC_FREE(frame);
1379 return qcount;
1384 * 'cups_queue_pause()' - Pause a print queue.
1387 static int cups_queue_pause(int snum)
1389 TALLOC_CTX *frame = talloc_stackframe();
1390 int ret = 1; /* Return value */
1391 http_t *http = NULL; /* HTTP connection to server */
1392 ipp_t *request = NULL, /* IPP Request */
1393 *response = NULL; /* IPP Response */
1394 cups_lang_t *language = NULL; /* Default language */
1395 char *printername = NULL;
1396 char *username = NULL;
1397 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
1398 size_t size;
1400 DEBUG(5,("cups_queue_pause(%d)\n", snum));
1403 * Make sure we don't ask for passwords...
1406 cupsSetPasswordCB(cups_passwd_cb);
1409 * Try to connect to the server...
1412 if ((http = cups_connect(frame)) == NULL) {
1413 goto out;
1417 * Build an IPP_PAUSE_PRINTER request, which requires the following
1418 * attributes:
1420 * attributes-charset
1421 * attributes-natural-language
1422 * printer-uri
1423 * requesting-user-name
1426 request = ippNew();
1428 request->request.op.operation_id = IPP_PAUSE_PRINTER;
1429 request->request.op.request_id = 1;
1431 language = cupsLangDefault();
1433 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1434 "attributes-charset", NULL, "utf-8");
1436 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1437 "attributes-natural-language", NULL, language->language);
1439 if (!push_utf8_talloc(frame, &printername, PRINTERNAME(snum), &size)) {
1440 goto out;
1442 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
1443 printername);
1445 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
1447 if (!push_utf8_talloc(frame, &username, current_user_info.unix_name, &size)) {
1448 goto out;
1450 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
1451 NULL, username);
1454 * Do the request and get back a response...
1457 if ((response = cupsDoRequest(http, request, "/admin/")) != NULL) {
1458 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
1459 DEBUG(0,("Unable to pause printer %s - %s\n", PRINTERNAME(snum),
1460 ippErrorString(cupsLastError())));
1461 } else {
1462 ret = 0;
1464 } else {
1465 DEBUG(0,("Unable to pause printer %s - %s\n", PRINTERNAME(snum),
1466 ippErrorString(cupsLastError())));
1469 out:
1470 if (response)
1471 ippDelete(response);
1473 if (language)
1474 cupsLangFree(language);
1476 if (http)
1477 httpClose(http);
1479 TALLOC_FREE(frame);
1480 return ret;
1485 * 'cups_queue_resume()' - Restart a print queue.
1488 static int cups_queue_resume(int snum)
1490 TALLOC_CTX *frame = talloc_stackframe();
1491 int ret = 1; /* Return value */
1492 http_t *http = NULL; /* HTTP connection to server */
1493 ipp_t *request = NULL, /* IPP Request */
1494 *response = NULL; /* IPP Response */
1495 cups_lang_t *language = NULL; /* Default language */
1496 char *printername = NULL;
1497 char *username = NULL;
1498 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
1499 size_t size;
1501 DEBUG(5,("cups_queue_resume(%d)\n", snum));
1504 * Make sure we don't ask for passwords...
1507 cupsSetPasswordCB(cups_passwd_cb);
1510 * Try to connect to the server...
1513 if ((http = cups_connect(frame)) == NULL) {
1514 goto out;
1518 * Build an IPP_RESUME_PRINTER request, which requires the following
1519 * attributes:
1521 * attributes-charset
1522 * attributes-natural-language
1523 * printer-uri
1524 * requesting-user-name
1527 request = ippNew();
1529 request->request.op.operation_id = IPP_RESUME_PRINTER;
1530 request->request.op.request_id = 1;
1532 language = cupsLangDefault();
1534 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1535 "attributes-charset", NULL, "utf-8");
1537 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1538 "attributes-natural-language", NULL, language->language);
1540 if (!push_utf8_talloc(frame, &printername, PRINTERNAME(snum), &size)) {
1541 goto out;
1543 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
1544 printername);
1546 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
1548 if (!push_utf8_talloc(frame, &username, current_user_info.unix_name, &size)) {
1549 goto out;
1551 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
1552 NULL, username);
1555 * Do the request and get back a response...
1558 if ((response = cupsDoRequest(http, request, "/admin/")) != NULL) {
1559 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
1560 DEBUG(0,("Unable to resume printer %s - %s\n", PRINTERNAME(snum),
1561 ippErrorString(cupsLastError())));
1562 } else {
1563 ret = 0;
1565 } else {
1566 DEBUG(0,("Unable to resume printer %s - %s\n", PRINTERNAME(snum),
1567 ippErrorString(cupsLastError())));
1570 out:
1571 if (response)
1572 ippDelete(response);
1574 if (language)
1575 cupsLangFree(language);
1577 if (http)
1578 httpClose(http);
1580 TALLOC_FREE(frame);
1581 return ret;
1584 /*******************************************************************
1585 * CUPS printing interface definitions...
1586 ******************************************************************/
1588 struct printif cups_printif =
1590 PRINT_CUPS,
1591 cups_queue_get,
1592 cups_queue_pause,
1593 cups_queue_resume,
1594 cups_job_delete,
1595 cups_job_pause,
1596 cups_job_resume,
1597 cups_job_submit,
1600 bool cups_pull_comment_location(NT_PRINTER_INFO_LEVEL_2 *printer)
1602 TALLOC_CTX *frame = talloc_stackframe();
1603 http_t *http = NULL; /* HTTP connection to server */
1604 ipp_t *request = NULL, /* IPP Request */
1605 *response = NULL; /* IPP Response */
1606 ipp_attribute_t *attr; /* Current attribute */
1607 cups_lang_t *language = NULL; /* Default language */
1608 char uri[HTTP_MAX_URI];
1609 char *server = NULL;
1610 char *sharename = NULL;
1611 char *name = NULL;
1612 static const char *requested[] =/* Requested attributes */
1614 "printer-name",
1615 "printer-info",
1616 "printer-location"
1618 bool ret = False;
1619 size_t size;
1621 DEBUG(5, ("pulling %s location\n", printer->sharename));
1624 * Make sure we don't ask for passwords...
1627 cupsSetPasswordCB(cups_passwd_cb);
1630 * Try to connect to the server...
1633 if ((http = cups_connect(frame)) == NULL) {
1634 goto out;
1637 request = ippNew();
1639 request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
1640 request->request.op.request_id = 1;
1642 language = cupsLangDefault();
1644 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1645 "attributes-charset", NULL, "utf-8");
1647 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1648 "attributes-natural-language", NULL, language->language);
1650 if (lp_cups_server() != NULL && strlen(lp_cups_server()) > 0) {
1651 if (!push_utf8_talloc(frame, &server, lp_cups_server(), &size)) {
1652 goto out;
1654 } else {
1655 server = talloc_strdup(frame,cupsServer());
1657 if (server) {
1658 goto out;
1660 if (!push_utf8_talloc(frame, &sharename, printer->sharename, &size)) {
1661 goto out;
1663 slprintf(uri, sizeof(uri) - 1, "ipp://%s/printers/%s",
1664 server, sharename);
1666 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
1667 "printer-uri", NULL, uri);
1669 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
1670 "requested-attributes",
1671 (sizeof(requested) / sizeof(requested[0])),
1672 NULL, requested);
1675 * Do the request and get back a response...
1678 if ((response = cupsDoRequest(http, request, "/")) == NULL) {
1679 DEBUG(0,("Unable to get printer attributes - %s\n",
1680 ippErrorString(cupsLastError())));
1681 goto out;
1684 for (attr = response->attrs; attr != NULL;) {
1686 * Skip leading attributes until we hit a printer...
1689 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
1690 attr = attr->next;
1692 if (attr == NULL)
1693 break;
1696 * Pull the needed attributes from this printer...
1699 while ( attr && (attr->group_tag == IPP_TAG_PRINTER) ) {
1700 if (strcmp(attr->name, "printer-name") == 0 &&
1701 attr->value_tag == IPP_TAG_NAME) {
1702 if (!pull_utf8_talloc(frame,
1703 &name,
1704 attr->values[0].string.text,
1705 &size)) {
1706 goto out;
1710 /* Grab the comment if we don't have one */
1711 if ( (strcmp(attr->name, "printer-info") == 0)
1712 && (attr->value_tag == IPP_TAG_TEXT)
1713 && !strlen(printer->comment) )
1715 char *comment = NULL;
1716 if (!pull_utf8_talloc(frame,
1717 &comment,
1718 attr->values[0].string.text,
1719 &size)) {
1720 goto out;
1722 DEBUG(5,("cups_pull_comment_location: Using cups comment: %s\n",
1723 comment));
1724 strlcpy(printer->comment,
1725 comment,
1726 sizeof(printer->comment));
1729 /* Grab the location if we don't have one */
1730 if ( (strcmp(attr->name, "printer-location") == 0)
1731 && (attr->value_tag == IPP_TAG_TEXT)
1732 && !strlen(printer->location) )
1734 char *location = NULL;
1735 if (!pull_utf8_talloc(frame,
1736 &location,
1737 attr->values[0].string.text,
1738 &size)) {
1739 goto out;
1741 DEBUG(5,("cups_pull_comment_location: Using cups location: %s\n",
1742 location));
1743 strlcpy(printer->location,
1744 location,
1745 sizeof(printer->location));
1748 attr = attr->next;
1752 * We have everything needed...
1755 if (name != NULL)
1756 break;
1759 ret = True;
1761 out:
1762 if (response)
1763 ippDelete(response);
1765 if (language)
1766 cupsLangFree(language);
1768 if (http)
1769 httpClose(http);
1771 TALLOC_FREE(frame);
1772 return ret;
1775 #else
1776 /* this keeps fussy compilers happy */
1777 void print_cups_dummy(void);
1778 void print_cups_dummy(void) {}
1779 #endif /* HAVE_CUPS */