2011-01-27 01:30 UTC+0100 Viktor Szakats (harbour.01 syenar.hu)
* contrib/hbnetio/utils/netiosrv/netiosrv.prg
* contrib/hbnetio/utils/netiosrv/netiocui.prg
+ Added 'clientinfo <ip:port>' console command. This will
display the self-identification variable sent by the client
to the server on connect. It's fully up to the client what
this info contains. The command works for both normal
and management connections.
+ Added 'adminfo' console command to list management client
connections.
+ Added stream based "cargo" data exchange based on Przemek's
code, purely as an experiment. Cargo data will be shown
in connection lists.
% Optimized out redundant connector code in console UI.
This commit is contained in:
@@ -16,6 +16,21 @@
|
||||
The license applies to all entries newer than 2009-04-28.
|
||||
*/
|
||||
|
||||
2011-01-27 01:30 UTC+0100 Viktor Szakats (harbour.01 syenar.hu)
|
||||
* contrib/hbnetio/utils/netiosrv/netiosrv.prg
|
||||
* contrib/hbnetio/utils/netiosrv/netiocui.prg
|
||||
+ Added 'clientinfo <ip:port>' console command. This will
|
||||
display the self-identification variable sent by the client
|
||||
to the server on connect. It's fully up to the client what
|
||||
this info contains. The command works for both normal
|
||||
and management connections.
|
||||
+ Added 'adminfo' console command to list management client
|
||||
connections.
|
||||
+ Added stream based "cargo" data exchange based on Przemek's
|
||||
code, purely as an experiment. Cargo data will be shown
|
||||
in connection lists.
|
||||
% Optimized out redundant connector code in console UI.
|
||||
|
||||
2011-01-27 00:22 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
|
||||
* harbour/include/hbcompdf.h
|
||||
* harbour/src/compiler/hbmain.c
|
||||
|
||||
@@ -163,20 +163,7 @@ PROCEDURE netiosrv_cmdUI( cIP, nPort, cPassword )
|
||||
LOCAL pConnection
|
||||
|
||||
IF ! Empty( cPassword )
|
||||
|
||||
/* connect to the server */
|
||||
QQOut( "Connecting to server management interface...", hb_eol() )
|
||||
|
||||
pConnection := netio_getconnection( cIP, nPort,, cPassword )
|
||||
cPassword := NIL
|
||||
|
||||
IF Empty( pConnection )
|
||||
QQOut( "Error connecting server.", hb_eol() )
|
||||
ELSE
|
||||
netio_funcexec( pConnection, "hbnetiomgm_sendclientinfo", netiosrv_clientinfo() )
|
||||
QQOut( "Connected.", hb_eol() )
|
||||
ENDIF
|
||||
|
||||
pConnection := ConnectLow( cIP, nPort, cPassword )
|
||||
QQOut( hb_eol() )
|
||||
ENDIF
|
||||
|
||||
@@ -192,12 +179,14 @@ PROCEDURE netiosrv_cmdUI( cIP, nPort, cPassword )
|
||||
"connect" => { "[<ip[:port>]]" , "Connect." , {| cCommand | cmdConnect( cCommand, @pConnection, @cIP, @nPort ) } },;
|
||||
"disconnect" => { "" , "Disconnect." , {|| cmdDisconnect( @pConnection ) } },;
|
||||
"sysinfo" => { "" , "Show system/build information." , {|| cmdSysInfo( pConnection ) } },;
|
||||
"show" => { "" , "Show list of connections." , {|| cmdConnInfo( pConnection ) } },;
|
||||
"show" => { "" , "Show list of connections." , {|| cmdConnInfo( pConnection, .F. ) } },;
|
||||
"showadmin" => { "" , "Show list of management connections." , {|| cmdConnInfo( pConnection, .T. ) } },;
|
||||
"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" => { "[<ip:port>|all]", "Stop specified connection(s)." , {| cCommand | cmdConnStop( pConnection, cCommand ) } },;
|
||||
"clientinfo" => { "[<ip:port>" , "Show client details." , {| cCommand | cmdConnClientInfo( pConnection, cCommand ) } },;
|
||||
"quit" => { "" , "Stop server and exit console." , {|| cmdShutdown( pConnection ), lQuit := .T. } },;
|
||||
"help" => { "" , "Display this help." , {|| cmdHelp( hCommands ) } } }
|
||||
|
||||
@@ -292,6 +281,27 @@ PROCEDURE netiosrv_cmdUI( cIP, nPort, cPassword )
|
||||
|
||||
RETURN
|
||||
|
||||
/* connect to the server */
|
||||
STATIC FUNCTION ConnectLow( cIP, nPort, cPassword )
|
||||
LOCAL pConnection
|
||||
|
||||
QQOut( hb_StrFormat( "Connecting to hbnetio server management at %1$s:%2$d...", cIP, nPort ), hb_eol() )
|
||||
|
||||
pConnection := netio_getconnection( cIP, nPort,, cPassword )
|
||||
cPassword := NIL
|
||||
|
||||
IF ! Empty( pConnection )
|
||||
|
||||
netio_funcexec( pConnection, "hbnetiomgm_setclientinfo", netiosrv_clientinfo() )
|
||||
netio_OpenItemStream( pConnection, "hbnetiomgm_cargo", "netiocui" )
|
||||
|
||||
QQOut( "Connected.", hb_eol() )
|
||||
ELSE
|
||||
QQOut( "Error connecting server.", hb_eol() )
|
||||
ENDIF
|
||||
|
||||
RETURN pConnection
|
||||
|
||||
STATIC FUNCTION GetPassword()
|
||||
LOCAL GetList := {}
|
||||
LOCAL cPassword := Space( 128 )
|
||||
@@ -358,6 +368,61 @@ STATIC PROCEDURE IPPortSplit( cAddr, /* @ */ cIP, /* @ */ nPort )
|
||||
|
||||
RETURN
|
||||
|
||||
STATIC FUNCTION XToStrX( xValue )
|
||||
LOCAL cType := ValType( xValue )
|
||||
|
||||
LOCAL tmp
|
||||
LOCAL cRetVal
|
||||
|
||||
SWITCH cType
|
||||
CASE "C"
|
||||
|
||||
xValue := StrTran( xValue, Chr( 0 ), '" + Chr( 0 ) + "' )
|
||||
xValue := StrTran( xValue, Chr( 9 ), '" + Chr( 9 ) + "' )
|
||||
xValue := StrTran( xValue, Chr( 10 ), '" + Chr( 10 ) + "' )
|
||||
xValue := StrTran( xValue, Chr( 13 ), '" + Chr( 13 ) + "' )
|
||||
xValue := StrTran( xValue, Chr( 26 ), '" + Chr( 26 ) + "' )
|
||||
|
||||
RETURN xValue
|
||||
|
||||
CASE "N" ; RETURN hb_ntos( xValue )
|
||||
CASE "D" ; RETURN DToC( xValue )
|
||||
CASE "T" ; RETURN hb_TToC( xValue )
|
||||
CASE "L" ; RETURN iif( xValue, ".T.", ".F." )
|
||||
CASE "O" ; RETURN xValue:className() + " Object"
|
||||
CASE "U" ; RETURN "NIL"
|
||||
CASE "B" ; RETURN '{||...} -> ' + XToStrX( Eval( xValue ) )
|
||||
CASE "A"
|
||||
|
||||
cRetVal := '{ '
|
||||
|
||||
FOR EACH tmp IN xValue
|
||||
cRetVal += XToStrX( tmp )
|
||||
IF tmp:__enumIndex() < Len( tmp:__enumBase() )
|
||||
cRetVal += ", "
|
||||
ENDIF
|
||||
NEXT
|
||||
|
||||
RETURN cRetVal + ' }'
|
||||
|
||||
CASE "H"
|
||||
|
||||
cRetVal := '{ '
|
||||
|
||||
FOR EACH tmp IN xValue
|
||||
cRetVal += tmp:__enumKey() + " => " + XToStrX( tmp )
|
||||
IF tmp:__enumIndex() < Len( tmp:__enumBase() )
|
||||
cRetVal += ", "
|
||||
ENDIF
|
||||
NEXT
|
||||
|
||||
RETURN cRetVal + ' }'
|
||||
|
||||
CASE "M" ; RETURN 'M:' + xValue
|
||||
ENDSWITCH
|
||||
|
||||
RETURN ""
|
||||
|
||||
/* Commands */
|
||||
|
||||
STATIC PROCEDURE cmdConnect( cCommand, /* @ */ pConnection, /* @ */ cIP, /* @ */ nPort )
|
||||
@@ -380,19 +445,7 @@ STATIC PROCEDURE cmdConnect( cCommand, /* @ */ pConnection, /* @ */ cIP, /* @ */
|
||||
cPassword := GetPassword()
|
||||
ENDIF
|
||||
|
||||
QQOut( hb_StrFormat( "Connecting to hbnetio server management at %1$s:%2$d...", cIP, nPort ), hb_eol() )
|
||||
|
||||
pConnection := netio_getconnection( cIP, nPort,, cPassword )
|
||||
cPassword := NIL
|
||||
|
||||
IF ! Empty( pConnection )
|
||||
|
||||
netio_funcexec( pConnection, "hbnetiomgm_sendclientinfo", netiosrv_clientinfo() )
|
||||
|
||||
QQOut( "Connected.", hb_eol() )
|
||||
ELSE
|
||||
QQOut( "Error connecting server.", hb_eol() )
|
||||
ENDIF
|
||||
pConnection := ConnectLow( cIP, nPort, cPassword )
|
||||
ELSE
|
||||
QQOut( "Already connected. Disconnect first.", hb_eol() )
|
||||
ENDIF
|
||||
@@ -438,14 +491,36 @@ STATIC PROCEDURE cmdConnStop( pConnection, cCommand )
|
||||
|
||||
RETURN
|
||||
|
||||
STATIC PROCEDURE cmdConnInfo( pConnection )
|
||||
STATIC PROCEDURE cmdConnClientInfo( pConnection, cCommand )
|
||||
LOCAL aToken
|
||||
LOCAL xCargo
|
||||
|
||||
IF Empty( pConnection )
|
||||
QQOut( "Not connected.", hb_eol() )
|
||||
ELSE
|
||||
aToken := hb_ATokens( cCommand, " " )
|
||||
IF Len( aToken ) > 1
|
||||
xCargo := netio_funcexec( pConnection, "hbnetiomgm_clientinfo", aToken[ 2 ] )
|
||||
IF xCargo == NIL
|
||||
QQOut( "No information", hb_eol() )
|
||||
ELSE
|
||||
QQOut( XToStrX( xCargo ), hb_eol() )
|
||||
ENDIF
|
||||
ELSE
|
||||
QQOut( "Error: Invalid syntax.", hb_eol() )
|
||||
ENDIF
|
||||
ENDIF
|
||||
|
||||
RETURN
|
||||
|
||||
STATIC PROCEDURE cmdConnInfo( pConnection, lManagement )
|
||||
LOCAL aArray
|
||||
LOCAL hConn
|
||||
|
||||
IF Empty( pConnection )
|
||||
QQOut( "Not connected.", hb_eol() )
|
||||
ELSE
|
||||
aArray := netio_funcexec( pConnection, "hbnetiomgm_conninfo" )
|
||||
aArray := netio_funcexec( pConnection, iif( lManagement, "hbnetiomgm_adminfo", "hbnetiomgm_conninfo" ) )
|
||||
|
||||
QQOut( "Number of connections: " + hb_ntos( Len( aArray ) ), hb_eol() )
|
||||
|
||||
@@ -456,7 +531,8 @@ STATIC PROCEDURE cmdConnInfo( pConnection )
|
||||
"fcnt: " + Str( hConn[ "nFilesCount" ] ) + " " +;
|
||||
"send: " + Str( hConn[ "nBytesSent" ] ) + " " +;
|
||||
"recv: " + Str( hConn[ "nBytesReceived" ] ) + " " +;
|
||||
hConn[ "cAddressPeer" ], hb_eol() )
|
||||
hConn[ "cAddressPeer" ] + " " +;
|
||||
iif( "xCargo" $ hconn, hb_ValToStr( hConn[ "xCargo" ] ), "" ), hb_eol() )
|
||||
NEXT
|
||||
ENDIF
|
||||
|
||||
|
||||
@@ -195,15 +195,18 @@ PROCEDURE Main( ... )
|
||||
netiomgm[ _NETIOSRV_cIFAddr ],;
|
||||
NIL,;
|
||||
{ "hbnetiomgm_ping" => {| ... | .T. } ,;
|
||||
"hbnetiomgm_sendclientinfo" => {| ... | netiomgm_rpc_clientinfo( netiomgm, ... ) } ,;
|
||||
"hbnetiomgm_setclientinfo" => {| ... | netiomgm_rpc_setclientinfo( netiomgm, ... ) } ,;
|
||||
"hbnetiomgm_sysinfo" => {| ... | netiomgm_rpc_sysinfo() } ,;
|
||||
"hbnetiomgm_clientinfo" => {| ... | netiomgm_rpc_clientinfo( netiosrv, netiomgm, ... ) } ,;
|
||||
"hbnetiomgm_shutdown" => {| ... | netiomgm_rpc_shutdown( netiosrv ) } ,;
|
||||
"hbnetiomgm_conninfo" => {| ... | netiomgm_rpc_conninfo( netiosrv ) } ,;
|
||||
"hbnetiomgm_adminfo" => {| ... | netiomgm_rpc_conninfo( netiomgm ) } ,;
|
||||
"hbnetiomgm_stop" => {| ... | netiomgm_rpc_stop( netiosrv, ... ) } ,;
|
||||
"hbnetiomgm_conn" => {| ... | netiomgm_rpc_conn( netiosrv, .T. ) } ,;
|
||||
"hbnetiomgm_noconn" => {| ... | netiomgm_rpc_conn( netiosrv, .F. ) } ,;
|
||||
"hbnetiomgm_logconn" => {| ... | netiomgm_rpc_logconn( netiosrv, .T. ) } ,;
|
||||
"hbnetiomgm_nologconn" => {| ... | netiomgm_rpc_logconn( netiosrv, .F. ) } },;
|
||||
"hbnetiomgm_nologconn" => {| ... | netiomgm_rpc_logconn( netiosrv, .F. ) } ,;
|
||||
"hbnetiomgm_cargo" => {| ... | netiomgm_rpc_cargo( ... ) } },;
|
||||
cPasswordManagement,;
|
||||
NIL,;
|
||||
NIL,;
|
||||
@@ -303,23 +306,34 @@ STATIC PROCEDURE netiosrv_conn_unregister( netiosrv, pConnectionSocket )
|
||||
|
||||
/* RPC management interface */
|
||||
|
||||
STATIC FUNCTION netiomgm_rpc_clientinfo( netiosrv, hInfo )
|
||||
STATIC FUNCTION netiomgm_rpc_cargo( pConnSock, nStreamID, xCargo )
|
||||
STATIC s_hCargo := { => }
|
||||
|
||||
LOCAL index := hb_valToStr( pConnSock )
|
||||
|
||||
HB_SYMBOL_UNUSED( nStreamID )
|
||||
|
||||
SWITCH PCount()
|
||||
CASE 1
|
||||
RETURN iif( index $ s_hCargo, s_hCargo[ index ], NIL )
|
||||
CASE 3
|
||||
IF xCargo == NIL
|
||||
IF index $ s_hCargo
|
||||
hb_HDel( s_hCargo, index )
|
||||
ENDIF
|
||||
ELSE
|
||||
s_hCargo[ index ] := xCargo
|
||||
ENDIF
|
||||
RETURN -1
|
||||
ENDSWITCH
|
||||
|
||||
RETURN NIL
|
||||
|
||||
STATIC FUNCTION netiomgm_rpc_setclientinfo( netiosrv, hInfo )
|
||||
LOCAL nconn
|
||||
#if 0
|
||||
LOCAL h
|
||||
#endif
|
||||
|
||||
IF hb_isHash( hInfo )
|
||||
|
||||
#if 0
|
||||
IF ! Empty( hInfo )
|
||||
QQOut( "Management client information:", hb_eol() )
|
||||
FOR EACH h IN hInfo
|
||||
QQOut( h:__enumKey(), h, hb_eol() )
|
||||
NEXT
|
||||
ENDIF
|
||||
#endif
|
||||
|
||||
hb_mutexLock( netiosrv[ _NETIOSRV_mtxConnection ] )
|
||||
|
||||
FOR EACH nconn IN netiosrv[ _NETIOSRV_hConnection ]
|
||||
@@ -387,6 +401,54 @@ STATIC FUNCTION netiomgm_rpc_stop( netiosrv, cIPPort )
|
||||
|
||||
RETURN .F.
|
||||
|
||||
STATIC FUNCTION netiomgm_rpc_clientinfo( netiosrv, netiomgm, cIPPort )
|
||||
LOCAL nconn
|
||||
LOCAL aAddressPeer
|
||||
LOCAL xCargo := NIL
|
||||
LOCAL lDone
|
||||
|
||||
IF hb_isString( cIPPort )
|
||||
|
||||
cIPPort := Lower( cIPPort )
|
||||
|
||||
lDone := .F.
|
||||
|
||||
IF ! lDone
|
||||
hb_mutexLock( netiosrv[ _NETIOSRV_mtxConnection ] )
|
||||
FOR EACH nconn IN netiosrv[ _NETIOSRV_hConnection ]
|
||||
|
||||
aAddressPeer := NIL
|
||||
netio_srvStatus( nconn[ _NETIOSRV_CONN_pConnection ], NETIO_SRVINFO_PEERADDRESS, @aAddressPeer )
|
||||
|
||||
IF cIPPort == AddrToIPPort( aAddressPeer )
|
||||
// xCargo := netiomgm_rpc_cargo( nconn[ _NETIOSRV_CONN_pConnection ] )
|
||||
xCargo := nconn[ _NETIOSRV_CONN_hInfo ]
|
||||
lDone := .T.
|
||||
EXIT
|
||||
ENDIF
|
||||
NEXT
|
||||
hb_mutexUnlock( netiosrv[ _NETIOSRV_mtxConnection ] )
|
||||
ENDIF
|
||||
|
||||
IF ! lDone
|
||||
hb_mutexLock( netiomgm[ _NETIOSRV_mtxConnection ] )
|
||||
FOR EACH nconn IN netiomgm[ _NETIOSRV_hConnection ]
|
||||
|
||||
aAddressPeer := NIL
|
||||
netio_srvStatus( nconn[ _NETIOSRV_CONN_pConnection ], NETIO_SRVINFO_PEERADDRESS, @aAddressPeer )
|
||||
|
||||
IF cIPPort == AddrToIPPort( aAddressPeer )
|
||||
// xCargo := netiomgm_rpc_cargo( nconn[ _NETIOSRV_CONN_pConnection ] )
|
||||
xCargo := nconn[ _NETIOSRV_CONN_hInfo ]
|
||||
EXIT
|
||||
ENDIF
|
||||
NEXT
|
||||
hb_mutexUnlock( netiomgm[ _NETIOSRV_mtxConnection ] )
|
||||
ENDIF
|
||||
ENDIF
|
||||
|
||||
RETURN xCargo
|
||||
|
||||
STATIC FUNCTION netiomgm_rpc_shutdown( netiosrv )
|
||||
|
||||
QQOut( "Shutdown initiated...", hb_eol() )
|
||||
@@ -428,7 +490,8 @@ STATIC FUNCTION netiomgm_rpc_conninfo( netiosrv )
|
||||
"nFilesCount" => nFilesCount,;
|
||||
"nBytesSent" => nBytesSent,;
|
||||
"nBytesReceived" => nBytesReceived,;
|
||||
"cAddressPeer" => AddrToIPPort( aAddressPeer ) } )
|
||||
"cAddressPeer" => AddrToIPPort( aAddressPeer ),;
|
||||
"xCargo" => netiomgm_rpc_cargo( nconn[ _NETIOSRV_CONN_pConnection ] ) } )
|
||||
NEXT
|
||||
|
||||
hb_mutexUnlock( netiosrv[ _NETIOSRV_mtxConnection ] )
|
||||
|
||||
Reference in New Issue
Block a user