ReactOS 0.4.15-dev-5666-gc548b97
precomp.h File Reference
#include <windef.h>
#include <winbase.h>
#include <winuser.h>
#include <wingdi.h>
#include <winreg.h>
#include <winspool.h>
#include <winspool_c.h>
#include <winsplp.h>
#include <winddiui.h>
#include <ndk/rtlfuncs.h>
#include <strsafe.h>
#include <spoolss.h>
#include <marshalling/marshalling.h>
#include "wspool.h"
#include <wine/debug.h>
Include dependency graph for precomp.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _SPOOLER_HANDLE
 
struct  _UNIVERSAL_FONT_ID
 

Macros

#define WIN32_NO_STATUS
 
#define SPOOLER_HANDLE_SIG   'gg'
 

Typedefs

typedef struct _SPOOLER_HANDLE SPOOLER_HANDLE
 
typedef struct _SPOOLER_HANDLEPSPOOLER_HANDLE
 
typedef struct _UNIVERSAL_FONT_ID UNIVERSAL_FONT_ID
 
typedef struct _UNIVERSAL_FONT_IDPUNIVERSAL_FONT_ID
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (winspool)
 
DWORD UnicodeToAnsiInPlace (PWSTR pwszField)
 
DWORD UnicodeToAnsiZZInPlace (PWSTR pwszzField)
 
SECURITY_DESCRIPTORget_sd (SECURITY_DESCRIPTOR *sd, DWORD *size)
 
LONG WINAPI IntProtectHandle (HANDLE, BOOL)
 
BOOL WINAPI IntUnprotectHandle (HANDLE)
 
VOID UpdateTrayIcon (HANDLE hPrinter, DWORD JobId)
 
void RosConvertAnsiDevModeToUnicodeDevmode (PDEVMODEA pDevModeInput, PDEVMODEW *pDevModeOutput)
 
void RosConvertUnicodeDevModeToAnsiDevmode (PDEVMODEW pDevModeInput, PDEVMODEA pDevModeOutput)
 
BOOL WINAPI IsValidDevmodeNoSizeW (PDEVMODEW pDevmode)
 
static PWSTR AsciiToUnicode (UNICODE_STRING *usBufferPtr, LPCSTR src)
 

Variables

HANDLE hProcessHeap
 
CRITICAL_SECTION rtlCritSec
 

Macro Definition Documentation

◆ SPOOLER_HANDLE_SIG

#define SPOOLER_HANDLE_SIG   'gg'

Definition at line 32 of file precomp.h.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 11 of file precomp.h.

Typedef Documentation

◆ PSPOOLER_HANDLE

◆ PUNIVERSAL_FONT_ID

◆ SPOOLER_HANDLE

◆ UNIVERSAL_FONT_ID

Function Documentation

◆ AsciiToUnicode()

static PWSTR AsciiToUnicode ( UNICODE_STRING usBufferPtr,
LPCSTR  src 
)
inlinestatic

Definition at line 89 of file precomp.h.

90{
91 if ( (src) )
92 {
94 return usBufferPtr->Buffer;
95 }
96 usBufferPtr->Buffer = NULL; /* so that RtlFreeUnicodeString won't barf */
97 return NULL;
98}
#define NULL
Definition: types.h:112
GLenum src
Definition: glext.h:6340
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeStringFromAsciiz(_Out_ PUNICODE_STRING Destination, _In_ PCSZ Source)

◆ get_sd()

SECURITY_DESCRIPTOR * get_sd ( SECURITY_DESCRIPTOR sd,
DWORD size 
)

Definition at line 285 of file utils.c.

