| 1 |
|
| MODULE = Punk PACKAGE = Punk::App |
| 2 |
|
| |
| 3 |
|
| PROTOTYPES: DISABLE |
| 4 |
|
| |
| 5 |
|
| # The boot compiler, in C (punk_compile.h). compile() freezes the registrar's |
| 6 |
|
| # accumulation into the state hash punk_serve.h reads and returns the PSGI app; |
| 7 |
|
| # the resolver, the docs targets, the app itself and the nonblocking Future |
| 8 |
|
| # chain are all real closures built with the magic-CV primitive. |
| 9 |
|
| |
| 10 |
|
| SV * |
| 11 |
|
| _resolve_target(self, target, what = &PL_sv_undef) |
| 12 |
|
| SV *self |
| 13 |
|
| SV *target |
| 14 |
|
| SV *what |
| 15 |
|
| CODE: |
| 16 |
61423 |
| RETVAL = pc_resolve_target(aTHX_ self, target, what); |
| 17 |
|
| OUTPUT: |
| 18 |
|
| RETVAL |
| 19 |
|
| |
| 20 |
|
| SV * |
| 21 |
|
| _context_class(self) |
| 22 |
|
| SV *self |
| 23 |
|
| CODE: |
| 24 |
0 |
| RETVAL = pc_context_class(aTHX_ self); |
| 25 |
|
| OUTPUT: |
| 26 |
|
| RETVAL |
| 27 |
|
| |
| 28 |
|
| SV * |
| 29 |
|
| _db_opts_for(self, class) |
| 30 |
|
| SV *self |
| 31 |
|
| SV *class |
| 32 |
|
| CODE: |
| 33 |
0 |
| RETVAL = pc_db_opts_for(aTHX_ self, class); |
| 34 |
|
| OUTPUT: |
| 35 |
|
| RETVAL |
| 36 |
|
| |
| 37 |
|
| void |
| 38 |
|
| _compile_models(self) |
| 39 |
|
| SV *self |
| 40 |
|
| CODE: |
| 41 |
5 |
| pc_compile_models(aTHX_ self); |
| 42 |
|
| |
| 43 |
|
| SV * |
| 44 |
|
| _docs_routes(self, api_mounts) |
| 45 |
|
| SV *self |
| 46 |
|
| SV *api_mounts |
| 47 |
|
| CODE: |
| 48 |
|
| { |
| 49 |
0 |
▶ | AV *am = (SvROK(api_mounts) && SvTYPE(SvRV(api_mounts)) == SVt_PVAV) |
Branch: 1 branch
| Branch | True | False | Total |
| AV *am = (SvROK(api_mounts) && SvTYPE(SvRV(api_mounts)) == SVt_PVAV) |
0 |
0 |
0 |
|
| 50 |
0 |
▶ | ? (AV *)SvRV(api_mounts) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| ? (AV *)SvRV(api_mounts) : NULL; |
0 |
0 |
0 |
|
| 51 |
0 |
| RETVAL = newRV_inc((SV *)pc_docs_routes(aTHX_ self, am)); |
| 52 |
|
| } |
| 53 |
|
| OUTPUT: |
| 54 |
|
| RETVAL |
| 55 |
|
| |
| 56 |
|
| # The per-worker model instance: built on first use, cached until the pid |
| 57 |
|
| # changes (fork-safe). |
| 58 |
|
| SV * |
| 59 |
|
| model_instance(self, name) |
| 60 |
|
| SV *self |
| 61 |
|
| SV *name |
| 62 |
|
| CODE: |
| 63 |
|
| { |
| 64 |
133 |
| HV *h = app_hv(aTHX_ self); |
| 65 |
133 |
| STRLEN nl; const char *n = SvPV_const(name, nl); |
| 66 |
133 |
| SV **regp = hv_fetchs(h, K_MODELS_C, 0); |
| 67 |
|
| HV *reg, *cache; SV **classp, **cachep, **pidp, **inst; |
| 68 |
133 |
| IV pid = (IV)PerlProc_getpid(); |
| 69 |
133 |
▶ | if (!(regp && *regp && SvROK(*regp))) |
Branch: 3 branches
| Branch | True | False | Total |
| if (!(regp && *regp && SvROK(*regp))) |
132 |
1 |
133 |
| if (!(regp && *regp && SvROK(*regp))) |
132 |
0 |
132 |
| if (!(regp && *regp && SvROK(*regp))) |
0 |
132 |
132 |
|
| 70 |
1 |
| croak("Punk: no model registered - add database/model keywords"); |
| 71 |
132 |
| reg = (HV *)SvRV(*regp); |
| 72 |
132 |
| classp = hv_fetch(reg, n, (I32)nl, 0); |
| 73 |
132 |
▶ | if (!(classp && *classp && SvOK(*classp))) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!(classp && *classp && SvOK(*classp))) { |
130 |
2 |
132 |
| if (!(classp && *classp && SvOK(*classp))) { |
130 |
0 |
130 |
| if (!(classp && *classp && SvOK(*classp))) { |
0 |
130 |
130 |
|
| 74 |
2 |
| AV *keys = app_sorted_keys(aTHX_ reg); |
| 75 |
2 |
| SV *have = sv_2mortal(newSVpvs("")); SSize_t i, m = av_len(keys) + 1; |
| 76 |
7 |
▶ | for (i = 0; i < m; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < m; i++) { |
5 |
2 |
7 |
|
| 77 |
5 |
▶ | if (i) sv_catpvs(have, ", "); |
Branch: 1 branch
| Branch | True | False | Total |
| if (i) sv_catpvs(have, ", "); |
3 |
2 |
5 |
|
| 78 |
5 |
| sv_catsv(have, *av_fetch(keys, i, 0)); |
| 79 |
|
| } |
| 80 |
2 |
| croak("Punk: no model '%s' registered (have: %s)", n, |
| 81 |
|
| SvPV_nolen(have)); |
| 82 |
|
| } |
| 83 |
130 |
| cachep = hv_fetchs(h, K_MODEL_CACHE, 0); |
| 84 |
130 |
▶ | if (cachep && *cachep && SvROK(*cachep)) cache = (HV *)SvRV(*cachep); |
Branch: 3 branches
| Branch | True | False | Total |
| if (cachep && *cachep && SvROK(*cachep)) cache = (HV *)SvRV(*cachep); |
109 |
21 |
130 |
| if (cachep && *cachep && SvROK(*cachep)) cache = (HV *)SvRV(*cachep); |
109 |
0 |
109 |
| if (cachep && *cachep && SvROK(*cachep)) cache = (HV *)SvRV(*cachep); |
109 |
0 |
109 |
|
| 85 |
|
| else { |
| 86 |
21 |
| cache = newHV(); |
| 87 |
21 |
| (void)hv_stores(cache, K_PID, newSViv(-1)); |
| 88 |
21 |
| (void)hv_stores(h, K_MODEL_CACHE, newRV_noinc((SV *)cache)); |
| 89 |
|
| } |
| 90 |
130 |
| pidp = hv_fetchs(cache, K_PID, 0); |
| 91 |
130 |
▶ | if (!(pidp && *pidp && SvIV(*pidp) == pid)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!(pidp && *pidp && SvIV(*pidp) == pid)) { |
130 |
0 |
130 |
| if (!(pidp && *pidp && SvIV(*pidp) == pid)) { |
130 |
0 |
130 |
| if (!(pidp && *pidp && SvIV(*pidp) == pid)) { |
21 |
109 |
130 |
|
| 92 |
21 |
| hv_clear(cache); |
| 93 |
21 |
| (void)hv_stores(cache, K_PID, newSViv(pid)); |
| 94 |
|
| } |
| 95 |
130 |
| inst = hv_fetch(cache, n, (I32)nl, 0); |
| 96 |
130 |
▶ | if (inst && *inst && SvTRUE(*inst)) RETVAL = newSVsv(*inst); |
Branch: 3 branches
| Branch | True | False | Total |
| if (inst && *inst && SvTRUE(*inst)) RETVAL = newSVsv(*inst); |
102 |
28 |
130 |
| if (inst && *inst && SvTRUE(*inst)) RETVAL = newSVsv(*inst); |
102 |
0 |
102 |
| if (inst && *inst && SvTRUE(*inst)) RETVAL = newSVsv(*inst); |
102 |
0 |
102 |
|
| 97 |
|
| else { |
| 98 |
28 |
| SV *opts = pc_db_opts_for(aTHX_ self, *classp); |
| 99 |
|
| SV *argv[2], *obj; |
| 100 |
27 |
| argv[0] = sv_2mortal(opts); |
| 101 |
27 |
| argv[1] = self; |
| 102 |
27 |
| obj = pcx_call_meth(aTHX_ *classp, "_instantiate", argv, 2, 1); |
| 103 |
27 |
▶ | (void)hv_store(cache, n, (I32)nl, |
Branch: 1 branch
| Branch | True | False | Total |
| (void)hv_store(cache, n, (I32)nl, |
27 |
0 |
27 |
|
| 104 |
|
| obj ? SvREFCNT_inc(obj) : newSV(0), 0); |
| 105 |
27 |
▶ | RETVAL = obj ? obj : newSV(0); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = obj ? obj : newSV(0); |
0 |
27 |
27 |
|
| 106 |
|
| } |
| 107 |
|
| } |
| 108 |
|
| OUTPUT: |
| 109 |
|
| RETVAL |
| 110 |
|
| |
| 111 |
|
| # $self->render_view($c, @args) -> the view engine's finished response. |
| 112 |
|
| SV * |
| 113 |
|
| render_view(self, ...) |
| 114 |
|
| SV *self |
| 115 |
|
| CODE: |
| 116 |
|
| { |
| 117 |
2166 |
| HV *h = app_hv(aTHX_ self); |
| 118 |
2166 |
| SV **vc = hv_fetchs(h, K_VIEWS_C, 0); |
| 119 |
2166 |
| int nargs = items - 1, i; |
| 120 |
|
| SV **argv; |
| 121 |
2166 |
▶ | if (!(vc && *vc && SvOK(*vc))) |
Branch: 3 branches
| Branch | True | False | Total |
| if (!(vc && *vc && SvOK(*vc))) |
2166 |
0 |
2166 |
| if (!(vc && *vc && SvOK(*vc))) |
2166 |
0 |
2166 |
| if (!(vc && *vc && SvOK(*vc))) |
1 |
2165 |
2166 |
|
| 122 |
1 |
| croak("Punk: no view engine configured - add a views keyword"); |
| 123 |
2165 |
▶ | Newx(argv, nargs > 0 ? nargs : 1, SV *); |
Branch: 1 branch
| Branch | True | False | Total |
| Newx(argv, nargs > 0 ? nargs : 1, SV *); |
2165 |
0 |
2165 |
|
| 124 |
6607 |
▶ | for (i = 0; i < nargs; i++) argv[i] = ST(i + 1); |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < nargs; i++) argv[i] = ST(i + 1); |
4442 |
2165 |
6607 |
|
| 125 |
2165 |
| RETVAL = pcx_call_meth(aTHX_ *vc, "render", argv, nargs, 1); |
| 126 |
2156 |
| Safefree(argv); |
| 127 |
2156 |
▶ | if (!RETVAL) RETVAL = newSV(0); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!RETVAL) RETVAL = newSV(0); |
0 |
2156 |
2156 |
|
| 128 |
|
| } |
| 129 |
|
| OUTPUT: |
| 130 |
|
| RETVAL |
| 131 |
|
| |
| 132 |
|
| # $on_error->($c,$err) coerced, or the 500 default. |
| 133 |
|
| SV * |
| 134 |
|
| _handle_error(self, c, err, on_error = &PL_sv_undef) |
| 135 |
|
| SV *self |
| 136 |
|
| SV *c |
| 137 |
|
| SV *err |
| 138 |
|
| SV *on_error |
| 139 |
|
| CODE: |
| 140 |
|
| PERL_UNUSED_VAR(self); |
| 141 |
0 |
▶ | RETVAL = punk_handle_error(aTHX_ c, err, SvOK(on_error) ? on_error : NULL); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = punk_handle_error(aTHX_ c, err, SvOK(on_error) ? on_error : NULL); |
0 |
0 |
0 |
|
| 142 |
|
| OUTPUT: |
| 143 |
|
| RETVAL |
| 144 |
|
| |
| 145 |
|
| # The one Perl-shaped piece of the finish path: a handler that returned a |
| 146 |
|
| # Future. On a nonblocking server hand back the ->then chain (built as two |
| 147 |
|
| # magic-CV closures); otherwise await it and finish inline. |
| 148 |
|
| SV * |
| 149 |
|
| _finish_future(self, c, ret, on_error = &PL_sv_undef, method = &PL_sv_undef, after = &PL_sv_undef) |
| 150 |
|
| SV *self |
| 151 |
|
| SV *c |
| 152 |
|
| SV *ret |
| 153 |
|
| SV *on_error |
| 154 |
|
| SV *method |
| 155 |
|
| SV *after |
| 156 |
|
| CODE: |
| 157 |
|
| { |
| 158 |
37 |
| AV *cav = pcx_av(aTHX_ c); |
| 159 |
37 |
| SV *envsv = pcx_get(aTHX_ cav, PCX_ENV); |
| 160 |
37 |
▶ | HV *env = (envsv && SvROK(envsv)) ? (HV *)SvRV(envsv) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| HV *env = (envsv && SvROK(envsv)) ? (HV *)SvRV(envsv) : NULL; |
37 |
0 |
37 |
| HV *env = (envsv && SvROK(envsv)) ? (HV *)SvRV(envsv) : NULL; |
37 |
0 |
37 |
|
| 161 |
37 |
▶ | SV **nb = env ? hv_fetchs(env, "psgi.nonblocking", 0) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| SV **nb = env ? hv_fetchs(env, "psgi.nonblocking", 0) : NULL; |
37 |
0 |
37 |
|
| 162 |
37 |
▶ | SV **st = env ? hv_fetchs(env, "psgi.streaming", 0) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| SV **st = env ? hv_fetchs(env, "psgi.streaming", 0) : NULL; |
37 |
0 |
37 |
|
| 163 |
37 |
▶ | int nonblocking = (nb && *nb && SvTRUE(*nb)); |
Branch: 3 branches
| Branch | True | False | Total |
| int nonblocking = (nb && *nb && SvTRUE(*nb)); |
14 |
23 |
37 |
| int nonblocking = (nb && *nb && SvTRUE(*nb)); |
14 |
0 |
14 |
| int nonblocking = (nb && *nb && SvTRUE(*nb)); |
14 |
0 |
14 |
|
| 164 |
37 |
▶ | int streaming = (st && *st && SvTRUE(*st)); |
Branch: 3 branches
| Branch | True | False | Total |
| int streaming = (st && *st && SvTRUE(*st)); |
4 |
33 |
37 |
| int streaming = (st && *st && SvTRUE(*st)); |
4 |
0 |
4 |
| int streaming = (st && *st && SvTRUE(*st)); |
4 |
0 |
4 |
|
| 165 |
37 |
▶ | int can_then = (SvROK(ret) && SvOBJECT(SvRV(ret)) |
Branch: 1 branch
| Branch | True | False | Total |
| int can_then = (SvROK(ret) && SvOBJECT(SvRV(ret)) |
37 |
0 |
37 |
|
| 166 |
74 |
▶ | && pcx_can(aTHX_ ret, "then")); |
Branch: 2 branches
| Branch | True | False | Total |
| && pcx_can(aTHX_ ret, "then")); |
37 |
0 |
37 |
| && pcx_can(aTHX_ ret, "then")); |
37 |
0 |
37 |
|
| 167 |
|
| PERL_UNUSED_VAR(self); |
| 168 |
40 |
▶ | if (nonblocking && can_then && streaming) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (nonblocking && can_then && streaming) { |
14 |
23 |
37 |
| if (nonblocking && can_then && streaming) { |
14 |
0 |
14 |
| if (nonblocking && can_then && streaming) { |
3 |
11 |
14 |
|
| 169 |
|
| /* the standard delayed response: middleware between Punk and the |
| 170 |
|
| * server (plackup's Lint, this app's own `middleware`) passes a |
| 171 |
|
| * coderef through where a raw Future would kill the request */ |
| 172 |
3 |
| AV *cap = newAV(); |
| 173 |
3 |
| av_push(cap, newSVsv(c)); |
| 174 |
3 |
| av_push(cap, newSVsv(ret)); |
| 175 |
3 |
▶ | av_push(cap, SvOK(on_error) ? newSVsv(on_error) : newSV(0)); |
Branch: 1 branch
| Branch | True | False | Total |
| av_push(cap, SvOK(on_error) ? newSVsv(on_error) : newSV(0)); |
0 |
3 |
3 |
|
| 176 |
3 |
| av_push(cap, newSVsv(method)); |
| 177 |
3 |
▶ | av_push(cap, SvOK(after) ? newSVsv(after) |
Branch: 1 branch
| Branch | True | False | Total |
| av_push(cap, SvOK(after) ? newSVsv(after) |
3 |
0 |
3 |
|
| 178 |
|
| : newRV_noinc((SV *)newAV())); |
| 179 |
3 |
| RETVAL = punk_closure(aTHX_ pc_ffs_cb, cap); |
| 180 |
|
| } |
| 181 |
|
| /* One of ours: the class is known, so the two probes above and the |
| 182 |
|
| * method call below are all answers we already have. Chain it in C - |
| 183 |
|
| * one closure and one capture instead of three of each. A subclass |
| 184 |
|
| * misses the stash compare and takes the general path, which is |
| 185 |
|
| * slower and correct. */ |
| 186 |
39 |
▶ | else if (nonblocking && can_then && pcx_is_punk_future(aTHX_ ret)) { |
Branch: 3 branches
| Branch | True | False | Total |
| else if (nonblocking && can_then && pcx_is_punk_future(aTHX_ ret)) { |
11 |
23 |
34 |
| else if (nonblocking && can_then && pcx_is_punk_future(aTHX_ ret)) { |
11 |
0 |
11 |
| else if (nonblocking && can_then && pcx_is_punk_future(aTHX_ ret)) { |
5 |
6 |
11 |
|
| 187 |
5 |
| AV *cap = newAV(); |
| 188 |
|
| SV *clos; |
| 189 |
5 |
| punk_future *pg = pf_new(aTHX); |
| 190 |
5 |
| RETVAL = pf_bless(aTHX_ pg, "Punk::Future"); |
| 191 |
5 |
| av_push(cap, newSVsv(c)); |
| 192 |
5 |
▶ | av_push(cap, SvOK(on_error) ? newSVsv(on_error) : newSV(0)); |
Branch: 1 branch
| Branch | True | False | Total |
| av_push(cap, SvOK(on_error) ? newSVsv(on_error) : newSV(0)); |
0 |
5 |
5 |
|
| 193 |
5 |
| av_push(cap, newSVsv(method)); |
| 194 |
5 |
▶ | av_push(cap, SvOK(after) ? newSVsv(after) |
Branch: 1 branch
| Branch | True | False | Total |
| av_push(cap, SvOK(after) ? newSVsv(after) |
5 |
0 |
5 |
|
| 195 |
|
| : newRV_noinc((SV *)newAV())); |
| 196 |
5 |
| av_push(cap, newSVsv(RETVAL)); |
| 197 |
5 |
| clos = sv_2mortal(punk_closure(aTHX_ pc_ff_both_cb, cap)); |
| 198 |
5 |
| pf_react(aTHX_ pf_of(aTHX_ ret), ret, PFR_ON_READY, clos); |
| 199 |
|
| } |
| 200 |
35 |
▶ | else if (nonblocking && can_then) { |
Branch: 2 branches
| Branch | True | False | Total |
| else if (nonblocking && can_then) { |
6 |
23 |
29 |
| else if (nonblocking && can_then) { |
6 |
0 |
6 |
|
| 201 |
6 |
| AV *cd = newAV(), *cf = newAV(); |
| 202 |
|
| SV *done, *fail, *argv[2]; |
| 203 |
|
| int j; |
| 204 |
|
| /* Does the app's future come from CPAN's Future? Then its `then` |
| 205 |
|
| * requires the callback to hand back a Future, and older |
| 206 |
|
| * releases enforce that strictly (CPAN Testers, 0.16, perls |
| 207 |
|
| * 5.20/5.22/5.24). Punk::Future's `then` takes the value |
| 208 |
|
| * directly and has no class-level `done` to wrap with, so the |
| 209 |
|
| * two are told apart once, here, rather than per callback. */ |
| 210 |
6 |
▶ | int wrap = (SvROK(ret) && sv_derived_from(ret, "Future")); |
Branch: 2 branches
| Branch | True | False | Total |
| int wrap = (SvROK(ret) && sv_derived_from(ret, "Future")); |
6 |
0 |
6 |
| int wrap = (SvROK(ret) && sv_derived_from(ret, "Future")); |
6 |
0 |
6 |
|
| 211 |
18 |
▶ | for (j = 0; j < 2; j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (j = 0; j < 2; j++) { |
12 |
6 |
18 |
|
| 212 |
12 |
▶ | AV *cap = j ? cf : cd; |
Branch: 1 branch
| Branch | True | False | Total |
| AV *cap = j ? cf : cd; |
6 |
6 |
12 |
|
| 213 |
12 |
| av_push(cap, newSVsv(c)); |
| 214 |
12 |
▶ | av_push(cap, SvOK(on_error) ? newSVsv(on_error) : newSV(0)); |
Branch: 1 branch
| Branch | True | False | Total |
| av_push(cap, SvOK(on_error) ? newSVsv(on_error) : newSV(0)); |
0 |
12 |
12 |
|
| 215 |
12 |
| av_push(cap, newSVsv(method)); |
| 216 |
12 |
▶ | av_push(cap, SvOK(after) ? newSVsv(after) |
Branch: 1 branch
| Branch | True | False | Total |
| av_push(cap, SvOK(after) ? newSVsv(after) |
12 |
0 |
12 |
|
| 217 |
|
| : newRV_noinc((SV *)newAV())); |
| 218 |
12 |
| av_push(cap, newSViv(wrap)); |
| 219 |
|
| } |
| 220 |
6 |
| done = sv_2mortal(punk_closure(aTHX_ pc_ff_done_cb, cd)); |
| 221 |
6 |
| fail = sv_2mortal(punk_closure(aTHX_ pc_ff_fail_cb, cf)); |
| 222 |
6 |
| argv[0] = done; argv[1] = fail; |
| 223 |
6 |
| RETVAL = pcx_call_meth(aTHX_ ret, "then", argv, 2, 1); |
| 224 |
6 |
▶ | if (!RETVAL) RETVAL = &PL_sv_undef; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!RETVAL) RETVAL = &PL_sv_undef; |
0 |
6 |
6 |
|
| 225 |
|
| } |
| 226 |
|
| else { |
| 227 |
23 |
| dSP; int count; SV *got, *resp; int died, is_head; |
| 228 |
23 |
| AV *aft = pc_after_of(aTHX_ after); |
| 229 |
23 |
| ENTER; SAVETMPS; |
| 230 |
23 |
▶ | PUSHMARK(SP); EXTEND(SP, 1); PUSHs(ret); PUTBACK; |
Branch: 2 branches
| Branch | True | False | Total |
| PUSHMARK(SP); EXTEND(SP, 1); PUSHs(ret); PUTBACK; |
0 |
23 |
23 |
| PUSHMARK(SP); EXTEND(SP, 1); PUSHs(ret); PUTBACK; |
0 |
23 |
23 |
|
| 231 |
23 |
| count = call_method("get", G_SCALAR | G_EVAL); |
| 232 |
23 |
| SPAGAIN; |
| 233 |
23 |
▶ | got = count > 0 ? SvREFCNT_inc(POPs) : &PL_sv_undef; |
Branch: 1 branch
| Branch | True | False | Total |
| got = count > 0 ? SvREFCNT_inc(POPs) : &PL_sv_undef; |
23 |
0 |
23 |
|
| 234 |
23 |
▶ | PUTBACK; FREETMPS; LEAVE; |
Branch: 1 branch
| Branch | True | False | Total |
| PUTBACK; FREETMPS; LEAVE; |
23 |
0 |
23 |
|
| 235 |
23 |
▶ | died = SvTRUE(ERRSV) ? 1 : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| died = SvTRUE(ERRSV) ? 1 : 0; |
23 |
0 |
23 |
|
| 236 |
23 |
| is_head = pc_is_head(aTHX_ method); |
| 237 |
5 |
▶ | resp = died ? punk_handle_error(aTHX_ c, ERRSV, |
Branch: 1 branch
| Branch | True | False | Total |
| resp = died ? punk_handle_error(aTHX_ c, ERRSV, |
5 |
0 |
5 |
|
| 238 |
5 |
▶ | SvOK(on_error) ? on_error : NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| SvOK(on_error) ? on_error : NULL) |
0 |
5 |
5 |
|
| 239 |
23 |
▶ | : punk_coerce(aTHX_ c, got); |
Branch: 1 branch
| Branch | True | False | Total |
| : punk_coerce(aTHX_ c, got); |
5 |
18 |
23 |
|
| 240 |
23 |
| RETVAL = punk_deliver(aTHX_ c, resp, is_head, aft); |
| 241 |
23 |
| SvREFCNT_dec(resp); |
| 242 |
23 |
▶ | if (got != &PL_sv_undef) SvREFCNT_dec(got); |
Branch: 1 branch
| Branch | True | False | Total |
| if (got != &PL_sv_undef) SvREFCNT_dec(got); |
18 |
5 |
23 |
|
| 243 |
|
| } |
| 244 |
|
| } |
| 245 |
|
| OUTPUT: |
| 246 |
|
| RETVAL |
| 247 |
|
| |
| 248 |
|
| # compile(): resolve and freeze everything into the state hash and return the |
| 249 |
|
| # PSGI app (a magic-CV closure over the state). |
| 250 |
|
| SV * |
| 251 |
|
| compile(self) |
| 252 |
|
| SV *self |
| 253 |
|
| CODE: |
| 254 |
|
| { |
| 255 |
676 |
| HV *h = app_hv(aTHX_ self); |
| 256 |
676 |
| SV *caller = app_get(aTHX_ h, K_CALLER); |
| 257 |
676 |
| AV *rcap = newAV(); |
| 258 |
|
| |
| 259 |
|
| /* The on_compile callbacks, FIRST: every keyword has recorded and |
| 260 |
|
| * nothing is compiled yet, so a callback may still use the registrar |
| 261 |
|
| * - read the databases, add a route, a hook or a helper - and what |
| 262 |
|
| * it adds is compiled below with the rest. In registration order; a |
| 263 |
|
| * die is this boot croak, naming the owner. */ |
| 264 |
|
| { |
| 265 |
676 |
| SV **lp = hv_fetchs(h, K_ON_COMPILE, 0); |
| 266 |
676 |
▶ | if (lp && *lp && SvROK(*lp) && SvTYPE(SvRV(*lp)) == SVt_PVAV) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (lp && *lp && SvROK(*lp) && SvTYPE(SvRV(*lp)) == SVt_PVAV) { |
6 |
670 |
676 |
| if (lp && *lp && SvROK(*lp) && SvTYPE(SvRV(*lp)) == SVt_PVAV) { |
6 |
0 |
6 |
| if (lp && *lp && SvROK(*lp) && SvTYPE(SvRV(*lp)) == SVt_PVAV) { |
6 |
0 |
6 |
| if (lp && *lp && SvROK(*lp) && SvTYPE(SvRV(*lp)) == SVt_PVAV) { |
6 |
0 |
6 |
|
| 267 |
6 |
| AV *list = (AV *)SvRV(*lp); |
| 268 |
6 |
| SSize_t i, n = av_len(list) + 1; |
| 269 |
11 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
7 |
4 |
11 |
|
| 270 |
7 |
| SV **rp = av_fetch(list, i, 0); |
| 271 |
|
| AV *rec; SV **code, **owner; |
| 272 |
7 |
| dSP; int count; |
| 273 |
7 |
▶ | if (!(rp && *rp && SvROK(*rp))) continue; |
Branch: 3 branches
| Branch | True | False | Total |
| if (!(rp && *rp && SvROK(*rp))) continue; |
7 |
0 |
7 |
| if (!(rp && *rp && SvROK(*rp))) continue; |
7 |
0 |
7 |
| if (!(rp && *rp && SvROK(*rp))) continue; |
0 |
7 |
7 |
|
| 274 |
7 |
| rec = (AV *)SvRV(*rp); |
| 275 |
7 |
| code = av_fetch(rec, 0, 0); |
| 276 |
7 |
| owner = av_fetch(rec, 1, 0); |
| 277 |
7 |
| ENTER; SAVETMPS; |
| 278 |
7 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
7 |
7 |
|
| 279 |
7 |
▶ | XPUSHs(self); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(self); |
0 |
7 |
7 |
|
| 280 |
7 |
| PUTBACK; |
| 281 |
7 |
| count = call_sv(*code, G_VOID | G_EVAL); |
| 282 |
7 |
| SPAGAIN; |
| 283 |
7 |
| SP -= count; |
| 284 |
7 |
| PUTBACK; |
| 285 |
7 |
▶ | if (SvTRUE(ERRSV)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvTRUE(ERRSV)) { |
7 |
0 |
7 |
| if (SvTRUE(ERRSV)) { |
2 |
5 |
7 |
|
| 286 |
|
| /* copied BEFORE the frame closes, made mortal AFTER: |
| 287 |
|
| * a mortal made inside the frame is freed by this |
| 288 |
|
| * FREETMPS before croak reads it */ |
| 289 |
2 |
▶ | SV *e = newSVsv(ERRSV); |
Branch: 1 branch
| Branch | True | False | Total |
| SV *e = newSVsv(ERRSV); |
2 |
0 |
2 |
|
| 290 |
2 |
▶ | FREETMPS; LEAVE; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; LEAVE; |
2 |
0 |
2 |
|
| 291 |
2 |
| sv_2mortal(e); |
| 292 |
4 |
▶ | croak("Punk: on_compile callback registered by %s died: %s", |
Branch: 2 branches
| Branch | True | False | Total |
| croak("Punk: on_compile callback registered by %s died: %s", |
2 |
0 |
2 |
| croak("Punk: on_compile callback registered by %s died: %s", |
2 |
0 |
2 |
|
| 293 |
|
| owner && *owner ? SvPV_nolen(*owner) : "?", |
| 294 |
|
| SvPV_nolen(e)); |
| 295 |
|
| } |
| 296 |
5 |
▶ | FREETMPS; LEAVE; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; LEAVE; |
3 |
2 |
5 |
|
| 297 |
|
| } |
| 298 |
|
| } |
| 299 |
|
| } |
| 300 |
|
| |
| 301 |
|
| /* Register the cross-worker bus subscription for every worker. |
| 302 |
|
| * |
| 303 |
|
| * HERE, at compile, because this runs in the PARENT before the server |
| 304 |
|
| * forks - which is the only place a registration can be made that |
| 305 |
|
| * every worker will inherit. The callback itself runs after the fork, |
| 306 |
|
| * on the process that will serve, which is the only place a |
| 307 |
|
| * subscription can usefully live. |
| 308 |
|
| * |
| 309 |
|
| * A no-op when there is no Hyperman, or one too old for the bus. */ |
| 310 |
674 |
| punk_bus_register(aTHX); |
| 311 |
|
| |
| 312 |
|
| /* The cache stores, built HERE so a bad backend name, an |
| 313 |
|
| * unparseable max_bytes or an unwritable directory croak at boot |
| 314 |
|
| * rather than on the first miss - and so every request on this |
| 315 |
|
| * worker shares one store per name, since a cache constructed per |
| 316 |
|
| * request never hits. */ |
| 317 |
|
| { |
| 318 |
674 |
| SV **spec = hv_fetchs(h, "cache_spec", 0); |
| 319 |
674 |
▶ | if (spec && *spec && SvROK(*spec) |
Branch: 3 branches
| Branch | True | False | Total |
| if (spec && *spec && SvROK(*spec) |
37 |
637 |
674 |
| if (spec && *spec && SvROK(*spec) |
37 |
0 |
37 |
| if (spec && *spec && SvROK(*spec) |
37 |
0 |
37 |
|
| 320 |
37 |
▶ | && SvTYPE(SvRV(*spec)) == SVt_PVHV) { |
Branch: 1 branch
| Branch | True | False | Total |
| && SvTYPE(SvRV(*spec)) == SVt_PVHV) { |
37 |
0 |
37 |
|
| 321 |
37 |
| HV *specs = (HV *)SvRV(*spec); |
| 322 |
37 |
| HV *built = newHV(); |
| 323 |
|
| HE *e; |
| 324 |
37 |
| hv_iterinit(specs); |
| 325 |
75 |
▶ | while ((e = hv_iternext(specs))) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ((e = hv_iternext(specs))) { |
41 |
34 |
75 |
|
| 326 |
41 |
| AV *rec = (AV *)SvRV(HeVAL(e)); |
| 327 |
41 |
| SV **backend = av_fetch(rec, 0, 0); |
| 328 |
41 |
| SV **opts = av_fetch(rec, 1, 0); |
| 329 |
|
| SV *argv[3], *store; |
| 330 |
41 |
▶ | argv[0] = backend && *backend ? *backend : &PL_sv_undef; |
Branch: 2 branches
| Branch | True | False | Total |
| argv[0] = backend && *backend ? *backend : &PL_sv_undef; |
41 |
0 |
41 |
| argv[0] = backend && *backend ? *backend : &PL_sv_undef; |
41 |
0 |
41 |
|
| 331 |
41 |
▶ | argv[1] = opts && *opts ? *opts : &PL_sv_undef; |
Branch: 2 branches
| Branch | True | False | Total |
| argv[1] = opts && *opts ? *opts : &PL_sv_undef; |
41 |
0 |
41 |
| argv[1] = opts && *opts ? *opts : &PL_sv_undef; |
41 |
0 |
41 |
|
| 332 |
|
| /* The NAME as well. Without it the store cannot address |
| 333 |
|
| * its own invalidation topic, and cross-worker |
| 334 |
|
| * invalidation is silently off in the only case that |
| 335 |
|
| * matters - the one configured by the keyword. */ |
| 336 |
41 |
| argv[2] = sv_2mortal(newSVsv(hv_iterkeysv(e))); |
| 337 |
41 |
| (void)pk_require_once(aTHX_ "Punk::Cache", TRUE); |
| 338 |
41 |
| store = pcx_call_meth(aTHX_ |
| 339 |
|
| sv_2mortal(newSVpvs("Punk::Cache")), |
| 340 |
|
| "_from_spec", argv, 3, 1); |
| 341 |
38 |
▶ | (void)hv_store_ent(built, hv_iterkeysv(e), |
Branch: 1 branch
| Branch | True | False | Total |
| (void)hv_store_ent(built, hv_iterkeysv(e), |
0 |
38 |
38 |
|
| 342 |
|
| store ? store : newSV(0), 0); |
| 343 |
|
| } |
| 344 |
34 |
| (void)hv_stores(h, "cache", newRV_noinc((SV *)built)); |
| 345 |
|
| } |
| 346 |
|
| } |
| 347 |
|
| |
| 348 |
|
| /* A server-side session resolves HERE, after those stores exist, |
| 349 |
|
| * because `session store => 'sessions'` names one of them. Going |
| 350 |
|
| * first would find an empty hash and every declared store would look |
| 351 |
|
| * like a typo. A bad backend, an undeclared name or a store that is |
| 352 |
|
| * not shared between workers croak at boot, in front of whoever |
| 353 |
|
| * deployed it, rather than as a random logout later. */ |
| 354 |
671 |
| ps_store_resolve(aTHX_ h); |
| 355 |
|
| |
| 356 |
|
| SV *resolve, *router, *xs_router, *all_recs, *ctx, *app_cv, *state_rv; |
| 357 |
|
| HV *state; |
| 358 |
663 |
| AV *api_src = app_av(aTHX_ h, K_API_MOUNTS); |
| 359 |
663 |
| AV *api_mounts = (AV *)sv_2mortal((SV *)newAV()); |
| 360 |
663 |
| AV *state_apims = newAV(); |
| 361 |
663 |
| AV *mounts_out = newAV(); |
| 362 |
663 |
| AV *before_out = newAV(), *after_out = newAV(); |
| 363 |
663 |
| AV *before_req_out = newAV(); |
| 364 |
|
| AV *docs_extra, *mount_src, *mw; |
| 365 |
|
| SSize_t i, n; |
| 366 |
|
| SV **x; |
| 367 |
|
| |
| 368 |
663 |
| av_push(rcap, newSVsv(self)); |
| 369 |
663 |
| resolve = sv_2mortal(punk_closure(aTHX_ pc_resolve_cb, rcap)); |
| 370 |
|
| |
| 371 |
|
| /* api mounts: compile each, wrap as {mount,prefix,len}, order longest */ |
| 372 |
663 |
▶ | n = api_src ? av_len(api_src) + 1 : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| n = api_src ? av_len(api_src) + 1 : 0; |
663 |
0 |
663 |
|
| 373 |
690 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
29 |
661 |
690 |
|
| 374 |
29 |
| SV **mp = av_fetch(api_src, i, 0); |
| 375 |
29 |
▶ | SV *m = (mp && *mp) ? *mp : &PL_sv_undef; |
Branch: 2 branches
| Branch | True | False | Total |
| SV *m = (mp && *mp) ? *mp : &PL_sv_undef; |
29 |
0 |
29 |
| SV *m = (mp && *mp) ? *mp : &PL_sv_undef; |
29 |
0 |
29 |
|
| 376 |
|
| SV *argv[2], *pfx; HV *rec; |
| 377 |
29 |
| argv[0] = self; argv[1] = resolve; |
| 378 |
29 |
| { SV *r = pcx_call_meth(aTHX_ m, "compile", argv, 2, 0); |
| 379 |
27 |
▶ | if (r) SvREFCNT_dec(r); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (r) SvREFCNT_dec(r); } |
0 |
27 |
27 |
|
| 380 |
27 |
| pfx = sv_2mortal(pcx_call_meth(aTHX_ m, K_PREFIX, NULL, 0, 1)); |
| 381 |
27 |
| rec = newHV(); |
| 382 |
27 |
| (void)hv_stores(rec, K_MOUNT, newSVsv(m)); |
| 383 |
27 |
| (void)hv_stores(rec, K_PREFIX, newSVsv(pfx)); |
| 384 |
27 |
▶ | (void)hv_stores(rec, K_LEN, |
Branch: 1 branch
| Branch | True | False | Total |
| (void)hv_stores(rec, K_LEN, |
27 |
0 |
27 |
|
| 385 |
|
| newSViv(SvOK(pfx) ? (IV)SvCUR(pfx) : 0)); |
| 386 |
27 |
| av_push(api_mounts, newRV_noinc((SV *)rec)); |
| 387 |
|
| } |
| 388 |
661 |
▶ | if (av_len(api_mounts) >= 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (av_len(api_mounts) >= 0) |
27 |
634 |
661 |
|
| 389 |
27 |
| sortsv(AvARRAY(api_mounts), (STRLEN)(av_len(api_mounts) + 1), |
| 390 |
|
| pc_cmp_len_desc); |
| 391 |
|
| |
| 392 |
|
| /* router: compile with the docs routes folded in; take its records */ |
| 393 |
661 |
| docs_extra = pc_docs_routes(aTHX_ self, api_mounts); |
| 394 |
659 |
| router = app_get(aTHX_ h, K_ROUTER); |
| 395 |
|
| { |
| 396 |
|
| SV *argv[2]; |
| 397 |
659 |
| argv[0] = resolve; |
| 398 |
659 |
| argv[1] = sv_2mortal(newRV_inc((SV *)docs_extra)); |
| 399 |
659 |
| xs_router = sv_2mortal(pcx_call_meth(aTHX_ router, "compile", |
| 400 |
|
| argv, 2, 1)); |
| 401 |
|
| } |
| 402 |
651 |
| all_recs = sv_2mortal(pcx_call_meth(aTHX_ xs_router, "records", |
| 403 |
|
| NULL, 0, 1)); |
| 404 |
651 |
| ctx = sv_2mortal(pc_context_class(aTHX_ self)); |
| 405 |
|
| |
| 406 |
|
| /* websocket routes: mark the records, check the server can upgrade */ |
| 407 |
651 |
| x = hv_fetchs(h, K_WS_ROUTES, 0); |
| 408 |
651 |
▶ | if (x && *x && SvROK(*x) && SvTYPE(SvRV(*x)) == SVt_PVAV) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (x && *x && SvROK(*x) && SvTYPE(SvRV(*x)) == SVt_PVAV) { |
13 |
638 |
651 |
| if (x && *x && SvROK(*x) && SvTYPE(SvRV(*x)) == SVt_PVAV) { |
13 |
0 |
13 |
| if (x && *x && SvROK(*x) && SvTYPE(SvRV(*x)) == SVt_PVAV) { |
13 |
0 |
13 |
| if (x && *x && SvROK(*x) && SvTYPE(SvRV(*x)) == SVt_PVAV) { |
13 |
0 |
13 |
|
| 409 |
13 |
| AV *wsr = (AV *)SvRV(*x); |
| 410 |
13 |
| HV *wsmap = (HV *)sv_2mortal((SV *)newHV()); |
| 411 |
13 |
▶ | AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL; |
13 |
0 |
13 |
| AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL; |
13 |
0 |
13 |
|
| 412 |
13 |
| SSize_t wi, wn = av_len(wsr) + 1; |
| 413 |
13 |
| int any_blocking = 0, ok; |
| 414 |
13 |
| (void)pk_require_once(aTHX_ PK_WEBSOCKET, TRUE); |
| 415 |
44 |
▶ | for (wi = 0; wi < wn; wi++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (wi = 0; wi < wn; wi++) { |
31 |
13 |
44 |
|
| 416 |
31 |
| HV *w = (HV *)SvRV(*av_fetch(wsr, wi, 0)); |
| 417 |
31 |
| SV **pp = hv_fetchs(w, K_PATH, 0); |
| 418 |
31 |
| SV **op = hv_fetchs(w, K_OPTS, 0); |
| 419 |
31 |
▶ | if (pp && *pp) |
Branch: 2 branches
| Branch | True | False | Total |
| if (pp && *pp) |
31 |
0 |
31 |
| if (pp && *pp) |
31 |
0 |
31 |
|
| 420 |
31 |
▶ | (void)hv_store_ent(wsmap, *pp, |
Branch: 2 branches
| Branch | True | False | Total |
| (void)hv_store_ent(wsmap, *pp, |
31 |
0 |
31 |
| (void)hv_store_ent(wsmap, *pp, |
31 |
0 |
31 |
|
| 421 |
|
| newSVsv(op && *op ? *op : &PL_sv_undef), 0); |
| 422 |
31 |
▶ | if (op && *op && SvROK(*op) && SvTYPE(SvRV(*op)) == SVt_PVHV) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (op && *op && SvROK(*op) && SvTYPE(SvRV(*op)) == SVt_PVHV) { |
31 |
0 |
31 |
| if (op && *op && SvROK(*op) && SvTYPE(SvRV(*op)) == SVt_PVHV) { |
31 |
0 |
31 |
| if (op && *op && SvROK(*op) && SvTYPE(SvRV(*op)) == SVt_PVHV) { |
31 |
0 |
31 |
| if (op && *op && SvROK(*op) && SvTYPE(SvRV(*op)) == SVt_PVHV) { |
31 |
0 |
31 |
|
| 423 |
31 |
| SV **b = hv_fetchs((HV *)SvRV(*op), K_BLOCKING, 0); |
| 424 |
31 |
▶ | if (b && *b && SvTRUE(*b)) any_blocking = 1; |
Branch: 3 branches
| Branch | True | False | Total |
| if (b && *b && SvTRUE(*b)) any_blocking = 1; |
3 |
28 |
31 |
| if (b && *b && SvTRUE(*b)) any_blocking = 1; |
3 |
0 |
3 |
| if (b && *b && SvTRUE(*b)) any_blocking = 1; |
3 |
0 |
3 |
|
| 425 |
|
| } |
| 426 |
|
| } |
| 427 |
13 |
▶ | n = recs ? av_len(recs) + 1 : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| n = recs ? av_len(recs) + 1 : 0; |
13 |
0 |
13 |
|
| 428 |
63 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
50 |
13 |
63 |
|
| 429 |
50 |
| HV *rr = (HV *)SvRV(*av_fetch(recs, i, 0)); |
| 430 |
50 |
| SV **meth = hv_fetchs(rr, K_METHOD, 0); |
| 431 |
50 |
| SV **pth = hv_fetchs(rr, K_PATH, 0); |
| 432 |
|
| HE *he; |
| 433 |
100 |
▶ | if (!(meth && *meth && strEQ(SvPV_nolen(*meth), "GET"))) continue; |
Branch: 3 branches
| Branch | True | False | Total |
| if (!(meth && *meth && strEQ(SvPV_nolen(*meth), "GET"))) continue; |
50 |
0 |
50 |
| if (!(meth && *meth && strEQ(SvPV_nolen(*meth), "GET"))) continue; |
50 |
0 |
50 |
| if (!(meth && *meth && strEQ(SvPV_nolen(*meth), "GET"))) continue; |
2 |
48 |
50 |
|
| 434 |
48 |
▶ | he = pth && *pth ? hv_fetch_ent(wsmap, *pth, 0, 0) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| he = pth && *pth ? hv_fetch_ent(wsmap, *pth, 0, 0) : NULL; |
48 |
0 |
48 |
| he = pth && *pth ? hv_fetch_ent(wsmap, *pth, 0, 0) : NULL; |
48 |
0 |
48 |
|
| 435 |
48 |
▶ | if (he) (void)hv_stores(rr, K_WS, newSVsv(HeVAL(he))); |
Branch: 1 branch
| Branch | True | False | Total |
| if (he) (void)hv_stores(rr, K_WS, newSVsv(HeVAL(he))); |
31 |
17 |
48 |
|
| 436 |
|
| } |
| 437 |
13 |
| { dSP; int c2; |
| 438 |
13 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
13 |
13 |
|
| 439 |
13 |
| c2 = call_pv(PK_WEBSOCKET "::_hm_available", G_SCALAR); |
| 440 |
13 |
| SPAGAIN; |
| 441 |
13 |
▶ | ok = c2 > 0 ? SvTRUE(TOPs) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| ok = c2 > 0 ? SvTRUE(TOPs) : 0; |
13 |
0 |
13 |
|
| 442 |
13 |
▶ | if (c2 > 0) (void)POPs; |
Branch: 1 branch
| Branch | True | False | Total |
| if (c2 > 0) (void)POPs; |
13 |
0 |
13 |
|
| 443 |
13 |
| PUTBACK; } |
| 444 |
13 |
▶ | if (!ok && !any_blocking) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!ok && !any_blocking) |
0 |
13 |
13 |
| if (!ok && !any_blocking) |
0 |
0 |
0 |
|
| 445 |
0 |
| croak("Punk: websocket routes need Hyperman 0.11 or later " |
| 446 |
|
| "(for its detach ABI), or blocking => 1 on the route " |
| 447 |
|
| "for other PSGI servers that provide psgix.io"); |
| 448 |
|
| } |
| 449 |
|
| |
| 450 |
|
| { /* max_body: the app-wide ceiling into the compiled state, and |
| 451 |
|
| * the per-route overrides stamped onto their records. A route's |
| 452 |
|
| * own value wins, including 0, which legitimately means "do not |
| 453 |
|
| * check here" - unlike the server's ceiling, this one is policy |
| 454 |
|
| * and not the memory backstop. */ |
| 455 |
651 |
▶ | AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL; |
651 |
0 |
651 |
| AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL; |
651 |
0 |
651 |
|
| 456 |
|
| { |
| 457 |
651 |
| SV **mr = hv_fetchs(h, K_MAXBODY_ROUTES, 0); |
| 458 |
651 |
▶ | if (mr && *mr && SvROK(*mr) && SvTYPE(SvRV(*mr)) == SVt_PVAV) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (mr && *mr && SvROK(*mr) && SvTYPE(SvRV(*mr)) == SVt_PVAV) { |
26 |
625 |
651 |
| if (mr && *mr && SvROK(*mr) && SvTYPE(SvRV(*mr)) == SVt_PVAV) { |
26 |
0 |
26 |
| if (mr && *mr && SvROK(*mr) && SvTYPE(SvRV(*mr)) == SVt_PVAV) { |
26 |
0 |
26 |
| if (mr && *mr && SvROK(*mr) && SvTYPE(SvRV(*mr)) == SVt_PVAV) { |
26 |
0 |
26 |
|
| 459 |
26 |
| AV *mrr = (AV *)SvRV(*mr); |
| 460 |
26 |
| SSize_t mi, mn = av_len(mrr) + 1; |
| 461 |
59 |
▶ | for (mi = 0; mi < mn; mi++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (mi = 0; mi < mn; mi++) { |
33 |
26 |
59 |
|
| 462 |
33 |
| HV *w = (HV *)SvRV(*av_fetch(mrr, mi, 0)); |
| 463 |
33 |
| SV **wm = hv_fetchs(w, K_METHOD, 0); |
| 464 |
33 |
| SV **wp = hv_fetchs(w, K_PATH, 0); |
| 465 |
33 |
| SV **wv = hv_fetchs(w, K_MAX_BODY, 0); |
| 466 |
33 |
▶ | SSize_t ri, rn = recs ? av_len(recs) + 1 : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| SSize_t ri, rn = recs ? av_len(recs) + 1 : 0; |
33 |
0 |
33 |
|
| 467 |
33 |
▶ | if (!(wm && *wm && wp && *wp && wv && *wv)) continue; |
Branch: 6 branches
| Branch | True | False | Total |
| if (!(wm && *wm && wp && *wp && wv && *wv)) continue; |
33 |
0 |
33 |
| if (!(wm && *wm && wp && *wp && wv && *wv)) continue; |
33 |
0 |
33 |
| if (!(wm && *wm && wp && *wp && wv && *wv)) continue; |
33 |
0 |
33 |
| if (!(wm && *wm && wp && *wp && wv && *wv)) continue; |
33 |
0 |
33 |
| if (!(wm && *wm && wp && *wp && wv && *wv)) continue; |
33 |
0 |
33 |
| if (!(wm && *wm && wp && *wp && wv && *wv)) continue; |
0 |
33 |
33 |
|
| 468 |
132 |
▶ | for (ri = 0; ri < rn; ri++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ri = 0; ri < rn; ri++) { |
99 |
33 |
132 |
|
| 469 |
99 |
| HV *rr = (HV *)SvRV(*av_fetch(recs, ri, 0)); |
| 470 |
99 |
| SV **rm = hv_fetchs(rr, K_METHOD, 0); |
| 471 |
99 |
| SV **rp = hv_fetchs(rr, K_PATH, 0); |
| 472 |
99 |
▶ | if (rm && *rm && rp && *rp |
Branch: 4 branches
| Branch | True | False | Total |
| if (rm && *rm && rp && *rp |
99 |
0 |
99 |
| if (rm && *rm && rp && *rp |
99 |
0 |
99 |
| if (rm && *rm && rp && *rp |
99 |
0 |
99 |
| if (rm && *rm && rp && *rp |
99 |
0 |
99 |
|
| 473 |
99 |
▶ | && sv_eq(*rm, *wm) && sv_eq(*rp, *wp)) |
Branch: 2 branches
| Branch | True | False | Total |
| && sv_eq(*rm, *wm) && sv_eq(*rp, *wp)) |
78 |
21 |
99 |
| && sv_eq(*rm, *wm) && sv_eq(*rp, *wp)) |
33 |
45 |
78 |
|
| 474 |
33 |
| (void)hv_stores(rr, K_MAX_BODY, newSVsv(*wv)); |
| 475 |
|
| } |
| 476 |
|
| } |
| 477 |
|
| } |
| 478 |
|
| } |
| 479 |
|
| } |
| 480 |
|
| |
| 481 |
|
| { /* compress => 0 routes: stamp the compiled record, the same way |
| 482 |
|
| * ws and sse are stamped. punk_serve then adds the header on the |
| 483 |
|
| * way out, where it knows which route answered. */ |
| 484 |
651 |
| SV **nc = hv_fetchs(h, K_NOCOMPRESS_ROUTES, 0); |
| 485 |
651 |
▶ | AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL; |
651 |
0 |
651 |
| AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL; |
651 |
0 |
651 |
|
| 486 |
651 |
▶ | if (nc && *nc && SvROK(*nc) && SvTYPE(SvRV(*nc)) == SVt_PVAV) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (nc && *nc && SvROK(*nc) && SvTYPE(SvRV(*nc)) == SVt_PVAV) { |
3 |
648 |
651 |
| if (nc && *nc && SvROK(*nc) && SvTYPE(SvRV(*nc)) == SVt_PVAV) { |
3 |
0 |
3 |
| if (nc && *nc && SvROK(*nc) && SvTYPE(SvRV(*nc)) == SVt_PVAV) { |
3 |
0 |
3 |
| if (nc && *nc && SvROK(*nc) && SvTYPE(SvRV(*nc)) == SVt_PVAV) { |
3 |
0 |
3 |
|
| 487 |
3 |
| AV *ncr = (AV *)SvRV(*nc); |
| 488 |
3 |
| SSize_t ci, cn = av_len(ncr) + 1; |
| 489 |
9 |
▶ | for (ci = 0; ci < cn; ci++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ci = 0; ci < cn; ci++) { |
6 |
3 |
9 |
|
| 490 |
6 |
| HV *w = (HV *)SvRV(*av_fetch(ncr, ci, 0)); |
| 491 |
6 |
| SV **wm = hv_fetchs(w, K_METHOD, 0); |
| 492 |
6 |
| SV **wp = hv_fetchs(w, K_PATH, 0); |
| 493 |
6 |
▶ | SSize_t ri, rn = recs ? av_len(recs) + 1 : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| SSize_t ri, rn = recs ? av_len(recs) + 1 : 0; |
6 |
0 |
6 |
|
| 494 |
6 |
▶ | if (!(wm && *wm && wp && *wp)) continue; |
Branch: 4 branches
| Branch | True | False | Total |
| if (!(wm && *wm && wp && *wp)) continue; |
6 |
0 |
6 |
| if (!(wm && *wm && wp && *wp)) continue; |
6 |
0 |
6 |
| if (!(wm && *wm && wp && *wp)) continue; |
6 |
0 |
6 |
| if (!(wm && *wm && wp && *wp)) continue; |
0 |
6 |
6 |
|
| 495 |
28 |
▶ | for (ri = 0; ri < rn; ri++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ri = 0; ri < rn; ri++) { |
22 |
6 |
28 |
|
| 496 |
22 |
| HV *rr = (HV *)SvRV(*av_fetch(recs, ri, 0)); |
| 497 |
22 |
| SV **rm = hv_fetchs(rr, K_METHOD, 0); |
| 498 |
22 |
| SV **rp = hv_fetchs(rr, K_PATH, 0); |
| 499 |
22 |
▶ | if (rm && *rm && rp && *rp |
Branch: 4 branches
| Branch | True | False | Total |
| if (rm && *rm && rp && *rp |
22 |
0 |
22 |
| if (rm && *rm && rp && *rp |
22 |
0 |
22 |
| if (rm && *rm && rp && *rp |
22 |
0 |
22 |
| if (rm && *rm && rp && *rp |
22 |
0 |
22 |
|
| 500 |
22 |
▶ | && sv_eq(*rm, *wm) && sv_eq(*rp, *wp)) |
Branch: 2 branches
| Branch | True | False | Total |
| && sv_eq(*rm, *wm) && sv_eq(*rp, *wp)) |
15 |
7 |
22 |
| && sv_eq(*rm, *wm) && sv_eq(*rp, *wp)) |
6 |
9 |
15 |
|
| 501 |
6 |
| (void)hv_stores(rr, K_COMPRESS, newSViv(0)); |
| 502 |
|
| } |
| 503 |
|
| } |
| 504 |
|
| } |
| 505 |
|
| } |
| 506 |
|
| |
| 507 |
|
| { /* etag routes: stamp the validator onto the compiled record, so |
| 508 |
|
| * the dispatcher finds it beside `guards` and `code` rather than |
| 509 |
|
| * looking anything up per request. Same walk as compress. */ |
| 510 |
651 |
| SV **ec = hv_fetchs(h, K_ETAG_ROUTES, 0); |
| 511 |
651 |
▶ | AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL; |
651 |
0 |
651 |
| AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL; |
651 |
0 |
651 |
|
| 512 |
651 |
▶ | if (ec && *ec && SvROK(*ec) && SvTYPE(SvRV(*ec)) == SVt_PVAV) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (ec && *ec && SvROK(*ec) && SvTYPE(SvRV(*ec)) == SVt_PVAV) { |
20 |
631 |
651 |
| if (ec && *ec && SvROK(*ec) && SvTYPE(SvRV(*ec)) == SVt_PVAV) { |
20 |
0 |
20 |
| if (ec && *ec && SvROK(*ec) && SvTYPE(SvRV(*ec)) == SVt_PVAV) { |
20 |
0 |
20 |
| if (ec && *ec && SvROK(*ec) && SvTYPE(SvRV(*ec)) == SVt_PVAV) { |
20 |
0 |
20 |
|
| 513 |
20 |
| AV *ecr = (AV *)SvRV(*ec); |
| 514 |
20 |
| SSize_t ci, cn = av_len(ecr) + 1; |
| 515 |
63 |
▶ | for (ci = 0; ci < cn; ci++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ci = 0; ci < cn; ci++) { |
43 |
20 |
63 |
|
| 516 |
43 |
| HV *w = (HV *)SvRV(*av_fetch(ecr, ci, 0)); |
| 517 |
43 |
| SV **wm = hv_fetchs(w, K_METHOD, 0); |
| 518 |
43 |
| SV **wp = hv_fetchs(w, K_PATH, 0); |
| 519 |
43 |
| SV **wv = hv_fetchs(w, K_ETAG, 0); |
| 520 |
43 |
▶ | SSize_t ri, rn = recs ? av_len(recs) + 1 : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| SSize_t ri, rn = recs ? av_len(recs) + 1 : 0; |
43 |
0 |
43 |
|
| 521 |
43 |
▶ | if (!(wm && *wm && wp && *wp && wv && *wv)) continue; |
Branch: 6 branches
| Branch | True | False | Total |
| if (!(wm && *wm && wp && *wp && wv && *wv)) continue; |
43 |
0 |
43 |
| if (!(wm && *wm && wp && *wp && wv && *wv)) continue; |
43 |
0 |
43 |
| if (!(wm && *wm && wp && *wp && wv && *wv)) continue; |
43 |
0 |
43 |
| if (!(wm && *wm && wp && *wp && wv && *wv)) continue; |
43 |
0 |
43 |
| if (!(wm && *wm && wp && *wp && wv && *wv)) continue; |
43 |
0 |
43 |
| if (!(wm && *wm && wp && *wp && wv && *wv)) continue; |
0 |
43 |
43 |
|
| 522 |
234 |
▶ | for (ri = 0; ri < rn; ri++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ri = 0; ri < rn; ri++) { |
191 |
43 |
234 |
|
| 523 |
191 |
| HV *rr = (HV *)SvRV(*av_fetch(recs, ri, 0)); |
| 524 |
191 |
| SV **rm = hv_fetchs(rr, K_METHOD, 0); |
| 525 |
191 |
| SV **rp = hv_fetchs(rr, K_PATH, 0); |
| 526 |
191 |
▶ | if (rm && *rm && rp && *rp |
Branch: 4 branches
| Branch | True | False | Total |
| if (rm && *rm && rp && *rp |
191 |
0 |
191 |
| if (rm && *rm && rp && *rp |
191 |
0 |
191 |
| if (rm && *rm && rp && *rp |
191 |
0 |
191 |
| if (rm && *rm && rp && *rp |
191 |
0 |
191 |
|
| 527 |
191 |
▶ | && sv_eq(*rm, *wm) && sv_eq(*rp, *wp)) |
Branch: 2 branches
| Branch | True | False | Total |
| && sv_eq(*rm, *wm) && sv_eq(*rp, *wp)) |
180 |
11 |
191 |
| && sv_eq(*rm, *wm) && sv_eq(*rp, *wp)) |
43 |
137 |
180 |
|
| 528 |
43 |
| (void)hv_stores(rr, K_ETAG, newSVsv(*wv)); |
| 529 |
|
| } |
| 530 |
|
| } |
| 531 |
|
| } |
| 532 |
|
| } |
| 533 |
|
| |
| 534 |
|
| { /* last_modified routes: stamp the validator, the etag walk */ |
| 535 |
651 |
| SV **ec = hv_fetchs(h, K_LM_ROUTES, 0); |
| 536 |
651 |
▶ | AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL; |
651 |
0 |
651 |
| AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL; |
651 |
0 |
651 |
|
| 537 |
651 |
▶ | if (ec && *ec && SvROK(*ec) && SvTYPE(SvRV(*ec)) == SVt_PVAV) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (ec && *ec && SvROK(*ec) && SvTYPE(SvRV(*ec)) == SVt_PVAV) { |
3 |
648 |
651 |
| if (ec && *ec && SvROK(*ec) && SvTYPE(SvRV(*ec)) == SVt_PVAV) { |
3 |
0 |
3 |
| if (ec && *ec && SvROK(*ec) && SvTYPE(SvRV(*ec)) == SVt_PVAV) { |
3 |
0 |
3 |
| if (ec && *ec && SvROK(*ec) && SvTYPE(SvRV(*ec)) == SVt_PVAV) { |
3 |
0 |
3 |
|
| 538 |
3 |
| AV *ecr = (AV *)SvRV(*ec); |
| 539 |
3 |
| SSize_t ci, cn = av_len(ecr) + 1; |
| 540 |
10 |
▶ | for (ci = 0; ci < cn; ci++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ci = 0; ci < cn; ci++) { |
7 |
3 |
10 |
|
| 541 |
7 |
| HV *w = (HV *)SvRV(*av_fetch(ecr, ci, 0)); |
| 542 |
7 |
| SV **wm = hv_fetchs(w, K_METHOD, 0); |
| 543 |
7 |
| SV **wp = hv_fetchs(w, K_PATH, 0); |
| 544 |
7 |
| SV **wv = hv_fetchs(w, K_LAST_MODIFIED, 0); |
| 545 |
7 |
▶ | SSize_t ri, rn = recs ? av_len(recs) + 1 : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| SSize_t ri, rn = recs ? av_len(recs) + 1 : 0; |
7 |
0 |
7 |
|
| 546 |
7 |
▶ | if (!(wm && *wm && wp && *wp && wv && *wv)) continue; |
Branch: 6 branches
| Branch | True | False | Total |
| if (!(wm && *wm && wp && *wp && wv && *wv)) continue; |
7 |
0 |
7 |
| if (!(wm && *wm && wp && *wp && wv && *wv)) continue; |
7 |
0 |
7 |
| if (!(wm && *wm && wp && *wp && wv && *wv)) continue; |
7 |
0 |
7 |
| if (!(wm && *wm && wp && *wp && wv && *wv)) continue; |
7 |
0 |
7 |
| if (!(wm && *wm && wp && *wp && wv && *wv)) continue; |
7 |
0 |
7 |
| if (!(wm && *wm && wp && *wp && wv && *wv)) continue; |
0 |
7 |
7 |
|
| 547 |
41 |
▶ | for (ri = 0; ri < rn; ri++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ri = 0; ri < rn; ri++) { |
34 |
7 |
41 |
|
| 548 |
34 |
| HV *rr = (HV *)SvRV(*av_fetch(recs, ri, 0)); |
| 549 |
34 |
| SV **rm = hv_fetchs(rr, K_METHOD, 0); |
| 550 |
34 |
| SV **rp = hv_fetchs(rr, K_PATH, 0); |
| 551 |
34 |
▶ | if (rm && *rm && rp && *rp |
Branch: 4 branches
| Branch | True | False | Total |
| if (rm && *rm && rp && *rp |
34 |
0 |
34 |
| if (rm && *rm && rp && *rp |
34 |
0 |
34 |
| if (rm && *rm && rp && *rp |
34 |
0 |
34 |
| if (rm && *rm && rp && *rp |
34 |
0 |
34 |
|
| 552 |
34 |
▶ | && sv_eq(*rm, *wm) && sv_eq(*rp, *wp)) |
Branch: 2 branches
| Branch | True | False | Total |
| && sv_eq(*rm, *wm) && sv_eq(*rp, *wp)) |
34 |
0 |
34 |
| && sv_eq(*rm, *wm) && sv_eq(*rp, *wp)) |
7 |
27 |
34 |
|
| 553 |
7 |
| (void)hv_stores(rr, K_LAST_MODIFIED, newSVsv(*wv)); |
| 554 |
|
| } |
| 555 |
|
| } |
| 556 |
|
| } |
| 557 |
|
| } |
| 558 |
|
| |
| 559 |
|
| { /* idempotent routes: stamp the record, the same walk as etag */ |
| 560 |
651 |
| SV **ic = hv_fetchs(h, K_IDEM_ROUTES, 0); |
| 561 |
651 |
▶ | AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL; |
651 |
0 |
651 |
| AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL; |
651 |
0 |
651 |
|
| 562 |
651 |
▶ | if (ic && *ic && SvROK(*ic) && SvTYPE(SvRV(*ic)) == SVt_PVAV) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (ic && *ic && SvROK(*ic) && SvTYPE(SvRV(*ic)) == SVt_PVAV) { |
12 |
639 |
651 |
| if (ic && *ic && SvROK(*ic) && SvTYPE(SvRV(*ic)) == SVt_PVAV) { |
12 |
0 |
12 |
| if (ic && *ic && SvROK(*ic) && SvTYPE(SvRV(*ic)) == SVt_PVAV) { |
12 |
0 |
12 |
| if (ic && *ic && SvROK(*ic) && SvTYPE(SvRV(*ic)) == SVt_PVAV) { |
12 |
0 |
12 |
|
| 563 |
12 |
| AV *icr = (AV *)SvRV(*ic); |
| 564 |
12 |
| SSize_t ci, cn = av_len(icr) + 1; |
| 565 |
34 |
▶ | for (ci = 0; ci < cn; ci++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ci = 0; ci < cn; ci++) { |
22 |
12 |
34 |
|
| 566 |
22 |
| HV *w = (HV *)SvRV(*av_fetch(icr, ci, 0)); |
| 567 |
22 |
| SV **wm = hv_fetchs(w, K_METHOD, 0); |
| 568 |
22 |
| SV **wp = hv_fetchs(w, K_PATH, 0); |
| 569 |
22 |
▶ | SSize_t ri, rn = recs ? av_len(recs) + 1 : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| SSize_t ri, rn = recs ? av_len(recs) + 1 : 0; |
22 |
0 |
22 |
|
| 570 |
22 |
▶ | if (!(wm && *wm && wp && *wp)) continue; |
Branch: 4 branches
| Branch | True | False | Total |
| if (!(wm && *wm && wp && *wp)) continue; |
22 |
0 |
22 |
| if (!(wm && *wm && wp && *wp)) continue; |
22 |
0 |
22 |
| if (!(wm && *wm && wp && *wp)) continue; |
22 |
0 |
22 |
| if (!(wm && *wm && wp && *wp)) continue; |
0 |
22 |
22 |
|
| 571 |
103 |
▶ | for (ri = 0; ri < rn; ri++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ri = 0; ri < rn; ri++) { |
81 |
22 |
103 |
|
| 572 |
81 |
| HV *rr = (HV *)SvRV(*av_fetch(recs, ri, 0)); |
| 573 |
81 |
| SV **rm = hv_fetchs(rr, K_METHOD, 0); |
| 574 |
81 |
| SV **rp = hv_fetchs(rr, K_PATH, 0); |
| 575 |
81 |
▶ | if (rm && *rm && rp && *rp |
Branch: 4 branches
| Branch | True | False | Total |
| if (rm && *rm && rp && *rp |
81 |
0 |
81 |
| if (rm && *rm && rp && *rp |
81 |
0 |
81 |
| if (rm && *rm && rp && *rp |
81 |
0 |
81 |
| if (rm && *rm && rp && *rp |
81 |
0 |
81 |
|
| 576 |
81 |
▶ | && sv_eq(*rm, *wm) && sv_eq(*rp, *wp)) |
Branch: 2 branches
| Branch | True | False | Total |
| && sv_eq(*rm, *wm) && sv_eq(*rp, *wp)) |
68 |
13 |
81 |
| && sv_eq(*rm, *wm) && sv_eq(*rp, *wp)) |
22 |
46 |
68 |
|
| 577 |
22 |
| (void)hv_stores(rr, K_IDEMPOTENT, newSViv(1)); |
| 578 |
|
| } |
| 579 |
|
| } |
| 580 |
|
| } |
| 581 |
|
| } |
| 582 |
|
| |
| 583 |
|
| { /* named routes: stamp the name onto the compiled record (the |
| 584 |
|
| * etag walk), then resolve the whole set into ONE name -> |
| 585 |
|
| * record index table. |
| 586 |
|
| * |
| 587 |
|
| * The table is the one namespace for the application: a plugin |
| 588 |
|
| * that takes `index` has taken it from the application, and a |
| 589 |
|
| * duplicate croaks here naming BOTH routes, because the person |
| 590 |
|
| * reading it wants to know which one to rename. */ |
| 591 |
651 |
| SV **nc = hv_fetchs(h, K_NAMED_ROUTES, 0); |
| 592 |
651 |
▶ | AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL; |
651 |
0 |
651 |
| AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL; |
651 |
0 |
651 |
|
| 593 |
651 |
| HV *names = newHV(); |
| 594 |
651 |
▶ | if (nc && *nc && SvROK(*nc) && SvTYPE(SvRV(*nc)) == SVt_PVAV) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (nc && *nc && SvROK(*nc) && SvTYPE(SvRV(*nc)) == SVt_PVAV) { |
37 |
614 |
651 |
| if (nc && *nc && SvROK(*nc) && SvTYPE(SvRV(*nc)) == SVt_PVAV) { |
37 |
0 |
37 |
| if (nc && *nc && SvROK(*nc) && SvTYPE(SvRV(*nc)) == SVt_PVAV) { |
37 |
0 |
37 |
| if (nc && *nc && SvROK(*nc) && SvTYPE(SvRV(*nc)) == SVt_PVAV) { |
37 |
0 |
37 |
|
| 595 |
37 |
| AV *ncr = (AV *)SvRV(*nc); |
| 596 |
37 |
| SSize_t ci, cn = av_len(ncr) + 1; |
| 597 |
113 |
▶ | for (ci = 0; ci < cn; ci++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ci = 0; ci < cn; ci++) { |
76 |
37 |
113 |
|
| 598 |
76 |
| HV *w = (HV *)SvRV(*av_fetch(ncr, ci, 0)); |
| 599 |
76 |
| SV **wm = hv_fetchs(w, K_METHOD, 0); |
| 600 |
76 |
| SV **wp = hv_fetchs(w, K_PATH, 0); |
| 601 |
76 |
| SV **wv = hv_fetchs(w, K_NAME, 0); |
| 602 |
76 |
▶ | SSize_t ri, rn = recs ? av_len(recs) + 1 : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| SSize_t ri, rn = recs ? av_len(recs) + 1 : 0; |
76 |
0 |
76 |
|
| 603 |
76 |
▶ | if (!(wm && *wm && wp && *wp && wv && *wv)) continue; |
Branch: 6 branches
| Branch | True | False | Total |
| if (!(wm && *wm && wp && *wp && wv && *wv)) continue; |
76 |
0 |
76 |
| if (!(wm && *wm && wp && *wp && wv && *wv)) continue; |
76 |
0 |
76 |
| if (!(wm && *wm && wp && *wp && wv && *wv)) continue; |
76 |
0 |
76 |
| if (!(wm && *wm && wp && *wp && wv && *wv)) continue; |
76 |
0 |
76 |
| if (!(wm && *wm && wp && *wp && wv && *wv)) continue; |
76 |
0 |
76 |
| if (!(wm && *wm && wp && *wp && wv && *wv)) continue; |
0 |
76 |
76 |
|
| 604 |
441 |
▶ | for (ri = 0; ri < rn; ri++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ri = 0; ri < rn; ri++) { |
365 |
76 |
441 |
|
| 605 |
365 |
| HV *rr = (HV *)SvRV(*av_fetch(recs, ri, 0)); |
| 606 |
365 |
| SV **rm = hv_fetchs(rr, K_METHOD, 0); |
| 607 |
365 |
| SV **rp = hv_fetchs(rr, K_PATH, 0); |
| 608 |
365 |
▶ | if (rm && *rm && rp && *rp |
Branch: 4 branches
| Branch | True | False | Total |
| if (rm && *rm && rp && *rp |
365 |
0 |
365 |
| if (rm && *rm && rp && *rp |
365 |
0 |
365 |
| if (rm && *rm && rp && *rp |
365 |
0 |
365 |
| if (rm && *rm && rp && *rp |
365 |
0 |
365 |
|
| 609 |
365 |
▶ | && sv_eq(*rm, *wm) && sv_eq(*rp, *wp)) |
Branch: 2 branches
| Branch | True | False | Total |
| && sv_eq(*rm, *wm) && sv_eq(*rp, *wp)) |
323 |
42 |
365 |
| && sv_eq(*rm, *wm) && sv_eq(*rp, *wp)) |
76 |
247 |
323 |
|
| 610 |
76 |
| (void)hv_stores(rr, K_NAME, newSVsv(*wv)); |
| 611 |
|
| } |
| 612 |
|
| } |
| 613 |
|
| } |
| 614 |
|
| { /* one pass over the records, in declaration order, so the |
| 615 |
|
| * route the croak calls "already" is the earlier one */ |
| 616 |
651 |
▶ | SSize_t ri, rn = recs ? av_len(recs) + 1 : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| SSize_t ri, rn = recs ? av_len(recs) + 1 : 0; |
651 |
0 |
651 |
|
| 617 |
61974 |
▶ | for (ri = 0; ri < rn; ri++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ri = 0; ri < rn; ri++) { |
61326 |
648 |
61974 |
|
| 618 |
61326 |
| HV *rr = (HV *)SvRV(*av_fetch(recs, ri, 0)); |
| 619 |
61326 |
| SV **nm = hv_fetchs(rr, K_NAME, 0); |
| 620 |
|
| HE *he; |
| 621 |
61326 |
▶ | if (!(nm && *nm && SvOK(*nm))) continue; |
Branch: 3 branches
| Branch | True | False | Total |
| if (!(nm && *nm && SvOK(*nm))) continue; |
76 |
61250 |
61326 |
| if (!(nm && *nm && SvOK(*nm))) continue; |
76 |
0 |
76 |
| if (!(nm && *nm && SvOK(*nm))) continue; |
0 |
76 |
76 |
|
| 622 |
76 |
| he = hv_fetch_ent(names, *nm, 0, 0); |
| 623 |
76 |
▶ | if (he) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (he) { |
3 |
73 |
76 |
|
| 624 |
3 |
| HV *first = (HV *)SvRV(*av_fetch(recs, |
| 625 |
|
| (SSize_t)SvIV(HeVAL(he)), 0)); |
| 626 |
3 |
| SV **fm = hv_fetchs(first, K_METHOD, 0); |
| 627 |
3 |
| SV **fp = hv_fetchs(first, K_PATH, 0); |
| 628 |
3 |
| SV **rm = hv_fetchs(rr, K_METHOD, 0); |
| 629 |
3 |
| SV **rp = hv_fetchs(rr, K_PATH, 0); |
| 630 |
3 |
| SvREFCNT_dec((SV *)names); |
| 631 |
18 |
▶ | croak("Punk: route name '%s' is declared twice: " |
Branch: 8 branches
| Branch | True | False | Total |
| croak("Punk: route name '%s' is declared twice: " |
3 |
0 |
3 |
| croak("Punk: route name '%s' is declared twice: " |
3 |
0 |
3 |
| croak("Punk: route name '%s' is declared twice: " |
3 |
0 |
3 |
| croak("Punk: route name '%s' is declared twice: " |
3 |
0 |
3 |
| croak("Punk: route name '%s' is declared twice: " |
3 |
0 |
3 |
| croak("Punk: route name '%s' is declared twice: " |
3 |
0 |
3 |
| croak("Punk: route name '%s' is declared twice: " |
3 |
0 |
3 |
| croak("Punk: route name '%s' is declared twice: " |
3 |
0 |
3 |
|
| 632 |
|
| "%s %s and %s %s - a name is one route, and " |
| 633 |
|
| "url_for would have had to choose", |
| 634 |
|
| SvPV_nolen(*nm), |
| 635 |
|
| fm && *fm ? SvPV_nolen(*fm) : "?", |
| 636 |
|
| fp && *fp ? SvPV_nolen(*fp) : "?", |
| 637 |
|
| rm && *rm ? SvPV_nolen(*rm) : "?", |
| 638 |
|
| rp && *rp ? SvPV_nolen(*rp) : "?"); |
| 639 |
|
| } |
| 640 |
73 |
| (void)hv_store_ent(names, *nm, newSViv((IV)ri), 0); |
| 641 |
|
| } |
| 642 |
|
| } |
| 643 |
|
| { /* The API mount is a routing table too. |
| 644 |
|
| * |
| 645 |
|
| * An operation has an operationId and a path template with |
| 646 |
|
| * {holes} - a named route by another spelling - so an |
| 647 |
|
| * application with an `api` keyword would be half-named |
| 648 |
|
| * without this. They go into the SAME table: one namespace |
| 649 |
|
| * for the whole application, and a route named like an |
| 650 |
|
| * operation is a duplicate like any other. |
| 651 |
|
| * |
| 652 |
|
| * The value is a REFERENCE where a route's is an integer, |
| 653 |
|
| * which is how url_for tells the two apart: [ mount prefix, |
| 654 |
|
| * parsed template ]. |
| 655 |
|
| * |
| 656 |
|
| * operationIds are NOT held to the route-name identifier |
| 657 |
|
| * rule. |
| 658 |
|
| * They are the spec's, and a spec may say `get-book` or |
| 659 |
|
| * `book.get`; those are callable from url_for as whatever |
| 660 |
|
| * they are, and simply absent from the template `url` hash, |
| 661 |
|
| * which the documentation says. It is the spec's choice, |
| 662 |
|
| * not Punk's. */ |
| 663 |
648 |
| SSize_t mi, mn = av_len(api_mounts) + 1; |
| 664 |
673 |
▶ | for (mi = 0; mi < mn; mi++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (mi = 0; mi < mn; mi++) { |
26 |
647 |
673 |
|
| 665 |
26 |
| HV *mrec = (HV *)SvRV(*av_fetch(api_mounts, mi, 0)); |
| 666 |
26 |
| SV **msv = hv_fetchs(mrec, K_MOUNT, 0); |
| 667 |
26 |
| SV **psv = hv_fetchs(mrec, K_PREFIX, 0); |
| 668 |
|
| SV *apio, *ops; |
| 669 |
|
| AV *opav; |
| 670 |
|
| SSize_t oi, on; |
| 671 |
26 |
▶ | if (!(msv && *msv)) continue; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!(msv && *msv)) continue; |
26 |
0 |
26 |
| if (!(msv && *msv)) continue; |
0 |
26 |
26 |
|
| 672 |
26 |
| apio = sv_2mortal(pcx_call_meth(aTHX_ *msv, "api", |
| 673 |
|
| NULL, 0, 1)); |
| 674 |
26 |
▶ | if (!(apio && SvOK(apio) && SvROK(apio))) continue; |
Branch: 3 branches
| Branch | True | False | Total |
| if (!(apio && SvOK(apio) && SvROK(apio))) continue; |
26 |
0 |
26 |
| if (!(apio && SvOK(apio) && SvROK(apio))) continue; |
26 |
0 |
26 |
| if (!(apio && SvOK(apio) && SvROK(apio))) continue; |
0 |
26 |
26 |
|
| 675 |
26 |
| ops = sv_2mortal(pcx_call_meth(aTHX_ apio, "operations", |
| 676 |
|
| NULL, 0, 1)); |
| 677 |
26 |
▶ | if (!(ops && SvROK(ops) && SvTYPE(SvRV(ops)) == SVt_PVAV)) |
Branch: 3 branches
| Branch | True | False | Total |
| if (!(ops && SvROK(ops) && SvTYPE(SvRV(ops)) == SVt_PVAV)) |
26 |
0 |
26 |
| if (!(ops && SvROK(ops) && SvTYPE(SvRV(ops)) == SVt_PVAV)) |
26 |
0 |
26 |
| if (!(ops && SvROK(ops) && SvTYPE(SvRV(ops)) == SVt_PVAV)) |
0 |
26 |
26 |
|
| 678 |
0 |
| continue; |
| 679 |
26 |
| opav = (AV *)SvRV(ops); |
| 680 |
26 |
| on = av_len(opav) + 1; |
| 681 |
91 |
▶ | for (oi = 0; oi < on; oi++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (oi = 0; oi < on; oi++) { |
66 |
25 |
91 |
|
| 682 |
66 |
| SV **e = av_fetch(opav, oi, 0); |
| 683 |
|
| HV *op; |
| 684 |
|
| SV **id, **pth; |
| 685 |
|
| STRLEN tl; |
| 686 |
|
| const char *tp; |
| 687 |
|
| AV *pair; |
| 688 |
66 |
▶ | if (!(e && *e && SvROK(*e) |
Branch: 3 branches
| Branch | True | False | Total |
| if (!(e && *e && SvROK(*e) |
66 |
0 |
66 |
| if (!(e && *e && SvROK(*e) |
66 |
0 |
66 |
| if (!(e && *e && SvROK(*e) |
66 |
0 |
66 |
|
| 689 |
66 |
▶ | && SvTYPE(SvRV(*e)) == SVt_PVHV)) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| && SvTYPE(SvRV(*e)) == SVt_PVHV)) continue; |
0 |
66 |
66 |
|
| 690 |
66 |
| op = (HV *)SvRV(*e); |
| 691 |
66 |
| id = hv_fetchs(op, "operationId", 0); |
| 692 |
66 |
| pth = hv_fetchs(op, "path", 0); |
| 693 |
66 |
▶ | if (!(id && *id && SvOK(*id) && SvCUR(*id) |
Branch: 4 branches
| Branch | True | False | Total |
| if (!(id && *id && SvOK(*id) && SvCUR(*id) |
66 |
0 |
66 |
| if (!(id && *id && SvOK(*id) && SvCUR(*id) |
66 |
0 |
66 |
| if (!(id && *id && SvOK(*id) && SvCUR(*id) |
66 |
0 |
66 |
| if (!(id && *id && SvOK(*id) && SvCUR(*id) |
66 |
0 |
66 |
|
| 694 |
66 |
▶ | && pth && *pth && SvOK(*pth))) continue; |
Branch: 3 branches
| Branch | True | False | Total |
| && pth && *pth && SvOK(*pth))) continue; |
66 |
0 |
66 |
| && pth && *pth && SvOK(*pth))) continue; |
66 |
0 |
66 |
| && pth && *pth && SvOK(*pth))) continue; |
0 |
66 |
66 |
|
| 695 |
66 |
▶ | if (hv_exists_ent(names, *id, 0)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (hv_exists_ent(names, *id, 0)) { |
1 |
65 |
66 |
|
| 696 |
1 |
| SV *prev = HeVAL(hv_fetch_ent(names, *id, 0, 0)); |
| 697 |
1 |
▶ | if (SvROK(prev)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvROK(prev)) |
0 |
1 |
1 |
|
| 698 |
0 |
| croak("Punk: route name '%s' is declared " |
| 699 |
|
| "twice: two api mounts both have an " |
| 700 |
|
| "operation called that - a name is " |
| 701 |
|
| "one route across the whole " |
| 702 |
|
| "application", SvPV_nolen(*id)); |
| 703 |
|
| { |
| 704 |
1 |
| HV *rr = (HV *)SvRV(*av_fetch(recs, |
| 705 |
|
| (SSize_t)SvIV(prev), 0)); |
| 706 |
1 |
| SV **rm = hv_fetchs(rr, K_METHOD, 0); |
| 707 |
1 |
| SV **rp = hv_fetchs(rr, K_PATH, 0); |
| 708 |
5 |
▶ | croak("Punk: route name '%s' is declared " |
Branch: 8 branches
| Branch | True | False | Total |
| croak("Punk: route name '%s' is declared " |
1 |
0 |
1 |
| croak("Punk: route name '%s' is declared " |
1 |
0 |
1 |
| croak("Punk: route name '%s' is declared " |
1 |
0 |
1 |
| croak("Punk: route name '%s' is declared " |
1 |
0 |
1 |
| croak("Punk: route name '%s' is declared " |
1 |
0 |
1 |
| croak("Punk: route name '%s' is declared " |
1 |
0 |
1 |
| croak("Punk: route name '%s' is declared " |
1 |
0 |
1 |
| croak("Punk: route name '%s' is declared " |
1 |
0 |
1 |
|
| 709 |
|
| "twice: %s %s and the operation of " |
| 710 |
|
| "that name in the %s mount - the " |
| 711 |
|
| "names are one namespace", |
| 712 |
|
| SvPV_nolen(*id), |
| 713 |
|
| rm && *rm ? SvPV_nolen(*rm) : "?", |
| 714 |
|
| rp && *rp ? SvPV_nolen(*rp) : "?", |
| 715 |
|
| (psv && *psv && SvOK(*psv) |
| 716 |
|
| && SvCUR(*psv)) |
| 717 |
|
| ? SvPV_nolen(*psv) : "/"); |
| 718 |
|
| } |
| 719 |
|
| } |
| 720 |
65 |
| tp = SvPV_const(*pth, tl); |
| 721 |
65 |
| pair = newAV(); |
| 722 |
65 |
▶ | av_push(pair, (psv && *psv) ? newSVsv(*psv) : newSV(0)); |
Branch: 2 branches
| Branch | True | False | Total |
| av_push(pair, (psv && *psv) ? newSVsv(*psv) : newSV(0)); |
65 |
0 |
65 |
| av_push(pair, (psv && *psv) ? newSVsv(*psv) : newSV(0)); |
65 |
0 |
65 |
|
| 723 |
65 |
| av_push(pair, newRV_noinc((SV *) |
| 724 |
|
| pk_url_parse_template(aTHX_ tp, tl))); |
| 725 |
65 |
| (void)hv_store_ent(names, *id, |
| 726 |
|
| newRV_noinc((SV *)pair), 0); |
| 727 |
|
| } |
| 728 |
|
| } |
| 729 |
|
| } |
| 730 |
647 |
| (void)hv_stores(h, K_NAMES_C, newRV_noinc((SV *)names)); |
| 731 |
|
| |
| 732 |
|
| { /* The path on `host`, split off once. |
| 733 |
|
| * |
| 734 |
|
| * A route matches PATH_INFO, and PATH_INFO is what is left |
| 735 |
|
| * after whatever sits in front of the application. Two |
| 736 |
|
| * things can: SCRIPT_NAME, which the request carries, and |
| 737 |
|
| * the path on `host` - `host 'https://example.com/app'`, |
| 738 |
|
| * which is how an application says a proxy strips /app |
| 739 |
|
| * before Punk ever sees the request. Only configuration |
| 740 |
|
| * knows the second, and $c->origin deliberately drops it |
| 741 |
|
| * (pk_origin_bare returns scheme://host, which is what an |
| 742 |
|
| * origin means to a browser), so it is kept here for the |
| 743 |
|
| * URL builder to put back. Empty for the deployments that |
| 744 |
|
| * have no prefix, which is nearly all of them. */ |
| 745 |
647 |
| SV *host = app_get(aTHX_ h, "host"); |
| 746 |
647 |
▶ | if (host && SvOK(host) && SvCUR(host)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (host && SvOK(host) && SvCUR(host)) { |
21 |
626 |
647 |
| if (host && SvOK(host) && SvCUR(host)) { |
21 |
0 |
21 |
| if (host && SvOK(host) && SvCUR(host)) { |
21 |
0 |
21 |
|
| 747 |
|
| STRLEN hl, hoff, hlen; |
| 748 |
21 |
| const char *hp = SvPV_const(host, hl); |
| 749 |
21 |
| SV *bare = pk_origin_bare(aTHX_ hp, hl, &hoff, &hlen); |
| 750 |
21 |
| STRLEN bl = SvCUR(bare); |
| 751 |
21 |
▶ | if (hl > bl) |
Branch: 1 branch
| Branch | True | False | Total |
| if (hl > bl) |
3 |
18 |
21 |
|
| 752 |
3 |
| (void)hv_stores(h, K_HOST_PATH_C, |
| 753 |
|
| newSVpvn(hp + bl, hl - bl)); |
| 754 |
21 |
| SvREFCNT_dec(bare); |
| 755 |
|
| } |
| 756 |
|
| } |
| 757 |
|
| } |
| 758 |
|
| |
| 759 |
|
| /* sse routes: mark the records; the transport is chosen per request |
| 760 |
|
| * (detach / psgi.streaming / blocking), so no boot capability check */ |
| 761 |
647 |
| x = hv_fetchs(h, K_SSE_ROUTES, 0); |
| 762 |
647 |
▶ | if (x && *x && SvROK(*x) && SvTYPE(SvRV(*x)) == SVt_PVAV) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (x && *x && SvROK(*x) && SvTYPE(SvRV(*x)) == SVt_PVAV) { |
9 |
638 |
647 |
| if (x && *x && SvROK(*x) && SvTYPE(SvRV(*x)) == SVt_PVAV) { |
9 |
0 |
9 |
| if (x && *x && SvROK(*x) && SvTYPE(SvRV(*x)) == SVt_PVAV) { |
9 |
0 |
9 |
| if (x && *x && SvROK(*x) && SvTYPE(SvRV(*x)) == SVt_PVAV) { |
9 |
0 |
9 |
|
| 763 |
9 |
| AV *ssr = (AV *)SvRV(*x); |
| 764 |
9 |
| HV *ssemap = (HV *)sv_2mortal((SV *)newHV()); |
| 765 |
9 |
▶ | AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL; |
9 |
0 |
9 |
| AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL; |
9 |
0 |
9 |
|
| 766 |
9 |
| SSize_t si, sn = av_len(ssr) + 1; |
| 767 |
19 |
▶ | for (si = 0; si < sn; si++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (si = 0; si < sn; si++) { |
10 |
9 |
19 |
|
| 768 |
10 |
| HV *w = (HV *)SvRV(*av_fetch(ssr, si, 0)); |
| 769 |
10 |
| SV **pp = hv_fetchs(w, K_PATH, 0); |
| 770 |
10 |
| SV **op = hv_fetchs(w, K_OPTS, 0); |
| 771 |
10 |
▶ | if (pp && *pp) |
Branch: 2 branches
| Branch | True | False | Total |
| if (pp && *pp) |
10 |
0 |
10 |
| if (pp && *pp) |
10 |
0 |
10 |
|
| 772 |
10 |
▶ | (void)hv_store_ent(ssemap, *pp, |
Branch: 2 branches
| Branch | True | False | Total |
| (void)hv_store_ent(ssemap, *pp, |
10 |
0 |
10 |
| (void)hv_store_ent(ssemap, *pp, |
10 |
0 |
10 |
|
| 773 |
|
| newSVsv(op && *op ? *op : &PL_sv_undef), 0); |
| 774 |
|
| } |
| 775 |
9 |
▶ | n = recs ? av_len(recs) + 1 : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| n = recs ? av_len(recs) + 1 : 0; |
9 |
0 |
9 |
|
| 776 |
26 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
17 |
9 |
26 |
|
| 777 |
17 |
| HV *rr = (HV *)SvRV(*av_fetch(recs, i, 0)); |
| 778 |
17 |
| SV **meth = hv_fetchs(rr, K_METHOD, 0); |
| 779 |
17 |
| SV **pth = hv_fetchs(rr, K_PATH, 0); |
| 780 |
|
| HE *he; |
| 781 |
34 |
▶ | if (!(meth && *meth && strEQ(SvPV_nolen(*meth), "GET"))) continue; |
Branch: 3 branches
| Branch | True | False | Total |
| if (!(meth && *meth && strEQ(SvPV_nolen(*meth), "GET"))) continue; |
17 |
0 |
17 |
| if (!(meth && *meth && strEQ(SvPV_nolen(*meth), "GET"))) continue; |
17 |
0 |
17 |
| if (!(meth && *meth && strEQ(SvPV_nolen(*meth), "GET"))) continue; |
0 |
17 |
17 |
|
| 782 |
17 |
▶ | he = pth && *pth ? hv_fetch_ent(ssemap, *pth, 0, 0) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| he = pth && *pth ? hv_fetch_ent(ssemap, *pth, 0, 0) : NULL; |
17 |
0 |
17 |
| he = pth && *pth ? hv_fetch_ent(ssemap, *pth, 0, 0) : NULL; |
17 |
0 |
17 |
|
| 783 |
17 |
▶ | if (he) (void)hv_stores(rr, K_SSE, newSVsv(HeVAL(he))); |
Branch: 1 branch
| Branch | True | False | Total |
| if (he) (void)hv_stores(rr, K_SSE, newSVsv(HeVAL(he))); |
10 |
7 |
17 |
|
| 784 |
|
| } |
| 785 |
|
| } |
| 786 |
|
| |
| 787 |
|
| /* views */ |
| 788 |
|
| { |
| 789 |
647 |
| AV *views = app_av(aTHX_ h, K_VIEWS); |
| 790 |
|
| /* the `asset` filter on the shipped engine, so a template can |
| 791 |
|
| * write {% "/static/app.css" | asset %}. Only stencil, because |
| 792 |
|
| * `filters` is its option; only when the application has not |
| 793 |
|
| * registered a filter of its own by that name. */ |
| 794 |
|
| { |
| 795 |
647 |
| SSize_t vi, vn = av_len(views) + 1; |
| 796 |
719 |
▶ | for (vi = 0; vi < vn; vi++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (vi = 0; vi < vn; vi++) { |
72 |
647 |
719 |
|
| 797 |
72 |
| SV **pp = av_fetch(views, vi, 0); |
| 798 |
|
| AV *pair; |
| 799 |
|
| SV **nm, **op; |
| 800 |
|
| HV *vopts, *filters; |
| 801 |
72 |
▶ | if (!(pp && *pp && SvROK(*pp))) continue; |
Branch: 3 branches
| Branch | True | False | Total |
| if (!(pp && *pp && SvROK(*pp))) continue; |
72 |
0 |
72 |
| if (!(pp && *pp && SvROK(*pp))) continue; |
72 |
0 |
72 |
| if (!(pp && *pp && SvROK(*pp))) continue; |
0 |
72 |
72 |
|
| 802 |
72 |
| pair = (AV *)SvRV(*pp); |
| 803 |
72 |
| nm = av_fetch(pair, 0, 0); |
| 804 |
72 |
| op = av_fetch(pair, 1, 0); |
| 805 |
72 |
▶ | if (!(nm && *nm && SvOK(*nm))) continue; |
Branch: 3 branches
| Branch | True | False | Total |
| if (!(nm && *nm && SvOK(*nm))) continue; |
72 |
0 |
72 |
| if (!(nm && *nm && SvOK(*nm))) continue; |
72 |
0 |
72 |
| if (!(nm && *nm && SvOK(*nm))) continue; |
0 |
72 |
72 |
|
| 806 |
|
| { /* `views Stencil => {...}` names a class suffix, so |
| 807 |
|
| * it is matched the way pv_load_engine resolves it - |
| 808 |
|
| * including the +Punk::View::Stencil spelling */ |
| 809 |
|
| STRLEN nl; |
| 810 |
72 |
| const char *nv = SvPV_const(*nm, nl); |
| 811 |
62 |
▶ | int ok = (nl == 7 && foldEQ(nv, "Stencil", 7)) |
Branch: 1 branch
| Branch | True | False | Total |
| int ok = (nl == 7 && foldEQ(nv, "Stencil", 7)) |
0 |
62 |
62 |
|
| 812 |
134 |
▶ | || (nl == 20 && memEQ(nv, "+Punk::View::Stencil", 20)); |
Branch: 3 branches
| Branch | True | False | Total |
| || (nl == 20 && memEQ(nv, "+Punk::View::Stencil", 20)); |
62 |
10 |
72 |
| || (nl == 20 && memEQ(nv, "+Punk::View::Stencil", 20)); |
0 |
10 |
10 |
| || (nl == 20 && memEQ(nv, "+Punk::View::Stencil", 20)); |
0 |
0 |
0 |
|
| 813 |
72 |
▶ | if (!ok) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!ok) continue; |
10 |
62 |
72 |
|
| 814 |
|
| } |
| 815 |
62 |
▶ | if (!(op && *op && SvROK(*op) |
Branch: 3 branches
| Branch | True | False | Total |
| if (!(op && *op && SvROK(*op) |
62 |
0 |
62 |
| if (!(op && *op && SvROK(*op) |
62 |
0 |
62 |
| if (!(op && *op && SvROK(*op) |
62 |
0 |
62 |
|
| 816 |
62 |
▶ | && SvTYPE(SvRV(*op)) == SVt_PVHV)) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| && SvTYPE(SvRV(*op)) == SVt_PVHV)) continue; |
0 |
62 |
62 |
|
| 817 |
62 |
| vopts = (HV *)SvRV(*op); |
| 818 |
|
| { |
| 819 |
62 |
| SV **fp = hv_fetchs(vopts, "filters", 0); |
| 820 |
62 |
▶ | if (fp && *fp && SvROK(*fp) |
Branch: 3 branches
| Branch | True | False | Total |
| if (fp && *fp && SvROK(*fp) |
4 |
58 |
62 |
| if (fp && *fp && SvROK(*fp) |
4 |
0 |
4 |
| if (fp && *fp && SvROK(*fp) |
4 |
0 |
4 |
|
| 821 |
4 |
▶ | && SvTYPE(SvRV(*fp)) == SVt_PVHV) |
Branch: 1 branch
| Branch | True | False | Total |
| && SvTYPE(SvRV(*fp)) == SVt_PVHV) |
4 |
0 |
4 |
|
| 822 |
4 |
| filters = (HV *)SvRV(*fp); |
| 823 |
|
| else { |
| 824 |
58 |
| filters = newHV(); |
| 825 |
58 |
| (void)hv_stores(vopts, "filters", |
| 826 |
|
| newRV_noinc((SV *)filters)); |
| 827 |
|
| } |
| 828 |
|
| } |
| 829 |
62 |
▶ | if (!hv_exists(filters, "asset", 5)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!hv_exists(filters, "asset", 5)) |
61 |
1 |
62 |
|
| 830 |
61 |
| (void)hv_stores(filters, "asset", |
| 831 |
|
| pa_asset_filter(aTHX_ self)); |
| 832 |
|
| /* ... and `url_for`, on the same terms. The |
| 833 |
|
| * application's own filter of either name wins, |
| 834 |
|
| * silently: `filters` is the application's, and Punk |
| 835 |
|
| * adds to it only where it left a gap. The prefix slot |
| 836 |
|
| * is created once and held by both the closure and the |
| 837 |
|
| * app, so the binder can set it per render. */ |
| 838 |
62 |
▶ | if (!hv_exists(filters, "url_for", 7)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!hv_exists(filters, "url_for", 7)) { |
61 |
1 |
62 |
|
| 839 |
61 |
| SV *slot = hv_fetchs(h, K_URL_PREFIX_C, 0) |
| 840 |
61 |
▶ | ? *hv_fetchs(h, K_URL_PREFIX_C, 0) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| ? *hv_fetchs(h, K_URL_PREFIX_C, 0) : NULL; |
0 |
61 |
61 |
|
| 841 |
61 |
▶ | if (!slot) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!slot) { |
61 |
0 |
61 |
|
| 842 |
61 |
| slot = newSVpvs(""); |
| 843 |
61 |
| (void)hv_stores(h, K_URL_PREFIX_C, slot); |
| 844 |
|
| } |
| 845 |
61 |
| (void)hv_stores(filters, "url_for", |
| 846 |
|
| pk_url_filter(aTHX_ self, slot)); |
| 847 |
|
| } |
| 848 |
|
| } |
| 849 |
|
| } |
| 850 |
647 |
▶ | if (av_len(views) >= 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (av_len(views) >= 0) { |
70 |
577 |
647 |
|
| 851 |
|
| SV *argv[1], *vobj; |
| 852 |
70 |
| (void)pk_require_once(aTHX_ PK_VIEWS, TRUE); |
| 853 |
70 |
| argv[0] = sv_2mortal(newRV_inc((SV *)views)); |
| 854 |
70 |
| vobj = pcx_call_meth(aTHX_ sv_2mortal(newSVpvs(PK_VIEWS)), |
| 855 |
|
| "new", argv, 1, 1); |
| 856 |
68 |
▶ | (void)hv_stores(h, K_VIEWS_C, vobj ? vobj : newSV(0)); |
Branch: 1 branch
| Branch | True | False | Total |
| (void)hv_stores(h, K_VIEWS_C, vobj ? vobj : newSV(0)); |
0 |
68 |
68 |
|
| 857 |
|
| } |
| 858 |
577 |
| else (void)hv_stores(h, K_VIEWS_C, newSV(0)); |
| 859 |
|
| } |
| 860 |
|
| |
| 861 |
645 |
| pc_compile_models(aTHX_ self); |
| 862 |
|
| |
| 863 |
|
| /* static / psgi mounts: instantiate the static apps, order longest */ |
| 864 |
645 |
| mount_src = app_av(aTHX_ h, K_MOUNTS); |
| 865 |
645 |
| n = av_len(mount_src) + 1; |
| 866 |
746 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
131 |
615 |
746 |
|
| 867 |
131 |
| HV *src = (HV *)SvRV(*av_fetch(mount_src, i, 0)); |
| 868 |
131 |
| HV *m = newHVhv(src); |
| 869 |
131 |
| SV **dir = hv_fetchs(m, K_DIR, 0); |
| 870 |
131 |
| SV **mdir = hv_fetchs(m, K_MD_DIR, 0); |
| 871 |
167 |
▶ | if (dir && *dir && SvOK(*dir)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (dir && *dir && SvOK(*dir)) { |
37 |
94 |
131 |
| if (dir && *dir && SvOK(*dir)) { |
37 |
0 |
37 |
| if (dir && *dir && SvOK(*dir)) { |
37 |
0 |
37 |
|
| 872 |
|
| SV *argv[2], *sapp; |
| 873 |
37 |
| SV **sop = hv_fetchs(m, K_OPTS, 0); |
| 874 |
37 |
▶ | HV *sopts = (sop && *sop && SvROK(*sop) |
Branch: 2 branches
| Branch | True | False | Total |
| HV *sopts = (sop && *sop && SvROK(*sop) |
37 |
0 |
37 |
| HV *sopts = (sop && *sop && SvROK(*sop) |
37 |
0 |
37 |
|
| 875 |
37 |
▶ | && SvTYPE(SvRV(*sop)) == SVt_PVHV) |
Branch: 1 branch
| Branch | True | False | Total |
| && SvTYPE(SvRV(*sop)) == SVt_PVHV) |
37 |
0 |
37 |
|
| 876 |
74 |
▶ | ? newHVhv((HV *)SvRV(*sop)) : newHV(); |
Branch: 1 branch
| Branch | True | False | Total |
| ? newHVhv((HV *)SvRV(*sop)) : newHV(); |
37 |
0 |
37 |
|
| 877 |
|
| /* whether a cached digest is re-checked against the file is |
| 878 |
|
| * the app's environment, not the mount's - an app that says |
| 879 |
|
| * nothing gets the answer $app->env gives, which reads the |
| 880 |
|
| * config before it reads PUNK_ENV */ |
| 881 |
37 |
▶ | if (!hv_exists(sopts, "dev", 3)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!hv_exists(sopts, "dev", 3)) { |
37 |
0 |
37 |
|
| 882 |
37 |
| SV *envsv = pc_app_env(aTHX_ self); |
| 883 |
74 |
▶ | (void)hv_stores(sopts, "dev", |
Branch: 2 branches
| Branch | True | False | Total |
| (void)hv_stores(sopts, "dev", |
37 |
0 |
37 |
| (void)hv_stores(sopts, "dev", |
0 |
37 |
37 |
|
| 884 |
|
| newSViv(SvOK(envsv) |
| 885 |
|
| && strEQ(SvPV_nolen(envsv), "development"))); |
| 886 |
|
| } |
| 887 |
37 |
| argv[0] = *dir; |
| 888 |
37 |
| argv[1] = sv_2mortal(newRV_noinc((SV *)sopts)); |
| 889 |
37 |
| sapp = pcx_call_meth(aTHX_ sv_2mortal(newSVpvs(PK_STATIC)), |
| 890 |
|
| K_APP, argv, 2, 1); |
| 891 |
36 |
▶ | (void)hv_stores(m, K_APP, sapp ? sapp : newSV(0)); |
Branch: 1 branch
| Branch | True | False | Total |
| (void)hv_stores(m, K_APP, sapp ? sapp : newSV(0)); |
0 |
36 |
36 |
|
| 892 |
|
| } |
| 893 |
94 |
▶ | else if (mdir && *mdir && SvOK(*mdir)) { |
Branch: 3 branches
| Branch | True | False | Total |
| else if (mdir && *mdir && SvOK(*mdir)) { |
80 |
14 |
94 |
| else if (mdir && *mdir && SvOK(*mdir)) { |
80 |
0 |
80 |
| else if (mdir && *mdir && SvOK(*mdir)) { |
80 |
0 |
80 |
|
| 894 |
|
| /* The whole documentation site is built here, at boot: the |
| 895 |
|
| * tree is walked, every page rendered and frozen, and the |
| 896 |
|
| * search index filled. A bad template or an unreadable |
| 897 |
|
| * directory is a configuration error and fails with the rest |
| 898 |
|
| * of the configuration rather than on the first request. */ |
| 899 |
|
| SV *argv[3], *mapp; |
| 900 |
80 |
| SV **op = hv_fetchs(m, K_OPTS, 0); |
| 901 |
80 |
| HV *mo = newHV(); |
| 902 |
|
| /* A copy, so the app's `host` can ride along for the |
| 903 |
|
| * canonical URLs without editing the caller's options. An |
| 904 |
|
| * explicit `host` on the mount wins. */ |
| 905 |
80 |
▶ | if (op && *op && SvROK(*op) |
Branch: 3 branches
| Branch | True | False | Total |
| if (op && *op && SvROK(*op) |
80 |
0 |
80 |
| if (op && *op && SvROK(*op) |
80 |
0 |
80 |
| if (op && *op && SvROK(*op) |
80 |
0 |
80 |
|
| 906 |
80 |
▶ | && SvTYPE(SvRV(*op)) == SVt_PVHV) { |
Branch: 1 branch
| Branch | True | False | Total |
| && SvTYPE(SvRV(*op)) == SVt_PVHV) { |
80 |
0 |
80 |
|
| 907 |
80 |
| HV *src = (HV *)SvRV(*op); |
| 908 |
|
| HE *he; |
| 909 |
80 |
| hv_iterinit(src); |
| 910 |
202 |
▶ | while ((he = hv_iternext(src))) |
Branch: 1 branch
| Branch | True | False | Total |
| while ((he = hv_iternext(src))) |
122 |
80 |
202 |
|
| 911 |
122 |
| (void)hv_store_ent(mo, hv_iterkeysv(he), |
| 912 |
|
| newSVsv(HeVAL(he)), 0); |
| 913 |
|
| } |
| 914 |
80 |
▶ | if (!hv_exists(mo, "host", 4)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!hv_exists(mo, "host", 4)) { |
79 |
1 |
80 |
|
| 915 |
79 |
| SV *host = app_get(aTHX_ h, "host"); |
| 916 |
79 |
▶ | if (host && SvOK(host) && SvCUR(host)) |
Branch: 3 branches
| Branch | True | False | Total |
| if (host && SvOK(host) && SvCUR(host)) |
2 |
77 |
79 |
| if (host && SvOK(host) && SvCUR(host)) |
2 |
0 |
2 |
| if (host && SvOK(host) && SvCUR(host)) |
2 |
0 |
2 |
|
| 917 |
2 |
| (void)hv_stores(mo, "host", newSVsv(host)); |
| 918 |
|
| } |
| 919 |
80 |
| argv[0] = *mdir; |
| 920 |
80 |
| argv[1] = sv_2mortal(newRV_noinc((SV *)mo)); |
| 921 |
80 |
| argv[2] = *hv_fetchs(m, K_PREFIX, 0); |
| 922 |
80 |
| mapp = pcx_call_meth(aTHX_ sv_2mortal(newSVpvs(PK_MOUNT_MD)), |
| 923 |
|
| K_APP, argv, 3, 1); |
| 924 |
51 |
▶ | (void)hv_stores(m, K_APP, mapp ? mapp : newSV(0)); |
Branch: 1 branch
| Branch | True | False | Total |
| (void)hv_stores(m, K_APP, mapp ? mapp : newSV(0)); |
0 |
51 |
51 |
|
| 925 |
|
| /* what $app->markdown_pages looks for: a closure's capture |
| 926 |
|
| * says nothing about whose it is */ |
| 927 |
51 |
| (void)hv_stores(m, K_MD_MOUNT, newSViv(1)); |
| 928 |
|
| } |
| 929 |
101 |
| av_push(mounts_out, newRV_noinc((SV *)m)); |
| 930 |
|
| } |
| 931 |
615 |
▶ | if (av_len(mounts_out) >= 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (av_len(mounts_out) >= 0) |
94 |
521 |
615 |
|
| 932 |
94 |
| sortsv(AvARRAY(mounts_out), (STRLEN)(av_len(mounts_out) + 1), |
| 933 |
|
| pc_cmp_len_desc); |
| 934 |
|
| /* the same table on the app, the way the compiled views already sit |
| 935 |
|
| * there: $c->asset walks it to find which mount owns a URL, and the |
| 936 |
|
| * request path's copy is not reachable from a context */ |
| 937 |
615 |
| (void)hv_stores(h, K_MOUNTS_C, newRV_inc((SV *)mounts_out)); |
| 938 |
|
| |
| 939 |
|
| /* before / after hooks and the app on_error, resolved to coderefs */ |
| 940 |
|
| { |
| 941 |
615 |
| HV *hooks = app_hash(aTHX_ h, K_HOOKS); |
| 942 |
615 |
| SV **rp = hv_fetchs(hooks, K_BEFORE_R, 0); |
| 943 |
615 |
| SV **bp = hv_fetchs(hooks, K_BEFORE_D, 0); |
| 944 |
615 |
| SV **ap = hv_fetchs(hooks, K_AFTER_D, 0); |
| 945 |
615 |
▶ | AV *rl = (rp && *rp && SvROK(*rp)) ? (AV *)SvRV(*rp) : NULL; |
Branch: 3 branches
| Branch | True | False | Total |
| AV *rl = (rp && *rp && SvROK(*rp)) ? (AV *)SvRV(*rp) : NULL; |
615 |
0 |
615 |
| AV *rl = (rp && *rp && SvROK(*rp)) ? (AV *)SvRV(*rp) : NULL; |
615 |
0 |
615 |
| AV *rl = (rp && *rp && SvROK(*rp)) ? (AV *)SvRV(*rp) : NULL; |
615 |
0 |
615 |
|
| 946 |
615 |
▶ | AV *bl = (bp && *bp && SvROK(*bp)) ? (AV *)SvRV(*bp) : NULL; |
Branch: 3 branches
| Branch | True | False | Total |
| AV *bl = (bp && *bp && SvROK(*bp)) ? (AV *)SvRV(*bp) : NULL; |
615 |
0 |
615 |
| AV *bl = (bp && *bp && SvROK(*bp)) ? (AV *)SvRV(*bp) : NULL; |
615 |
0 |
615 |
| AV *bl = (bp && *bp && SvROK(*bp)) ? (AV *)SvRV(*bp) : NULL; |
615 |
0 |
615 |
|
| 947 |
615 |
▶ | AV *al = (ap && *ap && SvROK(*ap)) ? (AV *)SvRV(*ap) : NULL; |
Branch: 3 branches
| Branch | True | False | Total |
| AV *al = (ap && *ap && SvROK(*ap)) ? (AV *)SvRV(*ap) : NULL; |
615 |
0 |
615 |
| AV *al = (ap && *ap && SvROK(*ap)) ? (AV *)SvRV(*ap) : NULL; |
615 |
0 |
615 |
| AV *al = (ap && *ap && SvROK(*ap)) ? (AV *)SvRV(*ap) : NULL; |
615 |
0 |
615 |
|
| 948 |
615 |
| SV *whatr = sv_2mortal(newSVpvs("before_request hook")); |
| 949 |
615 |
| SV *whatb = sv_2mortal(newSVpvs("before_dispatch hook")); |
| 950 |
615 |
| SV *whata = sv_2mortal(newSVpvs("after_dispatch hook")); |
| 951 |
615 |
▶ | n = rl ? av_len(rl) + 1 : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| n = rl ? av_len(rl) + 1 : 0; |
615 |
0 |
615 |
|
| 952 |
631 |
▶ | for (i = 0; i < n; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) |
16 |
615 |
631 |
|
| 953 |
16 |
| av_push(before_req_out, |
| 954 |
|
| pc_resolve_target(aTHX_ self, *av_fetch(rl, i, 0), whatr)); |
| 955 |
615 |
▶ | n = bl ? av_len(bl) + 1 : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| n = bl ? av_len(bl) + 1 : 0; |
615 |
0 |
615 |
|
| 956 |
647 |
▶ | for (i = 0; i < n; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) |
32 |
615 |
647 |
|
| 957 |
32 |
| av_push(before_out, |
| 958 |
|
| pc_resolve_target(aTHX_ self, *av_fetch(bl, i, 0), whatb)); |
| 959 |
615 |
▶ | n = al ? av_len(al) + 1 : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| n = al ? av_len(al) + 1 : 0; |
615 |
0 |
615 |
|
| 960 |
621 |
▶ | for (i = 0; i < n; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) |
6 |
615 |
621 |
|
| 961 |
6 |
| av_push(after_out, |
| 962 |
|
| pc_resolve_target(aTHX_ self, *av_fetch(al, i, 0), whata)); |
| 963 |
|
| |
| 964 |
|
| /* before_render lives on the app rather than in the request |
| 965 |
|
| * state: a render is reached from a context, and the views object |
| 966 |
|
| * has no route to the compiled state the dispatcher carries. |
| 967 |
|
| * Stored only when there is one, so the ordinary render does one |
| 968 |
|
| * hv_fetch that misses and nothing else. */ |
| 969 |
|
| { |
| 970 |
615 |
| SV **np = hv_fetchs(hooks, K_BEFORE_RN, 0); |
| 971 |
615 |
▶ | AV *nl = (np && *np && SvROK(*np)) ? (AV *)SvRV(*np) : NULL; |
Branch: 3 branches
| Branch | True | False | Total |
| AV *nl = (np && *np && SvROK(*np)) ? (AV *)SvRV(*np) : NULL; |
615 |
0 |
615 |
| AV *nl = (np && *np && SvROK(*np)) ? (AV *)SvRV(*np) : NULL; |
615 |
0 |
615 |
| AV *nl = (np && *np && SvROK(*np)) ? (AV *)SvRV(*np) : NULL; |
615 |
0 |
615 |
|
| 972 |
615 |
| SV *whatn = sv_2mortal(newSVpvs("before_render hook")); |
| 973 |
615 |
▶ | n = nl ? av_len(nl) + 1 : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| n = nl ? av_len(nl) + 1 : 0; |
615 |
0 |
615 |
|
| 974 |
615 |
▶ | if (n) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (n) { |
10 |
605 |
615 |
|
| 975 |
10 |
| AV *render_out = newAV(); |
| 976 |
21 |
▶ | for (i = 0; i < n; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) |
11 |
10 |
21 |
|
| 977 |
11 |
| av_push(render_out, pc_resolve_target(aTHX_ self, |
| 978 |
|
| *av_fetch(nl, i, 0), whatn)); |
| 979 |
10 |
| (void)hv_stores(h, K_BEFORE_RENDER_C, |
| 980 |
|
| newRV_noinc((SV *)render_out)); |
| 981 |
|
| } |
| 982 |
|
| } |
| 983 |
|
| |
| 984 |
|
| /* after_response lives on the app for the same reason: it is |
| 985 |
|
| * reached from a context at delivery, and a delivery from a |
| 986 |
|
| * settled future has no route to the compiled state. Stored only |
| 987 |
|
| * when there is one, so a response in an application that |
| 988 |
|
| * declares none does one hv_fetch that misses. */ |
| 989 |
|
| { |
| 990 |
615 |
| SV **sp2 = hv_fetchs(hooks, K_AFTER_RES, 0); |
| 991 |
615 |
▶ | AV *sl = (sp2 && *sp2 && SvROK(*sp2)) ? (AV *)SvRV(*sp2) : NULL; |
Branch: 3 branches
| Branch | True | False | Total |
| AV *sl = (sp2 && *sp2 && SvROK(*sp2)) ? (AV *)SvRV(*sp2) : NULL; |
615 |
0 |
615 |
| AV *sl = (sp2 && *sp2 && SvROK(*sp2)) ? (AV *)SvRV(*sp2) : NULL; |
615 |
0 |
615 |
| AV *sl = (sp2 && *sp2 && SvROK(*sp2)) ? (AV *)SvRV(*sp2) : NULL; |
615 |
0 |
615 |
|
| 992 |
615 |
| SV *whats = sv_2mortal(newSVpvs("after_response hook")); |
| 993 |
615 |
▶ | n = sl ? av_len(sl) + 1 : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| n = sl ? av_len(sl) + 1 : 0; |
615 |
0 |
615 |
|
| 994 |
615 |
▶ | if (n) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (n) { |
2 |
613 |
615 |
|
| 995 |
2 |
| AV *ares_out = newAV(); |
| 996 |
4 |
▶ | for (i = 0; i < n; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) |
2 |
2 |
4 |
|
| 997 |
2 |
| av_push(ares_out, pc_resolve_target(aTHX_ self, |
| 998 |
|
| *av_fetch(sl, i, 0), whats)); |
| 999 |
2 |
| (void)hv_stores(h, K_AFTER_RES_C, |
| 1000 |
|
| newRV_noinc((SV *)ares_out)); |
| 1001 |
|
| } |
| 1002 |
|
| } |
| 1003 |
|
| |
| 1004 |
|
| /* The csrf check goes at the head of before_dispatch: a forged |
| 1005 |
|
| * request should be refused before an application hook sees it. */ |
| 1006 |
|
| { |
| 1007 |
615 |
| SV **cc = hv_fetchs(h, K_CSRF, 0); |
| 1008 |
615 |
▶ | if (cc && *cc && SvROK(*cc)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (cc && *cc && SvROK(*cc)) { |
19 |
596 |
615 |
| if (cc && *cc && SvROK(*cc)) { |
19 |
0 |
19 |
| if (cc && *cc && SvROK(*cc)) { |
19 |
0 |
19 |
|
| 1009 |
19 |
| CV *ck = get_cv("Punk::CSRF::_check", 0); |
| 1010 |
19 |
▶ | if (ck) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ck) { |
19 |
0 |
19 |
|
| 1011 |
19 |
| av_unshift(before_out, 1); |
| 1012 |
19 |
| (void)av_store(before_out, 0, newRV_inc((SV *)ck)); |
| 1013 |
|
| } |
| 1014 |
|
| } |
| 1015 |
|
| } |
| 1016 |
|
| } |
| 1017 |
|
| |
| 1018 |
|
| /* when sessions are configured, the write-back runs last (it sees the |
| 1019 |
|
| * finished triplet and adds the signed Set-Cookie) */ |
| 1020 |
|
| { |
| 1021 |
615 |
| SV **sc = hv_fetchs(h, "session", 0); |
| 1022 |
615 |
▶ | if (sc && *sc && SvROK(*sc)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (sc && *sc && SvROK(*sc)) { |
83 |
532 |
615 |
| if (sc && *sc && SvROK(*sc)) { |
83 |
0 |
83 |
| if (sc && *sc && SvROK(*sc)) { |
83 |
0 |
83 |
|
| 1023 |
83 |
| CV *wb = get_cv("Punk::Session::_writeback", 0); |
| 1024 |
83 |
▶ | if (wb) av_push(after_out, newRV_inc((SV *)wb)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (wb) av_push(after_out, newRV_inc((SV *)wb)); |
83 |
0 |
83 |
|
| 1025 |
|
| } |
| 1026 |
|
| /* csrf rides on the session - the token has nowhere else to live - |
| 1027 |
|
| * and its mirror cookie goes out after the session's own, on the |
| 1028 |
|
| * same response */ |
| 1029 |
|
| { |
| 1030 |
615 |
| SV **cc = hv_fetchs(h, K_CSRF, 0); |
| 1031 |
615 |
▶ | if (cc && *cc && SvROK(*cc)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (cc && *cc && SvROK(*cc)) { |
19 |
596 |
615 |
| if (cc && *cc && SvROK(*cc)) { |
19 |
0 |
19 |
| if (cc && *cc && SvROK(*cc)) { |
19 |
0 |
19 |
|
| 1032 |
|
| CV *wb; |
| 1033 |
19 |
▶ | if (!(sc && *sc && SvROK(*sc))) |
Branch: 3 branches
| Branch | True | False | Total |
| if (!(sc && *sc && SvROK(*sc))) |
18 |
1 |
19 |
| if (!(sc && *sc && SvROK(*sc))) |
18 |
0 |
18 |
| if (!(sc && *sc && SvROK(*sc))) |
0 |
18 |
18 |
|
| 1034 |
1 |
| croak("Punk: `csrf` needs a session for the token to " |
| 1035 |
|
| "live in - add a `session` keyword"); |
| 1036 |
18 |
| wb = get_cv("Punk::CSRF::_writeback", 0); |
| 1037 |
18 |
▶ | if (wb) av_push(after_out, newRV_inc((SV *)wb)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (wb) av_push(after_out, newRV_inc((SV *)wb)); |
18 |
0 |
18 |
|
| 1038 |
|
| } |
| 1039 |
|
| } |
| 1040 |
|
| } |
| 1041 |
|
| |
| 1042 |
|
| { /* the body ETag, last on the chain - after any application hook |
| 1043 |
|
| * that might rewrite the body (or the tag would describe bytes |
| 1044 |
|
| * nobody was sent) and after the session write-back (whose |
| 1045 |
|
| * Set-Cookie the 304 then carries rather than drops) */ |
| 1046 |
614 |
| SV **cg = hv_fetchs(h, K_CGET, 0); |
| 1047 |
614 |
▶ | if (cg && *cg && SvTRUE(*cg)) |
Branch: 3 branches
| Branch | True | False | Total |
| if (cg && *cg && SvTRUE(*cg)) |
19 |
595 |
614 |
| if (cg && *cg && SvTRUE(*cg)) |
19 |
0 |
19 |
| if (cg && *cg && SvTRUE(*cg)) |
19 |
0 |
19 |
|
| 1048 |
19 |
| av_push(after_out, |
| 1049 |
|
| punk_closure(aTHX_ pcg_after_cb, newAV())); |
| 1050 |
|
| } |
| 1051 |
|
| |
| 1052 |
|
| { /* the idempotency recorder, also last: what is stored has to be |
| 1053 |
|
| * what was actually sent, after every application hook has had |
| 1054 |
|
| * its say. The TTL rides in the capture rather than being read |
| 1055 |
|
| * from the state per response. */ |
| 1056 |
614 |
| SV **ic = hv_fetchs(h, K_IDEM, 0); |
| 1057 |
614 |
▶ | if (ic && *ic && SvROK(*ic) && SvTYPE(SvRV(*ic)) == SVt_PVHV) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (ic && *ic && SvROK(*ic) && SvTYPE(SvRV(*ic)) == SVt_PVHV) { |
11 |
603 |
614 |
| if (ic && *ic && SvROK(*ic) && SvTYPE(SvRV(*ic)) == SVt_PVHV) { |
11 |
0 |
11 |
| if (ic && *ic && SvROK(*ic) && SvTYPE(SvRV(*ic)) == SVt_PVHV) { |
11 |
0 |
11 |
| if (ic && *ic && SvROK(*ic) && SvTYPE(SvRV(*ic)) == SVt_PVHV) { |
11 |
0 |
11 |
|
| 1058 |
11 |
| AV *cap = newAV(); |
| 1059 |
11 |
| SV **t = hv_fetchs((HV *)SvRV(*ic), "ttl", 0); |
| 1060 |
11 |
| SV **m = hv_fetchs((HV *)SvRV(*ic), "max_record", 0); |
| 1061 |
11 |
▶ | av_push(cap, (t && *t && SvOK(*t)) ? newSVnv(SvNV(*t)) |
Branch: 3 branches
| Branch | True | False | Total |
| av_push(cap, (t && *t && SvOK(*t)) ? newSVnv(SvNV(*t)) |
11 |
0 |
11 |
| av_push(cap, (t && *t && SvOK(*t)) ? newSVnv(SvNV(*t)) |
11 |
0 |
11 |
| av_push(cap, (t && *t && SvOK(*t)) ? newSVnv(SvNV(*t)) |
11 |
0 |
11 |
|
| 1062 |
|
| : newSVnv(86400)); |
| 1063 |
11 |
▶ | av_push(cap, (m && *m && SvOK(*m)) ? newSViv(SvIV(*m)) |
Branch: 3 branches
| Branch | True | False | Total |
| av_push(cap, (m && *m && SvOK(*m)) ? newSViv(SvIV(*m)) |
11 |
0 |
11 |
| av_push(cap, (m && *m && SvOK(*m)) ? newSViv(SvIV(*m)) |
11 |
0 |
11 |
| av_push(cap, (m && *m && SvOK(*m)) ? newSViv(SvIV(*m)) |
11 |
0 |
11 |
|
| 1064 |
|
| : newSViv(1048576)); |
| 1065 |
11 |
| av_push(after_out, punk_closure(aTHX_ pi_record_cb, cap)); |
| 1066 |
|
| } |
| 1067 |
|
| } |
| 1068 |
|
| |
| 1069 |
614 |
▶ | if (pcx_can(aTHX_ self, "compile_extras")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (pcx_can(aTHX_ self, "compile_extras")) { |
614 |
0 |
614 |
|
| 1070 |
614 |
| SV *r = pcx_call_meth(aTHX_ self, "compile_extras", NULL, 0, 0); |
| 1071 |
610 |
▶ | if (r) SvREFCNT_dec(r); |
Branch: 1 branch
| Branch | True | False | Total |
| if (r) SvREFCNT_dec(r); |
0 |
610 |
610 |
|
| 1072 |
|
| } |
| 1073 |
|
| |
| 1074 |
|
| /* flatten the api mounts to the fields the C dispatcher reads */ |
| 1075 |
610 |
| n = av_len(api_mounts) + 1; |
| 1076 |
635 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
25 |
610 |
635 |
|
| 1077 |
25 |
| HV *rec = (HV *)SvRV(*av_fetch(api_mounts, i, 0)); |
| 1078 |
25 |
| SV *m = *hv_fetchs(rec, K_MOUNT, 0); |
| 1079 |
25 |
| SV *pfx = *hv_fetchs(rec, K_PREFIX, 0); |
| 1080 |
25 |
| HV *flat = newHV(); |
| 1081 |
25 |
| SV *apio = pcx_call_meth(aTHX_ m, K_API, NULL, 0, 1); |
| 1082 |
25 |
| SV *opso = pcx_call_meth(aTHX_ m, K_OPS, NULL, 0, 1); |
| 1083 |
25 |
| SV *mbo = pcx_call_meth(aTHX_ m, "max_body_size", NULL, 0, 1); |
| 1084 |
25 |
| SV *oeo = pcx_call_meth(aTHX_ m, K_ON_ERROR, NULL, 0, 1); |
| 1085 |
25 |
| (void)hv_stores(flat, K_PREFIX, newSVsv(pfx)); |
| 1086 |
25 |
▶ | (void)hv_stores(flat, K_API, apio ? apio : newSV(0)); |
Branch: 1 branch
| Branch | True | False | Total |
| (void)hv_stores(flat, K_API, apio ? apio : newSV(0)); |
0 |
25 |
25 |
|
| 1087 |
25 |
▶ | (void)hv_stores(flat, K_OPS, opso ? opso : newSV(0)); |
Branch: 1 branch
| Branch | True | False | Total |
| (void)hv_stores(flat, K_OPS, opso ? opso : newSV(0)); |
0 |
25 |
25 |
|
| 1088 |
25 |
▶ | (void)hv_stores(flat, K_MAX_BODY, mbo ? mbo : newSV(0)); |
Branch: 1 branch
| Branch | True | False | Total |
| (void)hv_stores(flat, K_MAX_BODY, mbo ? mbo : newSV(0)); |
0 |
25 |
25 |
|
| 1089 |
25 |
▶ | (void)hv_stores(flat, K_ON_ERROR, oeo ? oeo : newSV(0)); |
Branch: 1 branch
| Branch | True | False | Total |
| (void)hv_stores(flat, K_ON_ERROR, oeo ? oeo : newSV(0)); |
0 |
25 |
25 |
|
| 1090 |
25 |
| av_push(state_apims, newRV_noinc((SV *)flat)); |
| 1091 |
|
| } |
| 1092 |
|
| |
| 1093 |
610 |
| state = newHV(); |
| 1094 |
|
| { /* the app-wide body ceiling; a route's own value overrides it, |
| 1095 |
|
| * and is stamped onto the compiled record further up */ |
| 1096 |
610 |
| SV **mb = hv_fetchs(h, K_MAX_BODY, 0); |
| 1097 |
610 |
▶ | if (mb && *mb && SvOK(*mb)) |
Branch: 3 branches
| Branch | True | False | Total |
| if (mb && *mb && SvOK(*mb)) |
2 |
608 |
610 |
| if (mb && *mb && SvOK(*mb)) |
2 |
0 |
2 |
| if (mb && *mb && SvOK(*mb)) |
2 |
0 |
2 |
|
| 1098 |
2 |
| (void)hv_stores(state, K_MAX_BODY, newSViv(SvIV(*mb))); |
| 1099 |
|
| } |
| 1100 |
610 |
| (void)hv_stores(state, K_ROUTER, newSVsv(xs_router)); |
| 1101 |
610 |
| (void)hv_stores(state, K_RECS, newSVsv(all_recs)); |
| 1102 |
610 |
| (void)hv_stores(state, K_API_MOUNTS, newRV_noinc((SV *)state_apims)); |
| 1103 |
610 |
| (void)hv_stores(state, K_MOUNTS, newRV_noinc((SV *)mounts_out)); |
| 1104 |
610 |
| (void)hv_stores(state, K_CTX, newSVsv(ctx)); |
| 1105 |
610 |
| (void)hv_stores(state, K_APP, newSVsv(self)); |
| 1106 |
|
| { /* upload_dir, so the multipart parser can reach it: it has the |
| 1107 |
|
| * request's env and nothing else, and the env is the server's. */ |
| 1108 |
610 |
| SV **ud = hv_fetchs(h, "upload_dir", 0); |
| 1109 |
610 |
▶ | if (ud && *ud && SvOK(*ud)) |
Branch: 3 branches
| Branch | True | False | Total |
| if (ud && *ud && SvOK(*ud)) |
2 |
608 |
610 |
| if (ud && *ud && SvOK(*ud)) |
2 |
0 |
2 |
| if (ud && *ud && SvOK(*ud)) |
2 |
0 |
2 |
|
| 1110 |
2 |
| (void)hv_stores(state, "upload_dir", newSVsv(*ud)); |
| 1111 |
|
| } |
| 1112 |
|
| |
| 1113 |
|
| /* The favicon bytes, frozen now: a missing file croaks here, at |
| 1114 |
|
| * boot, rather than 404ing for as long as nobody notices. */ |
| 1115 |
610 |
| pfav_freeze(aTHX_ h); |
| 1116 |
|
| |
| 1117 |
|
| { /* Punk::Plugin::CSP's policy, copied from the app hash so |
| 1118 |
|
| * phd_effective can read it once per response without walking |
| 1119 |
|
| * back to the registrar. Absent when the plugin was never |
| 1120 |
|
| * registered, which is what keeps the header off. */ |
| 1121 |
609 |
| SV **cs = hv_fetchs(h, K_CSP, 0); |
| 1122 |
609 |
▶ | if (cs && *cs && SvROK(*cs)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (cs && *cs && SvROK(*cs)) { |
62 |
547 |
609 |
| if (cs && *cs && SvROK(*cs)) { |
62 |
0 |
62 |
| if (cs && *cs && SvROK(*cs)) { |
62 |
0 |
62 |
|
| 1123 |
62 |
| (void)hv_stores(state, K_CSP, newSVsv(*cs)); |
| 1124 |
|
| /* Freeze whether this is development INTO the policy hash - |
| 1125 |
|
| * here rather than in register, because `plugin` is written |
| 1126 |
|
| * at the top of an application and `config` below it, so at |
| 1127 |
|
| * registration time the answer is not known yet. |
| 1128 |
|
| * |
| 1129 |
|
| * Both the state and the app hold the same HV, so writing it |
| 1130 |
|
| * once is visible from the view path (which has a context) |
| 1131 |
|
| * and the header path (which has the state), with no second |
| 1132 |
|
| * copy to drift. */ |
| 1133 |
62 |
▶ | if (SvTYPE(SvRV(*cs)) == SVt_PVHV) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvTYPE(SvRV(*cs)) == SVt_PVHV) { |
62 |
0 |
62 |
|
| 1134 |
62 |
| SV *e = pc_app_env(aTHX_ self); |
| 1135 |
124 |
▶ | (void)hv_stores((HV *)SvRV(*cs), "dev", |
Branch: 2 branches
| Branch | True | False | Total |
| (void)hv_stores((HV *)SvRV(*cs), "dev", |
62 |
0 |
62 |
| (void)hv_stores((HV *)SvRV(*cs), "dev", |
0 |
62 |
62 |
|
| 1136 |
|
| newSViv(SvOK(e) && strEQ(SvPV_nolen(e), |
| 1137 |
|
| "development"))); |
| 1138 |
|
| } |
| 1139 |
|
| } |
| 1140 |
|
| } |
| 1141 |
|
| |
| 1142 |
|
| { /* Punk::Plugin::I18n, the same arrangement as CSP above and for |
| 1143 |
|
| * the same reason: whether this is development decides whether a |
| 1144 |
|
| * missing key warns, and `plugin` is written above `config`, so |
| 1145 |
|
| * registration is too early to ask. */ |
| 1146 |
609 |
| SV **is = hv_fetchs(h, K_I18N, 0); |
| 1147 |
609 |
▶ | if (is && *is && SvROK(*is)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (is && *is && SvROK(*is)) { |
30 |
579 |
609 |
| if (is && *is && SvROK(*is)) { |
30 |
0 |
30 |
| if (is && *is && SvROK(*is)) { |
30 |
0 |
30 |
|
| 1148 |
30 |
| (void)hv_stores(state, K_I18N, newSVsv(*is)); |
| 1149 |
30 |
▶ | if (SvTYPE(SvRV(*is)) == SVt_PVHV) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvTYPE(SvRV(*is)) == SVt_PVHV) { |
30 |
0 |
30 |
|
| 1150 |
30 |
| SV *e = pc_app_env(aTHX_ self); |
| 1151 |
60 |
▶ | (void)hv_stores((HV *)SvRV(*is), "dev", |
Branch: 2 branches
| Branch | True | False | Total |
| (void)hv_stores((HV *)SvRV(*is), "dev", |
30 |
0 |
30 |
| (void)hv_stores((HV *)SvRV(*is), "dev", |
1 |
29 |
30 |
|
| 1152 |
|
| newSViv(SvOK(e) && strEQ(SvPV_nolen(e), |
| 1153 |
|
| "development"))); |
| 1154 |
|
| } |
| 1155 |
|
| } |
| 1156 |
|
| } |
| 1157 |
|
| |
| 1158 |
|
| { /* Punk::Plugin::ConditionalGet's on-switch, copied from the app |
| 1159 |
|
| * hash where `register` put it. Absent when the plugin was never |
| 1160 |
|
| * registered, which is what makes the `etag` route option inert |
| 1161 |
|
| * without it - the `sitemap` arrangement. */ |
| 1162 |
609 |
| SV **cg = hv_fetchs(h, K_CGET, 0); |
| 1163 |
609 |
▶ | if (cg && *cg && SvTRUE(*cg)) |
Branch: 3 branches
| Branch | True | False | Total |
| if (cg && *cg && SvTRUE(*cg)) |
19 |
590 |
609 |
| if (cg && *cg && SvTRUE(*cg)) |
19 |
0 |
19 |
| if (cg && *cg && SvTRUE(*cg)) |
19 |
0 |
19 |
|
| 1164 |
19 |
| (void)hv_stores(state, K_CGET, newSVsv(*cg)); |
| 1165 |
|
| } |
| 1166 |
|
| { /* Punk::Plugin::Idempotency's config, from where `register` |
| 1167 |
|
| * put it. Absent when the plugin was never registered, which is |
| 1168 |
|
| * what makes the `idempotent` route option inert without it. */ |
| 1169 |
609 |
| SV **ic = hv_fetchs(h, K_IDEM, 0); |
| 1170 |
609 |
▶ | if (ic && *ic && SvROK(*ic)) |
Branch: 3 branches
| Branch | True | False | Total |
| if (ic && *ic && SvROK(*ic)) |
11 |
598 |
609 |
| if (ic && *ic && SvROK(*ic)) |
11 |
0 |
11 |
| if (ic && *ic && SvROK(*ic)) |
11 |
0 |
11 |
|
| 1171 |
11 |
| (void)hv_stores(state, K_IDEM, newSVsv(*ic)); |
| 1172 |
|
| } |
| 1173 |
609 |
| (void)hv_stores(state, K_BEFORE, newRV_noinc((SV *)before_out)); |
| 1174 |
609 |
| (void)hv_stores(state, K_AFTER, newRV_noinc((SV *)after_out)); |
| 1175 |
|
| /* The before_request chain is stored only when there is one. punk_serve |
| 1176 |
|
| * reads it with ps_state_av, which is NULL for a key that was never |
| 1177 |
|
| * set, so an app without the hook takes the NULL branch: one hv_fetch |
| 1178 |
|
| * and one test, no context built and no chain walked. Storing an empty |
| 1179 |
|
| * AV instead would make the common path the slower one. */ |
| 1180 |
609 |
▶ | if (av_len(before_req_out) >= 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (av_len(before_req_out) >= 0) |
14 |
595 |
609 |
|
| 1181 |
14 |
| (void)hv_stores(state, K_BEFORE_REQ, |
| 1182 |
|
| newRV_noinc((SV *)before_req_out)); |
| 1183 |
|
| else |
| 1184 |
595 |
| SvREFCNT_dec((SV *)before_req_out); |
| 1185 |
|
| { /* the CORS policy, read once per request by pc_app_cb; absent |
| 1186 |
|
| * when the keyword was never used, so it costs one failed fetch */ |
| 1187 |
609 |
| SV **co = hv_fetchs(h, K_CORS, 0); |
| 1188 |
609 |
▶ | if (co && *co && SvROK(*co)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (co && *co && SvROK(*co)) { |
13 |
596 |
609 |
| if (co && *co && SvROK(*co)) { |
13 |
0 |
13 |
| if (co && *co && SvROK(*co)) { |
13 |
0 |
13 |
|
| 1189 |
13 |
| (void)hv_stores(state, K_CORS, newSVsv(*co)); |
| 1190 |
|
| /* Punk::CORS::_chain is the one Perl piece of the path - it |
| 1191 |
|
| * chains the decoration onto a Future - and nothing else |
| 1192 |
|
| * loads the file, so it is required here rather than |
| 1193 |
|
| * discovered missing on the first nonblocking response. */ |
| 1194 |
13 |
▶ | if (!pk_require_once(aTHX_ "Punk::CORS", FALSE)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!pk_require_once(aTHX_ "Punk::CORS", FALSE)) |
0 |
13 |
13 |
|
| 1195 |
0 |
▶ | croak("Punk: cors needs Punk::CORS, which failed to " |
Branch: 1 branch
| Branch | True | False | Total |
| croak("Punk: cors needs Punk::CORS, which failed to " |
0 |
0 |
0 |
|
| 1196 |
|
| "load: %s", SvPV_nolen(ERRSV)); |
| 1197 |
|
| } |
| 1198 |
|
| } |
| 1199 |
|
| { /* the security-header policy: the defaults and the keyword's |
| 1200 |
|
| * overrides merged once, so a request only walks a frozen pair |
| 1201 |
|
| * list; absent when the keyword was never used */ |
| 1202 |
609 |
| SV **hd = hv_fetchs(h, K_HEADERS, 0); |
| 1203 |
609 |
▶ | if (hd && *hd && SvROK(*hd) |
Branch: 3 branches
| Branch | True | False | Total |
| if (hd && *hd && SvROK(*hd) |
6 |
603 |
609 |
| if (hd && *hd && SvROK(*hd) |
6 |
0 |
6 |
| if (hd && *hd && SvROK(*hd) |
6 |
0 |
6 |
|
| 1204 |
6 |
▶ | && SvTYPE(SvRV(*hd)) == SVt_PVHV) { |
Branch: 1 branch
| Branch | True | False | Total |
| && SvTYPE(SvRV(*hd)) == SVt_PVHV) { |
6 |
0 |
6 |
|
| 1205 |
6 |
| AV *pairs = phd_compile(aTHX_ (HV *)SvRV(*hd)); |
| 1206 |
6 |
| (void)hv_stores(state, K_HEADERS, newRV_noinc((SV *)pairs)); |
| 1207 |
|
| /* Punk::Headers::_chain is the one Perl piece of the path, |
| 1208 |
|
| * for the Future shape - required here, like Punk::CORS */ |
| 1209 |
6 |
▶ | if (!pk_require_once(aTHX_ "Punk::Headers", FALSE)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!pk_require_once(aTHX_ "Punk::Headers", FALSE)) |
0 |
6 |
6 |
|
| 1210 |
0 |
▶ | croak("Punk: headers needs Punk::Headers, which failed " |
Branch: 1 branch
| Branch | True | False | Total |
| croak("Punk: headers needs Punk::Headers, which failed " |
0 |
0 |
0 |
|
| 1211 |
|
| "to load: %s", SvPV_nolen(ERRSV)); |
| 1212 |
|
| } |
| 1213 |
|
| } |
| 1214 |
|
| { /* proxy: parse the CIDRs and settle the hop rule once, so a |
| 1215 |
|
| * request is a header fetch and a walk. The policy is a C struct |
| 1216 |
|
| * behind a blessed IV-ref (the Punk::Router shape), freed with |
| 1217 |
|
| * the compiled app. */ |
| 1218 |
609 |
| SV **px = hv_fetchs(h, K_PROXY, 0); |
| 1219 |
609 |
▶ | if (px && *px && SvROK(*px) |
Branch: 3 branches
| Branch | True | False | Total |
| if (px && *px && SvROK(*px) |
18 |
591 |
609 |
| if (px && *px && SvROK(*px) |
18 |
0 |
18 |
| if (px && *px && SvROK(*px) |
18 |
0 |
18 |
|
| 1220 |
18 |
▶ | && SvTYPE(SvRV(*px)) == SVt_PVHV) { |
Branch: 1 branch
| Branch | True | False | Total |
| && SvTYPE(SvRV(*px)) == SVt_PVHV) { |
18 |
0 |
18 |
|
| 1221 |
|
| SV *envsv; |
| 1222 |
|
| pp_policy *pol; |
| 1223 |
|
| { /* $app->env - production unless opted out of, which is |
| 1224 |
|
| * what decides whether trust => 'all' is allowed */ |
| 1225 |
18 |
| dSP; int count; |
| 1226 |
18 |
| ENTER; SAVETMPS; |
| 1227 |
18 |
▶ | PUSHMARK(SP); EXTEND(SP, 1); PUSHs(self); PUTBACK; |
Branch: 2 branches
| Branch | True | False | Total |
| PUSHMARK(SP); EXTEND(SP, 1); PUSHs(self); PUTBACK; |
0 |
18 |
18 |
| PUSHMARK(SP); EXTEND(SP, 1); PUSHs(self); PUTBACK; |
0 |
18 |
18 |
|
| 1228 |
18 |
| count = call_method("env", G_SCALAR); |
| 1229 |
18 |
| SPAGAIN; |
| 1230 |
18 |
▶ | envsv = count > 0 ? newSVsv(POPs) : newSVpvs("production"); |
Branch: 1 branch
| Branch | True | False | Total |
| envsv = count > 0 ? newSVsv(POPs) : newSVpvs("production"); |
18 |
0 |
18 |
|
| 1231 |
18 |
▶ | PUTBACK; FREETMPS; LEAVE; |
Branch: 1 branch
| Branch | True | False | Total |
| PUTBACK; FREETMPS; LEAVE; |
18 |
0 |
18 |
|
| 1232 |
|
| } |
| 1233 |
18 |
| sv_2mortal(envsv); |
| 1234 |
18 |
| pol = pp_compile(aTHX_ (HV *)SvRV(*px), |
| 1235 |
36 |
▶ | SvOK(envsv) ? SvPV_nolen(envsv) : "production"); |
Branch: 1 branch
| Branch | True | False | Total |
| SvOK(envsv) ? SvPV_nolen(envsv) : "production"); |
18 |
0 |
18 |
|
| 1236 |
10 |
| (void)hv_stores(state, K_PROXY, |
| 1237 |
|
| sv_setref_iv(newSV(0), "Punk::Proxy", |
| 1238 |
|
| PTR2IV(pol))); |
| 1239 |
|
| } |
| 1240 |
|
| } |
| 1241 |
|
| { /* auth: the battery needs a session for the identity to live in, |
| 1242 |
|
| * and a roles target resolves now so a typo croaks at boot */ |
| 1243 |
601 |
| SV **au = hv_fetchs(h, K_AUTH, 0); |
| 1244 |
601 |
▶ | if (au && *au && SvROK(*au) |
Branch: 3 branches
| Branch | True | False | Total |
| if (au && *au && SvROK(*au) |
16 |
585 |
601 |
| if (au && *au && SvROK(*au) |
16 |
0 |
16 |
| if (au && *au && SvROK(*au) |
16 |
0 |
16 |
|
| 1245 |
16 |
▶ | && SvTYPE(SvRV(*au)) == SVt_PVHV) { |
Branch: 1 branch
| Branch | True | False | Total |
| && SvTYPE(SvRV(*au)) == SVt_PVHV) { |
16 |
0 |
16 |
|
| 1246 |
16 |
| HV *acfg = (HV *)SvRV(*au); |
| 1247 |
16 |
| SV **sc = hv_fetchs(h, "session", 0); |
| 1248 |
|
| SV **rl; |
| 1249 |
16 |
▶ | if (!(sc && *sc && SvROK(*sc))) |
Branch: 3 branches
| Branch | True | False | Total |
| if (!(sc && *sc && SvROK(*sc))) |
15 |
1 |
16 |
| if (!(sc && *sc && SvROK(*sc))) |
15 |
0 |
15 |
| if (!(sc && *sc && SvROK(*sc))) |
0 |
15 |
15 |
|
| 1250 |
1 |
| croak("Punk: `auth` needs a session for the identity to " |
| 1251 |
|
| "live in - add a `session` keyword"); |
| 1252 |
15 |
| rl = hv_fetchs(acfg, "roles", 0); |
| 1253 |
15 |
▶ | if (rl && *rl && SvOK(*rl) && !SvROK(*rl)) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (rl && *rl && SvOK(*rl) && !SvROK(*rl)) { |
4 |
11 |
15 |
| if (rl && *rl && SvOK(*rl) && !SvROK(*rl)) { |
4 |
0 |
4 |
| if (rl && *rl && SvOK(*rl) && !SvROK(*rl)) { |
4 |
0 |
4 |
| if (rl && *rl && SvOK(*rl) && !SvROK(*rl)) { |
1 |
3 |
4 |
|
| 1254 |
1 |
| SV *what = sv_2mortal(newSVpvs("auth roles")); |
| 1255 |
1 |
| SV *code = pc_resolve_target(aTHX_ self, *rl, what); |
| 1256 |
0 |
| (void)hv_stores(acfg, "roles", code); |
| 1257 |
|
| } |
| 1258 |
|
| /* the Perl half: current_user and the role/verified checks */ |
| 1259 |
14 |
▶ | if (!pk_require_once(aTHX_ "Punk::Auth", FALSE)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!pk_require_once(aTHX_ "Punk::Auth", FALSE)) |
0 |
14 |
14 |
|
| 1260 |
0 |
▶ | croak("Punk: auth needs Punk::Auth, which failed to " |
Branch: 1 branch
| Branch | True | False | Total |
| croak("Punk: auth needs Punk::Auth, which failed to " |
0 |
0 |
0 |
|
| 1261 |
|
| "load: %s", SvPV_nolen(ERRSV)); |
| 1262 |
|
| } |
| 1263 |
|
| } |
| 1264 |
|
| { /* scoped header policies ($scope->headers): flattened per record |
| 1265 |
|
| * and sorted longest-prefix-first, so a request under nested |
| 1266 |
|
| * scopes reads the most specific mention of a name first */ |
| 1267 |
599 |
| SV **sh = hv_fetchs(h, K_HEADERS_SCOPED, 0); |
| 1268 |
599 |
▶ | if (sh && *sh && SvROK(*sh) && SvTYPE(SvRV(*sh)) == SVt_PVAV) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (sh && *sh && SvROK(*sh) && SvTYPE(SvRV(*sh)) == SVt_PVAV) { |
2 |
597 |
599 |
| if (sh && *sh && SvROK(*sh) && SvTYPE(SvRV(*sh)) == SVt_PVAV) { |
2 |
0 |
2 |
| if (sh && *sh && SvROK(*sh) && SvTYPE(SvRV(*sh)) == SVt_PVAV) { |
2 |
0 |
2 |
| if (sh && *sh && SvROK(*sh) && SvTYPE(SvRV(*sh)) == SVt_PVAV) { |
2 |
0 |
2 |
|
| 1269 |
2 |
| AV *src = (AV *)SvRV(*sh); |
| 1270 |
2 |
| SSize_t si, sn = av_len(src) + 1; |
| 1271 |
2 |
| AV *outav = newAV(); |
| 1272 |
5 |
▶ | for (si = 0; si < sn; si++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (si = 0; si < sn; si++) { |
3 |
2 |
5 |
|
| 1273 |
3 |
| SV **rp = av_fetch(src, si, 0); |
| 1274 |
|
| HV *rec, *out; |
| 1275 |
|
| SV **x; |
| 1276 |
3 |
| STRLEN pfl = 0; |
| 1277 |
3 |
▶ | if (!(rp && *rp && SvROK(*rp))) continue; |
Branch: 3 branches
| Branch | True | False | Total |
| if (!(rp && *rp && SvROK(*rp))) continue; |
3 |
0 |
3 |
| if (!(rp && *rp && SvROK(*rp))) continue; |
3 |
0 |
3 |
| if (!(rp && *rp && SvROK(*rp))) continue; |
0 |
3 |
3 |
|
| 1278 |
3 |
| rec = (HV *)SvRV(*rp); |
| 1279 |
3 |
| out = newHV(); |
| 1280 |
3 |
| x = hv_fetchs(rec, K_PREFIX, 0); |
| 1281 |
3 |
▶ | if (x && *x && SvOK(*x)) (void)SvPV_const(*x, pfl); |
Branch: 3 branches
| Branch | True | False | Total |
| if (x && *x && SvOK(*x)) (void)SvPV_const(*x, pfl); |
3 |
0 |
3 |
| if (x && *x && SvOK(*x)) (void)SvPV_const(*x, pfl); |
3 |
0 |
3 |
| if (x && *x && SvOK(*x)) (void)SvPV_const(*x, pfl); |
3 |
0 |
3 |
|
| 1282 |
3 |
▶ | (void)hv_stores(out, K_PREFIX, |
Branch: 3 branches
| Branch | True | False | Total |
| (void)hv_stores(out, K_PREFIX, |
3 |
0 |
3 |
| (void)hv_stores(out, K_PREFIX, |
3 |
0 |
3 |
| (void)hv_stores(out, K_PREFIX, |
3 |
0 |
3 |
|
| 1283 |
|
| (x && *x && SvOK(*x)) ? newSVsv(*x) : newSVpvs("")); |
| 1284 |
3 |
| (void)hv_stores(out, K_LEN, newSViv((IV)pfl)); |
| 1285 |
3 |
| x = hv_fetchs(rec, K_HEADERS, 0); |
| 1286 |
3 |
▶ | if (x && *x && SvROK(*x) |
Branch: 3 branches
| Branch | True | False | Total |
| if (x && *x && SvROK(*x) |
3 |
0 |
3 |
| if (x && *x && SvROK(*x) |
3 |
0 |
3 |
| if (x && *x && SvROK(*x) |
3 |
0 |
3 |
|
| 1287 |
3 |
▶ | && SvTYPE(SvRV(*x)) == SVt_PVHV) |
Branch: 1 branch
| Branch | True | False | Total |
| && SvTYPE(SvRV(*x)) == SVt_PVHV) |
3 |
0 |
3 |
|
| 1288 |
3 |
| (void)hv_stores(out, K_HEADERS, newRV_noinc( |
| 1289 |
|
| (SV *)phd_flat(aTHX_ (HV *)SvRV(*x)))); |
| 1290 |
3 |
| av_push(outav, newRV_noinc((SV *)out)); |
| 1291 |
|
| } |
| 1292 |
2 |
▶ | if (av_len(outav) > 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (av_len(outav) > 0) |
1 |
1 |
2 |
|
| 1293 |
1 |
| sortsv(AvARRAY(outav), (STRLEN)(av_len(outav) + 1), |
| 1294 |
|
| pc_cmp_len_desc); |
| 1295 |
2 |
▶ | if (av_len(outav) >= 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (av_len(outav) >= 0) { |
2 |
0 |
2 |
|
| 1296 |
2 |
| (void)hv_stores(state, K_HEADERS_SCOPED, |
| 1297 |
|
| newRV_noinc((SV *)outav)); |
| 1298 |
2 |
▶ | if (!pk_require_once(aTHX_ "Punk::Headers", FALSE)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!pk_require_once(aTHX_ "Punk::Headers", FALSE)) |
0 |
2 |
2 |
|
| 1299 |
0 |
▶ | croak("Punk: headers needs Punk::Headers, which " |
Branch: 1 branch
| Branch | True | False | Total |
| croak("Punk: headers needs Punk::Headers, which " |
0 |
0 |
0 |
|
| 1300 |
|
| "failed to load: %s", SvPV_nolen(ERRSV)); |
| 1301 |
|
| } |
| 1302 |
0 |
| else SvREFCNT_dec((SV *)outav); |
| 1303 |
|
| } |
| 1304 |
|
| } |
| 1305 |
|
| { |
| 1306 |
599 |
| SV **nf = hv_fetchs(h, K_ON_NOT_FOUND, 0); |
| 1307 |
599 |
| SV *on_nf = &PL_sv_undef; |
| 1308 |
599 |
▶ | if (nf && *nf && SvOK(*nf)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (nf && *nf && SvOK(*nf)) { |
6 |
593 |
599 |
| if (nf && *nf && SvOK(*nf)) { |
6 |
0 |
6 |
| if (nf && *nf && SvOK(*nf)) { |
6 |
0 |
6 |
|
| 1309 |
6 |
| SV *what = sv_2mortal(newSVpvs(K_ON_NOT_FOUND)); |
| 1310 |
6 |
| on_nf = sv_2mortal(pc_resolve_target(aTHX_ self, *nf, what)); |
| 1311 |
|
| } |
| 1312 |
598 |
| (void)hv_stores(state, K_ON_NOT_FOUND, newSVsv(on_nf)); |
| 1313 |
|
| } |
| 1314 |
|
| { |
| 1315 |
598 |
| SV **oe = hv_fetchs(h, K_ON_ERROR, 0); |
| 1316 |
598 |
| SV *on_err = &PL_sv_undef; |
| 1317 |
598 |
▶ | if (oe && *oe && SvOK(*oe)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (oe && *oe && SvOK(*oe)) { |
598 |
0 |
598 |
| if (oe && *oe && SvOK(*oe)) { |
598 |
0 |
598 |
| if (oe && *oe && SvOK(*oe)) { |
9 |
589 |
598 |
|
| 1318 |
9 |
| SV *what = sv_2mortal(newSVpvs(K_ON_ERROR)); |
| 1319 |
9 |
| on_err = sv_2mortal(pc_resolve_target(aTHX_ self, *oe, what)); |
| 1320 |
|
| } |
| 1321 |
598 |
| (void)hv_stores(state, K_ON_ERROR, newSVsv(on_err)); |
| 1322 |
|
| } |
| 1323 |
|
| PERL_UNUSED_VAR(caller); |
| 1324 |
|
| |
| 1325 |
598 |
| state_rv = sv_2mortal(newRV_noinc((SV *)state)); |
| 1326 |
|
| { |
| 1327 |
598 |
| AV *acap = newAV(); |
| 1328 |
598 |
| av_push(acap, newSVsv(state_rv)); |
| 1329 |
|
| /* the same state read once into a struct (punk_state.h); it |
| 1330 |
|
| * borrows from the hash in slot 0, which the capture keeps */ |
| 1331 |
598 |
| av_push(acap, pk_state_build(aTHX_ state)); |
| 1332 |
598 |
| app_cv = punk_closure(aTHX_ pc_app_cb, acap); |
| 1333 |
|
| } |
| 1334 |
|
| |
| 1335 |
|
| /* wrap in middleware, innermost last (reverse registration order): |
| 1336 |
|
| * $app = $mw->($app) - a coderef call, our +1 on the old app handed in |
| 1337 |
|
| * and released by the call scope. */ |
| 1338 |
598 |
| mw = app_av(aTHX_ h, K_MIDDLEWARE); |
| 1339 |
640 |
▶ | for (i = av_len(mw); i >= 0; i--) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = av_len(mw); i >= 0; i--) { |
44 |
596 |
640 |
|
| 1340 |
44 |
| SV **wp = av_fetch(mw, i, 0); |
| 1341 |
44 |
| SV *wrapped; dSP; int count; |
| 1342 |
44 |
▶ | if (!wp || !*wp) continue; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!wp || !*wp) continue; |
44 |
0 |
44 |
| if (!wp || !*wp) continue; |
0 |
44 |
44 |
|
| 1343 |
44 |
| ENTER; SAVETMPS; |
| 1344 |
44 |
▶ | PUSHMARK(SP); EXTEND(SP, 1); |
Branch: 2 branches
| Branch | True | False | Total |
| PUSHMARK(SP); EXTEND(SP, 1); |
0 |
44 |
44 |
| PUSHMARK(SP); EXTEND(SP, 1); |
0 |
44 |
44 |
|
| 1345 |
44 |
| PUSHs(sv_2mortal(app_cv)); |
| 1346 |
44 |
| PUTBACK; |
| 1347 |
44 |
| count = call_sv(*wp, G_SCALAR); |
| 1348 |
42 |
| SPAGAIN; |
| 1349 |
42 |
▶ | wrapped = count > 0 ? SvREFCNT_inc(POPs) : newSV(0); |
Branch: 1 branch
| Branch | True | False | Total |
| wrapped = count > 0 ? SvREFCNT_inc(POPs) : newSV(0); |
42 |
0 |
42 |
|
| 1350 |
42 |
▶ | PUTBACK; FREETMPS; LEAVE; |
Branch: 1 branch
| Branch | True | False | Total |
| PUTBACK; FREETMPS; LEAVE; |
42 |
0 |
42 |
|
| 1351 |
42 |
| app_cv = wrapped; |
| 1352 |
|
| } |
| 1353 |
|
| |
| 1354 |
596 |
| { SV **cp = hv_fetchs(h, K_COMPILED, 0); |
| 1355 |
596 |
▶ | (void)hv_stores(h, K_COMPILED, |
Branch: 3 branches
| Branch | True | False | Total |
| (void)hv_stores(h, K_COMPILED, |
596 |
0 |
596 |
| (void)hv_stores(h, K_COMPILED, |
596 |
0 |
596 |
| (void)hv_stores(h, K_COMPILED, |
596 |
0 |
596 |
|
| 1356 |
|
| newSViv((cp && *cp && SvOK(*cp) ? SvIV(*cp) : 0) + 1)); } |
| 1357 |
596 |
| RETVAL = app_cv; |
| 1358 |
|
| } |
| 1359 |
|
| OUTPUT: |
| 1360 |
|
| RETVAL |