Changeset 228 for branches/samba-3.2.x/source/printing/print_cups.c
- Timestamp:
- May 26, 2009, 9:44:50 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/samba-3.2.x/source/printing/print_cups.c
r133 r228 3 3 * 4 4 * Copyright 1999-2003 by Michael R Sweet. 5 * Copyright 2008 Jeremy Allison. 5 6 * 6 7 * This program is free software; you can redistribute it and/or modify … … 8 9 * the Free Software Foundation; either version 3 of the License, or 9 10 * (at your option) any later version. 10 * 11 * 11 12 * This program is distributed in the hope that it will be useful, 12 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 15 * GNU General Public License for more details. 15 * 16 * 16 17 * You should have received a copy of the GNU General Public License 17 18 * along with this program; if not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 /* 22 * JRA. Converted to utf8 pull/push. 18 23 */ 19 24 … … 41 46 } 42 47 43 static http_t *cups_connect( void)48 static http_t *cups_connect(TALLOC_CTX *frame) 44 49 { 45 http_t *http ;46 char *server , *p;50 http_t *http = NULL; 51 char *server = NULL, *p = NULL; 47 52 int port; 48 53 49 54 if (lp_cups_server() != NULL && strlen(lp_cups_server()) > 0) { 50 server = smb_xstrdup(lp_cups_server()); 55 if (push_utf8_talloc(frame, &server, lp_cups_server()) == (size_t)-1) { 56 return NULL; 57 } 51 58 } else { 52 server = smb_xstrdup(cupsServer()); 59 server = talloc_strdup(frame,cupsServer()); 60 } 61 if (!server) { 62 return NULL; 53 63 } 54 64 … … 60 70 port = ippPort(); 61 71 } 62 72 63 73 DEBUG(10, ("connecting to cups server %s:%d\n", 64 74 server, port)); 65 75 66 76 if ((http = httpConnect(server, port)) == NULL) { 67 DEBUG(0,("Unable to connect to CUPS server %s:%d - %s\n", 77 DEBUG(0,("Unable to connect to CUPS server %s:%d - %s\n", 68 78 server, port, strerror(errno))); 69 SAFE_FREE(server);70 79 return NULL; 71 80 } 72 81 73 SAFE_FREE(server);74 82 return http; 75 83 } 76 84 77 bool cups_cache_reload(void)85 static void send_pcap_info(const char *name, const char *info, void *pd) 78 86 { 87 int fd = *(int *)pd; 88 size_t namelen = name ? strlen(name)+1 : 0; 89 size_t infolen = info ? strlen(info)+1 : 0; 90 91 DEBUG(11,("send_pcap_info: writing namelen %u\n", (unsigned int)namelen)); 92 if (sys_write(fd, &namelen, sizeof(namelen)) != sizeof(namelen)) { 93 DEBUG(10,("send_pcap_info: namelen write failed %s\n", 94 strerror(errno))); 95 return; 96 } 97 DEBUG(11,("send_pcap_info: writing infolen %u\n", (unsigned int)infolen)); 98 if (sys_write(fd, &infolen, sizeof(infolen)) != sizeof(infolen)) { 99 DEBUG(10,("send_pcap_info: infolen write failed %s\n", 100 strerror(errno))); 101 return; 102 } 103 if (namelen) { 104 DEBUG(11,("send_pcap_info: writing name %s\n", name)); 105 if (sys_write(fd, name, namelen) != namelen) { 106 DEBUG(10,("send_pcap_info: name write failed %s\n", 107 strerror(errno))); 108 return; 109 } 110 } 111 if (infolen) { 112 DEBUG(11,("send_pcap_info: writing info %s\n", info)); 113 if (sys_write(fd, info, infolen) != infolen) { 114 DEBUG(10,("send_pcap_info: info write failed %s\n", 115 strerror(errno))); 116 return; 117 } 118 } 119 } 120 121 static bool cups_cache_reload_async(int fd) 122 { 123 TALLOC_CTX *frame = talloc_stackframe(); 124 struct pcap_cache *tmp_pcap_cache = NULL; 79 125 http_t *http = NULL; /* HTTP connection to server */ 80 126 ipp_t *request = NULL, /* IPP Request */ … … 88 134 "printer-name", 89 135 "printer-info" 90 }; 136 }; 91 137 bool ret = False; 92 138 … … 103 149 */ 104 150 105 if ((http = cups_connect( )) == NULL) {151 if ((http = cups_connect(frame)) == NULL) { 106 152 goto out; 107 153 } … … 124 170 125 171 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, 126 "attributes-charset", NULL, cupsLangEncoding(language));172 "attributes-charset", NULL, "utf-8"); 127 173 128 174 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, … … 164 210 while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) { 165 211 if (strcmp(attr->name, "printer-name") == 0 && 166 attr->value_tag == IPP_TAG_NAME) 167 name = attr->values[0].string.text; 212 attr->value_tag == IPP_TAG_NAME) { 213 pull_utf8_talloc(frame, 214 &name, 215 attr->values[0].string.text); 216 } 168 217 169 218 if (strcmp(attr->name, "printer-info") == 0 && 170 attr->value_tag == IPP_TAG_TEXT) 171 info = attr->values[0].string.text; 219 attr->value_tag == IPP_TAG_TEXT) { 220 pull_utf8_talloc(frame, 221 &info, 222 attr->values[0].string.text); 223 } 172 224 173 225 attr = attr->next; … … 181 233 break; 182 234 183 if (!pcap_cache_add (name, info)) {235 if (!pcap_cache_add_specific(&tmp_pcap_cache, name, info)) { 184 236 goto out; 185 237 } … … 204 256 205 257 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, 206 "attributes-charset", NULL, cupsLangEncoding(language));258 "attributes-charset", NULL, "utf-8"); 207 259 208 260 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, … … 244 296 while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) { 245 297 if (strcmp(attr->name, "printer-name") == 0 && 246 attr->value_tag == IPP_TAG_NAME) 247 name = attr->values[0].string.text; 298 attr->value_tag == IPP_TAG_NAME) { 299 pull_utf8_talloc(frame, 300 &name, 301 attr->values[0].string.text); 302 } 248 303 249 304 if (strcmp(attr->name, "printer-info") == 0 && 250 attr->value_tag == IPP_TAG_TEXT) 251 info = attr->values[0].string.text; 305 attr->value_tag == IPP_TAG_TEXT) { 306 pull_utf8_talloc(frame, 307 &info, 308 attr->values[0].string.text); 309 } 252 310 253 311 attr = attr->next; … … 261 319 break; 262 320 263 if (!pcap_cache_add (name, info)) {321 if (!pcap_cache_add_specific(&tmp_pcap_cache, name, info)) { 264 322 goto out; 265 323 } … … 278 336 httpClose(http); 279 337 338 /* Send all the entries up the pipe. */ 339 if (tmp_pcap_cache) { 340 pcap_printer_fn_specific(tmp_pcap_cache, 341 send_pcap_info, 342 (void *)&fd); 343 344 pcap_cache_destroy_specific(&tmp_pcap_cache); 345 } 346 TALLOC_FREE(frame); 280 347 return ret; 281 348 } 282 349 350 static struct pcap_cache *local_pcap_copy; 351 struct fd_event *cache_fd_event; 352 353 static bool cups_pcap_load_async(int *pfd) 354 { 355 int fds[2]; 356 pid_t pid; 357 358 *pfd = -1; 359 360 if (cache_fd_event) { 361 DEBUG(3,("cups_pcap_load_async: already waiting for " 362 "a refresh event\n" )); 363 return false; 364 } 365 366 DEBUG(5,("cups_pcap_load_async: asynchronously loading cups printers\n")); 367 368 if (pipe(fds) == -1) { 369 return false; 370 } 371 372 pid = sys_fork(); 373 if (pid == (pid_t)-1) { 374 DEBUG(10,("cups_pcap_load_async: fork failed %s\n", 375 strerror(errno) )); 376 close(fds[0]); 377 close(fds[1]); 378 return false; 379 } 380 381 if (pid) { 382 DEBUG(10,("cups_pcap_load_async: child pid = %u\n", 383 (unsigned int)pid )); 384 /* Parent. */ 385 close(fds[1]); 386 *pfd = fds[0]; 387 return true; 388 } 389 390 /* Child. */ 391 if (!reinit_after_fork(smbd_messaging_context(), true)) { 392 DEBUG(0,("cups_pcap_load_async: reinit_after_fork() failed\n")); 393 smb_panic("cups_pcap_load_async: reinit_after_fork() failed"); 394 } 395 396 close(fds[0]); 397 cups_cache_reload_async(fds[1]); 398 close(fds[1]); 399 _exit(0); 400 } 401 402 static void cups_async_callback(struct event_context *event_ctx, 403 struct fd_event *event, 404 uint16 flags, 405 void *p) 406 { 407 TALLOC_CTX *frame = talloc_stackframe(); 408 int fd = *(int *)p; 409 struct pcap_cache *tmp_pcap_cache = NULL; 410 411 DEBUG(5,("cups_async_callback: callback received for printer data. " 412 "fd = %d\n", fd)); 413 414 while (1) { 415 char *name = NULL, *info = NULL; 416 size_t namelen = 0, infolen = 0; 417 ssize_t ret = -1; 418 419 ret = sys_read(fd, &namelen, sizeof(namelen)); 420 if (ret == 0) { 421 /* EOF */ 422 break; 423 } 424 if (ret != sizeof(namelen)) { 425 DEBUG(10,("cups_async_callback: namelen read failed %d %s\n", 426 errno, strerror(errno))); 427 break; 428 } 429 430 DEBUG(11,("cups_async_callback: read namelen %u\n", 431 (unsigned int)namelen)); 432 433 ret = sys_read(fd, &infolen, sizeof(infolen)); 434 if (ret == 0) { 435 /* EOF */ 436 break; 437 } 438 if (ret != sizeof(infolen)) { 439 DEBUG(10,("cups_async_callback: infolen read failed %s\n", 440 strerror(errno))); 441 break; 442 } 443 444 DEBUG(11,("cups_async_callback: read infolen %u\n", 445 (unsigned int)infolen)); 446 447 if (namelen) { 448 name = TALLOC_ARRAY(frame, char, namelen); 449 if (!name) { 450 break; 451 } 452 ret = sys_read(fd, name, namelen); 453 if (ret == 0) { 454 /* EOF */ 455 break; 456 } 457 if (ret != namelen) { 458 DEBUG(10,("cups_async_callback: name read failed %s\n", 459 strerror(errno))); 460 break; 461 } 462 DEBUG(11,("cups_async_callback: read name %s\n", 463 name)); 464 } else { 465 name = NULL; 466 } 467 if (infolen) { 468 info = TALLOC_ARRAY(frame, char, infolen); 469 if (!info) { 470 break; 471 } 472 ret = sys_read(fd, info, infolen); 473 if (ret == 0) { 474 /* EOF */ 475 break; 476 } 477 if (ret != infolen) { 478 DEBUG(10,("cups_async_callback: info read failed %s\n", 479 strerror(errno))); 480 break; 481 } 482 DEBUG(11,("cups_async_callback: read info %s\n", 483 info)); 484 } else { 485 info = NULL; 486 } 487 488 /* Add to our local pcap cache. */ 489 pcap_cache_add_specific(&tmp_pcap_cache, name, info); 490 TALLOC_FREE(name); 491 TALLOC_FREE(info); 492 } 493 494 TALLOC_FREE(frame); 495 if (tmp_pcap_cache) { 496 /* We got a namelist, replace our local cache. */ 497 pcap_cache_destroy_specific(&local_pcap_copy); 498 local_pcap_copy = tmp_pcap_cache; 499 500 /* And the systemwide pcap cache. */ 501 pcap_cache_replace(local_pcap_copy); 502 } else { 503 DEBUG(2,("cups_async_callback: failed to read a new " 504 "printer list\n")); 505 } 506 close(fd); 507 TALLOC_FREE(p); 508 TALLOC_FREE(cache_fd_event); 509 } 510 511 bool cups_cache_reload(void) 512 { 513 int *p_pipe_fd = TALLOC_P(NULL, int); 514 515 if (!p_pipe_fd) { 516 return false; 517 } 518 519 *p_pipe_fd = -1; 520 521 /* Set up an async refresh. */ 522 if (!cups_pcap_load_async(p_pipe_fd)) { 523 return false; 524 } 525 if (!local_pcap_copy) { 526 /* We have no local cache, wait directly for 527 * async refresh to complete. 528 */ 529 DEBUG(10,("cups_cache_reload: sync read on fd %d\n", 530 *p_pipe_fd )); 531 532 cups_async_callback(smbd_event_context(), 533 NULL, 534 EVENT_FD_READ, 535 (void *)p_pipe_fd); 536 if (!local_pcap_copy) { 537 return false; 538 } 539 } else { 540 /* Replace the system cache with our 541 * local copy. */ 542 pcap_cache_replace(local_pcap_copy); 543 544 DEBUG(10,("cups_cache_reload: async read on fd %d\n", 545 *p_pipe_fd )); 546 547 /* Trigger an event when the pipe can be read. */ 548 cache_fd_event = event_add_fd(smbd_event_context(), 549 NULL, *p_pipe_fd, 550 EVENT_FD_READ, 551 cups_async_callback, 552 (void *)p_pipe_fd); 553 if (!cache_fd_event) { 554 close(*p_pipe_fd); 555 TALLOC_FREE(p_pipe_fd); 556 return false; 557 } 558 } 559 return true; 560 } 283 561 284 562 /* … … 288 566 static int cups_job_delete(const char *sharename, const char *lprm_command, struct printjob *pjob) 289 567 { 568 TALLOC_CTX *frame = talloc_stackframe(); 290 569 int ret = 1; /* Return value */ 291 570 http_t *http = NULL; /* HTTP connection to server */ … … 293 572 *response = NULL; /* IPP Response */ 294 573 cups_lang_t *language = NULL; /* Default language */ 574 char *user = NULL; 295 575 char uri[HTTP_MAX_URI]; /* printer-uri attribute */ 296 576 … … 308 588 */ 309 589 310 if ((http = cups_connect( )) == NULL) {590 if ((http = cups_connect(frame)) == NULL) { 311 591 goto out; 312 592 } … … 330 610 331 611 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, 332 "attributes-charset", NULL, cupsLangEncoding(language));612 "attributes-charset", NULL, "utf-8"); 333 613 334 614 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, … … 339 619 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri); 340 620 621 if (push_utf8_talloc(frame, &user, pjob->user) == (size_t)-1) { 622 goto out; 623 } 624 341 625 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", 342 NULL, pjob->user);626 NULL, user); 343 627 344 628 /* … … 368 652 httpClose(http); 369 653 654 TALLOC_FREE(frame); 370 655 return ret; 371 656 } … … 378 663 static int cups_job_pause(int snum, struct printjob *pjob) 379 664 { 665 TALLOC_CTX *frame = talloc_stackframe(); 380 666 int ret = 1; /* Return value */ 381 667 http_t *http = NULL; /* HTTP connection to server */ … … 383 669 *response = NULL; /* IPP Response */ 384 670 cups_lang_t *language = NULL; /* Default language */ 671 char *user = NULL; 385 672 char uri[HTTP_MAX_URI]; /* printer-uri attribute */ 386 673 … … 398 685 */ 399 686 400 if ((http = cups_connect( )) == NULL) {687 if ((http = cups_connect(frame)) == NULL) { 401 688 goto out; 402 689 } … … 420 707 421 708 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, 422 "attributes-charset", NULL, cupsLangEncoding(language));709 "attributes-charset", NULL, "utf-8"); 423 710 424 711 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, … … 429 716 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri); 430 717 718 if (push_utf8_talloc(frame, &user, pjob->user) == (size_t)-1) { 719 goto out; 720 } 431 721 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", 432 NULL, pjob->user);722 NULL, user); 433 723 434 724 /* … … 458 748 httpClose(http); 459 749 750 TALLOC_FREE(frame); 460 751 return ret; 461 752 } … … 468 759 static int cups_job_resume(int snum, struct printjob *pjob) 469 760 { 761 TALLOC_CTX *frame = talloc_stackframe(); 470 762 int ret = 1; /* Return value */ 471 763 http_t *http = NULL; /* HTTP connection to server */ … … 473 765 *response = NULL; /* IPP Response */ 474 766 cups_lang_t *language = NULL; /* Default language */ 767 char *user = NULL; 475 768 char uri[HTTP_MAX_URI]; /* printer-uri attribute */ 476 769 … … 488 781 */ 489 782 490 if ((http = cups_connect( )) == NULL) {783 if ((http = cups_connect(frame)) == NULL) { 491 784 goto out; 492 785 } … … 510 803 511 804 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, 512 "attributes-charset", NULL, cupsLangEncoding(language));805 "attributes-charset", NULL, "utf-8"); 513 806 514 807 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, … … 519 812 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri); 520 813 814 if (push_utf8_talloc(frame, &user, pjob->user) == (size_t)-1) { 815 goto out; 816 } 521 817 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", 522 NULL, pjob->user);818 NULL, user); 523 819 524 820 /* … … 548 844 httpClose(http); 549 845 846 TALLOC_FREE(frame); 550 847 return ret; 551 848 } … … 558 855 static int cups_job_submit(int snum, struct printjob *pjob) 559 856 { 857 TALLOC_CTX *frame = talloc_stackframe(); 560 858 int ret = 1; /* Return value */ 561 859 http_t *http = NULL; /* HTTP connection to server */ … … 568 866 int num_options = 0; 569 867 cups_option_t *options = NULL; 868 char *printername = NULL; 869 char *user = NULL; 870 char *jobname = NULL; 871 char *cupsoptions = NULL; 872 char *filename = NULL; 570 873 char addr[INET6_ADDRSTRLEN]; 571 874 … … 582 885 */ 583 886 584 if ((http = cups_connect( )) == NULL) {887 if ((http = cups_connect(frame)) == NULL) { 585 888 goto out; 586 889 } … … 605 908 606 909 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, 607 "attributes-charset", NULL, cupsLangEncoding(language));910 "attributes-charset", NULL, "utf-8"); 608 911 609 912 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, 610 913 "attributes-natural-language", NULL, language->language); 611 914 915 if (push_utf8_talloc(frame, &printername, PRINTERNAME(snum)) == (size_t)-1) { 916 goto out; 917 } 612 918 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s", 613 PRINTERNAME(snum));919 printername); 614 920 615 921 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, 616 922 "printer-uri", NULL, uri); 617 923 924 if (push_utf8_talloc(frame, &user, pjob->user) == (size_t)-1) { 925 goto out; 926 } 618 927 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", 619 NULL, pjob->user);928 NULL, user); 620 929 621 930 clientname = client_name(get_client_fd()); … … 628 937 clientname); 629 938 630 if (asprintf(&new_jobname,"%s%.8u %s", PRINT_SPOOL_PREFIX, 631 (unsigned int)pjob->smbjob, pjob->jobname) < 0) { 939 if (push_utf8_talloc(frame, &jobname, pjob->jobname) == (size_t)-1) { 940 goto out; 941 } 942 new_jobname = talloc_asprintf(frame, 943 "%s%.8u %s", PRINT_SPOOL_PREFIX, 944 (unsigned int)pjob->smbjob, 945 jobname); 946 if (new_jobname == NULL) { 632 947 goto out; 633 948 } … … 636 951 new_jobname); 637 952 638 /* 639 * add any options defined in smb.conf 953 /* 954 * add any options defined in smb.conf 640 955 */ 641 956 957 if (push_utf8_talloc(frame, &cupsoptions, lp_cups_options(snum)) == (size_t)-1) { 958 goto out; 959 } 642 960 num_options = 0; 643 961 options = NULL; 644 num_options = cupsParseOptions( lp_cups_options(snum), num_options, &options);962 num_options = cupsParseOptions(cupsoptions, num_options, &options); 645 963 646 964 if ( num_options ) 647 cupsEncodeOptions(request, num_options, options); 965 cupsEncodeOptions(request, num_options, options); 648 966 649 967 /* … … 651 969 */ 652 970 653 slprintf(uri, sizeof(uri) - 1, "/printers/%s", PRINTERNAME(snum)); 654 971 slprintf(uri, sizeof(uri) - 1, "/printers/%s", printername); 972 973 if (push_utf8_talloc(frame, &filename, pjob->filename) == (size_t)-1) { 974 goto out; 975 } 655 976 if ((response = cupsDoFileRequest(http, request, uri, pjob->filename)) != NULL) { 656 977 if (response->request.status.status_code >= IPP_OK_CONFLICT) { … … 679 1000 httpClose(http); 680 1001 681 SAFE_FREE(new_jobname);1002 TALLOC_FREE(frame); 682 1003 683 1004 return ret; … … 691 1012 enum printing_types printing_type, 692 1013 char *lpq_command, 693 print_queue_struct **q, 1014 print_queue_struct **q, 694 1015 print_status_struct *status) 695 1016 { 696 fstring printername; 1017 TALLOC_CTX *frame = talloc_stackframe(); 1018 char *printername = NULL; 697 1019 http_t *http = NULL; /* HTTP connection to server */ 698 1020 ipp_t *request = NULL, /* IPP Request */ … … 705 1027 print_queue_struct *queue = NULL, /* Queue entries */ 706 1028 *temp; /* Temporary pointer for queue */ 707 c onst char *user_name, /* job-originating-user-name attribute */708 *job_name ; /* job-name attribute */1029 char *user_name = NULL, /* job-originating-user-name attribute */ 1030 *job_name = NULL; /* job-name attribute */ 709 1031 int job_id; /* job-id attribute */ 710 1032 int job_k_octets; /* job-k-octets attribute */ … … 730 1052 *q = NULL; 731 1053 732 /* HACK ALERT!!! The problem with support the 'printer name' 733 option is that we key the tdb off the sharename. So we will 734 overload the lpq_command string to pass in the printername 735 (which is basically what we do for non-cups printers ... using 1054 /* HACK ALERT!!! The problem with support the 'printer name' 1055 option is that we key the tdb off the sharename. So we will 1056 overload the lpq_command string to pass in the printername 1057 (which is basically what we do for non-cups printers ... using 736 1058 the lpq_command to get the queue listing). */ 737 1059 738 fstrcpy( printername, lpq_command ); 739 740 DEBUG(5,("cups_queue_get(%s, %p, %p)\n", printername, q, status)); 1060 if (push_utf8_talloc(frame, &printername, lpq_command) == (size_t)-1) { 1061 goto out; 1062 } 1063 DEBUG(5,("cups_queue_get(%s, %p, %p)\n", lpq_command, q, status)); 741 1064 742 1065 /* … … 750 1073 */ 751 1074 752 if ((http = cups_connect( )) == NULL) {1075 if ((http = cups_connect(frame)) == NULL) { 753 1076 goto out; 754 1077 } … … 778 1101 779 1102 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, 780 "attributes-charset", NULL, cupsLangEncoding(language));1103 "attributes-charset", NULL, "utf-8"); 781 1104 782 1105 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, … … 883 1206 884 1207 if (strcmp(attr->name, "job-name") == 0 && 885 attr->value_tag == IPP_TAG_NAME) 886 job_name = attr->values[0].string.text; 1208 attr->value_tag == IPP_TAG_NAME) { 1209 pull_utf8_talloc(frame, 1210 &job_name, 1211 attr->values[0].string.text); 1212 } 887 1213 888 1214 if (strcmp(attr->name, "job-originating-user-name") == 0 && 889 attr->value_tag == IPP_TAG_NAME) 890 user_name = attr->values[0].string.text; 1215 attr->value_tag == IPP_TAG_NAME) { 1216 pull_utf8_talloc(frame, 1217 &user_name, 1218 attr->values[0].string.text); 1219 } 891 1220 892 1221 attr = attr->next; … … 912 1241 temp->priority = job_priority; 913 1242 temp->time = job_time; 914 str ncpy(temp->fs_user, user_name, sizeof(temp->fs_user) - 1);915 str ncpy(temp->fs_file, job_name, sizeof(temp->fs_file) - 1);1243 strlcpy(temp->fs_user, user_name, sizeof(temp->fs_user)); 1244 strlcpy(temp->fs_file, job_name, sizeof(temp->fs_file)); 916 1245 917 1246 qcount ++; … … 940 1269 941 1270 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, 942 "attributes-charset", NULL, cupsLangEncoding(language));1271 "attributes-charset", NULL, "utf-8"); 943 1272 944 1273 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, … … 983 1312 984 1313 if ((attr = ippFindAttribute(response, "printer-state-message", 985 IPP_TAG_TEXT)) != NULL) 986 fstrcpy(status->message, attr->values[0].string.text); 1314 IPP_TAG_TEXT)) != NULL) { 1315 char *msg = NULL; 1316 pull_utf8_talloc(frame, &msg, attr->values[0].string.text); 1317 fstrcpy(status->message, msg); 1318 } 987 1319 988 1320 /* … … 1002 1334 httpClose(http); 1003 1335 1336 TALLOC_FREE(frame); 1004 1337 return qcount; 1005 1338 } … … 1012 1345 static int cups_queue_pause(int snum) 1013 1346 { 1347 TALLOC_CTX *frame = talloc_stackframe(); 1014 1348 int ret = 1; /* Return value */ 1015 1349 http_t *http = NULL; /* HTTP connection to server */ … … 1017 1351 *response = NULL; /* IPP Response */ 1018 1352 cups_lang_t *language = NULL; /* Default language */ 1353 char *printername = NULL; 1354 char *username = NULL; 1019 1355 char uri[HTTP_MAX_URI]; /* printer-uri attribute */ 1020 1356 … … 1032 1368 */ 1033 1369 1034 if ((http = cups_connect( )) == NULL) {1370 if ((http = cups_connect(frame)) == NULL) { 1035 1371 goto out; 1036 1372 } … … 1054 1390 1055 1391 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, 1056 "attributes-charset", NULL, cupsLangEncoding(language));1392 "attributes-charset", NULL, "utf-8"); 1057 1393 1058 1394 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, 1059 1395 "attributes-natural-language", NULL, language->language); 1060 1396 1397 if (push_utf8_talloc(frame, &printername, PRINTERNAME(snum)) == (size_t)-1) { 1398 goto out; 1399 } 1061 1400 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s", 1062 PRINTERNAME(snum));1401 printername); 1063 1402 1064 1403 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri); 1065 1404 1405 if (push_utf8_talloc(frame, &username, current_user_info.unix_name) == (size_t)-1) { 1406 goto out; 1407 } 1066 1408 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", 1067 NULL, current_user_info.unix_name);1409 NULL, username); 1068 1410 1069 1411 /* … … 1093 1435 httpClose(http); 1094 1436 1437 TALLOC_FREE(frame); 1095 1438 return ret; 1096 1439 } … … 1103 1446 static int cups_queue_resume(int snum) 1104 1447 { 1448 TALLOC_CTX *frame = talloc_stackframe(); 1105 1449 int ret = 1; /* Return value */ 1106 1450 http_t *http = NULL; /* HTTP connection to server */ … … 1108 1452 *response = NULL; /* IPP Response */ 1109 1453 cups_lang_t *language = NULL; /* Default language */ 1454 char *printername = NULL; 1455 char *username = NULL; 1110 1456 char uri[HTTP_MAX_URI]; /* printer-uri attribute */ 1111 1457 … … 1123 1469 */ 1124 1470 1125 if ((http = cups_connect( )) == NULL) {1471 if ((http = cups_connect(frame)) == NULL) { 1126 1472 goto out; 1127 1473 } … … 1145 1491 1146 1492 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, 1147 "attributes-charset", NULL, cupsLangEncoding(language));1493 "attributes-charset", NULL, "utf-8"); 1148 1494 1149 1495 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, 1150 1496 "attributes-natural-language", NULL, language->language); 1151 1497 1498 if (push_utf8_talloc(frame, &printername, PRINTERNAME(snum)) == (size_t)-1) { 1499 goto out; 1500 } 1152 1501 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s", 1153 PRINTERNAME(snum));1502 printername); 1154 1503 1155 1504 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri); 1156 1505 1506 if (push_utf8_talloc(frame, &username, current_user_info.unix_name) == (size_t)-1) { 1507 goto out; 1508 } 1157 1509 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", 1158 NULL, current_user_info.unix_name);1510 NULL, username); 1159 1511 1160 1512 /* … … 1184 1536 httpClose(http); 1185 1537 1538 TALLOC_FREE(frame); 1186 1539 return ret; 1187 1540 } … … 1205 1558 bool cups_pull_comment_location(NT_PRINTER_INFO_LEVEL_2 *printer) 1206 1559 { 1560 TALLOC_CTX *frame = talloc_stackframe(); 1207 1561 http_t *http = NULL; /* HTTP connection to server */ 1208 1562 ipp_t *request = NULL, /* IPP Request */ … … 1210 1564 ipp_attribute_t *attr; /* Current attribute */ 1211 1565 cups_lang_t *language = NULL; /* Default language */ 1212 char *name, /* printer-name attribute */1213 *info, /* printer-info attribute */1214 *location; /* printer-location attribute */1215 1566 char uri[HTTP_MAX_URI]; 1567 char *server = NULL; 1568 char *sharename = NULL; 1569 char *name = NULL; 1216 1570 static const char *requested[] =/* Requested attributes */ 1217 1571 { … … 1234 1588 */ 1235 1589 1236 if ((http = cups_connect( )) == NULL) {1590 if ((http = cups_connect(frame)) == NULL) { 1237 1591 goto out; 1238 1592 } … … 1246 1600 1247 1601 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, 1248 "attributes-charset", NULL, cupsLangEncoding(language));1602 "attributes-charset", NULL, "utf-8"); 1249 1603 1250 1604 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, 1251 1605 "attributes-natural-language", NULL, language->language); 1252 1606 1607 if (lp_cups_server() != NULL && strlen(lp_cups_server()) > 0) { 1608 if (push_utf8_talloc(frame, &server, lp_cups_server()) == (size_t)-1) { 1609 goto out; 1610 } 1611 } else { 1612 server = talloc_strdup(frame,cupsServer()); 1613 } 1614 if (server) { 1615 goto out; 1616 } 1617 if (push_utf8_talloc(frame, &sharename, printer->sharename) == (size_t)-1) { 1618 goto out; 1619 } 1253 1620 slprintf(uri, sizeof(uri) - 1, "ipp://%s/printers/%s", 1254 lp_cups_server(), printer->sharename);1621 server, sharename); 1255 1622 1256 1623 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, … … 1287 1654 */ 1288 1655 1289 name = NULL;1290 info = NULL;1291 location = NULL;1292 1293 1656 while ( attr && (attr->group_tag == IPP_TAG_PRINTER) ) { 1657 if (strcmp(attr->name, "printer-name") == 0 && 1658 attr->value_tag == IPP_TAG_NAME) { 1659 pull_utf8_talloc(frame, 1660 &name, 1661 attr->values[0].string.text); 1662 } 1663 1294 1664 /* Grab the comment if we don't have one */ 1295 1665 if ( (strcmp(attr->name, "printer-info") == 0) 1296 1666 && (attr->value_tag == IPP_TAG_TEXT) 1297 && !strlen(printer->comment) ) 1667 && !strlen(printer->comment) ) 1298 1668 { 1669 char *comment = NULL; 1670 pull_utf8_talloc(frame, 1671 &comment, 1672 attr->values[0].string.text); 1299 1673 DEBUG(5,("cups_pull_comment_location: Using cups comment: %s\n", 1300 attr->values[0].string.text));1674 comment)); 1301 1675 strlcpy(printer->comment, 1302 attr->values[0].string.text,1303 1676 comment, 1677 sizeof(printer->comment)); 1304 1678 } 1305 1679 1306 /* Grab the location if we don't have one */ 1680 /* Grab the location if we don't have one */ 1307 1681 if ( (strcmp(attr->name, "printer-location") == 0) 1308 && (attr->value_tag == IPP_TAG_TEXT) 1682 && (attr->value_tag == IPP_TAG_TEXT) 1309 1683 && !strlen(printer->location) ) 1310 1684 { 1685 char *location = NULL; 1686 pull_utf8_talloc(frame, 1687 &location, 1688 attr->values[0].string.text); 1311 1689 DEBUG(5,("cups_pull_comment_location: Using cups location: %s\n", 1312 attr->values[0].string.text)); 1313 fstrcpy(printer->location,attr->values[0].string.text); 1690 location)); 1691 strlcpy(printer->location, 1692 location, 1693 sizeof(printer->location)); 1314 1694 } 1315 1695 … … 1318 1698 1319 1699 /* 1320 * See if we have everything needed...1700 * We have everything needed... 1321 1701 */ 1322 1702 1323 if (name == NULL)1703 if (name != NULL) 1324 1704 break; 1325 1326 1705 } 1327 1706 … … 1338 1717 httpClose(http); 1339 1718 1719 TALLOC_FREE(frame); 1340 1720 return ret; 1341 1721 }
Note:
See TracChangeset
for help on using the changeset viewer.