1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//! Vendor-neutral client for the TR-064 device management protocol.
//!
//! TR-064 (Broadband Forum) describes a device and its services in UPnP
//! description and SCPD documents, and controls it with SOAP calls. This crate
//! reads those documents and makes the calls. It knows nothing about specific
//! vendors: vendor extensions are services and actions like any other.
//!
//! # Example
//!
//! ```no_run
//! use tr064::{Client, SecretString, Url};
//!
//! # async fn run() -> Result<(), Box<dyn std::error::Error>> {
//! let client = Client::builder(Url::parse("http://192.168.178.1:49000")?)
//! .credentials("user", SecretString::from("password"))
//! .build()?;
//!
//! // The device description lists the services; SCPDs list their actions.
//! let description = client.description().await?;
//! let device_info = description.service("DeviceInfo1")?;
//! let scpd = client.scpd(device_info).await?;
//! for action in &scpd.actions {
//! println!("{}", action.name);
//! }
//!
//! let out = client.call(device_info, "GetInfo", &[]).await?;
//! println!("{:?}", out.get("NewSoftwareVersion"));
//! # Ok(())
//! # }
//! ```
//!
//! # TLS
//!
//! Devices usually present a self-signed certificate, so the client does not
//! check it against certificate authorities. Instead it accepts exactly one
//! certificate, given by its SHA-256 [`Fingerprint`]. Fetch it once with
//! [`fetch_fingerprint`], have someone confirm it, store it, and
//! [pin](ClientBuilder::pin) it from then on:
//!
//! ```no_run
//! use std::time::Duration;
//! use tr064::{Client, Url};
//!
//! # async fn run() -> Result<(), Box<dyn std::error::Error>> {
//! let url = Url::parse("https://192.168.178.1:49443")?;
//! let fingerprint = tr064::fetch_fingerprint(&url, Duration::from_secs(5)).await?;
//! println!("the device presents {fingerprint}");
//! let client = Client::builder(url).pin(fingerprint).build()?;
//! # Ok(())
//! # }
//! ```
//!
//! Plain `http` works too, but sends everything except the password readable
//! on the network.
//!
//! # Errors
//!
//! The device reports failed actions as UPnP errors with a numeric code. The
//! standard codes are below 800, vendors define their own above:
//!
//! ```no_run
//! # async fn run(client: tr064::Client, service: tr064::Service) {
//! match client.call(&service, "GetGenericHostEntry", &[("NewIndex", "99")]).await {
//! Ok(out) => println!("{out:?}"),
//! Err(error) if error.upnp_code() == Some(713) => println!("no such entry"),
//! Err(error) => eprintln!("{error}"),
//! }
//! # }
//! ```
//!
//! # Logging
//!
//! The client logs through [`tracing`](https://docs.rs/tracing): one event
//! per request at `info`, the steps of the Digest authentication and the
//! check of the certificate at `debug`, and the arguments of action calls at
//! `trace`. Passwords, headers, nonces and Digest answers are never logged,
//! and of other documents only the size. Values of arguments and query
//! parameters pass a [`Redact`] hook, which hides all of them unless the
//! client is given [another one](ClientBuilder::redact).
//!
//! The client answers HTTP Digest challenges and reuses the nonce while the
//! device accepts it. It never retries with credentials the device rejected
//! ([`Error::AuthenticationFailed`]), so that a wrong password does not lock
//! the account.
pub use DescriptionCache;
pub use ;
pub use ;
pub use Error;
pub use ;
pub use Url;
pub use ;
pub use SecretString;
pub use Arguments;
pub use ;