ToxHexAddress ResolveToxAddressFromDnsRecordV1(const std::string &dnsRecord) { std::smatch match; std::regex regex("^v=tox1;id=([A-Fa-f0-9]{76})(;sign=(\\S+))?$"); if (std::regex_search(dnsRecord, match, regex)) return ToxHexAddress(match[1]); return ToxHexAddress::Empty(); }
ToxHexAddress ResolveToxAddressFromDnsRecordV3(void *dns, uint32_t requestId, const std::string &dnsRecord) { std::smatch match; std::regex regex("^v=tox3;id=([a-z0-5.]+)$"); if (std::regex_search(dnsRecord, match, regex)) { std::string id = match[1]; uint8_t data[TOX_ADDRESS_SIZE]; if (tox_decrypt_dns3_TXT(dns, data, (uint8_t*)id.c_str(), (uint32_t)id.length(), requestId) != TOX_ERROR) { return ToxHexAddress(data, TOX_ADDRESS_SIZE); } } return ToxHexAddress::Empty(); }
ToxHexAddress ResolveToxAddressFromToxme(HANDLE hNetlib, const char *query) { ToxHexAddress address = ToxHexAddress::Empty(); HttpRequest request(REQUEST_POST, "https://toxme.io/api"); JSONNode root(JSON_NODE); root << JSONNode("action", 3) << JSONNode("name", query); json_string data = root.write(); request.SetData(data.c_str(), data.length()); NLHR_PTR response(request.Send(hNetlib)); if (response->resultCode != HTTP_CODE_OK || !response->pData) return ToxHexAddress::Empty(); root = JSONNode::parse(response->pData); if (root.empty()) return ToxHexAddress::Empty(); json_string id = root.at("tox_id").as_string(); return ToxHexAddress(id.c_str()); }