Attempt to fix crash seen with new CUPS async printcap loading code.
[Samba/bb.git] / source3 / printing / print_cups.c
blobecdd0e4f3839d1428d4cacbd010c86de61320b03
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. */
429 close_all_print_db();
431 if (!reinit_after_fork(smbd_messaging_context(),
432 smbd_event_context(), true)) {
433 DEBUG(0,("cups_pcap_load_async: reinit_after_fork() failed\n"));
434 smb_panic("cups_pcap_load_async: reinit_after_fork() failed");
437 close(fds[0]);
438 cups_cache_reload_async(fds[1]);
439 close(fds[1]);
440 _exit(0);
443 static void cups_async_callback(struct event_context *event_ctx,
444 struct fd_event *event,
445 uint16 flags,
446 void *p)
448 TALLOC_CTX *frame = talloc_stackframe();
449 int fd = *(int *)p;
450 struct pcap_cache *tmp_pcap_cache = NULL;
452 DEBUG(5,("cups_async_callback: callback received for printer data. "
453 "fd = %d\n", fd));
455 while (1) {
456 char *name = NULL, *info = NULL;
457 size_t namelen = 0, infolen = 0;
458 ssize_t ret = -1;
460 ret = sys_read(fd, &namelen, sizeof(namelen));
461 if (ret == 0) {
462 /* EOF */
463 break;
465 if (ret != sizeof(namelen)) {
466 DEBUG(10,("cups_async_callback: namelen read failed %d %s\n",
467 errno, strerror(errno)));
468 break;
471 DEBUG(11,("cups_async_callback: read namelen %u\n",
472 (unsigned int)namelen));
474 ret = sys_read(fd, &infolen, sizeof(infolen));
475 if (ret == 0) {
476 /* EOF */
477 break;
479 if (ret != sizeof(infolen)) {
480 DEBUG(10,("cups_async_callback: infolen read failed %s\n",
481 strerror(errno)));
482 break;
485 DEBUG(11,("cups_async_callback: read infolen %u\n",
486 (unsigned int)infolen));
488 if (namelen) {
489 name = TALLOC_ARRAY(frame, char, namelen);
490 if (!name) {
491 break;
493 ret = sys_read(fd, name, namelen);
494 if (ret == 0) {
495 /* EOF */
496 break;
498 if (ret != namelen) {
499 DEBUG(10,("cups_async_callback: name read failed %s\n",
500 strerror(errno)));
501 break;
503 DEBUG(11,("cups_async_callback: read name %s\n",
504 name));
505 } else {
506 name = NULL;
508 if (infolen) {
509 info = TALLOC_ARRAY(frame, char, infolen);
510 if (!info) {
511 break;
513 ret = sys_read(fd, info, infolen);
514 if (ret == 0) {
515 /* EOF */
516 break;
518 if (ret != infolen) {
519 DEBUG(10,("cups_async_callback: info read failed %s\n",
520 strerror(errno)));
521 break;
523 DEBUG(11,("cups_async_callback: read info %s\n",
524 info));
525 } else {
526 info = NULL;
529 /* Add to our local pcap cache. */
530 pcap_cache_add_specific(&tmp_pcap_cache, name, info);
531 TALLOC_FREE(name);
532 TALLOC_FREE(info);
535 TALLOC_FREE(frame);
536 if (tmp_pcap_cache) {
537 /* We got a namelist, replace our local cache. */
538 pcap_cache_destroy_specific(&local_pcap_copy);
539 local_pcap_copy = tmp_pcap_cache;
541 /* And the systemwide pcap cache. */
542 pcap_cache_replace(local_pcap_copy);
543 } else {
544 DEBUG(2,("cups_async_callback: failed to read a new "
545 "printer list\n"));
547 close(fd);
548 TALLOC_FREE(p);
549 TALLOC_FREE(cache_fd_event);
552 bool cups_cache_reload(void)
554 int *p_pipe_fd = TALLOC_P(NULL, int);
556 if (!p_pipe_fd) {
557 return false;
560 *p_pipe_fd = -1;
562 /* Set up an async refresh. */
563 if (!cups_pcap_load_async(p_pipe_fd)) {
564 return false;
566 if (!local_pcap_copy) {
567 /* We have no local cache, wait directly for
568 * async refresh to complete.
570 DEBUG(10,("cups_cache_reload: sync read on fd %d\n",
571 *p_pipe_fd ));
573 cups_async_callback(smbd_event_context(),
574 NULL,
575 EVENT_FD_READ,
576 (void *)p_pipe_fd);
577 if (!local_pcap_copy) {
578 return false;
580 } else {
581 /* Replace the system cache with our
582 * local copy. */
583 pcap_cache_replace(local_pcap_copy);
585 DEBUG(10,("cups_cache_reload: async read on fd %d\n",
586 *p_pipe_fd ));
588 /* Trigger an event when the pipe can be read. */
589 cache_fd_event = event_add_fd(smbd_event_context(),
590 NULL, *p_pipe_fd,
591 EVENT_FD_READ,
592 cups_async_callback,
593 (void *)p_pipe_fd);
594 if (!cache_fd_event) {
595 close(*p_pipe_fd);
596 TALLOC_FREE(p_pipe_fd);
597 return false;
600 return true;
604 * 'cups_job_delete()' - Delete a job.
607 static int cups_job_delete(const char *sharename, const char *lprm_command, struct printjob *pjob)
609 TALLOC_CTX *frame = talloc_stackframe();
610 int ret = 1; /* Return value */
611 http_t *http = NULL; /* HTTP connection to server */
612 ipp_t *request = NULL, /* IPP Request */
613 *response = NULL; /* IPP Response */
614 cups_lang_t *language = NULL; /* Default language */
615 char *user = NULL;
616 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
617 size_t size;
619 DEBUG(5,("cups_job_delete(%s, %p (%d))\n", sharename, pjob, pjob->sysjob));
622 * Make sure we don't ask for passwords...
625 cupsSetPasswordCB(cups_passwd_cb);
628 * Try to connect to the server...
631 if ((http = cups_connect(frame)) == NULL) {
632 goto out;
636 * Build an IPP_CANCEL_JOB request, which requires the following
637 * attributes:
639 * attributes-charset
640 * attributes-natural-language
641 * job-uri
642 * requesting-user-name
645 request = ippNew();
647 request->request.op.operation_id = IPP_CANCEL_JOB;
648 request->request.op.request_id = 1;
650 language = cupsLangDefault();
652 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
653 "attributes-charset", NULL, "utf-8");
655 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
656 "attributes-natural-language", NULL, language->language);
658 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
660 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
662 if (!push_utf8_talloc(frame, &user, pjob->user, &size)) {
663 goto out;
666 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
667 NULL, user);
670 * Do the request and get back a response...
673 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) {
674 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
675 DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob,
676 ippErrorString(cupsLastError())));
677 } else {
678 ret = 0;
680 } else {
681 DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob,
682 ippErrorString(cupsLastError())));
685 out:
686 if (response)
687 ippDelete(response);
689 if (language)
690 cupsLangFree(language);
692 if (http)
693 httpClose(http);
695 TALLOC_FREE(frame);
696 return ret;
701 * 'cups_job_pause()' - Pause a job.
704 static int cups_job_pause(int snum, struct printjob *pjob)
706 TALLOC_CTX *frame = talloc_stackframe();
707 int ret = 1; /* Return value */
708 http_t *http = NULL; /* HTTP connection to server */
709 ipp_t *request = NULL, /* IPP Request */
710 *response = NULL; /* IPP Response */
711 cups_lang_t *language = NULL; /* Default language */
712 char *user = NULL;
713 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
714 size_t size;
716 DEBUG(5,("cups_job_pause(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
719 * Make sure we don't ask for passwords...
722 cupsSetPasswordCB(cups_passwd_cb);
725 * Try to connect to the server...
728 if ((http = cups_connect(frame)) == NULL) {
729 goto out;
733 * Build an IPP_HOLD_JOB request, which requires the following
734 * attributes:
736 * attributes-charset
737 * attributes-natural-language
738 * job-uri
739 * requesting-user-name
742 request = ippNew();
744 request->request.op.operation_id = IPP_HOLD_JOB;
745 request->request.op.request_id = 1;
747 language = cupsLangDefault();
749 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
750 "attributes-charset", NULL, "utf-8");
752 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
753 "attributes-natural-language", NULL, language->language);
755 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
757 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
759 if (!push_utf8_talloc(frame, &user, pjob->user, &size)) {
760 goto out;
762 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
763 NULL, user);
766 * Do the request and get back a response...
769 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) {
770 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
771 DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob,
772 ippErrorString(cupsLastError())));
773 } else {
774 ret = 0;
776 } else {
777 DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob,
778 ippErrorString(cupsLastError())));
781 out:
782 if (response)
783 ippDelete(response);
785 if (language)
786 cupsLangFree(language);
788 if (http)
789 httpClose(http);
791 TALLOC_FREE(frame);
792 return ret;
797 * 'cups_job_resume()' - Resume a paused job.
800 static int cups_job_resume(int snum, struct printjob *pjob)
802 TALLOC_CTX *frame = talloc_stackframe();
803 int ret = 1; /* Return value */
804 http_t *http = NULL; /* HTTP connection to server */
805 ipp_t *request = NULL, /* IPP Request */
806 *response = NULL; /* IPP Response */
807 cups_lang_t *language = NULL; /* Default language */
808 char *user = NULL;
809 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
810 size_t size;
812 DEBUG(5,("cups_job_resume(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
815 * Make sure we don't ask for passwords...
818 cupsSetPasswordCB(cups_passwd_cb);
821 * Try to connect to the server...
824 if ((http = cups_connect(frame)) == NULL) {
825 goto out;
829 * Build an IPP_RELEASE_JOB request, which requires the following
830 * attributes:
832 * attributes-charset
833 * attributes-natural-language
834 * job-uri
835 * requesting-user-name
838 request = ippNew();
840 request->request.op.operation_id = IPP_RELEASE_JOB;
841 request->request.op.request_id = 1;
843 language = cupsLangDefault();
845 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
846 "attributes-charset", NULL, "utf-8");
848 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
849 "attributes-natural-language", NULL, language->language);
851 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
853 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
855 if (!push_utf8_talloc(frame, &user, pjob->user, &size)) {
856 goto out;
858 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
859 NULL, user);
862 * Do the request and get back a response...
865 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) {
866 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
867 DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob,
868 ippErrorString(cupsLastError())));
869 } else {
870 ret = 0;
872 } else {
873 DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob,
874 ippErrorString(cupsLastError())));
877 out:
878 if (response)
879 ippDelete(response);
881 if (language)
882 cupsLangFree(language);
884 if (http)
885 httpClose(http);
887 TALLOC_FREE(frame);
888 return ret;
893 * 'cups_job_submit()' - Submit a job for printing.
896 static int cups_job_submit(int snum, struct printjob *pjob)
898 TALLOC_CTX *frame = talloc_stackframe();
899 int ret = 1; /* Return value */
900 http_t *http = NULL; /* HTTP connection to server */
901 ipp_t *request = NULL, /* IPP Request */
902 *response = NULL; /* IPP Response */
903 cups_lang_t *language = NULL; /* Default language */
904 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
905 const char *clientname = NULL; /* hostname of client for job-originating-host attribute */
906 char *new_jobname = NULL;
907 int num_options = 0;
908 cups_option_t *options = NULL;
909 char *printername = NULL;
910 char *user = NULL;
911 char *jobname = NULL;
912 char *cupsoptions = NULL;
913 char *filename = NULL;
914 size_t size;
915 char addr[INET6_ADDRSTRLEN];
917 DEBUG(5,("cups_job_submit(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
920 * Make sure we don't ask for passwords...
923 cupsSetPasswordCB(cups_passwd_cb);
926 * Try to connect to the server...
929 if ((http = cups_connect(frame)) == NULL) {
930 goto out;
934 * Build an IPP_PRINT_JOB request, which requires the following
935 * attributes:
937 * attributes-charset
938 * attributes-natural-language
939 * printer-uri
940 * requesting-user-name
941 * [document-data]
944 request = ippNew();
946 request->request.op.operation_id = IPP_PRINT_JOB;
947 request->request.op.request_id = 1;
949 language = cupsLangDefault();
951 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
952 "attributes-charset", NULL, "utf-8");
954 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
955 "attributes-natural-language", NULL, language->language);
957 if (!push_utf8_talloc(frame, &printername, PRINTERNAME(snum), &size)) {
958 goto out;
960 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
961 printername);
963 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
964 "printer-uri", NULL, uri);
966 if (!push_utf8_talloc(frame, &user, pjob->user, &size)) {
967 goto out;
969 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
970 NULL, user);
972 clientname = client_name(get_client_fd());
973 if (strcmp(clientname, "UNKNOWN") == 0) {
974 clientname = client_addr(get_client_fd(),addr,sizeof(addr));
977 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
978 "job-originating-host-name", NULL,
979 clientname);
981 if (!push_utf8_talloc(frame, &jobname, pjob->jobname, &size)) {
982 goto out;
984 new_jobname = talloc_asprintf(frame,
985 "%s%.8u %s", PRINT_SPOOL_PREFIX,
986 (unsigned int)pjob->smbjob,
987 jobname);
988 if (new_jobname == NULL) {
989 goto out;
992 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "job-name", NULL,
993 new_jobname);
996 * add any options defined in smb.conf
999 if (!push_utf8_talloc(frame, &cupsoptions, lp_cups_options(snum), &size)) {
1000 goto out;
1002 num_options = 0;
1003 options = NULL;
1004 num_options = cupsParseOptions(cupsoptions, num_options, &options);
1006 if ( num_options )
1007 cupsEncodeOptions(request, num_options, options);
1010 * Do the request and get back a response...
1013 slprintf(uri, sizeof(uri) - 1, "/printers/%s", printername);
1015 if (!push_utf8_talloc(frame, &filename, pjob->filename, &size)) {
1016 goto out;
1018 if ((response = cupsDoFileRequest(http, request, uri, pjob->filename)) != NULL) {
1019 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
1020 DEBUG(0,("Unable to print file to %s - %s\n", PRINTERNAME(snum),
1021 ippErrorString(cupsLastError())));
1022 } else {
1023 ret = 0;
1025 } else {
1026 DEBUG(0,("Unable to print file to `%s' - %s\n", PRINTERNAME(snum),
1027 ippErrorString(cupsLastError())));
1030 if ( ret == 0 )
1031 unlink(pjob->filename);
1032 /* else print_job_end will do it for us */
1034 out:
1035 if (response)
1036 ippDelete(response);
1038 if (language)
1039 cupsLangFree(language);
1041 if (http)
1042 httpClose(http);
1044 TALLOC_FREE(frame);
1046 return ret;
1050 * 'cups_queue_get()' - Get all the jobs in the print queue.
1053 static int cups_queue_get(const char *sharename,
1054 enum printing_types printing_type,
1055 char *lpq_command,
1056 print_queue_struct **q,
1057 print_status_struct *status)
1059 TALLOC_CTX *frame = talloc_stackframe();
1060 char *printername = NULL;
1061 http_t *http = NULL; /* HTTP connection to server */
1062 ipp_t *request = NULL, /* IPP Request */
1063 *response = NULL; /* IPP Response */
1064 ipp_attribute_t *attr = NULL; /* Current attribute */
1065 cups_lang_t *language = NULL; /* Default language */
1066 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
1067 int qcount = 0, /* Number of active queue entries */
1068 qalloc = 0; /* Number of queue entries allocated */
1069 print_queue_struct *queue = NULL, /* Queue entries */
1070 *temp; /* Temporary pointer for queue */
1071 char *user_name = NULL, /* job-originating-user-name attribute */
1072 *job_name = NULL; /* job-name attribute */
1073 int job_id; /* job-id attribute */
1074 int job_k_octets; /* job-k-octets attribute */
1075 time_t job_time; /* time-at-creation attribute */
1076 ipp_jstate_t job_status; /* job-status attribute */
1077 int job_priority; /* job-priority attribute */
1078 size_t size;
1079 static const char *jattrs[] = /* Requested job attributes */
1081 "job-id",
1082 "job-k-octets",
1083 "job-name",
1084 "job-originating-user-name",
1085 "job-priority",
1086 "job-state",
1087 "time-at-creation",
1089 static const char *pattrs[] = /* Requested printer attributes */
1091 "printer-state",
1092 "printer-state-message"
1095 *q = NULL;
1097 /* HACK ALERT!!! The problem with support the 'printer name'
1098 option is that we key the tdb off the sharename. So we will
1099 overload the lpq_command string to pass in the printername
1100 (which is basically what we do for non-cups printers ... using
1101 the lpq_command to get the queue listing). */
1103 if (!push_utf8_talloc(frame, &printername, lpq_command, &size)) {
1104 goto out;
1106 DEBUG(5,("cups_queue_get(%s, %p, %p)\n", lpq_command, q, status));
1109 * Make sure we don't ask for passwords...
1112 cupsSetPasswordCB(cups_passwd_cb);
1115 * Try to connect to the server...
1118 if ((http = cups_connect(frame)) == NULL) {
1119 goto out;
1123 * Generate the printer URI...
1126 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s", printername);
1129 * Build an IPP_GET_JOBS request, which requires the following
1130 * attributes:
1132 * attributes-charset
1133 * attributes-natural-language
1134 * requested-attributes
1135 * printer-uri
1138 request = ippNew();
1140 request->request.op.operation_id = IPP_GET_JOBS;
1141 request->request.op.request_id = 1;
1143 language = cupsLangDefault();
1145 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1146 "attributes-charset", NULL, "utf-8");
1148 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1149 "attributes-natural-language", NULL, language->language);
1151 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
1152 "requested-attributes",
1153 (sizeof(jattrs) / sizeof(jattrs[0])),
1154 NULL, jattrs);
1156 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
1157 "printer-uri", NULL, uri);
1160 * Do the request and get back a response...
1163 if ((response = cupsDoRequest(http, request, "/")) == NULL) {
1164 DEBUG(0,("Unable to get jobs for %s - %s\n", uri,
1165 ippErrorString(cupsLastError())));
1166 goto out;
1169 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
1170 DEBUG(0,("Unable to get jobs for %s - %s\n", uri,
1171 ippErrorString(response->request.status.status_code)));
1172 goto out;
1176 * Process the jobs...
1179 qcount = 0;
1180 qalloc = 0;
1181 queue = NULL;
1183 for (attr = response->attrs; attr != NULL; attr = attr->next) {
1185 * Skip leading attributes until we hit a job...
1188 while (attr != NULL && attr->group_tag != IPP_TAG_JOB)
1189 attr = attr->next;
1191 if (attr == NULL)
1192 break;
1195 * Allocate memory as needed...
1197 if (qcount >= qalloc) {
1198 qalloc += 16;
1200 queue = SMB_REALLOC_ARRAY(queue, print_queue_struct, qalloc);
1202 if (queue == NULL) {
1203 DEBUG(0,("cups_queue_get: Not enough memory!"));
1204 qcount = 0;
1205 goto out;
1209 temp = queue + qcount;
1210 memset(temp, 0, sizeof(print_queue_struct));
1213 * Pull the needed attributes from this job...
1216 job_id = 0;
1217 job_priority = 50;
1218 job_status = IPP_JOB_PENDING;
1219 job_time = 0;
1220 job_k_octets = 0;
1221 user_name = NULL;
1222 job_name = NULL;
1224 while (attr != NULL && attr->group_tag == IPP_TAG_JOB) {
1225 if (attr->name == NULL) {
1226 attr = attr->next;
1227 break;
1230 if (strcmp(attr->name, "job-id") == 0 &&
1231 attr->value_tag == IPP_TAG_INTEGER)
1232 job_id = attr->values[0].integer;
1234 if (strcmp(attr->name, "job-k-octets") == 0 &&
1235 attr->value_tag == IPP_TAG_INTEGER)
1236 job_k_octets = attr->values[0].integer;
1238 if (strcmp(attr->name, "job-priority") == 0 &&
1239 attr->value_tag == IPP_TAG_INTEGER)
1240 job_priority = attr->values[0].integer;
1242 if (strcmp(attr->name, "job-state") == 0 &&
1243 attr->value_tag == IPP_TAG_ENUM)
1244 job_status = (ipp_jstate_t)(attr->values[0].integer);
1246 if (strcmp(attr->name, "time-at-creation") == 0 &&
1247 attr->value_tag == IPP_TAG_INTEGER)
1248 job_time = attr->values[0].integer;
1250 if (strcmp(attr->name, "job-name") == 0 &&
1251 attr->value_tag == IPP_TAG_NAME) {
1252 if (!pull_utf8_talloc(frame,
1253 &job_name,
1254 attr->values[0].string.text,
1255 &size)) {
1256 goto out;
1260 if (strcmp(attr->name, "job-originating-user-name") == 0 &&
1261 attr->value_tag == IPP_TAG_NAME) {
1262 if (!pull_utf8_talloc(frame,
1263 &user_name,
1264 attr->values[0].string.text,
1265 &size)) {
1266 goto out;
1270 attr = attr->next;
1274 * See if we have everything needed...
1277 if (user_name == NULL || job_name == NULL || job_id == 0) {
1278 if (attr == NULL)
1279 break;
1280 else
1281 continue;
1284 temp->job = job_id;
1285 temp->size = job_k_octets * 1024;
1286 temp->status = job_status == IPP_JOB_PENDING ? LPQ_QUEUED :
1287 job_status == IPP_JOB_STOPPED ? LPQ_PAUSED :
1288 job_status == IPP_JOB_HELD ? LPQ_PAUSED :
1289 LPQ_PRINTING;
1290 temp->priority = job_priority;
1291 temp->time = job_time;
1292 strlcpy(temp->fs_user, user_name, sizeof(temp->fs_user));
1293 strlcpy(temp->fs_file, job_name, sizeof(temp->fs_file));
1295 qcount ++;
1297 if (attr == NULL)
1298 break;
1301 ippDelete(response);
1302 response = NULL;
1305 * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the
1306 * following attributes:
1308 * attributes-charset
1309 * attributes-natural-language
1310 * requested-attributes
1311 * printer-uri
1314 request = ippNew();
1316 request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
1317 request->request.op.request_id = 1;
1319 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1320 "attributes-charset", NULL, "utf-8");
1322 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1323 "attributes-natural-language", NULL, language->language);
1325 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
1326 "requested-attributes",
1327 (sizeof(pattrs) / sizeof(pattrs[0])),
1328 NULL, pattrs);
1330 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
1331 "printer-uri", NULL, uri);
1334 * Do the request and get back a response...
1337 if ((response = cupsDoRequest(http, request, "/")) == NULL) {
1338 DEBUG(0,("Unable to get printer status for %s - %s\n", printername,
1339 ippErrorString(cupsLastError())));
1340 *q = queue;
1341 goto out;
1344 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
1345 DEBUG(0,("Unable to get printer status for %s - %s\n", printername,
1346 ippErrorString(response->request.status.status_code)));
1347 *q = queue;
1348 goto out;
1352 * Get the current printer status and convert it to the SAMBA values.
1355 if ((attr = ippFindAttribute(response, "printer-state", IPP_TAG_ENUM)) != NULL) {
1356 if (attr->values[0].integer == IPP_PRINTER_STOPPED)
1357 status->status = LPSTAT_STOPPED;
1358 else
1359 status->status = LPSTAT_OK;
1362 if ((attr = ippFindAttribute(response, "printer-state-message",
1363 IPP_TAG_TEXT)) != NULL) {
1364 char *msg = NULL;
1365 if (!pull_utf8_talloc(frame, &msg,
1366 attr->values[0].string.text,
1367 &size)) {
1368 goto out;
1370 fstrcpy(status->message, msg);
1374 * Return the job queue...
1377 *q = queue;
1379 out:
1380 if (response)
1381 ippDelete(response);
1383 if (language)
1384 cupsLangFree(language);
1386 if (http)
1387 httpClose(http);
1389 TALLOC_FREE(frame);
1390 return qcount;
1395 * 'cups_queue_pause()' - Pause a print queue.
1398 static int cups_queue_pause(int snum)
1400 TALLOC_CTX *frame = talloc_stackframe();
1401 int ret = 1; /* Return value */
1402 http_t *http = NULL; /* HTTP connection to server */
1403 ipp_t *request = NULL, /* IPP Request */
1404 *response = NULL; /* IPP Response */
1405 cups_lang_t *language = NULL; /* Default language */
1406 char *printername = NULL;
1407 char *username = NULL;
1408 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
1409 size_t size;
1411 DEBUG(5,("cups_queue_pause(%d)\n", snum));
1414 * Make sure we don't ask for passwords...
1417 cupsSetPasswordCB(cups_passwd_cb);
1420 * Try to connect to the server...
1423 if ((http = cups_connect(frame)) == NULL) {
1424 goto out;
1428 * Build an IPP_PAUSE_PRINTER request, which requires the following
1429 * attributes:
1431 * attributes-charset
1432 * attributes-natural-language
1433 * printer-uri
1434 * requesting-user-name
1437 request = ippNew();
1439 request->request.op.operation_id = IPP_PAUSE_PRINTER;
1440 request->request.op.request_id = 1;
1442 language = cupsLangDefault();
1444 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1445 "attributes-charset", NULL, "utf-8");
1447 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1448 "attributes-natural-language", NULL, language->language);
1450 if (!push_utf8_talloc(frame, &printername, PRINTERNAME(snum), &size)) {
1451 goto out;
1453 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
1454 printername);
1456 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
1458 if (!push_utf8_talloc(frame, &username, current_user_info.unix_name, &size)) {
1459 goto out;
1461 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
1462 NULL, username);
1465 * Do the request and get back a response...
1468 if ((response = cupsDoRequest(http, request, "/admin/")) != NULL) {
1469 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
1470 DEBUG(0,("Unable to pause printer %s - %s\n", PRINTERNAME(snum),
1471 ippErrorString(cupsLastError())));
1472 } else {
1473 ret = 0;
1475 } else {
1476 DEBUG(0,("Unable to pause printer %s - %s\n", PRINTERNAME(snum),
1477 ippErrorString(cupsLastError())));
1480 out:
1481 if (response)
1482 ippDelete(response);
1484 if (language)
1485 cupsLangFree(language);
1487 if (http)
1488 httpClose(http);
1490 TALLOC_FREE(frame);
1491 return ret;
1496 * 'cups_queue_resume()' - Restart a print queue.
1499 static int cups_queue_resume(int snum)
1501 TALLOC_CTX *frame = talloc_stackframe();
1502 int ret = 1; /* Return value */
1503 http_t *http = NULL; /* HTTP connection to server */
1504 ipp_t *request = NULL, /* IPP Request */
1505 *response = NULL; /* IPP Response */
1506 cups_lang_t *language = NULL; /* Default language */
1507 char *printername = NULL;
1508 char *username = NULL;
1509 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
1510 size_t size;
1512 DEBUG(5,("cups_queue_resume(%d)\n", snum));
1515 * Make sure we don't ask for passwords...
1518 cupsSetPasswordCB(cups_passwd_cb);
1521 * Try to connect to the server...
1524 if ((http = cups_connect(frame)) == NULL) {
1525 goto out;
1529 * Build an IPP_RESUME_PRINTER request, which requires the following
1530 * attributes:
1532 * attributes-charset
1533 * attributes-natural-language
1534 * printer-uri
1535 * requesting-user-name
1538 request = ippNew();
1540 request->request.op.operation_id = IPP_RESUME_PRINTER;
1541 request->request.op.request_id = 1;
1543 language = cupsLangDefault();
1545 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1546 "attributes-charset", NULL, "utf-8");
1548 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1549 "attributes-natural-language", NULL, language->language);
1551 if (!push_utf8_talloc(frame, &printername, PRINTERNAME(snum), &size)) {
1552 goto out;
1554 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
1555 printername);
1557 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
1559 if (!push_utf8_talloc(frame, &username, current_user_info.unix_name, &size)) {
1560 goto out;
1562 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
1563 NULL, username);
1566 * Do the request and get back a response...
1569 if ((response = cupsDoRequest(http, request, "/admin/")) != NULL) {
1570 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
1571 DEBUG(0,("Unable to resume printer %s - %s\n", PRINTERNAME(snum),
1572 ippErrorString(cupsLastError())));
1573 } else {
1574 ret = 0;
1576 } else {
1577 DEBUG(0,("Unable to resume printer %s - %s\n", PRINTERNAME(snum),
1578 ippErrorString(cupsLastError())));
1581 out:
1582 if (response)
1583 ippDelete(response);
1585 if (language)
1586 cupsLangFree(language);
1588 if (http)
1589 httpClose(http);
1591 TALLOC_FREE(frame);
1592 return ret;
1595 /*******************************************************************
1596 * CUPS printing interface definitions...
1597 ******************************************************************/
1599 struct printif cups_printif =
1601 PRINT_CUPS,
1602 cups_queue_get,
1603 cups_queue_pause,
1604 cups_queue_resume,
1605 cups_job_delete,
1606 cups_job_pause,
1607 cups_job_resume,
1608 cups_job_submit,
1611 bool cups_pull_comment_location(NT_PRINTER_INFO_LEVEL_2 *printer)
1613 TALLOC_CTX *frame = talloc_stackframe();
1614 http_t *http = NULL; /* HTTP connection to server */
1615 ipp_t *request = NULL, /* IPP Request */
1616 *response = NULL; /* IPP Response */
1617 ipp_attribute_t *attr; /* Current attribute */
1618 cups_lang_t *language = NULL; /* Default language */
1619 char uri[HTTP_MAX_URI];
1620 char *server = NULL;
1621 char *sharename = NULL;
1622 char *name = NULL;
1623 static const char *requested[] =/* Requested attributes */
1625 "printer-name",
1626 "printer-info",
1627 "printer-location"
1629 bool ret = False;
1630 size_t size;
1632 DEBUG(5, ("pulling %s location\n", printer->sharename));
1635 * Make sure we don't ask for passwords...
1638 cupsSetPasswordCB(cups_passwd_cb);
1641 * Try to connect to the server...
1644 if ((http = cups_connect(frame)) == NULL) {
1645 goto out;
1648 request = ippNew();
1650 request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
1651 request->request.op.request_id = 1;
1653 language = cupsLangDefault();
1655 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1656 "attributes-charset", NULL, "utf-8");
1658 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1659 "attributes-natural-language", NULL, language->language);
1661 if (lp_cups_server() != NULL && strlen(lp_cups_server()) > 0) {
1662 if (!push_utf8_talloc(frame, &server, lp_cups_server(), &size)) {
1663 goto out;
1665 } else {
1666 server = talloc_strdup(frame,cupsServer());
1668 if (server) {
1669 goto out;
1671 if (!push_utf8_talloc(frame, &sharename, printer->sharename, &size)) {
1672 goto out;
1674 slprintf(uri, sizeof(uri) - 1, "ipp://%s/printers/%s",
1675 server, sharename);
1677 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
1678 "printer-uri", NULL, uri);
1680 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
1681 "requested-attributes",
1682 (sizeof(requested) / sizeof(requested[0])),
1683 NULL, requested);
1686 * Do the request and get back a response...
1689 if ((response = cupsDoRequest(http, request, "/")) == NULL) {
1690 DEBUG(0,("Unable to get printer attributes - %s\n",
1691 ippErrorString(cupsLastError())));
1692 goto out;
1695 for (attr = response->attrs; attr != NULL;) {
1697 * Skip leading attributes until we hit a printer...
1700 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
1701 attr = attr->next;
1703 if (attr == NULL)
1704 break;
1707 * Pull the needed attributes from this printer...
1710 while ( attr && (attr->group_tag == IPP_TAG_PRINTER) ) {
1711 if (strcmp(attr->name, "printer-name") == 0 &&
1712 attr->value_tag == IPP_TAG_NAME) {
1713 if (!pull_utf8_talloc(frame,
1714 &name,
1715 attr->values[0].string.text,
1716 &size)) {
1717 goto out;
1721 /* Grab the comment if we don't have one */
1722 if ( (strcmp(attr->name, "printer-info") == 0)
1723 && (attr->value_tag == IPP_TAG_TEXT)
1724 && !strlen(printer->comment) )
1726 char *comment = NULL;
1727 if (!pull_utf8_talloc(frame,
1728 &comment,
1729 attr->values[0].string.text,
1730 &size)) {
1731 goto out;
1733 DEBUG(5,("cups_pull_comment_location: Using cups comment: %s\n",
1734 comment));
1735 strlcpy(printer->comment,
1736 comment,
1737 sizeof(printer->comment));
1740 /* Grab the location if we don't have one */
1741 if ( (strcmp(attr->name, "printer-location") == 0)
1742 && (attr->value_tag == IPP_TAG_TEXT)
1743 && !strlen(printer->location) )
1745 char *location = NULL;
1746 if (!pull_utf8_talloc(frame,
1747 &location,
1748 attr->values[0].string.text,
1749 &size)) {
1750 goto out;
1752 DEBUG(5,("cups_pull_comment_location: Using cups location: %s\n",
1753 location));
1754 strlcpy(printer->location,
1755 location,
1756 sizeof(printer->location));
1759 attr = attr->next;
1763 * We have everything needed...
1766 if (name != NULL)
1767 break;
1770 ret = True;
1772 out:
1773 if (response)
1774 ippDelete(response);
1776 if (request) {
1777 ippDelete(request);
1780 if (language)
1781 cupsLangFree(language);
1783 if (http)
1784 httpClose(http);
1786 TALLOC_FREE(frame);
1787 return ret;
1790 #else
1791 /* this keeps fussy compilers happy */
1792 void print_cups_dummy(void);
1793 void print_cups_dummy(void) {}
1794 #endif /* HAVE_CUPS */