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.

339 lines
8.4 KiB

  1. /////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998 Active Voice Corporation. All Rights Reserved.
  4. //
  5. // Active Agent(r) and Unified Communications(tm) are trademarks of Active Voice Corporation.
  6. //
  7. // Other brand and product names used herein are trademarks of their respective owners.
  8. //
  9. // The entire program and user interface including the structure, sequence, selection,
  10. // and arrangement of the dialog, the exclusively "yes" and "no" choices represented
  11. // by "1" and "2," and each dialog message are protected by copyrights registered in
  12. // the United States and by international treaties.
  13. //
  14. // Protected by one or more of the following United States patents: 5,070,526, 5,488,650,
  15. // 5,434,906, 5,581,604, 5,533,102, 5,568,540, 5,625,676, 5,651,054.
  16. //
  17. // Active Voice Corporation
  18. // Seattle, Washington
  19. // USA
  20. //
  21. /////////////////////////////////////////////////////////////////////////////////////////
  22. ////
  23. // propio.cpp - property i/o functions
  24. ////
  25. #include "winlocal.h"
  26. #include <mmsystem.h>
  27. #include <mapi.h>
  28. #include <mapidefs.h>
  29. #include "propio.h"
  30. #include "trace.h"
  31. #include "str.h"
  32. ////
  33. // private definitions
  34. ////
  35. // helper functions
  36. //
  37. static LRESULT PropIOOpen(LPMMIOINFO lpmmioinfo, LPTSTR lpszFileName);
  38. static LRESULT PropIOClose(LPMMIOINFO lpmmioinfo, UINT uFlags);
  39. static LRESULT PropIORead(LPMMIOINFO lpmmioinfo, HPSTR pch, LONG cch);
  40. static LRESULT PropIOWrite(LPMMIOINFO lpmmioinfo, const HPSTR pch, LONG cch, BOOL fFlush);
  41. static LRESULT PropIOSeek(LPMMIOINFO lpmmioinfo, LONG lOffset, int iOrigin);
  42. static LRESULT PropIORename(LPMMIOINFO lpmmioinfo, LPCTSTR lpszFileName, LPCTSTR lpszNewFileName);
  43. ////
  44. // public functions
  45. ////
  46. // PropIOProc - i/o procedure for property data
  47. // <lpmmioinfo> (i/o) information about open file
  48. // <uMessage> (i) message indicating the requested I/O operation
  49. // <lParam1> (i) message specific parameter
  50. // <lParam2> (i) message specific parameter
  51. // returns 0 if message not recognized, otherwise message specific value
  52. //
  53. // NOTE: the address of this function should be passed to the WavOpen()
  54. // or mmioInstallIOProc() functions for accessing property data.
  55. //
  56. LRESULT DLLEXPORT CALLBACK PropIOProc(LPSTR lpmmioinfo,
  57. UINT uMessage, LPARAM lParam1, LPARAM lParam2)
  58. {
  59. BOOL fSuccess = TRUE;
  60. LRESULT lResult = 0;
  61. if (lpmmioinfo == NULL)
  62. fSuccess = TraceFALSE(NULL);
  63. else switch (uMessage)
  64. {
  65. case MMIOM_OPEN:
  66. lResult = PropIOOpen((LPMMIOINFO) lpmmioinfo,
  67. (LPTSTR) lParam1);
  68. break;
  69. case MMIOM_CLOSE:
  70. lResult = PropIOClose((LPMMIOINFO) lpmmioinfo,
  71. (UINT) lParam1);
  72. break;
  73. case MMIOM_READ:
  74. lResult = PropIORead((LPMMIOINFO) lpmmioinfo,
  75. (HPSTR) lParam1, (LONG) lParam2);
  76. break;
  77. case MMIOM_WRITE:
  78. lResult = PropIOWrite((LPMMIOINFO) lpmmioinfo,
  79. (const HPSTR) lParam1, (LONG) lParam2, FALSE);
  80. break;
  81. case MMIOM_WRITEFLUSH:
  82. lResult = PropIOWrite((LPMMIOINFO) lpmmioinfo,
  83. (const HPSTR) lParam1, (LONG) lParam2, TRUE);
  84. break;
  85. case MMIOM_SEEK:
  86. lResult = PropIOSeek((LPMMIOINFO) lpmmioinfo,
  87. (LONG) lParam1, (int) lParam2);
  88. break;
  89. case MMIOM_RENAME:
  90. lResult = PropIORename((LPMMIOINFO) lpmmioinfo,
  91. (LPCTSTR) lParam1, (LPCTSTR) lParam2);
  92. break;
  93. default:
  94. lResult = 0;
  95. break;
  96. }
  97. return lResult;
  98. }
  99. ////
  100. // installable file i/o procedures
  101. ////
  102. static LRESULT PropIOOpen(LPMMIOINFO lpmmioinfo, LPTSTR lpszFileName)
  103. {
  104. BOOL fSuccess = TRUE;
  105. LPMESSAGE lpmsg;
  106. ULONG ulPropTag;
  107. ULONG ulFlags = 0L;
  108. HRESULT hr;
  109. IID IID_IStream;
  110. LPSTREAM lpStream;
  111. TracePrintf_0(NULL, 5,
  112. TEXT("PropIOOpen\n"));
  113. // convert MMIOINFO flags to equivalent OpenProperty flags
  114. //
  115. if (lpmmioinfo->dwFlags & MMIO_CREATE)
  116. ulFlags |= MAPI_CREATE | MAPI_MODIFY;
  117. if (lpmmioinfo->dwFlags & MMIO_READWRITE)
  118. ulFlags |= MAPI_MODIFY;
  119. // message pointer is within first element of info array
  120. //
  121. if ((lpmsg = (LPMESSAGE) lpmmioinfo->adwInfo[0]) == NULL)
  122. fSuccess = TraceFALSE(NULL);
  123. // property id is within second element of info array
  124. //
  125. else if ((ulPropTag = (ULONG) lpmmioinfo->adwInfo[1]) == (ULONG) 0)
  126. fSuccess = TraceFALSE(NULL);
  127. // open the property
  128. //
  129. else if ((hr = lpmsg->OpenProperty(ulPropTag, (LPCIID) &IID_IStream, 0,
  130. ulFlags, (LPUNKNOWN *) &lpStream)) != S_OK)
  131. {
  132. fSuccess = TraceFALSE(NULL);
  133. TracePrintf_1(NULL, 5,
  134. TEXT("OpenProperty failed (%ld)\n"),
  135. (long) hr);
  136. }
  137. else
  138. {
  139. // save stream pointer for use in other i/o routines
  140. //
  141. lpmmioinfo->adwInfo[0] = (DWORD) (LPVOID) lpStream;
  142. }
  143. // return the same error code given by mmioOpen
  144. //
  145. return fSuccess ? lpmmioinfo->wErrorRet = 0 : MMIOERR_CANNOTOPEN;
  146. }
  147. static LRESULT PropIOClose(LPMMIOINFO lpmmioinfo, UINT uFlags)
  148. {
  149. BOOL fSuccess = TRUE;
  150. LPSTREAM lpStream = (LPSTREAM) lpmmioinfo->adwInfo[0];
  151. UINT uRet = MMIOERR_CANNOTCLOSE;
  152. TracePrintf_0(NULL, 5,
  153. TEXT("PropIOClose\n"));
  154. // close the stream
  155. //
  156. if (lpStream->Release() < 0)
  157. {
  158. fSuccess = TraceFALSE(NULL);
  159. TracePrintf_0(NULL, 5,
  160. TEXT("Stream:Close failed\n"));
  161. }
  162. else
  163. {
  164. lpmmioinfo->adwInfo[0] = (DWORD) NULL;
  165. }
  166. return fSuccess ? 0 : uRet;
  167. }
  168. static LRESULT PropIORead(LPMMIOINFO lpmmioinfo, HPSTR pch, LONG cch)
  169. {
  170. BOOL fSuccess = TRUE;
  171. LPSTREAM lpStream = (LPSTREAM) lpmmioinfo->adwInfo[0];
  172. HRESULT hr;
  173. LONG lBytesRead = 0L;
  174. TracePrintf_1(NULL, 5,
  175. TEXT("PropIORead (%ld)\n"),
  176. (long) cch);
  177. if (cch <= 0)
  178. lBytesRead = 0; // nothing to do
  179. // read
  180. //
  181. else if ((hr = lpStream->Read((LPVOID) pch,
  182. (ULONG) cch, (ULONG FAR *) &lBytesRead)) != S_OK)
  183. {
  184. fSuccess = TraceFALSE(NULL);
  185. TracePrintf_2(NULL, 5,
  186. TEXT("IStream:Read failed (%ld, %ld)\n"),
  187. (long) hr,
  188. (long) lBytesRead);
  189. }
  190. // update simulated file position
  191. //
  192. else
  193. lpmmioinfo->lDiskOffset += (LONG) lBytesRead;
  194. TracePrintf_2(NULL, 5,
  195. TEXT("PropIO: lpmmioinfo->lDiskOffset=%ld, lBytesRead=%ld\n"),
  196. (long) lpmmioinfo->lDiskOffset,
  197. (long) lBytesRead);
  198. // return number of bytes read
  199. //
  200. return fSuccess ? lBytesRead : -1;
  201. }
  202. static LRESULT PropIOWrite(LPMMIOINFO lpmmioinfo, const HPSTR pch, LONG cch, BOOL fFlush)
  203. {
  204. BOOL fSuccess = TRUE;
  205. LPSTREAM lpStream = (LPSTREAM) lpmmioinfo->adwInfo[0];
  206. HRESULT hr;
  207. LONG lBytesWritten;
  208. TracePrintf_1(NULL, 5,
  209. TEXT("PropIOWrite (%ld)\n"),
  210. (long) cch);
  211. if (cch <= 0)
  212. lBytesWritten = 0; // nothing to do
  213. // write
  214. //
  215. else if ((hr = lpStream->Write((LPVOID) pch,
  216. (ULONG) cch, (ULONG FAR *) &lBytesWritten)) != S_OK)
  217. {
  218. fSuccess = TraceFALSE(NULL);
  219. TracePrintf_2(NULL, 5,
  220. TEXT("IStream:Write failed (%ld, %ld)\n"),
  221. (long) hr,
  222. (long) lBytesWritten);
  223. }
  224. // update file position
  225. //
  226. else
  227. lpmmioinfo->lDiskOffset += lBytesWritten;
  228. TracePrintf_2(NULL, 5,
  229. TEXT("PropIO: lpmmioinfo->lDiskOffset=%ld, lBytesWritten=%ld\n"),
  230. (long) lpmmioinfo->lDiskOffset,
  231. (long) lBytesWritten);
  232. // return number of bytes written
  233. //
  234. return fSuccess ? lBytesWritten : -1;
  235. }
  236. static LRESULT PropIOSeek(LPMMIOINFO lpmmioinfo, LONG lOffset, int iOrigin)
  237. {
  238. BOOL fSuccess = TRUE;
  239. LPSTREAM lpStream = (LPSTREAM) lpmmioinfo->adwInfo[0];
  240. HRESULT hr;
  241. LARGE_INTEGER largeOffset;
  242. ULARGE_INTEGER ulargePosNew;
  243. largeOffset.LowPart = (DWORD) lOffset;
  244. largeOffset.HighPart = (DWORD) 0L;
  245. TracePrintf_2(NULL, 5,
  246. TEXT("PropIOSeek (%ld, %d)\n"),
  247. (long) lOffset,
  248. (int) iOrigin);
  249. // seek
  250. //
  251. if ((hr = lpStream->Seek(largeOffset,
  252. (DWORD) iOrigin, &ulargePosNew)) != S_OK)
  253. {
  254. fSuccess = TraceFALSE(NULL);
  255. TracePrintf_1(NULL, 5,
  256. TEXT("IStream:Seek failed (%ld)\n"),
  257. (long) hr);
  258. }
  259. // update file position
  260. //
  261. else
  262. lpmmioinfo->lDiskOffset = (long) ulargePosNew.LowPart;
  263. TracePrintf_1(NULL, 5,
  264. TEXT("PropIO: lpmmioinfo->lDiskOffset=%ld\n"),
  265. (long) lpmmioinfo->lDiskOffset);
  266. return fSuccess ? lpmmioinfo->lDiskOffset : -1;
  267. }
  268. static LRESULT PropIORename(LPMMIOINFO lpmmioinfo, LPCTSTR lpszFileName, LPCTSTR lpszNewFileName)
  269. {
  270. BOOL fSuccess = TRUE;
  271. UINT uRet = MMIOERR_FILENOTFOUND;
  272. TracePrintf_2(NULL, 5,
  273. TEXT("PropIORename (%s, %s)\n"),
  274. (LPTSTR) lpszFileName,
  275. (LPTSTR) lpszNewFileName);
  276. // rename is not supported by this i/o procedure
  277. //
  278. if (TRUE)
  279. fSuccess = TraceFALSE(NULL);
  280. return fSuccess ? 0 : uRet;
  281. }