Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

221 lines
4.2 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. clusspl.c
  5. Abstract:
  6. Cluster code support.
  7. Author:
  8. Albert Ting (AlbertT) 1-Oct-96
  9. Revision History:
  10. --*/
  11. #include <precomp.h>
  12. #pragma hdrstop
  13. #include "local.h"
  14. #include "clusrout.h"
  15. typedef struct _CLUSTERHANDLE {
  16. DWORD signature;
  17. LPPROVIDOR pProvidor;
  18. HANDLE hCluster;
  19. } CLUSTERHANDLE, *PCLUSTERHANDLE;
  20. BOOL
  21. ClusterSplOpen(
  22. LPCTSTR pszServer,
  23. LPCTSTR pszResource,
  24. PHANDLE phSpooler,
  25. LPCTSTR pszName,
  26. LPCTSTR pszAddress
  27. )
  28. /*++
  29. Routine Description:
  30. Open a hSpooler resource by searching the providers.
  31. Arguments:
  32. pszServer - Server that should be opened. Currently only NULL
  33. is supported.
  34. pszResource - Name of the resource to open.
  35. phSpooler - Receives new spooler handle.
  36. pszName - Name that the resource should recognize. Comma delimted.
  37. pszAddress - Tcp/ip address the resource should recognize. Comma delimited.
  38. Return Value:
  39. TRUE - Success
  40. FALSE - Failure, GetLastError() set.
  41. --*/
  42. {
  43. LPPROVIDOR pProvidor;
  44. DWORD dwFirstSignificantError = ERROR_INVALID_NAME;
  45. PCLUSTERHANDLE pClusterHandle;
  46. LPWSTR pPrinterName;
  47. DWORD dwStatus;
  48. HANDLE hCluster;
  49. WaitForSpoolerInitialization();
  50. if( pszServer ){
  51. SetLastError(ERROR_INVALID_PARAMETER);
  52. return FALSE;
  53. }
  54. pClusterHandle = AllocSplMem( sizeof( CLUSTERHANDLE ));
  55. if (!pClusterHandle) {
  56. DBGMSG( DBG_WARNING, ("Failed to alloc cluster handle."));
  57. return FALSE;
  58. }
  59. pProvidor = pLocalProvidor;
  60. *phSpooler = NULL;
  61. while (pProvidor) {
  62. dwStatus = (*pProvidor->PrintProvidor.fpClusterSplOpen)(
  63. pszServer,
  64. pszResource,
  65. &hCluster,
  66. pszName,
  67. pszAddress);
  68. if ( dwStatus == ROUTER_SUCCESS ) {
  69. pClusterHandle->signature = CLUSTERHANDLE_SIGNATURE;
  70. pClusterHandle->pProvidor = pProvidor;
  71. pClusterHandle->hCluster = hCluster;
  72. *phSpooler = (HANDLE)pClusterHandle;
  73. return TRUE;
  74. } else {
  75. UpdateSignificantError( GetLastError(),
  76. &dwFirstSignificantError );
  77. }
  78. pProvidor = pProvidor->pNext;
  79. }
  80. FreeSplMem(pClusterHandle);
  81. UpdateSignificantError( ERROR_INVALID_PRINTER_NAME,
  82. &dwFirstSignificantError );
  83. SetLastError(dwFirstSignificantError);
  84. return FALSE;
  85. }
  86. BOOL
  87. ClusterSplClose(
  88. HANDLE hSpooler
  89. )
  90. /*++
  91. Routine Description:
  92. Closes the spooler handle.
  93. Arguments:
  94. hSpooler - hSpooler to close.
  95. Return Value:
  96. TRUE - Success
  97. FALSE - Failure. LastError set.
  98. Note: What happens if this fails? Should the user try again.
  99. --*/
  100. {
  101. PCLUSTERHANDLE pClusterHandle=(PCLUSTERHANDLE)hSpooler;
  102. EnterRouterSem();
  103. if (!pClusterHandle ||
  104. pClusterHandle->signature != CLUSTERHANDLE_SIGNATURE) {
  105. LeaveRouterSem();
  106. SetLastError(ERROR_INVALID_HANDLE);
  107. return FALSE;
  108. }
  109. LeaveRouterSem();
  110. if ((*pClusterHandle->pProvidor->PrintProvidor.fpClusterSplClose)(
  111. pClusterHandle->hCluster)) {
  112. FreeSplMem( pClusterHandle );
  113. return TRUE;
  114. }
  115. return FALSE;
  116. }
  117. BOOL
  118. ClusterSplIsAlive(
  119. HANDLE hSpooler
  120. )
  121. /*++
  122. Routine Description:
  123. Determines whether the spooler is alive.
  124. Arguments:
  125. hSpooler - Spooler to check.
  126. Return Value:
  127. TRUE - Alive
  128. FALSE - Dead, LastError set.
  129. --*/
  130. {
  131. PCLUSTERHANDLE pClusterHandle=(PCLUSTERHANDLE)hSpooler;
  132. if (!pClusterHandle ||
  133. pClusterHandle->signature != CLUSTERHANDLE_SIGNATURE) {
  134. SetLastError(ERROR_INVALID_HANDLE);
  135. return FALSE;
  136. }
  137. return (*pClusterHandle->pProvidor->PrintProvidor.fpClusterSplIsAlive)(
  138. pClusterHandle->hCluster );
  139. }