Skip to content

Commit

Permalink
Merge pull request #98 from harlanc/support_auth
Browse files Browse the repository at this point in the history
Support auth
  • Loading branch information
harlanc authored Feb 14, 2024
2 parents 1cad13a + 07166ba commit 99ddb71
Show file tree
Hide file tree
Showing 56 changed files with 922 additions and 527 deletions.
28 changes: 28 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ members = [
"library/codec/h264",
"library/logger",
"library/streamhub",
"library/common",
]
1 change: 1 addition & 0 deletions application/xiu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ tokio-metrics = { version = "0.2.0", default-features = false }

env_logger_extend = { path = "../../library/logger/" }
streamhub = { path = "../../library/streamhub/" }
commonlib = { path = "../../library/common/" }
rtmp = { path = "../../protocol/rtmp/" }
xrtsp = { path = "../../protocol/rtsp/" }
xwebrtc = { path = "../../protocol/webrtc/" }
Expand Down
33 changes: 32 additions & 1 deletion application/xiu/src/config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
enabled = true
port = 1935
gop_num = 0
[rtmp.auth]
pull_enabled = true
push_enabled = true
# simple or md5
algorithm = "simple"
# pull streams from other server node.
[rtmp.pull]
enabled = false
Expand All @@ -28,35 +33,61 @@ on_unpublish = "http://localhost:3001/on_unpuslish"
on_play = "http://localhost:3001/on_play"
on_stop = "http://localhost:3001/on_stop"

[authsecret]
# used for md5 authentication
key = ""
# used for simple authentication
password = ""


##########################
# RTSP configurations #
##########################
[rtsp]
enabled = false
port = 445
[rtsp.auth]
pull_enabled = true
push_enabled = true
# simple or md5
algorithm = "simple"

##########################
# WebRTC configurations #
##########################
[webrtc]
enabled = false
port = 8083
[webrtc.auth]
pull_enabled = true
push_enabled = true
# simple or md5
algorithm = "simple"

##########################
# HTTPFLV configurations #
##########################
[httpflv]
enabled = false
port = 8081
[httpflv.auth]
pull_enabled = true
# simple or md5
algorithm = "simple"


##########################
# HLS configurations #
##########################
[hls]
enabled = false
port = 8080
need_record = true
need_record = false
[hls.auth]
pull_enabled = true
# simple or md5
algorithm = "simple"


##########################
# LOG configurations #
Expand Down
32 changes: 28 additions & 4 deletions application/xiu/src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod errors;

use commonlib::auth::AuthAlgorithm;
use errors::ConfigError;
use serde_derive::Deserialize;
use std::fs;
Expand All @@ -14,6 +15,7 @@ pub struct Config {
pub hls: Option<HlsConfig>,
pub httpapi: Option<HttpApiConfig>,
pub httpnotify: Option<HttpNotifierConfig>,
pub authsecret: AuthSecretConfig,
pub log: Option<LogConfig>,
}

Expand All @@ -34,6 +36,7 @@ impl Config {
port: rtmp_port,
pull: None,
push: None,
auth: None,
});
}

Expand All @@ -42,6 +45,7 @@ impl Config {
rtsp_config = Some(RtspConfig {
enabled: true,
port: rtsp_port,
auth: None,
});
}

Expand All @@ -50,6 +54,7 @@ impl Config {
webrtc_config = Some(WebRTCConfig {
enabled: true,
port: webrtc_port,
auth: None,
});
}

Expand All @@ -58,6 +63,7 @@ impl Config {
httpflv_config = Some(HttpFlvConfig {
enabled: true,
port: httpflv_port,
auth: None,
});
}

Expand All @@ -67,6 +73,7 @@ impl Config {
enabled: true,
port: hls_port,
need_record: false,
auth: None,
});
}

Expand All @@ -83,6 +90,7 @@ impl Config {
hls: hls_config,
httpapi: None,
httpnotify: None,
authsecret: AuthSecretConfig::default(),
log: log_config,
}
}
Expand All @@ -95,6 +103,7 @@ pub struct RtmpConfig {
pub gop_num: Option<usize>,
pub pull: Option<RtmpPullConfig>,
pub push: Option<Vec<RtmpPushConfig>>,
pub auth: Option<AuthConfig>,
}
#[derive(Debug, Deserialize, Clone)]
pub struct RtmpPullConfig {
Expand All @@ -113,18 +122,21 @@ pub struct RtmpPushConfig {
pub struct RtspConfig {
pub enabled: bool,
pub port: usize,
pub auth: Option<AuthConfig>,
}

#[derive(Debug, Deserialize, Clone)]
pub struct WebRTCConfig {
pub enabled: bool,
pub port: usize,
pub auth: Option<AuthConfig>,
}

#[derive(Debug, Deserialize, Clone)]
pub struct HttpFlvConfig {
pub enabled: bool,
pub port: usize,
pub auth: Option<AuthConfig>,
}

#[derive(Debug, Deserialize, Clone)]
Expand All @@ -133,6 +145,7 @@ pub struct HlsConfig {
pub port: usize,
//record or not
pub need_record: bool,
pub auth: Option<AuthConfig>,
}

pub enum LogLevel {
Expand Down Expand Up @@ -170,6 +183,19 @@ pub struct HttpNotifierConfig {
pub on_stop: Option<String>,
}

#[derive(Debug, Deserialize, Clone, Default)]
pub struct AuthSecretConfig {
pub key: String,
pub password: String,
}

#[derive(Debug, Deserialize, Clone, Default)]
pub struct AuthConfig {
pub pull_enabled: bool,
pub push_enabled: Option<bool>,
pub algorithm: AuthAlgorithm,
}

pub fn load(cfg_path: &String) -> Result<Config, ConfigError> {
let content = fs::read_to_string(cfg_path)?;
let decoded_config = toml::from_str(&content[..]).unwrap();
Expand All @@ -184,15 +210,13 @@ fn test_toml_parse() {
Err(err) => println!("{}", err),
}

let str = fs::read_to_string(
"./src/config/config.toml",
);
let str = fs::read_to_string("./src/config/config.toml");

match str {
Ok(val) => {
println!("++++++{val}\n");
let decoded: Config = toml::from_str(&val[..]).unwrap();

println!("whole config: {:?}", decoded);
let rtmp = decoded.httpnotify;

if let Some(val) = rtmp {
Expand Down
Loading

0 comments on commit 99ddb71

Please sign in to comment.