| 1 |
|
| MODULE = Punk PACKAGE = Punk::Plugin::RequestId |
| 2 |
|
| |
| 3 |
|
| PROTOTYPES: DISABLE |
| 4 |
|
| |
| 5 |
|
| # The whole plugin's request path lives in include/punk/punk_reqid.h. What is |
| 6 |
|
| # exposed here is registration and one mint, which is all lib/Punk/Plugin/ |
| 7 |
|
| # RequestId.pm needs. |
| 8 |
|
| |
| 9 |
|
| # _enable($app, $header_name_or_undef) |
| 10 |
|
| # |
| 11 |
|
| # Registers the process-wide observers once, and freezes THIS app's header |
| 12 |
|
| # name onto its app hash - beside where the `session` and `csrf` keywords keep |
| 13 |
|
| # theirs. Per-app, because two Punk apps can share a process under |
| 14 |
|
| # Plack::Builder and a header name held in a static made the last one to |
| 15 |
|
| # register name the header for both. |
| 16 |
|
| # |
| 17 |
|
| # An undefined header stores a false value rather than nothing: "the plugin is |
| 18 |
|
| # loaded and the header is off" has to stay distinguishable from "this app |
| 19 |
|
| # never loaded the plugin", or an app without the plugin would still mint ids. |
| 20 |
|
| # (Starting that sentence with the word `undef` made the line read as a cpp |
| 21 |
|
| # #undef directive - the xsubpp trap this workspace has met before.) |
| 22 |
|
| IV |
| 23 |
|
| _enable(class, app, header = &PL_sv_undef, envkey = &PL_sv_undef) |
| 24 |
|
| SV *class |
| 25 |
|
| SV *app |
| 26 |
|
| SV *header |
| 27 |
|
| SV *envkey |
| 28 |
|
| CODE: |
| 29 |
|
| { |
| 30 |
44 |
| HV *h = app_hv(aTHX_ app); |
| 31 |
44 |
| AV *cfg = newAV(); |
| 32 |
44 |
▶ | av_push(cfg, (SvOK(header) && SvTRUE(header)) /* # uncoverable condition right count:2 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| av_push(cfg, (SvOK(header) && SvTRUE(header)) /* # uncoverable condition right count:2 class:ignore_covered_err */ |
39 |
5 |
44 |
| av_push(cfg, (SvOK(header) && SvTRUE(header)) /* # uncoverable condition right count:2 class:ignore_covered_err */ |
39 |
0 |
39 |
|
| 33 |
|
| ? newSVsv(header) : newSViv(0)); |
| 34 |
44 |
▶ | av_push(cfg, (SvOK(envkey) && SvTRUE(envkey)) /* # uncoverable condition right count:2 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| av_push(cfg, (SvOK(envkey) && SvTRUE(envkey)) /* # uncoverable condition right count:2 class:ignore_covered_err */ |
3 |
41 |
44 |
| av_push(cfg, (SvOK(envkey) && SvTRUE(envkey)) /* # uncoverable condition right count:2 class:ignore_covered_err */ |
3 |
0 |
3 |
|
| 35 |
|
| ? newSVsv(envkey) : newSV(0)); |
| 36 |
44 |
| (void)hv_stores(h, PR_APP_KEY, newRV_noinc((SV *)cfg)); |
| 37 |
|
| PERL_UNUSED_VAR(class); |
| 38 |
44 |
▶ | RETVAL = pr_enable(aTHX); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = pr_enable(aTHX); |
34 |
10 |
44 |
|
| 39 |
|
| } |
| 40 |
|
| OUTPUT: |
| 41 |
|
| RETVAL |
| 42 |
|
| |
| 43 |
|
| # One id, for a caller that wants one outside a request - and for the tests |
| 44 |
|
| # that assert uniqueness and format without standing a server up. |
| 45 |
|
| SV * |
| 46 |
|
| _mint(class = &PL_sv_undef) |
| 47 |
|
| SV *class |
| 48 |
|
| CODE: |
| 49 |
|
| PERL_UNUSED_VAR(class); |
| 50 |
52035 |
| RETVAL = pr_mint(aTHX); |
| 51 |
|
| OUTPUT: |
| 52 |
|
| RETVAL |
| 53 |
|
| |
| 54 |
|
| # $c->request_id - installed as the helper itself, so the accessor is an XSUB |
| 55 |
|
| # rather than a Perl closure wrapping one. |
| 56 |
|
| SV * |
| 57 |
|
| _id(c) |
| 58 |
|
| SV *c |
| 59 |
|
| CODE: |
| 60 |
|
| { |
| 61 |
62 |
| AV *av = pcx_av(aTHX_ c); |
| 62 |
62 |
▶ | SV *id = av ? pcx_get(aTHX_ av, PCX_REQID) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| SV *id = av ? pcx_get(aTHX_ av, PCX_REQID) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
62 |
0 |
62 |
|
| 63 |
62 |
▶ | # uncoverable condition right count:1 class:ignore_covered_err |
Branch: 2 branches
| Branch | True | False | Total |
| # uncoverable condition right count:1 class:ignore_covered_err |
62 |
0 |
62 |
| # uncoverable condition right count:1 class:ignore_covered_err |
62 |
0 |
62 |
|
| 64 |
|
| # uncoverable condition right count:2 class:ignore_covered_err |
| 65 |
|
| RETVAL = (id && SvOK(id)) ? newSVsv(id) : newSV(0); |
| 66 |
|
| } |
| 67 |
|
| OUTPUT: |
| 68 |
|
| RETVAL |
| 69 |
|
| |
| 70 |
|
| # What the plugin has done, process-wide. `adopted` and `rejected` are only |
| 71 |
|
| # ever non-zero where trust_header is on, and a rising `rejected` is somebody |
| 72 |
|
| # sending ids that are not ids - which is worth being able to see rather than |
| 73 |
|
| # discarding silently. |
| 74 |
|
| void |
| 75 |
|
| stats(class = &PL_sv_undef) |
| 76 |
|
| SV *class |
| 77 |
|
| PPCODE: |
| 78 |
|
| { |
| 79 |
|
| PERL_UNUSED_VAR(class); |
| 80 |
4 |
▶ | EXTEND(SP, 6); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 6); |
0 |
4 |
4 |
|
| 81 |
4 |
| mPUSHs(newSVpvs("minted")); mPUSHu(pr_n_minted); |
| 82 |
4 |
| mPUSHs(newSVpvs("adopted")); mPUSHu(pr_n_adopted); |
| 83 |
4 |
| mPUSHs(newSVpvs("rejected")); mPUSHu(pr_n_rejected); |
| 84 |
4 |
| XSRETURN(6); |
| 85 |
|
| } |