Ignore:
Timestamp:
May 26, 2009, 9:44:50 AM (16 years ago)
Author:
Herwig Bauernfeind
Message:

Update 3.2 branch to 3.2.6

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/samba-3.2.x/source/printing/print_cups.c

    r133 r228  
    33 *
    44 * Copyright 1999-2003 by Michael R Sweet.
     5 * Copyright 2008 Jeremy Allison.
    56 *
    67 * This program is free software; you can redistribute it and/or modify
     
    89 * the Free Software Foundation; either version 3 of the License, or
    910 * (at your option) any later version.
    10  * 
     11 *
    1112 * This program is distributed in the hope that it will be useful,
    1213 * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1314 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1415 * GNU General Public License for more details.
    15  * 
     16 *
    1617 * You should have received a copy of the GNU General Public License
    1718 * along with this program; if not, see <http://www.gnu.org/licenses/>.
     19 */
     20
     21/*
     22 * JRA. Converted to utf8 pull/push.
    1823 */
    1924
     
    4146}
    4247
    43 static http_t *cups_connect(void)
     48static http_t *cups_connect(TALLOC_CTX *frame)
    4449{
    45         http_t *http;
    46         char *server, *p;
     50        http_t *http = NULL;
     51        char *server = NULL, *p = NULL;
    4752        int port;
    48        
     53
    4954        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                }
    5158        } else {
    52                 server = smb_xstrdup(cupsServer());
     59                server = talloc_strdup(frame,cupsServer());
     60        }
     61        if (!server) {
     62                return NULL;
    5363        }
    5464
     
    6070                port = ippPort();
    6171        }
    62        
     72
    6373        DEBUG(10, ("connecting to cups server %s:%d\n",
    6474                   server, port));
    6575
    6676        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",
    6878                         server, port, strerror(errno)));
    69                 SAFE_FREE(server);
    7079                return NULL;
    7180        }
    7281
    73         SAFE_FREE(server);
    7482        return http;
    7583}
    7684
    77 bool cups_cache_reload(void)
     85static void send_pcap_info(const char *name, const char *info, void *pd)
    7886{
     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
     121static bool cups_cache_reload_async(int fd)
     122{
     123        TALLOC_CTX *frame = talloc_stackframe();
     124        struct pcap_cache *tmp_pcap_cache = NULL;
    79125        http_t          *http = NULL;           /* HTTP connection to server */
    80126        ipp_t           *request = NULL,        /* IPP Request */
     
    88134                          "printer-name",
    89135                          "printer-info"
    90                         };       
     136                        };
    91137        bool ret = False;
    92138
     
    103149        */
    104150
    105         if ((http = cups_connect()) == NULL) {
     151        if ((http = cups_connect(frame)) == NULL) {
    106152                goto out;
    107153        }
     
    124170
    125171        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
    126                      "attributes-charset", NULL, cupsLangEncoding(language));
     172                     "attributes-charset", NULL, "utf-8");
    127173
    128174        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
     
    164210                while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) {
    165211                        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                        }
    168217
    169218                        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                        }
    172224
    173225                        attr = attr->next;
     
    181233                        break;
    182234
    183                 if (!pcap_cache_add(name, info)) {
     235                if (!pcap_cache_add_specific(&tmp_pcap_cache, name, info)) {
    184236                        goto out;
    185237                }
     
    204256
    205257        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
    206                      "attributes-charset", NULL, cupsLangEncoding(language));
     258                     "attributes-charset", NULL, "utf-8");
    207259
    208260        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
     
    244296                while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) {
    245297                        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                        }
    248303
    249304                        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                        }
    252310
    253311                        attr = attr->next;
     
    261319                        break;
    262320
    263                 if (!pcap_cache_add(name, info)) {
     321                if (!pcap_cache_add_specific(&tmp_pcap_cache, name, info)) {
    264322                        goto out;
    265323                }
     
    278336                httpClose(http);
    279337
     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);
    280347        return ret;
    281348}
    282349
     350static struct pcap_cache *local_pcap_copy;
     351struct fd_event *cache_fd_event;
     352
     353static 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
     402static 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
     511bool 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}
    283561
    284562/*
     
    288566static int cups_job_delete(const char *sharename, const char *lprm_command, struct printjob *pjob)
    289567{
     568        TALLOC_CTX *frame = talloc_stackframe();
    290569        int             ret = 1;                /* Return value */
    291570        http_t          *http = NULL;           /* HTTP connection to server */
     
    293572                        *response = NULL;       /* IPP Response */
    294573        cups_lang_t     *language = NULL;       /* Default language */
     574        char *user = NULL;
    295575        char            uri[HTTP_MAX_URI]; /* printer-uri attribute */
    296576
     
    308588        */
    309589
    310         if ((http = cups_connect()) == NULL) {
     590        if ((http = cups_connect(frame)) == NULL) {
    311591                goto out;
    312592        }
     
    330610
    331611        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
    332                      "attributes-charset", NULL, cupsLangEncoding(language));
     612                     "attributes-charset", NULL, "utf-8");
    333613
    334614        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
     
    339619        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
    340620
     621        if (push_utf8_talloc(frame, &user, pjob->user) == (size_t)-1) {
     622                goto out;
     623        }
     624
    341625        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
    342                      NULL, pjob->user);
     626                     NULL, user);
    343627
    344628       /*
     
    368652                httpClose(http);
    369653
     654        TALLOC_FREE(frame);
    370655        return ret;
    371656}
     
    378663static int cups_job_pause(int snum, struct printjob *pjob)
    379664{
     665        TALLOC_CTX *frame = talloc_stackframe();
    380666        int             ret = 1;                /* Return value */
    381667        http_t          *http = NULL;           /* HTTP connection to server */
     
    383669                        *response = NULL;       /* IPP Response */
    384670        cups_lang_t     *language = NULL;       /* Default language */
     671        char *user = NULL;
    385672        char            uri[HTTP_MAX_URI]; /* printer-uri attribute */
    386673
     
    398685        */
    399686
    400         if ((http = cups_connect()) == NULL) {
     687        if ((http = cups_connect(frame)) == NULL) {
    401688                goto out;
    402689        }
     
    420707
    421708        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
    422                      "attributes-charset", NULL, cupsLangEncoding(language));
     709                     "attributes-charset", NULL, "utf-8");
    423710
    424711        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
     
    429716        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
    430717
     718        if (push_utf8_talloc(frame, &user, pjob->user) == (size_t)-1) {
     719                goto out;
     720        }
    431721        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
    432                      NULL, pjob->user);
     722                     NULL, user);
    433723
    434724       /*
     
    458748                httpClose(http);
    459749
     750        TALLOC_FREE(frame);
    460751        return ret;
    461752}
     
    468759static int cups_job_resume(int snum, struct printjob *pjob)
    469760{
     761        TALLOC_CTX *frame = talloc_stackframe();
    470762        int             ret = 1;                /* Return value */
    471763        http_t          *http = NULL;           /* HTTP connection to server */
     
    473765                        *response = NULL;       /* IPP Response */
    474766        cups_lang_t     *language = NULL;       /* Default language */
     767        char *user = NULL;
    475768        char            uri[HTTP_MAX_URI]; /* printer-uri attribute */
    476769
     
    488781        */
    489782
    490         if ((http = cups_connect()) == NULL) {
     783        if ((http = cups_connect(frame)) == NULL) {
    491784                goto out;
    492785        }
     
    510803
    511804        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
    512                      "attributes-charset", NULL, cupsLangEncoding(language));
     805                     "attributes-charset", NULL, "utf-8");
    513806
    514807        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
     
    519812        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
    520813
     814        if (push_utf8_talloc(frame, &user, pjob->user) == (size_t)-1) {
     815                goto out;
     816        }
    521817        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
    522                      NULL, pjob->user);
     818                     NULL, user);
    523819
    524820       /*
     
    548844                httpClose(http);
    549845
     846        TALLOC_FREE(frame);
    550847        return ret;
    551848}
     
    558855static int cups_job_submit(int snum, struct printjob *pjob)
    559856{
     857        TALLOC_CTX *frame = talloc_stackframe();
    560858        int             ret = 1;                /* Return value */
    561859        http_t          *http = NULL;           /* HTTP connection to server */
     
    568866        int             num_options = 0;
    569867        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;
    570873        char addr[INET6_ADDRSTRLEN];
    571874
     
    582885        */
    583886
    584         if ((http = cups_connect()) == NULL) {
     887        if ((http = cups_connect(frame)) == NULL) {
    585888                goto out;
    586889        }
     
    605908
    606909        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
    607                      "attributes-charset", NULL, cupsLangEncoding(language));
     910                     "attributes-charset", NULL, "utf-8");
    608911
    609912        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
    610913                     "attributes-natural-language", NULL, language->language);
    611914
     915        if (push_utf8_talloc(frame, &printername, PRINTERNAME(snum)) == (size_t)-1) {
     916                goto out;
     917        }
    612918        slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
    613                  PRINTERNAME(snum));
     919                 printername);
    614920
    615921        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
    616922                     "printer-uri", NULL, uri);
    617923
     924        if (push_utf8_talloc(frame, &user, pjob->user) == (size_t)-1) {
     925                goto out;
     926        }
    618927        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
    619                      NULL, pjob->user);
     928                     NULL, user);
    620929
    621930        clientname = client_name(get_client_fd());
     
    628937                      clientname);
    629938
    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) {
    632947                goto out;
    633948        }
     
    636951                     new_jobname);
    637952
    638         /* 
    639          * add any options defined in smb.conf 
     953        /*
     954         * add any options defined in smb.conf
    640955         */
    641956
     957        if (push_utf8_talloc(frame, &cupsoptions, lp_cups_options(snum)) == (size_t)-1) {
     958                goto out;
     959        }
    642960        num_options = 0;
    643961        options     = NULL;
    644         num_options = cupsParseOptions(lp_cups_options(snum), num_options, &options);
     962        num_options = cupsParseOptions(cupsoptions, num_options, &options);
    645963
    646964        if ( num_options )
    647                 cupsEncodeOptions(request, num_options, options); 
     965                cupsEncodeOptions(request, num_options, options);
    648966
    649967       /*
     
    651969        */
    652970
    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        }
    655976        if ((response = cupsDoFileRequest(http, request, uri, pjob->filename)) != NULL) {
    656977                if (response->request.status.status_code >= IPP_OK_CONFLICT) {
     
    6791000                httpClose(http);
    6801001
    681         SAFE_FREE(new_jobname);
     1002        TALLOC_FREE(frame);
    6821003
    6831004        return ret;
     
    6911012               enum printing_types printing_type,
    6921013               char *lpq_command,
    693                print_queue_struct **q, 
     1014               print_queue_struct **q,
    6941015               print_status_struct *status)
    6951016{
    696         fstring         printername;
     1017        TALLOC_CTX *frame = talloc_stackframe();
     1018        char *printername = NULL;
    6971019        http_t          *http = NULL;           /* HTTP connection to server */
    6981020        ipp_t           *request = NULL,        /* IPP Request */
     
    7051027        print_queue_struct *queue = NULL,       /* Queue entries */
    7061028                        *temp;          /* Temporary pointer for queue */
    707         const 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 */
    7091031        int             job_id;         /* job-id attribute */
    7101032        int             job_k_octets;   /* job-k-octets attribute */
     
    7301052        *q = NULL;
    7311053
    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
    7361058           the lpq_command to get the queue listing). */
    7371059
    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));
    7411064
    7421065       /*
     
    7501073        */
    7511074
    752         if ((http = cups_connect()) == NULL) {
     1075        if ((http = cups_connect(frame)) == NULL) {
    7531076                goto out;
    7541077        }
     
    7781101
    7791102        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
    780                      "attributes-charset", NULL, cupsLangEncoding(language));
     1103                     "attributes-charset", NULL, "utf-8");
    7811104
    7821105        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
     
    8831206
    8841207                        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                        }
    8871213
    8881214                        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                        }
    8911220
    8921221                        attr = attr->next;
     
    9121241                temp->priority = job_priority;
    9131242                temp->time     = job_time;
    914                 strncpy(temp->fs_user, user_name, sizeof(temp->fs_user) - 1);
    915                 strncpy(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));
    9161245
    9171246                qcount ++;
     
    9401269
    9411270        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
    942                      "attributes-charset", NULL, cupsLangEncoding(language));
     1271                     "attributes-charset", NULL, "utf-8");
    9431272
    9441273        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
     
    9831312
    9841313        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        }
    9871319
    9881320       /*
     
    10021334                httpClose(http);
    10031335
     1336        TALLOC_FREE(frame);
    10041337        return qcount;
    10051338}
     
    10121345static int cups_queue_pause(int snum)
    10131346{
     1347        TALLOC_CTX *frame = talloc_stackframe();
    10141348        int             ret = 1;                /* Return value */
    10151349        http_t          *http = NULL;           /* HTTP connection to server */
     
    10171351                        *response = NULL;       /* IPP Response */
    10181352        cups_lang_t     *language = NULL;       /* Default language */
     1353        char *printername = NULL;
     1354        char *username = NULL;
    10191355        char            uri[HTTP_MAX_URI]; /* printer-uri attribute */
    10201356
     
    10321368         */
    10331369
    1034         if ((http = cups_connect()) == NULL) {
     1370        if ((http = cups_connect(frame)) == NULL) {
    10351371                goto out;
    10361372        }
     
    10541390
    10551391        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
    1056                      "attributes-charset", NULL, cupsLangEncoding(language));
     1392                     "attributes-charset", NULL, "utf-8");
    10571393
    10581394        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
    10591395                     "attributes-natural-language", NULL, language->language);
    10601396
     1397        if (push_utf8_talloc(frame, &printername, PRINTERNAME(snum)) == (size_t)-1) {
     1398                goto out;
     1399        }
    10611400        slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
    1062                  PRINTERNAME(snum));
     1401                 printername);
    10631402
    10641403        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
    10651404
     1405        if (push_utf8_talloc(frame, &username, current_user_info.unix_name) == (size_t)-1) {
     1406                goto out;
     1407        }
    10661408        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
    1067                      NULL, current_user_info.unix_name);
     1409                     NULL, username);
    10681410
    10691411       /*
     
    10931435                httpClose(http);
    10941436
     1437        TALLOC_FREE(frame);
    10951438        return ret;
    10961439}
     
    11031446static int cups_queue_resume(int snum)
    11041447{
     1448        TALLOC_CTX *frame = talloc_stackframe();
    11051449        int             ret = 1;                /* Return value */
    11061450        http_t          *http = NULL;           /* HTTP connection to server */
     
    11081452                        *response = NULL;       /* IPP Response */
    11091453        cups_lang_t     *language = NULL;       /* Default language */
     1454        char *printername = NULL;
     1455        char *username = NULL;
    11101456        char            uri[HTTP_MAX_URI]; /* printer-uri attribute */
    11111457
     
    11231469        */
    11241470
    1125         if ((http = cups_connect()) == NULL) {
     1471        if ((http = cups_connect(frame)) == NULL) {
    11261472                goto out;
    11271473        }
     
    11451491
    11461492        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
    1147                      "attributes-charset", NULL, cupsLangEncoding(language));
     1493                     "attributes-charset", NULL, "utf-8");
    11481494
    11491495        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
    11501496                     "attributes-natural-language", NULL, language->language);
    11511497
     1498        if (push_utf8_talloc(frame, &printername, PRINTERNAME(snum)) == (size_t)-1) {
     1499                goto out;
     1500        }
    11521501        slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
    1153                  PRINTERNAME(snum));
     1502                 printername);
    11541503
    11551504        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
    11561505
     1506        if (push_utf8_talloc(frame, &username, current_user_info.unix_name) == (size_t)-1) {
     1507                goto out;
     1508        }
    11571509        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
    1158                      NULL, current_user_info.unix_name);
     1510                     NULL, username);
    11591511
    11601512       /*
     
    11841536                httpClose(http);
    11851537
     1538        TALLOC_FREE(frame);
    11861539        return ret;
    11871540}
     
    12051558bool cups_pull_comment_location(NT_PRINTER_INFO_LEVEL_2 *printer)
    12061559{
     1560        TALLOC_CTX *frame = talloc_stackframe();
    12071561        http_t          *http = NULL;           /* HTTP connection to server */
    12081562        ipp_t           *request = NULL,        /* IPP Request */
     
    12101564        ipp_attribute_t *attr;          /* Current attribute */
    12111565        cups_lang_t     *language = NULL;       /* Default language */
    1212         char            *name,          /* printer-name attribute */
    1213                         *info,          /* printer-info attribute */
    1214                         *location;      /* printer-location attribute */
    12151566        char            uri[HTTP_MAX_URI];
     1567        char *server = NULL;
     1568        char *sharename = NULL;
     1569        char *name = NULL;
    12161570        static const char *requested[] =/* Requested attributes */
    12171571                        {
     
    12341588         */
    12351589
    1236         if ((http = cups_connect()) == NULL) {
     1590        if ((http = cups_connect(frame)) == NULL) {
    12371591                goto out;
    12381592        }
     
    12461600
    12471601        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
    1248                      "attributes-charset", NULL, cupsLangEncoding(language));
     1602                     "attributes-charset", NULL, "utf-8");
    12491603
    12501604        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
    12511605                     "attributes-natural-language", NULL, language->language);
    12521606
     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        }
    12531620        slprintf(uri, sizeof(uri) - 1, "ipp://%s/printers/%s",
    1254                  lp_cups_server(), printer->sharename);
     1621                 server, sharename);
    12551622
    12561623        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
     
    12871654                 */
    12881655
    1289                 name       = NULL;
    1290                 info       = NULL;
    1291                 location   = NULL;
    1292 
    12931656                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
    12941664                        /* Grab the comment if we don't have one */
    12951665                        if ( (strcmp(attr->name, "printer-info") == 0)
    12961666                             && (attr->value_tag == IPP_TAG_TEXT)
    1297                              && !strlen(printer->comment) ) 
     1667                             && !strlen(printer->comment) )
    12981668                        {
     1669                                char *comment = NULL;
     1670                                pull_utf8_talloc(frame,
     1671                                        &comment,
     1672                                        attr->values[0].string.text);
    12991673                                DEBUG(5,("cups_pull_comment_location: Using cups comment: %s\n",
    1300                                          attr->values[0].string.text));                         
     1674                                         comment));
    13011675                                strlcpy(printer->comment,
    1302                                                 attr->values[0].string.text,
    1303                                                 sizeof(printer->comment));
     1676                                        comment,
     1677                                        sizeof(printer->comment));
    13041678                        }
    13051679
    1306                         /* Grab the location if we don't have one */ 
     1680                        /* Grab the location if we don't have one */
    13071681                        if ( (strcmp(attr->name, "printer-location") == 0)
    1308                              && (attr->value_tag == IPP_TAG_TEXT) 
     1682                             && (attr->value_tag == IPP_TAG_TEXT)
    13091683                             && !strlen(printer->location) )
    13101684                        {
     1685                                char *location = NULL;
     1686                                pull_utf8_talloc(frame,
     1687                                        &location,
     1688                                        attr->values[0].string.text);
    13111689                                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));
    13141694                        }
    13151695
     
    13181698
    13191699                /*
    1320                  * See if we have everything needed...
     1700                 * We have everything needed...
    13211701                 */
    13221702
    1323                 if (name == NULL)
     1703                if (name != NULL)
    13241704                        break;
    1325 
    13261705        }
    13271706
     
    13381717                httpClose(http);
    13391718
     1719        TALLOC_FREE(frame);
    13401720        return ret;
    13411721}
Note: See TracChangeset for help on using the changeset viewer.