epcgiinit.c

filter: Statementstmt 0.0% 0 / 60 Branchbran 0.0% 0 / 42 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 102 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« epcfg.h ↑ Summary epcmd2.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 "epdefault.c"
20  
21  
22 #undef EPCFG
23 #define EPCFG_INT(STRUCT,TYPE,NAME,CFGNAME) \
24 { \
25 char * p ; \
26 tainted = 0 ; \
27 p = GetHashValueStr (aTHX_ pThread -> pEnvHash, REDIR"EMBPERL_"#CFGNAME, NULL) ; \
28 if (p) \
29 pConfig -> NAME = (TYPE)strtol (p, NULL, 0) ; \
30 tainted = 0 ; \
31 }
32  
33 #define EPCFG_INTOPT(STRUCT,TYPE,NAME,CFGNAME) \
34 { \
35 char * p ; \
36 tainted = 0 ; \
37 p = GetHashValueStr (aTHX_ pThread -> pEnvHash, REDIR"EMBPERL_"#CFGNAME, NULL) ; \
38 if (p) \
39 { \
40 if (isdigit(*p)) \
41 pConfig -> NAME = (TYPE)strtol (p, NULL, 0) ; \
42 else \
43 { \
44 int val ; \
45 int rc ; \
46 if ((rc = embperl_OptionListSearch(Options##CFGNAME,1,#CFGNAME,p,&val))) \
47 return rc ; \
48 pConfig -> NAME = (TYPE)val ; \
49 } \
50 } \
51 tainted = 0 ; \
52 }
53  
54 #undef EPCFG_BOOL
55 #define EPCFG_BOOL(STRUCT,TYPE,NAME,CFGNAME) \
56 tainted = 0 ; \
57 pConfig -> NAME = (char)GetHashValueInt (aTHX_ pThread -> pEnvHash, REDIR"EMBPERL_"#CFGNAME, pConfig -> NAME) ; \
58 tainted = 0 ;
59  
60 #undef EPCFG_STR
61 #define EPCFG_STR(STRUCT,TYPE,NAME,CFGNAME) \
62 tainted = 0 ; \
63 pConfig -> NAME = GetHashValueStrDup (aTHX_ pPool, pThread -> pEnvHash, REDIR"EMBPERL_"#CFGNAME, pConfig -> NAME) ; \
64 tainted = 0 ;
65  
66 #undef EPCFG_EXPIRES
67 #define EPCFG_EXPIRES(STRUCT,TYPE,NAME,CFGNAME) \
68 tainted = 0 ; \
69 { \
70 char buf [256] = "" ; \
71 char * s = GetHashValueStr (aTHX_ pThread -> pEnvHash, REDIR"EMBPERL_"#CFGNAME, NULL) ; \
72 if (s) \
73 { \
74 if (!embperl_CalcExpires (s, buf, 0)) \
75 LogErrorParam (NULL, rcTimeFormatErr, "EMBPERL_"#CFGNAME, s) ; \
76 else \
77 pConfig -> NAME = ep_pstrdup (pPool, s) ; \
78 } \
79 } \
80 tainted = 0 ;
81  
82 #undef EPCFG_CHAR
83 #define EPCFG_CHAR(STRUCT,TYPE,NAME,CFGNAME) \
84 { \
85 char buf[2] ; \
86 char *p ; \
87 buf[0] = pConfig -> NAME ; \
88 buf[1] = '\0' ; \
89 tainted = 0 ; \
90 p = GetHashValueStrDup (aTHX_ pPool, pThread -> pEnvHash, REDIR"EMBPERL_"#CFGNAME, buf) ; \
91 tainted = 0 ; \
92 pConfig -> NAME = *p ; \
93 }
94  
95 #undef EPCFG_SV
96 #define EPCFG_SV(STRUCT,TYPE,NAME,CFGNAME) \
97 { \
98 char * arg ; \
99 tainted = 0 ; \
100 arg = GetHashValueStr (aTHX_ pThread -> pEnvHash, REDIR"EMBPERL_"#CFGNAME, NULL) ; \
101 tainted = 0 ; \
102 if (arg) \
103 pConfig -> NAME = newSVpv (arg, 0) ; \
104 tainted = 0 ; \
105 }
106  
107 #undef EPCFG_AV
108 #define EPCFG_AV(STRUCT,TYPE,NAME,CFGNAME,SEPARATOR) \
109 { \
110 char * arg ; \
111 tainted = 0 ; \
112 arg = GetHashValueStr (aTHX_ pThread -> pEnvHash, REDIR"EMBPERL_"#CFGNAME, NULL) ; \
113 tainted = 0 ; \
114 if (arg) \
115 pConfig -> NAME = embperl_String2AV(pApp, arg, SEPARATOR) ;\
116 tainted = 0 ; \
117 }
118  
119 #undef EPCFG_HV
120 #define EPCFG_HV(STRUCT,TYPE,NAME,CFGNAME) \
121 { \
122 char * arg ; \
123 tainted = 0 ; \
124 arg = GetHashValueStr (aTHX_ pThread -> pEnvHash, REDIR"EMBPERL_"#CFGNAME, NULL) ; \
125 tainted = 0 ; \
126 if (arg) \
127 pConfig -> NAME = embperl_String2HV(pApp, arg, ' ', NULL) ;\
128 tainted = 0 ; \
129 }
130  
131 #undef EPCFG_CV
132 #define EPCFG_CV(STRUCT,TYPE,NAME,CFGNAME) \
133 { \
134 int rc ;\
135 char * arg ; \
136 tainted = 0 ; \
137 arg = GetHashValueStr (aTHX_ pThread -> pEnvHash, REDIR"EMBPERL_"#CFGNAME, NULL) ; \
138 tainted = 0 ; \
139 if (arg) \
140 if ((rc = EvalConfig (pApp, sv_2mortal(newSVpv(arg, 0)), 0, NULL, "Configuration: EMBPERL_"#CFGNAME, &pConfig -> NAME)) != ok) \
141 return rc ; \
142 tainted = 0 ; \
143 }
144  
145 #undef EPCFG_REGEX
146 #define EPCFG_REGEX(STRUCT,TYPE,NAME,CFGNAME) \
147 { \
148 int rc ;\
149 char * arg ; \
150 tainted = 0 ; \
151 arg = GetHashValueStr (aTHX_ pThread -> pEnvHash, REDIR"EMBPERL_"#CFGNAME, NULL) ; \
152 tainted = 0 ; \
153 if (arg) \
154 if ((rc = EvalRegEx (pApp, arg, "Configuration: EMBPERL_"#CFGNAME, &pConfig -> NAME)) != ok) \
155 return rc ; \
156 tainted = 0 ; \
157 }
158  
159  
160 0 char * embperl_GetCGIAppName (/*in*/ tThreadData * pThread)
161  
162  
163 {
164 #ifdef PERL_IMPLICIT_CONTEXT
165 pTHX = pThread -> pPerlTHX;
166 #endif
167 0 tainted = 0 ;
168 0 return GetHashValueStr (aTHX_ pThread -> pEnvHash, "EMBPERL_APPNAME", "Embperl") ;
169 }
170  
171  
172  
173 0 int embperl_GetCGIAppConfig (/*in*/ tThreadData * pThread,
174 /*in*/ tMemPool * pPool,
175 /*out*/ tAppConfig * pConfig,
176 /*in*/ bool bUseEnv,
177 /*in*/ bool bUseRedirectEnv,
178 /*in*/ bool bSetDefault)
179  
180  
181 {
182 eptTHX_
183 0 tApp * pApp = NULL ;
184 0 ▶ if (bSetDefault)
Branch: 1 branch
BranchTrueFalseTotal
if (bSetDefault) 0 0 0
185 0 embperl_DefaultAppConfig (pConfig) ;
186  
187 #define EPCFG_APP
188 #define REDIR ""
189 0 ▶ if (bUseEnv)
Branch: 1 branch
BranchTrueFalseTotal
if (bUseEnv) 0 0 0
190 {
191 #include "epcfg.h"
192 }
193 #undef REDIR
194 #define REDIR "REDIRECT_"
195 0 ▶ if (bUseRedirectEnv)
Branch: 1 branch
BranchTrueFalseTotal
if (bUseRedirectEnv) 0 0 0
196 {
197 #include "epcfg.h"
198 }
199 #undef EPCFG_APP
200 #undef REDIR
201  
202 0 return ok ;
203 }
204  
205  
206 0 int embperl_GetCGIReqConfig (/*in*/ tApp * pApp,
207 /*in*/ tMemPool * pPool,
208 /*out*/ tReqConfig * pConfig,
209 /*in*/ bool bUseEnv,
210 /*in*/ bool bUseRedirectEnv,
211 /*in*/ bool bSetDefault)
212  
213  
214 {
215 0 tThreadData * pThread = pApp -> pThread ;
216 eptTHX_
217  
218 0 ▶ if (bSetDefault)
Branch: 1 branch
BranchTrueFalseTotal
if (bSetDefault) 0 0 0
219 0 embperl_DefaultReqConfig (pConfig) ;
220  
221 #define EPCFG_REQ
222 #define REDIR ""
223 0 ▶ if (bUseEnv)
Branch: 1 branch
BranchTrueFalseTotal
if (bUseEnv) 0 0 0
224 {
225 #include "epcfg.h"
226 }
227 #undef REDIR
228 #define REDIR "REDIRECT_"
229 0 ▶ if (bUseRedirectEnv)
Branch: 1 branch
BranchTrueFalseTotal
if (bUseRedirectEnv) 0 0 0
230 {
231 #include "epcfg.h"
232 }
233 #undef EPCFG_REQ
234 #undef REDIR
235  
236  
237 0 ▶ if ((bUseEnv || bUseRedirectEnv) && GetHashValueStr (aTHX_ pThread -> pEnvHash, "GATEWAY_INTERFACE", NULL))
Branch: 3 branches
BranchTrueFalseTotal
if ((bUseEnv || bUseRedirectEnv) && GetHashValueStr (aTHX_ pThread -> pEnvHash, "GATEWAY_INTERFACE", NULL)) 0 0 0
if ((bUseEnv || bUseRedirectEnv) && GetHashValueStr (aTHX_ pThread -> pEnvHash, "GATEWAY_INTERFACE", NULL)) 0 0 0
if ((bUseEnv || bUseRedirectEnv) && GetHashValueStr (aTHX_ pThread -> pEnvHash, "GATEWAY_INTERFACE", NULL)) 0 0 0
238 0 pConfig -> bOptions |= optSendHttpHeader ;
239  
240 0 return ok ;
241 }
242  
243  
244 0 int embperl_GetCGIComponentConfig (/*in*/ tReq * pReq,
245 /*in*/ tMemPool * pPool,
246 /*out*/ tComponentConfig * pConfig,
247 /*in*/ bool bUseEnv,
248 /*in*/ bool bUseRedirectEnv,
249 /*in*/ bool bSetDefault)
250  
251  
252 {
253 0 tApp * pApp = pReq -> pApp ;
254 0 tThreadData * pThread = pApp -> pThread ;
255 eptTHX_
256  
257 0 ▶ if (bSetDefault)
Branch: 1 branch
BranchTrueFalseTotal
if (bSetDefault) 0 0 0
258 0 embperl_DefaultComponentConfig (pConfig) ;
259  
260 #define EPCFG_COMPONENT
261 #define REDIR ""
262 0 ▶ if (bUseEnv)
Branch: 1 branch
BranchTrueFalseTotal
if (bUseEnv) 0 0 0
263 {
264 #include "epcfg.h"
265 }
266 #undef REDIR
267 #define REDIR "REDIRECT_"
268 0 ▶ if (bUseRedirectEnv)
Branch: 1 branch
BranchTrueFalseTotal
if (bUseRedirectEnv) 0 0 0
269 {
270 #include "epcfg.h"
271 }
272 #undef EPCFG_COMPONENT
273 #undef REDIR
274  
275 0 return ok ;
276 }
277  
278  
279  
280 0 int embperl_GetCGIReqParam (/*in*/ tApp * pApp,
281 /*in*/ tMemPool * pPool,
282 /*out*/ tReqParam * pParam)
283  
284  
285 {
286 0 tThreadData * pThread = pApp -> pThread ;
287 eptTHX_
288 char * p ;
289 char buf[20] ;
290 char * sHost ;
291 int nPort ;
292 char * scheme ;
293  
294 0 pParam -> sFilename = GetHashValueStrDup (aTHX_ pPool, pThread -> pEnvHash, "PATH_TRANSLATED", "") ;
295 0 pParam -> sUnparsedUri = GetHashValueStrDup (aTHX_ pPool, pThread -> pEnvHash, "REQUEST_URI", "") ;
296 0 pParam -> sUri = GetHashValueStrDup (aTHX_ pPool, pThread -> pEnvHash, "PATH_INFO", "") ;
297 0 pParam -> sPathInfo = GetHashValueStrDup (aTHX_ pPool, pThread -> pEnvHash, "PATH_INFO", "") ;
298 0 pParam -> sQueryInfo = GetHashValueStrDup (aTHX_ pPool, pThread -> pEnvHash, "QUERY_STRING", "") ;
299 0 ▶ if ((p = GetHashValueStrDup (aTHX_ pPool, pThread -> pEnvHash, "HTTP_ACCEPT_LANGUAGE", NULL)))
Branch: 1 branch
BranchTrueFalseTotal
if ((p = GetHashValueStrDup (aTHX_ pPool, pThread -> pEnvHash, "HTTP_ACCEPT_LANGUAGE", NULL))) 0 0 0
300 {
301 0 ▶ while (isspace(*p))
Branch: 1 branch
BranchTrueFalseTotal
while (isspace(*p)) 0 0 0
302 0 p++ ;
303 0 pParam -> sLanguage = p ;
304 0 ▶ while (isalpha(*p))
Branch: 1 branch
BranchTrueFalseTotal
while (isalpha(*p)) 0 0 0
305 0 p++ ;
306 0 *p = '\0' ;
307 }
308
309 0 p = GetHashValueStr (aTHX_ pThread -> pEnvHash, "HTTP_COOKIE", NULL) ;
310 0 ▶ if (p)
Branch: 1 branch
BranchTrueFalseTotal
if (p) 0 0 0
311 {
312 HV * pHV ;
313 0 ▶ if (!(pHV = pParam -> pCookies))
Branch: 1 branch
BranchTrueFalseTotal
if (!(pHV = pParam -> pCookies)) 0 0 0
314 0 pHV = pParam -> pCookies = newHV () ;
315  
316 0 embperl_String2HV(pApp, p, ';', pHV) ;
317 }
318  
319  
320 0 buf[0] = '\0' ;
321 0 nPort = GetHashValueInt (aTHX_ pThread -> pEnvHash, "SERVER_PORT", 80) ;
322 0 ▶ if (GetHashValueStr (aTHX_ pThread -> pEnvHash, "HTTPS", NULL))
Branch: 1 branch
BranchTrueFalseTotal
if (GetHashValueStr (aTHX_ pThread -> pEnvHash, "HTTPS", NULL)) 0 0 0
323 {
324 0 scheme = "https" ;
325 0 ▶ if (nPort != 443)
Branch: 1 branch
BranchTrueFalseTotal
if (nPort != 443) 0 0 0
326 0 sprintf (buf, ":%d", nPort) ;
327 }
328 else
329 {
330 0 scheme = "http" ;
331 0 ▶ if (nPort != 80)
Branch: 1 branch
BranchTrueFalseTotal
if (nPort != 80) 0 0 0
332 0 sprintf (buf, ":%d", nPort) ;
333 }
334  
335 0 ▶ if (!(sHost = GetHashValueStr (aTHX_ pThread -> pEnvHash, "HTTP_HOST", NULL)))
Branch: 1 branch
BranchTrueFalseTotal
if (!(sHost = GetHashValueStr (aTHX_ pThread -> pEnvHash, "HTTP_HOST", NULL))) 0 0 0
336 {
337 0 sHost = GetHashValueStr (aTHX_ pThread -> pEnvHash, "SERVER_NAME", "") ;
338  
339 0 pParam -> sServerAddr = ep_pstrcat (pPool, scheme, "://",
340 sHost, buf, "//", NULL) ;
341 }
342 else
343 {
344 0 pParam -> sServerAddr = ep_pstrcat (pPool, scheme, "://",
345 sHost, "//", NULL) ;
346 }
347
348  
349 0 return ok ;
350 }
351  
352  
« epcfg.h ↑ Summary epcmd2.c »