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.

393 lines
14 KiB

  1. //
  2. // twin.h: Declares data, defines and struct types for twin handling
  3. // module.
  4. //
  5. //
  6. #ifndef __TWIN_H__
  7. #define __TWIN_H__
  8. ///////////////////////////////////////////////////// INCLUDES
  9. ///////////////////////////////////////////////////// DEFINES
  10. #define CMP_RECNODES 1L
  11. #define CMP_FOLDERTWINS 2L
  12. #define OBJECT_TWIN_ATTRIBUTES (FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_READONLY)
  13. ///////////////////////////////////////////////////// MACROS
  14. #ifdef DEBUG
  15. #define Sync_Dump(lpvBuf, type) Sync_FnDump((LPVOID)lpvBuf, sizeof(type))
  16. extern CONST LPCTSTR rgcpcszTwinResult[];
  17. #define SzFromTR(tr) (rgcpcszTwinResult[(tr)])
  18. #else
  19. #define Sync_Dump(lpvBuf, type)
  20. #define Sync_DumpRecItem(tr, lpri, pszMsg)
  21. #define Sync_DumpRecNode(tr, lprn)
  22. #define Sync_DumpRecList(tr, lprl, pszMsg)
  23. #define SzFromTR(tr) (tr)
  24. #endif
  25. // Global v-table to the engine
  26. //
  27. typedef struct
  28. {
  29. HINSTANCE hinst;
  30. OPENBRIEFCASEINDIRECT OpenBriefcase;
  31. SAVEBRIEFCASEINDIRECT SaveBriefcase;
  32. CLOSEBRIEFCASEINDIRECT CloseBriefcase;
  33. DELETEBRIEFCASEINDIRECT DeleteBriefcase;
  34. GETOPENBRIEFCASEINFOINDIRECT GetOpenBriefcaseInfo;
  35. CLEARBRIEFCASECACHEINDIRECT ClearBriefcaseCache;
  36. FINDFIRSTBRIEFCASEINDIRECT FindFirstBriefcase;
  37. FINDNEXTBRIEFCASEINDIRECT FindNextBriefcase;
  38. FINDBRIEFCASECLOSEINDIRECT FindBriefcaseClose;
  39. ADDOBJECTTWININDIRECT AddObjectTwin;
  40. ADDFOLDERTWININDIRECT AddFolderTwin;
  41. RELEASETWINHANDLEINDIRECT ReleaseTwinHandle;
  42. DELETETWININDIRECT DeleteTwin;
  43. GETOBJECTTWINHANDLEINDIRECT GetObjectTwinHandle;
  44. ISFOLDERTWININDIRECT IsFolderTwin;
  45. CREATEFOLDERTWINLISTINDIRECT CreateFolderTwinList;
  46. DESTROYFOLDERTWINLISTINDIRECT DestroyFolderTwinList;
  47. GETFOLDERTWINSTATUSINDIRECT GetFolderTwinStatus;
  48. ISORPHANOBJECTTWININDIRECT IsOrphanObjectTwin;
  49. COUNTSOURCEFOLDERTWINSINDIRECT CountSourceFolderTwins;
  50. ANYTWINSINDIRECT AnyTwins;
  51. CREATETWINLISTINDIRECT CreateTwinList;
  52. DESTROYTWINLISTINDIRECT DestroyTwinList;
  53. ADDTWINTOTWINLISTINDIRECT AddTwinToTwinList;
  54. ADDALLTWINSTOTWINLISTINDIRECT AddAllTwinsToTwinList;
  55. REMOVETWINFROMTWINLISTINDIRECT RemoveTwinFromTwinList;
  56. REMOVEALLTWINSFROMTWINLISTINDIRECT RemoveAllTwinsFromTwinList;
  57. CREATERECLISTINDIRECT CreateRecList;
  58. DESTROYRECLISTINDIRECT DestroyRecList;
  59. RECONCILEITEMINDIRECT ReconcileItem;
  60. BEGINRECONCILIATIONINDIRECT BeginReconciliation;
  61. ENDRECONCILIATIONINDIRECT EndReconciliation;
  62. ISPATHONVOLUMEINDIRECT IsPathOnVolume;
  63. GETVOLUMEDESCRIPTIONINDIRECT GetVolumeDescription;
  64. } VTBLENGINE, * PVTBLENGINE;
  65. // Function wrappers
  66. //
  67. // TWINRESULT Sync_Verify(fn, args)
  68. // Returns the twinresult of the function that is called
  69. //
  70. #ifdef DEBUG
  71. #define Sync_Verify(fn, args) \
  72. (Sync_SetLastError(g_vtblEngine[0].##fn args), VERIFYSZ2(TR_SUCCESS == Sync_GetLastError(), TEXT("Assert ") TEXT(#fn) TEXT(": %s (LastError=%ldL)"), SzFromTR(Sync_GetLastError()), GetLastError()), Sync_GetLastError())
  73. #else
  74. // Optimized version for retail
  75. //
  76. #define Sync_Verify(fn, args) \
  77. Sync_SetLastError(g_vtblEngine[0].##fn args)
  78. #endif
  79. // BOOL Sync_IsEngineLoaded();
  80. // Returns TRUE if the engine is loaded.
  81. //
  82. BOOL PUBLIC Sync_IsEngineLoaded();
  83. // TWINRESULT Sync_SetLastError(TWINRESULT tr);
  84. //
  85. TWINRESULT PUBLIC Sync_SetLastError(TWINRESULT tr);
  86. // TWINRESULT Sync_GetLastError();
  87. //
  88. TWINRESULT PUBLIC Sync_GetLastError(void);
  89. // TWINRESULT Sync_OpenBriefcase(LPCSTR pszPath, DWORD dwFlags, HWND hwndOwner, HBRFCASE FAR * lphbrf);
  90. //
  91. #define Sync_OpenBriefcase(lpcsz, dwflags, hwnd, lphbrf) \
  92. Sync_Verify(OpenBriefcase, (lpcsz, dwflags, hwnd, lphbrf))
  93. // TWINRESULT Sync_SaveBriefcase(HBRFCASE hbrf);
  94. //
  95. #define Sync_SaveBriefcase(hbrf) \
  96. Sync_Verify(SaveBriefcase, (hbrf))
  97. // TWINRESULT Sync_DeleteBriefcase(LPCSTR pszPath);
  98. //
  99. #define Sync_DeleteBriefcase(lpcsz) \
  100. Sync_Verify(DeleteBriefcase, (lpcsz))
  101. // TWINRESULT Sync_CloseBriefcase(HBRFCASE hbrf);
  102. //
  103. #define Sync_CloseBriefcase(hbrf) \
  104. Sync_Verify(CloseBriefcase, (hbrf))
  105. // TWINRESULT Sync_GetOpenBriefcaseInfo(HBRFCASE hbrf, POPENBRFCASEINFO pinfo);
  106. //
  107. #define Sync_GetOpenBriefcaseInfo(hbrf, pinfo) \
  108. Sync_Verify(GetOpenBriefcaseInfo, (hbrf, pinfo))
  109. // TWINRESULT Sync_ClearBriefcaseCache(HBRFCASE hbrf);
  110. //
  111. #define Sync_ClearBriefcaseCache(hbrf) \
  112. Sync_Verify(ClearBriefcaseCache, (hbrf))
  113. // TWINRESULT Sync_FindFirst(PHBRFCASEITER phbrfiter, PBRFCASEINFO pinfo);
  114. //
  115. #define Sync_FindFirst(phbrfiter, pinfo) \
  116. Sync_Verify(FindFirstBriefcase, (phbrfiter, pinfo))
  117. // TWINRESULT Sync_FindNext(HBRFCASEITER hbrfiter, PBRFCASEINFO pinfo);
  118. //
  119. #define Sync_FindNext(hbrfiter, pinfo) \
  120. Sync_Verify(FindNextBriefcase, (hbrfiter, pinfo))
  121. // TWINRESULT Sync_FindClose(HBRFCASEITER hbrfiter);
  122. //
  123. #define Sync_FindClose(hbrfiter) \
  124. Sync_Verify(FindBriefcaseClose, (hbrfiter))
  125. // TWINRESULT Sync_AddObject(HBRFCASE hbrf, LPNEWOBJECTTWIN lpnot, HTWIN FAR * lphtfam);
  126. //
  127. #define Sync_AddObject(hbrf, lpnot, lphtfam) \
  128. Sync_Verify(AddObjectTwin, (hbrf, lpnot, lphtfam))
  129. // TWINRESULT Sync_AddFolder(HBRFCASE hbrf, LPNEWFOLDERTWIN lpnft, HTWIN FAR * lphft);
  130. //
  131. #define Sync_AddFolder(hbrf, lpnft, lphft) \
  132. Sync_Verify(AddFolderTwin, (hbrf, lpnft, lphft))
  133. // TWINRESULT Sync_ReleaseTwin(HTWIN htwin);
  134. //
  135. #define Sync_ReleaseTwin(htwin) \
  136. Sync_Verify(ReleaseTwinHandle, ((HTWIN)htwin))
  137. // TWINRESULT Sync_DeleteTwin(HTWIN htwin);
  138. //
  139. #define Sync_DeleteTwin(htwin) \
  140. Sync_Verify(DeleteTwin, ((HTWIN)htwin))
  141. // TWINRESULT Sync_AnyTwins(HBRFCASE hbrf, BOOL FAR * lpb);
  142. //
  143. #define Sync_AnyTwins(hbrf, lpb) \
  144. Sync_Verify(AnyTwins, (hbrf, lpb))
  145. // TWINRESULT Sync_CountSourceFolders(HOBJECTTWIN hot, ULONG FAR * lpulcSource);
  146. //
  147. #define Sync_CountSourceFolders(hot, lpulcSource) \
  148. Sync_Verify(CountSourceFolderTwins, (hot, lpulcSource))
  149. // TWINRESULT Sync_IsExplicitObject(HOBJECTTWIN hot, BOOL FAR * lpb);
  150. //
  151. #define Sync_IsExplicitObject(hot, lpb) \
  152. Sync_Verify(IsOrphanObjectTwin, (hot, lpb))
  153. // TWINRESULT Sync_GetObject(HBRFCASE hbrf, LPCSTR pszDir, LPCSTR pszName, HOBJECTTWIN FAR * lphot);
  154. //
  155. #define Sync_GetObject(hbrf, lpszFolder, lpszName, lphot) \
  156. Sync_Verify(GetObjectTwinHandle, (hbrf, lpszFolder, lpszName, lphot))
  157. // TWINRESULT Sync_IsFolder(HBRFCASE hbrf, LPCSTR pszFolder, BOOL FAR * lpb);
  158. //
  159. #define Sync_IsFolder(hbrf, lpszFolder, lpb) \
  160. Sync_Verify(IsFolderTwin, (hbrf, lpszFolder, lpb))
  161. // TWINRESULT Sync_GetFolderTwinStatus(HFOLDERTWIN hft, CREATERECLISTPROC crlp, LPARAM lpCallbackData, PFOLDERTWINSTATUS pfts);
  162. //
  163. #ifdef NEW_REC
  164. #define Sync_GetFolderTwinStatus(hft, crlp, lpcb, pfts) \
  165. Sync_Verify(GetFolderTwinStatus, (hft, crlp, lpcb, pfts))
  166. #else
  167. #define Sync_GetFolderTwinStatus(hft, crlp, lpcb, pfts) \
  168. Sync_Verify(GetFolderTwinStatus, (hft, crlp, lpcb, CRL_FLAGS, pfts))
  169. #endif
  170. // TWINRESULT Sync_CreateFolderList(HBRFCASE hbrf, LPCSTR pszDir, LPFOLDERTWINLIST FAR * lplpftl);
  171. //
  172. #define Sync_CreateFolderList(hbrf, lpszFolder, lplpftl) \
  173. Sync_Verify(CreateFolderTwinList, (hbrf, lpszFolder, lplpftl))
  174. // TWINRESULT Sync_DestroyFolderList(LPFOLDERTWINLIST lpftl);
  175. //
  176. #define Sync_DestroyFolderList(lpftl) \
  177. Sync_Verify(DestroyFolderTwinList, (lpftl))
  178. // TWINRESULT Sync_CreateTwinList(HBRFCASE hbrf, LPHTWINLIST lphtl);
  179. //
  180. #define Sync_CreateTwinList(hbrf, lphtl) \
  181. Sync_Verify(CreateTwinList, (hbrf, lphtl))
  182. // TWINRESULT Sync_DestroyTwinList(HTWINLIST htl);
  183. //
  184. #define Sync_DestroyTwinList(htl) \
  185. Sync_Verify(DestroyTwinList, (htl))
  186. // TWINRESULT Sync_AddToTwinList(HTWINLIST htl, HTWIN htwin);
  187. //
  188. #define Sync_AddToTwinList(htl, htwin) \
  189. Sync_Verify(AddTwinToTwinList, (htl, (HTWIN)htwin))
  190. // TWINRESULT Sync_AddAllToTwinList(HTWINLIST htl);
  191. //
  192. #define Sync_AddAllToTwinList(htl) \
  193. Sync_Verify(AddAllTwinsToTwinList, (htl))
  194. // TWINRESULT Sync_RemoveFromTwinList(HTWINLIST htl, HTWIN htwin);
  195. //
  196. #define Sync_RemoveFromTwinList(htl, htwin) \
  197. Sync_Verify(RemoveTwinFromTwinList, (htl, (HTWIN)htwin))
  198. // TWINRESULT Sync_RemoveAllFromTwinList(HTWINLIST htl);
  199. //
  200. #define Sync_RemoveAllFromTwinList(htl) \
  201. Sync_Verify(RemoveAllTwinsFromTwinList, (htl))
  202. // TWINRESULT Sync_CreateRecList(HTWINLIST htl, CREATERECLISTPROC crlp, LPARAM lpcb, LPRECLIST FAR * lplprl);
  203. //
  204. #ifdef NEW_REC
  205. #define Sync_CreateRecList(htl, crlp, lpcb, lplprl) \
  206. Sync_Verify(CreateRecList, (htl, crlp, lpcb, lplprl))
  207. #else
  208. #define Sync_CreateRecList(htl, crlp, lpcb, lplprl) \
  209. Sync_Verify(CreateRecList, (htl, crlp, lpcb, CRL_FLAGS, lplprl))
  210. #endif
  211. // TWINRESULT Sync_DestroyRecList(LPRECLIST lprl);
  212. //
  213. #define Sync_DestroyRecList(lprl) \
  214. Sync_Verify(DestroyRecList, (lprl))
  215. // TWINRESULT Sync_BeginRec(HBRFCASE hbrf);
  216. //
  217. #define Sync_BeginRec(hbrf) \
  218. Sync_Verify(BeginReconciliation, (hbrf))
  219. // TWINRESULT Sync_EndRec(HBRFCASE hbrf);
  220. //
  221. #define Sync_EndRec(hbrf) \
  222. Sync_Verify(EndReconciliation, (hbrf))
  223. // TWINRESULT Sync_ReconcileItem(LPRECITEM lpri, RECSTATUSPROC rsp, LPARAM lpCallbackData, DWORD dwFlags, HWND hwndOwner, HWND hwndStatusText);
  224. //
  225. #define Sync_ReconcileItem(lpri, rsp, lpcb, flags, hwnd, hwndStatusText) \
  226. Sync_Verify(ReconcileItem, (lpri, rsp, lpcb, flags, hwnd, hwndStatusText))
  227. // BOOL Sync_IsPathOnVolume(LPCSTR pszPath, HVOLUMEID hvid);
  228. //
  229. #define Sync_IsPathOnVolume(pszPath, hvid, pbool) \
  230. Sync_Verify(IsPathOnVolume, (pszPath, hvid, pbool))
  231. // BOOL Sync_GetVolumeDecription(HVOLUMEID hvid, PVOLUMEDESC pvd);
  232. //
  233. #define Sync_GetVolumeDescription(hvid, pvd) \
  234. Sync_Verify(GetVolumeDescription, (hvid, pvd))
  235. #ifdef NEW_REC
  236. // Returns TRUE if the recitem is referring to a file (not a folder)
  237. #define IsFileRecItem(pri) (0 != *(pri)->pcszName)
  238. #else
  239. #define IsFileRecItem(pri) TRUE
  240. #endif
  241. extern const TCHAR szAll[];
  242. extern VTBLENGINE g_vtblEngine[1];
  243. int CALLBACK _export NCompareFolders (LPVOID lpv1, LPVOID lpv2, LPARAM lParam);
  244. // Structure for the ChooseSide functions
  245. typedef struct tagCHOOSESIDE
  246. {
  247. DWORD dwFlags; // CSF_* flags
  248. int nRank; // Higher means better choice
  249. HTWIN htwin;
  250. HVOLUMEID hvid;
  251. LPCTSTR pszFolder;
  252. PRECNODE prn; // Only if CSF_FOLDER is clear
  253. } CHOOSESIDE, * PCHOOSESIDE;
  254. #define CSF_FOLDER 0x0001
  255. #define CSF_INSIDE 0x0002 // Ranking for inside
  256. #ifdef DEBUG
  257. void PUBLIC ChooseSide_DumpList(HDSA hdsa);
  258. #endif
  259. void PUBLIC ChooseSide_InitAsFile(HDSA hdsa, PRECITEM pri);
  260. HRESULT PUBLIC ChooseSide_CreateEmpty(HDSA * phdsa);
  261. HRESULT PUBLIC ChooseSide_CreateAsFile(HDSA * phdsa, PRECITEM pri);
  262. HRESULT PUBLIC ChooseSide_CreateAsFolder(HDSA * phdsa, PFOLDERTWINLIST pftl);
  263. BOOL PUBLIC ChooseSide_GetBest(HDSA hdsa, LPCTSTR pszBrfPath, LPCTSTR pszFolder, PCHOOSESIDE * ppchside);
  264. BOOL PUBLIC ChooseSide_GetNextBest(HDSA hdsa, PCHOOSESIDE * ppchside);
  265. void PUBLIC ChooseSide_Free(HDSA hdsa);
  266. HRESULT PUBLIC Sync_GetNodePair(PRECITEM pri, LPCTSTR pszBrfPath, LPCTSTR pszFolder, PRECNODE * pprnInside, PRECNODE * pprnOutside);
  267. void PUBLIC Sync_ChangeRecItemAction(PRECITEM pri, LPCTSTR pszBrfPath, LPCTSTR pszInsideDir, UINT uAction);
  268. BOOL PUBLIC Sync_QueryVTable();
  269. void PUBLIC Sync_ReleaseVTable();
  270. BOOL PUBLIC Sync_AddPathToTwinList(HBRFCASE hbrf, HTWINLIST htl, LPCTSTR lpcszPath, PFOLDERTWINLIST * lplpftl);
  271. HRESULT PUBLIC Sync_CreateCompleteRecList(HBRFCASE hbrf, PABORTEVT pabortevt, PRECLIST * pprl);
  272. HRESULT PUBLIC Sync_CreateRecListEx(HTWINLIST htl, PABORTEVT pabortevt, PRECLIST * pprl);
  273. // Flags for Sync_ReconcileRecList
  274. #define RF_DEFAULT 0x0000
  275. #define RF_ONADD 0x0001
  276. HRESULT PUBLIC Sync_ReconcileRecList (PRECLIST lprl, LPCTSTR pszPathBrf, HWND hwndParent, UINT uFlags);
  277. // Flags for Sync_Split
  278. #define SF_NOCONFIRM 0x0001
  279. #define SF_QUIET 0x0002
  280. // Flags for Sync_IsTwin and Sync_Split
  281. #define SF_ISFOLDER 0x1000
  282. #define SF_ISFILE 0x2000
  283. #define SF_ISTWIN 0x4000
  284. #define SF_ISNOTTWIN 0x8000
  285. HRESULT PUBLIC Sync_IsTwin (HBRFCASE hbrf, LPCTSTR lpcszPath, UINT uFlags);
  286. HRESULT PUBLIC Sync_Split (HBRFCASE hbrf, LPCTSTR pszList, UINT cFiles, HWND hwndOwner, UINT uFlags);
  287. ULONG PUBLIC CountActionItems(PRECLIST prl);
  288. #ifdef DEBUG
  289. void PUBLIC Sync_FnDump (LPVOID lpvBuf, UINT cbBuf);
  290. void PUBLIC Sync_DumpRecItem (TWINRESULT tr, PRECITEM lpri, LPCTSTR pszMsg);
  291. void PUBLIC Sync_DumpRecNode (TWINRESULT tr, PRECNODE lprn);
  292. void PUBLIC Sync_DumpRecList(TWINRESULT tr, PRECLIST lprl, LPCTSTR pszMsg);
  293. void PUBLIC Sync_DumpFolderTwin(PCFOLDERTWIN pft);
  294. void PUBLIC Sync_DumpFolderTwinList(PFOLDERTWINLIST pftl, LPCTSTR pszMsg);
  295. #endif
  296. #endif // __TWIN_H__