286{
287 PSID sid_group, sid_owner;
288 ACL *sacl, *dacl;
289 BOOL bSet = FALSE, bSetd = FALSE, bSets = FALSE;
290 PSECURITY_DESCRIPTOR absolute_sd, retsd;
291
293 {
294 return NULL;
295 }
296
298
299 if ( !GetSecurityDescriptorOwner( sd, &sid_owner, &bSet ) )
300 {
301 return NULL;
302 }
303
304 SetSecurityDescriptorOwner( &absolute_sd, sid_owner, bSet );
305
306 if ( !GetSecurityDescriptorGroup( sd, &sid_group, &bSet ) )
307 {
308 return NULL;
309 }
310
311 SetSecurityDescriptorGroup( &absolute_sd, sid_group, bSet );
312
313 if ( !GetSecurityDescriptorDacl( sd, &bSetd, &dacl, &bSet ) )
314 {
315 return NULL;
316 }
317
318 SetSecurityDescriptorDacl( &absolute_sd, bSetd, dacl, bSet );
319
320 if ( !GetSecurityDescriptorSacl( sd, &bSets, &sacl, &bSet ) )
321 {
322 return(NULL);
323 }
324
325 SetSecurityDescriptorSacl( &absolute_sd, bSets, sacl, bSet );
326
327 *size = GetSecurityDescriptorLength( &absolute_sd );
328
329 retsd = HeapAlloc( GetProcessHeap(), 0, *size );
330
331 if ( retsd )
332 {
333 if ( !MakeSelfRelativeSD( &absolute_sd, retsd, size ) )
334 {
335 HeapFree( GetProcessHeap(), 0, retsd );
336 retsd = NULL;
337 }
338 }
339
340 return retsd;
341}
#define FALSE
Definition: types.h:117
BOOL WINAPI InitializeSecurityDescriptor(PSECURITY_DESCRIPTOR pSecurityDescriptor, DWORD dwRevision)
Definition: security.c:931
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
unsigned int BOOL
Definition: ntddk_ex.h:94
GLsizeiptr size
Definition: glext.h:5919
static const WCHAR sd[]
Definition: suminfo.c:286
BOOL WINAPI IsValidSecurityDescriptor(PSECURITY_DESCRIPTOR pSecurityDescriptor)
Definition: sec.c:176
BOOL WINAPI GetSecurityDescriptorGroup(PSECURITY_DESCRIPTOR pSecurityDescriptor, PSID *pGroup, LPBOOL lpbGroupDefaulted)
Definition: sec.c:76
BOOL WINAPI SetSecurityDescriptorDacl(PSECURITY_DESCRIPTOR pSecurityDescriptor, BOOL bDaclPresent, PACL pDacl, BOOL bDaclDefaulted)
Definition: sec.c:262
BOOL WINAPI GetSecurityDescriptorSacl(PSECURITY_DESCRIPTOR pSecurityDescriptor, LPBOOL lpbSaclPresent, PACL *pSacl, LPBOOL lpbSaclDefaulted)
Definition: sec.c:146
BOOL WINAPI SetSecurityDescriptorOwner(PSECURITY_DESCRIPTOR pSecurityDescriptor, PSID pOwner, BOOL bOwnerDefaulted)
Definition: sec.c:312
BOOL WINAPI SetSecurityDescriptorSacl(PSECURITY_DESCRIPTOR pSecurityDescriptor, BOOL bSaclPresent, PACL pSacl, BOOL bSaclDefaulted)
Definition: sec.c:351
BOOL WINAPI MakeSelfRelativeSD(PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor, PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor, LPDWORD lpdwBufferLength)
Definition: sec.c:214
BOOL WINAPI GetSecurityDescriptorDacl(PSECURITY_DESCRIPTOR pSecurityDescriptor, LPBOOL lpbDaclPresent, PACL *pDacl, LPBOOL lpbDaclDefaulted)
Definition: sec.c:45
BOOL WINAPI SetSecurityDescriptorGroup(PSECURITY_DESCRIPTOR pSecurityDescriptor, PSID pGroup, BOOL bGroupDefaulted)
Definition: sec.c:288
BOOL WINAPI GetSecurityDescriptorOwner(PSECURITY_DESCRIPTOR pSecurityDescriptor, PSID *pOwner, LPBOOL lpbOwnerDefaulted)
Definition: sec.c:103
Definition: security.c:35
DWORD WINAPI GetSecurityDescriptorLength(PSECURITY_DESCRIPTOR)
#define SECURITY_DESCRIPTOR_REVISION
Definition: setypes.h:58

◆ IntProtectHandle()

LONG WINAPI IntProtectHandle ( HANDLE  hSpooler,
BOOL  Close 
)

Definition at line 107 of file utils.c.

