summary history branches tags files
commit:1190eb6a616d7819c8d3b8f6ee380c29d96db105
author:Trevor Bentley
committer:Trevor Bentley
date:Fri Jul 12 20:00:55 2019 +0200
parents:fb5d39bc10abaeb50c521eac4c60bf09017af457
Remove 175 transitive dependencies

This commit removes *175* crate dependencies from the build by:
 * removing unused logging features from fruitbasket crate
 * replacing regex with dumb string searches
 * vendoring rustfm-scrobble, modifying to use 'curl' instead of 'reqwest'
 * vendoring rust-url just to include percent-encoding subcrate directly

Dropped from 275 to 100 crates built.  Build time and binary size both
halved as well.
diff --git a/.gitmodules b/.gitmodules
line changes: +6/-3
index 148e8e6..61011f3
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,6 +1,9 @@
 [submodule "deps/systray-rs"]
 	path = deps/systray-rs
 	url = https://github.com/mrmekon/systray-rs
-[submodule "deps/timer.rs"]
-	path = deps/timer.rs
-	url = https://github.com/mrmekon/timer.rs
+[submodule "deps/rustfm-scrobble"]
+	path = deps/rustfm-scrobble
+	url = https://github.com/mrmekon/rustfm-scrobble.git
+[submodule "deps/rust-url"]
+	path = deps/rust-url
+	url = https://github.com/servo/rust-url.git

diff --git a/Cargo.toml b/Cargo.toml
line changes: +6/-9
index 79743b7..6605a51
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -38,24 +38,21 @@ default = ["scrobble"]
 [dependencies]
 curl = "0.4.11"
 open = "1.2.1"
-regex = "1.1"
 serde = "1.0.37"
 serde_json = "1.0.13"
 serde_derive = "1.0"
-url = "1.7"
 rust-ini = "0.13"
 time = "0.1"
-#timer = {path = "deps/timer.rs", version="0.1.4"} # Modified for chrono 0.3.1
 timer = "0.2"
 chrono = "0.4"
 log = "0.4"
-log4rs = "0.8"
 ctrlc = "3.1"
 dirs = "2.0"
-rustfm-scrobble = {version="0.9.1", optional = true}
+percent-encoding = {version="1.0.2", path="deps/rust-url/percent_encoding/"}
+rustfm-scrobble = {version="0.9.2", optional = true, path = "deps/rustfm-scrobble/"}
 
 [dependencies.fruitbasket]
-version = "^0.7"
+version = "0.8"
 features = ["logging"]
 
 [target."cfg(windows)".dependencies]
@@ -65,13 +62,13 @@ systray = {path = "deps/systray-rs", version="0.1.1-connectr"}
 
 [target."cfg(windows)".dependencies.rubrail]
 default-features=false
-version = "^0.8"
+version = "0.9"
 
 [target."cfg(all(unix, not(target_os = \"macos\")))".dependencies]
 
 [target."cfg(all(unix, not(target_os = \"macos\")))".dependencies.rubrail]
 default-features = false
-version = "^0.8"
+version = "0.9"
 
 [target."cfg(target_os = \"macos\")".dependencies]
 cocoa = "0.18"
@@ -79,7 +76,7 @@ objc-foundation = "0.1"
 objc_id = "0.1"
 
 [target."cfg(target_os = \"macos\")".dependencies.rubrail]
-version = "^0.8"
+version = "0.9"
 
 [target."cfg(target_os = \"macos\")".dependencies.objc]
 version = "0.2"

diff --git a/deps/rust-url b/deps/rust-url
line changes: +1/-0
index 0000000..c1914b3
--- /dev/null
+++ b/deps/rust-url
@@ -0,0 +1 @@
+Subproject commit c1914b3a27c657eac1def4a85aa97717460c3061

diff --git a/deps/rustfm-scrobble b/deps/rustfm-scrobble
line changes: +1/-0
index 0000000..b6bf724
--- /dev/null
+++ b/deps/rustfm-scrobble
@@ -0,0 +1 @@
+Subproject commit b6bf724631a50592fa1a8967f8232808710aac78

diff --git a/deps/timer.rs b/deps/timer.rs
line changes: +0/-1
index 9052a51..0000000
--- a/deps/timer.rs
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit 9052a51a4a7d66a517926198a16d278d2cc22662

diff --git a/src/http/mod.rs b/src/http/mod.rs
line changes: +11/-14
index b500a97..b0953f4
--- a/src/http/mod.rs
+++ b/src/http/mod.rs
@@ -8,16 +8,12 @@ use std::sync::mpsc::channel;
 use std::time::Duration;
 use std::collections::BTreeMap;
 
-extern crate regex;
-use self::regex::Regex;
-
 extern crate curl;
 use self::curl::easy::{Easy, List};
 
 extern crate time;
 extern crate open;
-extern crate url;
-use self::url::percent_encoding;
+extern crate percent_encoding;
 
 use super::settings;
 
@@ -252,12 +248,11 @@ pub fn config_request_local_webserver(port: u32, form: String, reply: String) ->
             let stream = conn.unwrap().0;
             let mut reader = BufReader::new(stream);
             let mut response = Vec::<String>::new();
-            let mut post_bytes: u32 = 0;
-            let re = Regex::new(r"Content-Length: ([0-9 ]+)").unwrap();
+            let post_bytes: u32 = 0;
             for line in reader.by_ref().lines() {
                 if let Ok(line_str) = line {
-                    if re.is_match(line_str.as_str()) {
-                        post_bytes = re.captures(line_str.as_str()).unwrap()[1].parse::<u32>().unwrap();
+                    if line_str.starts_with("Content-Length: ") {
+                        line_str[16..].parse::<u32>().unwrap_or(0);
                     }
                     response.push(line_str.clone());
                     if line_str == "" {
@@ -319,14 +314,16 @@ pub fn config_request_local_webserver(port: u32, form: String, reply: String) ->
 
 fn spotify_auth_code(lines: Vec<String>) -> String {
     let mut auth_code = String::new();
+    // Looking for HTTP request header with format:
+    //   GET /?code=<MASSIVE STRING> HTTP/1.1
     for line in lines {
         let line_str = line;
-        let re = Regex::new(r"code=([^?& ]+)").unwrap();
-        let ismatch = re.is_match(line_str.as_str());
-        if ismatch {
-            let cap = re.captures(line_str.as_str()).unwrap();
-            auth_code = auth_code + &cap[1];
+        if !line_str.starts_with("GET ") {
+            continue;
         }
+        let code_idx = line_str.find("code=").unwrap_or(line_str.len() - 5) + 5;
+        let code_end_idx = line_str[code_idx..].find(|c| { c == '&' || c == '?' || c == ' '}).unwrap_or(line_str.len() - code_idx) + code_idx;
+        auth_code.push_str(&line_str[code_idx..code_end_idx]);
     }
     auth_code
 }

diff --git a/src/main.rs b/src/main.rs
line changes: +0/-1
index ad45e68..c48adc6
--- a/src/main.rs
+++ b/src/main.rs
@@ -28,7 +28,6 @@ use std::sync::RwLock;
 
 #[macro_use]
 extern crate log;
-extern crate log4rs;
 
 use std::ptr;
 use std::thread;