Skip to content

Commit 2d7fd00

Browse files
committed
chore: expose minimal sufficient set of symbols via ::prelude::*
1 parent a575249 commit 2d7fd00

File tree

11 files changed

+112
-37
lines changed

11 files changed

+112
-37
lines changed

examples/async.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ use std::sync::Arc;
55
use std::time::Instant;
66

77
use ngx::core;
8+
use ngx::core::prelude::*;
89
use ngx::ffi::{
9-
nginx_version, ngx_array_push, ngx_command_t, ngx_conf_t, ngx_cycle, ngx_event_t, ngx_http_core_module,
10-
ngx_http_core_run_phases, ngx_http_handler_pt, ngx_http_module_t, ngx_http_phases_NGX_HTTP_ACCESS_PHASE,
11-
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,
12-
NGX_HTTP_LOC_CONF, NGX_HTTP_MODULE, NGX_RS_HTTP_LOC_CONF_OFFSET, NGX_RS_MODULE_SIGNATURE,
10+
nginx_version, ngx_array_push, ngx_http_core_run_phases, ngx_http_phases_NGX_HTTP_ACCESS_PHASE, ngx_queue_s,
11+
NGX_RS_MODULE_SIGNATURE,
1312
};
13+
use ngx::http::prelude::*;
1414
use ngx::http::{self, HTTPModule, MergeConfigError};
1515
use ngx::{http_request_handler, ngx_log_debug_http, ngx_null_command, ngx_string};
1616
use tokio::runtime::Runtime;
@@ -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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@ use std::ptr::addr_of;
33

44
use http::HeaderMap;
55
use ngx::core;
6-
use ngx::ffi::{
7-
nginx_version, ngx_array_push, ngx_command_t, ngx_conf_t, ngx_http_core_module, ngx_http_handler_pt,
8-
ngx_http_module_t, ngx_http_phases_NGX_HTTP_PRECONTENT_PHASE, ngx_int_t, ngx_module_t, ngx_str_t, ngx_uint_t,
9-
NGX_CONF_TAKE1, NGX_HTTP_LOC_CONF, NGX_HTTP_MODULE, NGX_HTTP_SRV_CONF, NGX_RS_HTTP_LOC_CONF_OFFSET,
10-
NGX_RS_MODULE_SIGNATURE,
11-
};
6+
use ngx::core::prelude::*;
7+
use ngx::ffi::{nginx_version, ngx_array_push, ngx_http_phases_NGX_HTTP_PRECONTENT_PHASE, NGX_RS_MODULE_SIGNATURE};
8+
use ngx::http::prelude::*;
129
use ngx::http::*;
1310
use ngx::{http_request_handler, ngx_log_debug_http, ngx_null_command, ngx_string};
1411

