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.

322 lines
11 KiB

  1. //
  2. // Copyright(c) Microsoft Corp., 1991, 1993
  3. //
  4. //
  5. // Macps.h - Defines, type definitions, and function prototypes for the
  6. // MacPrint service of Windows NT Advanced Server
  7. //
  8. // History:
  9. // Created for LAN Manager 2.1 Jameel Hyder @ Microsoft
  10. // modified for Windows NT Frank Byrum @ Microsoft
  11. // Cleaned up Jameel Hyder @ Microsoft
  12. //
  13. #include <winsock2.h>
  14. #include <atalkwsh.h>
  15. #ifndef _MACPS
  16. #define _MACPS
  17. #include <winspool.h>
  18. #include <prtdefs.h>
  19. // default string if string table not available - no need to localize
  20. #define STATUS_MSG_ACTIVE "Spooling to print server \"%s\" ..."
  21. #define CLIENTNAME "MAC_Client"
  22. #define GENERIC_BUFFER_SIZE 1024
  23. #define STACKSIZE 8192
  24. #define PRINT_SHARE_CHECK_DEF 60000L
  25. #define PS_EOF 4
  26. #define FONTNAMELEN 49
  27. #define FONTVERSIONLEN 7
  28. #define FONTENCODINGLEN 9
  29. // these strings are not localized - they are used for NBP browsing
  30. #define LW_TYPE "LaserWriter"
  31. #define DEF_ZONE "*"
  32. #define NULL_STR ""
  33. #define MACPRINT_NAME L"MacPrint"
  34. #define TOKLEN 255
  35. #define PPDLEN 49
  36. #define PSLEN 259
  37. #define PENDLEN PSLEN+1 // This needs to be 4*N
  38. // ProcSet states
  39. #define PROCSETMISSING 0
  40. #define PROCSETPRESENT 1
  41. #define PROCSETALMOSTPRESENT 2
  42. // Registry Parameters - registry key names are not localized
  43. #define HKEY_MACPRINT L"SYSTEM\\CurrentControlSet\\Services\\MacPrint"
  44. #define HKEY_PARAMETERS L"Parameters"
  45. #define HVAL_SHARECHECKINTERVAL L"ShareCheckInterval"
  46. #define HVAL_LOGFILE L"LogFilePath"
  47. #define HVAL_DUMPFILE L"DumpFilePath"
  48. #define MACSPOOL_MAX_EVENTS 2
  49. #define MACSPOOL_EVENT_SERVICE_STOP 0
  50. #define MACSPOOL_EVENT_PNP 1
  51. typedef SOCKET * PSOCKET;
  52. // A FONT_RECORD structure will contain the information describing a font.
  53. // A list of these stuctures will be associated with each shared PostScript
  54. // printer.
  55. typedef struct
  56. {
  57. char name[FONTNAMELEN+1];
  58. char encoding[FONTENCODINGLEN+1];
  59. char version[FONTVERSIONLEN+1];
  60. } FONT_RECORD, *PFR;
  61. // A DICT_RECORD structure contains information describing a PostScript
  62. // dictionary. It is used to determine what version of the Macintosh
  63. // LaserWriter driver was used to submit a job, as this structure is
  64. // filled in from information provided by ADSC comments in the print job.
  65. #define DICTNAMELEN 17
  66. #define DICTVERSIONLEN 7
  67. #define DICTREVISIONLEN 7
  68. typedef struct dict_record
  69. {
  70. char name[DICTNAMELEN+1];
  71. char version[DICTVERSIONLEN+1];
  72. char revision[DICTREVISIONLEN+1];
  73. } DICT_RECORD, *PDR;
  74. // A BUF_READ structure exists for each print job. All data that is read from
  75. // a client is read here. PendingBuffer field is used to copy partial lines
  76. // from previous I/O. A pointer to this structure can be found in the job
  77. // record
  78. #define PAP_QUANTUM_SIZE 512
  79. #define PAP_DEFAULT_QUANTUM 8
  80. #define PAP_DEFAULT_BUFFER (PAP_DEFAULT_QUANTUM*PAP_QUANTUM_SIZE)
  81. typedef struct
  82. {
  83. BYTE PendingBuffer[PENDLEN]; // Keep commands that span buffers here.
  84. BYTE Buffer[PAP_DEFAULT_BUFFER]; // buffer for data Xfers
  85. } BUF_READ, *PBR;
  86. // A JOB_RECORD structure will exist for each job to be service by the
  87. // queue service routine. All job specific data can be found through
  88. // this structure
  89. typedef struct job_record
  90. {
  91. struct queue_record * job_pQr; // owning print queue structure
  92. struct job_record * NextJob; // next job for this printer
  93. DWORD dwFlags; // Flags, what else ?
  94. HANDLE hPrinter; // NT Printer Handle for this job
  95. DWORD dwJobId; // NT Print Manager Job ID.
  96. SOCKET sJob; // socket for this job
  97. HDC hicFontFamily; // used for querying PostScript fonts
  98. HDC hicFontFace; // used for querying PostScript fonts
  99. DWORD dwFlowQuantum; // negotiated flow quantum
  100. DWORD XferLen; // Number of bytes in DataBuffer
  101. PBYTE DataBuffer; // Data buffer for xfer's
  102. PBR bufPool; // pool of two buffers
  103. DWORD bufIndx; // index into Buffer Pool
  104. int cbRead; // Bytes read in last read
  105. DWORD PendingLen; // Length of partial command stored in PendingBuffer
  106. USHORT psJobState; // Current state of the PostScript job.
  107. USHORT JSState; // Current PostScript Data Stream state.
  108. USHORT SavedJSState; // Saved PostScript Data Stream state.
  109. USHORT InProgress; // Flags for query state
  110. DWORD EOFRecvdAt; // Time when we recvd EOF from client
  111. BOOL InBinaryOp; // We are accepting Binary information.
  112. BOOL FirstWrite; // Set to True initially. Set to False after header is written
  113. BOOL EOFRecvd; // True, if EOF received, False otherwise
  114. #if DBG
  115. DWORD PapEventCount; // Count of events
  116. #endif
  117. BYTE buffer[2*sizeof(BUF_READ)];
  118. // read data buffer
  119. WCHAR pszUser[TOKLEN + 1];// username from DSC comment
  120. BYTE JSKeyWord[TOKLEN+1];// Keyword being scanned for.
  121. } JOB_RECORD, *PJR;
  122. // once we get EOF, if we don't hear from the client for 60 seconds, assume done! (oti hack!)
  123. #define OTI_EOF_LIMIT 60000
  124. #define EXECUTE_OTI_HACK(_StartTime) ( ((GetTickCount() - (_StartTime)) > OTI_EOF_LIMIT) ? \
  125. TRUE : FALSE )
  126. //
  127. // Job Record Defines
  128. //
  129. // dwFlags
  130. #define JOB_FLAG_NULL 0x00000000
  131. #define JOB_FLAG_TITLESET 0x00000001
  132. #define JOB_FLAG_OWNERSET 0x00000002
  133. // psJobState
  134. #define psNullJob 0 // Not in a PostScript Job Structure (S0)
  135. #define psQueryJob 1 // In a Query Job (S1)
  136. #define psExitServerJob 2 // In an Exit Server Job (S2)
  137. #define psStandardJob 3 // In a Standard Job (S3)
  138. // JSState
  139. #define JSStrip 0 // Write nothing, scan for Structuring Comment
  140. #define JSStripEOL 1 // Write nothing, scan for end of line, then restore state
  141. #define JSStripKW 2 // Write nothing, scan for JSKeyword, then restore state
  142. #define JSStripTok 3 // Write nothing, scan for next token, then restore state
  143. #define JSWrite 4 // Write everything, scan for Structuring Comment
  144. #define JSWriteEOL 5 // Write everything, scan for end of line, then restore state
  145. #define JSWriteKW 6 // Write everything, scan for JSKeyword, then restore state
  146. #define JSWriteTok 7 // Write everything, scan for next token, then restore state
  147. // InProgress
  148. #define NOTHING 0 // A scan is not currently in progress
  149. #define QUERYDEFAULT 1 // Currently scanning for the default response to a query
  150. #define RESOLUTIONBUFFLEN 9 // room for "xxxxxdpi"
  151. #define COLORDEVICEBUFFLEN 6 // room for "False"
  152. // A QUEUE_RECORD structure exists for each shared Windows NT local printer
  153. // defined by the Windows NT Print Manager. All relevant data specific to
  154. // a Windows NT Printer is accessed through this data structure. This
  155. // structure also serves as the head of the list of jobs to service that
  156. // are being spooled to this printer.
  157. typedef struct queue_record
  158. {
  159. struct queue_record * pNext; // Next queue in the list
  160. BOOL bFound; // TRUE if found in EnumPrinters list
  161. BOOL SupportsBinary; // True, if printer supports binary mode
  162. LPWSTR pPrinterName; // Print Manager printer name
  163. LPSTR pMacPrinterName; // Macintosh ANSI printer name
  164. LPWSTR pDriverName; // NT Printer driver
  165. LPWSTR pPortName; // NT Port name
  166. LPWSTR pDataType; // datatype used for jobs
  167. LPSTR IdleStatus; // "status: idle"
  168. LPSTR SpoolingStatus; // "status: Spooling to ......"
  169. PJR PendingJobs; // Pointer to the list of pending jobs.
  170. BOOL ExitThread; // Flag to Exit thread.
  171. HANDLE hThread; // handle to queue service thread
  172. PFR fonts; // array of fonts on this printer (PostScript only)
  173. DWORD MaxFontIndex; // max # fonts in fonts array
  174. SOCKET sListener; // listener socket for this printer
  175. DWORD JobCount; // Number of Jobs Outstanding.
  176. DWORD FreeVM; // Virtual memory available on printer
  177. CHAR LanguageVersion[PPDLEN+1];// PPD LangaugeVersion, default: English
  178. CHAR Product[PPDLEN+1]; // PPD Product name
  179. CHAR Version[PPDLEN+1]; // PPD PostScript Version, Null = Unknown
  180. CHAR Revision[PPDLEN+1]; // PPD Revision
  181. CHAR DeviceNickName[PPDLEN+1];// Human readable device name
  182. CHAR pszColorDevice[COLORDEVICEBUFFLEN];
  183. CHAR pszResolution[RESOLUTIONBUFFLEN];
  184. CHAR pszLanguageLevel[PPDLEN+1];
  185. } QUEUE_RECORD, *PQR;
  186. // pDataType
  187. #define MACPS_DATATYPE_RAW L"RAW"
  188. #define MACPS_DATATYPE_PS2DIB L"PSCRIPT1"
  189. typedef struct _failed_cache
  190. {
  191. struct _failed_cache *Next;
  192. WCHAR PrinterName[1];
  193. } FAIL_CACHE, *PFAIL_CACHE;
  194. // Action codes for CheckFailCache
  195. #define PSP_ADD 1
  196. #define PSP_DELETE 2
  197. // Return codes from CheckFailCache
  198. #define PSP_OPERATION_SUCCESSFUL 0
  199. #define PSP_OPERATION_FAILED 12
  200. #define PSP_ALREADY_THERE 10
  201. #define PSP_NOT_FOUND 11
  202. BOOLEAN
  203. PostPnpWatchEvent(
  204. VOID
  205. );
  206. BOOLEAN
  207. HandlePnPEvent(
  208. VOID
  209. );
  210. // Function Prototypes for macpsq.c
  211. void ReportWin32Error (DWORD dwError);
  212. void QueueServiceThread(PQR pqr);
  213. DWORD HandleNewJob(PQR pqr);
  214. DWORD HandleRead(PJR pjr);
  215. DWORD CreateNewJob(PQR pqr);
  216. void RemoveJob(PJR pjr);
  217. void HandleNextPAPEvent(PQR pqr);
  218. void MoveJobAtEnd(PQR pqr, PJR pjr);
  219. DWORD CreateListenerSocket(PQR pqr);
  220. // Function Prototypes for psp.c
  221. BOOLEAN SetDefaultPPDInfo(PQR pqr);
  222. BOOLEAN SetDefaultFonts(PQR pqr);
  223. BOOLEAN GetPPDInfo (PQR pqr);
  224. int LineLength(PBYTE pBuf, int cbBuf);
  225. DWORD WriteToSpool(PJR pjr, PBYTE pchbuf, int cchlen);
  226. DWORD MoveToPending(PJR pjr, PBYTE pchbuf, int cchlen);
  227. DWORD TellClient (PJR, BOOL, PBYTE, int);
  228. DWORD PSParse(PJR, PBYTE, int);
  229. #define PopJSState(Job) Job->JSState = Job->SavedJSState
  230. #define PushJSState(Job, NewState) \
  231. { \
  232. Job->SavedJSState = Job->JSState; \
  233. Job->JSState = NewState; \
  234. }
  235. // Function prototype for pspquery.c
  236. DWORD HandleEndFontListQuery(PJR);
  237. DWORD HandleEndQuery (PJR, PBYTE);
  238. DWORD FinishDefaultQuery (PJR, PBYTE);
  239. void FindDictVer(PDR DictQuery);
  240. DWORD HandleBQComment(PJR, PBYTE);
  241. DWORD HandleBeginProcSetQuery(PJR, PSZ);
  242. DWORD HandleBeginFontQuery(PJR, PSZ);
  243. DWORD HandleEndPrinterQuery(PJR);
  244. void HandleBeginXQuery(PJR, PSZ);
  245. void EnumeratePostScriptFonts(PJR pjr);
  246. DWORD CheckFailedCache(LPWSTR pPrinterName, DWORD dwAction);
  247. int CALLBACK FamilyEnumCallback(
  248. LPENUMLOGFONT lpelf,
  249. LPNEWTEXTMETRIC pntm,
  250. int iFontType,
  251. LPARAM lParam);
  252. int CALLBACK FontEnumCallback(
  253. LPENUMLOGFONT lpelf,
  254. LPNEWTEXTMETRIC pntm,
  255. int iFontType,
  256. LPARAM lParam);
  257. //
  258. // global data
  259. //
  260. extern HANDLE mutexQueueList;
  261. extern HANDLE hevStopRequested;
  262. #if DBG
  263. extern HANDLE hDumpFile;
  264. #endif
  265. extern HANDLE hEventLog;
  266. extern SERVICE_STATUS MacPrintStatus;
  267. #endif
  268. 
  269.