s3-dcerpc: Pull packet in the caller, before validation
[Samba.git] / source3 / printing / print_cups.c
bloba85fba89974f316c5e49e33f6d1942b5b87a2d2e
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(struct tevent_context *ev,
397 struct messaging_context *msg_ctx,
398 int *pfd)
400 int fds[2];
401 pid_t pid;
402 NTSTATUS status;
404 *pfd = -1;
406 if (cache_fd_event) {
407 DEBUG(3,("cups_pcap_load_async: already waiting for "
408 "a refresh event\n" ));
409 return false;
412 DEBUG(5,("cups_pcap_load_async: asynchronously loading cups printers\n"));
414 if (pipe(fds) == -1) {
415 return false;
418 pid = sys_fork();
419 if (pid == (pid_t)-1) {
420 DEBUG(10,("cups_pcap_load_async: fork failed %s\n",
421 strerror(errno) ));
422 close(fds[0]);
423 close(fds[1]);
424 return false;
427 if (pid) {
428 DEBUG(10,("cups_pcap_load_async: child pid = %u\n",
429 (unsigned int)pid ));
430 /* Parent. */
431 close(fds[1]);
432 *pfd = fds[0];
433 return true;
436 /* Child. */
438 close_all_print_db();
440 status = reinit_after_fork(msg_ctx, ev, procid_self(), true);
441 if (!NT_STATUS_IS_OK(status)) {
442 DEBUG(0,("cups_pcap_load_async: reinit_after_fork() failed\n"));
443 smb_panic("cups_pcap_load_async: reinit_after_fork() failed");
446 close(fds[0]);
447 cups_cache_reload_async(fds[1]);
448 close(fds[1]);
449 _exit(0);
452 static void cups_async_callback(struct event_context *event_ctx,
453 struct fd_event *event,
454 uint16 flags,
455 void *p)
457 TALLOC_CTX *frame = talloc_stackframe();
458 int fd = *(int *)p;
459 struct pcap_cache *tmp_pcap_cache = NULL;
461 DEBUG(5,("cups_async_callback: callback received for printer data. "
462 "fd = %d\n", fd));
464 while (1) {
465 char *name = NULL, *info = NULL;
466 size_t namelen = 0, infolen = 0;
467 ssize_t ret = -1;
469 ret = sys_read(fd, &namelen, sizeof(namelen));
470 if (ret == 0) {
471 /* EOF */
472 break;
474 if (ret != sizeof(namelen)) {
475 DEBUG(10,("cups_async_callback: namelen read failed %d %s\n",
476 errno, strerror(errno)));
477 break;
480 DEBUG(11,("cups_async_callback: read namelen %u\n",
481 (unsigned int)namelen));
483 ret = sys_read(fd, &infolen, sizeof(infolen));
484 if (ret == 0) {
485 /* EOF */
486 break;
488 if (ret != sizeof(infolen)) {
489 DEBUG(10,("cups_async_callback: infolen read failed %s\n",
490 strerror(errno)));
491 break;
494 DEBUG(11,("cups_async_callback: read infolen %u\n",
495 (unsigned int)infolen));
497 if (namelen) {
498 name = TALLOC_ARRAY(frame, char, namelen);
499 if (!name) {
500 break;
502 ret = sys_read(fd, name, namelen);
503 if (ret == 0) {
504 /* EOF */
505 break;
507 if (ret != namelen) {
508 DEBUG(10,("cups_async_callback: name read failed %s\n",
509 strerror(errno)));
510 break;
512 DEBUG(11,("cups_async_callback: read name %s\n",
513 name));
514 } else {
515 name = NULL;
517 if (infolen) {
518 info = TALLOC_ARRAY(frame, char, infolen);
519 if (!info) {
520 break;
522 ret = sys_read(fd, info, infolen);
523 if (ret == 0) {
524 /* EOF */
525 break;
527 if (ret != infolen) {
528 DEBUG(10,("cups_async_callback: info read failed %s\n",
529 strerror(errno)));
530 break;
532 DEBUG(11,("cups_async_callback: read info %s\n",
533 info));
534 } else {
535 info = NULL;
538 /* Add to our local pcap cache. */
539 pcap_cache_add_specific(&tmp_pcap_cache, name, info);
540 TALLOC_FREE(name);
541 TALLOC_FREE(info);
544 TALLOC_FREE(frame);
545 if (tmp_pcap_cache) {
546 /* We got a namelist, replace our local cache. */
547 pcap_cache_destroy_specific(&local_pcap_copy);
548 local_pcap_copy = tmp_pcap_cache;
550 /* And the systemwide pcap cache. */
551 pcap_cache_replace(local_pcap_copy);
552 } else {
553 DEBUG(2,("cups_async_callback: failed to read a new "
554 "printer list\n"));
556 close(fd);
557 TALLOC_FREE(p);
558 TALLOC_FREE(cache_fd_event);
561 bool cups_cache_reload(struct tevent_context *ev,
562 struct messaging_context *msg_ctx)
564 int *p_pipe_fd = TALLOC_P(NULL, int);
566 if (!p_pipe_fd) {
567 return false;
570 *p_pipe_fd = -1;
572 /* Set up an async refresh. */
573 if (!cups_pcap_load_async(ev, msg_ctx, p_pipe_fd)) {
574 return false;
576 if (!local_pcap_copy) {
577 /* We have no local cache, wait directly for
578 * async refresh to complete.
580 DEBUG(10,("cups_cache_reload: sync read on fd %d\n",
581 *p_pipe_fd ));
583 cups_async_callback(ev, NULL,
584 EVENT_FD_READ,
585 (void *)p_pipe_fd);
586 if (!local_pcap_copy) {
587 return false;
589 } else {
590 /* Replace the system cache with our
591 * local copy. */
592 pcap_cache_replace(local_pcap_copy);
594 DEBUG(10,("cups_cache_reload: async read on fd %d\n",
595 *p_pipe_fd ));
597 /* Trigger an event when the pipe can be read. */
598 cache_fd_event = event_add_fd(ev,
599 NULL, *p_pipe_fd,
600 EVENT_FD_READ,
601 cups_async_callback,
602 (void *)p_pipe_fd);
603 if (!cache_fd_event) {
604 close(*p_pipe_fd);
605 TALLOC_FREE(p_pipe_fd);
606 return false;
609 return true;
613 * 'cups_job_delete()' - Delete a job.
616 static int cups_job_delete(const char *sharename, const char *lprm_command, struct printjob *pjob)
618 TALLOC_CTX *frame = talloc_stackframe();
619 int ret = 1; /* Return value */
620 http_t *http = NULL; /* HTTP connection to server */
621 ipp_t *request = NULL, /* IPP Request */
622 *response = NULL; /* IPP Response */
623 cups_lang_t *language = NULL; /* Default language */
624 char *user = NULL;
625 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
626 size_t size;
628 DEBUG(5,("cups_job_delete(%s, %p (%d))\n", sharename, pjob, pjob->sysjob));
631 * Make sure we don't ask for passwords...
634 cupsSetPasswordCB(cups_passwd_cb);
637 * Try to connect to the server...
640 if ((http = cups_connect(frame)) == NULL) {
641 goto out;
645 * Build an IPP_CANCEL_JOB request, which requires the following
646 * attributes:
648 * attributes-charset
649 * attributes-natural-language
650 * job-uri
651 * requesting-user-name
654 request = ippNew();
656 request->request.op.operation_id = IPP_CANCEL_JOB;
657 request->request.op.request_id = 1;
659 language = cupsLangDefault();
661 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
662 "attributes-charset", NULL, "utf-8");
664 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
665 "attributes-natural-language", NULL, language->language);
667 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
669 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
671 if (!push_utf8_talloc(frame, &user, pjob->user, &size)) {
672 goto out;
675 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
676 NULL, user);
679 * Do the request and get back a response...
682 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) {
683 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
684 DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob,
685 ippErrorString(cupsLastError())));
686 } else {
687 ret = 0;
689 } else {
690 DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob,
691 ippErrorString(cupsLastError())));
694 out:
695 if (response)
696 ippDelete(response);
698 if (language)
699 cupsLangFree(language);
701 if (http)
702 httpClose(http);
704 TALLOC_FREE(frame);
705 return ret;
710 * 'cups_job_pause()' - Pause a job.
713 static int cups_job_pause(int snum, struct printjob *pjob)
715 TALLOC_CTX *frame = talloc_stackframe();
716 int ret = 1; /* Return value */
717 http_t *http = NULL; /* HTTP connection to server */
718 ipp_t *request = NULL, /* IPP Request */
719 *response = NULL; /* IPP Response */
720 cups_lang_t *language = NULL; /* Default language */
721 char *user = NULL;
722 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
723 size_t size;
725 DEBUG(5,("cups_job_pause(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
728 * Make sure we don't ask for passwords...
731 cupsSetPasswordCB(cups_passwd_cb);
734 * Try to connect to the server...
737 if ((http = cups_connect(frame)) == NULL) {
738 goto out;
742 * Build an IPP_HOLD_JOB request, which requires the following
743 * attributes:
745 * attributes-charset
746 * attributes-natural-language
747 * job-uri
748 * requesting-user-name
751 request = ippNew();
753 request->request.op.operation_id = IPP_HOLD_JOB;
754 request->request.op.request_id = 1;
756 language = cupsLangDefault();
758 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
759 "attributes-charset", NULL, "utf-8");
761 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
762 "attributes-natural-language", NULL, language->language);
764 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
766 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
768 if (!push_utf8_talloc(frame, &user, pjob->user, &size)) {
769 goto out;
771 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
772 NULL, user);
775 * Do the request and get back a response...
778 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) {
779 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
780 DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob,
781 ippErrorString(cupsLastError())));
782 } else {
783 ret = 0;
785 } else {
786 DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob,
787 ippErrorString(cupsLastError())));
790 out:
791 if (response)
792 ippDelete(response);
794 if (language)
795 cupsLangFree(language);
797 if (http)
798 httpClose(http);
800 TALLOC_FREE(frame);
801 return ret;
806 * 'cups_job_resume()' - Resume a paused job.
809 static int cups_job_resume(int snum, struct printjob *pjob)
811 TALLOC_CTX *frame = talloc_stackframe();
812 int ret = 1; /* Return value */
813 http_t *http = NULL; /* HTTP connection to server */
814 ipp_t *request = NULL, /* IPP Request */
815 *response = NULL; /* IPP Response */
816 cups_lang_t *language = NULL; /* Default language */
817 char *user = NULL;
818 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
819 size_t size;
821 DEBUG(5,("cups_job_resume(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
824 * Make sure we don't ask for passwords...
827 cupsSetPasswordCB(cups_passwd_cb);
830 * Try to connect to the server...
833 if ((http = cups_connect(frame)) == NULL) {
834 goto out;
838 * Build an IPP_RELEASE_JOB request, which requires the following
839 * attributes:
841 * attributes-charset
842 * attributes-natural-language
843 * job-uri
844 * requesting-user-name
847 request = ippNew();
849 request->request.op.operation_id = IPP_RELEASE_JOB;
850 request->request.op.request_id = 1;
852 language = cupsLangDefault();
854 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
855 "attributes-charset", NULL, "utf-8");
857 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
858 "attributes-natural-language", NULL, language->language);
860 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
862 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
864 if (!push_utf8_talloc(frame, &user, pjob->user, &size)) {
865 goto out;
867 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
868 NULL, user);
871 * Do the request and get back a response...
874 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) {
875 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
876 DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob,
877 ippErrorString(cupsLastError())));
878 } else {
879 ret = 0;
881 } else {
882 DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob,
883 ippErrorString(cupsLastError())));
886 out:
887 if (response)
888 ippDelete(response);
890 if (language)
891 cupsLangFree(language);
893 if (http)
894 httpClose(http);
896 TALLOC_FREE(frame);
897 return ret;
902 * 'cups_job_submit()' - Submit a job for printing.
905 static int cups_job_submit(int snum, struct printjob *pjob)
907 TALLOC_CTX *frame = talloc_stackframe();
908 int ret = 1; /* Return value */
909 http_t *http = NULL; /* HTTP connection to server */
910 ipp_t *request = NULL, /* IPP Request */
911 *response = NULL; /* IPP Response */
912 ipp_attribute_t *attr_job_id = NULL; /* IPP Attribute "job-id" */
913 cups_lang_t *language = NULL; /* Default language */
914 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
915 char *new_jobname = NULL;
916 int num_options = 0;
917 cups_option_t *options = NULL;
918 char *printername = NULL;
919 char *user = NULL;
920 char *jobname = NULL;
921 char *cupsoptions = NULL;
922 char *filename = NULL;
923 size_t size;
924 uint32_t jobid = (uint32_t)-1;
926 DEBUG(5,("cups_job_submit(%d, %p)\n", snum, pjob));
929 * Make sure we don't ask for passwords...
932 cupsSetPasswordCB(cups_passwd_cb);
935 * Try to connect to the server...
938 if ((http = cups_connect(frame)) == NULL) {
939 goto out;
943 * Build an IPP_PRINT_JOB request, which requires the following
944 * attributes:
946 * attributes-charset
947 * attributes-natural-language
948 * printer-uri
949 * requesting-user-name
950 * [document-data]
953 request = ippNew();
955 request->request.op.operation_id = IPP_PRINT_JOB;
956 request->request.op.request_id = 1;
958 language = cupsLangDefault();
960 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
961 "attributes-charset", NULL, "utf-8");
963 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
964 "attributes-natural-language", NULL, language->language);
966 if (!push_utf8_talloc(frame, &printername, lp_printername(snum),
967 &size)) {
968 goto out;
970 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
971 printername);
973 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
974 "printer-uri", NULL, uri);
976 if (!push_utf8_talloc(frame, &user, pjob->user, &size)) {
977 goto out;
979 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
980 NULL, user);
982 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
983 "job-originating-host-name", NULL,
984 pjob->clientmachine);
986 /* Get the jobid from the filename. */
987 jobid = print_parse_jobid(pjob->filename);
988 if (jobid == (uint32_t)-1) {
989 DEBUG(0,("cups_job_submit: failed to parse jobid from name %s\n",
990 pjob->filename ));
991 jobid = 0;
994 if (!push_utf8_talloc(frame, &jobname, pjob->jobname, &size)) {
995 goto out;
997 new_jobname = talloc_asprintf(frame,
998 "%s%.8u %s", PRINT_SPOOL_PREFIX,
999 (unsigned int)jobid,
1000 jobname);
1001 if (new_jobname == NULL) {
1002 goto out;
1005 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "job-name", NULL,
1006 new_jobname);
1009 * add any options defined in smb.conf
1012 if (!push_utf8_talloc(frame, &cupsoptions, lp_cups_options(snum), &size)) {
1013 goto out;
1015 num_options = 0;
1016 options = NULL;
1017 num_options = cupsParseOptions(cupsoptions, num_options, &options);
1019 if ( num_options )
1020 cupsEncodeOptions(request, num_options, options);
1023 * Do the request and get back a response...
1026 slprintf(uri, sizeof(uri) - 1, "/printers/%s", printername);
1028 if (!push_utf8_talloc(frame, &filename, pjob->filename, &size)) {
1029 goto out;
1031 if ((response = cupsDoFileRequest(http, request, uri, pjob->filename)) != NULL) {
1032 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
1033 DEBUG(0,("Unable to print file to %s - %s\n",
1034 lp_printername(snum),
1035 ippErrorString(cupsLastError())));
1036 } else {
1037 ret = 0;
1038 attr_job_id = ippFindAttribute(response, "job-id", IPP_TAG_INTEGER);
1039 if(attr_job_id) {
1040 pjob->sysjob = attr_job_id->values[0].integer;
1041 DEBUG(5,("cups_job_submit: job-id %d\n", pjob->sysjob));
1042 } else {
1043 DEBUG(0,("Missing job-id attribute in IPP response"));
1046 } else {
1047 DEBUG(0,("Unable to print file to `%s' - %s\n",
1048 lp_printername(snum),
1049 ippErrorString(cupsLastError())));
1052 if ( ret == 0 )
1053 unlink(pjob->filename);
1054 /* else print_job_end will do it for us */
1056 out:
1057 if (response)
1058 ippDelete(response);
1060 if (language)
1061 cupsLangFree(language);
1063 if (http)
1064 httpClose(http);
1066 TALLOC_FREE(frame);
1068 return ret;
1072 * 'cups_queue_get()' - Get all the jobs in the print queue.
1075 static int cups_queue_get(const char *sharename,
1076 enum printing_types printing_type,
1077 char *lpq_command,
1078 print_queue_struct **q,
1079 print_status_struct *status)
1081 TALLOC_CTX *frame = talloc_stackframe();
1082 char *printername = NULL;
1083 http_t *http = NULL; /* HTTP connection to server */
1084 ipp_t *request = NULL, /* IPP Request */
1085 *response = NULL; /* IPP Response */
1086 ipp_attribute_t *attr = NULL; /* Current attribute */
1087 cups_lang_t *language = NULL; /* Default language */
1088 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
1089 int qcount = 0, /* Number of active queue entries */
1090 qalloc = 0; /* Number of queue entries allocated */
1091 print_queue_struct *queue = NULL, /* Queue entries */
1092 *temp; /* Temporary pointer for queue */
1093 char *user_name = NULL, /* job-originating-user-name attribute */
1094 *job_name = NULL; /* job-name attribute */
1095 int job_id; /* job-id attribute */
1096 int job_k_octets; /* job-k-octets attribute */
1097 time_t job_time; /* time-at-creation attribute */
1098 ipp_jstate_t job_status; /* job-status attribute */
1099 int job_priority; /* job-priority attribute */
1100 size_t size;
1101 static const char *jattrs[] = /* Requested job attributes */
1103 "job-id",
1104 "job-k-octets",
1105 "job-name",
1106 "job-originating-user-name",
1107 "job-priority",
1108 "job-state",
1109 "time-at-creation",
1111 static const char *pattrs[] = /* Requested printer attributes */
1113 "printer-state",
1114 "printer-state-message"
1117 *q = NULL;
1119 /* HACK ALERT!!! The problem with support the 'printer name'
1120 option is that we key the tdb off the sharename. So we will
1121 overload the lpq_command string to pass in the printername
1122 (which is basically what we do for non-cups printers ... using
1123 the lpq_command to get the queue listing). */
1125 if (!push_utf8_talloc(frame, &printername, lpq_command, &size)) {
1126 goto out;
1128 DEBUG(5,("cups_queue_get(%s, %p, %p)\n", lpq_command, q, status));
1131 * Make sure we don't ask for passwords...
1134 cupsSetPasswordCB(cups_passwd_cb);
1137 * Try to connect to the server...
1140 if ((http = cups_connect(frame)) == NULL) {
1141 goto out;
1145 * Generate the printer URI...
1148 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s", printername);
1151 * Build an IPP_GET_JOBS request, which requires the following
1152 * attributes:
1154 * attributes-charset
1155 * attributes-natural-language
1156 * requested-attributes
1157 * printer-uri
1160 request = ippNew();
1162 request->request.op.operation_id = IPP_GET_JOBS;
1163 request->request.op.request_id = 1;
1165 language = cupsLangDefault();
1167 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1168 "attributes-charset", NULL, "utf-8");
1170 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1171 "attributes-natural-language", NULL, language->language);
1173 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
1174 "requested-attributes",
1175 (sizeof(jattrs) / sizeof(jattrs[0])),
1176 NULL, jattrs);
1178 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
1179 "printer-uri", NULL, uri);
1182 * Do the request and get back a response...
1185 if ((response = cupsDoRequest(http, request, "/")) == NULL) {
1186 DEBUG(0,("Unable to get jobs for %s - %s\n", uri,
1187 ippErrorString(cupsLastError())));
1188 goto out;
1191 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
1192 DEBUG(0,("Unable to get jobs for %s - %s\n", uri,
1193 ippErrorString(response->request.status.status_code)));
1194 goto out;
1198 * Process the jobs...
1201 qcount = 0;
1202 qalloc = 0;
1203 queue = NULL;
1205 for (attr = response->attrs; attr != NULL; attr = attr->next) {
1207 * Skip leading attributes until we hit a job...
1210 while (attr != NULL && attr->group_tag != IPP_TAG_JOB)
1211 attr = attr->next;
1213 if (attr == NULL)
1214 break;
1217 * Allocate memory as needed...
1219 if (qcount >= qalloc) {
1220 qalloc += 16;
1222 queue = SMB_REALLOC_ARRAY(queue, print_queue_struct, qalloc);
1224 if (queue == NULL) {
1225 DEBUG(0,("cups_queue_get: Not enough memory!"));
1226 qcount = 0;
1227 goto out;
1231 temp = queue + qcount;
1232 memset(temp, 0, sizeof(print_queue_struct));
1235 * Pull the needed attributes from this job...
1238 job_id = 0;
1239 job_priority = 50;
1240 job_status = IPP_JOB_PENDING;
1241 job_time = 0;
1242 job_k_octets = 0;
1243 user_name = NULL;
1244 job_name = NULL;
1246 while (attr != NULL && attr->group_tag == IPP_TAG_JOB) {
1247 if (attr->name == NULL) {
1248 attr = attr->next;
1249 break;
1252 if (strcmp(attr->name, "job-id") == 0 &&
1253 attr->value_tag == IPP_TAG_INTEGER)
1254 job_id = attr->values[0].integer;
1256 if (strcmp(attr->name, "job-k-octets") == 0 &&
1257 attr->value_tag == IPP_TAG_INTEGER)
1258 job_k_octets = attr->values[0].integer;
1260 if (strcmp(attr->name, "job-priority") == 0 &&
1261 attr->value_tag == IPP_TAG_INTEGER)
1262 job_priority = attr->values[0].integer;
1264 if (strcmp(attr->name, "job-state") == 0 &&
1265 attr->value_tag == IPP_TAG_ENUM)
1266 job_status = (ipp_jstate_t)(attr->values[0].integer);
1268 if (strcmp(attr->name, "time-at-creation") == 0 &&
1269 attr->value_tag == IPP_TAG_INTEGER)
1270 job_time = attr->values[0].integer;
1272 if (strcmp(attr->name, "job-name") == 0 &&
1273 attr->value_tag == IPP_TAG_NAME) {
1274 if (!pull_utf8_talloc(frame,
1275 &job_name,
1276 attr->values[0].string.text,
1277 &size)) {
1278 goto out;
1282 if (strcmp(attr->name, "job-originating-user-name") == 0 &&
1283 attr->value_tag == IPP_TAG_NAME) {
1284 if (!pull_utf8_talloc(frame,
1285 &user_name,
1286 attr->values[0].string.text,
1287 &size)) {
1288 goto out;
1292 attr = attr->next;
1296 * See if we have everything needed...
1299 if (user_name == NULL || job_name == NULL || job_id == 0) {
1300 if (attr == NULL)
1301 break;
1302 else
1303 continue;
1306 temp->job = job_id;
1307 temp->size = job_k_octets * 1024;
1308 temp->status = job_status == IPP_JOB_PENDING ? LPQ_QUEUED :
1309 job_status == IPP_JOB_STOPPED ? LPQ_PAUSED :
1310 job_status == IPP_JOB_HELD ? LPQ_PAUSED :
1311 LPQ_PRINTING;
1312 temp->priority = job_priority;
1313 temp->time = job_time;
1314 strlcpy(temp->fs_user, user_name, sizeof(temp->fs_user));
1315 strlcpy(temp->fs_file, job_name, sizeof(temp->fs_file));
1317 qcount ++;
1319 if (attr == NULL)
1320 break;
1323 ippDelete(response);
1324 response = NULL;
1327 * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the
1328 * following attributes:
1330 * attributes-charset
1331 * attributes-natural-language
1332 * requested-attributes
1333 * printer-uri
1336 request = ippNew();
1338 request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
1339 request->request.op.request_id = 1;
1341 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1342 "attributes-charset", NULL, "utf-8");
1344 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1345 "attributes-natural-language", NULL, language->language);
1347 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
1348 "requested-attributes",
1349 (sizeof(pattrs) / sizeof(pattrs[0])),
1350 NULL, pattrs);
1352 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
1353 "printer-uri", NULL, uri);
1356 * Do the request and get back a response...
1359 if ((response = cupsDoRequest(http, request, "/")) == NULL) {
1360 DEBUG(0,("Unable to get printer status for %s - %s\n", printername,
1361 ippErrorString(cupsLastError())));
1362 goto out;
1365 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
1366 DEBUG(0,("Unable to get printer status for %s - %s\n", printername,
1367 ippErrorString(response->request.status.status_code)));
1368 goto out;
1372 * Get the current printer status and convert it to the SAMBA values.
1375 if ((attr = ippFindAttribute(response, "printer-state", IPP_TAG_ENUM)) != NULL) {
1376 if (attr->values[0].integer == IPP_PRINTER_STOPPED)
1377 status->status = LPSTAT_STOPPED;
1378 else
1379 status->status = LPSTAT_OK;
1382 if ((attr = ippFindAttribute(response, "printer-state-message",
1383 IPP_TAG_TEXT)) != NULL) {
1384 char *msg = NULL;
1385 if (!pull_utf8_talloc(frame, &msg,
1386 attr->values[0].string.text,
1387 &size)) {
1388 SAFE_FREE(queue);
1389 qcount = 0;
1390 goto out;
1392 fstrcpy(status->message, msg);
1395 out:
1398 * Return the job queue...
1401 *q = queue;
1403 if (response)
1404 ippDelete(response);
1406 if (language)
1407 cupsLangFree(language);
1409 if (http)
1410 httpClose(http);
1412 TALLOC_FREE(frame);
1413 return qcount;
1418 * 'cups_queue_pause()' - Pause a print queue.
1421 static int cups_queue_pause(int snum)
1423 TALLOC_CTX *frame = talloc_stackframe();
1424 int ret = 1; /* Return value */
1425 http_t *http = NULL; /* HTTP connection to server */
1426 ipp_t *request = NULL, /* IPP Request */
1427 *response = NULL; /* IPP Response */
1428 cups_lang_t *language = NULL; /* Default language */
1429 char *printername = NULL;
1430 char *username = NULL;
1431 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
1432 size_t size;
1434 DEBUG(5,("cups_queue_pause(%d)\n", snum));
1437 * Make sure we don't ask for passwords...
1440 cupsSetPasswordCB(cups_passwd_cb);
1443 * Try to connect to the server...
1446 if ((http = cups_connect(frame)) == NULL) {
1447 goto out;
1451 * Build an IPP_PAUSE_PRINTER request, which requires the following
1452 * attributes:
1454 * attributes-charset
1455 * attributes-natural-language
1456 * printer-uri
1457 * requesting-user-name
1460 request = ippNew();
1462 request->request.op.operation_id = IPP_PAUSE_PRINTER;
1463 request->request.op.request_id = 1;
1465 language = cupsLangDefault();
1467 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1468 "attributes-charset", NULL, "utf-8");
1470 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1471 "attributes-natural-language", NULL, language->language);
1473 if (!push_utf8_talloc(frame, &printername, lp_printername(snum),
1474 &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",
1495 lp_printername(snum),
1496 ippErrorString(cupsLastError())));
1497 } else {
1498 ret = 0;
1500 } else {
1501 DEBUG(0,("Unable to pause printer %s - %s\n",
1502 lp_printername(snum),
1503 ippErrorString(cupsLastError())));
1506 out:
1507 if (response)
1508 ippDelete(response);
1510 if (language)
1511 cupsLangFree(language);
1513 if (http)
1514 httpClose(http);
1516 TALLOC_FREE(frame);
1517 return ret;
1522 * 'cups_queue_resume()' - Restart a print queue.
1525 static int cups_queue_resume(int snum)
1527 TALLOC_CTX *frame = talloc_stackframe();
1528 int ret = 1; /* Return value */
1529 http_t *http = NULL; /* HTTP connection to server */
1530 ipp_t *request = NULL, /* IPP Request */
1531 *response = NULL; /* IPP Response */
1532 cups_lang_t *language = NULL; /* Default language */
1533 char *printername = NULL;
1534 char *username = NULL;
1535 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
1536 size_t size;
1538 DEBUG(5,("cups_queue_resume(%d)\n", snum));
1541 * Make sure we don't ask for passwords...
1544 cupsSetPasswordCB(cups_passwd_cb);
1547 * Try to connect to the server...
1550 if ((http = cups_connect(frame)) == NULL) {
1551 goto out;
1555 * Build an IPP_RESUME_PRINTER request, which requires the following
1556 * attributes:
1558 * attributes-charset
1559 * attributes-natural-language
1560 * printer-uri
1561 * requesting-user-name
1564 request = ippNew();
1566 request->request.op.operation_id = IPP_RESUME_PRINTER;
1567 request->request.op.request_id = 1;
1569 language = cupsLangDefault();
1571 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1572 "attributes-charset", NULL, "utf-8");
1574 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1575 "attributes-natural-language", NULL, language->language);
1577 if (!push_utf8_talloc(frame, &printername, lp_printername(snum),
1578 &size)) {
1579 goto out;
1581 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
1582 printername);
1584 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
1586 if (!push_utf8_talloc(frame, &username, current_user_info.unix_name, &size)) {
1587 goto out;
1589 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
1590 NULL, username);
1593 * Do the request and get back a response...
1596 if ((response = cupsDoRequest(http, request, "/admin/")) != NULL) {
1597 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
1598 DEBUG(0,("Unable to resume printer %s - %s\n",
1599 lp_printername(snum),
1600 ippErrorString(cupsLastError())));
1601 } else {
1602 ret = 0;
1604 } else {
1605 DEBUG(0,("Unable to resume printer %s - %s\n",
1606 lp_printername(snum),
1607 ippErrorString(cupsLastError())));
1610 out:
1611 if (response)
1612 ippDelete(response);
1614 if (language)
1615 cupsLangFree(language);
1617 if (http)
1618 httpClose(http);
1620 TALLOC_FREE(frame);
1621 return ret;
1624 /*******************************************************************
1625 * CUPS printing interface definitions...
1626 ******************************************************************/
1628 struct printif cups_printif =
1630 PRINT_CUPS,
1631 cups_queue_get,
1632 cups_queue_pause,
1633 cups_queue_resume,
1634 cups_job_delete,
1635 cups_job_pause,
1636 cups_job_resume,
1637 cups_job_submit,
1640 bool cups_pull_comment_location(TALLOC_CTX *mem_ctx,
1641 const char *printername,
1642 char **comment,
1643 char **location)
1645 TALLOC_CTX *frame = talloc_stackframe();
1646 http_t *http = NULL; /* HTTP connection to server */
1647 ipp_t *request = NULL, /* IPP Request */
1648 *response = NULL; /* IPP Response */
1649 ipp_attribute_t *attr; /* Current attribute */
1650 cups_lang_t *language = NULL; /* Default language */
1651 char uri[HTTP_MAX_URI];
1652 char *server = NULL;
1653 char *sharename = NULL;
1654 char *name = NULL;
1655 static const char *requested[] =/* Requested attributes */
1657 "printer-name",
1658 "printer-info",
1659 "printer-location"
1661 bool ret = False;
1662 size_t size;
1664 DEBUG(5, ("pulling %s location\n", printername));
1667 * Make sure we don't ask for passwords...
1670 cupsSetPasswordCB(cups_passwd_cb);
1673 * Try to connect to the server...
1676 if ((http = cups_connect(frame)) == NULL) {
1677 goto out;
1680 request = ippNew();
1682 request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
1683 request->request.op.request_id = 1;
1685 language = cupsLangDefault();
1687 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1688 "attributes-charset", NULL, "utf-8");
1690 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1691 "attributes-natural-language", NULL, language->language);
1693 if (lp_cups_server() != NULL && strlen(lp_cups_server()) > 0) {
1694 if (!push_utf8_talloc(frame, &server, lp_cups_server(), &size)) {
1695 goto out;
1697 } else {
1698 server = talloc_strdup(frame,cupsServer());
1700 if (server) {
1701 goto out;
1703 if (!push_utf8_talloc(frame, &sharename, printername, &size)) {
1704 goto out;
1706 slprintf(uri, sizeof(uri) - 1, "ipp://%s/printers/%s",
1707 server, sharename);
1709 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
1710 "printer-uri", NULL, uri);
1712 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
1713 "requested-attributes",
1714 (sizeof(requested) / sizeof(requested[0])),
1715 NULL, requested);
1718 * Do the request and get back a response...
1721 if ((response = cupsDoRequest(http, request, "/")) == NULL) {
1722 DEBUG(0,("Unable to get printer attributes - %s\n",
1723 ippErrorString(cupsLastError())));
1724 goto out;
1727 for (attr = response->attrs; attr != NULL;) {
1729 * Skip leading attributes until we hit a printer...
1732 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
1733 attr = attr->next;
1735 if (attr == NULL)
1736 break;
1739 * Pull the needed attributes from this printer...
1742 while ( attr && (attr->group_tag == IPP_TAG_PRINTER) ) {
1743 if (strcmp(attr->name, "printer-name") == 0 &&
1744 attr->value_tag == IPP_TAG_NAME) {
1745 if (!pull_utf8_talloc(frame,
1746 &name,
1747 attr->values[0].string.text,
1748 &size)) {
1749 goto out;
1753 /* Grab the comment if we don't have one */
1754 if ( (strcmp(attr->name, "printer-info") == 0)
1755 && (attr->value_tag == IPP_TAG_TEXT))
1757 if (!pull_utf8_talloc(mem_ctx,
1758 comment,
1759 attr->values[0].string.text,
1760 &size)) {
1761 goto out;
1763 DEBUG(5,("cups_pull_comment_location: Using cups comment: %s\n",
1764 *comment));
1767 /* Grab the location if we don't have one */
1768 if ( (strcmp(attr->name, "printer-location") == 0)
1769 && (attr->value_tag == IPP_TAG_TEXT))
1771 if (!pull_utf8_talloc(mem_ctx,
1772 location,
1773 attr->values[0].string.text,
1774 &size)) {
1775 goto out;
1777 DEBUG(5,("cups_pull_comment_location: Using cups location: %s\n",
1778 *location));
1781 attr = attr->next;
1785 * We have everything needed...
1788 if (name != NULL)
1789 break;
1792 ret = True;
1794 out:
1795 if (response)
1796 ippDelete(response);
1798 if (request) {
1799 ippDelete(request);
1802 if (language)
1803 cupsLangFree(language);
1805 if (http)
1806 httpClose(http);
1808 TALLOC_FREE(frame);
1809 return ret;
1812 #else
1813 /* this keeps fussy compilers happy */
1814 void print_cups_dummy(void);
1815 void print_cups_dummy(void) {}
1816 #endif /* HAVE_CUPS */