Skip to content

Commit a542225

Browse files
xeioexbavshin-f5
authored andcommitted
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.
1 parent dd3e3d9 commit a542225

File tree

6 files changed

+28
-17
lines changed

6 files changed

+28
-17
lines changed

examples/async.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use ngx::ffi::{
99
ngx_array_push, ngx_command_t, ngx_conf_t, ngx_cycle, ngx_event_t, ngx_http_core_module, ngx_http_core_run_phases,
1010
ngx_http_handler_pt, ngx_http_module_t, ngx_http_phases_NGX_HTTP_ACCESS_PHASE, ngx_http_request_t, ngx_int_t,
1111
ngx_module_t, ngx_posted_events, ngx_queue_s, ngx_str_t, ngx_uint_t, NGX_CONF_TAKE1, NGX_HTTP_LOC_CONF,
12-
NGX_HTTP_MODULE, NGX_RS_HTTP_LOC_CONF_OFFSET,
12+
NGX_HTTP_LOC_CONF_OFFSET, NGX_HTTP_MODULE,
1313
};
1414
use ngx::http::{self, HTTPModule, MergeConfigError};
1515
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] = [
5959
name: ngx_string!("async"),
6060
type_: (NGX_HTTP_LOC_CONF | NGX_CONF_TAKE1) as ngx_uint_t,
6161
set: Some(ngx_http_async_commands_set_enable),
62-
conf: NGX_RS_HTTP_LOC_CONF_OFFSET,
62+
conf: NGX_HTTP_LOC_CONF_OFFSET,
6363
offset: 0,
6464
post: std::ptr::null_mut(),
6565
},

examples/awssig.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use ngx::core;
66
use ngx::ffi::{
77
ngx_array_push, ngx_command_t, ngx_conf_t, ngx_http_core_module, ngx_http_handler_pt, ngx_http_module_t,
88
ngx_http_phases_NGX_HTTP_PRECONTENT_PHASE, ngx_int_t, ngx_module_t, ngx_str_t, ngx_uint_t, NGX_CONF_TAKE1,
9-
NGX_HTTP_LOC_CONF, NGX_HTTP_MODULE, NGX_HTTP_SRV_CONF, NGX_RS_HTTP_LOC_CONF_OFFSET,
9+
NGX_HTTP_LOC_CONF, NGX_HTTP_LOC_CONF_OFFSET, NGX_HTTP_MODULE, NGX_HTTP_SRV_CONF,
1010
};
1111
use ngx::http::*;
1212
use ngx::{http_request_handler, ngx_log_debug_http, ngx_null_command, ngx_string};
@@ -46,39 +46,39 @@ static mut NGX_HTTP_AWSSIGV4_COMMANDS: [ngx_command_t; 6] = [
4646
name: ngx_string!("awssigv4"),
4747
type_: (NGX_HTTP_LOC_CONF | NGX_HTTP_SRV_CONF | NGX_CONF_TAKE1) as ngx_uint_t,
4848
set: Some(ngx_http_awssigv4_commands_set_enable),
49-
conf: NGX_RS_HTTP_LOC_CONF_OFFSET,
49+
conf: NGX_HTTP_LOC_CONF_OFFSET,
5050
offset: 0,
5151
post: std::ptr::null_mut(),
5252
},
5353
ngx_command_t {
5454
name: ngx_string!("awssigv4_access_key"),
5555
type_: (NGX_HTTP_LOC_CONF | NGX_HTTP_SRV_CONF | NGX_CONF_TAKE1) as ngx_uint_t,
5656
set: Some(ngx_http_awssigv4_commands_set_access_key),
57-
conf: NGX_RS_HTTP_LOC_CONF_OFFSET,
57+
conf: NGX_HTTP_LOC_CONF_OFFSET,
5858
offset: 0,
5959
post: std::ptr::null_mut(),
6060
},
6161
ngx_command_t {
6262
name: ngx_string!("awssigv4_secret_key"),
6363
type_: (NGX_HTTP_LOC_CONF | NGX_HTTP_SRV_CONF | NGX_CONF_TAKE1) as ngx_uint_t,
6464
set: Some(ngx_http_awssigv4_commands_set_secret_key),
65-
conf: NGX_RS_HTTP_LOC_CONF_OFFSET,
65+
conf: NGX_HTTP_LOC_CONF_OFFSET,
6666
offset: 0,
6767
post: std::ptr::null_mut(),
6868
},
6969
ngx_command_t {
7070
name: ngx_string!("awssigv4_s3_bucket"),
7171
type_: (NGX_HTTP_LOC_CONF | NGX_HTTP_SRV_CONF | NGX_CONF_TAKE1) as ngx_uint_t,
7272
set: Some(ngx_http_awssigv4_commands_set_s3_bucket),
73-
conf: NGX_RS_HTTP_LOC_CONF_OFFSET,
73+
conf: NGX_HTTP_LOC_CONF_OFFSET,
7474
offset: 0,
7575
post: std::ptr::null_mut(),
7676
},
7777
ngx_command_t {
7878
name: ngx_string!("awssigv4_s3_endpoint"),
7979
type_: (NGX_HTTP_LOC_CONF | NGX_HTTP_SRV_CONF | NGX_CONF_TAKE1) as ngx_uint_t,
8080
set: Some(ngx_http_awssigv4_commands_set_s3_endpoint),
81-
conf: NGX_RS_HTTP_LOC_CONF_OFFSET,
81+
conf: NGX_HTTP_LOC_CONF_OFFSET,
8282
offset: 0,
8383
post: std::ptr::null_mut(),
8484
},

