From 5cb6e43767257a76eb64ad380f7cbd2133d49e1a Mon Sep 17 00:00:00 2001 From: mfranz Date: Wed, 11 Jun 2008 17:16:50 +0000 Subject: [PATCH] Anders GIDENSTAM: catch all exceptions to avoid aborting fgfs after commands like "ls .." --- src/Network/props.cxx | 49 ++++++++++++++++--------------------------- 1 file changed, 18 insertions(+), 31 deletions(-) diff --git a/src/Network/props.cxx b/src/Network/props.cxx index 1048a5cc1..667805849 100644 --- a/src/Network/props.cxx +++ b/src/Network/props.cxx @@ -89,10 +89,9 @@ public: void foundTerminator(); private: - /** - * Return a "Node no found" error message to the client. - */ - void node_not_found_error( const string& node_name ); + inline void node_not_found_error( const string& s ) const { + throw "node '" + s + "' not found"; + } }; /** @@ -115,19 +114,6 @@ PropsChannel::collectIncomingData( const char* s, int 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" static string getValueTypeString( const SGPropertyNode *node ) @@ -175,6 +161,7 @@ PropsChannel::foundTerminator() SGPropertyNode* node = globals->get_props()->getNode( path.c_str() ); + try { if (!tokens.empty()) { string command = tokens[0]; @@ -192,7 +179,6 @@ PropsChannel::foundTerminator() if (dir == 0) { node_not_found_error( tokens[1] ); - goto prompt; } } @@ -235,16 +221,12 @@ PropsChannel::foundTerminator() } else if ( command == "cd" ) { if (tokens.size() == 2) { - try { - SGPropertyNode* child = node->getNode( tokens[1].c_str() ); - if ( child ) { - node = child; - path = node->getPath(); - } else { - node_not_found_error( tokens[1] ); - } - } catch (...) { - // Ignore attempt to move past root node with ".." + SGPropertyNode* child = node->getNode( tokens[1].c_str() ); + if ( child ) { + node = child; + path = node->getPath(); + } else { + node_not_found_error( tokens[1] ); } } } else if ( command == "pwd" ) { @@ -393,7 +375,7 @@ PropsChannel::foundTerminator() push( getTerminator() ); } } - } else if (command == "quit") { + } else if ( command == "quit" || command == "exit" ) { close(); shouldDelete(); return; @@ -420,8 +402,13 @@ set set to a new \r\n"; } } - prompt: - if (mode == PROMPT) { + } catch ( const string& msg ) { + string error = "-ERR \"" + msg + "\""; + push( error.c_str() ); + push( getTerminator() ); + } + + if ( mode == PROMPT ) { string prompt = node->getPath(); if (prompt.empty()) { prompt = "/";