Metropoli BBS
VIEWER: interap MODE: TEXT (ASCII)
'
' Visual Basic InterAp Module
' Copyright (C) 1994
' California Software, Inc.
'
' Last revised: 14/02/1995
' By:   Max Sokolov
'
' Last revised: 3/3/1995
' By:   Roman Kriis

' This module has Visual Basic Compatible function declarations and:
'   Terminal/Telnet receiving prompt
'   Terminal connection control (dial/disconnect)
'   NetNew command completion
'   Web Navigator command completion
'   FTP command completion
'   InterAp Kernel command completion
'      and some other useful functions
'

Global Const SCHEDULED_LATER = 0
Global Const SCHEDULED_NOW = 1
Global Const SCHEDULED_HOURLY = 2
Global Const SCHEDULED_DAILY = 3
Global Const SCHEDULED_WEEKLY = 4
Global Const SCHEDULED_MONTHLY = 5

' Mail messages flags
Global Const MAIL_POSTED = 1
Global Const MAIL_POSTPONED = 2
Global Const MAIL_READ = 4
Global Const MAIL_INCOMING = 8
Global Const MAIL_SENT = 16
Global Const MAIL_NEW = 32
Global Const MAIL_DELETED = 64
Global Const MAIL_DELETE_AFTER = 128
Global Const FAILED_TO_GET_STATUS = -1

Declare Function IAMailSend& Lib "ia-dll.dll" (ByVal ToList$, ByVal CcList$, ByVal BccList$, ByVal AttList$, ByVal From$, ByVal Subject$, ByVal MailText$, ByVal SendNow%, ByVal SendTime$, ByVal ComposeFlag%, ByVal DeleteAfterSend%)
Declare Function IAMailGetMessageList Lib "ia-dll.dll" (ByVal inFlag%, ByVal outFlag%, ByVal readFlag%, ByVal unreadFlag%, ByVal resultFile$) As Integer
Declare Function IAMailGetMessage Lib "ia-dll.dll" (ByVal mailID&, ByVal resultFile$) As Integer
Declare Function IAMailGetMessageStatus Lib "ia-dll.dll" (ByVal mailID&) As Long

Declare Function IAScheduledRun% Lib "ia-dll.dll" (ByVal cmdLine$, ByVal SchedulingMode%, ByVal TimeString$, ByVal RepetitionCount%)
Declare Function IAKernelStart% Lib "ia-dll.dll" ()
Declare Function IAKernelLoaded% Lib "ia-dll.dll" ()
Declare Function IAKernelQuit% Lib "ia-dll.dll" ()
Declare Function WritePrivateProfileString Lib "krnl386.exe" (ByVal sectName$, ByVal entryName$, ByVal entryValue$, ByVal fileName$) As Integer
Declare Function lstrcpy Lib "krnl386.exe" (ByVal lpStringTo As Any, ByVal lpStringFrom As Any) As Long

Declare Function IAGetWinDir Lib "ia-dll.dll" (retVal%) As Long
Declare Function IAGetProfileString Lib "ia-dll.dll" (retVal%, ByVal fileName$, ByVal sectionName$, ByVal entryName$) As Long
Declare Function IANetNewsActive Lib "ia-dll.dll" (errorCode%) As Long
Declare Function IAWebNavActive Lib "ia-dll.dll" (errorCode%) As Long

Declare Function IANetNewsStart% Lib "ia-dll.dll" ()
Declare Function IANetNewsQuit% Lib "ia-dll.dll" ()
Declare Function IANetNewsSubscribe% Lib "ia-dll.dll" (ByVal groupList$)
Declare Function IANetNewsUnSubscribe% Lib "ia-dll.dll" (ByVal groupList$)
Declare Function IANetNewsConnect% Lib "ia-dll.dll" (ByVal hostName$, ByVal portNo%, ByVal userID$, ByVal Password$)
Declare Function IANetNewsRCSubscribedGroupList% Lib "ia-dll.dll" (ByVal resultFileName$)
Declare Function IANetNewsSubscribedGroupList% Lib "ia-dll.dll" (ByVal resultFileName$)
Declare Function IANetNewsUnSubscribedGroupList% Lib "ia-dll.dll" (ByVal resultFileName$)
Declare Function IANetNewsGetArticlesList% Lib "ia-dll.dll" (ByVal resultFileName$, ByVal groupTitle$, ByVal artNumber%)
Declare Function IANetNewsGetNewGroupsList% Lib "ia-dll.dll" (ByVal resultFileName$, ByVal updateResource%)
Declare Function IANetNewsGetNewArticlesList% Lib "ia-dll.dll" (ByVal resultFileName$, ByVal groupTitle$, ByVal artNumber%)
Declare Function IANetNewsSaveArticles% Lib "ia-dll.dll" (ByVal resultFileName$, ByVal groupTitle$, ByVal articlesList$)
Declare Function IANetNewsPostArticle% Lib "ia-dll.dll" (ByVal groupTitle$, ByVal articleSubject$, ByVal articleTextFileName$)
Declare Function IANetNewsRefreshResource% Lib "ia-dll.dll" ()

