From c079fae074e7e54afa35f7e1633feb058db38747 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Wed, 13 Apr 2011 15:19:45 +0000 Subject: [PATCH] 2011-04-13 17:19 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/contrib/hbnetio/netiosrv.c * harbour/contrib/hbnetio/readme.txt + added new server function: NETIO_VERIFYCLIENT( ) -> By default client verification is done inside NETIO_SERVER() function but some servers may want to verify client password before they execute some expensive initialization code necessary for RPC executed from NETIO_SERVER() --- harbour/ChangeLog | 10 ++++ harbour/contrib/hbnetio/netiosrv.c | 77 ++++++++++++++++++------------ harbour/contrib/hbnetio/readme.txt | 1 + 3 files changed, 57 insertions(+), 31 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index fbcb2a482c..74b7f4a8ff 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,16 @@ The license applies to all entries newer than 2009-04-28. */ +2011-04-13 17:19 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/contrib/hbnetio/netiosrv.c + * harbour/contrib/hbnetio/readme.txt + + added new server function: + NETIO_VERIFYCLIENT( ) -> + By default client verification is done inside NETIO_SERVER() + function but some servers may want to verify client password + before they execute some expensive initialization code necessary + for RPC executed from NETIO_SERVER() + 2011-04-13 14:12 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/src/rtl/cdpapi.c ! fixed U+0000 conversion - it should not be converted. diff --git a/harbour/contrib/hbnetio/netiosrv.c b/harbour/contrib/hbnetio/netiosrv.c index 884c567c71..23c447d9c4 100644 --- a/harbour/contrib/hbnetio/netiosrv.c +++ b/harbour/contrib/hbnetio/netiosrv.c @@ -692,47 +692,62 @@ HB_FUNC( NETIO_COMPRESS ) } } +static HB_BOOL s_netio_login_accept( PHB_CONSRV conn ) +{ + if( conn && conn->sd != HB_NO_SOCKET && !conn->stop && !conn->login ) + { + HB_BYTE msgbuf[ NETIO_MSGLEN ]; + + if( s_srvRecvAll( conn, msgbuf, NETIO_MSGLEN ) == NETIO_MSGLEN && + HB_GET_LE_INT32( msgbuf ) == NETIO_LOGIN ) + { + long len = HB_GET_LE_INT16( &msgbuf[ 4 ] ); + + if( len < ( long ) sizeof( msgbuf ) && + len == ( long ) strlen( NETIO_LOGINSTRID ) && + s_srvRecvAll( conn, msgbuf, len ) == len ) + { + if( memcmp( NETIO_LOGINSTRID, msgbuf, len ) == 0 ) + { + HB_PUT_LE_UINT32( &msgbuf[ 0 ], NETIO_LOGIN ); + HB_PUT_LE_UINT32( &msgbuf[ 4 ], NETIO_CONNECTED ); + memset( msgbuf + 8, '\0', NETIO_MSGLEN - 8 ); + if( s_srvSendAll( conn, msgbuf, NETIO_MSGLEN ) == NETIO_MSGLEN ) + conn->login = HB_TRUE; + } + } + } + if( !conn->login ) + s_consrv_disconnect( conn ); + } + + return conn->login; +} + +/* NETIO_VERIFYCLIENT( ) -> + */ +HB_FUNC( NETIO_VERIFYCLIENT ) +{ + PHB_CONSRV conn = s_consrvParam( 1 ); + if( conn ) + hb_retl( s_netio_login_accept( conn ) ); +} + /* NETIO_SERVER( ) -> NIL */ HB_FUNC( NETIO_SERVER ) { PHB_CONSRV conn = s_consrvParam( 1 ); - /* clear return value if any */ - hb_ret(); - - if( conn && conn->sd != HB_NO_SOCKET && !conn->stop ) + if( s_netio_login_accept( conn ) ) { - HB_BYTE msgbuf[ NETIO_MSGLEN ]; + /* clear return value if any */ + hb_ret(); - if( !conn->login ) - { - if( s_srvRecvAll( conn, msgbuf, NETIO_MSGLEN ) == NETIO_MSGLEN && - HB_GET_LE_INT32( msgbuf ) == NETIO_LOGIN ) - { - long len = HB_GET_LE_INT16( &msgbuf[ 4 ] ); - - if( len < ( long ) sizeof( msgbuf ) && - len == ( long ) strlen( NETIO_LOGINSTRID ) && - s_srvRecvAll( conn, msgbuf, len ) == len ) - { - if( memcmp( NETIO_LOGINSTRID, msgbuf, len ) == 0 ) - { - HB_PUT_LE_UINT32( &msgbuf[ 0 ], NETIO_LOGIN ); - HB_PUT_LE_UINT32( &msgbuf[ 4 ], NETIO_CONNECTED ); - memset( msgbuf + 8, '\0', NETIO_MSGLEN - 8 ); - if( s_srvSendAll( conn, msgbuf, NETIO_MSGLEN ) == NETIO_MSGLEN ) - conn->login = HB_TRUE; - } - } - } - } - - if( !conn->login ) - s_consrv_disconnect( conn ); - else for( ;; ) + for( ;; ) { HB_BYTE buffer[ 2048 ], * ptr = NULL, * msg; + HB_BYTE msgbuf[ NETIO_MSGLEN ]; HB_BOOL fNoAnswer = HB_FALSE; HB_ERRCODE errCode = 0, errFsCode; long len = 0, size, size2; diff --git a/harbour/contrib/hbnetio/readme.txt b/harbour/contrib/hbnetio/readme.txt index 04c1911885..176ac43041 100644 --- a/harbour/contrib/hbnetio/readme.txt +++ b/harbour/contrib/hbnetio/readme.txt @@ -140,6 +140,7 @@ Server side functions: -> | NIL NETIO_COMPRESS( , [], [], [] ) -> NIL + NETIO_VERIFYCLIENT( ) -> NETIO_SERVER( ) -> NIL NETIO_RPC( | [, ] ) -> NETIO_RPCFILTER( ,