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.

399 lines
11 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. nwlibs\psdb.c
  5. Abstract:
  6. Read the Print Con database file APIs.
  7. Author:
  8. Shawn Walker (v-swalk) 12-12-1994
  9. Revision History:
  10. --*/
  11. #include "common.h"
  12. extern DWORD SwapLong(DWORD number);
  13. unsigned int
  14. PSGetJobName(
  15. unsigned int ConnectionHandle,
  16. unsigned short SearchFlag,
  17. unsigned char *pOwner,
  18. unsigned char *pJobName,
  19. PPS_JOB_RECORD pJobRecord,
  20. unsigned char GetDefault
  21. );
  22. #define MAX_JOB_NAME_ENTRY 37
  23. #define O_RDONLY 0x0000 /* open for reading only */
  24. #define O_WRONLY 0x0001 /* open for writing only */
  25. #define O_RDWR 0x0002 /* open for reading and writing */
  26. #define O_APPEND 0x0008 /* writes done at eof */
  27. #define O_CREAT 0x0100 /* create and open file */
  28. #define O_TRUNC 0x0200 /* open and truncate */
  29. #define O_EXCL 0x0400 /* open only if file doesn't already exist */
  30. #define O_TEXT 0x4000 /* file mode is text (translated) */
  31. #define O_BINARY 0x8000 /* file mode is binary (untranslated) */
  32. #define S_IEXEC 0000100 /* execute/search permission, owner */
  33. #define S_IWRITE 0000200 /* write permission, owner */
  34. #define S_IREAD 0000400 /* read permission, owner */
  35. #define S_IFCHR 0020000 /* character special */
  36. #define S_IFDIR 0040000 /* directory */
  37. #define S_IFREG 0100000 /* regular */
  38. #define S_IFMT 0170000 /* file type mask */
  39. #include <pshpack1.h>
  40. typedef struct _PRINTCON_HEADER {
  41. unsigned char Text[115];
  42. unsigned char MajorVersion;
  43. unsigned char MinorVersion1;
  44. unsigned char MinorVersion2;
  45. unsigned char DefaultJobName[32];
  46. } PRINTCON_HEADER, *PPRINTCON_HEADER;
  47. #define PRINTCON_HEADER_SIZE sizeof(PRINTCON_HEADER)
  48. typedef struct _JOB_NAME_AREA {
  49. unsigned char JobName[32];
  50. unsigned long JobRecordOffset;
  51. } JOB_NAME_AREA, *PJOB_NAME_AREA;
  52. #define JOB_NAME_AREA_SIZE sizeof(JOB_NAME_AREA)
  53. typedef struct _JOB_RECORD_AREA {
  54. unsigned char ServerName[NCP_BINDERY_OBJECT_NAME_LENGTH];
  55. unsigned char QueueName[NCP_BINDERY_OBJECT_NAME_LENGTH];
  56. unsigned char TabSize;
  57. unsigned short NumberOfCopies;
  58. unsigned char FormName[40];
  59. unsigned char NotifyWhenDone; //0=No, 1=Yes
  60. unsigned long PrintServerID;
  61. unsigned char Name[13];
  62. unsigned char BannerName[13];
  63. unsigned char Device[33];
  64. unsigned char Mode[33];
  65. unsigned char BannerFlag; //0=No Banner, 1=Banner
  66. unsigned char DataType; //1=Byte,0=Stream
  67. unsigned char FormFeed; //0=Don't Suppress FF, 1=Suppress FF
  68. unsigned short TimeoutCount;
  69. unsigned char LocalPrinter; //1=LPT1, 2=LPT2, 3=LPT3
  70. unsigned char AutoEndCap; //0=Don't Auto EndCap, 1=Do Auto EndCap
  71. } JOB_RECORD_AREA, *PJOB_RECORD_AREA;
  72. #include <poppack.h>
  73. #define JOB_RECORD_AREA_SIZE sizeof(JOB_RECORD_AREA)
  74. /*++
  75. *******************************************************************
  76. PSJobGetDefault
  77. Routine Description:
  78. Get the default print job configuration from the printcon.dat
  79. file.
  80. Arguments:
  81. ConnectionHandle = The connection handle to use.
  82. SearchFlag =
  83. pOwner =
  84. pJobName = A pointer to return the default job configuration name.
  85. pJobRecord = A pointer to return the default job configuration.
  86. Return Value:
  87. SUCCESSFUL 0x0000
  88. PS_ERR_BAD_VERSION 0x7770
  89. PS_ERR_GETTING_DEFAULT 0x7773
  90. PS_ERR_OPENING_DB 0x7774
  91. PS_ERR_READING_DB 0x7775
  92. PS_ERR_READING_RECORD 0x7776
  93. PS_ERR_INTERNAL_ERROR 0x7779
  94. PS_ERR_NO_DEFAULT_SPECIFIED 0x777B
  95. INVALID_CONNECTION 0x8801
  96. *******************************************************************
  97. --*/
  98. unsigned int
  99. PSJobGetDefault(
  100. unsigned int ConnectionHandle,
  101. unsigned short SearchFlag,
  102. unsigned char *pOwner,
  103. unsigned char *pJobName,
  104. PPS_JOB_RECORD pJobRecord
  105. )
  106. {
  107. return PSGetJobName(
  108. ConnectionHandle,
  109. SearchFlag,
  110. pOwner,
  111. pJobName,
  112. pJobRecord,
  113. TRUE);
  114. }
  115. /*++
  116. *******************************************************************
  117. PSJobRead
  118. Routine Description:
  119. Get the print job configuration from the printcon.dat file.
  120. Arguments:
  121. ConnectionHandle = The connection handle to use.
  122. pOwner =
  123. pJobName = A pointer to return the default job configuration name.
  124. pJobRecord = A pointer to return the default job configuration.
  125. Return Value:
  126. SUCCESSFUL 0x0000
  127. PS_ERR_BAD_VERSION 0x7770
  128. PS_ERR_GETTING_DEFAULT 0x7773
  129. PS_ERR_OPENING_DB 0x7774
  130. PS_ERR_READING_DB 0x7775
  131. PS_ERR_READING_RECORD 0x7776
  132. PS_ERR_INTERNAL_ERROR 0x7779
  133. PS_ERR_NO_DEFAULT_SPECIFIED 0x777B
  134. INVALID_CONNECTION 0x8801
  135. *******************************************************************
  136. --*/
  137. unsigned int
  138. PSJobRead(
  139. unsigned int ConnectionHandle,
  140. unsigned char *pOwner,
  141. unsigned char *pJobName,
  142. PPS_JOB_RECORD pJobRecord
  143. )
  144. {
  145. return PSGetJobName(
  146. ConnectionHandle,
  147. 0,
  148. pOwner,
  149. pJobName,
  150. pJobRecord,
  151. FALSE);
  152. }
  153. /*++
  154. *******************************************************************
  155. PSGetJobName
  156. Routine Description:
  157. Common routine to get the print job configuration from the
  158. printcon.dat file.
  159. Arguments:
  160. ConnectionHandle = The connection handle to use.
  161. SearchFlag =
  162. pOwner =
  163. pJobName = A pointer to return the default job configuration name.
  164. pJobRecord = A pointer to return the default job configuration.
  165. GetDefault = TRUE = get the default job name, FALSE = Don't get
  166. the default job name.
  167. Return Value:
  168. SUCCESSFUL 0x0000
  169. PS_ERR_BAD_VERSION 0x7770
  170. PS_ERR_GETTING_DEFAULT 0x7773
  171. PS_ERR_OPENING_DB 0x7774
  172. PS_ERR_READING_DB 0x7775
  173. PS_ERR_READING_RECORD 0x7776
  174. PS_ERR_INTERNAL_ERROR 0x7779
  175. PS_ERR_NO_DEFAULT_SPECIFIED 0x777B
  176. INVALID_CONNECTION 0x8801
  177. *******************************************************************
  178. --*/
  179. unsigned int
  180. PSGetJobName(
  181. unsigned int ConnectionHandle,
  182. unsigned short SearchFlag,
  183. unsigned char *pOwner,
  184. unsigned char *pJobName,
  185. PPS_JOB_RECORD pJobRecord,
  186. unsigned char GetDefault
  187. )
  188. {
  189. unsigned char *pSearchJobName;
  190. unsigned long ObjectId;
  191. FILE *stream = NULL;
  192. unsigned int Count;
  193. unsigned int Bytes;
  194. unsigned int RetCode;
  195. unsigned int ConnectionNumber;
  196. JOB_NAME_AREA JobNameArea;
  197. JOB_RECORD_AREA JobRecord;
  198. PRINTCON_HEADER PrintConHeader;
  199. unsigned char MailDirPath[NCP_MAX_PATH_LENGTH];
  200. /** Get the connection number for this connection **/
  201. RetCode = GetConnectionNumber(ConnectionHandle, &ConnectionNumber);
  202. if (RetCode) {
  203. goto CommonExit;
  204. }
  205. RetCode = GetBinderyObjectID (ConnectionHandle, LOGIN_NAME,
  206. OT_USER, &ObjectId);
  207. if (RetCode) {
  208. goto CommonExit;
  209. }
  210. /** Build the path to open the file **/
  211. sprintf(MailDirPath, "SYS:MAIL/%lX/PRINTCON.DAT", SwapLong(ObjectId));
  212. stream = fopen(NTNWtoUNCFormat( MailDirPath), "rb");
  213. if (stream == NULL) {
  214. RetCode = PS_ERR_OPENING_DB;
  215. goto CommonExit;
  216. }
  217. Bytes = fread( (unsigned char *) &PrintConHeader, sizeof( char), PRINTCON_HEADER_SIZE, stream);
  218. if (Bytes < PRINTCON_HEADER_SIZE) {
  219. RetCode = PS_ERR_INTERNAL_ERROR;
  220. goto CommonExit;
  221. }
  222. /** Check the version number **/
  223. if ((PrintConHeader.MajorVersion != 3 &&
  224. PrintConHeader.MajorVersion != 1) ||
  225. PrintConHeader.MinorVersion1 != 1 ||
  226. PrintConHeader.MinorVersion2 != 1) {
  227. RetCode = PS_ERR_BAD_VERSION;
  228. goto CommonExit;
  229. }
  230. /** Get the name we are looking for **/
  231. if (GetDefault) {
  232. if (PrintConHeader.DefaultJobName[0] == 0) {
  233. RetCode = PS_ERR_NO_DEFAULT_SPECIFIED;
  234. goto CommonExit;
  235. }
  236. pSearchJobName = PrintConHeader.DefaultJobName;
  237. }
  238. else {
  239. pSearchJobName = pJobName;
  240. }
  241. Count = 0;
  242. /** Go through all of the job entry to look for the name **/
  243. while (Count < MAX_JOB_NAME_ENTRY) {
  244. Bytes = fread( (unsigned char *) &JobNameArea, sizeof(unsigned char), JOB_NAME_AREA_SIZE, stream);
  245. if (Bytes < JOB_NAME_AREA_SIZE) {
  246. RetCode = PS_ERR_INTERNAL_ERROR;
  247. goto CommonExit;
  248. }
  249. Count++;
  250. /** Skip the entry with a null job name **/
  251. if (JobNameArea.JobName[0] == 0) {
  252. continue;
  253. }
  254. /** Is this the job name we are looking for? **/
  255. if (!_strcmpi(pSearchJobName, JobNameArea.JobName)) {
  256. break;
  257. }
  258. }
  259. /** See if we found the job name **/
  260. if (Count > MAX_JOB_NAME_ENTRY) {
  261. if (GetDefault) {
  262. RetCode = PS_ERR_GETTING_DEFAULT;
  263. }
  264. else {
  265. RetCode = PS_ERR_READING_RECORD;
  266. }
  267. goto CommonExit;
  268. }
  269. if (fseek(stream, JobNameArea.JobRecordOffset, SEEK_SET)) {
  270. RetCode = PS_ERR_READING_RECORD;
  271. goto CommonExit;
  272. }
  273. Bytes = fread( (unsigned char *) &JobRecord, sizeof(unsigned char), JOB_RECORD_AREA_SIZE, stream);
  274. if (Bytes < JOB_RECORD_AREA_SIZE) {
  275. RetCode = PS_ERR_READING_RECORD;
  276. goto CommonExit;
  277. }
  278. memset(pJobRecord, 0, PS_JOB_RECORD_SIZE);
  279. if (JobRecord.NotifyWhenDone) {
  280. pJobRecord->PrintJobFlag |= PS_JOB_NOTIFY;
  281. }
  282. if (JobRecord.BannerFlag) {
  283. pJobRecord->PrintJobFlag |= PS_JOB_PRINT_BANNER;
  284. }
  285. if (JobRecord.DataType) {
  286. pJobRecord->PrintJobFlag |= PS_JOB_EXPAND_TABS;
  287. }
  288. if (JobRecord.FormFeed) {
  289. pJobRecord->PrintJobFlag |= PS_JOB_NO_FORMFEED;
  290. }
  291. if (JobRecord.AutoEndCap) {
  292. pJobRecord->PrintJobFlag |= PS_JOB_AUTO_END;
  293. }
  294. if (JobRecord.TimeoutCount) {
  295. pJobRecord->PrintJobFlag |= PS_JOB_TIMEOUT;
  296. }
  297. pJobRecord->Copies = JobRecord.NumberOfCopies;
  298. pJobRecord->TabSize = JobRecord.TabSize;
  299. pJobRecord->TimeOutCount = JobRecord.TimeoutCount;
  300. pJobRecord->LocalPrinter = JobRecord.LocalPrinter;
  301. strcpy(pJobRecord->Mode, JobRecord.Mode);
  302. strcpy(pJobRecord->Device, JobRecord.Device);
  303. strcpy(pJobRecord->FormName, JobRecord.FormName);
  304. strcpy(pJobRecord->BannerName, JobRecord.BannerName);
  305. strcpy(pJobRecord->u.NonDS.PrintQueue, JobRecord.QueueName);
  306. strcpy(pJobRecord->u.NonDS.FileServer, JobRecord.ServerName);
  307. if (GetDefault && pJobName) {
  308. strcpy(pJobName, JobNameArea.JobName);
  309. }
  310. if (pOwner) {
  311. *pOwner = 0;
  312. }
  313. CommonExit:
  314. if (stream != NULL) {
  315. fclose( stream );
  316. }
  317. return RetCode;
  318. }