108{
109 BOOL Bad = TRUE;
110 LONG Ret;
111 PSPOOLER_HANDLE pHandle;
112
114
116 {
117 pHandle = (PSPOOLER_HANDLE)hSpooler;
118 if ( pHandle && pHandle->Sig == SPOOLER_HANDLE_SIG )
119 {
120 Bad = FALSE; // Not bad.
121 }
122 }
124 {
125 }
126 _SEH2_END;
127
128 Ret = Bad; // Set return Level to 1 if we are BAD.
129
130 if ( Bad )
131 {
133 ERR("IPH : Printer Handle failed!\n");
134 }
135 else
136 {
137 if ( Close )
138 {
139 if ( pHandle->bShared || pHandle->cCount != 0 )
140 {
141 pHandle->bShared = TRUE;
142 Ret = 2; // Return a high level and we are shared.
143 FIXME("IPH Close : We are shared\n");
144 }
145 else
146 {
147 pHandle->bClosed = TRUE;
148 FIXME("IPH Close : closing.\n");
149 }
150 }
151 }
152
153 if ( !Ret ) // Need to be Level 0.
154 {
155 pHandle->cCount++;
156 FIXME("IPH : Count %d\n",pHandle->cCount);
157 }
158
160
161 // Return Level:
162 // 2 : Close and/or shared
163 // 1 : Failed Handle
164 // 0 : In use.
165 return Ret;
166}
#define FIXME(fmt,...)
Definition: debug.h:111
#define ERR(fmt,...)
Definition: debug.h:110
#define TRUE
Definition: types.h:120
#define SetLastError(x)
Definition: compat.h:752
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
long LONG
Definition: pedump.c:60
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:34
@ Close
Definition: sacdrv.h:268
BOOL bShared
Definition: precomp.h:47
DWORD cCount
Definition: precomp.h:52
BOOL bClosed
Definition: precomp.h:48
DWORD_PTR Sig
Definition: precomp.h:40
CRITICAL_SECTION rtlCritSec
Definition: main.c:13
struct _SPOOLER_HANDLE * PSPOOLER_HANDLE
#define SPOOLER_HANDLE_SIG
Definition: precomp.h:32
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)

Referenced by ClosePrinter(), CloseSpoolFileHandle(), CommitSpoolData(), and GetSpoolFileHandle().

◆ IntUnprotectHandle()

BOOL WINAPI IntUnprotectHandle ( HANDLE  hSpooler)

Definition at line 171 of file utils.c.

172{
173 BOOL Ret = FALSE;
174 PSPOOLER_HANDLE pHandle = (PSPOOLER_HANDLE)hSpooler;
176 if ( pHandle->bShared && --pHandle->cCount == 0 )
177 {
178 pHandle->bClosed = TRUE;
179 pHandle->bShared = FALSE;
180 Ret = TRUE;
181 }
183 FIXME("IUH : Count %d\n",pHandle->cCount);
184 if ( Ret )
185 {
186// ClosePrinterWorker( pHandle );
187 }
188 return Ret;
189}

Referenced by CloseSpoolFileHandle(), CommitSpoolData(), and GetSpoolFileHandle().

◆ IsValidDevmodeNoSizeW()

BOOL WINAPI IsValidDevmodeNoSizeW ( PDEVMODEW  pDevmode)

Definition at line 238 of file devmode.c.

239{
241 WORD wRequiredSize;
242
243 TRACE("IsValidDevmodeNoSizeW(%p)\n", pDevmode);
244
245 // Check if a Devmode was given at all.
246 if (!pDevmode)
247 goto Failure;
248
249 // If the structure has private members, the public structure must be 32-bit packed.
250 if (pDevmode->dmDriverExtra && pDevmode->dmSize % 4)
251 goto Failure;
252
253 // Now determine the minimum possible dmSize based on the given fields in dmFields.
254 wRequiredSize = FIELD_OFFSET(DEVMODEW, dmFields) + RTL_FIELD_SIZE(DEVMODEW, dmFields);
255
256 while (pTable->dwField)
257 {
258 if (pDevmode->dmFields & pTable->dwField)
259 {
260 wRequiredSize = pTable->wSize;
261 break;
262 }
263
264 pTable++;
265 }
266
267 // Verify that the value in dmSize is big enough for the used fields.
268 if (pDevmode->dmSize < wRequiredSize)
269 goto Failure;
270
271 // Check if dmDeviceName and (if used) dmFormName are null-terminated.
272 // Fix this if they aren't.
273 _FixStringW(pDevmode->dmDeviceName, sizeof(pDevmode->dmDeviceName));
274 if (pDevmode->dmFields & DM_FORMNAME)
275 _FixStringW(pDevmode->dmFormName, sizeof(pDevmode->dmFormName));
276
277 // Return success without setting the error code.
278 return TRUE;
279
280Failure:
282 return FALSE;
283}
static __inline void _FixStringW(PWSTR String, DWORD cbString)
Definition: devmode.c:116
static MINIMUM_SIZE_TABLE MinimumSizeW[]
Definition: devmode.c:57
unsigned short WORD
Definition: ntddk_ex.h:93
#define RTL_FIELD_SIZE(type, field)
Definition: kdb_expr.c:84
#define TRACE(s)
Definition: solgame.cpp:4
WCHAR dmDeviceName[CCHDEVICENAME]
Definition: wingdi.h:1617
DWORD dmFields
Definition: wingdi.h:1622
WORD dmDriverExtra
Definition: wingdi.h:1621
WCHAR dmFormName[CCHFORMNAME]
Definition: wingdi.h:1645
WORD dmSize
Definition: wingdi.h:1620
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
static const EHCI_PERIOD pTable[]
Definition: usbehci.c:29
#define ERROR_INVALID_DATA
Definition: winerror.h:116
#define DM_FORMNAME
Definition: wingdi.h:1266

