From 7f66c29e5c7103f9fd5f1fe672b5f7cbef92cd5e Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Sat, 3 Aug 2019 16:44:31 +0200 Subject: [PATCH] remove src/tools/common_regex.rs, use proxmox::tools::common_regex instead --- src/api2/node/dns.rs | 2 ++ src/api2/node/syslog.rs | 2 +- src/api2/types.rs | 4 ++-- src/tools.rs | 2 -- src/tools/common_regex.rs | 47 --------------------------------------- 5 files changed, 5 insertions(+), 52 deletions(-) delete mode 100644 src/tools/common_regex.rs diff --git a/src/api2/node/dns.rs b/src/api2/node/dns.rs index 5f24da2b..af8ec643 100644 --- a/src/api2/node/dns.rs +++ b/src/api2/node/dns.rs @@ -1,6 +1,8 @@ use failure::*; use proxmox::tools::fs::{file_get_contents, file_set_contents}; +use proxmox::tools::*; // required to use IPRE!() macro ??? + use crate::api2::*; use crate::api_schema::*; //use crate::api_schema::router::*; diff --git a/src/api2/node/syslog.rs b/src/api2/node/syslog.rs index 128b94a9..0940a30f 100644 --- a/src/api2/node/syslog.rs +++ b/src/api2/node/syslog.rs @@ -8,7 +8,7 @@ use serde_json::{json, Value}; use std::sync::Arc; use lazy_static::lazy_static; -use crate::tools::common_regex; +use proxmox::tools::common_regex; use std::process::{Command, Stdio}; fn dump_journal( diff --git a/src/api2/types.rs b/src/api2/types.rs index da8cd61b..89a97202 100644 --- a/src/api2/types.rs +++ b/src/api2/types.rs @@ -3,7 +3,7 @@ use lazy_static::lazy_static; use std::sync::Arc; use crate::api_schema::*; -use crate::tools::{self, common_regex}; +use proxmox::tools::common_regex; lazy_static!{ @@ -38,7 +38,7 @@ lazy_static!{ StringSchema::new("Node name (or 'localhost')") .format( Arc::new(ApiStringFormat::VerifyFn(|node| { - if node == "localhost" || node == tools::nodename() { + if node == "localhost" || node == crate::tools::nodename() { Ok(()) } else { bail!("no such node '{}'", node); diff --git a/src/tools.rs b/src/tools.rs index fcd11e31..533417ac 100644 --- a/src/tools.rs +++ b/src/tools.rs @@ -22,8 +22,6 @@ use proxmox::tools::vec; pub mod async_mutex; pub mod timer; pub mod wrapped_reader_stream; -#[macro_use] -pub mod common_regex; pub mod ticket; pub mod borrow; pub mod fs; diff --git a/src/tools/common_regex.rs b/src/tools/common_regex.rs deleted file mode 100644 index fcf43653..00000000 --- a/src/tools/common_regex.rs +++ /dev/null @@ -1,47 +0,0 @@ -//! Predefined Regular Expressions -//! -//! This is a collection of useful regular expressions - -use lazy_static::lazy_static; -use regex::Regex; - -#[macro_export] -macro_rules! IPV4OCTET { () => (r"(?:25[0-5]|(?:2[0-4]|1[0-9]|[1-9])?[0-9])") } -#[macro_export] -macro_rules! IPV6H16 { () => (r"(?:[0-9a-fA-F]{1,4})") } -#[macro_export] -macro_rules! IPV6LS32 { () => (concat!(r"(?:(?:", IPV4RE!(), "|", IPV6H16!(), ":", IPV6H16!(), "))" )) } - -/// Returns the regular expression string to match IPv4 addresses -#[macro_export] -macro_rules! IPV4RE { () => (concat!(r"(?:(?:", IPV4OCTET!(), r"\.){3}", IPV4OCTET!(), ")")) } - -/// Returns the regular expression string to match IPv6 addresses -#[macro_export] -macro_rules! IPV6RE { () => (concat!(r"(?:", - r"(?:(?:", r"(?:", IPV6H16!(), r":){6})", IPV6LS32!(), r")|", - r"(?:(?:", r"::(?:", IPV6H16!(), r":){5})", IPV6LS32!(), r")|", - r"(?:(?:(?:", IPV6H16!(), r")?::(?:", IPV6H16!(), r":){4})", IPV6LS32!(), r")|", - r"(?:(?:(?:(?:", IPV6H16!(), r":){0,1}", IPV6H16!(), r")?::(?:", IPV6H16!(), r":){3})", IPV6LS32!(), r")|", - r"(?:(?:(?:(?:", IPV6H16!(), r":){0,2}", IPV6H16!(), r")?::(?:", IPV6H16!(), r":){2})", IPV6LS32!(), r")|", - r"(?:(?:(?:(?:", IPV6H16!(), r":){0,3}", IPV6H16!(), r")?::(?:", IPV6H16!(), r":){1})", IPV6LS32!(), r")|", - r"(?:(?:(?:(?:", IPV6H16!(), r":){0,4}", IPV6H16!(), r")?::", ")", IPV6LS32!(), r")|", - r"(?:(?:(?:(?:", IPV6H16!(), r":){0,5}", IPV6H16!(), r")?::", ")", IPV6H16!(), r")|", - r"(?:(?:(?:(?:", IPV6H16!(), r":){0,6}", IPV6H16!(), r")?::", ")))")) -} - -/// Returns the regular expression string to match IP addresses (v4 or v6) -#[macro_export] -macro_rules! IPRE { () => (concat!(r"(?:", IPV4RE!(), "|", IPV6RE!(), ")")) } - -lazy_static! { - pub static ref IP_REGEX: Regex = Regex::new(IPRE!()).unwrap(); - - pub static ref SHA256_HEX_REGEX: Regex = - Regex::new(r"^[a-f0-9]{64}$") - .unwrap(); - - pub static ref SYSTEMD_DATETIME_REGEX: Regex = - Regex::new(r"^\d{4}-\d{2}-\d{2}( \d{2}:\d{2}(:\d{2})?)?$") - .unwrap(); -}