Created
November 29, 2014 18:03
-
-
Save ddur/34033ed1392cdce1253c to your computer and use it in GitHub Desktop.
Read internet page/file from Clarion 6.3 using wininet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AgentFF CSTRING('Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8.0.3) Gecko/20060426 Firefox/1.5.0.3<0>') | |
AgentIE CSTRING('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)<0>') | |
Agent00 CSTRING(' <0>') | |
szGET CSTRING('GET<0>') | |
szPOST CSTRING('POST<0>') | |
equ:szAgent equate ( Agent00 ) | |
INTERNET_INVALID_PORT_NUMBER equate (0) ! use the protocol-specific default | |
INTERNET_DEFAULT_FTP_PORT equate (21) ! default for FTP servers | |
INTERNET_DEFAULT_GOPHER_PORT equate (70) ! " " gopher " | |
INTERNET_DEFAULT_HTTP_PORT equate (80) ! " " HTTP " | |
INTERNET_DEFAULT_HTTPS_PORT equate (443) ! " " HTTPS " | |
INTERNET_DEFAULT_SOCKS_PORT equate (1080) ! default for SOCKS firewall servers. | |
INTERNET_MAX_HOST_NAME_LENGTH equate (256) | |
INTERNET_MAX_USER_NAME_LENGTH equate (128) | |
INTERNET_MAX_PASSWORD_LENGTH equate (128) | |
INTERNET_MAX_PORT_NUMBER_LENGTH equate (5) ! INTERNET_PORT is unsigned short | |
INTERNET_MAX_PORT_NUMBER_VALUE equate (65535) ! maximum unsigned short value | |
INTERNET_MAX_PATH_LENGTH equate (2048) | |
INTERNET_MAX_SCHEME_LENGTH equate (32) ! longest protocol name length | |
INTERNET_MAX_DELIMITER_SIZE equate (3) | |
INTERNET_MAX_URL_LENGTH equate (INTERNET_MAX_SCHEME_LENGTH | | |
+ INTERNET_MAX_DELIMITER_SIZE | | |
+ INTERNET_MAX_PATH_LENGTH) | |
INTERNET_SERVICE_URL equate (0) | |
INTERNET_SERVICE_FTP equate (1) | |
INTERNET_SERVICE_GOPHER equate (2) | |
INTERNET_SERVICE_HTTP equate (3) | |
INTERNET_OPEN_TYPE_PRECONFIG equate (0) ! use registry configuration | |
INTERNET_OPEN_TYPE_DIRECT equate (1) ! direct to net | |
INTERNET_OPEN_TYPE_PROXY equate (3) ! via named proxy | |
INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY equate (4) ! prevent using java/script/INS | |
!INTERNET_FLAG_ASYNC equate (010000000h) ! this request is asynchronous (where supported) | |
!INTERNET_FLAG_NEED_FILE equate (000000010h) ! need a file for this request | |
!COOKIES | |
INTERNET_FLAG_RESTRICTED_ZONE equate ( 00020000H ) !// apply restricted zone policies for cookies, auth | |
INTERNET_COOKIE_HTTPONLY equate ( 00002000H ) | |
INTERNET_COOKIE_THIRD_PARTY equate ( 00000010H ) | |
!WinAPI InternetGetCookie(Ex) GetLastError() | |
ERROR_INSUFFICIENT_BUFFER equate (122) | |
ERROR_NO_MORE_ITEMS equate (259) | |
ERROR_INVALID_PARAMETER equate (87) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ( 'WinApi' ) | |
GetLastError (), long, proc, raw, pascal | |
sleep ( long ), pascal | |
. | |
module ( 'WinInet' ) | |
! HINTERNET InternetOpen( | |
! IN LPCSTR lpszAgent, | |
! IN DWORD dwAccessType, | |
! IN LPCSTR lpszProxyName, | |
! IN LPCSTR lpszProxyBypass, | |
! IN DWORD dwFlags | |
! ); | |
internetOpen ( long, long, long, long, long), long, raw, pascal, name( 'InternetOpenA' ) | |
! HINTERNET InternetOpenUrl( | |
! IN HINTERNET hInternetSession, | |
! IN LPCSTR lpszUrl, | |
! IN LPCSTR lpszHeaders, | |
! IN DWORD dwHeadersLength, | |
! IN DWORD dwFlags, | |
! IN DWORD dwContext | |
! ); | |
internetOpenURL ( long, long, long, long, long, long), long, proc, raw, pascal, name( 'InternetOpenURLA' ) | |
! HINTERNET InternetConnect( | |
! IN HINTERNET hInternetSession, | |
! IN LPCSTR lpszServerName, | |
! IN INTERNET_PORT nServerPort, | |
! IN LPCSTR lpszUsername, | |
! IN LPCSTR lpszPassword, | |
! IN DWORD dwService, | |
! IN DWORD dwFlags, | |
! IN DWORD dwContext | |
! ); | |
internetConnect ( long, long, uShort, long, long, long, long, long ), long, raw, pascal, name ( 'InternetConnectA' ) | |
! HINTERNET HttpOpenRequest( | |
! IN HINTERNET hHttpSession, | |
! IN LPCSTR lpszVerb, | |
! IN LPCSTR lpszObjectName, | |
! IN LPCSTR lpszVersion, | |
! IN LPCSTR lpszReferer, | |
! IN LPCSTR FAR * lpszAcceptTypes, | |
! IN DWORD dwFlags, | |
! IN DWORD dwContext | |
! ); | |
httpOpenRequest ( long, long, long, long, long, long, long, long ), long, raw, pascal, name ( 'HttpOpenRequestA' ) | |
! BOOL HttpSendRequest( | |
! IN HINTERNET hHttpRequest, | |
! IN LPCSTR lpszHeaders, | |
! IN DWORD dwHeadersLength, | |
! IN LPVOID lpOptional, | |
! DWORD dwOptionalLength | |
! ); | |
httpSendRequest ( long, long, long, long, long ), long, proc, raw, pascal, name ( 'HttpSendRequestA' ) | |
! BOOL InternetReadFile( | |
! IN HINTERNET hFile, | |
! IN LPVOID lpBuffer, | |
! IN DWORD dwNumberOfBytesToRead, | |
! OUT LPDWORD lpNumberOfBytesRead | |
! ); | |
internetReadFile ( long, long, long, *long), long, proc, raw, pascal | |
! BOOL InternetCloseHandle( | |
! IN HINTERNET hInet | |
! ); | |
internetCloseHandle ( long ), long, proc, raw, pascal | |
. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ReadHttpPage PROCEDURE ( szServer, szAction, szPage, dwSize ) ! Declare Procedure | |
hWininetSession LONG ! | |
hWininetHttpSession LONG ! | |
hWininetHttpRequest LONG ! | |
dwBytesRead LONG ! | |
dwOutSize LONG ! | |
dwResult LONG ! | |
szBuffer CSTRING(1025) ! | |
! Start of "Data Section" | |
! [Priority 3500] | |
dwBufferSize equate ( size ( szBuffer ) - 1 ) | |
! End of "Data Section" | |
CODE | |
! Start of "Processed Code" | |
! [Priority 4000] | |
dwResult = false | |
dwOutSize = false | |
hWininetSession = internetOpen ( address ( equ:szAgent ), INTERNET_OPEN_TYPE_PRECONFIG, false, false, false ) | |
if hWininetSession | |
hWininetHttpSession = internetConnect ( hWininetSession, address ( szServer ), INTERNET_DEFAULT_HTTP_PORT, false, false, INTERNET_SERVICE_HTTP, false, true ) | |
if hWininetHttpSession | |
hWininetHttpRequest = httpOpenRequest ( hWininetHttpSession, address ( szGET ), address ( szAction ), false, false, false, false, true ) | |
if hWininetHttpRequest | |
loop | |
loop 10 times | |
sleep ( 0 ) | |
. | |
dwResult = internetReadFile ( hWininetHttpRequest, address ( szBuffer ), dwBufferSize, dwBytesRead ) | |
if ~dwResult or ~dwBytesRead | |
break | |
. | |
if ( dwOutSize + dwBytesRead ) <= dwSize | |
szPage [ ( dwOutSize + 1 ) : ( dwOutSize + dwBytesRead ) ] = szBuffer [ 1 : dwBytesRead ] | |
else | |
szPage [ ( dwOutSize + 1 ) : dwSize ] = szBuffer [ 1 : dwBytesRead ] | |
break | |
. | |
dwOutSize += dwBytesRead | |
. | |
internetCloseHandle ( hWininetHttpRequest ) | |
. | |
internetCloseHandle ( hWininetHttpSession ) | |
. | |
internetCloseHandle ( hWininetSession ) | |
. | |
return dwResult |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ReadInetFile PROCEDURE ( szURL, szFile, dwSize ) ! Declare Procedure | |
hWininetSession LONG ! | |
hWininetURLSession LONG ! | |
dwBytesRead LONG ! | |
dwOutSize LONG ! | |
dwResult LONG ! | |
szBuffer CSTRING(1025) ! | |
! Start of "Data Section" | |
! [Priority 3500] | |
dwBufferSize equate ( size ( szBuffer ) - 1 ) | |
! End of "Data Section" | |
CODE | |
! Start of "Processed Code" | |
! [Priority 4000] | |
dwResult = false | |
hWininetSession = internetOpen ( address ( equ:szAgent ), INTERNET_OPEN_TYPE_PRECONFIG, false, false, false ) | |
if hWininetSession | |
hWininetURLSession = internetOpenURL ( hWininetSession, address ( szURL ), false, false, false, false ) | |
if hWininetURLSession | |
dwOutSize = false | |
if ~dwSize | |
dwSize = size ( szFile ) - 1 | |
. | |
loop | |
loop 10 times | |
sleep ( 0 ) | |
. | |
dwResult = internetReadFile ( hWininetURLSession, address ( szBuffer ), dwBufferSize, dwBytesRead ) | |
if ~dwResult or ~dwBytesRead | |
break | |
. | |
if ( dwOutSize + dwBytesRead ) <= dwSize | |
szFile [ ( dwOutSize + 1 ) : ( dwOutSize + dwBytesRead ) ] = szBuffer [ 1 : dwBytesRead ] | |
else | |
szFile [ ( dwOutSize + 1 ) : dwSize ] = szBuffer [ 1 : dwBytesRead ] | |
break | |
. | |
dwOutSize += dwBytesRead | |
. | |
internetCloseHandle ( hWininetURLSession ) | |
. | |
internetCloseHandle ( hWininetSession ) | |
. | |
return dwResult |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment