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.

263 lines
8.1 KiB

  1. // agfxc.cpp : Client side code for agfx.
  2. //
  3. // Created by FrankYe on 7/3/2000
  4. //
  5. #define UNICODE
  6. #define _UNICODE
  7. #include <windows.h>
  8. #include <mmsystem.h>
  9. #include <mmsysp.h>
  10. #include <tchar.h>
  11. #include <regstr.h>
  12. #include <ks.h>
  13. #include <ksmedia.h>
  14. #include "agfxp.h"
  15. #include "audiosrv.h"
  16. #include "audiosrvc.h"
  17. // ISSUE-2000/09/25-FrankYe TODO list
  18. // - move heap helpers somewhere else
  19. // - remove ClientUpdatePnpInfo, and hHeap extern definitions
  20. extern "C" void ClientUpdatePnpInfo(void);
  21. extern "C" HANDLE hHeap;
  22. //
  23. // This global variable tracks the most device interfaces contained in any
  24. // DEVICEINTERFACELIST structure created by these functions. This helps
  25. // validate the input to gfxDestroyDeviceInterfaceList
  26. //
  27. LONG gcMostDeviceInterfaces = 0;
  28. #define RPC_CALL_START RpcTryExcept {
  29. #define RPC_CALL_END_(status) } RpcExcept(1) { status = RpcExceptionCode(); } RpcEndExcept
  30. #define RPC_CALL_END } RpcExcept(1) { RpcExceptionCode(); } RpcEndExcept
  31. //=============================================================================
  32. //=== Heap helpers ===
  33. //=============================================================================
  34. static BOOL HeapFreeIfNotNull(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem)
  35. {
  36. return lpMem ? HeapFree(hHeap, dwFlags, lpMem) : TRUE;
  37. }
  38. //=============================================================================
  39. //=== gfx API ===
  40. //=============================================================================
  41. WINMMAPI LONG WINAPI gfxModifyGfx(DWORD Id, ULONG Order)
  42. {
  43. LONG status;
  44. ClientUpdatePnpInfo();
  45. RPC_CALL_START;
  46. status = s_gfxModifyGfx(Id, Order);
  47. RPC_CALL_END_(status);
  48. return status;
  49. }
  50. WINMMAPI LONG WINAPI gfxAddGfx(IN PCWSTR ZoneFactoryDi, IN PCWSTR GfxFactoryDi, IN ULONG Type, IN ULONG Order, OUT PULONG pNewId)
  51. {
  52. LONG status;
  53. if (IsBadStringPtr(ZoneFactoryDi, (UINT_PTR)(-1))) return ERROR_INVALID_PARAMETER;
  54. if (IsBadStringPtr(GfxFactoryDi, (UINT_PTR)(-1))) return ERROR_INVALID_PARAMETER;
  55. if (IsBadWritePtr(pNewId, sizeof(*pNewId))) return ERROR_INVALID_PARAMETER;
  56. ClientUpdatePnpInfo();
  57. RPC_CALL_START;
  58. status = s_gfxAddGfx((PWSTR)ZoneFactoryDi, (PWSTR)GfxFactoryDi, Type, Order, pNewId);
  59. RPC_CALL_END_(status);
  60. return status;
  61. }
  62. WINMMAPI LONG WINAPI gfxRemoveGfx(DWORD Id)
  63. {
  64. LONG status;
  65. ClientUpdatePnpInfo();
  66. RPC_CALL_START;
  67. status = s_gfxRemoveGfx(Id);
  68. RPC_CALL_END_(status);
  69. return status;
  70. }
  71. WINMMAPI LONG WINAPI gfxDestroyDeviceInterfaceList(PDEVICEINTERFACELIST pDiList)
  72. {
  73. LONG Count;
  74. PTSTR *ppDi;
  75. LONG result;
  76. if (IsBadReadPtr(&pDiList->Count, sizeof(pDiList->Count))) return ERROR_INVALID_PARAMETER;
  77. Count = pDiList->Count;
  78. if (Count < 0 || Count > gcMostDeviceInterfaces) return ERROR_INVALID_PARAMETER;
  79. if (IsBadWritePtr(pDiList, (PBYTE)&pDiList->DeviceInterface[Count] - (PBYTE)pDiList)) return ERROR_INVALID_PARAMETER;
  80. ppDi = &pDiList->DeviceInterface[0];
  81. while (Count-- > 0) if (IsBadStringPtr(*ppDi, (UINT_PTR)(-1))) return ERROR_INVALID_PARAMETER;
  82. // Now we are reasonably confident that we have good input
  83. // parameters. We design the following logic to return the
  84. // first error encountered, if any.
  85. ClientUpdatePnpInfo();
  86. result = NO_ERROR;
  87. Count = pDiList->Count;
  88. ppDi = &pDiList->DeviceInterface[0];
  89. while (Count-- > 0) if (!HeapFree(hHeap, 0, *(ppDi++)) && (NO_ERROR == result)) result = GetLastError();
  90. if ((!HeapFree(hHeap, 0, pDiList)) && (NO_ERROR == result)) result = GetLastError();
  91. SetLastError(result);
  92. return result;
  93. }
  94. WINMMAPI LONG WINAPI gfxEnumerateGfxs(PCWSTR ZoneFactoryDi, GFXENUMCALLBACK pGfxEnumCallback, PVOID Context)
  95. {
  96. LONG lresult;
  97. UNIQUE_PGFXLIST pGfxList = NULL;
  98. if (IsBadStringPtr(ZoneFactoryDi, (UINT_PTR)(-1))) return ERROR_INVALID_PARAMETER;
  99. if (IsBadCodePtr((FARPROC)pGfxEnumCallback)) return ERROR_INVALID_PARAMETER;
  100. ClientUpdatePnpInfo();
  101. RPC_CALL_START;
  102. lresult = s_gfxCreateGfxList((PWSTR)ZoneFactoryDi, &pGfxList);
  103. RPC_CALL_END_(lresult);
  104. // ISSUE-2000/09/25-FrankYe Should not have to check for pGfxList != NULL. Fix this interface
  105. if (!lresult && pGfxList)
  106. {
  107. if (pGfxList->Count > 0)
  108. {
  109. int i = 0;
  110. while (i < pGfxList->Count)
  111. {
  112. if (!lresult) lresult = pGfxEnumCallback(Context,
  113. pGfxList->Gfx[i].Id,
  114. pGfxList->Gfx[i].GfxFactoryDi,
  115. *(LPCLSID)(&pGfxList->Gfx[i].Clsid),
  116. pGfxList->Gfx[i].Type,
  117. pGfxList->Gfx[i].Order);
  118. HeapFree(hHeap, 0, pGfxList->Gfx[i].GfxFactoryDi);
  119. i++;
  120. }
  121. }
  122. HeapFree(hHeap, 0, pGfxList);
  123. }
  124. return lresult;
  125. }
  126. WINMMAPI LONG WINAPI gfxCreateGfxFactoriesList(PCWSTR ZoneFactoryDi, OUT PDEVICEINTERFACELIST *ppDiList)
  127. {
  128. LONG lresult;
  129. UNIQUE_PDILIST pDiList = NULL;
  130. if (IsBadWritePtr(ppDiList, sizeof(*ppDiList))) return ERROR_INVALID_PARAMETER;
  131. ClientUpdatePnpInfo();
  132. RPC_CALL_START;
  133. lresult = s_gfxCreateGfxFactoriesList((PWSTR)ZoneFactoryDi, &pDiList);
  134. RPC_CALL_END_(lresult);
  135. if (!lresult) {
  136. gcMostDeviceInterfaces = max(gcMostDeviceInterfaces, pDiList->Count);
  137. *ppDiList = (PDEVICEINTERFACELIST)pDiList;
  138. }
  139. return lresult;
  140. }
  141. WINMMAPI LONG WINAPI gfxCreateZoneFactoriesList(OUT PDEVICEINTERFACELIST *ppDiList)
  142. {
  143. LONG lresult;
  144. UNIQUE_PDILIST pDiList = NULL;
  145. if (IsBadWritePtr(ppDiList, sizeof(*ppDiList))) return ERROR_INVALID_PARAMETER;
  146. ClientUpdatePnpInfo();
  147. RPC_CALL_START;
  148. lresult = s_gfxCreateZoneFactoriesList(&pDiList);
  149. RPC_CALL_END_(lresult);
  150. if (!lresult) {
  151. gcMostDeviceInterfaces = max(gcMostDeviceInterfaces, pDiList->Count);
  152. *ppDiList = (PDEVICEINTERFACELIST)pDiList;
  153. }
  154. return lresult;
  155. }
  156. WINMMAPI LONG WINAPI gfxBatchChange(PGFXREMOVEREQUEST paGfxRemoveRequests, ULONG cGfxRemoveRequests,
  157. PGFXMODIFYREQUEST paGfxModifyRequests, ULONG cGfxModifyRequests,
  158. PGFXADDREQUEST paGfxAddRequests, ULONG cGfxAddRequests)
  159. {
  160. ULONG Index;
  161. LONG Error;
  162. if ((cGfxRemoveRequests > 0) && IsBadWritePtr(paGfxRemoveRequests, cGfxRemoveRequests * sizeof(*paGfxRemoveRequests))) return ERROR_INVALID_PARAMETER;
  163. if ((cGfxModifyRequests > 0) && IsBadWritePtr(paGfxModifyRequests, cGfxModifyRequests * sizeof(*paGfxModifyRequests))) return ERROR_INVALID_PARAMETER;
  164. if ((cGfxAddRequests > 0) && IsBadWritePtr(paGfxAddRequests, cGfxAddRequests * sizeof(*paGfxAddRequests))) return ERROR_INVALID_PARAMETER;
  165. ClientUpdatePnpInfo();
  166. Error = ERROR_SUCCESS;
  167. for (Index = 0; Index < cGfxRemoveRequests && ERROR_SUCCESS == Error; Index++)
  168. {
  169. Error = gfxRemoveGfx(paGfxRemoveRequests[Index].IdToRemove);
  170. paGfxRemoveRequests[Index].Error = Error;
  171. }
  172. for (Index = 0; Index < cGfxModifyRequests && ERROR_SUCCESS == Error; Index++)
  173. {
  174. Error = gfxModifyGfx(paGfxModifyRequests[Index].IdToModify,
  175. paGfxModifyRequests[Index].NewOrder);
  176. paGfxModifyRequests[Index].Error = Error;
  177. }
  178. for (Index = 0; Index < cGfxAddRequests && ERROR_SUCCESS == Error; Index++)
  179. {
  180. Error = gfxAddGfx(paGfxAddRequests[Index].ZoneFactoryDi,
  181. paGfxAddRequests[Index].GfxFactoryDi,
  182. paGfxAddRequests[Index].Type,
  183. paGfxAddRequests[Index].Order,
  184. &paGfxAddRequests[Index].NewId);
  185. paGfxAddRequests[Index].Error = Error;
  186. }
  187. return Error;
  188. }
  189. WINMMAPI LONG WINAPI gfxOpenGfx(DWORD dwGfxId, PHANDLE pFileHandle)
  190. {
  191. LONG status;
  192. ClientUpdatePnpInfo();
  193. RPC_CALL_START;
  194. status = s_gfxOpenGfx(GetCurrentProcessId(), dwGfxId, (RHANDLE*)pFileHandle);
  195. RPC_CALL_END_(status);
  196. return status;
  197. }
  198. WINMMAPI void WINAPI gfxLogon(DWORD dwProcessId)
  199. {
  200. ClientUpdatePnpInfo();
  201. RPC_CALL_START;
  202. s_gfxLogon(AudioSrv_IfHandle, dwProcessId);
  203. RPC_CALL_END;
  204. }
  205. WINMMAPI void WINAPI gfxLogoff(void)
  206. {
  207. ClientUpdatePnpInfo();
  208. RPC_CALL_START;
  209. s_gfxLogoff();
  210. RPC_CALL_END;
  211. }