| 1 |
#include "clConnectionString.h" |
| 2 |
#include "file_logger.h" |
| 3 |
|
| 4 |
clConnectionString::clConnectionString(const wxString& connectionString) |
| 5 |
: m_port(wxNOT_FOUND) |
| 6 |
, m_isOK(false) |
| 7 |
{ |
| 8 |
DoParse(connectionString); |
| 9 |
} |
| 10 |
|
| 11 |
clConnectionString::~clConnectionString() {} |
| 12 |
|
| 13 |
void clConnectionString::DoParse(const wxString& connectionString) |
| 14 |
{ |
| 15 |
m_isOK = false; // default |
| 16 |
// get the protocol part |
| 17 |
clDEBUG() << "Parsing connection string:" << connectionString << clEndl; |
| 18 |
wxString protocol = connectionString.BeforeFirst(':'); |
| 19 |
if(protocol == "tcp") { |
| 20 |
m_protocol = kTcp; |
| 21 |
} else if(protocol == "unix") { |
| 22 |
#ifdef __WXMSW__ |
| 23 |
clWARNING() << "unix protocol is not suppported on Windows" << clEndl; |
| 24 |
return; |
| 25 |
#endif |
| 26 |
m_protocol = kUnixLocalSocket; |
| 27 |
} else { |
| 28 |
clWARNING() << "Invalid protocol in connection string:" << connectionString << clEndl; |
| 29 |
return; |
| 30 |
} |
| 31 |
|
| 32 |
wxString address = connectionString.AfterFirst(':'); |
| 33 |
address = address.Mid(2); // Skip the "//" |
| 34 |
if(m_protocol == kUnixLocalSocket) { |
| 35 |
// The rest is the file path |
| 36 |
m_path = address; |
| 37 |
m_isOK = !m_path.IsEmpty(); |
| 38 |
} else { |
| 39 |
// we now expect host[:port] |
| 40 |
m_host = address.BeforeFirst(':'); |
| 41 |
wxString port = address.AfterFirst(':'); |
| 42 |
if(!port.IsEmpty()) { |
| 43 |
port.ToCLong(&m_port); |
| 44 |
} |
| 45 |
m_isOK = !m_host.IsEmpty() && (m_port != wxNOT_FOUND); |
| 46 |
} |
| 47 |
} |