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.

272 lines
7.2 KiB

  1. /*++
  2. Copyright (c) 1996-1998 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. // NTRAID#NTBUG9-588495-2002/03/28-yasuho-: Remove dead code.
  15. #include "pdev.h"
  16. DWORD gdwDrvMemPoolTag = 'meoD'; // lib.h requires this global var, for debugging
  17. ////////////////////////////////////////////////////////
  18. // INTERNAL PROTOTYPES
  19. ////////////////////////////////////////////////////////
  20. static BOOL BIsValidOEMDevModeParam(DWORD dwMode, POEMDMPARAM pOEMDevModeParam);
  21. static void VDumpOEMDevModeParam(POEMDMPARAM pOEMDevModeParam);
  22. BOOL APIENTRY OEMGetInfo(DWORD dwInfo, PVOID pBuffer, DWORD cbSize, PDWORD pcbNeeded)
  23. {
  24. LPCSTR OEM_INFO[] = { "Bad Index",
  25. "OEMGI_GETSIGNATURE",
  26. "OEMGI_GETINTERFACEVERSION",
  27. "OEMGI_GETVERSION",
  28. };
  29. VERBOSE(("OEMGetInfo(%s) entry.\n", OEM_INFO[dwInfo]));
  30. // Validate parameters.
  31. if( ( (OEMGI_GETSIGNATURE != dwInfo) &&
  32. (OEMGI_GETINTERFACEVERSION != dwInfo) &&
  33. (OEMGI_GETVERSION != dwInfo) ) ||
  34. (NULL == pcbNeeded)
  35. )
  36. {
  37. ERR(("OEMGetInfo() ERROR_INVALID_PARAMETER.\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. ERR(("OEMGetInfo() ERROR_INSUFFICIENT_BUFFER.\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. };
  76. VERBOSE(("OEMDevMode(%s) entry.\n", OEMDevMode_fMode[dwMode]));
  77. // Validate parameters.
  78. if(!BIsValidOEMDevModeParam(dwMode, pOEMDevModeParam))
  79. {
  80. ERR(("OEMDevMode() ERROR_INVALID_PARAMETER.\n"));
  81. VDumpOEMDevModeParam(pOEMDevModeParam);
  82. return FALSE;
  83. }
  84. // Verify OEM extra data size.
  85. if( (dwMode != OEMDM_SIZE) &&
  86. sizeof(OEMUD_EXTRADATA) > pOEMDevModeParam->cbBufSize )
  87. {
  88. ERR(("OEMDevMode() ERROR_INSUFFICIENT_BUFFER.\n"));
  89. return FALSE;
  90. }
  91. // Handle dwMode.
  92. switch(dwMode)
  93. {
  94. case OEMDM_SIZE:
  95. pOEMDevModeParam->cbBufSize = sizeof(OEMUD_EXTRADATA);
  96. break;
  97. case OEMDM_DEFAULT:
  98. return BInitOEMExtraData((POEMUD_EXTRADATA)pOEMDevModeParam->pOEMDMOut);
  99. case OEMDM_CONVERT:
  100. // nothing to convert for this private devmode. So just initialize it.
  101. return BInitOEMExtraData((POEMUD_EXTRADATA)pOEMDevModeParam->pOEMDMOut);
  102. case OEMDM_MERGE:
  103. if(!BMergeOEMExtraData((POEMUD_EXTRADATA)pOEMDevModeParam->pOEMDMIn,
  104. (POEMUD_EXTRADATA)pOEMDevModeParam->pOEMDMOut) )
  105. {
  106. DBGPRINT(DBG_WARNING,("OEMUD OEMDevMode(): not valid OEM Extra Data.\n"));
  107. return FALSE;
  108. }
  109. break;
  110. }
  111. return TRUE;
  112. }
  113. //////////////////////////////////////////////////////////////////////////
  114. // Function: BIsValidOEMDevModeParam
  115. //
  116. // Description: Validates OEM_DEVMODEPARAM structure.
  117. //
  118. //
  119. // Parameters:
  120. //
  121. // dwMode calling mode
  122. // pOEMDevModeParam Pointer to a OEMDEVMODEPARAM structure.
  123. //
  124. //
  125. // Returns: TRUE if valid; FALSE otherwise.
  126. //
  127. //
  128. // Comments:
  129. //
  130. //
  131. // History:
  132. // 02/11/97 APresley Created.
  133. //
  134. //////////////////////////////////////////////////////////////////////////
  135. static BOOL BIsValidOEMDevModeParam(
  136. DWORD dwMode,
  137. POEMDMPARAM pOEMDevModeParam)
  138. {
  139. BOOL bValid = TRUE;
  140. if(NULL == pOEMDevModeParam)
  141. {
  142. DBGPRINT(DBG_WARNING,("OEMUD IsValidOEMDevModeParam(): pOEMDevModeParam is NULL.\n"));
  143. return FALSE;
  144. }
  145. if(sizeof(OEMDMPARAM) > pOEMDevModeParam->cbSize)
  146. {
  147. DBGPRINT(DBG_WARNING,("OEMUD IsValidOEMDevModeParam(): cbSize is smaller than sizeof(OEM_DEVMODEPARAM).\n"));
  148. bValid = FALSE;
  149. }
  150. if(NULL == pOEMDevModeParam->hPrinter)
  151. {
  152. DBGPRINT(DBG_WARNING,("OEMUD IsValidOEMDevModeParam(): hPrinter is NULL.\n"));
  153. bValid = FALSE;
  154. }
  155. if(NULL == pOEMDevModeParam->hModule)
  156. {
  157. DBGPRINT(DBG_WARNING,("OEMUD IsValidOEMDevModeParam(): hModule is NULL.\n"));
  158. bValid = FALSE;
  159. }
  160. if( (0 != pOEMDevModeParam->cbBufSize) &&
  161. (NULL == pOEMDevModeParam->pOEMDMOut)
  162. )
  163. {
  164. DBGPRINT(DBG_WARNING,("OEMUD IsValidOEMDevModeParam(): pOEMDMOut is NULL when it should not be.\n"));
  165. bValid = FALSE;
  166. }
  167. if( (OEMDM_MERGE == dwMode) && (NULL == pOEMDevModeParam->pOEMDMIn) )
  168. {
  169. DBGPRINT(DBG_WARNING,("OEMUD IsValidOEMDevModeParam(): pOEMDMIn is NULL when it should not be.\n"));
  170. bValid = FALSE;
  171. }
  172. return bValid;
  173. }
  174. //////////////////////////////////////////////////////////////////////////
  175. // Function: VDumpOEMDevModeParam
  176. //
  177. // Description: Debug dump of OEM_DEVMODEPARAM structure.
  178. //
  179. //
  180. // Parameters:
  181. //
  182. // pOEMDevModeParam Pointer to an OEM DevMode param structure.
  183. //
  184. //
  185. // Returns: N/A.
  186. //
  187. //
  188. // Comments:
  189. //
  190. //
  191. // History:
  192. // 02/18/97 APresley Created.
  193. //
  194. //////////////////////////////////////////////////////////////////////////
  195. static void VDumpOEMDevModeParam(POEMDMPARAM pOEMDevModeParam)
  196. {
  197. // Can't dump if pOEMDevModeParam NULL.
  198. if(NULL != pOEMDevModeParam)
  199. {
  200. DBGPRINT(DBG_WARNING,("\n\tOEM_DEVMODEPARAM dump:\n\n"));
  201. DBGPRINT(DBG_WARNING,("\tcbSize = %d.\n", pOEMDevModeParam->cbSize));
  202. DBGPRINT(DBG_WARNING,("\thPrinter = %#lx.\n", pOEMDevModeParam->hPrinter));
  203. DBGPRINT(DBG_WARNING,("\thModule = %#lx.\n", pOEMDevModeParam->hModule));
  204. DBGPRINT(DBG_WARNING,("\tpPublicDMIn = %#lx.\n", pOEMDevModeParam->pPublicDMIn));
  205. DBGPRINT(DBG_WARNING,("\tpPublicDMOut = %#lx.\n", pOEMDevModeParam->pPublicDMOut));
  206. DBGPRINT(DBG_WARNING,("\tpOEMDMIn = %#lx.\n", pOEMDevModeParam->pOEMDMIn));
  207. DBGPRINT(DBG_WARNING,("\tpOEMDMOut = %#lx.\n", pOEMDevModeParam->pOEMDMOut));
  208. DBGPRINT(DBG_WARNING,("\tcbBufSize = %d.\n", pOEMDevModeParam->cbBufSize));
  209. }
  210. }