Declare Function IAWebNavStart% Lib "ia-dll.dll" ()
Declare Function IAWebNavQuit% Lib "ia-dll.dll" ()
Declare Function IAWebNavGetURL% Lib "ia-dll.dll" (ByVal urlRequest$, ByVal resultFileName$, ByVal resultType$)

Declare Sub IA911Info Lib "ia-dll.dll" (ByVal fileName As Any, ByVal textString As Any)
Declare Sub IA911Warning Lib "ia-dll.dll" (ByVal fileName As Any, ByVal textString As Any)
Declare Sub IA911Error Lib "ia-dll.dll" (ByVal fileName As Any, ByVal textString As Any)
Declare Sub IA911FatalError Lib "ia-dll.dll" (ByVal fileName As Any, ByVal textString As Any)

Declare Function IAIsCommActive% Lib "ia.dll" ()
Declare Function IAisWait% Lib "ia.dll" ()
Declare Function IATerminalStart% Lib "ia.dll" (ByVal commPort%)
Declare Function IATelnetStart% Lib "ia.dll" ()
Declare Function IATerminalQuit% Lib "ia.dll" ()
Declare Function IATelnetQuit% Lib "ia.dll" ()
Declare Function IATerminalConnect% Lib "ia.dll" (ByVal phoneNumber$)
Declare Function IATelnetConnect% Lib "ia.dll" (ByVal hostName$, ByVal portNumber%)
Declare Function IATerminalSendString% Lib "ia.dll" (ByVal sendString$)
Declare Function IATelnetSendString% Lib "ia.dll" (ByVal sendString$)
Declare Function IATerminalReadString% Lib "ia.dll" (ByVal patternString$)
Declare Function IATelnetReadString% Lib "ia.dll" (ByVal patternString$)
Declare Function IATerminalSendFile% Lib "ia.dll" (ByVal fileName$, ByVal protocolCode%)
Declare Function IATerminalReceiveFile% Lib "ia.dll" (ByVal fileName$, ByVal protocolCode%)
Declare Function IAStartCapture% Lib "ia.dll" (ByVal fileName$)
Declare Function IAStopCapture% Lib "ia.dll" ()

'
' This function is used to close terminal connection and Terminal Window.
'   First, this function is waiting for any current async operation to complete
'   (otherwise GPF may occure) and only then it quits the Terminal Window.
'
Sub CloseTerminalConnection ()
    Dim i%, t&

    'Do
    '    t = Timer
    '    If (t Mod 2) = 0 Then
    '        i = IAIsCommActive()
    '    End If
    '    DoEvents
    'Loop While i = 1
    i = IATerminalQuit()
End Sub

'
' This function is used to read string from .INI file. Given the .INI file name,
'   section and entry names this function fills in variable retVal with the value
'   of the specified entry and returns the length of the value in characters. If
'   entry value is empty or entry name couldn't be found then retVal takes value
'   "No Entry".
'
Function GetProfileString (retValue As String, iniFile As String, Section As String, Entry As String) As Integer
    Dim lpStr&, tmpStr$, i%, j%

    tmpStr = Space$(129)
    lpStr = IAGetProfileString(i, iniFile, Section, Entry)
    lpStr = lstrcpy(tmpStr, lpStr)
    j = Len(Trim$(tmpStr)) - 1
    retValue = Left$(tmpStr, j)
    GetProfileString = i
End Function

'
' This function is used to retrieve directory name where Windows was installed
'   and returns the length of the string.
'
Function GetWindowsDirectory (winDir As String) As Integer
    Dim lpStr&, tmpStr$, i%, j%

    tmpStr = Space$(129)
    lpStr = IAGetWinDir(i)
    lpStr = lstrcpy(tmpStr, lpStr)
    j = Len(Trim$(tmpStr)) - 1
    winDir = Left$(tmpStr, j)
    GetWindowsDirectory = i
End Function

'
' This function is used to establish asynchronous connection using given values
'   for the Comm port number, phone number to dial and time out value for
'   dial-up (in seconds). The function returns 1 if successfully connected,
'   0 if timed out and -1 if failed to initializa Comm port.
'
Function OpenTerminalConnection% (commPort As Integer, phoneNumber As String, Timeout As Integer)
    Dim i%, t&, tt&, ii&, retVal%

    i = IATerminalStart(commPort)                 '' initialize Comm port
    If i = 0 Then
	retVal = -1
	GoTo otc_end
    End If
    
    Do
	DoEvents
    Loop While (IAisWait() = 0)
    
    i = IATerminalConnect(phoneNumber)             '' begin dialing
