mirror of
https://github.com/house-of-vanity/v2-uri-parser.git
synced 2025-12-16 06:57:52 +00:00
Cargo format
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
use clap::{value_parser, Arg, Command};
|
use clap::{Arg, Command, value_parser};
|
||||||
pub mod config_models;
|
pub mod config_models;
|
||||||
mod parser;
|
mod parser;
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
@@ -54,7 +54,10 @@ async fn main() {
|
|||||||
let httpport = matches.get_one::<u16>("httpport").copied();
|
let httpport = matches.get_one::<u16>("httpport").copied();
|
||||||
let get_metadata = matches.get_flag("get_metadata");
|
let get_metadata = matches.get_flag("get_metadata");
|
||||||
let run_mode = matches.get_flag("run");
|
let run_mode = matches.get_flag("run");
|
||||||
let xray_binary = matches.get_one::<String>("xray_binary").map(|s| s.as_str()).unwrap_or("xray-core");
|
let xray_binary = matches
|
||||||
|
.get_one::<String>("xray_binary")
|
||||||
|
.map(|s| s.as_str())
|
||||||
|
.unwrap_or("xray-core");
|
||||||
|
|
||||||
if get_metadata {
|
if get_metadata {
|
||||||
print!("{}", parser::get_metadata(uri));
|
print!("{}", parser::get_metadata(uri));
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use crate::{
|
|||||||
parser::shadow_socks::models,
|
parser::shadow_socks::models,
|
||||||
utils::{url_decode, url_decode_str},
|
utils::{url_decode, url_decode_str},
|
||||||
};
|
};
|
||||||
use base64::{engine::general_purpose, Engine};
|
use base64::{Engine, engine::general_purpose};
|
||||||
|
|
||||||
pub fn get_data(uri: &str) -> RawData {
|
pub fn get_data(uri: &str) -> RawData {
|
||||||
let data = uri.split_once("ss://").unwrap().1;
|
let data = uri.split_once("ss://").unwrap().1;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use crate::{
|
|||||||
parser::socks::models,
|
parser::socks::models,
|
||||||
utils::{url_decode, url_decode_str},
|
utils::{url_decode, url_decode_str},
|
||||||
};
|
};
|
||||||
use base64::{engine::general_purpose, Engine};
|
use base64::{Engine, engine::general_purpose};
|
||||||
|
|
||||||
pub fn get_data(uri: &str) -> RawData {
|
pub fn get_data(uri: &str) -> RawData {
|
||||||
let data = uri.split_once("://").unwrap().1;
|
let data = uri.split_once("://").unwrap().1;
|
||||||
|
|||||||
@@ -34,7 +34,9 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
#[test]
|
#[test]
|
||||||
fn return_none_for_invalid_uri() {
|
fn return_none_for_invalid_uri() {
|
||||||
let protocol = get_uri_protocol("123-vless://3d1c3f04-729d-59d3-bdb6-3f3f4352e173@root.ii.one:2083?security=reality&sni=www.spamhaus.org&fp=safari&pbk=7xhH4b_VkliBxGulljcyPOH-bYUA2dl-XAdZAsfhk04&sid=6ba85179e30d4fc2&type=tcp&flow=xtls-rprx-vision#Ha-ac");
|
let protocol = get_uri_protocol(
|
||||||
|
"123-vless://3d1c3f04-729d-59d3-bdb6-3f3f4352e173@root.ii.one:2083?security=reality&sni=www.spamhaus.org&fp=safari&pbk=7xhH4b_VkliBxGulljcyPOH-bYUA2dl-XAdZAsfhk04&sid=6ba85179e30d4fc2&type=tcp&flow=xtls-rprx-vision#Ha-ac",
|
||||||
|
);
|
||||||
assert!(matches!(protocol, None));
|
assert!(matches!(protocol, None));
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ pub fn get_data(uri: &str) -> RawData {
|
|||||||
extra: url_decode(get_parameter_value(&query, "extra")),
|
extra: url_decode(get_parameter_value(&query, "extra")),
|
||||||
allowInsecure: get_parameter_value(&query, "allowInsecure"),
|
allowInsecure: get_parameter_value(&query, "allowInsecure"),
|
||||||
server_method: None,
|
server_method: None,
|
||||||
username:None,
|
username: None,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use crate::config_models::RawData;
|
use crate::config_models::RawData;
|
||||||
use crate::parser::vmess::models::VmessAddress;
|
use crate::parser::vmess::models::VmessAddress;
|
||||||
use crate::utils::{get_parameter_value, url_decode, url_decode_str};
|
use crate::utils::{get_parameter_value, url_decode, url_decode_str};
|
||||||
use base64::{engine::general_purpose, Engine};
|
use base64::{Engine, engine::general_purpose};
|
||||||
use http::Uri;
|
use http::Uri;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::process::Stdio;
|
|
||||||
use tokio::process::{Child, Command};
|
|
||||||
use tempfile::NamedTempFile;
|
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
use std::process::Stdio;
|
||||||
|
use tempfile::NamedTempFile;
|
||||||
|
use tokio::process::{Child, Command};
|
||||||
|
|
||||||
pub struct XrayRunner {
|
pub struct XrayRunner {
|
||||||
process: Option<Child>,
|
process: Option<Child>,
|
||||||
@@ -16,7 +16,11 @@ impl XrayRunner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn start(&mut self, config_json: &str, xray_binary: &str) -> Result<(), Box<dyn std::error::Error>> {
|
pub async fn start(
|
||||||
|
&mut self,
|
||||||
|
config_json: &str,
|
||||||
|
xray_binary: &str,
|
||||||
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
// Create temporary config file with .json extension
|
// Create temporary config file with .json extension
|
||||||
let mut temp_file = NamedTempFile::with_suffix(".json")?;
|
let mut temp_file = NamedTempFile::with_suffix(".json")?;
|
||||||
temp_file.write_all(config_json.as_bytes())?;
|
temp_file.write_all(config_json.as_bytes())?;
|
||||||
@@ -27,10 +31,10 @@ impl XrayRunner {
|
|||||||
// Start xray-core process
|
// Start xray-core process
|
||||||
let mut cmd = Command::new(xray_binary);
|
let mut cmd = Command::new(xray_binary);
|
||||||
cmd.arg("-config")
|
cmd.arg("-config")
|
||||||
.arg(&config_path)
|
.arg(&config_path)
|
||||||
.stdin(Stdio::null())
|
.stdin(Stdio::null())
|
||||||
.stdout(Stdio::inherit())
|
.stdout(Stdio::inherit())
|
||||||
.stderr(Stdio::inherit());
|
.stderr(Stdio::inherit());
|
||||||
|
|
||||||
let child = cmd.spawn()?;
|
let child = cmd.spawn()?;
|
||||||
|
|
||||||
@@ -89,9 +93,9 @@ impl Drop for XrayRunner {
|
|||||||
pub async fn wait_for_shutdown_signal() {
|
pub async fn wait_for_shutdown_signal() {
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
{
|
{
|
||||||
|
use futures::stream::StreamExt;
|
||||||
use signal_hook::consts::signal::*;
|
use signal_hook::consts::signal::*;
|
||||||
use signal_hook_tokio::Signals;
|
use signal_hook_tokio::Signals;
|
||||||
use futures::stream::StreamExt;
|
|
||||||
|
|
||||||
let mut signals = Signals::new(&[SIGINT, SIGTERM]).expect("Failed to create signals");
|
let mut signals = Signals::new(&[SIGINT, SIGTERM]).expect("Failed to create signals");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user