Ignore:
Timestamp:
Nov 29, 2012, 1:59:04 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.9

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/server/source3/printing/print_generic.c

    r745 r751  
    140140
    141141/****************************************************************************
     142get the current list of queued jobs
     143****************************************************************************/
     144static int generic_queue_get(const char *printer_name,
     145                             enum printing_types printing_type,
     146                             char *lpq_command,
     147                             print_queue_struct **q,
     148                             print_status_struct *status)
     149{
     150        char **qlines;
     151        int fd;
     152        int numlines, i, qcount;
     153        print_queue_struct *queue = NULL;
     154
     155        /* never do substitution when running the 'lpq command' since we can't
     156           get it rigt when using the background update daemon.  Make the caller
     157           do it before passing off the command string to us here. */
     158
     159        print_run_command(-1, printer_name, False, lpq_command, &fd, NULL);
     160
     161        if (fd == -1) {
     162                DEBUG(5,("generic_queue_get: Can't read print queue status for printer %s\n",
     163                        printer_name ));
     164                return 0;
     165        }
     166
     167        numlines = 0;
     168        qlines = fd_lines_load(fd, &numlines,0,NULL);
     169        close(fd);
     170
     171        /* turn the lpq output into a series of job structures */
     172        qcount = 0;
     173        ZERO_STRUCTP(status);
     174        if (numlines && qlines) {
     175                queue = SMB_MALLOC_ARRAY(print_queue_struct, numlines+1);
     176                if (!queue) {
     177                        TALLOC_FREE(qlines);
     178                        *q = NULL;
     179                        return 0;
     180                }
     181                memset(queue, '\0', sizeof(print_queue_struct)*(numlines+1));
     182
     183                for (i=0; i<numlines; i++) {
     184                        /* parse the line */
     185                        if (parse_lpq_entry(printing_type,qlines[i],
     186                                            &queue[qcount],status,qcount==0)) {
     187                                qcount++;
     188                        }
     189                }
     190        }
     191
     192        TALLOC_FREE(qlines);
     193        *q = queue;
     194        return qcount;
     195}
     196
     197/****************************************************************************
    142198 Submit a file for printing - called from print_job_end()
    143199****************************************************************************/
    144200
    145 static int generic_job_submit(int snum, struct printjob *pjob)
     201static int generic_job_submit(int snum, struct printjob *pjob,
     202                              enum printing_types printing_type,
     203                              char *lpq_cmd)
    146204{
    147205        int ret = -1;
     
    153211        TALLOC_CTX *ctx = talloc_tos();
    154212        fstring job_page_count, job_size;
     213        print_queue_struct *q;
     214        print_status_struct status;
    155215
    156216        /* we print from the directory path to give the best chance of
     
    203263                        "%c", job_page_count,
    204264                        NULL);
     265        if (ret != 0) {
     266                ret = -1;
     267                goto out;
     268        }
     269
     270        /*
     271         * check the queue for the newly submitted job, this allows us to
     272         * determine the backend job identifier (sysjob).
     273         */
     274        pjob->sysjob = -1;
     275        ret = generic_queue_get(lp_printername(snum), printing_type, lpq_cmd,
     276                                &q, &status);
     277        if (ret > 0) {
     278                int i;
     279                for (i = 0; i < ret; i++) {
     280                        if (strcmp(q[i].fs_file, p) == 0) {
     281                                pjob->sysjob = q[i].sysjob;
     282                                DEBUG(5, ("new job %u (%s) matches sysjob %d\n",
     283                                          pjob->jobid, jobname, pjob->sysjob));
     284                                break;
     285                        }
     286                }
     287                SAFE_FREE(q);
     288                ret = 0;
     289        }
     290        if (pjob->sysjob == -1) {
     291                DEBUG(2, ("failed to get sysjob for job %u (%s), tracking as "
     292                          "Unix job\n", pjob->jobid, jobname));
     293        }
     294
    205295
    206296 out:
     
    211301        TALLOC_FREE(current_directory);
    212302        return ret;
    213 }
    214 
    215 
    216 /****************************************************************************
    217 get the current list of queued jobs
    218 ****************************************************************************/
    219 static int generic_queue_get(const char *printer_name,
    220                              enum printing_types printing_type,
    221                              char *lpq_command,
    222                              print_queue_struct **q,
    223                              print_status_struct *status)
    224 {
    225         char **qlines;
    226         int fd;
    227         int numlines, i, qcount;
    228         print_queue_struct *queue = NULL;
    229        
    230         /* never do substitution when running the 'lpq command' since we can't
    231            get it rigt when using the background update daemon.  Make the caller
    232            do it before passing off the command string to us here. */
    233 
    234         print_run_command(-1, printer_name, False, lpq_command, &fd, NULL);
    235 
    236         if (fd == -1) {
    237                 DEBUG(5,("generic_queue_get: Can't read print queue status for printer %s\n",
    238                         printer_name ));
    239                 return 0;
    240         }
    241        
    242         numlines = 0;
    243         qlines = fd_lines_load(fd, &numlines,0,NULL);
    244         close(fd);
    245 
    246         /* turn the lpq output into a series of job structures */
    247         qcount = 0;
    248         ZERO_STRUCTP(status);
    249         if (numlines && qlines) {
    250                 queue = SMB_MALLOC_ARRAY(print_queue_struct, numlines+1);
    251                 if (!queue) {
    252                         TALLOC_FREE(qlines);
    253                         *q = NULL;
    254                         return 0;
    255                 }
    256                 memset(queue, '\0', sizeof(print_queue_struct)*(numlines+1));
    257 
    258                 for (i=0; i<numlines; i++) {
    259                         /* parse the line */
    260                         if (parse_lpq_entry(printing_type,qlines[i],
    261                                             &queue[qcount],status,qcount==0)) {
    262                                 qcount++;
    263                         }
    264                 }               
    265         }
    266 
    267         TALLOC_FREE(qlines);
    268         *q = queue;
    269         return qcount;
    270303}
    271304
Note: See TracChangeset for help on using the changeset viewer.