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