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.

237 lines
5.5 KiB

  1. /*++
  2. Copyright (c) 1990-1994 Microsoft Corporation
  3. All rights reserved
  4. Module Name:
  5. Change.c
  6. Abstract:
  7. Handles implementation for WaitForPrinterChange and related apis.
  8. FindFirstPrinterChangeNotification
  9. FindClosePrinterChangeNotification
  10. RefreshPrinterChangeNotification
  11. Author:
  12. Albert Ting (AlbertT) 24-Apr-94
  13. Environment:
  14. User Mode -Win32
  15. Revision History:
  16. --*/
  17. #include <precomp.h>
  18. #pragma hdrstop
  19. BOOL
  20. RemoteFindFirstPrinterChangeNotification(
  21. HANDLE hPrinter,
  22. DWORD fdwFlags,
  23. DWORD fdwOptions,
  24. HANDLE hNotify,
  25. PDWORD pfdwStatus,
  26. PVOID pvReserved0,
  27. PVOID pvReserved1);
  28. BOOL
  29. RemoteFindClosePrinterChangeNotification(
  30. HANDLE hPrinter);
  31. BOOL
  32. RemoteFindFirstPrinterChangeNotification(
  33. HANDLE hPrinter,
  34. DWORD fdwFlags,
  35. DWORD fdwOptions,
  36. HANDLE hNotify,
  37. PDWORD pfdwStatus,
  38. PVOID pvReserved0,
  39. PVOID pvReserved1)
  40. {
  41. BOOL bReturnValue = TRUE;
  42. PWSPOOL pSpool = (PWSPOOL)hPrinter;
  43. VALIDATEW32HANDLE( pSpool );
  44. SPLASSERT( !*pfdwStatus );
  45. if (bReturnValue = BoolFromHResult(AllowRemoteCalls()))
  46. {
  47. if( !(pSpool->Status & WSPOOL_STATUS_NOTIFY) ){
  48. if( pSpool->Type == SJ_WIN32HANDLE ){
  49. DWORD dwStatus;
  50. SYNCRPCHANDLE( pSpool );
  51. dwStatus = CallRouterFindFirstPrinterChangeNotification(
  52. pSpool->RpcHandle,
  53. fdwFlags,
  54. fdwOptions,
  55. hNotify,
  56. pvReserved0);
  57. switch( dwStatus ){
  58. case RPC_S_SERVER_UNAVAILABLE:
  59. //
  60. // Drop into polling mode. This can happen if the
  61. // server service on the client is disabled.
  62. //
  63. *pfdwStatus = PRINTER_NOTIFY_STATUS_ENDPOINT |
  64. PRINTER_NOTIFY_STATUS_POLL;
  65. pSpool->Status |= WSPOOL_STATUS_NOTIFY_POLL;
  66. DBGMSG( DBG_WARNING, ( "RemoteFFPCN: Dropping into poll mode.\n" ));
  67. break;
  68. case ERROR_SUCCESS:
  69. //
  70. // Using regular notification system; not polling.
  71. //
  72. pSpool->Status &= ~WSPOOL_STATUS_NOTIFY_POLL;
  73. break;
  74. default:
  75. SetLastError(dwStatus);
  76. bReturnValue = FALSE;
  77. break;
  78. }
  79. } else {
  80. bReturnValue = LMFindFirstPrinterChangeNotification(
  81. hPrinter,
  82. fdwFlags,
  83. fdwOptions,
  84. hNotify,
  85. pfdwStatus);
  86. }
  87. if( bReturnValue ){
  88. pSpool->Status |= WSPOOL_STATUS_NOTIFY;
  89. }
  90. }
  91. else
  92. {
  93. DBGMSG( DBG_WARNING, ( "RemoteFFPCN: Already waiting.\n" ));
  94. SetLastError( ERROR_ALREADY_WAITING );
  95. }
  96. }
  97. return bReturnValue;
  98. }
  99. BOOL
  100. RemoteFindClosePrinterChangeNotification(
  101. HANDLE hPrinter)
  102. {
  103. DWORD ReturnValue;
  104. PWSPOOL pSpool = (PWSPOOL)hPrinter;
  105. VALIDATEW32HANDLE( pSpool );
  106. pSpool->Status &= ~WSPOOL_STATUS_NOTIFY;
  107. if( pSpool->Status & WSPOOL_STATUS_NOTIFY_POLL ){
  108. //
  109. // In the polling case, there's no cleanup.
  110. //
  111. return TRUE;
  112. }
  113. if (pSpool->Type == SJ_WIN32HANDLE) {
  114. SYNCRPCHANDLE( pSpool );
  115. RpcTryExcept {
  116. if (ReturnValue = RpcFindClosePrinterChangeNotification(
  117. pSpool->RpcHandle)) {
  118. SetLastError(ReturnValue);
  119. ReturnValue = FALSE;
  120. } else
  121. ReturnValue = TRUE;
  122. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  123. SetLastError(RpcExceptionCode());
  124. ReturnValue = FALSE;
  125. } RpcEndExcept
  126. } else {
  127. EnterSplSem();
  128. ReturnValue = LMFindClosePrinterChangeNotification(hPrinter);
  129. LeaveSplSem();
  130. }
  131. return ReturnValue;
  132. }
  133. BOOL
  134. RemoteRefreshPrinterChangeNotification(
  135. HANDLE hPrinter,
  136. DWORD dwColor,
  137. PVOID pPrinterNotifyOptions,
  138. PVOID* ppPrinterNotifyInfo)
  139. {
  140. DWORD ReturnValue;
  141. PWSPOOL pSpool = (PWSPOOL)hPrinter;
  142. VALIDATEW32HANDLE( pSpool );
  143. if (ppPrinterNotifyInfo)
  144. *ppPrinterNotifyInfo = NULL;
  145. if (pSpool->Type != SJ_WIN32HANDLE) {
  146. SetLastError(ERROR_INVALID_FUNCTION);
  147. return FALSE;
  148. }
  149. SYNCRPCHANDLE( pSpool );
  150. RpcTryExcept {
  151. if (ReturnValue = RpcRouterRefreshPrinterChangeNotification(
  152. pSpool->RpcHandle,
  153. dwColor,
  154. pPrinterNotifyOptions,
  155. (PRPC_V2_NOTIFY_INFO*)ppPrinterNotifyInfo)) {
  156. SetLastError(ReturnValue);
  157. ReturnValue = FALSE;
  158. } else
  159. ReturnValue = TRUE;
  160. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  161. SetLastError(RpcExceptionCode());
  162. ReturnValue = FALSE;
  163. } RpcEndExcept
  164. return ReturnValue;
  165. }