1
0
Fork 0

Anders GIDENSTAM: catch all exceptions to avoid aborting fgfs after

commands like "ls .."
This commit is contained in:
mfranz 2008-06-11 17:16:50 +00:00
parent 876bd2055c
commit 5cb6e43767

View file

@ -89,10 +89,9 @@ public:
void foundTerminator(); void foundTerminator();
private: private:
/** inline void node_not_found_error( const string& s ) const {
* Return a "Node no found" error message to the client. throw "node '" + s + "' not found";
*/ }
void node_not_found_error( const string& node_name );
}; };
/** /**
@ -115,19 +114,6 @@ PropsChannel::collectIncomingData( const char* s, int n )
buffer.append( s, n ); buffer.append( s, n );
} }
/**
*
*/
void
PropsChannel::node_not_found_error( const string& node_name )
{
string error = "-ERR Node \"";
error += node_name;
error += "\" not found.";
push( error.c_str() );
push( getTerminator() );
}
// return a human readable form of the value "type" // return a human readable form of the value "type"
static string static string
getValueTypeString( const SGPropertyNode *node ) getValueTypeString( const SGPropertyNode *node )
@ -175,6 +161,7 @@ PropsChannel::foundTerminator()
SGPropertyNode* node = globals->get_props()->getNode( path.c_str() ); SGPropertyNode* node = globals->get_props()->getNode( path.c_str() );
try {
if (!tokens.empty()) { if (!tokens.empty()) {
string command = tokens[0]; string command = tokens[0];
@ -192,7 +179,6 @@ PropsChannel::foundTerminator()
if (dir == 0) { if (dir == 0) {
node_not_found_error( tokens[1] ); node_not_found_error( tokens[1] );
goto prompt;
} }
} }
@ -235,16 +221,12 @@ PropsChannel::foundTerminator()
} }
else if ( command == "cd" ) { else if ( command == "cd" ) {
if (tokens.size() == 2) { if (tokens.size() == 2) {
try { SGPropertyNode* child = node->getNode( tokens[1].c_str() );
SGPropertyNode* child = node->getNode( tokens[1].c_str() ); if ( child ) {
if ( child ) { node = child;
node = child; path = node->getPath();
path = node->getPath(); } else {
} else { node_not_found_error( tokens[1] );
node_not_found_error( tokens[1] );
}
} catch (...) {
// Ignore attempt to move past root node with ".."
} }
} }
} else if ( command == "pwd" ) { } else if ( command == "pwd" ) {
@ -393,7 +375,7 @@ PropsChannel::foundTerminator()
push( getTerminator() ); push( getTerminator() );
} }
} }
} else if (command == "quit") { } else if ( command == "quit" || command == "exit" ) {
close(); close();
shouldDelete(); shouldDelete();
return; return;
@ -420,8 +402,13 @@ set <var> <val> set <var> to a new <val>\r\n";
} }
} }
prompt: } catch ( const string& msg ) {
if (mode == PROMPT) { string error = "-ERR \"" + msg + "\"";
push( error.c_str() );
push( getTerminator() );
}
if ( mode == PROMPT ) {
string prompt = node->getPath(); string prompt = node->getPath();
if (prompt.empty()) { if (prompt.empty()) {
prompt = "/"; prompt = "/";