diff --git a/harbour/ChangeLog b/harbour/ChangeLog index f9e5ae5257..b9cc74ea2c 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,22 @@ The license applies to all entries newer than 2009-04-28. */ +2011-01-26 13:54 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) + * contrib/hbnetio/utils/netiosrv/netiosrv.prg + * contrib/hbnetio/utils/netiosrv/netiocmd.prg + ! 'netio_logconn()' RPC was returning wrong value. + + Console UI extended to use NETIO_GETCONNECTION() and + use pConnection to make RPC calls. Which opens the door + to support multiple server connections at the same time. + + Added experimental code for management client indentification. + Currently the management client will identify itself right + after connection, and this information will be shown on the + server console. + ; QUESTION: How to find out in an RPC call on the server side, + which connection it belongs to? + ; QUESTION: Should NETIO_DISCONNECT() support optional pConnection + parameter (instead of IP/port pair)? + 2011-01-25 23:15 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) * contrib/hbxbp/xbpmenubar.prg ! Fixed: a stupid untested typo. diff --git a/harbour/contrib/hbnetio/utils/netiosrv/netiocmd.prg b/harbour/contrib/hbnetio/utils/netiosrv/netiocmd.prg index d0bdb39bd8..caf07c9a7a 100644 --- a/harbour/contrib/hbnetio/utils/netiosrv/netiocmd.prg +++ b/harbour/contrib/hbnetio/utils/netiosrv/netiocmd.prg @@ -18,18 +18,18 @@ #include "hbgtinfo.ch" -STATIC FUNCTION hbnetiosrv_LoadCmds() +STATIC FUNCTION hbnetiosrv_LoadCmds( pConnection ) LOCAL hCmds := { ; "?" => { "" , "Synonym for 'help'." , {|| cmdHelp( hCmds ) } },; "clear" => { "" , "Clear screen." , {|| Scroll(), SetPos( 0, 0 ) } },; - "sysinfo" => { "" , "Show system/build information." , {|| cmdSysInfo() } },; - "show" => { "" , "Show list of connections." , {|| cmdConnInfo() } },; - "noconn" => { "" , "Disable incoming connections." , {|| cmdConnEnable( .F. ) } },; - "conn" => { "" , "Enable incoming connections." , {|| cmdConnEnable( .T. ) } },; - "nologconn" => { "" , "Disable logging incoming connections." , {|| cmdConnLogEnable( .F. ) } },; - "logconn" => { "" , "Enable logging incoming connections." , {|| cmdConnLogEnable( .T. ) } },; - "stop" => { "[|all]", "Stop specified connection(s)." , {| cCommand | cmdConnStop( cCommand ) } },; - "quit" => { "" , "Stop server and exit." , {|| netio_funcexec( "netio_shutdown" ) } },; + "sysinfo" => { "" , "Show system/build information." , {|| cmdSysInfo( pConnection ) } },; + "show" => { "" , "Show list of connections." , {|| cmdConnInfo( pConnection ) } },; + "noconn" => { "" , "Disable incoming connections." , {|| cmdConnEnable( pConnection, .F. ) } },; + "conn" => { "" , "Enable incoming connections." , {|| cmdConnEnable( pConnection, .T. ) } },; + "nologconn" => { "" , "Disable logging incoming connections." , {|| cmdConnLogEnable( pConnection, .F. ) } },; + "logconn" => { "" , "Enable logging incoming connections." , {|| cmdConnLogEnable( pConnection, .T. ) } },; + "stop" => { "[|all]", "Stop specified connection(s)." , {| cCommand | cmdConnStop( pConnection, cCommand ) } },; + "quit" => { "" , "Stop server and exit." , {|| netio_funcexec( pConnection, "netio_shutdown" ) } },; "help" => { "" , "Display this help." , {|| cmdHelp( hCmds ) } } } RETURN hCmds @@ -75,7 +75,20 @@ STATIC PROCEDURE cmdHelp( hCommands ) RETURN -PROCEDURE netio_cmdUI( cIP, nPort, cPassword ) +STATIC FUNCTION netiosrv_clientinfo() + LOCAL hInfo := { => } + + hb_hKeepOrder( hInfo, .T. ) + + hInfo[ "OS()" ] := OS() + hInfo[ "Version()" ] := Version() + hInfo[ "hb_Compiler()" ] := hb_Compiler() + hInfo[ "NetName()" ] := NetName() + hInfo[ "hb_UserName()" ] := hb_UserName() + + RETURN hInfo + +PROCEDURE netiosrv_cmdUI( cIP, nPort, cPassword ) LOCAL GetList := {} LOCAL hCommands LOCAL nSavedRow @@ -91,15 +104,17 @@ PROCEDURE netio_cmdUI( cIP, nPort, cPassword ) LOCAL aHistory, nHistIndex - LOCAL lOk + LOCAL pConnection /* connect to the server */ QQOut( "Connecting to server management interface...", hb_eol() ) - lOk := netio_connect( cIP, nPort,, cPassword ) + pConnection := netio_getconnection( cIP, nPort,, cPassword ) cPassword := NIL - IF lOk + IF ! Empty( pConnection ) + + netio_funcexec( pConnection, "netio_sendclientinfo", netiosrv_clientinfo() ) QQOut( "Connected.", hb_eol() ) QQOut( hb_eol() ) @@ -107,7 +122,7 @@ PROCEDURE netio_cmdUI( cIP, nPort, cPassword ) aHistory := { "quit" } nHistIndex := Len( aHistory ) + 1 - hCommands := hbnetiosrv_LoadCmds() + hCommands := hbnetiosrv_LoadCmds( pConnection ) /* Command prompt */ DO WHILE .T. @@ -204,28 +219,28 @@ STATIC PROCEDURE CompleteCmd( cCommand, hCommands ) /* Commands */ -STATIC PROCEDURE cmdSysInfo() +STATIC PROCEDURE cmdSysInfo( pConnection ) LOCAL cLine - FOR EACH cLine IN netio_funcexec( "netio_sysinfo" ) + FOR EACH cLine IN netio_funcexec( pConnection , "netio_sysinfo" ) QQOut( cLine, hb_eol() ) NEXT RETURN -STATIC PROCEDURE cmdConnStop( cCommand ) +STATIC PROCEDURE cmdConnStop( pConnection, cCommand ) LOCAL aToken := hb_ATokens( cCommand, " " ) IF Len( aToken ) > 1 - netio_funcexec( "netio_stop", aToken[ 2 ] ) + netio_funcexec( pConnection, "netio_stop", aToken[ 2 ] ) ELSE QQOut( "Error: Invalid syntax.", hb_eol() ) ENDIF RETURN -STATIC PROCEDURE cmdConnInfo() - LOCAL aArray := netio_funcexec( "netio_conninfo" ) +STATIC PROCEDURE cmdConnInfo( pConnection ) + LOCAL aArray := netio_funcexec( pConnection, "netio_conninfo" ) LOCAL hConn QQOut( "Number of connections: " + hb_ntos( Len( aArray ) ), hb_eol() ) @@ -242,14 +257,14 @@ STATIC PROCEDURE cmdConnInfo() RETURN -PROCEDURE cmdConnEnable( lValue ) +PROCEDURE cmdConnEnable( pConnection, lValue ) - netio_funcexec( "netio_conn", lValue ) + netio_funcexec( pConnection, "netio_conn", lValue ) RETURN -PROCEDURE cmdConnLogEnable( lValue ) +PROCEDURE cmdConnLogEnable( pConnection, lValue ) - netio_funcexec( "netio_logconn", lValue ) + netio_funcexec( pConnection, "netio_logconn", lValue ) RETURN diff --git a/harbour/contrib/hbnetio/utils/netiosrv/netiosrv.prg b/harbour/contrib/hbnetio/utils/netiosrv/netiosrv.prg index 04ec540cec..b7e3571eb3 100644 --- a/harbour/contrib/hbnetio/utils/netiosrv/netiosrv.prg +++ b/harbour/contrib/hbnetio/utils/netiosrv/netiosrv.prg @@ -55,7 +55,8 @@ REQUEST HB_MT #define _NETIOSRV_CONN_pConnection 1 #define _NETIOSRV_CONN_tStart 2 -#define _NETIOSRV_CONN_MAX_ 2 +#define _NETIOSRV_CONN_hInfo 3 +#define _NETIOSRV_CONN_MAX_ 3 PROCEDURE Main( ... ) LOCAL netiosrv[ _NETIOSRV_MAX_ ] @@ -186,14 +187,15 @@ PROCEDURE Main( ... ) netio_mtserver( netiomgm[ _NETIOSRV_nPort ],; netiomgm[ _NETIOSRV_cIFAddr ],; NIL,; - { "netio_sysinfo" => {| ... | netio_mgmt_rpc_sysinfo() } ,; - "netio_shutdown" => {| ... | netio_mgmt_rpc_shutdown( netiosrv ) } ,; - "netio_conninfo" => {| ... | netio_mgmt_rpc_conninfo( netiosrv ) } ,; - "netio_stop" => {| ... | netio_mgmt_rpc_stop( netiosrv, ... ) } ,; - "netio_conn" => {| ... | netio_mgmt_rpc_conn( netiosrv, .T. ) } ,; - "netio_noconn" => {| ... | netio_mgmt_rpc_conn( netiosrv, .F. ) } ,; - "netio_logconn" => {| ... | netio_mgmt_rpc_logconn( netiosrv, .T. ) } ,; - "netio_nologconn" => {| ... | netio_mgmt_rpc_logconn( netiosrv, .F. ) } },; + { "netio_sendclientinfo" => {| ... | netio_mgmt_rpc_clientinfo( netiomgm, ... ) } ,; + "netio_sysinfo" => {| ... | netio_mgmt_rpc_sysinfo() } ,; + "netio_shutdown" => {| ... | netio_mgmt_rpc_shutdown( netiosrv ) } ,; + "netio_conninfo" => {| ... | netio_mgmt_rpc_conninfo( netiosrv ) } ,; + "netio_stop" => {| ... | netio_mgmt_rpc_stop( netiosrv, ... ) } ,; + "netio_conn" => {| ... | netio_mgmt_rpc_conn( netiosrv, .T. ) } ,; + "netio_noconn" => {| ... | netio_mgmt_rpc_conn( netiosrv, .F. ) } ,; + "netio_logconn" => {| ... | netio_mgmt_rpc_logconn( netiosrv, .T. ) } ,; + "netio_nologconn" => {| ... | netio_mgmt_rpc_logconn( netiosrv, .F. ) } },; cPasswordManagement,; NIL,; NIL,; @@ -203,7 +205,7 @@ PROCEDURE Main( ... ) OutStd( "Warning: Cannot start server management." + hb_eol() ) ELSE IF lUI - hb_threadDetach( hb_threadStart( {|| netio_cmdUI( netiomgm[ _NETIOSRV_cIFAddr ], netiomgm[ _NETIOSRV_nPort ], cPasswordManagement ) } ) ) + hb_threadDetach( hb_threadStart( {|| netiosrv_cmdUI( netiomgm[ _NETIOSRV_cIFAddr ], netiomgm[ _NETIOSRV_nPort ], cPasswordManagement ) } ) ) ENDIF ENDIF ENDIF @@ -292,6 +294,22 @@ STATIC PROCEDURE netiosrv_conn_unregister( netiosrv, pConnectionSocket ) /* RPC management interface */ +STATIC FUNCTION netio_mgmt_rpc_clientinfo( netiomgm, hInfo ) + LOCAL h + + HB_SYMBOL_UNUSED( netiomgm ) + + /* QUESTION: How to find out which connection has sent this RPC request? [vszakats] */ + + IF hb_isHash( hInfo ) .AND. ! Empty( hInfo ) + QQOut( "Management client information:", hb_eol() ) + FOR EACH h IN hInfo + QQOut( h:__enumKey(), h, hb_eol() ) + NEXT + ENDIF + + RETURN NIL + STATIC FUNCTION netio_mgmt_rpc_sysinfo() RETURN {; "OS: " + OS() ,; @@ -300,7 +318,7 @@ STATIC FUNCTION netio_mgmt_rpc_sysinfo() "Memory (KB): " + hb_ntos( Memory( 0 ) ) } STATIC FUNCTION netio_mgmt_rpc_logconn( netiosrv, lValue ) - LOCAL lOldValue := netiosrv[ _NETIOSRV_lAcceptConn ] + LOCAL lOldValue := netiosrv[ _NETIOSRV_lShowConn ] IF hb_isLogical( lValue ) netiosrv[ _NETIOSRV_lShowConn ] := lValue