-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathepinit.c
More file actions
2358 lines (1934 loc) · 69.6 KB
/
epinit.c
File metadata and controls
2358 lines (1934 loc) · 69.6 KB
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
/*###################################################################################
#
# Embperl - Copyright (c) 1997-2008 Gerald Richter / ecos gmbh www.ecos.de
# Embperl - Copyright (c) 2008-2014 Gerald Richter
#
# You may distribute under the terms of either the GNU General Public
# License or the Artistic License, as specified in the Perl README file.
# For use with Apache httpd and mod_perl, see also Apache copyright.
#
# THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
# WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
# $Id: epinit.c 1578075 2014-03-16 14:01:14Z richter $
#
###################################################################################*/
#include "ep.h"
#include "epmacro.h"
#include "xs/ep_xs_typedefs.h"
#include "xs/ep_xs_sv_convert.h"
#include "epdefault.c"
SV ep_sv_undef ; /* we need our own undef value, because when
storing a PL_sv_undef with Perl 5.8.0 in a hash
Perl takes it as a placeholder and pretents it isn't there :-( */
#ifndef PERL_IMPLICIT_CONTEXT
SV * embperl_ThreadDataRV ;
#define SINGLETHREAD
#endif
#define OPTPREFIX EMBPERL_PACKAGE_STR
#define EMBPERL_APP_PACKAGE EMBPERL_PACKAGE_STR"::Application"
#define EMBPERL_REQ_PACKAGE EMBPERL_PACKAGE_STR"::Req"
#define EMBPERL_THREAD_PACKAGE EMBPERL_PACKAGE_STR"::Thread"
#define FDAT_NAME "fdat"
#define EMBPERL_FDAT_NAME EMBPERL_PACKAGE_STR"::"FDAT_NAME
#define EMBPERL_SPLIFDAT_NAME EMBPERL_PACKAGE_STR"::splitfdat"
#define FFLD_NAME "ffld"
#define EMBPERL_FFLD_NAME EMBPERL_PACKAGE_STR"::"FFLD_NAME
#define EMBPERL_HDR_NAME EMBPERL_PACKAGE_STR"::http_headers_out"
#define EMBPERL_IDAT_NAME EMBPERL_PACKAGE_STR"::idat"
#define PARAM_NAME "param"
#define EMBPERL_PARAM_NAME EMBPERL_PACKAGE_STR"::"PARAM_NAME
#define EMBPERL_REQ_NAME EMBPERL_PACKAGE_STR"::req"
#define EMBPERL_APP_NAME EMBPERL_PACKAGE_STR"::app"
#define EMBPERL_ENV_NAME "ENV"
#define EMBPERL_EscMode_NAME EMBPERL_PACKAGE_STR"::escmode"
#define EMBPERL_CurrNode_NAME EMBPERL_PACKAGE_STR"::_ep_node"
static int bInitDone = 0 ; /* c part is already initialized */
static int nRequestCount = 1 ;
static perl_mutex RequestCountMutex ;
static tMemPool * pMainPool ;
static tReq NullRequest ; /* a request object with all zero, to point for deleted objects */
/* -------------------------------------------------------------------------
*
* Options lists for configuration
*
*/
#define OPTION(a,b) { #a, a}, { #b, a},
tOptionEntry OptionsDEBUG[] =
{
OPTION(dbgStd, std)
OPTION(dbgMem,Mem)
OPTION(dbgEval,Eval)
OPTION(dbgCmd,Cmd)
OPTION(dbgEnv,Env)
OPTION(dbgForm,Form)
OPTION(dbgTab,Tab)
OPTION(dbgInput,Input)
OPTION(dbgFlushOutput,FlushOutput)
OPTION(dbgFlushLog,FlushLog)
OPTION(dbgAllCmds,AllCmds)
OPTION(dbgSource,Source)
OPTION(dbgFunc,Func)
OPTION(dbgLogLink,LogLink)
OPTION(dbgDefEval,DefEval)
OPTION(dbgOutput,Output)
OPTION(dbgDOM,DOM)
OPTION(dbgRun,Run)
OPTION(dbgHeadersIn,HeadersIn)
OPTION(dbgShowCleanup,ShowCleanup)
OPTION(dbgProfile,Profile)
OPTION(dbgSession,Session)
OPTION(dbgImport,Import)
OPTION(dbgBuildToken,BuildToken)
OPTION(dbgParse,Parse)
OPTION(dbgObjectSearch,ObjectSearch)
OPTION(dbgCache,Cache)
OPTION(dbgCompile,Compile)
OPTION(dbgXML,XML)
OPTION(dbgXSLT,XSLT)
OPTION(dbgCheckpoint,Checkpoint)
OPTION(dbgAll,All)
} ;
#define OPTION_OPT(a) OPTION(opt##a, a)
tOptionEntry OptionsOPTIONS[] =
{
OPTION_OPT(DisableVarCleanup)
OPTION_OPT(DisableEmbperlErrorPage)
OPTION_OPT(SafeNamespace)
OPTION_OPT(OpcodeMask)
OPTION_OPT(RawInput)
OPTION_OPT(SendHttpHeader)
OPTION_OPT(EarlyHttpHeader)
OPTION_OPT(DisableChdir)
OPTION_OPT(DisableFormData)
OPTION_OPT(DisableHtmlScan)
OPTION_OPT(DisableInputScan)
OPTION_OPT(DisableTableScan)
OPTION_OPT(DisableMetaScan)
OPTION_OPT(AllFormData)
OPTION_OPT(RedirectStdout)
OPTION_OPT(UndefToEmptyValue)
OPTION_OPT(NoHiddenEmptyValue)
OPTION_OPT(AllowZeroFilesize)
OPTION_OPT(ReturnError)
OPTION_OPT(KeepSrcInMemory)
OPTION_OPT(KeepSpaces)
OPTION_OPT(OpenLogEarly)
OPTION_OPT(NoUncloseWarn)
OPTION_OPT(DisableSelectScan)
OPTION_OPT(ShowBacktrace)
OPTION_OPT(EnableChdir)
OPTION_OPT(FormDataNoUtf8)
} ;
#define OPTION_ESC(a) OPTION(esc##a, a)
tOptionEntry OptionsESCMODE[] =
{
OPTION_ESC(None)
OPTION_ESC(Html)
OPTION_ESC(Url)
OPTION_ESC(Escape)
OPTION_ESC(XML)
OPTION_ESC(Std)
} ;
#define OPTION_IESC(a) OPTION(iesc##a, a)
tOptionEntry OptionsINPUT_ESCMODE[] =
{
OPTION_IESC(None)
OPTION_IESC(Html)
OPTION_IESC(Url)
OPTION_IESC(RemoveTags)
} ;
#define OPTION_OMODE(a) OPTION(omode##a, a)
tOptionEntry OptionsOUTPUT_MODE[] =
{
OPTION_OMODE(Html)
OPTION_OMODE(Xml)
} ;
#define OPTION_OCHARSET(a) OPTION(ocharset##a, a)
tOptionEntry OptionsOUTPUT_ESC_CHARSET[] =
{
OPTION_OCHARSET(Utf8)
OPTION_OCHARSET(Latin1)
OPTION_OCHARSET(Latin2)
} ;
#define OPTION_SMODE(a) OPTION(smode##a, a)
tOptionEntry OptionsSESSION_MODE[] =
{
OPTION_SMODE(None)
OPTION_SMODE(UDatCookie)
OPTION_SMODE(UDatParam)
OPTION_SMODE(UDatUrl)
OPTION_SMODE(SDatParam)
} ;
/*---------------------------------------------------------------------------
* embperl_SetupThread
*/
/*!
*
* \_en
* Setup an thread object. Either take an existing one, if this thread
* already has a azocitaed object or create a new one.
*
* \endif
*
* \_de
* Initialisiert ein Threadobjekt. Ist dem Thread schon ein Objekt zugeorndet
* wird das bestehende genutzt, ansonsten ein neues zur?ck geliefert.
* \endif
*
* ------------------------------------------------------------------------ */
int embperl_SetupThread (/*in*/ pTHX_
/*out*/tThreadData * * ppThread)
{
tThreadData * pThread ;
SV * * ppSV ;
#ifdef SINGLETHREAD
ppSV = &embperl_ThreadDataRV ;
#else
ppSV = hv_fetch (PL_modglobal, "Embperl::Thread", 15, 1) ;
#endif
if (!ppSV)
{
LogErrorParam (NULL, rcHashError, "PL_modglobal (key=Embperl::Thread)", "") ;
return rcHashError ;
}
if (!*ppSV || !SvOK(*ppSV))
{
SV * pThreadRV ;
SV * pThreadSV ;
HV * pStash = gv_stashpv (EMBPERL_PACKAGE_STR, 1) ;
tMemPool * pPool = ep_make_sub_pool (pMainPool) ;
epxs_Embperl__Thread_create_obj(pThread,pThreadSV,pThreadRV,ep_palloc(pPool,sizeof(*pThread))) ;
#ifdef PERL_IMPLICIT_CONTEXT
pThread -> pPerlTHX = aTHX ;
#endif
pThread -> pPool = pPool ;
pThread -> pMainPool = pMainPool ;
pThread -> nPid = getpid () ;
pThread -> pApplications = newHV () ;
pThread -> pFormHash = perl_get_hv (EMBPERL_FDAT_NAME, GV_ADD | GV_ADDMULTI) ;
SvREFCNT_inc(pThread -> pFormHash) ;
pThread -> pFormHashGV = *((GV **)hv_fetch (pStash, FDAT_NAME, sizeof (FDAT_NAME) - 1, 0)) ;
pThread -> pFormSplitHash = perl_get_hv (EMBPERL_SPLIFDAT_NAME, GV_ADD | GV_ADDMULTI) ;
SvREFCNT_inc(pThread -> pFormSplitHash) ;
pThread -> pFormArray = perl_get_av (EMBPERL_FFLD_NAME, GV_ADD | GV_ADDMULTI) ;
SvREFCNT_inc(pThread -> pFormArray) ;
pThread -> pFormArrayGV = *((GV **)hv_fetch (pStash, FFLD_NAME, sizeof (FFLD_NAME) - 1, 0)) ;
pThread -> pHeaderHash = perl_get_hv (EMBPERL_HDR_NAME, GV_ADD | GV_ADDMULTI) ;
SvREFCNT_inc(pThread -> pHeaderHash) ;
pThread -> pInputHash = perl_get_hv (EMBPERL_IDAT_NAME, GV_ADD | GV_ADDMULTI) ;
SvREFCNT_inc(pThread -> pInputHash) ;
#ifdef DMALLOC
pThread -> pEnvHash = Perl_get_hv(aTHX_ EMBPERL_ENV_NAME, GV_ADD | GV_ADDMULTI) ;
#else
pThread -> pEnvHash = perl_get_hv (EMBPERL_ENV_NAME, GV_ADD | GV_ADDMULTI) ;
#endif
SvREFCNT_inc(pThread -> pEnvHash) ;
pThread -> pParamArray = perl_get_av (EMBPERL_PARAM_NAME, GV_ADD | GV_ADDMULTI) ;
SvREFCNT_inc(pThread -> pParamArray) ;
pThread -> pParamArrayGV = *((GV **)hv_fetch (pStash, PARAM_NAME, sizeof (PARAM_NAME) - 1, 0)) ;
pThread -> pReqRV = perl_get_sv (EMBPERL_REQ_NAME, GV_ADD | GV_ADDMULTI) ;
SvREFCNT_inc(pThread -> pReqRV) ;
pThread -> pAppRV = perl_get_sv (EMBPERL_APP_NAME, GV_ADD | GV_ADDMULTI) ;
SvREFCNT_inc(pThread -> pAppRV) ;
*ppSV = pThreadRV ;
}
else
{
pThread = epxs_sv2_Embperl__Thread(*ppSV) ;
}
*ppThread = pThread ;
return ok ;
}
/*---------------------------------------------------------------------------
* embperl_GetThread
*/
/*!
*
* \_en
* Returns already has a azocitaed object thread object. The thread object
* must be setup before via embperl_SetupThread
* \endif
*
* \_de
* Liefert das diesem Thread zugeordnete Thread-Objekt zur?ck. Das Objekt mu?
* vorher mittels embperl_SetupThread initialisiert worden sein.
* \endif
*
* ------------------------------------------------------------------------ */
tThreadData * embperl_GetThread (/*in*/ pTHX)
{
tThreadData * pThread ;
int rc ;
if ((rc = embperl_SetupThread (aTHX_ &pThread)) != ok)
{
LogError (NULL, rc) ;
return NULL ;
}
return pThread ;
}
/*---------------------------------------------------------------------------
* embperl_EndPass1
*/
/*!
*
* \_en
* Call when configuration pass 1 of apache is done.
* \endif
*
* \_de
* Wird aufgerufen wenn Pass 1 des Einlesens der Konfiguration beendet ist.
* \endif
*
* ------------------------------------------------------------------------ */
int embperl_EndPass1 (void)
{
tThreadData * pThread ;
dTHX ;
pThread = embperl_GetThread (aTHX) ;
hv_clear (pThread -> pApplications) ;
return ok ;
}
/*---------------------------------------------------------------------------
* embperl_CreateSessionObject
*/
/*!
*
* \_en
* Creates a new session object.
*
* \endif
*
* \_de
* Erzeugt eine neues Sessionobjekt.
*
* \endif
*
* ------------------------------------------------------------------------ */
static int embperl_CreateSessionObject(/*in*/ tApp * a,
/*in*/ HV * pArgs,
/*out*/ HV * * ppHash,
/*out*/ SV * * ppObj)
{
epaTHX_
dSP ;
tAppConfig * pCfg = &a -> Config ;
char * sPackage = pCfg -> sSessionHandlerClass ;
HV * pHash = newHV () ;
SV * pTie = NULL ;
int n ;
SV * pSVCode ;
pSVCode = newSVpvf ("require %s", sPackage) ;
newSVpvf2(pSVCode) ;
/* there is no c api to the require function, eval it... */
perl_eval_sv(pSVCode, G_EVAL | G_DISCARD) ;
SvREFCNT_dec(pSVCode);
tainted = 0 ;
if (SvTRUE (ERRSV))
{
STRLEN l ;
if (strcmp (sPackage, "Apache::SessionX") != 0 ||
GetHashValueStr (aTHX_ a -> pThread -> pEnvHash, "GATEWAY_INTERFACE", NULL))
LogErrorParam (a, rcSetupSessionErr, SvPV (ERRSV, l), NULL) ;
sv_setpv(ERRSV,"");
return rcEvalErr ;
}
SPAGAIN;
PUSHMARK(sp);
XPUSHs(sv_2mortal(newSVpv(sPackage, 0)));
XPUSHs(&sv_undef); /* id */
XPUSHs(sv_2mortal (newRV((SV *)pArgs)));
PUTBACK;
n = perl_call_method ("TIEHASH", G_EVAL | G_SCALAR) ;
SPAGAIN;
if (n > 0)
pTie = POPs ;
PUTBACK;
if (SvTRUE (ERRSV))
{
STRLEN l ;
LogErrorParam (a, rcSetupSessionErr, SvPV (ERRSV, l), NULL) ;
sv_setpv(ERRSV,"");
return rcEvalErr ;
}
if (n == 0 || !SvROK(pTie))
{
LogErrorParam (a, rcSetupSessionErr, "TIEHASH didn't returns a hashref", sPackage) ;
return rcNotHashRef ;
}
hv_magic(pHash, (GV *)pTie, 'P') ;
*ppHash = pHash ;
*ppObj = SvREFCNT_inc(pTie) ;
return ok ;
}
/*---------------------------------------------------------------------------
* embperl_SetupSessionObjects
*/
/*!
*
* \_en
* Setup the session onbjects.
*
* \endif
*
* \_de
* Initialisiert neue Sessionobjekte.
*
* \endif
*
* ------------------------------------------------------------------------ */
int embperl_SetupSessionObjects (/*in*/ tApp * a)
{
epaTHX_
int rc ;
SV * pStore ;
SV ** ppStore ;
SV * pLocker ;
SV ** ppLocker ;
SV * pSerializer ;
SV ** ppSerializer ;
SV * pGenerator ;
SV ** ppGenerator ;
tAppConfig * pCfg = &a -> Config ;
HV * pArgs = pCfg -> pSessionArgs ;
HV * pArgs1 ;
HV * pArgs2 ;
HV * pArgs3 ;
dSP ;
if (strcmp (pCfg -> sSessionHandlerClass, "no") == 0)
return ok ;
if (!pArgs)
pCfg -> pSessionArgs = pArgs = newHV() ;
if (pCfg -> pSessionClasses)
{
if ((ppStore = av_fetch (pCfg -> pSessionClasses, 0, 0)))
pStore = SvREFCNT_inc(*ppStore) ;
else
pStore = newSVpv("File", 4) ;
hv_store (pArgs, "Store", 5, pStore, 0) ;
if ((ppLocker = av_fetch (pCfg -> pSessionClasses, 1, 0)))
pLocker = SvREFCNT_inc(*ppLocker) ;
else
pLocker = newSVpv("Null", 4) ;
hv_store (pArgs, "Lock", 4, pLocker, 0) ;
if ((ppSerializer = av_fetch (pCfg -> pSessionClasses, 2, 0)))
pSerializer = SvREFCNT_inc(*ppSerializer) ;
else
pSerializer = newSVpv("Storable", 8) ;
hv_store (pArgs, "Serialize", 9, pSerializer, 0) ;
if ((ppGenerator = av_fetch (pCfg -> pSessionClasses, 3, 0)))
pGenerator = SvREFCNT_inc(*ppGenerator) ;
else
pGenerator = newSVpv("MD5", 3) ;
hv_store (pArgs, "Generate", 8, pGenerator, 0) ;
}
else
{
/* workaround for perl bug in newHVhv when to less hash entries */
hv_store (pArgs, "__dummy1__", 10, newSViv (1), 0) ;
hv_store (pArgs, "__dummy2__", 10, newSViv (1), 0) ;
hv_store (pArgs, "__dummy3__", 10, newSViv (1), 0) ;
hv_store (pArgs, "__dummy4__", 10, newSViv (1), 0) ;
}
if (pCfg -> sSessionConfig)
hv_store (pArgs, "config", 5, newSVpv (pCfg -> sSessionConfig, 0), 0) ;
hv_store (pArgs, "lazy", 4, newSViv (1), 0) ;
hv_store (pArgs, "create_unknown", 14, newSViv (1), 0) ;
pArgs1 = newHVhv(pArgs) ;
hv_store (pArgs1, "Transaction", 11, newSViv (1), 0) ;
pArgs2 = newHVhv(pArgs) ;
hv_store (pArgs2, "recreate_id", 11, newSViv (1), 0) ;
pArgs3 = newHVhv(pArgs2) ;
if ((rc = embperl_CreateSessionObject (a, pArgs1, &a -> pAppHash, &a -> pAppObj)) != ok)
return rc ;
SPAGAIN ;
PUSHMARK(sp);
XPUSHs(a -> pAppObj);
XPUSHs(sv_2mortal (newSVpv(a -> Config.sAppName, 0)));
PUTBACK;
perl_call_method ("setidfrom", G_DISCARD) ;
if ((rc = embperl_CreateSessionObject (a, pArgs2, &a -> pUserHash, &a -> pUserObj)) != ok)
return rc ;
hv_store (pArgs3, "newid", 5, newSViv (1), 0) ;
if ((rc = embperl_CreateSessionObject (a, pArgs3, &a -> pStateHash, &a -> pStateObj)) != ok)
return rc ;
return ok ;
}
/*---------------------------------------------------------------------------
* embperl_SetupApp
*/
/*!
*
* \_en
* Setup an application object. Either take an existing one, if the
* application is already created for that thread or create a new
* one.
*
* @param pThread per thread data
* @param pApacheCfg apache configuration vector
* @param pPerlParam parameters passed from Perl
* \endif
*
* \_de
* Initialisiert ein Applicationobjekt. Entweder wird ein bereits bestehendes
* benutzt, oder falls nicht vorhanden, ein neues erzeugt.
*
* @param pThread per thread daten
* @param pApacheCfg apache Konfigurations Vector
* @param pPerlParam Parameter die von Perl aus ?bergeben wurden
* \endif
*
* ------------------------------------------------------------------------ */
int embperl_SetupApp (/*in*/ pTHX_
/*in*/ tThreadData * pThread,
/*in*/ tApacheDirConfig * pApacheCfg,
/*in*/ SV * pPerlParam,
/*out*/tApp * * ppApp)
{
char * sAppName = NULL ;
tApp * pApp = NULL ;
HV * pParam = NULL ;
if (pPerlParam && SvROK(pPerlParam))
{
pParam = (HV *)SvRV(pPerlParam) ;
sAppName = GetHashValueStr (aTHX_ pParam, "app_name", NULL) ;
if (!sAppName) // backward compability to broken appname
sAppName = GetHashValueStr (aTHX_ pParam, "appname", NULL) ;
}
if (!sAppName)
{
#ifdef APACHE
if (pApacheCfg)
sAppName = embperl_GetApacheAppName (pApacheCfg) ;
else
#endif
sAppName = embperl_GetCGIAppName (pThread) ;
}
if (sAppName)
pApp = (tApp * )GetHashValuePtr (NULL, pThread -> pApplications, sAppName, NULL) ;
if (!pApp)
{
int rc ;
SV * pAppSV ;
SV * pAppRV ;
SV * pSV ;
SV * pRV ;
tAppConfig * pCfg ;
tMemPool * pPool = ep_make_sub_pool (pThread -> pPool) ;
epxs_Embperl__App_create_obj(pApp,pAppSV,pAppRV,ep_palloc(pPool,sizeof(*pApp))) ;
epxs_Embperl__App__Config_create_obj(pCfg,pSV,pRV,&pApp -> Config) ;
#ifdef PERL_IMPLICIT_CONTEXT
pApp -> pPerlTHX = aTHX ;
#endif
pApp -> pPool = pPool ;
pCfg -> pPool = pPool ;
#ifdef APACHE
if (pApacheCfg)
embperl_GetApacheAppConfig (pThread, pPool, pApacheCfg, &pApp -> Config) ;
else
#endif
{
bool bUseEnv = 0 ;
bool bUseRedirectEnv = 0 ;
if (pParam)
{
bUseEnv = (bool)GetHashValueInt (aTHX_ pParam, "use_env", 0) ;
bUseRedirectEnv = (bool)GetHashValueInt (aTHX_ pParam, "use_redirect_env", 0) ;
}
embperl_GetCGIAppConfig (pThread, pPool, &pApp -> Config, bUseEnv, bUseRedirectEnv, 1) ;
}
SetHashValueInt (NULL, pThread -> pApplications, sAppName, (IV)pApp) ;
pApp -> pThread = pThread ;
if (pParam)
Embperl__App__Config_new_init(aTHX_ &pApp -> Config, (SV *)pParam, 0) ;
tainted = 0 ;
if (pApp -> Config.sLog && pApp -> Config.sLog[0])
{
if ((rc = OpenLog (pApp)) != ok)
{
pApp -> Config.bDebug = 0 ; /* Turn debbuging off, only errors will go to stderr */
LogErrorParam (pApp, rc, pApp -> Config.sLog, Strerror(errno)) ;
}
}
if (pApp -> Config.sAppHandlerClass)
{
HV * stash = gv_stashpv(pApp -> Config.sAppHandlerClass, TRUE) ;
sv_bless(pApp -> _perlsv, stash) ;
}
embperl_SetupSessionObjects (pApp) ;
}
sv_setsv(pThread -> pAppRV, pApp -> _perlsv) ;
*ppApp = pApp ;
return ok ;
}
static int notused ;
#if 0
INTMG (TabCount, pCurrReq -> TableStack.State.nCount, pCurrReq -> TableStack.State.nCountUsed, ;)
INTMG (TabRow, pCurrReq -> TableStack.State.nRow, pCurrReq -> TableStack.State.nRowUsed, ;)
INTMG (TabCol, pCurrReq -> TableStack.State.nCol, pCurrReq -> TableStack.State.nColUsed, ;)
INTMG (TabMaxRow, pCurrReq -> nTabMaxRow, notused, ;)
INTMG (TabMaxCol, pCurrReq -> nTabMaxCol, notused, ;)
INTMG (TabMode, pCurrReq -> nTabMode, notused, ;)
#endif
INTMG_COMP (EscMode, Config.nEscMode, notused, NewEscMode (CurrReq, pSV))
#ifdef EP2
INTMGshort_COMP (CurrNode, xCurrNode)
#endif
OPTMGRD_COMP (optDisableVarCleanup , Config.bOptions)
OPTMG_COMP (optDisableEmbperlErrorPage, Config.bOptions)
OPTMG_COMP (optReturnError , Config.bOptions)
OPTMGRD_COMP (optSafeNamespace , Config.bOptions)
OPTMGRD_COMP (optOpcodeMask , Config.bOptions)
OPTMG_COMP (optRawInput , Config.bOptions)
OPTMG_COMP (optSendHttpHeader , Config.bOptions)
OPTMGRD_COMP (optDisableChdir , Config.bOptions)
OPTMG_COMP (optDisableHtmlScan , Config.bOptions)
OPTMGRD_COMP (optEarlyHttpHeader , Config.bOptions)
OPTMGRD_COMP (optDisableFormData , Config.bOptions)
OPTMG_COMP (optDisableInputScan , Config.bOptions)
OPTMG_COMP (optDisableTableScan , Config.bOptions)
OPTMG_COMP (optDisableMetaScan , Config.bOptions)
OPTMGRD_COMP (optAllFormData , Config.bOptions)
OPTMGRD_COMP (optRedirectStdout , Config.bOptions)
OPTMG_COMP (optUndefToEmptyValue , Config.bOptions)
OPTMG_COMP (optNoHiddenEmptyValue , Config.bOptions)
OPTMGRD_COMP (optAllowZeroFilesize , Config.bOptions)
OPTMGRD_COMP (optKeepSrcInMemory , Config.bOptions)
OPTMG_COMP (optKeepSpaces , Config.bOptions)
OPTMG_COMP (optOpenLogEarly , Config.bOptions)
OPTMG_COMP (optNoUncloseWarn , Config.bOptions)
OPTMG_COMP (dbgStd , Config.bDebug)
OPTMG_COMP (dbgMem , Config.bDebug)
OPTMG_COMP (dbgEval , Config.bDebug)
OPTMG_COMP (dbgCmd , Config.bDebug)
OPTMG_COMP (dbgEnv , Config.bDebug)
OPTMG_COMP (dbgForm , Config.bDebug)
OPTMG_COMP (dbgTab , Config.bDebug)
OPTMG_COMP (dbgInput , Config.bDebug)
OPTMG_COMP (dbgFlushOutput , Config.bDebug)
OPTMG_COMP (dbgFlushLog , Config.bDebug)
OPTMG_COMP (dbgAllCmds , Config.bDebug)
OPTMG_COMP (dbgSource , Config.bDebug)
OPTMG_COMP (dbgFunc , Config.bDebug)
OPTMG_COMP (dbgLogLink , Config.bDebug)
OPTMG_COMP (dbgDefEval , Config.bDebug)
OPTMG_COMP (dbgHeadersIn , Config.bDebug)
OPTMG_COMP (dbgShowCleanup , Config.bDebug)
OPTMG_COMP (dbgProfile , Config.bDebug)
OPTMG_COMP (dbgSession , Config.bDebug)
OPTMG_COMP (dbgImport , Config.bDebug)
/* ---------------------------------------------------------------------------- */
/* add magic to integer var */
/* */
/* in sVarName = Name of varibale */
/* in pVirtTab = pointer to virtual table */
/* */
/* ---------------------------------------------------------------------------- */
static int AddMagic (/*i/o*/ tApp * a,
/*in*/ char * sVarName,
/*in*/ MGVTBL * pVirtTab)
{
SV * pSV ;
struct magic * pMagic ;
epaTHX ;
EPENTRY (AddMagic) ;
pSV = perl_get_sv (sVarName, TRUE) ;
sv_magic (pSV, NULL, 0, sVarName, strlen (sVarName)) ;
sv_setiv (pSV, 0) ;
pMagic = mg_find (pSV, 0) ;
if (pMagic)
pMagic -> mg_virtual = pVirtTab ;
else
{
LogError (NULL, rcMagicError) ;
return 1 ;
}
perl_get_sv (sVarName, TRUE) ; /* avoid warning */
return ok ;
}
/* ---------------------------------------------------------------------------- */
/* add magic to array */
/* */
/* in sVarName = Name of varibale */
/* in pVirtTab = pointer to virtual table */
/* */
/* ---------------------------------------------------------------------------- */
int AddMagicAV (/*i/o*/ register req * r,
/*in*/ char * sVarName,
/*in*/ MGVTBL * pVirtTab)
{
SV * pSV ;
struct magic * pMagic ;
epTHX ;
EPENTRY (AddMagicAV) ;
pSV = (SV *)perl_get_av (sVarName, TRUE) ;
sv_magic (pSV, NULL, 'P', sVarName, strlen (sVarName)) ;
pMagic = mg_find (pSV, 0) ;
if (pMagic)
pMagic -> mg_virtual = pVirtTab ;
else
{
LogError (r, rcMagicError) ;
return 1 ;
}
return ok ;
}
/* ---------------------------------------------------------------------------- */
/* init embperl module */
/* */
/* in nIOType = type of requested i/o */
/* */
/* ---------------------------------------------------------------------------- */
int embperl_Init (/*in*/ pTHX_
/*in*/ SV * pApacheSrvSV,
/*in*/ SV * pPerlParam,
/*in*/ server_rec * ap_s)
{
int rc ;
tThreadData * pThread ;
tApp * pApp ;
tApacheDirConfig * pApacheCfg = NULL ;
memcpy (&ep_sv_undef, &PL_sv_undef, sizeof (PL_sv_undef)) ;
#ifdef APACHE
if (pApacheSrvSV && SvROK (pApacheSrvSV))
{
/* when running under mod_perl only register the module */
/* rest will be call from module initialzation when config has been read */
ap_s = epxs_sv2_Apache__Server(pApacheSrvSV) ;
embperl_ApacheAddModule () ;
#ifdef APACHE2
#else
return ok ;
#endif
}
#endif
if (!pMainPool)
pMainPool = ep_init_alloc() ;
if ((rc = embperl_SetupThread (aTHX_ &pThread)) != ok)
return rc ;
#ifdef APACHE
if (ap_s)
{
embperl_GetApacheConfig (pThread, NULL, ap_s, &pApacheCfg) ;
}
#endif
if ((rc = embperl_SetupApp (aTHX_ pThread, pApacheCfg, pPerlParam, &pApp)) != ok)
return rc ;
ADDINTMG (EscMode)
ADDINTMG (CurrNode)
ADDOPTMG (optDisableVarCleanup )
ADDOPTMG (optDisableEmbperlErrorPage)
ADDOPTMG (optReturnError)
ADDOPTMG (optSafeNamespace )
ADDOPTMG (optOpcodeMask )
ADDOPTMG (optRawInput )
ADDOPTMG (optSendHttpHeader )
ADDOPTMG (optDisableChdir )
ADDOPTMG (optDisableHtmlScan )
ADDOPTMG (optEarlyHttpHeader )
ADDOPTMG (optDisableFormData )
ADDOPTMG (optDisableInputScan )
ADDOPTMG (optDisableTableScan )
ADDOPTMG (optDisableMetaScan )
ADDOPTMG (optAllFormData )
ADDOPTMG (optRedirectStdout )
ADDOPTMG (optUndefToEmptyValue )
ADDOPTMG (optNoHiddenEmptyValue )
ADDOPTMG (optAllowZeroFilesize )
ADDOPTMG (optKeepSrcInMemory )
ADDOPTMG (optKeepSpaces )
ADDOPTMG (optOpenLogEarly )
ADDOPTMG (optNoUncloseWarn )
ADDOPTMG (dbgStd )
ADDOPTMG (dbgMem )
ADDOPTMG (dbgEval )
ADDOPTMG (dbgCmd )
ADDOPTMG (dbgEnv )
ADDOPTMG (dbgForm )
ADDOPTMG (dbgTab )
ADDOPTMG (dbgInput )
ADDOPTMG (dbgFlushOutput )
ADDOPTMG (dbgFlushLog )
ADDOPTMG (dbgAllCmds )
ADDOPTMG (dbgSource )
ADDOPTMG (dbgFunc )
ADDOPTMG (dbgLogLink )
ADDOPTMG (dbgDefEval )
ADDOPTMG (dbgHeadersIn )
ADDOPTMG (dbgShowCleanup )
ADDOPTMG (dbgProfile )
ADDOPTMG (dbgSession )
ADDOPTMG (dbgImport )
if (bInitDone)
return ok ; /* the rest needs to be done only once per process */
#if defined (_MDEBUG) && defined (WIN32)
_CrtSetReportHook( EmbperlCRTDebugOutput );
#endif
DomInit (pApp) ;
Cache_Init (pApp) ;
Provider_Init (pApp) ;
#ifdef APACHE2
ApFilter_Init (pApp) ;
#endif
#ifdef XALAN
embperl_Xalan_Init () ;
#endif
#ifdef LIBXSLT
embperl_LibXSLT_Init () ;
#endif
ep_create_mutex(RequestCountMutex) ;
bInitDone = 1 ;
#ifdef APACHE
{
int preload = 1 ;
if (ap_s)
{
module * m ;
if ((m = ap_find_linked_module("mod_perl.c")))
{
if (m -> dynamic_load_handle)
preload = 0 ;
}
}
if (preload)
{
dSP;
PUSHMARK(sp) ;
perl_call_pv ("Embperl::PreLoadFiles", G_DISCARD) ;
}
}
#else
{
dSP;
PUSHMARK(sp) ;
perl_call_pv ("Embperl::PreLoadFiles", G_DISCARD) ;
}
#endif
return rc ;
}
/*---------------------------------------------------------------------------
* embperl_GetFormData
*/
/*!
*
* \_en
* Takes the given form data and put them in %fdat/@ffld
* \endif
*