added module loading support, should work out of the box now

git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@325 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
imaginos
2005-05-16 17:24:31 +00:00
parent 8676e35172
commit a31064dd00
2 changed files with 72 additions and 7 deletions

View File

@@ -153,7 +153,6 @@ public:
if ( isspace( sTmp[a] ) )
sTmp[a] = ' ';
}
cerr << "ERROR: " << sTmp << endl;
PutModule( sTmp );
}
@@ -320,17 +319,30 @@ public:
bool Eval( const CString & sScript, const CString & sFuncName = ZNCEvalCB );
virtual EModRet OnStatusCommand( const CString& sCommand )
virtual EModRet OnStatusCommand( const CString& sLine )
{
/*
* TODO if sCommand == loadmod or unloadmod on a .pm, then call the appropriate perl guts
* if sCommand = reloadmod on a .pm, send a warning to reloadmod modperl
*/
CString sCommand = sLine.Token( 0 );
if ( ( sCommand == "loadmod" ) || ( sCommand == "unloadmod" ) || ( sCommand == "reloadmod" ) )
{
CString sModule = sLine.Token( 1 );
if ( sModule.find( ".pm" ) != CString::npos )
{
if ( sCommand == "loadmod" )
LoadPerlMod( sModule );
else if ( sCommand == "unloadmod" )
UnLoadPerlMod( sModule );
else
PutModule( "Perl modules can not be reloaded one at a time, you have to reload the interpreter to pick up code changes (reloadmod modperl)" );
return( HALT );
}
}
return( CONTINUE );
}
private:
void LoadPerlMod( const CString & sModule );
void UnLoadPerlMod( const CString & sModule );
PerlInterpreter *m_pPerl;
@@ -637,9 +649,36 @@ bool CModPerl::OnLoad( const CString & sArgs )
newCONSTSUB( pZNCSpace, "HALTMODS", newSViv( HALTMODS ) );
newCONSTSUB( pZNCSpace, "HALTCORE", newSViv( HALTCORE ) );
for( u_int a = 0; a < 255; a++ )
{
CString sModule = sArgs.Token( a );
if ( sModule.empty() )
break;
LoadPerlMod( sModule );
}
return( true );
}
void CModPerl::LoadPerlMod( const CString & sModule )
{
CString sModPath = m_pUser->FindModPath( sModule );
if ( sModPath.empty() )
PutModule( "No such module " + sModule );
else
{
PutModule( "Using " + sModPath );
Eval( "ZNC::LoadMod( '" + m_pUser->GetUserName() + "', '" + sModPath + "');" );
}
}
void CModPerl::UnLoadPerlMod( const CString & sModule )
{
Eval( "ZNC::UnLoadMod( '" + m_pUser->GetUserName() + "', '" + sModule + "');" );
}
CModPerl::EModRet CModPerl::OnDCCUserSend(const CNick& RemoteNick, unsigned long uLongIP, unsigned short uPort,
const CString& sFile, unsigned long uFileSize)
{

View File

@@ -42,8 +42,26 @@ sub CallFunc
sub LoadMod
{
my ( $Username, $Module, $ModPath ) = @_;
my ( $Username, $ModPath ) = @_;
my $Module;
if ( $ModPath =~ /\/([^\/.]+)\.pm/ )
{
$Module = $1;
}
if ( !$Module )
{
ZNC::PutModule( "Invalid Module requested!" );
return( HALTMODS() );
}
# TODO need to do module caching to protect name spaces!!!!
my $DPath = GetString( "DataPath" );
my $FileName = $DPath . "/" . $Username . $Module . ".pm";
if ( $Modules{"$Username|$Module"} )
{
ZNC::PutModule( "$Module Already Loaded" );
@@ -70,6 +88,14 @@ sub UnLoadMod
{
my ( $Username, $Module ) = @_;
$Module =~ s/(.+?)\.pm/$1/;
if ( !$Module )
{
ZNC::PutModule( "Invalid Module requested!" );
return( HALTMODS() );
}
if ( !$Modules{"$Username|$Module"} )
{
ZNC::PutModule( "$Module Isn't Loaded" );