Esempio n. 1
0
int P4ClientAPI::Except( const char *func, Error *e )
{
	StrBuf	m;

	e->Fmt( &m );
	return Except( func, m.Text() );
}
static bool ErrorStringMatch(Error *err, const char* msg)
{
    StrBuf buf;
    err->Fmt(&buf);
    string value(buf.Text());
    return value.find(msg) != string::npos;
}
Esempio n. 3
0
void PythonClientUser::ProcessMessage( Error *e )
{
    if( this->handler != Py_None )
    {
	int s = e->GetSeverity();

	if ( s == E_EMPTY || s == E_INFO )
	{
	    // info messages should be send to outputInfo
	    // not outputError, or untagged output looks
	    // very strange indeed

	    StrBuf m;
	    e->Fmt( &m, EF_PLAIN );
	    PyObject * s = specMgr->CreatePyString( m.Text() );

	    if( s && CallOutputMethod( "outputInfo", s) )
		results.AddOutput( s );
	}
	else
	{
	    P4Message * msg = (P4Message *) PyObject_New(P4Message, &P4MessageType);
	    msg->msg = new PythonMessage(e, specMgr);

	    if( CallOutputMethod( "outputMessage", (PyObject *) msg ) )
		results.AddError( e );
	}
    }
    else
	results.AddError( e );
}
Esempio n. 4
0
static void ReadConnectionSettings( lua_State* L, StrBuf& connection )
{
	char* buffer = new char[ connection.Length() + 1 ];
	strcpy( buffer, connection.Text() );
	lua_createtable( L, 3, 0 );

	char* start = buffer;
	char* ptr = buffer;
	int index = 1;
	while ( *ptr ) {
		if ( *ptr == ',' ) {
			lua_pushlstring( L, start, ptr - start );
			lua_rawseti( L, -2, index );
			++index;

			++ptr;
			if ( *ptr == ' ' )
				++ptr;
			start = ptr;
		}
		else
			++ptr;
	}
	lua_pushlstring( L, start, ptr - start );
	lua_rawseti( L, -2, index );

	delete[] buffer;
}
Esempio n. 5
0
bool FindListFile(const wchar_t *FileName, StrBuf &output)
{
	StrBuf Path;
	DWORD dwSize;
	StrBuf FullPath;
	GetFullPath(FileName, FullPath);
	StrBuf NtPath;
	FormNtPath(FullPath, NtPath);
	const wchar_t *final=NULL;

	if (GetFileAttributes(NtPath) != INVALID_FILE_ATTRIBUTES)
	{
		output.Grow(FullPath.Size());
		lstrcpy(output, FullPath);
		return true;
	}

	{
		const wchar_t *tmp = FSF.PointToName(Info.ModuleName);
		Path.Grow(tmp-Info.ModuleName+1);
		lstrcpyn(Path,Info.ModuleName,(int)(tmp-Info.ModuleName+1));
		dwSize=SearchPath(Path,FileName,NULL,0,NULL,NULL);

		if (dwSize)
		{
			final = Path;
			goto success;
		}
	}
Esempio n. 6
0
int P4ClientAPI::SetCharset( const char *c )
{
	if( P4LUADEBUG_COMMANDS )
		fprintf( stderr, "[P4] Setting charset: %s\n", c );

    CharSetApi::CharSet cs = CharSetApi::NOCONV;

	if ( strlen(c) > 0 ) {
		cs = CharSetApi::Lookup( c );
		if( cs < 0 )
		{
			if( exceptionLevel )
			{
				StrBuf	m;
				m = "Unknown or unsupported charset: ";
				m.Append( c );
				return Except( "P4.charset", m.Text() );
			}
			return 0;
		}
	}

    if( CharSetApi::Granularity( cs ) != 1 ) {
		return Except( "P4.charset", "P4Lua does not support a wide charset!");
    }

	client.SetCharset(c);
	
    client.SetTrans( cs, cs, cs, cs );
	return 1;
}
Esempio n. 7
0
void PythonClientUser::Diff( FileSys *f1, FileSys *f2, int doPage, 
				char *diffFlags, Error *e )
{
    EnsurePythonLock guard;
    
    if ( P4PYDBG_CALLS )
	cerr << "[P4] Diff() - comparing files" << endl;

    //
    // Duck binary files. Much the same as ClientUser::Diff, we just
    // put the output into Python space rather than stdout.
    //
    if( !f1->IsTextual() || !f2->IsTextual() )
    {
	if ( f1->Compare( f2, e ) )
	    results.AddOutput( "(... files differ ...)" );
	return;
    }

    // Time to diff the two text files. Need to ensure that the
    // files are in binary mode, so we have to create new FileSys
    // objects to do this.

    FileSys *f1_bin = FileSys::Create( FST_BINARY );
    FileSys *f2_bin = FileSys::Create( FST_BINARY );
    FileSys *t = FileSys::CreateGlobalTemp( f1->GetType() );

    f1_bin->Set( f1->Name() );
    f2_bin->Set( f2->Name() );

    {
	//
	// In its own block to make sure that the diff object is deleted
	// before we delete the FileSys objects.
	//
	::Diff d;

	d.SetInput( f1_bin, f2_bin, diffFlags, e );
	if ( ! e->Test() ) d.SetOutput( t->Name(), e );
	if ( ! e->Test() ) d.DiffWithFlags( diffFlags );
	d.CloseOutput( e );

	// OK, now we have the diff output, read it in and add it to 
	// the output.
	if ( ! e->Test() ) t->Open( FOM_READ, e );
	if ( ! e->Test() ) 
	{
	    StrBuf 	b;
	    while( t->ReadLine( &b, e ) )
		results.AddOutput( b.Text() );
	}
    }

    delete t;
    delete f1_bin;
    delete f2_bin;

    if ( e->Test() ) HandleError( e );
}
Esempio n. 8
0
void
P4ClientApi::SetApiLevel( int level )
{
	StrBuf	b;
	b << level;
	apiLevel = level;
	client.SetProtocol( "api", b.Text() );
}
Esempio n. 9
0
int P4ClientAPI::Except( const char *func, const char *msg, const char *cmd )
{
	StrBuf m;

	m << msg;
	m << "( " << cmd << " )";
	return Except( func, m.Text() );
}
Esempio n. 10
0
	void HandleError(Error *InError)
	{
#if USE_P4_API
		StrBuf ErrorMessage;
		InError->Fmt(&ErrorMessage);
		OutErrorMessages.Add(FText::FromString(FString(TO_TCHAR(ErrorMessage.Text(), bIsUnicodeServer))));
#endif
	}
Esempio n. 11
0
int P4ClientAPI::Run( const char *cmd, int argc, char * const *argv )
{
	// Save the entire command string for our error messages. Makes it
	// easy to see where a script has gone wrong.
	StrBuf	cmdString;
	cmdString << "\"p4 " << cmd;
	for( int i = 0; i < argc; i++ )
		cmdString << " " << argv[ i ];
	cmdString << "\"";

	if ( P4LUADEBUG_COMMANDS )
		fprintf( stderr, "[P4] Executing %s\n", cmdString.Text()  );

	if ( depth )
	{
		lua_pushboolean( L, false );
		lua_pushstring( L, "Can't execute nested Perforce commands." );
		return 2;
	}

	// Clear out any results from the previous command
	ui.Reset();

	// Tell the UI which command we're running.
	ui.SetCommand( cmd );

    if ( ! IsConnected() && exceptionLevel ) {
		Except( "P4.run()", "not connected." );
		return 0;
    }
    
    if ( ! IsConnected()  ) {
		lua_pushboolean( L, false );
		return 1;
	}

	depth++;
	RunCmd( cmd, &ui, argc, argv );
	depth--;

    if( ui.GetHandler() != LUA_NOREF ) {
		if( client.Dropped() && ! ui.IsAlive() ) {
			Disconnect();
			ConnectOrReconnect();
		}
	}

	P4Result &results = ui.GetResults();

	if ( results.ErrorCount() && exceptionLevel )
		return Except( "P4:run", "Errors during command execution", cmdString.Text() );

	if ( results.WarningCount() && exceptionLevel > 1 )
		return Except( "P4:run", "Warnings during command execution",cmdString.Text());

	lua_rawgeti( L, LUA_REGISTRYINDEX, results.GetOutput() );
	return 1;
}
Esempio n. 12
0
int P4ClientAPI::SetApiLevel( int level )
{
	StrBuf	b;
	b << level;
	apiLevel = level;
	client.SetProtocol( "api", b.Text() );
    ui.SetApiLevel( level );
	return 0;
}
Esempio n. 13
0
P4ClientAPI::P4ClientAPI( lua_State *L )
	: L( L )
	, specMgr( L )
	, ui( L, &specMgr )
{
	debug = 0;
	server2 = 0;
	depth = 0;
	exceptionLevel = 2;
	maxResults = 0;
	maxScanRows = 0;
	maxLockTime = 0;
	prog = "unnamed p4lua script";
	apiLevel = atoi( P4Tag::l_client );
	enviro = new Enviro;

//	cb.client = this;

	InitFlags();

	// Enable form parsing
	client.SetProtocol( "specstring", "" );

    //
    // Load the current working directory, and any P4CONFIG file in place
    //
	HostEnv henv;
	StrBuf cwd;

	henv.GetCwd( cwd, enviro );
	if( cwd.Length() )
		enviro->Config( cwd );

	//
	// Load the current ticket file. Start with the default, and then
	// override it if P4TICKETS is set.
	//
	const char *t;

  	henv.GetTicketFile( ticketFile );

	if( t = enviro->Get( "P4TICKETS" ) ) {
		ticketFile = t;
	}

    // 
    // Do the same for P4CHARSET
    //
    
    const char *lc;
    if( ( lc = enviro->Get( "P4CHARSET" )) ) {
        SetCharset(lc);
    }
}
Esempio n. 14
0
static int p4_retrieve_gui_connections( lua_State *L ) {
	StrBuf settingsFilename;
	settingsFilename << getenv( "HOMEDRIVE" );
	settingsFilename << getenv( "HOMEPATH" );
	settingsFilename << "/.p4qt/settings";

	FILE* file = fopen( settingsFilename.Text(), "rt" );
	if ( !file )
		return 0;

	lua_newtable( L );						// p4Connections
	int p4ConnectionsCount = 0;
	bool inRecentConnections = false;

	char line[ 4096 ];
	while ( fgets( line, sizeof( line ) - 1, file ) ) {
		char* end = line + strlen( line ) - 1;
		while ( *end == 13  ||  *end == 10 )
			*end-- = 0;
		if ( inRecentConnections ) {
			if ( line[0] != '\t' ) {
				inRecentConnections = false;
			} else {
				StrBuf connection;
				ReadValue( connection, line + 1 );
				ReadConnectionSettings( L, connection );
				lua_rawseti( L, -2, ++p4ConnectionsCount );
			}
		}
		if ( !inRecentConnections ) {
			if ( strcmp( line, "RecentConnections:" ) == 0  ||  strcmp( line, "RecentConnection:" ) == 0 )
				inRecentConnections = true;
			else if ( strncmp( line, "LastConnection=", 15 ) == 0  ||  strncmp( line, "PrevConnection=", 15 ) == 0 )
			{
				lua_pushliteral( L, "LastConnection" );
				StrBuf connection;
				ReadValue( connection, line + 15 );
				ReadConnectionSettings( L, connection );
				lua_rawset( L, -3 );
			}
			else if ( strncmp( line, "OpenWorkspaces=", 15 ) == 0 )
			{
				lua_pushliteral( L, "OpenWorkspaces" );
				StrBuf connection;
				ReadValue( connection, line + 15 );
				ReadConnectionSettings( L, connection );
				lua_rawset( L, -3 );
			}
		}
	}

	return 1;
}
Esempio n. 15
0
P4ClientApi::P4ClientApi( lua_State *L )
	: L( L )
	, specMgr( L )
	, ui( L, &specMgr )
	, keepAliveRef( LUA_NOREF )
{
	initCount = 0;
	debug = 0;
	server2 = 0;
	depth = 0;
	exceptionLevel = 2;
	maxResults = 0;
	maxScanRows = 0;
	maxLockTime = 0;
	apiLevel = atoi( P4Tag::l_client );
	enviro = new Enviro;
	prog = "unnamed p4lua script";
	cb.client = this;

	// Enable form parsing, and set tagged mode on by default
	mode |= M_PARSE_FORMS + M_TAGGED ;
	client.SetProtocol( "specstring", "" );

	//
	// Load any P4CONFIG file
	//
	HostEnv henv;
	StrBuf cwd;

	henv.GetCwd( cwd, enviro );
	if( cwd.Length() )
		enviro->Config( cwd );

	//
	// Load the current ticket file. Start with the default, and then
	// override it if P4TICKETS is set.
	//
	const char *t;

  	henv.GetTicketFile( ticketFile );

	if( t = enviro->Get( "P4TICKETS" ) )
		ticketFile = t;

	//
	// Load the current P4CHARSET if set.
	//
	if( client.GetCharset().Length() )
		SetCharset( client.GetCharset().Text() );
}
Esempio n. 16
0
void LuaMessage::getRepr()
{
    StrBuf a;
    StrBuf b;

    err.Fmt( a, EF_PLAIN );
    b << "[";
    b << "Gen:" << err.GetGeneric();
    b << "/Sev:" << err.GetSeverity();
    b << "]: ";
    b << a;

	lua_pushlstring( L, b.Text(), b.Length() );
}
Esempio n. 17
0
//
// Returns a hash whose keys contain the names of the fields in a spec of the
// specified type. Not yet exposed to Ruby clients, but may be in future.
//
int
P4ClientApi::SpecFields( const char * type )
{
	if ( !specMgr.HaveSpecDef( type ) )
	{
		StrBuf m;
		m = "No spec definition for ";
		m.Append( type );
		m.Append( " objects." );
		return Except( "P4#spec_fields", m.Text() );
	}

	return specMgr.SpecFields( type );
}
Esempio n. 18
0
int
P4ClientApi::FormatSpec( const char * type, int table )
{
	if ( !specMgr.HaveSpecDef( type ) )
	{
		StrBuf m;
		m = "No spec definition for ";
		m.Append( type );
		m.Append( " objects." );
		return Except( "P4#format_spec", m.Text() );
	}

	// Got a specdef so now we can attempt to convert.
	StrBuf	buf;
	Error	e;

	specMgr.SpecToString( type, table, buf, &e );
	if( !e.Test() ) {
		lua_pushstring( L, buf.Text() );
		return 1;
	}

	StrBuf m;
	m = "Error converting hash to a string.";
	if( e.Test() ) e.Fmt( m, EF_PLAIN );
	return Except( "P4#format_spec", m.Text() );
}
Esempio n. 19
0
void
ClientUserLua::HandleError( Error *e )
{
	if( P4LUADEBUG_CALLS )
		fprintf( stderr, "[P4] HandleError()\n" );

	if( P4LUADEBUG_DATA )
	{
		StrBuf t;
		e->Fmt( t, EF_PLAIN );
		fprintf( stderr, "... [%s] %s\n", e->FmtSeverity(), t.Text() );
	}

	results.AddError( e );
}
	// Entering password
	void Prompt( const StrPtr &msg, StrBuf &buf, int noEcho ,Error *e )
	{
		Conn().Log().Info() << "Prompted for password by server" << Endl;
		Conn().Log().Debug() << "Prompt: " << msg.Text() << Endl;
		buf.Set(m_Password.c_str());
		Conn().VerboseLine("Prompted for password");
	}
Esempio n. 21
0
void FPerforceConnection::Disconnect()
{
#if USE_P4_API
	Error P4Error;

	P4Client.Final(&P4Error);

	if (P4Error.Test())
	{
		StrBuf ErrorMessage;
		P4Error.Fmt(&ErrorMessage);
		UE_LOG(LogSourceControl, Error, TEXT("P4ERROR: Failed to disconnect from Server."));
		UE_LOG(LogSourceControl, Error, TEXT("%s"), TO_TCHAR(ErrorMessage.Text(), bIsUnicode));
	}
#endif
}
	virtual void HandleError( Error *err )
	{
		if ( err == 0 )
			return;
				
		StrBuf buf;
		err->Fmt(&buf);
		
		const string upToDate = " - file(s) up-to-date.";
		string value(buf.Text());
		value = TrimEnd(value, '\n');
		
		if (EndsWith(value, upToDate)) return; // ignore
		
		P4Command::HandleError(err);
	}
Esempio n. 23
0
void CCmd_Password::OnPrompt( const StrPtr &msg, StrBuf &rsp, int noEcho, Error *e )
{
	CString message = CharToCString(msg.Text());
	CString *csp;
	csp = (message.Find(_T("old")) != -1) ? &m_OldPwd : &m_NewPwd;
	rsp.Set(CharFromCString(*csp));
}
Esempio n. 24
0
void PythonClientUser::HandleError( Error *e )
{
    EnsurePythonLock guard;
    
    if( P4PYDBG_CALLS )
	cerr << "[P4] HandleError()" << endl;

    if( P4PYDBG_DATA ) 
    {
	StrBuf t;
	e->Fmt( t, EF_PLAIN );
	cerr << "... [" << e->FmtSeverity() << "] " << t.Text() << endl;
    }

    ProcessMessage( e );
}
Esempio n. 25
0
int P4ClientAPI::Except( const char *func, const char *msg )
{
	StrBuf	m;
	StrBuf	errors;
	StrBuf	warnings;
	bool	terminate = false;

	m << "[" << func << "] " << msg;

	// Now append any errors and warnings to the text
	ui.GetResults().FmtErrors( errors );
	ui.GetResults().FmtWarnings( warnings );

	if( errors.Length() )
	{
		m << "\n" << errors;
		terminate= true;
	}

	if( exceptionLevel > 1 && warnings.Length() )
	{
		m << "\n" << warnings;
		terminate= true;
	}

	if( terminate )
		m << "\n\n";

	if ( exceptionLevel )
	{
		luaL_error( L, m.Text() );
		return 0;
	}

	lua_pushnil( L );

	if( apiLevel < 68 ) {
		lua_pushstring( L, m.Text() );
	} else {
		// return a list with three elements:
		// the string value, the list of errors and list of warnings
		// P4Exception will sort out what's what
		lua_newtable( L );

		lua_pushstring( L, m.Text() );
		lua_rawseti( L, -2, 1 );

		lua_rawgeti( L, LUA_REGISTRYINDEX, ui.GetResults().GetErrors() );
		lua_rawseti( L, -2, 2 );

		lua_rawgeti( L, LUA_REGISTRYINDEX, ui.GetResults().GetWarnings() );
		lua_rawseti( L, -2, 3 );
	}

	return 2;
}
Esempio n. 26
0
int
P4ClientApi::SetCharset( const char *c )
{
	if( P4LUADEBUG_COMMANDS )
		fprintf( stderr, "[P4] Setting charset: %s\n", c );

	CharSetApi::CharSet cs = CharSetApi::Lookup( c );
	if( cs < 0 )
	{
		StrBuf	m;
		m = "Unknown or unsupported charset: ";
		m.Append( c );
		return Except( "P4#charset=", m.Text() );
	}
	client.SetTrans( cs, cs, cs, cs );
	client.SetCharset( c );
	return 1;
}
Esempio n. 27
0
void CForceSyncDlg::OnDeleteSelected() 
{
	CString filename;
	POSITION pos;
	POSITION oldPos;

	for(int i=m_List.GetCount()-1; i>=0; i--)
	{
		if(m_List.GetSel(i))
		{
			m_List.GetText(i, filename);
			if (filename.FindOneOf(_T("@#%")) != -1)
			{
				StrBuf b;
				StrBuf f;
				f << CharFromCString(filename);
				StrPtr *p = &f;
				StrOps::WildToStr(*p, b);
				filename = CharToCString(b.Value());
			}
			for(pos = m_lpCstrListC->GetHeadPosition(); pos != NULL; )
			{
				oldPos = pos;
				if (filename == m_lpCstrListC->GetNext(pos))
				{
					m_lpCstrListC->RemoveAt(oldPos);
					m_List.DeleteString(i);
					continue;
				}
			}
			for(pos = m_lpCstrListD->GetHeadPosition(); pos != NULL; )
			{
				oldPos = pos;
				if (filename == m_lpCstrListD->GetNext(pos))
				{
					m_lpCstrListD->RemoveAt(oldPos);
					m_List.DeleteString(i);
					break;
				}
			}
		}
	}
	m_Delete.EnableWindow(FALSE);
}
Esempio n. 28
0
static void ReadValue( StrBuf& string, const char* ptr )
{
	for ( ; *ptr; ++ptr ) {
		if ( *ptr == '%'  &&
			( ( ptr[1] >= '0'  &&  ptr[1] <= '9' )  ||  ( ptr[1] >= 'A'  &&  ptr[1] <= 'F' ) )  &&
			( ( ptr[2] >= '0'  &&  ptr[2] <= '9' )  ||  ( ptr[2] >= 'A'  &&  ptr[2] <= 'F' ) ) ) {
			unsigned char ch;
			if ( ptr[1] >= '0'  &&  ptr[1] <= '9' )
				ch = ( ptr[1] - '0' ) << 4;
			else
				ch = ( ( ptr[1] - 'A' ) + 10 ) << 4;
			if ( ptr[2] >= '0'  &&  ptr[2] <= '9' )
				ch |= ( ptr[2] - '0' );
			else
				ch |= ( ptr[2] - 'A' ) + 10;
			ptr += 2;
			string.Extend( (char)ch );
		} else
			string.Extend( *ptr );
	}
	string.Extend( 0 );
}
Esempio n. 29
0
//
// Returns a hash whose keys contain the names of the fields in a spec of the
// specified type. Not yet exposed to Ruby clients, but may be in future.
//
int
P4ClientAPI::SpecFields( const char * type )
{
	if ( !specMgr.HaveSpecDef( type ) )
	{
		if( exceptionLevel )
		{
			StrBuf m;
			m = "No spec definition for ";
			m.Append( type );
			m.Append( " objects." );
			return Except( "P4:spec_fields", m.Text() );
		}
		else
		{
			lua_pushboolean( L, false );
			return 0;
		}
	}

	return specMgr.SpecFields( type );
}
// Default handler of P4 error output. Called by the default P4Command::Message() handler.
void P4Command::HandleError( Error *err )
{
    if ( err == 0 )
        return;

    StrBuf buf;
    err->Fmt(&buf);

    if (HandleOnlineStatusOnError(err))
    {
        Conn().Log().Fatal() <<  buf.Text() << Endl;
        return; // Error logged and Unity notified about plugin offline
    }

    // This is a regular non-connection related error

    VCSStatus s = errorToVCSStatus(*err);
    m_Status.insert(s.begin(), s.end());

    // m_Status will contain the error messages to be sent to unity
    // Just log locally
    Conn().Log().Fatal() << buf.Text() << Endl;
}