diff --git a/Cargo.lock b/Cargo.lock index ad69b18..0489068 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -56,7 +56,7 @@ version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" dependencies = [ - "windows-sys", + "windows-sys 0.61.2", ] [[package]] @@ -67,7 +67,7 @@ checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" dependencies = [ "anstyle", "once_cell_polyfill", - "windows-sys", + "windows-sys 0.61.2", ] [[package]] @@ -140,6 +140,12 @@ dependencies = [ "tracing", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + [[package]] name = "bitflags" version = "2.11.1" @@ -174,6 +180,12 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + [[package]] name = "chrono" version = "0.4.44" @@ -240,6 +252,26 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "encoding_rs" +version = "0.8.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" +dependencies = [ + "cfg-if", +] + [[package]] name = "equivalent" version = "1.0.2" @@ -253,7 +285,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.61.2", ] [[package]] @@ -262,6 +294,12 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + [[package]] name = "foldhash" version = "0.1.5" @@ -292,6 +330,12 @@ version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" +[[package]] +name = "futures-sink" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c39754e157331b013978ec91992bde1ac089843443c49cbc7f46150b0fad0893" + [[package]] name = "futures-task" version = "0.3.32" @@ -310,6 +354,33 @@ dependencies = [ "slab", ] +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi", + "wasm-bindgen", +] + +[[package]] +name = "getrandom" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "r-efi 5.3.0", + "wasip2", + "wasm-bindgen", +] + [[package]] name = "getrandom" version = "0.4.2" @@ -318,11 +389,30 @@ checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555" dependencies = [ "cfg-if", "libc", - "r-efi", + "r-efi 6.0.0", "wasip2", "wasip3", ] +[[package]] +name = "h2" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f44da3a8150a6703ed5d34e164b875fd14c2cdab9af1252a9a1020bde2bdc54" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + [[package]] name = "hashbrown" version = "0.15.5" @@ -399,6 +489,7 @@ dependencies = [ "bytes", "futures-channel", "futures-core", + "h2", "http", "http-body", "httparse", @@ -407,6 +498,23 @@ dependencies = [ "pin-project-lite", "smallvec", "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2b52f86d1d4bc0d6b4e6826d960b1b333217e07d36b882dca570a5e1c48895b" +dependencies = [ + "http", + "hyper", + "hyper-util", + "rustls", + "tokio", + "tokio-rustls", + "tower-service", + "webpki-roots", ] [[package]] @@ -415,13 +523,21 @@ version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0" dependencies = [ + "base64", "bytes", + "futures-channel", + "futures-util", "http", "http-body", "hyper", + "ipnet", + "libc", + "percent-encoding", "pin-project-lite", + "socket2", "tokio", "tower-service", + "tracing", ] [[package]] @@ -448,12 +564,115 @@ dependencies = [ "cc", ] +[[package]] +name = "icu_collections" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2984d1cd16c883d7935b9e07e44071dca8d917fd52ecc02c04d5fa0b5a3f191c" +dependencies = [ + "displaydoc", + "potential_utf", + "utf8_iter", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92219b62b3e2b4d88ac5119f8904c10f8f61bf7e95b640d25ba3075e6cac2c29" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c56e5ee99d6e3d33bd91c5d85458b6005a22140021cc324cea84dd0e72cff3b4" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da3be0ae77ea334f4da67c12f149704f19f81d1adf7c51cf482943e84a2bad38" + +[[package]] +name = "icu_properties" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bee3b67d0ea5c2cca5003417989af8996f8604e34fb9ddf96208a033901e70de" +dependencies = [ + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e2bbb201e0c04f7b4b3e14382af113e17ba4f63e2c9d2ee626b720cbce54a14" + +[[package]] +name = "icu_provider" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "139c4cf31c8b5f33d7e199446eff9c1e02decfc2f0eec2c8d71f65befa45b421" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + [[package]] name = "id-arena" version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + [[package]] name = "indexmap" version = "2.14.0" @@ -466,6 +685,22 @@ dependencies = [ "serde_core", ] +[[package]] +name = "ipnet" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d98f6fed1fde3f8c21bc40a1abb88dd75e67924f9cffc3ef95607bad8017f8e2" + +[[package]] +name = "iri-string" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25e659a4bb38e810ebc252e53b5814ff908a8c58c2a9ce2fae1bbec24cbf4e20" +dependencies = [ + "memchr", + "serde", +] + [[package]] name = "is_terminal_polyfill" version = "1.70.2" @@ -484,6 +719,8 @@ version = "0.3.95" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2964e92d1d9dc3364cae4d718d93f227e3abb088e747d92e0395bfdedf1c12ca" dependencies = [ + "cfg-if", + "futures-util", "once_cell", "wasm-bindgen", ] @@ -506,6 +743,12 @@ version = "0.2.185" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "52ff2c0fe9bc6cb6b14a0592c2ff4fa9ceb83eea9db979b0487cd054946a2b8f" +[[package]] +name = "litemap" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92daf443525c4cce67b150400bc2316076100ce0b3686209eb8cf3c31612e6f0" + [[package]] name = "lock_api" version = "0.4.14" @@ -521,6 +764,12 @@ version = "0.4.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" +[[package]] +name = "lru-slab" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154" + [[package]] name = "matchers" version = "0.2.0" @@ -548,6 +797,16 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" +[[package]] +name = "mime_guess" +version = "2.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e" +dependencies = [ + "mime", + "unicase", +] + [[package]] name = "mio" version = "1.2.0" @@ -556,7 +815,7 @@ checksum = "50b7e5b27aa02a74bac8c3f23f448f8d87ff11f92d3aac1a6ed369ee08cc56c1" dependencies = [ "libc", "wasi", - "windows-sys", + "windows-sys 0.61.2", ] [[package]] @@ -565,7 +824,7 @@ version = "0.50.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" dependencies = [ - "windows-sys", + "windows-sys 0.61.2", ] [[package]] @@ -624,6 +883,24 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" +[[package]] +name = "potential_utf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0103b1cef7ec0cf76490e969665504990193874ea05c85ff9bab8b911d0a0564" +dependencies = [ + "zerovec", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + [[package]] name = "prettyplease" version = "0.2.37" @@ -643,6 +920,61 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e20a958963c291dc322d98411f541009df2ced7b5a4f2bd52337638cfccf20" +dependencies = [ + "bytes", + "cfg_aliases", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-proto" +version = "0.11.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "434b42fec591c96ef50e21e886936e66d3cc3f737104fdb9b737c40ffb94c098" +dependencies = [ + "bytes", + "getrandom 0.3.4", + "lru-slab", + "rand", + "ring", + "rustc-hash", + "rustls", + "rustls-pki-types", + "slab", + "thiserror", + "tinyvec", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-udp" +version = "0.5.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "addec6a0dcad8a8d96a771f815f0eaf55f9d1805756410b39f5fa81332574cbd" +dependencies = [ + "cfg_aliases", + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.60.2", +] + [[package]] name = "quote" version = "1.0.45" @@ -652,12 +984,47 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "r-efi" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" + [[package]] name = "r-efi" version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" +[[package]] +name = "rand" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c5af06bb1b7d3216d91932aed5265164bf384dc89cd6ba05cf59a35f5f76ea" +dependencies = [ + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c" +dependencies = [ + "getrandom 0.3.4", +] + [[package]] name = "redox_syscall" version = "0.5.18" @@ -684,6 +1051,110 @@ version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a" +[[package]] +name = "reqwest" +version = "0.12.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eddd3ca559203180a307f12d114c268abf583f59b03cb906fd0b3ff8646c1147" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-util", + "js-sys", + "log", + "mime", + "mime_guess", + "percent-encoding", + "pin-project-lite", + "quinn", + "rustls", + "rustls-pki-types", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tokio-rustls", + "tower", + "tower-http", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "webpki-roots", +] + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.17", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "roxmltree" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c20b6793b5c2fa6553b250154b78d6d0db37e72700ae35fad9387a46f487c97" + +[[package]] +name = "rustc-hash" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94300abf3f1ae2e2b8ffb7b58043de3d399c73fa6f4b73826402a5c457614dbe" + +[[package]] +name = "rustls" +version = "0.23.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69f9466fb2c14ea04357e91413efb882e2a6d4a406e625449bc0a5d360d53a21" +dependencies = [ + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pki-types" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be040f8b0a225e40375822a563fa9524378b9d63112f53e19ffff34df5d33fdd" +dependencies = [ + "web-time", + "zeroize", +] + +[[package]] +name = "rustls-webpki" +version = "0.103.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8279bb85272c9f10811ae6a6c547ff594d6a7f3c6c6b02ee9726d1d0dcfcdd06" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + [[package]] name = "rustversion" version = "1.0.22" @@ -827,15 +1298,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3a766e1110788c36f4fa1c2b71b387a7815aa65f88ce0229841826633d93723e" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.61.2", ] +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + [[package]] name = "strsim" version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + [[package]] name = "syn" version = "2.0.117" @@ -852,6 +1335,20 @@ name = "sync_wrapper" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" +dependencies = [ + "futures-core", +] + +[[package]] +name = "synstructure" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] name = "thiserror" @@ -882,6 +1379,31 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "tinystr" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8323304221c2a851516f22236c5722a72eaa19749016521d6dff0824447d96d" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tinyvec" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e61e67053d25a4e82c844e8424039d9745781b3fc4f32b8d55ed50f5f667ef3" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + [[package]] name = "tokio" version = "1.51.1" @@ -896,7 +1418,7 @@ dependencies = [ "signal-hook-registry", "socket2", "tokio-macros", - "windows-sys", + "windows-sys 0.61.2", ] [[package]] @@ -910,6 +1432,29 @@ dependencies = [ "syn", ] +[[package]] +name = "tokio-rustls" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1729aa945f29d91ba541258c8df89027d5792d85a8841fb65e8bf0f4ede4ef61" +dependencies = [ + "rustls", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ae9cec805b01e8fc3fd2fe289f89149a9b66dd16786abd8b19cfa7b48cb0098" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + [[package]] name = "toml" version = "0.8.23" @@ -967,6 +1512,24 @@ dependencies = [ "tracing", ] +[[package]] +name = "tower-http" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4e6559d53cc268e5031cd8429d05415bc4cb4aefc4aa5d6cc35fbf5b924a1f8" +dependencies = [ + "bitflags", + "bytes", + "futures-util", + "http", + "http-body", + "iri-string", + "pin-project-lite", + "tower", + "tower-layer", + "tower-service", +] + [[package]] name = "tower-layer" version = "0.3.3" @@ -1041,6 +1604,12 @@ dependencies = [ "tracing-log", ] +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + [[package]] name = "tvctl" version = "0.1.0" @@ -1049,6 +1618,8 @@ dependencies = [ "axum", "chrono", "clap", + "reqwest", + "roxmltree", "serde", "serde_json", "thiserror", @@ -1056,9 +1627,16 @@ dependencies = [ "toml", "tracing", "tracing-subscriber", + "urlencoding", "uuid", ] +[[package]] +name = "unicase" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbc4bc3a9f746d862c45cb89d705aa10f187bb96c76001afab07a0d35ce60142" + [[package]] name = "unicode-ident" version = "1.0.24" @@ -1071,6 +1649,36 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "urlencoding" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + [[package]] name = "utf8parse" version = "0.2.2" @@ -1083,7 +1691,7 @@ version = "1.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5ac8b6f42ead25368cf5b098aeb3dc8a1a2c05a3eee8a9a1a68c640edbfc79d9" dependencies = [ - "getrandom", + "getrandom 0.4.2", "js-sys", "serde_core", "wasm-bindgen", @@ -1095,6 +1703,15 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + [[package]] name = "wasi" version = "0.11.1+wasi-snapshot-preview1" @@ -1132,6 +1749,16 @@ dependencies = [ "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f371d383f2fb139252e0bfac3b81b265689bf45b6874af544ffa4c975ac1ebf8" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "wasm-bindgen-macro" version = "0.2.118" @@ -1198,6 +1825,35 @@ dependencies = [ "semver", ] +[[package]] +name = "web-sys" +version = "0.3.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f2dfbb17949fa2088e5d39408c48368947b86f7834484e87b73de55bc14d97d" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki-roots" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22cfaf3c063993ff62e73cb4311efde4db1efb31ab78a3e5c457939ad5cc0bed" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-core" version = "0.62.2" @@ -1257,6 +1913,24 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets 0.53.5", +] + [[package]] name = "windows-sys" version = "0.61.2" @@ -1266,6 +1940,135 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm 0.52.6", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.53.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" +dependencies = [ + "windows-link", + "windows_aarch64_gnullvm 0.53.1", + "windows_aarch64_msvc 0.53.1", + "windows_i686_gnu 0.53.1", + "windows_i686_gnullvm 0.53.1", + "windows_i686_msvc 0.53.1", + "windows_x86_64_gnu 0.53.1", + "windows_x86_64_gnullvm 0.53.1", + "windows_x86_64_msvc 0.53.1", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_i686_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" + [[package]] name = "winnow" version = "0.7.15" @@ -1363,6 +2166,115 @@ dependencies = [ "wasmparser", ] +[[package]] +name = "writeable" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ffae5123b2d3fc086436f8834ae3ab053a283cfac8fe0a0b8eaae044768a4c4" + +[[package]] +name = "yoke" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abe8c5fda708d9ca3df187cae8bfb9ceda00dd96231bed36e445a1a48e66f9ca" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de844c262c8848816172cef550288e7dc6c7b7814b4ee56b3e1553f275f1858e" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zerocopy" +version = "0.8.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eed437bf9d6692032087e337407a86f04cd8d6a16a37199ed57949d415bd68e9" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70e3cd084b1788766f53af483dd21f93881ff30d7320490ec3ef7526d203bad4" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zerofrom" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69faa1f2a1ea75661980b013019ed6687ed0e83d069bc1114e2cc74c6c04c4df" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11532158c46691caf0f2593ea8358fed6bbf68a0315e80aae9bd41fbade684a1" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" + +[[package]] +name = "zerotrie" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f9152d31db0792fa83f70fb2f83148effb5c1f5b8c7686c3459e361d9bc20bf" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90f911cbc359ab6af17377d242225f4d75119aec87ea711a880987b18cd7b239" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "625dc425cab0dca6dc3c3319506e6593dcb08a9f387ea3b284dbd52a92c40555" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "zmij" version = "1.0.21" diff --git a/Cargo.toml b/Cargo.toml index ec6b7f7..ea627d2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,8 @@ anyhow = "1.0" axum = "0.8" chrono = { version = "0.4", features = ["serde"] } clap = { version = "4.5", features = ["derive"] } +reqwest = { version = "0.12", default-features = false, features = ["charset", "http2", "json", "multipart", "rustls-tls"] } +roxmltree = "0.20" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" thiserror = "2.0" @@ -15,4 +17,5 @@ tokio = { version = "1.0", features = ["full"] } toml = "0.8" tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter", "fmt"] } +urlencoding = "2.1" uuid = { version = "1.0", features = ["serde", "v4"] } diff --git a/PROJECT_MAP.md b/PROJECT_MAP.md index 58629a8..67ffa86 100644 --- a/PROJECT_MAP.md +++ b/PROJECT_MAP.md @@ -19,7 +19,7 @@ script and control smart TVs through a stable, brand-agnostic API. ## Project Status -**Phase:** Milestone 1 scaffolded. Foundation compiles; runtime logic not started. +**Phase:** Milestone 2 in progress. Core Roku ECP support exists; daemon and CLI wiring are still pending. **Platform v1:** Roku only (via ECP HTTP API) **Language:** Rust **Crate type:** Binary (single binary distribution target) @@ -56,7 +56,7 @@ tvctl/ │ │ └── mod.rs │ └── adapters/ ← Platform adapters and shared types │ ├── mod.rs ← Adapter trait definition and core data shapes -│ └── roku/ ← Roku ECP adapter scaffold +│ └── roku/ ← Roku ECP adapter implementation │ └── mod.rs └── cache/ ← Runtime cache (gitignored) ``` @@ -332,11 +332,10 @@ enabled = true ## What Has NOT Been Started -- Roku ECP transport and device discovery logic - Daemon runtime, socket transport, and persistence logic - HTTP route handlers and request validation - Real CLI command handling beyond skeleton parsing -- Any tests +- Integration and hardware validation coverage - CI/CD configuration - Release/packaging diff --git a/ROADMAP.md b/ROADMAP.md index c3f1e87..979df65 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -14,7 +14,7 @@ Foundation scaffold is complete. Begin platform implementation work. ## In Progress -_Nothing in progress yet._ +- Roku adapter `dev_install()` and `dev_logs()` need developer-web credential handling plus real-device validation --- @@ -28,18 +28,18 @@ _Completed 2026-04-14. See Completed below._ ## Milestone 2 — Roku Adapter _Goal: Can communicate with a real Roku TV over ECP._ -- [ ] Implement Roku ECP adapter in `src/adapters/roku/` -- [ ] `discover()` — SSDP scan returning Roku devices -- [ ] `list_apps()` — fetch installed channel list via ECP -- [ ] `launch()` — launch app by ECP channel ID -- [ ] `stop_app()` — exit current app -- [ ] `key()` — send ECP keypress -- [ ] `sequence()` — send multiple keypresses -- [ ] `state()` — query power state and active app +- [x] 2026-04-14 — Implement core Roku ECP adapter in `src/adapters/roku/` +- [x] 2026-04-14 — `discover()` — SSDP scan returning Roku devices +- [x] 2026-04-14 — `list_apps()` — fetch installed channel list via ECP +- [x] 2026-04-14 — `launch()` — launch app by ECP channel ID +- [x] 2026-04-14 — `stop_app()` — exit current app +- [x] 2026-04-14 — `key()` — send ECP keypress +- [x] 2026-04-14 — `sequence()` — send multiple keypresses +- [x] 2026-04-14 — `state()` — query power state and active app - [ ] `dev_install()` — zip upload via ECP dev mode -- [ ] `dev_reload()` — reload sideloaded app +- [x] 2026-04-14 — `dev_reload()` — reload the sideloaded app via `launch/dev` - [ ] `dev_logs()` — fetch dev logs -- [ ] Key translation table (TvKey → Roku ECP key string) +- [x] 2026-04-14 — Key translation table (TvKey → Roku ECP key string) - [ ] Manual integration test against real Roku device --- @@ -155,6 +155,7 @@ out of scope until Milestone 6 is complete and stable. - [x] 2026-04-14 — Create module skeleton and placeholder docs layout - [x] 2026-04-14 — Define the adapter contract and core shared data types - [x] 2026-04-14 — Compile the project cleanly with `cargo build` +- [x] 2026-04-14 — Add Roku ECP discovery, input, app, and state adapter support with unit tests --- diff --git a/src/adapters/roku/mod.rs b/src/adapters/roku/mod.rs index 5d34815..2cf244f 100644 --- a/src/adapters/roku/mod.rs +++ b/src/adapters/roku/mod.rs @@ -1,42 +1,535 @@ -use super::{AppInfo, Device, DeviceInfo, DeviceState, Result, TvAdapter, TvError, TvKey}; +use std::{ + collections::{BTreeMap, BTreeSet}, + net::IpAddr, + time::Duration, +}; -/// The Roku ECP adapter placeholder for the foundation milestone. -#[derive(Debug, Clone, Default)] -pub struct RokuAdapter; +use chrono::Utc; +use reqwest::{Client, StatusCode, Url}; +use roxmltree::Document; +use tokio::{ + net::UdpSocket, + time::{Instant, timeout}, +}; + +use super::{ + AppInfo, Device, DeviceInfo, DeviceState, PowerState, Result, TvAdapter, TvError, TvKey, +}; + +const ROKU_ECP_DISCOVERY_ADDR: &str = "239.255.255.250:1900"; +const ROKU_ECP_DISCOVERY_REQUEST: &str = concat!( + "M-SEARCH * HTTP/1.1\r\n", + "Host: 239.255.255.250:1900\r\n", + "Man: \"ssdp:discover\"\r\n", + "ST: roku:ecp\r\n", + "\r\n", +); +const DEFAULT_REQUEST_TIMEOUT_SECS: u64 = 5; +const DEFAULT_DISCOVERY_TIMEOUT_SECS: u64 = 3; + +/// A Roku ECP adapter backed by SSDP and HTTP requests. +#[derive(Debug, Clone)] +pub struct RokuAdapter { + client: Client, + request_timeout: Duration, + discovery_timeout: Duration, +} impl RokuAdapter { /// Create a new Roku adapter instance. pub fn new() -> Self { - Self + Self { + client: Client::new(), + request_timeout: Duration::from_secs(DEFAULT_REQUEST_TIMEOUT_SECS), + discovery_timeout: Duration::from_secs(DEFAULT_DISCOVERY_TIMEOUT_SECS), + } + } + + /// Create a Roku adapter with custom request timeouts. + pub fn with_timeouts(request_timeout: Duration, discovery_timeout: Duration) -> Self { + Self { + client: Client::new(), + request_timeout, + discovery_timeout, + } + } + + async fn get_text(&self, url: Url) -> Result { + let response = self + .client + .get(url.clone()) + .timeout(self.request_timeout) + .send() + .await + .map_err(|error| TvError::Transport(format!("GET {url} failed: {error}")))?; + + let status = response.status(); + if !status.is_success() { + return Err(TvError::Transport(format!( + "GET {url} failed with status {status}" + ))); + } + + response + .text() + .await + .map_err(|error| TvError::Transport(format!("reading {url} failed: {error}"))) + } + + async fn get_optional_text(&self, url: Url) -> Result> { + let response = self + .client + .get(url.clone()) + .timeout(self.request_timeout) + .send() + .await + .map_err(|error| TvError::Transport(format!("GET {url} failed: {error}")))?; + + if response.status() == StatusCode::NOT_FOUND { + return Ok(None); + } + + let status = response.status(); + if !status.is_success() { + return Err(TvError::Transport(format!( + "GET {url} failed with status {status}" + ))); + } + + response + .text() + .await + .map(Some) + .map_err(|error| TvError::Transport(format!("reading {url} failed: {error}"))) + } + + async fn post_empty(&self, url: Url) -> Result<()> { + let response = self + .client + .post(url.clone()) + .timeout(self.request_timeout) + .body(Vec::new()) + .send() + .await + .map_err(|error| TvError::Transport(format!("POST {url} failed: {error}")))?; + + let status = response.status(); + if !status.is_success() { + return Err(TvError::Transport(format!( + "POST {url} failed with status {status}" + ))); + } + + Ok(()) + } + + fn device_base_url(device: &Device) -> Result { + let host = match device.address { + IpAddr::V4(address) => address.to_string(), + IpAddr::V6(address) => format!("[{address}]"), + }; + Url::parse(&format!("http://{host}:{}/", device.port)) + .map_err(|error| TvError::Transport(format!("invalid device URL: {error}"))) + } + + fn join_url(base_url: &Url, path: &str) -> Result { + base_url + .join(path) + .map_err(|error| TvError::Transport(format!("invalid Roku endpoint {path}: {error}"))) + } + + async fn device_text(&self, device: &Device, path: &str) -> Result { + let base_url = Self::device_base_url(device)?; + let url = Self::join_url(&base_url, path)?; + self.get_text(url).await + } + + async fn device_optional_text(&self, device: &Device, path: &str) -> Result> { + let base_url = Self::device_base_url(device)?; + let url = Self::join_url(&base_url, path)?; + self.get_optional_text(url).await + } + + async fn device_post(&self, device: &Device, path: &str) -> Result<()> { + let base_url = Self::device_base_url(device)?; + let url = Self::join_url(&base_url, path)?; + self.post_empty(url).await + } + + async fn fetch_device_info(&self, base_url: &Url) -> Result { + let url = Self::join_url(base_url, "query/device-info")?; + let xml = self.get_text(url).await?; + parse_device_info(&xml) + } +} + +impl Default for RokuAdapter { + fn default() -> Self { + Self::new() } } impl TvAdapter for RokuAdapter { async fn discover(&self) -> Result> { - Err(TvError::NotSupported("discover")) + let socket = UdpSocket::bind("0.0.0.0:0").await?; + socket + .send_to( + ROKU_ECP_DISCOVERY_REQUEST.as_bytes(), + ROKU_ECP_DISCOVERY_ADDR, + ) + .await?; + + let deadline = Instant::now() + self.discovery_timeout; + let mut buffer = [0_u8; 2048]; + let mut locations = BTreeSet::new(); + + loop { + let now = Instant::now(); + if now >= deadline { + break; + } + + let remaining = deadline - now; + match timeout(remaining, socket.recv_from(&mut buffer)).await { + Ok(Ok((size, _peer))) => { + let response = String::from_utf8_lossy(&buffer[..size]); + if let Some(location) = parse_ssdp_location(&response) { + locations.insert(location); + } + } + Ok(Err(error)) => return Err(TvError::Io(error)), + Err(_) => break, + } + } + + let mut devices = BTreeMap::new(); + for location in locations { + let Ok(base_url) = Url::parse(&location) else { + continue; + }; + + let info = self.fetch_device_info(&base_url).await?; + let address = match base_url + .host_str() + .and_then(|value| value.parse::().ok()) + { + Some(address) => address, + None => continue, + }; + let port = base_url.port_or_known_default().unwrap_or(8060); + + devices.insert( + format!("{address}:{port}"), + DeviceInfo { + name: info.display_name(), + platform: "roku".to_string(), + address, + port, + }, + ); + } + + Ok(devices.into_values().collect()) } - async fn state(&self, _device: &Device) -> Result { - Err(TvError::NotSupported("state")) + async fn state(&self, device: &Device) -> Result { + let info_xml = self.device_text(device, "query/device-info").await?; + let info = parse_device_info(&info_xml)?; + let active_app_xml = self + .device_optional_text(device, "query/active-app") + .await?; + + Ok(DeviceState { + device_id: device.id, + power: info.power_state, + active_app: active_app_xml + .as_deref() + .map(parse_active_app) + .transpose()? + .flatten(), + volume: None, + timestamp: Utc::now(), + }) } - async fn launch(&self, _device: &Device, _app: &str) -> Result<()> { - Err(TvError::NotSupported("launch")) + async fn launch(&self, device: &Device, app: &str) -> Result<()> { + self.device_post(device, &format!("launch/{app}")).await } - async fn stop_app(&self, _device: &Device) -> Result<()> { - Err(TvError::NotSupported("stop_app")) + async fn stop_app(&self, device: &Device) -> Result<()> { + // Roku exposes a generic app-exit path only for developer workflows, so + // returning to Home is the stable user-mode equivalent of stopping the app. + self.device_post(device, "keypress/Home").await } - async fn key(&self, _device: &Device, _key: TvKey) -> Result<()> { - Err(TvError::NotSupported("key")) + async fn key(&self, device: &Device, key: TvKey) -> Result<()> { + for path in roku_key_paths(&key)? { + self.device_post(device, &format!("keypress/{path}")) + .await?; + } + Ok(()) } - async fn sequence(&self, _device: &Device, _keys: Vec) -> Result<()> { - Err(TvError::NotSupported("sequence")) + async fn sequence(&self, device: &Device, keys: Vec) -> Result<()> { + for key in keys { + self.key(device, key).await?; + } + Ok(()) } - async fn list_apps(&self, _device: &Device) -> Result> { - Err(TvError::NotSupported("list_apps")) + async fn list_apps(&self, device: &Device) -> Result> { + let xml = self.device_text(device, "query/apps").await?; + parse_apps(&xml) + } + + async fn dev_reload(&self, device: &Device) -> Result<()> { + self.device_post(device, "launch/dev").await + } +} + +#[derive(Debug, Clone, PartialEq, Eq)] +struct RokuDeviceInfo { + user_device_name: Option, + model_name: Option, + power_state: PowerState, +} + +impl RokuDeviceInfo { + fn display_name(&self) -> String { + self.user_device_name + .clone() + .or_else(|| self.model_name.clone()) + .unwrap_or_else(|| "Roku".to_string()) + } +} + +fn parse_device_info(xml: &str) -> Result { + let document = parse_xml_document(xml)?; + let root = document.root_element(); + + Ok(RokuDeviceInfo { + user_device_name: text_at(&root, "user-device-name"), + model_name: text_at(&root, "model-name"), + power_state: map_power_state(text_at(&root, "power-mode").as_deref()), + }) +} + +fn parse_apps(xml: &str) -> Result> { + let document = parse_xml_document(xml)?; + let apps = document + .descendants() + .filter(|node| node.is_element() && node.tag_name().name() == "app") + .filter_map(|node| { + let platform_id = node.attribute("id")?.trim(); + if platform_id.is_empty() { + return None; + } + + let name = node.text()?.trim(); + if name.is_empty() { + return None; + } + + Some(AppInfo { + id: platform_id.to_string(), + name: name.to_string(), + version: node.attribute("version").map(ToString::to_string), + platform_id: platform_id.to_string(), + }) + }) + .collect(); + + Ok(apps) +} + +fn parse_active_app(xml: &str) -> Result> { + let document = parse_xml_document(xml)?; + let root = document.root_element(); + let Some(node) = root.children().find(|child| child.is_element()) else { + return Ok(None); + }; + + let Some(platform_id) = node + .attribute("id") + .map(str::trim) + .filter(|value| !value.is_empty()) + else { + return Ok(None); + }; + + let name = node.text().unwrap_or_default().trim(); + if name.is_empty() { + return Ok(None); + } + + Ok(Some(AppInfo { + id: platform_id.to_string(), + name: name.to_string(), + version: node.attribute("version").map(ToString::to_string), + platform_id: platform_id.to_string(), + })) +} + +fn parse_xml_document(xml: &str) -> Result> { + Document::parse(xml) + .map_err(|error| TvError::Serialization(format!("invalid Roku XML: {error}"))) +} + +fn text_at(node: &roxmltree::Node<'_, '_>, tag_name: &str) -> Option { + node.children() + .find(|child| child.is_element() && child.tag_name().name() == tag_name) + .and_then(|child| child.text()) + .map(str::trim) + .filter(|value| !value.is_empty()) + .map(ToString::to_string) +} + +fn parse_ssdp_location(response: &str) -> Option { + response.lines().find_map(|line| { + let (name, value) = line.split_once(':')?; + if !name.trim().eq_ignore_ascii_case("location") { + return None; + } + let value = value.trim(); + if value.is_empty() { + return None; + } + Some(value.to_string()) + }) +} + +fn map_power_state(value: Option<&str>) -> PowerState { + let Some(value) = value else { + return PowerState::Unknown; + }; + + let normalized = value.trim().to_ascii_lowercase(); + if normalized.contains("on") { + PowerState::On + } else if normalized.contains("off") + || normalized.contains("standby") + || normalized.contains("suspend") + { + PowerState::Off + } else { + PowerState::Unknown + } +} + +fn roku_key_paths(key: &TvKey) -> Result> { + let path = match key { + TvKey::Home => return Ok(vec!["Home".to_string()]), + TvKey::Back => return Ok(vec!["Back".to_string()]), + TvKey::Up => return Ok(vec!["Up".to_string()]), + TvKey::Down => return Ok(vec!["Down".to_string()]), + TvKey::Left => return Ok(vec!["Left".to_string()]), + TvKey::Right => return Ok(vec!["Right".to_string()]), + TvKey::Select => return Ok(vec!["Select".to_string()]), + TvKey::Play | TvKey::Pause | TvKey::PlayPause => return Ok(vec!["Play".to_string()]), + TvKey::Rewind => return Ok(vec!["Rev".to_string()]), + TvKey::FastForward => return Ok(vec!["Fwd".to_string()]), + TvKey::Replay => return Ok(vec!["InstantReplay".to_string()]), + TvKey::ChannelUp => return Ok(vec!["ChannelUp".to_string()]), + TvKey::ChannelDown => return Ok(vec!["ChannelDown".to_string()]), + TvKey::VolumeUp => return Ok(vec!["VolumeUp".to_string()]), + TvKey::VolumeDown => return Ok(vec!["VolumeDown".to_string()]), + TvKey::Mute => return Ok(vec!["VolumeMute".to_string()]), + TvKey::PowerOff => return Ok(vec!["PowerOff".to_string()]), + TvKey::InputHdmi1 => return Ok(vec!["InputHDMI1".to_string()]), + TvKey::InputHdmi2 => return Ok(vec!["InputHDMI2".to_string()]), + TvKey::InputHdmi3 => return Ok(vec!["InputHDMI3".to_string()]), + TvKey::InputHdmi4 => return Ok(vec!["InputHDMI4".to_string()]), + TvKey::InputAv => return Ok(vec!["InputAV1".to_string()]), + TvKey::InputTuner => return Ok(vec!["InputTuner".to_string()]), + TvKey::Search => return Ok(vec!["Search".to_string()]), + TvKey::Info => return Ok(vec!["Info".to_string()]), + TvKey::Literal(value) => { + return Ok(value + .chars() + .map(|character| format!("Lit_{}", urlencoding::encode(&character.to_string()))) + .collect()); + } + TvKey::Stop => "stop", + TvKey::Skip => "skip", + TvKey::Power => "power", + TvKey::PowerOn => "power-on", + TvKey::Options => "options", + }; + + Err(TvError::InvalidKey(path.to_string())) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn parses_ssdp_location_case_insensitively() { + let response = "HTTP/1.1 200 OK\r\nLOCATION: http://192.168.1.42:8060/\r\nUSN: uuid:roku:ecp:1234\r\n\r\n"; + assert_eq!( + parse_ssdp_location(response).as_deref(), + Some("http://192.168.1.42:8060/") + ); + } + + #[test] + fn parses_device_info_power_and_name() { + let xml = r#" + + Living Room Roku + Roku Ultra + PowerOn + + "#; + let info = parse_device_info(xml).expect("device info should parse"); + assert_eq!(info.display_name(), "Living Room Roku"); + assert_eq!(info.power_state, PowerState::On); + } + + #[test] + fn parses_app_lists() { + let xml = r#" + + Netflix + YouTube + + "#; + let apps = parse_apps(xml).expect("apps should parse"); + assert_eq!(apps.len(), 2); + assert_eq!(apps[0].platform_id, "12"); + assert_eq!(apps[0].name, "Netflix"); + assert_eq!(apps[0].version.as_deref(), Some("4.1.218")); + } + + #[test] + fn parses_active_app() { + let xml = r#" + + Netflix + + "#; + let app = parse_active_app(xml) + .expect("active app XML should parse") + .expect("active app should exist"); + assert_eq!(app.id, "12"); + assert_eq!(app.name, "Netflix"); + } + + #[test] + fn maps_supported_keys_and_literals() { + assert_eq!( + roku_key_paths(&TvKey::FastForward).expect("key should map"), + vec!["Fwd"] + ); + assert_eq!( + roku_key_paths(&TvKey::Literal("a ".to_string())).expect("literal should map"), + vec!["Lit_a", "Lit_%20"] + ); + } + + #[test] + fn rejects_keys_without_a_documented_roku_mapping() { + let error = roku_key_paths(&TvKey::PowerOn).expect_err("PowerOn should not map"); + assert!(matches!(error, TvError::InvalidKey(key) if key == "power-on")); } }