aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--Cargo.lock82
-rw-r--r--Cargo.toml6
-rw-r--r--src/encoding/headermap.rs (renamed from src/headermap.rs)6
-rw-r--r--src/encoding/headers.rs (renamed from src/headers.rs)0
-rw-r--r--src/encoding/method.rs (renamed from src/method.rs)0
-rw-r--r--src/encoding/mod.rs7
-rw-r--r--src/encoding/request.rs (renamed from src/request.rs)2
-rw-r--r--src/encoding/response.rs40
-rw-r--r--src/encoding/status.rs (renamed from src/status.rs)0
-rw-r--r--src/encoding/uri.rs (renamed from src/uri.rs)0
-rw-r--r--src/lib.rs9
-rw-r--r--src/response.rs7
-rw-r--r--src/transport/client.rs0
-rw-r--r--src/transport/mod.rs1
15 files changed, 136 insertions, 27 deletions
diff --git a/.gitignore b/.gitignore
index 0c92d86..3413e08 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
/target
-/src/bin/*
+/examples/n_*
+
diff --git a/Cargo.lock b/Cargo.lock
index 53b83fc..f391134 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3,6 +3,21 @@
version = 3
[[package]]
+name = "addr2line"
+version = "0.22.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678"
+dependencies = [
+ "gimli",
+]
+
+[[package]]
+name = "adler"
+version = "1.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
+
+[[package]]
name = "aho-corasick"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -67,12 +82,33 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da"
[[package]]
+name = "backtrace"
+version = "0.3.73"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a"
+dependencies = [
+ "addr2line",
+ "cc",
+ "cfg-if",
+ "libc",
+ "miniz_oxide",
+ "object",
+ "rustc-demangle",
+]
+
+[[package]]
name = "base64"
version = "0.22.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
[[package]]
+name = "cc"
+version = "1.0.104"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "74b6a57f98764a267ff415d50a25e6e166f3831a5071af4995296ea97d210490"
+
+[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -119,6 +155,12 @@ dependencies = [
]
[[package]]
+name = "gimli"
+version = "0.29.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd"
+
+[[package]]
name = "humantime"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -149,22 +191,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
[[package]]
-name = "minimal-lexical"
-version = "0.2.1"
+name = "miniz_oxide"
+version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
+checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08"
+dependencies = [
+ "adler",
+]
[[package]]
-name = "nom"
-version = "7.1.3"
+name = "object"
+version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
+checksum = "081b846d1d56ddfc18fdf1a922e4f6e07a11768ea1b92dec44e42b72712ccfce"
dependencies = [
"memchr",
- "minimal-lexical",
]
[[package]]
+name = "pin-project-lite"
+version = "0.2.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02"
+
+[[package]]
name = "ppv-lite86"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -249,6 +299,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b"
[[package]]
+name = "rustc-demangle"
+version = "0.1.24"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f"
+
+[[package]]
name = "sip"
version = "0.1.0"
dependencies = [
@@ -256,8 +312,8 @@ dependencies = [
"base64",
"env_logger",
"log",
- "nom",
"rand",
+ "tokio",
]
[[package]]
@@ -272,6 +328,16 @@ dependencies = [
]
[[package]]
+name = "tokio"
+version = "1.38.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a"
+dependencies = [
+ "backtrace",
+ "pin-project-lite",
+]
+
+[[package]]
name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 66cf791..8e4b3ab 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -4,9 +4,11 @@ version = "0.1.0"
edition = "2021"
[dependencies]
+tokio = "1.38.0"
anyhow = "1.0.86"
log = "0.4.22"
-env_logger = "0.11.3"
-nom = "7.1.3"
rand = "0.9.0-alpha.1"
base64 = "0.22.1"
+
+[dev-dependencies]
+env_logger = "0.11.3"
diff --git a/src/headermap.rs b/src/encoding/headermap.rs
index 8712df1..313d8b5 100644
--- a/src/headermap.rs
+++ b/src/encoding/headermap.rs
@@ -1,7 +1,8 @@
-use crate::headers::Header;
+use super::headers::Header;
use anyhow::Result;
use std::fmt::Display;
+#[derive(Debug)]
pub struct HeaderMap(pub Vec<(String, String)>);
impl HeaderMap {
@@ -18,6 +19,9 @@ impl HeaderMap {
.find(|(k, _)| k == H::NAME)
.map(|(_, v)| H::from_str(v))
}
+ pub fn insert_raw(&mut self, key: String, value: String) {
+ self.0.push((key, value))
+ }
}
impl Display for HeaderMap {
diff --git a/src/headers.rs b/src/encoding/headers.rs
index d837ee5..d837ee5 100644
--- a/src/headers.rs
+++ b/src/encoding/headers.rs
diff --git a/src/method.rs b/src/encoding/method.rs
index 5f8110a..5f8110a 100644
--- a/src/method.rs
+++ b/src/encoding/method.rs
diff --git a/src/encoding/mod.rs b/src/encoding/mod.rs
new file mode 100644
index 0000000..a7dd227
--- /dev/null
+++ b/src/encoding/mod.rs
@@ -0,0 +1,7 @@
+pub mod headermap;
+pub mod headers;
+pub mod method;
+pub mod request;
+pub mod response;
+pub mod status;
+pub mod uri;
diff --git a/src/request.rs b/src/encoding/request.rs
index 827dae1..03b93c9 100644
--- a/src/request.rs
+++ b/src/encoding/request.rs
@@ -1,4 +1,4 @@
-use crate::{headermap::HeaderMap, method::Method, uri::Uri};
+use super::{headermap::HeaderMap, method::Method, uri::Uri};
use std::fmt::Display;
pub struct Request {
diff --git a/src/encoding/response.rs b/src/encoding/response.rs
new file mode 100644
index 0000000..3564b34
--- /dev/null
+++ b/src/encoding/response.rs
@@ -0,0 +1,40 @@
+use super::headermap::HeaderMap;
+use anyhow::{anyhow, bail, Context};
+use std::str::FromStr;
+
+#[derive(Debug)]
+pub struct Response {
+ pub code: u16,
+ pub headers: HeaderMap,
+}
+
+impl FromStr for Response {
+ type Err = anyhow::Error;
+ fn from_str(s: &str) -> Result<Self, Self::Err> {
+ let mut lines = s.lines();
+ let statusline = lines.next().ok_or(anyhow!("status line missing"))?;
+ let (sipver, rest) = statusline
+ .split_once(" ")
+ .ok_or(anyhow!("status line malformed"))?;
+ let (code, _status_str) = rest
+ .split_once(" ")
+ .ok_or(anyhow!("status line malformed"))?;
+ let code = u16::from_str(code).context("status code")?;
+
+ let Some(ver) = sipver.strip_prefix("SIP/") else {
+ bail!("sip version malformed");
+ };
+ if ver != "2.0" {
+ bail!("sip version {ver:?} is not supported");
+ }
+
+ let mut headers = HeaderMap::new();
+ for line in lines {
+ // TODO multiline values
+ let (key, value) = line.split_once(":").ok_or(anyhow!("header malformed"))?;
+ headers.insert_raw(key.trim().to_string(), value.trim().to_string())
+ }
+
+ Ok(Self { code, headers })
+ }
+}
diff --git a/src/status.rs b/src/encoding/status.rs
index de9ea88..de9ea88 100644
--- a/src/status.rs
+++ b/src/encoding/status.rs
diff --git a/src/uri.rs b/src/encoding/uri.rs
index 2d77df2..2d77df2 100644
--- a/src/uri.rs
+++ b/src/encoding/uri.rs
diff --git a/src/lib.rs b/src/lib.rs
index a7dd227..d9935d3 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,7 +1,2 @@
-pub mod headermap;
-pub mod headers;
-pub mod method;
-pub mod request;
-pub mod response;
-pub mod status;
-pub mod uri;
+pub mod encoding;
+pub mod transport;
diff --git a/src/response.rs b/src/response.rs
deleted file mode 100644
index 4403c6e..0000000
--- a/src/response.rs
+++ /dev/null
@@ -1,7 +0,0 @@
-use crate::headermap::HeaderMap;
-
-
-pub struct Reponse {
- pub code: u16,
- pub headers: HeaderMap,
-}
diff --git a/src/transport/client.rs b/src/transport/client.rs
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/transport/client.rs
diff --git a/src/transport/mod.rs b/src/transport/mod.rs
new file mode 100644
index 0000000..b9babe5
--- /dev/null
+++ b/src/transport/mod.rs
@@ -0,0 +1 @@
+pub mod client;