1*7bffb703SJames Tabor /*
2*7bffb703SJames Tabor * PROJECT: ReactOS Spooler API
3*7bffb703SJames Tabor * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4*7bffb703SJames Tabor * PURPOSE: Functions related to Spool Files and printing
5*7bffb703SJames Tabor * COPYRIGHT: Copyright 1998-2020 ReactOS
6*7bffb703SJames Tabor */
7*7bffb703SJames Tabor
8*7bffb703SJames Tabor #include "precomp.h"
9*7bffb703SJames Tabor
10*7bffb703SJames Tabor
11*7bffb703SJames Tabor HANDLE WINAPI
GetSpoolFileHandle(HANDLE hPrinter)12*7bffb703SJames Tabor GetSpoolFileHandle( HANDLE hPrinter )
13*7bffb703SJames Tabor {
14*7bffb703SJames Tabor DWORD dwErrorCode, cpid;
15*7bffb703SJames Tabor WINSPOOL_FILE_INFO_CONTAINER FileInfoContainer;
16*7bffb703SJames Tabor WINSPOOL_FILE_INFO_1 wsplfi;
17*7bffb703SJames Tabor PSPOOLER_HANDLE pHandle = (PSPOOLER_HANDLE)hPrinter;
18*7bffb703SJames Tabor HANDLE hHandle = NULL;
19*7bffb703SJames Tabor
20*7bffb703SJames Tabor FIXME("GetSpoolFileHandle(%p)\n", hPrinter);
21*7bffb703SJames Tabor
22*7bffb703SJames Tabor if ( IntProtectHandle( hPrinter, FALSE ) )
23*7bffb703SJames Tabor {
24*7bffb703SJames Tabor dwErrorCode = ERROR_INVALID_HANDLE;
25*7bffb703SJames Tabor }
26*7bffb703SJames Tabor else
27*7bffb703SJames Tabor {
28*7bffb703SJames Tabor if ( pHandle->hSpoolFileHandle != INVALID_HANDLE_VALUE )
29*7bffb703SJames Tabor {
30*7bffb703SJames Tabor hHandle = pHandle->hSpoolFileHandle;
31*7bffb703SJames Tabor }
32*7bffb703SJames Tabor else
33*7bffb703SJames Tabor {
34*7bffb703SJames Tabor cpid = GetCurrentProcessId();
35*7bffb703SJames Tabor
36*7bffb703SJames Tabor FileInfoContainer.Level = 1;
37*7bffb703SJames Tabor FileInfoContainer.FileInfo.pFileInfo1 = &wsplfi;
38*7bffb703SJames Tabor
39*7bffb703SJames Tabor // Do the RPC call.
40*7bffb703SJames Tabor RpcTryExcept
41*7bffb703SJames Tabor {
42*7bffb703SJames Tabor dwErrorCode = _RpcGetSpoolFileInfo2( &pHandle->hPrinter, cpid, 1, &FileInfoContainer );
43*7bffb703SJames Tabor }
44*7bffb703SJames Tabor RpcExcept(EXCEPTION_EXECUTE_HANDLER)
45*7bffb703SJames Tabor {
46*7bffb703SJames Tabor dwErrorCode = RpcExceptionCode();
47*7bffb703SJames Tabor ERR("_RpcGetSpoolFileInfo failed with exception code %lu!\n", dwErrorCode);
48*7bffb703SJames Tabor }
49*7bffb703SJames Tabor RpcEndExcept;
50*7bffb703SJames Tabor
51*7bffb703SJames Tabor if (dwErrorCode == ERROR_SUCCESS)
52*7bffb703SJames Tabor {
53*7bffb703SJames Tabor pHandle->hSpoolFileHandle = wsplfi.hSpoolFileHandle;
54*7bffb703SJames Tabor pHandle->dwOptions = wsplfi.dwOptions;
55*7bffb703SJames Tabor hHandle = pHandle->hSpoolFileHandle;
56*7bffb703SJames Tabor }
57*7bffb703SJames Tabor }
58*7bffb703SJames Tabor IntUnprotectHandle(pHandle);
59*7bffb703SJames Tabor }
60*7bffb703SJames Tabor SetLastError(dwErrorCode);
61*7bffb703SJames Tabor return hHandle;
62*7bffb703SJames Tabor }
63*7bffb703SJames Tabor
64*7bffb703SJames Tabor HANDLE WINAPI
CommitSpoolData(HANDLE hPrinter,HANDLE hSpoolFile,DWORD cbCommit)65*7bffb703SJames Tabor CommitSpoolData( HANDLE hPrinter, HANDLE hSpoolFile, DWORD cbCommit )
66*7bffb703SJames Tabor {
67*7bffb703SJames Tabor DWORD dwErrorCode, cpid;
68*7bffb703SJames Tabor WINSPOOL_FILE_INFO_CONTAINER FileInfoContainer;
69*7bffb703SJames Tabor WINSPOOL_FILE_INFO_1 wsplfi;
70*7bffb703SJames Tabor PSPOOLER_HANDLE pHandle = (PSPOOLER_HANDLE)hPrinter;
71*7bffb703SJames Tabor HANDLE hHandle = INVALID_HANDLE_VALUE;
72*7bffb703SJames Tabor
73*7bffb703SJames Tabor FIXME("CommitSpoolData(%p, %p, %d)\n", hPrinter,hSpoolFile,cbCommit);
74*7bffb703SJames Tabor
75*7bffb703SJames Tabor if ( IntProtectHandle( hPrinter, FALSE ) )
76*7bffb703SJames Tabor {
77*7bffb703SJames Tabor return hHandle;
78*7bffb703SJames Tabor }
79*7bffb703SJames Tabor
80*7bffb703SJames Tabor if ( pHandle->hSpoolFileHandle == INVALID_HANDLE_VALUE || pHandle->hSpoolFileHandle != hSpoolFile )
81*7bffb703SJames Tabor {
82*7bffb703SJames Tabor dwErrorCode = ERROR_INVALID_HANDLE;
83*7bffb703SJames Tabor }
84*7bffb703SJames Tabor else
85*7bffb703SJames Tabor {
86*7bffb703SJames Tabor cpid = GetCurrentProcessId();
87*7bffb703SJames Tabor
88*7bffb703SJames Tabor FileInfoContainer.Level = 1;
89*7bffb703SJames Tabor FileInfoContainer.FileInfo.pFileInfo1 = &wsplfi;
90*7bffb703SJames Tabor
91*7bffb703SJames Tabor // Do the RPC call.
92*7bffb703SJames Tabor RpcTryExcept
93*7bffb703SJames Tabor {
94*7bffb703SJames Tabor dwErrorCode = _RpcCommitSpoolData2( &pHandle->hPrinter, cpid, cbCommit, 1, &FileInfoContainer );
95*7bffb703SJames Tabor }
96*7bffb703SJames Tabor RpcExcept(EXCEPTION_EXECUTE_HANDLER)
97*7bffb703SJames Tabor {
98*7bffb703SJames Tabor dwErrorCode = RpcExceptionCode();
99*7bffb703SJames Tabor ERR("_RpcCommitSpoolData failed with exception code %lu!\n", dwErrorCode);
100*7bffb703SJames Tabor }
101*7bffb703SJames Tabor RpcEndExcept;
102*7bffb703SJames Tabor
103*7bffb703SJames Tabor if (dwErrorCode == ERROR_SUCCESS)
104*7bffb703SJames Tabor {
105*7bffb703SJames Tabor if ( wsplfi.hSpoolFileHandle != INVALID_HANDLE_VALUE )
106*7bffb703SJames Tabor {
107*7bffb703SJames Tabor CloseHandle( pHandle->hSpoolFileHandle );
108*7bffb703SJames Tabor pHandle->hSpoolFileHandle = wsplfi.hSpoolFileHandle;
109*7bffb703SJames Tabor }
110*7bffb703SJames Tabor hHandle = pHandle->hSpoolFileHandle;
111*7bffb703SJames Tabor }
112*7bffb703SJames Tabor IntUnprotectHandle(pHandle);
113*7bffb703SJames Tabor }
114*7bffb703SJames Tabor SetLastError(dwErrorCode);
115*7bffb703SJames Tabor return hHandle;
116*7bffb703SJames Tabor }
117*7bffb703SJames Tabor
118*7bffb703SJames Tabor BOOL WINAPI
CloseSpoolFileHandle(HANDLE hPrinter,HANDLE hSpoolFile)119*7bffb703SJames Tabor CloseSpoolFileHandle( HANDLE hPrinter, HANDLE hSpoolFile )
120*7bffb703SJames Tabor {
121*7bffb703SJames Tabor DWORD dwErrorCode;
122*7bffb703SJames Tabor PSPOOLER_HANDLE pHandle = (PSPOOLER_HANDLE)hPrinter;
123*7bffb703SJames Tabor
124*7bffb703SJames Tabor FIXME("CloseSpoolFileHandle(%p, %p)\n", hPrinter,hSpoolFile);
125*7bffb703SJames Tabor
126*7bffb703SJames Tabor if ( IntProtectHandle( hPrinter, FALSE ) )
127*7bffb703SJames Tabor {
128*7bffb703SJames Tabor return FALSE;
129*7bffb703SJames Tabor }
130*7bffb703SJames Tabor if ( pHandle->hSpoolFileHandle == hSpoolFile )
131*7bffb703SJames Tabor {
132*7bffb703SJames Tabor CloseHandle( pHandle->hSpoolFileHandle );
133*7bffb703SJames Tabor pHandle->hSpoolFileHandle = INVALID_HANDLE_VALUE;
134*7bffb703SJames Tabor
135*7bffb703SJames Tabor // Do the RPC call.
136*7bffb703SJames Tabor RpcTryExcept
137*7bffb703SJames Tabor {
138*7bffb703SJames Tabor dwErrorCode = _RpcCloseSpoolFileHandle( &pHandle->hPrinter );
139*7bffb703SJames Tabor }
140*7bffb703SJames Tabor RpcExcept(EXCEPTION_EXECUTE_HANDLER)
141*7bffb703SJames Tabor {
142*7bffb703SJames Tabor dwErrorCode = RpcExceptionCode();
143*7bffb703SJames Tabor ERR("_RpcloseSpoolFileHandle failed with exception code %lu!\n", dwErrorCode);
144*7bffb703SJames Tabor }
145*7bffb703SJames Tabor RpcEndExcept;
146*7bffb703SJames Tabor }
147*7bffb703SJames Tabor else
148*7bffb703SJames Tabor {
149*7bffb703SJames Tabor dwErrorCode = ERROR_INVALID_HANDLE;
150*7bffb703SJames Tabor }
151*7bffb703SJames Tabor IntUnprotectHandle(pHandle);
152*7bffb703SJames Tabor SetLastError(dwErrorCode);
153*7bffb703SJames Tabor return (dwErrorCode == ERROR_SUCCESS);
154*7bffb703SJames Tabor }
155