MCPcopy Create free account
hub / github.com/RGAA-Software/GoDesk / Parse

Method Parse

src/render_panel/util/conn_info_parser.cpp:16–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14{
15
16 std::shared_ptr<GrConnectionInfo> ConnInfoParser::Parse(const std::string& info) {
17 std::string prefix = "link://";
18 if (!info.starts_with(prefix)) {
19 return nullptr;
20 }
21 auto target_info = info.substr(prefix.size());
22 target_info = Base64::Base64Decode(target_info);
23
24 try {
25 LOGI("Origin ConnInfo: {}", target_info);
26 auto conn_info = std::make_shared<GrConnectionInfo>();
27 auto obj = json::parse(target_info);
28
29 // device_id
30 conn_info->device_id_ = obj["did"].get<std::string>();
31 // device name
32 if (!obj["dn"].is_null()) {
33 conn_info->device_name_ = obj["dn"].get<std::string>();
34 }
35 // random password
36 conn_info->random_pwd_ = obj["rpwd"].get<std::string>();
37 // icon index
38 conn_info->icon_idx_ = obj["iidx"].get<int>();
39 // ips
40 auto ips_array = obj["ips"];
41 if (ips_array.is_array()) {
42 for (const auto& item : ips_array) {
43 GrConnectionInfo::GrConnectionHost host;
44 host.ip_ = item["ip"].get<std::string>();
45 //host.type_ = item["type"].get<std::string>();
46 conn_info->hosts_.push_back(host);
47 }
48 }
49
50 // panel server port
51 conn_info->panel_srv_port_ = obj["ppt"].get<int>();
52 // render server port
53 conn_info->render_srv_port_ = obj["rdpt"].get<int>();
54
55 // relay host
56 if (!obj["rlst"].is_null()) {
57 conn_info->relay_host_ = obj["rlst"].get<std::string>();
58 }
59
60 // relay port
61 if (!obj["rlpt"].is_null()) {
62 conn_info->relay_port_ = obj["rlpt"].get<int>();
63 }
64
65 // relay appkey
66 if (!obj["rlak"].is_null()) {
67 conn_info->relay_appkey_ = obj["rlak"].get<std::string>();
68 }
69
70 return conn_info;
71 }
72 catch(std::exception& e) {
73 LOGE("Parse link:// failed: {}, err: {}", target_info, e.what());

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected