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 9, 2023
1 parent bb6b2de commit 04bc3af
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 50 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
80 changes: 30 additions & 50 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[MUMBLE_MAX_PATH];
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 NULL;
strcpy(path, buffer);
#elif defined(_WIN32)
path = strdup("");
#else
Expand All @@ -63,45 +46,42 @@ 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)
if ((path = malloc(strlen(home))) == NULL)
return NULL;
n += strlen(home);
if (home[(strlen(home) - 1)] != '/')
n++;
if ((path = malloc(n + 1)) == NULL)
return path;
strcpy(path, home);
if (home[(strlen(home) - 1)] != '/')
strcat(path, "/");
#endif
return path;
}

char *getAndCreateOverlayPipePath__() {
char *runtimePath = getRuntimePath__();
char *path = NULL;
char buffer[MUMBLE_MAX_PATH];
char *runtimePath = getRuntimePath__();
char *overlapyPipeFile = NULL;
char *path = NULL;
if (runtimePath == NULL)
return runtimePath;
return NULL;
#if _WIN32
/*
* on Windows we don't create the directory as getRuntimePath__() returns an empty string.
_mkdir(runtimePath);
*/
* _mkdir(runtimePath);
*/
#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");
size_t path_len = cwk_path_join(runtimePath, overlapyPipeFile, buffer, sizeof(buffer));
// if (path_len != strlen(path))
// path is too small. Result is truncated
if ((path = malloc(path_len)) == NULL)
return NULL;
strcpy(path, buffer);
free(runtimePath);
return path;
}
5 changes: 5 additions & 0 deletions overlay/ipc_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
#ifndef MUMBLE_OVERLAY_IPC_UTILS_H__
#define MUMBLE_OVERLAY_IPC_UTILS_H__

// can't trust POSIX's nor Window's PATH_MAX constants
// see: https://eklitzke.org/path-max-is-tricky
// https://stackoverflow.com/a/56385296
const int MUMBLE_MAX_PATH = 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 04bc3af

Please sign in to comment.