r6334: revert 3.0.15pre1 changes. roll back to 3.0.14.
[Samba.git] / source / printing / printfsp.c
blob7c5de468701ce217b44fca62421c908adfa241d1
1 /*
2 Unix SMB/CIFS implementation.
3 printing backend routines for smbd - using files_struct rather
4 than only snum
5 Copyright (C) Andrew Tridgell 1992-2000
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "includes.h"
24 /***************************************************************************
25 open a print file and setup a fsp for it. This is a wrapper around
26 print_job_start().
27 ***************************************************************************/
29 files_struct *print_fsp_open(connection_struct *conn, char *fname)
31 int jobid;
32 SMB_STRUCT_STAT sbuf;
33 extern struct current_user current_user;
34 files_struct *fsp = file_new(conn);
35 fstring name;
37 if(!fsp)
38 return NULL;
40 fstrcpy( name, "Remote Downlevel Document");
41 if (fname) {
42 char *p = strrchr(fname, '/');
43 fstrcat(name, " ");
44 if (!p)
45 p = fname;
46 fstrcat(name, p);
49 jobid = print_job_start(&current_user, SNUM(conn), name, NULL);
50 if (jobid == -1) {
51 file_free(fsp);
52 return NULL;
55 /* Convert to RAP id. */
56 fsp->rap_print_jobid = pjobid_to_rap(lp_const_servicename(SNUM(conn)), jobid);
57 if (fsp->rap_print_jobid == 0) {
58 /* We need to delete the entry in the tdb. */
59 pjob_delete(lp_const_servicename(SNUM(conn)), jobid);
60 file_free(fsp);
61 return NULL;
64 /* setup a full fsp */
65 fsp->fd = print_job_fd(lp_const_servicename(SNUM(conn)),jobid);
66 GetTimeOfDay(&fsp->open_time);
67 fsp->vuid = current_user.vuid;
68 fsp->size = 0;
69 fsp->pos = -1;
70 fsp->can_lock = True;
71 fsp->can_read = False;
72 fsp->can_write = True;
73 fsp->share_mode = 0;
74 fsp->print_file = True;
75 fsp->modified = False;
76 fsp->oplock_type = NO_OPLOCK;
77 fsp->sent_oplock_break = NO_BREAK_SENT;
78 fsp->is_directory = False;
79 fsp->directory_delete_on_close = False;
80 string_set(&fsp->fsp_name,print_job_fname(lp_const_servicename(SNUM(conn)),jobid));
81 fsp->wbmpx_ptr = NULL;
82 fsp->wcp = NULL;
83 SMB_VFS_FSTAT(fsp,fsp->fd, &sbuf);
84 fsp->mode = sbuf.st_mode;
85 fsp->inode = sbuf.st_ino;
86 fsp->dev = sbuf.st_dev;
88 conn->num_files_open++;
90 return fsp;
93 /****************************************************************************
94 print a file - called on closing the file
95 ****************************************************************************/
96 void print_fsp_end(files_struct *fsp, BOOL normal_close)
98 uint32 jobid;
99 fstring sharename;
101 if (fsp->share_mode == FILE_DELETE_ON_CLOSE) {
103 * Truncate the job. print_job_end will take
104 * care of deleting it for us. JRA.
106 sys_ftruncate(fsp->fd, 0);
109 if (fsp->fsp_name) {
110 string_free(&fsp->fsp_name);
113 if (!rap_to_pjobid(fsp->rap_print_jobid, sharename, &jobid)) {
114 DEBUG(3,("print_fsp_end: Unable to convert RAP jobid %u to print jobid.\n",
115 (unsigned int)fsp->rap_print_jobid ));
116 return;
119 print_job_end(SNUM(fsp->conn),jobid, normal_close);