Skip to content

Commit

Permalink
c-ares 1.30 checks dns strings
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbleby committed Jun 5, 2024
1 parent 9d78f95 commit b3a9d20
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
5 changes: 5 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,10 @@ fn main() {
if version >= 0x1_1d_00 {
println!("cargo:rustc-cfg=cares1_29");
}

println!("cargo::rustc-check-cfg=cfg(cares1_30)");
if version >= 0x1_1e_00 {
println!("cargo:rustc-cfg=cares1_30");
}
}
}
4 changes: 2 additions & 2 deletions src/caa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use itertools::Itertools;

use crate::error::{Error, Result};
use crate::panic;
use crate::utils::c_string_as_str_checked;
use crate::utils::dns_string_as_str;

/// The result of a successful CAA lookup.
#[derive(Debug)]
Expand Down Expand Up @@ -104,7 +104,7 @@ impl<'a> CAAResult<'a> {

/// The property represented by this `CAAResult`.
pub fn property(self) -> &'a str {
unsafe { c_string_as_str_checked(self.caa_reply.property.cast()) }
unsafe { dns_string_as_str(self.caa_reply.property.cast()) }
}

/// The value represented by this `CAAResult`.
Expand Down
8 changes: 4 additions & 4 deletions src/naptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use itertools::Itertools;

use crate::error::{Error, Result};
use crate::panic;
use crate::utils::{c_string_as_str_checked, hostname_as_str};
use crate::utils::{dns_string_as_str, hostname_as_str};

/// The result of a successful NAPTR lookup.
#[derive(Debug)]
Expand Down Expand Up @@ -100,17 +100,17 @@ unsafe impl<'a> Sync for NAPTRResultsIter<'a> {}
impl<'a> NAPTRResult<'a> {
/// Returns the flags in this `NAPTRResult`.
pub fn flags(self) -> &'a str {
unsafe { c_string_as_str_checked(self.naptr_reply.flags.cast()) }
unsafe { dns_string_as_str(self.naptr_reply.flags.cast()) }
}

/// Returns the service name in this `NAPTRResult`.
pub fn service_name(self) -> &'a str {
unsafe { c_string_as_str_checked(self.naptr_reply.service.cast()) }
unsafe { dns_string_as_str(self.naptr_reply.service.cast()) }
}

/// Returns the regular expression in this `NAPTRResult`.
pub fn reg_exp(self) -> &'a str {
unsafe { c_string_as_str_checked(self.naptr_reply.regexp.cast()) }
unsafe { dns_string_as_str(self.naptr_reply.regexp.cast()) }
}

/// Returns the replacement pattern in this `NAPTRResult`.
Expand Down
4 changes: 2 additions & 2 deletions src/uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use itertools::Itertools;

use crate::error::{Error, Result};
use crate::panic;
use crate::utils::c_string_as_str_checked;
use crate::utils::dns_string_as_str;

/// The result of a successful URI lookup.
#[derive(Debug)]
Expand Down Expand Up @@ -111,7 +111,7 @@ impl<'a> URIResult<'a> {

/// Returns the uri in this `URIResult`.
pub fn uri(self) -> &'a str {
unsafe { c_string_as_str_checked(self.uri_reply.uri) }
unsafe { dns_string_as_str(self.uri_reply.uri) }
}

/// Returns the time-to-live in this `URIResult`.
Expand Down
10 changes: 10 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,16 @@ pub unsafe fn hostname_as_str<'a>(hostname: *const c_char) -> &'a str {
c_string_as_str_unchecked(hostname)
}

#[cfg(not(cares1_30))]
pub unsafe fn dns_string_as_str<'a>(hostname: *const c_char) -> &'a str {
c_string_as_str_checked(hostname)
}

#[cfg(cares1_30)]
pub unsafe fn dns_string_as_str<'a>(hostname: *const c_char) -> &'a str {
c_string_as_str_unchecked(hostname)
}

/// Get the version number of the underlying `c-ares` library.
///
/// The version is returned as both a string and an integer. The integer is built up as 24bit
Expand Down

0 comments on commit b3a9d20

Please sign in to comment.