From 4ee19c071ae3ef1759def71217b478601aa72fa3 Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Tue, 28 Jan 2025 22:30:31 -0800 Subject: [PATCH] refactor!: rename NGX_RS_*_OFFSET constants to original names This replaces the custom NGX_RS_HTTP_*_CONF_OFFSET constants with the original NGX_HTTP_*_CONF_OFFSET. NGX_RS_* constants were introduced as a workaround because bindgen failed to translate NGX_HTTP_*_CONF_OFFSET. --- examples/async.rs | 4 ++-- examples/awssig.rs | 12 ++++++------ examples/curl.rs | 4 ++-- examples/upstream.rs | 4 ++-- nginx-sys/build/wrapper.h | 5 ----- nginx-sys/src/lib.rs | 14 ++++++++++++++ 6 files changed, 26 insertions(+), 17 deletions(-) diff --git a/examples/async.rs b/examples/async.rs index caf0909..2d1522f 100644 --- a/examples/async.rs +++ b/examples/async.rs @@ -9,7 +9,7 @@ use ngx::ffi::{ ngx_array_push, ngx_command_t, ngx_conf_t, ngx_cycle, ngx_event_t, ngx_http_core_module, ngx_http_core_run_phases, ngx_http_handler_pt, ngx_http_module_t, ngx_http_phases_NGX_HTTP_ACCESS_PHASE, ngx_http_request_t, ngx_int_t, ngx_module_t, ngx_posted_events, ngx_queue_s, ngx_str_t, ngx_uint_t, NGX_CONF_TAKE1, NGX_HTTP_LOC_CONF, - NGX_HTTP_MODULE, NGX_RS_HTTP_LOC_CONF_OFFSET, + NGX_HTTP_LOC_CONF_OFFSET, NGX_HTTP_MODULE, }; use ngx::http::{self, HTTPModule, MergeConfigError}; use ngx::{http_request_handler, ngx_log_debug_http, ngx_null_command, ngx_string}; @@ -59,7 +59,7 @@ static mut NGX_HTTP_ASYNC_COMMANDS: [ngx_command_t; 2] = [ name: ngx_string!("async"), type_: (NGX_HTTP_LOC_CONF | NGX_CONF_TAKE1) as ngx_uint_t, set: Some(ngx_http_async_commands_set_enable), - conf: NGX_RS_HTTP_LOC_CONF_OFFSET, + conf: NGX_HTTP_LOC_CONF_OFFSET, offset: 0, post: std::ptr::null_mut(), }, diff --git a/examples/awssig.rs b/examples/awssig.rs index 9e63146..bc99f02 100644 --- a/examples/awssig.rs +++ b/examples/awssig.rs @@ -6,7 +6,7 @@ use ngx::core; use ngx::ffi::{ ngx_array_push, ngx_command_t, ngx_conf_t, ngx_http_core_module, ngx_http_handler_pt, ngx_http_module_t, ngx_http_phases_NGX_HTTP_PRECONTENT_PHASE, ngx_int_t, ngx_module_t, ngx_str_t, ngx_uint_t, NGX_CONF_TAKE1, - NGX_HTTP_LOC_CONF, NGX_HTTP_MODULE, NGX_HTTP_SRV_CONF, NGX_RS_HTTP_LOC_CONF_OFFSET, + NGX_HTTP_LOC_CONF, NGX_HTTP_LOC_CONF_OFFSET, NGX_HTTP_MODULE, NGX_HTTP_SRV_CONF, }; use ngx::http::*; use ngx::{http_request_handler, ngx_log_debug_http, ngx_null_command, ngx_string}; @@ -46,7 +46,7 @@ static mut NGX_HTTP_AWSSIGV4_COMMANDS: [ngx_command_t; 6] = [ name: ngx_string!("awssigv4"), type_: (NGX_HTTP_LOC_CONF | NGX_HTTP_SRV_CONF | NGX_CONF_TAKE1) as ngx_uint_t, set: Some(ngx_http_awssigv4_commands_set_enable), - conf: NGX_RS_HTTP_LOC_CONF_OFFSET, + conf: NGX_HTTP_LOC_CONF_OFFSET, offset: 0, post: std::ptr::null_mut(), }, @@ -54,7 +54,7 @@ static mut NGX_HTTP_AWSSIGV4_COMMANDS: [ngx_command_t; 6] = [ name: ngx_string!("awssigv4_access_key"), type_: (NGX_HTTP_LOC_CONF | NGX_HTTP_SRV_CONF | NGX_CONF_TAKE1) as ngx_uint_t, set: Some(ngx_http_awssigv4_commands_set_access_key), - conf: NGX_RS_HTTP_LOC_CONF_OFFSET, + conf: NGX_HTTP_LOC_CONF_OFFSET, offset: 0, post: std::ptr::null_mut(), }, @@ -62,7 +62,7 @@ static mut NGX_HTTP_AWSSIGV4_COMMANDS: [ngx_command_t; 6] = [ name: ngx_string!("awssigv4_secret_key"), type_: (NGX_HTTP_LOC_CONF | NGX_HTTP_SRV_CONF | NGX_CONF_TAKE1) as ngx_uint_t, set: Some(ngx_http_awssigv4_commands_set_secret_key), - conf: NGX_RS_HTTP_LOC_CONF_OFFSET, + conf: NGX_HTTP_LOC_CONF_OFFSET, offset: 0, post: std::ptr::null_mut(), }, @@ -70,7 +70,7 @@ static mut NGX_HTTP_AWSSIGV4_COMMANDS: [ngx_command_t; 6] = [ name: ngx_string!("awssigv4_s3_bucket"), type_: (NGX_HTTP_LOC_CONF | NGX_HTTP_SRV_CONF | NGX_CONF_TAKE1) as ngx_uint_t, set: Some(ngx_http_awssigv4_commands_set_s3_bucket), - conf: NGX_RS_HTTP_LOC_CONF_OFFSET, + conf: NGX_HTTP_LOC_CONF_OFFSET, offset: 0, post: std::ptr::null_mut(), }, @@ -78,7 +78,7 @@ static mut NGX_HTTP_AWSSIGV4_COMMANDS: [ngx_command_t; 6] = [ name: ngx_string!("awssigv4_s3_endpoint"), type_: (NGX_HTTP_LOC_CONF | NGX_HTTP_SRV_CONF | NGX_CONF_TAKE1) as ngx_uint_t, set: Some(ngx_http_awssigv4_commands_set_s3_endpoint), - conf: NGX_RS_HTTP_LOC_CONF_OFFSET, + conf: NGX_HTTP_LOC_CONF_OFFSET, offset: 0, post: std::ptr::null_mut(), }, diff --git a/examples/curl.rs b/examples/curl.rs index 9ed1bfe..1e4521b 100644 --- a/examples/curl.rs +++ b/examples/curl.rs @@ -5,7 +5,7 @@ use ngx::core; use ngx::ffi::{ ngx_array_push, ngx_command_t, ngx_conf_t, ngx_http_core_module, ngx_http_handler_pt, ngx_http_module_t, ngx_http_phases_NGX_HTTP_ACCESS_PHASE, ngx_int_t, ngx_module_t, ngx_str_t, ngx_uint_t, NGX_CONF_TAKE1, - NGX_HTTP_LOC_CONF, NGX_HTTP_MODULE, NGX_RS_HTTP_LOC_CONF_OFFSET, + NGX_HTTP_LOC_CONF, NGX_HTTP_LOC_CONF_OFFSET, NGX_HTTP_MODULE, }; use ngx::http::{self, HTTPModule, MergeConfigError}; use ngx::{http_request_handler, ngx_log_debug_http, ngx_null_command, ngx_string}; @@ -41,7 +41,7 @@ static mut NGX_HTTP_CURL_COMMANDS: [ngx_command_t; 2] = [ name: ngx_string!("curl"), type_: (NGX_HTTP_LOC_CONF | NGX_CONF_TAKE1) as ngx_uint_t, set: Some(ngx_http_curl_commands_set_enable), - conf: NGX_RS_HTTP_LOC_CONF_OFFSET, + conf: NGX_HTTP_LOC_CONF_OFFSET, offset: 0, post: std::ptr::null_mut(), }, diff --git a/examples/upstream.rs b/examples/upstream.rs index 14c3385..1b701ac 100644 --- a/examples/upstream.rs +++ b/examples/upstream.rs @@ -17,7 +17,7 @@ use ngx::ffi::{ ngx_http_module_t, ngx_http_upstream_init_peer_pt, ngx_http_upstream_init_pt, ngx_http_upstream_init_round_robin, ngx_http_upstream_module, ngx_http_upstream_srv_conf_t, ngx_http_upstream_t, ngx_int_t, ngx_module_t, ngx_peer_connection_t, ngx_str_t, ngx_uint_t, NGX_CONF_NOARGS, NGX_CONF_TAKE1, NGX_CONF_UNSET, NGX_ERROR, - NGX_HTTP_MODULE, NGX_HTTP_UPS_CONF, NGX_LOG_EMERG, NGX_RS_HTTP_SRV_CONF_OFFSET, + NGX_HTTP_MODULE, NGX_HTTP_SRV_CONF_OFFSET, NGX_HTTP_UPS_CONF, NGX_LOG_EMERG, }; use ngx::http::{ ngx_http_conf_get_module_srv_conf, ngx_http_conf_upstream_srv_conf_immutable, @@ -93,7 +93,7 @@ static mut NGX_HTTP_UPSTREAM_CUSTOM_COMMANDS: [ngx_command_t; 2] = [ name: ngx_string!("custom"), type_: (NGX_HTTP_UPS_CONF | NGX_CONF_NOARGS | NGX_CONF_TAKE1) as ngx_uint_t, set: Some(ngx_http_upstream_commands_set_custom), - conf: NGX_RS_HTTP_SRV_CONF_OFFSET, + conf: NGX_HTTP_SRV_CONF_OFFSET, offset: 0, post: std::ptr::null_mut(), }, diff --git a/nginx-sys/build/wrapper.h b/nginx-sys/build/wrapper.h index 1f1d17e..daaf38d 100644 --- a/nginx-sys/build/wrapper.h +++ b/nginx-sys/build/wrapper.h @@ -3,11 +3,6 @@ #include #include -// Define as constants since bindgen can't parse these values -const size_t NGX_RS_HTTP_MAIN_CONF_OFFSET = NGX_HTTP_MAIN_CONF_OFFSET; -const size_t NGX_RS_HTTP_SRV_CONF_OFFSET = NGX_HTTP_SRV_CONF_OFFSET; -const size_t NGX_RS_HTTP_LOC_CONF_OFFSET = NGX_HTTP_LOC_CONF_OFFSET; - const char *NGX_RS_MODULE_SIGNATURE = NGX_MODULE_SIGNATURE; // `--prefix=` results in not emitting the declaration diff --git a/nginx-sys/src/lib.rs b/nginx-sys/src/lib.rs index 557c517..d614e84 100644 --- a/nginx-sys/src/lib.rs +++ b/nginx-sys/src/lib.rs @@ -3,6 +3,7 @@ #![no_std] use core::fmt; +use core::mem::offset_of; use core::ptr::copy_nonoverlapping; use core::slice; @@ -21,6 +22,19 @@ mod bindings { #[doc(no_inline)] pub use bindings::*; +/// The offset of the `main_conf` field in the `ngx_http_conf_ctx_t` struct. +/// +/// This is used to access the main configuration context for an HTTP module. +pub const NGX_HTTP_MAIN_CONF_OFFSET: usize = offset_of!(ngx_http_conf_ctx_t, main_conf); +/// The offset of the `srv_conf` field in the `ngx_http_conf_ctx_t` struct. +/// +/// This is used to access the server configuration context for an HTTP module. +pub const NGX_HTTP_SRV_CONF_OFFSET: usize = offset_of!(ngx_http_conf_ctx_t, srv_conf); +/// The offset of the `loc_conf` field in the `ngx_http_conf_ctx_t` struct. +/// +/// This is used to access the location configuration context for an HTTP module. +pub const NGX_HTTP_LOC_CONF_OFFSET: usize = offset_of!(ngx_http_conf_ctx_t, loc_conf); + /// Convert a byte slice to a raw pointer (`*mut u_char`) allocated in the given nginx memory pool. /// /// # Safety