Skip to content

Commit

Permalink
refactor!: rename NGX_RS_*_OFFSET constants to original names
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
xeioex committed Jan 29, 2025
1 parent e834149 commit 4ee19c0
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 17 deletions.
4 changes: 2 additions & 2 deletions examples/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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(),
},
Expand Down
12 changes: 6 additions & 6 deletions examples/awssig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -46,39 +46,39 @@ 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(),
},
ngx_command_t {
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(),
},
ngx_command_t {
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(),
},
ngx_command_t {
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(),
},
ngx_command_t {
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(),
},
Expand Down
4 changes: 2 additions & 2 deletions examples/curl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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(),
},
Expand Down
4 changes: 2 additions & 2 deletions examples/upstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
},
Expand Down
5 changes: 0 additions & 5 deletions nginx-sys/build/wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
#include <ngx_config.h>
#include <ngx_core.h>

// 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
Expand Down
14 changes: 14 additions & 0 deletions nginx-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#![no_std]

use core::fmt;
use core::mem::offset_of;
use core::ptr::copy_nonoverlapping;
use core::slice;

Expand All @@ -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
Expand Down

0 comments on commit 4ee19c0

Please sign in to comment.