Revert "Change strict allocate to default to true.
[samba.git] / source3 / include / printing.h
1 #ifndef PRINTING_H_
2 #define PRINTING_H_
3
4 /* 
5    Unix SMB/CIFS implementation.
6    printing definitions
7    Copyright (C) Andrew Tridgell 1992-2000
8    
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 3 of the License, or
12    (at your option) any later version.
13    
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18    
19    You should have received a copy of the GNU General Public License
20    along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 */
22
23 /*
24    This file defines the low-level printing system interfaces used by the
25    SAMBA printing subsystem.
26 */
27
28 /* Extra fields above "LPQ_PRINTING" are used to map extra NT status codes. */
29
30 enum {
31         LPQ_QUEUED = 0,
32         LPQ_PAUSED,
33         LPQ_SPOOLING,
34         LPQ_PRINTING,
35         LPQ_ERROR,
36         LPQ_DELETING,
37         LPQ_OFFLINE,
38         LPQ_PAPEROUT,
39         LPQ_PRINTED,
40         LPQ_DELETED,
41         LPQ_BLOCKED,
42         LPQ_USER_INTERVENTION,
43
44         /* smbd is dooing the file spooling before passing control to spoolss */
45         PJOB_SMBD_SPOOLING
46 };
47
48 typedef struct _print_queue_struct {
49         int job;                /* normally the UNIX jobid -- see note in
50                                    printing.c:traverse_fn_delete() */
51         int size;
52         int page_count;
53         int status;
54         int priority;
55         time_t time;
56         fstring fs_user;
57         fstring fs_file;
58 } print_queue_struct;
59
60 enum {LPSTAT_OK, LPSTAT_STOPPED, LPSTAT_ERROR};
61
62 typedef struct {
63         fstring message;
64         int qcount;
65         int status;
66 }  print_status_struct;
67
68 /* Information for print jobs */
69 struct printjob {
70         pid_t pid; /* which process launched the job */
71         int sysjob; /* the system (lp) job number */
72         int fd; /* file descriptor of open file if open */
73         time_t starttime; /* when the job started spooling */
74         int status; /* the status of this job */
75         size_t size; /* the size of the job so far */
76         int page_count; /* then number of pages so far */
77         bool spooled; /* has it been sent to the spooler yet? */
78         bool smbjob; /* set if the job is a SMB job */
79         fstring filename; /* the filename used to spool the file */
80         fstring jobname; /* the job name given to us by the client */
81         fstring user; /* the user who started the job */
82         fstring clientmachine; /* The client machine which started this job */
83         fstring queuename; /* service number of printer for this job */
84         struct spoolss_DeviceMode *devmode;
85 };
86
87 /* Information for print interfaces */
88 struct printif
89 {
90   /* value of the 'printing' option for this service */
91   enum printing_types type;
92
93   int (*queue_get)(const char *printer_name,
94                    enum printing_types printing_type,
95                    char *lpq_command,
96                    print_queue_struct **q,
97                    print_status_struct *status);
98   int (*queue_pause)(int snum);
99   int (*queue_resume)(int snum);
100   int (*job_delete)(const char *sharename, const char *lprm_command, struct printjob *pjob);
101   int (*job_pause)(int snum, struct printjob *pjob);
102   int (*job_resume)(int snum, struct printjob *pjob);
103   int (*job_submit)(int snum, struct printjob *pjob);
104 };
105
106 extern struct printif   generic_printif;
107
108 #ifdef HAVE_CUPS
109 extern struct printif   cups_printif;
110 #endif /* HAVE_CUPS */
111
112 #ifdef HAVE_IPRINT
113 extern struct printif   iprint_printif;
114 #endif /* HAVE_IPRINT */
115
116 /* PRINT_MAX_JOBID is now defined in local.h */
117 #define UNIX_JOB_START PRINT_MAX_JOBID
118 #define NEXT_JOBID(j) ((j+1) % PRINT_MAX_JOBID > 0 ? (j+1) % PRINT_MAX_JOBID : 1)
119
120 #define MAX_CACHE_VALID_TIME 3600
121 #define CUPS_DEFAULT_CONNECTION_TIMEOUT 30
122
123 #ifndef PRINT_SPOOL_PREFIX
124 #define PRINT_SPOOL_PREFIX "smbprn."
125 #endif
126 #define PRINT_DATABASE_VERSION 7
127
128 #ifdef AIX
129 #define DEFAULT_PRINTING PRINT_AIX
130 #define PRINTCAP_NAME "/etc/qconfig"
131 #endif
132
133 #ifdef HPUX
134 #define DEFAULT_PRINTING PRINT_HPUX
135 #endif
136
137 #ifdef QNX
138 #define DEFAULT_PRINTING PRINT_QNX
139 #endif
140
141 #ifndef DEFAULT_PRINTING
142 #ifdef HAVE_CUPS
143 #define DEFAULT_PRINTING PRINT_CUPS
144 #define PRINTCAP_NAME "cups"
145 #elif defined(SYSV)
146 #define DEFAULT_PRINTING PRINT_SYSV
147 #define PRINTCAP_NAME "lpstat"
148 #else
149 #define DEFAULT_PRINTING PRINT_BSD
150 #define PRINTCAP_NAME "/etc/printcap"
151 #endif
152 #endif
153
154 #ifndef PRINTCAP_NAME
155 #define PRINTCAP_NAME "/etc/printcap"
156 #endif
157
158 /* There can be this many printing tdb's open, plus any locked ones. */
159 #define MAX_PRINT_DBS_OPEN 1
160
161 struct tdb_print_db {
162         struct tdb_print_db *next, *prev;
163         TDB_CONTEXT *tdb;
164         int ref_count;
165         fstring printer_name;
166 };
167
168 /* 
169  * Used for print notify
170  */
171
172 #define NOTIFY_PID_LIST_KEY "NOTIFY_PID_LIST"
173
174 /* The following definitions come from printing/printspoolss.c  */
175
176 NTSTATUS print_spool_open(files_struct *fsp,
177                           const char *fname,
178                           uint16_t current_vuid);
179
180 int print_spool_write(files_struct *fsp, const char *data, uint32_t size,
181                       SMB_OFF_T offset, uint32_t *written);
182
183 void print_spool_end(files_struct *fsp, enum file_close_type close_type);
184
185 void print_spool_terminate(struct connection_struct *conn,
186                            struct print_file_data *print_file);
187
188 /* The following definitions come from printing/printing.c  */
189
190 uint32 sysjob_to_jobid(int unix_jobid);
191 bool print_notify_register_pid(int snum);
192 bool print_notify_deregister_pid(int snum);
193 bool print_job_exists(const char* sharename, uint32 jobid);
194 char *print_job_fname(const char* sharename, uint32 jobid);
195 struct spoolss_DeviceMode *print_job_devmode(const char* sharename, uint32 jobid);
196 bool print_job_set_name(struct tevent_context *ev,
197                         struct messaging_context *msg_ctx,
198                         const char *sharename, uint32 jobid, const char *name);
199 bool print_job_get_name(TALLOC_CTX *mem_ctx, const char *sharename, uint32_t jobid, char **name);
200 WERROR print_job_delete(const struct auth_serversupplied_info *server_info,
201                         struct messaging_context *msg_ctx,
202                         int snum, uint32_t jobid);
203 bool print_job_pause(const struct auth_serversupplied_info *server_info,
204                      struct messaging_context *msg_ctx,
205                      int snum, uint32 jobid, WERROR *errcode);
206 bool print_job_resume(const struct auth_serversupplied_info *server_info,
207                       struct messaging_context *msg_ctx,
208                       int snum, uint32 jobid, WERROR *errcode);
209 ssize_t print_job_write(struct tevent_context *ev,
210                         struct messaging_context *msg_ctx,
211                         int snum, uint32 jobid, const char *buf, size_t size);
212 int print_queue_length(struct messaging_context *msg_ctx, int snum,
213                        print_status_struct *pstatus);
214 WERROR print_job_start(const struct auth_serversupplied_info *server_info,
215                        struct messaging_context *msg_ctx,
216                        const char *clientmachine,
217                        int snum, const char *docname, const char *filename,
218                        struct spoolss_DeviceMode *devmode, uint32_t *_jobid);
219 void print_job_endpage(struct messaging_context *msg_ctx,
220                        int snum, uint32 jobid);
221 NTSTATUS print_job_end(struct messaging_context *msg_ctx, int snum,
222                        uint32 jobid, enum file_close_type close_type);
223 int print_queue_status(struct messaging_context *msg_ctx, int snum,
224                        print_queue_struct **ppqueue,
225                        print_status_struct *status);
226 WERROR print_queue_pause(const struct auth_serversupplied_info *server_info,
227                          struct messaging_context *msg_ctx, int snum);
228 WERROR print_queue_resume(const struct auth_serversupplied_info *server_info,
229                           struct messaging_context *msg_ctx, int snum);
230 WERROR print_queue_purge(const struct auth_serversupplied_info *server_info,
231                          struct messaging_context *msg_ctx, int snum);
232 uint16 pjobid_to_rap(const char* sharename, uint32 jobid);
233 bool rap_to_pjobid(uint16 rap_jobid, fstring sharename, uint32 *pjobid);
234 void rap_jobid_delete(const char* sharename, uint32 jobid);
235 bool print_backend_init(struct messaging_context *msg_ctx);
236 void start_background_queue(struct tevent_context *ev,
237                             struct messaging_context *msg);
238 void printing_end(void);
239
240 /* The following definitions come from printing/lpq_parse.c  */
241
242 bool parse_lpq_entry(enum printing_types printing_type,char *line,
243                      print_queue_struct *buf,
244                      print_status_struct *status,bool first);
245 uint32_t print_parse_jobid(const char *fname);
246
247 /* The following definitions come from printing/printing_db.c  */
248
249 struct tdb_print_db *get_print_db_byname(const char *printername);
250 void release_print_db( struct tdb_print_db *pdb);
251 void close_all_print_db(void);
252 TDB_DATA get_printer_notify_pid_list(TDB_CONTEXT *tdb, const char *printer_name, bool cleanlist);
253
254 #endif /* PRINTING_H_ */