From 0ffe2138c80684eb4159f1ad64aadca4828e1950 Mon Sep 17 00:00:00 2001 From: Nedko Arnaudov Date: Sun, 24 May 2009 19:19:08 +0300 Subject: [PATCH] chery-pick the no-self-connect patch from the old repo --- common/JackLibClient.cpp | 50 ++++++++++++++++++++++++++++++++++++++++ common/JackLibClient.h | 2 ++ 2 files changed, 52 insertions(+) diff --git a/common/JackLibClient.cpp b/common/JackLibClient.cpp index ff6055e5..167cd1d7 100644 --- a/common/JackLibClient.cpp +++ b/common/JackLibClient.cpp @@ -168,6 +168,56 @@ JackClientControl* JackLibClient::GetClientControl() const return fClientControl; } +int JackLibClient::PortConnect(const char* src, const char* dst) +{ + // this check is to prevent apps to self connect to other apps + // TODO: make this work with multiple clients per app + { + const char * sep_ptr; + const char * client_name_ptr; + int src_self; + int dst_self; + + client_name_ptr = GetClientControl()->fName; + + //jack_info("Client '%s' connecting '%s' to '%s'", client_name_ptr, src, dst); + + sep_ptr = strchr(src, ':'); + if (sep_ptr == NULL) + { + jack_error("source port '%s' is invalid", src); + return -1; + } + + src_self = strncmp(client_name_ptr, src, sep_ptr - src) == 0 ? 0 : 1; + + sep_ptr = strchr(dst, ':'); + if (sep_ptr == NULL) + { + jack_error("destination port '%s' is invalid", dst); + return -1; + } + + dst_self = strncmp(client_name_ptr, dst, sep_ptr - dst) == 0 ? 0 : 1; + + //jack_info("src_self is %s", src_self ? "true" : "false"); + //jack_info("dst_self is %s", dst_self ? "true" : "false"); + + // 0 means client is connecting other client ports (i.e. control app patchbay functionality) + // 1 means client is connecting its own port to port of other client (i.e. self hooking into system app) + // 2 means client is connecting its own ports (i.e. for app internal functionality) + // TODO: Make this check an engine option and more tweakable (return error or success) + // MAYBE: make the engine option changable on the fly and expose it through client or control API + if (src_self + dst_self == 1) + { + jack_info("ignoring self hook to other client ports ('%s': '%s' -> '%s')", client_name_ptr, src, dst); + return 0; + } + } + + return JackClient::PortConnect(src, dst); +} + } // end of namespace diff --git a/common/JackLibClient.h b/common/JackLibClient.h index 3ad9e3c9..83296910 100644 --- a/common/JackLibClient.h +++ b/common/JackLibClient.h @@ -51,6 +51,8 @@ class JackLibClient : public JackClient JackGraphManager* GetGraphManager() const; JackEngineControl* GetEngineControl() const; JackClientControl* GetClientControl() const; + + virtual int PortConnect(const char* src, const char* dst); };