4 Persistable =
0 'NotPersistable
5 DataBindingBehavior =
0 'vbNone
6 DataSourceBehavior =
0 'vbNone
7 MTSTransactionMode =
0 'NotAnMTSObject
9 Attribute VB_Name = "AuroNet"
10 Attribute VB_GlobalNameSpace = False
11 Attribute VB_Creatable = True
12 Attribute VB_PredeclaredId = False
13 Attribute VB_Exposed = False
16 '--------------------------------------------------------------------------------
17 ' Componente : AuroNet
0.1
18 ' Projecto : Herramientas AuroWare
20 ' Descripción : Libreria de uso general para la interacción WEB
21 ' Depende de : cSocketMaster, modSocketMaster, modBasico, AuroNetConf
24 '
24/
06/
07 - UserAgent como propiedad
25 '
24/
06/
07 - Control de versión
26 '--------------------------------------------------------------------------------
29 Private WithEvents AuroSocket As CSocketMaster
30 Attribute AuroSocket.VB_VarHelpID = -
1
31 Private ErrorGeneral As Boolean
32 Private ExitoGeneral As Boolean
33 Private MiTag As String
34 Private pBuffer As String
36 Private Proxy As String
37 Private Proxy_Puerto As Integer
38 Private strHTTP As String
40 Public Function HTML_CONSULTAR() As Boolean
42 On Error GoTo HTML_CONSULTAR_Err
44 100 ExitoGeneral = False
45 101 ErrorGeneral = False
46 102 Debug.Print Time & "$ CONSULTAR - Inicio | " & URL
47 103 strHTTP = vbNullString
48 104 AuroSocket.Connect IIf(Proxy <> "", Proxy, HostDeURL) & pBuffer, IIf(Proxy <> "", Proxy_Puerto,
80)
52 106 Loop Until AuroSocket.State = sckConnected Or AuroSocket.State = sckError Or ErrorGeneral
54 107 If AuroSocket.State <> sckConnected Then
55 108 HTML_CONSULTAR = False
56 109 ExitoGeneral = False
57 110 ErrorGeneral = True
59 111 HTML_CONSULTAR = True
60 112 ExitoGeneral = True
61 113 ErrorGeneral = False
64 114 AuroSocket.CloseSck
65 115 Debug.Print Time & "$ CONSULTAR - Fin | " & HTML_CONSULTAR
69 Controlar_Error Erl, Err.Description, "Reseter.AuroNet.HTML_CONSULTAR.Ref
12/
2/
2008 :
09:
38:
32"
74 Public Function Exito()
76 On Error GoTo Exito_Err
78 100 Exito = ExitoGeneral
82 Controlar_Error Erl, Err.Description, "Reseter.AuroNet.Exito.Ref
12/
2/
2008 :
09:
38:
32"
87 Public Function HTML_GET(Optional Parametros As String) As String
89 On Error GoTo HTML_GET_Err
92 100 Debug.Print "$ GET - Inicio | " & URL & " | " & Now
93 101 AuroSocket.CloseSck
95 102 If IsMissing(Parametros) Then pBuffer = vbNullString Else pBuffer = Parametros
96 103 ErrorGeneral = False
97 104 ExitoGeneral = False
98 105 strHTTP = "GET " + IIf(Proxy <> "", URL, URLdeHost) & pBuffer + " HTTP/
1.0" + vbCrLf
99 106 strHTTP = strHTTP + "Accept: " + ACCEPT_TOKEN + vbCrLf
100 107 strHTTP = strHTTP + "Referer: " + HostDeURL + vbCrLf
101 108 strHTTP = strHTTP + "User-Agent: " + USERAGENT_TOKEN + vbCrLf
102 109 strHTTP = strHTTP + "Host: " + HostDeURL + vbCrLf
103 110 strHTTP = strHTTP + vbCrLf
104 111 AuroSocket.Connect IIf(Proxy <> "", Proxy, HostDeURL) & pBuffer, IIf(Proxy <> "", Proxy_Puerto,
80)
108 113 Loop Until ExitoGeneral Or ErrorGeneral
110 114 AuroSocket.CloseSck
111 Dim pRedireccion As Long
112 Dim Redireccion As String
113 Dim Cabeceras As String
114 115 Cabeceras = ObtenerCabeceras(pBuffer)
115 116 pRedireccion = InStr(
1, Cabeceras, "Location:")
117 117 If pRedireccion <>
0 Then
118 118 pRedireccion = pRedireccion + Len("Location:")
119 119 Redireccion = Trim$(Mid$(Cabeceras, pRedireccion, InStr(pRedireccion, Cabeceras, vbCrLf) - pRedireccion))
121 120 If URL <> Redireccion Then
122 121 Direccion = Redireccion
123 122 Debug.Print Time & "$ GET - Redirección | " & URL
128 124 HTML_GET = ObtenerHTML(pBuffer)
129 125 Debug.Print "$SOCKET HTML leido | " & Len(HTML_GET) & " | " & Now
131 126 If Len(pBuffer) <>
0 And ExitoGeneral = True And ErrorGeneral = False Then
132 127 ExitoGeneral = True
134 128 ErrorGeneral = True
140 Controlar_Error Erl, Err.Description, "Reseter.AuroNet.HTML_GET.Ref
12/
2/
2008 :
09:
38:
32"
145 Public Function IpLocal()
147 On Error GoTo IpLocal_Err
149 100 IpLocal = AuroSocket.LocalIP
153 Controlar_Error Erl, Err.Description, "Reseter.AuroNet.IpLocal.Ref
12/
2/
2008 :
09:
38:
32"
158 Private Function HostDeURL() As String
160 On Error GoTo HostDeURL_Err
162 100 HostDeURL = Replace$(Trim$(URL), "http://", vbNullString)
164 101 Init = InStr(
1, HostDeURL, "/", vbTextCompare)
166 102 If Init <>
0 Then HostDeURL = Left$(HostDeURL, Init -
1)
170 Controlar_Error Erl, Err.Description, "Reseter.AuroNet.HostDeURL.Ref
12/
2/
2008 :
09:
38:
32"
175 Private Function URLdeHost() As String
177 On Error GoTo URLdeHost_Err
179 100 URLdeHost = Replace$(Trim$(URL), "http://", vbNullString)
181 101 Init = InStr(
1, URLdeHost, "/", vbTextCompare)
183 102 If Init <>
0 Then URLdeHost = Mid$(URLdeHost, Init)
187 Controlar_Error Erl, Err.Description, "Reseter.AuroNet.URLdeHost.Ref
12/
2/
2008 :
09:
38:
32"
192 Private Sub AuroSocket_CloseSck()
194 On Error GoTo AuroSocket_CloseSck_Err
196 100 Debug.Print "$SOCKET - Cerrado" & " | " & Now
197 101 ExitoGeneral = True
200 AuroSocket_CloseSck_Err:
201 Controlar_Error Erl, Err.Description, "Reseter.AuroNet.AuroSocket_CloseSck.Ref
12/
2/
2008 :
09:
38:
32"
206 Private Sub AuroSocket_Connect()
208 On Error GoTo AuroSocket_Connect_Err
210 100 AuroSocket.SendData strHTTP
211 101 Debug.Print "$SOCKET - Datos enviados" & " | " & Now
214 AuroSocket_Connect_Err:
215 Controlar_Error Erl, Err.Description, "Reseter.AuroNet.AuroSocket_Connect.Ref
12/
2/
2008 :
09:
38:
32"
220 Private Sub AuroSocket_DataArrival(ByVal bytesTotal As Long)
222 On Error GoTo AuroSocket_DataArrival_Err
225 100 AuroSocket.GetData Pedazo
226 101 pBuffer = pBuffer & Pedazo
227 102 Debug.Print "$SOCKET - Respuesta recibida | " & AuroSocket.State & " | " & bytesTotal & " | " & Now
230 AuroSocket_DataArrival_Err:
231 Controlar_Error Erl, Err.Description, "Reseter.AuroNet.AuroSocket_DataArrival.Ref
12/
2/
2008 :
09:
38:
32"
236 Private Sub AuroSocket_Error(ByVal Number As Integer, _
237 Description As String, _
238 ByVal sCode As Long, _
239 ByVal Source As String, _
240 ByVal HelpFile As String, _
241 ByVal HelpContext As Long, _
242 CancelDisplay As Boolean)
244 On Error GoTo AuroSocket_Error_Err
246 100 Debug.Print "$SOCKET - ERROR!!!" & " | " & Now
247 101 ErrorGeneral = True
250 AuroSocket_Error_Err:
251 Controlar_Error Erl, Err.Description, "Reseter.AuroNet.AuroSocket_Error.Ref
12/
2/
2008 :
09:
38:
32"
256 Private Sub Class_Initialize()
258 On Error GoTo Class_Initialize_Err
260 100 USERAGENT_TOKEN = "Auronet " & AuroNetVer
261 101 Set AuroSocket = New CSocketMaster
264 Class_Initialize_Err:
265 Controlar_Error Erl, Err.Description, "Reseter.AuroNet.Class_Initialize.Ref
12/
2/
2008 :
09:
38:
32"
270 Private Sub Class_Terminate()
274 Set AuroSocket = Nothing
277 Public Property Get Direccion() As Variant
279 On Error GoTo Direccion_Err
285 Controlar_Error Erl, Err.Description, "Reseter.AuroNet.Direccion.Ref
12/
2/
2008 :
09:
38:
32"
290 Public Property Let Direccion(ByVal pDato As Variant)
292 On Error GoTo Direccion_Err
295 101 pDato = Replace$(pDato, "http://", "")
297 102 If InStr(
1, pDato, "/") =
0 Then URL = URL & "/"
301 Controlar_Error Erl, Err.Description, "Reseter.AuroNet.Direccion.Ref
12/
2/
2008 :
09:
38:
32"
306 Public Property Get error() As Variant
308 On Error GoTo error_Err
310 100 error = ErrorGeneral
314 Controlar_Error Erl, Err.Description, "Reseter.AuroNet.error.Ref
12/
2/
2008 :
09:
38:
32"
319 Public Property Let error(ByVal Estado As Variant)
321 On Error GoTo error_Err
323 100 ErrorGeneral = Estado
327 Controlar_Error Erl, Err.Description, "Reseter.AuroNet.error.Ref
12/
2/
2008 :
09:
38:
32"
332 Public Property Get Tag() As Variant
334 On Error GoTo Tag_Err
340 Controlar_Error Erl, Err.Description, "Reseter.AuroNet.Tag.Ref
12/
2/
2008 :
09:
38:
32"
345 Public Property Let Tag(ByVal Tag As Variant)
347 On Error GoTo Tag_Err
353 Controlar_Error Erl, Err.Description, "Reseter.AuroNet.Tag.Ref
12/
2/
2008 :
09:
38:
32"
358 Public Property Get Agente() As Variant
360 On Error GoTo Agente_Err
362 100 Agente = USERAGENT_TOKEN
366 Controlar_Error Erl, Err.Description, "Reseter.AuroNet.Agente.Ref
12/
2/
2008 :
09:
38:
32"
371 Public Property Let Agente(ByVal vNewValue As Variant)
373 On Error GoTo Agente_Err
375 100 USERAGENT_TOKEN = CStr(vNewValue)
379 Controlar_Error Erl, Err.Description, "Reseter.AuroNet.Agente.Ref
12/
2/
2008 :
09:
38:
32"
384 Private Function ObtenerCabeceras(HTML As String) As String
386 On Error GoTo ObtenerCabeceras_Err
389 100 Prueba = InStr(
1, HTML, vbCrLf & vbCrLf)
391 101 If Prueba <>
0 Then ObtenerCabeceras = Left$(HTML, Prueba)
394 ObtenerCabeceras_Err:
395 Controlar_Error Erl, Err.Description, "Reseter.AuroNet.ObtenerCabeceras.Ref
12/
2/
2008 :
09:
38:
32"
400 Private Function ObtenerHTML(HTML As String) As String
402 On Error GoTo ObtenerHTML_Err
405 100 Prueba = InStr(
1, HTML, vbCrLf & vbCrLf)
407 101 If Prueba <>
0 Then ObtenerHTML = Mid$(HTML, Prueba +
4)
411 Controlar_Error Erl, Err.Description, "Reseter.AuroNet.ObtenerHTML.Ref
12/
2/
2008 :
09:
38:
32"
416 Public Property Get Usar_Proxy() As Variant
418 On Error GoTo Usar_Proxy_Err
420 100 Usar_Proxy = Direccion
424 Controlar_Error Erl, Err.Description, "Reseter.AuroNet.Usar_Proxy.Ref
12/
2/
2008 :
09:
38:
32"
429 Public Property Let Usar_Proxy(ByVal Direccion As Variant)
431 On Error GoTo Usar_Proxy_Err
433 100 Proxy = CStr(Direccion)
437 Controlar_Error Erl, Err.Description, "Reseter.AuroNet.Usar_Proxy.Ref
12/
2/
2008 :
09:
38:
32"
442 Public Property Get Usar_Proxy_Puerto() As Variant
444 On Error GoTo Usar_Proxy_Puerto_Err
446 100 Usar_Proxy_Puerto = CStr(Proxy_Puerto)
449 Usar_Proxy_Puerto_Err:
450 Controlar_Error Erl, Err.Description, "Reseter.AuroNet.Usar_Proxy_Puerto.Ref
12/
2/
2008 :
09:
38:
32"
455 Public Property Let Usar_Proxy_Puerto(ByVal puerto As Variant)
457 On Error GoTo Usar_Proxy_Puerto_Err
459 100 Proxy_Puerto = CInt(puerto)
462 Usar_Proxy_Puerto_Err:
463 Controlar_Error Erl, Err.Description, "Reseter.AuroNet.Usar_Proxy_Puerto.Ref
12/
2/
2008 :
09:
38:
32"