Expand description
GETCONF response parsing.
This module parses responses from the GETCONF command, which retrieves
Tor configuration values. Configuration options can have single values,
multiple values (like exit policies), or no value (unset options).
§Response Format
A successful GETCONF response contains key-value pairs:
250-CookieAuthentication=0
250-ControlPort=9100
250-DataDirectory=/home/user/.tor
250 DirPortOptions without values (like DirPort above) indicate the option is unset
or using its default value.
§Example
use stem_rs::response::{ControlMessage, GetConfResponse};
let response_text = "250-CookieAuthentication=0\r\n\
250-ControlPort=9100\r\n\
250 OK\r\n";
let msg = ControlMessage::from_str(response_text, None, false).unwrap();
let response = GetConfResponse::from_message(&msg).unwrap();
// Single-value options return a Vec with one element
assert_eq!(
response.entries.get("CookieAuthentication"),
Some(&vec!["0".to_string()])
);§Multi-Value Options
Some options like ExitPolicy can have multiple values:
use stem_rs::response::{ControlMessage, GetConfResponse};
let response_text = "250-ExitPolicy=accept *:80\r\n\
250-ExitPolicy=accept *:443\r\n\
250-ExitPolicy=reject *:*\r\n\
250 OK\r\n";
let msg = ControlMessage::from_str(response_text, None, false).unwrap();
let response = GetConfResponse::from_message(&msg).unwrap();
let policies = response.entries.get("ExitPolicy").unwrap();
assert_eq!(policies.len(), 3);§See Also
crate::Controller::get_conf: High-level API for getting configuration- [
GetInfoResponse]: For querying runtime information - Tor Control Protocol: GETCONF
Structs§
- GetConf
Response - Parsed response from the GETCONF command.