CPluginHandler.cpp [plain text]
#include <CoreFoundation/CFPlugIn.h>
#include <CoreFoundation/CFString.h>
#include <CoreFoundation/CFURL.h>
#include "CPluginHandler.h"
#include "CPlugInList.h"
#include "ServerControl.h"
#include "DirServiceMain.h"
#include "CString.h"
#include "COSUtils.h"
#include "CLog.h"
#include "CServerPlugin.h"
#warning VERIFY the version string for the static plugins before each software release
static const char *sStaticPluginList[ kNumStaticPlugins ][ 2 ] =
{
{ "Configure", "1.6" },
{ "NetInfo", "1.6" },
{ "LDAPv3", "1.6.2" },
{ "Search", "1.6.1" }
};
CPluginHandler::CPluginHandler ( void ) : CInternalDispatchThread(kTSPlugInHndlrThread)
{
fThreadSignature = kTSPlugInHndlrThread;
}
CPluginHandler::~CPluginHandler()
{
}
void CPluginHandler::StartThread ( void )
{
if ( this == nil ) throw((sInt32)eMemoryError);
this->Resume();
}
void CPluginHandler::StopThread ( void )
{
if ( this == nil ) throw((sInt32)eMemoryError);
SetThreadRunState( kThreadStop );
}
long CPluginHandler::ThreadMain ( void )
{
uInt32 uiPluginCnt = 0;
uiPluginCnt = LoadPlugins();
if ( uiPluginCnt == 0 )
{
ERRORLOG( kLogApplication, "*** WARNING: No Plugins loaded ***" );
}
else
{
DBGLOG1( kLogApplication, "%d Plugins loaded or processed.", uiPluginCnt );
DBGLOG( kLogApplication, "Initializing plugins." );
gPlugins->InitPlugIns();
}
return( 0 );
}
sInt32 CPluginHandler::LoadPlugins ( void )
{
sInt32 status = eDSNoErr;
uInt32 uiCount = 0;
CString cSubPath( COSUtils::GetStringFromList( kAppStringsListID, kStrPlugInsFolder ) );
CString cOtherSubPath( COSUtils::GetStringFromList( kAppStringsListID, kStrOtherPlugInsFolder ) );
CString cPlugExt( COSUtils::GetStringFromList( kAppStringsListID, kStrPluginExtension ) );
CFStringRef sType = nil;
char string [ PATH_MAX ];
for (uInt32 iPlugin = 0; iPlugin < kNumStaticPlugins; iPlugin++)
{
status = CServerPlugin::ProcessStaticPlugin( sStaticPluginList[iPlugin][0],
sStaticPluginList[iPlugin][1]);
if (status == eDSNoErr)
{
uiCount++;
}
}
sType = ::CFStringCreateWithCString( kCFAllocatorDefault, cPlugExt.GetData(), kCFStringEncodingMacRoman );
CFURLRef urlPath = 0;
CFStringRef sBase, sPath;
CFArrayRef aBundles;
sBase = CFSTR( "/System/Library" );
sPath = ::CFStringCreateWithFormat( kCFAllocatorDefault, NULL, CFSTR( "%@/%s" ), sBase, cSubPath.GetData() );
sBase = nil;
::CFStringGetCString( sPath, string, sizeof( string ), kCFStringEncodingMacRoman );
DBGLOG( kLogApplication, "Checking for plugins in:" );
DBGLOG1( kLogApplication, " %s", string );
urlPath = ::CFURLCreateWithFileSystemPath( kCFAllocatorDefault, sPath, kCFURLPOSIXPathStyle, true );
::CFRelease( sPath );
sPath = nil;
aBundles = ::CFBundleCopyResourceURLsOfTypeInDirectory( urlPath, sType, NULL );
::CFRelease( urlPath );
urlPath = nil;
if ( aBundles != nil )
{
register CFIndex bundleCount = CFArrayGetCount( aBundles );
for ( register CFIndex j = 0; j < bundleCount; ++j )
{
status = CServerPlugin::ProcessURL( (CFURLRef)::CFArrayGetValueAtIndex( aBundles, j ) );
if ( status == eDSNoErr )
{
uiCount++;
}
else
SRVRLOG( kLogApplication, "\tError loading plugin, see DirectoryService.error.log for details" );
}
::CFRelease( aBundles );
aBundles = nil;
}
if ( sType != nil )
{
::CFRelease( sType );
sType = nil;
}
sType = ::CFStringCreateWithCString( kCFAllocatorDefault, cPlugExt.GetData(), kCFStringEncodingMacRoman );
sBase = CFSTR( "/Library" );
sPath = ::CFStringCreateWithFormat( kCFAllocatorDefault, NULL, CFSTR( "%@/%s" ), sBase, cOtherSubPath.GetData() );
sBase = nil;
::CFStringGetCString( sPath, string, sizeof( string ), kCFStringEncodingMacRoman );
DBGLOG( kLogApplication, "Checking for plugins in:" );
DBGLOG1( kLogApplication, " %s", string );
urlPath = ::CFURLCreateWithFileSystemPath( kCFAllocatorDefault, sPath, kCFURLPOSIXPathStyle, true );
::CFRelease( sPath );
sPath = nil;
aBundles = ::CFBundleCopyResourceURLsOfTypeInDirectory( urlPath, sType, NULL );
::CFRelease( urlPath );
urlPath = nil;
if ( aBundles != nil )
{
register CFIndex j = ::CFArrayGetCount( aBundles );
while ( j-- )
{
status = CServerPlugin::ProcessURL( (CFURLRef)::CFArrayGetValueAtIndex( aBundles, j ) );
if ( status == eDSNoErr )
{
uiCount++;
}
else
SRVRLOG( kLogApplication, "\tError loading 3rd party plugin, see DirectoryService.error.log for details" );
}
::CFRelease( aBundles );
aBundles = nil;
}
if ( sType != nil )
{
::CFRelease( sType );
sType = nil;
}
return( uiCount );
}