| 1 |
|
| MODULE = Punk::SAML PACKAGE = Punk::Plugin::SAML |
| 2 |
|
| |
| 3 |
|
| # The plugin object and its registration. |
| 4 |
|
| # |
| 5 |
|
| # Both `import` and `register` install the keywords. Punk makes a second |
| 6 |
|
| # install by the same owner a no-op, which is what lets an application say |
| 7 |
|
| # `use Punk::Plugin::SAML` for the keywords at compile time and |
| 8 |
|
| # `plugin 'SAML' => {...}` for the settings, in either order, without the |
| 9 |
|
| # second undoing the first. |
| 10 |
|
| |
| 11 |
|
| # `use Punk::Plugin::SAML` installs the keywords at COMPILE time, which is |
| 12 |
|
| # the only moment that helps: `saml_idp okta => {...}` is a bareword call |
| 13 |
|
| # and perl has to know the name before it parses the line. `plugin 'SAML'` |
| 14 |
|
| # runs at runtime of the package body, long after those lines were |
| 15 |
|
| # compiled, so a keyword installed only there is one perl has already |
| 16 |
|
| # refused to parse. Punk-Feed, Punk::Plugin::Queue and ::OpenTelemetry all |
| 17 |
|
| # split it this way and for this reason. |
| 18 |
|
| # |
| 19 |
|
| # Silent in a package that is not a Punk application: `use` from a script |
| 20 |
|
| # has nothing to install onto and no reason to complain. |
| 21 |
|
| void |
| 22 |
|
| import(class, ...) |
| 23 |
|
| SV *class |
| 24 |
|
| CODE: |
| 25 |
50 |
▶ | const char *pkg = CopSTASHPV(PL_curcop); |
Branch: 7 branches
| Branch | True | False | Total |
| const char *pkg = CopSTASHPV(PL_curcop); |
50 |
0 |
50 |
| const char *pkg = CopSTASHPV(PL_curcop); |
50 |
0 |
50 |
| const char *pkg = CopSTASHPV(PL_curcop); |
50 |
0 |
50 |
| const char *pkg = CopSTASHPV(PL_curcop); |
0 |
50 |
50 |
| const char *pkg = CopSTASHPV(PL_curcop); |
0 |
0 |
0 |
| const char *pkg = CopSTASHPV(PL_curcop); |
50 |
0 |
50 |
| const char *pkg = CopSTASHPV(PL_curcop); |
0 |
50 |
50 |
|
| 26 |
|
| SV *pkgsv, *appsv; |
| 27 |
|
| PERL_UNUSED_VAR(class); |
| 28 |
|
| PERL_UNUSED_VAR(items); |
| 29 |
50 |
▶ | if (!pkg) XSRETURN_EMPTY; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!pkg) XSRETURN_EMPTY; |
0 |
50 |
50 |
|
| 30 |
50 |
| pkgsv = sv_2mortal(newSVpv(pkg, 0)); |
| 31 |
50 |
▶ | if (!psaml_can(aTHX_ pkgsv, "punk_app")) XSRETURN_EMPTY; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!psaml_can(aTHX_ pkgsv, "punk_app")) XSRETURN_EMPTY; |
1 |
49 |
50 |
|
| 32 |
49 |
| appsv = sv_2mortal(psaml_call(aTHX_ pkgsv, "punk_app", NULL, 0)); |
| 33 |
49 |
▶ | if (appsv && SvROK(appsv)) psaml_install_kw(aTHX_ appsv); |
Branch: 2 branches
| Branch | True | False | Total |
| if (appsv && SvROK(appsv)) psaml_install_kw(aTHX_ appsv); |
49 |
0 |
49 |
| if (appsv && SvROK(appsv)) psaml_install_kw(aTHX_ appsv); |
49 |
0 |
49 |
|
| 34 |
49 |
| XSRETURN_EMPTY; |
| 35 |
|
| |
| 36 |
|
| SV * |
| 37 |
|
| new(class, ...) |
| 38 |
|
| SV *class |
| 39 |
|
| CODE: |
| 40 |
49 |
| HV *self = newHV(); |
| 41 |
|
| PERL_UNUSED_VAR(items); |
| 42 |
49 |
| RETVAL = sv_bless(newRV_noinc((SV *)self), |
| 43 |
|
| gv_stashsv(class, GV_ADD)); |
| 44 |
|
| OUTPUT: |
| 45 |
|
| RETVAL |
| 46 |
|
| |
| 47 |
|
| # register($app, \%opts): validate the options, record them, install the |
| 48 |
|
| # keywords and the helpers, and book the on_compile that needs `host`. |
| 49 |
|
| void |
| 50 |
|
| register(self, app, opts = &PL_sv_undef) |
| 51 |
|
| SV *self |
| 52 |
|
| SV *app |
| 53 |
|
| SV *opts |
| 54 |
|
| CODE: |
| 55 |
|
| HV *validated; |
| 56 |
|
| PERL_UNUSED_VAR(self); |
| 57 |
49 |
▶ | if (!app || !SvROK(app)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!app || !SvROK(app)) |
49 |
0 |
49 |
| if (!app || !SvROK(app)) |
0 |
49 |
49 |
|
| 58 |
0 |
| croak("%s: register needs the Punk::App", PSAML_WHO); |
| 59 |
49 |
| validated = psaml_opts(aTHX_ app, opts); |
| 60 |
40 |
| psaml_app_set(aTHX_ app, PSAML_K_OPTS, |
| 61 |
|
| newRV_noinc((SV *)validated)); |
| 62 |
|
| /* Again, for `plugin 'SAML'` with no `use`: the parenthesised form |
| 63 |
|
| * of a keyword resolves at runtime, and this is what it finds. */ |
| 64 |
40 |
| psaml_install_kw(aTHX_ app); |
| 65 |
40 |
| psaml_install_rest(aTHX_ app); |
| 66 |
|
| |
| 67 |
|
| # _refetch_idp($app, $name, $now): re-read one provider's metadata and |
| 68 |
|
| # merge it into the recorded configuration, returning whether it happened. |
| 69 |
|
| # |
| 70 |
|
| # The ACS failure path calls this through call_method with G_EVAL rather |
| 71 |
|
| # than calling psaml_idp_refetch directly, and that is the whole reason it |
| 72 |
|
| # is an XSUB: the refetch croaks when the provider cannot be reached, and |
| 73 |
|
| # an unreachable provider during somebody's login has to become a refused |
| 74 |
|
| # login rather than a 500. Going out through Perl is how C code in this |
| 75 |
|
| # dist gets an exception frame. |
| 76 |
|
| # |
| 77 |
|
| # Not public API, for the same reason _state is not. |
| 78 |
|
| IV |
| 79 |
|
| _refetch_idp(class, app, name, now) |
| 80 |
|
| SV *class |
| 81 |
|
| SV *app |
| 82 |
|
| SV *name |
| 83 |
|
| IV now |
| 84 |
|
| CODE: |
| 85 |
|
| HV *opts; |
| 86 |
6 |
| HV *cfg = NULL; |
| 87 |
|
| SV *idpsv; |
| 88 |
|
| PERL_UNUSED_VAR(class); |
| 89 |
6 |
▶ | if (!app || !SvROK(app)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!app || !SvROK(app)) |
6 |
0 |
6 |
| if (!app || !SvROK(app)) |
0 |
6 |
6 |
|
| 90 |
0 |
| croak("%s: _refetch_idp needs the Punk::App", PSAML_WHO); |
| 91 |
6 |
| opts = psaml_opts_of(aTHX_ app); |
| 92 |
6 |
| idpsv = psaml_app_get(aTHX_ app, PSAML_K_IDPS); |
| 93 |
6 |
▶ | if (opts && idpsv && SvROK(idpsv) && name && SvOK(name)) { |
Branch: 5 branches
| Branch | True | False | Total |
| if (opts && idpsv && SvROK(idpsv) && name && SvOK(name)) { |
6 |
0 |
6 |
| if (opts && idpsv && SvROK(idpsv) && name && SvOK(name)) { |
6 |
0 |
6 |
| if (opts && idpsv && SvROK(idpsv) && name && SvOK(name)) { |
6 |
0 |
6 |
| if (opts && idpsv && SvROK(idpsv) && name && SvOK(name)) { |
6 |
0 |
6 |
| if (opts && idpsv && SvROK(idpsv) && name && SvOK(name)) { |
6 |
0 |
6 |
|
| 94 |
|
| STRLEN nl; |
| 95 |
6 |
| const char *np = SvPV_const(name, nl); |
| 96 |
6 |
| SV **e = hv_fetch((HV *)SvRV(idpsv), np, (I32)nl, 0); |
| 97 |
6 |
▶ | if (e && *e && SvROK(*e)) cfg = (HV *)SvRV(*e); |
Branch: 3 branches
| Branch | True | False | Total |
| if (e && *e && SvROK(*e)) cfg = (HV *)SvRV(*e); |
6 |
0 |
6 |
| if (e && *e && SvROK(*e)) cfg = (HV *)SvRV(*e); |
6 |
0 |
6 |
| if (e && *e && SvROK(*e)) cfg = (HV *)SvRV(*e); |
6 |
0 |
6 |
|
| 98 |
|
| } |
| 99 |
6 |
▶ | RETVAL = cfg ? psaml_idp_refetch(aTHX_ app, opts, name, cfg, now) : 0; |
Branch: 2 branches
| Branch | True | False | Total |
| RETVAL = cfg ? psaml_idp_refetch(aTHX_ app, opts, name, cfg, now) : 0; |
6 |
0 |
6 |
| RETVAL = cfg ? psaml_idp_refetch(aTHX_ app, opts, name, cfg, now) : 0; |
0 |
6 |
6 |
|
| 100 |
|
| OUTPUT: |
| 101 |
|
| RETVAL |
| 102 |
|
| |
| 103 |
|
| # The recorded state, for t/. Not public API and not documented: the |
| 104 |
|
| # application hash is Punk's, and a plugin that invited callers to read |
| 105 |
|
| # its keys would have made them interface. |
| 106 |
|
| SV * |
| 107 |
|
| _state(class, app, key) |
| 108 |
|
| SV *class |
| 109 |
|
| SV *app |
| 110 |
|
| const char *key |
| 111 |
|
| CODE: |
| 112 |
|
| SV *v; |
| 113 |
|
| PERL_UNUSED_VAR(class); |
| 114 |
117 |
| v = psaml_app_get(aTHX_ app, key); |
| 115 |
|
| /* XSRETURN_UNDEF, never `RETVAL = &PL_sv_undef`: xsubpp mortalises |
| 116 |
|
| * RETVAL, and a mortalise on an immortal spends a reference nobody |
| 117 |
|
| * took. Harmless from perl 5.20 and fatal before it. */ |
| 118 |
117 |
▶ | if (!v) XSRETURN_UNDEF; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!v) XSRETURN_UNDEF; |
53 |
64 |
117 |
|
| 119 |
64 |
| RETVAL = newSVsv(v); |
| 120 |
|
| OUTPUT: |
| 121 |
|
| RETVAL |