diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 10a2d3a136..1c325c22d8 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,31 @@ The license applies to all entries newer than 2009-04-28. */ +2011-08-12 17:53 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) + * contrib/hbtip/sendmail.prg + * contrib/hbtip/httpcli.prg + * contrib/hbtip/smtpcli.prg + * contrib/hbtip/client.prg + * contrib/hbtip/log.prg + * contrib/hbtip/ftpcli.prg + * contrib/hbtip/popcli.prg + + allowing to pass custom tracelog filename to TIPCLIENT*:New() + % moved tracelog initialization from subclasses to TIPCLIENT class + + added TIPLOG:Clear() method + - deleted TIPCLIENTFTP:StartCleanLogFile() and + TIPCLIENTFTP:cLogFile because they're not compatible + with the generic logging solution implemented now, ie. + they wouldn't work when using custom tracelog block and + would require additional changes into the wrong direction + to implement fully. In current form, it was also broken, + creating an RTE. For similar functionality a custom codeblock + can be used together with TIPLOG:Clear() method, and this + can be used with all TIPCLIENT* classes. + * minor formatting and renamed bTrace to xTrace + ; Thanks to Klas Engwall for raising and walking through these + issues. + ; Please test and tell if anything is broken + 2011-08-12 02:46 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * package/winuni/mpkg_win_uni.bat ! added workaround for what it seems like a BCC IMPLIB tool diff --git a/harbour/contrib/hbtip/client.prg b/harbour/contrib/hbtip/client.prg index add0a876c3..d95f6aad15 100644 --- a/harbour/contrib/hbtip/client.prg +++ b/harbour/contrib/hbtip/client.prg @@ -135,7 +135,7 @@ CREATE CLASS tIPClient VAR cProxyUser VAR cProxyPassword - METHOD New( oUrl, bTrace, oCredentials ) + METHOD New( oUrl, xTrace, oCredentials ) METHOD Open( cUrl ) METHOD EnableTLS( lEnable ) @@ -181,8 +181,9 @@ CREATE CLASS tIPClient ENDCLASS -METHOD New( oUrl, bTrace, oCredentials ) CLASS tIPClient +METHOD New( oUrl, xTrace, oCredentials ) CLASS tIPClient LOCAL oErr + LOCAL oLog LOCAL aProtoAccepted := { "ftp", "http", "pop", "smtp" } #if defined( HB_HAS_OPENSSL ) @@ -191,6 +192,14 @@ METHOD New( oUrl, bTrace, oCredentials ) CLASS tIPClient LOCAL aProtoAcceptedSSL := {} #endif + IF ISCHARACTER( xTrace ) .OR. ; + ( ISLOGICAL( xTrace ) .AND. xTrace ) + oLog := tIPLog():New( iif( ISCHARACTER( xTrace ), xTrace, NIL ) ) + ::bTrace := {| cMsg | iif( PCount() > 0, oLog:Add( cMsg ), oLog:Close() ) } + ELSEIF ISBLOCK( xTrace ) + ::bTrace := xTrace + ENDIF + IF ISCHARACTER( oUrl ) oUrl := tUrl():New( oUrl ) ENDIF @@ -232,7 +241,6 @@ METHOD New( oUrl, bTrace, oCredentials ) CLASS tIPClient ::oUrl := oUrl ::oCredentials := oCredentials - ::bTrace := bTrace RETURN self diff --git a/harbour/contrib/hbtip/ftpcli.prg b/harbour/contrib/hbtip/ftpcli.prg index 522983b04a..c816af132d 100644 --- a/harbour/contrib/hbtip/ftpcli.prg +++ b/harbour/contrib/hbtip/ftpcli.prg @@ -110,9 +110,8 @@ CREATE CLASS tIPClientFTP FROM tIPClient // Socket opened in response to a port command VAR SocketControl VAR SocketPortServer - VAR cLogFile - METHOD New( oUrl, bTrace, oCredentials ) + METHOD New( oUrl, xTrace, oCredentials ) METHOD Open( cUrl ) METHOD Read( nLen ) METHOD Write( cData, nLen ) @@ -151,21 +150,13 @@ CREATE CLASS tIPClientFTP FROM tIPClient METHOD RMD( cPath ) METHOD listFiles( cFileSpec ) METHOD MPut - METHOD StartCleanLogFile() METHOD fileSize( cFileSpec ) ENDCLASS -METHOD New( oUrl, bTrace, oCredentials ) CLASS tIPClientFTP +METHOD New( oUrl, xTrace, oCredentials ) CLASS tIPClientFTP - LOCAL oLog - - IF ISLOGICAL( bTrace ) .AND. bTrace - oLog := tIPLog():New( "ftp" ) - bTrace := {| cMsg | iif( PCount() > 0, oLog:Add( cMsg ), oLog:Close() ) } - ENDIF - - ::super:new( oUrl, bTrace, oCredentials ) + ::super:new( oUrl, iif( ISLOGICAL( xTrace ) .AND. xTrace, "ftp", xTrace ), oCredentials ) ::nDefaultPort := 21 ::nConnTimeout := 3000 @@ -180,11 +171,6 @@ METHOD New( oUrl, bTrace, oCredentials ) CLASS tIPClientFTP RETURN Self -METHOD StartCleanLogFile() CLASS tIPClientFTP - FClose( ::nHandle ) - ::nHandle := FCreate( ::cLogFile ) - RETURN NIL - METHOD Open( cUrl ) CLASS tIPClientFTP IF hb_isString( cUrl ) @@ -792,44 +778,51 @@ METHOD listFiles( cFileSpec ) CLASS tIPClientFTP nStart := nEnd // # of links - DO WHILE SubStr( cEntry, ++nStart, 1 ) == " " ; ENDDO + DO WHILE SubStr( cEntry, ++nStart, 1 ) == " " + ENDDO nEnd := hb_At( " ", cEntry, nStart ) aFile[ F_LEN + 1 ] := Val( SubStr( cEntry, nStart, nEnd - nStart ) ) nStart := nEnd // owner name - DO WHILE SubStr( cEntry, ++nStart, 1 ) == " " ; ENDDO + DO WHILE SubStr( cEntry, ++nStart, 1 ) == " " + ENDDO nEnd := hb_At( " ", cEntry, nStart ) aFile[ F_LEN + 2 ] := SubStr( cEntry, nStart, nEnd - nStart ) nStart := nEnd // group name - DO WHILE SubStr( cEntry, ++nStart, 1 ) == " " ; ENDDO + DO WHILE SubStr( cEntry, ++nStart, 1 ) == " " + ENDDO nEnd := hb_At( " ", cEntry, nStart ) aFile[ F_LEN + 3 ] := SubStr( cEntry, nStart, nEnd - nStart ) nStart := nEnd // file size - DO WHILE SubStr( cEntry, ++nStart, 1 ) == " " ; ENDDO + DO WHILE SubStr( cEntry, ++nStart, 1 ) == " " + ENDDO nEnd := hb_At( " ", cEntry, nStart ) aFile[ F_SIZE ] := Val( SubStr( cEntry, nStart, nEnd - nStart ) ) nStart := nEnd // Month - DO WHILE SubStr( cEntry, ++nStart, 1 ) == " " ; ENDDO + DO WHILE SubStr( cEntry, ++nStart, 1 ) == " " + ENDDO nEnd := hb_At( " ", cEntry, nStart ) cMonth := SubStr( cEntry, nStart, nEnd - nStart ) cMonth := PadL( AScan( aMonth, cMonth ), 2, "0" ) nStart := nEnd // Day - DO WHILE SubStr( cEntry, ++nStart, 1 ) == " " ; ENDDO + DO WHILE SubStr( cEntry, ++nStart, 1 ) == " " + ENDDO nEnd := hb_At( " ", cEntry, nStart ) cDay := SubStr( cEntry, nStart, nEnd - nStart ) nStart := nEnd // year - DO WHILE SubStr( cEntry, ++nStart, 1 ) == " " ; ENDDO + DO WHILE SubStr( cEntry, ++nStart, 1 ) == " " + ENDDO nEnd := hb_At( " ", cEntry, nStart ) cYear := SubStr( cEntry, nStart, nEnd - nStart ) nStart := nEnd @@ -842,7 +835,8 @@ METHOD listFiles( cFileSpec ) CLASS tIPClientFTP ENDIF // file name - DO WHILE SubStr( cEntry, ++nStart, 1 ) == " " ; ENDDO + DO WHILE SubStr( cEntry, ++nStart, 1 ) == " " + ENDDO aFile[ F_NAME ] := SubStr( cEntry, nStart ) aFile[ F_DATE ] := hb_SToD( cYear + cMonth + cDay ) diff --git a/harbour/contrib/hbtip/httpcli.prg b/harbour/contrib/hbtip/httpcli.prg index 1957fb3278..46fe11dc7e 100644 --- a/harbour/contrib/hbtip/httpcli.prg +++ b/harbour/contrib/hbtip/httpcli.prg @@ -71,7 +71,7 @@ CREATE CLASS tIPClientHTTP FROM tIPClient VAR cBoundary VAR aAttachments INIT {} - METHOD New( oUrl, bTrace, oCredentials ) + METHOD New( oUrl, xTrace, oCredentials ) METHOD Get( cQuery ) METHOD Post( xPostData, cQuery ) METHOD ReadHeaders( lClear ) @@ -91,16 +91,9 @@ CREATE CLASS tIPClientHTTP FROM tIPClient ENDCLASS -METHOD New( oUrl, bTrace, oCredentials ) CLASS tIPClientHTTP +METHOD New( oUrl, xTrace, oCredentials ) CLASS tIPClientHTTP - LOCAL oLog - - IF ISLOGICAL( bTrace ) .AND. bTrace - oLog := tIPLog():New( "http" ) - bTrace := {| cMsg | iif( PCount() > 0, oLog:Add( cMsg ), oLog:Close() ) } - ENDIF - - ::super:new( oUrl, bTrace, oCredentials ) + ::super:new( oUrl, iif( ISLOGICAL( xTrace ) .AND. xTrace, "http", xTrace ), oCredentials ) ::nDefaultPort := iif( ::oUrl:cProto == "https", 443, 80 ) ::nConnTimeout := 5000 diff --git a/harbour/contrib/hbtip/log.prg b/harbour/contrib/hbtip/log.prg index b4e5d83275..f0daddf7d3 100644 --- a/harbour/contrib/hbtip/log.prg +++ b/harbour/contrib/hbtip/log.prg @@ -60,6 +60,7 @@ CREATE CLASS TIPLOG METHOD New( cFileName ) METHOD Add( cMsg ) METHOD Close() + METHOD Clear() PROTECTED: @@ -121,3 +122,6 @@ METHOD Close() CLASS TIPLOG ENDIF RETURN .F. + +METHOD Clear() CLASS TIPLOG + RETURN ::Close() .AND. FErase( ::cFileName ) == 0 diff --git a/harbour/contrib/hbtip/popcli.prg b/harbour/contrib/hbtip/popcli.prg index b9d04832dd..04b4d333ae 100644 --- a/harbour/contrib/hbtip/popcli.prg +++ b/harbour/contrib/hbtip/popcli.prg @@ -64,7 +64,7 @@ CREATE CLASS tIPClientPOP FROM tIPClient - METHOD New( oUrl, bTrace, oCredentials ) + METHOD New( oUrl, xTrace, oCredentials ) METHOD Open( cUrl ) METHOD OpenDigest( cUrl ) METHOD Close( lAutoQuit ) @@ -84,15 +84,9 @@ CREATE CLASS tIPClientPOP FROM tIPClient ENDCLASS -METHOD New( oUrl, bTrace, oCredentials ) CLASS tIPClientPOP - LOCAL oLog +METHOD New( oUrl, xTrace, oCredentials ) CLASS tIPClientPOP - IF ISLOGICAL( bTrace ) .AND. bTrace - oLog := tIPLog():New( "pop3" ) - bTrace := {| cMsg | iif( PCount() > 0, oLog:Add( cMsg ), oLog:Close() ) } - ENDIF - - ::super:New( oUrl, bTrace, oCredentials ) + ::super:new( oUrl, iif( ISLOGICAL( xTrace ) .AND. xTrace, "pop3", xTrace ), oCredentials ) ::nDefaultPort := iif( ::oUrl:cProto == "pop3s" .OR. ::oUrl:cProto == "pops", 995, 110 ) ::nConnTimeout := 10000 diff --git a/harbour/contrib/hbtip/sendmail.prg b/harbour/contrib/hbtip/sendmail.prg index c0e3c1714f..dfaeab6b65 100644 --- a/harbour/contrib/hbtip/sendmail.prg +++ b/harbour/contrib/hbtip/sendmail.prg @@ -57,7 +57,7 @@ FUNCTION hb_SendMail( cServer, nPort, cFrom, xTo, xCC, xBCC, cBody, cSubject, ; aFiles, cUser, cPass, cPopServer, nPriority, lRead, ; - bTrace, lPopAuth, lNoAuth, nTimeOut, cReplyTo, ; + xTrace, lPopAuth, lNoAuth, nTimeOut, cReplyTo, ; lTLS, cSMTPPass, cCharset, cEncoding ) /* cServer -> Required. IP or domain name of the mail server @@ -74,7 +74,7 @@ FUNCTION hb_SendMail( cServer, nPort, cFrom, xTo, xCC, xBCC, cBody, cSubject, ; cPopServer -> Required. POP3 server name or address nPriority -> Optional. Email priority: 1=High, 3=Normal (Standard), 5=Low lRead -> Optional. If set to .T., a confirmation request is send. Standard setting is .F. - bTrace -> Optional. If set to .T., a log file is created (smtp-.log). Standard setting is NIL. + xTrace -> Optional. If set to .T., a log file is created (smtp-.log). Standard setting is .F. If a block is passed, it will be called for each log event with the message a string, no param on session close. lPopAuth -> Optional. Do POP3 authentication before sending mail. lNoAuth -> Optional. Disable Autentication methods @@ -197,7 +197,7 @@ FUNCTION hb_SendMail( cServer, nPort, cFrom, xTo, xCC, xBCC, cBody, cSubject, ; BEGIN SEQUENCE oUrl1 := tUrl():New( iif( lTLS, "pop3s://" , "pop://" ) + cUser + ":" + cPass + "@" + cPopServer + "/" ) oUrl1:cUserid := StrTran( cUser, "&at;", "@" ) - opop:= tIPClientPOP():New( oUrl1, bTrace ) + opop:= tIPClientPOP():New( oUrl1, xTrace ) IF oPop:Open() oPop:Close() ENDIF @@ -226,7 +226,7 @@ FUNCTION hb_SendMail( cServer, nPort, cFrom, xTo, xCC, xBCC, cBody, cSubject, ; oUrl:cFile := cTo + iif( Empty( cCC ), "", "," + cCC ) + iif( Empty( cBCC ), "", "," + cBCC ) BEGIN SEQUENCE - oInmail := tIPClientSMTP():New( oUrl, bTrace ) + oInmail := tIPClientSMTP():New( oUrl, xTrace ) RECOVER lReturn := .F. END SEQUENCE @@ -291,7 +291,7 @@ FUNCTION hb_SendMail( cServer, nPort, cFrom, xTo, xCC, xBCC, cBody, cSubject, ; ENDIF BEGIN SEQUENCE - oInmail := tIPClientSMTP():New( oUrl, bTrace ) + oInmail := tIPClientSMTP():New( oUrl, xTrace ) RECOVER lReturn := .F. END SEQUENCE diff --git a/harbour/contrib/hbtip/smtpcli.prg b/harbour/contrib/hbtip/smtpcli.prg index a9b656ca8a..acb13bc13a 100644 --- a/harbour/contrib/hbtip/smtpcli.prg +++ b/harbour/contrib/hbtip/smtpcli.prg @@ -63,7 +63,7 @@ CREATE CLASS tIPClientSMTP FROM tIPClient - METHOD New( oUrl, bTrace, oCredentials ) + METHOD New( oUrl, xTrace, oCredentials ) METHOD Open( cUrl, lTLS ) METHOD Close() METHOD Write( cData, nLen, bCommit ) @@ -87,16 +87,9 @@ CREATE CLASS tIPClientSMTP FROM tIPClient ENDCLASS -METHOD New( oUrl, bTrace, oCredentials ) CLASS tIPClientSMTP +METHOD New( oUrl, xTrace, oCredentials ) CLASS tIPClientSMTP - LOCAL oLog - - IF ISLOGICAL( bTrace ) .AND. bTrace - oLog := tIPLog():New( "smtp" ) - bTrace := {| cMsg | iif( PCount() > 0, oLog:Add( cMsg ), oLog:Close() ) } - ENDIF - - ::super:New( oUrl, bTrace, oCredentials ) + ::super:new( oUrl, iif( ISLOGICAL( xTrace ) .AND. xTrace, "smtp", xTrace ), oCredentials ) ::nDefaultPort := iif( ::oUrl:cProto == "smtps", 465, 25 ) ::nConnTimeout := 50000