From 188505126f477d9940a3c3bc6d023c8d0d1888cd Mon Sep 17 00:00:00 2001 From: sletz Date: Thu, 1 Nov 2007 15:52:57 +0000 Subject: [PATCH] Client name rewritting to remove path characters (used in fifo naming). git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@1686 0c269be4-1314-0410-8aa9-9f06e86f4224 --- ChangeLog | 1 + common/JackLibAPI.cpp | 6 +++++- common/JackServerAPI.cpp | 6 +++++- common/JackTools.cpp | 42 ++++++++++++++++++++++++++++++++++++++++ common/JackTools.h | 2 ++ 5 files changed, 55 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 576090ad..476e1719 100644 --- a/ChangeLog +++ b/ChangeLog @@ -16,6 +16,7 @@ Tom Szilagyi 2007-10-31 Stephane Letz * Server and user directory related code moved in a JackTools file. + * Client name rewritting to remove path characters (used in fifo naming). 2007-10-30 Stephane Letz diff --git a/common/JackLibAPI.cpp b/common/JackLibAPI.cpp index 8831606b..c301eaa8 100644 --- a/common/JackLibAPI.cpp +++ b/common/JackLibAPI.cpp @@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "JackLibGlobals.h" #include "JackGlobals.h" #include "JackServerLaunch.h" +#include "JackTools.h" using namespace Jack; @@ -56,12 +57,15 @@ static inline bool CheckPort(jack_port_id_t port_index) return (port_index < PORT_NUM); } -EXPORT jack_client_t* jack_client_open(const char* client_name, jack_options_t options, jack_status_t* status, ...) +EXPORT jack_client_t* jack_client_open(const char* ext_client_name, jack_options_t options, jack_status_t* status, ...) { va_list ap; /* variable argument pointer */ jack_varargs_t va; /* variable arguments */ jack_status_t my_status; JackClient* client; + char client_name[JACK_CLIENT_NAME_SIZE]; + + JackTools::RewriteName(ext_client_name, client_name); if (status == NULL) /* no status from caller? */ status = &my_status; /* use local status word */ diff --git a/common/JackServerAPI.cpp b/common/JackServerAPI.cpp index 430f9748..0ad300b5 100644 --- a/common/JackServerAPI.cpp +++ b/common/JackServerAPI.cpp @@ -29,6 +29,7 @@ This program is free software; you can redistribute it and/or modify #include "JackServerGlobals.h" #include "JackError.h" #include "JackServerLaunch.h" +#include "JackTools.h" #ifdef WIN32 #define EXPORT __declspec(dllexport) @@ -62,12 +63,15 @@ EXPORT jack_client_t* jack_client_new(const char* client_name) return jack_client_open(client_name, (jack_options_t)options, NULL); } -EXPORT jack_client_t* jack_client_open(const char* client_name, jack_options_t options, jack_status_t* status, ...) +EXPORT jack_client_t* jack_client_open(const char* ext_client_name, jack_options_t options, jack_status_t* status, ...) { va_list ap; /* variable argument pointer */ jack_varargs_t va; /* variable arguments */ jack_status_t my_status; JackClient* client; + char client_name[JACK_CLIENT_NAME_SIZE]; + + JackTools::RewriteName(ext_client_name, client_name); if (status == NULL) /* no status from caller? */ status = &my_status; /* use local status word */ diff --git a/common/JackTools.cpp b/common/JackTools.cpp index 9a38f4e9..6b88196a 100644 --- a/common/JackTools.cpp +++ b/common/JackTools.cpp @@ -140,5 +140,47 @@ void JackTools::CleanupFiles(const char* server_name) } } +int JackTools::GetTmpdir() +{ + FILE* in; + size_t len; + char buf[PATH_MAX + 2]; /* allow tmpdir to live anywhere, plus newline, plus null */ + + if ((in = popen("jackd -l", "r")) == NULL) { + return -1; + } + + if (fgets(buf, sizeof(buf), in) == NULL) { + fclose(in); + return -1; + } + + len = strlen(buf); + + if (buf[len - 1] != '\n') { + /* didn't get a whole line */ + fclose(in); + return -1; + } + + jack_tmpdir = (char *)malloc(len); + memcpy(jack_tmpdir, buf, len - 1); + jack_tmpdir[len - 1] = '\0'; + + fclose(in); + return 0; +} + +void JackTools::RewriteName(const char* name, char* new_name) +{ + int i; + for (i = 0; i < strlen(name); i++) { + if ((name[i] == '/') || (name[i] == '\\')) + new_name[i] = '_'; + else + new_name[i] = name[i]; + } + new_name[i] = '\0'; +} } diff --git a/common/JackTools.h b/common/JackTools.h index 63940765..8a965c2b 100644 --- a/common/JackTools.h +++ b/common/JackTools.h @@ -40,6 +40,8 @@ namespace Jack static char* ServerDir(const char* server_name, char* server_dir); static char* DefaultServerName(); static void CleanupFiles(const char* server_name); + static int GetTmpdir(); + static void RewriteName(const char* name, char* new_name); }; }