@@ -670,15 +670,15 @@ inline void JackClient::Error() | |||
int JackClient::PortRegister(const char* port_name, const char* port_type, unsigned long flags, unsigned long buffer_size) | |||
{ | |||
// Check if port name is empty | |||
string port_name_str = string(port_name); | |||
if (port_name_str.size() == 0) { | |||
string port_short_name_str = string(port_name); | |||
if (port_short_name_str.size() == 0) { | |||
jack_error("port_name is empty"); | |||
return 0; // Means failure here... | |||
} | |||
// Check port name length | |||
string name = string(GetClientControl()->fName) + string(":") + port_name_str; | |||
if (name.size() >= REAL_JACK_PORT_NAME_SIZE) { | |||
string port_full_name_str = string(GetClientControl()->fName) + string(":") + port_short_name_str; | |||
if (port_full_name_str.size() >= REAL_JACK_PORT_NAME_SIZE) { | |||
jack_error("\"%s:%s\" is too long to be used as a JACK port name.\n" | |||
"Please use %lu characters or less", | |||
GetClientControl()->fName, | |||
@@ -689,10 +689,10 @@ int JackClient::PortRegister(const char* port_name, const char* port_type, unsig | |||
int result = -1; | |||
jack_port_id_t port_index = NO_PORT; | |||
fChannel->PortRegister(GetClientControl()->fRefNum, name.c_str(), port_type, flags, buffer_size, &port_index, &result); | |||
fChannel->PortRegister(GetClientControl()->fRefNum, port_full_name_str.c_str(), port_type, flags, buffer_size, &port_index, &result); | |||
if (result == 0) { | |||
jack_log("JackClient::PortRegister ref = %ld name = %s type = %s port_index = %ld", GetClientControl()->fRefNum, name.c_str(), port_type, port_index); | |||
jack_log("JackClient::PortRegister ref = %ld name = %s type = %s port_index = %ld", GetClientControl()->fRefNum, port_full_name_str.c_str(), port_type, port_index); | |||
fPortList.push_back(port_index); | |||
return port_index; | |||
} else { | |||
@@ -719,6 +719,14 @@ int JackClient::PortUnRegister(jack_port_id_t port_index) | |||
int JackClient::PortConnect(const char* src, const char* dst) | |||
{ | |||
jack_log("JackClient::Connect src = %s dst = %s", src, dst); | |||
if (strlen(src) >= REAL_JACK_PORT_NAME_SIZE) { | |||
jack_error("\"%s\" is too long to be used as a JACK port name.\n", src); | |||
return -1; | |||
} | |||
if (strlen(dst) >= REAL_JACK_PORT_NAME_SIZE) { | |||
jack_error("\"%s\" is too long to be used as a JACK port name.\n", src); | |||
return -1; | |||
} | |||
int result = -1; | |||
fChannel->PortConnect(GetClientControl()->fRefNum, src, dst, &result); | |||
return result; | |||
@@ -727,6 +735,14 @@ int JackClient::PortConnect(const char* src, const char* dst) | |||
int JackClient::PortDisconnect(const char* src, const char* dst) | |||
{ | |||
jack_log("JackClient::Disconnect src = %s dst = %s", src, dst); | |||
if (strlen(src) >= REAL_JACK_PORT_NAME_SIZE) { | |||
jack_error("\"%s\" is too long to be used as a JACK port name.\n", src); | |||
return -1; | |||
} | |||
if (strlen(dst) >= REAL_JACK_PORT_NAME_SIZE) { | |||
jack_error("\"%s\" is too long to be used as a JACK port name.\n", src); | |||
return -1; | |||
} | |||
int result = -1; | |||
fChannel->PortDisconnect(GetClientControl()->fRefNum, src, dst, &result); | |||
return result; | |||
@@ -39,7 +39,7 @@ | |||
#define SYNC_MAX_NAME_SIZE 256 | |||
#define REAL_JACK_PORT_NAME_SIZE JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE | |||
#define REAL_JACK_PORT_NAME_SIZE JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE // full name like "client_name:short_port_name" | |||
#ifndef PORT_NUM | |||
#define PORT_NUM 2048 | |||
@@ -68,6 +68,14 @@ int JackInternalClient::Open(const char* server_name, const char* name, int uuid | |||
int result; | |||
char name_res[JACK_CLIENT_NAME_SIZE + 1]; | |||
jack_log("JackInternalClient::Open name = %s", name); | |||
if (strlen(name) >= JACK_CLIENT_NAME_SIZE) { | |||
jack_error("\"%s\" is too long to be used as a JACK client name.\n" | |||
"Please use %lu characters or less", | |||
name, | |||
JACK_CLIENT_NAME_SIZE - 1); | |||
return -1; | |||
} | |||
strncpy(fServerName, server_name, sizeof(fServerName)); | |||
@@ -86,7 +86,15 @@ int JackLibClient::Open(const char* server_name, const char* name, int uuid, jac | |||
int shared_engine, shared_client, shared_graph, result; | |||
bool res; | |||
jack_log("JackLibClient::Open name = %s", name); | |||
if (strlen(name) >= JACK_CLIENT_NAME_SIZE) { | |||
jack_error("\"%s\" is too long to be used as a JACK client name.\n" | |||
"Please use %lu characters or less", | |||
name, | |||
JACK_CLIENT_NAME_SIZE - 1); | |||
return -1; | |||
} | |||
strncpy(fServerName, server_name, sizeof(fServerName)); | |||
// Open server/client channel | |||
@@ -408,7 +408,7 @@ struct JackPortRegisterRequest : public JackRequest | |||
{ | |||
int fRefNum; | |||
char fName[JACK_PORT_NAME_SIZE + 1]; | |||
char fName[JACK_PORT_NAME_SIZE + 1]; // port short name | |||
char fPortType[JACK_PORT_TYPE_SIZE + 1]; | |||
unsigned int fFlags; | |||
unsigned int fBufferSize; | |||
@@ -517,8 +517,8 @@ struct JackPortConnectNameRequest : public JackRequest | |||
{ | |||
int fRefNum; | |||
char fSrc[JACK_PORT_NAME_SIZE + 1]; | |||
char fDst[JACK_PORT_NAME_SIZE + 1]; | |||
char fSrc[REAL_JACK_PORT_NAME_SIZE + 1]; // port full name | |||
char fDst[REAL_JACK_PORT_NAME_SIZE + 1]; // port full name | |||
JackPortConnectNameRequest() | |||
{} | |||
@@ -559,8 +559,8 @@ struct JackPortDisconnectNameRequest : public JackRequest | |||
{ | |||
int fRefNum; | |||
char fSrc[JACK_PORT_NAME_SIZE + 1]; | |||
char fDst[JACK_PORT_NAME_SIZE + 1]; | |||
char fSrc[REAL_JACK_PORT_NAME_SIZE + 1]; // port full name | |||
char fDst[REAL_JACK_PORT_NAME_SIZE + 1]; // port full name | |||
JackPortDisconnectNameRequest() | |||
{} | |||
@@ -678,7 +678,7 @@ struct JackPortRenameRequest : public JackRequest | |||
int fRefNum; | |||
jack_port_id_t fPort; | |||
char fName[JACK_PORT_NAME_SIZE + 1]; | |||
char fName[JACK_PORT_NAME_SIZE + 1]; // port short name | |||
JackPortRenameRequest() | |||
{} | |||
@@ -1194,7 +1194,7 @@ struct JackClientNotificationRequest : public JackRequest | |||
struct JackSessionCommand | |||
{ | |||
char fUUID[JACK_UUID_SIZE]; | |||
char fClientName[JACK_CLIENT_NAME_SIZE+1]; | |||
char fClientName[JACK_CLIENT_NAME_SIZE + 1]; | |||
char fCommand[JACK_SESSION_COMMAND_SIZE]; | |||
jack_session_flags_t fFlags; | |||
@@ -750,10 +750,12 @@ int main (int argc, char *argv[]) | |||
* | |||
*/ | |||
char client_name3[jack_client_name_size()]; | |||
// "jack_client_name_size" - 1 effective characters | |||
for (int i = 0; i < jack_client_name_size() - 1; i++) { | |||
client_name3[i] = 'A'; | |||
} | |||
client_name3[jack_client_name_size()] = 0; | |||
// And last one is the terminating '0' | |||
client_name3[jack_client_name_size()] = 0; | |||
Log("trying to register a new jackd client with maximum possible client name size...\n", client_name3); | |||
client2 = jack_client_open(client_name3, jack_options, &status, server_name); | |||
if (client2 != NULL) { | |||
@@ -934,15 +936,17 @@ int main (int argc, char *argv[]) | |||
} | |||
/** | |||
* Verify if a port can be registered with maximum port name size | |||
* Verify if a port can be registered with maximum port name size (that is "short name") | |||
* | |||
*/ | |||
int port_size_max = jack_port_name_size() - strlen(client_name1) - 2; // Port is of shape: "client_name:port_name" | |||
char port_name3[port_size_max]; | |||
for (int i = 0; i < port_size_max - 1; i++) { | |||
int short_port_size_max = jack_port_name_size() - jack_client_name_size() - 1; // Port is of shape: "client_name:port_name" | |||
char port_name3[short_port_size_max]; | |||
// "short_port_size_max" - 1 effective characters | |||
for (int i = 0; i < short_port_size_max - 1; i++) { | |||
port_name3[i] = 'A'; | |||
} | |||
port_name3[port_size_max] = 0; | |||
// And last one is the terminating '0' | |||
port_name3[short_port_size_max] = 0; | |||
jack_port_t * test_max_port = jack_port_register(client1, port_name3, | |||
JACK_DEFAULT_AUDIO_TYPE, | |||
JackPortIsOutput, 0); | |||