From 6509fea778f6f873e738129d0438773ea2826641 Mon Sep 17 00:00:00 2001
From: Koichiro IWAO
Date: Fri, 24 Aug 2018 15:58:44 +0900
Subject: [PATCH] pass sockets names via environment variable
now this module no longer depends on xrdp headers.
---
src/module-xrdp-sink.c | 15 ++++++++++-----
src/module-xrdp-source.c | 15 ++++++++++-----
2 files changed, 20 insertions(+), 10 deletions(-)
diff --git a/src/module-xrdp-sink.c b/src/module-xrdp-sink.c
index 5daaf85..1dd11b9 100644
--- a/src/module-xrdp-sink.c
+++ b/src/module-xrdp-sink.c
@@ -59,9 +59,6 @@
#include
#include
-#include
-
-
/* defined in pulse/version.h */
#if PA_PROTOCOL_VERSION > 28
/* these used to be defined in pulsecore/macro.h */
@@ -297,6 +294,7 @@ static int lsend(int fd, char *data, int bytes) {
static int data_send(struct userdata *u, pa_memchunk *chunk) {
char *data;
char *socket_dir;
+ char *sink_socket;
int bytes;
int sent;
int fd;
@@ -318,9 +316,16 @@ static int data_send(struct userdata *u, pa_memchunk *chunk) {
{
socket_dir = "/tmp/.xrdp";
}
- snprintf(s.sun_path, bytes, "%s/" CHANSRV_PORT_OUT_BASE_STR,
- socket_dir, u->display_num);
+ sink_socket = getenv("CHANSRV_PULSE_SINK_SOCKET");
+ if (sink_socket == NULL || sink_socket[0] == '\0')
+ {
+ /* usually it doesn't reach here. if the socket name is not given
+ via environment variable, use hardcoded name as fallback */
+ snprintf(sink_socket, bytes, "xrdp_chansrv_audio_out_socket_%d", u->display_num);
+ }
+ snprintf(s.sun_path, bytes, "%s/%s", socket_dir, sink_socket);
pa_log_debug("trying to connect to %s", s.sun_path);
+
if (connect(fd, (struct sockaddr *)&s,
sizeof(struct sockaddr_un)) != 0) {
u->failed_connect_time = pa_rtclock_now();
diff --git a/src/module-xrdp-source.c b/src/module-xrdp-source.c
index a8ec94b..652a07b 100644
--- a/src/module-xrdp-source.c
+++ b/src/module-xrdp-source.c
@@ -46,9 +46,6 @@
#include
#include
-#include
-
-
/* defined in pulse/version.h */
#if PA_PROTOCOL_VERSION > 28
/* these used to be defined in pulsecore/macro.h */
@@ -181,6 +178,7 @@ static int data_get(struct userdata *u, pa_memchunk *chunk) {
struct sockaddr_un s;
char *data;
char *socket_dir;
+ char *source_socket;
char buf[11];
unsigned char ubuf[10];
@@ -195,8 +193,15 @@ static int data_get(struct userdata *u, pa_memchunk *chunk) {
{
socket_dir = "/tmp/.xrdp";
}
- snprintf(s.sun_path, bytes, "%s/" CHANSRV_PORT_IN_BASE_STR,
- socket_dir, u->display_num);
+ source_socket = getenv("CHANSRV_PULSE_SINK_SOCKET");
+ if (source_socket == NULL || source_socket[0] == '\0')
+ {
+
+ /* usually it doesn't reach here. if the socket name is not given
+ via environment variable, use hardcoded name as fallback */
+ snprintf(source_socket, bytes, "xrdp_chansrv_audio_in_socket_%d", u->display_num);
+ }
+ snprintf(s.sun_path, bytes, "%s/%s", socket_dir, source_socket);
pa_log_debug("Trying to connect to %s", s.sun_path);
if (connect(fd, (struct sockaddr *) &s, sizeof(struct sockaddr_un)) != 0) {