changeset 1444:c04ce16b2b57 trunk

[svn] - libaudacious/beepctrl.c: optimise further and be more paranoid about leaks - audacious/main.c, main.h: add `session_uri_base' key. - audacious/controlsocket.c: TCP session code (no security yet, thus no public option)
author nenolod
date Fri, 28 Jul 2006 01:31:44 -0700
parents 2f714bee0645
children cdb339ef1b1a
files ChangeLog audacious/controlsocket.c audacious/main.c audacious/main.h libaudacious/beepctrl.c
diffstat 5 files changed, 78 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Jul 28 01:11:15 2006 -0700
+++ b/ChangeLog	Fri Jul 28 01:31:44 2006 -0700
@@ -1,3 +1,13 @@
+2006-07-28 08:11:15 +0000  William Pitcock <nenolod@nenolod.net>
+  revision [1800]
+  - prepare for tcp listener code
+  
+
+  Changes:        Modified:
+  +6 -0           trunk/audacious/controlsocket.c  
+  +2 -0           trunk/audacious/controlsocket.h  
+
+
 2006-07-28 08:07:14 +0000  William Pitcock <nenolod@nenolod.net>
   revision [1798]
   - more sanity
--- a/audacious/controlsocket.c	Fri Jul 28 01:11:15 2006 -0700
+++ b/audacious/controlsocket.c	Fri Jul 28 01:31:44 2006 -0700
@@ -31,6 +31,8 @@
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/un.h>
+#include <arpa/inet.h>
+#include <netdb.h>
 
 #include "main.h"
 #include "equalizer.h"
@@ -78,6 +80,11 @@
 gboolean
 ctrlsocket_setup(void)
 {
+    audacious_set_session_uri(cfg.session_uri_base);
+
+    if (!g_strncasecmp(cfg.session_uri_base, "tcp://", 6))
+	return ctrlsocket_setup_tcp();
+
     return ctrlsocket_setup_unix();
 }
 
@@ -137,6 +144,52 @@
     return FALSE;
 }
 
+gboolean
+ctrlsocket_setup_tcp(void)
+{
+    struct sockaddr_in saddr;
+    gint i;
+    gint fd;
+
+    if ((fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
+        g_critical("ctrlsocket_setup(): Failed to open socket: %s",
+                   strerror(errno));
+        return FALSE;
+    }
+
+    for (i = 0;; i++) {
+        saddr.sin_family = AF_INET;
+	saddr.sin_port = htons(37370 + i);
+
+        if (xmms_remote_is_running(i)) {
+            if (cfg.allow_multiple_instances)
+                continue;
+            break;
+        }
+
+        if (bind(fd, (struct sockaddr *) &saddr, sizeof(saddr)) == -1) {
+            g_critical
+                ("ctrlsocket_setup(): Failed to bind the socket (Error: %s)",
+                 strerror(errno));
+            break;
+        }
+
+        listen(fd, CTRLSOCKET_BACKLOG);
+
+        ctrl_fd = fd;
+        session_id = i;
+        going = TRUE;
+
+        ctrlsocket_start_thread();
+
+        return TRUE;
+    }
+
+    close(fd);
+
+    return FALSE;
+}
+
 gint
 ctrlsocket_get_session_id(void)
 {
@@ -158,8 +211,12 @@
         /* close and remove socket */
         close(ctrl_fd);
         ctrl_fd = 0;
-        unlink(socket_name);
-        g_free(socket_name);
+
+        if (socket_name != NULL)
+	{
+            unlink(socket_name);
+            g_free(socket_name);
+	}
 
         g_cond_free(start_cond);
         g_mutex_free(status_mutex);
--- a/audacious/main.c	Fri Jul 28 01:11:15 2006 -0700
+++ b/audacious/main.c	Fri Jul 28 01:31:44 2006 -0700
@@ -205,6 +205,9 @@
     TRUE,			/* show filepopup for tuple */
     NULL,			/* words identifying covers */
     NULL,			/* words that might not show up in cover names */
+    FALSE,
+    0,
+    NULL,			/* default session uri base (non-NULL = custom session uri base) */
 };
 
 typedef struct bmp_cfg_boolent_t {
@@ -351,6 +354,7 @@
     {"chardet_fallback", &cfg.chardet_fallback, TRUE},
     {"cover_name_include", &cfg.cover_name_include, TRUE},
     {"cover_name_exclude", &cfg.cover_name_exclude, TRUE},
+    {"session_uri_base", &cfg.session_uri_base, TRUE}
 };
 
 static gint ncfgsent = G_N_ELEMENTS(bmp_strents);
--- a/audacious/main.h	Fri Jul 28 01:11:15 2006 -0700
+++ b/audacious/main.h	Fri Jul 28 01:31:44 2006 -0700
@@ -115,6 +115,7 @@
     gchar *cover_name_include, *cover_name_exclude;
     gboolean recurse_for_cover;
     gint recurse_for_cover_depth;
+    gchar *session_uri_base;
 };
 
 typedef struct _BmpConfig BmpConfig;
--- a/libaudacious/beepctrl.c	Fri Jul 28 01:11:15 2006 -0700
+++ b/libaudacious/beepctrl.c	Fri Jul 28 01:31:44 2006 -0700
@@ -309,13 +309,13 @@
     ConfigDb *db;
     gchar *value = NULL;
 
-    db = bmp_cfg_db_open();
-
     if (audacious_session_uri != NULL)
     {
 	return audacious_session_uri;
     }
 
+    db = bmp_cfg_db_open();
+
     bmp_cfg_db_get_string(db, NULL, "session_uri_base", &value);
 
     bmp_cfg_db_close(db);
@@ -324,6 +324,8 @@
         return g_strdup_printf("unix://localhost/%s/%s_%s.%d", g_get_tmp_dir(),
 		CTRLSOCKET_NAME, g_get_user_name(), session);
 
+    audacious_session_uri = value;
+
     return value;
 }