Changeset View
Changeset View
Standalone View
Standalone View
src/torcontrol.cpp
Show First 20 Lines • Show All 268 Lines • ▼ Show 20 Lines | |||||
/****** General parsing utilities ********/ | /****** General parsing utilities ********/ | ||||
/* Split reply line in the form 'AUTH METHODS=...' into a type | /* Split reply line in the form 'AUTH METHODS=...' into a type | ||||
* 'AUTH' and arguments 'METHODS=...'. | * 'AUTH' and arguments 'METHODS=...'. | ||||
* Grammar is implicitly defined in https://spec.torproject.org/control-spec by | * Grammar is implicitly defined in https://spec.torproject.org/control-spec by | ||||
* the server reply formats for PROTOCOLINFO (S3.21) and AUTHCHALLENGE (S3.24). | * the server reply formats for PROTOCOLINFO (S3.21) and AUTHCHALLENGE (S3.24). | ||||
*/ | */ | ||||
static std::pair<std::string, std::string> | std::pair<std::string, std::string> SplitTorReplyLine(const std::string &s) { | ||||
SplitTorReplyLine(const std::string &s) { | |||||
size_t ptr = 0; | size_t ptr = 0; | ||||
std::string type; | std::string type; | ||||
while (ptr < s.size() && s[ptr] != ' ') { | while (ptr < s.size() && s[ptr] != ' ') { | ||||
type.push_back(s[ptr]); | type.push_back(s[ptr]); | ||||
++ptr; | ++ptr; | ||||
} | } | ||||
if (ptr < s.size()) { | if (ptr < s.size()) { | ||||
// skip ' ' | // skip ' ' | ||||
++ptr; | ++ptr; | ||||
} | } | ||||
return make_pair(type, s.substr(ptr)); | return make_pair(type, s.substr(ptr)); | ||||
} | } | ||||
/** | /** | ||||
* Parse reply arguments in the form 'METHODS=COOKIE,SAFECOOKIE | * Parse reply arguments in the form 'METHODS=COOKIE,SAFECOOKIE | ||||
* COOKIEFILE=".../control_auth_cookie"'. | * COOKIEFILE=".../control_auth_cookie"'. | ||||
* Returns a map of keys to values, or an empty map if there was an error. | * Returns a map of keys to values, or an empty map if there was an error. | ||||
* Grammar is implicitly defined in https://spec.torproject.org/control-spec by | * Grammar is implicitly defined in https://spec.torproject.org/control-spec by | ||||
* the server reply formats for PROTOCOLINFO (S3.21), AUTHCHALLENGE (S3.24), | * the server reply formats for PROTOCOLINFO (S3.21), AUTHCHALLENGE (S3.24), | ||||
* and ADD_ONION (S3.27). See also sections 2.1 and 2.3. | * and ADD_ONION (S3.27). See also sections 2.1 and 2.3. | ||||
*/ | */ | ||||
static std::map<std::string, std::string> | std::map<std::string, std::string> ParseTorReplyMapping(const std::string &s) { | ||||
ParseTorReplyMapping(const std::string &s) { | |||||
std::map<std::string, std::string> mapping; | std::map<std::string, std::string> mapping; | ||||
size_t ptr = 0; | size_t ptr = 0; | ||||
while (ptr < s.size()) { | while (ptr < s.size()) { | ||||
std::string key, value; | std::string key, value; | ||||
while (ptr < s.size() && s[ptr] != '=' && s[ptr] != ' ') { | while (ptr < s.size() && s[ptr] != '=' && s[ptr] != ' ') { | ||||
key.push_back(s[ptr]); | key.push_back(s[ptr]); | ||||
++ptr; | ++ptr; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 584 Lines • Show Last 20 Lines |