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