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.

201 lines
6.2 KiB

  1. /*---------------------------------------------------------------------------
  2. File: PlugInInfo.cpp
  3. Comments: COM Object to enumerate information about available plug-ins
  4. and extensions. These plug-ins are distributed with the agent to the remote
  5. machines to perform custom migration tasks.
  6. This interface would be used by the dispatcher, and possibly by the GUI, to
  7. enumerate the list of available plug-ins.
  8. (c) Copyright 1999, Mission Critical Software, Inc., All Rights Reserved
  9. Proprietary and confidential to Mission Critical Software, Inc.
  10. REVISION LOG ENTRY
  11. Revision By: Christy Boles
  12. Revised on 02/18/99 11:34:16
  13. ---------------------------------------------------------------------------
  14. */
  15. // PlugInInfo.cpp : Implementation of CPlugInInfo
  16. #include "stdafx.h"
  17. #include "WorkObj.h"
  18. #include "PlugInfo.h"
  19. #include "Common.hpp"
  20. #include "UString.hpp"
  21. #include "ErrDct.hpp"
  22. #include "TReg.hpp"
  23. #include "TNode.hpp"
  24. #include "EaLen.hpp"
  25. #include "McsPI.h"
  26. #include "McsPI_i.c"
  27. #include "ARExt_i.c"
  28. #include "folders.h"
  29. using namespace nsFolders;
  30. #ifdef _DEBUG
  31. #define new DEBUG_NEW
  32. #undef THIS_FILE
  33. static char THIS_FILE[] = __FILE__;
  34. #endif
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CPlugInInfo
  37. // the PlugInNode is used to build a list of available plug-ins
  38. class PlugInNode : public TNode
  39. {
  40. WCHAR name[LEN_Guid]; // CLSID of the plug-in
  41. public:
  42. PlugInNode(WCHAR const * n) { safecopy(name,n); }
  43. WCHAR const * GetName() { return name; }
  44. };
  45. // Checks the specified file to see if it implements any COM objects that implement the
  46. // McsDomPlugIn interface -- if so, it appends them to the list of available plug-ins
  47. void
  48. AppendPlugInsToList(
  49. TNodeList * pList, // in - list of plug-ins
  50. WCHAR const * path // in - file to examine for Plug-In COM objects
  51. )
  52. {
  53. HRESULT hr = S_OK;
  54. ITypeLib * pTlib = NULL;
  55. hr = LoadTypeLib(path,&pTlib);
  56. if ( SUCCEEDED(hr) )
  57. {
  58. UINT count = pTlib->GetTypeInfoCount();
  59. for ( UINT i = 0 ; i < count ; i++ )
  60. {
  61. ITypeInfo * pInfo = NULL;
  62. hr = pTlib->GetTypeInfo(i,&pInfo);
  63. if ( SUCCEEDED(hr) )
  64. {
  65. TYPEATTR * attr = NULL;
  66. hr = pInfo->GetTypeAttr(&attr);
  67. if ( SUCCEEDED(hr) )
  68. {
  69. if ( attr->typekind == TKIND_COCLASS )
  70. {
  71. IMcsDomPlugIn * pPlugIn = NULL;
  72. // see if it supports IMcsDomPlugIn
  73. hr = CoCreateInstance(attr->guid,NULL,CLSCTX_ALL,IID_IMcsDomPlugIn,(void**)&pPlugIn);
  74. if ( SUCCEEDED(hr) )
  75. {
  76. pPlugIn->Release();
  77. // add the coclass to the list
  78. LPOLESTR strClsid = NULL;
  79. hr = StringFromCLSID(attr->guid,&strClsid);
  80. if ( SUCCEEDED(hr) )
  81. {
  82. PlugInNode * pNode = new PlugInNode(strClsid);
  83. CoTaskMemFree(strClsid);
  84. pList->InsertBottom(pNode);
  85. }
  86. }
  87. }
  88. pInfo->ReleaseTypeAttr(attr);
  89. }
  90. pInfo->Release();
  91. }
  92. }
  93. pTlib->Release();
  94. }
  95. }
  96. SAFEARRAY * // ret- SAFEARRAY(BSTR) of filenames
  97. SafeArrayFromList(
  98. TNodeList * pList // in - list of filenames
  99. )
  100. {
  101. SAFEARRAYBOUND bound[1] = { pList->Count(),0 };
  102. SAFEARRAY * pArray = SafeArrayCreate(VT_BSTR,1,bound);
  103. TNodeListEnum tEnum;
  104. PlugInNode * pNode;
  105. PlugInNode * pNext;
  106. long ndx[1] = {0};
  107. for ( pNode = (PlugInNode *)tEnum.OpenFirst(pList) ; pNode ; pNode = pNext )
  108. {
  109. pNext = (PlugInNode *)tEnum.Next();
  110. SafeArrayPutElement(pArray,ndx,SysAllocString(pNode->GetName()));
  111. ndx[0]++;
  112. pList->Remove(pNode);
  113. delete pNode;
  114. }
  115. tEnum.Close();
  116. return pArray;
  117. }
  118. STDMETHODIMP
  119. CPlugInInfo::EnumeratePlugIns(
  120. SAFEARRAY ** pPlugIns // out- safearray containing clsids of available migration plug-ins
  121. )
  122. {
  123. HRESULT hr = S_OK;
  124. DWORD rc;
  125. TRegKey key;
  126. WCHAR directory[MAX_PATH];
  127. WCHAR path[MAX_PATH];
  128. WCHAR dllPath[MAX_PATH];
  129. TNodeList list;
  130. // Get the plug-ins directory from the registry
  131. rc = key.Open(REGKEY_ADMT,HKEY_LOCAL_MACHINE);
  132. if ( ! rc )
  133. {
  134. rc = key.ValueGetStr(L"PlugInDirectory",directory,(sizeof directory));
  135. if ( ! rc )
  136. {
  137. // Enumerate the files there that match the naming convention:
  138. WIN32_FIND_DATA fDat;
  139. HANDLE hFind;
  140. UStrCpy(path,directory);
  141. UStrCpy(path + UStrLen(path),L"\\McsPi*.Dll");
  142. hFind = FindFirstFile(path,&fDat);
  143. if ( hFind && hFind != INVALID_HANDLE_VALUE )
  144. {
  145. BOOL bRc = TRUE;
  146. for ( ; rc == 0 ; bRc = FindNextFile(hFind,&fDat) )
  147. {
  148. if ( bRc )
  149. {
  150. UStrCpy(dllPath,directory);
  151. UStrCpy(dllPath + UStrLen(dllPath),L"\\");
  152. UStrCpy(dllPath + UStrLen(dllPath),fDat.cFileName);
  153. // check each one to see if it is a plug-in
  154. AppendPlugInsToList(&list,dllPath);
  155. }
  156. else
  157. {
  158. rc = GetLastError();
  159. }
  160. }
  161. // create a safearray from the contents of the list
  162. (*pPlugIns) = SafeArrayFromList(&list);
  163. }
  164. }
  165. else
  166. {
  167. hr = HRESULT_FROM_WIN32(rc);
  168. }
  169. }
  170. else
  171. {
  172. hr = HRESULT_FROM_WIN32(rc);
  173. }
  174. return hr;
  175. }