-
Notifications
You must be signed in to change notification settings - Fork 6
/
Internet.xs
1637 lines (1521 loc) · 39.8 KB
/
Internet.xs
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
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Internet.CPP
* 07 Nov 96 by Aldo Calpini <[email protected]>
*
* XS interface to the Win32 Internet Functions (WININET.DLL)
* based on Registry.CPP written by Jesse Dougherty
*
* Version: 0.083 15 Apr 2008
*
*/
// Basic includes
#define WIN32_LEAN_AND_MEAN
// #include <math.h>
#include <windows.h>
// Extension specific includes
#include <wininet.h>
#include <winver.h>
#define __TEMP_WORD WORD /* perl defines a WORD, yikes! */
// Perl includes
#if (defined(__cplusplus) && !defined(PERL_OBJECT))
extern "C" {
#endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#if (defined(__cplusplus) && !defined(PERL_OBJECT))
}
#endif
#undef WORD
#define WORD __TEMP_WORD
#ifndef PERL_VERSION
# include "patchlevel.h"
# define PERL_REVISION 5
# define PERL_VERSION PATCHLEVEL
# define PERL_SUBVERSION SUBVERSION
#endif
#if PERL_REVISION == 5 && (PERL_VERSION < 4 || \
(PERL_VERSION == 4 && PERL_SUBVERSION <= 75))
# define PL_sv_undef sv_undef
# define PL_sv_yes sv_yes
# define PL_sv_no sv_no
# define PL_na na
# define PL_dowarn dowarn
#endif
// Section for the constant definitions.
#define CROAK croak
#define MAX_LENGTH 2048
#define TMPBUFSZ 1024
// VALUES FILLED IN BY PerlCallback
DWORD status = -1;
static time_t ft2timet(FILETIME *ft)
{
SYSTEMTIME st;
struct tm tm;
FileTimeToSystemTime(ft, &st);
tm.tm_sec = st.wSecond;
tm.tm_min = st.wMinute;
tm.tm_hour = st.wHour;
tm.tm_mday = st.wDay;
tm.tm_mon = st.wMonth - 1;
tm.tm_year = st.wYear - 1900;
tm.tm_wday = st.wDayOfWeek;
tm.tm_yday = -1;
tm.tm_isdst = -1;
return mktime (&tm);
}
#define SUCCESSRETURNED(x) (x == ERROR_SUCCESS)
#define INETRETURN(x) XSRETURN_IV(SUCCESSRETURNED(x))
#ifndef XST_mPVn
#define XST_mPVn(i,v,n) (ST(i) = sv_2mortal(newSVpv((v),(n))))
#endif
DWORD
constant(char *name, int arg) {
errno = 0;
switch (*name) {
case 'A':
break;
case 'B':
break;
case 'C':
break;
case 'D':
break;
case 'E':
break;
case 'F':
break;
case 'G':
break;
case 'H':
if(strncmp(name, "HTTP_", 5) == 0)
switch(name[5]) {
case 'A':
if (strEQ(name, "HTTP_ADDREQ_FLAG_ADD"))
#ifdef HTTP_ADDREQ_FLAG_ADD
return HTTP_ADDREQ_FLAG_ADD;
#else
goto not_there;
#endif
if (strEQ(name, "HTTP_ADDREQ_FLAG_REPLACE"))
#ifdef HTTP_ADDREQ_FLAG_REPLACE
return HTTP_ADDREQ_FLAG_REPLACE;
#else
goto not_there;
#endif
break;
case 'Q':
if(strncmp(name, "HTTP_QUERY_", 11) == 0)
switch(name[11]) {
case 'A':
if (strEQ(name, "HTTP_QUERY_ALLOW"))
#ifdef HTTP_QUERY_ALLOW
return HTTP_QUERY_ALLOW;
#else
goto not_there;
#endif
break;
case 'C':
if (strEQ(name, "HTTP_QUERY_CONTENT_DESCRIPTION"))
#ifdef HTTP_QUERY_CONTENT_DESCRIPTION
return HTTP_QUERY_CONTENT_DESCRIPTION;
#else
goto not_there;
#endif
if (strEQ(name, "HTTP_QUERY_CONTENT_ID"))
#ifdef HTTP_QUERY_CONTENT_ID
return HTTP_QUERY_CONTENT_ID;
#else
goto not_there;
#endif
if (strEQ(name, "HTTP_QUERY_CONTENT_LENGTH"))
#ifdef HTTP_QUERY_CONTENT_LENGTH
return HTTP_QUERY_CONTENT_LENGTH;
#else
goto not_there;
#endif
if (strEQ(name, "HTTP_QUERY_CONTENT_TRANSFER_ENCODING"))
#ifdef HTTP_QUERY_CONTENT_TRANSFER_ENCODING
return HTTP_QUERY_CONTENT_TRANSFER_ENCODING;
#else
goto not_there;
#endif
if (strEQ(name, "HTTP_QUERY_CONTENT_TYPE"))
#ifdef HTTP_QUERY_CONTENT_TYPE
return HTTP_QUERY_CONTENT_TYPE;
#else
goto not_there;
#endif
if (strEQ(name, "HTTP_QUERY_COST"))
#ifdef HTTP_QUERY_COST
return HTTP_QUERY_COST;
#else
goto not_there;
#endif
if (strEQ(name, "HTTP_QUERY_CUSTOM"))
#ifdef HTTP_QUERY_CUSTOM
return HTTP_QUERY_CUSTOM;
#else
goto not_there;
#endif
break;
case 'D':
if (strEQ(name, "HTTP_QUERY_DATE"))
#ifdef HTTP_QUERY_DATE
return HTTP_QUERY_DATE;
#else
goto not_there;
#endif
if (strEQ(name, "HTTP_QUERY_DERIVED_FROM"))
#ifdef HTTP_QUERY_DERIVED_FROM
return HTTP_QUERY_DERIVED_FROM;
#else
goto not_there;
#endif
break;
case 'E':
if (strEQ(name, "HTTP_QUERY_EXPIRES"))
#ifdef HTTP_QUERY_EXPIRES
return HTTP_QUERY_EXPIRES;
#else
goto not_there;
#endif
break;
case 'F':
if (strEQ(name, "HTTP_QUERY_FLAG_REQUEST_HEADERS"))
#ifdef HTTP_QUERY_FLAG_REQUEST_HEADERS
return HTTP_QUERY_FLAG_REQUEST_HEADERS;
#else
goto not_there;
#endif
if (strEQ(name, "HTTP_QUERY_FLAG_SYSTEMTIME"))
#ifdef HTTP_QUERY_FLAG_SYSTEMTIME
return HTTP_QUERY_FLAG_SYSTEMTIME;
#else
goto not_there;
#endif
break;
case 'L':
if (strEQ(name, "HTTP_QUERY_LANGUAGE"))
#ifdef HTTP_QUERY_LANGUAGE
return HTTP_QUERY_LANGUAGE;
#else
goto not_there;
#endif
if (strEQ(name, "HTTP_QUERY_LAST_MODIFIED"))
#ifdef HTTP_QUERY_LAST_MODIFIED
return HTTP_QUERY_LAST_MODIFIED;
#else
goto not_there;
#endif
break;
case 'M':
if (strEQ(name, "HTTP_QUERY_MESSAGE_ID"))
#ifdef HTTP_QUERY_MESSAGE_ID
return HTTP_QUERY_MESSAGE_ID;
#else
goto not_there;
#endif
if (strEQ(name, "HTTP_QUERY_MIME_VERSION"))
#ifdef HTTP_QUERY_MIME_VERSION
return HTTP_QUERY_MIME_VERSION;
#else
goto not_there;
#endif
break;
case 'P':
if (strEQ(name, "HTTP_QUERY_PRAGMA"))
#ifdef HTTP_QUERY_PRAGMA
return HTTP_QUERY_PRAGMA;
#else
goto not_there;
#endif
if (strEQ(name, "HTTP_QUERY_PUBLIC"))
#ifdef HTTP_QUERY_PUBLIC
return HTTP_QUERY_PUBLIC;
#else
goto not_there;
#endif
break;
case 'R':
if (strEQ(name, "HTTP_QUERY_RAW_HEADERS"))
#ifdef HTTP_QUERY_RAW_HEADERS
return HTTP_QUERY_RAW_HEADERS;
#else
goto not_there;
#endif
if (strEQ(name, "HTTP_QUERY_RAW_HEADERS_CRLF"))
#ifdef HTTP_QUERY_RAW_HEADERS_CRLF
return HTTP_QUERY_RAW_HEADERS_CRLF;
#else
goto not_there;
#endif
if (strEQ(name, "HTTP_QUERY_REQUEST_METHOD"))
#ifdef HTTP_QUERY_REQUEST_METHOD
return HTTP_QUERY_REQUEST_METHOD;
#else
goto not_there;
#endif
break;
case 'S':
if (strEQ(name, "HTTP_QUERY_SERVER"))
#ifdef HTTP_QUERY_SERVER
return HTTP_QUERY_SERVER;
#else
goto not_there;
#endif
if (strEQ(name, "HTTP_QUERY_STATUS_CODE"))
#ifdef HTTP_QUERY_STATUS_CODE
return HTTP_QUERY_STATUS_CODE;
#else
goto not_there;
#endif
if (strEQ(name, "HTTP_QUERY_STATUS_TEXT"))
#ifdef HTTP_QUERY_STATUS_TEXT
return HTTP_QUERY_STATUS_TEXT;
#else
goto not_there;
#endif
break;
case 'U':
if (strEQ(name, "HTTP_QUERY_URI"))
#ifdef HTTP_QUERY_URI
return HTTP_QUERY_URI;
#else
goto not_there;
#endif
if (strEQ(name, "HTTP_QUERY_USER_AGENT"))
#ifdef HTTP_QUERY_USER_AGENT
return HTTP_QUERY_USER_AGENT;
#else
goto not_there;
#endif
break;
case 'V':
if (strEQ(name, "HTTP_QUERY_VERSION"))
#ifdef HTTP_QUERY_VERSION
return HTTP_QUERY_VERSION;
#else
goto not_there;
#endif
break;
case 'W':
if (strEQ(name, "HTTP_QUERY_WWW_LINK"))
#ifdef HTTP_QUERY_WWW_LINK
return HTTP_QUERY_WWW_LINK;
#else
goto not_there;
#endif
break;
}
break;
}
break;
case 'I':
if(strncmp(name, "ICU_", 4) == 0)
switch(name[4]) {
case 'B':
if(strEQ(name, "ICU_BROWSER_MODE"))
#ifdef ICU_BROWSER_MODE
return ICU_BROWSER_MODE;
#else
goto not_there;
#endif
break;
case 'D':
if(strEQ(name, "ICU_DECODE"))
#ifdef ICU_DECODE
return ICU_DECODE;
#else
goto not_there;
#endif
break;
case 'E':
if(strEQ(name, "ICU_ENCODE_SPACES_ONLY"))
#ifdef ICU_ENCODE_SPACES_ONLY
return ICU_ENCODE_SPACES_ONLY;
#else
goto not_there;
#endif
if(strEQ(name, "ICU_ESCAPE"))
#ifdef ICU_ESCAPE
return ICU_ESCAPE;
#else
goto not_there;
#endif
break;
case 'N':
if(strEQ(name, "ICU_NO_ENCODE"))
#ifdef ICU_NO_ENCODE
return ICU_NO_ENCODE;
#else
goto not_there;
#endif
if(strEQ(name, "ICU_NO_META"))
#ifdef ICU_NO_META
return ICU_NO_META;
#else
goto not_there;
#endif
break;
case 'U':
if(strEQ(name, "ICU_USERNAME"))
#ifdef ICU_USERNAME
return ICU_USERNAME;
#else
goto not_there;
#endif
break;
}
if(strncmp(name, "INTERNET_", 9) == 0)
switch(name[9]) {
case 'F':
if(strEQ(name, "INTERNET_FLAG_PASSIVE"))
#ifdef INTERNET_FLAG_PASSIVE
return INTERNET_FLAG_PASSIVE;
#else
goto not_there;
#endif
if(strEQ(name, "INTERNET_FLAG_ASYNC"))
#ifdef INTERNET_FLAG_ASYNC
return INTERNET_FLAG_ASYNC;
#else
goto not_there;
#endif
if(strEQ(name, "INTERNET_FLAG_HYPERLINK"))
#ifdef INTERNET_FLAG_HYPERLINK
return INTERNET_FLAG_HYPERLINK;
#else
goto not_there;
#endif
if(strEQ(name, "INTERNET_FLAG_KEEP_CONNECTION"))
#ifdef INTERNET_FLAG_KEEP_CONNECTION
return INTERNET_FLAG_KEEP_CONNECTION;
#else
goto not_there;
#endif
if(strEQ(name, "INTERNET_FLAG_MAKE_PERSISTENT"))
#ifdef INTERNET_FLAG_MAKE_PERSISTENT
return INTERNET_FLAG_MAKE_PERSISTENT;
#else
goto not_there;
#endif
if(strEQ(name, "INTERNET_FLAG_NO_AUTH"))
#ifdef INTERNET_FLAG_NO_AUTH
return INTERNET_FLAG_NO_AUTH;
#else
goto not_there;
#endif
if(strEQ(name, "INTERNET_FLAG_NO_AUTO_REDIRECT"))
#ifdef INTERNET_FLAG_NO_AUTO_REDIRECT
return INTERNET_FLAG_NO_AUTO_REDIRECT;
#else
goto not_there;
#endif
if(strEQ(name, "INTERNET_FLAG_NO_CACHE_WRITE"))
#ifdef INTERNET_FLAG_NO_CACHE_WRITE
return INTERNET_FLAG_NO_CACHE_WRITE;
#else
goto not_there;
#endif
if(strEQ(name, "INTERNET_FLAG_NO_COOKIES"))
#ifdef INTERNET_FLAG_NO_COOKIES
return INTERNET_FLAG_NO_COOKIES;
#else
goto not_there;
#endif
if(strEQ(name, "INTERNET_FLAG_READ_PREFETCH"))
#ifdef INTERNET_FLAG_READ_PREFETCH
return INTERNET_FLAG_READ_PREFETCH;
#else
goto not_there;
#endif
if(strEQ(name, "INTERNET_FLAG_RELOAD"))
#ifdef INTERNET_FLAG_RELOAD
return INTERNET_FLAG_RELOAD;
#else
goto not_there;
#endif
if(strEQ(name, "INTERNET_FLAG_RESYNCHRONIZE"))
#ifdef INTERNET_FLAG_RESYNCHRONIZE
return INTERNET_FLAG_RESYNCHRONIZE;
#else
goto not_there;
#endif
if(strEQ(name, "INTERNET_FLAG_TRANSFER_ASCII"))
#ifdef INTERNET_FLAG_TRANSFER_ASCII
return INTERNET_FLAG_TRANSFER_ASCII;
#else
goto not_there;
#endif
if(strEQ(name, "INTERNET_FLAG_TRANSFER_BINARY"))
#ifdef INTERNET_FLAG_TRANSFER_BINARY
return INTERNET_FLAG_TRANSFER_BINARY;
#else
goto not_there;
#endif
break;
case 'I':
if(strEQ(name, "INTERNET_INVALID_PORT_NUMBER"))
#ifdef INTERNET_INVALID_PORT_NUMBER
return (DWORD) INTERNET_INVALID_PORT_NUMBER;
#else
goto not_there;
#endif
if(strEQ(name, "INTERNET_INVALID_STATUS_CALLBACK"))
#ifdef INTERNET_INVALID_STATUS_CALLBACK
return (DWORD) INTERNET_INVALID_STATUS_CALLBACK;
#else
goto not_there;
#endif
break;
case 'O':
if(strncmp(name,"INTERNET_OPEN_TYPE_",19) == 0)
switch(name[19]) {
case 'D':
if(strEQ(name, "INTERNET_OPEN_TYPE_DIRECT"))
#ifdef INTERNET_OPEN_TYPE_DIRECT
return INTERNET_OPEN_TYPE_DIRECT;
#else
goto not_there;
#endif
break;
case 'P':
if(strEQ(name, "INTERNET_OPEN_TYPE_PROXY"))
#ifdef INTERNET_OPEN_TYPE_PROXY
return INTERNET_OPEN_TYPE_PROXY;
#else
goto not_there;
#endif
if(strEQ(name, "INTERNET_OPEN_TYPE_PROXY_PRECONFIG"))
#ifdef INTERNET_OPEN_TYPE_PROXY_PRECONFIG
return INTERNET_OPEN_TYPE_PROXY_PRECONFIG;
#else
goto not_there;
#endif
break;
}
if(strncmp(name,"INTERNET_OPTION_",16) == 0)
switch(name[16]) {
case 'C':
if(strEQ(name, "INTERNET_OPTION_CONNECT_BACKOFF"))
#ifdef INTERNET_OPTION_CONNECT_BACKOFF
return INTERNET_OPTION_CONNECT_BACKOFF;
#else
goto not_there;
#endif
if (strEQ(name, "INTERNET_OPTION_CONNECT_RETRIES"))
#ifdef INTERNET_OPTION_CONNECT_RETRIES
return INTERNET_OPTION_CONNECT_RETRIES;
#else
goto not_there;
#endif
if (strEQ(name, "INTERNET_OPTION_CONNECT_TIMEOUT"))
#ifdef INTERNET_OPTION_CONNECT_TIMEOUT
return INTERNET_OPTION_CONNECT_TIMEOUT;
#else
goto not_there;
#endif
if (strEQ(name, "INTERNET_OPTION_CONTROL_SEND_TIMEOUT"))
#ifdef INTERNET_OPTION_CONTROL_SEND_TIMEOUT
return INTERNET_OPTION_CONTROL_SEND_TIMEOUT;
#else
goto not_there;
#endif
if (strEQ(name, "INTERNET_OPTION_CONTROL_RECEIVE_TIMEOUT"))
#ifdef INTERNET_OPTION_CONTROL_RECEIVE_TIMEOUT
return INTERNET_OPTION_CONTROL_RECEIVE_TIMEOUT;
#else
goto not_there;
#endif
break;
case 'D':
if(strEQ(name, "INTERNET_OPTION_DATA_SEND_TIMEOUT"))
#ifdef INTERNET_OPTION_DATA_SEND_TIMEOUT
return INTERNET_OPTION_DATA_SEND_TIMEOUT;
#else
goto not_there;
#endif
if (strEQ(name, "INTERNET_OPTION_DATA_RECEIVE_TIMEOUT"))
#ifdef INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
return INTERNET_OPTION_DATA_RECEIVE_TIMEOUT;
#else
goto not_there;
#endif
break;
case 'H':
if(strEQ(name, "INTERNET_OPTION_HANDLE_TYPE"))
#ifdef INTERNET_OPTION_HANDLE_TYPE
return INTERNET_OPTION_HANDLE_TYPE;
#else
goto not_there;
#endif
break;
case 'L':
if (strEQ(name, "INTERNET_OPTION_LISTEN_TIMEOUT"))
#ifdef INTERNET_OPTION_LISTEN_TIMEOUT
return INTERNET_OPTION_LISTEN_TIMEOUT;
#else
goto not_there;
#endif
break;
case 'P':
if (strEQ(name, "INTERNET_OPTION_PASSWORD"))
#ifdef INTERNET_OPTION_PASSWORD
return INTERNET_OPTION_PASSWORD;
#else
goto not_there;
#endif
break;
case 'R':
if (strEQ(name, "INTERNET_OPTION_READ_BUFFER_SIZE"))
#ifdef INTERNET_OPTION_READ_BUFFER_SIZE
return INTERNET_OPTION_READ_BUFFER_SIZE;
#else
goto not_there;
#endif
break;
case 'U':
if (strEQ(name, "INTERNET_OPTION_USERNAME"))
#ifdef INTERNET_OPTION_USERNAME
return INTERNET_OPTION_USERNAME;
#else
goto not_there;
#endif
if (strEQ(name, "INTERNET_OPTION_USER_AGENT"))
#ifdef INTERNET_OPTION_USER_AGENT
return INTERNET_OPTION_USER_AGENT;
#else
goto not_there;
#endif
break;
case 'V':
if (strEQ(name, "INTERNET_OPTION_VERSION"))
#ifdef INTERNET_OPTION_VERSION
return INTERNET_OPTION_VERSION;
#else
goto not_there;
#endif
break;
case 'W':
if (strEQ(name, "INTERNET_OPTION_WRITE_BUFFER_SIZE"))
#ifdef INTERNET_OPTION_WRITE_BUFFER_SIZE
return INTERNET_OPTION_WRITE_BUFFER_SIZE;
#else
goto not_there;
#endif
break;
}
break;
case 'S':
if (strEQ(name, "INTERNET_SERVICE_FTP"))
#ifdef INTERNET_SERVICE_FTP
return INTERNET_SERVICE_FTP;
#else
goto not_there;
#endif
if (strEQ(name, "INTERNET_SERVICE_GOPHER"))
#ifdef INTERNET_SERVICE_GOPHER
return INTERNET_SERVICE_GOPHER;
#else
goto not_there;
#endif
if (strEQ(name, "INTERNET_SERVICE_HTTP"))
#ifdef INTERNET_SERVICE_HTTP
return INTERNET_SERVICE_HTTP;
#else
goto not_there;
#endif
if (strEQ(name, "INTERNET_STATUS_RESOLVING_NAME"))
#ifdef INTERNET_STATUS_RESOLVING_NAME
return INTERNET_STATUS_RESOLVING_NAME;
#else
goto not_there;
#endif
if (strEQ(name, "INTERNET_STATUS_NAME_RESOLVED"))
#ifdef INTERNET_STATUS_NAME_RESOLVED
return INTERNET_STATUS_NAME_RESOLVED;
#else
goto not_there;
#endif
if (strEQ(name, "INTERNET_STATUS_CONNECTING_TO_SERVER"))
#ifdef INTERNET_STATUS_CONNECTING_TO_SERVER
return INTERNET_STATUS_CONNECTING_TO_SERVER;
#else
goto not_there;
#endif
if (strEQ(name, "INTERNET_STATUS_CONNECTED_TO_SERVER"))
#ifdef INTERNET_STATUS_CONNECTED_TO_SERVER
return INTERNET_STATUS_CONNECTED_TO_SERVER;
#else
goto not_there;
#endif
if (strEQ(name, "INTERNET_STATUS_SENDING_REQUEST"))
#ifdef INTERNET_STATUS_SENDING_REQUEST
return INTERNET_STATUS_SENDING_REQUEST;
#else
goto not_there;
#endif
if (strEQ(name, "INTERNET_STATUS_REQUEST_SENT"))
#ifdef INTERNET_STATUS_REQUEST_SENT
return INTERNET_STATUS_REQUEST_SENT;
#else
goto not_there;
#endif
if (strEQ(name, "INTERNET_STATUS_RECEIVING_RESPONSE"))
#ifdef INTERNET_STATUS_RECEIVING_RESPONSE
return INTERNET_STATUS_RECEIVING_RESPONSE;
#else
goto not_there;
#endif
if (strEQ(name, "INTERNET_STATUS_RESPONSE_RECEIVED"))
#ifdef INTERNET_STATUS_RESPONSE_RECEIVED
return INTERNET_STATUS_RESPONSE_RECEIVED;
#else
goto not_there;
#endif
if (strEQ(name, "INTERNET_STATUS_REDIRECT"))
#ifdef INTERNET_STATUS_REDIRECT
return INTERNET_STATUS_REDIRECT;
#else
goto not_there;
#endif
if (strEQ(name, "INTERNET_STATUS_CLOSING_CONNECTION"))
#ifdef INTERNET_STATUS_CLOSING_CONNECTION
return INTERNET_STATUS_CLOSING_CONNECTION;
#else
goto not_there;
#endif
if (strEQ(name, "INTERNET_STATUS_CONNECTION_CLOSED"))
#ifdef INTERNET_STATUS_CONNECTION_CLOSED
return INTERNET_STATUS_CONNECTION_CLOSED;
#else
goto not_there;
#endif
if (strEQ(name, "INTERNET_STATUS_HANDLE_CREATED"))
#ifdef INTERNET_STATUS_HANDLE_CREATED
return INTERNET_STATUS_HANDLE_CREATED;
#else
goto not_there;
#endif
if (strEQ(name, "INTERNET_STATUS_HANDLE_CLOSING"))
#ifdef INTERNET_STATUS_HANDLE_CLOSING
return INTERNET_STATUS_HANDLE_CLOSING;
#else
goto not_there;
#endif
if (strEQ(name, "INTERNET_STATUS_REQUEST_COMPLETE"))
#ifdef INTERNET_STATUS_REQUEST_COMPLETE
return INTERNET_STATUS_REQUEST_COMPLETE;
#else
goto not_there;
#endif
break;
}
break;
case 'J':
break;
case 'K':
break;
case 'L':
break;
case 'M':
break;
case 'N':
break;
case 'O':
break;
case 'P':
break;
case 'Q':
break;
case 'R':
break;
case 'S':
break;
case 'T':
break;
case 'U':
break;
case 'V':
break;
case 'W':
break;
case 'X':
break;
case 'Y':
break;
case 'Z':
break;
}
errno = EINVAL;
return 0;
not_there:
errno = ENOENT;
return 0;
}
void WINAPI CALLBACK
PerlCallback(HINTERNET h,
DWORD context,
DWORD mystatus,
LPVOID mystatusinfo,
DWORD mystatuslength) {
DWORD myret;
HINTERNET myhandle;
/*
// Tried to simply set a variable in Perl
// with the status info for this context,
// but it fails with:
// Modification of a read-only value attempted at testcallback.pl line 10.
char mytmp[80];
char mystring[80];
SV* myvar;
SV* myvarcheck;
// ultoa((DWORD) h, mystring, 10);
// strncat(mystring, ".", 1);
// ultoa((DWORD) context, mytmp, 10);
// strcat(mystring, mytmp);
// // why the handle?
ultoa((DWORD) context, mystring, 10);
printf("PerlCallback: got context=%d mystring=%s\n",context,mystring);
myvar=perl_get_sv(mystring, FALSE);
if(myvar==NULL) {
printf("PerlCallback: creating new var...\n");
myvar=perl_get_sv(mystring, TRUE | 0x02);
}
if(!SvOK(myvar)) printf("PerlCallback: var is NOT defined...\n");
myvarcheck=perl_get_sv(mystring, FALSE);
if(myvarcheck==NULL) printf("PerlCallback: var does not exist!\n");
if(myvarcheck==myvar) printf("PerlCallback: var exists...\n");
printf("PerlCallback: populating var...\n");
sv_setiv(myvar, mystatus);
printf("PerlCallback: returning...\n");
*/
// Let's try with perl_call_method
// ...to clarify:
// a C routine
// called from Perl
// callbacks this C routine
// that callbacks a Perl routine.
// ;)
// if(mystatus!=status) {
dSP;
ENTER;
SAVETMPS;
PUSHMARK(sp);
// XPUSHs(sv_2mortal(newSVpv("Win32::Internet\0",0)));
XPUSHs(sv_2mortal(newSViv(context)));
XPUSHs(sv_2mortal(newSViv(mystatus)));
switch(mystatus) {
case INTERNET_STATUS_HANDLE_CREATED:
myhandle=(HINTERNET) *(LPHINTERNET)mystatusinfo;
XPUSHs(sv_2mortal(newSViv((DWORD) myhandle)));
break;
case INTERNET_STATUS_RESPONSE_RECEIVED:
case INTERNET_STATUS_REQUEST_SENT:
myret=(DWORD) *(LPDWORD)mystatusinfo;
// printf("PerlCallback: received/sent(%d) %d bytes\n",mystatus,myret);
XPUSHs(sv_2mortal(newSViv(myret)));
break;
default:
XPUSHs(sv_2mortal(newSViv(0)));
break;
}
PUTBACK;
// printf("PerlCallback: calling callback with context=%d, status=%d\n",context,mystatus);
perl_call_pv("Win32::Internet::callback", G_DISCARD);
FREETMPS;
LEAVE;
// }
// status=mystatus;
// return;
}
MODULE = Win32::Internet PACKAGE = Win32::Internet
PROTOTYPES: DISABLE
DWORD
constant(name,arg)
char *name
int arg
CODE:
RETVAL = constant(name, arg);
OUTPUT:
RETVAL
long
InternetSetStatusCallback(handle)
HINTERNET handle
CODE:
RETVAL = (long)InternetSetStatusCallback(handle, PerlCallback);
OUTPUT:
RETVAL
HINTERNET
InternetOpen(agent,type,proxy,proxybypass,flags)
LPCTSTR agent
DWORD type
LPCTSTR proxy
LPCTSTR proxybypass
DWORD flags
CODE:
RETVAL = InternetOpen(agent,type,proxy,proxybypass,flags);
OUTPUT:
RETVAL
void
InternetGetLastResponseInfo()
PPCODE:
DWORD myerrnum;
unsigned char mybuf[TMPBUFSZ*2];
DWORD mybufsz = sizeof(mybuf);
if (InternetGetLastResponseInfo(&myerrnum, (LPTSTR) &mybuf, &mybufsz)) {
// printf("InternetGetLastResponseInfo: myerrnum=%d\n",myerrnum);
// printf("InternetGetLastResponseInfo: mybuf=%s\n",mybuf);
XPUSHs(sv_2mortal(newSViv(myerrnum)));
XPUSHs(sv_2mortal(newSVpv((char *) &mybuf,0)));
}
else {
XPUSHs(&PL_sv_no);
}
void
InternetQueryDataAvailable(handle)
HINTERNET handle
PPCODE:
DWORD mydatalen;
if (InternetQueryDataAvailable(handle, &mydatalen, 0, 0))
XSRETURN_IV((long) mydatalen);
else
XSRETURN_NO;
void
InternetReadFile(handle,size)
HINTERNET handle
DWORD size
PPCODE:
char *mybuf;
DWORD myread;
mybuf=(char *)safemalloc(size+1);
if (InternetReadFile(handle, mybuf, size, &myread))
XPUSHs(sv_2mortal(newSVpv(mybuf,myread)));
else
XPUSHs(&PL_sv_no);
safefree(mybuf);
void
InternetDllVersion()
PPCODE:
DWORD infosize;
DWORD zero;
void *ver;
void *verbuf;
BOOL myerror;
// Attempting to get WININET.DLL true version
infosize = GetFileVersionInfoSize("WININET.DLL\0",&zero);
// printf("InternetQueryVersion: GetFileVersionInfoSize.result=%d\n",infosize);
ver = (void *)safemalloc(infosize);
myerror = GetFileVersionInfo("WININET.DLL\0",zero,infosize,(LPVOID)ver);
// printf("InternetQueryVersion: GetFileVersionInfo.result=%d\n",myerror);
if (VerQueryValue(ver,
TEXT("\\StringFileInfo\\040904B0\\FileVersion"),
&verbuf,
(PUINT) &infosize))
{
// TEXT("\\VarFileInfo\\Translation"), // returns 040904B0, hope it is always true
// printf("InternetQueryVersion: VerQueryValue.result=%d\n",myerror);
// printf("InternetQueryVersion: infosize=%d\n",infosize);
// printf("InternetQueryVersion: verbuf=%s\n",verbuf);
XPUSHs(sv_2mortal(newSVpv((char *)verbuf,infosize)));
} else {
XPUSHs(&PL_sv_no);
}
safefree((char *)ver);
void
InternetQueryOption(handle,option)
HINTERNET handle
DWORD option
PPCODE:
char *mybuf;
long mybufsz = 16000;
DWORD mynum;
unsigned char myc;
int i;
mybuf=(char *)safemalloc(mybufsz);
if (InternetQueryOption(handle, option, mybuf, (DWORD*)&mybufsz)) {
switch (option) {
case INTERNET_OPTION_VERSION:
// returns an array
XST_mIV(0,((LPINTERNET_VERSION_INFO)mybuf)->dwMajorVersion);
XST_mIV(1,((LPINTERNET_VERSION_INFO)mybuf)->dwMinorVersion);
safefree((char *)mybuf);
XSRETURN(2);
break;
case INTERNET_OPTION_CONNECT_TIMEOUT:
case INTERNET_OPTION_CONNECT_RETRIES:
case INTERNET_OPTION_CONNECT_BACKOFF:
case INTERNET_OPTION_CONTROL_RECEIVE_TIMEOUT:
case INTERNET_OPTION_CONTROL_SEND_TIMEOUT:
case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT:
case INTERNET_OPTION_DATA_SEND_TIMEOUT:
case INTERNET_OPTION_LISTEN_TIMEOUT: