libs/StartExe/StartExe.cpp
//---------------------------------------------------------------------------------------------
// This function will process given command with it's arguments and will send the reply
//---------------------------------------------------------------------------------------------
This function will process given command with it's arguments and will send the reply
This function will process given command with it ' s arguments and will send the reply
int ProcessOneCommand(ClientDescriptor* client, char args[10][1000],int paramsCount) {
	int		cmdType	=	START_NO_WAIT;
	DWORD	exitCode;
	char*	outputFile = NULL;
	char	replyString[1024];
	if(strcmp(args[0],"register")==0) {
		nClients++;
		SendString(client->m_ClientSocket, "done");
		_DBG(fprintf(log_fd,"A new client has been registered.\n"));
		return 1;
	}
	if(strcmp(args[0],"unregister")==0) {
		nClients--;
		if(nClients<1){
			do_shutdown = 1;
		}
		SendString(client->m_ClientSocket, "done");
		_DBG(fprintf(log_fd,"A client has been unregistered.\n"));
		return 1;
	}
	if(strcmp(args[0],"start")==0) {
		cmdType	=	START_NO_WAIT;
		_DBG(fprintf(log_fd,"Processing START_NO_WAIT command...\n"));
	} else {
		if(strcmp(args[0],"start_and_wait")==0) {
			cmdType	=	START_AND_WAIT;
			_DBG(fprintf(log_fd,"Processing START_AND_WAIT command...\n"));
		} else {
			if(strcmp(args[0],"start_wait_and_get_output")==0) {
				cmdType	= START_AND_WAIT;
				outputFile = args[paramsCount-1];
				_DBG(fprintf(log_fd,"Processing START_WAIT_AND_GET_OUTPUT command...\n"));
			} else {
				sprintf(replyString,"Error%s0%sunknown command",REPLY_DELIM,REPLY_DELIM);
				SendString(client->m_ClientSocket,replyString);
				_DBG(fprintf(log_fd,"Unknown command %s.\n",args[0]));
				return 0;
			}
		}
	}
	if(StartProcess(args[1],args[2],outputFile,&exitCode,cmdType)==true) {
		sprintf(replyString,"Done%s%d%s",REPLY_DELIM,exitCode,REPLY_DELIM);
		_DBG(fprintf(log_fd,"Command successed. Return code %d\n",exitCode));
	} else {
#ifdef _WIN32
		LPVOID lpMsgBuf;
		FormatMessage( 
				FORMAT_MESSAGE_ALLOCATE_BUFFER | 
				FORMAT_MESSAGE_FROM_SYSTEM | 
				FORMAT_MESSAGE_IGNORE_INSERTS,
				NULL,
				GetLastError(),
				MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 
				(LPTSTR) &lpMsgBuf,
				0,
				NULL 
				);
		sprintf(replyString,"Error%s%d%s%s",REPLY_DELIM,&exitCode,REPLY_DELIM,(LPTSTR)lpMsgBuf);
		LocalFree( lpMsgBuf );
#else
		sprintf(replyString,"Error%s%d%s%s",REPLY_DELIM,&exitCode,REPLY_DELIM,FormatErrorMessage(GetLastError()));
#endif
		_DBG(fprintf(log_fd,"Command FAILED. Return code %d. Error %s\n",exitCode,replyString));
	}
	SendString(client->m_ClientSocket,replyString);
	return 1;
}
int ProcessOneCommand ( ClientDescriptor * client , char args [ 10 ] [ 1000 ] , int paramsCount ) { int cmdType = START_NO_WAIT ; DWORD exitCode ; char * outputFile = NULL ; char replyString [ 1024 ] ; if ( strcmp ( args [ 0 ] , " " ) == 0 ) { nClients ++ ; SendString ( client -> m_ClientSocket , " " ) ; _DBG ( fprintf ( log_fd , " \n " ) ) ; return 1 ; } if ( strcmp ( args [ 0 ] , " " ) == 0 ) { nClients -- ; if ( nClients < 1 ) { do_shutdown = 1 ; } SendString ( client -> m_ClientSocket , " " ) ; _DBG ( fprintf ( log_fd , " \n " ) ) ; return 1 ; } if ( strcmp ( args [ 0 ] , " " ) == 0 ) { cmdType = START_NO_WAIT ; _DBG ( fprintf ( log_fd , " \n " ) ) ; } else { if ( strcmp ( args [ 0 ] , " " ) == 0 ) { cmdType = START_AND_WAIT ; _DBG ( fprintf ( log_fd , " \n " ) ) ; } else { if ( strcmp ( args [ 0 ] , " " ) == 0 ) { cmdType = START_AND_WAIT ; outputFile = args [ paramsCount - 1 ] ; _DBG ( fprintf ( log_fd , " \n " ) ) ; } else { sprintf ( replyString , " " , REPLY_DELIM , REPLY_DELIM ) ; SendString ( client -> m_ClientSocket , replyString ) ; _DBG ( fprintf ( log_fd , " \n " , args [ 0 ] ) ) ; return 0 ; } } } if ( StartProcess ( args [ 1 ] , args [ 2 ] , outputFile , & exitCode , cmdType ) == true ) { sprintf ( replyString , " " , REPLY_DELIM , exitCode , REPLY_DELIM ) ; _DBG ( fprintf ( log_fd , " \n " , exitCode ) ) ; } else { #ifdef _WIN32 LPVOID lpMsgBuf ; FormatMessage ( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS , NULL , GetLastError ( ) , MAKELANGID ( LANG_NEUTRAL , SUBLANG_DEFAULT ) , ( LPTSTR ) & lpMsgBuf , 0 , NULL ) ; sprintf ( replyString , " " , REPLY_DELIM , & exitCode , REPLY_DELIM , ( LPTSTR ) lpMsgBuf ) ; LocalFree ( lpMsgBuf ) ; #else sprintf ( replyString , " " , REPLY_DELIM , & exitCode , REPLY_DELIM , FormatErrorMessage ( GetLastError ( ) ) ) ; #endif _DBG ( fprintf ( log_fd , " \n " , exitCode , replyString ) ) ; } SendString ( client -> m_ClientSocket , replyString ) ; return 1 ; }
This function will process given command with it's arguments and will send the reply
This function will process given command with it ' s arguments and will send the reply
// Starts detached process // We do not know this command  // Default language // Save the error string. // Free the buffer.