2010-01-12 13:08 UTC+0100 Viktor Szakats (harbour.01 syenar.hu)

* contrib/hbnetio/utils/netiosrv.prg
    + Added new parameter parsing allowing to pass options in free
      order in any combination.
This commit is contained in:
Viktor Szakats
2010-01-12 12:08:46 +00:00
parent 1b2dbede47
commit 774bf60b43
2 changed files with 45 additions and 30 deletions

View File

@@ -17,6 +17,11 @@
past entries belonging to author(s): Viktor Szakats.
*/
2010-01-12 13:08 UTC+0100 Viktor Szakats (harbour.01 syenar.hu)
* contrib/hbnetio/utils/netiosrv.prg
+ Added new parameter parsing allowing to pass options in free
order in any combination.
2010-01-12 12:23 UTC+0100 Viktor Szakats (harbour.01 syenar.hu)
* contrib/hbnetio/utils/netiosrv.hbp
+ Now includes hbmk.hbm so that the .hbp file works when

View File

@@ -18,49 +18,59 @@ REQUEST HB_MT
/* enable this if you need all core functions in RPC support */
//REQUEST __HB_EXTERN__
PROCEDURE Main( port, ifaddr, rootdir, rpc, passwd )
PROCEDURE Main( ... )
LOCAL pListenSocket
LOCAL cParam
LOCAL port := 2941
LOCAL ifaddr := "0.0.0.0"
LOCAL rootdir := hb_dirBase()
LOCAL rpc := .F.
LOCAL passwd := NIL
HB_Logo()
port := IIF( Empty( port ), 2941, Val( port ) )
IF Empty( ifaddr )
ifaddr := "0.0.0.0"
ENDIF
IF Empty( rootdir )
rootdir := hb_dirBase()
ENDIF
rpc := !Empty( rpc )
IF !Empty( passwd ) .AND. Len( passwd ) == 0
passwd := NIL
ENDIF
FOR EACH cParam IN hb_AParams()
DO CASE
CASE Lower( Left( cParam, 6 ) ) == "-port="
port := Val( SubStr( cParam, 7 ) )
CASE Lower( Left( cParam, 6 ) ) == "-addr="
ifaddr := SubStr( cParam, 7 )
CASE Lower( Left( cParam, 9 ) ) == "-rootdir="
rootdir := SubStr( cParam, 10 )
CASE Lower( Left( cParam, 6 ) ) == "-pass="
passwd := SubStr( cParam, 7 )
CASE Lower( cParam ) == "-rpc"
rpc := .T.
CASE Lower( cParam ) == "-help" .OR. ;
Lower( cParam ) == "--help"
HB_Usage()
RETURN
ENDCASE
NEXT
IF port == 0
HB_Usage()
pListenSocket := netio_mtserver( port, ifaddr, rootdir, rpc, passwd )
IF Empty( pListenSocket )
OutStd( "Cannot start server." + hb_osNewLine() )
ELSE
pListenSocket := netio_mtserver( port, ifaddr, rootdir, rpc, passwd )
IF Empty( pListenSocket )
OutStd( "Cannot start server." + hb_osNewLine() )
ELSE
OutStd( "Listening on: " + ifaddr + ":" + hb_ntos( port ) + hb_osNewLine() )
OutStd( "Root filesystem: " + rootdir + hb_osNewLine() )
OutStd( "RPC support: " + iif( rpc, "enabled", "disabled" ) + hb_osNewLine() )
OutStd( "Encryption: " + iif( passwd != NIL, "enabled", "disabled" ) + hb_osNewLine() )
OutStd( "Listening on: " + ifaddr + ":" + hb_ntos( port ) + hb_osNewLine() )
OutStd( "Root filesystem: " + rootdir + hb_osNewLine() )
OutStd( "RPC support: " + iif( rpc, "enabled", "disabled" ) + hb_osNewLine() )
OutStd( "Encryption: " + iif( passwd != NIL, "enabled", "disabled" ) + hb_osNewLine() )
OutStd( hb_osNewLine() )
OutStd( "Press any key to stop NETIO server." + hb_osNewLine() )
Inkey( 0 )
OutStd( hb_osNewLine() )
OutStd( "Press any key to stop NETIO server." + hb_osNewLine() )
Inkey( 0 )
netio_serverstop( pListenSocket )
pListenSocket := NIL
ENDIF
netio_serverstop( pListenSocket )
pListenSocket := NIL
ENDIF
RETURN
STATIC PROCEDURE HB_Logo()
OutStd( 'Harbour NETIO Server ' + HBRawVersion() + hb_osNewLine() +;
OutStd( "Harbour NETIO Server " + HBRawVersion() + hb_osNewLine() +;
"Copyright (c) 2009, Przemyslaw Czerpak" + hb_osNewLine() + ;
"http://www.harbour-project.org/" + hb_osNewLine() +;
hb_osNewLine() )
@@ -69,7 +79,7 @@ STATIC PROCEDURE HB_Logo()
STATIC PROCEDURE HB_Usage()
OutStd( "Syntax: netiosrv [<port>] [<inetaddr>] [<rootdir>] [<rpc>] [<passwd>]" + hb_osNewLine() )
OutStd( "Syntax: netiosrv [-port=<port>] [-addr=<inetaddr>] [-rootdir=<rootdir>] [-rpc] [-pass=<passwd>]" + hb_osNewLine() )
RETURN