''
'' let's wait until connection is established or time out is reached
''
    tt = Timer
    Do
	i = 0
	t = Timer
	If (t Mod 5) = 0 Then
	    i = IAIsCommActive()
	End If
	DoEvents
	ii = t - tt
    Loop While i = 0 And (ii <= Timeout And Timeout <> 0)
    retVal = 0                                  '' time out has been reached
    If i = 1 Then retVal = 1                    '' connection has been established
otc_end:
    OpenTerminalConnection = retVal
End Function

'
' This function is used to write string to .INI file. Given the .INI file name,
'   section and entry names this function stores the value of the specified entry
'   and returns the 1 if everything was OK and 0 otherwise.
'
Function PutProfileString (iniFile As String, Section As String, Entry As String, ProfileString As String) As Integer
    Dim i%

    i = WritePrivateProfileString(Section, Entry, ProfileString, iniFile)
    PutProfileString = i
End Function

'
' This function is used to receive prompt string during the telnet session. It
'   compares given pattern against the string being accumulated in the
'   buffer. And once they match or given time out value (in seconds) has been
'   reached the function is finished.
'
Function TelnetReadLine% (sExpect As String, Timeout As Integer)
    Dim i%, tmr1&, tmr2&

    tmr1 = Timer
    Do
	i = IATelnetReadString(sExpect)
	DoEvents
	tmr2 = Timer
	If Timeout <> 0 And tmr2 - tmr1 >= Timeout Then Exit Do
    Loop While i = 0
    TelnetReadLine = i
End Function

'
' This function is used to receive prompt string during the asynchronous
'   communication. It compares given pattern against the string being
'   accumulated in the communication buffer. And once they match or given
'   time out value (in seconds) has been reached the function is finished.
'   The return value depends on whether string match (1) or time out occured (0)
'
Function TerminalReadLine% (sExpect As String, Timeout As Integer)
    Dim i%, tmr1&, tmr2&

    tmr1 = Timer
    Do
	i = IATerminalReadString(sExpect)
	DoEvents
	tmr2 = Timer
	If Timeout <> 0 And tmr2 - tmr1 >= Timeout Then Exit Do
    Loop While i = 0
    TerminalReadLine = i
End Function

'
' This function is used to decide whether the InterAp Kernel is loaded or not.
'
Sub WaitForKernel (Delay%)
    Dim i%, t&, t1&

    i = 0
    t1 = Timer
    Do
	t = Timer
	If (t Mod 2) = 0 Then
	    If t - t1 >= Delay Then
		i = IAKernelLoaded()
		t1 = Timer
	    End If
	End If
	DoEvents
    Loop While i = 0
End Sub

'
' This function is used to decide whether the NetNews is still active and
'   executes the command it was given. If error has occured this functions
'   returns error description. If Timeout value is not zero then after (Timeout)
'   minutes function will return "Timed Out". The Delay value tell function
'   how frequently (in seconds) check for the NetNews status.
'
Function WaitForNews$ (Delay%, ByVal Timeout%)
    Dim i%, t&, t1&, errString$, lpStr&, tStart&
    i = 1
    t1 = Timer
    tStart = t1
    Do
	t = Timer
	If Timeout > 0 And (t - tStart >= Timeout * 60) Then
	    errString = "Timed Out " + Chr$(0)
	    Exit Do
	End If
'' every 2 seconds ....
	If (t Mod 2) = 0 Then
'' ..... see if DELAY seconds have elapsed since last check
	    If t - t1 >= Delay Then
		errString = Space$(1024)
		lpStr = IANetNewsActive(i)
		lpStr = lstrcpy(errString, lpStr)
		t1 = Timer
	    End If
	End If
	DoEvents
	If i = -1 Then i = 1
    Loop While i <> 0 And i <= 1
    i = InStr(1, Trim$(errString), Chr$(0))
    WaitForNews = Left$(errString, i - 1)
End Function

'
' This function is used to decide whether the Web Navigator is still active
'   executes the command it was given. If error has occured this functions
'   returns error description. If Timeout value is not zero then after (Timeout)
'   minutes function will return "Timed Out". The Delay value tell function
'   how frequently (in seconds) check for the Web Navigator status.
'
'
Function WaitForWeb$ (Delay%, ByVal Timeout%)
    Dim i%, t&, t1&, errString$, lpStr&, tStart&
    i = 1
    t1 = Timer
    tStart& = t1
    Do
	t = Timer
	If Timeout > 0 And (t - tStart >= Timeout * 60) Then
	    errString = "Timed Out "
	    Exit Do
	End If
'' every 2 seconds ....
	If (t Mod 2) = 0 Then
'' ..... see if DELAY seconds have elapsed since last check
	    If t - t1 >= Delay Then
		errString = Space$(1024)
		lpStr = IAWebNavActive(i)
		lpStr = lstrcpy(errString, lpStr)
		t1 = Timer
	    End If
	End If
	DoEvents
    Loop While i = 1
    i = Len(Trim$(errString)) - 1
    WaitForWeb = Left$(errString, i)
End Function

[ RETURN TO DIRECTORY ]