Skip to content

Commit 3b5b8c5

Browse files
author
Matthew Yacobucci
committed
WIP: updating naming conventions
1 parent 840d789 commit 3b5b8c5

File tree

10 files changed

+61
-57
lines changed

10 files changed

+61
-57
lines changed

examples/awssig.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl HTTPModule for Module {
1717
type LocConf = ModuleConfig;
1818

1919
unsafe extern "C" fn postconfiguration(cf: *mut ngx_conf_t) -> ngx_int_t {
20-
let cmcf = ngx_http_conf_get_module_main_conf(cf, &ngx_http_core_module);
20+
let cmcf = ngx_http_conf_get_module_main_conf_mut_ptr(cf, &ngx_http_core_module);
2121

2222
let h = ngx_array_push(&mut (*cmcf).phases[ngx_http_phases_NGX_HTTP_PRECONTENT_PHASE as usize].handlers)
2323
as *mut ngx_http_handler_pt;

examples/curl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl http::HTTPModule for Module {
1717
type LocConf = ModuleConfig;
1818

1919
unsafe extern "C" fn postconfiguration(cf: *mut ngx_conf_t) -> ngx_int_t {
20-
let cmcf = http::ngx_http_conf_get_module_main_conf(cf, &ngx_http_core_module);
20+
let cmcf = http::ngx_http_conf_get_module_main_conf_mut_ptr(cf, &ngx_http_core_module);
2121

2222
let h = ngx_array_push(&mut (*cmcf).phases[ngx_http_phases_NGX_HTTP_ACCESS_PHASE as usize].handlers)
2323
as *mut ngx_http_handler_pt;

examples/httporigdst.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl Default for NgxHttpOrigDstCtx {
2727

2828
impl NgxHttpOrigDstCtx {
2929
pub fn save(&mut self, addr: &str, port: in_port_t, pool: &mut core::Pool) -> core::Status {
30-
let addr_data = pool.alloc(IPV4_STRLEN);
30+
let addr_data = pool.alloc_mut_ptr(IPV4_STRLEN);
3131
if addr_data.is_null() {
3232
return core::Status::NGX_ERROR;
3333
}
@@ -36,7 +36,7 @@ impl NgxHttpOrigDstCtx {
3636
self.orig_dst_addr.data = addr_data as *mut u8;
3737

3838
let port_str = port.to_string();
39-
let port_data = pool.alloc(port_str.len());
39+
let port_data = pool.alloc_mut_ptr(port_str.len());
4040
if port_data.is_null() {
4141
return core::Status::NGX_ERROR;
4242
}
@@ -147,7 +147,7 @@ static mut ngx_http_orig_dst_vars: [ngx_http_variable_t; 3] = [
147147
];
148148

149149
unsafe fn ngx_get_origdst(request: &mut http::Request) -> Result<(String, in_port_t), core::Status> {
150-
let c = request.connection();
150+
let c = request.connection_mut_ptr();
151151

152152
if (*c).type_ != libc::SOCK_STREAM {
153153
ngx_log_debug_http!(request, "httporigdst: connection is not type SOCK_STREAM");
@@ -228,7 +228,7 @@ http_variable_get!(
228228
Ok((ip, port)) => {
229229
// create context,
230230
// set context
231-
let new_ctx = request.pool().allocate::<NgxHttpOrigDstCtx>(Default::default());
231+
let new_ctx = request.pool().allocate_mut_ptr::<NgxHttpOrigDstCtx>(Default::default());
232232

233233
if new_ctx.is_null() {
234234
return core::Status::NGX_ERROR;
@@ -267,7 +267,7 @@ http_variable_get!(
267267
Ok((ip, port)) => {
268268
// create context,
269269
// set context
270-
let new_ctx = request.pool().allocate::<NgxHttpOrigDstCtx>(Default::default());
270+
let new_ctx = request.pool().allocate_mut_ptr::<NgxHttpOrigDstCtx>(Default::default());
271271

272272
if new_ctx.is_null() {
273273
return core::Status::NGX_ERROR;

examples/upstream.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use ngx::{
1717
NGX_HTTP_MODULE, NGX_HTTP_UPS_CONF, NGX_LOG_EMERG, NGX_RS_HTTP_SRV_CONF_OFFSET, NGX_RS_MODULE_SIGNATURE,
1818
},
1919
http::{
20-
ngx_http_conf_get_module_srv_conf, ngx_http_conf_upstream_srv_conf_immutable,
21-
ngx_http_conf_upstream_srv_conf_mutable, HTTPModule, Merge, MergeConfigError, Request,
20+
ngx_http_conf_get_module_srv_conf_mut_ptr, ngx_http_conf_upstream_srv_conf_mut_ptr,
21+
ngx_http_conf_upstream_srv_conf_ptr, HTTPModule, Merge, MergeConfigError, Request,
2222
},
2323
http_upstream_init_peer_pt,
2424
log::DebugMask,
@@ -146,13 +146,13 @@ http_upstream_init_peer_pt!(
146146
|request: &mut Request, us: *mut ngx_http_upstream_srv_conf_t| {
147147
ngx_log_debug_http!(request, "CUSTOM UPSTREAM request peer init");
148148

149-
let mut hcpd = request.pool().alloc_type::<UpstreamPeerData>();
149+
let mut hcpd = request.pool().alloc_type_mut_ptr::<UpstreamPeerData>();
150150
if hcpd.is_null() {
151151
return Status::NGX_ERROR;
152152
}
153153

154154
let maybe_conf: Option<*const SrvConfig> =
155-
unsafe { ngx_http_conf_upstream_srv_conf_immutable(us, &ngx_http_upstream_custom_module) };
155+
unsafe { ngx_http_conf_upstream_srv_conf_ptr(us, &ngx_http_upstream_custom_module) };
156156
if maybe_conf.is_none() {
157157
return Status::NGX_ERROR;
158158
}
@@ -163,7 +163,7 @@ http_upstream_init_peer_pt!(
163163
return Status::NGX_ERROR;
164164
}
165165

166-
let maybe_upstream = request.upstream();
166+
let maybe_upstream = request.upstream_mut_ptr();
167167
if maybe_upstream.is_none() {
168168
return Status::NGX_ERROR;
169169
}
@@ -173,7 +173,7 @@ http_upstream_init_peer_pt!(
173173
(*hcpd).conf = Some(hccf);
174174
(*hcpd).upstream = maybe_upstream;
175175
(*hcpd).data = (*upstream_ptr).peer.data;
176-
(*hcpd).client_connection = Some(request.connection());
176+
(*hcpd).client_connection = Some(request.connection_mut_ptr());
177177
(*hcpd).original_get_peer = (*upstream_ptr).peer.get;
178178
(*hcpd).original_free_peer = (*upstream_ptr).peer.free;
179179

@@ -244,7 +244,7 @@ unsafe extern "C" fn ngx_http_upstream_init_custom(
244244
ngx_log_debug_mask!(DebugMask::Http, (*cf).log, "CUSTOM UPSTREAM peer init_upstream");
245245

246246
let maybe_conf: Option<*mut SrvConfig> =
247-
ngx_http_conf_upstream_srv_conf_mutable(us, &ngx_http_upstream_custom_module);
247+
ngx_http_conf_upstream_srv_conf_mut_ptr(us, &ngx_http_upstream_custom_module);
248248
if maybe_conf.is_none() {
249249
ngx_conf_log_error(
250250
NGX_LOG_EMERG as usize,
@@ -309,7 +309,7 @@ unsafe extern "C" fn ngx_http_upstream_commands_set_custom(
309309
}
310310

311311
let uscf: *mut ngx_http_upstream_srv_conf_t =
312-
ngx_http_conf_get_module_srv_conf(cf, &ngx_http_upstream_module) as *mut ngx_http_upstream_srv_conf_t;
312+
ngx_http_conf_get_module_srv_conf_mut_ptr(cf, &ngx_http_upstream_module) as *mut ngx_http_upstream_srv_conf_t;
313313

314314
ccf.original_init_upstream = if (*uscf).peer.init_upstream.is_some() {
315315
(*uscf).peer.init_upstream
@@ -336,7 +336,7 @@ impl HTTPModule for Module {
336336

337337
unsafe extern "C" fn create_srv_conf(cf: *mut ngx_conf_t) -> *mut c_void {
338338
let mut pool = Pool::from_ngx_pool((*cf).pool);
339-
let conf = pool.alloc_type::<SrvConfig>();
339+
let conf = pool.alloc_type_mut_ptr::<SrvConfig>();
340340
if conf.is_null() {
341341
ngx_conf_log_error(
342342
NGX_LOG_EMERG as usize,

src/core/buffer.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ use std::slice;
55
/// The `Buffer` trait provides methods for working with an nginx buffer (`ngx_buf_t`).
66
pub trait Buffer {
77
/// Returns a raw pointer to the underlying `ngx_buf_t` of the buffer.
8-
fn as_ngx_buf(&self) -> *const ngx_buf_t;
8+
fn as_ngx_buf_ptr(&self) -> *const ngx_buf_t;
99

1010
/// Returns a mutable raw pointer to the underlying `ngx_buf_t` of the buffer.
11-
fn as_ngx_buf_mut(&mut self) -> *mut ngx_buf_t;
11+
fn as_ngx_buf_mut_ptr(&mut self) -> *mut ngx_buf_t;
1212

1313
/// Returns the buffer contents as a byte slice.
1414
///
1515
/// # Safety
1616
/// This function is marked as unsafe because it involves raw pointer manipulation.
1717
fn as_bytes(&self) -> &[u8] {
18-
let buf = self.as_ngx_buf();
18+
let buf = self.as_ngx_buf_ptr();
1919
unsafe { slice::from_raw_parts((*buf).pos, self.len()) }
2020
}
2121

@@ -24,7 +24,7 @@ pub trait Buffer {
2424
/// # Safety
2525
/// This function is marked as unsafe because it involves raw pointer manipulation.
2626
fn len(&self) -> usize {
27-
let buf = self.as_ngx_buf();
27+
let buf = self.as_ngx_buf_ptr();
2828
unsafe {
2929
let pos = (*buf).pos;
3030
let last = (*buf).last;
@@ -44,7 +44,7 @@ pub trait Buffer {
4444
///
4545
/// * `last` - A boolean indicating whether the buffer is the last buffer in a request.
4646
fn set_last_buf(&mut self, last: bool) {
47-
let buf = self.as_ngx_buf_mut();
47+
let buf = self.as_ngx_buf_mut_ptr();
4848
unsafe {
4949
(*buf).set_last_buf(if last { 1 } else { 0 });
5050
}
@@ -56,7 +56,7 @@ pub trait Buffer {
5656
///
5757
/// * `last` - A boolean indicating whether the buffer is the last buffer in a chain of buffers.
5858
fn set_last_in_chain(&mut self, last: bool) {
59-
let buf = self.as_ngx_buf_mut();
59+
let buf = self.as_ngx_buf_mut_ptr();
6060
unsafe {
6161
(*buf).set_last_in_chain(if last { 1 } else { 0 });
6262
}
@@ -70,7 +70,7 @@ pub trait MutableBuffer: Buffer {
7070
/// # Safety
7171
/// This function is marked as unsafe because it involves raw pointer manipulation.
7272
fn as_bytes_mut(&mut self) -> &mut [u8] {
73-
let buf = self.as_ngx_buf_mut();
73+
let buf = self.as_ngx_buf_mut_ptr();
7474
unsafe { slice::from_raw_parts_mut((*buf).pos, self.len()) }
7575
}
7676
}
@@ -91,12 +91,12 @@ impl TemporaryBuffer {
9191

9292
impl Buffer for TemporaryBuffer {
9393
/// Returns the underlying `ngx_buf_t` pointer as a raw pointer.
94-
fn as_ngx_buf(&self) -> *const ngx_buf_t {
94+
fn as_ngx_buf_ptr(&self) -> *const ngx_buf_t {
9595
self.0
9696
}
9797

9898
/// Returns a mutable reference to the underlying `ngx_buf_t` pointer.
99-
fn as_ngx_buf_mut(&mut self) -> *mut ngx_buf_t {
99+
fn as_ngx_buf_mut_ptr(&mut self) -> *mut ngx_buf_t {
100100
self.0
101101
}
102102
}
@@ -127,12 +127,12 @@ impl MemoryBuffer {
127127

128128
impl Buffer for MemoryBuffer {
129129
/// Returns the underlying `ngx_buf_t` pointer as a raw pointer.
130-
fn as_ngx_buf(&self) -> *const ngx_buf_t {
130+
fn as_ngx_buf_ptr(&self) -> *const ngx_buf_t {
131131
self.0
132132
}
133133

134134
/// Returns a mutable reference to the underlying `ngx_buf_t` pointer.
135-
fn as_ngx_buf_mut(&mut self) -> *mut ngx_buf_t {
135+
fn as_ngx_buf_mut_ptr(&mut self) -> *mut ngx_buf_t {
136136
self.0
137137
}
138138
}

src/core/pool.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl Pool {
3636
pub fn create_buffer_from_str(&mut self, str: &str) -> Option<TemporaryBuffer> {
3737
let mut buffer = self.create_buffer(str.len())?;
3838
unsafe {
39-
let mut buf = buffer.as_ngx_buf_mut();
39+
let mut buf = buffer.as_ngx_buf_mut_ptr();
4040
ptr::copy_nonoverlapping(str.as_ptr(), (*buf).pos, str.len());
4141
(*buf).last = (*buf).pos.add(str.len());
4242
}
@@ -47,7 +47,7 @@ impl Pool {
4747
///
4848
/// Returns `Some(MemoryBuffer)` if the buffer is successfully created, or `None` if allocation fails.
4949
pub fn create_buffer_from_static_str(&mut self, str: &'static str) -> Option<MemoryBuffer> {
50-
let buf = self.calloc_type::<ngx_buf_t>();
50+
let buf = self.calloc_type_mut_ptr::<ngx_buf_t>();
5151
if buf.is_null() {
5252
return None;
5353
}
@@ -87,29 +87,29 @@ impl Pool {
8787
/// Allocates memory from the pool of the specified size.
8888
///
8989
/// Returns a raw pointer to the allocated memory.
90-
pub fn alloc(&mut self, size: usize) -> *mut c_void {
90+
pub fn alloc_mut_ptr(&mut self, size: usize) -> *mut c_void {
9191
unsafe { ngx_palloc(self.0, size) }
9292
}
9393

9494
/// Allocates memory for a type from the pool.
9595
///
9696
/// Returns a typed pointer to the allocated memory.
97-
pub fn alloc_type<T: Copy>(&mut self) -> *mut T {
98-
self.alloc(mem::size_of::<T>()) as *mut T
97+
pub fn alloc_type_mut_ptr<T: Copy>(&mut self) -> *mut T {
98+
self.alloc_mut_ptr(mem::size_of::<T>()) as *mut T
9999
}
100100

101101
/// Allocates zeroed memory from the pool of the specified size.
102102
///
103103
/// Returns a raw pointer to the allocated memory.
104-
pub fn calloc(&mut self, size: usize) -> *mut c_void {
104+
pub fn calloc_mut_ptr(&mut self, size: usize) -> *mut c_void {
105105
unsafe { ngx_pcalloc(self.0, size) }
106106
}
107107

108108
/// Allocates zeroed memory for a type from the pool.
109109
///
110110
/// Returns a typed pointer to the allocated memory.
111-
pub fn calloc_type<T: Copy>(&mut self) -> *mut T {
112-
self.calloc(mem::size_of::<T>()) as *mut T
111+
pub fn calloc_type_mut_ptr<T: Copy>(&mut self) -> *mut T {
112+
self.calloc_mut_ptr(mem::size_of::<T>()) as *mut T
113113
}
114114

115115
/// Allocates memory for a value of a specified type and adds a cleanup handler to the memory pool.
@@ -118,9 +118,9 @@ impl Pool {
118118
///
119119
/// # Safety
120120
/// This function is marked as unsafe because it involves raw pointer manipulation.
121-
pub fn allocate<T>(&mut self, value: T) -> *mut T {
121+
pub fn allocate_mut_ptr<T>(&mut self, value: T) -> *mut T {
122122
unsafe {
123-
let p = self.alloc(mem::size_of::<T>()) as *mut T;
123+
let p = self.alloc_mut_ptr(mem::size_of::<T>()) as *mut T;
124124
ptr::write(p, value);
125125
if self.add_cleanup_for_value(p).is_err() {
126126
ptr::drop_in_place(p);

src/http/conf.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::os::raw::c_void;
55
/// # Safety
66
///
77
/// The caller has provided a valid `ngx_conf_t` that points to valid memory and is non-null.
8-
pub unsafe fn ngx_http_conf_get_module_main_conf(
8+
pub unsafe fn ngx_http_conf_get_module_main_conf_mut_ptr(
99
cf: *mut ngx_conf_t,
1010
module: &ngx_module_t,
1111
) -> *mut ngx_http_core_main_conf_t {
@@ -16,15 +16,15 @@ pub unsafe fn ngx_http_conf_get_module_main_conf(
1616
/// # Safety
1717
///
1818
/// The caller has provided a valid `ngx_conf_t` that points to valid memory and is non-null.
19-
pub unsafe fn ngx_http_conf_get_module_srv_conf(cf: *mut ngx_conf_t, module: &ngx_module_t) -> *mut c_void {
19+
pub unsafe fn ngx_http_conf_get_module_srv_conf_mut_ptr(cf: *mut ngx_conf_t, module: &ngx_module_t) -> *mut c_void {
2020
let http_conf_ctx = (*cf).ctx as *mut ngx_http_conf_ctx_t;
2121
*(*http_conf_ctx).srv_conf.add(module.ctx_index)
2222
}
2323

2424
/// # Safety
2525
///
2626
/// The caller has provided a valid `ngx_conf_t` that points to valid memory and is non-null.
27-
pub unsafe fn ngx_http_conf_get_module_loc_conf(
27+
pub unsafe fn ngx_http_conf_get_module_loc_conf_mut_ptr(
2828
cf: *mut ngx_conf_t,
2929
module: &ngx_module_t,
3030
) -> *mut ngx_http_core_loc_conf_t {
@@ -37,7 +37,7 @@ pub unsafe fn ngx_http_conf_get_module_loc_conf(
3737
/// The caller has provided a value `ngx_http_upstream_srv_conf_t. If the `us` argument is null, a
3838
/// None Option is returned; however, if the `us` internal fields are invalid or the module index
3939
/// is out of bounds failures may still occur.
40-
pub unsafe fn ngx_http_conf_upstream_srv_conf_immutable<T>(
40+
pub unsafe fn ngx_http_conf_upstream_srv_conf_ptr<T>(
4141
us: *const ngx_http_upstream_srv_conf_t,
4242
module: &ngx_module_t,
4343
) -> Option<*const T> {
@@ -52,7 +52,7 @@ pub unsafe fn ngx_http_conf_upstream_srv_conf_immutable<T>(
5252
/// The caller has provided a value `ngx_http_upstream_srv_conf_t. If the `us` argument is null, a
5353
/// None Option is returned; however, if the `us` internal fields are invalid or the module index
5454
/// is out of bounds failures may still occur.
55-
pub unsafe fn ngx_http_conf_upstream_srv_conf_mutable<T>(
55+
pub unsafe fn ngx_http_conf_upstream_srv_conf_mut_ptr<T>(
5656
us: *const ngx_http_upstream_srv_conf_t,
5757
module: &ngx_module_t,
5858
) -> Option<*mut T> {

src/http/module.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub trait HTTPModule {
7676
/// guard against null inputs or risk runtime errors.
7777
unsafe extern "C" fn create_main_conf(cf: *mut ngx_conf_t) -> *mut c_void {
7878
let mut pool = Pool::from_ngx_pool((*cf).pool);
79-
pool.allocate::<Self::MainConf>(Default::default()) as *mut c_void
79+
pool.allocate_mut_ptr::<Self::MainConf>(Default::default()) as *mut c_void
8080
}
8181

8282
/// # Safety
@@ -93,7 +93,7 @@ pub trait HTTPModule {
9393
/// guard against null inputs or risk runtime errors.
9494
unsafe extern "C" fn create_srv_conf(cf: *mut ngx_conf_t) -> *mut c_void {
9595
let mut pool = Pool::from_ngx_pool((*cf).pool);
96-
pool.allocate::<Self::SrvConf>(Default::default()) as *mut c_void
96+
pool.allocate_mut_ptr::<Self::SrvConf>(Default::default()) as *mut c_void
9797
}
9898

9999
/// # Safety
@@ -115,7 +115,7 @@ pub trait HTTPModule {
115115
/// guard against null inputs or risk runtime errors.
116116
unsafe extern "C" fn create_loc_conf(cf: *mut ngx_conf_t) -> *mut c_void {
117117
let mut pool = Pool::from_ngx_pool((*cf).pool);
118-
pool.allocate::<Self::LocConf>(Default::default()) as *mut c_void
118+
pool.allocate_mut_ptr::<Self::LocConf>(Default::default()) as *mut c_void
119119
}
120120

121121
/// # Safety

0 commit comments

Comments
 (0)