FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour TInternet
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
TInternet
Posted: Sat Mar 14, 2015 07:41 PM
Dear Antonio,
I faced a problem with TInternet.
I have a program which is downloading files from the internet. But when I update a file online the program still downloads the old version.
I felt that the content must be somewhere in a buffer.
Now looking into TInternet class it seems to me as there classdata hWinINet and aFTPs is not released.
If I make following changes for me all is working.
I am not very experienced with this class. Can someone please check.
Thanks in advance
Otto


Code (fw): Select all Collapse
METHOD New() CLASS TInternet

   local hWinINet := WinINet()
    
    ::hWinINet := hWinINet    //Otto
   
   if hWinINet < 0 .or. hWinINet >= 32
      ::hSession = InternetOpen( "FW", 0, 0, 0, 0 )
   endif

return Self

//----------------------------------------------------------------------------//

METHOD End() CLASS TInternet

xbrowse(::aFTPs)
xbrowse(::hWinINet)
   
   #ifdef __CLIPPER__
      ASend( ::aFTPs, "End" )
   #else
      ASend( ::aFTPs, "End()" )
   #endif

   if ::hSession != nil
      InternetCloseHandle( ::hSession )
      ::hSession = nil
      ::hWinINet = nil   //Otto
      ::aFTPs := {}      //Otto
   endif

return nil
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Re: TInternet
Posted: Sun Mar 15, 2015 06:42 AM
Otto,

I experienced the same problem. You need to delete the filecache first before redownloading a file.

This is the way I do this :
Code (fw): Select all Collapse
DELFILECACHE({"http://file1","http://file2",...})

******************************************************************************

#pragma BEGINDUMP

#include <stdio.h>
#include <Windows.h>
#include <WinINet.h>
#include <hbapi.h>
#include <hbapiitm.h>
#include <hbapifs.h>
#include <hbvm.h>
#include <hbstack.h>

static int mystrcmp( char *val1, char *val2 )
{
        int     nret = 0 ;

        for ( ; *val1 ; val1++, val2++ )  {
                if ( ! *val2 || *val1 != *val2 )  {
                        nret = 1 ;
                        break ;
                }
        }
        if ( ! nret && *val2 )
                nret = 1 ;

        return nret ;
}

HB_FUNC( DELFILECACHE )
{
        BOOL                            bResult = FALSE ;
        BOOL                            bDone = FALSE ;
        LPINTERNET_CACHE_ENTRY_INFO     lpCacheEntry = NULL ;
        DWORD                           dwTrySize, dwEntrySize = 4096 ; // start buffer size
        HANDLE                          hCacheDir = NULL ;
        DWORD                           dwError = ERROR_INSUFFICIENT_BUFFER ;
        BOOL                            bSuccess ;
        PHB_ITEM                        iFiles, iElem ;
        int                             nfile, npos ;
        char                            buffile[FILENAME_MAX] ;

        iFiles = hb_itemParam( 1 ) ;
        nfile = hb_parinfa( 1, 0 ) ;

        do  {
                switch ( dwError )  {
                        // need a bigger buffer
                        case ERROR_INSUFFICIENT_BUFFER :
                                if ( lpCacheEntry != NULL )
                                        free( (LPBYTE)lpCacheEntry ) ;
                                lpCacheEntry = (LPINTERNET_CACHE_ENTRY_INFO) malloc( dwEntrySize ) ;
                                lpCacheEntry->dwStructSize = dwEntrySize ;
                                dwTrySize = dwEntrySize ;

                                if ( hCacheDir == NULL )
                                        bSuccess = (hCacheDir = FindFirstUrlCacheEntry( NULL, lpCacheEntry, &dwTrySize )) != NULL ;
                                else
                                        bSuccess = FindNextUrlCacheEntry(hCacheDir, lpCacheEntry, &dwTrySize ) ;
                                if ( bSuccess )
                                        dwError = ERROR_SUCCESS ;
                                else  {
                                        dwError = GetLastError() ;
                                        dwEntrySize = dwTrySize ; // use new size returned
                                }
                                break ;

                        // we are done
                        case ERROR_NO_MORE_ITEMS :
                                bDone = TRUE ;
                                bResult = TRUE ;
                                break ;

                        // we have got an entry
                        case ERROR_SUCCESS:
                                // don't delete cookie entry

                                if ( !( lpCacheEntry->CacheEntryType & COOKIE_CACHE_ENTRY ) )  {
                                        for ( npos = 1 ; npos <= nfile ; npos++ )  {
                                                iElem = hb_itemArrayGet( iFiles, npos ) ;

                                                hb_itemCopyC( iElem, buffile, 0 ) ;
                                                buffile[hb_itemSize( iElem )] = '\0' ;

                                                if ( ! mystrcmp( (char *)(lpCacheEntry->lpszSourceUrlName), buffile ) )  {
                                                        DeleteUrlCacheEntry( lpCacheEntry->lpszSourceUrlName ) ;
                                                        break ;
                                                }
                                        }
                                }

                                // get ready for next entry
                                dwTrySize = dwEntrySize;
                                if ( FindNextUrlCacheEntry(hCacheDir, lpCacheEntry, &dwTrySize ) )
                                        dwError = ERROR_SUCCESS ;
                                else  {
                                        dwError = GetLastError() ;
                                        dwEntrySize = dwTrySize ; // use new size returned
                                }
                                break;

                        // unknown error
                        default:
                                bDone = TRUE ;
                                break ;
                }
                if ( bDone )  {
                        free( (LPBYTE)lpCacheEntry ) ;
                        if ( hCacheDir )
                                FindCloseUrlCache( hCacheDir ) ;
                }
        }  while ( !bDone ) ;

        hb_retnl( bResult ) ;
}

#pragma ENDDUMP

*****************************************************************************
I hope htis can help you.

Regards,

Michel D.
Genk (Belgium)


_____________________________________________________________________________________________

I use : FiveWin for (x)Harbour v. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: TInternet
Posted: Sun Mar 15, 2015 06:54 AM

xbrowse(::aFTPs)

Hello Michel,

here in my case classdata aFTPs every time adds a new entry.
As my program runs 24/7 I think this can’t be right.

Also deleting the cache seems to me only a workaround. I think if you end the object all should be done.

I do not know which side effects the change has but as for now it is working.
Best regards,
Otto

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: TInternet
Posted: Mon Mar 16, 2015 03:14 PM
Otto,

I use the same. This is my definition:

Code (fw): Select all Collapse
DLL FUNCTION DELETEURLCACHEENTRY( cUrl AS LPSTR ) AS BOOL;
    PASCAL FROM "DeleteUrlCacheEntryA" LIB "wininet.dll"


EMG

Continue the discussion