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.

207 lines
9.8 KiB

  1. /*****************************************************************************\
  2. FILE: util.cpp
  3. DESCRIPTION:
  4. Shared stuff that operates on all classes.
  5. \*****************************************************************************/
  6. #ifndef _UTIL_H
  7. #define _UTIL_H
  8. #include "encoding.h"
  9. #include "ftpfoldr.h"
  10. #include "ftpdir.h"
  11. #include "ftpsite.h"
  12. #include "ftplist.h"
  13. #include "ftpefe.h"
  14. #include "ftpglob.h"
  15. #include "ftpcm.h"
  16. #include "ftpstm.h"
  17. #include "dllload.h"
  18. #include "security.h"
  19. // Don't ship with this on. Only for BryanSt's debugging
  20. //#define DEBUG_WININET_BREAKS
  21. #define DOES_POINTER_MATCHES_HRESULT(pointer, hr) ((pointer && SUCCEEDED(hr)) || (!pointer && FAILED(hr)))
  22. #define ASSERT_POINTER_MATCHES_HRESULT(pointer, hr) ASSERT(DOES_POINTER_MATCHES_HRESULT((pointer), hr))
  23. #define EVAL_POINTER_MATCHES_HRESULT(pointer, hr) EVAL(DOES_POINTER_MATCHES_HRESULT((pointer), hr)
  24. extern "C" void *_ReturnAddress();
  25. #pragma intrinsic(_ReturnAddress)
  26. #ifdef DEBUG // DEBUG - DEBUG - DEBUG - DEBUG - DEBUG - DEBUG - DEBUG - DEBUG - DEBUG - DEBUG
  27. #define CREATE_CALLERS_ADDRESS
  28. #define GET_CALLERS_ADDRESS _ReturnAddress()
  29. #ifdef DEBUG_WININET_BREAKS
  30. #define WININET_ASSERT(val) ASSERT(val)
  31. #endif // DEBUG_WININET_BREAKS
  32. void TraceMsgWithCurrentDir(DWORD dwTFOperation, LPCSTR pszMessage, HINTERNET hint);
  33. void DebugStartWatch(void);
  34. DWORD DebugStopWatch(void);
  35. #else // DEBUG - DEBUG - DEBUG - DEBUG - DEBUG - DEBUG - DEBUG - DEBUG - DEBUG - DEBUG
  36. #define CREATE_CALLERS_ADDRESS NULL;
  37. #define GET_CALLERS_ADDRESS 0x00000000
  38. #define TraceMsgWithCurrentDir(dwTFOperation, pszMessage, hint) NULL;
  39. #define DebugStartWatch() NULL;
  40. #define DebugStopWatch() 0
  41. #endif // DEBUG - DEBUG - DEBUG - DEBUG - DEBUG - DEBUG - DEBUG - DEBUG - DEBUG - DEBUG
  42. #ifndef WININET_ASSERT
  43. #define WININET_ASSERT(val) NULL
  44. #endif // DEBUG_WININET_BREAKS
  45. #define ChooseWindow(hwnd1, hwnd2) (hwnd1 ? hwnd1 : hwnd2)
  46. typedef BOOL (*HGLOBWITHPROC)(LPVOID pv, LPVOID pvRef, LPCVOID pvParam2, BOOL fUnicode);
  47. int SHMessageBox(HWND hwnd, LPCTSTR pszMessage, UINT uMessageID, UINT uTitleID, UINT uType);
  48. //HRESULT ShellExecFtpUrl(LPCTSTR pszUrl);
  49. //HRESULT ShellExecFtpPidl(LPCITEMIDLIST pidl);
  50. // SHChangeNotify() wrappers that will update our cache of the FTP server contents before
  51. // calling SHChangeNotify(). This will make sure DefView still has valid dates when it
  52. // converts the pidl passed to SHChangeNotify() to a display name and then has us turn
  53. // it back into a pidl via ::ParseDisplayName(). DefView does this to
  54. void FtpChangeNotify(HWND hwnd, LONG wEventId, CFtpFolder * pff, CFtpDir * pfd, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2, BOOL fTopLevel);
  55. BOOL IsLegacyChangeNotifyNeeded(LONG wEventId);
  56. HRESULT ForceDefViewRefresh(HWND hwnd, LPCITEMIDLIST pidl);
  57. DWORD GetOSVer(void);
  58. BOOL IsOSNT(void);
  59. #define HANDLE_NULLSTR(str) (str ? str : SZ_EMPTY)
  60. #define HANDLE_NULLSTRA(str) (str ? str : "")
  61. // Allocation Helper Funcitions
  62. void IUnknown_Set(IMalloc ** ppm, IMalloc * pm);
  63. void IUnknown_Set(CFtpFolder ** ppff, CFtpFolder * pff);
  64. void IUnknown_Set(CFtpDir ** ppfd, CFtpDir * pfd);
  65. void IUnknown_Set(CFtpSite ** ppfs, CFtpSite * pfs);
  66. void IUnknown_Set(CFtpList ** ppfl, CFtpList * pfl);
  67. void IUnknown_Set(CFtpPidlList ** ppflpidl, CFtpPidlList * pflpidl);
  68. void IUnknown_Set(CFtpEfe ** ppfefe, CFtpEfe * pfefe);
  69. void IUnknown_Set(CFtpGlob ** ppfg, CFtpGlob * pfg);
  70. void IUnknown_Set(CFtpMenu ** ppfcm, CFtpMenu * pfcm);
  71. void IUnknown_Set(CFtpStm ** ppfstm, CFtpStm * pfstm);
  72. HRESULT IUnknown_PidlNavigate(IUnknown * punk, LPCITEMIDLIST pidl, BOOL fHistoryEntry);
  73. //HRESULT IUnknown_UrlNavigate(IUnknown * punk, LPCTSTR pszUrl);
  74. DWORD StrListLength(LPCTSTR ppszStrList);
  75. #ifdef UNICODE
  76. #define TCharSysAllocString(psz) SysAllocString(psz)
  77. #define Str_StrAndThunk Str_StrAndThunkW
  78. #else
  79. extern BSTR AllocBStrFromString(LPCTSTR);
  80. #define TCharSysAllocString(psz) AllocBStrFromString(psz)
  81. #define Str_StrAndThunk Str_StrAndThunkA
  82. #endif
  83. HRESULT Str_StrAndThunkW(LPTSTR * ppszOut, LPCWSTR pwzIn, BOOL fStringList);
  84. HRESULT Str_StrAndThunkA(LPTSTR * ppszOut, LPCSTR pszIn, BOOL fStringList);
  85. DWORD GetUrlSchemeA(LPCSTR psz);
  86. DWORD GetUrlSchemeW(LPCWSTR pwz);
  87. DWORD Misc_SfgaoFromFileAttributes(DWORD dwFAFLFlags);
  88. HRESULT Misc_StringFromFileTime(LPTSTR pszDateTime, DWORD cchSize, LPFILETIME pft, DWORD flType);
  89. HRESULT Misc_CreateHglob(SIZE_T cb, LPVOID pv, HGLOBAL *phglob);
  90. int _HIDA_Create_Tally(LPVOID pvPidl, LPVOID pv);
  91. int _HIDA_Create_AddIdl(LPVOID pvPidl, LPVOID pv);
  92. BOOL _Misc_HIDA_Init(LPCVOID hida, LPCVOID pv, BOOL fUnicode);
  93. HIDA Misc_HIDA_Create(LPCITEMIDLIST pidlFolder, CFtpPidlList * pflHfpl);
  94. BOOL _Misc_HFGD_Init(LPVOID pv, LPVOID pvHFPL, BOOL fUnicode);
  95. HGLOBAL Misc_HFGD_Create(CFtpPidlList * pflHfpl, LPCITEMIDLIST pidlItem, BOOL fUnicode);
  96. UINT AddToPopupMenu(HMENU hmenuDst, UINT idMenuToAdd, UINT idSubMenuIndex, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags);
  97. UINT MergeInToPopupMenu(HMENU hmenuDst, UINT idMenuToMerge, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags);
  98. HMENU GetMenuFromID(HMENU hmenu, UINT idm);
  99. UINT MergeMenuHierarchy(HMENU hmenuDst, HMENU hmenuSrc, UINT idcMin, UINT idcMax);
  100. HRESULT Misc_CopyPidl(LPCITEMIDLIST pidl, LPITEMIDLIST * ppidlOut);
  101. HRESULT Misc_CloneHglobal(HGLOBAL hglob, HGLOBAL *phglob);
  102. HRESULT Misc_DeleteHfpl(CFtpFolder * pff, HWND hwnd, CFtpPidlList * pflHfpl);
  103. HWND Misc_FindStatusBar(HWND hwndOwner);
  104. void GetCfBufA(UINT cf, LPSTR psz, int cch);
  105. HGLOBAL AllocHGlob(UINT cb, HGLOBWITHPROC pfn, LPVOID pvRef, LPCVOID pvParam2, BOOL fUnicode);
  106. LPITEMIDLIST GetPidlFromFtpFolderAndPidlList(CFtpFolder * pff, CFtpPidlList * pflHfpl);
  107. HRESULT FtpSafeCreateDirectory(HWND hwnd, HINTERNET hint, CMultiLanguageCache * pmlc, CFtpFolder * pff, CFtpDir * pfd, IProgressDialog * ppd, LPCWSTR pwzFtpPath, BOOL fRoot);
  108. BOOL IsValidFtpAnsiFileName(LPCTSTR pszString);
  109. HRESULT HrShellExecute(HWND hwnd, LPCTSTR lpVerb, LPCTSTR lpFile, LPCTSTR lpParameters, LPCTSTR lpDirectory, INT nShowCmd);
  110. enum SHELL_VERSION
  111. {
  112. SHELL_VERSION_UNKNOWN = 0,
  113. SHELL_VERSION_W95NT4,
  114. SHELL_VERSION_IE4,
  115. SHELL_VERSION_NT5,
  116. };
  117. SHELL_VERSION GetShellVersion(void);
  118. DWORD GetShdocvwVersion(void);
  119. BOOL ShouldSkipDropFormat(int nIndex);
  120. HWND GetProgressHWnd(IProgressDialog * ppd, HWND hwndDefault);
  121. void FtpProgressInternetStatusCB(IN HINTERNET hInternet, IN DWORD_PTR pdwContext, IN DWORD dwInternetStatus, IN LPVOID lpwStatusInfo, IN DWORD dwStatusInfoLen);
  122. // In ftpresp.cpp
  123. CFtpGlob * GetFtpResponse(CWireEncoding * pwe);
  124. LPITEMIDLIST SHILCreateFromPathWrapper(LPCTSTR pszPath);
  125. HRESULT _SetStatusBarZone(CStatusBar * psb, CFtpSite * pfs);
  126. HRESULT CreateFromToStr(LPWSTR pwzStrOut, DWORD cchSize, ...);
  127. int _LoadStringW(HINSTANCE hinst, UINT id, LPWSTR wsz, UINT cchMax); // Implemented in olestuff.cpp
  128. void SetWindowBits(HWND hWnd, int iWhich, DWORD dwBits, DWORD dwValue);
  129. int DisplayWininetError(HWND hwnd, BOOL fAssertOnNULLHWND, DWORD dwError, UINT idTitleStr, UINT idBaseErrorStr, UINT idDetailsStr, UINT nMsgBoxType, IProgressDialog * ppd);
  130. int DisplayWininetErrorEx(HWND hwnd, BOOL fAssertOnNULLHWND, DWORD dwError, UINT idTitleStr, UINT idBaseErrorStr, UINT idDetailsStr, UINT nMsgBoxType, IProgressDialog * ppd, LPCWSTR pwzDetails);
  131. void ShowEnableWindow(HWND hwnd, BOOL fHide);
  132. HRESULT RemoveCharsFromString(LPTSTR pszLocToRemove, DWORD cchSizeToRemove);
  133. HRESULT RemoveCharsFromStringA(LPSTR pszLocToRemove, DWORD cchSizeToRemove);
  134. HRESULT CharReplaceWithStrA(LPSTR pszLocToInsert, DWORD cchSize, DWORD cchChars, LPSTR pszStrToInsert);
  135. HRESULT CharReplaceWithStrW(LPWSTR pszLocToInsert, DWORD cchSize, DWORD cchChars, LPWSTR pszStrToInsert);
  136. HRESULT EscapeString(LPCTSTR pszStrToEscape, LPTSTR pszEscapedStr, DWORD cchSize);
  137. HRESULT UnEscapeString(LPCTSTR pszStrToUnEscape, LPTSTR pszUnEscapedStr, DWORD cchSize);
  138. HRESULT DisplayBlockingProxyDialog(LPCITEMIDLIST pidl, HWND hwnd);
  139. HRESULT CopyStgMediumWrap(const STGMEDIUM * pcstgmedSrc, STGMEDIUM * pstgmedDest);
  140. HRESULT SHBindToIDList(LPCITEMIDLIST pidl, LPBC pbc, REFIID riid, void **ppv);
  141. STDAPI StringToStrRetW(LPCWSTR pwzString, STRRET *pstrret);
  142. HRESULT LoginAsViaFolder(HWND hwnd, CFtpFolder * pff, IUnknown * punkSite);
  143. HRESULT LoginAs(HWND hwnd, CFtpFolder * pff, CFtpDir * pfd, IUnknown * punkSite);
  144. void InitComctlForNaviteFonts(void);
  145. CFtpPidlList * CreateRelativePidlList(CFtpFolder * pff, CFtpPidlList * pPidlListFull);
  146. LPCITEMIDLIST ILGetLastID(LPCITEMIDLIST pidl);
  147. LPCITEMIDLIST ILGetLastNonFragID(LPCITEMIDLIST pidl);
  148. IProgressDialog * CProgressDialog_CreateInstance(UINT idTitle, UINT idAnimation);
  149. HRESULT AddFTPPropertyPages(LPFNADDPROPSHEETPAGE pfnAddPropSheetPage, LPARAM lParam, HINSTANCE * phinstInetCpl, IUnknown * punkSite);
  150. BOOL Is7BitAnsi(LPCWIRESTR pwByteStr);
  151. HRESULT SHPathPrepareForWriteWrapW(HWND hwnd, IUnknown *punkEnableModless, LPCWSTR pwzPath, UINT wFunc, DWORD dwFlags);
  152. STDAPI DataObj_SetPreferredEffect(IDataObject *pdtobj, DWORD dwEffect);
  153. STDAPI DataObj_SetPasteSucceeded(IDataObject *pdtobj, DWORD dwEffect);
  154. STDAPI DataObj_GetDWORD(IDataObject *pdtobj, UINT cf, DWORD *pdwOut);
  155. STDAPI DataObj_GetDropTarget(IDataObject *pdtobj, CLSID *pclsid);
  156. STDAPI DataObj_SetDWORD(IDataObject *pdtobj, UINT cf, DWORD dw);
  157. #define DEBUG_LEGACY_PROGRESS 0
  158. EXTERN_C void _FTPDebugMemLeak(UINT wFlags, LPCTSTR pszFile, UINT iLine);
  159. #define FTPDebugMemLeak(wFlags) _FTPDebugMemLeak(wFlags, TEXT(__FILE__), __LINE__)
  160. #endif // _UTIL_H