ftp.cpp
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 4k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. /*****************************************************************************
  2.  *
  3.  * ftp.cpp - FTP folder bookkeeping
  4.  *
  5.  *****************************************************************************/
  6. #include "priv.h"
  7. //#include "ftpinet.h"
  8. //#include "ftpsite.h"
  9. //#include "ftplist.h"
  10. //#include "msieftp.h"
  11. //#include "cookie.h"
  12. extern struct GLOBALTIMEOUTINFO g_gti;
  13. extern DWORD g_dwOpenConnections;
  14. /*****************************************************************************
  15.  *
  16.  * Dynamic Globals.  There should be as few of these as possible.
  17.  *
  18.  * All access to dynamic globals must be thread-safe.
  19.  *
  20.  *****************************************************************************/
  21. ULONG g_cRef = 0; /* Global reference count */
  22. CRITICAL_SECTION g_csDll; /* The shared critical section */
  23. #ifdef DEBUG
  24. DWORD g_TlsMem = 0xffffffff;
  25. #endif // DEBUG
  26. ULONG g_cRef_CFtpView = 0;  // Needed to determine when to purge cache.
  27. /*****************************************************************************
  28.  *
  29.  * DllAddRef / DllRelease
  30.  *
  31.  * Maintain the DLL reference count.
  32.  *
  33.  *****************************************************************************/
  34. void DllAddRef(void)
  35. {
  36.     InterlockedIncrement((LPLONG)&g_cRef);
  37. }
  38. void DllRelease(void)
  39. {
  40.     InterlockedDecrement((LPLONG)&g_cRef);
  41. }
  42. /*****************************************************************************
  43.  *
  44.  * DllGetClassObject
  45.  *
  46.  * OLE entry point.  Produces an IClassFactory for the indicated GUID.
  47.  *
  48.  * The artificial refcount inside DllGetClassObject helps to
  49.  * avoid the race condition described in DllCanUnloadNow.  It's
  50.  * not perfect, but it makes the race window much smaller.
  51.  *
  52.  *****************************************************************************/
  53. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID * ppvObj)
  54. {
  55.     HRESULT hres;
  56.     DllAddRef();
  57. //    if (IsEqualIID(rclsid, CLSID_FtpFolder) ||
  58. //        IsEqualIID(rclsid, CLSID_FtpWebView))
  59.     {
  60.     hres = CFtpFactory_Create(rclsid, riid, ppvObj);
  61.     }
  62. //    else
  63. //    {
  64. //     *ppvObj = NULL;
  65. //     hres = CLASS_E_CLASSNOTAVAILABLE;
  66. //    }
  67.     DllRelease();
  68.     return hres;
  69. }
  70. /*****************************************************************************
  71.  *
  72.  * DllCanUnloadNow
  73.  *
  74.  * OLE entry point.  Fail iff there are outstanding refs.
  75.  *
  76.  * There is an unavoidable race condition between DllCanUnloadNow
  77.  * and the creation of a new IClassFactory:  Between the time we
  78.  * return from DllCanUnloadNow() and the caller inspects the value,
  79.  * another thread in the same process may decide to call
  80.  * DllGetClassObject, thus suddenly creating an object in this DLL
  81.  * when there previously was none.
  82.  *
  83.  * It is the caller's responsibility to prepare for this possibility;
  84.  * there is nothing we can do about it.
  85.  *
  86.  *****************************************************************************/
  87. STDMETHODIMP DllCanUnloadNow(void)
  88. {
  89.     HRESULT hres;
  90.     ENTERCRITICAL;
  91.     hres = g_cRef ? S_FALSE : S_OK;
  92.     TraceMsg(TF_FTP_DLLLOADING, "DllCanUnloadNow() returning hres=%#08lx. (S_OK means yes)", hres);
  93.     LEAVECRITICAL;
  94.     return hres;
  95. }
  96. /*****************************************************************************
  97.  *
  98.  * Entry32
  99.  *
  100.  * DLL entry point.
  101.  *
  102.  * BUGBUG -- On a thread detach, must check if the thread owns any
  103.  * global timeouts.  If so, we must transfer the timeout to another
  104.  * thread or something.
  105.  *
  106.  *****************************************************************************/
  107. STDAPI_(BOOL) DllEntry(HINSTANCE hinst, DWORD dwReason, LPVOID lpReserved)
  108. {
  109.     static s_hresOle = E_FAIL;
  110.     switch (dwReason)
  111.     {
  112.     case DLL_PROCESS_ATTACH:
  113.         InitializeCriticalSection(&g_csDll);
  114. g_hinst = hinst;
  115. DisableThreadLibraryCalls(hinst);
  116.         break;
  117.     case DLL_PROCESS_DETACH:
  118.         DeleteCriticalSection(&g_csDll);
  119.         break;
  120.     }
  121.     return 1;
  122. }
  123. const CLSID CLSID_FtpFolder = {0x63da6ec0, 0x2e98, 0x11cf, 0x8d,0x82,0x44,0x45,0x53,0x54,0,0};