2015-05-06 12:47:20 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Print Spooler Service
|
2017-09-29 17:18:19 +00:00
|
|
|
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
|
2015-05-06 12:47:20 +00:00
|
|
|
* PURPOSE: Main functions
|
2017-09-29 17:18:19 +00:00
|
|
|
* COPYRIGHT: Copyright 2015 Colin Finck (colin@reactos.org)
|
2015-05-06 12:47:20 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precomp.h"
|
|
|
|
|
|
|
|
SERVICE_STATUS_HANDLE hServiceStatus;
|
|
|
|
SERVICE_STATUS ServiceStatus;
|
|
|
|
WCHAR wszServiceName[] = L"Spooler";
|
|
|
|
|
|
|
|
static void
|
|
|
|
_UpdateServiceStatus(DWORD dwNewStatus, DWORD dwCheckPoint)
|
|
|
|
{
|
|
|
|
ServiceStatus.dwCheckPoint = dwCheckPoint;
|
|
|
|
ServiceStatus.dwCurrentState = dwNewStatus;
|
|
|
|
SetServiceStatus(hServiceStatus, &ServiceStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD WINAPI
|
|
|
|
_ServiceControlHandlerEx(DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext)
|
|
|
|
{
|
|
|
|
switch (dwControl)
|
|
|
|
{
|
|
|
|
case SERVICE_CONTROL_SHUTDOWN:
|
|
|
|
case SERVICE_CONTROL_STOP:
|
|
|
|
_UpdateServiceStatus(SERVICE_STOP_PENDING, 1);
|
|
|
|
RpcMgmtStopServerListening(NULL);
|
|
|
|
_UpdateServiceStatus(SERVICE_STOPPED, 0);
|
|
|
|
return NO_ERROR;
|
|
|
|
|
|
|
|
case SERVICE_CONTROL_INTERROGATE:
|
|
|
|
return NO_ERROR;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static VOID WINAPI
|
|
|
|
_ServiceMain(DWORD dwArgc, LPWSTR* lpszArgv)
|
|
|
|
{
|
|
|
|
HANDLE hThread;
|
|
|
|
|
|
|
|
UNREFERENCED_PARAMETER(dwArgc);
|
|
|
|
UNREFERENCED_PARAMETER(lpszArgv);
|
|
|
|
|
|
|
|
// Register our service for control
|
|
|
|
hServiceStatus = RegisterServiceCtrlHandlerExW(wszServiceName, _ServiceControlHandlerEx, NULL);
|
|
|
|
|
|
|
|
// Report initial SERVICE_START_PENDING status
|
|
|
|
ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
|
|
|
|
ServiceStatus.dwServiceSpecificExitCode = 0;
|
|
|
|
ServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
|
|
|
|
ServiceStatus.dwWaitHint = 4000;
|
|
|
|
ServiceStatus.dwWin32ExitCode = NO_ERROR;
|
|
|
|
_UpdateServiceStatus(SERVICE_START_PENDING, 0);
|
|
|
|
|
|
|
|
// Create a thread for serving RPC requests
|
2015-06-24 16:20:13 +00:00
|
|
|
hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)LrpcThreadProc, NULL, 0, NULL);
|
Time to commit some Work-In-Progress stuff before my diff gets too large..
[LOCALSPL]
- Begin work on the Local Spooler. Return a structure with function pointers in InitializePrintProvidor.
- Design and document internal structures for managing LocalSpl Handles, Printer Handles, Printers, Print Jobs and Print Processors.
Manage Printers and Print Processors in Generic Tables, with one Job Queue per Printer managed as a Doubly Linked List.
- Implement LocalOpenPrinter, LocalEnumPrintProcessorDatatypes, LocalEnumPrintProcessors, LocalGetPrintProcessorDirectory, with focus on catching all corner cases.
Currently working on LocalStartDocPrinter.
- Build upon the documentation at http://www.undocprint.org/formats/winspool/shd to read and write .SHD files.
[WINPRINT]
Begin work on the Standard Print Processor. Implement EnumPrintProcessorDatatypesW.
[WINSPOOL_APITEST]
Add an API Test for winspool.drv, currently testing some corner cases of ClosePrinter, EnumPrintProcessorDatatypesW, GetPrintProcessorDirectoryW, OpenPrinterW, StartDocPrinterW.
TODO: Find a way to actually test the localspl.dll functions instead of only winspool.drv. This DLL doesn't like to be tested standalone under Windows, e.g. without being used through spoolsv/spoolss.
[SPOOLSS]
Implement InitializeRouter by calling the InitializePrintProvidor function of localspl there.
This function should later also initialize further Print Providers.
[SPOOLSV]
Call InitializeRouter when starting up the service.
[WINSPOOL]
Add dummy functions for EnumPrintProcessorDatatypesA/EnumPrintProcessorDatatypesW.
[All modules]
Fix printf format specifiers for errors (%lu) and statuses (%ld).
svn path=/branches/colins-printing-for-freedom/; revision=67847
2015-05-22 15:29:07 +00:00
|
|
|
if (!hThread)
|
2015-05-06 12:47:20 +00:00
|
|
|
{
|
Time to commit some Work-In-Progress stuff before my diff gets too large..
[LOCALSPL]
- Begin work on the Local Spooler. Return a structure with function pointers in InitializePrintProvidor.
- Design and document internal structures for managing LocalSpl Handles, Printer Handles, Printers, Print Jobs and Print Processors.
Manage Printers and Print Processors in Generic Tables, with one Job Queue per Printer managed as a Doubly Linked List.
- Implement LocalOpenPrinter, LocalEnumPrintProcessorDatatypes, LocalEnumPrintProcessors, LocalGetPrintProcessorDirectory, with focus on catching all corner cases.
Currently working on LocalStartDocPrinter.
- Build upon the documentation at http://www.undocprint.org/formats/winspool/shd to read and write .SHD files.
[WINPRINT]
Begin work on the Standard Print Processor. Implement EnumPrintProcessorDatatypesW.
[WINSPOOL_APITEST]
Add an API Test for winspool.drv, currently testing some corner cases of ClosePrinter, EnumPrintProcessorDatatypesW, GetPrintProcessorDirectoryW, OpenPrinterW, StartDocPrinterW.
TODO: Find a way to actually test the localspl.dll functions instead of only winspool.drv. This DLL doesn't like to be tested standalone under Windows, e.g. without being used through spoolsv/spoolss.
[SPOOLSS]
Implement InitializeRouter by calling the InitializePrintProvidor function of localspl there.
This function should later also initialize further Print Providers.
[SPOOLSV]
Call InitializeRouter when starting up the service.
[WINSPOOL]
Add dummy functions for EnumPrintProcessorDatatypesA/EnumPrintProcessorDatatypesW.
[All modules]
Fix printf format specifiers for errors (%lu) and statuses (%ld).
svn path=/branches/colins-printing-for-freedom/; revision=67847
2015-05-22 15:29:07 +00:00
|
|
|
ERR("CreateThread failed with error %u!\n", GetLastError());
|
|
|
|
_UpdateServiceStatus(SERVICE_STOPPED, 0);
|
|
|
|
return;
|
2015-05-06 12:47:20 +00:00
|
|
|
}
|
Time to commit some Work-In-Progress stuff before my diff gets too large..
[LOCALSPL]
- Begin work on the Local Spooler. Return a structure with function pointers in InitializePrintProvidor.
- Design and document internal structures for managing LocalSpl Handles, Printer Handles, Printers, Print Jobs and Print Processors.
Manage Printers and Print Processors in Generic Tables, with one Job Queue per Printer managed as a Doubly Linked List.
- Implement LocalOpenPrinter, LocalEnumPrintProcessorDatatypes, LocalEnumPrintProcessors, LocalGetPrintProcessorDirectory, with focus on catching all corner cases.
Currently working on LocalStartDocPrinter.
- Build upon the documentation at http://www.undocprint.org/formats/winspool/shd to read and write .SHD files.
[WINPRINT]
Begin work on the Standard Print Processor. Implement EnumPrintProcessorDatatypesW.
[WINSPOOL_APITEST]
Add an API Test for winspool.drv, currently testing some corner cases of ClosePrinter, EnumPrintProcessorDatatypesW, GetPrintProcessorDirectoryW, OpenPrinterW, StartDocPrinterW.
TODO: Find a way to actually test the localspl.dll functions instead of only winspool.drv. This DLL doesn't like to be tested standalone under Windows, e.g. without being used through spoolsv/spoolss.
[SPOOLSS]
Implement InitializeRouter by calling the InitializePrintProvidor function of localspl there.
This function should later also initialize further Print Providers.
[SPOOLSV]
Call InitializeRouter when starting up the service.
[WINSPOOL]
Add dummy functions for EnumPrintProcessorDatatypesA/EnumPrintProcessorDatatypesW.
[All modules]
Fix printf format specifiers for errors (%lu) and statuses (%ld).
svn path=/branches/colins-printing-for-freedom/; revision=67847
2015-05-22 15:29:07 +00:00
|
|
|
|
|
|
|
// We don't need the thread handle. Keeping it open blocks the thread from terminating.
|
|
|
|
CloseHandle(hThread);
|
|
|
|
|
|
|
|
// Initialize the routing layer in spoolss.dll
|
|
|
|
if (!InitializeRouter(hServiceStatus))
|
2015-05-06 12:47:20 +00:00
|
|
|
{
|
Time to commit some Work-In-Progress stuff before my diff gets too large..
[LOCALSPL]
- Begin work on the Local Spooler. Return a structure with function pointers in InitializePrintProvidor.
- Design and document internal structures for managing LocalSpl Handles, Printer Handles, Printers, Print Jobs and Print Processors.
Manage Printers and Print Processors in Generic Tables, with one Job Queue per Printer managed as a Doubly Linked List.
- Implement LocalOpenPrinter, LocalEnumPrintProcessorDatatypes, LocalEnumPrintProcessors, LocalGetPrintProcessorDirectory, with focus on catching all corner cases.
Currently working on LocalStartDocPrinter.
- Build upon the documentation at http://www.undocprint.org/formats/winspool/shd to read and write .SHD files.
[WINPRINT]
Begin work on the Standard Print Processor. Implement EnumPrintProcessorDatatypesW.
[WINSPOOL_APITEST]
Add an API Test for winspool.drv, currently testing some corner cases of ClosePrinter, EnumPrintProcessorDatatypesW, GetPrintProcessorDirectoryW, OpenPrinterW, StartDocPrinterW.
TODO: Find a way to actually test the localspl.dll functions instead of only winspool.drv. This DLL doesn't like to be tested standalone under Windows, e.g. without being used through spoolsv/spoolss.
[SPOOLSS]
Implement InitializeRouter by calling the InitializePrintProvidor function of localspl there.
This function should later also initialize further Print Providers.
[SPOOLSV]
Call InitializeRouter when starting up the service.
[WINSPOOL]
Add dummy functions for EnumPrintProcessorDatatypesA/EnumPrintProcessorDatatypesW.
[All modules]
Fix printf format specifiers for errors (%lu) and statuses (%ld).
svn path=/branches/colins-printing-for-freedom/; revision=67847
2015-05-22 15:29:07 +00:00
|
|
|
ERR("InitializeRouter failed with error %lu!\n", GetLastError());
|
2015-05-06 12:47:20 +00:00
|
|
|
_UpdateServiceStatus(SERVICE_STOPPED, 0);
|
Time to commit some Work-In-Progress stuff before my diff gets too large..
[LOCALSPL]
- Begin work on the Local Spooler. Return a structure with function pointers in InitializePrintProvidor.
- Design and document internal structures for managing LocalSpl Handles, Printer Handles, Printers, Print Jobs and Print Processors.
Manage Printers and Print Processors in Generic Tables, with one Job Queue per Printer managed as a Doubly Linked List.
- Implement LocalOpenPrinter, LocalEnumPrintProcessorDatatypes, LocalEnumPrintProcessors, LocalGetPrintProcessorDirectory, with focus on catching all corner cases.
Currently working on LocalStartDocPrinter.
- Build upon the documentation at http://www.undocprint.org/formats/winspool/shd to read and write .SHD files.
[WINPRINT]
Begin work on the Standard Print Processor. Implement EnumPrintProcessorDatatypesW.
[WINSPOOL_APITEST]
Add an API Test for winspool.drv, currently testing some corner cases of ClosePrinter, EnumPrintProcessorDatatypesW, GetPrintProcessorDirectoryW, OpenPrinterW, StartDocPrinterW.
TODO: Find a way to actually test the localspl.dll functions instead of only winspool.drv. This DLL doesn't like to be tested standalone under Windows, e.g. without being used through spoolsv/spoolss.
[SPOOLSS]
Implement InitializeRouter by calling the InitializePrintProvidor function of localspl there.
This function should later also initialize further Print Providers.
[SPOOLSV]
Call InitializeRouter when starting up the service.
[WINSPOOL]
Add dummy functions for EnumPrintProcessorDatatypesA/EnumPrintProcessorDatatypesW.
[All modules]
Fix printf format specifiers for errors (%lu) and statuses (%ld).
svn path=/branches/colins-printing-for-freedom/; revision=67847
2015-05-22 15:29:07 +00:00
|
|
|
return;
|
2015-05-06 12:47:20 +00:00
|
|
|
}
|
Time to commit some Work-In-Progress stuff before my diff gets too large..
[LOCALSPL]
- Begin work on the Local Spooler. Return a structure with function pointers in InitializePrintProvidor.
- Design and document internal structures for managing LocalSpl Handles, Printer Handles, Printers, Print Jobs and Print Processors.
Manage Printers and Print Processors in Generic Tables, with one Job Queue per Printer managed as a Doubly Linked List.
- Implement LocalOpenPrinter, LocalEnumPrintProcessorDatatypes, LocalEnumPrintProcessors, LocalGetPrintProcessorDirectory, with focus on catching all corner cases.
Currently working on LocalStartDocPrinter.
- Build upon the documentation at http://www.undocprint.org/formats/winspool/shd to read and write .SHD files.
[WINPRINT]
Begin work on the Standard Print Processor. Implement EnumPrintProcessorDatatypesW.
[WINSPOOL_APITEST]
Add an API Test for winspool.drv, currently testing some corner cases of ClosePrinter, EnumPrintProcessorDatatypesW, GetPrintProcessorDirectoryW, OpenPrinterW, StartDocPrinterW.
TODO: Find a way to actually test the localspl.dll functions instead of only winspool.drv. This DLL doesn't like to be tested standalone under Windows, e.g. without being used through spoolsv/spoolss.
[SPOOLSS]
Implement InitializeRouter by calling the InitializePrintProvidor function of localspl there.
This function should later also initialize further Print Providers.
[SPOOLSV]
Call InitializeRouter when starting up the service.
[WINSPOOL]
Add dummy functions for EnumPrintProcessorDatatypesA/EnumPrintProcessorDatatypesW.
[All modules]
Fix printf format specifiers for errors (%lu) and statuses (%ld).
svn path=/branches/colins-printing-for-freedom/; revision=67847
2015-05-22 15:29:07 +00:00
|
|
|
|
|
|
|
// We're alive!
|
|
|
|
_UpdateServiceStatus(SERVICE_RUNNING, 0);
|
2015-05-06 12:47:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
wmain(int argc, WCHAR* argv[])
|
|
|
|
{
|
|
|
|
SERVICE_TABLE_ENTRYW ServiceTable[] =
|
|
|
|
{
|
|
|
|
{wszServiceName, _ServiceMain},
|
|
|
|
{NULL, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
UNREFERENCED_PARAMETER(argc);
|
|
|
|
UNREFERENCED_PARAMETER(argv);
|
|
|
|
|
|
|
|
StartServiceCtrlDispatcherW(ServiceTable);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|