diff --git a/.gitmodules b/.gitmodules index c19da4099cd..18a0104cfb1 100644 --- a/.gitmodules +++ b/.gitmodules @@ -25,3 +25,6 @@ [submodule "3rdparty/SPSCQueue"] path = 3rdparty/SPSCQueue url = https://github.com/rigtorp/SPSCQueue.git +[submodule "3rdparty/cwalk"] + path = 3rdparty/cwalk + url = https://github.com/likle/cwalk.git diff --git a/3rdparty/cwalk b/3rdparty/cwalk new file mode 160000 index 00000000000..cfe8282fce9 --- /dev/null +++ b/3rdparty/cwalk @@ -0,0 +1 @@ +Subproject commit cfe8282fce9dcf14cfabe53a253084ff967cfbed diff --git a/overlay/ipc_utils.c b/overlay/ipc_utils.c index 30d0b6736b9..7b00b7e9824 100644 --- a/overlay/ipc_utils.c +++ b/overlay/ipc_utils.c @@ -4,6 +4,7 @@ // Mumble source tree or at . #include "ipc_utils.h" +#include #include #ifdef _WIN32 @@ -20,41 +21,23 @@ #endif char *getRuntimePath__() { - size_t n = 0; char *path = NULL; #ifdef __linux__ + char buffer[MAXPATHLEN]; char *xdgRuntimeDir = getenv("XDG_RUNTIME_DIR"); - - if (xdgRuntimeDir != NULL) { - if (xdgRuntimeDir) - n += strlen(xdgRuntimeDir); - if (xdgRuntimeDir[(strlen(xdgRuntimeDir) - 1)] != '/') - n++; - n += strlen("mumble/"); - - if ((path = malloc(n + 1)) == NULL) - return path; - *path = '\0'; - - strcpy(path, xdgRuntimeDir); - if (xdgRuntimeDir[(strlen(xdgRuntimeDir) - 1)] != '/') - strcat(path, "/"); - strcat(path, "mumble/"); - } else { + if (xdgRuntimeDir == NULL || !xdgRuntimeDir) { char uid[10]; - n += strlen("/run/user//mumble/"); sprintf(uid, "%d", getuid()); - n += strlen(uid); - - if ((path = malloc(n + 1)) == NULL) - return path; - *path = '\0'; - - strcpy(path, "/run/user/"); - strcat(path, uid); - strcat(path, "/mumble/"); + xdgRuntimeDir = "/run/user/"; + cwk_path_join(xdgRuntimeDir, uid, buffer, sizeof(buffer)); } + size_t path_len = cwk_path_join(xdgRuntimeDir, "mumble", buffer, sizeof(buffer)); + // if (path_len != strlen(buffer)) + // buffer is too small. Result is truncated + if ((path = malloc(path_len)) == NULL) + return path; + strcpy(path, buffer); #elif defined(_WIN32) path = strdup(""); #else @@ -63,23 +46,19 @@ char *getRuntimePath__() { struct passwd *pwent = getpwuid(getuid()); if (pwent && pwent->pw_dir && pwent->pw_dir[0]) home = pwent->pw_dir; + else + return NULL; } - if (home == NULL) - return NULL; - n += strlen(home); - if (home[(strlen(home) - 1)] != '/') - n++; - if ((path = malloc(n + 1)) == NULL) + if ((path = malloc(strlen(home))) == NULL) return path; strcpy(path, home); - if (home[(strlen(home) - 1)] != '/') - strcat(path, "/"); #endif return path; } char *getAndCreateOverlayPipePath__() { char *runtimePath = getRuntimePath__(); + char *overlapyPipeFile = NULL; char *path = NULL; if (runtimePath == NULL) return runtimePath; @@ -91,17 +70,19 @@ char *getAndCreateOverlayPipePath__() { #else mkdir(runtimePath, 0755); #endif - size_t n = 1; - n += strlen(runtimePath); - n += strlen("MumbleOverlayPipe"); - path = (char *) malloc(n + 1); - if (path == NULL) - return path; #if !defined __linux__ && !defined _WIN32 - strcat(path, "."); + overlapyPipeFile = ".MumbleOverlayPipe"; +#else + overlapyPipeFile = "MumbleOverlayPipe"; #endif - strcpy(path, runtimePath); - strcat(path, "MumbleOverlayPipe"); + if ((path = malloc(MAXPATHLEN)) == NULL) + return path; + cwk_path_join(runtimePath, overlapyPipeFile, path, MAXPATHLEN); + // fprintf(stderr, "runtimePath: %s -- overlapyPipeFile: %s -- path: %s -- sizeof(path): %zd\n", runtimePath, overlapyPipeFile, path, MAXPATHLEN); + // if (path_len != strlen(path)) + // buffer is too small. Result is truncated + if (path == NULL) + return path; free(runtimePath); return path; } \ No newline at end of file diff --git a/overlay/ipc_utils.h b/overlay/ipc_utils.h index 2fc91d0cb33..6688c59cef6 100644 --- a/overlay/ipc_utils.h +++ b/overlay/ipc_utils.h @@ -6,6 +6,8 @@ #ifndef MUMBLE_OVERLAY_IPC_UTILS_H__ #define MUMBLE_OVERLAY_IPC_UTILS_H__ +const int MAXPATHLEN = 1024; + char *getRuntimePath__(); char *getAndCreateOverlayPipePath__(); diff --git a/src/mumble/CMakeLists.txt b/src/mumble/CMakeLists.txt index ad07bda55c3..88001dd213a 100644 --- a/src/mumble/CMakeLists.txt +++ b/src/mumble/CMakeLists.txt @@ -26,6 +26,7 @@ option(bundled-speex "Build the included version of Speex instead of looking for option(rnnoise "Use RNNoise for machine learning noise reduction." ON) option(bundled-rnnoise "Build the included version of RNNoise instead of looking for one on the system." ${rnnoise}) option(bundled-json "Build the included version of nlohmann_json instead of looking for one on the system" ON) +option(bundled-cwalk "Build the included version of CWalk instead of looking for one on the system." ON) option(manual-plugin "Include the built-in \"manual\" positional audio plugin." ON) @@ -512,6 +513,15 @@ else() find_pkg("nlohmann_json" REQUIRED) endif() +if(bundled-cwalk) + add_subdirectory("${3RDPARTY_DIR}/cwalk" "${CMAKE_CURRENT_BINARY_DIR}/cwalk" EXCLUDE_FROM_ALL) + target_link_libraries(mumble_client_object_lib PUBLIC cwalk) + install_library(cwalk mumble_client) +else() + find_pkg(Cwalk REQUIRED) + target_link_libraries(mumble_client_object_lib PUBLIC cwalk) +endif() + target_link_libraries(mumble_client_object_lib PUBLIC nlohmann_json::nlohmann_json) find_pkg("SndFile;LibSndFile;sndfile" REQUIRED)