Referenced by AddPrinterW(), DeviceCapabilitiesW(), DocumentPropertiesW(), QueryColorProfile(), and SetPrinterW().

◆ RosConvertAnsiDevModeToUnicodeDevmode()

void RosConvertAnsiDevModeToUnicodeDevmode ( PDEVMODEA  pDevModeInput,
PDEVMODEW pDevModeOutput 
)

Definition at line 285 of file devmode.c.

286{
287 // FIXME: This function should become ConvertAnsiDevModeToUnicodeDevmode when its parameters are known!
288
289 // Check if a pDevModeInput and pDevModeOutput are both not NULL.
290 if (!pDevModeInput || !pDevModeOutput)
291 return;
292
293 *pDevModeOutput = GdiConvertToDevmodeW(pDevModeInput);
294}
DEVMODEW *WINAPI GdiConvertToDevmodeW(const DEVMODEA *)
Definition: misc.c:969

Referenced by AddPrinterA(), DeviceCapabilitiesA(), DocumentPropertiesA(), ResetPrinterA(), and SetPrinterA().

◆ RosConvertUnicodeDevModeToAnsiDevmode()

void RosConvertUnicodeDevModeToAnsiDevmode ( PDEVMODEW  pDevModeInput,
PDEVMODEA  pDevModeOutput 
)

Definition at line 353 of file devmode.c.

354{
355 PDEVMODEA pTmp;
356
357 // FIXME: This function should become ConvertUnicodeDevModeToAnsiDevmode when its parameters are known!
358
359 // Check if a pDevModeInput and pDevModeOutput are both not NULL.
360 if (!pDevModeInput || !pDevModeOutput)
361 return;
362
363 pTmp = _ConvertToDevmodeA(pDevModeInput);
364 memcpy( pDevModeOutput, pTmp, pTmp->dmSize + pTmp->dmDriverExtra); // Copy into a Wide char (Larger) buffer.
365 HeapFree(hProcessHeap, 0, pTmp);
366}
static __inline DEVMODEA * _ConvertToDevmodeA(const DEVMODEW *dmW)
Definition: devmode.c:298
HANDLE hProcessHeap
Definition: kbswitch.c:34
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
WORD dmDriverExtra
Definition: wingdi.h:1569
WORD dmSize
Definition: wingdi.h:1568

Referenced by DocumentPropertiesA(), EnumJobsA(), EnumPrintersA(), GetJobA(), and GetPrinterA().

◆ UnicodeToAnsiInPlace()

DWORD UnicodeToAnsiInPlace ( PWSTR  pwszField)

Definition at line 28 of file utils.c.

29{
30 PSTR pszTemp;
31 DWORD cch;
32
33 /*
34 * Map the incoming Unicode pwszField string to an ANSI one here so that we can do
35 * in-place conversion. We read the Unicode input and then we write back the ANSI
36 * conversion into the same buffer for use with our GetPrinterDriverA function
37 */
38 PSTR pszField = (PSTR)pwszField;
39
40 if (!pwszField)
41 {
42 return ERROR_SUCCESS;
43 }
44
45 cch = wcslen(pwszField);
46 if (cch == 0)
47 {
48 return ERROR_SUCCESS;
49 }
50
51 pszTemp = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
52 if (!pszTemp)
53 {
54 ERR("HeapAlloc failed!\n");
56 }
57
58 WideCharToMultiByte(CP_ACP, 0, pwszField, -1, pszTemp, cch + 1, NULL, NULL);
59 StringCchCopyA(pszField, cch + 1, pszTemp);
60
61 HeapFree(hProcessHeap, 0, pszTemp);
62
63 return ERROR_SUCCESS;
64}
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define ERROR_SUCCESS
Definition: deptool.c:10
#define CP_ACP
Definition: compat.h:109
#define WideCharToMultiByte
Definition: compat.h:111
unsigned long DWORD
Definition: ntddk_ex.h:95
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
signed char * PSTR
Definition: retypes.h:7
static DWORD DWORD void LPSTR DWORD cch
Definition: str.c:202
STRSAFEAPI StringCchCopyA(STRSAFE_LPSTR pszDest, size_t cchDest, STRSAFE_LPCSTR pszSrc)
Definition: strsafe.h:145
char CHAR
Definition: xmlstorage.h:175

