forked from pgul/binkd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
perlhooks.c
2476 lines (2358 loc) · 79.1 KB
/
perlhooks.c
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
/*
* perlhooks.c -- perl-hooks interface
*
* perlhooks.c is a part of binkd project
*
* Copyright (C) 2003 val khokhlov, FIDONet 2:550/180
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. See COPYING.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <fcntl.h>
#ifdef HAVE_FORK
#include <sys/wait.h>
#endif
#ifdef OS2
#ifdef PERLDL
#define INCL_DOSMODULEMGR
#endif
#define INCL_DOSPROCESS
#include <os2.h>
#endif
#ifdef _MSC_VER
#undef __STDC__
#endif
#include <sys/types.h>
#include <sys/stat.h>
#if defined(__NT__) && !defined(WIN32) /* WIN32 needed for perl-core include files */
# define WIN32
#endif
#ifdef WIN32
# define NO_XSLOCKS
#endif
#ifndef EXTERN_C
# define EXTERN_C extern
#endif
/* ---------------- binkd stuff --------------- */
#include "sys.h"
#include "readcfg.h"
#include "tools.h"
#include "ftnaddr.h"
#include "ftnq.h"
#include "ftnnode.h"
#include "readflo.h"
#include "iphdr.h"
#include "protoco2.h"
#include "sem.h"
#include "protocol.h"
#include "common.h"
#include "perlhooks.h"
#include "rfc2553.h"
/* ---------------- perl stuff --------------- */
/* dynamic load */
#ifdef PERLDL
# define Perl_sv_2pv (hl_Perl_sv_2pv)
# define Perl_sv_2pv_flags (hl_Perl_sv_2pv_flags)
# define Perl_sv_2uv (hl_Perl_sv_2uv)
# define Perl_sv_2uv_flags (hl_Perl_sv_2uv_flags)
# define Perl_sv_2iv (hl_Perl_sv_2iv)
# define Perl_sv_2iv_flags (hl_Perl_sv_2iv_flags)
# define Perl_sv_setsv (hl_Perl_sv_setsv)
# define Perl_sv_setsv_flags (hl_Perl_sv_setsv_flags)
# define Perl_sv_2mortal (*dl_Perl_sv_2mortal)
# define Perl_newSViv (*dl_Perl_newSViv)
# define Perl_av_store (*dl_Perl_av_store)
# define Perl_av_fetch (*dl_Perl_av_fetch)
# define Perl_av_len (*dl_Perl_av_len)
# define Perl_newXS (*dl_Perl_newXS)
# define Perl_sv_2bool (*dl_Perl_sv_2bool)
# define perl_run (*dl_perl_run)
# define Perl_sv_setiv (*dl_Perl_sv_setiv)
# define perl_free (*dl_perl_free)
# define perl_destruct (*dl_perl_destruct)
# define perl_parse (*dl_perl_parse)
# define perl_construct (*dl_perl_construct)
# define perl_alloc (*dl_perl_alloc)
# define Perl_newAV (*dl_Perl_newAV)
# define Perl_av_push (*dl_Perl_av_push)
# define Perl_av_clear (*dl_Perl_av_clear)
# define Perl_newRV_noinc (*dl_Perl_newRV_noinc)
# define Perl_newHV (*dl_Perl_newHV)
# define Perl_hv_store (*dl_Perl_hv_store)
# define Perl_newSVpv (*dl_Perl_newSVpv)
# define Perl_hv_clear (*dl_Perl_hv_clear)
# define Perl_push_scope (*dl_Perl_push_scope)
# define Perl_pop_scope (*dl_Perl_pop_scope)
# define Perl_free_tmps (*dl_Perl_free_tmps)
# define Perl_markstack_grow (*dl_Perl_markstack_grow)
# define Perl_save_int (*dl_Perl_save_int)
# define Perl_sv_setpv (*dl_Perl_sv_setpv)
# define Perl_sv_setpvn (*dl_Perl_sv_setpvn)
# define Perl_av_undef (*dl_Perl_av_undef)
# define Perl_hv_fetch (*dl_Perl_hv_fetch)
# define Perl_eval_pv (*dl_Perl_eval_pv)
# define Perl_newRV (*dl_Perl_newRV)
# define Perl_sv_free (*dl_Perl_sv_free)
# define Perl_sv_free2 (*dl_Perl_sv_free2)
# define Perl_hv_common_key_len (*dl_Perl_hv_common_key_len)
# define Perl_sys_init3 (*dl_Perl_sys_init3)
#ifdef OS2
# define PL_errgv (*dl_PL_errgv)
# define PL_stack_sp (*dl_PL_stack_sp)
# define PL_markstack_ptr (*dl_PL_markstack_ptr)
# define PL_sv_undef (*dl_PL_sv_undef)
# define PL_stack_base (*dl_PL_stack_base)
# define PL_markstack_max (*dl_PL_markstack_max)
# define PL_tmps_ix (*dl_PL_tmps_ix)
# define PL_tmps_floor (*dl_PL_tmps_floor)
# define PL_diehook (*dl_PL_diehook)
# define PL_warnhook (*dl_PL_warnhook)
# define Perl_sv_setpvf (*dl_Perl_sv_setpvf)
# define perl_get_sv (*dl_perl_get_sv)
# define perl_get_av (*dl_perl_get_av)
# define perl_get_hv (*dl_perl_get_hv)
# define perl_get_cv (*dl_perl_get_cv)
# define perl_call_pv (*dl_perl_call_pv)
#else
# define Perl_Ierrgv_ptr (*dl_Perl_Ierrgv_ptr)
# define Perl_Isv_undef_ptr (*dl_Perl_Isv_undef_ptr)
# define Perl_Tstack_sp_ptr (*dl_Perl_Tstack_sp_ptr)
# define Perl_Tmarkstack_ptr_ptr (*dl_Perl_Tmarkstack_ptr_ptr)
# define Perl_Tstack_base_ptr (*dl_Perl_Tstack_base_ptr)
# define Perl_Tmarkstack_max_ptr (*dl_Perl_Tmarkstack_max_ptr)
# define Perl_Ttmps_ix_ptr (*dl_Perl_Ttmps_ix_ptr)
# define Perl_Ttmps_floor_ptr (*dl_Perl_Ttmps_floor_ptr)
# define Perl_Tscopestack_ix_ptr (*dl_Perl_Tscopestack_ix_ptr)
# define Perl_Tmarkstack_ptr (*dl_Perl_Tmarkstack_ptr)
# define Perl_TXpv_ptr (*dl_Perl_TXpv_ptr)
# define Perl_Istack_base_ptr (*dl_Perl_Istack_base_ptr)
# define Perl_Istack_sp_ptr (*dl_Perl_Istack_sp_ptr)
# define Perl_Imarkstack_max_ptr (*dl_Perl_Imarkstack_max_ptr)
# define Perl_Imarkstack_ptr_ptr (*dl_Perl_Imarkstack_ptr_ptr)
# define Perl_Itmps_floor_ptr (*dl_Perl_Itmps_floor_ptr)
# define Perl_Itmps_ix_ptr (*dl_Perl_Itmps_ix_ptr)
# define Perl_Iscopestack_ix_ptr (*dl_Perl_Iscopestack_ix_ptr)
# define Perl_sv_setpvf_nocontext (*dl_Perl_sv_setpvf_nocontext)
# define Perl_get_sv (*dl_Perl_get_sv)
# define Perl_get_av (*dl_Perl_get_av)
# define Perl_get_hv (*dl_Perl_get_hv)
# define Perl_get_cv (*dl_Perl_get_cv)
# define Perl_call_pv (*dl_Perl_call_pv)
# define Perl_get_context (*dl_Perl_get_context)
# define Perl_set_context (*dl_Perl_set_context)
# define perl_clone (*dl_perl_clone)
# define Perl_Iperl_destruct_level_ptr (*dl_Perl_Iperl_destruct_level_ptr)
# define Perl_Idiehook_ptr (*dl_Perl_Idiehook_ptr)
# define Perl_Iwarnhook_ptr (*dl_Perl_Iwarnhook_ptr)
# define boot_DynaLoader (*dl_boot_DynaLoader)
#endif
#endif
#ifdef DEBUG
# undef DEBUG
#endif
#include <EXTERN.h>
#include <perl.h>
#include <XSUB.h>
/* perl prior to 5.6 support */
#ifndef get_sv
# define get_sv perl_get_sv
#endif
#ifndef eval_pv
# define eval_pv perl_eval_pv
#endif
#ifndef newSVuv
# define newSVuv newSViv
#endif
#ifndef sv_undef
# define sv_undef PL_sv_undef
#endif
#ifndef aTHX_
# define aTHX_
#endif
#ifdef q
# undef q
#endif
#ifdef PERLDL
#if PERL_REVISION<5 || (PERL_REVISION==5 && PERL_VERSION<8)
# define SV_GMAGIC 2 /* sv.h */
#endif
#ifdef OS2
#define pTHX_
#define pTHX void
#define pTHXo_
#define pTHXo void
#define _Const
#define OS2_Perl_data (*dl_OS2_Perl_data)
typedef void (*XSUBADDR_t)(CV* cv _CPERLproto);
typedef void(*XSINIT_t)(void);
#else
#define _Const const
#endif
/* below are the prototypes as they should appear:
PERL_CALLCONV char* (*dl_Perl_sv_2pv)(pTHX_ SV* sv, STRLEN *lp);
PERL_CALLCONV UV (*dl_Perl_sv_2uv)(pTHX_ SV* sv);
PERL_CALLCONV void* (*dl_Perl_get_context)(void);
PERL_CALLCONV void (*dl_Perl_set_context)(void *thx);
PERL_CALLCONV SV* (*dl_Perl_sv_2mortal)(pTHX_ SV* sv);
PERL_CALLCONV SV* (*dl_Perl_newSViv)(pTHX_ IV i);
PERL_CALLCONV SV** (*dl_Perl_av_store)(pTHX_ AV* ar, I32 key, SV* val);
PERL_CALLCONV SV** (*dl_Perl_av_fetch)(pTHX_ AV* ar, I32 key, I32 lval);
PERL_CALLCONV void (*dl_Perl_av_push)(pTHX_ AV* ar, SV* val);
PERL_CALLCONV void (*dl_Perl_av_clear)(pTHX_ AV* ar);
#if PERL_REVISION<5 || (PERL_REVISION==5 && PERL_VERSION<10)
PERL_CALLCONV I32 (*dl_Perl_av_len)(pTHX_ AV* ar);
PERL_CALLCONV CV* (*dl_Perl_newXS)(pTHX_ char* name, XSUBADDR_t f, char* filename);
#else
PERL_CALLCONV I32 (*dl_Perl_av_len)(pTHX_ const AV* ar);
PERL_CALLCONV CV* (*dl_Perl_newXS)(pTHX_ const char* name, XSUBADDR_t f, const char* filename);
#endif
PERL_CALLCONV bool (*dl_Perl_sv_2bool)(pTHX_ SV* sv);
PERL_CALLCONV CV* (*dl_Perl_get_cv)(pTHX_ const char* name, I32 create);
PERL_CALLCONV SV* (*dl_Perl_get_sv)(pTHX_ const char* name, I32 create);
PERL_CALLCONV AV* (*dl_Perl_get_av)(pTHX_ const char* name, I32 create);
PERL_CALLCONV HV* (*dl_Perl_get_hv)(pTHX_ const char* name, I32 create);
PERL_CALLCONV PerlInterpreter* (*dl_perl_alloc)(void);
PERL_CALLCONV void (*dl_perl_construct)(PerlInterpreter* interp);
PERL_CALLCONV void (*dl_perl_destruct)(PerlInterpreter* interp);
PERL_CALLCONV void (*dl_perl_free)(PerlInterpreter* interp);
PERL_CALLCONV int (*dl_perl_run)(PerlInterpreter* interp);
PERL_CALLCONV int (*dl_perl_parse)(PerlInterpreter* interp, XSINIT_t xsinit, int argc, char** argv, char** env);
PERL_CALLCONV PerlInterpreter* (*dl_perl_clone)(PerlInterpreter* interp, UV flags);
PERL_CALLCONV void (*dl_Perl_sv_setiv)(pTHX_ SV* sv, IV num);
PERL_CALLCONV void (*dl_Perl_sv_setsv)(pTHX_ SV* dsv, SV* ssv);
PERL_CALLCONV void (*dl_Perl_sv_setpv)(pTHX_ SV* sv, const char* ptr);
PERL_CALLCONV void (*dl_Perl_sv_setpvn)(pTHX_ SV* sv, const char* ptr, STRLEN len);
PERL_CALLCONV AV* (*dl_Perl_newAV)(pTHX);
PERL_CALLCONV SV* (*dl_Perl_newRV_noinc)(pTHX_ SV *sv);
PERL_CALLCONV HV* (*dl_Perl_newHV)(pTHX);
PERL_CALLCONV SV* (*dl_Perl_newSVpv)(pTHX_ const char* s, STRLEN len);
PERL_CALLCONV SV** (*dl_Perl_hv_store)(pTHX_ HV* tb, _Const char* key, U32 klen, SV* val, U32 hash);
PERL_CALLCONV void (*dl_Perl_hv_clear)(pTHX_ HV* tb);
PERL_CALLCONV SV** (*dl_Perl_hv_fetch)(pTHX_ HV* tb, _Const char* key, U32 klen, I32 lval);
PERL_CALLCONV void (*dl_Perl_push_scope)(pTHX);
PERL_CALLCONV void (*dl_Perl_pop_scope)(pTHX);
PERL_CALLCONV void (*dl_Perl_free_tmps)(pTHX);
PERL_CALLCONV I32 (*dl_Perl_call_pv)(pTHX_ const char* sub_name, I32 flags);
PERL_CALLCONV void (*dl_Perl_markstack_grow)(pTHX);
PERL_CALLCONV void (*dl_Perl_save_int)(pTHX_ int* intp);
PERL_CALLCONV IV (*dl_Perl_sv_2iv)(pTHX_ SV* sv);
PERL_CALLCONV void (*dl_Perl_av_undef)(pTHX_ AV* ar);
PERL_CALLCONV void (*dl_Perl_sv_setpvf_nocontext)(SV* sv, const char* pat, ...)
PERL_CALLCONV SV* (*dl_Perl_eval_pv)(pTHX_ const char* p, I32 croak_on_error);
PERL_CALLCONV SV* (*dl_Perl_newRV)(pTHX_ SV* pref);
PERL_CALLCONV void (*dl_Perl_sv_free)(pTHX_ SV* sv);
PERL_CALLCONV void (*dl_Perl_sv_free2)(pTHX_ SV* sv);
PERL_CALLCONV void* (*dl_Perl_hv_common_key_len)(pTHX_ HV* hv, const char *key, I32 klen_i32, const int action, SV *val, const U32 hash);
PERL_CALLCONV void (*dl_Perl_sys_init3)(int *argc, char ***argv, char ***env);
#ifdef CHECK_FORMAT
__attribute__((format(printf,2,3)))
#endif
;
PERL_CALLCONV int* (*dl_Perl_Iperl_destruct_level_ptr)(pTHXo);
PERL_CALLCONV GV** (*dl_Perl_Ierrgv_ptr)(pTHXo);
PERL_CALLCONV SV* (*dl_Perl_Isv_undef_ptr)(pTHXo);
PERL_CALLCONV SV** (*dl_Perl_Idiehook_ptr)(pTHXo);
PERL_CALLCONV SV** (*dl_Perl_Iwarnhook_ptr)(pTHXo);
#if PERL_REVISION<5 || (PERL_REVISION==5 && PERL_VERSION<10)
PERL_CALLCONV I32* (*dl_Perl_Tscopestack_ix_ptr)(pTHXo);
PERL_CALLCONV I32** (*dl_Perl_Tmarkstack_ptr)(pTHXo);
PERL_CALLCONV I32** (*dl_Perl_Tmarkstack_max_ptr)(pTHXo);
PERL_CALLCONV I32* (*dl_Perl_Ttmps_ix_ptr)(pTHXo);
PERL_CALLCONV I32* (*dl_Perl_Ttmps_floor_ptr)(pTHXo);
PERL_CALLCONV XPV** (*dl_Perl_TXpv_ptr)(pTHXo);
PERL_CALLCONV SV*** (*dl_Perl_Tstack_base_ptr)(pTHXo);
PERL_CALLCONV I32** (*dl_Perl_Tmarkstack_ptr_ptr)(pTHXo);
PERL_CALLCONV SV*** (*dl_Perl_Tstack_sp_ptr)(pTHXo);
#else
PERL_CALLCONV SV** (*dl_Perl_Istack_base_ptr)(pTHXo);
PERL_CALLCONV SV** (*dl_Perl_Istack_sp_ptr)(pTHXo);
PERL_CALLCONV I32* (*dl_Perl_Imarkstack_max_ptr)(pTHXo);
PERL_CALLCONV I32* (*dl_Perl_Imarkstack_ptr_ptr)(pTHXo);
PERL_CALLCONV I32 (*dl_Perl_Itmps_floor_ptr)(pTHXo);
PERL_CALLCONV I32 (*dl_Perl_Itmps_ix_ptr)(pTHXo);
PERL_CALLCONV I32 (*dl_Perl_Iscopestack_ix_ptr)(pTHXo);
#endif
PERL_CALLCONV void (*dl_boot_DynaLoader)(pTHXo_ CV* cv);
*/
/* below is the prototype with typedef:
typedef char* (PERL_CALLCONV *tf_Perl_sv_2pv)(pTHX_ SV* sv, STRLEN* lp);
tf_Perl_sv_2pv dl_Perl_sv_2pv;
*/
/* the currently used way to define prototypes via macro */
#define VK_MAKE_DFL(t,n,a) t (PERL_CALLCONV *n) a
VK_MAKE_DFL(char*, dl_Perl_sv_2pv_flags, (pTHX_ SV* sv, STRLEN* lp, I32 flags));
VK_MAKE_DFL(char*, dl_Perl_sv_2pv, (pTHX_ SV* sv, STRLEN* lp));
PERL_CALLCONV char* hl_Perl_sv_2pv(pTHX_ SV* sv, STRLEN* lp) {
if (dl_Perl_sv_2pv) return dl_Perl_sv_2pv(aTHX_ sv, lp);
else return dl_Perl_sv_2pv_flags(aTHX_ sv, lp, SV_GMAGIC);
}
PERL_CALLCONV char* hl_Perl_sv_2pv_flags(pTHX_ SV* sv, STRLEN* lp, I32 flags) {
if (dl_Perl_sv_2pv_flags) return dl_Perl_sv_2pv_flags(aTHX_ sv, lp, flags);
else return dl_Perl_sv_2pv(aTHX_ sv, lp);
}
VK_MAKE_DFL(UV, dl_Perl_sv_2uv, (pTHX_ SV* sv));
VK_MAKE_DFL(UV, dl_Perl_sv_2uv_flags, (pTHX_ SV* sv, I32 flags));
PERL_CALLCONV UV hl_Perl_sv_2uv(pTHX_ SV* sv) {
if (dl_Perl_sv_2uv) return dl_Perl_sv_2uv(aTHX_ sv);
else return dl_Perl_sv_2uv_flags(aTHX_ sv, SV_GMAGIC);
}
PERL_CALLCONV UV hl_Perl_sv_2uv_flags(pTHX_ SV* sv, I32 flags) {
if (dl_Perl_sv_2uv_flags) return dl_Perl_sv_2uv_flags(aTHX_ sv, flags);
else return dl_Perl_sv_2uv(aTHX_ sv);
}
VK_MAKE_DFL(IV, dl_Perl_sv_2iv, (pTHX_ SV* sv));
VK_MAKE_DFL(IV, dl_Perl_sv_2iv_flags, (pTHX_ SV* sv, I32 flags));
PERL_CALLCONV IV hl_Perl_sv_2iv(pTHX_ SV* sv) {
if (dl_Perl_sv_2iv) return dl_Perl_sv_2iv(aTHX_ sv);
else return dl_Perl_sv_2iv_flags(aTHX_ sv, SV_GMAGIC);
}
PERL_CALLCONV IV hl_Perl_sv_2iv_flags(pTHX_ SV* sv, I32 flags) {
if (dl_Perl_sv_2iv_flags) return dl_Perl_sv_2iv_flags(aTHX_ sv, flags);
else return dl_Perl_sv_2iv(aTHX_ sv);
}
VK_MAKE_DFL(SV*, dl_Perl_sv_2mortal, (pTHX_ SV* sv));
VK_MAKE_DFL(SV*, dl_Perl_newSViv, (pTHX_ IV i));
VK_MAKE_DFL(SV**, dl_Perl_av_store, (pTHX_ AV* ar, I32 key, SV* val));
VK_MAKE_DFL(SV**, dl_Perl_av_fetch, (pTHX_ AV* ar, I32 key, I32 lval));
VK_MAKE_DFL(void, dl_Perl_av_push, (pTHX_ AV* ar, SV* val));
VK_MAKE_DFL(void, dl_Perl_av_clear, (pTHX_ AV* ar));
#if PERL_REVISION<5 || (PERL_REVISION==5 && PERL_VERSION<10)
VK_MAKE_DFL(CV*, dl_Perl_newXS, (pTHX_ char* name, XSUBADDR_t f, char* filename));
VK_MAKE_DFL(I32, dl_Perl_av_len, (pTHX_ AV* ar));
#else
VK_MAKE_DFL(CV*, dl_Perl_newXS, (pTHX_ const char* name, XSUBADDR_t f, const char* filename));
VK_MAKE_DFL(I32, dl_Perl_av_len, (pTHX_ const AV* ar));
#endif
VK_MAKE_DFL(bool, dl_Perl_sv_2bool, (pTHX_ SV* sv));
VK_MAKE_DFL(PerlInterpreter*, dl_perl_alloc, (void));
VK_MAKE_DFL(void, dl_perl_construct, (PerlInterpreter* interp));
#if PERL_REVISION>5 || (PERL_REVISION==5 && PERL_VERSION>=8)
VK_MAKE_DFL(int, dl_perl_destruct, (PerlInterpreter* interp));
#else
VK_MAKE_DFL(void, dl_perl_destruct, (PerlInterpreter* interp));
#endif
VK_MAKE_DFL(void, dl_perl_free, (PerlInterpreter* interp));
VK_MAKE_DFL(int, dl_perl_run, (PerlInterpreter* interp));
VK_MAKE_DFL(int, dl_perl_parse, (PerlInterpreter* interp, XSINIT_t xsinit, int argc, char** argv, char** env));
VK_MAKE_DFL(void, dl_Perl_sv_setiv, (pTHX_ SV* sv, IV num));
VK_MAKE_DFL(void, dl_Perl_sv_setsv_flags, (pTHX_ SV* dsv, SV* ssv, I32 flags));
VK_MAKE_DFL(void, dl_Perl_sv_setsv, (pTHX_ SV* dsv, SV* ssv));
void hl_Perl_sv_setsv(pTHX_ SV* sv, SV* ssv) {
if (dl_Perl_sv_setsv) dl_Perl_sv_setsv(aTHX_ sv, ssv);
else dl_Perl_sv_setsv_flags(aTHX_ sv, ssv, SV_GMAGIC);
}
void hl_Perl_sv_setsv_flags(pTHX_ SV* sv, SV* ssv, I32 flags) {
if (dl_Perl_sv_setsv) dl_Perl_sv_setsv_flags(aTHX_ sv, ssv, flags);
else dl_Perl_sv_setsv(aTHX_ sv, ssv);
}
VK_MAKE_DFL(void, dl_Perl_sv_setpv, (pTHX_ SV* sv, const char* ptr));
VK_MAKE_DFL(void, dl_Perl_sv_setpvn, (pTHX_ SV* sv, const char* ptr, STRLEN len));
VK_MAKE_DFL(AV*, dl_Perl_newAV, (pTHX));
VK_MAKE_DFL(SV*, dl_Perl_newRV_noinc, (pTHX_ SV *sv));
VK_MAKE_DFL(HV*, dl_Perl_newHV, (pTHX));
VK_MAKE_DFL(SV*, dl_Perl_newSVpv, (pTHX_ _Const char* s, STRLEN len));
VK_MAKE_DFL(void, dl_Perl_hv_clear, (pTHX_ HV* tb));
#if PERL_REVISION<5 || (PERL_REVISION==5 && PERL_VERSION<8)
VK_MAKE_DFL(SV**, dl_Perl_hv_store, (pTHX_ HV* tb, _Const char* key, U32 klen, SV* val, U32 hash));
VK_MAKE_DFL(SV**, dl_Perl_hv_fetch, (pTHX_ HV* tb, _Const char* key, U32 klen, I32 lval));
#else
VK_MAKE_DFL(SV**, dl_Perl_hv_store, (pTHX_ HV* tb, _Const char* key, I32 klen, SV* val, U32 hash));
VK_MAKE_DFL(SV**, dl_Perl_hv_fetch, (pTHX_ HV* tb, _Const char* key, I32 klen, I32 lval));
#endif
VK_MAKE_DFL(void, dl_Perl_push_scope, (pTHX));
VK_MAKE_DFL(void, dl_Perl_pop_scope, (pTHX));
VK_MAKE_DFL(void, dl_Perl_free_tmps, (pTHX));
VK_MAKE_DFL(void, dl_Perl_markstack_grow, (pTHX));
VK_MAKE_DFL(void, dl_Perl_save_int, (pTHX_ int* intp));
VK_MAKE_DFL(void, dl_Perl_av_undef, (pTHX_ AV* ar));
VK_MAKE_DFL(SV*, dl_Perl_eval_pv, (pTHX_ const char* p, I32 croak_on_error));
VK_MAKE_DFL(SV*, dl_Perl_newRV, (pTHX_ SV* pref));
VK_MAKE_DFL(void, dl_Perl_sv_free, (pTHX_ SV* sv));
VK_MAKE_DFL(void, dl_Perl_sv_free2, (pTHX_ SV* sv));
VK_MAKE_DFL(void*, dl_Perl_hv_common_key_len, (pTHX_ HV* hv, const char *key, I32 klen_i32, const int action, SV *val, const U32 hash));
VK_MAKE_DFL(void, dl_Perl_sys_init3, (int *argc, char ***argv, char ***env));
#ifdef OS2
VK_MAKE_DFL(void, dl_Perl_sv_setpvf, (SV* sv, const char* pat, ...));
VK_MAKE_DFL(CV*, dl_perl_get_cv, (pTHX_ _Const char* name, I32 create));
VK_MAKE_DFL(SV*, dl_perl_get_sv, (pTHX_ _Const char* name, I32 create));
VK_MAKE_DFL(AV*, dl_perl_get_av, (pTHX_ _Const char* name, I32 create));
VK_MAKE_DFL(HV*, dl_perl_get_hv, (pTHX_ _Const char* name, I32 create));
VK_MAKE_DFL(I32, dl_perl_call_pv, (pTHX_ _Const char* sub_name, I32 flags));
GV* *dl_PL_errgv;
SV** *dl_PL_stack_sp;
I32* *dl_PL_markstack_ptr;
SV *dl_PL_sv_undef;
SV** *dl_PL_stack_base;
I32* *dl_PL_markstack_max;
I32 *dl_PL_tmps_ix;
I32 *dl_PL_tmps_floor;
SV* *dl_PL_diehook;
SV* *dl_PL_warnhook;
OS2_Perl_data_t *dl_OS2_Perl_data;
#else
VK_MAKE_DFL(CV*, dl_Perl_get_cv, (pTHX_ _Const char* name, I32 create));
VK_MAKE_DFL(SV*, dl_Perl_get_sv, (pTHX_ _Const char* name, I32 create));
VK_MAKE_DFL(AV*, dl_Perl_get_av, (pTHX_ _Const char* name, I32 create));
VK_MAKE_DFL(HV*, dl_Perl_get_hv, (pTHX_ _Const char* name, I32 create));
VK_MAKE_DFL(I32, dl_Perl_call_pv, (pTHX_ _Const char* sub_name, I32 flags));
VK_MAKE_DFL(GV**, dl_Perl_Ierrgv_ptr, (pTHXo));
VK_MAKE_DFL(SV*, dl_Perl_Isv_undef_ptr, (pTHXo));
VK_MAKE_DFL(SV**, dl_Perl_Idiehook_ptr, (pTHXo));
VK_MAKE_DFL(SV**, dl_Perl_Iwarnhook_ptr, (pTHXo));
#if PERL_REVISION<5 || (PERL_REVISION==5 && PERL_VERSION<10)
VK_MAKE_DFL(SV***, dl_Perl_Tstack_sp_ptr, (pTHXo));
VK_MAKE_DFL(I32**, dl_Perl_Tmarkstack_ptr_ptr, (pTHXo));
VK_MAKE_DFL(SV***, dl_Perl_Tstack_base_ptr, (pTHXo));
VK_MAKE_DFL(I32**, dl_Perl_Tmarkstack_max_ptr, (pTHXo));
VK_MAKE_DFL(I32*, dl_Perl_Ttmps_ix_ptr, (pTHXo));
VK_MAKE_DFL(I32*, dl_Perl_Ttmps_floor_ptr, (pTHXo));
VK_MAKE_DFL(I32**, dl_Perl_Tmarkstack_ptr, (pTHXo));
VK_MAKE_DFL(XPV**, dl_Perl_TXpv_ptr, (pTHXo));
VK_MAKE_DFL(int*, dl_Perl_Iperl_destruct_level_ptr, (pTHXo));
#else
VK_MAKE_DFL(SV***, dl_Perl_Istack_base_ptr, (pTHXo));
VK_MAKE_DFL(SV***, dl_Perl_Istack_sp_ptr, (pTHXo));
VK_MAKE_DFL(I32**, dl_Perl_Imarkstack_max_ptr, (pTHXo));
VK_MAKE_DFL(I32**, dl_Perl_Imarkstack_ptr_ptr, (pTHXo));
VK_MAKE_DFL(I32*, dl_Perl_Itmps_floor_ptr, (pTHXo));
VK_MAKE_DFL(I32*, dl_Perl_Itmps_ix_ptr, (pTHXo));
VK_MAKE_DFL(I32*, dl_Perl_Iscopestack_ix_ptr, (pTHXo));
VK_MAKE_DFL(signed char*, dl_Perl_Iperl_destruct_level_ptr, (pTHXo));
#endif
VK_MAKE_DFL(void, dl_boot_DynaLoader, (pTHXo_ CV* cv));
VK_MAKE_DFL(void*, dl_Perl_get_context, (void));
VK_MAKE_DFL(void, dl_Perl_set_context, (void *thx));
VK_MAKE_DFL(PerlInterpreter*, dl_perl_clone, (PerlInterpreter* interp, UV flags));
VK_MAKE_DFL(I32*, dl_Perl_Tscopestack_ix_ptr, (pTHXo));
#ifdef CHECK_FORMAT
VK_MAKE_DFL(void, dl_Perl_sv_setpvf_nocontext, (SV* sv, const char* pat, ...) __attribute__((format(printf,2,3))) );
#else
VK_MAKE_DFL(void, dl_Perl_sv_setpvf_nocontext, (SV* sv, const char* pat, ...));
#endif
#endif
/* the list of functions to import from DLL */
#define VK_MAKE_DLFUNC(n) { (void **)&dl_##n, #n }
struct perl_dlfunc { void **f; char *name; } perl_dlfuncs[] = {
/*#if PERL_REVISION>5 || (PERL_REVISION==5 && PERL_VERSION>=8)
VK_MAKE_DLFUNC(Perl_sv_2pv_flags),
#else
VK_MAKE_DLFUNC(Perl_sv_2pv),
#endif*/
VK_MAKE_DLFUNC(Perl_sv_2mortal),
VK_MAKE_DLFUNC(Perl_newSViv),
VK_MAKE_DLFUNC(Perl_av_store),
VK_MAKE_DLFUNC(Perl_av_fetch),
VK_MAKE_DLFUNC(Perl_av_len),
VK_MAKE_DLFUNC(Perl_av_push),
VK_MAKE_DLFUNC(Perl_av_clear),
VK_MAKE_DLFUNC(Perl_newXS),
VK_MAKE_DLFUNC(Perl_sv_2bool),
VK_MAKE_DLFUNC(perl_alloc),
VK_MAKE_DLFUNC(perl_construct),
VK_MAKE_DLFUNC(perl_destruct),
VK_MAKE_DLFUNC(perl_free),
VK_MAKE_DLFUNC(perl_run),
VK_MAKE_DLFUNC(perl_parse),
VK_MAKE_DLFUNC(Perl_sv_setiv),
/*#if PERL_REVISION>5 || (PERL_REVISION==5 && PERL_VERSION>=8)
VK_MAKE_DLFUNC(Perl_sv_setsv_flags),
#else
VK_MAKE_DLFUNC(Perl_sv_setsv),
#endif*/
VK_MAKE_DLFUNC(Perl_sv_setpv),
VK_MAKE_DLFUNC(Perl_sv_setpvn),
VK_MAKE_DLFUNC(Perl_newAV),
VK_MAKE_DLFUNC(Perl_newRV_noinc),
VK_MAKE_DLFUNC(Perl_newHV),
VK_MAKE_DLFUNC(Perl_newSVpv),
VK_MAKE_DLFUNC(Perl_hv_store),
VK_MAKE_DLFUNC(Perl_hv_clear),
VK_MAKE_DLFUNC(Perl_hv_fetch),
VK_MAKE_DLFUNC(Perl_push_scope),
VK_MAKE_DLFUNC(Perl_pop_scope),
VK_MAKE_DLFUNC(Perl_free_tmps),
VK_MAKE_DLFUNC(Perl_markstack_grow),
VK_MAKE_DLFUNC(Perl_save_int),
VK_MAKE_DLFUNC(Perl_av_undef),
VK_MAKE_DLFUNC(Perl_eval_pv),
VK_MAKE_DLFUNC(Perl_newRV),
VK_MAKE_DLFUNC(Perl_sv_free),
VK_MAKE_DLFUNC(Perl_sys_init3),
#ifdef OS2
VK_MAKE_DLFUNC(perl_get_cv),
VK_MAKE_DLFUNC(perl_get_sv),
VK_MAKE_DLFUNC(perl_get_av),
VK_MAKE_DLFUNC(perl_get_hv),
VK_MAKE_DLFUNC(perl_call_pv),
VK_MAKE_DLFUNC(PL_errgv),
VK_MAKE_DLFUNC(PL_stack_sp),
VK_MAKE_DLFUNC(PL_markstack_ptr),
VK_MAKE_DLFUNC(PL_sv_undef),
VK_MAKE_DLFUNC(PL_stack_base),
VK_MAKE_DLFUNC(PL_markstack_max),
VK_MAKE_DLFUNC(PL_tmps_ix),
VK_MAKE_DLFUNC(PL_tmps_floor),
VK_MAKE_DLFUNC(PL_diehook),
VK_MAKE_DLFUNC(PL_warnhook),
VK_MAKE_DLFUNC(OS2_Perl_data),
VK_MAKE_DLFUNC(Perl_sv_setpvf),
#else
VK_MAKE_DLFUNC(Perl_hv_common_key_len),
VK_MAKE_DLFUNC(Perl_get_cv),
VK_MAKE_DLFUNC(Perl_get_sv),
VK_MAKE_DLFUNC(Perl_get_av),
VK_MAKE_DLFUNC(Perl_get_hv),
VK_MAKE_DLFUNC(Perl_call_pv),
VK_MAKE_DLFUNC(Perl_Ierrgv_ptr),
#if PERL_REVISION<5 || (PERL_REVISION==5 && PERL_VERSION<10)
VK_MAKE_DLFUNC(Perl_Tstack_sp_ptr),
VK_MAKE_DLFUNC(Perl_Tmarkstack_ptr_ptr),
VK_MAKE_DLFUNC(Perl_Tmarkstack_ptr),
VK_MAKE_DLFUNC(Perl_Tstack_base_ptr),
VK_MAKE_DLFUNC(Perl_Tmarkstack_max_ptr),
VK_MAKE_DLFUNC(Perl_Ttmps_ix_ptr),
VK_MAKE_DLFUNC(Perl_Ttmps_floor_ptr),
VK_MAKE_DLFUNC(Perl_Tscopestack_ix_ptr),
VK_MAKE_DLFUNC(Perl_TXpv_ptr),
#else
VK_MAKE_DLFUNC(Perl_Istack_base_ptr),
VK_MAKE_DLFUNC(Perl_Istack_sp_ptr),
VK_MAKE_DLFUNC(Perl_Imarkstack_max_ptr),
VK_MAKE_DLFUNC(Perl_Imarkstack_ptr_ptr),
VK_MAKE_DLFUNC(Perl_Itmps_floor_ptr),
VK_MAKE_DLFUNC(Perl_Itmps_ix_ptr),
VK_MAKE_DLFUNC(Perl_Iscopestack_ix_ptr),
VK_MAKE_DLFUNC(Perl_sv_free2),
#endif
VK_MAKE_DLFUNC(Perl_Isv_undef_ptr),
VK_MAKE_DLFUNC(Perl_sv_setpvf_nocontext),
VK_MAKE_DLFUNC(Perl_get_context),
VK_MAKE_DLFUNC(Perl_set_context),
VK_MAKE_DLFUNC(perl_clone),
VK_MAKE_DLFUNC(Perl_Iperl_destruct_level_ptr),
VK_MAKE_DLFUNC(Perl_Idiehook_ptr),
VK_MAKE_DLFUNC(Perl_Iwarnhook_ptr),
VK_MAKE_DLFUNC(boot_DynaLoader),
#endif
{ NULL, NULL }
};
#endif /* PERLDL */
#if defined(HAVE_FORK) && !defined(HAVE_THREADS) && !defined(Perl_get_context)
# define Perl_get_context() cfg->perl
#endif
#if !defined(PERL_SET_CONTEXT)
# if defined(HAVE_THREADS)
# error Your perl is not thread-safe!
# endif
# define PERL_SET_CONTEXT(p)
#endif
/* =========================== vars ================================== */
#define sv_config_format "__config_%u" /* SV that keeps pointer to config */
#define sv_state_format "__state_%u" /* SV that keeps pointer to state */
#define def_state() sprintf(sv_state, sv_state_format, (unsigned)PID())
#define def_config() sprintf(sv_config, sv_config_format, (unsigned)PID())
#if defined(HAVE_THREADS) && defined(PERL_MULTITHREAD)
MUTEXSEM perlsem;
#endif
#define VK_FIND_CONFIG(cfg) \
{ char sv_config[20]; \
SV *sv; \
STRLEN n_a; \
def_config(); \
sv = perl_get_sv(sv_config, FALSE); \
if (sv) { \
cfg = *((BINKD_CONFIG**)SvPV(sv, n_a)); \
if (!cfg || n_a == 0) cfg = current_config; \
} else \
cfg = current_config; \
}
#define SET_CONFIG(cfg) \
{ SV *svret; \
char sv_config[20]; \
def_config(); \
if ( ( svret = perl_get_sv(sv_config, TRUE)) != NULL ) { \
sv_setpvn(svret, (char *)&cfg, sizeof(&cfg)); \
SvREADONLY_on(svret); \
} \
}
#define CLEAR_CONFIG \
{ SV *svret; \
char sv_config[20]; \
def_config(); \
if ( ( svret = perl_get_sv(sv_config, FALSE)) != NULL ) { \
SvREFCNT_dec(svret); \
} \
}
#define FIND_STATE(state) \
{ SV *sv; \
char sv_state[20]; \
def_state(); \
sv = perl_get_sv(sv_state, FALSE); \
if (!sv) { \
Log(LL_ERR, "can't find $%s pointer", sv_state); \
state = NULL; \
} else { \
state = *((STATE**)SvPV(sv, n_a)); \
if (!(state) || !n_a) { \
Log(LL_ERR, "$%s pointer is NULL", sv_state); \
state = NULL; \
} \
} \
}
#define SET_STATE(state) \
{ SV *svret; \
char sv_state[20]; \
def_state(); \
if ( ( svret = perl_get_sv(sv_state, TRUE)) != NULL ) { \
sv_setpvn(svret, (char *)&state, sizeof(&state)); \
SvREADONLY_on(svret); \
} \
}
#define CLEAR_STATE \
{ SV *svret; \
char sv_state[20]; \
def_state(); \
if ( ( svret = perl_get_sv(sv_state, FALSE)) != NULL ) { \
SvREFCNT_dec(svret); \
} \
}
/* bits for subroutines, must correspond to perl_subnames */
typedef enum {
PERL_ON_START, PERL_ON_EXIT, PERL_ON_CALL, PERL_ON_ERROR,
PERL_ON_HANDSHAKE, PERL_AFTER_HANDSHAKE, PERL_AFTER_SESSION,
PERL_BEFORE_RECV, PERL_AFTER_RECV, PERL_BEFORE_SEND, PERL_AFTER_SENT,
PERL_ON_LOG, PERL_ON_SEND, PERL_ON_RECV, PERL_SETUP_RLIMIT,
PERL_NEED_RELOAD, PERL_CONFIG_LOADED
} perl_subs;
/* sub bit to corresponding name */
char *perl_subnames[] = {
"on_start",
"on_exit",
"on_call",
"on_error",
"on_handshake",
"after_handshake",
"after_session",
"before_recv",
"after_recv",
"before_send",
"after_sent",
"on_log",
"on_send",
"on_recv",
"setup_rlimit",
"need_reload",
"config_loaded"
};
/* constants */
struct perl_const { char *name; int value; } perl_consts[] = {
{ "SECURE", P_SECURE },
{ "NONSECURE", P_NONSECURE },
{ "WE_NONSECURE", P_WE_NONSECURE },
{ "REMOTE_NONSECURE", P_REMOTE_NONSECURE },
{ "OK", 1 },
{ "FAILED", 0 },
{ "BAD_CALL", BAD_CALL },
{ "BAD_MERR", BAD_MERR },
{ "BAD_MBSY", BAD_MBSY },
{ "BAD_IO", BAD_IO },
{ "BAD_TIMEOUT", BAD_TIMEOUT },
{ "BAD_AKA", BAD_AKA },
{ "BAD_AUTH", BAD_AUTH }
};
/* log levels */
#define LL_ERR 1
#define LL_WARN 2
#define LL_INFO 3
#define LL_LOG 3
#define LL_DBG 7
#define LL_DBG2 9
/* ---------------------------- defines ------------------------------- */
#define VK_ADD_intz(_sv, _name, _v) \
if ( (_sv = perl_get_sv(_name, TRUE)) != NULL ) { \
SvREADONLY_off(_sv); \
sv_setiv(_sv, _v); \
SvREADONLY_on(_sv); \
}
#define VK_ADD_strz(_sv, _name, _v) \
if ( (_sv = perl_get_sv(_name, TRUE)) != NULL ) { \
SvREADONLY_off(_sv); \
sv_setpv(_sv, _v ? _v : ""); \
SvREADONLY_on(_sv); \
}
#define VK_ADD_str(_sv, _name, _v) \
if ( (_sv = perl_get_sv(_name, TRUE)) != NULL ) { \
SvREADONLY_off(_sv); \
if (_v) sv_setpv(_sv, _v); else sv_setsv(_sv, &sv_undef); \
SvREADONLY_on(_sv); \
}
#define VK_ADD_strs(_sv, _name, _v) \
if ( (_sv = perl_get_sv(_name, TRUE)) != NULL ) { \
SvREADONLY_off(_sv); \
sv_setpv(_sv, (char *)_v); \
SvREADONLY_on(_sv); \
}
#define VK_ADD_strn(_sv, _name, _v, len) \
if ( (_sv = perl_get_sv(_name, TRUE)) != NULL ) { \
SvREADONLY_off(_sv); \
sv_setpvn(_sv, (char *)_v, len); \
SvREADONLY_on(_sv); \
}
#define VK_ADD_HASH_sv(_hv,_sv,_name) \
if (_sv != NULL) { \
SvREADONLY_on(_sv); \
(void) hv_store(_hv, _name, strlen(_name), _sv, 0); \
}
#define VK_ADD_HASH_str(_hv,_sv,_name,_value) \
if ( ((_value) != NULL) && (_sv = newSVpv(_value, 0)) != NULL ) { \
SvREADONLY_on(_sv); \
(void) hv_store(_hv, _name, strlen(_name), _sv, 0); \
} \
else (void) hv_store(_hv, _name, strlen(_name), &sv_undef, 0);
#define VK_ADD_HASH_intz(_hv,_sv,_name,_value) \
if ( (_sv = newSViv(_value)) != NULL ) { \
SvREADONLY_on(_sv); \
(void) hv_store(_hv, _name, strlen(_name), _sv, 0); \
}
#define VK_ADD_HASH_int(_hv,_sv,_name,_value) \
if (_value) { VK_ADD_HASH_intz(_hv,_sv,_name,_value) }
/* =========================== err handling ========================== */
static void perl_warn_str (char* str) {
while (str && *str) {
char* cp = strchr (str, '\n');
char c = 0;
if (cp) { c = *cp; *cp = 0; }
Log(LL_ERR, "Perl error: %s", str);
if (cp) *cp = c;
else break;
str = cp + 1;
}
}
static void perl_warn_sv (SV* sv) {
STRLEN n_a;
char * str = (char *) SvPV (sv, n_a);
perl_warn_str (str);
}
#ifdef _MSC_VER
EXTERN_C void perl_warn(pTHXo_ CV* cv)
#else
static XS(perl_warn)
#endif
{
dXSARGS;
if (items == 1) perl_warn_sv (ST(0));
XSRETURN_EMPTY;
}
/* handle multi-line perl eval error message */
static void sub_err(int sub) {
STRLEN len;
char *s, *p;
p = SvPV(ERRSV, len);
if (len) {
s = xalloc(len+1);
strnzcpy(s, p, len+1);
}
else
s = xstrdup("(empty error message)");
if ( strchr(s, '\n') == NULL )
Log(LL_ERR, "Perl %s error: %s", perl_subnames[sub], s);
else {
p = s;
Log(LL_ERR, "Perl %s error below:", perl_subnames[sub]);
while ( *p && (*p != '\n' || *(p+1)) ) {
char *r = strchr(p, '\n');
if (r) {
*r = 0;
Log(LL_ERR, " %s", p);
p = r+1;
}
else {
Log(LL_ERR, " %s", p);
break;
}
}
}
xfree(s);
}
/* =========================== xs ========================== */
#ifdef _MSC_VER
EXTERN_C void xs_init (pTHXo);
# ifndef PERLDL
EXTERN_C void boot_DynaLoader (pTHXo_ CV* cv);
# endif
EXTERN_C void perl_Log(pTHXo_ CV* cv);
EXTERN_C void perl_aeq(pTHXo_ CV* cv);
EXTERN_C void perl_arm(pTHXo_ CV* cv);
#else
# ifndef PERLDL
XS(boot_DynaLoader);
# else
/* I don't know how to use DynaLoader with PERLDL under OS/2 :-( */
# endif
#endif
/* interface to Log() */
#ifdef _MSC_VER
EXTERN_C void perl_Log(pTHXo_ CV* cv)
#else
static XS(perl_Log)
#endif
{
dXSARGS;
char *str;
int lvl;
STRLEN n_a;
if (items != 1 && items != 2)
{ Log(LL_ERR, "wrong params number to Log (need 1 or 2, exist %d)", items);
XSRETURN_EMPTY;
}
if (items == 2) {
lvl = SvUV(ST(0));
str = (char *)SvPV(ST(1), n_a); if (n_a == 0) str = "";
} else {
lvl = LL_LOG;
str = (char *)SvPV(ST(0), n_a); if (n_a == 0) str = "";
}
Log(lvl, "%s", str);
XSRETURN_EMPTY;
}
/* returns 1 if the first addr matches to any of the rest */
#ifdef _MSC_VER
EXTERN_C void perl_aeq(pTHXo_ CV* cv)
#else
static XS(perl_aeq)
#endif
{
dXSARGS;
BINKD_CONFIG *cfg;
STRLEN len;
int i;
char *a, *b;
FTN_ADDR A, B;
int mask_mode = 0;
if (items == 1) {
Log(LL_ERR, "aeq() requires 2 or more parameters, %d exist", items);
XSRETURN_UNDEF;
}
VK_FIND_CONFIG(cfg);
a = (char *)SvPV(ST(0), len);
if (len == 0) XSRETURN_UNDEF;
else if (strchr(a, '*')) mask_mode = 1;
else if (!parse_ftnaddress(a, &A, cfg->pDomains.first)) XSRETURN_UNDEF;
else exp_ftnaddress(&A, cfg->pAddr, cfg->nAddr, cfg->pDomains.first);
for (i = 1; i < items; i++) {
b = (char *)SvPV(ST(i), len);
if (len == 0 || !parse_ftnaddress(b, &B, cfg->pDomains.first)) continue;
exp_ftnaddress(&B, cfg->pAddr, cfg->nAddr, cfg->pDomains.first);
if (mask_mode) {
char bb[FTN_ADDR_SZ];
xftnaddress_to_str(bb, &B, 1);
if (ftnamask_cmps(a, bb) == 0) XSRETURN_IV(1);
} else {
if (ftnaddress_cmp(&A, &B) == 0) XSRETURN_IV(1);
}
}
XSRETURN_IV(0);
}
/* deletes all the addresses from the array (the first arg) */
#ifdef _MSC_VER
EXTERN_C void perl_arm(pTHXo_ CV* cv)
#else
static XS(perl_arm)
#endif
{
dXSARGS;
BINKD_CONFIG *cfg;
STRLEN len;
int i, j, k, K, N, m;
char *a, *b, **C;
FTN_ADDR A, *B;
AV *arr;
SV **svp;
if (items == 1) {
Log(LL_ERR, "arm() requires 2 or more parameters, %d exist", items);
XSRETURN_UNDEF;
}
if (!SvROK(ST(0)) || SvTYPE(SvRV(ST(0))) != SVt_PVAV) {
Log(LL_ERR, "first parameter to arm() should be array reference");
XSRETURN_UNDEF;
}
VK_FIND_CONFIG(cfg);
arr = (AV*)SvRV(ST(0));
B = xalloc( (items-1)*sizeof(FTN_ADDR) );
C = xalloc( (items-1)*sizeof(char*) );
memset(C, 0, (items-1)*sizeof(char*));
/* i - args, k - valid addresses */
for (i = 1, k = K = 0; i < items; i++) {
b = (char *)SvPV(ST(i), len);
if (len == 0) continue;
if (strchr(b, '*')) { C[K++] = b; continue; }
if (!parse_ftnaddress(b, B+k, cfg->pDomains.first)) continue;
exp_ftnaddress(B+k, cfg->pAddr, cfg->nAddr, cfg->pDomains.first);
k++;
}
/* j - array elements, i - valid addresses */
N = av_len(arr) + 1;
for (j = m = 0; j < N; j++) {
int found = 0;
svp = av_fetch(arr, j, FALSE);
if (j != m) av_store(arr, m, (*svp));
if (!svp) { m++; continue; }
a = (char *)SvPV((*svp), len);
if (len == 0 || !parse_ftnaddress(a, &A, cfg->pDomains.first)) { m++; continue; }
exp_ftnaddress(&A, cfg->pAddr, cfg->nAddr, cfg->pDomains.first);
/* compare */
for (i = 0; i < k; i++) {
if (ftnaddress_cmp(&A, B+i) == 0) { found = 1; break; }
}
for (i = 0; i < K; i++) {
char aa[FTN_ADDR_SZ];
xftnaddress_to_str(aa, &A, 1);
if (ftnamask_cmps(C[i], aa) == 0) { found = 1; break; }
}
if (!found) m++;
}
/* reduce array size */
if (m != N) AvFILLp(arr) = m-1;
free(B); free(C);
XSRETURN_IV(N - m);
}
/* puts a message to msg-queue */
extern void msg_send2 (STATE *state, t_msg m, char *s1, char *s2);
#ifdef _MSC_VER
EXTERN_C void perl_msg_send(pTHXo_ CV* cv)
#else
static XS(perl_msg_send)
#endif
{
dXSARGS;
STATE *state;
t_msg m;
char *str;
STRLEN n_a;
if (items != 2) {
Log(LL_ERR, "wrong params number to msg_send (needs 2, exist %d)", items);