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.

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