27 |
#include <qregexp.h> |
#include <qregexp.h> |
28 |
|
|
29 |
// converts the given file path into a path as expected by LSCP 1.2 |
// converts the given file path into a path as expected by LSCP 1.2 |
30 |
QString lscpEscapePath(QString path) { |
QString lscpEscapePath ( const QString& sPath ) |
31 |
|
{ |
32 |
|
QString path(sPath); |
33 |
|
|
34 |
// check if remote side supports LSCP escape sequences |
// check if remote side supports LSCP escape sequences |
35 |
const lscpVersion_t version = getRemoteLscpVersion(); |
const lscpVersion_t version = getRemoteLscpVersion(); |
36 |
if (version.major < 1 || version.minor < 2) |
if (version.major < 1 || version.minor < 2) |
43 |
for (int i = path.find(regexp); i >= 0; i = path.find(regexp, i + 3)) |
for (int i = path.find(regexp); i >= 0; i = path.find(regexp, i + 3)) |
44 |
path.replace(i, 1, "\\x"); |
path.replace(i, 1, "\\x"); |
45 |
} |
} |
46 |
|
|
47 |
// replace all non-basic characters by LSCP escape sequences |
// replace all non-basic characters by LSCP escape sequences |
48 |
{ |
{ |
49 |
const char pathSeparator = '/'; |
const char pathSeparator = '/'; |
66 |
) { |
) { |
67 |
// convert the non-basic character into a LSCP escape sequence |
// convert the non-basic character into a LSCP escape sequence |
68 |
char buf[5]; |
char buf[5]; |
69 |
snprintf(buf, sizeof(buf), "\\x%2x", static_cast<unsigned char>(c)); |
::snprintf(buf, sizeof(buf), "\\x%2x", static_cast<unsigned char>(c)); |
70 |
path.replace(i, 1, buf); |
path.replace(i, 1, buf); |
71 |
i += 3; |
i += 3; |
72 |
} |
} |
73 |
} |
} |
74 |
} |
} |
75 |
|
|
76 |
return path; |
return path; |
77 |
} |
} |
78 |
|
|
79 |
lscpVersion_t getRemoteLscpVersion() { |
|
80 |
|
lscpVersion_t getRemoteLscpVersion (void) |
81 |
|
{ |
82 |
lscpVersion_t result = { 0, 0 }; |
lscpVersion_t result = { 0, 0 }; |
83 |
|
|
84 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
85 |
if (!pMainForm || !pMainForm->client()) return result; |
if (pMainForm == NULL) |
86 |
|
return result; |
87 |
|
if (pMainForm->client() == NULL) |
88 |
|
return result; |
89 |
|
|
90 |
lscp_server_info_t* pServerInfo = |
lscp_server_info_t* pServerInfo = |
91 |
::lscp_get_server_info(pMainForm->client()); |
::lscp_get_server_info(pMainForm->client()); |
92 |
if (!pServerInfo) return result; |
if (pServerInfo && pServerInfo->protocol_version) |
93 |
|
::sscanf(pServerInfo->protocol_version, "%d.%d", |
94 |
|
&result.major, &result.minor); |
95 |
|
|
|
sscanf(pServerInfo->protocol_version, "%d.%d", &result.major, &result.minor); |
|
96 |
return result; |
return result; |
97 |
} |
} |