3921b7c8fc2bbb5bfd6470e45a6f687759d1778b
[amitay/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 /* Information for print jobs */
29 struct printjob {
30         pid_t pid; /* which process launched the job */
31         int sysjob; /* the system (lp) job number */
32         int fd; /* file descriptor of open file if open */
33         time_t starttime; /* when the job started spooling */
34         int status; /* the status of this job */
35         size_t size; /* the size of the job so far */
36         int page_count; /* then number of pages so far */
37         bool spooled; /* has it been sent to the spooler yet? */
38         bool smbjob; /* set if the job is a SMB job */
39         fstring filename; /* the filename used to spool the file */
40         fstring jobname; /* the job name given to us by the client */
41         fstring user; /* the user who started the job */
42         fstring queuename; /* service number of printer for this job */
43         struct spoolss_DeviceMode *devmode;
44 };
45
46 /* Information for print interfaces */
47 struct printif
48 {
49   /* value of the 'printing' option for this service */
50   enum printing_types type;
51
52   int (*queue_get)(const char *printer_name,
53                    enum printing_types printing_type,
54                    char *lpq_command,
55                    print_queue_struct **q,
56                    print_status_struct *status);
57   int (*queue_pause)(int snum);
58   int (*queue_resume)(int snum);
59   int (*job_delete)(const char *sharename, const char *lprm_command, struct printjob *pjob);
60   int (*job_pause)(int snum, struct printjob *pjob);
61   int (*job_resume)(int snum, struct printjob *pjob);
62   int (*job_submit)(int snum, struct printjob *pjob);
63 };
64
65 extern struct printif   generic_printif;
66
67 #ifdef HAVE_CUPS
68 extern struct printif   cups_printif;
69 #endif /* HAVE_CUPS */
70
71 #ifdef HAVE_IPRINT
72 extern struct printif   iprint_printif;
73 #endif /* HAVE_IPRINT */
74
75 /* PRINT_MAX_JOBID is now defined in local.h */
76 #define UNIX_JOB_START PRINT_MAX_JOBID
77 #define NEXT_JOBID(j) ((j+1) % PRINT_MAX_JOBID > 0 ? (j+1) % PRINT_MAX_JOBID : 1)
78
79 #define MAX_CACHE_VALID_TIME 3600
80 #define CUPS_DEFAULT_CONNECTION_TIMEOUT 30
81
82 #ifndef PRINT_SPOOL_PREFIX
83 #define PRINT_SPOOL_PREFIX "smbprn."
84 #endif
85 #define PRINT_DATABASE_VERSION 5
86
87 /* There can be this many printing tdb's open, plus any locked ones. */
88 #define MAX_PRINT_DBS_OPEN 1
89
90 struct tdb_print_db {
91         struct tdb_print_db *next, *prev;
92         TDB_CONTEXT *tdb;
93         int ref_count;
94         fstring printer_name;
95 };
96
97 /* 
98  * Used for print notify
99  */
100
101 #define NOTIFY_PID_LIST_KEY "NOTIFY_PID_LIST"
102
103 NTSTATUS print_spool_open(files_struct *fsp,
104                           const char *fname,
105                           uint16_t current_vuid);
106
107 int print_spool_write(files_struct *fsp, const char *data, uint32_t size,
108                       SMB_OFF_T offset, uint32_t *written);
109
110 void print_spool_end(files_struct *fsp, enum file_close_type close_type);
111
112 void print_spool_terminate(struct connection_struct *conn,
113                            struct print_file_data *print_file);
114
115 /* The following definitions come from printing/printing.c  */
116
117 int unpack_pjob( uint8 *buf, int buflen, struct printjob *pjob );
118 uint32 sysjob_to_jobid(int unix_jobid);
119 bool print_notify_register_pid(int snum);
120 bool print_notify_deregister_pid(int snum);
121 bool print_job_exists(const char* sharename, uint32 jobid);
122 char *print_job_fname(const char* sharename, uint32 jobid);
123 struct spoolss_DeviceMode *print_job_devmode(const char* sharename, uint32 jobid);
124 bool print_job_set_name(const char *sharename, uint32 jobid, const char *name);
125 bool print_job_get_name(TALLOC_CTX *mem_ctx, const char *sharename, uint32_t jobid, char **name);
126 WERROR print_job_delete(struct auth_serversupplied_info *server_info,
127                         struct messaging_context *msg_ctx,
128                         int snum, uint32_t jobid);
129 bool print_job_pause(struct auth_serversupplied_info *server_info,
130                      struct messaging_context *msg_ctx,
131                      int snum, uint32 jobid, WERROR *errcode);
132 bool print_job_resume(struct auth_serversupplied_info *server_info,
133                       struct messaging_context *msg_ctx,
134                       int snum, uint32 jobid, WERROR *errcode);
135 ssize_t print_job_write(int snum, uint32 jobid, const char *buf, SMB_OFF_T pos, size_t size);
136 int print_queue_length(struct messaging_context *msg_ctx, int snum,
137                        print_status_struct *pstatus);
138 WERROR print_job_start(struct auth_serversupplied_info *server_info,
139                        struct messaging_context *msg_ctx,
140                        int snum, const char *docname, const char *filename,
141                        struct spoolss_DeviceMode *devmode, uint32_t *_jobid);
142 void print_job_endpage(int snum, uint32 jobid);
143 NTSTATUS print_job_end(struct messaging_context *msg_ctx, int snum,
144                        uint32 jobid, enum file_close_type close_type);
145 int print_queue_status(struct messaging_context *msg_ctx, int snum,
146                        print_queue_struct **ppqueue,
147                        print_status_struct *status);
148 WERROR print_queue_pause(struct auth_serversupplied_info *server_info,
149                          struct messaging_context *msg_ctx, int snum);
150 WERROR print_queue_resume(struct auth_serversupplied_info *server_info,
151                           struct messaging_context *msg_ctx, int snum);
152 WERROR print_queue_purge(struct auth_serversupplied_info *server_info,
153                          struct messaging_context *msg_ctx, int snum);
154
155 #endif /* PRINTING_H_ */