2015-07-22 17:59:46 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Spooler API
|
2017-09-29 17:18:19 +00:00
|
|
|
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
|
2015-07-22 17:59:46 +00:00
|
|
|
* PURPOSE: Functions related to Print Providers
|
2017-12-09 11:00:09 +00:00
|
|
|
* COPYRIGHT: Copyright 2015-2017 Colin Finck (colin@reactos.org)
|
2015-07-22 17:59:46 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precomp.h"
|
|
|
|
|
2017-12-09 12:35:42 +00:00
|
|
|
BOOL WINAPI
|
|
|
|
AddPrintProvidorA(PSTR pName, DWORD Level, PBYTE pProviderInfo)
|
|
|
|
{
|
2020-08-04 02:07:58 +00:00
|
|
|
LPWSTR nameW = NULL;
|
|
|
|
PROVIDOR_INFO_1W pi1W;
|
|
|
|
PROVIDOR_INFO_2W pi2W;
|
|
|
|
DWORD len;
|
|
|
|
BOOL res;
|
|
|
|
PBYTE pPI = NULL;
|
|
|
|
|
2017-12-09 12:35:42 +00:00
|
|
|
TRACE("AddPrintProvidorA(%s, %lu, %p)\n", pName, Level, pProviderInfo);
|
2020-08-04 02:07:58 +00:00
|
|
|
|
|
|
|
ZeroMemory(&pi1W, sizeof(PROVIDOR_INFO_1W));
|
|
|
|
pi2W.pOrder = NULL;
|
|
|
|
|
|
|
|
switch (Level)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
PROVIDOR_INFO_1A *pi1A = (PROVIDOR_INFO_1A*)pProviderInfo;
|
|
|
|
if (pi1A->pName)
|
|
|
|
{
|
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, pi1A->pName, -1, NULL, 0);
|
|
|
|
pi1W.pName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, pi1A->pName, -1, pi1W.pName, len);
|
|
|
|
}
|
|
|
|
if (pi1A->pEnvironment)
|
|
|
|
{
|
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, pi1A->pEnvironment, -1, NULL, 0);
|
|
|
|
pi1W.pEnvironment = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, pi1A->pEnvironment, -1, pi1W.pEnvironment, len);
|
|
|
|
}
|
|
|
|
if (pi1A->pDLLName)
|
|
|
|
{
|
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, pi1A->pDLLName, -1, NULL, 0);
|
|
|
|
pi1W.pDLLName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, pi1A->pDLLName, -1, pi1W.pDLLName, len);
|
|
|
|
}
|
|
|
|
pPI = (PBYTE)&pi1W;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
PROVIDOR_INFO_2A *pi2A = (PROVIDOR_INFO_2A*)pProviderInfo;
|
|
|
|
if (pi2A->pOrder)
|
|
|
|
{
|
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, pi2A->pOrder, -1, NULL, 0);
|
|
|
|
pi2W.pOrder = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, pi2A->pOrder, -1, pi2W.pOrder, len);
|
|
|
|
}
|
|
|
|
pPI = (PBYTE)&pi2W;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
SetLastError(ERROR_INVALID_LEVEL);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pName)
|
|
|
|
{
|
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, pName, -1, NULL, 0);
|
|
|
|
nameW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, pName, -1, nameW, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
res = AddPrintProvidorW( nameW, Level, pPI );
|
|
|
|
|
|
|
|
if (pName) HeapFree(GetProcessHeap(), 0, nameW);
|
|
|
|
if (pi1W.pName) HeapFree(GetProcessHeap(), 0, pi1W.pName);
|
|
|
|
if (pi1W.pEnvironment) HeapFree(GetProcessHeap(), 0, pi1W.pEnvironment);
|
|
|
|
if (pi1W.pDLLName) HeapFree(GetProcessHeap(), 0, pi1W.pDLLName);
|
|
|
|
if (pi2W.pOrder) HeapFree(GetProcessHeap(), 0, pi2W.pOrder);
|
|
|
|
|
|
|
|
return res;
|
2017-12-09 12:35:42 +00:00
|
|
|
}
|
|
|
|
|
2015-07-22 17:59:46 +00:00
|
|
|
BOOL WINAPI
|
|
|
|
AddPrintProvidorW(PWSTR pName, DWORD Level, PBYTE pProviderInfo)
|
|
|
|
{
|
2020-08-04 02:07:58 +00:00
|
|
|
DWORD dwErrorCode;
|
|
|
|
WINSPOOL_PROVIDOR_CONTAINER ProvidorContainer;
|
|
|
|
|
2017-12-09 11:00:09 +00:00
|
|
|
TRACE("AddPrintProvidorW(%S, %lu, %p)\n", pName, Level, pProviderInfo);
|
2020-08-04 02:07:58 +00:00
|
|
|
|
|
|
|
if ((Level < 1) || (Level > 2))
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_LEVEL);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProvidorContainer.ProvidorInfo.pProvidorInfo1 = (WINSPOOL_PROVIDOR_INFO_1*)pProviderInfo;
|
|
|
|
ProvidorContainer.Level = Level;
|
|
|
|
|
|
|
|
RpcTryExcept
|
|
|
|
{
|
|
|
|
dwErrorCode = _RpcAddPrintProvidor( pName, &ProvidorContainer );
|
|
|
|
}
|
|
|
|
RpcExcept(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
dwErrorCode = RpcExceptionCode();
|
|
|
|
ERR("_RpcEnumPorts failed with exception code %lu!\n", dwErrorCode);
|
|
|
|
}
|
|
|
|
RpcEndExcept;
|
|
|
|
|
|
|
|
SetLastError(dwErrorCode);
|
|
|
|
return (dwErrorCode == ERROR_SUCCESS);
|
2015-07-22 17:59:46 +00:00
|
|
|
}
|
|
|
|
|
2017-12-09 12:35:42 +00:00
|
|
|
BOOL WINAPI
|
|
|
|
DeletePrintProvidorA(PSTR pName, PSTR pEnvironment, PSTR pPrintProviderName)
|
|
|
|
{
|
2020-08-04 02:07:58 +00:00
|
|
|
UNICODE_STRING NameW, EnvW, ProviderW;
|
|
|
|
BOOL Ret;
|
|
|
|
|
2017-12-09 12:35:42 +00:00
|
|
|
TRACE("DeletePrintProvidorW(%s, %s, %s)\n", pName, pEnvironment, pPrintProviderName);
|
2020-08-04 02:07:58 +00:00
|
|
|
|
|
|
|
AsciiToUnicode(&NameW, pName);
|
|
|
|
AsciiToUnicode(&EnvW, pEnvironment);
|
|
|
|
AsciiToUnicode(&ProviderW, pPrintProviderName);
|
|
|
|
|
|
|
|
Ret = DeletePrintProvidorW(NameW.Buffer, EnvW.Buffer, ProviderW.Buffer);
|
|
|
|
|
|
|
|
RtlFreeUnicodeString(&ProviderW);
|
|
|
|
RtlFreeUnicodeString(&EnvW);
|
|
|
|
RtlFreeUnicodeString(&NameW);
|
|
|
|
|
|
|
|
return Ret;
|
2017-12-09 12:35:42 +00:00
|
|
|
}
|
|
|
|
|
2015-07-22 17:59:46 +00:00
|
|
|
BOOL WINAPI
|
|
|
|
DeletePrintProvidorW(PWSTR pName, PWSTR pEnvironment, PWSTR pPrintProviderName)
|
|
|
|
{
|
2020-08-04 02:07:58 +00:00
|
|
|
DWORD dwErrorCode;
|
|
|
|
|
2017-12-09 11:00:09 +00:00
|
|
|
TRACE("DeletePrintProvidorW(%S, %S, %S)\n", pName, pEnvironment, pPrintProviderName);
|
2020-08-04 02:07:58 +00:00
|
|
|
|
|
|
|
RpcTryExcept
|
|
|
|
{
|
|
|
|
dwErrorCode = _RpcDeletePrintProvidor( pName, pEnvironment, pPrintProviderName );
|
|
|
|
}
|
|
|
|
RpcExcept(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
dwErrorCode = RpcExceptionCode();
|
|
|
|
ERR("_RpcEnumPorts failed with exception code %lu!\n", dwErrorCode);
|
|
|
|
}
|
|
|
|
RpcEndExcept;
|
|
|
|
|
|
|
|
SetLastError(dwErrorCode);
|
|
|
|
return (dwErrorCode == ERROR_SUCCESS);
|
2015-07-22 17:59:46 +00:00
|
|
|
}
|