rap: use rap_LogonHours in rap_NetUserInfo11 as well.
[Samba/ekacnet.git] / source3 / printing / print_cups.c
blob7366f8597330148adef67b59bdf816360c4c3cc2
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"
27 #include "printing/pcap.h"
29 #ifdef HAVE_CUPS
30 #include <cups/cups.h>
31 #include <cups/language.h>
33 static SIG_ATOMIC_T gotalarm;
35 /***************************************************************
36 Signal function to tell us we timed out.
37 ****************************************************************/
39 static void gotalarm_sig(int signum)
41 gotalarm = 1;
44 extern userdom_struct current_user_info;
47 * 'cups_passwd_cb()' - The CUPS password callback...
50 static const char * /* O - Password or NULL */
51 cups_passwd_cb(const char *prompt) /* I - Prompt */
54 * Always return NULL to indicate that no password is available...
57 return (NULL);
60 static http_t *cups_connect(TALLOC_CTX *frame)
62 http_t *http = NULL;
63 char *server = NULL, *p = NULL;
64 int port;
65 int timeout = lp_cups_connection_timeout();
66 size_t size;
68 if (lp_cups_server() != NULL && strlen(lp_cups_server()) > 0) {
69 if (!push_utf8_talloc(frame, &server, lp_cups_server(), &size)) {
70 return NULL;
72 } else {
73 server = talloc_strdup(frame,cupsServer());
75 if (!server) {
76 return NULL;
79 p = strchr(server, ':');
80 if (p) {
81 port = atoi(p+1);
82 *p = '\0';
83 } else {
84 port = ippPort();
87 DEBUG(10, ("connecting to cups server %s:%d\n",
88 server, port));
90 gotalarm = 0;
92 if (timeout) {
93 CatchSignal(SIGALRM, gotalarm_sig);
94 alarm(timeout);
97 #ifdef HAVE_HTTPCONNECTENCRYPT
98 http = httpConnectEncrypt(server, port, lp_cups_encrypt());
99 #else
100 http = httpConnect(server, port);
101 #endif
104 CatchSignal(SIGALRM, SIG_IGN);
105 alarm(0);
107 if (http == NULL) {
108 DEBUG(0,("Unable to connect to CUPS server %s:%d - %s\n",
109 server, port, strerror(errno)));
112 return http;
115 static void send_pcap_info(const char *name, const char *info, void *pd)
117 int fd = *(int *)pd;
118 size_t namelen = name ? strlen(name)+1 : 0;
119 size_t infolen = info ? strlen(info)+1 : 0;
121 DEBUG(11,("send_pcap_info: writing namelen %u\n", (unsigned int)namelen));
122 if (sys_write(fd, &namelen, sizeof(namelen)) != sizeof(namelen)) {
123 DEBUG(10,("send_pcap_info: namelen write failed %s\n",
124 strerror(errno)));
125 return;
127 DEBUG(11,("send_pcap_info: writing infolen %u\n", (unsigned int)infolen));
128 if (sys_write(fd, &infolen, sizeof(infolen)) != sizeof(infolen)) {
129 DEBUG(10,("send_pcap_info: infolen write failed %s\n",
130 strerror(errno)));
131 return;
133 if (namelen) {
134 DEBUG(11,("send_pcap_info: writing name %s\n", name));
135 if (sys_write(fd, name, namelen) != namelen) {
136 DEBUG(10,("send_pcap_info: name write failed %s\n",
137 strerror(errno)));
138 return;
141 if (infolen) {
142 DEBUG(11,("send_pcap_info: writing info %s\n", info));
143 if (sys_write(fd, info, infolen) != infolen) {
144 DEBUG(10,("send_pcap_info: info write failed %s\n",
145 strerror(errno)));
146 return;
151 static bool cups_cache_reload_async(int fd)
153 TALLOC_CTX *frame = talloc_stackframe();
154 struct pcap_cache *tmp_pcap_cache = NULL;
155 http_t *http = NULL; /* HTTP connection to server */
156 ipp_t *request = NULL, /* IPP Request */
157 *response = NULL; /* IPP Response */
158 ipp_attribute_t *attr; /* Current attribute */
159 cups_lang_t *language = NULL; /* Default language */
160 char *name, /* printer-name attribute */
161 *info; /* printer-info attribute */
162 static const char *requested[] =/* Requested attributes */
164 "printer-name",
165 "printer-info"
167 bool ret = False;
168 size_t size;
170 DEBUG(5, ("reloading cups printcap cache\n"));
173 * Make sure we don't ask for passwords...
176 cupsSetPasswordCB(cups_passwd_cb);
179 * Try to connect to the server...
182 if ((http = cups_connect(frame)) == NULL) {
183 goto out;
187 * Build a CUPS_GET_PRINTERS request, which requires the following
188 * attributes:
190 * attributes-charset
191 * attributes-natural-language
192 * requested-attributes
195 request = ippNew();
197 request->request.op.operation_id = CUPS_GET_PRINTERS;
198 request->request.op.request_id = 1;
200 language = cupsLangDefault();
202 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
203 "attributes-charset", NULL, "utf-8");
205 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
206 "attributes-natural-language", NULL, language->language);
208 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
209 "requested-attributes",
210 (sizeof(requested) / sizeof(requested[0])),
211 NULL, requested);
214 * Do the request and get back a response...
217 if ((response = cupsDoRequest(http, request, "/")) == NULL) {
218 DEBUG(0,("Unable to get printer list - %s\n",
219 ippErrorString(cupsLastError())));
220 goto out;
223 for (attr = response->attrs; attr != NULL;) {
225 * Skip leading attributes until we hit a printer...
228 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
229 attr = attr->next;
231 if (attr == NULL)
232 break;
235 * Pull the needed attributes from this printer...
238 name = NULL;
239 info = NULL;
241 while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) {
242 if (strcmp(attr->name, "printer-name") == 0 &&
243 attr->value_tag == IPP_TAG_NAME) {
244 if (!pull_utf8_talloc(frame,
245 &name,
246 attr->values[0].string.text,
247 &size)) {
248 goto out;
252 if (strcmp(attr->name, "printer-info") == 0 &&
253 attr->value_tag == IPP_TAG_TEXT) {
254 if (!pull_utf8_talloc(frame,
255 &info,
256 attr->values[0].string.text,
257 &size)) {
258 goto out;
262 attr = attr->next;
266 * See if we have everything needed...
269 if (name == NULL)
270 break;
272 if (!pcap_cache_add_specific(&tmp_pcap_cache, name, info)) {
273 goto out;
277 ippDelete(response);
278 response = NULL;
281 * Build a CUPS_GET_CLASSES request, which requires the following
282 * attributes:
284 * attributes-charset
285 * attributes-natural-language
286 * requested-attributes
289 request = ippNew();
291 request->request.op.operation_id = CUPS_GET_CLASSES;
292 request->request.op.request_id = 1;
294 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
295 "attributes-charset", NULL, "utf-8");
297 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
298 "attributes-natural-language", NULL, language->language);
300 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
301 "requested-attributes",
302 (sizeof(requested) / sizeof(requested[0])),
303 NULL, requested);
306 * Do the request and get back a response...
309 if ((response = cupsDoRequest(http, request, "/")) == NULL) {
310 DEBUG(0,("Unable to get printer list - %s\n",
311 ippErrorString(cupsLastError())));
312 goto out;
315 for (attr = response->attrs; attr != NULL;) {
317 * Skip leading attributes until we hit a printer...
320 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
321 attr = attr->next;
323 if (attr == NULL)
324 break;
327 * Pull the needed attributes from this printer...
330 name = NULL;
331 info = NULL;
333 while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) {
334 if (strcmp(attr->name, "printer-name") == 0 &&
335 attr->value_tag == IPP_TAG_NAME) {
336 if (!pull_utf8_talloc(frame,
337 &name,
338 attr->values[0].string.text,
339 &size)) {
340 goto out;
344 if (strcmp(attr->name, "printer-info") == 0 &&
345 attr->value_tag == IPP_TAG_TEXT) {
346 if (!pull_utf8_talloc(frame,
347 &info,
348 attr->values[0].string.text,
349 &size)) {
350 goto out;
354 attr = attr->next;
358 * See if we have everything needed...
361 if (name == NULL)
362 break;
364 if (!pcap_cache_add_specific(&tmp_pcap_cache, name, info)) {
365 goto out;
369 ret = True;
371 out:
372 if (response)
373 ippDelete(response);
375 if (language)
376 cupsLangFree(language);
378 if (http)
379 httpClose(http);
381 /* Send all the entries up the pipe. */
382 if (tmp_pcap_cache) {
383 pcap_printer_fn_specific(tmp_pcap_cache,
384 send_pcap_info,
385 (void *)&fd);
387 pcap_cache_destroy_specific(&tmp_pcap_cache);
389 TALLOC_FREE(frame);
390 return ret;
393 static struct pcap_cache *local_pcap_copy;
394 struct fd_event *cache_fd_event;
396 static bool cups_pcap_load_async(int *pfd)
398 int fds[2];
399 pid_t pid;
401 *pfd = -1;
403 if (cache_fd_event) {
404 DEBUG(3,("cups_pcap_load_async: already waiting for "
405 "a refresh event\n" ));
406 return false;
409 DEBUG(5,("cups_pcap_load_async: asynchronously loading cups printers\n"));
411 if (pipe(fds) == -1) {
412 return false;
415 pid = sys_fork();
416 if (pid == (pid_t)-1) {
417 DEBUG(10,("cups_pcap_load_async: fork failed %s\n",
418 strerror(errno) ));
419 close(fds[0]);
420 close(fds[1]);
421 return false;
424 if (pid) {
425 DEBUG(10,("cups_pcap_load_async: child pid = %u\n",
426 (unsigned int)pid ));
427 /* Parent. */
428 close(fds[1]);
429 *pfd = fds[0];
430 return true;
433 /* Child. */
435 close_all_print_db();
437 if (!NT_STATUS_IS_OK(reinit_after_fork(smbd_messaging_context(),
438 smbd_event_context(), true))) {
439 DEBUG(0,("cups_pcap_load_async: reinit_after_fork() failed\n"));
440 smb_panic("cups_pcap_load_async: reinit_after_fork() failed");
443 close(fds[0]);
444 cups_cache_reload_async(fds[1]);
445 close(fds[1]);
446 _exit(0);
449 static void cups_async_callback(struct event_context *event_ctx,
450 struct fd_event *event,
451 uint16 flags,
452 void *p)
454 TALLOC_CTX *frame = talloc_stackframe();
455 int fd = *(int *)p;
456 struct pcap_cache *tmp_pcap_cache = NULL;
458 DEBUG(5,("cups_async_callback: callback received for printer data. "
459 "fd = %d\n", fd));
461 while (1) {
462 char *name = NULL, *info = NULL;
463 size_t namelen = 0, infolen = 0;
464 ssize_t ret = -1;
466 ret = sys_read(fd, &namelen, sizeof(namelen));
467 if (ret == 0) {
468 /* EOF */
469 break;
471 if (ret != sizeof(namelen)) {
472 DEBUG(10,("cups_async_callback: namelen read failed %d %s\n",
473 errno, strerror(errno)));
474 break;
477 DEBUG(11,("cups_async_callback: read namelen %u\n",
478 (unsigned int)namelen));
480 ret = sys_read(fd, &infolen, sizeof(infolen));
481 if (ret == 0) {
482 /* EOF */
483 break;
485 if (ret != sizeof(infolen)) {
486 DEBUG(10,("cups_async_callback: infolen read failed %s\n",
487 strerror(errno)));
488 break;
491 DEBUG(11,("cups_async_callback: read infolen %u\n",
492 (unsigned int)infolen));
494 if (namelen) {
495 name = TALLOC_ARRAY(frame, char, namelen);
496 if (!name) {
497 break;
499 ret = sys_read(fd, name, namelen);
500 if (ret == 0) {
501 /* EOF */
502 break;
504 if (ret != namelen) {
505 DEBUG(10,("cups_async_callback: name read failed %s\n",
506 strerror(errno)));
507 break;
509 DEBUG(11,("cups_async_callback: read name %s\n",
510 name));
511 } else {
512 name = NULL;
514 if (infolen) {
515 info = TALLOC_ARRAY(frame, char, infolen);
516 if (!info) {
517 break;
519 ret = sys_read(fd, info, infolen);
520 if (ret == 0) {
521 /* EOF */
522 break;
524 if (ret != infolen) {
525 DEBUG(10,("cups_async_callback: info read failed %s\n",
526 strerror(errno)));
527 break;
529 DEBUG(11,("cups_async_callback: read info %s\n",
530 info));
531 } else {
532 info = NULL;
535 /* Add to our local pcap cache. */
536 pcap_cache_add_specific(&tmp_pcap_cache, name, info);
537 TALLOC_FREE(name);
538 TALLOC_FREE(info);
541 TALLOC_FREE(frame);
542 if (tmp_pcap_cache) {
543 /* We got a namelist, replace our local cache. */
544 pcap_cache_destroy_specific(&local_pcap_copy);
545 local_pcap_copy = tmp_pcap_cache;
547 /* And the systemwide pcap cache. */
548 pcap_cache_replace(local_pcap_copy);
549 } else {
550 DEBUG(2,("cups_async_callback: failed to read a new "
551 "printer list\n"));
553 close(fd);
554 TALLOC_FREE(p);
555 TALLOC_FREE(cache_fd_event);
558 bool cups_cache_reload(void)
560 int *p_pipe_fd = TALLOC_P(NULL, int);
562 if (!p_pipe_fd) {
563 return false;
566 *p_pipe_fd = -1;
568 /* Set up an async refresh. */
569 if (!cups_pcap_load_async(p_pipe_fd)) {
570 return false;
572 if (!local_pcap_copy) {
573 /* We have no local cache, wait directly for
574 * async refresh to complete.
576 DEBUG(10,("cups_cache_reload: sync read on fd %d\n",
577 *p_pipe_fd ));
579 cups_async_callback(smbd_event_context(),
580 NULL,
581 EVENT_FD_READ,
582 (void *)p_pipe_fd);
583 if (!local_pcap_copy) {
584 return false;
586 } else {
587 /* Replace the system cache with our
588 * local copy. */
589 pcap_cache_replace(local_pcap_copy);
591 DEBUG(10,("cups_cache_reload: async read on fd %d\n",
592 *p_pipe_fd ));
594 /* Trigger an event when the pipe can be read. */
595 cache_fd_event = event_add_fd(smbd_event_context(),
596 NULL, *p_pipe_fd,
597 EVENT_FD_READ,
598 cups_async_callback,
599 (void *)p_pipe_fd);
600 if (!cache_fd_event) {
601 close(*p_pipe_fd);
602 TALLOC_FREE(p_pipe_fd);
603 return false;
606 return true;
610 * 'cups_job_delete()' - Delete a job.
613 static int cups_job_delete(const char *sharename, const char *lprm_command, struct printjob *pjob)
615 TALLOC_CTX *frame = talloc_stackframe();
616 int ret = 1; /* Return value */
617 http_t *http = NULL; /* HTTP connection to server */
618 ipp_t *request = NULL, /* IPP Request */
619 *response = NULL; /* IPP Response */
620 cups_lang_t *language = NULL; /* Default language */
621 char *user = NULL;
622 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
623 size_t size;
625 DEBUG(5,("cups_job_delete(%s, %p (%d))\n", sharename, pjob, pjob->sysjob));
628 * Make sure we don't ask for passwords...
631 cupsSetPasswordCB(cups_passwd_cb);
634 * Try to connect to the server...
637 if ((http = cups_connect(frame)) == NULL) {
638 goto out;
642 * Build an IPP_CANCEL_JOB request, which requires the following
643 * attributes:
645 * attributes-charset
646 * attributes-natural-language
647 * job-uri
648 * requesting-user-name
651 request = ippNew();
653 request->request.op.operation_id = IPP_CANCEL_JOB;
654 request->request.op.request_id = 1;
656 language = cupsLangDefault();
658 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
659 "attributes-charset", NULL, "utf-8");
661 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
662 "attributes-natural-language", NULL, language->language);
664 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
666 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
668 if (!push_utf8_talloc(frame, &user, pjob->user, &size)) {
669 goto out;
672 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
673 NULL, user);
676 * Do the request and get back a response...
679 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) {
680 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
681 DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob,
682 ippErrorString(cupsLastError())));
683 } else {
684 ret = 0;
686 } else {
687 DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob,
688 ippErrorString(cupsLastError())));
691 out:
692 if (response)
693 ippDelete(response);
695 if (language)
696 cupsLangFree(language);
698 if (http)
699 httpClose(http);
701 TALLOC_FREE(frame);
702 return ret;
707 * 'cups_job_pause()' - Pause a job.
710 static int cups_job_pause(int snum, struct printjob *pjob)
712 TALLOC_CTX *frame = talloc_stackframe();
713 int ret = 1; /* Return value */
714 http_t *http = NULL; /* HTTP connection to server */
715 ipp_t *request = NULL, /* IPP Request */
716 *response = NULL; /* IPP Response */
717 cups_lang_t *language = NULL; /* Default language */
718 char *user = NULL;
719 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
720 size_t size;
722 DEBUG(5,("cups_job_pause(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
725 * Make sure we don't ask for passwords...
728 cupsSetPasswordCB(cups_passwd_cb);
731 * Try to connect to the server...
734 if ((http = cups_connect(frame)) == NULL) {
735 goto out;
739 * Build an IPP_HOLD_JOB request, which requires the following
740 * attributes:
742 * attributes-charset
743 * attributes-natural-language
744 * job-uri
745 * requesting-user-name
748 request = ippNew();
750 request->request.op.operation_id = IPP_HOLD_JOB;
751 request->request.op.request_id = 1;
753 language = cupsLangDefault();
755 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
756 "attributes-charset", NULL, "utf-8");
758 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
759 "attributes-natural-language", NULL, language->language);
761 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
763 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
765 if (!push_utf8_talloc(frame, &user, pjob->user, &size)) {
766 goto out;
768 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
769 NULL, user);
772 * Do the request and get back a response...
775 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) {
776 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
777 DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob,
778 ippErrorString(cupsLastError())));
779 } else {
780 ret = 0;
782 } else {
783 DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob,
784 ippErrorString(cupsLastError())));
787 out:
788 if (response)
789 ippDelete(response);
791 if (language)
792 cupsLangFree(language);
794 if (http)
795 httpClose(http);
797 TALLOC_FREE(frame);
798 return ret;
803 * 'cups_job_resume()' - Resume a paused job.
806 static int cups_job_resume(int snum, struct printjob *pjob)
808 TALLOC_CTX *frame = talloc_stackframe();
809 int ret = 1; /* Return value */
810 http_t *http = NULL; /* HTTP connection to server */
811 ipp_t *request = NULL, /* IPP Request */
812 *response = NULL; /* IPP Response */
813 cups_lang_t *language = NULL; /* Default language */
814 char *user = NULL;
815 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
816 size_t size;
818 DEBUG(5,("cups_job_resume(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
821 * Make sure we don't ask for passwords...
824 cupsSetPasswordCB(cups_passwd_cb);
827 * Try to connect to the server...
830 if ((http = cups_connect(frame)) == NULL) {
831 goto out;
835 * Build an IPP_RELEASE_JOB request, which requires the following
836 * attributes:
838 * attributes-charset
839 * attributes-natural-language
840 * job-uri
841 * requesting-user-name
844 request = ippNew();
846 request->request.op.operation_id = IPP_RELEASE_JOB;
847 request->request.op.request_id = 1;
849 language = cupsLangDefault();
851 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
852 "attributes-charset", NULL, "utf-8");
854 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
855 "attributes-natural-language", NULL, language->language);
857 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
859 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
861 if (!push_utf8_talloc(frame, &user, pjob->user, &size)) {
862 goto out;
864 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
865 NULL, user);
868 * Do the request and get back a response...
871 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) {
872 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
873 DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob,
874 ippErrorString(cupsLastError())));
875 } else {
876 ret = 0;
878 } else {
879 DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob,
880 ippErrorString(cupsLastError())));
883 out:
884 if (response)
885 ippDelete(response);
887 if (language)
888 cupsLangFree(language);
890 if (http)
891 httpClose(http);
893 TALLOC_FREE(frame);
894 return ret;
899 * 'cups_job_submit()' - Submit a job for printing.
902 static int cups_job_submit(int snum, struct printjob *pjob)
904 TALLOC_CTX *frame = talloc_stackframe();
905 int ret = 1; /* Return value */
906 http_t *http = NULL; /* HTTP connection to server */
907 ipp_t *request = NULL, /* IPP Request */
908 *response = NULL; /* IPP Response */
909 ipp_attribute_t *attr_job_id = NULL; /* IPP Attribute "job-id" */
910 cups_lang_t *language = NULL; /* Default language */
911 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
912 const char *clientname = NULL; /* hostname of client for job-originating-host attribute */
913 char *new_jobname = NULL;
914 int num_options = 0;
915 cups_option_t *options = NULL;
916 char *printername = NULL;
917 char *user = NULL;
918 char *jobname = NULL;
919 char *cupsoptions = NULL;
920 char *filename = NULL;
921 size_t size;
922 uint32_t jobid = (uint32_t)-1;
923 char addr[INET6_ADDRSTRLEN];
925 DEBUG(5,("cups_job_submit(%d, %p)\n", snum, pjob));
928 * Make sure we don't ask for passwords...
931 cupsSetPasswordCB(cups_passwd_cb);
934 * Try to connect to the server...
937 if ((http = cups_connect(frame)) == NULL) {
938 goto out;
942 * Build an IPP_PRINT_JOB request, which requires the following
943 * attributes:
945 * attributes-charset
946 * attributes-natural-language
947 * printer-uri
948 * requesting-user-name
949 * [document-data]
952 request = ippNew();
954 request->request.op.operation_id = IPP_PRINT_JOB;
955 request->request.op.request_id = 1;
957 language = cupsLangDefault();
959 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
960 "attributes-charset", NULL, "utf-8");
962 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
963 "attributes-natural-language", NULL, language->language);
965 if (!push_utf8_talloc(frame, &printername, PRINTERNAME(snum), &size)) {
966 goto out;
968 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
969 printername);
971 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
972 "printer-uri", NULL, uri);
974 if (!push_utf8_talloc(frame, &user, pjob->user, &size)) {
975 goto out;
977 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
978 NULL, user);
980 clientname = client_name(get_client_fd());
981 if (strcmp(clientname, "UNKNOWN") == 0) {
982 clientname = client_addr(get_client_fd(),addr,sizeof(addr));
985 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
986 "job-originating-host-name", NULL,
987 clientname);
989 /* Get the jobid from the filename. */
990 jobid = print_parse_jobid(pjob->filename);
991 if (jobid == (uint32_t)-1) {
992 DEBUG(0,("cups_job_submit: failed to parse jobid from name %s\n",
993 pjob->filename ));
994 jobid = 0;
997 if (!push_utf8_talloc(frame, &jobname, pjob->jobname, &size)) {
998 goto out;
1000 new_jobname = talloc_asprintf(frame,
1001 "%s%.8u %s", PRINT_SPOOL_PREFIX,
1002 (unsigned int)jobid,
1003 jobname);
1004 if (new_jobname == NULL) {
1005 goto out;
1008 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "job-name", NULL,
1009 new_jobname);
1012 * add any options defined in smb.conf
1015 if (!push_utf8_talloc(frame, &cupsoptions, lp_cups_options(snum), &size)) {
1016 goto out;
1018 num_options = 0;
1019 options = NULL;
1020 num_options = cupsParseOptions(cupsoptions, num_options, &options);
1022 if ( num_options )
1023 cupsEncodeOptions(request, num_options, options);
1026 * Do the request and get back a response...
1029 slprintf(uri, sizeof(uri) - 1, "/printers/%s", printername);
1031 if (!push_utf8_talloc(frame, &filename, pjob->filename, &size)) {
1032 goto out;
1034 if ((response = cupsDoFileRequest(http, request, uri, pjob->filename)) != NULL) {
1035 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
1036 DEBUG(0,("Unable to print file to %s - %s\n", PRINTERNAME(snum),
1037 ippErrorString(cupsLastError())));
1038 } else {
1039 ret = 0;
1040 attr_job_id = ippFindAttribute(response, "job-id", IPP_TAG_INTEGER);
1041 if(attr_job_id) {
1042 pjob->sysjob = attr_job_id->values[0].integer;
1043 DEBUG(5,("cups_job_submit: job-id %d\n", pjob->sysjob));
1044 } else {
1045 DEBUG(0,("Missing job-id attribute in IPP response"));
1048 } else {
1049 DEBUG(0,("Unable to print file to `%s' - %s\n", PRINTERNAME(snum),
1050 ippErrorString(cupsLastError())));
1053 if ( ret == 0 )
1054 unlink(pjob->filename);
1055 /* else print_job_end will do it for us */
1057 out:
1058 if (response)
1059 ippDelete(response);
1061 if (language)
1062 cupsLangFree(language);
1064 if (http)
1065 httpClose(http);
1067 TALLOC_FREE(frame);
1069 return ret;
1073 * 'cups_queue_get()' - Get all the jobs in the print queue.
1076 static int cups_queue_get(const char *sharename,
1077 enum printing_types printing_type,
1078 char *lpq_command,
1079 print_queue_struct **q,
1080 print_status_struct *status)
1082 TALLOC_CTX *frame = talloc_stackframe();
1083 char *printername = NULL;
1084 http_t *http = NULL; /* HTTP connection to server */
1085 ipp_t *request = NULL, /* IPP Request */
1086 *response = NULL; /* IPP Response */
1087 ipp_attribute_t *attr = NULL; /* Current attribute */
1088 cups_lang_t *language = NULL; /* Default language */
1089 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
1090 int qcount = 0, /* Number of active queue entries */
1091 qalloc = 0; /* Number of queue entries allocated */
1092 print_queue_struct *queue = NULL, /* Queue entries */
1093 *temp; /* Temporary pointer for queue */
1094 char *user_name = NULL, /* job-originating-user-name attribute */
1095 *job_name = NULL; /* job-name attribute */
1096 int job_id; /* job-id attribute */
1097 int job_k_octets; /* job-k-octets attribute */
1098 time_t job_time; /* time-at-creation attribute */
1099 ipp_jstate_t job_status; /* job-status attribute */
1100 int job_priority; /* job-priority attribute */
1101 size_t size;
1102 static const char *jattrs[] = /* Requested job attributes */
1104 "job-id",
1105 "job-k-octets",
1106 "job-name",
1107 "job-originating-user-name",
1108 "job-priority",
1109 "job-state",
1110 "time-at-creation",
1112 static const char *pattrs[] = /* Requested printer attributes */
1114 "printer-state",
1115 "printer-state-message"
1118 *q = NULL;
1120 /* HACK ALERT!!! The problem with support the 'printer name'
1121 option is that we key the tdb off the sharename. So we will
1122 overload the lpq_command string to pass in the printername
1123 (which is basically what we do for non-cups printers ... using
1124 the lpq_command to get the queue listing). */
1126 if (!push_utf8_talloc(frame, &printername, lpq_command, &size)) {
1127 goto out;
1129 DEBUG(5,("cups_queue_get(%s, %p, %p)\n", lpq_command, q, status));
1132 * Make sure we don't ask for passwords...
1135 cupsSetPasswordCB(cups_passwd_cb);
1138 * Try to connect to the server...
1141 if ((http = cups_connect(frame)) == NULL) {
1142 goto out;
1146 * Generate the printer URI...
1149 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s", printername);
1152 * Build an IPP_GET_JOBS request, which requires the following
1153 * attributes:
1155 * attributes-charset
1156 * attributes-natural-language
1157 * requested-attributes
1158 * printer-uri
1161 request = ippNew();
1163 request->request.op.operation_id = IPP_GET_JOBS;
1164 request->request.op.request_id = 1;
1166 language = cupsLangDefault();
1168 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1169 "attributes-charset", NULL, "utf-8");
1171 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1172 "attributes-natural-language", NULL, language->language);
1174 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
1175 "requested-attributes",
1176 (sizeof(jattrs) / sizeof(jattrs[0])),
1177 NULL, jattrs);
1179 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
1180 "printer-uri", NULL, uri);
1183 * Do the request and get back a response...
1186 if ((response = cupsDoRequest(http, request, "/")) == NULL) {
1187 DEBUG(0,("Unable to get jobs for %s - %s\n", uri,
1188 ippErrorString(cupsLastError())));
1189 goto out;
1192 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
1193 DEBUG(0,("Unable to get jobs for %s - %s\n", uri,
1194 ippErrorString(response->request.status.status_code)));
1195 goto out;
1199 * Process the jobs...
1202 qcount = 0;
1203 qalloc = 0;
1204 queue = NULL;
1206 for (attr = response->attrs; attr != NULL; attr = attr->next) {
1208 * Skip leading attributes until we hit a job...
1211 while (attr != NULL && attr->group_tag != IPP_TAG_JOB)
1212 attr = attr->next;
1214 if (attr == NULL)
1215 break;
1218 * Allocate memory as needed...
1220 if (qcount >= qalloc) {
1221 qalloc += 16;
1223 queue = SMB_REALLOC_ARRAY(queue, print_queue_struct, qalloc);
1225 if (queue == NULL) {
1226 DEBUG(0,("cups_queue_get: Not enough memory!"));
1227 qcount = 0;
1228 goto out;
1232 temp = queue + qcount;
1233 memset(temp, 0, sizeof(print_queue_struct));
1236 * Pull the needed attributes from this job...
1239 job_id = 0;
1240 job_priority = 50;
1241 job_status = IPP_JOB_PENDING;
1242 job_time = 0;
1243 job_k_octets = 0;
1244 user_name = NULL;
1245 job_name = NULL;
1247 while (attr != NULL && attr->group_tag == IPP_TAG_JOB) {
1248 if (attr->name == NULL) {
1249 attr = attr->next;
1250 break;
1253 if (strcmp(attr->name, "job-id") == 0 &&
1254 attr->value_tag == IPP_TAG_INTEGER)
1255 job_id = attr->values[0].integer;
1257 if (strcmp(attr->name, "job-k-octets") == 0 &&
1258 attr->value_tag == IPP_TAG_INTEGER)
1259 job_k_octets = attr->values[0].integer;
1261 if (strcmp(attr->name, "job-priority") == 0 &&
1262 attr->value_tag == IPP_TAG_INTEGER)
1263 job_priority = attr->values[0].integer;
1265 if (strcmp(attr->name, "job-state") == 0 &&
1266 attr->value_tag == IPP_TAG_ENUM)
1267 job_status = (ipp_jstate_t)(attr->values[0].integer);
1269 if (strcmp(attr->name, "time-at-creation") == 0 &&
1270 attr->value_tag == IPP_TAG_INTEGER)
1271 job_time = attr->values[0].integer;
1273 if (strcmp(attr->name, "job-name") == 0 &&
1274 attr->value_tag == IPP_TAG_NAME) {
1275 if (!pull_utf8_talloc(frame,
1276 &job_name,
1277 attr->values[0].string.text,
1278 &size)) {
1279 goto out;
1283 if (strcmp(attr->name, "job-originating-user-name") == 0 &&
1284 attr->value_tag == IPP_TAG_NAME) {
1285 if (!pull_utf8_talloc(frame,
1286 &user_name,
1287 attr->values[0].string.text,
1288 &size)) {
1289 goto out;
1293 attr = attr->next;
1297 * See if we have everything needed...
1300 if (user_name == NULL || job_name == NULL || job_id == 0) {
1301 if (attr == NULL)
1302 break;
1303 else
1304 continue;
1307 temp->job = job_id;
1308 temp->size = job_k_octets * 1024;
1309 temp->status = job_status == IPP_JOB_PENDING ? LPQ_QUEUED :
1310 job_status == IPP_JOB_STOPPED ? LPQ_PAUSED :
1311 job_status == IPP_JOB_HELD ? LPQ_PAUSED :
1312 LPQ_PRINTING;
1313 temp->priority = job_priority;
1314 temp->time = job_time;
1315 strlcpy(temp->fs_user, user_name, sizeof(temp->fs_user));
1316 strlcpy(temp->fs_file, job_name, sizeof(temp->fs_file));
1318 qcount ++;
1320 if (attr == NULL)
1321 break;
1324 ippDelete(response);
1325 response = NULL;
1328 * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the
1329 * following attributes:
1331 * attributes-charset
1332 * attributes-natural-language
1333 * requested-attributes
1334 * printer-uri
1337 request = ippNew();
1339 request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
1340 request->request.op.request_id = 1;
1342 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1343 "attributes-charset", NULL, "utf-8");
1345 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1346 "attributes-natural-language", NULL, language->language);
1348 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
1349 "requested-attributes",
1350 (sizeof(pattrs) / sizeof(pattrs[0])),
1351 NULL, pattrs);
1353 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
1354 "printer-uri", NULL, uri);
1357 * Do the request and get back a response...
1360 if ((response = cupsDoRequest(http, request, "/")) == NULL) {
1361 DEBUG(0,("Unable to get printer status for %s - %s\n", printername,
1362 ippErrorString(cupsLastError())));
1363 goto out;
1366 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
1367 DEBUG(0,("Unable to get printer status for %s - %s\n", printername,
1368 ippErrorString(response->request.status.status_code)));
1369 goto out;
1373 * Get the current printer status and convert it to the SAMBA values.
1376 if ((attr = ippFindAttribute(response, "printer-state", IPP_TAG_ENUM)) != NULL) {
1377 if (attr->values[0].integer == IPP_PRINTER_STOPPED)
1378 status->status = LPSTAT_STOPPED;
1379 else
1380 status->status = LPSTAT_OK;
1383 if ((attr = ippFindAttribute(response, "printer-state-message",
1384 IPP_TAG_TEXT)) != NULL) {
1385 char *msg = NULL;
1386 if (!pull_utf8_talloc(frame, &msg,
1387 attr->values[0].string.text,
1388 &size)) {
1389 SAFE_FREE(queue);
1390 qcount = 0;
1391 goto out;
1393 fstrcpy(status->message, msg);
1396 out:
1399 * Return the job queue...
1402 *q = queue;
1404 if (response)
1405 ippDelete(response);
1407 if (language)
1408 cupsLangFree(language);
1410 if (http)
1411 httpClose(http);
1413 TALLOC_FREE(frame);
1414 return qcount;
1419 * 'cups_queue_pause()' - Pause a print queue.
1422 static int cups_queue_pause(int snum)
1424 TALLOC_CTX *frame = talloc_stackframe();
1425 int ret = 1; /* Return value */
1426 http_t *http = NULL; /* HTTP connection to server */
1427 ipp_t *request = NULL, /* IPP Request */
1428 *response = NULL; /* IPP Response */
1429 cups_lang_t *language = NULL; /* Default language */
1430 char *printername = NULL;
1431 char *username = NULL;
1432 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
1433 size_t size;
1435 DEBUG(5,("cups_queue_pause(%d)\n", snum));
1438 * Make sure we don't ask for passwords...
1441 cupsSetPasswordCB(cups_passwd_cb);
1444 * Try to connect to the server...
1447 if ((http = cups_connect(frame)) == NULL) {
1448 goto out;
1452 * Build an IPP_PAUSE_PRINTER request, which requires the following
1453 * attributes:
1455 * attributes-charset
1456 * attributes-natural-language
1457 * printer-uri
1458 * requesting-user-name
1461 request = ippNew();
1463 request->request.op.operation_id = IPP_PAUSE_PRINTER;
1464 request->request.op.request_id = 1;
1466 language = cupsLangDefault();
1468 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1469 "attributes-charset", NULL, "utf-8");
1471 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1472 "attributes-natural-language", NULL, language->language);
1474 if (!push_utf8_talloc(frame, &printername, PRINTERNAME(snum), &size)) {
1475 goto out;
1477 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
1478 printername);
1480 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
1482 if (!push_utf8_talloc(frame, &username, current_user_info.unix_name, &size)) {
1483 goto out;
1485 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
1486 NULL, username);
1489 * Do the request and get back a response...
1492 if ((response = cupsDoRequest(http, request, "/admin/")) != NULL) {
1493 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
1494 DEBUG(0,("Unable to pause printer %s - %s\n", PRINTERNAME(snum),
1495 ippErrorString(cupsLastError())));
1496 } else {
1497 ret = 0;
1499 } else {
1500 DEBUG(0,("Unable to pause printer %s - %s\n", PRINTERNAME(snum),
1501 ippErrorString(cupsLastError())));
1504 out:
1505 if (response)
1506 ippDelete(response);
1508 if (language)
1509 cupsLangFree(language);
1511 if (http)
1512 httpClose(http);
1514 TALLOC_FREE(frame);
1515 return ret;
1520 * 'cups_queue_resume()' - Restart a print queue.
1523 static int cups_queue_resume(int snum)
1525 TALLOC_CTX *frame = talloc_stackframe();
1526 int ret = 1; /* Return value */
1527 http_t *http = NULL; /* HTTP connection to server */
1528 ipp_t *request = NULL, /* IPP Request */
1529 *response = NULL; /* IPP Response */
1530 cups_lang_t *language = NULL; /* Default language */
1531 char *printername = NULL;
1532 char *username = NULL;
1533 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
1534 size_t size;
1536 DEBUG(5,("cups_queue_resume(%d)\n", snum));
1539 * Make sure we don't ask for passwords...
1542 cupsSetPasswordCB(cups_passwd_cb);
1545 * Try to connect to the server...
1548 if ((http = cups_connect(frame)) == NULL) {
1549 goto out;
1553 * Build an IPP_RESUME_PRINTER request, which requires the following
1554 * attributes:
1556 * attributes-charset
1557 * attributes-natural-language
1558 * printer-uri
1559 * requesting-user-name
1562 request = ippNew();
1564 request->request.op.operation_id = IPP_RESUME_PRINTER;
1565 request->request.op.request_id = 1;
1567 language = cupsLangDefault();
1569 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1570 "attributes-charset", NULL, "utf-8");
1572 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1573 "attributes-natural-language", NULL, language->language);
1575 if (!push_utf8_talloc(frame, &printername, PRINTERNAME(snum), &size)) {
1576 goto out;
1578 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
1579 printername);
1581 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
1583 if (!push_utf8_talloc(frame, &username, current_user_info.unix_name, &size)) {
1584 goto out;
1586 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
1587 NULL, username);
1590 * Do the request and get back a response...
1593 if ((response = cupsDoRequest(http, request, "/admin/")) != NULL) {
1594 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
1595 DEBUG(0,("Unable to resume printer %s - %s\n", PRINTERNAME(snum),
1596 ippErrorString(cupsLastError())));
1597 } else {
1598 ret = 0;
1600 } else {
1601 DEBUG(0,("Unable to resume printer %s - %s\n", PRINTERNAME(snum),
1602 ippErrorString(cupsLastError())));
1605 out:
1606 if (response)
1607 ippDelete(response);
1609 if (language)
1610 cupsLangFree(language);
1612 if (http)
1613 httpClose(http);
1615 TALLOC_FREE(frame);
1616 return ret;
1619 /*******************************************************************
1620 * CUPS printing interface definitions...
1621 ******************************************************************/
1623 struct printif cups_printif =
1625 PRINT_CUPS,
1626 cups_queue_get,
1627 cups_queue_pause,
1628 cups_queue_resume,
1629 cups_job_delete,
1630 cups_job_pause,
1631 cups_job_resume,
1632 cups_job_submit,
1635 bool cups_pull_comment_location(TALLOC_CTX *mem_ctx,
1636 const char *printername,
1637 char **comment,
1638 char **location)
1640 TALLOC_CTX *frame = talloc_stackframe();
1641 http_t *http = NULL; /* HTTP connection to server */
1642 ipp_t *request = NULL, /* IPP Request */
1643 *response = NULL; /* IPP Response */
1644 ipp_attribute_t *attr; /* Current attribute */
1645 cups_lang_t *language = NULL; /* Default language */
1646 char uri[HTTP_MAX_URI];
1647 char *server = NULL;
1648 char *sharename = NULL;
1649 char *name = NULL;
1650 static const char *requested[] =/* Requested attributes */
1652 "printer-name",
1653 "printer-info",
1654 "printer-location"
1656 bool ret = False;
1657 size_t size;
1659 DEBUG(5, ("pulling %s location\n", printername));
1662 * Make sure we don't ask for passwords...
1665 cupsSetPasswordCB(cups_passwd_cb);
1668 * Try to connect to the server...
1671 if ((http = cups_connect(frame)) == NULL) {
1672 goto out;
1675 request = ippNew();
1677 request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
1678 request->request.op.request_id = 1;
1680 language = cupsLangDefault();
1682 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1683 "attributes-charset", NULL, "utf-8");
1685 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1686 "attributes-natural-language", NULL, language->language);
1688 if (lp_cups_server() != NULL && strlen(lp_cups_server()) > 0) {
1689 if (!push_utf8_talloc(frame, &server, lp_cups_server(), &size)) {
1690 goto out;
1692 } else {
1693 server = talloc_strdup(frame,cupsServer());
1695 if (server) {
1696 goto out;
1698 if (!push_utf8_talloc(frame, &sharename, printername, &size)) {
1699 goto out;
1701 slprintf(uri, sizeof(uri) - 1, "ipp://%s/printers/%s",
1702 server, sharename);
1704 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
1705 "printer-uri", NULL, uri);
1707 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
1708 "requested-attributes",
1709 (sizeof(requested) / sizeof(requested[0])),
1710 NULL, requested);
1713 * Do the request and get back a response...
1716 if ((response = cupsDoRequest(http, request, "/")) == NULL) {
1717 DEBUG(0,("Unable to get printer attributes - %s\n",
1718 ippErrorString(cupsLastError())));
1719 goto out;
1722 for (attr = response->attrs; attr != NULL;) {
1724 * Skip leading attributes until we hit a printer...
1727 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
1728 attr = attr->next;
1730 if (attr == NULL)
1731 break;
1734 * Pull the needed attributes from this printer...
1737 while ( attr && (attr->group_tag == IPP_TAG_PRINTER) ) {
1738 if (strcmp(attr->name, "printer-name") == 0 &&
1739 attr->value_tag == IPP_TAG_NAME) {
1740 if (!pull_utf8_talloc(frame,
1741 &name,
1742 attr->values[0].string.text,
1743 &size)) {
1744 goto out;
1748 /* Grab the comment if we don't have one */
1749 if ( (strcmp(attr->name, "printer-info") == 0)
1750 && (attr->value_tag == IPP_TAG_TEXT))
1752 if (!pull_utf8_talloc(mem_ctx,
1753 comment,
1754 attr->values[0].string.text,
1755 &size)) {
1756 goto out;
1758 DEBUG(5,("cups_pull_comment_location: Using cups comment: %s\n",
1759 *comment));
1762 /* Grab the location if we don't have one */
1763 if ( (strcmp(attr->name, "printer-location") == 0)
1764 && (attr->value_tag == IPP_TAG_TEXT))
1766 if (!pull_utf8_talloc(mem_ctx,
1767 location,
1768 attr->values[0].string.text,
1769 &size)) {
1770 goto out;
1772 DEBUG(5,("cups_pull_comment_location: Using cups location: %s\n",
1773 *location));
1776 attr = attr->next;
1780 * We have everything needed...
1783 if (name != NULL)
1784 break;
1787 ret = True;
1789 out:
1790 if (response)
1791 ippDelete(response);
1793 if (request) {
1794 ippDelete(request);
1797 if (language)
1798 cupsLangFree(language);
1800 if (http)
1801 httpClose(http);
1803 TALLOC_FREE(frame);
1804 return ret;
1807 #else
1808 /* this keeps fussy compilers happy */
1809 void print_cups_dummy(void);
1810 void print_cups_dummy(void) {}
1811 #endif /* HAVE_CUPS */