| 1 |
|
| /* |
| 2 |
|
| * Fetch.xs - root XS file |
| 3 |
|
| * |
| 4 |
|
| * Thin wrapper (Hyperman-style layout): pulls in the vendored C core from |
| 5 |
|
| * include/fetch/ (readiness backends + Future + loop + HTTP/1.1/2 + TLS, plus |
| 6 |
|
| * the Headers/CookieJar/user-agent logic), then the per-package XS fragments |
| 7 |
|
| * via INCLUDE:. All Fetch behaviour lives in C; the .pm files are |
| 8 |
|
| * documentation/loader stubs (except the foreign event-loop adapters, which |
| 9 |
|
| * are Perl glue over other frameworks). |
| 10 |
|
| */ |
| 11 |
|
| |
| 12 |
|
| /* Native Windows: rand_s() (ft_win.h) is only declared by <stdlib.h> when |
| 13 |
|
| * _CRT_RAND_S is set before it is first included - and perl.h pulls <stdlib.h> |
| 14 |
|
| * in. So define it here, ahead of every include. No-op off Windows. */ |
| 15 |
|
| #ifdef _WIN32 |
| 16 |
|
| #define _CRT_RAND_S |
| 17 |
|
| #endif |
| 18 |
|
| |
| 19 |
|
| #include "EXTERN.h" |
| 20 |
|
| #include "perl.h" |
| 21 |
|
| #include "XSUB.h" |
| 22 |
|
| |
| 23 |
|
| #include "fetch/ft_compat.h" /* perl-version portability shims (pre-5.16) */ |
| 24 |
|
| #include "fetch/ft_core.h" |
| 25 |
|
| |
| 26 |
|
| /* ---- helpers -------------------------------------------------------------- */ |
| 27 |
|
| |
| 28 |
378 |
| static ft_loop *ft_loop_from_sv(pTHX_ SV *sv) { |
| 29 |
378 |
▶ | if (!(SvROK(sv) && SvIOK(SvRV(sv)))) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!(SvROK(sv) && SvIOK(SvRV(sv)))) |
378 |
0 |
378 |
| if (!(SvROK(sv) && SvIOK(SvRV(sv)))) |
0 |
378 |
378 |
|
| 30 |
0 |
| croak("Fetch::Loop: not a loop object"); |
| 31 |
378 |
| return INT2PTR(ft_loop *, SvIV(SvRV(sv))); |
| 32 |
|
| } |
| 33 |
|
| |
| 34 |
200 |
| static ft_pool *ft_pool_from_sv(pTHX_ SV *sv) { |
| 35 |
200 |
▶ | if (!SvOK(sv) || !(SvROK(sv) && SvIOK(SvRV(sv)))) return NULL; |
Branch: 3 branches
| Branch | True | False | Total |
| if (!SvOK(sv) || !(SvROK(sv) && SvIOK(SvRV(sv)))) return NULL; |
200 |
0 |
200 |
| if (!SvOK(sv) || !(SvROK(sv) && SvIOK(SvRV(sv)))) return NULL; |
200 |
0 |
200 |
| if (!SvOK(sv) || !(SvROK(sv) && SvIOK(SvRV(sv)))) return NULL; |
0 |
200 |
200 |
|
| 36 |
200 |
| return INT2PTR(ft_pool *, SvIV(SvRV(sv))); |
| 37 |
|
| } |
| 38 |
|
| |
| 39 |
2 |
| static int ft_fileno(pTHX_ SV *fh) { |
| 40 |
2 |
▶ | if (SvROK(fh) || SvTYPE(fh) == SVt_PVGV) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvROK(fh) || SvTYPE(fh) == SVt_PVGV) { |
0 |
2 |
2 |
| if (SvROK(fh) || SvTYPE(fh) == SVt_PVGV) { |
0 |
0 |
0 |
|
| 41 |
2 |
| IO *io = sv_2io(fh); |
| 42 |
2 |
▶ | if (io && IoIFP(io)) return PerlIO_fileno(IoIFP(io)); |
Branch: 2 branches
| Branch | True | False | Total |
| if (io && IoIFP(io)) return PerlIO_fileno(IoIFP(io)); |
2 |
0 |
2 |
| if (io && IoIFP(io)) return PerlIO_fileno(IoIFP(io)); |
2 |
0 |
2 |
|
| 43 |
0 |
| return -1; |
| 44 |
|
| } |
| 45 |
0 |
| return (int)SvIV(fh); /* a bare fd number */ |
| 46 |
|
| } |
| 47 |
|
| |
| 48 |
2 |
| static int ft_mode(pTHX_ SV *m) { |
| 49 |
2 |
| const char *s = SvPV_nolen(m); |
| 50 |
2 |
| int mask = 0; |
| 51 |
2 |
▶ | if (strchr(s, 'r')) mask |= HM_EV_READ; |
Branch: 1 branch
| Branch | True | False | Total |
| if (strchr(s, 'r')) mask |= HM_EV_READ; |
2 |
0 |
2 |
|
| 52 |
2 |
▶ | if (strchr(s, 'w')) mask |= HM_EV_WRITE; |
Branch: 1 branch
| Branch | True | False | Total |
| if (strchr(s, 'w')) mask |= HM_EV_WRITE; |
0 |
2 |
2 |
|
| 53 |
2 |
▶ | if (!mask) croak("watch_io: mode must contain 'r' and/or 'w'"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!mask) croak("watch_io: mode must contain 'r' and/or 'w'"); |
0 |
2 |
2 |
|
| 54 |
2 |
| return mask; |
| 55 |
|
| } |
| 56 |
|
| |
| 57 |
|
| /* does the (blessed) object $obj resolve a method named $meth? (->can) */ |
| 58 |
55 |
| static int ft_obj_can(pTHX_ SV *obj, const char *meth) { |
| 59 |
|
| HV *stash; |
| 60 |
55 |
▶ | if (!sv_isobject(obj)) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sv_isobject(obj)) return 0; |
0 |
55 |
55 |
|
| 61 |
55 |
| stash = SvSTASH(SvRV(obj)); |
| 62 |
55 |
▶ | return stash && gv_fetchmethod_autoload(stash, meth, FALSE) ? 1 : 0; |
Branch: 2 branches
| Branch | True | False | Total |
| return stash && gv_fetchmethod_autoload(stash, meth, FALSE) ? 1 : 0; |
55 |
0 |
55 |
| return stash && gv_fetchmethod_autoload(stash, meth, FALSE) ? 1 : 0; |
55 |
0 |
55 |
|
| 63 |
|
| } |
| 64 |
|
| |
| 65 |
|
| /* the v2 outbound observer registry - before ft_ua.h, which fires it, and |
| 66 |
|
| * long before ft_abi.h, which registers into it */ |
| 67 |
|
| #include "fetch/ft_obs.h" |
| 68 |
|
| #include "fetch/ft_obs_perl.h" /* ... and the Perl door onto it */ |
| 69 |
|
| |
| 70 |
|
| |
| 71 |
|
| /* the user agent - URL parsing, header merge, cookies, request build, and |
| 72 |
|
| * redirect following (depends on the statics above, so included here) */ |
| 73 |
|
| #include "fetch/ft_ua.h" |
| 74 |
|
| |
| 75 |
|
| /* the C ABI table other XS modules (e.g. Reverse::Proxy) call through */ |
| 76 |
|
| #include "fetch/ft_abi.h" |
| 77 |
|
| |
| 78 |
|
| MODULE = Fetch PACKAGE = Fetch |
| 79 |
|
| |
| 80 |
|
| PROTOTYPES: DISABLE |
| 81 |
|
| |
| 82 |
|
| INCLUDE: xs/fetch.xs |
| 83 |
|
| INCLUDE: xs/abi.xs |
| 84 |
|
| INCLUDE: xs/future.xs |
| 85 |
|
| INCLUDE: xs/loop.xs |
| 86 |
|
| INCLUDE: xs/headers.xs |
| 87 |
|
| INCLUDE: xs/response.xs |
| 88 |
|
| INCLUDE: xs/cookiejar.xs |
| 89 |
|
| INCLUDE: xs/websocket.xs |