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.

379 lines
7.7 KiB

  1. /*****
  2. AppleTalk Print Monitor
  3. (c) Microsoft 1992, all rights reserved
  4. FILE NAME: atalkmon.h
  5. DESCRIPTION: This is the interface to the main module for
  6. the AppleTalk Print Monitor.
  7. AUTHOR: Frank D. Byrum
  8. MODIFICATION HISTORY:
  9. date who description
  10. 26-Aug-92 frankb Initial version
  11. *****/
  12. #define APPLETALK_SERVICE_NAME TEXT("AppleTalk")
  13. /***** REGISTRY USAGE
  14. AppleTalk port information is kept in the registry using the
  15. registry API of Win32. The monitor is installed by creating
  16. a registry key, "AppleTalk Printers" at
  17. HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Print\Monitors
  18. This key is refered to as the AppleTalk Monitor root key. Two
  19. subkey of this root key are created. "Options" contains registry
  20. values for configuration options for the monitor on a global
  21. scale, and "Ports" contains subkeys for each AppleTalk printer
  22. defined.
  23. The name of the port subkey is the port name for the printer
  24. as viewed in the NT Print Manager port list. This key contains
  25. a number of values describing the port, including:
  26. REG_DWORD: TimeOut Number of miliseconds to wait for writes to
  27. the printer to complete
  28. REG_DWORD: ConfigFlags Set of flags describing configuration of the
  29. port. Currently only includes the flag
  30. indicating the printer is captured.
  31. REG_BINARY: NBP Name NBP name of the printer as an NBP_NAME structure
  32. The "Options" subkey contains a number of registry values, including:
  33. REG_DWORD: DebugLevel
  34. REG_DWORD: DebugSystems
  35. REG_SZ: LogFile
  36. *****/
  37. #define PRINTER_ENUM_BUFFER_SIZE 1024
  38. #define GENERIC_BUFFER_SIZE 512
  39. #define STATUS_BUFFER_SIZE 100
  40. //
  41. // registry keys
  42. //
  43. #define ATALKMON_PORTS_SUBKEY TEXT("\\Ports")
  44. #define ATALKMON_OPTIONS_SUBKEY TEXT("Options")
  45. //
  46. // registry value names
  47. //
  48. #define ATALKMON_CONFIGFLAGS_VALUE "Configuration Flags"
  49. #define ATALKMON_ZONENAME_VALUE "Zone Name"
  50. #define ATALKMON_PORTNAME_VALUE "Port Name"
  51. #define ATALKMON_PORT_CAPTURED "Port Captured"
  52. #define ATALKMON_FILTER_VALUE TEXT("Filter")
  53. #define ATALKMON_LOGFILE_VALUE TEXT("LogFile")
  54. //
  55. // config flags
  56. //
  57. #define SFM_PORT_CAPTURED 0x00000001
  58. #define SFM_PORT_IN_USE 0x00000002
  59. #define SFM_PORT_POST_READ 0x00000004
  60. #define SFM_PORT_OPEN 0x00000008
  61. #define SFM_PORT_CLOSE_PENDING 0x00000010
  62. #define SFM_PORT_IS_SPOOLER 0x00000020
  63. //
  64. // job flags
  65. //
  66. #define SFM_JOB_FIRST_WRITE 0x00000001
  67. #define SFM_JOB_FILTER 0x00000002
  68. #define SFM_JOB_DISCONNECTED 0x00000004
  69. #define SFM_JOB_OPEN_PENDING 0x00000008
  70. #define SFM_JOB_ERROR 0x00000010
  71. //
  72. // Various timeout values.
  73. //
  74. #define ATALKMON_DEFAULT_TIMEOUT 5000
  75. #define ATALKMON_DEFAULT_TIMEOUT_SEC 5
  76. #define CONFIG_TIMEOUT (5*60*1000)
  77. //
  78. // filter characters
  79. //
  80. #define CTRL_C 0x03
  81. #define CTRL_D 0x04
  82. #define CTRL_S 0x13
  83. #define CTRL_Q 0x11
  84. #define CTRL_T 0x14
  85. #define CR 0x0d
  86. //
  87. // postscript commands to instruct the printer to ignore ctrl-c (\0x003), ctrl-d (\004),
  88. // ctrl-q (\021), ctrl-s (\023), ctrl-t (\024) and escape (\033) characters.
  89. // The last part (/@PJL { currentfile .... bind def) is dual-mode printer specific stuff:
  90. // it tells it to ignore anything starting with /@PJL. This last part is based on the
  91. // assumption that no postscript implementation ever uses anything starting with @PJL as
  92. // a valid command - it's a pretty safe assumption, but something to remember.
  93. //
  94. #define PS_HEADER "(\033) cvn {} def\r\n/@PJL { currentfile 256 string readline pop pop } bind def\r\n"
  95. #define SIZE_PS_HEADER (sizeof(PS_HEADER) - 1)
  96. #define PJL_ENDING_COMMAND "\033%-12345X@PJL EOJ\n\033%-12345X"
  97. #define PJL_ENDING_COMMAND_LEN (sizeof(PJL_ENDING_COMMAND) - 1)
  98. //
  99. // NBP types
  100. //
  101. #define ATALKMON_RELEASED_TYPE "LaserWriter"
  102. #define ATALKMON_CAPTURED_TYPE " LaserWriter"
  103. #define PAP_QUANTUM_SIZE 512
  104. #define PAP_DEFAULT_QUANTUM 8
  105. #define PAP_DEFAULT_BUFFER (PAP_DEFAULT_QUANTUM*PAP_QUANTUM_SIZE)
  106. //
  107. // Data structures used.
  108. //
  109. typedef struct _ATALKPORT
  110. {
  111. struct _ATALKPORT * pNext;
  112. // Get/Set is protected by hmutexPortList.
  113. DWORD fPortFlags;
  114. // These flags do not need mutual exclusion since only the current
  115. // job will look at them. There will be no contention.
  116. DWORD fJobFlags;
  117. HANDLE hmutexPort;
  118. HANDLE hPrinter;
  119. DWORD dwJobId;
  120. SOCKET sockQuery;
  121. SOCKET sockIo;
  122. SOCKET sockStatus;
  123. WSH_NBP_NAME nbpPortName;
  124. WSH_ATALK_ADDRESS wshatPrinterAddress;
  125. DWORD OnlyOneByteAsCtrlD;
  126. WCHAR pPortName[(MAX_ENTITY+1)*2];
  127. UCHAR pReadBuffer[PAP_DEFAULT_BUFFER];
  128. } ATALKPORT;
  129. typedef ATALKPORT * PATALKPORT;
  130. typedef SOCKET * PSOCKET;
  131. typedef struct _TOKENLIST
  132. {
  133. LPSTR pszToken;
  134. DWORD dwError;
  135. DWORD dwStatus;
  136. } TOKENLIST, *PTOKENLIST;
  137. //
  138. //***** GLOBAL VARIABLES
  139. //
  140. #ifdef ALLOCATE
  141. HANDLE hInst;
  142. HKEY hkeyPorts = NULL;
  143. HANDLE hmutexPortList = NULL;
  144. HANDLE hmutexDeleteList= NULL;
  145. HANDLE hmutexBlt = NULL;
  146. HANDLE hmutexJob = NULL;
  147. PATALKPORT pPortList = NULL;
  148. PATALKPORT pDeleteList = NULL;
  149. HANDLE hEventLog = NULL;
  150. HANDLE hevConfigChange = NULL;
  151. HANDLE hevPrimeRead = NULL;
  152. HANDLE hCapturePrinterThread = INVALID_HANDLE_VALUE;
  153. HANDLE hReadThread = INVALID_HANDLE_VALUE;
  154. BOOL boolExitThread = FALSE, Filter = TRUE;
  155. CHAR chComputerName[MAX_ENTITY+1];
  156. WCHAR wchBusy[STATUS_BUFFER_SIZE];
  157. WCHAR wchPrinting[STATUS_BUFFER_SIZE];
  158. WCHAR wchPrinterError[STATUS_BUFFER_SIZE];
  159. WCHAR wchPrinterOffline[STATUS_BUFFER_SIZE];
  160. WCHAR wchDllName[STATUS_BUFFER_SIZE];
  161. WCHAR wchPortDescription[STATUS_BUFFER_SIZE];
  162. #ifdef DEBUG_MONITOR
  163. HANDLE hLogFile = INVALID_HANDLE_VALUE ;
  164. #endif
  165. #else
  166. extern HANDLE hInst;
  167. extern HKEY hkeyPorts;
  168. extern HANDLE hmutexPortList;
  169. extern HANDLE hmutexDeleteList;
  170. extern HANDLE hmutexBlt;
  171. extern HANDLE hmutexJob;
  172. extern PATALKPORT pPortList;
  173. extern PATALKPORT pDeleteList;
  174. extern HANDLE hEventLog;
  175. extern HANDLE hevConfigChange;
  176. extern HANDLE hevPrimeRead;
  177. extern HANDLE hCapturePrinterThread;
  178. extern HANDLE hReadThread;
  179. extern BOOL boolExitThread, Filter;
  180. extern CHAR chComputerName[];
  181. extern WCHAR wchBusy[];
  182. extern WCHAR wchPrinting[];
  183. extern WCHAR wchPrinterError[];
  184. extern WCHAR wchPrinterOffline[];
  185. extern WCHAR wchDllName[];
  186. extern WCHAR wchPortDescription[];
  187. #ifdef DEBUG_MONITOR
  188. extern HANDLE hLogFile;
  189. #endif
  190. #endif
  191. #ifdef DEBUG_MONITOR
  192. VOID
  193. DbgPrintf(
  194. char *Format,
  195. ...
  196. );
  197. #define DBGPRINT(args) DbgPrintf args
  198. #else
  199. #define DBGPRINT(args)
  200. #endif
  201. //***** FUNCTION PROTOTYPES
  202. DWORD
  203. CapturePrinterThread(
  204. IN LPVOID pParameterBlock
  205. );
  206. DWORD
  207. ReadThread(
  208. IN LPVOID pParameterBlock
  209. );
  210. DWORD
  211. CaptureAtalkPrinter(
  212. IN SOCKET sock,
  213. IN PWSH_ATALK_ADDRESS pAddress,
  214. IN BOOL fCapture
  215. );
  216. DWORD
  217. TransactPrinter(
  218. IN SOCKET sock,
  219. IN PWSH_ATALK_ADDRESS pAddress,
  220. IN LPBYTE pRequest,
  221. IN DWORD cbRequest,
  222. IN LPBYTE pResponse,
  223. IN DWORD cbResponse
  224. );
  225. VOID
  226. ParseAndSetPrinterStatus(
  227. IN PATALKPORT pPort
  228. );
  229. DWORD
  230. ConnectToPrinter(
  231. IN PATALKPORT pPort,
  232. IN DWORD dwTimeout
  233. );
  234. DWORD
  235. SetPrinterStatus(
  236. IN PATALKPORT pPort,
  237. IN LPWSTR lpwsStatus
  238. );
  239. PATALKPORT
  240. AllocAndInitializePort(
  241. VOID
  242. );
  243. VOID
  244. FreeAppleTalkPort(
  245. IN PATALKPORT pNewPort
  246. );
  247. DWORD
  248. LoadAtalkmonRegistry(
  249. IN HKEY hkeyPorts
  250. );
  251. DWORD
  252. CreateRegistryPort(
  253. IN PATALKPORT pNewPort
  254. );
  255. DWORD
  256. SetRegistryInfo(
  257. IN PATALKPORT pWalker
  258. );
  259. DWORD
  260. WinSockNbpLookup(
  261. SOCKET sQuerySocket,
  262. PCHAR pchZone,
  263. PCHAR pchType,
  264. PCHAR pchObject,
  265. PWSH_NBP_TUPLE pTuples,
  266. DWORD cbTuples,
  267. PDWORD pcTuplesFound);
  268. DWORD
  269. OpenAndBindAppleTalkSocket(
  270. IN PSOCKET pSocket
  271. );
  272. DWORD
  273. CapturePrinter(
  274. IN PATALKPORT pPort,
  275. IN BOOL fCapture
  276. );
  277. DWORD
  278. IsSpooler(
  279. IN PWSH_ATALK_ADDRESS pAddress,
  280. IN OUT BOOL * pfSpooler
  281. );
  282. VOID
  283. GetAndSetPrinterStatus(
  284. IN PATALKPORT pPort
  285. );
  286. BOOLEAN
  287. IsJobFromMac(
  288. IN PATALKPORT pPort
  289. );
  290. 
  291.