epcache.c

filter: Statementstmt 0.0% 0 / 339 Branchbran 0.0% 0 / 304 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 643 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« Syntax.xs ↑ Summary epcfg.h »
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 #
10 # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
11 # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
12 # WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13 #
14 ###################################################################################*/
15  
16 #include "ep.h"
17 #include "epmacro.h"
18  
19  
20 /* --- don't use Perl's memory management here --- */
21  
22 #ifndef DMALLOC
23 #undef malloc
24 #undef realloc
25 #undef strdup
26 #undef free
27 #endif
28  
29 HV * pProviders ; /**< global hash that holds all known providers classes */
30 HV * pCacheItems ; /**< hash which contains all CacheItems by Key */
31 tCacheItem * * pCachesToRelease = NULL ;
32  
33  
34  
35  
36  
37 /* ------------------------------------------------------------------------ */
38 /* */
39 /* Cache_AddProviderClass */
40 /* */
41 /*!
42 * \_en
43 * Add a provider class to list of known providers
44 * @param sName Name of the Providerclass
45 * @param pProviderClass Provider class record
46 * @return error code
47 *
48 * \endif
49 *
50 * \_de
51 * Fügt eine Providerklasse den der Liste der bekannten Providern hinzu
52 * @param sName Name der Providerklasse
53 * @param pProviderClass Provider class record
54 * @return Fehlercode
55 *
56 * \endif
57 *
58 * ------------------------------------------------------------------------ */
59  
60 0 int Cache_AddProviderClass (/*in*/ const char * sName,
61 /*in*/ tProviderClass * pClass)
62  
63 {
64 0 SetHashValueInt (NULL, pProviders, sName, (IV)pClass) ;
65 0 return ok ;
66 }
67  
68 /* ------------------------------------------------------------------------ */
69 /* */
70 /* Cache_Init */
71 /* */
72 /*!
73 * \_en
74 * Do global initialization of cache system
75 * @return error code
76 *
77 * \endif
78 *
79 * \_de
80 * Führt die globale Initialisierung des Cachesystems durch
81 * @return Fehlercode
82 *
83 * \endif
84 *
85 * ------------------------------------------------------------------------ */
86  
87 0 int Cache_Init (/*in*/ tApp * a)
88  
89 {
90 epaTHX_
91 0 pProviders = newHV () ;
92 0 pCacheItems = newHV () ;
93  
94 0 ArrayNew (a, &pCachesToRelease, 16, sizeof (tCacheItem *)) ;
95  
96 /* lprintf (a, "XXXXX Cache_Init [%d/%d] pProviders=%x pCacheItems=%x pCachesToRelease=%x", _getpid(), GetCurrentThreadId(), pProviders, pCacheItems, pCachesToRelease) ; */
97
98 0 return ok ;
99 }
100  
101  
102 /* ------------------------------------------------------------------------ */
103 /* */
104 /* Cache_CleanupRequest */
105 /* */
106 /*!
107 * \_en
108 * Do cleanup at end of request
109 * @param r Embperl request record
110 * @return error code
111 *
112 * \endif
113 *
114 * \_de
115 * Führt die Aufräumarbeiten am Requestende aus
116 * @param r Embperl request record
117 * @return Fehlercode
118 *
119 * \endif
120 *
121 * ------------------------------------------------------------------------ */
122  
123 0 int Cache_CleanupRequest (req * r)
124  
125 {
126 0 ▶ if (pCachesToRelease)
Branch: 1 branch
BranchTrueFalseTotal
if (pCachesToRelease) 0 0 0
127 {
128 0 int n = ArrayGetSize (r -> pApp, pCachesToRelease) ;
129 int i ;
130  
131 /* lprintf (r -> pApp, "XXXXX Cache_CleanupRequest [%d/%d] pProviders=%x pCacheItems=%x pCachesToRelease=%x", _getpid(), GetCurrentThreadId(), pProviders, pCacheItems, pCachesToRelease) ; */
132  
133 0 ▶ for (i = 0; i < n; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) 0 0 0
134 0 Cache_FreeContent (r, pCachesToRelease[i]) ;
135  
136 0 ArraySetSize(r -> pApp, &pCachesToRelease, 0) ;
137 }
138  
139 0 return ok ;
140 }
141  
142  
143 /* ------------------------------------------------------------------------ */
144 /* */
145 /* Cache_ParamUpdate */
146 /* */
147  
148  
149
150 0 int Cache_ParamUpdate (/*in*/ req * r,
151 /*in*/ HV * pProviderParam,
152 /*in*/ bool bTopLevel,
153 /*in*/ char * sLogText,
154 /*in*/ tCacheItem * pNew)
155  
156  
157 {
158 epTHX_
159 char * exfn ;
160 int rc ;
161  
162 0 ▶ pNew -> nExpiresInTime = GetHashValueInt (aTHX_ pProviderParam, "expires_in", bTopLevel?r -> Component.Config.nExpiresIn:0) ;
Branch: 1 branch
BranchTrueFalseTotal
pNew -> nExpiresInTime = GetHashValueInt (aTHX_ pProviderParam, "expires_in", bTopLevel?r -> Component.Config.nExpiresIn:0) ; 0 0 0
163 0 ▶ if (pNew -> pExpiresCV)
Branch: 1 branch
BranchTrueFalseTotal
if (pNew -> pExpiresCV) 0 0 0
164 0 SvREFCNT_dec (pNew -> pExpiresCV) ;
165 0 ▶ if ((rc = GetHashValueCREF (r, pProviderParam, "expires_func", &pNew -> pExpiresCV)) != ok)
Branch: 1 branch
BranchTrueFalseTotal
if ((rc = GetHashValueCREF (r, pProviderParam, "expires_func", &pNew -> pExpiresCV)) != ok) 0 0 0
166 0 return rc ;
167 0 ▶ if (!pNew -> pExpiresCV && bTopLevel)
Branch: 2 branches
BranchTrueFalseTotal
if (!pNew -> pExpiresCV && bTopLevel) 0 0 0
if (!pNew -> pExpiresCV && bTopLevel) 0 0 0
168 0 pNew -> pExpiresCV = (CV *)SvREFCNT_inc((SV *)r -> Component.Config.pExpiredFunc) ;
169
170 0 ▶ exfn = GetHashValueStrDupA (aTHX_ pProviderParam, "expires_filename", bTopLevel?r -> Component.Config.sExpiresFilename:NULL) ;
Branch: 1 branch
BranchTrueFalseTotal
exfn = GetHashValueStrDupA (aTHX_ pProviderParam, "expires_filename", bTopLevel?r -> Component.Config.sExpiresFilename:NULL) ; 0 0 0
171 0 ▶ if (pNew -> sExpiresFilename)
Branch: 1 branch
BranchTrueFalseTotal
if (pNew -> sExpiresFilename) 0 0 0
172 {
173 0 ▶ if (exfn)
Branch: 1 branch
BranchTrueFalseTotal
if (exfn) 0 0 0
174 {
175 /* lprintf (r -> pApp, "exfn=%s\n", exfn) ; */
176 0 free ((void *)pNew -> sExpiresFilename) ;
177 0 pNew -> sExpiresFilename = exfn ;
178 }
179 }
180 else
181 0 pNew -> sExpiresFilename = exfn ;
182  
183 0 ▶ pNew -> bCache = (bool)GetHashValueInt (aTHX_ pProviderParam, "cache", exfn || pNew -> pExpiresCV || pNew -> nExpiresInTime?1:0) ;
Branch: 3 branches
BranchTrueFalseTotal
pNew -> bCache = (bool)GetHashValueInt (aTHX_ pProviderParam, "cache", exfn || pNew -> pExpiresCV || pNew -> nExpiresInTime?1:0) ; 0 0 0
pNew -> bCache = (bool)GetHashValueInt (aTHX_ pProviderParam, "cache", exfn || pNew -> pExpiresCV || pNew -> nExpiresInTime?1:0) ; 0 0 0
pNew -> bCache = (bool)GetHashValueInt (aTHX_ pProviderParam, "cache", exfn || pNew -> pExpiresCV || pNew -> nExpiresInTime?1:0) ; 0 0 0
184  
185 0 ▶ if (sLogText && (r -> Component.Config.bDebug & dbgCache))
Branch: 2 branches
BranchTrueFalseTotal
if (sLogText && (r -> Component.Config.bDebug & dbgCache)) 0 0 0
if (sLogText && (r -> Component.Config.bDebug & dbgCache)) 0 0 0
186 0 lprintf (r -> pApp, "[%d]CACHE: %s CacheItem %s; expires_in=%d expires_func=%s expires_filename=%s cache=%s\n",
187 0 r -> pThread -> nPid, sLogText, pNew -> sKey, pNew -> nExpiresInTime,
188 0 ▶ pNew -> pExpiresCV?"yes":"no", pNew -> sExpiresFilename?pNew -> sExpiresFilename:"",
Branch: 2 branches
BranchTrueFalseTotal
pNew -> pExpiresCV?"yes":"no", pNew -> sExpiresFilename?pNew -> sExpiresFilename:"", 0 0 0
pNew -> pExpiresCV?"yes":"no", pNew -> sExpiresFilename?pNew -> sExpiresFilename:"", 0 0 0
189 0 ▶ pNew -> bCache?"yes":"no") ;
Branch: 1 branch
BranchTrueFalseTotal
pNew -> bCache?"yes":"no") ; 0 0 0
190  
191 0 return ok ;
192 }
193  
194 /* ------------------------------------------------------------------------ */
195 /* */
196 /* Cache_New */
197 /* */
198 /*!
199 * \_en
200 * Checks if a CacheItem which matches the parameters already exists, if
201 * not it creates a new CacheItem and fills it with data from the hash
202 * pParam
203 *
204 * @param r Embperl request record
205 * @param pParam Parameter (PV,HV,AV)
206 * expires_in number of seconds when the item
207 * expires, 0 = expires never
208 * expires_func Perl Function (coderef) that
209 * is called and item is expired
210 * if it returns TRUE
211 * expires_filename item expires when modification
212 * time of file changes
213 * cache set to zero to not cache the content
214 * provider parameter for the provider
215 * @param nParamNdx If pParam is a AV, this parameter gives the index into the Array
216 * @param bTopLevel True if last elemet before output. In this case the cache parameters
217 * defaults to the ones from Componet.Config
218 * @param pItem Return of the new Items
219 * @return error code
220 * \endif
221 *
222 * \_de
223 * Prüft ob ein passendes CacheItem bereits vorhanden ist, wenn nicht
224 * erzeugt die Funktion ein neues CacheItem und füllte es mit den Daten aus
225 * pParam
226 *
227 * @param r Embperl request record
228 * @param pParam Parameter (PV,HV,AV)
229 * expires_in anzahl der Sekunden wenn Item
230 * abläuft; 0 = nie
231 * expires_func Perl Funktion (coderef) die
232 * aufgerufen wird. Wenn sie wahr
233 * zurückgibt ist das Item abgelaufen
234 * expires_filename Item ist abgelaufen wenn
235 * Dateidatum sich ändert
236 * cache Auf Null setzen damit Inhalt
237 * nicht gecacht wird
238 * provider parameter für Provider
239 * @param nParamNdx Wenn pParam ein AV ist, gibt dieser Parameter den Index an
240 * @param bTopLevel Wahr wenn letztes Element vor der Ausgabe, dann werden
241 * die Cache Parameter aus Componet.Config herangezogen
242 * @param pItem Rückgabe des neuen Items
243 * @return Fehlercode
244 * \endif
245 *
246 * ------------------------------------------------------------------------ */
247  
248 0 int Cache_New (/*in*/ req * r,
249 /*in*/ SV * pParam,
250 /*in*/ IV nParamNdx,
251 /*in*/ bool bTopLevel,
252 /*in*/ tCacheItem * * pItem)
253  
254  
255 {
256 epTHX_
257 int rc ;
258 HV * pProviderParam ;
259 char * sProvider ;
260 tProviderClass * pProviderClass ;
261 0 tCacheItem * pNew = NULL ;
262 0 SV * pKey = NULL ;
263 0 const char * sKey = "" ;
264 STRLEN len ;
265  
266 /* lprintf (r -> pApp, "XXXXX Cache_New [%d/%d] pProviders=%x %s pCacheItems=%x %s pCachesToRelease=%x %s\n", _getpid(), GetCurrentThreadId(), pProviders, IsBadReadPtr (pProviders,4 )?"bad":"ok", pCacheItems, IsBadReadPtr (pCacheItems, 4)?"bad":"ok", pCachesToRelease, IsBadReadPtr (pCachesToRelease, 4)?"bad":"ok") ; */
267  
268 0 ▶ if (SvROK(pParam))
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(pParam)) 0 0 0
269 0 pParam = SvRV (pParam) ;
270  
271 0 ▶ if (SvTYPE(pParam) == SVt_PV)
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(pParam) == SVt_PV) 0 0 0
272 {
273 /* change this to auto match later on ... */
274 0 pProviderParam = (HV *)SvRV(sv_2mortal (CreateHashRef (r,
275 "type", hashtstr, "file",
276 "filename", hashtsv, pParam,
277 NULL)
278 )) ;
279 }
280 0 ▶ else if (SvTYPE(pParam) == SVt_PVAV)
Branch: 1 branch
BranchTrueFalseTotal
else if (SvTYPE(pParam) == SVt_PVAV) 0 0 0
281 {
282 0 SV * * ppRV = av_fetch ((AV *)pParam, nParamNdx, 0) ;
283 0 ▶ if (!ppRV || !*ppRV)
Branch: 2 branches
BranchTrueFalseTotal
if (!ppRV || !*ppRV) 0 0 0
if (!ppRV || !*ppRV) 0 0 0
284 {
285 0 strncpy (r -> errdat1, "<provider missing>", sizeof(r -> errdat1) - 1) ;
286 0 return rcUnknownProvider ;
287 }
288 0 ▶ if (!SvROK (*ppRV) || SvTYPE(pProviderParam = (HV *)SvRV (*ppRV)) != SVt_PVHV)
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK (*ppRV) || SvTYPE(pProviderParam = (HV *)SvRV (*ppRV)) != SVt_PVHV) 0 0 0
if (!SvROK (*ppRV) || SvTYPE(pProviderParam = (HV *)SvRV (*ppRV)) != SVt_PVHV) 0 0 0
289 {
290 0 strncpy (r -> errdat1, "<provider missing, element is no hashref>", sizeof(r -> errdat1) - 1) ;
291 0 return rcUnknownProvider ;
292 }
293 }
294 0 ▶ else if (SvTYPE(pParam) == SVt_PVHV)
Branch: 1 branch
BranchTrueFalseTotal
else if (SvTYPE(pParam) == SVt_PVHV) 0 0 0
295 {
296 0 pProviderParam = (HV *)pParam ;
297 }
298 else
299 {
300 0 strncpy (r -> errdat1, "<provider missing, no description found>", sizeof(r -> errdat1) - 1) ;
301 0 return rcUnknownProvider ;
302 }
303  
304
305 0 sProvider = GetHashValueStr (aTHX_ pProviderParam, "type", "") ;
306 0 pProviderClass = (tProviderClass *)GetHashValuePtr (r, pProviders, sProvider, NULL) ;
307 0 ▶ if (!pProviderClass)
Branch: 1 branch
BranchTrueFalseTotal
if (!pProviderClass) 0 0 0
308 {
309 0 ▶ if (*sProvider)
Branch: 1 branch
BranchTrueFalseTotal
if (*sProvider) 0 0 0
310 0 strncpy (r -> errdat1, sProvider, sizeof(r -> errdat1) - 1) ;
311 else
312 0 strncpy (r -> errdat1, "<provider missing>", sizeof(r -> errdat1) - 1) ;
313  
314 0 return rcUnknownProvider ;
315 }
316 0 pKey = newSVpv ("", 0) ;
317 0 ▶ if (pProviderClass -> fAppendKey)
Branch: 1 branch
BranchTrueFalseTotal
if (pProviderClass -> fAppendKey) 0 0 0
318 0 ▶ if ((rc = (*pProviderClass -> fAppendKey)(r, pProviderClass, pProviderParam, pParam, nParamNdx - 1, pKey)) != ok)
Branch: 1 branch
BranchTrueFalseTotal
if ((rc = (*pProviderClass -> fAppendKey)(r, pProviderClass, pProviderParam, pParam, nParamNdx - 1, pKey)) != ok) 0 0 0
319 0 return rc ;
320  
321 0 sKey = SvPV(pKey, len) ;
322 0 ▶ if ((pNew = Cache_GetByKey (r, sKey)))
Branch: 1 branch
BranchTrueFalseTotal
if ((pNew = Cache_GetByKey (r, sKey))) 0 0 0
323 {
324 0 Cache_ParamUpdate (r, pProviderParam, bTopLevel, "Update", pNew) ;
325
326  
327 0 ▶ if (pProviderClass -> fUpdateParam)
Branch: 1 branch
BranchTrueFalseTotal
if (pProviderClass -> fUpdateParam) 0 0 0
328 0 ▶ if ((rc = (*pProviderClass -> fUpdateParam)(r, pNew -> pProvider, pProviderParam)) != ok)
Branch: 1 branch
BranchTrueFalseTotal
if ((rc = (*pProviderClass -> fUpdateParam)(r, pNew -> pProvider, pProviderParam)) != ok) 0 0 0
329 0 return rc ;
330 }
331  
332 0 ▶ if (!pNew)
Branch: 1 branch
BranchTrueFalseTotal
if (!pNew) 0 0 0
333 {
334 0 pNew = cache_malloc (r, sizeof(tCacheItem)) ;
335 0 ▶ if (!pNew)
Branch: 1 branch
BranchTrueFalseTotal
if (!pNew) 0 0 0
336 {
337 0 ▶ if (pKey)
Branch: 1 branch
BranchTrueFalseTotal
if (pKey) 0 0 0
338 0 SvREFCNT_dec (pKey) ;
339 0 return rcOutOfMemory ;
340 }
341  
342 0 *pItem = NULL ;
343 0 memset (pNew, 0, sizeof (tCacheItem)) ;
344  
345 0 Cache_ParamUpdate (r, pProviderParam, bTopLevel, NULL, pNew) ;
346 0 pNew -> sKey = strdup (sKey) ;
347  
348 0 ▶ if (pProviderParam)
Branch: 1 branch
BranchTrueFalseTotal
if (pProviderParam) 0 0 0
349 {
350 0 ▶ if ((rc = (*pProviderClass -> fNew)(r, pNew, pProviderClass, pProviderParam, pParam, nParamNdx - 1)) != ok)
Branch: 1 branch
BranchTrueFalseTotal
if ((rc = (*pProviderClass -> fNew)(r, pNew, pProviderClass, pProviderParam, pParam, nParamNdx - 1)) != ok) 0 0 0
351 {
352 0 ▶ if (pKey)
Branch: 1 branch
BranchTrueFalseTotal
if (pKey) 0 0 0
353 0 SvREFCNT_dec (pKey) ;
354 0 cache_free (r, pNew) ;
355 0 return rc ;
356 }
357 0 ▶ if (pProviderClass -> fUpdateParam)
Branch: 1 branch
BranchTrueFalseTotal
if (pProviderClass -> fUpdateParam) 0 0 0
358 0 ▶ if ((rc = (*pProviderClass -> fUpdateParam)(r, pNew -> pProvider, pProviderParam)) != ok)
Branch: 1 branch
BranchTrueFalseTotal
if ((rc = (*pProviderClass -> fUpdateParam)(r, pNew -> pProvider, pProviderParam)) != ok) 0 0 0
359 0 return rc ;
360 }
361  
362
363 0 ▶ if (r -> Component.Config.bDebug & dbgCache)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgCache) 0 0 0
364 0 lprintf (r -> pApp, "[%d]CACHE: Created new CacheItem %s; expires_in=%d expires_func=%s expires_filename=%s cache=%s\n",
365 0 r -> pThread -> nPid, sKey, pNew -> nExpiresInTime,
366 0 ▶ pNew -> pExpiresCV?"yes":"no", pNew -> sExpiresFilename?pNew -> sExpiresFilename:"",
Branch: 2 branches
BranchTrueFalseTotal
pNew -> pExpiresCV?"yes":"no", pNew -> sExpiresFilename?pNew -> sExpiresFilename:"", 0 0 0
pNew -> pExpiresCV?"yes":"no", pNew -> sExpiresFilename?pNew -> sExpiresFilename:"", 0 0 0
367 0 ▶ pNew -> bCache?"yes":"no") ;
Branch: 1 branch
BranchTrueFalseTotal
pNew -> bCache?"yes":"no") ; 0 0 0
368 0 SetHashValueInt (r, pCacheItems, sKey, (IV)pNew) ;
369 }
370  
371 0 ▶ if (pKey)
Branch: 1 branch
BranchTrueFalseTotal
if (pKey) 0 0 0
372 0 SvREFCNT_dec (pKey) ;
373 0 *pItem = pNew ;
374  
375 0 return ok ;
376 }
377  
378  
379 /* ------------------------------------------------------------------------ */
380 /* */
381 /* Cache_AppendKey */
382 /* */
383 /*!
384 * \_en
385 * Append it's key to the keystring. If it depends on anything it must
386 * call Cache_AppendKey for any dependency.
387 * The file provider appends the filename
388 *
389 * @param r Embperl request record
390 * @param pParam Parameter Hash
391 * @param sSubProvider sub provider parameter
392 * @param pKey Key to which string should be appended
393 * @return error code
394 * \endif
395 *
396 * \_de
397 * Hängt ein eigenen Schlüssel an den Schlüsselstring an. Wenn irgednwelche
398 * Abhänigkeiten bestehen, muß Cache_AppendKey für alle Abhänigkeiten aufgerufen
399 * werden.
400 * Der File Provider hängt den Dateinamen an.
401 *
402 * @param r Embperl request record
403 * @param pParam Parameter Hash
404 * @param sSubProvider sub provider parameter
405 * @param pKey Schlüssel zu welchem hinzugefügt wird
406 * @return Fehlercode
407 * \endif
408 *
409 * ------------------------------------------------------------------------ */
410  
411 0 int Cache_AppendKey (/*in*/ req * r,
412 /*in*/ HV * pProviderParam,
413 /*in*/ const char * sSubProvider,
414 /*in*/ SV * pParam,
415 /*in*/ IV nParamIndex,
416 /*i/o*/ SV * pKey)
417 {
418 epTHX_
419 int rc ;
420 char * sProvider ;
421 tProviderClass * pProviderClass ;
422 STRLEN len ;
423 tCacheItem * pItem ;
424  
425 0 SV * pSubParam = GetHashValueSV (r, pProviderParam, sSubProvider) ;
426
427 0 ▶ if (pSubParam)
Branch: 1 branch
BranchTrueFalseTotal
if (pSubParam) 0 0 0
428 0 pParam = pSubParam ;
429
430 0 ▶ if (!pParam)
Branch: 1 branch
BranchTrueFalseTotal
if (!pParam) 0 0 0
431 {
432 0 strncpy (r -> errdat1, sSubProvider, sizeof (r -> errdat1) - 1) ;
433
434 0 return rcMissingParam ;
435 }
436  
437
438 0 ▶ if (SvROK(pParam))
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(pParam)) 0 0 0
439 0 pParam = SvRV (pParam) ;
440  
441 0 ▶ if (SvTYPE(pParam) == SVt_PV)
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(pParam) == SVt_PV) 0 0 0
442 {
443 /* change this to auto match later on ... */
444 0 pProviderParam = (HV *)SvRV(sv_2mortal (CreateHashRef (r,
445 "type", hashtstr, "file",
446 "filename", hashtsv, pParam,
447 NULL)
448 )) ;
449 }
450 0 ▶ else if (SvTYPE(pParam) == SVt_PVAV)
Branch: 1 branch
BranchTrueFalseTotal
else if (SvTYPE(pParam) == SVt_PVAV) 0 0 0
451 {
452 0 SV * * ppRV = av_fetch ((AV *)pParam, nParamIndex, 0) ;
453 0 ▶ if (!ppRV || !*ppRV)
Branch: 2 branches
BranchTrueFalseTotal
if (!ppRV || !*ppRV) 0 0 0
if (!ppRV || !*ppRV) 0 0 0
454 {
455 0 strncpy (r -> errdat1, "<provider missing>", sizeof(r -> errdat1) - 1) ;
456  
457 0 return rcUnknownProvider ;
458 }
459 0 ▶ if (!SvROK (*ppRV) || SvTYPE(pProviderParam = (HV *)SvRV (*ppRV)) != SVt_PVHV)
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK (*ppRV) || SvTYPE(pProviderParam = (HV *)SvRV (*ppRV)) != SVt_PVHV) 0 0 0
if (!SvROK (*ppRV) || SvTYPE(pProviderParam = (HV *)SvRV (*ppRV)) != SVt_PVHV) 0 0 0
460 {
461 0 strncpy (r -> errdat1, "<provider missing, element is no hashref>", sizeof(r -> errdat1) - 1) ;
462  
463 0 return rcUnknownProvider ;
464 }
465 }
466 0 ▶ else if (SvTYPE(pParam) == SVt_PVHV)
Branch: 1 branch
BranchTrueFalseTotal
else if (SvTYPE(pParam) == SVt_PVHV) 0 0 0
467 {
468 0 pProviderParam = (HV *)pParam ;
469 }
470 else
471 {
472 0 strncpy (r -> errdat1, "<provider missing, no description found>", sizeof(r -> errdat1) - 1) ;
473  
474 0 return rcUnknownProvider ;
475 }
476  
477  
478 0 sProvider = GetHashValueStr (aTHX_ pProviderParam, "type", "") ;
479 0 pProviderClass = (tProviderClass *)GetHashValuePtr (r, pProviders, sProvider, NULL) ;
480 0 ▶ if (!pProviderClass)
Branch: 1 branch
BranchTrueFalseTotal
if (!pProviderClass) 0 0 0
481 {
482 0 ▶ if (*sProvider)
Branch: 1 branch
BranchTrueFalseTotal
if (*sProvider) 0 0 0
483 0 strncpy (r -> errdat1, sProvider, sizeof(r -> errdat1) - 1) ;
484 else
485 0 strncpy (r -> errdat1, "<provider missing>", sizeof(r -> errdat1) - 1) ;
486 0 return rcUnknownProvider ;
487 }
488 0 ▶ if (pProviderClass -> fAppendKey)
Branch: 1 branch
BranchTrueFalseTotal
if (pProviderClass -> fAppendKey) 0 0 0
489 0 ▶ if ((rc = (*pProviderClass -> fAppendKey)(r, pProviderClass, pProviderParam, pParam, nParamIndex - 1, pKey)) != ok)
Branch: 1 branch
BranchTrueFalseTotal
if ((rc = (*pProviderClass -> fAppendKey)(r, pProviderClass, pProviderParam, pParam, nParamIndex - 1, pKey)) != ok) 0 0 0
490 {
491 0 ▶ if (r -> Component.Config.bDebug & dbgCache)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgCache) 0 0 0
492 0 lprintf (r -> pApp, "[%d]CACHE: Error in Update CacheItem provider=%s\n",
493 0 r -> pThread -> nPid, sProvider) ;
494 0 return rc ;
495 }
496 0 ▶ if ((pItem = Cache_GetByKey (r, SvPV(pKey, len))))
Branch: 1 branch
BranchTrueFalseTotal
if ((pItem = Cache_GetByKey (r, SvPV(pKey, len)))) 0 0 0
497 {
498 0 int bCache = pItem -> bCache ;
499  
500 0 Cache_ParamUpdate (r, pProviderParam, 0, "Update", pItem) ;
501  
502 0 ▶ if (!pItem -> bCache && bCache)
Branch: 2 branches
BranchTrueFalseTotal
if (!pItem -> bCache && bCache) 0 0 0
if (!pItem -> bCache && bCache) 0 0 0
503 0 Cache_FreeContent (r, pItem) ;
504  
505  
506 0 ▶ if (pProviderClass -> fUpdateParam)
Branch: 1 branch
BranchTrueFalseTotal
if (pProviderClass -> fUpdateParam) 0 0 0
507 0 ▶ if ((rc = (*pProviderClass -> fUpdateParam)(r, pItem -> pProvider, pProviderParam)) != ok)
Branch: 1 branch
BranchTrueFalseTotal
if ((rc = (*pProviderClass -> fUpdateParam)(r, pItem -> pProvider, pProviderParam)) != ok) 0 0 0
508 0 return rc ;
509 }
510  
511 0 return ok ;
512 }
513  
514  
515 /* ------------------------------------------------------------------------ */
516 /* */
517 /* Cache_GetByKey */
518 /* */
519 /*!
520 * \_en
521 * Gets an CacheItem by it's key.
522 *
523 * @param r Embperl request record
524 * @param sKey Key
525 * @return Returns the cache item specified by the key if found
526 * \endif
527 *
528 * \_de
529 * Liefert das durch den Schlüssel angegeben CacheItem zurück.
530 *
531 * @param r Embperl request record
532 * @param sKey Key
533 * @return Liefert das CacheItem welches durch den Schlüssel
534 * angegeben wird, soweit gefunden.
535 * \endif
536 *
537 * ------------------------------------------------------------------------ */
538  
539 0 tCacheItem * Cache_GetByKey (/*in*/ req * r,
540 /*in*/ const char * sKey)
541  
542 {
543 tCacheItem * pItem ;
544
545 0 pItem = (tCacheItem *)GetHashValuePtr (r, pCacheItems, sKey, NULL) ;
546  
547 0 return pItem ;
548 }
549  
550  
551  
552 /* ------------------------------------------------------------------------ */
553 /* */
554 /* Cache_AddDependency */
555 /* */
556 /*!
557 * \_en
558 * Adds a CacheItem on which this cache items depends
559 *
560 * @param r Embperl request record
561 * @param pItem CacheItem which depends on pDependsOn
562 * @param pDependsOn CacheItem on which pItem depends
563 * @return 0 on success
564 * \endif
565 *
566 * \_de
567 * Fügt ein CacheItem von welches Adds a CacheItem on which this cache items depends
568 *
569 * @param r Embperl request record
570 * @param pItem CacheItem welches von pDependsOn anhängt
571 * @param pDependsOn CacheItem von welchem pItem abhängt
572 * @return 0 wenn fehlerfrei ausgeführt
573 * \endif
574 *
575 * ------------------------------------------------------------------------ */
576  
577  
578  
579  
580 0 int Cache_AddDependency (/*in*/ req * r,
581 /*in*/ tCacheItem * pItem,
582 /*in*/ tCacheItem * pDependsOn)
583  
584 {
585 int n ;
586
587 0 ▶ if (!pItem -> pDependsOn)
Branch: 1 branch
BranchTrueFalseTotal
if (!pItem -> pDependsOn) 0 0 0
588 0 ArrayNew (r -> pApp, &pItem -> pDependsOn, 2, sizeof (tCacheItem *)) ;
589  
590 0 n = ArrayAdd (r -> pApp, &pItem -> pDependsOn, 1) ;
591 0 pItem -> pDependsOn[n] = pDependsOn ;
592  
593  
594 0 ▶ if (!pDependsOn -> pNeededFor)
Branch: 1 branch
BranchTrueFalseTotal
if (!pDependsOn -> pNeededFor) 0 0 0
595 0 ArrayNew (r -> pApp, &pDependsOn -> pNeededFor, 2, sizeof (tCacheItem *)) ;
596  
597 0 n = ArrayAdd (r -> pApp, &pDependsOn -> pNeededFor, 1) ;
598 0 pDependsOn -> pNeededFor[n] = pItem ;
599  
600 0 return ok ;
601 }
602  
603  
604 /* ------------------------------------------------------------------------ */
605 /* */
606 /* Cache_GetDependency */
607 /* */
608 /*!
609 * \_en
610 * Get the Nth CacheItem on which this cache depends
611 *
612 * @param r Embperl request record
613 * @param pItem CacheItem
614 * @param n Dependency number
615 * @return Nth Dependency CacheItem
616 * \endif
617 *
618 * \_de
619 * Gibt das Nte CacheItem von dem pItem abhängt zurück
620 *
621 * @param r Embperl request record
622 * @param pItem CacheItem
623 * @param n Number der Abhänigkeit
624 * @return Ntes CacheItem von welchem pItem abhängt
625 * \endif
626 *
627 * ------------------------------------------------------------------------ */
628  
629  
630  
631  
632 0 tCacheItem * Cache_GetDependency (/*in*/ req * r,
633 /*in*/ tCacheItem * pItem,
634 /*in*/ int n)
635  
636 {
637 0 ▶ if (!pItem -> pDependsOn || ArrayGetSize (r -> pApp, pItem -> pDependsOn) < n || n < 0)
Branch: 3 branches
BranchTrueFalseTotal
if (!pItem -> pDependsOn || ArrayGetSize (r -> pApp, pItem -> pDependsOn) < n || n < 0) 0 0 0
if (!pItem -> pDependsOn || ArrayGetSize (r -> pApp, pItem -> pDependsOn) < n || n < 0) 0 0 0
if (!pItem -> pDependsOn || ArrayGetSize (r -> pApp, pItem -> pDependsOn) < n || n < 0) 0 0 0
638 0 return NULL ;
639  
640 0 return pItem -> pDependsOn[n] ;
641 }
642  
643  
644  
645 /* ------------------------------------------------------------------------ */
646 /* */
647 /* Cache_IsExpired */
648 /* */
649 /*!
650 * \_en
651 * Checks if the cache item or a cache item on which this one depends is
652 * expired
653 *
654 * @param r Embperl request record
655 * @param pItem CacheItem which should be checked
656 * @param nLastUpdated When a item on which this one depends, was
657 * updated after the given request count, then
658 * this item is expired
659 * @return TRUE if expired, otherwise FALSE
660 * \endif
661 *
662 * \_de
663 * Prüft ob das CacheItem oder eines von welchem dieses abhängt nihct
664 * mehr gültig ist
665 *
666 * @param r Embperl request record
667 * @param pItem CacheItem welches überprüft werden soll
668 * @param nLastUpdated Wenn ein Item von welchem dieses Item abhängt
669 * nach dem angegebenen Request Count geändert
670 * wurde ist diese Item nicht mehr gültig
671 * @return wahr wenn ungültig, ansonsten falsch
672 * \endif
673 *
674 * ------------------------------------------------------------------------ */
675  
676  
677  
678  
679 0 int Cache_IsExpired (/*in*/ req * r,
680 /*in*/ tCacheItem * pItem,
681 /*in*/ int nLastUpdated)
682  
683  
684 {
685 epTHX_
686 int rc ;
687 tCacheItem * pSubItem ;
688 int i ;
689 0 ▶ int numItems = pItem -> pDependsOn?ArrayGetSize (r -> pApp, pItem -> pDependsOn):0 ;
Branch: 1 branch
BranchTrueFalseTotal
int numItems = pItem -> pDependsOn?ArrayGetSize (r -> pApp, pItem -> pDependsOn):0 ; 0 0 0
690  
691 0 ▶ if (nLastUpdated < pItem -> nLastUpdated)
Branch: 1 branch
BranchTrueFalseTotal
if (nLastUpdated < pItem -> nLastUpdated) 0 0 0
692 0 return TRUE ;
693  
694 0 ▶ if (pItem -> pProvider -> pProviderClass -> fExpires)
Branch: 1 branch
BranchTrueFalseTotal
if (pItem -> pProvider -> pProviderClass -> fExpires) 0 0 0
695 {
696 0 ▶ if ((*pItem -> pProvider -> pProviderClass -> fExpires)(r, pItem -> pProvider))
Branch: 1 branch
BranchTrueFalseTotal
if ((*pItem -> pProvider -> pProviderClass -> fExpires)(r, pItem -> pProvider)) 0 0 0
697 {
698 0 ▶ if (r -> Component.Config.bDebug & dbgCache)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgCache) 0 0 0
699 0 lprintf (r -> pApp, "[%d]CACHE: %s expired because provider C sub returned TRUE\n", r -> pThread -> nPid, pItem -> sKey) ;
700 0 Cache_FreeContent (r, pItem) ;
701 0 return pItem -> bExpired = TRUE ;
702 }
703 }
704  
705 0 ▶ if (pItem -> bExpired || pItem -> nLastChecked == r -> nRequestCount)
Branch: 2 branches
BranchTrueFalseTotal
if (pItem -> bExpired || pItem -> nLastChecked == r -> nRequestCount) 0 0 0
if (pItem -> bExpired || pItem -> nLastChecked == r -> nRequestCount) 0 0 0
706 0 return pItem -> bExpired ; /* we already have checked this or know that is it expired */
707  
708 0 pItem -> nLastChecked = r -> nRequestCount ;
709  
710 /* first check dependency */
711 0 ▶ for (i = 0; i < numItems; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < numItems; i++) 0 0 0
712 {
713 0 pSubItem = pItem -> pDependsOn[i] ;
714 0 ▶ if (Cache_IsExpired (r, pSubItem, pItem -> nLastUpdated))
Branch: 1 branch
BranchTrueFalseTotal
if (Cache_IsExpired (r, pSubItem, pItem -> nLastUpdated)) 0 0 0
715 {
716 0 ▶ if (r -> Component.Config.bDebug & dbgCache)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgCache) 0 0 0
717 0 lprintf (r -> pApp, "[%d]CACHE: %s expired because dependencies is expired or newer\n", r -> pThread -> nPid, pItem -> sKey) ;
718 0 Cache_FreeContent (r, pItem) ;
719 0 return pItem -> bExpired = TRUE ;
720 }
721 }
722  
723 0 ▶ if (pItem -> nExpiresInTime && pItem -> nLastModified + pItem -> nExpiresInTime < r -> nRequestTime)
Branch: 2 branches
BranchTrueFalseTotal
if (pItem -> nExpiresInTime && pItem -> nLastModified + pItem -> nExpiresInTime < r -> nRequestTime) 0 0 0
if (pItem -> nExpiresInTime && pItem -> nLastModified + pItem -> nExpiresInTime < r -> nRequestTime) 0 0 0
724 {
725 0 ▶ if (r -> Component.Config.bDebug & dbgCache)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgCache) 0 0 0
726 0 lprintf (r -> pApp, "[%d]CACHE: %s expired because of timeout (%d sec)\n", r -> pThread -> nPid, pItem -> sKey, pItem -> nExpiresInTime) ;
727 0 Cache_FreeContent (r, pItem) ;
728 0 return pItem -> bExpired = TRUE ;
729 }
730  
731 0 ▶ if (pItem -> sExpiresFilename)
Branch: 1 branch
BranchTrueFalseTotal
if (pItem -> sExpiresFilename) 0 0 0
732 {
733 #ifdef WIN32
734 if (_stat (pItem -> sExpiresFilename, &pItem -> FileStat))
735 #else
736 0 ▶ if (stat (pItem -> sExpiresFilename, &pItem -> FileStat))
Branch: 1 branch
BranchTrueFalseTotal
if (stat (pItem -> sExpiresFilename, &pItem -> FileStat)) 0 0 0
737 #endif
738 {
739 0 ▶ if (r -> Component.Config.bDebug & dbgCache)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgCache) 0 0 0
740 0 lprintf (r -> pApp, "[%d]CACHE: %s expired because cannot stat file %s\n", r -> pThread -> nPid, pItem -> sKey, pItem -> sExpiresFilename) ;
741 0 Cache_FreeContent (r, pItem) ;
742 0 return pItem -> bExpired = TRUE ;
743 }
744  
745 0 ▶ if (r -> Component.Config.bDebug & dbgCache)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgCache) 0 0 0
746 0 lprintf (r -> pApp, "[%d]CACHE: %s stat file %s mtime=%d size=%d\n", r -> pThread -> nPid, pItem -> sKey, pItem -> sExpiresFilename, pItem -> FileStat.st_mtime, pItem -> FileStat.st_size) ;
747 0 ▶ if (pItem -> nFileModified != pItem -> FileStat.st_mtime)
Branch: 1 branch
BranchTrueFalseTotal
if (pItem -> nFileModified != pItem -> FileStat.st_mtime) 0 0 0
748 {
749 0 ▶ if (r -> Component.Config.bDebug & dbgCache)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgCache) 0 0 0
750 0 lprintf (r -> pApp, "[%d]CACHE: %s expired because file %s changed\n", r -> pThread -> nPid, pItem -> sKey, pItem -> sExpiresFilename) ;
751 0 pItem -> nFileModified = pItem -> FileStat.st_mtime ;
752 0 Cache_FreeContent (r, pItem) ;
753 0 return pItem -> bExpired = TRUE ;
754 }
755 }
756
757
758 0 ▶ if (pItem -> pExpiresCV)
Branch: 1 branch
BranchTrueFalseTotal
if (pItem -> pExpiresCV) 0 0 0
759 {
760 SV * pRet ;
761  
762 0 ▶ if ((rc = CallCV (r, "Expired?", pItem -> pExpiresCV, 0, &pRet)) != ok)
Branch: 1 branch
BranchTrueFalseTotal
if ((rc = CallCV (r, "Expired?", pItem -> pExpiresCV, 0, &pRet)) != ok) 0 0 0
763 {
764 0 LogError (r, rc) ;
765 0 Cache_FreeContent (r, pItem) ;
766 0 return pItem -> bExpired = TRUE ;
767 }
768
769 0 ▶ if (pRet && SvTRUE(pRet))
Branch: 2 branches
BranchTrueFalseTotal
if (pRet && SvTRUE(pRet)) 0 0 0
if (pRet && SvTRUE(pRet)) 0 0 0
770 { /* Expire the entry */
771 0 ▶ if (r -> Component.Config.bDebug & dbgCache)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgCache) 0 0 0
772 0 lprintf (r -> pApp, "[%d]CACHE: %s expired because expirey Perl sub returned TRUE\n", r -> pThread -> nPid, pItem -> sKey) ;
773 0 Cache_FreeContent (r, pItem) ;
774 0 return pItem -> bExpired = TRUE ;
775 }
776 }
777  
778 0 ▶ if (pItem -> fExpires)
Branch: 1 branch
BranchTrueFalseTotal
if (pItem -> fExpires) 0 0 0
779 {
780 0 ▶ if ((*pItem -> fExpires)(pItem))
Branch: 1 branch
BranchTrueFalseTotal
if ((*pItem -> fExpires)(pItem)) 0 0 0
781 {
782 0 ▶ if (r -> Component.Config.bDebug & dbgCache)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgCache) 0 0 0
783 0 lprintf (r -> pApp, "[%d]CACHE: %s expired because expirey C sub returned TRUE\n", r -> pThread -> nPid, pItem -> sKey) ;
784 0 Cache_FreeContent (r, pItem) ;
785 0 return pItem -> bExpired = TRUE ;
786 }
787 }
788  
789 0 ▶ if (r -> Component.Config.bDebug & dbgCache)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgCache) 0 0 0
790 0 lprintf (r -> pApp, "[%d]CACHE: %s NOT expired\n", r -> pThread -> nPid, pItem -> sKey) ;
791  
792 0 return FALSE ;
793 }
794  
795  
796 /* ------------------------------------------------------------------------ */
797 /* */
798 /* Cache_SetNotExpired */
799 /* */
800 /*!
801 * \_en
802 * Reset expired flag and last modification time
803 *
804 * @param r Embperl request record
805 * @param pItem CacheItem which should be checked
806 * @return TRUE if expired, otherwise FALSE
807 * \endif
808 *
809 * \_de
810 * Abgelaufen Flag zurücksetzen und Zeitpunkt der letzten Änderung setzen
811 *
812 * @param r Embperl request record
813 * @param pItem CacheItem welches überprüft werden soll
814 * @return wahr wenn ungültig, ansonsten falsch
815 * \endif
816 *
817 * ------------------------------------------------------------------------ */
818  
819  
820 0 int Cache_SetNotExpired (/*in*/ req * r,
821 /*in*/ tCacheItem * pItem)
822  
823 {
824 0 pItem -> nLastChecked = r -> nRequestCount ;
825 0 pItem -> nLastUpdated = r -> nRequestCount ;
826 0 pItem -> nLastModified = r -> nRequestTime ;
827 0 pItem -> bExpired = FALSE ;
828  
829 0 ▶ if (!pItem -> bCache)
Branch: 1 branch
BranchTrueFalseTotal
if (!pItem -> bCache) 0 0 0
830 {
831 0 int n = ArrayAdd(r -> pApp, &pCachesToRelease, 1) ;
832 0 pCachesToRelease[n] = pItem ;
833 }
834  
835 0 return ok ;
836 }
837  
838  
839 /* ------------------------------------------------------------------------ */
840 /* */
841 /* Cache_GetContentSV */
842 /* */
843 /*!
844 * \_en
845 * Get the whole content as SV, if not expired from the cache, otherwise ask
846 * the provider to fetch it. This will also put a read lock on the
847 * Cacheitem. When you are done with the content call ReleaseContent
848 *
849 * @param r Embperl request record
850 * @param pItem CacheItem which should be checked
851 * @param pData Returns the content
852 * @param bUseCache Set if the content should not recomputed
853 * @return error code
854 * \endif
855 *
856 * \_de
857 * Holt den gesamt Inhalt als SV soweit nich abgelaufen aus dem Cache, ansonsten
858 * wird der Provider beauftragt ihn einzulesen. Zusätzlich wird ein
859 * Read Lock gesetzt. Nach der Bearbeitetung des Inhalts sollte deshalb
860 * ReleaseLock zum freigeben aufgerufen werden.
861 *
862 * @param r Embperl request record
863 * @param pItem CacheItem welches überprüft werden soll
864 * @param pData Liefert den Inhalt
865 * @param bUseCache Gesetzt wenn der Inhalt nicht neu berechnet werden soll
866 * @return Fehlercode
867 * \endif
868 *
869 * ------------------------------------------------------------------------ */
870  
871  
872  
873 0 int Cache_GetContentSV (/*in*/ req * r,
874 /*in*/ tCacheItem *pItem,
875 /*in*/ SV * * pData,
876 /*in*/ bool bUseCache)
877  
878 {
879 epTHX_
880 int rc ;
881  
882 0 ▶ if (!bUseCache && (Cache_IsExpired (r, pItem, pItem -> nLastUpdated) || !pItem -> pSVData))
Branch: 3 branches
BranchTrueFalseTotal
if (!bUseCache && (Cache_IsExpired (r, pItem, pItem -> nLastUpdated) || !pItem -> pSVData)) 0 0 0
if (!bUseCache && (Cache_IsExpired (r, pItem, pItem -> nLastUpdated) || !pItem -> pSVData)) 0 0 0
if (!bUseCache && (Cache_IsExpired (r, pItem, pItem -> nLastUpdated) || !pItem -> pSVData)) 0 0 0
883 {
884 0 ▶ if (pItem -> pProvider -> pProviderClass -> fGetContentSV)
Branch: 1 branch
BranchTrueFalseTotal
if (pItem -> pProvider -> pProviderClass -> fGetContentSV) 0 0 0
885 0 ▶ if ((rc = ((*pItem -> pProvider -> pProviderClass -> fGetContentSV) (r, pItem -> pProvider, pData, FALSE))) != ok)
Branch: 1 branch
BranchTrueFalseTotal
if ((rc = ((*pItem -> pProvider -> pProviderClass -> fGetContentSV) (r, pItem -> pProvider, pData, FALSE))) != ok) 0 0 0
886 {
887 0 Cache_FreeContent (r, pItem) ;
888 0 return rc ;
889 }
890 0 Cache_SetNotExpired (r, pItem) ;
891 0 ▶ if (pItem -> pSVData)
Branch: 1 branch
BranchTrueFalseTotal
if (pItem -> pSVData) 0 0 0
892 0 SvREFCNT_dec (pItem -> pSVData) ;
893 0 pItem -> pSVData = *pData ;
894 }
895 else
896 {
897 0 ▶ if (r -> Component.Config.bDebug & dbgCache)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgCache) 0 0 0
898 0 lprintf (r -> pApp, "[%d]CACHE: %s take from cache\n", r -> pThread -> nPid, pItem -> sKey) ;
899 0 *pData = pItem -> pSVData ;
900 0 ▶ if (pItem -> pProvider -> pProviderClass -> fGetContentSV)
Branch: 1 branch
BranchTrueFalseTotal
if (pItem -> pProvider -> pProviderClass -> fGetContentSV) 0 0 0
901 0 ▶ if ((rc = ((*pItem -> pProvider -> pProviderClass -> fGetContentSV) (r, pItem -> pProvider, pData, TRUE))) != ok)
Branch: 1 branch
BranchTrueFalseTotal
if ((rc = ((*pItem -> pProvider -> pProviderClass -> fGetContentSV) (r, pItem -> pProvider, pData, TRUE))) != ok) 0 0 0
902 {
903 0 Cache_FreeContent (r, pItem) ;
904 0 return rc ;
905 }
906 }
907  
908  
909 0 return ok ;
910 }
911  
912 /* ------------------------------------------------------------------------ */
913 /* */
914 /* Cache_GetContentPtr */
915 /* */
916 /*!
917 * \_en
918 * Get the whole content as pointer, if not expired from the cache, otherwise ask
919 * the provider to fetch it. This will also put a read lock on the
920 * Cacheitem. When you are done with the content call ReleaseContent
921 *
922 * @param r Embperl request record
923 * @param pItem CacheItem which should be checked
924 * @param pData Returns the content
925 * @param bUseCache Set if the content should not recomputed
926 * @return error code
927 * \endif
928 *
929 * \_de
930 * Holt den gesamt Inhalt als Zeiger soweit nich abgelaufen aus dem Cache, ansonsten
931 * wird der Provider beauftragt ihn einzulesen. Zusätzlich wird ein
932 * Read Lock gesetzt. Nach der Bearbeitetung des Inhalts sollte deshalb
933 * ReleaseLock zum freigeben aufgerufen werden.
934 *
935 * @param r Embperl request record
936 * @param pItem CacheItem welches überprüft werden soll
937 * @param pData Liefert den Inhalt
938 * @param bUseCache Gesetzt wenn der Inhalt nicht neu berechnet werden soll
939 * @return Fehlercode
940 * \endif
941 *
942 * ------------------------------------------------------------------------ */
943  
944  
945  
946 0 int Cache_GetContentPtr (/*in*/ req * r,
947 /*in*/ tCacheItem *pItem,
948 /*in*/ void * * pData,
949 /*in*/ bool bUseCache)
950  
951 {
952 int rc ;
953  
954 0 ▶ if (!bUseCache && (Cache_IsExpired (r, pItem, pItem -> nLastUpdated) || !pItem -> pData))
Branch: 3 branches
BranchTrueFalseTotal
if (!bUseCache && (Cache_IsExpired (r, pItem, pItem -> nLastUpdated) || !pItem -> pData)) 0 0 0
if (!bUseCache && (Cache_IsExpired (r, pItem, pItem -> nLastUpdated) || !pItem -> pData)) 0 0 0
if (!bUseCache && (Cache_IsExpired (r, pItem, pItem -> nLastUpdated) || !pItem -> pData)) 0 0 0
955 {
956 0 ▶ if (r -> Component.Config.bDebug & dbgCache)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgCache) 0 0 0
957 0 lprintf (r -> pApp, "[%d]CACHE: %s get from provider\n", r -> pThread -> nPid, pItem -> sKey) ;
958 0 ▶ if (pItem -> pProvider -> pProviderClass -> fGetContentPtr)
Branch: 1 branch
BranchTrueFalseTotal
if (pItem -> pProvider -> pProviderClass -> fGetContentPtr) 0 0 0
959 0 ▶ if ((rc = (*pItem -> pProvider -> pProviderClass -> fGetContentPtr) (r, pItem -> pProvider, pData, FALSE)) != ok)
Branch: 1 branch
BranchTrueFalseTotal
if ((rc = (*pItem -> pProvider -> pProviderClass -> fGetContentPtr) (r, pItem -> pProvider, pData, FALSE)) != ok) 0 0 0
960 {
961 0 Cache_FreeContent (r, pItem) ;
962 0 return rc ;
963 }
964 0 pItem -> pData = *pData ;
965 0 Cache_SetNotExpired (r, pItem) ;
966 }
967 else
968 {
969 0 ▶ if (r -> Component.Config.bDebug & dbgCache)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgCache) 0 0 0
970 0 lprintf (r -> pApp, "[%d]CACHE: %s take from cache\n", r -> pThread -> nPid, pItem -> sKey) ;
971 0 *pData = pItem -> pData ;
972 0 ▶ if (pItem -> pProvider -> pProviderClass -> fGetContentPtr)
Branch: 1 branch
BranchTrueFalseTotal
if (pItem -> pProvider -> pProviderClass -> fGetContentPtr) 0 0 0
973 0 ▶ if ((rc = (*pItem -> pProvider -> pProviderClass -> fGetContentPtr) (r, pItem -> pProvider, pData, TRUE)) != ok)
Branch: 1 branch
BranchTrueFalseTotal
if ((rc = (*pItem -> pProvider -> pProviderClass -> fGetContentPtr) (r, pItem -> pProvider, pData, TRUE)) != ok) 0 0 0
974 {
975 0 Cache_FreeContent (r, pItem) ;
976 0 return rc ;
977 }
978 }
979 0 return ok ;
980 }
981  
982 /* ------------------------------------------------------------------------ */
983 /* */
984 /* Cache_GetContentIndex */
985 /* */
986 /*!
987 * \_en
988 * Get the whole content as pointer, if not expired from the cache, otherwise ask
989 * the provider to fetch it. This will also put a read lock on the
990 * Cacheitem. When you are done with the content call ReleaseContent
991 *
992 * @param r Embperl request record
993 * @param pItem CacheItem which should be checked
994 * @param pData Returns the content
995 * @param bUseCache Set if the content should not recomputed
996 * @return error code
997 * \endif
998 *
999 * \_de
1000 * Holt den gesamt Inhalt als Zeiger soweit nich abgelaufen aus dem Cache, ansonsten
1001 * wird der Provider beauftragt ihn einzulesen. Zusätzlich wird ein
1002 * Read Lock gesetzt. Nach der Bearbeitetung des Inhalts sollte deshalb
1003 * ReleaseLock zum freigeben aufgerufen werden.
1004 *
1005 * @param r Embperl request record
1006 * @param pItem CacheItem welches überprüft werden soll
1007 * @param pData Liefert den Inhalt
1008 * @param bUseCache Gesetzt wenn der Inhalt nicht neu berechnet werden soll
1009 * @return Fehlercode
1010 * \endif
1011 *
1012 * ------------------------------------------------------------------------ */
1013  
1014  
1015  
1016 0 int Cache_GetContentIndex (/*in*/ req * r,
1017 /*in*/ tCacheItem *pItem,
1018 /*in*/ tIndex * pData,
1019 /*in*/ bool bUseCache)
1020  
1021 {
1022 int rc ;
1023  
1024 0 ▶ if (!bUseCache && (Cache_IsExpired (r, pItem, pItem -> nLastUpdated) || !pItem -> xData))
Branch: 3 branches
BranchTrueFalseTotal
if (!bUseCache && (Cache_IsExpired (r, pItem, pItem -> nLastUpdated) || !pItem -> xData)) 0 0 0
if (!bUseCache && (Cache_IsExpired (r, pItem, pItem -> nLastUpdated) || !pItem -> xData)) 0 0 0
if (!bUseCache && (Cache_IsExpired (r, pItem, pItem -> nLastUpdated) || !pItem -> xData)) 0 0 0
1025 {
1026 0 ▶ if (r -> Component.Config.bDebug & dbgCache)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgCache) 0 0 0
1027 0 lprintf (r -> pApp, "[%d]CACHE: %s get from provider\n", r -> pThread -> nPid, pItem -> sKey) ;
1028 0 ▶ if (pItem -> pProvider -> pProviderClass -> fGetContentIndex)
Branch: 1 branch
BranchTrueFalseTotal
if (pItem -> pProvider -> pProviderClass -> fGetContentIndex) 0 0 0
1029 0 ▶ if ((rc = (*pItem -> pProvider -> pProviderClass -> fGetContentIndex) (r, pItem -> pProvider, pData, FALSE)) != ok)
Branch: 1 branch
BranchTrueFalseTotal
if ((rc = (*pItem -> pProvider -> pProviderClass -> fGetContentIndex) (r, pItem -> pProvider, pData, FALSE)) != ok) 0 0 0
1030 {
1031 0 Cache_FreeContent (r, pItem) ;
1032 0 return rc ;
1033 }
1034 0 pItem -> xData = *pData ;
1035 0 Cache_SetNotExpired (r, pItem) ;
1036 }
1037 else
1038 {
1039 0 ▶ if (r -> Component.Config.bDebug & dbgCache)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgCache) 0 0 0
1040 0 lprintf (r -> pApp, "[%d]CACHE: %s take from cache\n", r -> pThread -> nPid, pItem -> sKey) ;
1041 0 *pData = pItem -> xData ;
1042 0 ▶ if (pItem -> pProvider -> pProviderClass -> fGetContentIndex)
Branch: 1 branch
BranchTrueFalseTotal
if (pItem -> pProvider -> pProviderClass -> fGetContentIndex) 0 0 0
1043 0 ▶ if ((rc = (*pItem -> pProvider -> pProviderClass -> fGetContentIndex) (r, pItem -> pProvider, pData, TRUE)) != ok)
Branch: 1 branch
BranchTrueFalseTotal
if ((rc = (*pItem -> pProvider -> pProviderClass -> fGetContentIndex) (r, pItem -> pProvider, pData, TRUE)) != ok) 0 0 0
1044 {
1045 0 Cache_FreeContent (r, pItem) ;
1046 0 return rc ;
1047 }
1048 }
1049 0 return ok ;
1050 }
1051  
1052 /* ------------------------------------------------------------------------ */
1053 /* */
1054 /* Cache_GetContentSvIndex */
1055 /* */
1056 /*!
1057 * \_en
1058 * Get the whole content as pointer, if not expired from the cache, otherwise ask
1059 * the provider to fetch it. This will also put a read lock on the
1060 * Cacheitem. When you are done with the content call ReleaseContent
1061 *
1062 * @param r Embperl request record
1063 * @param pItem CacheItem which should be checked
1064 * @param pData Returns the content
1065 * @param bUseCache Set if the content should not recomputed
1066 * @return error code
1067 * \endif
1068 *
1069 * \_de
1070 * Holt den gesamt Inhalt als Zeiger soweit nich abgelaufen aus dem Cache, ansonsten
1071 * wird der Provider beauftragt ihn einzulesen. Zusätzlich wird ein
1072 * Read Lock gesetzt. Nach der Bearbeitetung des Inhalts sollte deshalb
1073 * ReleaseLock zum freigeben aufgerufen werden.
1074 *
1075 * @param r Embperl request record
1076 * @param pItem CacheItem welches überprüft werden soll
1077 * @param pData Liefert den Inhalt
1078 * @param bUseCache Gesetzt wenn der Inhalt nicht neu berechnet werden soll
1079 * @return Fehlercode
1080 * \endif
1081 *
1082 * ------------------------------------------------------------------------ */
1083  
1084  
1085  
1086 0 int Cache_GetContentSvIndex (/*in*/ req * r,
1087 /*in*/ tCacheItem *pItem,
1088 /*in*/ SV * * pSVData,
1089 /*in*/ tIndex * pData,
1090 /*in*/ bool bUseCache)
1091  
1092 {
1093 int rc ;
1094 0 bool bUpdate = FALSE ;
1095  
1096 0 ▶ if (!bUseCache && (Cache_IsExpired (r, pItem, pItem -> nLastUpdated)))
Branch: 2 branches
BranchTrueFalseTotal
if (!bUseCache && (Cache_IsExpired (r, pItem, pItem -> nLastUpdated))) 0 0 0
if (!bUseCache && (Cache_IsExpired (r, pItem, pItem -> nLastUpdated))) 0 0 0
1097 {
1098 0 pItem -> xData = 0 ;
1099 0 pItem -> pSVData = NULL ;
1100 }
1101 0 ▶ if (!pItem -> xData)
Branch: 1 branch
BranchTrueFalseTotal
if (!pItem -> xData) 0 0 0
1102 {
1103 0 ▶ if (r -> Component.Config.bDebug & dbgCache)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgCache) 0 0 0
1104 0 lprintf (r -> pApp, "[%d]CACHE: %s get from provider\n", r -> pThread -> nPid, pItem -> sKey) ;
1105 0 ▶ if (pItem -> pProvider -> pProviderClass -> fGetContentIndex)
Branch: 1 branch
BranchTrueFalseTotal
if (pItem -> pProvider -> pProviderClass -> fGetContentIndex) 0 0 0
1106 0 ▶ if ((rc = (*pItem -> pProvider -> pProviderClass -> fGetContentIndex) (r, pItem -> pProvider, pData, FALSE)) != ok)
Branch: 1 branch
BranchTrueFalseTotal
if ((rc = (*pItem -> pProvider -> pProviderClass -> fGetContentIndex) (r, pItem -> pProvider, pData, FALSE)) != ok) 0 0 0
1107 {
1108 0 Cache_FreeContent (r, pItem) ;
1109 0 return rc ;
1110 }
1111 0 pItem -> xData = *pData ;
1112 0 bUpdate = TRUE ;
1113 }
1114 else
1115 {
1116 0 *pData = pItem -> xData ;
1117 0 ▶ if (pItem -> pProvider -> pProviderClass -> fGetContentIndex)
Branch: 1 branch
BranchTrueFalseTotal
if (pItem -> pProvider -> pProviderClass -> fGetContentIndex) 0 0 0
1118 0 ▶ if ((rc = (*pItem -> pProvider -> pProviderClass -> fGetContentIndex) (r, pItem -> pProvider, pData, TRUE)) != ok)
Branch: 1 branch
BranchTrueFalseTotal
if ((rc = (*pItem -> pProvider -> pProviderClass -> fGetContentIndex) (r, pItem -> pProvider, pData, TRUE)) != ok) 0 0 0
1119 {
1120 0 Cache_FreeContent (r, pItem) ;
1121 0 return rc ;
1122 }
1123 }
1124  
1125 0 ▶ if (!pItem -> pSVData)
Branch: 1 branch
BranchTrueFalseTotal
if (!pItem -> pSVData) 0 0 0
1126 {
1127 0 ▶ if ((r -> Component.Config.bDebug & dbgCache) && !bUpdate)
Branch: 2 branches
BranchTrueFalseTotal
if ((r -> Component.Config.bDebug & dbgCache) && !bUpdate) 0 0 0
if ((r -> Component.Config.bDebug & dbgCache) && !bUpdate) 0 0 0
1128 0 lprintf (r -> pApp, "[%d]CACHE: %s get from provider\n", r -> pThread -> nPid, pItem -> sKey) ;
1129 0 ▶ if (pItem -> pProvider -> pProviderClass -> fGetContentSV)
Branch: 1 branch
BranchTrueFalseTotal
if (pItem -> pProvider -> pProviderClass -> fGetContentSV) 0 0 0
1130 0 ▶ if ((rc = (*pItem -> pProvider -> pProviderClass -> fGetContentSV) (r, pItem -> pProvider, pSVData, FALSE)) != ok)
Branch: 1 branch
BranchTrueFalseTotal
if ((rc = (*pItem -> pProvider -> pProviderClass -> fGetContentSV) (r, pItem -> pProvider, pSVData, FALSE)) != ok) 0 0 0
1131 {
1132 0 Cache_FreeContent (r, pItem) ;
1133 0 return rc ;
1134 }
1135 0 pItem -> pSVData = *pSVData ;
1136 0 bUpdate = TRUE ;
1137 }
1138 else
1139 0 *pSVData = pItem -> pSVData ;
1140  
1141 0 ▶ if (bUpdate)
Branch: 1 branch
BranchTrueFalseTotal
if (bUpdate) 0 0 0
1142 {
1143 0 Cache_SetNotExpired (r, pItem) ;
1144 }
1145 else
1146 {
1147 0 ▶ if (r -> Component.Config.bDebug & dbgCache)
Branch: 1 branch
BranchTrueFalseTotal
if (r -> Component.Config.bDebug & dbgCache) 0 0 0
1148 0 lprintf (r -> pApp, "[%d]CACHE: %s taken from cache\n", r -> pThread -> nPid, pItem -> sKey) ;
1149 }
1150 0 return ok ;
1151 }
1152  
1153 /* ------------------------------------------------------------------------ */
1154 /* */
1155 /* Cache_ReleaseContent */
1156 /* */
1157 /*!
1158 * \_en
1159 * Removes the read and/or write lock from the content.
1160 *
1161 * @param r Embperl request record
1162 * @param pItem CacheItem which should be checked
1163 * @return error code
1164 * \endif
1165 *
1166 * \_de
1167 * Gibt den Read und/oder Write Lock wieder frei.
1168 *
1169 * @param r Embperl request record
1170 * @param pItem CacheItem welches überprüft werden soll
1171 * @return Fehlercode
1172 * \endif
1173 *
1174 * ------------------------------------------------------------------------ */
1175  
1176  
1177  
1178 0 int Cache_ReleaseContent (/*in*/ req * r,
1179 /*in*/ tCacheItem *pItem)
1180  
1181 {
1182 /* locking not yet implemented */
1183 tCacheItem * pSubItem ;
1184 int i ;
1185 0 ▶ int numItems = pItem -> pDependsOn?ArrayGetSize (r -> pApp, pItem -> pDependsOn):0 ;
Branch: 1 branch
BranchTrueFalseTotal
int numItems = pItem -> pDependsOn?ArrayGetSize (r -> pApp, pItem -> pDependsOn):0 ; 0 0 0
1186  
1187 0 ▶ if (!pItem -> bCache)
Branch: 1 branch
BranchTrueFalseTotal
if (!pItem -> bCache) 0 0 0
1188 0 Cache_FreeContent (r, pItem) ;
1189  
1190 0 ▶ for (i = 0; i < numItems; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < numItems; i++) 0 0 0
1191 {
1192 0 pSubItem = pItem -> pDependsOn[i] ;
1193 0 Cache_ReleaseContent (r, pSubItem) ;
1194 }
1195  
1196 0 return ok ;
1197 }
1198  
1199  
1200 /* ------------------------------------------------------------------------ */
1201 /* */
1202 /* Cache_FreeContent */
1203 /* */
1204 /*!
1205 * \_en
1206 * Free the cached data
1207 *
1208 * @param r Embperl request record
1209 * @param pItem CacheItem
1210 * @return error code
1211 * \endif
1212 *
1213 * \_de
1214 * Gibt die gecachten Daten frei
1215 *
1216 * @param r Embperl request record
1217 * @param pItem CacheItem
1218 * @return Fehlercode
1219 * \endif
1220 *
1221 * ------------------------------------------------------------------------ */
1222  
1223  
1224  
1225 0 int Cache_FreeContent (/*in*/ req * r,
1226 /*in*/ tCacheItem *pItem)
1227  
1228 {
1229 epTHX_
1230 int rc ;
1231
1232 0 ▶ if ((r -> Component.Config.bDebug & dbgCache) && (pItem -> pSVData || pItem -> pData || pItem -> xData))
Branch: 4 branches
BranchTrueFalseTotal
if ((r -> Component.Config.bDebug & dbgCache) && (pItem -> pSVData || pItem -> pData || pItem -> xData)) 0 0 0
if ((r -> Component.Config.bDebug & dbgCache) && (pItem -> pSVData || pItem -> pData || pItem -> xData)) 0 0 0
if ((r -> Component.Config.bDebug & dbgCache) && (pItem -> pSVData || pItem -> pData || pItem -> xData)) 0 0 0
if ((r -> Component.Config.bDebug & dbgCache) && (pItem -> pSVData || pItem -> pData || pItem -> xData)) 0 0 0
1233 0 lprintf (r -> pApp, "[%d]CACHE: Free content for %s\n", r -> pThread -> nPid, pItem -> sKey) ;
1234  
1235 0 ▶ if (pItem -> pProvider -> pProviderClass -> fFreeContent)
Branch: 1 branch
BranchTrueFalseTotal
if (pItem -> pProvider -> pProviderClass -> fFreeContent) 0 0 0
1236 0 ▶ if ((rc = (*pItem -> pProvider -> pProviderClass -> fFreeContent) (r, pItem)) != ok)
Branch: 1 branch
BranchTrueFalseTotal
if ((rc = (*pItem -> pProvider -> pProviderClass -> fFreeContent) (r, pItem)) != ok) 0 0 0
1237 0 return rc ;
1238
1239 0 ▶ if (pItem -> pSVData)
Branch: 1 branch
BranchTrueFalseTotal
if (pItem -> pSVData) 0 0 0
1240 {
1241 0 SvREFCNT_dec (pItem -> pSVData) ;
1242 0 pItem -> pSVData = NULL ;
1243 }
1244 0 pItem -> pData = NULL ;
1245 0 pItem -> xData = 0 ;
1246  
1247 0 return ok ;
1248 }
1249  
1250  
« Syntax.xs ↑ Summary epcfg.h »