-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathxmlServerActions.bas
678 lines (434 loc) · 15.2 KB
/
xmlServerActions.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
Attribute VB_Name = "xmlServerActions"
Option Explicit
Private Type TGUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type
Public Const FLAG_ICC_FORCE_CONNECTION = &H1
Public Declare Function InternetCheckConnection Lib "wininet.dll" Alias "InternetCheckConnectionA" (ByVal lpszUrl As String, ByVal dwFlags As Long, ByVal dwReserved As Long) As Long
Private Declare Function OleLoadPicturePath Lib "oleaut32.dll" (ByVal szURLorPath As Long, ByVal punkCaller As Long, ByVal dwReserved As Long, ByVal clrReserved As OLE_COLOR, ByRef riid As TGUID, ByRef ppvRet As IPicture) As Long
Public Function LoadPicture(ByVal strFileName As String) As Picture
Dim IID As TGUID
On Error GoTo LoadPicture_Error
With IID
.Data1 = &H7BF80980
.Data2 = &HBF32
.Data3 = &H101A
.Data4(0) = &H8B
.Data4(1) = &HBB
.Data4(2) = &H0
.Data4(3) = &HAA
.Data4(4) = &H0
.Data4(5) = &H30
.Data4(6) = &HC
.Data4(7) = &HAB
End With
On Error GoTo ERR_LINE
OleLoadPicturePath StrPtr(strFileName), 0&, 0&, 0&, IID, LoadPicture
Exit Function
ERR_LINE:
Set LoadPicture = VB.LoadPicture(strFileName)
On Error GoTo 0
Exit Function
LoadPicture_Error:
writeError "Error " & Err.Number & " (" & Err.Description & ") in procedure LoadPicture of Module xmlServerActions" & vbCrLf & "HelpContext = " & Err.HelpContext & " Source = " & Err.Source
End Function
Public Function getResponse(url As String, myXml As String) As String
On Error GoTo ErRa
'If InternetCheckConnection(url, FLAG_ICC_FORCE_CONNECTION, 0&) = 0 Then
'getResponse = ""
'Else
Dim m As String
m = ""
'HTTP variable
Dim myHTTP As MSXML2.XMLHTTP
'HTTP object
Set myHTTP = CreateObject("msxml2.xmlhttp")
'create dom document variable ‘stores the xml to send
Dim myDom As MSXML2.DOMDocument
'Create the DomDocument Object
Set myDom = CreateObject("MSXML2.DOMDocument")
'Load entire Document before moving on
myDom.async = True
'xml string variable
'replace with location if sending from file or URL
'loads the xml
'change to .Load for file or url
myDom.loadXML (myXml)
'open the connection
myHTTP.open "post", url, True 'False true for asynchronous
myHTTP.setRequestHeader "Content-Type", "text/xml;charset=utf-8"
myHTTP.setRequestHeader "Connection", "keep-alive"
myDom.async = True
myDom.loadXML myXml
myHTTP.send myDom.xml
Do
DoEvents
If stopSignalNet = True Then GoTo ErRa
Loop While myHTTP.readyState <> 4
'Text6 = myDom.xml
'send the XML
'myHTTP.send (myDom.xml)
'Display the response
'while myhttp.status
m = myHTTP.responseText
Set myHTTP = Nothing
getResponse = m
'End If
Exit Function
ErRa:
On Error GoTo 0
Set myHTTP = Nothing
getResponse = ""
If Not Err.Number = 0 Then
writeError "Error " & Err.Number & " (" & Err.Description & ") in procedure getResponse of Module xmlServerActions" & vbCrLf & "HelpContext = " & Err.HelpContext & " Source = " & Err.Source
End If
End Function
Public Function loginXml() As String()
Dim str(3) As String
Dim ms As String, url As String, usrAgt As String, usr As String, pass As String, lang As String
Dim prefData As New ChilkatXml
On Error GoTo loginXml_Error
prefData.LoadXmlFile App.path & "\Data\Preferences.xml"
url = prefData.GetChildContent("apiURL")
usrAgt = prefData.GetChildContent("UserAgent")
usr = ""
pass = ""
lang = "en"
'MsgBox prefData.GetXml
'If InternetCheckConnection(url, FLAG_ICC_FORCE_CONNECTION, 0&) = 0 Then
'str(0) = "Not OK"
'str(1) = ""
'str(2) = ""
'str(3) = ""
'loginXml = str
'Exit Function
'End If
ms = "<methodCall>" & _
"<methodName>LogIn</methodName>" & _
"<params>" & _
"<param>" & _
"<value><string>" & usr & "</string></value>" & _
"</param>" & _
"<param>" & _
"<value><string>" & pass & "</string></value>" & _
"</param>" & _
"<param>" & _
"<value><string>" & lang & "</string></value>" & _
"</param>" & _
"<param>" & _
"<value><string>" & usrAgt & "</string></value>" & _
"</param>" & _
"</params>" & _
"</methodCall>"
Dim chk As New ChilkatXml
chk.loadXML ms
ms = chk.GetXml
Dim xF As New ChilkatXml
Dim xFc As New ChilkatXml
Dim i
xF.loadXML getResponse(url, ms)
Set xF = xF.GetChildWithTag("params")
Set xF = xF.GetChildWithTag("param")
Set xF = xF.GetChildWithTag("value")
Set xF = xF.GetChildWithTag("struct")
For i = 0 To 2
Set xFc = xF.GetNthChildWithTag("member", i)
Select Case (xFc.GetChildContent("name"))
Case "token"
Set xFc = xFc.GetChildWithTag("value")
str(1) = xFc.GetChildContent("string")
Case "status"
Set xFc = xFc.GetChildWithTag("value")
str(0) = xFc.GetChildContent("string")
Case "seconds"
Set xFc = xFc.GetChildWithTag("value")
str(2) = xFc.GetChildContent("double")
Case Else
str(0) = "0"
End Select
Next
str(3) = url
loginXml = str
'str(0)=status
'str(1)=token
'str(2)=seconds
'3 = url
On Error GoTo 0
Exit Function
loginXml_Error:
writeError "Error " & Err.Number & " (" & Err.Description & ") in procedure loginXml of Module xmlServerActions" & vbCrLf & "HelpContext = " & Err.HelpContext & " Source = " & Err.Source
End Function
Public Function checkMovieHashXml(url As String, token As String, Hash As String) As String()
Dim str(4) As String
'If InternetCheckConnection(url, FLAG_ICC_FORCE_CONNECTION, 0&) = 0 Then
'str(0) = "Not OK"
'str(1) = ""
'str(2) = ""
'str(3) = ""
'str(4) = ""
'checkMovieHashXml = str
'Exit Function
'End If
Dim ms As String
On Error GoTo checkMovieHashXml_Error
ms = "<methodCall>" & _
"<methodName>CheckMovieHash</methodName>" & _
"<params>" & _
"<param>" & _
"<value><string>" & token & "</string></value>" & _
"</param>" & _
"<param>" & _
"<value>" & _
"<array>" & _
"<data>" & _
"<value><string>" & Hash & "</string></value>" & _
"</data>" & _
"</array>" & _
"</value>" & _
"</param>" & _
"</params>" & _
"</methodCall>"
Dim chk As New ChilkatXml
chk.loadXML ms
ms = chk.GetXml
'Text6 = ms
''''''''''''
'MsgBox ms
'''''''''''
Dim xF As New ChilkatXml
Dim xFc As New ChilkatXml
Dim xFcC As New ChilkatXml
Dim i
xF.loadXML getResponse(url, ms)
Set xF = xF.GetChildWithTag("params")
Set xF = xF.GetChildWithTag("param")
Set xF = xF.GetChildWithTag("value")
Set xF = xF.GetChildWithTag("struct")
Dim skcm
For i = 0 To xF.NumChildrenHavingTag("member") - 1
Set xFc = xF.GetNthChildWithTag("member", i)
Select Case (xFc.GetChildContent("name"))
Case "status"
Set xFc = xFc.GetChildWithTag("value")
str(0) = xFc.GetChildContent("string")
Case "data"
Set xFc = xFc.GetChildWithTag("value")
Set xFc = xFc.GetChildWithTag("struct")
Set xFc = xFc.GetChildWithTag("member")
Set xFc = xFc.GetChildWithTag("value")
Set xFc = xFc.GetChildWithTag("struct")
For skcm = 0 To xFc.NumChildrenHavingTag("member") - 1
Set xFcC = xFc.GetNthChildWithTag("member", skcm)
Select Case (xFcC.GetChildContent("name"))
Case "MovieImdbID"
Set xFcC = xFcC.GetChildWithTag("value")
str(1) = xFcC.GetChildContent("string")
Case "MovieName"
Set xFcC = xFcC.GetChildWithTag("value")
str(2) = xFcC.GetChildContent("string")
Case "MovieHash"
Set xFcC = xFcC.GetChildWithTag("value")
str(3) = xFcC.GetChildContent("string")
End Select
Next
Case "seconds"
Set xFc = xFc.GetChildWithTag("value")
str(4) = xFc.GetChildContent("double")
End Select
Next
checkMovieHashXml = str
'0->status
'1->movie IMDB ID - is "" if not identified
'2->movie name - is "" if not identified
'3->movie hash
'4->seconds
On Error GoTo 0
Exit Function
checkMovieHashXml_Error:
writeError "Error " & Err.Number & " (" & Err.Description & ") in procedure checkMovieHashXml of Module xmlServerActions" & vbCrLf & "HelpContext = " & Err.HelpContext & " Source = " & Err.Source
End Function
Public Function getIMDBdetailsXml(url As String, token As String, id As String) As String()
Dim i, j
Dim moneLaddu
Dim str(13) As String
'If InternetCheckConnection(url, FLAG_ICC_FORCE_CONNECTION, 0&) = 0 Then
'str(0) = "Not OK"
'For moneLaddu = 1 To 13
'str(moneLaddu) = ""
'Next
'Exit Function
'End If
Dim ms As String
On Error GoTo getIMDBdetailsXml_Error
ms = "<methodCall>" & _
"<methodName>GetIMDBMovieDetails</methodName>" & _
"<params>" & _
"<param>" & _
"<value><string>" & token & "</string></value>" & _
"</param>" & _
"<param>" & _
"<value><string>" & id & "</string></value>" & _
"</param>" & _
"</params>" & _
"</methodCall>"
'getIMDBdetailsXml = getResponse(url, ms)
Dim chk As New ChilkatXml
chk.loadXML ms
ms = chk.GetXml
Dim xF As New ChilkatXml
Dim xFc As New ChilkatXml
Dim xFcC As New ChilkatXml
Dim nCh As New ChilkatXml
Dim v2 As New ChilkatXml
xF.loadXML htmlDecode(getResponse(url, ms))
Set xF = xF.GetChildWithTag("params")
Set xF = xF.GetChildWithTag("param")
Set xF = xF.GetChildWithTag("value")
Set xF = xF.GetChildWithTag("struct")
Dim i2, j2
For i = 0 To xF.NumChildrenHavingTag("member") - 1
Set xFc = xF.GetNthChildWithTag("member", i)
Select Case (xFc.GetChildContent("name"))
Case "status"
Set xFc = xFc.GetChildWithTag("value")
str(0) = xFc.GetChildContent("string")
Case "data"
Set xFc = xFc.GetChildWithTag("value")
Set xFc = xFc.GetChildWithTag("struct")
For j = 0 To xFc.NumChildrenHavingTag("member") - 1
Set xFcC = xFc.GetNthChildWithTag("member", j)
Select Case (xFcC.GetChildContent("name"))
Case "title"
Set nCh = xFcC.GetChildWithTag("value")
str(1) = nCh.GetChildContent("string")
Case "year"
Set nCh = xFcC.GetChildWithTag("value")
str(2) = nCh.GetChildContent("string")
Case "rating"
Set nCh = xFcC.GetChildWithTag("value")
str(3) = nCh.GetChildContent("string")
Case "language"
Set nCh = xFcC.GetChildWithTag("value")
Set nCh = nCh.GetChildWithTag("array")
Set nCh = nCh.GetChildWithTag("data")
str(4) = ""
For i2 = 0 To nCh.NumChildrenHavingTag("value") - 1
Set v2 = nCh.GetNthChildWithTag("value", i2)
str(4) = str(4) & v2.GetChildContent("string") & ", "
Next
If Right(str(4), 2) = ", " Then
str(4) = Left(str(4), Len(str(4)) - 2)
End If
Case "country"
Set nCh = xFcC.GetChildWithTag("value")
Set nCh = nCh.GetChildWithTag("array")
Set nCh = nCh.GetChildWithTag("data")
str(5) = ""
For i2 = 0 To nCh.NumChildrenHavingTag("value") - 1
Set v2 = nCh.GetNthChildWithTag("value", i2)
str(5) = str(5) & v2.GetChildContent("string") & ", "
Next
If Right(str(5), 2) = ", " Then
str(5) = Left(str(5), Len(str(5)) - 2)
End If
Case "duration"
Set nCh = xFcC.GetChildWithTag("value")
str(6) = nCh.GetChildContent("string")
Case "directors"
Set nCh = xFcC.GetChildWithTag("value")
Set nCh = nCh.GetChildWithTag("struct")
str(7) = ""
For j2 = 0 To nCh.NumChildrenHavingTag("member") - 1
Set v2 = nCh.GetNthChildWithTag("member", j2)
Set v2 = v2.GetChildWithTag("value")
str(7) = str(7) & v2.GetChildContent("string") & ", "
Next
If Right(str(7), 2) = ", " Then
str(7) = Left(str(7), Len(str(7)) - 2)
End If
Case "id"
Set nCh = xFcC.GetChildWithTag("value")
str(8) = nCh.GetChildContent("string")
Case "plot"
Set nCh = xFcC.GetChildWithTag("value")
str(9) = nCh.GetChildContent("string")
Case "genres"
Set nCh = xFcC.GetChildWithTag("value")
Set nCh = nCh.GetChildWithTag("array")
Set nCh = nCh.GetChildWithTag("data")
str(10) = ""
For i2 = 0 To nCh.NumChildrenHavingTag("value") - 1
Set v2 = nCh.GetNthChildWithTag("value", i2)
str(10) = str(10) & "<value>" & v2.GetChildContent("string") & "</value>" & vbNewLine
Next
Case "cover"
Set nCh = xFcC.GetChildWithTag("value")
str(11) = nCh.GetChildContent("string")
Case "cast"
Set nCh = xFcC.GetChildWithTag("value")
Set nCh = nCh.GetChildWithTag("struct")
str(13) = ""
For j2 = 0 To nCh.NumChildrenHavingTag("member") - 1
Set v2 = nCh.GetNthChildWithTag("member", j2)
Set v2 = v2.GetChildWithTag("value")
str(13) = str(13) & v2.GetChildContent("string") & ", "
Next
If Right(str(13), 2) = ", " Then
str(13) = Left(str(13), Len(str(13)) - 2)
End If
End Select
Next
End Select
Next
str(12) = ""
Dim cov As String, covLen As Long
If Not str(11) = "" Then
cov = str(11)
covLen = InStr(cov, "._")
cov = Left(cov, covLen - 1)
str(11) = cov & "._V1._SY150_CR0,0,102,150_.jpg"
str(12) = cov & "._V1._SY317_CR0,0,214,317_.jpg"
End If
getIMDBdetailsXml = str
On Error GoTo 0
Exit Function
getIMDBdetailsXml_Error:
writeError "Error " & Err.Number & " (" & Err.Description & ") in procedure getIMDBdetailsXml of Module xmlServerActions" & vbCrLf & "HelpContext = " & Err.HelpContext & " Source = " & Err.Source
End Function
Public Function logoutXml(url As String, token As String) As String
'If InternetCheckConnection(url, FLAG_ICC_FORCE_CONNECTION, 0&) = 0 Then
'Exit Function
'End If
Dim ms As String
On Error GoTo logoutXml_Error
ms = "<methodCall>" & _
"<methodName>LogOut</methodName>" & _
"<params>" & _
"<param>" & _
"<value><string>" & token & "</string></value>" & _
"</param>" & _
"</params>" & _
"</methodCall>"
logoutXml = getResponse(url, ms)
On Error GoTo 0
Exit Function
logoutXml_Error:
writeError "Error " & Err.Number & " (" & Err.Description & ") in procedure logoutXml of Module xmlServerActions" & vbCrLf & "HelpContext = " & Err.HelpContext & " Source = " & Err.Source
End Function
Public Function htmlDecode(strQ As String) As String
Dim i As Long
On Error GoTo htmlDecode_Error
For i = 1 To 255
strQ = Replace(strQ, "&#" & i & ";", ChrW(i), , , vbTextCompare)
strQ = Replace(strQ, "&#" & i & ";", ChrW(i), , , vbTextCompare)
Next
strQ = Replace(strQ, "See Full Summary", "", , , vbTextCompare)
htmlDecode = strQ
On Error GoTo 0
Exit Function
htmlDecode_Error:
writeError "Error " & Err.Number & " (" & Err.Description & ") in procedure htmlDecode of Module xmlServerActions" & vbCrLf & "HelpContext = " & Err.HelpContext & " Source = " & Err.Source
End Function