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.

270 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. #include "pdev.h" // defined in sub-directory such as DDICMDCB, FONTCB, etc.
  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. };
  28. VERBOSE(("OEMGetInfo(%s) entry.\n", OEM_INFO[dwInfo]));
  29. // Validate parameters.
  30. if( ( (OEMGI_GETSIGNATURE != dwInfo) &&
  31. (OEMGI_GETINTERFACEVERSION != dwInfo) &&
  32. (OEMGI_GETVERSION != dwInfo) ) ||
  33. (NULL == pcbNeeded)
  34. )
  35. {
  36. ERR(("OEMGetInfo() ERROR_INVALID_PARAMETER.\n"));
  37. // Did not write any bytes.
  38. if(NULL != pcbNeeded)
  39. *pcbNeeded = 0;
  40. return FALSE;
  41. }
  42. // Need/wrote 4 bytes.
  43. *pcbNeeded = 4;
  44. // Validate buffer size. Minimum size is four bytes.
  45. if( (NULL == pBuffer) || (4 > cbSize) )
  46. {
  47. ERR(("OEMGetInfo() ERROR_INSUFFICIENT_BUFFER.\n"));
  48. return FALSE;
  49. }
  50. // Write information to buffer.
  51. switch(dwInfo)
  52. {
  53. case OEMGI_GETSIGNATURE:
  54. *(LPDWORD)pBuffer = OEM_SIGNATURE;
  55. break;
  56. case OEMGI_GETINTERFACEVERSION:
  57. *(LPDWORD)pBuffer = PRINTER_OEMINTF_VERSION;
  58. break;
  59. case OEMGI_GETVERSION:
  60. *(LPDWORD)pBuffer = OEM_VERSION;
  61. break;
  62. }
  63. return TRUE;
  64. }
  65. BOOL APIENTRY OEMDevMode(
  66. DWORD dwMode,
  67. POEMDMPARAM pOEMDevModeParam)
  68. {
  69. LPCSTR OEMDevMode_fMode[] = { "NULL",
  70. "OEMDM_SIZE",
  71. "OEMDM_DEFAULT",
  72. "OEMDM_CONVERT",
  73. "OEMDM_MERGE",
  74. };
  75. VERBOSE(("OEMDevMode(%s) entry.\n", OEMDevMode_fMode[dwMode]));
  76. // Validate parameters.
  77. if(!BIsValidOEMDevModeParam(dwMode, pOEMDevModeParam))
  78. {
  79. ERR(("OEMDevMode() ERROR_INVALID_PARAMETER.\n"));
  80. VDumpOEMDevModeParam(pOEMDevModeParam);
  81. return FALSE;
  82. }
  83. // Verify OEM extra data size.
  84. if( (dwMode != OEMDM_SIZE) &&
  85. sizeof(OEMUD_EXTRADATA) > pOEMDevModeParam->cbBufSize )
  86. {
  87. ERR(("OEMDevMode() ERROR_INSUFFICIENT_BUFFER.\n"));
  88. return FALSE;
  89. }
  90. // Handle dwMode.
  91. switch(dwMode)
  92. {
  93. case OEMDM_SIZE:
  94. pOEMDevModeParam->cbBufSize = sizeof(OEMUD_EXTRADATA);
  95. break;
  96. case OEMDM_DEFAULT:
  97. return BInitOEMExtraData((POEMUD_EXTRADATA)pOEMDevModeParam->pOEMDMOut);
  98. case OEMDM_CONVERT:
  99. // nothing to convert for this private devmode. So just initialize it.
  100. return BInitOEMExtraData((POEMUD_EXTRADATA)pOEMDevModeParam->pOEMDMOut);
  101. case OEMDM_MERGE:
  102. if(!BMergeOEMExtraData((POEMUD_EXTRADATA)pOEMDevModeParam->pOEMDMIn,
  103. (POEMUD_EXTRADATA)pOEMDevModeParam->pOEMDMOut) )
  104. {
  105. DBGPRINT(DBG_WARNING,("OEMUD OEMDevMode(): not valid OEM Extra Data.\n"));
  106. return FALSE;
  107. }
  108. break;
  109. }
  110. return TRUE;
  111. }
  112. //////////////////////////////////////////////////////////////////////////
  113. // Function: BIsValidOEMDevModeParam
  114. //
  115. // Description: Validates OEM_DEVMODEPARAM structure.
  116. //
  117. //
  118. // Parameters:
  119. //
  120. // dwMode calling mode
  121. // pOEMDevModeParam Pointer to a OEMDEVMODEPARAM structure.
  122. //
  123. //
  124. // Returns: TRUE if valid; FALSE otherwise.
  125. //
  126. //
  127. // Comments:
  128. //
  129. //NOTICE-2002/03/28-hiroi-:
  130. // History:
  131. // 02/11/97 APresley Created.
  132. //
  133. //////////////////////////////////////////////////////////////////////////
  134. static BOOL BIsValidOEMDevModeParam(
  135. DWORD dwMode,
  136. POEMDMPARAM pOEMDevModeParam)
  137. {
  138. BOOL bValid = TRUE;
  139. if(NULL == pOEMDevModeParam)
  140. {
  141. DBGPRINT(DBG_WARNING,("OEMUD IsValidOEMDevModeParam(): pOEMDevModeParam is NULL.\n"));
  142. return FALSE;
  143. }
  144. if(sizeof(OEMDMPARAM) > pOEMDevModeParam->cbSize)
  145. {
  146. DBGPRINT(DBG_WARNING,("OEMUD IsValidOEMDevModeParam(): cbSize is smaller than sizeof(OEM_DEVMODEPARAM).\n"));
  147. bValid = FALSE;
  148. }
  149. if(NULL == pOEMDevModeParam->hPrinter)
  150. {
  151. DBGPRINT(DBG_WARNING,("OEMUD IsValidOEMDevModeParam(): hPrinter is NULL.\n"));
  152. bValid = FALSE;
  153. }
  154. if(NULL == pOEMDevModeParam->hModule)
  155. {
  156. DBGPRINT(DBG_WARNING,("OEMUD IsValidOEMDevModeParam(): hModule is NULL.\n"));
  157. bValid = FALSE;
  158. }
  159. if( (0 != pOEMDevModeParam->cbBufSize) &&
  160. (NULL == pOEMDevModeParam->pOEMDMOut)
  161. )
  162. {
  163. DBGPRINT(DBG_WARNING,("OEMUD IsValidOEMDevModeParam(): pOEMDMOut is NULL when it should not be.\n"));
  164. bValid = FALSE;
  165. }
  166. if( (OEMDM_MERGE == dwMode) && (NULL == pOEMDevModeParam->pOEMDMIn) )
  167. {
  168. DBGPRINT(DBG_WARNING,("OEMUD IsValidOEMDevModeParam(): pOEMDMIn is NULL when it should not be.\n"));
  169. bValid = FALSE;
  170. }
  171. return bValid;
  172. }
  173. //////////////////////////////////////////////////////////////////////////
  174. // Function: VDumpOEMDevModeParam
  175. //
  176. // Description: Debug dump of OEM_DEVMODEPARAM structure.
  177. //
  178. //
  179. // Parameters:
  180. //
  181. // pOEMDevModeParam Pointer to an OEM DevMode param structure.
  182. //
  183. //
  184. // Returns: N/A.
  185. //
  186. //
  187. // Comments:
  188. //
  189. //NOTICE-2002/03/28-hiroi-:
  190. // History:
  191. // 02/18/97 APresley Created.
  192. //
  193. //////////////////////////////////////////////////////////////////////////
  194. static void VDumpOEMDevModeParam(POEMDMPARAM pOEMDevModeParam)
  195. {
  196. // Can't dump if pOEMDevModeParam NULL.
  197. if(NULL != pOEMDevModeParam)
  198. {
  199. DBGPRINT(DBG_WARNING,("\n\tOEM_DEVMODEPARAM dump:\n\n"));
  200. DBGPRINT(DBG_WARNING,("\tcbSize = %d.\n", pOEMDevModeParam->cbSize));
  201. DBGPRINT(DBG_WARNING,("\thPrinter = %#lx.\n", pOEMDevModeParam->hPrinter));
  202. DBGPRINT(DBG_WARNING,("\thModule = %#lx.\n", pOEMDevModeParam->hModule));
  203. DBGPRINT(DBG_WARNING,("\tpPublicDMIn = %#lx.\n", pOEMDevModeParam->pPublicDMIn));
  204. DBGPRINT(DBG_WARNING,("\tpPublicDMOut = %#lx.\n", pOEMDevModeParam->pPublicDMOut));
  205. DBGPRINT(DBG_WARNING,("\tpOEMDMIn = %#lx.\n", pOEMDevModeParam->pOEMDMIn));
  206. DBGPRINT(DBG_WARNING,("\tpOEMDMOut = %#lx.\n", pOEMDevModeParam->pOEMDMOut));
  207. DBGPRINT(DBG_WARNING,("\tcbBufSize = %d.\n", pOEMDevModeParam->cbBufSize));
  208. }
  209. }