speechd-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v3 3/3] Connect to socket if SPEECHD_ADDRESS begins with /


From: Boris Dušek
Subject: [PATCH v3 3/3] Connect to socket if SPEECHD_ADDRESS begins with /
Date: Sun, 29 Jul 2012 10:42:51 +0200

From: Boris Dus?ek <address@hidden>
To: address@hidden

On OS X, launchd can pass the location of a socket with random name it
creates only in an environment variable, with its value being the
absolute path to the socket. This environment variable is then set in
the whole user session and any clients should check its value to know
how to connect to the relevant service.

To adapt Speech Dispatcher client libraries to this, either we would
invent a new environment variable only for this
purpose (e.g. SPEECHD_LAUNCHD_ADDRESS) and honor it on OS X before
trying the traditional means of specifying the communication socket,
or we can use SPEECHD_ADDRESS by adding a new rule - any value
beginning with "/" is treated as path. This does not collide with the
current use of SPEECHD_ADDRESS - it begins with specifier of the
communication method and no specifier begins with "/". Also no IP or
DNS address begins with "/".

I chose the second variant since it does not require adding a new
environment variable to the mix, and might simplify the syntax for
some current users setting the socket path. But I admit it might be a
bit non-systematic.
---
 src/api/c/libspeechd.c           |    8 ++++++++
 src/api/python/speechd/client.py |    2 ++
 2 files changed, 10 insertions(+)

diff --git a/src/api/c/libspeechd.c b/src/api/c/libspeechd.c
index 25e5250..2901028 100644
--- a/src/api/c/libspeechd.c
+++ b/src/api/c/libspeechd.c
@@ -176,6 +176,14 @@ SPDConnectionAddress *spd_get_default_address(char **error)
        if (env_address == NULL) {      // Default method = unix sockets
                address->method = SPD_METHOD_UNIX_SOCKET;
                address->unix_socket_name = _get_default_unix_socket_name();
+       } else if (env_address[0] == '/') {
+               address->method = SPD_METHOD_UNIX_SOCKET;
+               address->unix_socket_name = strdup(env_address);
+               if (!address->unix_socket_name) {
+                       free(address);
+                       address = NULL;
+                       *error = strdup("Could not allocate memory for copying 
env_address");
+               }
        } else {
                pa = g_strsplit(env_address, ":", 0);
                assert(pa);
diff --git a/src/api/python/speechd/client.py b/src/api/python/speechd/client.py
index 8d34363..4bcaf85 100644
--- a/src/api/python/speechd/client.py
+++ b/src/api/python/speechd/client.py
@@ -549,6 +549,8 @@ class SSIPClient(object):
         _address = address or os.environ.get("SPEECHD_ADDRESS")        
 
         if _address:
+            if _address[0]='/':
+                _address = '%s:%s' % (CommunicationMethod.UNIX_SOCKET, 
_address,)
             
connection_args.update(self._connection_arguments_from_address(_address))
         # Respect the old (deprecated) key arguments and environment variables
         # TODO: Remove this section in 0.8 release
-- 
1.7.9.6 (Apple Git-31.1)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]