VERSION 1.0 CLASS BEGIN MultiUse = -1 'True Persistable = 0 'NotPersistable DataBindingBehavior = 0 'vbNone DataSourceBehavior = 0 'vbNone MTSTransactionMode = 0 'NotAnMTSObject END Attribute VB_Name = "InetTools" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = True Attribute VB_PredeclaredId = False Attribute VB_Exposed = False Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes" Attribute VB_Ext_KEY = "Top_Level" ,"Yes" Attribute VB_Ext_KEY = "Member0" ,"TimeOut" 'local variable(s) to hold property value(s) Private mvarProxyServer As String 'local copy Private mvarProxyPort As Integer 'local copy Private Type CookieEntry body As String name As String End Type Private mvarinStreamBuffer As String 'local copy Private mvarOutStreamBuffer As String 'local copy 'local variable(s) to hold property value(s) Private mvarCookie As String 'local copy 'local variable(s) to hold property value(s) Private mvarTimeOut As New TimeOut 'local copy Public Property Set TimeOut(ByVal vData As TimeOut) Set mvarTimeOut = vData End Property Public Property Get TimeOut() As TimeOut Set TimeOut = mvarTimeOut End Property Public Property Let Cookie(ByVal vData As String) mvarCookie = vData End Property Public Property Get Cookie() As String Cookie = mvarCookie End Property Public Property Let OutStreamBuffer(ByVal vData As String) mvarOutStreamBuffer = vData End Property Public Property Get OutStreamBuffer() As String OutStreamBuffer = mvarOutStreamBuffer End Property Public Property Let inStreamBuffer(ByVal vData As String) mvarinStreamBuffer = vData End Property Public Property Get inStreamBuffer() As String inStreamBuffer = mvarinStreamBuffer End Property Public Property Let ProxyPort(ByVal vData As Integer) mvarProxyPort = vData End Property Public Property Get ProxyPort() As Integer ProxyPort = mvarProxyPort End Property Public Property Let ProxyServer(ByVal vData As String) mvarProxyServer = vData End Property Public Property Get ProxyServer() As String 'used when retrieving value of a property, on the right side of an assignment. 'Syntax: Debug.Print X.ProxyServer ProxyServer = mvarProxyServer End Property Public Function Create_Get_Request(host As String, Script As String, Optional Refer As String, Optional Cookie As String, Optional RangeStart As Long, Optional UserAgent As String) As String Dim tosend As String If Not IsEmpty(appconfig) Then If Not appconfig.ProxyServer = "" Then Script = "http://" + host + Script If host > "" Then host = appconfig.ProxyServer End If End If If RangeStart > 0 Then tosend = tosend + "GET " + Script + " HTTP/1.1" + vbCrLf tosend = tosend + "Range: bytes=" + CStr(RangeStart) + "-" + vbCrLf Else tosend = tosend + "GET " + Script + " HTTP/1.0" + vbCrLf End If If Len(Refer) > 0 Then tosend = tosend + "Referer: " + Refer + vbCrLf If host > "" Then tosend = tosend + "Host: " + host + vbCrLf If UserAgent > "" Then tosend = tosend + "User-Agent: " + UserAgent + vbCrLf If Cookie > "" Then tosend = tosend + "Cookie:" + Cookie + vbCrLf + vbCrLf Else tosend = tosend + vbCrLf OutStreamBuffer = tosend Create_Get_Request = tosend ' written by IWiz mity@ropnet.ru End Function Public Function Create_HEAD_Request(host As String, Script As String, Optional Refer As String, Optional Cookie As String) As String Dim tosend As String If Not ProxyServer = "" Then Script = "http://" + host + Script If host > "" Then host = mvarProxyServer End If tosend = tosend + "HEAD " + Script + " HTTP/1.0" + vbCrLf If Len(Refer) > 0 Then tosend = tosend + "Referer: " + Refer + vbCrLf If host > "" Then tosend = tosend + "Host: " + host + vbCrLf If Cookie > "" Then tosend = tosend + "Cookie:" + Cookie + vbCrLf + vbCrLf Else tosend = tosend + vbCrLf OutStreamBuffer = tosend Create_HEAD_Request = tosend ' written by IWiz mity@ropnet.ru End Function Public Function Create_Post_Request(host As String, Script As String, postData As String, Optional Refer As String, Optional Cookie As String, Optional UserAgent As String) As String Dim tosend As String Dim formlen As Integer If Not ProxyServer = "" Then Script = "http://" + host + Script If host > "" Then host = mvarProxyServer End If tosend = "POST " + Script + " HTTP/1.0" + vbCrLf If Len(host) > 0 Then tosend = tosend + "Host: " + host + vbCrLf If Len(Refer) > 0 Then tosend = tosend + "Referer: " + Refer + vbCrLf If Len(Cookie) > 0 Then tosend = tosend + "Cookie:" + Cookie + vbCrLf If Len(UserAgent) > 0 Then tosend = tosend + "User-Agent: " + UserAgent + vbCrLf Else tosend = tosend + "User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)" + vbCrLf End If formlen = Len(postData) tosend = tosend + "Content-type: application/x-www-form-urlencoded" + vbCrLf + "Content-Length:" + Str(formlen) + vbCrLf + vbCrLf + postData + vbCrLf OutStreamBuffer = tosend Create_Post_Request = tosend ' written by IWiz mity@ropnet.ru End Function Public Function GetRedirection(Optional InComestr As String) As Variant Dim Locatstr As String Dim firstHoste As String Dim firstScript As String Dim locationPos As Long Dim Redirect(0 To 1) As String On Error GoTo errorhandler If InComestr = "" Then InComestr = mvarinStreamBuffer If InStr(1, LCase(InComestr), LCase("Location: "), vbTextCompare) = 0 Then Exit Function locationPos = InStr(1, LCase(InComestr), LCase("Location: "), vbTextCompare) Locatstr = Mid(InComestr, locationPos, InStr(locationPos, InComestr, vbCrLf, vbTextCompare) - locationPos) Locatstr = Right(Locatstr, Len(Locatstr) - Len("Location: ")) If Left(Locatstr, Len("http://")) = "http://" Then Locatstr = Right(Locatstr, Len(Locatstr) - Len("http://")) If InStr(1, Locatstr, "/") = 0 Then firstHoste = Locatstr Else firstHoste = Mid(Locatstr, 1, InStr(1, Locatstr, "/") - 1) firstScript = Right(Locatstr, Len(Locatstr) - Len(firstHoste)) End If Redirect(0) = firstHoste Redirect(1) = firstScript Else firstScript = Locatstr Redirect(1) = firstScript End If out: On Error GoTo 0 GetRedirection = Redirect Exit Function errorhandler: Resume out: ' written by IWiz mity@ropnet.ru End Function Public Function GetInfoHeader(Optional strData As String) As Integer Dim info As String Dim Brake1 As Integer Dim Brake2 As Integer Dim InfoLen As Integer On Error GoTo errorhandler If strData = "" Then strData = mvarinStreamBuffer If Left(strData, 8) = "HTTP/1.1" Or Left(strData, 8) = "HTTP/1.0" Then Brake1 = InStr(1, strData, " ", vbTextCompare) Brake2 = InStr(Brake1 + 1, strData, " ", vbTextCompare) InfoLen = Brake2 - Brake1 - 1 info = Mid(strData, Brake1 + 1, InfoLen) GetInfoHeader = CInt(info) End If out: On Error GoTo 0 Exit Function errorhandler: Resume out: ' written by IWiz mity@ropnet.ru End Function Public Function CookieChack(Optional strData As String, Optional UpdateCookie As String) As String Dim SetCookyPos As Long Dim BrakePos As Long Dim OldBrakePos As Long Dim CookieArray As Variant Dim i1 As Integer Dim CookieLen As Integer Dim switcher As Byte Dim FirstArray As Variant Dim char As String * 1 Dim TempCookie As String Dim tempCookie1 As String Dim cookie1() As CookieEntry On Error GoTo errorhandler If strData = "" Then strData = mvarinStreamBuffer If UpdateCookie = "" Then UpdateCookie = mvarCookie SetCookyPos = 1 BrakePos = 1 OldBrakePos = 1 If InStr(BrakePos, LCase(strData), LCase("Set-Cookie:"), vbTextCompare) = 0 Then Exit Function SetCookyPos = 1 BrakePos = 1 While SetCookyPos > 0 SetCookyPos = InStr(BrakePos, LCase(strData), LCase("Set-Cookie:"), vbTextCompare) If SetCookyPos > 0 Then BrakePos = InStr(SetCookyPos, strData, ";") If BrakePos = 0 Then BrakePos = InStr(SetCookyPos, strData, vbCrLf) End If CookieLen = BrakePos - SetCookyPos - Len("Set-Cookie:") TempCookie = TempCookie + Mid(strData, SetCookyPos + 11, CookieLen) + ";" End If Wend FirstArray = Split(TempCookie, ";") ReDim cookie1(0 To UBound(FirstArray)) For i = 0 To UBound(FirstArray) switcher = 1 For i1 = 1 To Len(FirstArray(i)) char = Mid(FirstArray(i), i1, 1) Select Case switcher Case 1 cookie1(i).name = cookie1(i).name + char Case 2 cookie1(i).body = cookie1(i).body + char End Select If char = "=" And switcher = 1 Then switcher = 2 Next SetCookyPos = 0 If cookie1(i).body = "" Then GoTo nextcookie If cookie1(i).name > "" Then SetCookyPos = InStr(1, LCase(UpdateCookie), LCase(cookie1(i).name)) If Not SetCookyPos = 0 Then If Right(UpdateCookie, 1) <> ";" Then UpdateCookie = UpdateCookie + ";" BrakePos = InStr(SetCookyPos, UpdateCookie, ";") UpdateCookie = Replace(UpdateCookie, Mid(UpdateCookie, SetCookyPos, BrakePos - SetCookyPos), cookie1(i).name + cookie1(i).body) FirstArray(i) = "" End If If FirstArray(i) > "" Then tempCookie1 = tempCookie1 + FirstArray(i) + ";" UpdateCookie = UpdateCookie + tempCookie1 nextcookie: Next CookieChack = UpdateCookie mvarCookie = CookieChack out: On Error GoTo 0 Exit Function errorhandler: Resume out ' written by IWiz mity@ropnet.ru End Function Public Function GetFileName(Optional ArrivedPocket) As String Dim SetDespPos As Long Dim DespFile As String Dim vbCrLfPos As Long Dim fnamelen On Error GoTo errorhandler If ArrivedPocket = "" Then ArrivedPocket = mvarinStreamBuffer SetDespPos = InStr(1, LCase(ArrivedPocket), LCase("filename="), vbTextCompare) If SetDespPos > 0 Then vbCrLfPos = InStr(SetDespPos, ArrivedPocket, vbCrLf) 'get first crlf ' ----------------------GET FILE NAME---------------------- fnamelen = vbCrLfPos - SetDespPos - Len("filename=") 'File Name len DespFile = Mid(ArrivedPocket, SetDespPos + Len("filename="), fnamelen) 'Get File Name End If DespFile = Replace(DespFile, ";", "") GetFileName = DespFile out: On Error GoTo 0 Exit Function errorhandler: Resume out ' written by IWiz mity@ropnet.ru End Function Public Function GetFileSize(Optional ArrivedPocket As String) As Long Dim setFilelenPos As Long Dim FileLen As String Dim vbCrLfPos As Long On Error GoTo errorhandler If ArrivedPocket = "" Then ArrivedPocket = mvarinStreamBuffer setFilelenPos = InStr(1, ArrivedPocket, "Content-Length: ", vbTextCompare) If setFilelenPos > 0 Then vbCrLfPos = InStr(setFilelenPos, ArrivedPocket, vbCrLf) FileLen = Mid(ArrivedPocket, setFilelenPos + Len("Content-Length: "), vbCrLfPos - setFilelenPos - Len("Content-Length: ")) 'get file size End If If Not IsNumeric(FileLen) Then GetFileSize = 0 Else GetFileSize = CLng(FileLen) End If out: On Error GoTo 0 Exit Function errorhandler: Resume out ' written by IWiz mity@ropnet.ru End Function Public Function GetRanges(Optional indata As String) As Long Dim RHeaderField As String Dim RStart As String Dim REnd As String Dim REntity As String Dim FStart As Integer If indata = "" Then indata = mvarinStreamBuffer FStart = InStr(1, indata, "Content-Range: bytes ") If FStart = 0 Then Exit Function 'Exit if no range RHeaderField = Mid(indata, FStart + Len("Content-Range: bytes "), InStr(FStart, indata, vbCrLf) - FStart - Len("Content-Range: bytes ")) RStart = Left(RHeaderField, InStr(1, RHeaderField, "-") - 1) GetRanges = CLng(RStart) ' written by IWiz mity@ropnet.ru End Function Public Sub RemoveHead() Dim ss As SuperString Dim xsplit As splitter Set ss = New SuperString ss.StringExpression = mvarinStreamBuffer Set xsplit = ss.sSplit(vbCrLf + vbCrLf, 2) mvarinStreamBuffer = xsplit(xsplit.Count).StringExpression ' written by IWiz mity@ropnet.ru End Sub Public Function OutStreamB() As Byte Dim buffer() As Byte For i = 1 To Len(mvarOutStreamBuffer) buffer(i) = CByte(Mid(mvarOutStreamBuffer, i, 1)) Next ' written by IWiz mity@ropnet.ru End Function