Skip to content

Commit

Permalink
CHANGE(ipc): ipc_utils now internally uses cwalk library
Browse files Browse the repository at this point in the history
  • Loading branch information
carlocastoldi committed Oct 8, 2023
1 parent bb6b2de commit 840cbee
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 45 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions 3rdparty/cwalk
Submodule cwalk added at cfe828
71 changes: 26 additions & 45 deletions overlay/ipc_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// Mumble source tree or at <https://www.mumble.info/LICENSE>.

#include "ipc_utils.h"
#include <cwalk.h>
#include <string.h>

#ifdef _WIN32
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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;
}
2 changes: 2 additions & 0 deletions overlay/ipc_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#ifndef MUMBLE_OVERLAY_IPC_UTILS_H__
#define MUMBLE_OVERLAY_IPC_UTILS_H__

const int MAXPATHLEN = 1024;

char *getRuntimePath__();

char *getAndCreateOverlayPipePath__();
Expand Down
10 changes: 10 additions & 0 deletions src/mumble/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 840cbee

Please sign in to comment.