@@ -47,39 +44,39 @@ static mut NGX_HTTP_AWSSIGV4_COMMANDS: [ngx_command_t; 6] = [
4744
name: ngx_string!("awssigv4"),
4845
type_: (NGX_HTTP_LOC_CONF | NGX_HTTP_SRV_CONF | NGX_CONF_TAKE1) as ngx_uint_t,
4946
set: Some(ngx_http_awssigv4_commands_set_enable),
50-
conf: NGX_RS_HTTP_LOC_CONF_OFFSET,
47+
conf: NGX_HTTP_LOC_CONF_OFFSET,
5148
offset: 0,
5249
post: std::ptr::null_mut(),
5350
},
5451
ngx_command_t {
5552
name: ngx_string!("awssigv4_access_key"),
5653
type_: (NGX_HTTP_LOC_CONF | NGX_HTTP_SRV_CONF | NGX_CONF_TAKE1) as ngx_uint_t,
5754
set: Some(ngx_http_awssigv4_commands_set_access_key),
58-
conf: NGX_RS_HTTP_LOC_CONF_OFFSET,
55+
conf: NGX_HTTP_LOC_CONF_OFFSET,
5956
offset: 0,
6057
post: std::ptr::null_mut(),
6158
},
6259
ngx_command_t {
6360
name: ngx_string!("awssigv4_secret_key"),
6461
type_: (NGX_HTTP_LOC_CONF | NGX_HTTP_SRV_CONF | NGX_CONF_TAKE1) as ngx_uint_t,
6562
set: Some(ngx_http_awssigv4_commands_set_secret_key),
66-
conf: NGX_RS_HTTP_LOC_CONF_OFFSET,
63+
conf: NGX_HTTP_LOC_CONF_OFFSET,
6764
offset: 0,
6865
post: std::ptr::null_mut(),
6966
},
7067
ngx_command_t {
7168
name: ngx_string!("awssigv4_s3_bucket"),
7269
type_: (NGX_HTTP_LOC_CONF | NGX_HTTP_SRV_CONF | NGX_CONF_TAKE1) as ngx_uint_t,
7370
set: Some(ngx_http_awssigv4_commands_set_s3_bucket),
74-
conf: NGX_RS_HTTP_LOC_CONF_OFFSET,
71+
conf: NGX_HTTP_LOC_CONF_OFFSET,
7572
offset: 0,
7673
post: std::ptr::null_mut(),
7774
},
7875
ngx_command_t {
7976
name: ngx_string!("awssigv4_s3_endpoint"),
8077
type_: (NGX_HTTP_LOC_CONF | NGX_HTTP_SRV_CONF | NGX_CONF_TAKE1) as ngx_uint_t,
8178
set: Some(ngx_http_awssigv4_commands_set_s3_endpoint),
82-
conf: NGX_RS_HTTP_LOC_CONF_OFFSET,
79+
conf: NGX_HTTP_LOC_CONF_OFFSET,
8380
offset: 0,
8481
post: std::ptr::null_mut(),
8582
},

examples/curl.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ use std::ffi::{c_char, c_void};
22
use std::ptr::addr_of;
33

44
use ngx::core;
5-
use ngx::ffi::{
6-
nginx_version, ngx_array_push, ngx_command_t, ngx_conf_t, ngx_http_core_module, ngx_http_handler_pt,
7-
ngx_http_module_t, ngx_http_phases_NGX_HTTP_ACCESS_PHASE, ngx_int_t, ngx_module_t, ngx_str_t, ngx_uint_t,
8-
NGX_CONF_TAKE1, NGX_HTTP_LOC_CONF, NGX_HTTP_MODULE, NGX_RS_HTTP_LOC_CONF_OFFSET, NGX_RS_MODULE_SIGNATURE,
9-
};
5+
use ngx::core::prelude::*;
6+
use ngx::ffi::{nginx_version, ngx_array_push, ngx_http_phases_NGX_HTTP_ACCESS_PHASE, NGX_RS_MODULE_SIGNATURE};
7+
use ngx::http::prelude::*;
108
use ngx::http::{self, HTTPModule, MergeConfigError};
119
use ngx::{http_request_handler, ngx_log_debug_http, ngx_null_command, ngx_string};
1210

@@ -41,7 +39,7 @@ static mut NGX_HTTP_CURL_COMMANDS: [ngx_command_t; 2] = [
4139
name: ngx_string!("curl"),
4240
type_: (NGX_HTTP_LOC_CONF | NGX_CONF_TAKE1) as ngx_uint_t,
4341
set: Some(ngx_http_curl_commands_set_enable),
44-
conf: NGX_RS_HTTP_LOC_CONF_OFFSET,
42+
conf: NGX_HTTP_LOC_CONF_OFFSET,
4543
offset: 0,
4644
post: std::ptr::null_mut(),
4745
},

examples/httporigdst.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ use std::ffi::{c_char, c_int, c_void};
22
use std::ptr::addr_of;
33

44
use ngx::core;
5+
use ngx::core::prelude::*;
56
use ngx::ffi::{
6-
in_port_t, nginx_version, ngx_conf_t, ngx_connection_local_sockaddr, ngx_http_add_variable, ngx_http_module_t,
7-
ngx_http_variable_t, ngx_inet_get_port, ngx_int_t, ngx_module_t, ngx_sock_ntop, ngx_str_t, ngx_uint_t,
8-
ngx_variable_value_t, sockaddr, sockaddr_storage, INET_ADDRSTRLEN, NGX_HTTP_MODULE, NGX_RS_MODULE_SIGNATURE,
7+
in_port_t, nginx_version, ngx_connection_local_sockaddr, ngx_inet_get_port, ngx_sock_ntop, sockaddr,
8+
sockaddr_storage, INET_ADDRSTRLEN, NGX_RS_MODULE_SIGNATURE,
99
};
10+
use ngx::http::prelude::*;
1011
use ngx::http::{self, HTTPModule};
1112
use ngx::{http_variable_get, ngx_http_null_variable, ngx_log_debug_http, ngx_null_string, ngx_string};
1213

