s4/asn1: fixed typo in torture messages
[Samba/fernandojvsilva.git] / source3 / printing / print_cups.c
blob7d8248e428596ecac31edc0b55c71bba0c23d21f
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 #ifdef HAVE_HTTPCONNECTENCRYPT
97 http = httpConnectEncrypt(server, port, lp_cups_encrypt());
98 #else
99 http = httpConnect(server, port);
100 #endif
103 CatchSignal(SIGALRM, SIGNAL_CAST SIG_IGN);
104 alarm(0);
106 if (http == NULL) {
107 DEBUG(0,("Unable to connect to CUPS server %s:%d - %s\n",
108 server, port, strerror(errno)));
111 return http;
114 static void send_pcap_info(const char *name, const char *info, void *pd)
116 int fd = *(int *)pd;
117 size_t namelen = name ? strlen(name)+1 : 0;
118 size_t infolen = info ? strlen(info)+1 : 0;
120 DEBUG(11,("send_pcap_info: writing namelen %u\n", (unsigned int)namelen));
121 if (sys_write(fd, &namelen, sizeof(namelen)) != sizeof(namelen)) {
122 DEBUG(10,("send_pcap_info: namelen write failed %s\n",
123 strerror(errno)));
124 return;
126 DEBUG(11,("send_pcap_info: writing infolen %u\n", (unsigned int)infolen));
127 if (sys_write(fd, &infolen, sizeof(infolen)) != sizeof(infolen)) {
128 DEBUG(10,("send_pcap_info: infolen write failed %s\n",
129 strerror(errno)));
130 return;
132 if (namelen) {
133 DEBUG(11,("send_pcap_info: writing name %s\n", name));
134 if (sys_write(fd, name, namelen) != namelen) {
135 DEBUG(10,("send_pcap_info: name write failed %s\n",
136 strerror(errno)));
137 return;
140 if (infolen) {
141 DEBUG(11,("send_pcap_info: writing info %s\n", info));
142 if (sys_write(fd, info, infolen) != infolen) {
143 DEBUG(10,("send_pcap_info: info write failed %s\n",
144 strerror(errno)));
145 return;
150 static bool cups_cache_reload_async(int fd)
152 TALLOC_CTX *frame = talloc_stackframe();
153 struct pcap_cache *tmp_pcap_cache = NULL;
154 http_t *http = NULL; /* HTTP connection to server */
155 ipp_t *request = NULL, /* IPP Request */
156 *response = NULL; /* IPP Response */
157 ipp_attribute_t *attr; /* Current attribute */
158 cups_lang_t *language = NULL; /* Default language */
159 char *name, /* printer-name attribute */
160 *info; /* printer-info attribute */
161 static const char *requested[] =/* Requested attributes */
163 "printer-name",
164 "printer-info"
166 bool ret = False;
167 size_t size;
169 DEBUG(5, ("reloading cups printcap cache\n"));
172 * Make sure we don't ask for passwords...
175 cupsSetPasswordCB(cups_passwd_cb);
178 * Try to connect to the server...
181 if ((http = cups_connect(frame)) == NULL) {
182 goto out;
186 * Build a CUPS_GET_PRINTERS request, which requires the following
187 * attributes:
189 * attributes-charset
190 * attributes-natural-language
191 * requested-attributes
194 request = ippNew();
196 request->request.op.operation_id = CUPS_GET_PRINTERS;
197 request->request.op.request_id = 1;
199 language = cupsLangDefault();
201 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
202 "attributes-charset", NULL, "utf-8");
204 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
205 "attributes-natural-language", NULL, language->language);
207 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
208 "requested-attributes",
209 (sizeof(requested) / sizeof(requested[0])),
210 NULL, requested);
213 * Do the request and get back a response...
216 if ((response = cupsDoRequest(http, request, "/")) == NULL) {
217 DEBUG(0,("Unable to get printer list - %s\n",
218 ippErrorString(cupsLastError())));
219 goto out;
222 for (attr = response->attrs; attr != NULL;) {
224 * Skip leading attributes until we hit a printer...
227 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
228 attr = attr->next;
230 if (attr == NULL)
231 break;
234 * Pull the needed attributes from this printer...
237 name = NULL;
238 info = NULL;
240 while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) {
241 if (strcmp(attr->name, "printer-name") == 0 &&
242 attr->value_tag == IPP_TAG_NAME) {
243 if (!pull_utf8_talloc(frame,
244 &name,
245 attr->values[0].string.text,
246 &size)) {
247 goto out;
251 if (strcmp(attr->name, "printer-info") == 0 &&
252 attr->value_tag == IPP_TAG_TEXT) {
253 if (!pull_utf8_talloc(frame,
254 &info,
255 attr->values[0].string.text,
256 &size)) {
257 goto out;
261 attr = attr->next;
265 * See if we have everything needed...
268 if (name == NULL)
269 break;
271 if (!pcap_cache_add_specific(&tmp_pcap_cache, name, info)) {
272 goto out;
276 ippDelete(response);
277 response = NULL;
280 * Build a CUPS_GET_CLASSES request, which requires the following
281 * attributes:
283 * attributes-charset
284 * attributes-natural-language
285 * requested-attributes
288 request = ippNew();
290 request->request.op.operation_id = CUPS_GET_CLASSES;
291 request->request.op.request_id = 1;
293 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
294 "attributes-charset", NULL, "utf-8");
296 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
297 "attributes-natural-language", NULL, language->language);
299 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
300 "requested-attributes",
301 (sizeof(requested) / sizeof(requested[0])),
302 NULL, requested);
305 * Do the request and get back a response...
308 if ((response = cupsDoRequest(http, request, "/")) == NULL) {
309 DEBUG(0,("Unable to get printer list - %s\n",
310 ippErrorString(cupsLastError())));
311 goto out;
314 for (attr = response->attrs; attr != NULL;) {
316 * Skip leading attributes until we hit a printer...
319 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
320 attr = attr->next;
322 if (attr == NULL)
323 break;
326 * Pull the needed attributes from this printer...
329 name = NULL;
330 info = NULL;
332 while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) {
333 if (strcmp(attr->name, "printer-name") == 0 &&
334 attr->value_tag == IPP_TAG_NAME) {
335 if (!pull_utf8_talloc(frame,
336 &name,
337 attr->values[0].string.text,
338 &size)) {
339 goto out;
343 if (strcmp(attr->name, "printer-info") == 0 &&
344 attr->value_tag == IPP_TAG_TEXT) {
345 if (!pull_utf8_talloc(frame,
346 &info,
347 attr->values[0].string.text,
348 &size)) {
349 goto out;
353 attr = attr->next;
357 * See if we have everything needed...
360 if (name == NULL)
361 break;
363 if (!pcap_cache_add_specific(&tmp_pcap_cache, name, info)) {
364 goto out;
368 ret = True;
370 out:
371 if (response)
372 ippDelete(response);
374 if (language)
375 cupsLangFree(language);
377 if (http)
378 httpClose(http);
380 /* Send all the entries up the pipe. */
381 if (tmp_pcap_cache) {
382 pcap_printer_fn_specific(tmp_pcap_cache,
383 send_pcap_info,
384 (void *)&fd);
386 pcap_cache_destroy_specific(&tmp_pcap_cache);
388 TALLOC_FREE(frame);
389 return ret;
392 static struct pcap_cache *local_pcap_copy;
393 struct fd_event *cache_fd_event;
395 static bool cups_pcap_load_async(int *pfd)
397 int fds[2];
398 pid_t pid;
400 *pfd = -1;
402 if (cache_fd_event) {
403 DEBUG(3,("cups_pcap_load_async: already waiting for "
404 "a refresh event\n" ));
405 return false;
408 DEBUG(5,("cups_pcap_load_async: asynchronously loading cups printers\n"));
410 if (pipe(fds) == -1) {
411 return false;
414 pid = sys_fork();
415 if (pid == (pid_t)-1) {
416 DEBUG(10,("cups_pcap_load_async: fork failed %s\n",
417 strerror(errno) ));
418 close(fds[0]);
419 close(fds[1]);
420 return false;
423 if (pid) {
424 DEBUG(10,("cups_pcap_load_async: child pid = %u\n",
425 (unsigned int)pid ));
426 /* Parent. */
427 close(fds[1]);
428 *pfd = fds[0];
429 return true;
432 /* Child. */
434 close_all_print_db();
436 if (!NT_STATUS_IS_OK(reinit_after_fork(smbd_messaging_context(),
437 smbd_event_context(), true))) {
438 DEBUG(0,("cups_pcap_load_async: reinit_after_fork() failed\n"));
439 smb_panic("cups_pcap_load_async: reinit_after_fork() failed");
442 close(fds[0]);
443 cups_cache_reload_async(fds[1]);
444 close(fds[1]);
445 _exit(0);
448 static void cups_async_callback(struct event_context *event_ctx,
449 struct fd_event *event,
450 uint16 flags,
451 void *p)
453 TALLOC_CTX *frame = talloc_stackframe();
454 int fd = *(int *)p;
455 struct pcap_cache *tmp_pcap_cache = NULL;
457 DEBUG(5,("cups_async_callback: callback received for printer data. "
458 "fd = %d\n", fd));
460 while (1) {
461 char *name = NULL, *info = NULL;
462 size_t namelen = 0, infolen = 0;
463 ssize_t ret = -1;
465 ret = sys_read(fd, &namelen, sizeof(namelen));
466 if (ret == 0) {
467 /* EOF */
468 break;
470 if (ret != sizeof(namelen)) {
471 DEBUG(10,("cups_async_callback: namelen read failed %d %s\n",
472 errno, strerror(errno)));
473 break;
476 DEBUG(11,("cups_async_callback: read namelen %u\n",
477 (unsigned int)namelen));
479 ret = sys_read(fd, &infolen, sizeof(infolen));
480 if (ret == 0) {
481 /* EOF */
482 break;
484 if (ret != sizeof(infolen)) {
485 DEBUG(10,("cups_async_callback: infolen read failed %s\n",
486 strerror(errno)));
487 break;
490 DEBUG(11,("cups_async_callback: read infolen %u\n",
491 (unsigned int)infolen));
493 if (namelen) {
494 name = TALLOC_ARRAY(frame, char, namelen);
495 if (!name) {
496 break;
498 ret = sys_read(fd, name, namelen);
499 if (ret == 0) {
500 /* EOF */
501 break;
503 if (ret != namelen) {
504 DEBUG(10,("cups_async_callback: name read failed %s\n",
505 strerror(errno)));
506 break;
508 DEBUG(11,("cups_async_callback: read name %s\n",
509 name));
510 } else {
511 name = NULL;
513 if (infolen) {
514 info = TALLOC_ARRAY(frame, char, infolen);
515 if (!info) {
516 break;
518 ret = sys_read(fd, info, infolen);
519 if (ret == 0) {
520 /* EOF */
521 break;
523 if (ret != infolen) {
524 DEBUG(10,("cups_async_callback: info read failed %s\n",
525 strerror(errno)));
526 break;
528 DEBUG(11,("cups_async_callback: read info %s\n",
529 info));
530 } else {
531 info = NULL;
534 /* Add to our local pcap cache. */
535 pcap_cache_add_specific(&tmp_pcap_cache, name, info);
536 TALLOC_FREE(name);
537 TALLOC_FREE(info);
540 TALLOC_FREE(frame);
541 if (tmp_pcap_cache) {
542 /* We got a namelist, replace our local cache. */
543 pcap_cache_destroy_specific(&local_pcap_copy);
544 local_pcap_copy = tmp_pcap_cache;
546 /* And the systemwide pcap cache. */
547 pcap_cache_replace(local_pcap_copy);
548 } else {
549 DEBUG(2,("cups_async_callback: failed to read a new "
550 "printer list\n"));
552 close(fd);
553 TALLOC_FREE(p);
554 TALLOC_FREE(cache_fd_event);
557 bool cups_cache_reload(void)
559 int *p_pipe_fd = TALLOC_P(NULL, int);
561 if (!p_pipe_fd) {
562 return false;
565 *p_pipe_fd = -1;
567 /* Set up an async refresh. */
568 if (!cups_pcap_load_async(p_pipe_fd)) {
569 return false;
571 if (!local_pcap_copy) {
572 /* We have no local cache, wait directly for
573 * async refresh to complete.
575 DEBUG(10,("cups_cache_reload: sync read on fd %d\n",
576 *p_pipe_fd ));
578 cups_async_callback(smbd_event_context(),
579 NULL,
580 EVENT_FD_READ,
581 (void *)p_pipe_fd);
582 if (!local_pcap_copy) {
583 return false;
585 } else {
586 /* Replace the system cache with our
587 * local copy. */
588 pcap_cache_replace(local_pcap_copy);
590 DEBUG(10,("cups_cache_reload: async read on fd %d\n",
591 *p_pipe_fd ));
593 /* Trigger an event when the pipe can be read. */
594 cache_fd_event = event_add_fd(smbd_event_context(),
595 NULL, *p_pipe_fd,
596 EVENT_FD_READ,
597 cups_async_callback,
598 (void *)p_pipe_fd);
599 if (!cache_fd_event) {
600 close(*p_pipe_fd);
601 TALLOC_FREE(p_pipe_fd);
602 return false;
605 return true;
609 * 'cups_job_delete()' - Delete a job.
612 static int cups_job_delete(const char *sharename, const char *lprm_command, struct printjob *pjob)
614 TALLOC_CTX *frame = talloc_stackframe();
615 int ret = 1; /* Return value */
616 http_t *http = NULL; /* HTTP connection to server */
617 ipp_t *request = NULL, /* IPP Request */
618 *response = NULL; /* IPP Response */
619 cups_lang_t *language = NULL; /* Default language */
620 char *user = NULL;
621 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
622 size_t size;
624 DEBUG(5,("cups_job_delete(%s, %p (%d))\n", sharename, pjob, pjob->sysjob));
627 * Make sure we don't ask for passwords...
630 cupsSetPasswordCB(cups_passwd_cb);
633 * Try to connect to the server...
636 if ((http = cups_connect(frame)) == NULL) {
637 goto out;
641 * Build an IPP_CANCEL_JOB request, which requires the following
642 * attributes:
644 * attributes-charset
645 * attributes-natural-language
646 * job-uri
647 * requesting-user-name
650 request = ippNew();
652 request->request.op.operation_id = IPP_CANCEL_JOB;
653 request->request.op.request_id = 1;
655 language = cupsLangDefault();
657 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
658 "attributes-charset", NULL, "utf-8");
660 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
661 "attributes-natural-language", NULL, language->language);
663 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
665 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
667 if (!push_utf8_talloc(frame, &user, pjob->user, &size)) {
668 goto out;
671 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
672 NULL, user);
675 * Do the request and get back a response...
678 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) {
679 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
680 DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob,
681 ippErrorString(cupsLastError())));
682 } else {
683 ret = 0;
685 } else {
686 DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob,
687 ippErrorString(cupsLastError())));
690 out:
691 if (response)
692 ippDelete(response);
694 if (language)
695 cupsLangFree(language);
697 if (http)
698 httpClose(http);
700 TALLOC_FREE(frame);
701 return ret;
706 * 'cups_job_pause()' - Pause a job.
709 static int cups_job_pause(int snum, struct printjob *pjob)
711 TALLOC_CTX *frame = talloc_stackframe();
712 int ret = 1; /* Return value */
713 http_t *http = NULL; /* HTTP connection to server */
714 ipp_t *request = NULL, /* IPP Request */
715 *response = NULL; /* IPP Response */
716 cups_lang_t *language = NULL; /* Default language */
717 char *user = NULL;
718 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
719 size_t size;
721 DEBUG(5,("cups_job_pause(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
724 * Make sure we don't ask for passwords...
727 cupsSetPasswordCB(cups_passwd_cb);
730 * Try to connect to the server...
733 if ((http = cups_connect(frame)) == NULL) {
734 goto out;
738 * Build an IPP_HOLD_JOB request, which requires the following
739 * attributes:
741 * attributes-charset
742 * attributes-natural-language
743 * job-uri
744 * requesting-user-name
747 request = ippNew();
749 request->request.op.operation_id = IPP_HOLD_JOB;
750 request->request.op.request_id = 1;
752 language = cupsLangDefault();
754 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
755 "attributes-charset", NULL, "utf-8");
757 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
758 "attributes-natural-language", NULL, language->language);
760 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
762 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
764 if (!push_utf8_talloc(frame, &user, pjob->user, &size)) {
765 goto out;
767 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
768 NULL, user);
771 * Do the request and get back a response...
774 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) {
775 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
776 DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob,
777 ippErrorString(cupsLastError())));
778 } else {
779 ret = 0;
781 } else {
782 DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob,
783 ippErrorString(cupsLastError())));
786 out:
787 if (response)
788 ippDelete(response);
790 if (language)
791 cupsLangFree(language);
793 if (http)
794 httpClose(http);
796 TALLOC_FREE(frame);
797 return ret;
802 * 'cups_job_resume()' - Resume a paused job.
805 static int cups_job_resume(int snum, struct printjob *pjob)
807 TALLOC_CTX *frame = talloc_stackframe();
808 int ret = 1; /* Return value */
809 http_t *http = NULL; /* HTTP connection to server */
810 ipp_t *request = NULL, /* IPP Request */
811 *response = NULL; /* IPP Response */
812 cups_lang_t *language = NULL; /* Default language */
813 char *user = NULL;
814 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
815 size_t size;
817 DEBUG(5,("cups_job_resume(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
820 * Make sure we don't ask for passwords...
823 cupsSetPasswordCB(cups_passwd_cb);
826 * Try to connect to the server...
829 if ((http = cups_connect(frame)) == NULL) {
830 goto out;
834 * Build an IPP_RELEASE_JOB request, which requires the following
835 * attributes:
837 * attributes-charset
838 * attributes-natural-language
839 * job-uri
840 * requesting-user-name
843 request = ippNew();
845 request->request.op.operation_id = IPP_RELEASE_JOB;
846 request->request.op.request_id = 1;
848 language = cupsLangDefault();
850 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
851 "attributes-charset", NULL, "utf-8");
853 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
854 "attributes-natural-language", NULL, language->language);
856 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
858 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
860 if (!push_utf8_talloc(frame, &user, pjob->user, &size)) {
861 goto out;
863 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
864 NULL, user);
867 * Do the request and get back a response...
870 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) {
871 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
872 DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob,
873 ippErrorString(cupsLastError())));
874 } else {
875 ret = 0;
877 } else {
878 DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob,
879 ippErrorString(cupsLastError())));
882 out:
883 if (response)
884 ippDelete(response);
886 if (language)
887 cupsLangFree(language);
889 if (http)
890 httpClose(http);
892 TALLOC_FREE(frame);
893 return ret;
898 * 'cups_job_submit()' - Submit a job for printing.
901 static int cups_job_submit(int snum, struct printjob *pjob)
903 TALLOC_CTX *frame = talloc_stackframe();
904 int ret = 1; /* Return value */
905 http_t *http = NULL; /* HTTP connection to server */
906 ipp_t *request = NULL, /* IPP Request */
907 *response = NULL; /* IPP Response */
908 cups_lang_t *language = NULL; /* Default language */
909 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
910 const char *clientname = NULL; /* hostname of client for job-originating-host attribute */
911 char *new_jobname = NULL;
912 int num_options = 0;
913 cups_option_t *options = NULL;
914 char *printername = NULL;
915 char *user = NULL;
916 char *jobname = NULL;
917 char *cupsoptions = NULL;
918 char *filename = NULL;
919 size_t size;
920 char addr[INET6_ADDRSTRLEN];
922 DEBUG(5,("cups_job_submit(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
925 * Make sure we don't ask for passwords...
928 cupsSetPasswordCB(cups_passwd_cb);
931 * Try to connect to the server...
934 if ((http = cups_connect(frame)) == NULL) {
935 goto out;
939 * Build an IPP_PRINT_JOB request, which requires the following
940 * attributes:
942 * attributes-charset
943 * attributes-natural-language
944 * printer-uri
945 * requesting-user-name
946 * [document-data]
949 request = ippNew();
951 request->request.op.operation_id = IPP_PRINT_JOB;
952 request->request.op.request_id = 1;
954 language = cupsLangDefault();
956 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
957 "attributes-charset", NULL, "utf-8");
959 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
960 "attributes-natural-language", NULL, language->language);
962 if (!push_utf8_talloc(frame, &printername, PRINTERNAME(snum), &size)) {
963 goto out;
965 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
966 printername);
968 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
969 "printer-uri", NULL, uri);
971 if (!push_utf8_talloc(frame, &user, pjob->user, &size)) {
972 goto out;
974 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
975 NULL, user);
977 clientname = client_name(get_client_fd());
978 if (strcmp(clientname, "UNKNOWN") == 0) {
979 clientname = client_addr(get_client_fd(),addr,sizeof(addr));
982 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
983 "job-originating-host-name", NULL,
984 clientname);
986 if (!push_utf8_talloc(frame, &jobname, pjob->jobname, &size)) {
987 goto out;
989 new_jobname = talloc_asprintf(frame,
990 "%s%.8u %s", PRINT_SPOOL_PREFIX,
991 (unsigned int)pjob->smbjob,
992 jobname);
993 if (new_jobname == NULL) {
994 goto out;
997 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "job-name", NULL,
998 new_jobname);
1001 * add any options defined in smb.conf
1004 if (!push_utf8_talloc(frame, &cupsoptions, lp_cups_options(snum), &size)) {
1005 goto out;
1007 num_options = 0;
1008 options = NULL;
1009 num_options = cupsParseOptions(cupsoptions, num_options, &options);
1011 if ( num_options )
1012 cupsEncodeOptions(request, num_options, options);
1015 * Do the request and get back a response...
1018 slprintf(uri, sizeof(uri) - 1, "/printers/%s", printername);
1020 if (!push_utf8_talloc(frame, &filename, pjob->filename, &size)) {
1021 goto out;
1023 if ((response = cupsDoFileRequest(http, request, uri, pjob->filename)) != NULL) {
1024 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
1025 DEBUG(0,("Unable to print file to %s - %s\n", PRINTERNAME(snum),
1026 ippErrorString(cupsLastError())));
1027 } else {
1028 ret = 0;
1030 } else {
1031 DEBUG(0,("Unable to print file to `%s' - %s\n", PRINTERNAME(snum),
1032 ippErrorString(cupsLastError())));
1035 if ( ret == 0 )
1036 unlink(pjob->filename);
1037 /* else print_job_end will do it for us */
1039 out:
1040 if (response)
1041 ippDelete(response);
1043 if (language)
1044 cupsLangFree(language);
1046 if (http)
1047 httpClose(http);
1049 TALLOC_FREE(frame);
1051 return ret;
1055 * 'cups_queue_get()' - Get all the jobs in the print queue.
1058 static int cups_queue_get(const char *sharename,
1059 enum printing_types printing_type,
1060 char *lpq_command,
1061 print_queue_struct **q,
1062 print_status_struct *status)
1064 TALLOC_CTX *frame = talloc_stackframe();
1065 char *printername = NULL;
1066 http_t *http = NULL; /* HTTP connection to server */
1067 ipp_t *request = NULL, /* IPP Request */
1068 *response = NULL; /* IPP Response */
1069 ipp_attribute_t *attr = NULL; /* Current attribute */
1070 cups_lang_t *language = NULL; /* Default language */
1071 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
1072 int qcount = 0, /* Number of active queue entries */
1073 qalloc = 0; /* Number of queue entries allocated */
1074 print_queue_struct *queue = NULL, /* Queue entries */
1075 *temp; /* Temporary pointer for queue */
1076 char *user_name = NULL, /* job-originating-user-name attribute */
1077 *job_name = NULL; /* job-name attribute */
1078 int job_id; /* job-id attribute */
1079 int job_k_octets; /* job-k-octets attribute */
1080 time_t job_time; /* time-at-creation attribute */
1081 ipp_jstate_t job_status; /* job-status attribute */
1082 int job_priority; /* job-priority attribute */
1083 size_t size;
1084 static const char *jattrs[] = /* Requested job attributes */
1086 "job-id",
1087 "job-k-octets",
1088 "job-name",
1089 "job-originating-user-name",
1090 "job-priority",
1091 "job-state",
1092 "time-at-creation",
1094 static const char *pattrs[] = /* Requested printer attributes */
1096 "printer-state",
1097 "printer-state-message"
1100 *q = NULL;
1102 /* HACK ALERT!!! The problem with support the 'printer name'
1103 option is that we key the tdb off the sharename. So we will
1104 overload the lpq_command string to pass in the printername
1105 (which is basically what we do for non-cups printers ... using
1106 the lpq_command to get the queue listing). */
1108 if (!push_utf8_talloc(frame, &printername, lpq_command, &size)) {
1109 goto out;
1111 DEBUG(5,("cups_queue_get(%s, %p, %p)\n", lpq_command, q, status));
1114 * Make sure we don't ask for passwords...
1117 cupsSetPasswordCB(cups_passwd_cb);
1120 * Try to connect to the server...
1123 if ((http = cups_connect(frame)) == NULL) {
1124 goto out;
1128 * Generate the printer URI...
1131 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s", printername);
1134 * Build an IPP_GET_JOBS request, which requires the following
1135 * attributes:
1137 * attributes-charset
1138 * attributes-natural-language
1139 * requested-attributes
1140 * printer-uri
1143 request = ippNew();
1145 request->request.op.operation_id = IPP_GET_JOBS;
1146 request->request.op.request_id = 1;
1148 language = cupsLangDefault();
1150 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1151 "attributes-charset", NULL, "utf-8");
1153 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1154 "attributes-natural-language", NULL, language->language);
1156 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
1157 "requested-attributes",
1158 (sizeof(jattrs) / sizeof(jattrs[0])),
1159 NULL, jattrs);
1161 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
1162 "printer-uri", NULL, uri);
1165 * Do the request and get back a response...
1168 if ((response = cupsDoRequest(http, request, "/")) == NULL) {
1169 DEBUG(0,("Unable to get jobs for %s - %s\n", uri,
1170 ippErrorString(cupsLastError())));
1171 goto out;
1174 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
1175 DEBUG(0,("Unable to get jobs for %s - %s\n", uri,
1176 ippErrorString(response->request.status.status_code)));
1177 goto out;
1181 * Process the jobs...
1184 qcount = 0;
1185 qalloc = 0;
1186 queue = NULL;
1188 for (attr = response->attrs; attr != NULL; attr = attr->next) {
1190 * Skip leading attributes until we hit a job...
1193 while (attr != NULL && attr->group_tag != IPP_TAG_JOB)
1194 attr = attr->next;
1196 if (attr == NULL)
1197 break;
1200 * Allocate memory as needed...
1202 if (qcount >= qalloc) {
1203 qalloc += 16;
1205 queue = SMB_REALLOC_ARRAY(queue, print_queue_struct, qalloc);
1207 if (queue == NULL) {
1208 DEBUG(0,("cups_queue_get: Not enough memory!"));
1209 qcount = 0;
1210 goto out;
1214 temp = queue + qcount;
1215 memset(temp, 0, sizeof(print_queue_struct));
1218 * Pull the needed attributes from this job...
1221 job_id = 0;
1222 job_priority = 50;
1223 job_status = IPP_JOB_PENDING;
1224 job_time = 0;
1225 job_k_octets = 0;
1226 user_name = NULL;
1227 job_name = NULL;
1229 while (attr != NULL && attr->group_tag == IPP_TAG_JOB) {
1230 if (attr->name == NULL) {
1231 attr = attr->next;
1232 break;
1235 if (strcmp(attr->name, "job-id") == 0 &&
1236 attr->value_tag == IPP_TAG_INTEGER)
1237 job_id = attr->values[0].integer;
1239 if (strcmp(attr->name, "job-k-octets") == 0 &&
1240 attr->value_tag == IPP_TAG_INTEGER)
1241 job_k_octets = attr->values[0].integer;
1243 if (strcmp(attr->name, "job-priority") == 0 &&
1244 attr->value_tag == IPP_TAG_INTEGER)
1245 job_priority = attr->values[0].integer;
1247 if (strcmp(attr->name, "job-state") == 0 &&
1248 attr->value_tag == IPP_TAG_ENUM)
1249 job_status = (ipp_jstate_t)(attr->values[0].integer);
1251 if (strcmp(attr->name, "time-at-creation") == 0 &&
1252 attr->value_tag == IPP_TAG_INTEGER)
1253 job_time = attr->values[0].integer;
1255 if (strcmp(attr->name, "job-name") == 0 &&
1256 attr->value_tag == IPP_TAG_NAME) {
1257 if (!pull_utf8_talloc(frame,
1258 &job_name,
1259 attr->values[0].string.text,
1260 &size)) {
1261 goto out;
1265 if (strcmp(attr->name, "job-originating-user-name") == 0 &&
1266 attr->value_tag == IPP_TAG_NAME) {
1267 if (!pull_utf8_talloc(frame,
1268 &user_name,
1269 attr->values[0].string.text,
1270 &size)) {
1271 goto out;
1275 attr = attr->next;
1279 * See if we have everything needed...
1282 if (user_name == NULL || job_name == NULL || job_id == 0) {
1283 if (attr == NULL)
1284 break;
1285 else
1286 continue;
1289 temp->job = job_id;
1290 temp->size = job_k_octets * 1024;
1291 temp->status = job_status == IPP_JOB_PENDING ? LPQ_QUEUED :
1292 job_status == IPP_JOB_STOPPED ? LPQ_PAUSED :
1293 job_status == IPP_JOB_HELD ? LPQ_PAUSED :
1294 LPQ_PRINTING;
1295 temp->priority = job_priority;
1296 temp->time = job_time;
1297 strlcpy(temp->fs_user, user_name, sizeof(temp->fs_user));
1298 strlcpy(temp->fs_file, job_name, sizeof(temp->fs_file));
1300 qcount ++;
1302 if (attr == NULL)
1303 break;
1306 ippDelete(response);
1307 response = NULL;
1310 * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the
1311 * following attributes:
1313 * attributes-charset
1314 * attributes-natural-language
1315 * requested-attributes
1316 * printer-uri
1319 request = ippNew();
1321 request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
1322 request->request.op.request_id = 1;
1324 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1325 "attributes-charset", NULL, "utf-8");
1327 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1328 "attributes-natural-language", NULL, language->language);
1330 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
1331 "requested-attributes",
1332 (sizeof(pattrs) / sizeof(pattrs[0])),
1333 NULL, pattrs);
1335 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
1336 "printer-uri", NULL, uri);
1339 * Do the request and get back a response...
1342 if ((response = cupsDoRequest(http, request, "/")) == NULL) {
1343 DEBUG(0,("Unable to get printer status for %s - %s\n", printername,
1344 ippErrorString(cupsLastError())));
1345 goto out;
1348 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
1349 DEBUG(0,("Unable to get printer status for %s - %s\n", printername,
1350 ippErrorString(response->request.status.status_code)));
1351 goto out;
1355 * Get the current printer status and convert it to the SAMBA values.
1358 if ((attr = ippFindAttribute(response, "printer-state", IPP_TAG_ENUM)) != NULL) {
1359 if (attr->values[0].integer == IPP_PRINTER_STOPPED)
1360 status->status = LPSTAT_STOPPED;
1361 else
1362 status->status = LPSTAT_OK;
1365 if ((attr = ippFindAttribute(response, "printer-state-message",
1366 IPP_TAG_TEXT)) != NULL) {
1367 char *msg = NULL;
1368 if (!pull_utf8_talloc(frame, &msg,
1369 attr->values[0].string.text,
1370 &size)) {
1371 SAFE_FREE(queue);
1372 qcount = 0;
1373 goto out;
1375 fstrcpy(status->message, msg);
1378 out:
1381 * Return the job queue...
1384 *q = queue;
1386 if (response)
1387 ippDelete(response);
1389 if (language)
1390 cupsLangFree(language);
1392 if (http)
1393 httpClose(http);
1395 TALLOC_FREE(frame);
1396 return qcount;
1401 * 'cups_queue_pause()' - Pause a print queue.
1404 static int cups_queue_pause(int snum)
1406 TALLOC_CTX *frame = talloc_stackframe();
1407 int ret = 1; /* Return value */
1408 http_t *http = NULL; /* HTTP connection to server */
1409 ipp_t *request = NULL, /* IPP Request */
1410 *response = NULL; /* IPP Response */
1411 cups_lang_t *language = NULL; /* Default language */
1412 char *printername = NULL;
1413 char *username = NULL;
1414 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
1415 size_t size;
1417 DEBUG(5,("cups_queue_pause(%d)\n", snum));
1420 * Make sure we don't ask for passwords...
1423 cupsSetPasswordCB(cups_passwd_cb);
1426 * Try to connect to the server...
1429 if ((http = cups_connect(frame)) == NULL) {
1430 goto out;
1434 * Build an IPP_PAUSE_PRINTER request, which requires the following
1435 * attributes:
1437 * attributes-charset
1438 * attributes-natural-language
1439 * printer-uri
1440 * requesting-user-name
1443 request = ippNew();
1445 request->request.op.operation_id = IPP_PAUSE_PRINTER;
1446 request->request.op.request_id = 1;
1448 language = cupsLangDefault();
1450 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1451 "attributes-charset", NULL, "utf-8");
1453 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1454 "attributes-natural-language", NULL, language->language);
1456 if (!push_utf8_talloc(frame, &printername, PRINTERNAME(snum), &size)) {
1457 goto out;
1459 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
1460 printername);
1462 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
1464 if (!push_utf8_talloc(frame, &username, current_user_info.unix_name, &size)) {
1465 goto out;
1467 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
1468 NULL, username);
1471 * Do the request and get back a response...
1474 if ((response = cupsDoRequest(http, request, "/admin/")) != NULL) {
1475 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
1476 DEBUG(0,("Unable to pause printer %s - %s\n", PRINTERNAME(snum),
1477 ippErrorString(cupsLastError())));
1478 } else {
1479 ret = 0;
1481 } else {
1482 DEBUG(0,("Unable to pause printer %s - %s\n", PRINTERNAME(snum),
1483 ippErrorString(cupsLastError())));
1486 out:
1487 if (response)
1488 ippDelete(response);
1490 if (language)
1491 cupsLangFree(language);
1493 if (http)
1494 httpClose(http);
1496 TALLOC_FREE(frame);
1497 return ret;
1502 * 'cups_queue_resume()' - Restart a print queue.
1505 static int cups_queue_resume(int snum)
1507 TALLOC_CTX *frame = talloc_stackframe();
1508 int ret = 1; /* Return value */
1509 http_t *http = NULL; /* HTTP connection to server */
1510 ipp_t *request = NULL, /* IPP Request */
1511 *response = NULL; /* IPP Response */
1512 cups_lang_t *language = NULL; /* Default language */
1513 char *printername = NULL;
1514 char *username = NULL;
1515 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
1516 size_t size;
1518 DEBUG(5,("cups_queue_resume(%d)\n", snum));
1521 * Make sure we don't ask for passwords...
1524 cupsSetPasswordCB(cups_passwd_cb);
1527 * Try to connect to the server...
1530 if ((http = cups_connect(frame)) == NULL) {
1531 goto out;
1535 * Build an IPP_RESUME_PRINTER request, which requires the following
1536 * attributes:
1538 * attributes-charset
1539 * attributes-natural-language
1540 * printer-uri
1541 * requesting-user-name
1544 request = ippNew();
1546 request->request.op.operation_id = IPP_RESUME_PRINTER;
1547 request->request.op.request_id = 1;
1549 language = cupsLangDefault();
1551 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1552 "attributes-charset", NULL, "utf-8");
1554 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1555 "attributes-natural-language", NULL, language->language);
1557 if (!push_utf8_talloc(frame, &printername, PRINTERNAME(snum), &size)) {
1558 goto out;
1560 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
1561 printername);
1563 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
1565 if (!push_utf8_talloc(frame, &username, current_user_info.unix_name, &size)) {
1566 goto out;
1568 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
1569 NULL, username);
1572 * Do the request and get back a response...
1575 if ((response = cupsDoRequest(http, request, "/admin/")) != NULL) {
1576 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
1577 DEBUG(0,("Unable to resume printer %s - %s\n", PRINTERNAME(snum),
1578 ippErrorString(cupsLastError())));
1579 } else {
1580 ret = 0;
1582 } else {
1583 DEBUG(0,("Unable to resume printer %s - %s\n", PRINTERNAME(snum),
1584 ippErrorString(cupsLastError())));
1587 out:
1588 if (response)
1589 ippDelete(response);
1591 if (language)
1592 cupsLangFree(language);
1594 if (http)
1595 httpClose(http);
1597 TALLOC_FREE(frame);
1598 return ret;
1601 /*******************************************************************
1602 * CUPS printing interface definitions...
1603 ******************************************************************/
1605 struct printif cups_printif =
1607 PRINT_CUPS,
1608 cups_queue_get,
1609 cups_queue_pause,
1610 cups_queue_resume,
1611 cups_job_delete,
1612 cups_job_pause,
1613 cups_job_resume,
1614 cups_job_submit,
1617 bool cups_pull_comment_location(NT_PRINTER_INFO_LEVEL_2 *printer)
1619 TALLOC_CTX *frame = talloc_stackframe();
1620 http_t *http = NULL; /* HTTP connection to server */
1621 ipp_t *request = NULL, /* IPP Request */
1622 *response = NULL; /* IPP Response */
1623 ipp_attribute_t *attr; /* Current attribute */
1624 cups_lang_t *language = NULL; /* Default language */
1625 char uri[HTTP_MAX_URI];
1626 char *server = NULL;
1627 char *sharename = NULL;
1628 char *name = NULL;
1629 static const char *requested[] =/* Requested attributes */
1631 "printer-name",
1632 "printer-info",
1633 "printer-location"
1635 bool ret = False;
1636 size_t size;
1638 DEBUG(5, ("pulling %s location\n", printer->sharename));
1641 * Make sure we don't ask for passwords...
1644 cupsSetPasswordCB(cups_passwd_cb);
1647 * Try to connect to the server...
1650 if ((http = cups_connect(frame)) == NULL) {
1651 goto out;
1654 request = ippNew();
1656 request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
1657 request->request.op.request_id = 1;
1659 language = cupsLangDefault();
1661 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1662 "attributes-charset", NULL, "utf-8");
1664 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1665 "attributes-natural-language", NULL, language->language);
1667 if (lp_cups_server() != NULL && strlen(lp_cups_server()) > 0) {
1668 if (!push_utf8_talloc(frame, &server, lp_cups_server(), &size)) {
1669 goto out;
1671 } else {
1672 server = talloc_strdup(frame,cupsServer());
1674 if (server) {
1675 goto out;
1677 if (!push_utf8_talloc(frame, &sharename, printer->sharename, &size)) {
1678 goto out;
1680 slprintf(uri, sizeof(uri) - 1, "ipp://%s/printers/%s",
1681 server, sharename);
1683 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
1684 "printer-uri", NULL, uri);
1686 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
1687 "requested-attributes",
1688 (sizeof(requested) / sizeof(requested[0])),
1689 NULL, requested);
1692 * Do the request and get back a response...
1695 if ((response = cupsDoRequest(http, request, "/")) == NULL) {
1696 DEBUG(0,("Unable to get printer attributes - %s\n",
1697 ippErrorString(cupsLastError())));
1698 goto out;
1701 for (attr = response->attrs; attr != NULL;) {
1703 * Skip leading attributes until we hit a printer...
1706 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
1707 attr = attr->next;
1709 if (attr == NULL)
1710 break;
1713 * Pull the needed attributes from this printer...
1716 while ( attr && (attr->group_tag == IPP_TAG_PRINTER) ) {
1717 if (strcmp(attr->name, "printer-name") == 0 &&
1718 attr->value_tag == IPP_TAG_NAME) {
1719 if (!pull_utf8_talloc(frame,
1720 &name,
1721 attr->values[0].string.text,
1722 &size)) {
1723 goto out;
1727 /* Grab the comment if we don't have one */
1728 if ( (strcmp(attr->name, "printer-info") == 0)
1729 && (attr->value_tag == IPP_TAG_TEXT)
1730 && !strlen(printer->comment) )
1732 char *comment = NULL;
1733 if (!pull_utf8_talloc(frame,
1734 &comment,
1735 attr->values[0].string.text,
1736 &size)) {
1737 goto out;
1739 DEBUG(5,("cups_pull_comment_location: Using cups comment: %s\n",
1740 comment));
1741 strlcpy(printer->comment,
1742 comment,
1743 sizeof(printer->comment));
1746 /* Grab the location if we don't have one */
1747 if ( (strcmp(attr->name, "printer-location") == 0)
1748 && (attr->value_tag == IPP_TAG_TEXT)
1749 && !strlen(printer->location) )
1751 char *location = NULL;
1752 if (!pull_utf8_talloc(frame,
1753 &location,
1754 attr->values[0].string.text,
1755 &size)) {
1756 goto out;
1758 DEBUG(5,("cups_pull_comment_location: Using cups location: %s\n",
1759 location));
1760 strlcpy(printer->location,
1761 location,
1762 sizeof(printer->location));
1765 attr = attr->next;
1769 * We have everything needed...
1772 if (name != NULL)
1773 break;
1776 ret = True;
1778 out:
1779 if (response)
1780 ippDelete(response);
1782 if (request) {
1783 ippDelete(request);
1786 if (language)
1787 cupsLangFree(language);
1789 if (http)
1790 httpClose(http);
1792 TALLOC_FREE(frame);
1793 return ret;
1796 #else
1797 /* this keeps fussy compilers happy */
1798 void print_cups_dummy(void);
1799 void print_cups_dummy(void) {}
1800 #endif /* HAVE_CUPS */