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.

325 lines
7.2 KiB

  1. /*++
  2. Copyright (c) 1992-1993 Microsoft Corporation
  3. Module Name:
  4. DosPrtP.c
  5. Abstract:
  6. This contains macros and prototypes private to the DosPrint APIs.
  7. Author:
  8. John Rogers (JohnRo) 02-Oct-1992
  9. Notes:
  10. Revision History:
  11. 02-Oct-1992 JohnRo
  12. Created for RAID 3556: DosPrintQGetInfo(from downlevel) level 3, rc=124.
  13. (4&5 too.)
  14. 08-Feb-1993 JohnRo
  15. RAID 10164: Data misalignment error during XsDosPrintQGetInfo().
  16. DosPrint API cleanup: avoid const vs. volatile compiler warnings.
  17. Extracted job count routine to netlib for use by convprt.c stuff.
  18. Added some IN and OUT keywords.
  19. 24-Mar-1993 JohnRo
  20. RAID 2974: NET PRINT says NT printer is held when it isn't.
  21. 17-May-1993 JohnRo
  22. FindLocalJob() should use INVALID_HANDLE_VALUE for consistentcy.
  23. Use NetpKdPrint() where possible.
  24. 29-Mar-1995 AlbertT
  25. Support for pause/resume/purge printer queue added.
  26. --*/
  27. #ifndef UNICODE
  28. #error "RxPrint APIs assume RxRemoteApi uses wide characters."
  29. #endif
  30. #define NOMINMAX
  31. #define NOSERVICE // Avoid <winsvc.h> vs. <lmsvc.h> conflicts.
  32. #include <windows.h>
  33. #include <lmcons.h> // NET_API_STATUS.
  34. #include <netdebug.h> // NetpKdPrint(), etc.
  35. #ifdef _WINSPOOL_
  36. #error "Include of winspool.h moved, make sure it doesn't get UNICODE."
  37. #endif
  38. #undef UNICODE
  39. #undef TEXT
  40. #define TEXT(quote) quote
  41. #include <winspool.h>
  42. #undef TEXT
  43. #define TEXT(quote) __TEXT(quote)
  44. #define UNICODE
  45. #ifndef _WINSPOOL_
  46. #error "Oops, winspool.h changed, make sure this code is still OK."
  47. #endif
  48. #include <dosprtp.h> // prototypes
  49. #include <lmapibuf.h> // NetApiBufferFree(), etc.
  50. #include <lmerr.h> // NO_ERROR, NERR_, and ERROR_ equates.
  51. #include <lmshare.h> // SHARE_INFO_2, STYPE_ equates, etc.
  52. #include <prefix.h> // PREFIX_ equates.
  53. #include <rxprint.h> // PPRQINFOW, etc.
  54. #include <string.h> // strrchr().
  55. #include <tstring.h> // NetpAlloc{type}From{type}.
  56. #include <wchar.h> // wscrchr().
  57. #include "myspool.h"
  58. NET_API_STATUS
  59. CommandALocalPrinterW(
  60. IN LPWSTR PrinterName,
  61. IN DWORD Command // PRINTER_CONTROL_PAUSE, etc.
  62. )
  63. {
  64. NET_API_STATUS ApiStatus;
  65. HANDLE PrinterHandle = INVALID_HANDLE_VALUE;
  66. PRINTER_DEFAULTSW pd = { NULL, NULL, PRINTER_ACCESS_ADMINISTER };
  67. if ( !MyOpenPrinterW(PrinterName, &PrinterHandle, &pd)) {
  68. ApiStatus = GetLastError();
  69. goto Cleanup;
  70. }
  71. if ( !MySetPrinterW(
  72. PrinterHandle,
  73. 0, // info level
  74. NULL, // no job structure
  75. Command) ) {
  76. ApiStatus = GetLastError();
  77. NetpKdPrint(( PREFIX_DOSPRINT
  78. "CommandALocalPrinterW: FAILED COMMAND " FORMAT_DWORD
  79. " for printer " FORMAT_LPWSTR ", api status " FORMAT_API_STATUS
  80. ".\n", Command, PrinterName, ApiStatus ));
  81. goto Cleanup;
  82. } else {
  83. ApiStatus = NO_ERROR;
  84. }
  85. Cleanup:
  86. if (PrinterHandle != INVALID_HANDLE_VALUE) {
  87. (VOID) MyClosePrinter(PrinterHandle);
  88. }
  89. return (ApiStatus);
  90. } // CommandALocalPrinterW
  91. NET_API_STATUS
  92. CommandALocalJobA(
  93. IN HANDLE PrinterHandle, OPTIONAL
  94. IN LPWSTR LocalServerNameW,
  95. IN LPSTR LocalServerNameA,
  96. IN DWORD JobId,
  97. IN DWORD Level,
  98. IN LPBYTE pJob,
  99. IN DWORD Command // JOB_CONTROL_PAUSE, etc.
  100. )
  101. /*++
  102. Routine Description:
  103. Sends a command to a Job based on a JobId. If a PrintHandle
  104. is passed in, it is used; otherwise a temporary one is opened
  105. and used instead.
  106. This is the ansi version--pJob must be ansi. The LocalSeverName
  107. can be passed in either ansi or UNICODE.
  108. Arguments:
  109. PrinterHandle - Print handle to use, may be NULL. If it is
  110. is NULL, then LocalServerName should point to the printer
  111. name that should be opened.
  112. LocalServerNameW - Used only if PrintHandle is NULL.
  113. LocalServerNameA - Used only if PrintHandle and LocalServerNamwW are NULL.
  114. JobId - Job that should be modified
  115. Level - Specifies pJob info level
  116. pJob - Information to set about job, level specified by Level
  117. ** WARNING ** This is an ANSI structure.
  118. Command - Command to execute on job
  119. Return Value:
  120. Return code, may be a win32 error code (!?)
  121. --*/
  122. {
  123. NET_API_STATUS ApiStatus;
  124. HANDLE PrinterHandleClose = INVALID_HANDLE_VALUE;
  125. //
  126. // If a print handle wasn't passed in, open one ourselves.
  127. // We store it in PrinterHandleClose so that we can close it later.
  128. //
  129. if ( PrinterHandle == NULL ) {
  130. if ( LocalServerNameW ){
  131. if ( !MyOpenPrinterW( LocalServerNameW, &PrinterHandle, NULL )) {
  132. ApiStatus = GetLastError();
  133. goto Cleanup;
  134. }
  135. } else {
  136. if ( !MyOpenPrinterA( LocalServerNameA, &PrinterHandle, NULL )) {
  137. ApiStatus = GetLastError();
  138. goto Cleanup;
  139. }
  140. }
  141. PrinterHandleClose = PrinterHandle;
  142. }
  143. if ( !MySetJobA(
  144. PrinterHandle,
  145. JobId,
  146. Level,
  147. pJob,
  148. Command) ) {
  149. ApiStatus = GetLastError();
  150. NetpKdPrint(( PREFIX_DOSPRINT
  151. "CommandALocalJobA: FAILED COMMAND " FORMAT_DWORD " for job "
  152. FORMAT_DWORD ", api status " FORMAT_API_STATUS ".\n",
  153. Command, JobId, ApiStatus ));
  154. goto Cleanup;
  155. } else {
  156. ApiStatus = NO_ERROR;
  157. }
  158. Cleanup:
  159. if (PrinterHandleClose != INVALID_HANDLE_VALUE) {
  160. (VOID) MyClosePrinter(PrinterHandle);
  161. }
  162. return (ApiStatus);
  163. } // CommandALocalJobA
  164. LPSTR
  165. FindQueueNameInPrinterNameA(
  166. IN LPCSTR PrinterName
  167. )
  168. {
  169. LPSTR QueueName;
  170. NetpAssert( PrinterName != NULL );
  171. QueueName = strrchr( PrinterName, '\\');
  172. if (QueueName) {
  173. ++QueueName; // Skip past the backslash.
  174. } else {
  175. QueueName = (LPSTR) PrinterName;
  176. }
  177. NetpAssert( QueueName != NULL );
  178. return (QueueName);
  179. }
  180. LPWSTR
  181. FindQueueNameInPrinterNameW(
  182. IN LPCWSTR PrinterName
  183. )
  184. {
  185. LPWSTR QueueName;
  186. NetpAssert( PrinterName != NULL );
  187. QueueName = wcsrchr( PrinterName, L'\\');
  188. if (QueueName) {
  189. ++QueueName; // Skip past the backslash.
  190. } else {
  191. QueueName = (LPWSTR) PrinterName;
  192. }
  193. NetpAssert( QueueName != NULL );
  194. return (QueueName);
  195. }
  196. WORD
  197. PrjStatusFromJobStatus(
  198. IN DWORD JobStatus
  199. )
  200. {
  201. WORD PrjStatus = 0;
  202. if (JobStatus & JOB_STATUS_SPOOLING)
  203. PrjStatus |= PRJ_QS_SPOOLING;
  204. if (JobStatus & JOB_STATUS_PAUSED)
  205. PrjStatus |= PRJ_QS_PAUSED;
  206. if (JobStatus & JOB_STATUS_PRINTING)
  207. PrjStatus |= PRJ_QS_PRINTING;
  208. if (JobStatus & JOB_STATUS_ERROR)
  209. PrjStatus |= PRJ_ERROR;
  210. return (PrjStatus);
  211. } // PrjStatusFromJobStatus
  212. WORD
  213. PrqStatusFromPrinterStatus(
  214. IN DWORD PrinterStatus
  215. )
  216. {
  217. WORD PrqStatus;
  218. if (PrinterStatus & PRINTER_STATUS_PAUSED) {
  219. PrqStatus = PRQ_PAUSED;
  220. } else if (PrinterStatus & PRINTER_STATUS_ERROR) {
  221. PrqStatus = PRQ_ERROR;
  222. } else if (PrinterStatus & PRINTER_STATUS_PENDING_DELETION) {
  223. PrqStatus = PRQ_PENDING;
  224. } else {
  225. PrqStatus = PRQ_ACTIVE;
  226. }
  227. return (PrqStatus);
  228. } // PrqStatusFromPrinterStatus