1use crate::ffi::{
2 self, director, req, sess, vcldir, vfp_ctx, vfp_entry, vrt_ctx, ws, DIRECTOR_MAGIC, REQ_MAGIC,
3 SESS_MAGIC, VCLDIR_MAGIC, VCL_BACKEND, VFP_CTX_MAGIC, VFP_ENTRY_MAGIC, VRT_CTX_MAGIC, WS_MAGIC,
4};
5use crate::vcl::{DeliveryFilters, FetchFilters};
6
7pub unsafe fn validate_vrt_ctx(ctxp: *const vrt_ctx) -> &'static vrt_ctx {
8 let val = ctxp.as_ref().expect("vrt_ctx pointer must not be null");
9 assert_eq!(val.magic, VRT_CTX_MAGIC);
10 val
11}
12
13pub unsafe fn validate_director(be: VCL_BACKEND) -> &'static director {
14 let val = be.0.as_ref().expect("director pointer must not be null");
15 assert_eq!(val.magic, DIRECTOR_MAGIC);
16 val
17}
18
19pub unsafe fn validate_ws(wsp: *mut ws) -> &'static mut ws {
20 let val = wsp.as_mut().expect("workspace pointer must not be null");
21 assert_eq!(val.magic, WS_MAGIC);
22 val
23}
24
25impl vrt_ctx {
26 pub fn validated_req(&mut self) -> &mut req {
27 let val = unsafe { self.req.as_mut().expect("req pointer must not be null") };
28 assert_eq!(val.magic, REQ_MAGIC);
29 val
30 }
31}
32
33impl req {
34 pub fn validated_session(&mut self) -> &sess {
35 let val = unsafe { self.sp.as_ref().expect("session pointer must not be null") };
36 assert_eq!(val.magic, SESS_MAGIC);
37 val
38 }
39}
40
41pub unsafe fn validate_vfp_ctx(ctxp: *mut vfp_ctx) -> &'static mut vfp_ctx {
42 let val = ctxp.as_mut().expect("vfp_ctx pointer must not be null");
43 assert_eq!(val.magic, VFP_CTX_MAGIC);
44 val
45}
46
47pub unsafe fn validate_vfp_entry(vfep: *mut vfp_entry) -> &'static mut vfp_entry {
48 let val = vfep.as_mut().expect("vfp_entry pointer must not be null");
49 assert_eq!(val.magic, VFP_ENTRY_MAGIC);
50 val
51}
52
53pub unsafe fn validate_vdir(be: &director) -> &'static mut vcldir {
54 let val = be
55 .vdir
56 .as_mut()
57 .expect("director vdir pointer must not be null");
58 assert_eq!(val.magic, VCLDIR_MAGIC);
59 val
60}
61
62impl vrt_ctx {
63 #[expect(clippy::vec_box)] pub fn fetch_filters<'c, 'f>(
65 &'c self,
66 filters: &'f mut Vec<Box<ffi::vfp>>,
67 ) -> FetchFilters<'c, 'f> {
68 FetchFilters::<'c, 'f>::new(self, filters)
69 }
70
71 #[expect(clippy::vec_box)] pub fn delivery_filters<'c, 'f>(
73 &'c self,
74 filters: &'f mut Vec<Box<ffi::vdp>>,
75 ) -> DeliveryFilters<'c, 'f> {
76 DeliveryFilters::<'c, 'f>::new(self, filters)
77 }
78}