5d0672cc36f8305775f45f368c1803dcc477b193
[metze/samba/wip.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 #include "tdb_compat.h"
28
29 /* Extra fields above "LPQ_PRINTING" are used to map extra NT status codes. */
30
31 enum {
32         LPQ_QUEUED = 0,
33         LPQ_PAUSED,
34         LPQ_SPOOLING,
35         LPQ_PRINTING,
36         LPQ_ERROR,
37         LPQ_DELETING,
38         LPQ_OFFLINE,
39         LPQ_PAPEROUT,
40         LPQ_PRINTED,
41         LPQ_DELETED,
42         LPQ_BLOCKED,
43         LPQ_USER_INTERVENTION,
44
45         /* smbd is dooing the file spooling before passing control to spoolss */
46         PJOB_SMBD_SPOOLING
47 };
48
49 typedef struct _print_queue_struct {
50         int sysjob;             /* normally the UNIX jobid -- see note in
51                                    printing.c:traverse_fn_delete() */
52         int size;
53         int page_count;
54         int status;
55         int priority;
56         time_t time;
57         fstring fs_user;
58         fstring fs_file;
59 } print_queue_struct;
60
61 enum {LPSTAT_OK, LPSTAT_STOPPED, LPSTAT_ERROR};
62
63 typedef struct {
64         fstring message;
65         int qcount;
66         int status;
67 }  print_status_struct;
68
69 /* Information for print jobs */
70 struct printjob {
71         pid_t pid; /* which process launched the job */
72         uint32_t jobid; /* the spoolss print job identifier */
73         int sysjob; /* the system (lp) job number */
74         int fd; /* file descriptor of open file if open */
75         time_t starttime; /* when the job started spooling */
76         int status; /* the status of this job */
77         size_t size; /* the size of the job so far */
78         int page_count; /* then number of pages so far */
79         bool spooled; /* has it been sent to the spooler yet? */
80         bool smbjob; /* set if the job is a SMB job */
81         fstring filename; /* the filename used to spool the file */
82         fstring jobname; /* the job name given to us by the client */
83         fstring user; /* the user who started the job */
84         fstring clientmachine; /* The client machine which started this job */
85         fstring queuename; /* service number of printer for this job */
86         struct spoolss_DeviceMode *devmode;
87 };
88
89 /* Information for print interfaces */
90 struct printif
91 {
92   /* value of the 'printing' option for this service */
93   enum printing_types type;
94
95   int (*queue_get)(const char *printer_name,
96                    enum printing_types printing_type,
97                    char *lpq_command,
98                    print_queue_struct **q,
99                    print_status_struct *status);
100   int (*queue_pause)(int snum);
101   int (*queue_resume)(int snum);
102   int (*job_delete)(const char *sharename, const char *lprm_command, struct printjob *pjob);
103   int (*job_pause)(int snum, struct printjob *pjob);
104   int (*job_resume)(int snum, struct printjob *pjob);
105   int (*job_submit)(int snum, struct printjob *pjob,
106                     enum printing_types printing_type,
107                     char *lpq_command);
108 };
109
110 extern struct printif   generic_printif;
111
112 #ifdef HAVE_CUPS
113 extern struct printif   cups_printif;
114 #endif /* HAVE_CUPS */
115
116 #ifdef HAVE_IPRINT
117 extern struct printif   iprint_printif;
118 #endif /* HAVE_IPRINT */
119
120 /* PRINT_MAX_JOBID is now defined in local.h */
121 #define UNIX_JOB_START PRINT_MAX_JOBID
122 #define NEXT_JOBID(j) ((j+1) % PRINT_MAX_JOBID > 0 ? (j+1) % PRINT_MAX_JOBID : 1)
123
124 #define MAX_CACHE_VALID_TIME 3600
125 #define CUPS_DEFAULT_CONNECTION_TIMEOUT 30
126
127 #ifndef PRINT_SPOOL_PREFIX
128 #define PRINT_SPOOL_PREFIX "smbprn."
129 #endif
130 #define PRINT_DATABASE_VERSION 8
131
132 #ifdef AIX
133 #define DEFAULT_PRINTING PRINT_AIX
134 #define PRINTCAP_NAME "/etc/qconfig"
135 #endif
136
137 #ifdef HPUX
138 #define DEFAULT_PRINTING PRINT_HPUX
139 #endif
140
141 #ifdef QNX
142 #define DEFAULT_PRINTING PRINT_QNX
143 #endif
144
145 #ifndef DEFAULT_PRINTING
146 #ifdef HAVE_CUPS
147 #define DEFAULT_PRINTING PRINT_CUPS
148 #define PRINTCAP_NAME "cups"
149 #elif defined(SYSV)
150 #define DEFAULT_PRINTING PRINT_SYSV
151 #define PRINTCAP_NAME "lpstat"
152 #else
153 #define DEFAULT_PRINTING PRINT_BSD
154 #define PRINTCAP_NAME "/etc/printcap"
155 #endif
156 #endif
157
158 #ifndef PRINTCAP_NAME
159 #define PRINTCAP_NAME "/etc/printcap"
160 #endif
161
162 /* There can be this many printing tdb's open, plus any locked ones. */
163 #define MAX_PRINT_DBS_OPEN 1
164
165 struct tdb_print_db {
166         struct tdb_print_db *next, *prev;
167         struct tdb_context *tdb;
168         int ref_count;
169         fstring printer_name;
170 };
171
172 /* 
173  * Used for print notify
174  */
175
176 #define NOTIFY_PID_LIST_KEY "NOTIFY_PID_LIST"
177
178 /* The following definitions come from printing/printspoolss.c  */
179
180 NTSTATUS print_spool_open(files_struct *fsp,
181                           const char *fname,
182                           uint64_t current_vuid);
183
184 int print_spool_write(files_struct *fsp, const char *data, uint32_t size,
185                       off_t offset, uint32_t *written);
186
187 void print_spool_end(files_struct *fsp, enum file_close_type close_type);
188
189 void print_spool_terminate(struct connection_struct *conn,
190                            struct print_file_data *print_file);
191 uint16_t print_spool_rap_jobid(struct print_file_data *print_file);
192
193 /* The following definitions come from printing/printing.c  */
194
195 uint32 sysjob_to_jobid(int unix_jobid);
196 bool print_notify_register_pid(int snum);
197 bool print_notify_deregister_pid(int snum);
198 bool print_job_exists(const char* sharename, uint32 jobid);
199 struct spoolss_DeviceMode *print_job_devmode(TALLOC_CTX *mem_ctx,
200                                              const char *sharename,
201                                              uint32 jobid);
202 bool print_job_set_name(struct tevent_context *ev,
203                         struct messaging_context *msg_ctx,
204                         const char *sharename, uint32 jobid, const char *name);
205 bool print_job_get_name(TALLOC_CTX *mem_ctx, const char *sharename, uint32_t jobid, char **name);
206 WERROR print_job_delete(const struct auth_session_info *server_info,
207                         struct messaging_context *msg_ctx,
208                         int snum, uint32_t jobid);
209 WERROR print_job_pause(const struct auth_session_info *server_info,
210                      struct messaging_context *msg_ctx,
211                      int snum, uint32 jobid);
212 WERROR print_job_resume(const struct auth_session_info *server_info,
213                       struct messaging_context *msg_ctx,
214                       int snum, uint32 jobid);
215 ssize_t print_job_write(struct tevent_context *ev,
216                         struct messaging_context *msg_ctx,
217                         int snum, uint32 jobid, const char *buf, size_t size);
218 int print_queue_length(struct messaging_context *msg_ctx, int snum,
219                        print_status_struct *pstatus);
220 WERROR print_job_start(const struct auth_session_info *server_info,
221                        struct messaging_context *msg_ctx,
222                        const char *clientmachine,
223                        int snum, const char *docname, const char *filename,
224                        struct spoolss_DeviceMode *devmode, uint32_t *_jobid);
225 void print_job_endpage(struct messaging_context *msg_ctx,
226                        int snum, uint32 jobid);
227 NTSTATUS print_job_end(struct messaging_context *msg_ctx, int snum,
228                        uint32 jobid, enum file_close_type close_type);
229 int print_queue_status(struct messaging_context *msg_ctx, int snum,
230                        print_queue_struct **ppqueue,
231                        print_status_struct *status);
232 WERROR print_queue_pause(const struct auth_session_info *server_info,
233                          struct messaging_context *msg_ctx, int snum);
234 WERROR print_queue_resume(const struct auth_session_info *server_info,
235                           struct messaging_context *msg_ctx, int snum);
236 WERROR print_queue_purge(const struct auth_session_info *server_info,
237                          struct messaging_context *msg_ctx, int snum);
238 uint16 pjobid_to_rap(const char* sharename, uint32 jobid);
239 bool rap_to_pjobid(uint16 rap_jobid, fstring sharename, uint32 *pjobid);
240 void rap_jobid_delete(const char* sharename, uint32 jobid);
241 bool print_backend_init(struct messaging_context *msg_ctx);
242 void printing_end(void);
243
244 /* The following definitions come from printing/lpq_parse.c  */
245
246 bool parse_lpq_entry(enum printing_types printing_type,char *line,
247                      print_queue_struct *buf,
248                      print_status_struct *status,bool first);
249
250 /* The following definitions come from printing/printing_db.c  */
251
252 struct tdb_print_db *get_print_db_byname(const char *printername);
253 void release_print_db( struct tdb_print_db *pdb);
254 void close_all_print_db(void);
255 TDB_DATA get_printer_notify_pid_list(struct tdb_context *tdb, const char *printer_name, bool cleanlist);
256
257 void print_queue_receive(struct messaging_context *msg,
258                                 void *private_data,
259                                 uint32_t msg_type,
260                                 struct server_id server_id,
261                                 DATA_BLOB *data);
262 #endif /* PRINTING_H_ */