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.

380 lines
6.4 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. cachemon.c
  5. Abstract:
  6. This module contains the Cache Port handling for Win32Spl
  7. true connected printers.
  8. Author:
  9. Matthew A Felton ( MattFe ) July 23 1994
  10. Revision History:
  11. July 23 1994 - Created.
  12. Notes:
  13. We shold collapse the LM Ports and the Win32 ports so they have use common
  14. ports.
  15. --*/
  16. #include <windows.h>
  17. #include <winspool.h>
  18. #include <winsplp.h>
  19. #include <stdio.h>
  20. #include <string.h>
  21. #include <stdlib.h>
  22. #include <wchar.h>
  23. #include "splapip.h"
  24. #include <w32types.h>
  25. #include "local.h"
  26. #include "splcom.h"
  27. PWINIPORT pW32FirstPort = NULL;
  28. BOOL
  29. OpenPort(
  30. LPWSTR pName,
  31. PHANDLE pHandle
  32. )
  33. {
  34. DBGMSG(DBG_TRACE, ("OpenPort %ws %x\n", pName, pHandle));
  35. *pHandle = NULL;
  36. return TRUE;
  37. }
  38. BOOL
  39. StartDocPort(
  40. HANDLE hPort,
  41. LPWSTR pPrinterName,
  42. DWORD JobId,
  43. DWORD Level,
  44. LPBYTE pDocInfo
  45. )
  46. {
  47. DBGMSG(DBG_TRACE, ("StartDocPort %x %ws %d %d %x\n", hPort, pPrinterName, JobId, Level, pDocInfo));
  48. return TRUE;
  49. }
  50. BOOL
  51. ReadPort(
  52. HANDLE hPort,
  53. LPBYTE pBuffer,
  54. DWORD cbBuf,
  55. LPDWORD pcbRead
  56. )
  57. {
  58. DBGMSG(DBG_TRACE, ("ReadPort %x %x %d %x\n", hPort, pBuffer, cbBuf, pcbRead));
  59. return TRUE;
  60. }
  61. BOOL
  62. WritePort(
  63. HANDLE hPort,
  64. LPBYTE pBuffer,
  65. DWORD cbBuf,
  66. LPDWORD pcbWritten
  67. )
  68. {
  69. DBGMSG(DBG_TRACE, ("WritePort %x %x %d %x\n", hPort, pBuffer, cbBuf, pcbWritten));
  70. return TRUE;
  71. }
  72. BOOL
  73. EndDocPort(
  74. HANDLE hPort
  75. )
  76. {
  77. DBGMSG(DBG_TRACE, ("EndDocPort %x\n", hPort ));
  78. return TRUE;
  79. }
  80. BOOL
  81. XcvOpenPort(
  82. PCWSTR pszObject,
  83. ACCESS_MASK GrantedAccess,
  84. PHANDLE phXcv
  85. )
  86. {
  87. DBGMSG(DBG_TRACE, ("XcvOpenPort\n"));
  88. return TRUE;
  89. }
  90. DWORD
  91. XcvDataPort(
  92. HANDLE hXcv,
  93. PCWSTR pszDataName,
  94. PBYTE pInputData,
  95. DWORD cbInputData,
  96. PBYTE pOutputData,
  97. DWORD cbOutputData,
  98. PDWORD pcbOutputNeeded
  99. )
  100. {
  101. DBGMSG(DBG_TRACE, ("XcvDataPort\n"));
  102. return TRUE;
  103. }
  104. BOOL
  105. XcvClosePort(
  106. HANDLE hXcv
  107. )
  108. {
  109. DBGMSG(DBG_TRACE, ("XcvClosePort\n"));
  110. return TRUE;
  111. }
  112. BOOL
  113. ClosePort(
  114. HANDLE hPort
  115. )
  116. {
  117. DBGMSG(DBG_TRACE, ("ClosePort %x\n", hPort ));
  118. return TRUE;
  119. }
  120. BOOL
  121. DeletePortW(
  122. LPWSTR pName,
  123. HWND hWnd,
  124. LPWSTR pPortName
  125. )
  126. {
  127. DBGMSG(DBG_TRACE, ("DeletePortW %ws %x %ws\n", pName, hWnd, pPortName));
  128. return TRUE;
  129. }
  130. BOOL
  131. AddPortW(
  132. LPWSTR pName,
  133. HWND hWnd,
  134. LPWSTR pMonitorName
  135. )
  136. {
  137. BOOL ReturnValue = FALSE;
  138. DBGMSG(DBG_TRACE, ("AddPortW %ws %x %ws\n", pName, hWnd, pMonitorName));
  139. if ( _wcsicmp( pMonitorName, pszMonitorName ) ) {
  140. SetLastError(ERROR_INVALID_PARAMETER);
  141. goto AddPortWErrorReturn;
  142. }
  143. SetLastError( ERROR_NOT_SUPPORTED );
  144. AddPortWErrorReturn:
  145. return ReturnValue;
  146. }
  147. BOOL
  148. ConfigurePortW(
  149. LPWSTR pName,
  150. HWND hWnd,
  151. LPWSTR pPortName
  152. )
  153. {
  154. DBGMSG(DBG_TRACE, ("ConfigurePortW %ws %x %ws\n", pName, hWnd, pPortName));
  155. return TRUE;
  156. }
  157. BOOL
  158. AddPortEx(
  159. LPWSTR pName,
  160. DWORD Level,
  161. LPBYTE pBuffer,
  162. LPWSTR pMonitorName
  163. )
  164. {
  165. BOOL ReturnValue = FALSE;
  166. DWORD LastError = ERROR_SUCCESS;
  167. PPORT_INFO_1 pPortInfo = (PPORT_INFO_1)pBuffer;
  168. EnterSplSem();
  169. DBGMSG(DBG_TRACE, ("AddPortEx %x %d %x %ws %ws\n", pName, Level, pBuffer, pPortInfo->pName, pMonitorName));
  170. if ( _wcsicmp( pMonitorName, pszMonitorName ) ) {
  171. LastError = ERROR_INVALID_PARAMETER;
  172. goto AddPortExErrorReturn;
  173. }
  174. //
  175. // Make Sure Port doesn't already exist
  176. //
  177. if ( FindPort( pPortInfo->pName, pW32FirstPort ) ) {
  178. LastError = ERROR_INVALID_NAME;
  179. goto AddPortExErrorReturn;
  180. }
  181. if ( CreatePortEntry( pPortInfo->pName, &pW32FirstPort ) )
  182. ReturnValue = TRUE;
  183. AddPortExErrorReturn:
  184. LeaveSplSem();
  185. if (LastError != ERROR_SUCCESS) {
  186. SetLastError( LastError );
  187. ReturnValue = FALSE;
  188. }
  189. return ReturnValue;
  190. }
  191. BOOL
  192. EnumPortsW(
  193. LPWSTR pName,
  194. DWORD Level,
  195. LPBYTE pPorts,
  196. DWORD cbBuf,
  197. LPDWORD pcbNeeded,
  198. LPDWORD pcReturned
  199. )
  200. {
  201. PWINIPORT pIniPort;
  202. DWORD cb;
  203. LPBYTE pEnd;
  204. DWORD LastError=0;
  205. switch (Level) {
  206. case 1:
  207. case 2:
  208. break;
  209. default:
  210. SetLastError(ERROR_INVALID_LEVEL);
  211. return FALSE;
  212. }
  213. EnterSplSem();
  214. DBGMSG(DBG_TRACE, ("EnumPortW %x %d %x %d %x %x\n", pName, Level, pPorts, cbBuf, pcbNeeded, pcReturned));
  215. cb=0;
  216. pIniPort = pW32FirstPort;
  217. while (pIniPort) {
  218. cb += GetPortSize(pIniPort, Level);
  219. pIniPort = pIniPort->pNext;
  220. }
  221. *pcbNeeded=cb;
  222. if (cb <= cbBuf) {
  223. pEnd=pPorts+cbBuf;
  224. *pcReturned=0;
  225. pIniPort = pW32FirstPort;
  226. while (pIniPort) {
  227. pEnd = CopyIniPortToPort(pIniPort, Level, pPorts, pEnd);
  228. switch (Level) {
  229. case 1:
  230. pPorts+=sizeof(PORT_INFO_1);
  231. break;
  232. case 2:
  233. pPorts+=sizeof(PORT_INFO_2);
  234. break;
  235. }
  236. pIniPort=pIniPort->pNext;
  237. (*pcReturned)++;
  238. }
  239. } else {
  240. *pcReturned = 0;
  241. LastError = ERROR_INSUFFICIENT_BUFFER;
  242. }
  243. LeaveSplSem();
  244. if (LastError) {
  245. SetLastError(LastError);
  246. return FALSE;
  247. } else
  248. return TRUE;
  249. }
  250. MONITOREX MonitorEx = {
  251. sizeof(MONITOR),
  252. {
  253. EnumPortsW,
  254. OpenPort,
  255. NULL, // OpenPortEx is not supported
  256. StartDocPort,
  257. WritePort,
  258. ReadPort,
  259. EndDocPort,
  260. ClosePort,
  261. AddPort,
  262. AddPortEx,
  263. ConfigurePortW,
  264. DeletePortW,
  265. NULL, // GetPrinterDataFromPort not supported
  266. NULL, // SetPortTimeouts not supported
  267. XcvOpenPort,
  268. XcvDataPort,
  269. XcvClosePort
  270. }
  271. };
  272. LPMONITOREX
  273. InitializePrintMonitor(
  274. LPWSTR pRegistryRoot
  275. )
  276. {
  277. BOOL bRet = TRUE;
  278. DBGMSG(DBG_TRACE, ("InitializeMonitor %ws\n", pRegistryRoot));
  279. EnterSplSem();
  280. if (!FindPort(L"NExx:", pW32FirstPort ) ) {
  281. if ( !CreatePortEntry( L"NExx:", &pW32FirstPort ) ) {
  282. DBGMSG( DBG_WARNING,("InitializeMonitor Failed to CreatePortEntry\n"));
  283. bRet = FALSE;
  284. }
  285. }
  286. LeaveSplSem();
  287. return bRet ? &MonitorEx : NULL;
  288. }