Bernie Bright:
Ensure lines sent to clients are CRLF terminated. Ensure the dump command null terminates its output string. Removed view command and comments.
This commit is contained in:
parent
1ffd296e27
commit
0efc08b6b6
1 changed files with 30 additions and 114 deletions
|
@ -42,6 +42,7 @@
|
||||||
|
|
||||||
#if !defined(SG_HAVE_NATIVE_SGI_COMPILERS)
|
#if !defined(SG_HAVE_NATIVE_SGI_COMPILERS)
|
||||||
SG_USING_STD(strstream);
|
SG_USING_STD(strstream);
|
||||||
|
SG_USING_STD(ends);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -87,8 +88,6 @@ private:
|
||||||
* Return a "Node no found" error message to the client.
|
* Return a "Node no found" error message to the client.
|
||||||
*/
|
*/
|
||||||
void node_not_found_error( const string& node_name );
|
void node_not_found_error( const string& node_name );
|
||||||
|
|
||||||
void view_cmd( const vector<string>& );
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -160,28 +159,6 @@ getValueTypeString( const SGPropertyNode *node )
|
||||||
/**
|
/**
|
||||||
* We have a command.
|
* We have a command.
|
||||||
*
|
*
|
||||||
* TODO: possible future commands:
|
|
||||||
* panel <subcmd>
|
|
||||||
* panel load [path]
|
|
||||||
* panel mouse <button> up|down|click <x> <y>
|
|
||||||
* panel visible 0|1
|
|
||||||
* panel height -> h, Retrieve panel height
|
|
||||||
* panel width -> w, Retrieve panel width
|
|
||||||
* panel xoffset -> x, Retrieve panel x offset
|
|
||||||
* panel yoffset -> y, Retrieve panel y offset
|
|
||||||
*
|
|
||||||
* property <subcmd>
|
|
||||||
* property toggle <prop>
|
|
||||||
* property adjust <prop> <step> <offset> <factor> <min> <max> <wrap>
|
|
||||||
* property multiply <prop> <factor>
|
|
||||||
* property swap <prop1> <prop2>
|
|
||||||
* property scale <prop> <setting> <offset> <factor>
|
|
||||||
*
|
|
||||||
* view <subcmd>
|
|
||||||
* view next
|
|
||||||
* view prev
|
|
||||||
* view set <n>
|
|
||||||
* view current -> n, Retrieve index of current view
|
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
TelnetChannel::foundTerminator()
|
TelnetChannel::foundTerminator()
|
||||||
|
@ -260,6 +237,7 @@ TelnetChannel::foundTerminator()
|
||||||
if ( tokens.size() <= 1 )
|
if ( tokens.size() <= 1 )
|
||||||
{
|
{
|
||||||
writeProperties( buf, node );
|
writeProperties( buf, node );
|
||||||
|
buf << ends; // null terminate the string
|
||||||
push( buf.str() );
|
push( buf.str() );
|
||||||
push( getTerminator() );
|
push( getTerminator() );
|
||||||
}
|
}
|
||||||
|
@ -269,6 +247,7 @@ TelnetChannel::foundTerminator()
|
||||||
if ( child )
|
if ( child )
|
||||||
{
|
{
|
||||||
writeProperties ( buf, child );
|
writeProperties ( buf, child );
|
||||||
|
buf << ends; // null terminate the string
|
||||||
push( buf.str() );
|
push( buf.str() );
|
||||||
push( getTerminator() );
|
push( getTerminator() );
|
||||||
}
|
}
|
||||||
|
@ -326,13 +305,14 @@ TelnetChannel::foundTerminator()
|
||||||
tmp += "' (";
|
tmp += "' (";
|
||||||
tmp += getValueTypeString(
|
tmp += getValueTypeString(
|
||||||
node->getNode( tokens[1].c_str() ) );
|
node->getNode( tokens[1].c_str() ) );
|
||||||
tmp += ")\n";
|
tmp += ")";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tmp = value + "\n";
|
tmp = value;
|
||||||
}
|
}
|
||||||
push( tmp.c_str() );
|
push( tmp.c_str() );
|
||||||
|
push( getTerminator() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( command == "set" )
|
else if ( command == "set" )
|
||||||
|
@ -348,8 +328,9 @@ TelnetChannel::foundTerminator()
|
||||||
string value = node->getStringValue ( tokens[1].c_str(), "" );
|
string value = node->getStringValue ( tokens[1].c_str(), "" );
|
||||||
string tmp = tokens[1] + " = '" + value + "' (";
|
string tmp = tokens[1] + " = '" + value + "' (";
|
||||||
tmp += getValueTypeString( node->getNode( tokens[1].c_str() ) );
|
tmp += getValueTypeString( node->getNode( tokens[1].c_str() ) );
|
||||||
tmp += ")\n";
|
tmp += ")";
|
||||||
push( tmp.c_str() );
|
push( tmp.c_str() );
|
||||||
|
push( getTerminator() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -367,40 +348,22 @@ TelnetChannel::foundTerminator()
|
||||||
{
|
{
|
||||||
mode = PROMPT;
|
mode = PROMPT;
|
||||||
}
|
}
|
||||||
else if ( command == "view" )
|
|
||||||
{
|
|
||||||
view_cmd( tokens );
|
|
||||||
}
|
|
||||||
// else if ( command == "panel" )
|
|
||||||
// {
|
|
||||||
// panel_cmd( tokens );
|
|
||||||
// }
|
|
||||||
// else if ( command == "property" )
|
|
||||||
// {
|
|
||||||
// property_cmd( tokens );
|
|
||||||
// }
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const char* msg = "\
|
const char* msg = "\
|
||||||
Valid commands are:\n\
|
Valid commands are:\r\n\
|
||||||
\n\
|
\r\n\
|
||||||
cd <dir> cd to a directory, '..' to move back\n\
|
cd <dir> cd to a directory, '..' to move back\r\n\
|
||||||
data switch to raw data mode\n\
|
data switch to raw data mode\r\n\
|
||||||
dump dump current state (in xml)\n\
|
dump dump current state (in xml)\r\n\
|
||||||
get <var> show the value of a parameter\n\
|
get <var> show the value of a parameter\r\n\
|
||||||
help show this help message\n\
|
help show this help message\r\n\
|
||||||
ls [<dir>] list directory\n\
|
ls [<dir>] list directory\r\n\
|
||||||
prompt switch to interactive mode (default)\n\
|
prompt switch to interactive mode (default)\r\n\
|
||||||
pwd display your current path\n\
|
pwd display your current path\r\n\
|
||||||
quit terminate connection\n\
|
quit terminate connection\r\n\
|
||||||
set <var> <val> set <var> to a new <val>\n\
|
set <var> <val> set <var> to a new <val>\r\n\
|
||||||
show <var> synonym for get\n\
|
show <var> synonym for get\r\n";
|
||||||
view next display next view\n\
|
|
||||||
view prev display prev view\n\
|
|
||||||
view set <n> display view 'n'\n\
|
|
||||||
view get return current view index\n\
|
|
||||||
view current return current view index\n\
|
|
||||||
";
|
|
||||||
push( msg );
|
push( msg );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -420,67 +383,20 @@ view current return current view index\n\
|
||||||
buffer.remove();
|
buffer.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
TelnetChannel::view_cmd( const vector<string>& tokens )
|
|
||||||
{
|
|
||||||
if (tokens.size() <= 1)
|
|
||||||
{
|
|
||||||
// ERROR: no sub-command
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
string subcmd = tokens[1];
|
|
||||||
|
|
||||||
if (subcmd == "next")
|
|
||||||
{
|
|
||||||
globals->get_current_view()->setHeadingOffset_deg(0.0);
|
|
||||||
globals->get_viewmgr()->next_view();
|
|
||||||
}
|
|
||||||
else if (subcmd == "prev")
|
|
||||||
{
|
|
||||||
globals->get_current_view()->setHeadingOffset_deg(0.0);
|
|
||||||
globals->get_viewmgr()->prev_view();
|
|
||||||
}
|
|
||||||
else if (subcmd == "set")
|
|
||||||
{
|
|
||||||
if (tokens.size() == 3)
|
|
||||||
{
|
|
||||||
int i = atoi( tokens[2].c_str() );
|
|
||||||
if (0 >= i && i < globals->get_viewmgr()->size())
|
|
||||||
{
|
|
||||||
globals->get_current_view()->setHeadingOffset_deg(0.0);
|
|
||||||
globals->get_viewmgr()->set_view(i);
|
|
||||||
globals->get_viewmgr()->copyToCurrent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (subcmd == "get" || subcmd == "current")
|
|
||||||
{
|
|
||||||
int i = globals->get_viewmgr()->get_current();
|
|
||||||
char buf[16];
|
|
||||||
snprintf( buf, sizeof(buf), "%d", i );
|
|
||||||
push( buf );
|
|
||||||
push( getTerminator() );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// ERROR: invalid subcommand.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
FGTelnet::FGTelnet( const vector<string>& tokens )
|
FGTelnet::FGTelnet( const vector<string>& tokens )
|
||||||
{
|
{
|
||||||
if (tokens.size() != 2)
|
// tokens:
|
||||||
{
|
// telnet,port#
|
||||||
throw FGProtocolConfigError( "FGProps: expected 1 argument, <port>" );
|
// props,medium,direction,hz,hostname,port#,style
|
||||||
}
|
if (tokens.size() == 2)
|
||||||
|
port = atoi( tokens[1].c_str() );
|
||||||
port = atoi( tokens[1].c_str() );
|
else if (tokens.size() == 7)
|
||||||
|
port = atoi( tokens[5].c_str() );
|
||||||
|
else
|
||||||
|
throw FGProtocolConfigError( "FGTelnet: incorrect number of configuration arguments" );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue