epmain.c

filter: Statementstmt 0.0% 0 / 554 Branchbran 0.0% 0 / 426 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 980 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« epio.c ↑ Summary epmem.c »
1 /*###################################################################################
2 #
3 # Embperl - Copyright (c) 1997-2008 Gerald Richter / ecos gmbh www.ecos.de
4 # Embperl - Copyright (c) 2008-2015 Gerald Richter
5 # Embperl - Copyright (c) 2015-2023 actevy.io
6 #
7 # You may distribute under the terms of either the GNU General Public
8 # License or the Artistic License, as specified in the Perl README file.
9 # For use with Apache httpd and mod_perl, see also Apache copyright.
10 #
11 # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
12 # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
13 # WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14 #
15 ###################################################################################*/
16  
17  
18 #include "ep.h"
19 #include "epmacro.h"
20  
21  
22  
23  
24 /*---------------------------------------------------------------------------
25 * DoLogError
26 */
27 /*!
28 *
29 * \_en
30 * Logs the occurence of an error to the embperl logfile and the httpd error log
31 *
32 * @param r the request object (maybe NULL)
33 * @param a the application object (maybe NULL)
34 * @param rc the error code
35 * @param errdat1 addtional information
36 * @param errdat2 addtional information
37 * \endif
38 *
39 * \_de
40 * logged das auftreten eines Fehler in das Embperl Logfile und den httpd
41 * error log
42 *
43 * @param r das Requestobjekt (kann NULL sein)
44 * @param a das Applikationobjekt (kann NULL sein)
45 * @param rc Fehlercode
46 * @param errdat1 Zusätzliche Informationen
47 * @param errdat2 Zusätzliche Informationen
48 * \endif
49 *
50 * ------------------------------------------------------------------------ */
51  
52 0 static char * DoLogError (/*i/o*/ struct tReq * r,
53 /*i/o*/ struct tApp * a,
54 /*in*/ int rc,
55 /*in*/ const char * errdat1,
56 /*in*/ const char * errdat2)
57  
58 {
59 const char * msg ;
60 char * sText ;
61 SV * pSV ;
62 0 SV * pSVLine = NULL ;
63 STRLEN l ;
64 pid_t nPid ;
65  
66 #ifdef PERL_IMPLICIT_CONTEXT
67 pTHX ;
68 if (r)
69 aTHX = r -> pPerlTHX ;
70 else if (a)
71 aTHX = a -> pPerlTHX ;
72 else
73 aTHX = PERL_GET_THX ;
74 #endif
75  
76  
77 0 ▶ if (r)
Branch: 1 branch
BranchTrueFalseTotal
if (r) 0 0 0
78 {
79 0 r -> errdat1 [sizeof (r -> errdat1) - 1] = '\0' ;
80 0 r -> errdat2 [sizeof (r -> errdat2) - 1] = '\0' ;
81  
82 0 GetLineNo (r) ;
83  
84 0 errdat1 = r -> errdat1 ;
85 0 errdat2 = r -> errdat2 ;
86  
87 0 ▶ if (rc != rcPerlWarn)
Branch: 1 branch
BranchTrueFalseTotal
if (rc != rcPerlWarn) 0 0 0
88 0 r -> bError = 1 ;
89 0 nPid = r -> pThread -> nPid ;
90 0 a = r -> pApp ;
91 }
92 0 ▶ else if (a)
Branch: 1 branch
BranchTrueFalseTotal
else if (a) 0 0 0
93 {
94 0 nPid = a -> pThread -> nPid ;
95 }
96 else
97 0 nPid = getpid() ;
98  
99
100 0 ▶ if (!errdat1)
Branch: 1 branch
BranchTrueFalseTotal
if (!errdat1) 0 0 0
101 0 errdat1 = "" ;
102 0 ▶ if (!errdat2)
Branch: 1 branch
BranchTrueFalseTotal
if (!errdat2) 0 0 0
103 0 errdat2 = "" ;
104
105 0 switch (rc)
106 {
107 0 case ok: msg ="[%d]ERR: %d: %s ok%s%s" ; break ;
108 0 case rcStackOverflow: msg ="[%d]ERR: %d: %s Stack Overflow%s%s" ; break ;
109 0 case rcArgStackOverflow: msg ="[%d]ERR: %d: %s Argumnet Stack Overflow (%s)%s" ; break ;
110 0 case rcStackUnderflow: msg ="[%d]ERR: %d: %s Stack Underflow%s%s" ; break ;
111 0 case rcEndifWithoutIf: msg ="[%d]ERR: %d: %s endif without if%s%s" ; break ;
112 0 case rcElseWithoutIf: msg ="[%d]ERR: %d: %s else without if%s%s" ; break ;
113 0 case rcEndwhileWithoutWhile: msg ="[%d]ERR: %d: %s endwhile without while%s%s" ; break ;
114 0 case rcEndtableWithoutTable: msg ="[%d]ERR: %d: %s blockend <%s> does not match blockstart <%s>" ; break ;
115 0 case rcTablerowOutsideOfTable: msg ="[%d]ERR: %d: %s <tr> outside of table%s%s" ; break ;
116 0 case rcCmdNotFound: msg ="[%d]ERR: %d: %s Unknown Command %s%s" ; break ;
117 0 case rcOutOfMemory: msg ="[%d]ERR: %d: %s Out of memory %s %s" ; break ;
118 0 case rcPerlVarError: msg ="[%d]ERR: %d: %s Perl variable error %s%s" ; break ;
119 0 case rcHashError: msg ="[%d]ERR: %d: %s Perl hash error, %%%s does not exist%s" ; break ;
120 0 case rcArrayError: msg ="[%d]ERR: %d: %s Perl array error , @%s does not exist%s" ; break ;
121 0 case rcFileOpenErr: msg ="[%d]ERR: %d: %s File %s open error: %s" ; break ;
122 0 case rcLogFileOpenErr: msg ="[%d]ERR: %d: %s Logfile %s open error: %s" ; break ;
123 0 case rcMissingRight: msg ="[%d]ERR: %d: %s Missing right %s%s" ; break ;
124 0 case rcNoRetFifo: msg ="[%d]ERR: %d: %s No Return Fifo%s%s" ; break ;
125 0 case rcMagicError: msg ="[%d]ERR: %d: %s Perl Magic Error%s%s" ; break ;
126 0 case rcWriteErr: msg ="[%d]ERR: %d: %s File write Error%s%s" ; break ;
127 0 case rcUnknownNameSpace: msg ="[%d]ERR: %d: %s Namespace %s unknown%s" ; break ;
128 0 case rcInputNotSupported: msg ="[%d]ERR: %d: %s Input not supported in mod_perl mode%s%s" ; break ;
129 0 case rcCannotUsedRecursive: msg ="[%d]ERR: %d: %s Cannot be called recursively in mod_perl mode%s%s" ; break ;
130 0 case rcEndtableWithoutTablerow: msg ="[%d]ERR: %d: %s </tr> without <tr>%s%s" ; break ;
131 0 case rcEndtextareaWithoutTextarea: msg ="[%d]ERR: %d: %s </textarea> without <textarea>%s%s" ; break ;
132 0 case rcEvalErr: msg ="[%d]ERR: %d: %s Error in Perl code: %s%s" ; break ;
133 0 case rcNotCompiledForModPerl: msg ="[%d]ERR: %d: %s Embperl is not compiled for mod_perl. Rerun Makefile.PL and give the correct Apache source tree location %s%s" ; break ;
134 0 case rcExecCGIMissing: msg ="[%d]ERR: %d: %s Forbidden %s: Options ExecCGI not set in your Apache configs%s" ; break ;
135 0 case rcIsDir: msg ="[%d]ERR: %d: %s Forbidden %s is a directory%s" ; break ;
136 0 case rcXNotSet: msg ="[%d]ERR: %d: %s Forbidden %s X Bit not set%s" ; break ;
137 0 case rcNotFound: msg ="[%d]ERR: %d: %s Not found '%s', searched: %s" ; break ;
138 0 case rcTokenNotFound: msg ="[%d]ERR: %d: %s Token not found '%s', %s" ; break ;
139 0 case rcUnknownVarType: msg ="[%d]ERR: %d: %s Type for Variable %s is unknown %s" ; break ;
140 0 case rcPerlWarn: msg ="[%d]ERR: %d: %s Warning in Perl code: %s%s" ; break ;
141 0 case rcVirtLogNotSet: msg ="[%d]ERR: %d: %s EMBPERL_VIRTLOG must be set, when dbgLogLink is set %s%s" ; break ;
142 0 case rcMissingInput: msg ="[%d]ERR: %d: %s Sourcedata/-file missing %s%s" ; break ;
143 0 case rcUntilWithoutDo: msg ="[%d]ERR: %d: %s until without do%s%s" ; break ;
144 0 case rcEndforeachWithoutForeach:msg ="[%d]ERR: %d: %s endforeach without foreach%s%s" ; break ;
145 0 case rcMissingArgs: msg ="[%d]ERR: %d: %s Too few arguments%s%s" ; break ;
146 0 case rcNotAnArray: msg ="[%d]ERR: %d: %s Second Argument must be array/list%s%s" ; break ;
147 0 case rcCallInputFuncFailed: msg ="[%d]ERR: %d: %s Call to Input Function failed: %s%s" ; break ;
148 0 case rcCallOutputFuncFailed: msg ="[%d]ERR: %d: %s Call to Output Function failed: %s%s" ; break ;
149 0 case rcSubNotFound: msg ="[%d]ERR: %d: %s Call to unknown Embperl macro %s%s" ; break ;
150 0 case rcImportStashErr: msg ="[%d]ERR: %d: %s Package %s for import unknown%s" ; break ;
151 0 case rcCGIError: msg ="[%d]ERR: %d: %s Setup of CGI.pm failed: %s%s" ; break ;
152 0 case rcUnclosedHtml: msg ="[%d]ERR: %d: %s Unclosed HTML tag <%s> at end of file %s" ; break ;
153 0 case rcUnclosedCmd: msg ="[%d]ERR: %d: %s Unclosed command [$ %s $] at end of file %s" ; break ;
154 0 case rcNotAllowed: msg ="[%d]ERR: %d: %s Forbidden %s: Does not match EMBPERL_ALLOW %s" ; break ;
155 0 case rcNotHashRef: msg ="[%d]ERR: %d: %s %s need hashref in '%s'" ; break ;
156 0 case rcTagMismatch: msg ="[%d]ERR: %d: %s Endtag '%s' doesn't match starttag '%s'" ; break ;
157 0 case rcCleanupErr: msg ="[%d]ERR: %d: %s Error in cleanup %s%s" ; break ;
158 0 case rcCryptoWrongHeader: msg ="[%d]ERR: %d: %s Decrypt-error: Not encrypted (%s)%s" ; break ;
159 0 case rcCryptoWrongSyntax: msg ="[%d]ERR: %d: %s Decrypt-error: Wrong syntax (%s)%s" ; break ;
160 0 case rcCryptoNotSupported: msg ="[%d]ERR: %d: %s Decrypt-error: Not supported (%s)%s" ; break ;
161 0 case rcCryptoBufferOverflow: msg ="[%d]ERR: %d: %s Decrypt-error: Buffer overflow (%s)%s" ; break ;
162 0 case rcCryptoErr: msg ="[%d]ERR: %d: %s Decrypt-error: OpenSSL error (%s)%s" ; break ;
163 0 case rcUnknownProvider: msg ="[%d]ERR: %d: %s Unknown Provider %s %s" ; break ;
164 0 case rcXalanError: msg ="[%d]ERR: %d: %s Xalan Error: %s: %s" ; break ;
165 0 case rcLibXSLTError: msg ="[%d]ERR: %d: %s LibXSLT Error: %s: %s" ; break ;
166 0 case rcMissingParam: msg ="[%d]ERR: %d: %s Missing Parameter %s %s" ; break ;
167 0 case rcNotCodeRef: msg ="[%d]ERR: %d: %s %s need coderef in '%s'" ; break ;
168 0 case rcUnknownRecipe: msg ="[%d]ERR: %d: %s Unknown recipe '%s'" ; break ;
169 0 case rcTypeMismatch: msg ="[%d]ERR: %d: %s Unsupported Outputformat %s of %s" ; break ;
170 0 case rcChdirError: msg ="[%d]ERR: %d: %s Cannot change to directory %s %s" ; break ;
171 0 case rcUnknownSyntax: msg ="[%d]ERR: %d: %s Unknown syntax '%s'" ; break ;
172 0 case rcForbidden: msg ="[%d]ERR: %d: %s Access Forbidden for '%s'" ; break ;
173 0 case rcDecline: msg ="[%d]ERR: %d: %s Decline for '%s'" ; break ;
174 0 case rcCannotCheckUri: msg ="[%d]ERR: %d: %s Cannot check URI against ALLOW and/or URIMATCH because URI is unknown" ; break ;
175 0 case rcSetupSessionErr: msg ="[%d]ERR: %d: %s Embperl Session handling DISABLED because of the following error: %s\nSet EMBPERL_SESSION_HANDLER_CLASS to 'no' to avoid this message. %s" ; break ;
176 0 case rcRefcntNotOne: msg ="[%d]ERR: %d: %s There is still %s reference(s) to the %s object, while there shouldn't be any." ; break ;
177 0 case rcApacheErr: msg ="[%d]ERR: %d: %s Apache returns Error: %s %s" ; break ;
178 0 case rcTooDeepNested: msg ="[%d]ERR: %d: %s Source data is too deep nested %s %s" ; break ;
179 0 case rcUnknownOption: msg ="[%d]ERR: %d: %s Unknown option '%s' in configuration directive '%s'" ; break ;
180 0 case rcTimeFormatErr: msg ="[%d]ERR: %d: %s Format error in %s = %s" ; break ;
181 0 case rcSubCallNotRequest: msg ="[%d]ERR: %d: %s A Embperl sub is called and no Embperl request is running %s %s" ; break ;
182 0 case rcNotScalarRef: msg ="[%d]ERR: %d: %s %s need scalar in '%s'" ; break ;
183 0 case rcFormDataTruncated: msg ="[%d]ERR: %d: %s Formdata exceeded length of %s bytes, truncated" ; break ;
184  
185 0 default: msg ="[%d]ERR: %d: %s Error (no description) %s %s" ; break ;
186 }
187  
188 0 ▶ if (r && ((rc != rcPerlWarn && rc != rcEvalErr) || r -> errdat1[0] == '\0'))
Branch: 4 branches
BranchTrueFalseTotal
if (r && ((rc != rcPerlWarn && rc != rcEvalErr) || r -> errdat1[0] == '\0')) 0 0 0
if (r && ((rc != rcPerlWarn && rc != rcEvalErr) || r -> errdat1[0] == '\0')) 0 0 0
if (r && ((rc != rcPerlWarn && rc != rcEvalErr) || r -> errdat1[0] == '\0')) 0 0 0
if (r && ((rc != rcPerlWarn && rc != rcEvalErr) || r -> errdat1[0] == '\0')) 0 0 0
189 {
190 0 char * p = NULL ;
191 0 char buf[20] = "" ;
192 char * f ;
193 0 tComponent * c = &r -> Component ;
194 0 ▶ if (!(f = c -> sSourcefile))
Branch: 1 branch
BranchTrueFalseTotal
if (!(f = c -> sSourcefile)) 0 0 0
195 {
196 0 c = r -> Component.pPrev ;
197 0 ▶ if (c && !(f = c -> sSourcefile))
Branch: 2 branches
BranchTrueFalseTotal
if (c && !(f = c -> sSourcefile)) 0 0 0
if (c && !(f = c -> sSourcefile)) 0 0 0
198 0 f = "", p = "" ;
199 }
200 0 ▶ if (f)
Branch: 1 branch
BranchTrueFalseTotal
if (f) 0 0 0
201 {
202 0 ▶ if (!p)
Branch: 1 branch
BranchTrueFalseTotal
if (!p) 0 0 0
203 0 p = strrchr (f, '/') ;
204 0 ▶ if (p)
Branch: 1 branch
BranchTrueFalseTotal
if (p) 0 0 0
205 0 p++ ;
206 else
207 {
208 0 p = strrchr (f, '\\') ;
209 0 ▶ if (!p)
Branch: 1 branch
BranchTrueFalseTotal
if (!p) 0 0 0
210 0 p = f ;
211 else
212 0 p++ ;
213 }
214 }
215 else
216 0 ▶ if (!p)
Branch: 1 branch
BranchTrueFalseTotal
if (!p) 0 0 0
217 0 p = "" ;
218 0 ▶ if (c && c -> nSourceline)
Branch: 2 branches
BranchTrueFalseTotal
if (c && c -> nSourceline) 0 0 0
if (c && c -> nSourceline) 0 0 0
219 0 sprintf (buf, "(%d)", c -> nSourceline) ;
220 0 pSVLine = newSVpvf ("%s%s:", p, buf) ;
221 newSVpvf2(pSVLine) ;
222 }
223  
224
225
226 0 ▶ pSV = newSVpvf (msg, nPid , rc, pSVLine?SvPV(pSVLine, l):"", errdat1, errdat2) ;
Branch: 1 branch
BranchTrueFalseTotal
pSV = newSVpvf (msg, nPid , rc, pSVLine?SvPV(pSVLine, l):"", errdat1, errdat2) ; 0 0 0
227 newSVpvf2(pSV) ;
228  
229 0 ▶ if (r && r -> Component.Config.bOptions & optShowBacktrace)
Branch: 2 branches
BranchTrueFalseTotal
if (r && r -> Component.Config.bOptions & optShowBacktrace) 0 0 0
if (r && r -> Component.Config.bOptions & optShowBacktrace) 0 0 0
230 {
231 0 tComponent * c = &r -> Component ;
232 0 ▶ while (c)
Branch: 1 branch
BranchTrueFalseTotal
while (c) 0 0 0
233 {
234 0 ▶ sv_catpvf(pSV, "\n * %s", (!c -> sSourcefile)?"<no filename available>":c -> sSourcefile) ;
Branch: 1 branch
BranchTrueFalseTotal
sv_catpvf(pSV, "\n * %s", (!c -> sSourcefile)?"<no filename available>":c -> sSourcefile) ; 0 0 0
235 0 c = c -> pPrev ;
236 }
237 }
238  
239  
240 0 ▶ if (pSVLine)
Branch: 1 branch
BranchTrueFalseTotal
if (pSVLine) 0 0 0
241 0 SvREFCNT_dec(pSVLine) ;
242  
243 0 sText = SvPV (pSV, l) ;
244
245 0 ▶ if (a)
Branch: 1 branch
BranchTrueFalseTotal
if (a) 0 0 0
246 0 lprintf (a, "%s\n", sText) ;
247  
248 #ifdef APACHE
249 if (r && r -> pApacheReq)
250 {
251 #ifdef APLOG_ERR
252 if (rc != rcPerlWarn)
253 ap_log_error (APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, APLOG_STATUSCODE r -> pApacheReq -> server, "%s", sText) ;
254 else
255 ap_log_error (APLOG_MARK, APLOG_WARNING | APLOG_NOERRNO, APLOG_STATUSCODE r -> pApacheReq -> server, "%s", sText) ;
256 #else
257 log_error (sText, r -> pApacheReq -> server) ;
258 #endif
259 }
260 else
261 #endif
262 {
263 #ifdef WIN32
264 PerlIO_printf (PerlIO_stderr(), "%s\n", sText) ;
265 PerlIO_flush (PerlIO_stderr()) ;
266 #else
267 #undef fprintf
268 #undef fflush
269 0 fprintf (stderr, "%s\n", sText) ;
270 0 fflush (stderr) ;
271 #endif
272 }
273
274 0 ▶ if (r)
Branch: 1 branch
BranchTrueFalseTotal
if (r) 0 0 0
275 {
276 0 ▶ if (rc == rcPerlWarn)
Branch: 1 branch
BranchTrueFalseTotal
if (rc == rcPerlWarn) 0 0 0
277 0 strncpy (r -> lastwarn, r -> errdat1, sizeof (r -> lastwarn) - 1) ;
278  
279 0 ▶ if (r -> pErrArray)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> pErrArray) 0 0 0
280 {
281 0 ▶ av_push (r -> pErrArray, r -> pErrSV?SvREFCNT_inc(r -> pErrSV):pSV) ;
Branch: 1 branch
BranchTrueFalseTotal
av_push (r -> pErrArray, r -> pErrSV?SvREFCNT_inc(r -> pErrSV):pSV) ; 0 0 0
282 }
283 else
284 0 SvREFCNT_dec (pSV) ;
285  
286 0 r -> errdat1[0] = '\0' ;
287 0 r -> errdat2[0] = '\0' ;
288 }
289 else
290 0 SvREFCNT_dec (pSV) ;
291  
292 0 return sText ;
293 }
294  
295 /*---------------------------------------------------------------------------
296 * LogErrorParam
297 */
298 /*!
299 *
300 * \_en
301 * Logs the occurence of an error to the embperl logfile and the httpd error log
302 *
303 * @param a the application object
304 * @param rc the error code
305 * @param errdat1 addtional information
306 * @param errdat2 addtional information
307 * \endif
308 *
309 * \_de
310 * logged das auftreten eines Fehler in das Embperl Logfile und den httpd
311 * error log
312 *
313 * @param a das Applikationobjekt
314 * @param rc Fehlercode
315 * @param errdat1 Zusätzliche Informationen
316 * @param errdat2 Zusätzliche Informationen
317 * \endif
318 *
319 * ------------------------------------------------------------------------ */
320  
321  
322 0 char * LogErrorParam (/*i/o*/ struct tApp * a,
323 /*in*/ int rc,
324 /*in*/ const char * errdat1,
325 /*in*/ const char * errdat2)
326 {
327 0 return DoLogError (NULL, a, rc, errdat1, errdat2) ;
328 }
329  
330  
331 /*---------------------------------------------------------------------------
332 * LogError
333 */
334 /*!
335 *
336 * \_en
337 * Logs the occurence of an error to the embperl logfile and the httpd error log
338 * Addtional information, like stack backtrace, is taken from the request object
339 *
340 * @param r the request object
341 * @param rc the error code
342 * \endif
343 *
344 * \_de
345 * Logged das auftreten eines Fehler in das Embperl Logfile und den httpd
346 * error log. Zusätzlich Informationen, wie z.B. ein Stackbacktrace, werden
347 * dem Requestobjket entnommen
348 *
349 * @param a das Requestobjekt
350 * @param rc Fehlercode
351 * \endif
352 *
353 * ------------------------------------------------------------------------ */
354  
355 0 char * LogError (/*i/o*/ register req * r,
356 /*in*/ int rc)
357
358
359 {
360 0 return DoLogError (r, NULL, rc, NULL, NULL) ;
361 }
362  
363  
364 #if defined (_MDEBUG) && defined (WIN32)
365  
366 static int EmbperlCRTDebugOutput( int reportType, char *userMessage, int *retVal )
367 {
368 lprintf (CurrReq, "[%d]CRTDBG: %s\n", pCurrReq -> nPid, userMessage) ;
369  
370 return TRUE ;
371 }
372  
373 #endif
374  
375 /* */
376 /* Magic */
377 /* */
378  
379 0 void NewEscMode (/*i/o*/ register req * r,
380 SV * pSV)
381  
382 {
383 0 ▶ if (r -> Component.Config.nEscMode & escXML && !r -> Component.bEscInUrl)
Branch: 2 branches
BranchTrueFalseTotal
if (r -> Component.Config.nEscMode & escXML && !r -> Component.bEscInUrl) 0 0 0
if (r -> Component.Config.nEscMode & escXML && !r -> Component.bEscInUrl) 0 0 0
384 0 r -> Component.pNextEscape = Char2XML ;
385 0 ▶ else if (r -> Component.Config.nEscMode & escHtml && !r -> Component.bEscInUrl)
Branch: 2 branches
BranchTrueFalseTotal
else if (r -> Component.Config.nEscMode & escHtml && !r -> Component.bEscInUrl) 0 0 0
else if (r -> Component.Config.nEscMode & escHtml && !r -> Component.bEscInUrl) 0 0 0
386 0 {
387 struct tCharTrans * pChar2Html ;
388  
389 0 ▶ if (r -> Config.nOutputEscCharset == ocharsetLatin1)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Config.nOutputEscCharset == ocharsetLatin1) 0 0 0
390 0 pChar2Html = Char2Html ;
391 0 ▶ else if (r -> Config.nOutputEscCharset == ocharsetLatin2)
Branch: 1 branch
BranchTrueFalseTotal
else if (r -> Config.nOutputEscCharset == ocharsetLatin2) 0 0 0
392 0 pChar2Html = Char2HtmlLatin2 ;
393 else
394 0 pChar2Html = Char2HtmlMin ;
395
396 0 r -> Component.pNextEscape = pChar2Html ;
397 }
398 0 ▶ else if (r -> Component.Config.nEscMode & escUrl)
Branch: 1 branch
BranchTrueFalseTotal
else if (r -> Component.Config.nEscMode & escUrl) 0 0 0
399 0 r -> Component.pNextEscape = Char2Url ;
400 else
401 0 r -> Component.pNextEscape = NULL ;
402  
403 0 ▶ if (r -> Component.bEscModeSet < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.bEscModeSet < 1) 0 0 0
404 {
405 0 r -> Component.pCurrEscape = r -> Component.pNextEscape ;
406 0 r -> Component.nCurrEscMode = r -> Component.Config.nEscMode ;
407 }
408  
409 0 ▶ if (r -> Component.bEscModeSet < 0 && pSV && SvOK (pSV))
Branch: 3 branches
BranchTrueFalseTotal
if (r -> Component.bEscModeSet < 0 && pSV && SvOK (pSV)) 0 0 0
if (r -> Component.bEscModeSet < 0 && pSV && SvOK (pSV)) 0 0 0
if (r -> Component.bEscModeSet < 0 && pSV && SvOK (pSV)) 0 0 0
410 0 r -> Component.bEscModeSet = 1 ;
411 0 }
412  
413  
414 #ifdef UNUSED
415  
416  
417 /* ---------------------------------------------------------------------------- */
418 /* */
419 /* Localise op_mask then opmask_add() */
420 /* */
421 /* Just copied from Opcode.xs */
422 /* */
423 /* ---------------------------------------------------------------------------- */
424  
425  
426 static void
427 opmask_addlocal(pTHX_
428 SV * opset,
429 char * op_mask_buf)
430 {
431 char *orig_op_mask = op_mask;
432 int i,j;
433 char *bitmask;
434 STRLEN len;
435 int myopcode = 0;
436 int opset_len = (maxo + 7) / 8 ;
437  
438 SAVEPPTR(op_mask);
439 op_mask = &op_mask_buf[0];
440 if (orig_op_mask)
441 Copy(orig_op_mask, op_mask, maxo, char);
442 else
443 Zero(op_mask, maxo, char);
444  
445  
446 /* OPCODES ALREADY MASKED ARE NEVER UNMASKED. See opmask_addlocal() */
447  
448 bitmask = SvPV(opset, len);
449 for (i=0; i < opset_len; i++)
450 {
451 U16 bits = bitmask[i];
452 if (!bits)
453 { /* optimise for sparse masks */
454 myopcode += 8;
455 continue;
456 }
457 for (j=0; j < 8 && myopcode < maxo; )
458 op_mask[myopcode++] |= bits & (1 << j++);
459 }
460 }
461  
462 #endif
463  
464  
465 /* ---------------------------------------------------------------------------- */
466 /* */
467 /* Create Session cookie */
468 /* */
469 /* ---------------------------------------------------------------------------- */
470  
471  
472 0 static char * CreateSessionCookie (/*i/o*/ register req * r,
473 /*in*/ SV * pSessionObj,
474 /*in*/ char type,
475 /*in*/ int bReturnCookie)
476
477 {
478 0 SV * pSVID = NULL ;
479 0 SV * pSVUID = NULL ;
480 0 char * pUID = NULL ;
481 0 char * pInitialUID = NULL ;
482 0 STRLEN ulen = 0 ;
483 0 STRLEN ilen = 0 ;
484 0 IV bModified = 0 ;
485 0 char * pCookie = NULL ;
486 STRLEN ldummy ;
487 0 tAppConfig * pCfg = &r -> pApp -> Config ;
488 epTHX ;
489  
490 0 ▶ if (r -> nSessionMgnt)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> nSessionMgnt) 0 0 0
491 {
492 0 dSP; /* initialize stack pointer */
493 int n ;
494  
495 0 ▶ PUSHMARK(sp); /* remember the stack pointer */
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(sp); /* remember the stack pointer */ 0 0 0
496 0 ▶ XPUSHs(pSessionObj) ; /* push pointer to obeject */
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(pSessionObj) ; /* push pointer to obeject */ 0 0 0
497 0 ▶ XPUSHs(sv_2mortal(newSViv(bReturnCookie?0:1))) ; /* init session if not for cookie */
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(bReturnCookie?0:1))) ; /* init session if not for cookie */ 0 0 0
498 0 PUTBACK;
499 0 n = perl_call_method ("getids", G_ARRAY) ; /* call the function */
500 0 SPAGAIN;
501 0 ▶ if (n > 2)
Branch: 1 branch
BranchTrueFalseTotal
if (n > 2) 0 0 0
502 {
503 0 int savewarn = dowarn ;
504 0 dowarn = 0 ; /* no warnings here */
505 0 bModified = POPi ;
506 0 pSVUID = POPs;
507 0 pUID = SvPV (pSVUID, ulen) ;
508 0 ▶ pSVID = POPs;
Branch: 1 branch
BranchTrueFalseTotal
pSVID = POPs; 0 0 0
509 0 pInitialUID = SvPV (pSVID, ilen) ;
510 0 dowarn = savewarn ;
511 }
512 0 PUTBACK;
513
514 0 ▶ if (r -> Config.bDebug & dbgSession)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Config.bDebug & dbgSession) 0 0 0
515 0 ▶ lprintf (r -> pApp, "[%d]SES: Received Cookie ID: %s New Cookie ID: %s %s data is%s modified\n", r -> pThread -> nPid, pInitialUID, pUID, type == 's'?"State":"User", bModified?"":" NOT") ;
Branch: 2 branches
BranchTrueFalseTotal
lprintf (r -> pApp, "[%d]SES: Received Cookie ID: %s New Cookie ID: %s %s data is%s modified\n", r -> pThread -> nPid, pInitialUID, pUID, type == 's'?"State":"User", bModified?"":" NOT") ; 0 0 0
lprintf (r -> pApp, "[%d]SES: Received Cookie ID: %s New Cookie ID: %s %s data is%s modified\n", r -> pThread -> nPid, pInitialUID, pUID, type == 's'?"State":"User", bModified?"":" NOT") ; 0 0 0
516  
517 0 ▶ if (ilen > 0 && (ulen == 0 || (!bModified && strcmp ("!DELETE", pInitialUID) == 0)))
Branch: 4 branches
BranchTrueFalseTotal
if (ilen > 0 && (ulen == 0 || (!bModified && strcmp ("!DELETE", pInitialUID) == 0))) 0 0 0
if (ilen > 0 && (ulen == 0 || (!bModified && strcmp ("!DELETE", pInitialUID) == 0))) 0 0 0
if (ilen > 0 && (ulen == 0 || (!bModified && strcmp ("!DELETE", pInitialUID) == 0))) 0 0 0
if (ilen > 0 && (ulen == 0 || (!bModified && strcmp ("!DELETE", pInitialUID) == 0))) 0 0 0
518 { /* delete cookie */
519 0 ▶ if (bReturnCookie)
Branch: 1 branch
BranchTrueFalseTotal
if (bReturnCookie) 0 0 0
520 {
521 0 ▶ pCookie = ep_pstrcat (r -> pPool, pCfg -> sCookieName, type == 's'?"s=":"=", "; expires=Thu, 1-Jan-1970 00:00:01 GMT", NULL) ;
Branch: 1 branch
BranchTrueFalseTotal
pCookie = ep_pstrcat (r -> pPool, pCfg -> sCookieName, type == 's'?"s=":"=", "; expires=Thu, 1-Jan-1970 00:00:01 GMT", NULL) ; 0 0 0
522 0 ▶ if (pCfg -> sCookieDomain)
Branch: 1 branch
BranchTrueFalseTotal
if (pCfg -> sCookieDomain) 0 0 0
523 0 pCookie = ep_pstrcat (r -> pPool, pCookie, "; domain=", pCfg -> sCookieDomain, NULL) ;
524 0 ▶ if (pCfg -> sCookiePath)
Branch: 1 branch
BranchTrueFalseTotal
if (pCfg -> sCookiePath) 0 0 0
525 0 pCookie = ep_pstrcat (r -> pPool, pCookie, "; path=", pCfg -> sCookiePath, NULL) ;
526 0 ▶ if (pCfg -> bCookieSecure)
Branch: 1 branch
BranchTrueFalseTotal
if (pCfg -> bCookieSecure) 0 0 0
527 0 pCookie = ep_pstrcat (r -> pPool, pCookie, "; secure", NULL) ;
528 }
529  
530 0 ▶ if (r -> Config.bDebug & dbgSession)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Config.bDebug & dbgSession) 0 0 0
531 0 lprintf (r -> pApp, "[%d]SES: Delete Cookie -> %s\n", r -> pThread -> nPid, pCookie) ;
532 }
533 0 ▶ else if (ulen > 0 &&
Branch: 2 branches
BranchTrueFalseTotal
else if (ulen > 0 && 0 0 0
else if (ulen > 0 && 0 0 0
534 0 ▶ ((bModified && (ilen == 0 || strcmp (pInitialUID, pUID) !=0)) ||
Branch: 2 branches
BranchTrueFalseTotal
((bModified && (ilen == 0 || strcmp (pInitialUID, pUID) !=0)) || 0 0 0
((bModified && (ilen == 0 || strcmp (pInitialUID, pUID) !=0)) || 0 0 0
535 0 ▶ (r -> nSessionMgnt & 4) || !bReturnCookie))
Branch: 2 branches
BranchTrueFalseTotal
(r -> nSessionMgnt & 4) || !bReturnCookie)) 0 0 0
(r -> nSessionMgnt & 4) || !bReturnCookie)) 0 0 0
536 {
537 0 ▶ if (bReturnCookie)
Branch: 1 branch
BranchTrueFalseTotal
if (bReturnCookie) 0 0 0
538 {
539 0 ▶ pCookie = ep_pstrcat (r -> pPool, pCfg -> sCookieName, type == 's'?"s=":"=", pUID, NULL) ;
Branch: 1 branch
BranchTrueFalseTotal
pCookie = ep_pstrcat (r -> pPool, pCfg -> sCookieName, type == 's'?"s=":"=", pUID, NULL) ; 0 0 0
540 0 ▶ if (pCfg -> sCookieDomain)
Branch: 1 branch
BranchTrueFalseTotal
if (pCfg -> sCookieDomain) 0 0 0
541 0 pCookie = ep_pstrcat (r -> pPool, pCookie, "; domain=", pCfg -> sCookieDomain, NULL) ;
542 0 ▶ if (pCfg -> sCookiePath)
Branch: 1 branch
BranchTrueFalseTotal
if (pCfg -> sCookiePath) 0 0 0
543 0 pCookie = ep_pstrcat (r -> pPool, pCookie, "; path=", pCfg -> sCookiePath, NULL) ;
544 0 ▶ if (r -> sCookieExpires)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> sCookieExpires) 0 0 0
545 0 pCookie = ep_pstrcat (r -> pPool, pCookie, "; expires=", r -> sCookieExpires, NULL) ;
546 0 ▶ if (pCfg -> bCookieSecure)
Branch: 1 branch
BranchTrueFalseTotal
if (pCfg -> bCookieSecure) 0 0 0
547 0 pCookie = ep_pstrcat (r -> pPool, pCookie, "; secure", NULL) ;
548  
549 0 ▶ if (r -> Config.bDebug & dbgSession)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Config.bDebug & dbgSession) 0 0 0
550 0 lprintf (r -> pApp, "[%d]SES: Send Cookie -> %s\n", r -> pThread -> nPid, pCookie) ;
551 }
552 else
553 {
554 0 pCookie = ep_pstrdup (r -> pPool, SvPV(pSVUID, ldummy)) ;
555 0 ▶ if (r -> Config.bDebug & dbgSession)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Config.bDebug & dbgSession) 0 0 0
556 0 lprintf (r -> pApp, "[%d]SES: Add ID to URL type=%c id=%s\n", r -> pThread -> nPid, type, pCookie) ;
557 }
558 }
559 }
560 0 return pCookie ;
561 }
562
563  
564 #ifdef UNUSED
565
566 /* ---------------------------------------------------------------------------- */
567 /* */
568 /* Setup Safe Namespace */
569 /* */
570 /* ---------------------------------------------------------------------------- */
571  
572  
573 static void SetupSafeNamespace (/*i/o*/ register req * r)
574  
575 {
576 GV * gv;
577  
578 dTHR ;
579 epTHX ;
580  
581 /* The following is borrowed from Opcode.xs */
582  
583 if (r -> Component.Config.bOptions & optOpcodeMask)
584 opmask_addlocal(aTHX_ r -> Component.Config.pOpcodeMask, r -> Component.op_mask_buf);
585  
586
587 if (r -> Component.Config.bOptions & optSafeNamespace)
588 {
589 save_aptr(&endav);
590 endav = (AV*)sv_2mortal((SV*)newAV()); /* ignore END blocks for now */
591  
592 save_hptr(&defstash); /* save current default stack */
593 /* the assignment to global defstash changes our sense of 'main' */
594 defstash = gv_stashpv(r -> Component.sCurrPackage, GV_ADDWARN); /* should exist already */
595  
596 if (r -> Component.Config.bDebug)
597 lprintf (r -> pApp, "[%d]REQ: switch to safe namespace %s\n", r -> pThread -> nPid, r -> Component.sCurrPackage) ;
598  
599  
600 /* defstash must itself contain a main:: so we'll add that now */
601 /* take care with the ref counts (was cause of long standing bug) */
602 /* XXX I'm still not sure if this is right, GV_ADDWARN should warn! */
603 gv = gv_fetchpv("main::", GV_ADDWARN, SVt_PVHV);
604 sv_free((SV*)GvHV(gv));
605 GvHV(gv) = (HV*)SvREFCNT_inc(defstash);
606 }
607 }
608  
609 #endif
610  
611 /* ---------------------------------------------------------------------------- */
612 /* */
613 /* Reset Request */
614 /* */
615 /* ---------------------------------------------------------------------------- */
616  
617  
618 0 static int ResetRequest (/*i/o*/ register req * r,
619 /*in*/ char * sInputfile)
620  
621 {
622 epTHX ;
623  
624 0 ▶ if (r -> Component.Config.bDebug)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug) 0 0 0
625 {
626 0 clock_t cl = clock () ;
627 time_t t ;
628 struct tm * tm ;
629
630 0 time (&t) ;
631 0 tm =localtime (&t) ;
632
633 0 ▶ lprintf (r -> pApp, "[%d]PERF: input = %s\n", r -> pThread -> nPid, sInputfile?sInputfile:"???") ;
Branch: 1 branch
BranchTrueFalseTotal
lprintf (r -> pApp, "[%d]PERF: input = %s\n", r -> pThread -> nPid, sInputfile?sInputfile:"???") ; 0 0 0
634 #ifdef CLOCKS_PER_SEC
635 0 lprintf (r -> pApp, "[%d]PERF: Time: %d ms ", r -> pThread -> nPid, ((cl - r -> startclock) * 1000 / CLOCKS_PER_SEC)) ;
636 #else
637 lprintf (r -> pApp, "[%d]PERF: ", r -> pThread -> nPid) ;
638 #endif
639 0 lprintf (r -> pApp, "\n") ;
640 0 lprintf (r -> pApp, "[%d]%sRequest finished. %s. Entry-SVs: %d Exit-SVs: %d \n", r -> pThread -> nPid,
641 0 ▶ (r -> Component.pPrev?"Sub-":""), asctime(tm), r -> stsv_count, sv_count) ;
Branch: 1 branch
BranchTrueFalseTotal
(r -> Component.pPrev?"Sub-":""), asctime(tm), r -> stsv_count, sv_count) ; 0 0 0
642 #ifdef DMALLOC
643 dmalloc_message ( "[%d]%sRequest finished. Entry-SVs: %d Exit-SVs: %d \n", r -> pThread -> nPid,
644 (r -> Component.pPrev?"Sub-":""), r -> stsv_count, sv_count) ;
645 #endif
646 }
647  
648
649 0 r -> Component.pCurrPos = NULL ;
650  
651  
652 0 FlushLog (r -> pApp) ;
653  
654 0 r -> Component.nSourceline = 1 ;
655 0 r -> Component.pSourcelinePos = NULL ;
656 0 r -> Component.pLineNoCurrPos = NULL ;
657  
658 0 r -> Component.bReqRunning = 0 ;
659  
660 /*
661 av_clear (r -> pErrFill) ;
662 av_clear (r -> pErrState) ;
663 */
664  
665 0 return ok ;
666 }
667  
668
669 /* ---------------------------------------------------------------------------- */
670 /* */
671 /* Start the output stream */
672 /* */
673 /* ---------------------------------------------------------------------------- */
674  
675
676 0 static int StartOutput (/*i/o*/ register req * r)
677  
678 {
679 0 ▶ int bOutToMem = r -> Component.Param.pOutput && SvROK (r -> Component.Param.pOutput) ;
Branch: 2 branches
BranchTrueFalseTotal
int bOutToMem = r -> Component.Param.pOutput && SvROK (r -> Component.Param.pOutput) ; 0 0 0
int bOutToMem = r -> Component.Param.pOutput && SvROK (r -> Component.Param.pOutput) ; 0 0 0
680 epTHX_
681  
682 #ifdef APACHE
683 if (r -> pApacheReq && r -> pApacheReq -> main)
684 r -> Config.bOptions |= optEarlyHttpHeader ; /* do not direct output to memory on internal redirect */
685 #endif
686 0 ▶ if (bOutToMem)
Branch: 1 branch
BranchTrueFalseTotal
if (bOutToMem) 0 0 0
687 0 r -> Config.bOptions &= ~optEarlyHttpHeader ;
688  
689 0 ▶ if (r -> Component.pPrev || r -> Component.pImportStash)
Branch: 2 branches
BranchTrueFalseTotal
if (r -> Component.pPrev || r -> Component.pImportStash) 0 0 0
if (r -> Component.pPrev || r -> Component.pImportStash) 0 0 0
690 0 r -> Config.bOptions &= ~optSendHttpHeader ;
691  
692  
693 0 ▶ if (r -> Config.bOptions & optEarlyHttpHeader)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Config.bOptions & optEarlyHttpHeader) 0 0 0
694 {
695 #ifdef APACHE
696 if (r -> pApacheReq == NULL)
697 {
698 #endif
699 0 ▶ if (r -> Config.bOptions & optSendHttpHeader)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Config.bOptions & optSendHttpHeader) 0 0 0
700 0 oputs (r, "Content-type: text/html\n\n") ;
701  
702 #ifdef APACHE
703 }
704 else
705 {
706 #ifndef APACHE2
707 if (r -> pApacheReq -> main == NULL && (r -> Config.bOptions & optSendHttpHeader))
708 send_http_header (r -> pApacheReq) ;
709 #endif
710 #ifndef WIN32
711 /* shouldn't be necessary for newer mod_perl versions !? */
712 /* mod_perl_sent_header(r -> pApacheReq, 1) ; */
713 #endif
714 if (r -> pApacheReq -> header_only)
715 return ok ;
716 }
717 #endif
718 }
719 else
720 {
721 /*
722 if (r -> nIOType == epIOCGI && (r -> Config.bOptions & optSendHttpHeader))
723 oputs (r, "Content-type: text/html\n\n") ;
724 */
725
726 0 oBegin (r) ;
727 }
728  
729  
730 0 ▶ if ((r -> Config.nSessionMode & smodeSDatParam) && !r -> Component.pPrev)
Branch: 2 branches
BranchTrueFalseTotal
if ((r -> Config.nSessionMode & smodeSDatParam) && !r -> Component.pPrev) 0 0 0
if ((r -> Config.nSessionMode & smodeSDatParam) && !r -> Component.pPrev) 0 0 0
731 {
732 0 char * pCookie = CreateSessionCookie (r, r -> pApp -> pStateObj, 's', 0) ;
733 /* lprintf (r -> pApp, "opt %x optadd %x options %x cookie %s\n", optAddStateSessionToLinks, r -> Component.Config.bOptions & optAddStateSessionToLinks, r -> Component.Config.bOptions, SvPV(pCookie, l)) ; */
734 0 ▶ if (pCookie)
Branch: 1 branch
BranchTrueFalseTotal
if (pCookie) 0 0 0
735 0 r -> sSessionID = ep_pstrcat (r -> pPool, r -> pApp -> Config.sCookieName, "=", pCookie, NULL) ;
736 }
737
738 0 ▶ if ((r -> Config.nSessionMode & smodeUDatParam) && !r -> Component.pPrev)
Branch: 2 branches
BranchTrueFalseTotal
if ((r -> Config.nSessionMode & smodeUDatParam) && !r -> Component.pPrev) 0 0 0
if ((r -> Config.nSessionMode & smodeUDatParam) && !r -> Component.pPrev) 0 0 0
739 {
740 0 char * pCookie = CreateSessionCookie (r, r -> pApp -> pUserObj, 'u', 0) ;
741 0 ▶ if (pCookie)
Branch: 1 branch
BranchTrueFalseTotal
if (pCookie) 0 0 0
742 {
743 0 ▶ if (r -> sSessionID)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> sSessionID) 0 0 0
744 0 r -> sSessionID = ep_pstrcat (r -> pPool, r -> sSessionID, ":", pCookie, NULL) ;
745 else
746 0 r -> sSessionID = ep_pstrcat (r -> pPool, r -> pApp -> Config.sCookieName, "=:", pCookie, NULL) ;
747 }
748 }
749  
750
751
752 0 return ok ;
753 }
754  
755  
756 /* ---------------------------------------------------------------------------- */
757 /* */
758 /* GenerateErrorPage */
759 /* */
760 /* ---------------------------------------------------------------------------- */
761  
762  
763  
764 0 static int GenerateErrorPage (/*i/o*/ register req * r,
765 /*in*/ int rc)
766
767  
768 {
769 epTHX_
770  
771 0 dSP; /* initialize stack pointer */
772
773 0 ▶ if (r -> pApp -> Config.sMailErrorsTo)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> pApp -> Config.sMailErrorsTo) 0 0 0
774 {
775 /* --- check if error should be mailed --- */
776 0 tApp * a = r -> pApp ;
777 0 time_t nTime = time(NULL) ;
778  
779 0 ▶ if (a -> nErrorsLastTime < nTime - a -> Config.nMailErrorsResetTime)
Branch: 1 branch
BranchTrueFalseTotal
if (a -> nErrorsLastTime < nTime - a -> Config.nMailErrorsResetTime) 0 0 0
780 0 a -> nErrorsCount = 0 ;
781 0 ▶ else if (a -> nErrorsLastSendTime < nTime - a -> Config.nMailErrorsResendTime)
Branch: 1 branch
BranchTrueFalseTotal
else if (a -> nErrorsLastSendTime < nTime - a -> Config.nMailErrorsResendTime) 0 0 0
782 0 a -> nErrorsCount = 0 ;
783 0 a -> nErrorsLastTime = nTime ;
784 0 ▶ if (a -> Config.nMailErrorsLimit == 0 || a -> nErrorsCount < a -> Config.nMailErrorsLimit)
Branch: 2 branches
BranchTrueFalseTotal
if (a -> Config.nMailErrorsLimit == 0 || a -> nErrorsCount < a -> Config.nMailErrorsLimit) 0 0 0
if (a -> Config.nMailErrorsLimit == 0 || a -> nErrorsCount < a -> Config.nMailErrorsLimit) 0 0 0
785 {
786 0 a -> nErrorsCount++ ;
787 0 a -> nErrorsLastSendTime = nTime ;
788  
789 0 ▶ PUSHMARK(sp);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(sp); 0 0 0
790 0 ▶ XPUSHs(r -> pApp -> _perlsv) ;
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(r -> pApp -> _perlsv) ; 0 0 0
791 0 ▶ XPUSHs(r -> _perlsv) ;
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(r -> _perlsv) ; 0 0 0
792 0 PUTBACK;
793 0 perl_call_method ("mail_errors", G_DISCARD) ;
794 0 SPAGAIN ;
795 }
796 }
797
798 0 ▶ if (r -> Component.Config.bOptions & optReturnError)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bOptions & optReturnError) 0 0 0
799 {
800 0 oRollbackOutput (r, NULL) ;
801 0 ▶ if (r -> Component.Param.pOutput && SvROK (r -> Component.Param.pOutput))
Branch: 2 branches
BranchTrueFalseTotal
if (r -> Component.Param.pOutput && SvROK (r -> Component.Param.pOutput)) 0 0 0
if (r -> Component.Param.pOutput && SvROK (r -> Component.Param.pOutput)) 0 0 0
802 {
803 0 sv_setsv (SvRV (r -> Component.Param.pOutput), &sv_undef) ;
804 }
805 0 r -> bExit = 1 ;
806 0 return ok ; /* No further output or header, this should be handle by the server */
807 }
808 0 ▶ else if (r -> Component.pOutput && !(r -> Component.Config.bOptions & optDisableEmbperlErrorPage))
Branch: 2 branches
BranchTrueFalseTotal
else if (r -> Component.pOutput && !(r -> Component.Config.bOptions & optDisableEmbperlErrorPage)) 0 0 0
else if (r -> Component.pOutput && !(r -> Component.Config.bOptions & optDisableEmbperlErrorPage)) 0 0 0
809 {
810 0 oRollbackOutput (r, NULL) ; /* forget everything outputed so far */
811 0 oBegin (r) ;
812  
813 0 SPAGAIN ;
814 0 ▶ PUSHMARK(sp);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(sp); 0 0 0
815 0 ▶ XPUSHs(r -> pApp -> _perlsv) ;
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(r -> pApp -> _perlsv) ; 0 0 0
816 0 ▶ XPUSHs(r -> _perlsv) ;
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(r -> _perlsv) ; 0 0 0
817 0 PUTBACK;
818 0 perl_call_method ("send_error_page", G_DISCARD) ;
819 0 SPAGAIN ;
820 #ifdef APACHE
821 if (r -> pApacheReq)
822 {
823 if (rc >= 400)
824 r -> pApacheReq -> status = rc ;
825 else
826 r -> pApacheReq -> status = 500 ;
827 }
828 #endif
829
830 0 SetHashValueInt (r, r -> pThread -> pHeaderHash, "Content-Length", GetContentLength (r) ) ;
831 }
832 0 r -> bError = 1 ;
833  
834 0 return ok ;
835 }
836  
837 /* ---------------------------------------------------------------------------- */
838 /* */
839 /* SendHttpHeader */
840 /* */
841 /* ---------------------------------------------------------------------------- */
842  
843  
844  
845 0 int embperl_SendHttpHeader (/*i/o*/ register req * r)
846  
847 {
848 epTHX_
849 0 char * pCookie = NULL ;
850  
851 0 ▶ if (r -> Config.nSessionMode & smodeUDatCookie)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Config.nSessionMode & smodeUDatCookie) 0 0 0
852 0 pCookie = CreateSessionCookie (r, r -> pApp -> pUserObj, 'u', 1) ;
853
854 #ifdef APACHE
855 if (r -> pApacheReq)
856 {
857 SV * pHeader ;
858 char * p ;
859 HE * pEntry ;
860 char * pKey ;
861 I32 l ;
862 STRLEN ldummy ;
863  
864 I32 i;
865 I32 len;
866 AV *arr;
867 SV **svp;
868  
869 /* loc = 0 => no location header found
870 * loc = 1 => location header found
871 * loc = 2 => location header + value found
872 * loc = 3 => location header + value + status found
873 */
874 I32 loc;
875 I32 loc_status = 301;
876  
877  
878 hv_iterinit (r -> pThread -> pHeaderHash) ;
879 while ((pEntry = hv_iternext (r -> pThread -> pHeaderHash)))
880 {
881 pKey = hv_iterkey (pEntry, &l) ;
882 pHeader = hv_iterval (r -> pThread -> pHeaderHash, pEntry) ;
883 loc = 0;
884 if (pHeader && pKey)
885 {
886  
887 if (stricmp (pKey, "location") == 0)
888 loc = 1;
889 if (stricmp (pKey, "content-type") == 0)
890 {
891 p = NULL;
892 if ( SvROK(pHeader) && SvTYPE(SvRV(pHeader)) == SVt_PVAV )
893 {
894 arr = (AV *)SvRV(pHeader);
895 if (av_len(arr) >= 0)
896 {
897 svp = av_fetch(arr, 0, 0);
898 p = SvPV(*svp, ldummy);
899 }
900 }
901 else
902 {
903 p = SvPV(pHeader, ldummy);
904 }
905 if (p)
906 r->pApacheReq->content_type = apr_pstrdup(r->pApacheReq->pool, p);
907 }
908 else if (SvROK(pHeader) && SvTYPE(SvRV(pHeader)) == SVt_PVAV )
909 {
910 arr = (AV *)SvRV(pHeader);
911 len = av_len(arr);
912 for (i = 0; i <= len; i++)
913 {
914 svp = av_fetch(arr, i, 0);
915 if (loc == 2)
916 {
917 loc = 3;
918 loc_status = SvIV(*svp);
919 break;
920 }
921  
922 p = SvPV(*svp, ldummy);
923 apr_table_add( r->pApacheReq->headers_out, apr_pstrdup(r->pApacheReq->pool, pKey),
924 apr_pstrdup(r->pApacheReq->pool, p ) );
925 if (loc == 1)
926 loc = 2;
927 }
928 }
929 else
930 {
931 p = SvPV(pHeader, ldummy);
932 apr_table_set(r -> pApacheReq->headers_out, apr_pstrdup(r -> pApacheReq->pool, pKey), apr_pstrdup(r -> pApacheReq->pool, p)) ;
933 if (loc == 1) loc = 2;
934 }
935  
936 if (loc >= 2) r->pApacheReq->status = loc_status;
937 }
938 }
939  
940  
941 if (pCookie)
942 apr_table_add(r -> pApacheReq->headers_out, "Set-Cookie", pCookie) ;
943 #if 0
944 if (r -> Component.Config.bEP1Compat) /* Embperl 2 currently cannot calc Content Length */
945 set_content_length (r -> pApacheReq, GetContentLength (r) + (r -> Component.pCurrEscape?2:0)) ;
946 #endif
947 #ifndef APACHE2
948 send_http_header (r -> pApacheReq) ;
949 #endif
950  
951 if (r -> Component.Config.bDebug & dbgHeadersIn)
952 {
953 int i;
954 const apr_array_header_t *hdrs_arr;
955 apr_table_entry_t *hdrs;
956  
957 hdrs_arr = apr_table_elts (r -> pApacheReq->headers_out);
958 hdrs = (apr_table_entry_t *)hdrs_arr->elts;
959  
960 lprintf (r -> pApp, "[%d]HDR: %d\n", r -> pThread -> nPid, hdrs_arr->nelts) ;
961 for (i = 0; i < hdrs_arr->nelts; ++i)
962 if (hdrs[i].key)
963 lprintf (r -> pApp, "[%d]HDR: %s=%s\n", r -> pThread -> nPid, hdrs[i].key, hdrs[i].val) ;
964 }
965 }
966 else
967 #endif
968 {
969 /*char txt[100] ;*/
970 0 int save = r -> Component.pOutput -> nMarker ;
971 SV * pHeader ;
972 char * p ;
973 HE * pEntry ;
974 char * pKey ;
975 I32 l ;
976 0 char * pContentType = "text/html";
977 STRLEN ldummy ;
978 /* loc = 0 => no location header found
979 * loc = 1 => location header found
980 */
981 I32 loc;
982  
983  
984 0 r -> Component.pOutput -> nMarker = 0 ; /* output directly */
985  
986 0 hv_iterinit (r -> pThread -> pHeaderHash) ;
987 0 ▶ while ((pEntry = hv_iternext (r -> pThread -> pHeaderHash)))
Branch: 1 branch
BranchTrueFalseTotal
while ((pEntry = hv_iternext (r -> pThread -> pHeaderHash))) 0 0 0
988 {
989 0 pKey = hv_iterkey (pEntry, &l) ;
990 0 pHeader = hv_iterval (r -> pThread -> pHeaderHash, pEntry) ;
991 0 loc = 0;
992  
993 0 ▶ if (pHeader && pKey)
Branch: 2 branches
BranchTrueFalseTotal
if (pHeader && pKey) 0 0 0
if (pHeader && pKey) 0 0 0
994 {
995 0 ▶ if (stricmp (pKey, "location") == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (stricmp (pKey, "location") == 0) 0 0 0
996 0 loc = 1;
997  
998 0 ▶ if (SvROK(pHeader) && SvTYPE(SvRV(pHeader)) == SVt_PVAV )
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(pHeader) && SvTYPE(SvRV(pHeader)) == SVt_PVAV ) 0 0 0
if (SvROK(pHeader) && SvTYPE(SvRV(pHeader)) == SVt_PVAV ) 0 0 0
999 0 {
1000 0 AV * arr = (AV *)SvRV(pHeader);
1001 0 I32 len = av_len(arr);
1002 int i ;
1003  
1004 0 ▶ for (i = 0; i <= len; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= len; i++) 0 0 0
1005 {
1006 0 SV ** svp = av_fetch(arr, i, 0);
1007 0 p = SvPV(*svp, ldummy);
1008 0 oputs (r, pKey) ;
1009 0 oputs (r, ": ") ;
1010 0 oputs (r, p) ;
1011 0 oputs (r, "\n") ;
1012 0 ▶ if (r -> Component.Config.bDebug & dbgHeadersIn)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgHeadersIn) 0 0 0
1013 0 lprintf (r -> pApp, "[%d]HDR: %s: %s\n", r -> pThread -> nPid, pKey, p) ;
1014 0 ▶ if (loc == 1)
Branch: 1 branch
BranchTrueFalseTotal
if (loc == 1) 0 0 0
1015 0 break;
1016 }
1017 }
1018 else
1019 {
1020 0 p = SvPV (pHeader, na) ;
1021 0 ▶ if (stricmp (pKey, "content-type") == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (stricmp (pKey, "content-type") == 0) 0 0 0
1022 0 pContentType = p ;
1023 else
1024 {
1025 0 oputs (r, pKey) ;
1026 0 oputs (r, ": ") ;
1027 0 oputs (r, p) ;
1028 0 oputs (r, "\n") ;
1029 }
1030 0 ▶ if (r -> Component.Config.bDebug & dbgHeadersIn)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgHeadersIn) 0 0 0
1031 0 lprintf (r -> pApp, "[%d]HDR: %s: %s\n", r -> pThread -> nPid, pKey, p) ;
1032 }
1033 }
1034 }
1035
1036 0 oputs (r, "Content-Type: ") ;
1037 0 oputs (r, pContentType) ;
1038 0 oputs (r, "\n") ;
1039 0 ▶ if (pCookie)
Branch: 1 branch
BranchTrueFalseTotal
if (pCookie) 0 0 0
1040 {
1041 0 oputs (r, "Set-Cookie") ;
1042 0 oputs (r, ": ") ;
1043 0 oputs (r, pCookie) ;
1044 0 oputs (r, "\n") ;
1045 }
1046  
1047 0 oputs (r, "\n") ;
1048  
1049 0 r -> Component.pOutput -> nMarker = save ;
1050 }
1051  
1052 0 return ok ;
1053 }
1054  
1055 /* ---------------------------------------------------------------------------- */
1056 /* */
1057 /* End the output stream to memory */
1058 /* */
1059 /* ---------------------------------------------------------------------------- */
1060  
1061  
1062 0 static int OutputToMem (/*i/o*/ register req * r)
1063  
1064 {
1065 epTHX_
1066 SV * pOut ;
1067 char * pData ;
1068 STRLEN l ;
1069
1070 0 ▶ if (!SvROK (r -> Component.Param.pOutput))
Branch: 1 branch
BranchTrueFalseTotal
if (!SvROK (r -> Component.Param.pOutput)) 0 0 0
1071 {
1072 0 strcpy (r -> errdat1, "OutputToMem") ;
1073 0 strcpy (r -> errdat2, "parameter output") ;
1074
1075 0 return rcNotScalarRef ;
1076 }
1077
1078 0 pOut = SvRV (r -> Component.Param.pOutput) ;
1079 0 ▶ if (!r -> bError && r -> Component.pOutputSV && !r -> Component.pImportStash)
Branch: 3 branches
BranchTrueFalseTotal
if (!r -> bError && r -> Component.pOutputSV && !r -> Component.pImportStash) 0 0 0
if (!r -> bError && r -> Component.pOutputSV && !r -> Component.pImportStash) 0 0 0
if (!r -> bError && r -> Component.pOutputSV && !r -> Component.pImportStash) 0 0 0
1080 {
1081 0 sv_setsv (pOut, r -> Component.pOutputSV) ;
1082 }
1083 else
1084 {
1085 0 ▶ if (!r -> bError && !r -> Component.pImportStash)
Branch: 2 branches
BranchTrueFalseTotal
if (!r -> bError && !r -> Component.pImportStash) 0 0 0
if (!r -> bError && !r -> Component.pImportStash) 0 0 0
1086 {
1087 0 tDomTree * pDomTree = DomTree_self (r -> Component.xCurrDomTree) ;
1088 0 Node_toString (r, pDomTree, pDomTree -> xDocument, 0) ;
1089 }
1090  
1091 0 l = GetContentLength (r) + 1 ;
1092
1093 0 sv_setpv (pOut, "") ;
1094 0 ▶ SvGROW (pOut, l) ;
Branch: 2 branches
BranchTrueFalseTotal
SvGROW (pOut, l) ; 0 0 0
SvGROW (pOut, l) ; 0 0 0
1095 0 pData = SvPVX (pOut) ;
1096 0 oCommitToMem (r, NULL, pData) ;
1097 0 SvCUR_set (pOut, l - 1) ;
1098 }
1099
1100 0 return ok ;
1101 }
1102  
1103  
1104 /* ---------------------------------------------------------------------------- */
1105 /* */
1106 /* End the output stream to file */
1107 /* */
1108 /* ---------------------------------------------------------------------------- */
1109  
1110  
1111 0 static int OutputToFile (/*i/o*/ register req * r)
1112  
1113 {
1114 epTHX_
1115 0 oCommit (r, NULL) ;
1116 0 ▶ if (!r -> bError && !r -> Component.pImportStash)
Branch: 2 branches
BranchTrueFalseTotal
if (!r -> bError && !r -> Component.pImportStash) 0 0 0
if (!r -> bError && !r -> Component.pImportStash) 0 0 0
1117 {
1118 0 ▶ if (r -> Component.pOutputSV)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.pOutputSV) 0 0 0
1119 {
1120 STRLEN l ;
1121 0 char * p = SvPV (r -> Component.pOutputSV, l) ;
1122 0 owrite (r, p, l) ;
1123 }
1124 else
1125 {
1126 0 tDomTree * pDomTree = DomTree_self (r -> Component.xCurrDomTree) ;
1127 0 Node_toString (r, pDomTree, pDomTree -> xDocument, 0) ;
1128 }
1129 }
1130 0 return ok ;
1131 }
1132  
1133 /* ---------------------------------------------------------------------------- */
1134 /* */
1135 /* Append tree to upper tree */
1136 /* */
1137 /* ---------------------------------------------------------------------------- */
1138  
1139  
1140 0 static int AppendToUpperTree (/*i/o*/ register req * r)
1141  
1142 {
1143 epTHX_
1144 0 tDomTree * pDomTree = DomTree_self (r -> Component.xCurrDomTree) ;
1145 0 tComponent * lc = r -> Component.pPrev ;
1146 0 ▶ if (lc -> xCurrNode)
Branch: 1 branch
BranchTrueFalseTotal
if (lc -> xCurrNode) 0 0 0
1147 {
1148 0 ▶ if (r -> Component.pOutputSV)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.pOutputSV) 0 0 0
1149 {
1150 STRLEN len ;
1151 0 char * p = SvPV (r -> Component.pOutputSV, len) ;
1152 0 lc -> xCurrNode = Node_insertAfter_CDATA (r -> pApp, p, len, 0, DomTree_self (lc -> xCurrDomTree), lc -> xCurrNode, lc -> nCurrRepeatLevel) ;
1153 }
1154 0 ▶ else if (pDomTree -> xDocument)
Branch: 1 branch
BranchTrueFalseTotal
else if (pDomTree -> xDocument) 0 0 0
1155 {
1156 0 lc -> xCurrNode = Node_insertAfter (r -> pApp, pDomTree, pDomTree -> xDocument, 0, DomTree_self (lc -> xCurrDomTree), lc -> xCurrNode, lc -> nCurrRepeatLevel) ;
1157 }
1158 }
1159 0 return ok ;
1160 }
1161  
1162 /* ---------------------------------------------------------------------------- */
1163 /* */
1164 /* End the output stream */
1165 /* */
1166 /* ---------------------------------------------------------------------------- */
1167  
1168  
1169 0 static int EndOutput (/*i/o*/ register req * r,
1170 /*in*/ int rc,
1171 /*in*/ SV * pOutData)
1172
1173  
1174 {
1175 epTHX_
1176  
1177
1178 0 r -> Component.bEscModeSet = 0 ;
1179  
1180 0 ▶ if (rc != ok || r -> bError)
Branch: 2 branches
BranchTrueFalseTotal
if (rc != ok || r -> bError) 0 0 0
if (rc != ok || r -> bError) 0 0 0
1181 { /* --- generate error page if necessary --- */
1182 0 GenerateErrorPage (r, rc) ;
1183 0 ▶ if (r -> bExit)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> bExit) 0 0 0
1184 0 return ok ;
1185 }
1186  
1187 0 ▶ if (!(r -> Config.bOptions & optEarlyHttpHeader) &&
Branch: 1 branch
BranchTrueFalseTotal
if (!(r -> Config.bOptions & optEarlyHttpHeader) && 0 0 0
1188 0 ▶ (r -> Config.bOptions & optSendHttpHeader) && !r -> Component.Param.pOutput)
Branch: 2 branches
BranchTrueFalseTotal
(r -> Config.bOptions & optSendHttpHeader) && !r -> Component.Param.pOutput) 0 0 0
(r -> Config.bOptions & optSendHttpHeader) && !r -> Component.Param.pOutput) 0 0 0
1189 0 embperl_SendHttpHeader (r) ;
1190  
1191 0 ▶ if (r -> Component.Param.pOutput)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Param.pOutput) 0 0 0
1192 0 return OutputToMem (r) ;
1193
1194 0 rc = OutputToFile (r) ;
1195 #ifdef APACHE
1196 if (r -> pApacheReq)
1197 ap_finalize_request_protocol (r -> pApacheReq) ;
1198 #endif
1199 0 oflush (r) ;
1200
1201 0 return rc ;
1202 }
1203  
1204 /* ---------------------------------------------------------------------------- */
1205 /* */
1206 /* export symbols into caller package */
1207 /* */
1208 /* ---------------------------------------------------------------------------- */
1209  
1210
1211 0 static int export (/*in*/ tReq * r)
1212
1213 {
1214 epTHX_
1215 0 ▶ SV * sCaller = sv_2mortal(newSVpv (HvNAME (r -> Component.pImportStash), 0)) ;
Branch: 6 branches
BranchTrueFalseTotal
SV * sCaller = sv_2mortal(newSVpv (HvNAME (r -> Component.pImportStash), 0)) ; 0 0 0
SV * sCaller = sv_2mortal(newSVpv (HvNAME (r -> Component.pImportStash), 0)) ; 0 0 0
SV * sCaller = sv_2mortal(newSVpv (HvNAME (r -> Component.pImportStash), 0)) ; 0 0 0
SV * sCaller = sv_2mortal(newSVpv (HvNAME (r -> Component.pImportStash), 0)) ; 0 0 0
SV * sCaller = sv_2mortal(newSVpv (HvNAME (r -> Component.pImportStash), 0)) ; 0 0 0
SV * sCaller = sv_2mortal(newSVpv (HvNAME (r -> Component.pImportStash), 0)) ; 0 0 0
1216 0 dSP ;
1217
1218 0 ▶ PUSHMARK(sp);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(sp); 0 0 0
1219 0 ▶ XPUSHs(r -> _perlsv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(r -> _perlsv); 0 0 0
1220 0 ▶ XPUSHs(sCaller) ;
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sCaller) ; 0 0 0
1221 0 PUTBACK;
1222 0 perl_call_method ("export", G_SCALAR | G_EVAL) ;
1223 0 SPAGAIN ;
1224 0 ▶ if (SvTRUE (ERRSV))
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE (ERRSV)) 0 0 0
if (SvTRUE (ERRSV)) 0 0 0
1225 {
1226 STRLEN l ;
1227 0 ▶ strncpy (r -> errdat1, SvPV (ERRSV, l), sizeof (r -> errdat1) - 1) ;
Branch: 1 branch
BranchTrueFalseTotal
strncpy (r -> errdat1, SvPV (ERRSV, l), sizeof (r -> errdat1) - 1) ; 0 0 0
1228 0 LogError (r, rcEvalErr) ;
1229 0 POPs ;
1230 0 ▶ sv_setpv(ERRSV,"");
Branch: 1 branch
BranchTrueFalseTotal
sv_setpv(ERRSV,""); 0 0 0
1231 }
1232 0 tainted = 0 ;
1233  
1234 0 return ok ;
1235 }
1236  
1237  
1238 /* ---------------------------------------------------------------------------- */
1239 /* */
1240 /* Process the file */
1241 /* */
1242 /* ---------------------------------------------------------------------------- */
1243  
1244
1245  
1246 0 static int ProcessFile (/*i/o*/ register req * r,
1247 /*in*/ int nFileSize)
1248  
1249 {
1250 epTHX_
1251 int rc ;
1252 SV * pParam ;
1253 0 SV * pParamRV = NULL ;
1254 0 SV * pRecipe = r -> Component.Config.pRecipe ;
1255 STRLEN l ;
1256 int num ;
1257  
1258 0 dSP ;
1259 0 tainted = 0 ;
1260  
1261 0 ▶ if (!pRecipe || !SvOK(pRecipe))
Branch: 2 branches
BranchTrueFalseTotal
if (!pRecipe || !SvOK(pRecipe)) 0 0 0
if (!pRecipe || !SvOK(pRecipe)) 0 0 0
1262 0 pRecipe = sv_2mortal(newSVpv("Embperl", 7)) ;
1263  
1264 0 ▶ if (SvPOK(pRecipe))
Branch: 1 branch
BranchTrueFalseTotal
if (SvPOK(pRecipe)) 0 0 0
1265 {
1266 0 ▶ PUSHMARK(sp);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(sp); 0 0 0
1267 0 ▶ XPUSHs(r -> pApp -> _perlsv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(r -> pApp -> _perlsv); 0 0 0
1268 0 ▶ XPUSHs(r -> _perlsv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(r -> _perlsv); 0 0 0
1269 0 ▶ XPUSHs(pRecipe);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(pRecipe); 0 0 0
1270 0 PUTBACK;
1271 0 num = perl_call_method ("get_recipe", G_SCALAR | G_EVAL) ;
1272 0 tainted = 0 ;
1273 0 SPAGAIN;
1274 0 ▶ if (num == 1)
Branch: 1 branch
BranchTrueFalseTotal
if (num == 1) 0 0 0
1275 0 pParamRV = POPs ;
1276 0 PUTBACK;
1277 0 ▶ if (SvTRUE (ERRSV))
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE (ERRSV)) 0 0 0
if (SvTRUE (ERRSV)) 0 0 0
1278 {
1279 STRLEN l ;
1280 0 ▶ strncpy (r -> errdat1, SvPV (ERRSV, l), sizeof (r -> errdat1) - 1) ;
Branch: 1 branch
BranchTrueFalseTotal
strncpy (r -> errdat1, SvPV (ERRSV, l), sizeof (r -> errdat1) - 1) ; 0 0 0
1281 0 LogError (r, rcEvalErr) ;
1282 0 ▶ sv_setpv(ERRSV,"");
Branch: 1 branch
BranchTrueFalseTotal
sv_setpv(ERRSV,""); 0 0 0
1283 0 num = 0 ;
1284 }
1285 0 ▶ if (num != 1 || !SvROK (pParamRV) || !(pParam = SvRV(pParamRV)) ||
Branch: 3 branches
BranchTrueFalseTotal
if (num != 1 || !SvROK (pParamRV) || !(pParam = SvRV(pParamRV)) || 0 0 0
if (num != 1 || !SvROK (pParamRV) || !(pParam = SvRV(pParamRV)) || 0 0 0
if (num != 1 || !SvROK (pParamRV) || !(pParam = SvRV(pParamRV)) || 0 0 0
1286 0 ▶ (SvTYPE((SV *)pParam) != SVt_PVHV && SvTYPE(pParam) != SVt_PVAV))
Branch: 2 branches
BranchTrueFalseTotal
(SvTYPE((SV *)pParam) != SVt_PVHV && SvTYPE(pParam) != SVt_PVAV)) 0 0 0
(SvTYPE((SV *)pParam) != SVt_PVHV && SvTYPE(pParam) != SVt_PVAV)) 0 0 0
1287 {
1288 0 strncpy (r -> errdat1, SvPV(pRecipe, l), sizeof (r -> errdat1) - 1) ;
1289 0 return rcUnknownRecipe ;
1290 }
1291 }
1292 0 ▶ else if (SvROK(pRecipe))
Branch: 1 branch
BranchTrueFalseTotal
else if (SvROK(pRecipe)) 0 0 0
1293 0 pParam = SvRV(pRecipe) ;
1294 else
1295 0 pParam = pRecipe ;
1296  
1297 0 ▶ if ((rc = Cache_New (r, pParam, -1, 1, &r -> Component.pOutputCache)) != ok)
Branch: 1 branch
BranchTrueFalseTotal
if ((rc = Cache_New (r, pParam, -1, 1, &r -> Component.pOutputCache)) != ok) 0 0 0
1298 0 return rc ;
1299  
1300  
1301 0 ▶ if (strncmp (r -> Component.pOutputCache -> pProvider -> sOutputType, "text/", 5) == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (strncmp (r -> Component.pOutputCache -> pProvider -> sOutputType, "text/", 5) == 0) 0 0 0
1302 {
1303 0 ▶ if ((rc = Cache_GetContentSV (r, r -> Component.pOutputCache, &r -> Component.pOutputSV, FALSE)) != ok)
Branch: 1 branch
BranchTrueFalseTotal
if ((rc = Cache_GetContentSV (r, r -> Component.pOutputCache, &r -> Component.pOutputSV, FALSE)) != ok) 0 0 0
1304 0 return rc ;
1305 }
1306 0 ▶ else if (strcmp (r -> Component.pOutputCache -> pProvider -> sOutputType, "X-Embperl/DomTree") == 0)
Branch: 1 branch
BranchTrueFalseTotal
else if (strcmp (r -> Component.pOutputCache -> pProvider -> sOutputType, "X-Embperl/DomTree") == 0) 0 0 0
1307 {
1308 0 ▶ if ((rc = Cache_GetContentIndex (r, r -> Component.pOutputCache, &r -> Component.xCurrDomTree, FALSE)) != ok)
Branch: 1 branch
BranchTrueFalseTotal
if ((rc = Cache_GetContentIndex (r, r -> Component.pOutputCache, &r -> Component.xCurrDomTree, FALSE)) != ok) 0 0 0
1309 0 return rc ;
1310 }
1311 else
1312 {
1313 0 sprintf (r -> errdat1, "'%s' (accpetable are 'text/*', 'X-Embperl/DomTree')", r -> Component.pOutputCache -> pProvider -> sOutputType) ;
1314 0 strncpy (r -> errdat2, r -> Component.pOutputCache -> sKey, sizeof (r -> errdat2) - 1) ;
1315 0 return rcTypeMismatch ;
1316 }
1317  
1318 0 return ok ;
1319 }
1320  
1321  
1322
1323 /* ---------------------------------------------------------------------------- */
1324 /* */
1325 /* Request handler */
1326 /* */
1327 /* ---------------------------------------------------------------------------- */
1328  
1329  
1330  
1331 0 int embperl_RunRequest (/*i/o*/ register req * r)
1332  
1333 {
1334 0 int rc = ok ;
1335 0 tComponent * c = &r -> Component ;
1336 0 char * sInputfile = c -> sSourcefile ;
1337
1338  
1339 dTHR ;
1340 epTHX ;
1341  
1342 EPENTRY (ExecuteReq) ;
1343  
1344 0 ▶ if (!r -> Component.pExportHash)
Branch: 1 branch
BranchTrueFalseTotal
if (!r -> Component.pExportHash) 0 0 0
1345 0 r -> Component.pExportHash = newHV () ;
1346
1347 0 ENTER;
1348 0 SAVETMPS ;
1349
1350 /* SetupSafeNamespace (r) ; */
1351  
1352  
1353 0 ▶ if (c -> Param.pErrArray)
Branch: 1 branch
BranchTrueFalseTotal
if (c -> Param.pErrArray) 0 0 0
1354 {
1355 0 SvREFCNT_inc(c -> Param.pErrArray) ;
1356 0 SvREFCNT_dec(r -> pErrArray) ;
1357 0 r -> pErrArray = c -> Param.pErrArray ;
1358 }
1359
1360 /* --- open output and send http header if EarlyHttpHeaders --- */
1361 0 ▶ if (rc == ok)
Branch: 1 branch
BranchTrueFalseTotal
if (rc == ok) 0 0 0
1362 0 rc = StartOutput (r) ;
1363  
1364
1365 /* --- ok so far? if not exit ---- */
1366 #ifdef APACHE
1367 if (rc != ok || (r -> pApacheReq && r -> pApacheReq -> header_only && (r -> Config.bOptions & optEarlyHttpHeader)))
1368 #else
1369 0 ▶ if (rc != ok)
Branch: 1 branch
BranchTrueFalseTotal
if (rc != ok) 0 0 0
1370 #endif
1371 {
1372 0 ▶ if (rc != ok)
Branch: 1 branch
BranchTrueFalseTotal
if (rc != ok) 0 0 0
1373 0 LogError (r, rc);
1374 #ifdef APACHE
1375 r -> pApacheReq = NULL ;
1376 #endif
1377 0 r -> Component.bReqRunning = 0 ;
1378 0 ▶ FREETMPS ;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS ; 0 0 0
1379 0 LEAVE;
1380 0 return rc ;
1381 }
1382  
1383 0 r -> Component.bReqRunning = 1 ;
1384  
1385 0 ▶ if (!r -> bError)
Branch: 1 branch
BranchTrueFalseTotal
if (!r -> bError) 0 0 0
1386 {
1387 0 ▶ if ((rc = ProcessFile (r, 0 /*r -> Buf.pFile -> nFilesize*/)) != ok)
Branch: 1 branch
BranchTrueFalseTotal
if ((rc = ProcessFile (r, 0 /*r -> Buf.pFile -> nFilesize*/)) != ok) 0 0 0
1388 {
1389 0 ▶ if (rc == rcExit)
Branch: 1 branch
BranchTrueFalseTotal
if (rc == rcExit) 0 0 0
1390 0 rc = ok ;
1391 else
1392 0 LogError (r, rc) ;
1393 }
1394  
1395 0 ▶ if (r -> Component.Param.nImport > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Param.nImport > 0) 0 0 0
1396 0 export (r) ;
1397 }
1398  
1399 /* --- Restore Operatormask and Package, destroy temp perl sv's --- */
1400 0 ▶ FREETMPS ;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS ; 0 0 0
1401 0 LEAVE;
1402 0 r -> Component.bReqRunning = 0 ;
1403  
1404 /* --- send http header and data to the browser if not already done --- */
1405 0 ▶ if ((rc = EndOutput (r, rc, r -> Component.Param.pOutput)) != ok)
Branch: 1 branch
BranchTrueFalseTotal
if ((rc = EndOutput (r, rc, r -> Component.Param.pOutput)) != ok) 0 0 0
1406 0 LogError (r, rc) ;
1407  
1408 #ifdef EP2
1409 0 ▶ if (r -> Component.pOutputCache)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.pOutputCache) 0 0 0
1410 0 Cache_ReleaseContent (r, r -> Component.pOutputCache) ;
1411 #endif
1412
1413 /* --- reset variables and log end of request --- */
1414 0 ▶ if ((rc = ResetRequest (r, sInputfile)) != ok)
Branch: 1 branch
BranchTrueFalseTotal
if ((rc = ResetRequest (r, sInputfile)) != ok) 0 0 0
1415 0 LogError (r, rc) ;
1416  
1417 #if defined (_MDEBUG) && defined (WIN32)
1418 _ASSERTE( _CrtCheckMemory( ) );
1419 #endif
1420  
1421 0 ▶ if ((c -> Config.bOptions & optReturnError) && r -> bError)
Branch: 2 branches
BranchTrueFalseTotal
if ((c -> Config.bOptions & optReturnError) && r -> bError) 0 0 0
if ((c -> Config.bOptions & optReturnError) && r -> bError) 0 0 0
1422 {
1423 #ifdef APACHE
1424 if (r -> pApacheReq && r -> pApacheReqSV)
1425 {
1426 dSP ;
1427 PUSHMARK(sp);
1428 XPUSHs(r -> pApacheReqSV);
1429 XPUSHs(sv_2mortal(newSVpv("EMBPERL_ERRORS", 14)));
1430 XPUSHs(sv_2mortal(newRV((SV*)r -> pErrArray)));
1431 PUTBACK;
1432 perl_call_method ("pnotes", G_DISCARD) ;
1433 }
1434 #endif
1435 #ifdef APACHE
1436 /* This must be the very very very last !!!!! */
1437 r -> pApacheReq = NULL ;
1438 #endif
1439 0 return 500 ;
1440 }
1441 #ifdef APACHE
1442 /* This must be the very very very last !!!!! */
1443 r -> pApacheReq = NULL ;
1444 #endif
1445  
1446 0 return ok ;
1447 }
1448  
1449 /* ---------------------------------------------------------------------------- */
1450 /* */
1451 /* Run Request */
1452 /* */
1453 /* ---------------------------------------------------------------------------- */
1454  
1455  
1456 0 int embperl_ExecuteRequest (/*in*/ pTHX_
1457 /*in*/ SV * pApacheReqSV,
1458 /*in*/ SV * pPerlParam)
1459  
1460  
1461 {
1462 int rc ;
1463 0 tReq * r = NULL ;
1464  
1465 #ifdef DMALLOC
1466 time_t t = time(NULL) ;
1467 static unsigned long nMemCheckpoint ;
1468 static unsigned long nMemCheckpoint2 ;
1469 dmalloc_message ("[%d]REQ: Start Request at %s\n", getpid(), ctime (&t)) ;
1470 #endif
1471  
1472 #if defined (_MDEBUG) && defined (WIN32)
1473 _CrtMemCheckpoint(&r -> MemCheckpoint);
1474 #endif
1475 #ifdef DMALLOC
1476 nMemCheckpoint2 = nMemCheckpoint ;
1477 nMemCheckpoint = dmalloc_mark () ;
1478 #endif
1479  
1480 0 ENTER;
1481 0 SAVETMPS ;
1482
1483 0 rc = embperl_InitRequestComponent (aTHX_ pApacheReqSV, pPerlParam, &r) ;
1484  
1485 #ifdef DMALLOC
1486 r -> MemCheckpoint = nMemCheckpoint;
1487 #endif
1488  
1489 0 ▶ if (rc == ok)
Branch: 1 branch
BranchTrueFalseTotal
if (rc == ok) 0 0 0
1490 0 rc = embperl_RunRequest (r) ;
1491  
1492 #ifdef DMALLOC
1493 dmalloc_message ( "[%d]%sRequest will be freed. Entry-SVs: %d: %%d\n", r -> pThread -> nPid,
1494 (r -> Component.pPrev?"Sub-":""), r -> stsv_count) ;
1495 #endif
1496  
1497 0 ▶ if (r)
Branch: 1 branch
BranchTrueFalseTotal
if (r) 0 0 0
1498 0 embperl_CleanupRequest (r) ;
1499  
1500 0 ▶ FREETMPS ;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS ; 0 0 0
1501 0 LEAVE;
1502  
1503 #if defined (_MDEBUG) && defined (WIN32)
1504 _CrtMemDumpAllObjectsSince(&r -> MemCheckpoint);
1505 #endif
1506 #ifdef DMALLOC
1507 /* unsigned long mark, int not_freed_b, int freed_b, int details_b */
1508 dmalloc_log_changed (nMemCheckpoint, 1, 0, 1) ;
1509 dmalloc_message ( "[%d]Request freed. Exit-SVs: %d\n", getpid(),
1510 sv_count) ;
1511 if (nMemCheckpoint2)
1512 {
1513 dmalloc_message ( "***TO PREVIOUS REQUEST***\n") ;
1514 dmalloc_log_changed (nMemCheckpoint2, 1, 0, 1) ;
1515 }
1516 #endif
1517  
1518 0 return rc ;
1519 }
1520
1521  
1522 /* ---------------------------------------------------------------------------- */
1523 /* */
1524 /* Run Component */
1525 /* */
1526 /* ---------------------------------------------------------------------------- */
1527  
1528 0 int embperl_RunComponent (/*in*/ tComponent * c)
1529  
1530  
1531 {
1532 0 tReq * r = c -> pReq ;
1533 epTHX_
1534 int rc ;
1535  
1536 0 ENTER;
1537 0 SAVETMPS ;
1538
1539 0 c -> bReqRunning = 1 ;
1540  
1541 0 ▶ if ((c -> Config.bOptions & optReturnError) )
Branch: 1 branch
BranchTrueFalseTotal
if ((c -> Config.bOptions & optReturnError) ) 0 0 0
1542 0 save_int(&r -> bError) ;
1543  
1544 0 ▶ if (c -> Param.pErrArray)
Branch: 1 branch
BranchTrueFalseTotal
if (c -> Param.pErrArray) 0 0 0
1545 {
1546 0 save_int(&r -> bError) ;
1547 0 save_aptr(&r -> pErrArray) ;
1548 0 r -> pErrArray = c -> Param.pErrArray ;
1549 }
1550  
1551 0 ▶ if ((c -> Config.bOptions & optEarlyHttpHeader) == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((c -> Config.bOptions & optEarlyHttpHeader) == 0) 0 0 0
1552 0 oBegin (r) ;
1553  
1554 0 ▶ if ((rc = ProcessFile (r, 0 /*r -> Buf.pFile -> nFilesize*/)) != ok)
Branch: 1 branch
BranchTrueFalseTotal
if ((rc = ProcessFile (r, 0 /*r -> Buf.pFile -> nFilesize*/)) != ok) 0 0 0
1555 {
1556 0 ▶ if (rc == rcExit)
Branch: 1 branch
BranchTrueFalseTotal
if (rc == rcExit) 0 0 0
1557 0 rc = ok ;
1558 else
1559 0 LogError (r, rc) ;
1560 }
1561  
1562 0 ▶ if (rc == ok && (c -> Config.bOptions & optReturnError) && r -> bError)
Branch: 3 branches
BranchTrueFalseTotal
if (rc == ok && (c -> Config.bOptions & optReturnError) && r -> bError) 0 0 0
if (rc == ok && (c -> Config.bOptions & optReturnError) && r -> bError) 0 0 0
if (rc == ok && (c -> Config.bOptions & optReturnError) && r -> bError) 0 0 0
1563 0 rc = 500 ;
1564
1565  
1566 0 ▶ if (!r -> bError)
Branch: 1 branch
BranchTrueFalseTotal
if (!r -> bError) 0 0 0
1567 {
1568 0 ▶ if (c -> Param.nImport > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (c -> Param.nImport > 0) 0 0 0
1569 0 export (r) ;
1570 0 ▶ else if (c -> pOutput && !c -> pOutput -> bDisableOutput)
Branch: 2 branches
BranchTrueFalseTotal
else if (c -> pOutput && !c -> pOutput -> bDisableOutput) 0 0 0
else if (c -> pOutput && !c -> pOutput -> bDisableOutput) 0 0 0
1571 {
1572 0 ▶ if (c -> Param.pOutput)
Branch: 1 branch
BranchTrueFalseTotal
if (c -> Param.pOutput) 0 0 0
1573 0 OutputToMem (r) ;
1574 0 ▶ else if (r -> Component.pPrev && c -> pOutput == r -> Component.pPrev -> pOutput)
Branch: 2 branches
BranchTrueFalseTotal
else if (r -> Component.pPrev && c -> pOutput == r -> Component.pPrev -> pOutput) 0 0 0
else if (r -> Component.pPrev && c -> pOutput == r -> Component.pPrev -> pOutput) 0 0 0
1575 0 AppendToUpperTree (r) ;
1576 else
1577 0 OutputToFile (r) ;
1578 }
1579 }
1580  
1581 /* --- Restore Operatormask and Package, destroy temp perl sv's --- */
1582 0 ▶ FREETMPS ;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS ; 0 0 0
1583 0 LEAVE;
1584 0 c -> bReqRunning = 0 ;
1585  
1586 0 return rc ;
1587 }
1588
1589 /* ---------------------------------------------------------------------------- */
1590 /* */
1591 /* Execute Component */
1592 /* */
1593 /* ---------------------------------------------------------------------------- */
1594  
1595  
1596 0 int embperl_ExecuteComponent(/*in*/ tReq * r,
1597 /*in*/ SV * pPerlParam)
1598  
1599  
1600 {
1601 epTHX_
1602 int rc ;
1603 tComponent * pComponent ;
1604  
1605 0 rc = embperl_SetupComponent (r, pPerlParam, &pComponent) ;
1606 0 ▶ if (rc == ok)
Branch: 1 branch
BranchTrueFalseTotal
if (rc == ok) 0 0 0
1607 {
1608 0 rc = embperl_RunComponent (pComponent) ;
1609
1610 0 embperl_CleanupComponent (pComponent) ;
1611 }
1612  
1613 0 return rc ;
1614 }
1615
« epio.c ↑ Summary epmem.c »