unauthorized(response, headers, "Basic");
return;
}
- handler(ctx, method, path, request, response);
+ handler(method, path, request, response);
}
#[allow(clippy::too_many_arguments)]
}
}
-// Data used by requests handlers, only counter is r/w.
+// Data used by requests handlers, if you add a r/w variable, make sure it's safe for concurrent access!
struct Context {
- urls: Vec<String>,
password_ch: cxx::UniquePtr<rustweb::CredentialsHolder>,
api_ch: cxx::UniquePtr<rustweb::CredentialsHolder>,
acl: cxx::UniquePtr<rustmisc::NetmaskGroup>,
// Serve a file
fn file(
- ctx: &Context,
method: &Method,
path: &str,
request: &rustweb::Request,
response: &mut rustweb::Response,
) {
- let mut uripath = path;
- if uripath == "/" {
- uripath = "/index.html";
- }
- let pos = ctx
- .urls
- .iter()
- .position(|x| String::from("/") + x == uripath);
- if pos.is_none() {
- rustmisc::log(
- request.logger,
- rustweb::Priority::Debug,
- "not found",
- &vec![
- rustmisc::KeyValue {
- key: "method".to_string(),
- value: method.to_string(),
- },
- rustmisc::KeyValue {
- key: "uripath".to_string(),
- value: uripath.to_string(),
- },
- ],
- );
- }
-
// This calls into C++
if rustweb::serveStuff(request, response).is_err() {
// Return 404 not found response.
rustmisc::log(
request.logger,
rustweb::Priority::Debug,
- "not found case 2",
+ "not found",
&vec![
rustmisc::KeyValue {
key: "method".to_string(),
value: method.to_string(),
},
rustmisc::KeyValue {
- key: "uripath".to_string(),
- value: uripath.to_string(),
+ key: "path".to_string(),
+ value: path.to_string(),
},
],
);
}
type FileFunc = fn(
- ctx: &Context,
method: &Method,
path: &str,
request: &rustweb::Request,
pub fn serveweb(
incoming: &Vec<rustweb::IncomingWSConfig>,
- urls: &[String],
password_ch: cxx::UniquePtr<rustweb::CredentialsHolder>,
api_ch: cxx::UniquePtr<rustweb::CredentialsHolder>,
acl: cxx::UniquePtr<rustmisc::NetmaskGroup>,
) -> Result<(), std::io::Error> {
// Context, atomically reference counted
let ctx = Arc::new(Context {
- urls: urls.to_vec(),
password_ch,
api_ch,
acl,
type CredentialsHolder;
#[namespace = "pdns::rust::misc"]
type NetmaskGroup = crate::misc::rustmisc::NetmaskGroup;
- //#[namespace = "pdns::rust::misc"]
- //type ComboAddress = crate::misc::rustmisc::ComboAddress;
#[namespace = "pdns::rust::misc"]
type Priority = crate::misc::rustmisc::Priority;
#[namespace = "pdns::rust::misc"]
* Functions callable from C++
*/
extern "Rust" {
- // The main entry point, This function will return, but will setup thread(s) to handle requests.
+ // The main entry point, This function will return, but will setup thread(s) and tokio runtime to handle requests.
fn serveweb(
incoming: &Vec<IncomingWSConfig>,
- urls: &[String],
pwch: UniquePtr<CredentialsHolder>,
apikeych: UniquePtr<CredentialsHolder>,
acl: UniquePtr<NetmaskGroup>,
config.emplace_back(tmp);
}
- ::rust::Vec<::rust::String> urls;
- for (const auto& [url, _] : g_urlmap) {
- urls.emplace_back(url);
- }
auto passwordString = arg()["webserver-password"];
std::unique_ptr<CredentialsHolder> password;
if (!passwordString.empty()) {
// This function returns after having created the web server object that handles the requests.
// That object and its runtime are associated with a Posix thread that waits until all tasks are
// done, which normally never happens. See rec-rust-lib/rust/src/web.rs for details
- pdns::rust::web::rec::serveweb(config, ::rust::Slice<const ::rust::String>{urls.data(), urls.size()}, std::move(password), std::move(apikey), std::move(aclPtr), std::move(logPtr), loglevel);
+ pdns::rust::web::rec::serveweb(config, std::move(password), std::move(apikey), std::move(aclPtr), std::move(logPtr), loglevel);
}
static void fromCxxToRust(const HttpResponse& cxxresp, pdns::rust::web::rec::Response& rustResponse)