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.

273 lines
7.4 KiB

  1. /*++
  2. Copyright (c) 1996-1999 Microsoft Corporation
  3. Module Name:
  4. main.c
  5. Abstract:
  6. Implementation of OEMGetInfo and OEMDevMode.
  7. Shared by all Unidrv OEM test dll's.
  8. Environment:
  9. Windows NT Unidrv driver
  10. Revision History:
  11. 04/07/97 -zhanw-
  12. Created it.
  13. --*/
  14. #include "pdev.h"
  15. DWORD gdwDrvMemPoolTag = 'meoD'; // lib.h requires this global var, for debugging
  16. ////////////////////////////////////////////////////////
  17. // INTERNAL PROTOTYPES
  18. ////////////////////////////////////////////////////////
  19. static BOOL BIsValidOEMDevModeParam(DWORD dwMode, POEMDMPARAM pOEMDevModeParam);
  20. static void VDumpOEMDevModeParam(POEMDMPARAM pOEMDevModeParam);
  21. BOOL APIENTRY OEMGetInfo(DWORD dwInfo, PVOID pBuffer, DWORD cbSize, PDWORD pcbNeeded)
  22. {
  23. LPCSTR OEM_INFO[] = { "Bad Index",
  24. "OEMGI_GETSIGNATURE",
  25. "OEMGI_GETINTERFACEVERSION",
  26. "OEMGI_GETVERSION",
  27. "OUT OF RANGE",
  28. };
  29. DBGPRINT(DBG_WARNING,(DLLTEXT("OEMGetInfo(%s) entry.\r\n"), OEM_INFO[dwInfo < 4? dwInfo: 4]));
  30. // Validate parameters.
  31. if( ( (OEMGI_GETSIGNATURE != dwInfo) &&
  32. (OEMGI_GETINTERFACEVERSION != dwInfo) &&
  33. (OEMGI_GETVERSION != dwInfo) ) ||
  34. (NULL == pcbNeeded)
  35. )
  36. {
  37. DBGPRINT(DBG_WARNING,(ERRORTEXT("OEMGetInfo() ERROR_INVALID_PARAMETER.\r\n")));
  38. // Did not write any bytes.
  39. if(NULL != pcbNeeded)
  40. *pcbNeeded = 0;
  41. return FALSE;
  42. }
  43. // Need/wrote 4 bytes.
  44. *pcbNeeded = 4;
  45. // Validate buffer size. Minimum size is four bytes.
  46. if( (NULL == pBuffer) || (4 > cbSize) )
  47. {
  48. DBGPRINT(DBG_WARNING,(ERRORTEXT("OEMGetInfo() ERROR_INSUFFICIENT_BUFFER.\r\n")));
  49. return FALSE;
  50. }
  51. // Write information to buffer.
  52. switch(dwInfo)
  53. {
  54. case OEMGI_GETSIGNATURE:
  55. *(LPDWORD)pBuffer = OEM_SIGNATURE;
  56. break;
  57. case OEMGI_GETINTERFACEVERSION:
  58. *(LPDWORD)pBuffer = PRINTER_OEMINTF_VERSION;
  59. break;
  60. case OEMGI_GETVERSION:
  61. *(LPDWORD)pBuffer = OEM_VERSION;
  62. break;
  63. }
  64. return TRUE;
  65. }
  66. BOOL APIENTRY OEMDevMode(
  67. DWORD dwMode,
  68. POEMDMPARAM pOEMDevModeParam)
  69. {
  70. LPCSTR OEMDevMode_fMode[] = { "NULL",
  71. "OEMDM_SIZE",
  72. "OEMDM_DEFAULT",
  73. "OEMDM_CONVERT",
  74. "OEMDM_MERGE",
  75. "OUT OF RANGE",
  76. };
  77. DBGPRINT(DBG_WARNING,(DLLTEXT("OEMDevMode(%s) entry.\r\n"), OEMDevMode_fMode[dwMode < 5? dwMode: 5]));
  78. // Validate parameters.
  79. if(!BIsValidOEMDevModeParam(dwMode, pOEMDevModeParam))
  80. {
  81. DBGPRINT(DBG_WARNING,(ERRORTEXT("OEMDevMode() ERROR_INVALID_PARAMETER.\r\n")));
  82. VDumpOEMDevModeParam(pOEMDevModeParam);
  83. return FALSE;
  84. }
  85. // Verify OEM extra data size.
  86. if( (dwMode != OEMDM_SIZE) &&
  87. sizeof(OEMUD_EXTRADATA) > pOEMDevModeParam->cbBufSize )
  88. {
  89. DBGPRINT(DBG_WARNING,(ERRORTEXT("OEMDevMode() ERROR_INSUFFICIENT_BUFFER.\r\n")));
  90. return FALSE;
  91. }
  92. // Handle dwMode.
  93. switch(dwMode)
  94. {
  95. case OEMDM_SIZE:
  96. pOEMDevModeParam->cbBufSize = sizeof(OEMUD_EXTRADATA);
  97. break;
  98. case OEMDM_DEFAULT:
  99. return BInitOEMExtraData((POEMUD_EXTRADATA)pOEMDevModeParam->pOEMDMOut);
  100. case OEMDM_CONVERT:
  101. // nothing to convert for this private devmode. So just initialize it.
  102. return BInitOEMExtraData((POEMUD_EXTRADATA)pOEMDevModeParam->pOEMDMOut);
  103. case OEMDM_MERGE:
  104. if(!BMergeOEMExtraData((POEMUD_EXTRADATA)pOEMDevModeParam->pOEMDMIn,
  105. (POEMUD_EXTRADATA)pOEMDevModeParam->pOEMDMOut) )
  106. {
  107. DBGPRINT(DBG_WARNING,("OEMUD OEMDevMode(): not valid OEM Extra Data.\r\n"));
  108. return FALSE;
  109. }
  110. break;
  111. }
  112. return TRUE;
  113. }
  114. //////////////////////////////////////////////////////////////////////////
  115. // Function: BIsValidOEMDevModeParam
  116. //
  117. // Description: Validates OEM_DEVMODEPARAM structure.
  118. //
  119. //
  120. // Parameters:
  121. //
  122. // dwMode calling mode
  123. // pOEMDevModeParam Pointer to a OEMDEVMODEPARAM structure.
  124. //
  125. //
  126. // Returns: TRUE if valid; FALSE otherwise.
  127. //
  128. //
  129. // Comments:
  130. //
  131. //
  132. // History:
  133. // 02/11/97 APresley Created.
  134. //
  135. //////////////////////////////////////////////////////////////////////////
  136. static BOOL BIsValidOEMDevModeParam(
  137. DWORD dwMode,
  138. POEMDMPARAM pOEMDevModeParam)
  139. {
  140. BOOL bValid = TRUE;
  141. if(NULL == pOEMDevModeParam)
  142. {
  143. DBGPRINT(DBG_WARNING,("OEMUD IsValidOEMDevModeParam(): pOEMDevModeParam is NULL.\r\n"));
  144. return FALSE;
  145. }
  146. if(sizeof(OEMDMPARAM) > pOEMDevModeParam->cbSize)
  147. {
  148. DBGPRINT(DBG_WARNING,("OEMUD IsValidOEMDevModeParam(): cbSize is smaller than sizeof(OEM_DEVMODEPARAM).\r\n"));
  149. bValid = FALSE;
  150. }
  151. if(NULL == pOEMDevModeParam->hPrinter)
  152. {
  153. DBGPRINT(DBG_WARNING,("OEMUD IsValidOEMDevModeParam(): hPrinter is NULL.\r\n"));
  154. bValid = FALSE;
  155. }
  156. if(NULL == pOEMDevModeParam->hModule)
  157. {
  158. DBGPRINT(DBG_WARNING,("OEMUD IsValidOEMDevModeParam(): hModule is NULL.\r\n"));
  159. bValid = FALSE;
  160. }
  161. if( (0 != pOEMDevModeParam->cbBufSize) &&
  162. (NULL == pOEMDevModeParam->pOEMDMOut)
  163. )
  164. {
  165. DBGPRINT(DBG_WARNING,("OEMUD IsValidOEMDevModeParam(): pOEMDMOut is NULL when it should not be.\r\n"));
  166. bValid = FALSE;
  167. }
  168. if( (OEMDM_MERGE == dwMode) && (NULL == pOEMDevModeParam->pOEMDMIn) )
  169. {
  170. DBGPRINT(DBG_WARNING,("OEMUD IsValidOEMDevModeParam(): pOEMDMIn is NULL when it should not be.\r\n"));
  171. bValid = FALSE;
  172. }
  173. return bValid;
  174. }
  175. //////////////////////////////////////////////////////////////////////////
  176. // Function: VDumpOEMDevModeParam
  177. //
  178. // Description: Debug dump of OEM_DEVMODEPARAM structure.
  179. //
  180. //
  181. // Parameters:
  182. //
  183. // pOEMDevModeParam Pointer to an OEM DevMode param structure.
  184. //
  185. //
  186. // Returns: N/A.
  187. //
  188. //
  189. // Comments:
  190. //
  191. //
  192. // History:
  193. // 02/18/97 APresley Created.
  194. //
  195. //////////////////////////////////////////////////////////////////////////
  196. static void VDumpOEMDevModeParam(POEMDMPARAM pOEMDevModeParam)
  197. {
  198. // Can't dump if pOEMDevModeParam NULL.
  199. if(NULL != pOEMDevModeParam)
  200. {
  201. DBGPRINT(DBG_WARNING,("\r\n\tOEM_DEVMODEPARAM dump:\r\n\r\n"));
  202. DBGPRINT(DBG_WARNING,("\tcbSize = %d.\r\n", pOEMDevModeParam->cbSize));
  203. DBGPRINT(DBG_WARNING,("\thPrinter = %#lx.\r\n", pOEMDevModeParam->hPrinter));
  204. DBGPRINT(DBG_WARNING,("\thModule = %#lx.\r\n", pOEMDevModeParam->hModule));
  205. DBGPRINT(DBG_WARNING,("\tpPublicDMIn = %#lx.\r\n", pOEMDevModeParam->pPublicDMIn));
  206. DBGPRINT(DBG_WARNING,("\tpPublicDMOut = %#lx.\r\n", pOEMDevModeParam->pPublicDMOut));
  207. DBGPRINT(DBG_WARNING,("\tpOEMDMIn = %#lx.\r\n", pOEMDevModeParam->pOEMDMIn));
  208. DBGPRINT(DBG_WARNING,("\tpOEMDMOut = %#lx.\r\n", pOEMDevModeParam->pOEMDMOut));
  209. DBGPRINT(DBG_WARNING,("\tcbBufSize = %d.\r\n", pOEMDevModeParam->cbBufSize));
  210. }
  211. }