From f2c01933de7f611427d05a0b474f94bee83c7168 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 9 Jul 2009 13:21:43 +0000 Subject: [PATCH] 2009-07-09 15:18 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbtip/utils.c - contrib/hbtip/base64x.c * contrib/hbtip/client.prg * contrib/hbtip/smtpcln.prg * contrib/hbtip/Makefile * contrib/hbvpdf/hbvpsup.prg * Using core BASE64 functions. ; Left HB_BASE64() as compatibility call in hbtip. * contrib/hbwin/wapi_winuser.c + Added WAPI_GETDESKTOPWINDOW(). --- harbour/ChangeLog | 13 ++++ harbour/contrib/hbtip/Makefile | 1 - harbour/contrib/hbtip/base64x.c | 100 --------------------------- harbour/contrib/hbtip/client.prg | 2 +- harbour/contrib/hbtip/smtpcln.prg | 6 +- harbour/contrib/hbtip/utils.c | 7 ++ harbour/contrib/hbvpdf/hbvpsup.prg | 73 +------------------ harbour/contrib/hbwin/wapi_winuser.c | 5 ++ 8 files changed, 30 insertions(+), 177 deletions(-) delete mode 100644 harbour/contrib/hbtip/base64x.c diff --git a/harbour/ChangeLog b/harbour/ChangeLog index aef961f13e..7ac2d1e801 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,19 @@ past entries belonging to author(s): Viktor Szakats. */ +2009-07-09 15:18 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) + * contrib/hbtip/utils.c + - contrib/hbtip/base64x.c + * contrib/hbtip/client.prg + * contrib/hbtip/smtpcln.prg + * contrib/hbtip/Makefile + * contrib/hbvpdf/hbvpsup.prg + * Using core BASE64 functions. + ; Left HB_BASE64() as compatibility call in hbtip. + + * contrib/hbwin/wapi_winuser.c + + Added WAPI_GETDESKTOPWINDOW(). + 2009-07-09 14:58 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * include/hbextern.ch * source/rtl/Makefile diff --git a/harbour/contrib/hbtip/Makefile b/harbour/contrib/hbtip/Makefile index 98145e5a6a..12b8aac5e0 100644 --- a/harbour/contrib/hbtip/Makefile +++ b/harbour/contrib/hbtip/Makefile @@ -9,7 +9,6 @@ LIBNAME=hbtip ifneq ($(HB_ARCHITECTURE),dos) C_SOURCES = \ - base64x.c \ encmthd.c \ utils.c \ diff --git a/harbour/contrib/hbtip/base64x.c b/harbour/contrib/hbtip/base64x.c deleted file mode 100644 index 82cbd051e0..0000000000 --- a/harbour/contrib/hbtip/base64x.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - * $Id$ - */ - -/* - * xHarbour Project source code: - * TIP Class oriented Internet protocol library - * - * Copyright 2003 Giancarlo Niccolai - * www - http://www.harbour-project.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this software; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). - * - * As a special exception, the Harbour Project gives permission for - * additional uses of the text contained in its release of Harbour. - * - * The exception is that, if you link the Harbour libraries with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the Harbour library code into it. - * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. - * - * This exception applies only to the code released by the Harbour - * Project under the name Harbour. If you copy code from other - * Harbour Project or Free Software Foundation releases into a copy of - * Harbour, as the General Public License permits, the exception does - * not apply to the code that you add in this way. To avoid misleading - * anyone as to the status of such modified files, you must delete - * this exception notice from them. - * - * If you write modifications of your own for Harbour, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. - * - */ - -#include "hbapi.h" - -HB_FUNC( HB_BASE64 ) -{ - ULONG len = hb_parclen( 1 ); - - if( len <= INT_MAX ) /* TOFIX */ - { - const char * s = hb_parcx( 1 ); - char * t, * p; - - t = p = ( char * ) hb_xgrab( ( 4 * ( ( len + 2 ) / 3 ) + 1 ) * sizeof( *t ) ); - - while( len-- > 0 ) - { - static const char s_b64chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - int x, y; - - x = *s++; - *p++ = s_b64chars[ ( x >> 2 ) & 0x3F ]; - - if( len-- <= 0 ) - { - *p++ = s_b64chars[ ( x << 4 ) & 0x3F ]; - *p++ = '='; - *p++ = '='; - break; - } - y = *s++; - *p++ = s_b64chars[ ( ( x << 4 ) | ( ( y >> 4 ) & 0x0F ) ) & 0x3F ]; - - if( len-- <= 0 ) - { - *p++ = s_b64chars[ ( y << 2 ) & 0x3F ]; - *p++ = '='; - break; - } - x = *s++; - *p++ = s_b64chars[ ( ( y << 2 ) | ( ( x >> 6 ) & 3 ) ) & 0x3F ]; - *p++ = s_b64chars[ x & 0x3F ]; - } - *p = '\0'; - - hb_retc_buffer( t ); - } - else - hb_retc_null(); -} diff --git a/harbour/contrib/hbtip/client.prg b/harbour/contrib/hbtip/client.prg index 12bd750452..1a4859cd91 100644 --- a/harbour/contrib/hbtip/client.prg +++ b/harbour/contrib/hbtip/client.prg @@ -252,7 +252,7 @@ METHOD OpenProxy( cServer, nPort, cProxy, nProxyPort, cResp, cUserName, cPassWor cRequest += "User-agent: " + cUserAgent + Chr( 13 ) + Chr( 10 ) ENDIF IF ! Empty( cUserName ) - cRequest += "Proxy-authorization: Basic " + hb_base64( cUserName + ":" + cPassWord ) + Chr( 13 ) + Chr( 10 ) + cRequest += "Proxy-authorization: Basic " + hb_base64Encode( cUserName + ":" + cPassWord ) + Chr( 13 ) + Chr( 10 ) ENDIF cRequest += Chr( 13 ) + Chr( 10 ) ::InetSendAll( ::SocketCon, cRequest ) diff --git a/harbour/contrib/hbtip/smtpcln.prg b/harbour/contrib/hbtip/smtpcln.prg index 24dabbb9dc..4685df95df 100644 --- a/harbour/contrib/hbtip/smtpcln.prg +++ b/harbour/contrib/hbtip/smtpcln.prg @@ -177,9 +177,9 @@ METHOD Auth( cUser, cPass ) CLASS tIPClientSMTP ::InetSendall( ::SocketCon, "AUTH LOGIN" + ::cCRLF ) IF ::GetOk() - ::InetSendall( ::SocketCon, hb_BASE64( StrTran( cUser, "&at;", "@" ) ) + ::cCRLF ) + ::InetSendall( ::SocketCon, hb_base64Encode( StrTran( cUser, "&at;", "@" ) ) + ::cCRLF ) IF ::GetOk() - ::InetSendall( ::SocketCon, hb_BASE64( cPass ) + ::cCRLF ) + ::InetSendall( ::SocketCon, hb_base64Encode( cPass ) + ::cCRLF ) ENDIF ENDIF @@ -187,7 +187,7 @@ METHOD Auth( cUser, cPass ) CLASS tIPClientSMTP METHOD AuthPlain( cUser, cPass ) CLASS tIPClientSMTP - ::InetSendall( ::SocketCon, "AUTH PLAIN" + hb_BASE64( Chr( 0 ) + cUser + Chr( 0 ) + cPass ) + ::cCRLF ) + ::InetSendall( ::SocketCon, "AUTH PLAIN" + hb_base64Encode( Chr( 0 ) + cUser + Chr( 0 ) + cPass ) + ::cCRLF ) RETURN ::isAuth := ::GetOk() diff --git a/harbour/contrib/hbtip/utils.c b/harbour/contrib/hbtip/utils.c index 3b46d2d7a5..839602445e 100644 --- a/harbour/contrib/hbtip/utils.c +++ b/harbour/contrib/hbtip/utils.c @@ -737,3 +737,10 @@ HB_FUNC( TIP_HTMLSPECIALCHARS ) else hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, 1, hb_paramError(1) ); } + +HB_FUNC_EXTERN( HB_BASE64ENCODE ); + +HB_FUNC( HB_BASE64 ) +{ + HB_FUNC_EXEC( HB_BASE64ENCODE ); +} diff --git a/harbour/contrib/hbvpdf/hbvpsup.prg b/harbour/contrib/hbvpdf/hbvpsup.prg index dc2a6b171f..dd73d6db2f 100644 --- a/harbour/contrib/hbvpdf/hbvpsup.prg +++ b/harbour/contrib/hbvpdf/hbvpsup.prg @@ -3,7 +3,7 @@ */ FUNCTION vpdf_FontsDat() - RETURN StrB64Decode( ; + RETURN hb_base64Decode( ; "+gD6APoA+gBNAU0BTQGFAZgBKwKkASsC9AH0AfQB9AH0AfQB9AH0AUED6ANBA0EDCgNBAwoDCgNN" +; "AU0BTQFNAU0BTQFNAU0BTQFNAU0BTQH0AfQB9AH0ATQCOgKjAjoC+gD6APoA+gBNAU0BTQFNAfoA" +; "+gD6APoAFgEWARYBFgH0AfQB9AH0AfQB9AH0AfQB9AH0AfQB9AH0AfQB9AH0AfQB9AH0AfQB9AH0" +; @@ -99,74 +99,3 @@ FUNCTION vpdf_FontsDat() "WAJYAlgCWAJYAlgCWAJYAlgCWAJYAlgCWAJYAlgCWAJYAlgCWAJYAlgCWAJYAlgCWAJYAlgCWAJY" +; "AlgCWAJYAlgCWAJYAlgCWAJYAlgCWAJYAlgCWAJYAlgCWAJYAlgCWAJYAlgCWAJYAlgCWAJYAlgC" +; "WAJYAlgCWAJYAlgCWAJYAlgC" ) - -// ; Decodes a base-64 encoded string. (RFC1521) -// ; Based on VB code from: 1999-2004 Antonin Foller, http://www.motobit.com, http://motobit.cz -// ; Converted to Clipper and optimized by Viktor Szakats (harbour.01 syenar.hu). - -STATIC FUNCTION StrB64Decode( cString ) - LOCAL cResult - - LOCAL nLen - LOCAL nGroupPos - LOCAL nGroup - LOCAL nCharPos - LOCAL nDataLen - LOCAL nData - - // ; remove white spaces, If any - cString := StrTran( cString, Chr( 10 ), "" ) - cString := StrTran( cString, Chr( 13 ), "" ) - cString := StrTran( cString, Chr( 9 ), "" ) - cString := StrTran( cString, " ", "" ) - - // ; The source must consists from groups with Len of 4 chars - IF ( nLen := Len( cString ) ) % 4 != 0 - RETURN "" // ; Bad Base64 string. - ENDIF - - /* - IF nLen > Int( MAXSTRINGLENGTH / 1.34 ) // ; Base64 is 1/3rd larger than source text. - RETURN "" // ; Not enough memory to decode. - ENDIF - */ - - cResult := "" - - // ; Now decode each group: - FOR nGroupPos := 1 TO nLen STEP 4 - - // ; Each data group encodes up To 3 actual bytes. - nDataLen := 3 - nGroup := 0 - - FOR nCharPos := 0 TO 3 - - // ; Convert each character into 6 bits of data, And add it To - // ; an integer For temporary storage. If a character is a '=', there - // ; is one fewer data byte. (There can only be a maximum of 2 '=' In - // ; the whole string.) - - nData := At( SubStr( cString, nGroupPos + nCharPos, 1 ), "=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" ) - 2 - - DO CASE - CASE nData >= 0 - // ; Do nothing (for speed) - CASE nData == -1 - nData := 0 - nDataLen-- - CASE nData == -2 - RETURN "" // ; Bad character In Base64 string. - ENDCASE - - nGroup := 64 * nGroup + nData - NEXT - - // ; Convert the 24 bits to 3 characters - // ; and add nDataLen characters To out string - cResult += Left( Chr( nGroup / 65536 ) +; // ; bitwise AND 255, which is done by Chr() automatically - Chr( nGroup / 256 ) +; // ; bitwise AND 255, which is done by Chr() automatically - Chr( nGroup ), nDataLen ) // ; bitwise AND 255, which is done by Chr() automatically - NEXT - - RETURN cResult diff --git a/harbour/contrib/hbwin/wapi_winuser.c b/harbour/contrib/hbwin/wapi_winuser.c index 33c68f2a70..4ef9deb02f 100644 --- a/harbour/contrib/hbwin/wapi_winuser.c +++ b/harbour/contrib/hbwin/wapi_winuser.c @@ -59,6 +59,11 @@ #include +HB_FUNC( WAPI_GETDESKTOPWINDOW ) +{ + hb_retptr( GetDesktopWindow() ); +} + HB_FUNC( WAPI_MESSAGEBOX ) { LPTSTR lpStr1 = HB_TCHAR_CONVTO( hb_parcx( 2 ) );