Source code of Windows XP (NT5)
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.

571 lines
9.0 KiB

  1. /*++
  2. Copyright (c) 1990-1994 Microsoft Corporation
  3. All rights reserved
  4. Module Name:
  5. Change.c
  6. Abstract:
  7. Handles new WaitForPrinterChange implementation and:
  8. FindFirstPrinterChangeNotification (client and remote)
  9. FindNextPrinterChangeNotification
  10. FindClosePrinterChangeNotification
  11. ReplyOpenPrinter
  12. ReplyClosePrinter
  13. RouterReplyPrinter{Ex}
  14. RefreshPrinterChangeNotification
  15. Author:
  16. Albert Ting (AlbertT) 18-Jan-94
  17. Environment:
  18. User Mode -Win32
  19. Revision History:
  20. --*/
  21. #include <windows.h>
  22. #include <rpc.h>
  23. #include <winspool.h>
  24. #include <offsets.h>
  25. #include "server.h"
  26. #include "winspl.h"
  27. BOOL
  28. RouterFindFirstPrinterChangeNotification(
  29. HANDLE hPrinter,
  30. DWORD fdwFlags,
  31. DWORD fdwOptions,
  32. DWORD dwPID,
  33. PPRINTER_NOTIFY_OPTIONS pPrinterNotifyOptions,
  34. PHANDLE phEvent);
  35. BOOL
  36. RemoteFindFirstPrinterChangeNotification(
  37. HANDLE hPrinter,
  38. DWORD fdwFlags,
  39. DWORD fdwOptions,
  40. LPWSTR pszLocalMachine,
  41. DWORD dwPrinterRemote,
  42. PPRINTER_NOTIFY_OPTIONS pPrinterNotifyOptions);
  43. BOOL
  44. RouterFindNextPrinterChangeNotification(
  45. HANDLE hPrinter,
  46. DWORD fdwFlags,
  47. LPDWORD pfdwChange,
  48. PVOID pPrinterNotifyRefresh,
  49. PVOID* ppPrinterNotifyInfo);
  50. BOOL
  51. RouterReplyPrinter(
  52. HANDLE hNotify,
  53. DWORD dwColor,
  54. DWORD fdwFlags,
  55. PDWORD pdwResult,
  56. DWORD dwType,
  57. PVOID pBuffer);
  58. BOOL
  59. RouterRefreshPrinterChangeNotification(
  60. HANDLE hPrinter,
  61. DWORD dwColor,
  62. PVOID pPrinterNotifyRefresh,
  63. PPRINTER_NOTIFY_INFO* ppInfo);
  64. BOOL
  65. ReplyOpenPrinter(
  66. DWORD dwPrinterRemote,
  67. PHANDLE phNotify,
  68. DWORD dwType,
  69. DWORD cbBuffer,
  70. LPBYTE pBuffer);
  71. BOOL
  72. ReplyClosePrinter(
  73. HANDLE hNotify);
  74. DWORD
  75. RpcRouterFindFirstPrinterChangeNotificationOld(
  76. HANDLE hPrinter,
  77. DWORD fdwFlags,
  78. DWORD fdwOptions,
  79. LPWSTR pszLocalMachine,
  80. DWORD dwPrinterLocal)
  81. /*++
  82. Routine Description:
  83. This call is only used by beta2 daytona, but we can't remove it
  84. since this will allow beta2 to crash daytona. (Someday, when
  85. beta2 is long gone, we can reuse this slot for something else.)
  86. Arguments:
  87. Return Value:
  88. --*/
  89. {
  90. return ERROR_INVALID_FUNCTION;
  91. }
  92. //
  93. // Old version for Daytona.
  94. //
  95. DWORD
  96. RpcRemoteFindFirstPrinterChangeNotification(
  97. HANDLE hPrinter,
  98. DWORD fdwFlags,
  99. DWORD fdwOptions,
  100. LPWSTR pszLocalMachine,
  101. DWORD dwPrinterLocal,
  102. DWORD cbBuffer,
  103. LPBYTE pBuffer)
  104. /*++
  105. Routine Description:
  106. Arguments:
  107. Return Value:
  108. --*/
  109. {
  110. BOOL bRet;
  111. RPC_STATUS Status;
  112. if ((Status = RpcImpersonateClient(NULL)) != RPC_S_OK)
  113. {
  114. SetLastError(Status);
  115. return FALSE;
  116. }
  117. bRet = RemoteFindFirstPrinterChangeNotification(hPrinter,
  118. fdwFlags,
  119. fdwOptions,
  120. pszLocalMachine,
  121. dwPrinterLocal,
  122. NULL);
  123. RpcRevertToSelf();
  124. if (bRet)
  125. return FALSE;
  126. else
  127. return GetLastError();
  128. }
  129. DWORD
  130. RpcRemoteFindFirstPrinterChangeNotificationEx(
  131. HANDLE hPrinter,
  132. DWORD fdwFlags,
  133. DWORD fdwOptions,
  134. LPWSTR pszLocalMachine,
  135. DWORD dwPrinterLocal,
  136. PRPC_V2_NOTIFY_OPTIONS pRpcV2NotifyOptions)
  137. /*++
  138. Routine Description:
  139. Arguments:
  140. Return Value:
  141. --*/
  142. {
  143. BOOL bRet;
  144. RPC_STATUS Status;
  145. if ((Status = RpcImpersonateClient(NULL)) != RPC_S_OK)
  146. {
  147. SetLastError(Status);
  148. return FALSE;
  149. }
  150. bRet = RemoteFindFirstPrinterChangeNotification(
  151. hPrinter,
  152. fdwFlags,
  153. fdwOptions,
  154. pszLocalMachine,
  155. dwPrinterLocal,
  156. (PPRINTER_NOTIFY_OPTIONS)pRpcV2NotifyOptions);
  157. RpcRevertToSelf();
  158. if (bRet)
  159. return FALSE;
  160. else
  161. return GetLastError();
  162. }
  163. DWORD
  164. RpcClientFindFirstPrinterChangeNotification(
  165. HANDLE hPrinter,
  166. DWORD fdwFlags,
  167. DWORD fdwOptions,
  168. DWORD dwPID,
  169. PRPC_V2_NOTIFY_OPTIONS pRpcV2NotifyOptions,
  170. LPDWORD pdwEvent)
  171. /*++
  172. Routine Description:
  173. Arguments:
  174. Return Value:
  175. --*/
  176. {
  177. BOOL bRet;
  178. RPC_STATUS Status;
  179. if ((Status = RpcImpersonateClient(NULL)) != RPC_S_OK)
  180. {
  181. SetLastError(Status);
  182. return FALSE;
  183. }
  184. bRet = RouterFindFirstPrinterChangeNotification(
  185. hPrinter,
  186. fdwFlags,
  187. fdwOptions,
  188. dwPID,
  189. (PPRINTER_NOTIFY_OPTIONS)pRpcV2NotifyOptions,
  190. (PHANDLE)pdwEvent);
  191. RpcRevertToSelf();
  192. if (bRet)
  193. return FALSE;
  194. else
  195. return GetLastError();
  196. }
  197. DWORD
  198. RpcFindNextPrinterChangeNotification(
  199. HANDLE hPrinter,
  200. DWORD fdwFlags,
  201. LPDWORD pfdwChange,
  202. PRPC_V2_NOTIFY_OPTIONS pRpcV2NotifyOptions,
  203. PRPC_V2_NOTIFY_INFO* ppInfo)
  204. /*++
  205. Routine Description:
  206. Arguments:
  207. Return Value:
  208. --*/
  209. {
  210. BOOL bRet;
  211. RPC_STATUS Status;
  212. if ((Status = RpcImpersonateClient(NULL)) != RPC_S_OK)
  213. {
  214. SetLastError(Status);
  215. return FALSE;
  216. }
  217. bRet = RouterFindNextPrinterChangeNotification(
  218. hPrinter,
  219. fdwFlags,
  220. pfdwChange,
  221. pRpcV2NotifyOptions,
  222. ppInfo);
  223. RpcRevertToSelf();
  224. if (bRet)
  225. return FALSE;
  226. else
  227. return GetLastError();
  228. }
  229. DWORD
  230. RpcFindClosePrinterChangeNotification(
  231. HANDLE hPrinter)
  232. /*++
  233. Routine Description:
  234. Arguments:
  235. Return Value:
  236. --*/
  237. {
  238. BOOL bRet;
  239. RPC_STATUS Status;
  240. if ((Status = RpcImpersonateClient(NULL)) != RPC_S_OK)
  241. {
  242. SetLastError(Status);
  243. return FALSE;
  244. }
  245. bRet = FindClosePrinterChangeNotification(hPrinter);
  246. RpcRevertToSelf();
  247. if (bRet)
  248. return FALSE;
  249. else
  250. return GetLastError();
  251. }
  252. DWORD
  253. RpcReplyOpenPrinter(
  254. LPWSTR pszLocalMachine,
  255. PHANDLE phNotify,
  256. DWORD dwPrinterRemote,
  257. DWORD dwType,
  258. DWORD cbBuffer,
  259. LPBYTE pBuffer)
  260. /*++
  261. Routine Description:
  262. Arguments:
  263. Return Value:
  264. --*/
  265. {
  266. BOOL bRet;
  267. RPC_STATUS Status;
  268. if ((Status = RpcImpersonateClient(NULL)) != RPC_S_OK)
  269. {
  270. SetLastError(Status);
  271. return FALSE;
  272. }
  273. bRet = ReplyOpenPrinter(dwPrinterRemote,
  274. phNotify,
  275. dwType,
  276. cbBuffer,
  277. pBuffer);
  278. RpcRevertToSelf();
  279. if (bRet)
  280. return FALSE;
  281. else
  282. return GetLastError();
  283. }
  284. DWORD
  285. RpcReplyClosePrinter(
  286. PHANDLE phNotify)
  287. /*++
  288. Routine Description:
  289. Arguments:
  290. Return Value:
  291. --*/
  292. {
  293. BOOL bRet;
  294. RPC_STATUS Status;
  295. if ((Status = RpcImpersonateClient(NULL)) != RPC_S_OK)
  296. {
  297. SetLastError(Status);
  298. return FALSE;
  299. }
  300. bRet = ReplyClosePrinter(*phNotify);
  301. RpcRevertToSelf();
  302. if (bRet) {
  303. *phNotify = NULL;
  304. return ERROR_SUCCESS;
  305. }
  306. else
  307. return GetLastError();
  308. }
  309. DWORD
  310. RpcRouterReplyPrinter(
  311. HANDLE hNotify,
  312. DWORD fdwFlags,
  313. DWORD cbBuffer,
  314. LPBYTE pBuffer)
  315. /*++
  316. Routine Description:
  317. Arguments:
  318. Return Value:
  319. --*/
  320. {
  321. BOOL bRet;
  322. RPC_STATUS Status;
  323. if ((Status = RpcImpersonateClient(NULL)) != RPC_S_OK)
  324. {
  325. SetLastError(Status);
  326. return FALSE;
  327. }
  328. bRet = RouterReplyPrinter(hNotify,
  329. 0,
  330. fdwFlags,
  331. NULL,
  332. 0,
  333. NULL);
  334. RpcRevertToSelf();
  335. if (bRet)
  336. return FALSE;
  337. else
  338. return GetLastError();
  339. }
  340. DWORD
  341. RpcRouterReplyPrinterEx(
  342. HANDLE hNotify,
  343. DWORD dwColor,
  344. DWORD fdwFlags,
  345. PDWORD pdwResult,
  346. DWORD dwReplyType,
  347. RPC_V2_UREPLY_PRINTER Reply)
  348. /*++
  349. Routine Description:
  350. Arguments:
  351. Return Value:
  352. --*/
  353. {
  354. BOOL bRet;
  355. RPC_STATUS Status;
  356. if ((Status = RpcImpersonateClient(NULL)) != RPC_S_OK)
  357. {
  358. SetLastError(Status);
  359. return FALSE;
  360. }
  361. bRet = RouterReplyPrinter(hNotify,
  362. dwColor,
  363. fdwFlags,
  364. pdwResult,
  365. dwReplyType,
  366. Reply.pInfo);
  367. RpcRevertToSelf();
  368. if (bRet)
  369. return FALSE;
  370. else
  371. return GetLastError();
  372. }
  373. DWORD
  374. RpcRouterRefreshPrinterChangeNotification(
  375. HANDLE hPrinter,
  376. DWORD dwColor,
  377. PRPC_V2_NOTIFY_OPTIONS pRpcV2NotifyOptions,
  378. PRPC_V2_NOTIFY_INFO* ppInfo)
  379. /*++
  380. Routine Description:
  381. Updates info.
  382. Arguments:
  383. Return Value:
  384. --*/
  385. {
  386. BOOL bRet;
  387. RPC_STATUS Status;
  388. if ((Status = RpcImpersonateClient(NULL)) != RPC_S_OK)
  389. {
  390. SetLastError(Status);
  391. return FALSE;
  392. }
  393. bRet = RouterRefreshPrinterChangeNotification(
  394. hPrinter,
  395. dwColor,
  396. (PPRINTER_NOTIFY_OPTIONS)pRpcV2NotifyOptions,
  397. (PPRINTER_NOTIFY_INFO*)ppInfo);
  398. RpcRevertToSelf();
  399. if (bRet)
  400. return FALSE;
  401. else
  402. return GetLastError();
  403. }