examples/upstream.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ use std::mem;
1111
use std::ptr::addr_of;
1212
use std::slice;
1313

14+
use ngx::core::prelude::*;
1415
use ngx::core::{Pool, Status};
1516
use ngx::ffi::{
16-
nginx_version, ngx_atoi, ngx_command_t, ngx_conf_t, ngx_connection_t, ngx_event_free_peer_pt,
17-
ngx_event_get_peer_pt, ngx_http_module_t, ngx_http_upstream_init_peer_pt, ngx_http_upstream_init_pt,
18-
ngx_http_upstream_init_round_robin, ngx_http_upstream_module, ngx_http_upstream_srv_conf_t, ngx_http_upstream_t,
19-
ngx_int_t, ngx_module_t, ngx_peer_connection_t, ngx_str_t, ngx_uint_t, NGX_CONF_NOARGS, NGX_CONF_TAKE1,
20-
NGX_CONF_UNSET, NGX_ERROR, NGX_HTTP_MODULE, NGX_HTTP_UPS_CONF, NGX_LOG_EMERG, NGX_RS_HTTP_SRV_CONF_OFFSET,
21-
NGX_RS_MODULE_SIGNATURE,
17+
nginx_version, ngx_atoi, ngx_event_free_peer_pt, ngx_event_get_peer_pt, ngx_http_upstream_init_peer_pt,
18+
ngx_http_upstream_init_pt, ngx_http_upstream_init_round_robin, ngx_http_upstream_module,
19+
ngx_http_upstream_srv_conf_t, ngx_http_upstream_t, ngx_peer_connection_t, NGX_ERROR, NGX_RS_MODULE_SIGNATURE,
2220
};
21+
use ngx::http::prelude::*;
2322
use ngx::http::{
2423
ngx_http_conf_get_module_srv_conf, ngx_http_conf_upstream_srv_conf_immutable,
2524
ngx_http_conf_upstream_srv_conf_mutable, HTTPModule, Merge, MergeConfigError, Request,
@@ -94,7 +93,7 @@ static mut NGX_HTTP_UPSTREAM_CUSTOM_COMMANDS: [ngx_command_t; 2] = [
9493
name: ngx_string!("custom"),
9594
type_: (NGX_HTTP_UPS_CONF | NGX_CONF_NOARGS | NGX_CONF_TAKE1) as ngx_uint_t,
9695
set: Some(ngx_http_upstream_commands_set_custom),
97-
conf: NGX_RS_HTTP_SRV_CONF_OFFSET,
96+
conf: NGX_HTTP_SRV_CONF_OFFSET,
9897
offset: 0,
9998
post: std::ptr::null_mut(),
10099
},

nginx-sys/build/wrapper.h

Lines changed: 0 additions & 5 deletions
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

Lines changed: 14 additions & 0 deletions
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,19 @@ 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+
/// The offset of the `srv_conf` field in the `ngx_http_conf_ctx_t` struct.
30+
///
31+
/// This is used to access the server configuration context for an HTTP module.
32+
pub const NGX_HTTP_SRV_CONF_OFFSET: usize = offset_of!(ngx_http_conf_ctx_t, srv_conf);
33+
/// The offset of the `loc_conf` field in the `ngx_http_conf_ctx_t` struct.
34+
///
35+
/// This is used to access the location configuration context for an HTTP module.
36+
pub const NGX_HTTP_LOC_CONF_OFFSET: usize = offset_of!(ngx_http_conf_ctx_t, loc_conf);
37+
2438
/// Convert a byte slice to a raw pointer (`*mut u_char`) allocated in the given nginx memory pool.
2539
///
2640
/// # Safety

src/core/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
mod buffer;
22
mod pool;
3+
/// The prelude module.
4+
///
5+
/// This module provides common constants and types that are used in NGINX modules.
6+
pub mod prelude;
37
mod status;
48
mod string;
59

src/core/prelude.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
pub use crate::ffi::ngx_command_t;
2+
pub use crate::ffi::ngx_conf_t;
3+
pub use crate::ffi::ngx_connection_t;
4+
pub use crate::ffi::ngx_event_t;
5+
pub use crate::ffi::ngx_int_t;
6+
pub use crate::ffi::ngx_module_t;
7+
pub use crate::ffi::ngx_str_t;
8+
pub use crate::ffi::ngx_uint_t;
9+
pub use crate::ffi::ngx_variable_value_t;
10+
11+
pub use crate::ffi::NGX_LOG_ALERT;
12+
pub use crate::ffi::NGX_LOG_CRIT;
13+
pub use crate::ffi::NGX_LOG_DEBUG;
14+
pub use crate::ffi::NGX_LOG_EMERG;
15+
pub use crate::ffi::NGX_LOG_ERR;
16+
pub use crate::ffi::NGX_LOG_INFO;
17+
pub use crate::ffi::NGX_LOG_NOTICE;
18+
pub use crate::ffi::NGX_LOG_WARN;
19+
20+
pub use crate::ffi::NGX_ANY_CONF;
21+
pub use crate::ffi::NGX_CONF_1MORE;
22+
pub use crate::ffi::NGX_CONF_2MORE;
23+
pub use crate::ffi::NGX_CONF_ANY;
24+
pub use crate::ffi::NGX_CONF_ARGS_NUMBER;
25+
pub use crate::ffi::NGX_CONF_BLOCK;
26+
pub use crate::ffi::NGX_CONF_FLAG;
27+
pub use crate::ffi::NGX_CONF_NOARGS;
28+
pub use crate::ffi::NGX_CONF_TAKE1;
29+
pub use crate::ffi::NGX_CONF_TAKE2;
30+
pub use crate::ffi::NGX_CONF_TAKE3;
31+
pub use crate::ffi::NGX_CONF_TAKE4;
32+
pub use crate::ffi::NGX_CONF_TAKE5;
33+
pub use crate::ffi::NGX_CONF_TAKE6;
34+
pub use crate::ffi::NGX_CONF_TAKE7;
35+
pub use crate::ffi::NGX_CONF_UNSET;
36+
pub use crate::ffi::NGX_DIRECT_CONF;
37+
pub use crate::ffi::NGX_MAIN_CONF;
38+
39+
pub use crate::ffi::ngx_cycle;
40+
pub use crate::ffi::ngx_posted_events;

src/http/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
mod conf;
22
mod module;
3+
/// The prelude module.
4+
///
5+
/// This module provides common constants and types that are used in NGINX http modules.
6+
pub mod prelude;
37
mod request;
48
mod status;
59
mod upstream;

src/http/prelude.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
pub use crate::ffi::ngx_http_handler_pt;
2+
pub use crate::ffi::ngx_http_module_t;
3+
pub use crate::ffi::ngx_http_request_t;
4+
pub use crate::ffi::ngx_http_variable_t;
5+
pub use crate::ffi::ngx_http_variable_value_t;
6+
7+
pub use crate::ffi::NGX_HTTP_MODULE;
8+
9+
pub use crate::ffi::NGX_HTTP_LIF_CONF;
10+
pub use crate::ffi::NGX_HTTP_LMT_CONF;
11+
pub use crate::ffi::NGX_HTTP_LOC_CONF;
12+
pub use crate::ffi::NGX_HTTP_MAIN_CONF;
13+
pub use crate::ffi::NGX_HTTP_SIF_CONF;
14+
pub use crate::ffi::NGX_HTTP_SRV_CONF;
15+
pub use crate::ffi::NGX_HTTP_UPS_CONF;
16+
17+
pub use crate::ffi::NGX_HTTP_LOC_CONF_OFFSET;
18+
pub use crate::ffi::NGX_HTTP_MAIN_CONF_OFFSET;
19+
pub use crate::ffi::NGX_HTTP_SRV_CONF_OFFSET;
20+
21+
pub use crate::ffi::ngx_http_core_module;
22+
23+
pub use crate::ffi::ngx_http_add_variable;

0 commit comments

Comments
 (0)