eputil.c

filter: Statementstmt 0.0% 0 / 780 Branchbran 0.0% 0 / 742 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 1522 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« epprovider.c ↑ Summary
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 /* Output a string and escape html special character to html special */
24 /* representation (&xxx;) */
25 /* */
26 /* i/o sData = input: perl string */
27 /* */
28 /* ---------------------------------------------------------------------------- */
29  
30 0 void OutputToHtml (/*i/o*/ register req * r,
31 /*i/o*/ const char * sData)
32  
33 {
34 char * pHtml ;
35 0 const char * p = sData ;
36
37 EPENTRY (OutputToHtml) ;
38  
39 0 ▶ if (r -> Component.pCurrEscape == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.pCurrEscape == NULL) 0 0 0
40 {
41 0 oputs (r, sData) ;
42 0 return ;
43 }
44  
45
46 0 ▶ while (*sData)
Branch: 1 branch
BranchTrueFalseTotal
while (*sData) 0 0 0
47 {
48 0 ▶ if (*sData == '\\' && (r -> Component.nCurrEscMode & escEscape) == 0)
Branch: 2 branches
BranchTrueFalseTotal
if (*sData == '\\' && (r -> Component.nCurrEscMode & escEscape) == 0) 0 0 0
if (*sData == '\\' && (r -> Component.nCurrEscMode & escEscape) == 0) 0 0 0
49 {
50 0 ▶ if (p != sData)
Branch: 1 branch
BranchTrueFalseTotal
if (p != sData) 0 0 0
51 0 owrite (r, p, sData - p) ;
52 0 sData++ ;
53 0 p = sData ;
54 }
55 else
56 {
57 0 pHtml = r -> Component.pCurrEscape[(unsigned char)(*sData)].sHtml ;
58 0 ▶ if (*pHtml)
Branch: 1 branch
BranchTrueFalseTotal
if (*pHtml) 0 0 0
59 {
60 0 ▶ if (p != sData)
Branch: 1 branch
BranchTrueFalseTotal
if (p != sData) 0 0 0
61 0 owrite (r, p, sData - p) ;
62 0 oputs (r, pHtml) ;
63 0 p = sData + 1;
64 }
65 }
66 0 sData++ ;
67 }
68 0 ▶ if (p != sData)
Branch: 1 branch
BranchTrueFalseTotal
if (p != sData) 0 0 0
69 0 owrite (r, p, sData - p) ;
70 }
71  
72 /* ---------------------------------------------------------------------------- */
73 /* */
74 /* Output a string and escape it */
75 /* */
76 /* in sData = input: string */
77 /* nDataLen = input: length of string */
78 /* pEscTab = input: escape table */
79 /* cEscChar = input: char to escape escaping (0 = off) */
80 /* */
81 /* ---------------------------------------------------------------------------- */
82  
83 0 void OutputEscape (/*i/o*/ register req * r,
84 /*in*/ const char * sData,
85 /*in*/ int nDataLen,
86 /*in*/ struct tCharTrans * pEscTab,
87 /*in*/ char cEscChar)
88  
89 {
90 char * pHtml ;
91 const char * p ;
92 int l ;
93  
94 EPENTRY (OutputEscape) ;
95  
96 0 ▶ if (pEscTab == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (pEscTab == NULL) 0 0 0
97 {
98 0 owrite (r, sData, nDataLen) ;
99 0 return ;
100 }
101  
102 0 p = sData ;
103 0 l = nDataLen ;
104  
105 0 ▶ while (l > 0)
Branch: 1 branch
BranchTrueFalseTotal
while (l > 0) 0 0 0
106 {
107 0 ▶ if (cEscChar && *sData == cEscChar)
Branch: 2 branches
BranchTrueFalseTotal
if (cEscChar && *sData == cEscChar) 0 0 0
if (cEscChar && *sData == cEscChar) 0 0 0
108 {
109 0 ▶ if (p != sData)
Branch: 1 branch
BranchTrueFalseTotal
if (p != sData) 0 0 0
110 0 owrite (r, p, sData - p) ;
111 0 sData++, l-- ;
112 0 p = sData ;
113 }
114 else
115 {
116 0 pHtml = pEscTab[(unsigned char)(*sData)].sHtml ;
117 0 ▶ if (*pHtml)
Branch: 1 branch
BranchTrueFalseTotal
if (*pHtml) 0 0 0
118 {
119 0 ▶ if (p != sData)
Branch: 1 branch
BranchTrueFalseTotal
if (p != sData) 0 0 0
120 0 owrite (r, p, sData - p) ;
121 0 oputs (r, pHtml) ;
122 0 p = sData + 1;
123 }
124 }
125 0 sData++, l-- ;
126 }
127 0 ▶ if (p != sData)
Branch: 1 branch
BranchTrueFalseTotal
if (p != sData) 0 0 0
128 0 owrite (r, p, sData - p) ;
129 }
130  
131 /* ---------------------------------------------------------------------------- */
132 /* */
133 /* Escape a string and return a sv */
134 /* */
135 /* in sData = input: string */
136 /* nDataLen = input: length of string */
137 /* pEscTab = input: escape table */
138 /* cEscChar = input: char to escape escaping (0 = off) */
139 /* */
140 /* ---------------------------------------------------------------------------- */
141  
142 0 SV * Escape (/*i/o*/ register req * r,
143 /*in*/ const char * sData,
144 /*in*/ int nDataLen,
145 /*in*/ int nEscMode,
146 /*in*/ struct tCharTrans * pEscTab,
147 /*in*/ char cEscChar)
148  
149 {
150 epTHX_
151 char * pHtml ;
152 const char * p ;
153 int l ;
154 0 SV * pSV = newSVpv("",0) ;
155  
156 EPENTRY (Escape) ;
157  
158  
159 0 ▶ if (nEscMode >= 0)
Branch: 1 branch
BranchTrueFalseTotal
if (nEscMode >= 0) 0 0 0
160 {
161 0 ▶ if ((nEscMode & escXML) && !r -> Component.bEscInUrl)
Branch: 2 branches
BranchTrueFalseTotal
if ((nEscMode & escXML) && !r -> Component.bEscInUrl) 0 0 0
if ((nEscMode & escXML) && !r -> Component.bEscInUrl) 0 0 0
162 0 pEscTab = Char2XML ;
163 0 ▶ else if ((nEscMode & escHtml) && !r -> Component.bEscInUrl)
Branch: 2 branches
BranchTrueFalseTotal
else if ((nEscMode & escHtml) && !r -> Component.bEscInUrl) 0 0 0
else if ((nEscMode & escHtml) && !r -> Component.bEscInUrl) 0 0 0
164 0 {
165 struct tCharTrans * pChar2Html ;
166  
167 0 ▶ if (nEscMode & escHtmlUtf8)
Branch: 1 branch
BranchTrueFalseTotal
if (nEscMode & escHtmlUtf8) 0 0 0
168 0 pChar2Html = Char2HtmlMin ;
169 0 ▶ else if (r -> Config.nOutputEscCharset == ocharsetLatin1)
Branch: 1 branch
BranchTrueFalseTotal
else if (r -> Config.nOutputEscCharset == ocharsetLatin1) 0 0 0
170 0 pChar2Html = Char2Html ;
171 0 ▶ else if (r -> Config.nOutputEscCharset == ocharsetLatin2)
Branch: 1 branch
BranchTrueFalseTotal
else if (r -> Config.nOutputEscCharset == ocharsetLatin2) 0 0 0
172 0 pChar2Html = Char2HtmlLatin2 ;
173 else
174 0 pChar2Html = Char2HtmlMin ;
175 0 pEscTab = pChar2Html ;
176 }
177 0 ▶ else if (nEscMode & escUrl)
Branch: 1 branch
BranchTrueFalseTotal
else if (nEscMode & escUrl) 0 0 0
178 0 pEscTab = Char2Url ;
179 else
180 0 pEscTab = NULL ;
181 0 ▶ if (nEscMode & escEscape)
Branch: 1 branch
BranchTrueFalseTotal
if (nEscMode & escEscape) 0 0 0
182 0 cEscChar = '\0' ;
183 else
184 0 cEscChar = '\\' ;
185 }
186  
187 0 ▶ if (pEscTab == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (pEscTab == NULL) 0 0 0
188 {
189 0 sv_setpvn (pSV, sData, nDataLen) ;
190 0 return pSV ;
191 }
192  
193 0 p = sData ;
194 0 l = nDataLen ;
195  
196 0 ▶ while (l > 0)
Branch: 1 branch
BranchTrueFalseTotal
while (l > 0) 0 0 0
197 {
198 0 ▶ if (cEscChar && *sData == cEscChar)
Branch: 2 branches
BranchTrueFalseTotal
if (cEscChar && *sData == cEscChar) 0 0 0
if (cEscChar && *sData == cEscChar) 0 0 0
199 {
200 0 ▶ if (p != sData)
Branch: 1 branch
BranchTrueFalseTotal
if (p != sData) 0 0 0
201 0 sv_catpvn (pSV, (char *)p, sData - p) ;
202 0 sData++, l-- ;
203 0 p = sData ;
204 }
205 else
206 {
207 0 pHtml = pEscTab[(unsigned char)(*sData)].sHtml ;
208 0 ▶ if (*pHtml)
Branch: 1 branch
BranchTrueFalseTotal
if (*pHtml) 0 0 0
209 {
210 0 ▶ if (p != sData)
Branch: 1 branch
BranchTrueFalseTotal
if (p != sData) 0 0 0
211 0 sv_catpvn (pSV, (char *)p, sData - p) ;
212 0 sv_catpv (pSV, pHtml) ;
213 0 p = sData + 1;
214 }
215 }
216 0 sData++, l-- ;
217 }
218 0 ▶ if (p != sData)
Branch: 1 branch
BranchTrueFalseTotal
if (p != sData) 0 0 0
219 0 sv_catpvn (pSV, (char *)p, sData - p) ;
220 0 return pSV ;
221 }
222  
223 #if 0
224  
225 /* ---------------------------------------------------------------------------- */
226 /* find substring ignore case */
227 /* */
228 /* in pSring = string to search in (any case) */
229 /* in pSubStr = string to search for (must be upper case) */
230 /* */
231 /* out ret = pointer to pSubStr in pStringvalue or NULL if not found */
232 /* */
233 /* ---------------------------------------------------------------------------- */
234  
235  
236  
237 static const char * stristr (/*in*/ const char * pString,
238 /*in*/ const char * pSubString)
239  
240 {
241 char c = *pSubString ;
242 int l = strlen (pSubString) ;
243
244 do
245 {
246 while (*pString && toupper (*pString) != c)
247 pString++ ;
248  
249 if (*pString == '\0')
250 return NULL ;
251  
252 if (strnicmp (pString, pSubString, l) == 0)
253 return pString ;
254 pString++ ;
255 }
256
257 while (TRUE) ;
258 }
259  
260  
261  
262 /* ---------------------------------------------------------------------------- */
263 /* make string lower case */
264 /* */
265 /* i/o pSring = string to search in (any case) */
266 /* */
267 /* ---------------------------------------------------------------------------- */
268  
269  
270 static char * strlower (/*in*/ char * pString)
271  
272 {
273 char * p = pString ;
274
275 while (*p)
276 {
277 *p = tolower (*p) ;
278 p++ ;
279 }
280  
281 return pString ;
282 }
283  
284 #endif
285  
286  
287 /* ---------------------------------------------------------------------------- */
288 /* find substring with max len */
289 /* */
290 /* in pSring = string to search in */
291 /* in pSubStr = string to search for */
292 /* */
293 /* out ret = pointer to pSubStr in pStringvalue or NULL if not found */
294 /* */
295 /* ---------------------------------------------------------------------------- */
296  
297  
298
299 0 const char * strnstr (/*in*/ const char * pString,
300 /*in*/ const char * pSubString,
301 /*in*/ int nMax)
302  
303 {
304 0 char c = *pSubString ;
305 0 int l = strlen (pSubString) ;
306
307 0 ▶ while (nMax-- > 0)
Branch: 1 branch
BranchTrueFalseTotal
while (nMax-- > 0) 0 0 0
308 {
309 0 ▶ while (*pString && *pString != c)
Branch: 2 branches
BranchTrueFalseTotal
while (*pString && *pString != c) 0 0 0
while (*pString && *pString != c) 0 0 0
310 0 pString++ ;
311  
312 0 ▶ if (*pString == '\0')
Branch: 1 branch
BranchTrueFalseTotal
if (*pString == '\0') 0 0 0
313 0 return NULL ;
314  
315 0 ▶ if (strncmp (pString, pSubString, l) == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (strncmp (pString, pSubString, l) == 0) 0 0 0
316 0 return pString ;
317 0 pString++ ;
318 }
319 0 return NULL ;
320 }
321  
322  
323  
324 /* ---------------------------------------------------------------------------- */
325 /* save strdup */
326 /* */
327 /* in pSring = string to save on memory heap */
328 /* */
329 /* ---------------------------------------------------------------------------- */
330  
331  
332 0 char * sstrdup (/*in*/ tReq * r,
333 /*in*/ char * pString)
334  
335 {
336 epTHX_
337 char * p ;
338
339 0 ▶ if (pString == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (pString == NULL) 0 0 0
340 0 return NULL ;
341  
342 0 p = malloc (strlen (pString) + 1) ;
343  
344 0 strcpy (p, pString) ;
345  
346 0 return p ;
347 }
348  
349  
350  
351 /* */
352 /* compare html escapes */
353 /* */
354  
355 0 static int CmpCharTrans (/*in*/ const void * pKey,
356 /*in*/ const void * pEntry)
357  
358 {
359 0 return strcmp ((const char *)pKey, ((struct tCharTrans *)pEntry) -> sHtml) ;
360 }
361  
362  
363  
364 /* ------------------------------------------------------------------------- */
365 /* */
366 /* replace html special character representation (&xxx;) with correct chars */
367 /* and delete all html tags */
368 /* The Replacement is done in place, the whole string will become shorter */
369 /* and is padded with spaces */
370 /* tags and special charcters which are preceeded by a \ are not translated */
371 /* carrige returns are replaced by spaces */
372 /* if optRawInput is set the functions do just nothing */
373 /* */
374 /* i/o sData = input: html string */
375 /* output: perl string */
376 /* in nLen = length of sData on input (or 0 for null terminated) */
377 /* */
378 /* ------------------------------------------------------------------------- */
379  
380 0 int TransHtml (/*i/o*/ register req * r,
381 /*i/o*/ char * sData,
382 /*in*/ int nLen)
383  
384 {
385 0 char * p = sData ;
386 char * s ;
387 char * e ;
388 struct tCharTrans * pChar ;
389 0 int bInUrl = r -> Component.bEscInUrl ;
390 0 bool bUrlEsc = r -> Component.Config.nInputEscMode & iescUrl ;
391 0 bool bHtmlEsc = r -> Component.Config.nInputEscMode & iescHtml ;
392 0 bool bRemove = r -> Component.Config.nInputEscMode & iescRemoveTags ;
393  
394 0 ▶ if (bUrlEsc && bHtmlEsc && !bInUrl)
Branch: 3 branches
BranchTrueFalseTotal
if (bUrlEsc && bHtmlEsc && !bInUrl) 0 0 0
if (bUrlEsc && bHtmlEsc && !bInUrl) 0 0 0
if (bUrlEsc && bHtmlEsc && !bInUrl) 0 0 0
395 0 bUrlEsc = 0 ;
396  
397 EPENTRY (TransHtml) ;
398
399 0 ▶ if (bInUrl == 16)
Branch: 1 branch
BranchTrueFalseTotal
if (bInUrl == 16) 0 0 0
400 {
401 /* Just remove \ and }{ for rtf */
402 0 ▶ if (nLen == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (nLen == 0) 0 0 0
403 0 nLen = strlen (sData) ;
404 0 e = sData + nLen ;
405 0 ▶ while (p < e)
Branch: 1 branch
BranchTrueFalseTotal
while (p < e) 0 0 0
406 {
407 0 ▶ if (*p == '}' && p[1] == '{')
Branch: 2 branches
BranchTrueFalseTotal
if (*p == '}' && p[1] == '{') 0 0 0
if (*p == '}' && p[1] == '{') 0 0 0
408 0 *p++ = ' ', *p++ = ' ' ;
409 0 ▶ if (*p == '\\' && p[1] != '\0')
Branch: 2 branches
BranchTrueFalseTotal
if (*p == '\\' && p[1] != '\0') 0 0 0
if (*p == '\\' && p[1] != '\0') 0 0 0
410 0 *p++ = ' ' ;
411 0 p++ ;
412 }
413 0 return nLen ;
414 }
415  
416 0 ▶ if (r -> Component.Config.nInputEscMode == iescNone)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.nInputEscMode == iescNone) 0 0 0
417 {
418 #if PERL_VERSION < 5
419 /* Just remove CR for raw input for perl 5.004 */
420 if (nLen == 0)
421 nLen = strlen (sData) ;
422 e = sData + nLen ;
423 while (p < e)
424 {
425 if (*p == '\r')
426 *p = ' ' ;
427 p++ ;
428 }
429 #endif
430 0 return nLen ;
431 }
432
433 0 s = NULL ;
434 0 ▶ if (nLen == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (nLen == 0) 0 0 0
435 0 nLen = strlen (sData) ;
436 0 e = sData + nLen ;
437  
438 0 ▶ while (p < e)
Branch: 1 branch
BranchTrueFalseTotal
while (p < e) 0 0 0
439 {
440 0 ▶ if (*p == '\\')
Branch: 1 branch
BranchTrueFalseTotal
if (*p == '\\') 0 0 0
441 {
442
443 0 ▶ if (bRemove && p[1] == '<')
Branch: 2 branches
BranchTrueFalseTotal
if (bRemove && p[1] == '<') 0 0 0
if (bRemove && p[1] == '<') 0 0 0
444 { /* Quote next HTML tag */
445 0 memmove (p, p + 1, e - p - 1) ;
446 0 e[-1] = ' ' ;
447 0 p++ ;
448 0 ▶ while (p < e && *p != '>')
Branch: 2 branches
BranchTrueFalseTotal
while (p < e && *p != '>') 0 0 0
while (p < e && *p != '>') 0 0 0
449 0 p++ ;
450 }
451 0 ▶ else if (bHtmlEsc && p[1] == '&')
Branch: 2 branches
BranchTrueFalseTotal
else if (bHtmlEsc && p[1] == '&') 0 0 0
else if (bHtmlEsc && p[1] == '&') 0 0 0
452 { /* Quote next HTML char */
453 0 memmove (p, p + 1, e - p - 1) ;
454 0 e[-1] = ' ' ;
455 0 p++ ;
456 0 ▶ while (p < e && *p != ';')
Branch: 2 branches
BranchTrueFalseTotal
while (p < e && *p != ';') 0 0 0
while (p < e && *p != ';') 0 0 0
457 0 p++ ;
458 }
459 0 ▶ else if (bUrlEsc && p[1] == '%')
Branch: 2 branches
BranchTrueFalseTotal
else if (bUrlEsc && p[1] == '%') 0 0 0
else if (bUrlEsc && p[1] == '%') 0 0 0
460 { /* Quote next URL escape */
461 0 memmove (p, p + 1, e - p - 1) ;
462 0 e[-1] = ' ' ;
463 0 p += 3 ;
464 }
465 else
466 0 p++ ; /* Nothing to quote */
467 }
468 #if PERL_VERSION < 5
469 /* remove CR for perl 5.004 */
470 else if (*p == '\r')
471 {
472 *p++ = ' ' ;
473 }
474 #endif
475 else
476 {
477 0 ▶ if (bRemove && p[0] == '<' && (isalpha (p[1]) || p[1] == '/'))
Branch: 4 branches
BranchTrueFalseTotal
if (bRemove && p[0] == '<' && (isalpha (p[1]) || p[1] == '/')) 0 0 0
if (bRemove && p[0] == '<' && (isalpha (p[1]) || p[1] == '/')) 0 0 0
if (bRemove && p[0] == '<' && (isalpha (p[1]) || p[1] == '/')) 0 0 0
if (bRemove && p[0] == '<' && (isalpha (p[1]) || p[1] == '/')) 0 0 0
478 { /* count HTML tag length */
479 0 s = p ;
480 0 p++ ;
481 0 ▶ while (p < e && *p != '>')
Branch: 2 branches
BranchTrueFalseTotal
while (p < e && *p != '>') 0 0 0
while (p < e && *p != '>') 0 0 0
482 0 p++ ;
483 0 ▶ if (p < e)
Branch: 1 branch
BranchTrueFalseTotal
if (p < e) 0 0 0
484 0 p++ ;
485 else
486 { /* missing left '>' -> no html tag */
487 0 p = s ;
488 0 s = NULL ;
489 }
490 }
491 0 ▶ else if (bHtmlEsc && p[0] == '&')
Branch: 2 branches
BranchTrueFalseTotal
else if (bHtmlEsc && p[0] == '&') 0 0 0
else if (bHtmlEsc && p[0] == '&') 0 0 0
492 { /* count HTML char length */
493 0 s = p ;
494 0 p++ ;
495 0 ▶ while (p < e && *p != ';')
Branch: 2 branches
BranchTrueFalseTotal
while (p < e && *p != ';') 0 0 0
while (p < e && *p != ';') 0 0 0
496 0 p++ ;
497  
498 0 ▶ if (p < e)
Branch: 1 branch
BranchTrueFalseTotal
if (p < e) 0 0 0
499 {
500 0 *p = '\0' ;
501 0 p++ ;
502 0 pChar = (struct tCharTrans *)bsearch (s, Html2Char, sizeHtml2Char, sizeof (struct tCharTrans), CmpCharTrans) ;
503 0 ▶ if (pChar)
Branch: 1 branch
BranchTrueFalseTotal
if (pChar) 0 0 0
504 0 *s++ = pChar -> c ;
505 else
506 {
507 0 *(p-1)=';' ;
508 0 p = s ;
509 0 s = NULL ;
510 }
511 }
512 else
513 {
514 0 p = s ;
515 0 s = NULL ;
516 }
517 }
518 0 ▶ else if (bUrlEsc && p[0] == '%' && isdigit (p[1]) && isxdigit (p[2]))
Branch: 4 branches
BranchTrueFalseTotal
else if (bUrlEsc && p[0] == '%' && isdigit (p[1]) && isxdigit (p[2])) 0 0 0
else if (bUrlEsc && p[0] == '%' && isdigit (p[1]) && isxdigit (p[2])) 0 0 0
else if (bUrlEsc && p[0] == '%' && isdigit (p[1]) && isxdigit (p[2])) 0 0 0
else if (bUrlEsc && p[0] == '%' && isdigit (p[1]) && isxdigit (p[2])) 0 0 0
519 {
520  
521 0 s = p ;
522 0 p += 3 ;
523 0 ▶ *s++ = ((toupper (p[-2]) - (isdigit (p[-2])?'0':('A' - 10))) << 4)
Branch: 1 branch
BranchTrueFalseTotal
*s++ = ((toupper (p[-2]) - (isdigit (p[-2])?'0':('A' - 10))) << 4) 0 0 0
524 0 ▶ + (toupper (p[-1]) - (isdigit (p[-1])?'0':('A' - 10))) ;
Branch: 1 branch
BranchTrueFalseTotal
+ (toupper (p[-1]) - (isdigit (p[-1])?'0':('A' - 10))) ; 0 0 0
525 }
526 0 ▶ if (s && (p - s) > 0)
Branch: 2 branches
BranchTrueFalseTotal
if (s && (p - s) > 0) 0 0 0
if (s && (p - s) > 0) 0 0 0
527 { /* copy rest of string, pad with spaces */
528 0 memmove (s, p, e - p + 1) ;
529 0 memset (e - (p - s), ' ', (p - s)) ;
530 0 nLen -= p - s ;
531 0 p = s ;
532 0 s = NULL ;
533 }
534 else
535 0 ▶ if (p < e)
Branch: 1 branch
BranchTrueFalseTotal
if (p < e) 0 0 0
536 0 p++ ;
537 }
538 }
539  
540 0 return nLen ;
541 }
542  
543  
544  
545 0 void TransHtmlSV (/*i/o*/ register req * r,
546 /*i/o*/ SV * pSV)
547  
548 {
549 epTHX_
550 STRLEN vlen ;
551 STRLEN nlen ;
552 0 char * pVal = SvPV (pSV, vlen) ;
553  
554 0 nlen = TransHtml (r, pVal, vlen) ;
555  
556 0 pVal[nlen] = '\0' ;
557 0 SvCUR_set(pSV, nlen) ;
558 0 }
559  
560  
561 /* ---------------------------------------------------------------------------- */
562 /* get argument from html tag */
563 /* */
564 /* in pTag = html tag args (eg. arg=val arg=val .... >) */
565 /* in pArg = name of argument (must be upper case) */
566 /* */
567 /* out pLen = length of value */
568 /* out ret = pointer to value or NULL if not found */
569 /* */
570 /* ---------------------------------------------------------------------------- */
571  
572 0 const char * GetHtmlArg (/*in*/ const char * pTag,
573 /*in*/ const char * pArg,
574 /*out*/ int * pLen)
575  
576 {
577 const char * pVal ;
578 const char * pEnd ;
579 int l ;
580  
581 /*EPENTRY (GetHtmlArg) ;*/
582  
583 0 l = strlen (pArg) ;
584 0 ▶ while (*pTag)
Branch: 1 branch
BranchTrueFalseTotal
while (*pTag) 0 0 0
585 {
586 0 *pLen = 0 ;
587  
588 0 ▶ while (*pTag && !isalpha (*pTag))
Branch: 2 branches
BranchTrueFalseTotal
while (*pTag && !isalpha (*pTag)) 0 0 0
while (*pTag && !isalpha (*pTag)) 0 0 0
589 0 pTag++ ;
590  
591 0 pVal = pTag ;
592 0 ▶ while (*pVal && !isspace (*pVal) && *pVal != '=' && *pVal != '>')
Branch: 4 branches
BranchTrueFalseTotal
while (*pVal && !isspace (*pVal) && *pVal != '=' && *pVal != '>') 0 0 0
while (*pVal && !isspace (*pVal) && *pVal != '=' && *pVal != '>') 0 0 0
while (*pVal && !isspace (*pVal) && *pVal != '=' && *pVal != '>') 0 0 0
while (*pVal && !isspace (*pVal) && *pVal != '=' && *pVal != '>') 0 0 0
593 0 pVal++ ;
594  
595 0 ▶ while (*pVal && isspace (*pVal))
Branch: 2 branches
BranchTrueFalseTotal
while (*pVal && isspace (*pVal)) 0 0 0
while (*pVal && isspace (*pVal)) 0 0 0
596 0 pVal++ ;
597  
598 0 ▶ if (*pVal == '=')
Branch: 1 branch
BranchTrueFalseTotal
if (*pVal == '=') 0 0 0
599 {
600 0 pVal++ ;
601 0 ▶ while (*pVal && isspace (*pVal))
Branch: 2 branches
BranchTrueFalseTotal
while (*pVal && isspace (*pVal)) 0 0 0
while (*pVal && isspace (*pVal)) 0 0 0
602 0 pVal++ ;
603
604 0 pEnd = pVal ;
605 0 ▶ if (*pVal == '"' || *pVal == '\'')
Branch: 2 branches
BranchTrueFalseTotal
if (*pVal == '"' || *pVal == '\'') 0 0 0
if (*pVal == '"' || *pVal == '\'') 0 0 0
606 0 {
607 0 char nType = '\0';
608 0 char q = *pVal++ ;
609 0 pEnd++ ;
610  
611 0 ▶ while ((*pEnd != q || nType) && *pEnd != '\0')
Branch: 3 branches
BranchTrueFalseTotal
while ((*pEnd != q || nType) && *pEnd != '\0') 0 0 0
while ((*pEnd != q || nType) && *pEnd != '\0') 0 0 0
while ((*pEnd != q || nType) && *pEnd != '\0') 0 0 0
612 {
613 0 ▶ if (nType == '\0' && *pEnd == '[' && (pEnd[1] == '+' || pEnd[1] == '-' || pEnd[1] == '$' || pEnd[1] == '!' || pEnd[1] == '#'))
Branch: 7 branches
BranchTrueFalseTotal
if (nType == '\0' && *pEnd == '[' && (pEnd[1] == '+' || pEnd[1] == '-' || pEnd[1] == '$' || pEnd[1] == '!' || pEnd[1] == '#')) 0 0 0
if (nType == '\0' && *pEnd == '[' && (pEnd[1] == '+' || pEnd[1] == '-' || pEnd[1] == '$' || pEnd[1] == '!' || pEnd[1] == '#')) 0 0 0
if (nType == '\0' && *pEnd == '[' && (pEnd[1] == '+' || pEnd[1] == '-' || pEnd[1] == '$' || pEnd[1] == '!' || pEnd[1] == '#')) 0 0 0
if (nType == '\0' && *pEnd == '[' && (pEnd[1] == '+' || pEnd[1] == '-' || pEnd[1] == '$' || pEnd[1] == '!' || pEnd[1] == '#')) 0 0 0
if (nType == '\0' && *pEnd == '[' && (pEnd[1] == '+' || pEnd[1] == '-' || pEnd[1] == '$' || pEnd[1] == '!' || pEnd[1] == '#')) 0 0 0
if (nType == '\0' && *pEnd == '[' && (pEnd[1] == '+' || pEnd[1] == '-' || pEnd[1] == '$' || pEnd[1] == '!' || pEnd[1] == '#')) 0 0 0
if (nType == '\0' && *pEnd == '[' && (pEnd[1] == '+' || pEnd[1] == '-' || pEnd[1] == '$' || pEnd[1] == '!' || pEnd[1] == '#')) 0 0 0
614 0 nType = *++pEnd ;
615 0 ▶ else if (nType && *pEnd == nType && pEnd[1] == ']')
Branch: 3 branches
BranchTrueFalseTotal
else if (nType && *pEnd == nType && pEnd[1] == ']') 0 0 0
else if (nType && *pEnd == nType && pEnd[1] == ']') 0 0 0
else if (nType && *pEnd == nType && pEnd[1] == ']') 0 0 0
616 {
617 0 nType = '\0';
618 0 pEnd++ ;
619 }
620 0 pEnd++ ;
621 }
622 }
623 else
624 {
625 0 char nType = '\0';
626 0 ▶ while ((!isspace (*pEnd) || nType) && *pEnd != '\0' && *pEnd != '>')
Branch: 4 branches
BranchTrueFalseTotal
while ((!isspace (*pEnd) || nType) && *pEnd != '\0' && *pEnd != '>') 0 0 0
while ((!isspace (*pEnd) || nType) && *pEnd != '\0' && *pEnd != '>') 0 0 0
while ((!isspace (*pEnd) || nType) && *pEnd != '\0' && *pEnd != '>') 0 0 0
while ((!isspace (*pEnd) || nType) && *pEnd != '\0' && *pEnd != '>') 0 0 0
627 {
628 0 ▶ if (nType == '\0' && *pEnd == '[' && (pEnd[1] == '+' || pEnd[1] == '-' || pEnd[1] == '$' || pEnd[1] == '!' || pEnd[1] == '#'))
Branch: 7 branches
BranchTrueFalseTotal
if (nType == '\0' && *pEnd == '[' && (pEnd[1] == '+' || pEnd[1] == '-' || pEnd[1] == '$' || pEnd[1] == '!' || pEnd[1] == '#')) 0 0 0
if (nType == '\0' && *pEnd == '[' && (pEnd[1] == '+' || pEnd[1] == '-' || pEnd[1] == '$' || pEnd[1] == '!' || pEnd[1] == '#')) 0 0 0
if (nType == '\0' && *pEnd == '[' && (pEnd[1] == '+' || pEnd[1] == '-' || pEnd[1] == '$' || pEnd[1] == '!' || pEnd[1] == '#')) 0 0 0
if (nType == '\0' && *pEnd == '[' && (pEnd[1] == '+' || pEnd[1] == '-' || pEnd[1] == '$' || pEnd[1] == '!' || pEnd[1] == '#')) 0 0 0
if (nType == '\0' && *pEnd == '[' && (pEnd[1] == '+' || pEnd[1] == '-' || pEnd[1] == '$' || pEnd[1] == '!' || pEnd[1] == '#')) 0 0 0
if (nType == '\0' && *pEnd == '[' && (pEnd[1] == '+' || pEnd[1] == '-' || pEnd[1] == '$' || pEnd[1] == '!' || pEnd[1] == '#')) 0 0 0
if (nType == '\0' && *pEnd == '[' && (pEnd[1] == '+' || pEnd[1] == '-' || pEnd[1] == '$' || pEnd[1] == '!' || pEnd[1] == '#')) 0 0 0
629 0 nType = *++pEnd ;
630 0 ▶ else if (nType && *pEnd == nType && pEnd[1] == ']')
Branch: 3 branches
BranchTrueFalseTotal
else if (nType && *pEnd == nType && pEnd[1] == ']') 0 0 0
else if (nType && *pEnd == nType && pEnd[1] == ']') 0 0 0
else if (nType && *pEnd == nType && pEnd[1] == ']') 0 0 0
631 {
632 0 nType = '\0';
633 0 pEnd++ ;
634 }
635 0 pEnd++ ;
636 }
637 }
638  
639 0 *pLen = pEnd - pVal ;
640 }
641 else
642 0 pEnd = pVal ;
643  
644
645 0 ▶ if (strnicmp (pTag, pArg, l) == 0 && (pTag[l] == '=' || isspace (pTag[l]) || pTag[l] == '>' || pTag[l] == '\0'))
Branch: 5 branches
BranchTrueFalseTotal
if (strnicmp (pTag, pArg, l) == 0 && (pTag[l] == '=' || isspace (pTag[l]) || pTag[l] == '>' || pTag[l] == '\0')) 0 0 0
if (strnicmp (pTag, pArg, l) == 0 && (pTag[l] == '=' || isspace (pTag[l]) || pTag[l] == '>' || pTag[l] == '\0')) 0 0 0
if (strnicmp (pTag, pArg, l) == 0 && (pTag[l] == '=' || isspace (pTag[l]) || pTag[l] == '>' || pTag[l] == '\0')) 0 0 0
if (strnicmp (pTag, pArg, l) == 0 && (pTag[l] == '=' || isspace (pTag[l]) || pTag[l] == '>' || pTag[l] == '\0')) 0 0 0
if (strnicmp (pTag, pArg, l) == 0 && (pTag[l] == '=' || isspace (pTag[l]) || pTag[l] == '>' || pTag[l] == '\0')) 0 0 0
646 {
647 0 ▶ if (*pLen > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (*pLen > 0) 0 0 0
648 0 return pVal ;
649 else
650 0 return pTag ;
651 }
652  
653 0 pTag = pEnd ;
654 }
655  
656 0 *pLen = 0 ;
657 0 return NULL ;
658 }
659  
660  
661
662
663 /* ---------------------------------------------------------------------------- */
664 /* */
665 /* Get a Value out of a perl hash */
666 /* */
667 /* ---------------------------------------------------------------------------- */
668  
669  
670 0 char * GetHashValueLen (/*in*/ tReq * r,
671 /*in*/ HV * pHash,
672 /*in*/ const char * sKey,
673 /*in*/ int nLen,
674 /*in*/ int nMaxLen,
675 /*out*/ char * sValue)
676  
677 {
678 epTHX_
679 SV ** ppSV ;
680 char * p ;
681 STRLEN len ;
682  
683 /*EPENTRY (GetHashValueLen) ;*/
684  
685 0 ppSV = hv_fetch(pHash, (char *)sKey, nLen, 0) ;
686 0 ▶ if (ppSV != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (ppSV != NULL) 0 0 0
687 {
688 0 p = SvPV (*ppSV ,len) ;
689 0 ▶ if (len >= (STRLEN)nMaxLen)
Branch: 1 branch
BranchTrueFalseTotal
if (len >= (STRLEN)nMaxLen) 0 0 0
690 0 len = nMaxLen - 1 ;
691 0 strncpy (sValue, p, len) ;
692 }
693 else
694 0 len = 0 ;
695  
696 0 sValue[len] = '\0' ;
697
698 0 return sValue ;
699 }
700  
701  
702 0 char * GetHashValue (/*in*/ tReq * r,
703 /*in*/ HV * pHash,
704 /*in*/ const char * sKey,
705 /*in*/ int nMaxLen,
706 /*out*/ char * sValue)
707 {
708 0 return GetHashValueLen (r, pHash, sKey, strlen (sKey), nMaxLen, sValue) ;
709 }
710  
711  
712  
713  
714 0 IV GetHashValueInt (/*in*/ pTHX_
715 /*in*/ HV * pHash,
716 /*in*/ const char * sKey,
717 /*in*/ IV nDefault)
718  
719 {
720 SV ** ppSV ;
721  
722 /*EPENTRY (GetHashValueInt) ;*/
723  
724 0 ppSV = hv_fetch(pHash, (char *)sKey, strlen (sKey), 0) ;
725 0 ▶ if (ppSV != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (ppSV != NULL) 0 0 0
726 0 return SvIV (*ppSV) ;
727
728 0 return nDefault ;
729 }
730  
731 0 UV GetHashValueUInt (/*in*/ tReq * r,
732 /*in*/ HV * pHash,
733 /*in*/ const char * sKey,
734 /*in*/ UV nDefault)
735  
736 {
737 SV ** ppSV ;
738 #ifdef PERL_IMPLICIT_CONTEXT
739 pTHX ;
740 if (r)
741 {
742 aTHX = r -> pPerlTHX ;
743 }
744 else
745 {
746 aTHX = PERL_GET_THX ;
747 }
748 #endif
749  
750 /*EPENTRY (GetHashValueInt) ;*/
751
752 0 ppSV = hv_fetch(pHash, (char *)sKey, strlen (sKey), 0) ;
753 0 ▶ if (ppSV != NULL && *ppSV && SvOK(*ppSV))
Branch: 3 branches
BranchTrueFalseTotal
if (ppSV != NULL && *ppSV && SvOK(*ppSV)) 0 0 0
if (ppSV != NULL && *ppSV && SvOK(*ppSV)) 0 0 0
if (ppSV != NULL && *ppSV && SvOK(*ppSV)) 0 0 0
754 {
755 0 return SvUV ((*ppSV)) ;
756 }
757  
758 0 return nDefault ;
759 }
760  
761  
762 0 char * GetHashValueStr (/*in*/ pTHX_
763 /*in*/ HV * pHash,
764 /*in*/ const char * sKey,
765 /*in*/ char * sDefault)
766  
767 {
768 SV ** ppSV ;
769 STRLEN l ;
770  
771 /*EPENTRY (GetHashValueInt) ;*/
772  
773 0 ppSV = hv_fetch(pHash, (char *)sKey, strlen (sKey), 0) ;
774 0 ▶ if (ppSV != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (ppSV != NULL) 0 0 0
775 0 return SvPV (*ppSV, l) ;
776
777 0 return sDefault ;
778 }
779  
780 0 char * GetHashValueStrDup (/*in*/ pTHX_
781 /*in*/ tMemPool * pPool,
782 /*in*/ HV * pHash,
783 /*in*/ const char * sKey,
784 /*in*/ char * sDefault)
785 {
786 SV ** ppSV ;
787 STRLEN l ;
788 char * s ;
789  
790 0 ppSV = hv_fetch(pHash, (char *)sKey, strlen (sKey), 0) ;
791 0 ▶ if (ppSV != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (ppSV != NULL) 0 0 0
792 {
793 0 ▶ if ((s = SvPV (*ppSV, l)))
Branch: 1 branch
BranchTrueFalseTotal
if ((s = SvPV (*ppSV, l))) 0 0 0
794 0 return ep_pstrdup (pPool, s);
795 else
796 0 return NULL ;
797 }
798  
799 0 ▶ if (sDefault)
Branch: 1 branch
BranchTrueFalseTotal
if (sDefault) 0 0 0
800 0 return ep_pstrdup (pPool, sDefault) ;
801 else
802 0 return NULL ;
803 }
804  
805 0 char * GetHashValueStrDupA (/*in*/ pTHX_
806 /*in*/ HV * pHash,
807 /*in*/ const char * sKey,
808 /*in*/ char * sDefault)
809 {
810 SV ** ppSV ;
811 STRLEN l ;
812 char * s ;
813  
814 0 ppSV = hv_fetch(pHash, (char *)sKey, strlen (sKey), 0) ;
815 0 ▶ if (ppSV != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (ppSV != NULL) 0 0 0
816 {
817 0 ▶ if ((s = SvPV (*ppSV, l)))
Branch: 1 branch
BranchTrueFalseTotal
if ((s = SvPV (*ppSV, l))) 0 0 0
818 0 return strdup (s);
819 else
820 0 return NULL ;
821 }
822  
823 0 ▶ if (sDefault)
Branch: 1 branch
BranchTrueFalseTotal
if (sDefault) 0 0 0
824 0 return strdup (sDefault) ;
825 else
826 0 return NULL ;
827 }
828  
829  
830 0 void GetHashValueStrOrHash (/*in*/ tReq * r,
831 /*in*/ HV * pHash,
832 /*in*/ const char * sKey,
833 /*out*/ char * * sValue,
834 /*out*/ HV * * pHV)
835  
836 {
837 epTHX_
838 SV ** ppSV ;
839 STRLEN l ;
840  
841 0 ppSV = hv_fetch(pHash, (char *)sKey, strlen (sKey), 0) ;
842 0 ▶ if (ppSV != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (ppSV != NULL) 0 0 0
843 {
844 0 ▶ if (!SvROK(*ppSV) || SvTYPE (SvRV(*ppSV)) != SVt_PVHV)
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(*ppSV) || SvTYPE (SvRV(*ppSV)) != SVt_PVHV) 0 0 0
if (!SvROK(*ppSV) || SvTYPE (SvRV(*ppSV)) != SVt_PVHV) 0 0 0
845 0 *sValue = SvPV (*ppSV, l), *pHV = NULL ;
846 else
847 0 *pHV = (HV *)SvRV(*ppSV), *sValue = NULL ;
848 }
849 0 }
850  
851  
852 0 SV * GetHashValueSVinc (/*in*/ tReq * r,
853 /*in*/ HV * pHash,
854 /*in*/ const char * sKey,
855 /*in*/ SV * sDefault)
856 {
857 epTHX_
858 SV ** ppSV ;
859  
860 0 ppSV = hv_fetch(pHash, (char *)sKey, strlen (sKey), 0) ;
861 0 ▶ if (ppSV != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (ppSV != NULL) 0 0 0
862 {
863 0 SvREFCNT_inc (*ppSV) ;
864 0 return *ppSV ;
865 }
866  
867 0 ▶ if (sDefault)
Branch: 1 branch
BranchTrueFalseTotal
if (sDefault) 0 0 0
868 0 return SvREFCNT_inc (sDefault) ;
869 else
870 0 return NULL ;
871 }
872  
873  
874 0 SV * GetHashValueSV (/*in*/ tReq * r,
875 /*in*/ HV * pHash,
876 /*in*/ const char * sKey)
877 {
878 epTHX_
879 SV ** ppSV ;
880  
881 0 ppSV = hv_fetch(pHash, (char *)sKey, strlen (sKey), 0) ;
882 0 ▶ if (ppSV != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (ppSV != NULL) 0 0 0
883 {
884 0 return *ppSV ;
885 }
886  
887 0 return NULL ;
888 }
889  
890 0 int GetHashValueHREF (/*in*/ req * r,
891 /*in*/ HV * pHash,
892 /*in*/ const char * sKey,
893 /*out*/ HV * * ppHV)
894 {
895 epTHX_
896 SV ** ppSV ;
897 HV * pHV ;
898  
899 0 ppSV = hv_fetch(pHash, (char *)sKey, strlen (sKey), 0) ;
900 0 ▶ if (ppSV != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (ppSV != NULL) 0 0 0
901 {
902 0 ▶ if (!SvROK(*ppSV))
Branch: 1 branch
BranchTrueFalseTotal
if (!SvROK(*ppSV)) 0 0 0
903 {
904 0 strncpy (r -> errdat2, sKey, sizeof(r -> errdat1) - 1) ;
905 0 return rcNotHashRef ;
906 }
907 0 pHV = (HV *)SvRV(*ppSV) ;
908 0 ▶ if (SvTYPE(pHV) != SVt_PVHV)
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(pHV) != SVt_PVHV) 0 0 0
909 {
910 0 strncpy (r -> errdat2, sKey, sizeof(r -> errdat1) - 1) ;
911 0 return rcNotHashRef ;
912 }
913 0 *ppHV = pHV ;
914 0 return ok ;
915 }
916  
917 0 strncpy (r -> errdat2, sKey, sizeof(r -> errdat1) - 1) ;
918 0 return rcNotHashRef ;
919 }
920  
921  
922 0 int GetHashValueCREF (/*in*/ req * r,
923 /*in*/ HV * pHash,
924 /*in*/ const char * sKey,
925 /*out*/ CV * * ppCV)
926 {
927 epTHX_
928 int rc ;
929 SV ** ppSV ;
930 CV * pCV ;
931  
932 0 ppSV = hv_fetch(pHash, (char *)sKey, strlen (sKey), 0) ;
933 0 ▶ if (ppSV != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (ppSV != NULL) 0 0 0
934 {
935 0 ▶ if (SvPOK(*ppSV))
Branch: 1 branch
BranchTrueFalseTotal
if (SvPOK(*ppSV)) 0 0 0
936 {
937 0 ▶ if ((rc = EvalConfig (r -> pApp, *ppSV, 0, NULL, sKey, ppCV)) != ok)
Branch: 1 branch
BranchTrueFalseTotal
if ((rc = EvalConfig (r -> pApp, *ppSV, 0, NULL, sKey, ppCV)) != ok) 0 0 0
938 0 return rc ;
939 0 return ok ;
940 }
941 0 ▶ if (!SvROK(*ppSV))
Branch: 1 branch
BranchTrueFalseTotal
if (!SvROK(*ppSV)) 0 0 0
942 {
943 0 strncpy (r -> errdat2, sKey, sizeof(r -> errdat1) - 1) ;
944 0 return rcNotCodeRef ;
945 }
946 0 pCV = (CV *)SvRV(*ppSV) ;
947 0 ▶ if (SvTYPE(pCV) != SVt_PVCV)
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(pCV) != SVt_PVCV) 0 0 0
948 {
949 0 strncpy (r -> errdat2, sKey, sizeof(r -> errdat1) - 1) ;
950 0 return rcNotCodeRef ;
951 }
952 0 *ppCV = (CV *)SvREFCNT_inc ((SV *)pCV) ;
953 0 return ok ;
954 }
955  
956 0 *ppCV = NULL ;
957 0 return ok ;
958 }
959  
960  
961 0 void SetHashValueStr (/*in*/ tReq * r,
962 /*in*/ HV * pHash,
963 /*in*/ const char * sKey,
964 /*in*/ char * sValue)
965  
966 {
967 epTHX_
968 0 SV * pSV = newSVpv (sValue, 0) ;
969  
970 /*EPENTRY (GetHashValueInt) ;*/
971  
972 0 hv_store(pHash, (char *)sKey, strlen (sKey), pSV, 0) ;
973 0 }
974  
975 0 void SetHashValueInt (/*in*/ tReq * r,
976 /*in*/ HV * pHash,
977 /*in*/ const char * sKey,
978 /*in*/ IV nValue)
979  
980 {
981 SV * pSV ;
982 #ifdef PERL_IMPLICIT_CONTEXT
983 pTHX ;
984 if (r)
985 aTHX = r -> pPerlTHX ;
986 else
987 aTHX = PERL_GET_THX ;
988 #endif
989  
990 /*EPENTRY (GetHashValueInt) ;*/
991  
992 0 tainted = 0 ; /* doesn't make sense to taint an integer */
993 0 pSV = newSViv (nValue) ;
994 0 hv_store(pHash, (char *)sKey, strlen (sKey), pSV, 0) ;
995  
996 0 }
997  
998  
999 0 SV * CreateHashRef (/*in*/ tReq * r,
1000 /*in*/ char * sKey, ...)
1001
1002 {
1003 epTHX_
1004 va_list marker;
1005 SV * pVal ;
1006 0 HV * pHash = newHV() ;
1007 int nType ;
1008  
1009 0 va_start (marker, sKey);
1010 0 ▶ while (sKey)
Branch: 1 branch
BranchTrueFalseTotal
while (sKey) 0 0 0
1011 {
1012 0 nType = va_arg (marker, int) ;
1013 0 ▶ if (nType == hashtstr)
Branch: 1 branch
BranchTrueFalseTotal
if (nType == hashtstr) 0 0 0
1014 {
1015 0 char * p = va_arg(marker, char *) ;
1016 0 ▶ if (p)
Branch: 1 branch
BranchTrueFalseTotal
if (p) 0 0 0
1017 0 pVal = newSVpv (p, 0) ;
1018 else
1019 0 pVal = NULL ;
1020 }
1021 0 ▶ else if (nType == hashtint)
Branch: 1 branch
BranchTrueFalseTotal
else if (nType == hashtint) 0 0 0
1022 0 pVal = newSViv (va_arg(marker, int)) ;
1023 else
1024 0 pVal = va_arg(marker, SV *) ;
1025  
1026 0 ▶ if (pVal)
Branch: 1 branch
BranchTrueFalseTotal
if (pVal) 0 0 0
1027 0 hv_store (pHash, sKey, strlen(sKey), pVal, 0) ;
1028 0 sKey = va_arg(marker, char *) ;
1029 }
1030 0 va_end (marker) ;
1031  
1032 0 return newRV_noinc ((SV *)pHash) ;
1033 }
1034  
1035  
1036  
1037 /* ------------------------------------------------------------------------- */
1038 /* */
1039 /* GetLineNo */
1040 /* */
1041 /* Counts the \n between pCurrPos and pSourcelinePos and in-/decrements */
1042 /* nSourceline accordingly */
1043 /* */
1044 /* return Linenumber of pCurrPos */
1045 /* */
1046 /* ------------------------------------------------------------------------- */
1047  
1048  
1049 0 int GetLineNoOf (/*i/o*/ register req * r,
1050 /*in*/ char * pPos)
1051  
1052 {
1053  
1054
1055 0 ▶ if (r -> Component.pSourcelinePos == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.pSourcelinePos == NULL) 0 0 0
1056 0 return r -> Component.nSourceline = r -> Component.Param.nFirstLine ;
1057  
1058 0 ▶ if (r -> Component.pLineNoCurrPos)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.pLineNoCurrPos) 0 0 0
1059 0 pPos = r -> Component.pLineNoCurrPos ;
1060  
1061 0 ▶ if (pPos == NULL || pPos == r -> Component.pSourcelinePos || pPos < r -> Component.pBuf || pPos > r -> Component.pEndPos)
Branch: 4 branches
BranchTrueFalseTotal
if (pPos == NULL || pPos == r -> Component.pSourcelinePos || pPos < r -> Component.pBuf || pPos > r -> Component.pEndPos) 0 0 0
if (pPos == NULL || pPos == r -> Component.pSourcelinePos || pPos < r -> Component.pBuf || pPos > r -> Component.pEndPos) 0 0 0
if (pPos == NULL || pPos == r -> Component.pSourcelinePos || pPos < r -> Component.pBuf || pPos > r -> Component.pEndPos) 0 0 0
if (pPos == NULL || pPos == r -> Component.pSourcelinePos || pPos < r -> Component.pBuf || pPos > r -> Component.pEndPos) 0 0 0
1062 0 return r -> Component.nSourceline ;
1063  
1064  
1065 0 ▶ if (pPos > r -> Component.pSourcelinePos)
Branch: 1 branch
BranchTrueFalseTotal
if (pPos > r -> Component.pSourcelinePos) 0 0 0
1066 {
1067 0 char * p = r -> Component.pSourcelinePos ;
1068  
1069 0 ▶ while (p < pPos && p < r -> Component.pEndPos)
Branch: 2 branches
BranchTrueFalseTotal
while (p < pPos && p < r -> Component.pEndPos) 0 0 0
while (p < pPos && p < r -> Component.pEndPos) 0 0 0
1070 {
1071 0 ▶ if (*p++ == '\n')
Branch: 1 branch
BranchTrueFalseTotal
if (*p++ == '\n') 0 0 0
1072 0 r -> Component.nSourceline++ ;
1073 }
1074 }
1075 else
1076 {
1077 0 char * p = r -> Component.pSourcelinePos ;
1078  
1079 0 ▶ while (p > pPos && p > r -> Component.pBuf)
Branch: 2 branches
BranchTrueFalseTotal
while (p > pPos && p > r -> Component.pBuf) 0 0 0
while (p > pPos && p > r -> Component.pBuf) 0 0 0
1080 {
1081 0 ▶ if (*--p == '\n')
Branch: 1 branch
BranchTrueFalseTotal
if (*--p == '\n') 0 0 0
1082 0 r -> Component.nSourceline-- ;
1083 }
1084 }
1085  
1086 0 r -> Component.pSourcelinePos = pPos ;
1087 0 return r -> Component.nSourceline ;
1088 }
1089  
1090  
1091 0 int GetLineNo (/*i/o*/ register req * r)
1092  
1093 {
1094 char * pPos ;
1095  
1096 0 ▶ if (r == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (r == NULL) 0 0 0
1097 0 return 0 ;
1098
1099 0 pPos = r -> Component.pCurrPos ;
1100 0 return GetLineNoOf (r, pPos) ;
1101 }
1102  
1103  
1104  
1105  
1106 #ifdef EP2
1107  
1108 /* ------------------------------------------------------------------------- */
1109 /* */
1110 /* ClearSymtab */
1111 /* */
1112 /* */
1113 /* in sPackage = package which symtab should be cleared */
1114 /* */
1115 /* ------------------------------------------------------------------------- */
1116  
1117  
1118  
1119 0 void ClearSymtab (/*i/o*/ register req * r,
1120 /*in*/ const char * sPackage,
1121 /*in*/ int bDebug)
1122  
1123 {
1124 /*dTHXsem */
1125 SV * val;
1126 char * key;
1127 I32 klen;
1128
1129 SV * sv;
1130 HV * hv;
1131 AV * av;
1132 struct io * io ;
1133 HV * symtab ;
1134 STRLEN l ;
1135 CV * pCV ;
1136 SV * pSV ;
1137 SV * * ppSV ;
1138 SV * pSVErr ;
1139 HV * pCleanupHV ;
1140 char * s ;
1141 char * sObjName ;
1142 /*
1143 GV * pFileGV ;
1144 GV * symtabgv ;
1145 GV * symtabfilegv ;
1146 */
1147  
1148 dTHR;
1149 epTHX_
1150  
1151 0 ▶ if ((symtab = gv_stashpv ((char *)sPackage, 0)) == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if ((symtab = gv_stashpv ((char *)sPackage, 0)) == NULL) 0 0 0
1152 0 return ;
1153  
1154 0 ppSV = hv_fetch (symtab, "_ep_DomTree", sizeof ("_ep_DomTree") - 1, 0) ;
1155 0 ▶ if (!ppSV || !*ppSV)
Branch: 2 branches
BranchTrueFalseTotal
if (!ppSV || !*ppSV) 0 0 0
if (!ppSV || !*ppSV) 0 0 0
1156 {
1157 0 ▶ if (bDebug)
Branch: 1 branch
BranchTrueFalseTotal
if (bDebug) 0 0 0
1158 0 lprintf (r -> pApp, "[%d]CUP: No Perl code in %s\n", r -> pThread -> nPid, sPackage) ;
1159 0 return ;
1160 }
1161  
1162 /*
1163 symtabgv = (GV *)*ppSV ;
1164 symtabfilegv = (GV *)GvFILEGV (symtabgv) ;
1165 */
1166  
1167 0 pSV = newSVpvf ("%s::CLEANUP", sPackage) ;
1168 newSVpvf2(pSV) ;
1169 0 s = SvPV (pSV, l) ;
1170 0 pCV = perl_get_cv (s, 0) ;
1171 0 ▶ if (pCV)
Branch: 1 branch
BranchTrueFalseTotal
if (pCV) 0 0 0
1172 {
1173 0 dSP ;
1174 0 ▶ if (bDebug)
Branch: 1 branch
BranchTrueFalseTotal
if (bDebug) 0 0 0
1175 0 lprintf (r -> pApp, "[%d]CUP: Call &%s::CLEANUP\n", r -> pThread -> nPid, sPackage) ;
1176 0 ▶ PUSHMARK(sp) ;
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(sp) ; 0 0 0
1177 0 perl_call_sv ((SV *)pCV, G_EVAL | G_NOARGS | G_DISCARD) ;
1178 0 ▶ pSVErr = ERRSV ;
Branch: 1 branch
BranchTrueFalseTotal
pSVErr = ERRSV ; 0 0 0
1179 0 ▶ if (SvTRUE (pSVErr))
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE (pSVErr)) 0 0 0
1180 {
1181 STRLEN l ;
1182 0 char * p = SvPV (pSVErr, l) ;
1183 0 ▶ if (l > sizeof (r -> errdat1) - 1)
Branch: 1 branch
BranchTrueFalseTotal
if (l > sizeof (r -> errdat1) - 1) 0 0 0
1184 0 l = sizeof (r -> errdat1) - 1 ;
1185 0 strncpy (r -> errdat1, p, l) ;
1186 0 ▶ if (l > 0 && r -> errdat1[l-1] == '\n')
Branch: 2 branches
BranchTrueFalseTotal
if (l > 0 && r -> errdat1[l-1] == '\n') 0 0 0
if (l > 0 && r -> errdat1[l-1] == '\n') 0 0 0
1187 0 l-- ;
1188 0 r -> errdat1[l] = '\0' ;
1189
1190 0 LogError (r, rcEvalErr) ;
1191  
1192 0 sv_setpv(pSVErr,"");
1193 }
1194 }
1195
1196
1197 0 pCleanupHV = perl_get_hv (s, 1) ;
1198
1199 0 SvREFCNT_dec(pSV) ;
1200  
1201 0 (void)hv_iterinit(symtab);
1202 0 ▶ while ((val = hv_iternextsv(symtab, &key, &klen)))
Branch: 1 branch
BranchTrueFalseTotal
while ((val = hv_iternextsv(symtab, &key, &klen))) 0 0 0
1203 {
1204 0 ▶ if(SvTYPE(val) != SVt_PVGV || SvANY(val) == NULL)
Branch: 2 branches
BranchTrueFalseTotal
if(SvTYPE(val) != SVt_PVGV || SvANY(val) == NULL) 0 0 0
if(SvTYPE(val) != SVt_PVGV || SvANY(val) == NULL) 0 0 0
1205 {
1206 /*
1207 if (bDebug)
1208 lprintf (r -> pApp, "[%d]CUP: Ignore %s because it's no gv\n", r -> pThread -> nPid, key) ;
1209 */
1210 0 continue;
1211 }
1212  
1213 0 s = GvNAME((GV *)val) ;
1214 0 l = strlen (s) ;
1215  
1216 0 ppSV = hv_fetch (pCleanupHV, s, l, 0) ;
1217  
1218 0 ▶ if (ppSV && *ppSV && SvIV (*ppSV) == 0)
Branch: 3 branches
BranchTrueFalseTotal
if (ppSV && *ppSV && SvIV (*ppSV) == 0) 0 0 0
if (ppSV && *ppSV && SvIV (*ppSV) == 0) 0 0 0
if (ppSV && *ppSV && SvIV (*ppSV) == 0) 0 0 0
1219 {
1220 /*
1221 if (bDebug)
1222 lprintf (r -> pApp, "[%d]CUP: Ignore %s because it's in %%CLEANUP\n", r -> pThread -> nPid, s) ;
1223 */
1224 0 continue ;
1225 }
1226  
1227
1228 0 ▶ if (!(ppSV && *ppSV && SvTRUE (*ppSV)))
Branch: 3 branches
BranchTrueFalseTotal
if (!(ppSV && *ppSV && SvTRUE (*ppSV))) 0 0 0
if (!(ppSV && *ppSV && SvTRUE (*ppSV))) 0 0 0
if (!(ppSV && *ppSV && SvTRUE (*ppSV))) 0 0 0
1229 {
1230 0 ▶ if(GvIMPORTED((GV*)val))
Branch: 1 branch
BranchTrueFalseTotal
if(GvIMPORTED((GV*)val)) 0 0 0
1231 {
1232 /*
1233 if (bDebug)
1234 lprintf (r -> pApp, "[%d]CUP: Ignore %s because it's imported\n", r -> pThread -> nPid, s) ;
1235 */
1236 0 continue ;
1237 }
1238
1239 0 ▶ if (s[0] == ':' && s[1] == ':')
Branch: 2 branches
BranchTrueFalseTotal
if (s[0] == ':' && s[1] == ':') 0 0 0
if (s[0] == ':' && s[1] == ':') 0 0 0
1240 {
1241 /*
1242 if (bDebug)
1243 lprintf (r -> pApp, "[%d]CUP: Ignore %s because it's special\n", r -> pThread -> nPid, s) ;
1244 */
1245 0 continue ;
1246 }
1247
1248 /*
1249 pFileGV = GvFILEGV ((GV *)val) ;
1250 if (pFileGV != symtabfilegv)
1251 {
1252 if (bDebug)
1253 lprintf (r -> pApp, "[%d]CUP: Ignore %s because it's defined in another source file (%s)\n", r -> pThread -> nPid, s, GvFILE((GV *)val)) ;
1254 continue ;
1255 }
1256 */
1257 }
1258
1259 0 sObjName = NULL ;
1260
1261 /* lprintf (r -> pApp, "[%d]CUP: type = %d flags=%x\n", r -> pThread -> nPid, SvTYPE (GvSV((GV*)val)), SvFLAGS (GvSV((GV*)val))) ; */
1262 0 ▶ if((sv = GvSV((GV*)val)) && SvTYPE (sv) == SVt_PVMG)
Branch: 2 branches
BranchTrueFalseTotal
if((sv = GvSV((GV*)val)) && SvTYPE (sv) == SVt_PVMG) 0 0 0
if((sv = GvSV((GV*)val)) && SvTYPE (sv) == SVt_PVMG) 0 0 0
1263 {
1264 0 HV * pStash = SvSTASH (sv) ;
1265  
1266 0 ▶ if (pStash)
Branch: 1 branch
BranchTrueFalseTotal
if (pStash) 0 0 0
1267 {
1268 0 ▶ sObjName = HvNAME(pStash) ;
Branch: 6 branches
BranchTrueFalseTotal
sObjName = HvNAME(pStash) ; 0 0 0
sObjName = HvNAME(pStash) ; 0 0 0
sObjName = HvNAME(pStash) ; 0 0 0
sObjName = HvNAME(pStash) ; 0 0 0
sObjName = HvNAME(pStash) ; 0 0 0
sObjName = HvNAME(pStash) ; 0 0 0
1269 0 ▶ if (sObjName && strcmp (sObjName, "DBIx::Recordset") == 0)
Branch: 2 branches
BranchTrueFalseTotal
if (sObjName && strcmp (sObjName, "DBIx::Recordset") == 0) 0 0 0
if (sObjName && strcmp (sObjName, "DBIx::Recordset") == 0) 0 0 0
1270 {
1271 0 SV * pSV = newSVpvf ("DBIx::Recordset::Undef ('%s')", s) ;
1272 newSVpvf2(pSV) ;
1273  
1274 0 ▶ if (bDebug)
Branch: 1 branch
BranchTrueFalseTotal
if (bDebug) 0 0 0
1275 0 lprintf (r -> pApp, "[%d]CUP: Recordset *%s\n", r -> pThread -> nPid, s) ;
1276 0 EvalDirect (r, pSV, 0, NULL) ;
1277 0 SvREFCNT_dec (pSV) ;
1278 }
1279 }
1280 }
1281  
1282 0 ▶ if((sv = GvSV((GV*)val)) && SvROK (sv) && SvOBJECT (SvRV(sv)))
Branch: 3 branches
BranchTrueFalseTotal
if((sv = GvSV((GV*)val)) && SvROK (sv) && SvOBJECT (SvRV(sv))) 0 0 0
if((sv = GvSV((GV*)val)) && SvROK (sv) && SvOBJECT (SvRV(sv))) 0 0 0
if((sv = GvSV((GV*)val)) && SvROK (sv) && SvOBJECT (SvRV(sv))) 0 0 0
1283 {
1284 0 HV * pStash = SvSTASH (SvRV(sv)) ;
1285 /* lprintf (r -> pApp, "[%d]CUP: rv type = %d\n", r -> pThread -> nPid, SvTYPE (SvRV(GvSV((GV*)val)))) ; */
1286 0 ▶ if (pStash)
Branch: 1 branch
BranchTrueFalseTotal
if (pStash) 0 0 0
1287 {
1288 0 ▶ sObjName = HvNAME(pStash) ;
Branch: 6 branches
BranchTrueFalseTotal
sObjName = HvNAME(pStash) ; 0 0 0
sObjName = HvNAME(pStash) ; 0 0 0
sObjName = HvNAME(pStash) ; 0 0 0
sObjName = HvNAME(pStash) ; 0 0 0
sObjName = HvNAME(pStash) ; 0 0 0
sObjName = HvNAME(pStash) ; 0 0 0
1289 0 ▶ if (sObjName && strcmp (sObjName, "DBIx::Recordset") == 0)
Branch: 2 branches
BranchTrueFalseTotal
if (sObjName && strcmp (sObjName, "DBIx::Recordset") == 0) 0 0 0
if (sObjName && strcmp (sObjName, "DBIx::Recordset") == 0) 0 0 0
1290 {
1291 0 SV * pSV = newSVpvf ("DBIx::Recordset::Undef ('%s')", s) ;
1292 newSVpvf2(pSV) ;
1293  
1294 0 ▶ if (bDebug)
Branch: 1 branch
BranchTrueFalseTotal
if (bDebug) 0 0 0
1295 0 lprintf (r -> pApp, "[%d]CUP: Recordset *%s\n", r -> pThread -> nPid, s) ;
1296 0 EvalDirect (r, pSV, 0, NULL) ;
1297 0 SvREFCNT_dec (pSV) ;
1298 }
1299 }
1300 }
1301 0 ▶ if((sv = GvSV((GV*)val)) && (SvOK (sv) || SvROK (sv)))
Branch: 3 branches
BranchTrueFalseTotal
if((sv = GvSV((GV*)val)) && (SvOK (sv) || SvROK (sv))) 0 0 0
if((sv = GvSV((GV*)val)) && (SvOK (sv) || SvROK (sv))) 0 0 0
if((sv = GvSV((GV*)val)) && (SvOK (sv) || SvROK (sv))) 0 0 0
1302 {
1303 0 ▶ if (bDebug)
Branch: 1 branch
BranchTrueFalseTotal
if (bDebug) 0 0 0
1304 0 ▶ lprintf (r -> pApp, "[%d]CUP: $%s = %s %s%s\n", r -> pThread -> nPid, s, SvPV (sv, l), sObjName?" Object of ":"", sObjName?sObjName:"") ;
Branch: 2 branches
BranchTrueFalseTotal
lprintf (r -> pApp, "[%d]CUP: $%s = %s %s%s\n", r -> pThread -> nPid, s, SvPV (sv, l), sObjName?" Object of ":"", sObjName?sObjName:"") ; 0 0 0
lprintf (r -> pApp, "[%d]CUP: $%s = %s %s%s\n", r -> pThread -> nPid, s, SvPV (sv, l), sObjName?" Object of ":"", sObjName?sObjName:"") ; 0 0 0
1305
1306 0 ▶ if ((sv = GvSV((GV*)val)) && SvREADONLY (sv))
Branch: 2 branches
BranchTrueFalseTotal
if ((sv = GvSV((GV*)val)) && SvREADONLY (sv)) 0 0 0
if ((sv = GvSV((GV*)val)) && SvREADONLY (sv)) 0 0 0
1307 {
1308 /*
1309 if (bDebug)
1310 lprintf (r -> pApp, "[%d]CUP: Ignore %s because it's readonly\n", r -> pThread -> nPid, s) ;
1311 */
1312 }
1313 else
1314 {
1315 0 sv_unmagic (sv, 'q') ; /* untie */
1316 0 sv_setsv(sv, &sv_undef);
1317 }
1318 }
1319 0 ▶ if((hv = GvHV((GV*)val)))
Branch: 1 branch
BranchTrueFalseTotal
if((hv = GvHV((GV*)val))) 0 0 0
1320 {
1321 0 ▶ if (bDebug)
Branch: 1 branch
BranchTrueFalseTotal
if (bDebug) 0 0 0
1322 0 lprintf (r -> pApp, "[%d]CUP: %%%s = ...\n", r -> pThread -> nPid, s) ;
1323 0 sv_unmagic ((SV *)hv, 'P') ; /* untie */
1324 0 hv_clear(hv);
1325 }
1326 0 ▶ if((av = GvAV((GV*)val)))
Branch: 1 branch
BranchTrueFalseTotal
if((av = GvAV((GV*)val))) 0 0 0
1327 {
1328 0 ▶ if (bDebug)
Branch: 1 branch
BranchTrueFalseTotal
if (bDebug) 0 0 0
1329 0 lprintf (r -> pApp, "[%d]CUP: @%s = ...\n", r -> pThread -> nPid, s) ;
1330 0 sv_unmagic ((SV *)av, 'P') ; /* untie */
1331 0 av_clear(av);
1332 }
1333 0 ▶ if((io = GvIO((GV*)val)))
Branch: 5 branches
BranchTrueFalseTotal
if((io = GvIO((GV*)val))) 0 0 0
if((io = GvIO((GV*)val))) 0 0 0
if((io = GvIO((GV*)val))) 0 0 0
if((io = GvIO((GV*)val))) 0 0 0
if((io = GvIO((GV*)val))) 0 0 0
1334 {
1335 0 ▶ if (bDebug)
Branch: 1 branch
BranchTrueFalseTotal
if (bDebug) 0 0 0
1336 0 lprintf (r -> pApp, "[%d]CUP: IO %s = ...\n", r -> pThread -> nPid, s) ;
1337 /* sv_unmagic ((SV *)io, 'q') ; */ /* untie */
1338 /* do_close((GV *)val, 0); */
1339 }
1340 }
1341 }
1342  
1343 #endif
1344  
1345  
1346 /* ------------------------------------------------------------------------- */
1347 /* */
1348 /* UndefSub */
1349 /* */
1350 /* */
1351 /* in sName = name of sub */
1352 /* in sPackage = package name */
1353 /* */
1354 /* ------------------------------------------------------------------------- */
1355  
1356  
1357  
1358 0 void UndefSub (/*i/o*/ register req * r,
1359 /*in*/ const char * sName,
1360 /*in*/ const char * sPackage)
1361  
1362  
1363 {
1364 CV * pCV ;
1365 0 int l = strlen (sName) + strlen (sPackage) ;
1366 0 char * sFullname = _malloc (r, l + 3) ;
1367 epTHX_
1368  
1369 0 strcpy (sFullname, sPackage) ;
1370 0 strcat (sFullname, "::") ;
1371 0 strcat (sFullname, sName) ;
1372 0 ▶ if (!(pCV = perl_get_cv (sFullname, 0)))
Branch: 1 branch
BranchTrueFalseTotal
if (!(pCV = perl_get_cv (sFullname, 0))) 0 0 0
1373 {
1374 0 _free (r, sFullname) ;
1375 0 return ;
1376 }
1377  
1378 0 _free (r, sFullname) ;
1379
1380 0 cv_undef (pCV) ;
1381 }
1382  
1383  
1384 /* ---------------------------------------------------------------------------- */
1385 /* */
1386 /* Get Session ID */
1387 /* */
1388 /* ---------------------------------------------------------------------------- */
1389  
1390  
1391 0 char * GetSessionID (/*i/o*/ register req * r,
1392 /*in*/ HV * pSessionHash,
1393 /*out*/ char * * ppInitialID,
1394 /*out*/ IV * pModified)
1395
1396 {
1397 0 SV * pSVID = NULL ;
1398 MAGIC * pMG ;
1399 0 char * pUID = "" ;
1400 0 STRLEN ulen = 0 ;
1401 0 STRLEN ilen = 0 ;
1402 epTHX_
1403  
1404 0 ▶ if (r -> nSessionMgnt)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> nSessionMgnt) 0 0 0
1405 {
1406 0 SV * pUserHashObj = NULL ;
1407 0 ▶ if ((pMG = mg_find((SV *)pSessionHash,'P')))
Branch: 1 branch
BranchTrueFalseTotal
if ((pMG = mg_find((SV *)pSessionHash,'P'))) 0 0 0
1408 {
1409 0 dSP; /* initialize stack pointer */
1410 int n ;
1411 0 pUserHashObj = pMG -> mg_obj ;
1412  
1413 0 ▶ PUSHMARK(sp); /* remember the stack pointer */
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(sp); /* remember the stack pointer */ 0 0 0
1414 0 ▶ XPUSHs(pUserHashObj) ; /* push pointer to obeject */
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(pUserHashObj) ; /* push pointer to obeject */ 0 0 0
1415 0 PUTBACK;
1416 0 n = perl_call_method ("getids", G_ARRAY) ; /* call the function */
1417 0 SPAGAIN;
1418 0 ▶ if (n > 2)
Branch: 1 branch
BranchTrueFalseTotal
if (n > 2) 0 0 0
1419 {
1420 0 int savewarn = dowarn ;
1421 0 dowarn = 0 ; /* no warnings here */
1422 0 *pModified = POPi ;
1423 0 pSVID = POPs;
1424 0 pUID = SvPV (pSVID, ulen) ;
1425 0 ▶ pSVID = POPs;
Branch: 1 branch
BranchTrueFalseTotal
pSVID = POPs; 0 0 0
1426 0 *ppInitialID = SvPV (pSVID, ilen) ;
1427 0 dowarn = savewarn ;
1428 }
1429 0 PUTBACK;
1430 }
1431 }
1432 0 return pUID ;
1433 }
1434  
1435 /* ------------------------------------------------------------------------- */
1436 /* */
1437 /* dirname */
1438 /* */
1439 /* returns dir name of file */
1440 /* */
1441 /* ------------------------------------------------------------------------- */
1442  
1443  
1444  
1445 0 static void dirname (/*in*/ const char * filename,
1446 /*out*/ char * dirname,
1447 /*in*/ int size)
1448  
1449 {
1450 0 char * p = strrchr (filename, '/') ;
1451  
1452 0 ▶ if (p == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (p == NULL) 0 0 0
1453 {
1454 0 strncpy (dirname, ".", size) ;
1455 0 return ;
1456 }
1457  
1458 0 ▶ if (size - 1 > p - filename)
Branch: 1 branch
BranchTrueFalseTotal
if (size - 1 > p - filename) 0 0 0
1459 0 size = p - filename ;
1460  
1461 0 strncpy (dirname, filename, size) ;
1462 0 dirname[size] = '\0' ;
1463  
1464 0 return ;
1465 }
1466  
1467  
1468 #ifdef WIN32
1469 #define isAbsPath(sFilename) \
1470 (sFilename[0] == '/' || sFilename[0] == '\\' || \
1471 (isalpha(sFilename[0]) && sFilename[1] == ':' && \
1472 (sFilename[2] == '\\' || sFilename[2] == '/') \
1473 ) \
1474 )
1475 #else
1476 #define isAbsPath(sFilename) (sFilename[0] == '/')
1477 #endif
1478  
1479 /* ---------------------------------------------------------------------------- */
1480 /* */
1481 /* Make filename absolut */
1482 /* */
1483 /* ---------------------------------------------------------------------------- */
1484  
1485 0 char * embperl_File2Abs (/*i/o*/ register req * r,
1486 /*in*/ tMemPool * pPool,
1487 /*in*/ const char * sFilename)
1488 {
1489 epTHX_
1490 #ifdef WIN32
1491 char * c ;
1492 #endif
1493 char * sAbsname ;
1494  
1495 0 ▶ if (sFilename == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (sFilename == NULL) 0 0 0
1496 0 return NULL ;
1497  
1498  
1499 /* is it a relative filename? -> append path */
1500 0 ▶ if (!isAbsPath(sFilename))
Branch: 1 branch
BranchTrueFalseTotal
if (!isAbsPath(sFilename)) 0 0 0
1501 {
1502 0 int l = strlen (sFilename) + strlen (r -> Component.sCWD) + 2 ;
1503
1504 0 ▶ sAbsname = pPool?ep_palloc(pPool, l):malloc (l) ;
Branch: 1 branch
BranchTrueFalseTotal
sAbsname = pPool?ep_palloc(pPool, l):malloc (l) ; 0 0 0
1505 0 strcpy (sAbsname, r -> Component.sCWD) ;
1506 0 strcat (sAbsname, PATH_SEPARATOR_STR) ;
1507 0 strcat (sAbsname, sFilename) ;
1508 }
1509 else
1510 0 ▶ sAbsname = pPool?ep_pstrdup (pPool, sFilename):strdup (sFilename) ;
Branch: 1 branch
BranchTrueFalseTotal
sAbsname = pPool?ep_pstrdup (pPool, sFilename):strdup (sFilename) ; 0 0 0
1511  
1512 #ifdef WIN32
1513 c = sAbsname ;
1514 while (*c)
1515 { /* convert / to \ */
1516 if (*c == '/')
1517 *c = '\\' ;
1518 c++ ;
1519 }
1520 #endif
1521  
1522 0 return sAbsname ;
1523 }
1524  
1525  
1526 /* ---------------------------------------------------------------------------- */
1527 /* */
1528 /* Change CWD to sourcefile dir */
1529 /* */
1530 /* ---------------------------------------------------------------------------- */
1531  
1532 0 void embperl_SetCWDToFile (/*i/o*/ register req * r,
1533 /*in*/ const char * sFilename)
1534  
1535 {
1536 epTHX_
1537
1538 char * sAbsFilename ;
1539 char * p ;
1540  
1541  
1542 0 ▶ if ((r -> Component.Config.bOptions & optDisableChdir) ||
Branch: 2 branches
BranchTrueFalseTotal
if ((r -> Component.Config.bOptions & optDisableChdir) || 0 0 0
if ((r -> Component.Config.bOptions & optDisableChdir) || 0 0 0
1543 0 ▶ sFilename == NULL || *sFilename == '\0' ||
Branch: 1 branch
BranchTrueFalseTotal
sFilename == NULL || *sFilename == '\0' || 0 0 0
1544 0 ▶ r -> Component.Param.pInput)
Branch: 1 branch
BranchTrueFalseTotal
r -> Component.Param.pInput) 0 0 0
1545 0 return ;
1546  
1547
1548
1549 0 sAbsFilename = embperl_File2Abs(r, r -> pPool, sFilename) ;
1550  
1551 0 p = strrchr(sAbsFilename, PATH_SEPARATOR_CHAR) ;
1552  
1553 0 ▶ while (p && p > sAbsFilename + 2 && p[-1] == '.' && p[-2] == '.' && p[-3] == PATH_SEPARATOR_CHAR)
Branch: 5 branches
BranchTrueFalseTotal
while (p && p > sAbsFilename + 2 && p[-1] == '.' && p[-2] == '.' && p[-3] == PATH_SEPARATOR_CHAR) 0 0 0
while (p && p > sAbsFilename + 2 && p[-1] == '.' && p[-2] == '.' && p[-3] == PATH_SEPARATOR_CHAR) 0 0 0
while (p && p > sAbsFilename + 2 && p[-1] == '.' && p[-2] == '.' && p[-3] == PATH_SEPARATOR_CHAR) 0 0 0
while (p && p > sAbsFilename + 2 && p[-1] == '.' && p[-2] == '.' && p[-3] == PATH_SEPARATOR_CHAR) 0 0 0
while (p && p > sAbsFilename + 2 && p[-1] == '.' && p[-2] == '.' && p[-3] == PATH_SEPARATOR_CHAR) 0 0 0
1554 {
1555 0 p[-3] = '\0' ;
1556 0 p = strrchr(sAbsFilename, PATH_SEPARATOR_CHAR) ;
1557 }
1558  
1559  
1560 0 r -> Component.sCWD = sAbsFilename ;
1561 0 ▶ if (p)
Branch: 1 branch
BranchTrueFalseTotal
if (p) 0 0 0
1562 0 *p = '\0' ;
1563 }
1564  
1565 /* ------------------------------------------------------------------------- */
1566 /* */
1567 /* Dirname */
1568 /* */
1569 /* returns dir name of file */
1570 /* */
1571 /* ------------------------------------------------------------------------- */
1572  
1573  
1574  
1575 0 void Dirname (/*in*/ const char * filename,
1576 /*out*/ char * dirname,
1577 /*in*/ int size)
1578  
1579 {
1580 0 char * p = strrchr (filename, '/') ;
1581  
1582 0 ▶ if (p == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (p == NULL) 0 0 0
1583 {
1584 0 strncpy (dirname, ".", size) ;
1585 0 return ;
1586 }
1587  
1588 0 ▶ if (size - 1 > p - filename)
Branch: 1 branch
BranchTrueFalseTotal
if (size - 1 > p - filename) 0 0 0
1589 0 size = p - filename ;
1590  
1591 0 strncpy (dirname, filename, size) ;
1592 0 dirname[size] = '\0' ;
1593  
1594 0 return ;
1595 }
1596  
1597 /* ---------------------------------------------------------------------------- */
1598 /* */
1599 /* Change Dir to sourcefile dir */
1600 /* */
1601 /* ---------------------------------------------------------------------------- */
1602  
1603 0 void ChdirToSource (/*i/o*/ register req * r,
1604 /*in*/ char * sInputfile)
1605  
1606 {
1607 0 ▶ if ((r -> Component.Config.bOptions & optDisableChdir) == 0 &&
Branch: 2 branches
BranchTrueFalseTotal
if ((r -> Component.Config.bOptions & optDisableChdir) == 0 && 0 0 0
if ((r -> Component.Config.bOptions & optDisableChdir) == 0 && 0 0 0
1608 0 ▶ sInputfile != NULL && *sInputfile != '\0' &&
Branch: 1 branch
BranchTrueFalseTotal
sInputfile != NULL && *sInputfile != '\0' && 0 0 0
1609 0 ▶ !r -> Component.Param.pInput && !r -> Component.sResetDir[0])
Branch: 2 branches
BranchTrueFalseTotal
!r -> Component.Param.pInput && !r -> Component.sResetDir[0]) 0 0 0
!r -> Component.Param.pInput && !r -> Component.sResetDir[0]) 0 0 0
1610 0 {
1611 char dir[PATH_MAX];
1612 #ifdef WIN32
1613 char drive[_MAX_DRIVE];
1614 char fname[_MAX_FNAME];
1615 char ext[_MAX_EXT];
1616 char * c = sInputfile ;
1617  
1618 while (*c)
1619 { /* convert / to \ */
1620 if (*c == '/')
1621 *c = '\\' ;
1622 c++ ;
1623 }
1624  
1625 r -> nResetDrive = _getdrive () ;
1626 getcwd (r -> Component.sResetDir, sizeof (r -> Component.sResetDir) - 1) ;
1627  
1628 _splitpath(sInputfile, drive, dir, fname, ext );
1629 _chdrive (drive[0] - 'A' + 1) ;
1630 #else
1631 0 Dirname (sInputfile, dir, sizeof (dir) - 1) ;
1632 0 getcwd (r -> Component.sResetDir, sizeof (r -> Component.sResetDir) - 1) ;
1633 #endif
1634 0 ▶ if (dir[0])
Branch: 1 branch
BranchTrueFalseTotal
if (dir[0]) 0 0 0
1635 {
1636 0 ▶ if (chdir (dir) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (chdir (dir) < 0) 0 0 0
1637 {
1638 0 strncpy (r -> errdat1, dir, sizeof(r -> errdat1) - 1) ;
1639 0 LogError (r, rcChdirError) ;
1640 }
1641 else
1642 {
1643 0 ▶ if (!(dir[0] == '/'
Branch: 1 branch
BranchTrueFalseTotal
if (!(dir[0] == '/' 0 0 0
1644 #ifdef WIN32
1645 ||
1646 dir[0] == '\\' ||
1647 (isalpha(dir[0]) && dir[1] == ':' &&
1648 (dir[2] == '\\' || dir[2] == '/'))
1649 #endif
1650 ))
1651 {
1652 0 strcpy (r->Component.sCWD,r -> Component.sResetDir) ;
1653 0 strcat (r->Component.sCWD,"/") ;
1654 0 strcat (r->Component.sCWD,dir) ;
1655 }
1656 else
1657 0 strcpy (r->Component.sCWD,dir) ;
1658 }
1659 }
1660 else
1661 0 r -> Component.Config.bOptions |= optDisableChdir ;
1662 }
1663 else
1664 0 r -> Component.Config.bOptions |= optDisableChdir ;
1665 0 }
1666
1667 /* ---------------------------------------------------------------------------- */
1668 /* */
1669 /* Path search */
1670 /* */
1671 /* ---------------------------------------------------------------------------- */
1672  
1673 0 char * embperl_PathSearch (/*i/o*/ register req * r,
1674 /*in*/ tMemPool * pPool,
1675 /*in*/ const char * sFilename,
1676 /*in*/ int nPathNdx)
1677  
1678 {
1679 epTHX_
1680 0 AV *pPathAV = r -> Config.pPathAV ;
1681 0 int skip = 0 ;
1682 int i ;
1683 struct stat st ;
1684 0 char * absfn = NULL ;
1685 char * fn ;
1686 STRLEN l ;
1687  
1688 0 ▶ if (r -> Config.bDebug & dbgObjectSearch)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Config.bDebug & dbgObjectSearch) 0 0 0
1689 0 lprintf (r -> pApp, "[%d]Search for %s\n", r -> pThread -> nPid, sFilename) ;
1690  
1691 0 ▶ if (isAbsPath(sFilename) || !pPathAV || AvFILL (pPathAV) < r -> Component.nPathNdx)
Branch: 3 branches
BranchTrueFalseTotal
if (isAbsPath(sFilename) || !pPathAV || AvFILL (pPathAV) < r -> Component.nPathNdx) 0 0 0
if (isAbsPath(sFilename) || !pPathAV || AvFILL (pPathAV) < r -> Component.nPathNdx) 0 0 0
if (isAbsPath(sFilename) || !pPathAV || AvFILL (pPathAV) < r -> Component.nPathNdx) 0 0 0
1692 {
1693 0 absfn = embperl_File2Abs (r, pPool, sFilename) ;
1694 0 ▶ if (r -> Config.bDebug & dbgObjectSearch)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Config.bDebug & dbgObjectSearch) 0 0 0
1695 0 lprintf (r -> pApp, "[%d]Search: nothing to search return %s\n", r -> pThread -> nPid, absfn) ;
1696 0 return absfn ;
1697 }
1698  
1699 0 ▶ while (sFilename[0] == '.' && sFilename[1] == '.' && (sFilename[2] == '/' || sFilename[2] == '\\'))
Branch: 4 branches
BranchTrueFalseTotal
while (sFilename[0] == '.' && sFilename[1] == '.' && (sFilename[2] == '/' || sFilename[2] == '\\')) 0 0 0
while (sFilename[0] == '.' && sFilename[1] == '.' && (sFilename[2] == '/' || sFilename[2] == '\\')) 0 0 0
while (sFilename[0] == '.' && sFilename[1] == '.' && (sFilename[2] == '/' || sFilename[2] == '\\')) 0 0 0
while (sFilename[0] == '.' && sFilename[1] == '.' && (sFilename[2] == '/' || sFilename[2] == '\\')) 0 0 0
1700 {
1701 0 skip++ ;
1702 0 sFilename += 3 ;
1703 }
1704 0 ▶ if (skip)
Branch: 1 branch
BranchTrueFalseTotal
if (skip) 0 0 0
1705 0 ▶ skip += nPathNdx >= 0?nPathNdx:r -> Component.pPrev?r -> Component.pPrev -> nPathNdx:0 ;
Branch: 2 branches
BranchTrueFalseTotal
skip += nPathNdx >= 0?nPathNdx:r -> Component.pPrev?r -> Component.pPrev -> nPathNdx:0 ; 0 0 0
skip += nPathNdx >= 0?nPathNdx:r -> Component.pPrev?r -> Component.pPrev -> nPathNdx:0 ; 0 0 0
1706  
1707 0 ▶ if (skip == 0 && sFilename[0] == '.' && (sFilename[1] == '/' || sFilename[1] == '\\'))
Branch: 4 branches
BranchTrueFalseTotal
if (skip == 0 && sFilename[0] == '.' && (sFilename[1] == '/' || sFilename[1] == '\\')) 0 0 0
if (skip == 0 && sFilename[0] == '.' && (sFilename[1] == '/' || sFilename[1] == '\\')) 0 0 0
if (skip == 0 && sFilename[0] == '.' && (sFilename[1] == '/' || sFilename[1] == '\\')) 0 0 0
if (skip == 0 && sFilename[0] == '.' && (sFilename[1] == '/' || sFilename[1] == '\\')) 0 0 0
1708 {
1709 0 absfn = embperl_File2Abs (r, pPool, sFilename) ;
1710 0 ▶ if (stat (absfn, &st) == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (stat (absfn, &st) == 0) 0 0 0
1711 {
1712 0 ▶ if (r -> Config.bDebug & dbgObjectSearch)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Config.bDebug & dbgObjectSearch) 0 0 0
1713 0 lprintf (r -> pApp, "[%d]Search: starts with ./ return %s\n", r -> pThread -> nPid, absfn) ;
1714 0 return absfn ;
1715 }
1716 0 ▶ if (r -> Config.bDebug & dbgObjectSearch)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Config.bDebug & dbgObjectSearch) 0 0 0
1717 0 lprintf (r -> pApp, "[%d]Search: starts with ./, but not found\n", r -> pThread -> nPid) ;
1718 0 return NULL ;
1719 }
1720  
1721  
1722 0 ▶ for (i = skip ; i <= AvFILL (pPathAV); i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = skip ; i <= AvFILL (pPathAV); i++) 0 0 0
1723 {
1724 0 fn = ep_pstrcat(r -> pPool, SvPV(*av_fetch (pPathAV, i, 0), l), PATH_SEPARATOR_STR, sFilename, NULL) ;
1725 0 ▶ if (r -> Config.bDebug & dbgObjectSearch)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Config.bDebug & dbgObjectSearch) 0 0 0
1726 0 lprintf (r -> pApp, "[%d]Search: #%d test dir=%s, fn=%s (skip=%d)\n", r -> pThread -> nPid,
1727 0 i, SvPV(*av_fetch (pPathAV, i, 0), l), fn, skip) ;
1728 0 ▶ if (stat (fn, &st) == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (stat (fn, &st) == 0) 0 0 0
1729 {
1730 0 r -> Component.nPathNdx = i ;
1731 0 absfn = embperl_File2Abs (r, pPool, fn) ;
1732 0 ▶ if (r -> Config.bDebug & dbgObjectSearch)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Config.bDebug & dbgObjectSearch) 0 0 0
1733 0 lprintf (r -> pApp, "[%d]Search: found %s\n", r -> pThread -> nPid, absfn) ;
1734 0 return absfn ;
1735 }
1736 }
1737  
1738 0 ▶ if (r -> Config.bDebug & dbgObjectSearch)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Config.bDebug & dbgObjectSearch) 0 0 0
1739 0 lprintf (r -> pApp, "[%d]Search: not found %s\n", r -> pThread -> nPid) ;
1740  
1741 0 return NULL ;
1742 }
1743  
1744 /* ---------------------------------------------------------------------------- */
1745 /* */
1746 /* Path str */
1747 /* */
1748 /* ---------------------------------------------------------------------------- */
1749  
1750 0 char * embperl_PathStr (/*i/o*/ register req * r,
1751 /*in*/ const char * sFilename)
1752  
1753 {
1754 epTHX_
1755 0 AV *pPathAV = r -> Config.pPathAV ;
1756 0 ▶ int skip = r -> Component.pPrev?r -> Component.pPrev -> nPathNdx:0 ;
Branch: 1 branch
BranchTrueFalseTotal
int skip = r -> Component.pPrev?r -> Component.pPrev -> nPathNdx:0 ; 0 0 0
1757 int i ;
1758 char * fn ;
1759 0 char * pPath = "" ;
1760 STRLEN l ;
1761  
1762 0 ▶ if (isAbsPath(sFilename) || !pPathAV || AvFILL (pPathAV) < r -> Component.nPathNdx)
Branch: 3 branches
BranchTrueFalseTotal
if (isAbsPath(sFilename) || !pPathAV || AvFILL (pPathAV) < r -> Component.nPathNdx) 0 0 0
if (isAbsPath(sFilename) || !pPathAV || AvFILL (pPathAV) < r -> Component.nPathNdx) 0 0 0
if (isAbsPath(sFilename) || !pPathAV || AvFILL (pPathAV) < r -> Component.nPathNdx) 0 0 0
1763 0 return embperl_File2Abs (r, r -> pPool, sFilename) ;
1764  
1765 0 ▶ while (sFilename[0] == '.' && sFilename[1] == '.' && (sFilename[2] == '/' || sFilename[2] == '\\'))
Branch: 4 branches
BranchTrueFalseTotal
while (sFilename[0] == '.' && sFilename[1] == '.' && (sFilename[2] == '/' || sFilename[2] == '\\')) 0 0 0
while (sFilename[0] == '.' && sFilename[1] == '.' && (sFilename[2] == '/' || sFilename[2] == '\\')) 0 0 0
while (sFilename[0] == '.' && sFilename[1] == '.' && (sFilename[2] == '/' || sFilename[2] == '\\')) 0 0 0
while (sFilename[0] == '.' && sFilename[1] == '.' && (sFilename[2] == '/' || sFilename[2] == '\\')) 0 0 0
1766 {
1767 0 skip++ ;
1768 0 sFilename += 3 ;
1769 }
1770
1771 0 ▶ for (i = skip ; i <= AvFILL (pPathAV); i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = skip ; i <= AvFILL (pPathAV); i++) 0 0 0
1772 {
1773 0 fn = ep_pstrcat(r -> pPool, SvPV(*av_fetch (pPathAV, i, 0), l), PATH_SEPARATOR_STR, sFilename, NULL) ;
1774 0 pPath = ep_pstrcat(r -> pPool, pPath, fn, ";", NULL) ;
1775 }
1776  
1777 0 return pPath ;
1778 }
1779  
1780  
1781 /* ---------------------------------------------------------------------------- */
1782 /* */
1783 /* Split string into Array */
1784 /* */
1785 /* ---------------------------------------------------------------------------- */
1786  
1787  
1788 0 AV * embperl_String2AV (/*in*/ tApp * a,
1789 /*in*/ const char * sData,
1790 /*in*/ const char * sSeparator)
1791
1792 {
1793 AV * pAV ;
1794 #ifdef PERL_IMPLICIT_CONTEXT
1795 pTHX ;
1796
1797 if (a)
1798 aTHX = a -> pPerlTHX ;
1799 else
1800 aTHX = PERL_GET_THX ;
1801 #endif
1802  
1803 0 pAV = newAV () ;
1804  
1805  
1806 0 ▶ while (*sData)
Branch: 1 branch
BranchTrueFalseTotal
while (*sData) 0 0 0
1807 {
1808 0 int n = strcspn (sData, sSeparator) ;
1809 0 ▶ if (n > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (n > 0) 0 0 0
1810 0 av_push (pAV, newSVpv((char *)sData, n)) ;
1811 0 sData += n ;
1812 0 ▶ if (*sData)
Branch: 1 branch
BranchTrueFalseTotal
if (*sData) 0 0 0
1813 0 sData++ ;
1814 }
1815  
1816 0 return pAV ;
1817 }
1818  
1819  
1820  
1821 /* ---------------------------------------------------------------------------- */
1822 /* */
1823 /* Split string into hash */
1824 /* */
1825 /* ---------------------------------------------------------------------------- */
1826  
1827  
1828 0 HV * embperl_String2HV (/*in*/ tApp * a,
1829 /*in*/ const char * sData,
1830 /*in*/ char cSeparator,
1831 /*in*/ HV * pHV)
1832
1833 {
1834 char * p ;
1835 char q ;
1836 char * pVal ;
1837 char * pKeyEnd ;
1838 #ifdef PERL_IMPLICIT_CONTEXT
1839 pTHX ;
1840
1841 if (a)
1842 aTHX = a -> pPerlTHX ;
1843 else
1844 aTHX = PERL_GET_THX ;
1845 #endif
1846  
1847 0 ▶ if (!pHV)
Branch: 1 branch
BranchTrueFalseTotal
if (!pHV) 0 0 0
1848 0 pHV = newHV () ;
1849  
1850  
1851 0 ▶ while (*sData)
Branch: 1 branch
BranchTrueFalseTotal
while (*sData) 0 0 0
1852 {
1853 0 ▶ while (isspace(*sData))
Branch: 1 branch
BranchTrueFalseTotal
while (isspace(*sData)) 0 0 0
1854 0 sData++ ;
1855
1856 0 ▶ if (*sData == '\'' || *sData == '"')
Branch: 2 branches
BranchTrueFalseTotal
if (*sData == '\'' || *sData == '"') 0 0 0
if (*sData == '\'' || *sData == '"') 0 0 0
1857 0 q = *sData++ ;
1858 else
1859 0 q = cSeparator ;
1860  
1861 0 p = strchr (sData, '=') ;
1862 0 ▶ if (!p)
Branch: 1 branch
BranchTrueFalseTotal
if (!p) 0 0 0
1863 0 break ;
1864 0 pKeyEnd = p ;
1865 0 ▶ while (pKeyEnd > sData && isspace(pKeyEnd[-1]))
Branch: 2 branches
BranchTrueFalseTotal
while (pKeyEnd > sData && isspace(pKeyEnd[-1])) 0 0 0
while (pKeyEnd > sData && isspace(pKeyEnd[-1])) 0 0 0
1866 0 pKeyEnd-- ;
1867
1868 0 p++ ;
1869 0 ▶ while (isspace(*p))
Branch: 1 branch
BranchTrueFalseTotal
while (isspace(*p)) 0 0 0
1870 0 p++ ;
1871  
1872 0 ▶ if (*p == '\'' || *p == '"')
Branch: 2 branches
BranchTrueFalseTotal
if (*p == '\'' || *p == '"') 0 0 0
if (*p == '\'' || *p == '"') 0 0 0
1873 0 q = *p++ ;
1874
1875 0 pVal = p ;
1876 0 ▶ while (*p && *p != q)
Branch: 2 branches
BranchTrueFalseTotal
while (*p && *p != q) 0 0 0
while (*p && *p != q) 0 0 0
1877 0 p++ ;
1878  
1879 0 hv_store(pHV, sData, pKeyEnd - sData, newSVpv(pVal, p - pVal), 0) ;
1880 0 sData = p ;
1881 0 ▶ if (*sData)
Branch: 1 branch
BranchTrueFalseTotal
if (*sData) 0 0 0
1882 0 sData++ ;
1883 }
1884  
1885 0 return pHV ;
1886 }
1887  
1888  
1889  
1890  
1891 /* ---------------------------------------------------------------------------- */
1892 /* */
1893 /* Seach message for id */
1894 /* */
1895 /* ---------------------------------------------------------------------------- */
1896  
1897 0 static char * embperl_GetText1 (/*in*/ tReq * r,
1898 /*in*/ const char * sMsgId,
1899 /*in*/ AV * arr)
1900
1901 {
1902 epTHX_
1903 IV len ;
1904 IV i ;
1905 SV ** ppSV ;
1906 STRLEN l ;
1907  
1908 0 ▶ if (!arr || SvTYPE(arr) != SVt_PVAV)
Branch: 2 branches
BranchTrueFalseTotal
if (!arr || SvTYPE(arr) != SVt_PVAV) 0 0 0
if (!arr || SvTYPE(arr) != SVt_PVAV) 0 0 0
1909 0 return NULL ;
1910  
1911 0 len = av_len(arr);
1912 0 ▶ for (i = len; i >= 0; i--)
Branch: 1 branch
BranchTrueFalseTotal
for (i = len; i >= 0; i--) 0 0 0
1913 {
1914 0 SV * * pHVREF = av_fetch(arr, i, 0);
1915 0 ▶ if (pHVREF && *pHVREF && SvROK (*pHVREF))
Branch: 3 branches
BranchTrueFalseTotal
if (pHVREF && *pHVREF && SvROK (*pHVREF)) 0 0 0
if (pHVREF && *pHVREF && SvROK (*pHVREF)) 0 0 0
if (pHVREF && *pHVREF && SvROK (*pHVREF)) 0 0 0
1916 {
1917 0 HV * pHV = (HV *)SvRV (*pHVREF) ;
1918 0 ▶ if (SvTYPE (pHV) == SVt_PVCV)
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE (pHV) == SVt_PVCV) 0 0 0
1919 {
1920 SV * pSVErr ;
1921 SV * pRet ;
1922 int num ;
1923
1924 0 dSP ;
1925 0 ▶ PUSHMARK(sp) ;
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(sp) ; 0 0 0
1926 0 ▶ XPUSHs (sv_2mortal(newSVpv(sMsgId,0))) ;
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs (sv_2mortal(newSVpv(sMsgId,0))) ; 0 0 0
1927 0 PUTBACK ;
1928 0 num = perl_call_sv ((SV *)pHV, G_EVAL) ;
1929 0 ▶ pSVErr = ERRSV ;
Branch: 1 branch
BranchTrueFalseTotal
pSVErr = ERRSV ; 0 0 0
1930 0 ▶ if (SvTRUE (pSVErr))
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE (pSVErr)) 0 0 0
1931 {
1932 STRLEN l ;
1933 0 char * p = SvPV (pSVErr, l) ;
1934 0 ▶ if (l > sizeof (r -> errdat1) - 1)
Branch: 1 branch
BranchTrueFalseTotal
if (l > sizeof (r -> errdat1) - 1) 0 0 0
1935 0 l = sizeof (r -> errdat1) - 1 ;
1936 0 strncpy (r -> errdat1, p, l) ;
1937 0 ▶ if (l > 0 && r -> errdat1[l-1] == '\n')
Branch: 2 branches
BranchTrueFalseTotal
if (l > 0 && r -> errdat1[l-1] == '\n') 0 0 0
if (l > 0 && r -> errdat1[l-1] == '\n') 0 0 0
1938 0 l-- ;
1939 0 r -> errdat1[l] = '\0' ;
1940
1941 0 LogError (r, rcEvalErr) ;
1942  
1943 0 sv_setpv(pSVErr,"");
1944 0 return NULL ;
1945 }
1946 else
1947 {
1948 0 SPAGAIN ;
1949 0 ▶ if (num > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (num > 0) 0 0 0
1950 0 pRet = POPs ;
1951 0 PUTBACK ;
1952 0 ▶ return num && pRet && SvOK(pRet)?SvPV (pRet, l):NULL ;
Branch: 3 branches
BranchTrueFalseTotal
return num && pRet && SvOK(pRet)?SvPV (pRet, l):NULL ; 0 0 0
return num && pRet && SvOK(pRet)?SvPV (pRet, l):NULL ; 0 0 0
return num && pRet && SvOK(pRet)?SvPV (pRet, l):NULL ; 0 0 0
1953 }
1954 }
1955  
1956 0 ▶ if (SvTYPE (pHV) != SVt_PVHV)
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE (pHV) != SVt_PVHV) 0 0 0
1957 0 continue ;
1958  
1959 0 ppSV = hv_fetch(pHV, (char *)sMsgId, strlen (sMsgId), 0) ;
1960 0 ▶ if (ppSV != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (ppSV != NULL) 0 0 0
1961 {
1962 0 ▶ return SvOK(*ppSV)?SvPV (*ppSV, l):NULL ;
Branch: 1 branch
BranchTrueFalseTotal
return SvOK(*ppSV)?SvPV (*ppSV, l):NULL ; 0 0 0
1963 }
1964 }
1965 }
1966 0 return NULL ;
1967 }
1968  
1969  
1970 0 const char * embperl_GetText (/*in*/ tReq * r,
1971 /*in*/ const char * sMsgId)
1972
1973 {
1974 epTHX_
1975 char * pMsg ;
1976  
1977 0 ▶ if ((pMsg = embperl_GetText1(r, sMsgId, r -> pMessages)))
Branch: 1 branch
BranchTrueFalseTotal
if ((pMsg = embperl_GetText1(r, sMsgId, r -> pMessages))) 0 0 0
1978 0 return pMsg ;
1979
1980 0 ▶ if ((pMsg = embperl_GetText1(r, sMsgId, r -> pDefaultMessages)))
Branch: 1 branch
BranchTrueFalseTotal
if ((pMsg = embperl_GetText1(r, sMsgId, r -> pDefaultMessages))) 0 0 0
1981 0 return pMsg ;
1982  
1983 0 return sMsgId ;
1984 }
1985  
1986  
1987 /* ------------------------------------------------------------------------ */
1988 /* */
1989 /* embperl_OptionListSearch */
1990 /* */
1991 /*!
1992 * \_en
1993 * Lookup a number of options from a list and return numeric equivalent
1994 * @param pList Option/Valus pairs
1995 * @param bMult Allow multiple options
1996 * @param sCmd Configurationdirective (for errormessage)
1997 * @param sOptions Option string
1998 * @param pnValue Returns option value
1999 * @return error code
2000 *
2001 * \endif
2002 *
2003 * \_de
2004 * Ermittelt aus einer Liste von Optionen das numerische Equivalent
2005 * @param pList Option/Wertepaare
2006 * @param bMult Mehrfachoptionen erlaubt
2007 * @param sCmd Konfigurationsdirektive (für Fehlermeldung)
2008 * @param sOptions Optionszeichenkette
2009 * @param pnValue Liefert den Optionswert zurück
2010 * @return Fehlercode
2011 *
2012 * \endif
2013 *
2014 * ------------------------------------------------------------------------ */
2015  
2016  
2017 0 int embperl_OptionListSearch (/*in*/ tOptionEntry * pList,
2018 /*in*/ bool bMult,
2019 /*in*/ const char * sCmd,
2020 /*in*/ const char * sOptions,
2021 /*in*/ int * pnValue)
2022 {
2023 char * sKeyword ;
2024 0 char * sOpts = strdup (sOptions) ;
2025 dTHX ;
2026  
2027 0 *pnValue = 0 ;
2028
2029 0 sKeyword = strtok (sOpts, ", \t\n") ;
2030 0 ▶ while (sKeyword)
Branch: 1 branch
BranchTrueFalseTotal
while (sKeyword) 0 0 0
2031 {
2032 0 tOptionEntry * pEntry = pList ;
2033 0 bool found = 0 ;
2034  
2035 0 ▶ while (pEntry -> sOption)
Branch: 1 branch
BranchTrueFalseTotal
while (pEntry -> sOption) 0 0 0
2036 {
2037 0 ▶ if (stricmp (sKeyword, pEntry -> sOption) == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (stricmp (sKeyword, pEntry -> sOption) == 0) 0 0 0
2038 {
2039 0 *pnValue |= pEntry -> nValue ;
2040 0 ▶ if (!bMult)
Branch: 1 branch
BranchTrueFalseTotal
if (!bMult) 0 0 0
2041 {
2042 0 ▶ if (sOpts)
Branch: 1 branch
BranchTrueFalseTotal
if (sOpts) 0 0 0
2043 0 free (sOpts) ;
2044  
2045 0 return ok ;
2046 }
2047 0 found = 1 ;
2048 }
2049 }
2050 0 ▶ if (!found)
Branch: 1 branch
BranchTrueFalseTotal
if (!found) 0 0 0
2051 {
2052 0 LogErrorParam (NULL, rcUnknownOption, sKeyword, sCmd) ;
2053 0 ▶ if (sOpts)
Branch: 1 branch
BranchTrueFalseTotal
if (sOpts) 0 0 0
2054 0 free (sOpts) ;
2055  
2056 0 return rcUnknownOption ;
2057 }
2058  
2059
2060 }
2061  
2062
2063 0 ▶ if (sOpts)
Branch: 1 branch
BranchTrueFalseTotal
if (sOpts) 0 0 0
2064 0 free (sOpts) ;
2065  
2066 0 return ok ;
2067 }
2068  
2069 /* ------------------------------------------------------------------------ */
2070 /* */
2071 /* embperl_CalcExpires */
2072 /* */
2073 /*!
2074 * \_en
2075 * Convert Expires time to HTTP format
2076 * @param sTime Time to convert
2077 * @param sResult Buffer for result
2078 * @param bHTTP http format
2079 * @return error code
2080 *
2081 * \endif
2082 *
2083 * \_de
2084 * Kovertiert Zeitangabe in HTTP Format
2085 * @param sTime Zeit die konvertioert werden soll
2086 * @param sResult Buffer für resultat
2087 * @param bHTTP http format
2088 * @return Fehlercode
2089 *
2090 * \endif
2091 *
2092 * ------------------------------------------------------------------------ */
2093  
2094 /* parts from libareq */
2095  
2096 #define Mult_s 1
2097 #define Mult_m 60
2098 #define Mult_h (60*60)
2099 #define Mult_d (60*60*24)
2100 #define Mult_M (60*60*24*30)
2101 #define Mult_y (60*60*24*365)
2102  
2103 0 static int expire_mult(char s)
2104 {
2105 0 switch (s) {
2106 0 case 's':
2107 0 return Mult_s;
2108 0 case 'm':
2109 0 return Mult_m;
2110 0 case 'h':
2111 0 return Mult_h;
2112 0 case 'd':
2113 0 return Mult_d;
2114 0 case 'M':
2115 0 return Mult_M;
2116 0 case 'y':
2117 0 return Mult_y;
2118 0 default:
2119 0 return 1;
2120 };
2121 }
2122  
2123 0 static time_t expire_calc(const char *time_str)
2124 {
2125 0 int is_neg = 0, offset = 0;
2126 char buf[256];
2127 0 int ix = 0;
2128  
2129 0 ▶ if (*time_str == '-') {
Branch: 1 branch
BranchTrueFalseTotal
if (*time_str == '-') { 0 0 0
2130 0 is_neg = 1;
2131 0 ++time_str;
2132 }
2133 0 ▶ else if (*time_str == '+') {
Branch: 1 branch
BranchTrueFalseTotal
else if (*time_str == '+') { 0 0 0
2134 0 ++time_str;
2135 }
2136 0 ▶ else if (!stricmp(time_str, "now")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (!stricmp(time_str, "now")) { 0 0 0
2137 /*ok*/
2138 }
2139 else {
2140 0 return 0;
2141 }
2142  
2143 0 ▶ while (*time_str && isdigit(*time_str)) {
Branch: 2 branches
BranchTrueFalseTotal
while (*time_str && isdigit(*time_str)) { 0 0 0
while (*time_str && isdigit(*time_str)) { 0 0 0
2144 0 buf[ix++] = *time_str++;
2145 }
2146 0 buf[ix] = '\0';
2147 0 offset = atoi(buf);
2148  
2149 0 return time(NULL) +
2150 0 ▶ (expire_mult(*time_str) * (is_neg ? (0 - offset) : offset));
Branch: 1 branch
BranchTrueFalseTotal
(expire_mult(*time_str) * (is_neg ? (0 - offset) : offset)); 0 0 0
2151 }
2152  
2153 static const char ep_month_snames[12][4] =
2154 {
2155 "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
2156 };
2157 static const char ep_day_snames[7][4] =
2158 {
2159 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
2160 };
2161
2162  
2163 0 const char * embperl_CalcExpires(const char *sTime, char * sResult, int bHTTP)
2164 {
2165 time_t when;
2166 #ifdef WIN32
2167 struct tm *tms;
2168 #else
2169 struct tm tms;
2170 #endif
2171 0 ▶ int sep = bHTTP ? ' ' : '-';
Branch: 1 branch
BranchTrueFalseTotal
int sep = bHTTP ? ' ' : '-'; 0 0 0
2172 dTHX ;
2173  
2174 0 ▶ if (!sTime) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sTime) { 0 0 0
2175 0 return NULL;
2176 }
2177  
2178 0 when = expire_calc(sTime);
2179  
2180 0 ▶ if (!when) {
Branch: 1 branch
BranchTrueFalseTotal
if (!when) { 0 0 0
2181 0 strcpy( sResult, sTime );
2182 0 return sResult ;
2183 }
2184  
2185 #ifdef WIN32
2186 tms = gmtime(&when);
2187 sprintf(sResult, "%s, %.2d%c%s%c%.2d %.2d:%.2d:%.2d GMT",
2188 ep_day_snames[tms->tm_wday],
2189 tms->tm_mday, sep, ep_month_snames[tms->tm_mon], sep,
2190 tms->tm_year + 1900,
2191 tms->tm_hour, tms->tm_min, tms->tm_sec);
2192 #else
2193 0 gmtime_r(&when, &tms);
2194 0 sprintf(sResult,
2195 "%s, %.2d%c%s%c%.2d %.2d:%.2d:%.2d GMT",
2196 0 ep_day_snames[tms.tm_wday],
2197 0 tms.tm_mday, sep, ep_month_snames[tms.tm_mon], sep,
2198 0 tms.tm_year + 1900,
2199 tms.tm_hour, tms.tm_min, tms.tm_sec);
2200 #endif
2201 0 return sResult ;
2202 }
2203  
2204  
2205  
2206 #ifdef WIN32
2207 extern long _timezone;
2208 #else
2209 #if !defined(__BSD_VISIBLE) && !defined(__DARWIN_UNIX03)
2210 extern long timezone;
2211 #endif
2212 #endif
2213  
2214  
2215 0 char * embperl_GetDateTime (char * sResult)
2216 {
2217 0 time_t when = time(NULL);
2218 0 int sep = ' ' ;
2219 int tz ;
2220 #ifdef WIN32
2221 struct tm *tms;
2222 #else
2223 struct tm tms;
2224 #endif
2225 dTHX ;
2226  
2227 #ifdef WIN32
2228 tms = localtime(&when);
2229 sprintf(sResult, "%s, %.2d%c%s%c%.2d %.2d:%.2d:%.2d %s%04d",
2230 ep_day_snames[tms->tm_wday],
2231 tms->tm_mday, sep, ep_month_snames[tms->tm_mon], sep,
2232 tms->tm_year + 1900,
2233 tms->tm_hour, tms->tm_min, tms->tm_sec, tz > 0?"+":"", tz);
2234 #else
2235 0 localtime_r(&when, &tms);
2236 #if !defined(__BSD_VISIBLE) && !defined(__DARWIN_UNIX03)
2237 0 ▶ tz = -timezone / 36 + (tms.tm_isdst?100:0) ;
Branch: 1 branch
BranchTrueFalseTotal
tz = -timezone / 36 + (tms.tm_isdst?100:0) ; 0 0 0
2238 #else
2239 tz = -tms.tm_gmtoff / 36 + (tms.tm_isdst?100:0) ;
2240 #endif
2241 0 ▶ sprintf(sResult,
Branch: 1 branch
BranchTrueFalseTotal
sprintf(sResult, 0 0 0
2242 "%s, %.2d%c%s%c%.2d %.2d:%.2d:%.2d %s%04d",
2243 0 ep_day_snames[tms.tm_wday],
2244 0 tms.tm_mday, sep, ep_month_snames[tms.tm_mon], sep,
2245 0 tms.tm_year + 1900,
2246 tms.tm_hour, tms.tm_min, tms.tm_sec, tz > 0?"+":"", tz);
2247 #endif
2248 0 return sResult ;
2249 }
2250  
2251  
2252  
2253 /* ---------------------------------------------------------------------------- */
2254 /* */
2255 /* Memory debugging functions */
2256 /* */
2257 /* ---------------------------------------------------------------------------- */
2258  
2259  
2260 #ifdef DMALLOC
2261  
2262 static int RemoveDMallocMagic (pTHX_ SV * pSV, MAGIC * mg)
2263  
2264 {
2265 char * s = *((char * *)(mg -> mg_ptr)) ;
2266 _free_leap(__FILE__, __LINE__, s) ;
2267 return ok ;
2268 }
2269  
2270 static MGVTBL DMalloc_mvtTab = { NULL, NULL, NULL, NULL, RemoveDMallocMagic } ;
2271  
2272 #define MGTTYPE '!'
2273  
2274 SV * AddDMallocMagic (/*in*/ SV * pSV,
2275 /*in*/ char * sText,
2276 /*in*/ char * sFile,
2277 /*in*/ int nLine)
2278  
2279 {
2280 dTHX ;
2281  
2282 if (pSV && (!SvMAGICAL(pSV) || !mg_find (pSV, MGTTYPE)))
2283 {
2284 char * s = _strdup_leap(sFile, nLine, sText) ;
2285 struct magic * pMagic ;
2286
2287 if ((!SvMAGICAL(pSV) || !(pMagic = mg_find (pSV, MGTTYPE))))
2288 {
2289 sv_magicext ((SV *)pSV, NULL, MGTTYPE, &DMalloc_mvtTab, (char *)&s, sizeof (s)) ;
2290 /* sv_magic ((SV *)pSV, NULL, MGTTYPE, (char *)&s, sizeof (s)) ; */
2291 pMagic = mg_find (pSV, MGTTYPE) ;
2292 }
2293  
2294 if (pMagic)
2295 {
2296 /* pMagic -> mg_virtual = &DMalloc_mvtTab ; */
2297 }
2298 else
2299 {
2300 LogError (CurrReq, rcMagicError) ;
2301 }
2302 }
2303  
2304 return pSV ;
2305 }
2306  
2307  
2308 #endif
2309  
« epprovider.c ↑ Summary