// STL
#include <iostream>
#include "SvnListener.h"
SvnListener::SvnListener( lua_State* luaState, int contextOptionReference )
:
m_luaState( luaState ),
m_contextOptionReference( contextOptionReference )
{
}
bool SvnListener::ContextGetLogin( const std::string& realm, std::string& username, std::string& password, bool& maySave )
{
bool retVal( false );
lua::state lState( m_luaState );
// Get the context options.
lState.rawgeti( m_contextOptionReference, LUA_REGISTRYINDEX );
// Place the listener on the stack.
lState.getfield( "listener" );
lState.getfield( "GetLogin" );
// Check if GetLogin is defined in Lua.
if ( lState.isfunction() )
{
// Push arguments
lState.push( realm );
lState.push( username );
lState.push( password );
lState.push( maySave );
// Call the function
lState.pcall( 4, 3 );
//Get the returns
maySave = lState.as( false );
lState.pop();
std::string passwordStr = lState.as( std::string() );
lState.pop();
username = lState.as( std::string() );
if ( passwordStr.length() > 0 )
{
password = passwordStr;
retVal = true;
}
}
else
{
std::cerr << "Ignoring prompt for credentials and dying" << std::endl;
}
return retVal;
}
void SvnListener::ContextNotify ( const char* path, svn_wc_notify_action_t action, svn_node_kind_t kind, const char * mime_type,
svn_wc_notify_state_t content_state, svn_wc_notify_state_t prop_state, svn_revnum_t revision )
{
lua::state lState( m_luaState );
// Get the context options.
lState.rawgeti( m_contextOptionReference, LUA_REGISTRYINDEX );
// Place the listener on the stack.
lState.getfield( "listener" );
lState.getfield( "Notify" );
// Check if Notify is defined in Lua.
if ( lState.isfunction() )
{
// Push arguments
lState.push( path );
lState.push( action );
lState.push( kind );
lState.push( mime_type );
lState.push( content_state );
lState.push( prop_state );
lState.push( revision );
// Call the function
lState.pcall( 7 );
}
}
bool SvnListener::ContextCancel()
{
return false;
}
bool SvnListener::ContextGetLogMessage( std::string& msg )
{
lua::state lState( m_luaState );
// Get the context options.
lState.rawgeti( m_contextOptionReference, LUA_REGISTRYINDEX );
// Place the listener on the stack.
lState.getfield( "listener" );
lState.getfield( "GetLogMessage" );
// Check if Notify is defined in Lua.
if ( lState.isfunction() )
{
lState.pcall( 0, 1 );
lState.to( msg );
lState.pop();
return true;
}
return false;
}
svn::ContextListener::SslServerTrustAnswer SvnListener::ContextSslServerTrustPrompt( const svn::ContextListener::SslServerTrustData& /* data */, apr_uint32_t& /* acceptedFailures */ )
{
return ACCEPT_TEMPORARILY;
}
bool SvnListener::ContextSslClientCertPrompt( std::string& /* certFile */ )
{
return false;
}
bool SvnListener::ContextSslClientCertPwPrompt( std::string& /* password */, const std::string& /* realm */, bool& /* maySave */ )
{
return false;
}