From 11180c413bdf875c116500a52159ef19d61a323b Mon Sep 17 00:00:00 2001 From: Mateusz Matejuk Date: Tue, 23 Jan 2024 09:50:46 +0100 Subject: [PATCH] [FEAT]: additional functions exposed * formatted * some function chagned to usnafe --- Cargo.lock | 67 ++++++++++++++++ Cargo.toml | 13 +-- examples/simple/Cargo.toml | 17 ++-- examples/simple/src/lib.rs | 20 ++++- nginx_derive/Cargo.toml | 32 ++++---- nginx_derive/src/lib.rs | 17 ++-- nginx_module/Cargo.toml | 31 ++++---- nginx_module/build.rs | 5 +- nginx_module/src/bindings.rs | 12 ++- nginx_module/src/complex_value.rs | 13 +-- nginx_module/src/connection.rs | 2 +- nginx_module/src/http_request.rs | 128 +++++++++++++++++++++++++++--- nginx_module/src/lib.rs | 51 ++++++++++-- nginx_module/src/log.rs | 4 +- nginx_module/src/md5.rs | 2 +- nginx_module/src/ngx_str.rs | 5 +- nginx_module/src/pool.rs | 2 +- nginx_module/src/var.rs | 21 +++-- nginx_module/src/wrappers.rs | 6 +- nginx_module/wrapper.h | 2 +- rust-toolchain.toml | 5 ++ 21 files changed, 353 insertions(+), 102 deletions(-) create mode 100644 rust-toolchain.toml diff --git a/Cargo.lock b/Cargo.lock index d864da7..19cf4d3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -88,6 +88,15 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + [[package]] name = "glob" version = "0.3.1" @@ -103,6 +112,16 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -172,6 +191,7 @@ dependencies = [ "bindgen", "bitflags", "libc", + "url", ] [[package]] @@ -196,6 +216,12 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + [[package]] name = "prettyplease" version = "0.2.15" @@ -298,12 +324,53 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "unicode-bidi" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" + [[package]] name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "url" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + [[package]] name = "which" version = "4.4.2" diff --git a/Cargo.toml b/Cargo.toml index a5c33ca..85745df 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,12 @@ [workspace] -resolver = "2" + resolver = "2" -members = [ - "examples/simple" -] + members = [ "examples/simple" ] [profile.release] -debug = true \ No newline at end of file + debug = true + lto = false + +[profile.dev] + opt-level = 1 + lto = false \ No newline at end of file diff --git a/examples/simple/Cargo.toml b/examples/simple/Cargo.toml index 3fe99e5..9e18970 100644 --- a/examples/simple/Cargo.toml +++ b/examples/simple/Cargo.toml @@ -1,16 +1,15 @@ [package] -name = "simple" -version = "0.1.0" -edition = "2021" + edition = "2021" + name = "simple" + version = "0.1.0" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [lib] -crate-type = ["staticlib"] - + crate-type = [ "staticlib" ] [dependencies] -anyhow = "1.0.71" -nginx_derive = { path = "../../nginx_derive" } -nginx_module = { path = "../../nginx_module" } + anyhow = "1.0.71" + nginx_derive = { path = "../../nginx_derive" } + nginx_module = { path = "../../nginx_module" } diff --git a/examples/simple/src/lib.rs b/examples/simple/src/lib.rs index fcee7c6..09ad33f 100644 --- a/examples/simple/src/lib.rs +++ b/examples/simple/src/lib.rs @@ -1,14 +1,26 @@ /* - * Copyright 2023 G-Core Innovations SARL + * Copyright 2024 G-Core Innovations SARL */ use std::ffi::{c_char, c_void}; use nginx_derive::NginxConfig; use nginx_module::{ - add_http_handler, nginx_version, ngx_command_t, ngx_conf_t, ngx_http_module_t, ngx_module_t, - ngx_str_t, HttpHandler, HttpRequestAndContext, NgxConfig, NgxStr, NGX_DECLINED, - NGX_HTTP_FORBIDDEN, NGX_HTTP_MODULE, NGX_RS_MODULE_SIGNATURE, + add_http_handler, + nginx_version, + ngx_command_t, + ngx_conf_t, + ngx_http_module_t, + ngx_module_t, + ngx_str_t, + HttpHandler, + HttpRequestAndContext, + NgxConfig, + NgxStr, + NGX_DECLINED, + NGX_HTTP_FORBIDDEN, + NGX_HTTP_MODULE, + NGX_RS_MODULE_SIGNATURE, }; #[no_mangle] diff --git a/nginx_derive/Cargo.toml b/nginx_derive/Cargo.toml index 2db93e4..db39eae 100644 --- a/nginx_derive/Cargo.toml +++ b/nginx_derive/Cargo.toml @@ -1,20 +1,24 @@ [package] -name = "nginx_derive" -version = "0.1.1" -edition = "2021" -authors = ["Gabriel Oprisan "] -description = "Helper crate for nginx-rust" -homepage = "https://github.com/g-Core/nginx-rust" -repository = "https://github.com/g-Core/nginx-rust" -readme = "README.md" -license = "Apache-2.0" + authors = [ "Gabriel Oprisan " ] + description = "Helper crate for nginx-rust" + edition = "2021" + homepage = "https://github.com/g-Core/nginx-rust" + license = "Apache-2.0" + name = "nginx_derive" + readme = "README.md" + repository = "https://github.com/g-Core/nginx-rust" + version = "0.1.1" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [lib] -proc-macro = true + proc-macro = true [dependencies] -syn = "2.0.18" -quote = "1.0.28" -proc-macro2 = "1.0.59" \ No newline at end of file + proc-macro2 = { version = "1.0.59" } + quote = { version = "1.0.28" } + syn = { version = "2.0.18" } + +[profile.release] + debug = true + lto = false \ No newline at end of file diff --git a/nginx_derive/src/lib.rs b/nginx_derive/src/lib.rs index a64b98c..bf8a78d 100644 --- a/nginx_derive/src/lib.rs +++ b/nginx_derive/src/lib.rs @@ -1,10 +1,10 @@ /* - * Copyright 2023 G-Core Innovations SARL + * Copyright 2024 G-Core Innovations SARL */ use proc_macro::TokenStream; use proc_macro2::Literal; -use quote::{quote, quote_spanned, format_ident}; +use quote::{format_ident, quote, quote_spanned}; use syn::{parse_macro_input, DeriveInput}; #[proc_macro_derive(NginxConfig)] @@ -21,7 +21,7 @@ fn impl_derive_config(input: DeriveInput) -> proc_macro2::TokenStream { syn::Data::Struct(s) => { let struct_name = input.ident; let commands_ident = format_ident!("{}_COMMANDS_AUTOGENERATED", struct_name); - + let mut field_defs: Vec<_> = s.fields.iter().filter_map(|f| { let name = f.ident.as_ref()?; let name_nil_terminated = Literal::byte_string((name.to_string() + "\0").as_bytes()); @@ -39,7 +39,7 @@ fn impl_derive_config(input: DeriveInput) -> proc_macro2::TokenStream { } }) }).collect(); - field_defs.push(quote!{ + field_defs.push(quote! { ::nginx_module::NGX_RS_NULL_COMMAND }); let field_count = field_defs.len(); @@ -64,10 +64,9 @@ fn impl_derive_config(input: DeriveInput) -> proc_macro2::TokenStream { Err(e) => { b"Invalid value\0".as_ptr() as *mut i8 } - } + } } }) - }); let merge_fields = s.fields.iter().filter_map(|f| { @@ -98,7 +97,7 @@ fn impl_derive_config(input: DeriveInput) -> proc_macro2::TokenStream { Ok(c) => (c as *mut #struct_name).cast(), } } - + pub unsafe extern "C" fn merge( _cf: *mut ngx_conf_t, parent: *mut c_void, @@ -115,7 +114,7 @@ fn impl_derive_config(input: DeriveInput) -> proc_macro2::TokenStream { } } } - }, + } syn::Data::Enum(e) => quote_spanned! { e.enum_token.span => compile_error!("Config derive: expected a struct"); @@ -125,4 +124,4 @@ fn impl_derive_config(input: DeriveInput) -> proc_macro2::TokenStream { compile_error!("Config derive: expected a struct"); }, } -} \ No newline at end of file +} diff --git a/nginx_module/Cargo.toml b/nginx_module/Cargo.toml index 63785e8..2abf2a7 100644 --- a/nginx_module/Cargo.toml +++ b/nginx_module/Cargo.toml @@ -1,22 +1,23 @@ [package] -name = "nginx_module" -version = "0.1.4" -edition = "2021" -build = "build.rs" -authors = ["Gabriel Oprisan "] -description = "Rust bindings for building Nginx modules" -homepage = "https://github.com/g-Core/nginx-rust" -repository = "https://github.com/g-Core/nginx-rust" -readme = "README.md" -license = "Apache-2.0" + authors = [ "Gabriel Oprisan " ] + build = "build.rs" + description = "Rust bindings for building Nginx modules" + edition = "2021" + homepage = "https://github.com/g-Core/nginx-rust" + license = "Apache-2.0" + name = "nginx_module" + readme = "README.md" + repository = "https://github.com/g-Core/nginx-rust" + version = "0.1.4" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [build-dependencies] -bindgen = "0.66.1" + bindgen = { version = "0.66.1" } [dependencies] -anyhow = "1.0.71" -bitflags = "2.3.1" -libc = "0.2.144" \ No newline at end of file + anyhow = { version = "1.0.71" } + bitflags = { version = "2.3.1" } + libc = { version = "0.2.144" } + url = { version = "2.5" } \ No newline at end of file diff --git a/nginx_module/build.rs b/nginx_module/build.rs index 0db0d64..f06ed8b 100644 --- a/nginx_module/build.rs +++ b/nginx_module/build.rs @@ -1,13 +1,14 @@ /* - * Copyright 2023 G-Core Innovations SARL + * Copyright 2024 G-Core Innovations SARL */ -use bindgen::callbacks::{IntKind, ParseCallbacks}; use std::{ env, path::{Path, PathBuf}, }; +use bindgen::callbacks::{IntKind, ParseCallbacks}; + const INCLUDE_SUBDIRS: &[&str] = &[ "objs/", "src/core/", diff --git a/nginx_module/src/bindings.rs b/nginx_module/src/bindings.rs index 8d599ae..742e395 100644 --- a/nginx_module/src/bindings.rs +++ b/nginx_module/src/bindings.rs @@ -1,7 +1,13 @@ /* - * Copyright 2023 G-Core Innovations SARL + * Copyright 2024 G-Core Innovations SARL */ -#![allow(non_upper_case_globals, non_snake_case, dead_code, non_camel_case_types, clippy::all)] +#![allow( + non_upper_case_globals, + non_snake_case, + dead_code, + non_camel_case_types, + clippy::all +)] -include!(concat!(env!("OUT_DIR"), "/bindings.rs")); \ No newline at end of file +include!(concat!(env!("OUT_DIR"), "/bindings.rs")); diff --git a/nginx_module/src/complex_value.rs b/nginx_module/src/complex_value.rs index b46cab2..eb4d42d 100644 --- a/nginx_module/src/complex_value.rs +++ b/nginx_module/src/complex_value.rs @@ -1,19 +1,22 @@ /* - * Copyright 2023 G-Core Innovations SARL + * Copyright 2024 G-Core Innovations SARL */ use std::{marker::PhantomData, mem::MaybeUninit}; +use super::{HttpRequest, NgxConfig, NgxStr}; use crate::{ bindings::{ - ngx_http_compile_complex_value, ngx_http_compile_complex_value_t, ngx_http_complex_value, - ngx_http_complex_value_t, ngx_palloc, NGX_OK, + ngx_http_compile_complex_value, + ngx_http_compile_complex_value_t, + ngx_http_complex_value, + ngx_http_complex_value_t, + ngx_palloc, + NGX_OK, }, ConfigValue, }; -use super::{HttpRequest, NgxConfig, NgxStr}; - #[derive(Copy, Clone)] pub struct ComplexValue<'a> { inner: *mut ngx_http_complex_value_t, diff --git a/nginx_module/src/connection.rs b/nginx_module/src/connection.rs index 88650b0..7229da9 100644 --- a/nginx_module/src/connection.rs +++ b/nginx_module/src/connection.rs @@ -1,5 +1,5 @@ /* - * Copyright 2023 G-Core Innovations SARL + * Copyright 2024 G-Core Innovations SARL */ use std::net::IpAddr; diff --git a/nginx_module/src/http_request.rs b/nginx_module/src/http_request.rs index dc09ede..fc8b4c0 100644 --- a/nginx_module/src/http_request.rs +++ b/nginx_module/src/http_request.rs @@ -1,28 +1,48 @@ /* - * Copyright 2023 G-Core Innovations SARL + * Copyright 2024 G-Core Innovations SARL */ +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] + use std::{ + collections::HashMap, marker::PhantomData, ops::{Deref, DerefMut}, }; -#[cfg(not(nginx_version_1023000))] -use crate::{ - bindings::{ngx_array_push, ngx_array_t, NGX_DECLINED, NGX_OK}, - wrappers::array_init, -}; +use anyhow::Ok; + +use super::{NgxStr, Pool}; use crate::{ bindings::{ - ngx_http_get_indexed_variable, ngx_http_parse_multi_header_lines, ngx_http_request_t, - ngx_list_push, ngx_list_t, ngx_module_t, ngx_table_elt_t, + ngx_alloc_chain_link, + ngx_buf_t, + ngx_chain_s, + ngx_http_get_indexed_variable, + ngx_http_headers_out_t, + ngx_http_output_filter, + ngx_http_parse_multi_header_lines, + ngx_http_request_s, + ngx_http_request_t, + ngx_http_send_header, + ngx_list_push, + ngx_list_t, + ngx_module_t, + ngx_pcalloc, + ngx_str_t, + ngx_table_elt_t, }, - ngx_str_t, + connection::Connection, wrappers::IndexedVar, + Log, + NGX_OK, +}; +#[cfg(not(nginx_version_1023000))] +use crate::{ + bindings::{ngx_array_push, ngx_array_t, NGX_DECLINED, NGX_ERROR, NGX_OK}, + wrappers::array_init, }; -use crate::{connection::Connection, Log}; - -use super::{NgxStr, Pool}; pub struct HttpRequestAndContext<'a, Ctx>(ngx_http_request_t, PhantomData<&'a Ctx>); @@ -57,6 +77,49 @@ impl<'a, Ctx: Default> HttpRequestAndContext<'a, Ctx> { Ok((req, ctx)) } } + + // get raw pointer to request structure + pub fn get_request_pointer(&mut self) -> *mut ngx_http_request_t { + &mut self.0 as *mut ngx_http_request_t + } + + // send prepared headers + // headers should be prepared in headers_out structure + /// # Safety + /// you have to ensure that headers_out is properly initialized + /// no checks for that are performed + pub unsafe fn send_headers(&mut self) -> anyhow::Result<()> { + anyhow::ensure!( + NGX_OK == ngx_http_send_header(self.get_request_pointer()) as u32, + "failed to send headers, ngx response" + ); + Ok(()) + } + + // request allocation of chain_link structure from nginx's pool + // returns pointer to allocated structure + // return is guaranteed to be proper + pub fn alloc_chain_link(&mut self) -> *mut ngx_chain_s { + unsafe { ngx_alloc_chain_link(self.0.pool) } + } + + // request allocation of chain_link structure from nginx's pool + // returns pointer to allocated structure + // return is guaranteed to be proper + pub fn alloc_buf(&mut self) -> *mut ngx_buf_t { + unsafe { ngx_pcalloc(self.0.pool, std::mem::size_of::()) as *mut ngx_buf_t } + } + + // request sending the prepared body + // body have to be prepared in ngx_chain_s structure + // TODO:esvi builderf for it? + // TODO:esvi any returns + /// # Safety + /// you have to ensure that chain is properly initialized + /// no checks for that are performed + pub unsafe fn send_body(&mut self, chain: *mut ngx_chain_s) { + ngx_http_output_filter(&mut self.0 as *mut ngx_http_request_s, chain); + } } impl<'a, Ctx> Deref for HttpRequestAndContext<'a, Ctx> { @@ -81,6 +144,15 @@ impl<'a> HttpRequest<'a> { } } + /// # Safety + /// access to that pointer could be safe + /// please ensure that you know what you are doing + /// check the nginx documentation for further details + pub unsafe fn get_main_config<'b, Config>(&self, module: &ngx_module_t) -> Option<&'b Config> { + let conf = (*(*self.0.main).main_conf.add(module.ctx_index)) as *const Config; + conf.as_ref() + } + pub fn is_main(&self) -> bool { std::ptr::eq(&self.0, self.0.main) } @@ -183,6 +255,12 @@ impl<'a> HttpRequest<'a> { } } + pub fn headers_out_ref(&mut self) -> &mut ngx_http_headers_out_t { + &mut self.0.headers_out + } + + // TODO:esavier its not named uri but it returns only path + // TODO:consider either helper or change results to Strings pub fn unparsed_uri(&self) -> NgxStr { unsafe { NgxStr::from_raw(self.0.unparsed_uri) } } @@ -191,6 +269,31 @@ impl<'a> HttpRequest<'a> { unsafe { NgxStr::from_raw(self.0.args) } } + pub fn uri_extension(&self) -> NgxStr { + unsafe { NgxStr::from_raw(self.0.exten) } + } + + pub fn uri_schema(&self) -> NgxStr { + unsafe { NgxStr::from_raw(self.0.schema) } + } + + pub fn request_line(&self) -> NgxStr { + unsafe { NgxStr::from_raw(self.0.request_line) } + } + + // constructs url::Url from request args + // schema and base are fake, and path is empty. + // used to get easy access to query params with validation + pub fn arg_map(&self) -> HashMap { + let args = String::from_utf8_lossy(self.uri_args().as_bytes()); + let url = url::Url::try_from(format!("data:text/plain?{}", args).as_str()).unwrap(); + let mut map: HashMap = HashMap::new(); + for (key, value) in url.query_pairs() { + map.insert(key.to_string(), value.to_string()); + } + map + } + pub fn server(&self) -> NgxStr { unsafe { NgxStr::from_raw(self.0.headers_in.server) } } @@ -279,6 +382,7 @@ impl<'a> HttpRequest<'a> { cc = slice[0]; }; } + #[cfg(nginx_version_1023000)] { cc = self.0.headers_out.cache_control; diff --git a/nginx_module/src/lib.rs b/nginx_module/src/lib.rs index 5dcd2ed..db8c8e1 100644 --- a/nginx_module/src/lib.rs +++ b/nginx_module/src/lib.rs @@ -1,5 +1,5 @@ /* - * Copyright 2023 G-Core Innovations SARL + * Copyright 2024 G-Core Innovations SARL */ mod bindings; @@ -10,15 +10,50 @@ use std::{ }; pub use bindings::{ - nginx_version, ngx_chain_t, ngx_command_t, ngx_conf_t, ngx_cycle_t, ngx_http_conf_ctx_t, - ngx_http_module_t, ngx_http_request_body_filter_pt, ngx_http_request_t, ngx_module_t, - ngx_str_t, NGX_CONF_TAKE1, NGX_DECLINED, NGX_ERROR, NGX_HTTP_FORBIDDEN, NGX_HTTP_LOC_CONF, - NGX_HTTP_MAIN_CONF, NGX_HTTP_MODULE, NGX_HTTP_SRV_CONF, NGX_HTTP_TEMPORARY_REDIRECT, - NGX_LOG_ERR, NGX_OK, NGX_RS_HTTP_LOC_CONF_OFFSET, NGX_RS_MODULE_SIGNATURE, + nginx_version, + ngx_buf_t, + ngx_chain_t, + ngx_command_t, + ngx_conf_t, + ngx_cycle_t, + ngx_http_conf_ctx_t, + ngx_http_module_t, + ngx_http_request_body_filter_pt, + ngx_http_request_t, + ngx_module_t, + ngx_str_t, + NGX_CONF_TAKE1, + NGX_ERROR, + NGX_HTTP_LOC_CONF, + NGX_HTTP_MAIN_CONF, + NGX_HTTP_MODULE, + NGX_HTTP_SRV_CONF, + NGX_LOG_ERR, + NGX_OK, + NGX_RS_HTTP_LOC_CONF_OFFSET, + NGX_RS_MODULE_SIGNATURE, }; use bindings::{ - ngx_array_push, ngx_cycle, ngx_http_core_main_conf_t, ngx_http_core_module, - ngx_http_handler_pt, ngx_http_phases_NGX_HTTP_ACCESS_PHASE, ngx_http_top_request_body_filter, + ngx_array_push, + ngx_cycle, + ngx_http_core_main_conf_t, + ngx_http_core_module, + ngx_http_handler_pt, + ngx_http_phases_NGX_HTTP_ACCESS_PHASE, + ngx_http_top_request_body_filter, +}; +// add common http return codes +pub use bindings::{ + NGX_DECLINED, + NGX_HTTP_ACCEPTED, + NGX_HTTP_BAD_REQUEST, + NGX_HTTP_FORBIDDEN, + NGX_HTTP_INTERNAL_SERVER_ERROR, + NGX_HTTP_NOT_ALLOWED, + NGX_HTTP_NOT_FOUND, + NGX_HTTP_NOT_IMPLEMENTED, + NGX_HTTP_OK, + NGX_HTTP_TEMPORARY_REDIRECT, }; mod ngx_str; diff --git a/nginx_module/src/log.rs b/nginx_module/src/log.rs index ad8e5f0..56c7772 100644 --- a/nginx_module/src/log.rs +++ b/nginx_module/src/log.rs @@ -1,5 +1,5 @@ /* - * Copyright 2023 G-Core Innovations SARL + * Copyright 2024 G-Core Innovations SARL */ use std::ffi::{CStr, CString}; @@ -9,7 +9,7 @@ use crate::{ NGX_LOG_ERR, }; -/// +/// /// # Safety /// /// `log` should be a valid ngx_log_t pointer diff --git a/nginx_module/src/md5.rs b/nginx_module/src/md5.rs index e8f5614..cc87f94 100644 --- a/nginx_module/src/md5.rs +++ b/nginx_module/src/md5.rs @@ -1,5 +1,5 @@ /* - * Copyright 2023 G-Core Innovations SARL + * Copyright 2024 G-Core Innovations SARL */ use std::mem::MaybeUninit; diff --git a/nginx_module/src/ngx_str.rs b/nginx_module/src/ngx_str.rs index 99eef3c..6f50795 100644 --- a/nginx_module/src/ngx_str.rs +++ b/nginx_module/src/ngx_str.rs @@ -1,5 +1,5 @@ /* - * Copyright 2023 G-Core Innovations SARL + * Copyright 2024 G-Core Innovations SARL */ use std::{ @@ -7,9 +7,8 @@ use std::{ ptr::{addr_of, addr_of_mut}, }; -use crate::bindings::ngx_str_t; - use super::Pool; +use crate::bindings::ngx_str_t; /// NgxStr is an abstraction over ngx_str_t. It has the same memory layout as the underlying `inner` ngx_str_t (the `lifetime` field is zero sized). /// In addition to ngx_str_t NgxStr also tracks the lifetime of the underlying byte chunk, most times this is the lifetime of the pool it was allocated from. diff --git a/nginx_module/src/pool.rs b/nginx_module/src/pool.rs index 117703b..2b3a1ec 100644 --- a/nginx_module/src/pool.rs +++ b/nginx_module/src/pool.rs @@ -1,5 +1,5 @@ /* - * Copyright 2023 G-Core Innovations SARL + * Copyright 2024 G-Core Innovations SARL */ use std::{ffi::c_void, ptr::addr_of}; diff --git a/nginx_module/src/var.rs b/nginx_module/src/var.rs index d44ae10..2414d51 100644 --- a/nginx_module/src/var.rs +++ b/nginx_module/src/var.rs @@ -1,15 +1,23 @@ /* - * Copyright 2023 G-Core Innovations SARL + * Copyright 2024 G-Core Innovations SARL */ use std::marker::PhantomData; use crate::{ bindings::{ - ngx_http_add_variable, ngx_variable_value_t, NGX_HTTP_VAR_CHANGEABLE, - NGX_HTTP_VAR_NOCACHEABLE, NGX_HTTP_VAR_NOHASH, + ngx_http_add_variable, + ngx_variable_value_t, + NGX_HTTP_VAR_CHANGEABLE, + NGX_HTTP_VAR_NOCACHEABLE, + NGX_HTTP_VAR_NOHASH, }, - ngx_http_request_t, HttpRequestAndContext, NgxConfig, NgxStr, NGX_ERROR, NGX_OK, + ngx_http_request_t, + HttpRequestAndContext, + NgxConfig, + NgxStr, + NGX_ERROR, + NGX_OK, }; pub struct Variables<'a, 'pool, Context> { @@ -48,7 +56,10 @@ impl<'a, 'pool, Context: Default + 'a> Variables<'a, 'pool, Context> { Ok(Var) } - pub fn add_changeable + 'a>(&mut self, name: NgxStr) -> anyhow::Result { + pub fn add_changeable + 'a>( + &mut self, + name: NgxStr, + ) -> anyhow::Result { unsafe { let var = ngx_http_add_variable( self.config.ptr_mut_unsafe(), diff --git a/nginx_module/src/wrappers.rs b/nginx_module/src/wrappers.rs index f8e0670..b827c41 100644 --- a/nginx_module/src/wrappers.rs +++ b/nginx_module/src/wrappers.rs @@ -1,5 +1,5 @@ /* - * Copyright 2023 G-Core Innovations SARL + * Copyright 2024 G-Core Innovations SARL */ use std::{marker::PhantomData, ptr::NonNull}; @@ -8,7 +8,9 @@ use bitflags::bitflags; use crate::{ bindings::{self, ngx_conf_t, ngx_hex_dump, ngx_http_get_variable_index, ngx_http_variable_t}, - Log, NgxStr, Pool, + Log, + NgxStr, + Pool, }; bitflags! { diff --git a/nginx_module/wrapper.h b/nginx_module/wrapper.h index 470fdd6..1f6461e 100644 --- a/nginx_module/wrapper.h +++ b/nginx_module/wrapper.h @@ -1,5 +1,5 @@ /* - * Copyright 2023 G-Core Innovations SARL + * Copyright 2024 G-Core Innovations SARL */ #include diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..f249a1c --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,5 @@ +[toolchain] + channel = "1.73" + components = [ "rustc-dev", "rustfmt" ] + profile = "minimal" + targets = [ "x86_64-unknown-linux-gnu" ]