examples/curl.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use ngx::core;
55
use ngx::ffi::{
66
ngx_array_push, ngx_command_t, ngx_conf_t, ngx_http_core_module, ngx_http_handler_pt, ngx_http_module_t,
77
ngx_http_phases_NGX_HTTP_ACCESS_PHASE, ngx_int_t, ngx_module_t, ngx_str_t, ngx_uint_t, NGX_CONF_TAKE1,
8-
NGX_HTTP_LOC_CONF, NGX_HTTP_MODULE, NGX_RS_HTTP_LOC_CONF_OFFSET,
8+
NGX_HTTP_LOC_CONF, NGX_HTTP_LOC_CONF_OFFSET, NGX_HTTP_MODULE,
99
};
1010
use ngx::http::{self, HTTPModule, MergeConfigError};
1111
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] = [
4141
name: ngx_string!("curl"),
4242
type_: (NGX_HTTP_LOC_CONF | NGX_CONF_TAKE1) as ngx_uint_t,
4343
set: Some(ngx_http_curl_commands_set_enable),
44-
conf: NGX_RS_HTTP_LOC_CONF_OFFSET,
44+
conf: NGX_HTTP_LOC_CONF_OFFSET,
4545
offset: 0,
4646
post: std::ptr::null_mut(),
4747
},

examples/upstream.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use ngx::ffi::{
1717
ngx_http_module_t, ngx_http_upstream_init_peer_pt, ngx_http_upstream_init_pt, ngx_http_upstream_init_round_robin,
1818
ngx_http_upstream_module, ngx_http_upstream_srv_conf_t, ngx_http_upstream_t, ngx_int_t, ngx_module_t,
1919
ngx_peer_connection_t, ngx_str_t, ngx_uint_t, NGX_CONF_NOARGS, NGX_CONF_TAKE1, NGX_CONF_UNSET, NGX_ERROR,
20-
NGX_HTTP_MODULE, NGX_HTTP_UPS_CONF, NGX_LOG_EMERG, NGX_RS_HTTP_SRV_CONF_OFFSET,
20+
NGX_HTTP_MODULE, NGX_HTTP_SRV_CONF_OFFSET, NGX_HTTP_UPS_CONF, NGX_LOG_EMERG,
2121
};
2222
use ngx::http::{
2323
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] = [
9393
name: ngx_string!("custom"),
9494
type_: (NGX_HTTP_UPS_CONF | NGX_CONF_NOARGS | NGX_CONF_TAKE1) as ngx_uint_t,
9595
set: Some(ngx_http_upstream_commands_set_custom),
96-
conf: NGX_RS_HTTP_SRV_CONF_OFFSET,
96+
conf: NGX_HTTP_SRV_CONF_OFFSET,
9797
offset: 0,
9898
post: std::ptr::null_mut(),
9999
},

nginx-sys/build/wrapper.h

-5
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
#include <ngx_config.h>
44
#include <ngx_core.h>
55

6-
// Define as constants since bindgen can't parse these values
7-
const size_t NGX_RS_HTTP_MAIN_CONF_OFFSET = NGX_HTTP_MAIN_CONF_OFFSET;
8-
const size_t NGX_RS_HTTP_SRV_CONF_OFFSET = NGX_HTTP_SRV_CONF_OFFSET;
9-
const size_t NGX_RS_HTTP_LOC_CONF_OFFSET = NGX_HTTP_LOC_CONF_OFFSET;
10-
116
const char *NGX_RS_MODULE_SIGNATURE = NGX_MODULE_SIGNATURE;
127

138
// `--prefix=` results in not emitting the declaration

nginx-sys/src/lib.rs

+16
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#![no_std]
44

55
use core::fmt;
6+
use core::mem::offset_of;
67
use core::ptr::copy_nonoverlapping;
78
use core::slice;
89

@@ -21,6 +22,21 @@ mod bindings {
2122
#[doc(no_inline)]
2223
pub use bindings::*;
2324

25+
/// The offset of the `main_conf` field in the `ngx_http_conf_ctx_t` struct.
26+
///
27+
/// This is used to access the main configuration context for an HTTP module.
28+
pub const NGX_HTTP_MAIN_CONF_OFFSET: usize = offset_of!(ngx_http_conf_ctx_t, main_conf);
29+
30+
/// The offset of the `srv_conf` field in the `ngx_http_conf_ctx_t` struct.
31+
///
32+
/// This is used to access the server configuration context for an HTTP module.
33+
pub const NGX_HTTP_SRV_CONF_OFFSET: usize = offset_of!(ngx_http_conf_ctx_t, srv_conf);
34+
35+
/// The offset of the `loc_conf` field in the `ngx_http_conf_ctx_t` struct.
36+
///
37+
/// This is used to access the location configuration context for an HTTP module.
38+
pub const NGX_HTTP_LOC_CONF_OFFSET: usize = offset_of!(ngx_http_conf_ctx_t, loc_conf);
39+
2440
/// Convert a byte slice to a raw pointer (`*mut u_char`) allocated in the given nginx memory pool.
2541
///
2642
/// # Safety

0 commit comments

Comments
 (0)