1 /* 2 * Print job definitions for the CUPS scheduler. 3 * 4 * Copyright © 2020-2024 by OpenPrinting. 5 * Copyright 2007-2015 by Apple Inc. 6 * Copyright 1997-2007 by Easy Software Products, all rights reserved. 7 * 8 * Licensed under Apache License v2.0. See the file "LICENSE" for more information. 9 */ 10 11 /* 12 * Constants... 13 */ 14 15 typedef enum cupsd_jobaction_e /**** Actions for state changes ****/ 16 { 17 CUPSD_JOB_DEFAULT, /* Use default action */ 18 CUPSD_JOB_FORCE, /* Force the change */ 19 CUPSD_JOB_PURGE /* Force the change and purge */ 20 } cupsd_jobaction_t; 21 22 23 /* 24 * Job request structure... 25 */ 26 27 struct cupsd_job_s /**** Job request ****/ 28 { 29 int id, /* Job ID */ 30 priority, /* Job priority */ 31 dirty; /* Do we need to write the "c" file? */ 32 ipp_jstate_t state_value; /* Cached job-state */ 33 int pending_timeout;/* Non-zero if the job was created and 34 * waiting on files */ 35 char *username; /* Printing user */ 36 char *dest; /* Destination printer or class */ 37 char *name; /* Job name/title */ 38 int koctets; /* job-k-octets */ 39 cups_ptype_t dtype; /* Destination type */ 40 cupsd_printer_t *printer; /* Printer this job is assigned to */ 41 int num_files; /* Number of files in job */ 42 mime_type_t **filetypes; /* File types */ 43 int *compressions; /* Compression status of each file */ 44 ipp_attribute_t *impressions, /* job-impressions-completed */ 45 *sheets; /* job-media-sheets-completed */ 46 time_t access_time, /* Last access time */ 47 cancel_time, /* When to cancel/send SIGTERM */ 48 creation_time, /* When job was created */ 49 completed_time, /* When job was completed (0 if not) */ 50 file_time, /* Job file retain time */ 51 history_time, /* Job history retain time */ 52 hold_until, /* Hold expiration date/time */ 53 kill_time; /* When to send SIGKILL */ 54 ipp_attribute_t *state; /* Job state */ 55 ipp_attribute_t *reasons; /* Job state reasons */ 56 ipp_attribute_t *job_sheets; /* Job sheets (NULL if none) */ 57 ipp_attribute_t *printer_message, 58 /* job-printer-state-message */ 59 *printer_reasons; 60 /* job-printer-state-reasons */ 61 int current_file; /* Current file in job */ 62 ipp_t *attrs; /* Job attributes */ 63 int print_pipes[2], /* Print data pipes */ 64 back_pipes[2], /* Backchannel pipes */ 65 side_pipes[2], /* Sidechannel pipes */ 66 status_pipes[2];/* Status pipes */ 67 cupsd_statbuf_t *status_buffer; /* Status buffer for this job */ 68 int status_level; /* Highest log level in a status 69 * message */ 70 int cost; /* Filtering cost */ 71 int pending_cost; /* Waiting for FilterLimit */ 72 int filters[MAX_FILTERS + 1]; 73 /* Filter process IDs, 0 terminated */ 74 int backend; /* Backend process ID */ 75 int status; /* Status code from filters */ 76 int tries; /* Number of tries for this job */ 77 int completed; /* cups-waiting-for-job-completed seen */ 78 int retry_as_raster;/* Need to retry the job as raster */ 79 char *auth_env[3], /* AUTH_xxx environment variables, 80 * if any */ 81 *auth_uid; /* AUTH_UID environment variable */ 82 void *profile, /* Security profile for filters */ 83 *bprofile; /* Security profile for backend */ 84 cups_array_t *history; /* Debug log history */ 85 int progress; /* Printing progress */ 86 int num_keywords; /* Number of PPD keywords */ 87 cups_option_t *keywords; /* PPD keywords */ 88 }; 89 90 typedef struct cupsd_joblog_s /**** Job log message ****/ 91 { 92 time_t time; /* Time of message */ 93 char message[1]; /* Message string */ 94 } cupsd_joblog_t; 95 96 97 /* 98 * Globals... 99 */ 100 101 VAR int JobHistory VALUE(INT_MAX); 102 /* Preserve job history? */ 103 VAR int JobFiles VALUE(86400); 104 /* Preserve job files? */ 105 VAR time_t JobHistoryUpdate VALUE(0); 106 /* Time for next job history update */ 107 VAR int MaxJobs VALUE(0), 108 /* Max number of jobs */ 109 MaxActiveJobs VALUE(0), 110 /* Max number of active jobs */ 111 MaxHoldTime VALUE(0), 112 /* Max time for indefinite hold */ 113 MaxJobsPerUser VALUE(0), 114 /* Max jobs per user */ 115 MaxJobsPerPrinter VALUE(0), 116 /* Max jobs per printer */ 117 MaxJobTime VALUE(3 * 60 * 60); 118 /* Max time for a job */ 119 VAR int JobAutoPurge VALUE(0); 120 /* Automatically purge jobs */ 121 VAR cups_array_t *Jobs VALUE(NULL), 122 /* List of current jobs */ 123 *ActiveJobs VALUE(NULL), 124 /* List of active jobs */ 125 *PrintingJobs VALUE(NULL); 126 /* List of jobs that are printing */ 127 VAR int NextJobId VALUE(1); 128 /* Next job ID to use */ 129 VAR int JobKillDelay VALUE(DEFAULT_TIMEOUT), 130 /* Delay before killing jobs */ 131 JobRetryLimit VALUE(5), 132 /* Max number of tries */ 133 JobRetryInterval VALUE(300); 134 /* Seconds between retries */ 135 136 137 /* 138 * Prototypes... 139 */ 140 141 extern cupsd_job_t *cupsdAddJob(int priority, const char *dest); 142 extern void cupsdCancelJobs(const char *dest, const char *username, 143 int purge); 144 extern void cupsdCheckJobs(void); 145 extern void cupsdCleanJobs(void); 146 extern void cupsdContinueJob(cupsd_job_t *job); 147 extern void cupsdDeleteJob(cupsd_job_t *job, 148 cupsd_jobaction_t action); 149 extern cupsd_job_t *cupsdFindJob(int id); 150 extern void cupsdFreeAllJobs(void); 151 extern cups_array_t *cupsdGetCompletedJobs(cupsd_printer_t *p); 152 extern int cupsdGetPrinterJobCount(const char *dest); 153 extern int cupsdGetUserJobCount(const char *username); 154 extern void cupsdLoadAllJobs(void); 155 extern int cupsdLoadJob(cupsd_job_t *job); 156 extern void cupsdMoveJob(cupsd_job_t *job, cupsd_printer_t *p); 157 extern void cupsdReleaseJob(cupsd_job_t *job); 158 extern void cupsdRestartJob(cupsd_job_t *job); 159 extern void cupsdSaveAllJobs(void); 160 extern void cupsdSaveJob(cupsd_job_t *job); 161 extern void cupsdSetJobHoldUntil(cupsd_job_t *job, 162 const char *when, int update); 163 extern void cupsdSetJobPriority(cupsd_job_t *job, int priority); 164 extern void cupsdSetJobState(cupsd_job_t *job, 165 ipp_jstate_t newstate, 166 cupsd_jobaction_t action, 167 const char *message, ...) 168 __attribute__((__format__(__printf__, 169 4, 5))); 170 extern void cupsdStopAllJobs(cupsd_jobaction_t action, 171 int kill_delay); 172 extern int cupsdTimeoutJob(cupsd_job_t *job); 173 extern void cupsdUnloadCompletedJobs(void); 174 extern void cupsdUpdateJobs(void); 175