Referenced by AddJobA(), EnumFormsA(), EnumJobsA(), EnumPrinterDriversA(), GetFormA(), GetJobA(), and GetPrinterDriverA().

◆ UnicodeToAnsiZZInPlace()

DWORD UnicodeToAnsiZZInPlace ( PWSTR  pwszzField)

Definition at line 78 of file utils.c.

79{
80 PSTR pszTemp;
81 INT len, lenW;
82 PSTR pszField = (PSTR)pwszzField;
83
84 lenW = multi_sz_lenW(pwszzField);
85 if (lenW == 0)
86 {
87 return ERROR_SUCCESS;
88 }
89
90 len = WideCharToMultiByte(CP_ACP, 0, pwszzField, lenW, NULL, 0, NULL, NULL);
91
92 pszTemp = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
93
94 WideCharToMultiByte(CP_ACP, 0, pwszzField, lenW, pszTemp, len, NULL, NULL);
95
96 StringCchCopyA(pszField, len, pszTemp);
97
98 HeapFree(hProcessHeap, 0, pszTemp);
99
100 return ERROR_SUCCESS;
101}
GLenum GLsizei len
Definition: glext.h:6722
int32_t INT
Definition: typedefs.h:58
static int multi_sz_lenW(const WCHAR *str)
Definition: utils.c:66
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by EnumPrinterDriversA(), and GetPrinterDriverA().

◆ UpdateTrayIcon()

VOID UpdateTrayIcon ( HANDLE  hPrinter,
DWORD  JobId 
)

Definition at line 344 of file utils.c.

345{
346 PSPOOLER_HANDLE pHandle = (PSPOOLER_HANDLE)hPrinter;
349 DWORD cbNeeded;
350 PPfpSHChangeNotify fpFunction;
351
352 pHandle->bTrayIcon = TRUE;
353
354 spji.JobId = JobId;
355
356 if (!GetPrinterW( hPrinter, 1, (PBYTE)&pi1w, MAX_GETPRINTER_SIZE, &cbNeeded) )
357 {
358 ERR("UpdateTrayIcon : GetPrinterW cbNeeded %d\n");
359 return;
360 }
361
362 if ( hShell32 == (HMODULE)-1 )
363 {
364 hShell32 = LoadLibraryW(L"shell32.dll");
365 }
366
367 if ( hShell32 )
368 {
369 fpFunction = (PPfpSHChangeNotify)GetProcAddress( hShell32, "SHChangeNotify" );
370
371 if ( fpFunction )
372 {
373 fpFunction( SHCNE_CREATE, (SHCNF_FLUSHNOWAIT|SHCNF_FLUSH|SHCNF_PRINTJOBW), pi1w->pName , &spji );
374 }
375 }
376 else
377 {
378 ERR("UpdateTrayIcon : No Shell32!\n");
379 }
380}
#define GetProcAddress(x, y)
Definition: compat.h:753
#define LoadLibraryW(x)
Definition: compat.h:747
#define L(x)
Definition: ntvdm.h:50
BYTE * PBYTE
Definition: pedump.c:66
#define SHCNE_CREATE
Definition: shlobj.h:1743
#define SHCNF_FLUSH
Definition: shlobj.h:1780
#define SHCNF_FLUSHNOWAIT
Definition: shlobj.h:1781
BOOL bTrayIcon
Definition: precomp.h:45
#define SHCNF_PRINTJOBW
Definition: undocshell.h:122
void(WINAPI * PPfpSHChangeNotify)(LONG wEventId, UINT uFlags, LPCVOID dwItem1, LPCVOID dwItem2)
Definition: utils.c:15
static HMODULE hShell32
Definition: utils.c:17
#define MAX_GETPRINTER_SIZE
Definition: utils.c:14
WINBOOL WINAPI GetPrinterW(HANDLE hPrinter, DWORD Level, LPBYTE pPrinter, DWORD cbBuf, LPDWORD pcbNeeded)
Definition: printers.c:2504

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( winspool  )

Variable Documentation

◆ hProcessHeap

HANDLE hProcessHeap
extern

◆ rtlCritSec

CRITICAL_SECTION rtlCritSec
extern

Definition at line 13 of file main.c.

Referenced by DllMain(), IntProtectHandle(), and IntUnprotectHandle().