Mercurial > audlegacy
annotate libaudacious/beepctrl.c @ 2008:efe4e38ffa32 trunk
[svn] - update Welsh translation:
407 strings (0 fuzzy, 0 bad tokens, 16 not translated)
| author | nenolod |
|---|---|
| date | Sat, 25 Nov 2006 19:13:55 -0800 |
| parents | c97cd4a8c470 |
| children | 0985452d1962 |
| rev | line source |
|---|---|
| 0 | 1 /* XMMS - Cross-platform multimedia player |
| 2 * Copyright (C) 1998-2003 Peter Alm, Mikael Alm, Olle Hallnas, | |
| 3 * Thomas Nilsson and 4Front Technologies | |
| 4 * Copyright (C) 1999-2003 Haavard Kvaalen | |
| 5 * | |
| 6 * This program is free software; you can redistribute it and/or modify | |
| 7 * it under the terms of the GNU General Public License as published by | |
| 8 * the Free Software Foundation; either version 2 of the License, or | |
| 9 * (at your option) any later version. | |
| 10 * | |
| 11 * This program is distributed in the hope that it will be useful, | |
| 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 * GNU General Public License for more details. | |
| 15 * | |
| 16 * You should have received a copy of the GNU General Public License | |
| 17 * along with this program; if not, write to the Free Software | |
| 1459 | 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 0 | 19 */ |
| 20 | |
| 21 #ifdef HAVE_CONFIG_H | |
| 22 # include "config.h" | |
| 23 #endif | |
| 24 | |
| 25 #include <glib.h> | |
| 26 #include <sys/types.h> | |
| 27 #include <sys/stat.h> | |
| 28 #include <sys/socket.h> | |
| 29 #include <sys/un.h> | |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
30 #include <arpa/inet.h> |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
31 #include <netdb.h> |
| 0 | 32 #include <errno.h> |
| 33 #include <stdio.h> | |
| 34 #include <stdlib.h> | |
| 35 #include <string.h> | |
| 36 #include "beepctrl.h" | |
| 37 #include "audacious/controlsocket.h" | |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
38 #include "libaudacious/configdb.h" |
| 0 | 39 |
| 1583 | 40 #include <netdb.h> |
| 41 #include <netinet/in.h> | |
| 42 #include <unistd.h> | |
| 43 #include <grp.h> | |
| 44 #include <sys/time.h> | |
| 45 #include <sys/wait.h> | |
| 46 #include <sys/resource.h> | |
| 47 #include <sys/socket.h> | |
| 48 #include <fcntl.h> | |
| 49 #include <arpa/inet.h> | |
| 50 | |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
51 /* overrides audacious_get_session_uri(). */ |
| 1438 | 52 gchar *audacious_session_uri = NULL; |
|
1456
6fe7ba6e5489
[svn] - Don't poll the config database if not using TCP sockets.
nhjm449
parents:
1450
diff
changeset
|
53 gint *audacious_session_type = NULL; |
| 0 | 54 |
| 55 #ifdef HAVE_UNISTD_H | |
| 56 #include <unistd.h> | |
| 57 #endif | |
| 58 | |
| 59 static gpointer | |
|
2002
c97cd4a8c470
[svn] - cleanup the controlsocket code. (nenolod + help from ticpu)
nenolod
parents:
1869
diff
changeset
|
60 remote_read_packet(gint fd) |
| 0 | 61 { |
| 62 gpointer data = NULL; | |
|
2002
c97cd4a8c470
[svn] - cleanup the controlsocket code. (nenolod + help from ticpu)
nenolod
parents:
1869
diff
changeset
|
63 ServerPktHeader pkt_hdr = { 0, 0 }; |
|
1766
6cbb9360e8e2
[svn] - always zero-out stack variables, as stack memory may be dirty on x86 and friends
nenolod
parents:
1583
diff
changeset
|
64 |
|
2002
c97cd4a8c470
[svn] - cleanup the controlsocket code. (nenolod + help from ticpu)
nenolod
parents:
1869
diff
changeset
|
65 if (read(fd, &pkt_hdr, sizeof(ServerPktHeader)) == |
|
c97cd4a8c470
[svn] - cleanup the controlsocket code. (nenolod + help from ticpu)
nenolod
parents:
1869
diff
changeset
|
66 sizeof(ServerPktHeader)) |
|
c97cd4a8c470
[svn] - cleanup the controlsocket code. (nenolod + help from ticpu)
nenolod
parents:
1869
diff
changeset
|
67 { |
|
c97cd4a8c470
[svn] - cleanup the controlsocket code. (nenolod + help from ticpu)
nenolod
parents:
1869
diff
changeset
|
68 if (pkt_hdr.version == XMMS_PROTOCOL_VERSION && |
|
c97cd4a8c470
[svn] - cleanup the controlsocket code. (nenolod + help from ticpu)
nenolod
parents:
1869
diff
changeset
|
69 pkt_hdr.data_length > 0) |
|
c97cd4a8c470
[svn] - cleanup the controlsocket code. (nenolod + help from ticpu)
nenolod
parents:
1869
diff
changeset
|
70 { |
|
c97cd4a8c470
[svn] - cleanup the controlsocket code. (nenolod + help from ticpu)
nenolod
parents:
1869
diff
changeset
|
71 size_t data_length = pkt_hdr.data_length; |
| 0 | 72 data = g_malloc0(data_length); |
|
2002
c97cd4a8c470
[svn] - cleanup the controlsocket code. (nenolod + help from ticpu)
nenolod
parents:
1869
diff
changeset
|
73 if ((size_t)read(fd, data, data_length) < data_length) |
|
c97cd4a8c470
[svn] - cleanup the controlsocket code. (nenolod + help from ticpu)
nenolod
parents:
1869
diff
changeset
|
74 { |
| 0 | 75 g_free(data); |
| 76 data = NULL; | |
| 77 } | |
| 78 } | |
| 79 } | |
|
2002
c97cd4a8c470
[svn] - cleanup the controlsocket code. (nenolod + help from ticpu)
nenolod
parents:
1869
diff
changeset
|
80 |
| 0 | 81 return data; |
| 82 } | |
| 83 | |
| 84 static void | |
| 85 remote_read_ack(gint fd) | |
| 86 { | |
| 87 gpointer data; | |
| 88 | |
|
2002
c97cd4a8c470
[svn] - cleanup the controlsocket code. (nenolod + help from ticpu)
nenolod
parents:
1869
diff
changeset
|
89 data = remote_read_packet(fd); |
| 0 | 90 if (data) |
| 91 g_free(data); | |
| 92 | |
| 93 } | |
| 94 | |
| 95 static void | |
| 96 remote_send_packet(gint fd, guint32 command, gpointer data, | |
| 97 guint32 data_length) | |
| 98 { | |
| 99 ClientPktHeader pkt_hdr; | |
| 100 | |
|
1766
6cbb9360e8e2
[svn] - always zero-out stack variables, as stack memory may be dirty on x86 and friends
nenolod
parents:
1583
diff
changeset
|
101 memset(&pkt_hdr, '\0', sizeof(ClientPktHeader)); |
|
6cbb9360e8e2
[svn] - always zero-out stack variables, as stack memory may be dirty on x86 and friends
nenolod
parents:
1583
diff
changeset
|
102 |
| 0 | 103 pkt_hdr.version = XMMS_PROTOCOL_VERSION; |
| 104 pkt_hdr.command = command; | |
| 105 pkt_hdr.data_length = data_length; | |
|
1582
d7af2755a397
[svn] - gcc 4.1.0, 4.1.1, 4.1.2 tree optimization workaround:
nenolod
parents:
1581
diff
changeset
|
106 if ((size_t)write(fd, &pkt_hdr, sizeof(ClientPktHeader)) < sizeof(pkt_hdr)) |
| 0 | 107 return; |
| 108 if (data_length && data) | |
|
1582
d7af2755a397
[svn] - gcc 4.1.0, 4.1.1, 4.1.2 tree optimization workaround:
nenolod
parents:
1581
diff
changeset
|
109 write(fd, data, data_length); |
| 0 | 110 } |
| 111 | |
| 112 static void | |
| 113 remote_send_guint32(gint session, guint32 cmd, guint32 val) | |
| 114 { | |
| 115 gint fd; | |
| 116 | |
| 117 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 118 return; | |
| 119 remote_send_packet(fd, cmd, &val, sizeof(guint32)); | |
| 120 remote_read_ack(fd); | |
| 121 close(fd); | |
| 122 } | |
| 123 | |
| 124 static void | |
| 125 remote_send_boolean(gint session, guint32 cmd, gboolean val) | |
| 126 { | |
| 127 gint fd; | |
| 128 | |
| 129 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 130 return; | |
| 131 remote_send_packet(fd, cmd, &val, sizeof(gboolean)); | |
| 132 remote_read_ack(fd); | |
| 133 close(fd); | |
| 134 } | |
| 135 | |
| 136 static void | |
| 137 remote_send_gfloat(gint session, guint32 cmd, gfloat value) | |
| 138 { | |
| 139 gint fd; | |
| 140 | |
| 141 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 142 return; | |
| 143 remote_send_packet(fd, cmd, &value, sizeof(gfloat)); | |
| 144 remote_read_ack(fd); | |
| 145 close(fd); | |
| 146 } | |
| 147 | |
| 148 static void | |
| 149 remote_send_string(gint session, guint32 cmd, gchar * string) | |
| 150 { | |
| 151 gint fd; | |
| 152 | |
| 153 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 154 return; | |
| 155 remote_send_packet(fd, cmd, string, string ? strlen(string) + 1 : 0); | |
| 156 remote_read_ack(fd); | |
| 157 close(fd); | |
| 158 } | |
| 159 | |
| 160 static gboolean | |
| 161 remote_cmd(gint session, guint32 cmd) | |
| 162 { | |
| 163 gint fd; | |
| 164 | |
| 165 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 166 return FALSE; | |
| 167 remote_send_packet(fd, cmd, NULL, 0); | |
| 168 remote_read_ack(fd); | |
| 169 close(fd); | |
| 170 | |
| 171 return TRUE; | |
| 172 } | |
| 173 | |
| 174 static gboolean | |
| 175 remote_get_gboolean(gint session, gint cmd) | |
| 176 { | |
| 177 gboolean ret = FALSE; | |
| 178 gpointer data; | |
| 179 gint fd; | |
| 180 | |
| 181 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 182 return ret; | |
| 183 remote_send_packet(fd, cmd, NULL, 0); | |
|
2002
c97cd4a8c470
[svn] - cleanup the controlsocket code. (nenolod + help from ticpu)
nenolod
parents:
1869
diff
changeset
|
184 data = remote_read_packet(fd); |
| 0 | 185 if (data) { |
| 186 ret = *((gboolean *) data); | |
| 187 g_free(data); | |
| 188 } | |
| 189 remote_read_ack(fd); | |
| 190 close(fd); | |
| 191 | |
| 192 return ret; | |
| 193 } | |
| 194 | |
| 195 static guint32 | |
| 196 remote_get_gint(gint session, gint cmd) | |
| 197 { | |
| 198 gpointer data; | |
| 199 gint fd, ret = 0; | |
| 200 | |
| 201 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 202 return ret; | |
| 203 remote_send_packet(fd, cmd, NULL, 0); | |
|
2002
c97cd4a8c470
[svn] - cleanup the controlsocket code. (nenolod + help from ticpu)
nenolod
parents:
1869
diff
changeset
|
204 data = remote_read_packet(fd); |
| 0 | 205 if (data) { |
| 206 ret = *((gint *) data); | |
| 207 g_free(data); | |
| 208 } | |
| 209 remote_read_ack(fd); | |
| 210 close(fd); | |
| 211 return ret; | |
| 212 } | |
| 213 | |
| 214 static gfloat | |
| 215 remote_get_gfloat(gint session, gint cmd) | |
| 216 { | |
| 217 gpointer data; | |
| 218 gint fd; | |
| 219 gfloat ret = 0.0; | |
| 220 | |
| 221 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 222 return ret; | |
| 223 remote_send_packet(fd, cmd, NULL, 0); | |
|
2002
c97cd4a8c470
[svn] - cleanup the controlsocket code. (nenolod + help from ticpu)
nenolod
parents:
1869
diff
changeset
|
224 data = remote_read_packet(fd); |
| 0 | 225 if (data) { |
| 226 ret = *((gfloat *) data); | |
| 227 g_free(data); | |
| 228 } | |
| 229 remote_read_ack(fd); | |
| 230 close(fd); | |
| 231 return ret; | |
| 232 } | |
| 233 | |
| 234 gchar * | |
| 235 remote_get_string(gint session, gint cmd) | |
| 236 { | |
| 237 gpointer data; | |
| 238 gint fd; | |
| 239 | |
| 240 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 241 return NULL; | |
| 242 remote_send_packet(fd, cmd, NULL, 0); | |
|
2002
c97cd4a8c470
[svn] - cleanup the controlsocket code. (nenolod + help from ticpu)
nenolod
parents:
1869
diff
changeset
|
243 data = remote_read_packet(fd); |
| 0 | 244 remote_read_ack(fd); |
| 245 close(fd); | |
| 246 return data; | |
| 247 } | |
| 248 | |
| 249 gchar * | |
| 250 remote_get_string_pos(gint session, gint cmd, guint32 pos) | |
| 251 { | |
| 252 gpointer data; | |
| 253 gint fd; | |
| 254 | |
| 255 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 256 return NULL; | |
| 257 remote_send_packet(fd, cmd, &pos, sizeof(guint32)); | |
|
2002
c97cd4a8c470
[svn] - cleanup the controlsocket code. (nenolod + help from ticpu)
nenolod
parents:
1869
diff
changeset
|
258 data = remote_read_packet(fd); |
| 0 | 259 remote_read_ack(fd); |
| 260 close(fd); | |
| 261 return data; | |
| 262 } | |
| 263 | |
| 1437 | 264 void |
| 265 audacious_set_session_uri(gchar *uri) | |
| 266 { | |
| 1438 | 267 audacious_session_uri = uri; |
| 1437 | 268 } |
| 269 | |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
270 gchar * |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
271 audacious_get_session_uri(gint session) |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
272 { |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
273 ConfigDb *db; |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
274 gchar *value = NULL; |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
275 |
| 1438 | 276 if (audacious_session_uri != NULL) |
| 277 { | |
|
1869
b7cac9c9c4a1
[svn] - audacious_determine_session_type() would crash if audacious_session_uri had value.
yaz
parents:
1766
diff
changeset
|
278 return g_strdup(audacious_session_uri); |
| 1438 | 279 } |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
280 |
|
1456
6fe7ba6e5489
[svn] - Don't poll the config database if not using TCP sockets.
nhjm449
parents:
1450
diff
changeset
|
281 if (audacious_session_type != AUDACIOUS_TYPE_UNIX) |
|
6fe7ba6e5489
[svn] - Don't poll the config database if not using TCP sockets.
nhjm449
parents:
1450
diff
changeset
|
282 { |
|
6fe7ba6e5489
[svn] - Don't poll the config database if not using TCP sockets.
nhjm449
parents:
1450
diff
changeset
|
283 db = bmp_cfg_db_open(); |
|
1444
c04ce16b2b57
[svn] - libaudacious/beepctrl.c: optimise further and be more paranoid about leaks
nenolod
parents:
1442
diff
changeset
|
284 |
|
1456
6fe7ba6e5489
[svn] - Don't poll the config database if not using TCP sockets.
nhjm449
parents:
1450
diff
changeset
|
285 bmp_cfg_db_get_string(db, NULL, "listen_uri_base", &value); |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
286 |
|
1456
6fe7ba6e5489
[svn] - Don't poll the config database if not using TCP sockets.
nhjm449
parents:
1450
diff
changeset
|
287 bmp_cfg_db_close(db); |
|
6fe7ba6e5489
[svn] - Don't poll the config database if not using TCP sockets.
nhjm449
parents:
1450
diff
changeset
|
288 } |
| 1442 | 289 |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
290 if (value == NULL) |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
291 return g_strdup_printf("unix://localhost/%s/%s_%s.%d", g_get_tmp_dir(), |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
292 CTRLSOCKET_NAME, g_get_user_name(), session); |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
293 |
|
1444
c04ce16b2b57
[svn] - libaudacious/beepctrl.c: optimise further and be more paranoid about leaks
nenolod
parents:
1442
diff
changeset
|
294 audacious_session_uri = value; |
|
c04ce16b2b57
[svn] - libaudacious/beepctrl.c: optimise further and be more paranoid about leaks
nenolod
parents:
1442
diff
changeset
|
295 |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
296 return value; |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
297 } |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
298 |
|
1456
6fe7ba6e5489
[svn] - Don't poll the config database if not using TCP sockets.
nhjm449
parents:
1450
diff
changeset
|
299 void |
|
6fe7ba6e5489
[svn] - Don't poll the config database if not using TCP sockets.
nhjm449
parents:
1450
diff
changeset
|
300 audacious_set_session_type(gint *type) |
|
6fe7ba6e5489
[svn] - Don't poll the config database if not using TCP sockets.
nhjm449
parents:
1450
diff
changeset
|
301 { |
|
6fe7ba6e5489
[svn] - Don't poll the config database if not using TCP sockets.
nhjm449
parents:
1450
diff
changeset
|
302 audacious_session_type = type; |
|
6fe7ba6e5489
[svn] - Don't poll the config database if not using TCP sockets.
nhjm449
parents:
1450
diff
changeset
|
303 } |
|
6fe7ba6e5489
[svn] - Don't poll the config database if not using TCP sockets.
nhjm449
parents:
1450
diff
changeset
|
304 |
|
6fe7ba6e5489
[svn] - Don't poll the config database if not using TCP sockets.
nhjm449
parents:
1450
diff
changeset
|
305 gint * |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
306 audacious_determine_session_type(gint session) |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
307 { |
|
1869
b7cac9c9c4a1
[svn] - audacious_determine_session_type() would crash if audacious_session_uri had value.
yaz
parents:
1766
diff
changeset
|
308 gchar *uri = NULL; |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
309 |
|
1456
6fe7ba6e5489
[svn] - Don't poll the config database if not using TCP sockets.
nhjm449
parents:
1450
diff
changeset
|
310 if (audacious_session_type != NULL) |
|
6fe7ba6e5489
[svn] - Don't poll the config database if not using TCP sockets.
nhjm449
parents:
1450
diff
changeset
|
311 { |
|
6fe7ba6e5489
[svn] - Don't poll the config database if not using TCP sockets.
nhjm449
parents:
1450
diff
changeset
|
312 return audacious_session_type; |
|
6fe7ba6e5489
[svn] - Don't poll the config database if not using TCP sockets.
nhjm449
parents:
1450
diff
changeset
|
313 } |
|
6fe7ba6e5489
[svn] - Don't poll the config database if not using TCP sockets.
nhjm449
parents:
1450
diff
changeset
|
314 |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
315 uri = audacious_get_session_uri(session); |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
316 |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
317 if (!g_strncasecmp(uri, "tcp://", 6)) |
|
1456
6fe7ba6e5489
[svn] - Don't poll the config database if not using TCP sockets.
nhjm449
parents:
1450
diff
changeset
|
318 audacious_session_type = (gint *) AUDACIOUS_TYPE_TCP; |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
319 else |
|
1456
6fe7ba6e5489
[svn] - Don't poll the config database if not using TCP sockets.
nhjm449
parents:
1450
diff
changeset
|
320 audacious_session_type = (gint *) AUDACIOUS_TYPE_UNIX; |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
321 |
|
1456
6fe7ba6e5489
[svn] - Don't poll the config database if not using TCP sockets.
nhjm449
parents:
1450
diff
changeset
|
322 if (audacious_session_type == NULL) |
|
6fe7ba6e5489
[svn] - Don't poll the config database if not using TCP sockets.
nhjm449
parents:
1450
diff
changeset
|
323 audacious_session_type = (gint *) AUDACIOUS_TYPE_UNIX; |
|
6fe7ba6e5489
[svn] - Don't poll the config database if not using TCP sockets.
nhjm449
parents:
1450
diff
changeset
|
324 |
| 1500 | 325 /* memory leak! */ |
| 326 g_free(uri); | |
| 327 | |
|
1456
6fe7ba6e5489
[svn] - Don't poll the config database if not using TCP sockets.
nhjm449
parents:
1450
diff
changeset
|
328 return audacious_session_type; |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
329 } |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
330 |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
331 /* tcp://192.168.100.1:5900/zyzychynxi389xvmfewqaxznvnw */ |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
332 void |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
333 audacious_decode_tcp_uri(gint session, gchar *in, gchar **host, gint *port, gchar **key) |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
334 { |
| 1439 | 335 static gchar *workbuf, *keybuf; |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
336 gint iport; |
| 1439 | 337 gchar *tmp = g_strdup(in); |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
338 |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
339 /* split out the host/port and key */ |
| 1439 | 340 workbuf = tmp; |
|
1448
3b1c464cbbb0
[svn] Seems safer to me to free this way, assuming I'm not misreading.
nemo
parents:
1447
diff
changeset
|
341 workbuf += 6; |
| 1439 | 342 |
|
1448
3b1c464cbbb0
[svn] Seems safer to me to free this way, assuming I'm not misreading.
nemo
parents:
1447
diff
changeset
|
343 keybuf = strchr(workbuf, '/'); |
| 1439 | 344 *keybuf++ = '\0'; |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
345 |
|
1441
ed80e946f30b
[svn] - ok, don't eat up all the system ram (I forgot to g_free())
nenolod
parents:
1439
diff
changeset
|
346 *key = g_strdup(keybuf); |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
347 |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
348 if (strchr(workbuf, ':') == NULL) |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
349 { |
|
1441
ed80e946f30b
[svn] - ok, don't eat up all the system ram (I forgot to g_free())
nenolod
parents:
1439
diff
changeset
|
350 *host = g_strdup(workbuf); |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
351 *port = 37370 + session; |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
352 } |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
353 else |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
354 { |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
355 gchar *hostbuf = NULL; |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
356 sscanf(workbuf, "%s:%d", hostbuf, &iport); |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
357 |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
358 *port = iport + session; |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
359 } |
|
1441
ed80e946f30b
[svn] - ok, don't eat up all the system ram (I forgot to g_free())
nenolod
parents:
1439
diff
changeset
|
360 |
| 1447 | 361 g_free(tmp); |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
362 } |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
363 |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
364 /* unix://localhost/tmp/audacious_nenolod.0 */ |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
365 void |
| 1439 | 366 audacious_decode_unix_uri(gint session, gchar *in, gchar **key) |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
367 { |
| 1439 | 368 static gchar *workbuf, *keybuf; |
| 369 gchar *tmp = g_strdup(in); | |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
370 |
| 1439 | 371 /* split out the host/port and key */ |
| 372 workbuf = tmp; | |
|
1448
3b1c464cbbb0
[svn] Seems safer to me to free this way, assuming I'm not misreading.
nemo
parents:
1447
diff
changeset
|
373 workbuf += 7; |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
374 |
|
1448
3b1c464cbbb0
[svn] Seems safer to me to free this way, assuming I'm not misreading.
nemo
parents:
1447
diff
changeset
|
375 keybuf = strchr(workbuf, '/'); |
| 1439 | 376 *keybuf++ = '\0'; |
| 377 | |
|
1441
ed80e946f30b
[svn] - ok, don't eat up all the system ram (I forgot to g_free())
nenolod
parents:
1439
diff
changeset
|
378 *key = g_strdup(keybuf); |
|
ed80e946f30b
[svn] - ok, don't eat up all the system ram (I forgot to g_free())
nenolod
parents:
1439
diff
changeset
|
379 |
| 1447 | 380 g_free(tmp); |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
381 } |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
382 |
| 0 | 383 gint |
| 384 xmms_connect_to_session(gint session) | |
| 385 { | |
| 386 gint fd; | |
|
1456
6fe7ba6e5489
[svn] - Don't poll the config database if not using TCP sockets.
nhjm449
parents:
1450
diff
changeset
|
387 gint *type = audacious_determine_session_type(session); |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
388 gchar *uri = audacious_get_session_uri(session); |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
389 |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
390 if (type == AUDACIOUS_TYPE_UNIX) |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
391 { |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
392 if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) != -1) |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
393 { |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
394 uid_t stored_uid, euid; |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
395 struct sockaddr_un saddr; |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
396 gchar *path; |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
397 |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
398 saddr.sun_family = AF_UNIX; |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
399 stored_uid = getuid(); |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
400 euid = geteuid(); |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
401 setuid(euid); |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
402 |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
403 audacious_decode_unix_uri(session, uri, &path); |
| 0 | 404 |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
405 g_strlcpy(saddr.sun_path, path, 108); |
|
1441
ed80e946f30b
[svn] - ok, don't eat up all the system ram (I forgot to g_free())
nenolod
parents:
1439
diff
changeset
|
406 g_free(path); |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
407 setreuid(stored_uid, euid); |
| 1501 | 408 |
| 409 g_free(uri); | |
| 410 | |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
411 if (connect(fd, (struct sockaddr *) &saddr, sizeof(saddr)) != -1) |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
412 return fd; |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
413 } |
| 0 | 414 } |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
415 else |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
416 { |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
417 if ((fd = socket(AF_INET, SOCK_STREAM, 0)) != -1) |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
418 { |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
419 struct hostent *hp; |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
420 struct sockaddr_in saddr; |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
421 gchar *host, *key; |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
422 gint port; |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
423 |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
424 audacious_decode_tcp_uri(session, uri, &host, &port, &key); |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
425 |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
426 /* resolve it */ |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
427 if ((hp = gethostbyname(host)) == NULL) |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
428 { |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
429 close(fd); |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
430 return -1; |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
431 } |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
432 |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
433 memset(&saddr, '\0', sizeof(saddr)); |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
434 saddr.sin_family = AF_INET; |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
435 saddr.sin_port = htons(port); |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
436 memcpy(&saddr.sin_addr, hp->h_addr, hp->h_length); |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
437 |
|
1441
ed80e946f30b
[svn] - ok, don't eat up all the system ram (I forgot to g_free())
nenolod
parents:
1439
diff
changeset
|
438 g_free(host); |
|
ed80e946f30b
[svn] - ok, don't eat up all the system ram (I forgot to g_free())
nenolod
parents:
1439
diff
changeset
|
439 g_free(key); |
|
ed80e946f30b
[svn] - ok, don't eat up all the system ram (I forgot to g_free())
nenolod
parents:
1439
diff
changeset
|
440 |
| 1501 | 441 g_free(uri); |
| 442 | |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
443 if (connect(fd, (struct sockaddr *) &saddr, sizeof(saddr)) != -1) |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
444 return fd; |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
445 } |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
446 } |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
447 |
| 0 | 448 close(fd); |
| 449 return -1; | |
| 450 } | |
| 451 | |
| 452 void | |
| 453 xmms_remote_playlist(gint session, gchar ** list, gint num, gboolean enqueue) | |
| 454 { | |
| 455 gint fd, i; | |
| 456 gchar *data, *ptr; | |
| 457 gint data_length; | |
| 458 guint32 len; | |
| 459 | |
| 460 g_return_if_fail(list != NULL); | |
| 461 g_return_if_fail(num > 0); | |
| 462 | |
| 463 if (!enqueue) | |
| 464 xmms_remote_playlist_clear(session); | |
| 465 | |
| 466 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 467 return; | |
| 468 | |
| 469 for (i = 0, data_length = 0; i < num; i++) | |
| 470 data_length += (((strlen(list[i]) + 1) + 3) / 4) * 4 + 4; | |
| 471 if (data_length) { | |
| 472 data_length += 4; | |
| 473 data = g_malloc(data_length); | |
| 474 for (i = 0, ptr = data; i < num; i++) { | |
| 475 len = strlen(list[i]) + 1; | |
| 476 *((guint32 *) ptr) = len; | |
| 477 ptr += 4; | |
| 478 memcpy(ptr, list[i], len); | |
| 479 ptr += ((len + 3) / 4) * 4; | |
| 480 } | |
| 481 *((guint32 *) ptr) = 0; | |
| 482 remote_send_packet(fd, CMD_PLAYLIST_ADD, data, data_length); | |
| 483 remote_read_ack(fd); | |
| 484 close(fd); | |
| 485 g_free(data); | |
| 486 } | |
| 487 | |
| 488 if (!enqueue) | |
| 489 xmms_remote_play(session); | |
| 490 } | |
| 491 | |
| 492 gint | |
| 493 xmms_remote_get_version(gint session) | |
| 494 { | |
| 495 return remote_get_gint(session, CMD_GET_VERSION); | |
| 496 } | |
| 497 | |
| 498 void | |
| 499 xmms_remote_play_files(gint session, GList * list) | |
| 500 { | |
| 501 g_return_if_fail(list != NULL); | |
| 502 | |
| 503 xmms_remote_playlist_clear(session); | |
| 504 xmms_remote_add_files(session, list); | |
| 505 xmms_remote_play(session); | |
| 506 } | |
| 507 | |
| 508 void | |
| 509 xmms_remote_playlist_add(gint session, GList * list) | |
| 510 { | |
| 511 gchar **str_list; | |
| 512 GList *node; | |
| 513 gint i, num; | |
| 514 | |
| 515 g_return_if_fail(list != NULL); | |
| 516 | |
| 517 num = g_list_length(list); | |
| 518 str_list = g_malloc0(num * sizeof(gchar *)); | |
| 519 for (i = 0, node = list; i < num && node; i++, node = g_list_next(node)) | |
| 520 str_list[i] = node->data; | |
| 521 | |
| 522 xmms_remote_playlist(session, str_list, num, TRUE); | |
| 523 g_free(str_list); | |
| 524 } | |
| 525 | |
| 526 void | |
| 527 xmms_remote_playlist_delete(gint session, gint pos) | |
| 528 { | |
| 529 remote_send_guint32(session, CMD_PLAYLIST_DELETE, pos); | |
| 530 } | |
| 531 | |
| 532 void | |
| 533 xmms_remote_play(gint session) | |
| 534 { | |
| 535 remote_cmd(session, CMD_PLAY); | |
| 536 } | |
| 537 | |
| 538 void | |
| 539 xmms_remote_pause(gint session) | |
| 540 { | |
| 541 remote_cmd(session, CMD_PAUSE); | |
| 542 } | |
| 543 | |
| 544 void | |
| 545 xmms_remote_stop(gint session) | |
| 546 { | |
| 547 remote_cmd(session, CMD_STOP); | |
| 548 } | |
| 549 | |
| 550 void | |
| 551 xmms_remote_play_pause(gint session) | |
| 552 { | |
| 553 remote_cmd(session, CMD_PLAY_PAUSE); | |
| 554 } | |
| 555 | |
| 556 gboolean | |
| 557 xmms_remote_is_playing(gint session) | |
| 558 { | |
| 559 return remote_get_gboolean(session, CMD_IS_PLAYING); | |
| 560 } | |
| 561 | |
| 562 gboolean | |
| 563 xmms_remote_is_paused(gint session) | |
| 564 { | |
| 565 return remote_get_gboolean(session, CMD_IS_PAUSED); | |
| 566 } | |
| 567 | |
| 568 gint | |
| 569 xmms_remote_get_playlist_pos(gint session) | |
| 570 { | |
| 571 return remote_get_gint(session, CMD_GET_PLAYLIST_POS); | |
| 572 } | |
| 573 | |
| 574 void | |
| 575 xmms_remote_set_playlist_pos(gint session, gint pos) | |
| 576 { | |
| 577 remote_send_guint32(session, CMD_SET_PLAYLIST_POS, pos); | |
| 578 } | |
| 579 | |
| 580 gint | |
| 581 xmms_remote_get_playlist_length(gint session) | |
| 582 { | |
| 583 return remote_get_gint(session, CMD_GET_PLAYLIST_LENGTH); | |
| 584 } | |
| 585 | |
| 586 void | |
| 587 xmms_remote_playlist_clear(gint session) | |
| 588 { | |
| 589 remote_cmd(session, CMD_PLAYLIST_CLEAR); | |
| 590 } | |
| 591 | |
| 592 gint | |
| 593 xmms_remote_get_output_time(gint session) | |
| 594 { | |
| 595 return remote_get_gint(session, CMD_GET_OUTPUT_TIME); | |
| 596 } | |
| 597 | |
| 598 void | |
| 599 xmms_remote_jump_to_time(gint session, gint pos) | |
| 600 { | |
| 601 remote_send_guint32(session, CMD_JUMP_TO_TIME, pos); | |
| 602 } | |
| 603 | |
| 604 void | |
| 605 xmms_remote_get_volume(gint session, gint * vl, gint * vr) | |
| 606 { | |
| 607 gint fd; | |
| 608 gpointer data; | |
| 609 | |
| 610 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 611 return; | |
| 612 | |
| 613 remote_send_packet(fd, CMD_GET_VOLUME, NULL, 0); | |
|
2002
c97cd4a8c470
[svn] - cleanup the controlsocket code. (nenolod + help from ticpu)
nenolod
parents:
1869
diff
changeset
|
614 data = remote_read_packet(fd); |
| 0 | 615 if (data) { |
| 616 *vl = ((guint32 *) data)[0]; | |
| 617 *vr = ((guint32 *) data)[1]; | |
| 618 g_free(data); | |
| 619 } | |
| 620 remote_read_ack(fd); | |
| 621 close(fd); | |
| 622 } | |
| 623 | |
| 624 gint | |
| 625 xmms_remote_get_main_volume(gint session) | |
| 626 { | |
| 627 gint vl, vr; | |
| 628 | |
| 629 xmms_remote_get_volume(session, &vl, &vr); | |
| 630 | |
| 631 return (vl > vr) ? vl : vr; | |
| 632 } | |
| 633 | |
| 634 gint | |
| 635 xmms_remote_get_balance(gint session) | |
| 636 { | |
| 637 return remote_get_gint(session, CMD_GET_BALANCE); | |
| 638 } | |
| 639 | |
| 640 void | |
| 641 xmms_remote_set_volume(gint session, gint vl, gint vr) | |
| 642 { | |
| 643 gint fd; | |
| 644 guint32 v[2]; | |
| 645 | |
| 646 if (vl < 0) | |
| 647 vl = 0; | |
| 648 if (vl > 100) | |
| 649 vl = 100; | |
| 650 if (vr < 0) | |
| 651 vr = 0; | |
| 652 if (vr > 100) | |
| 653 vr = 100; | |
| 654 | |
| 655 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 656 return; | |
| 657 v[0] = vl; | |
| 658 v[1] = vr; | |
| 659 remote_send_packet(fd, CMD_SET_VOLUME, v, 2 * sizeof(guint32)); | |
| 660 remote_read_ack(fd); | |
| 661 close(fd); | |
| 662 } | |
| 663 | |
| 664 void | |
| 665 xmms_remote_set_main_volume(gint session, gint v) | |
| 666 { | |
| 667 gint b, vl, vr; | |
| 668 | |
| 669 b = xmms_remote_get_balance(session); | |
| 670 | |
| 671 if (b < 0) { | |
| 672 vl = v; | |
| 673 vr = (v * (100 - abs(b))) / 100; | |
| 674 } | |
| 675 else if (b > 0) { | |
| 676 vl = (v * (100 - b)) / 100; | |
| 677 vr = v; | |
| 678 } | |
| 679 else | |
| 680 vl = vr = v; | |
| 681 xmms_remote_set_volume(session, vl, vr); | |
| 682 } | |
| 683 | |
| 684 void | |
| 685 xmms_remote_set_balance(gint session, gint b) | |
| 686 { | |
| 687 gint v, vl, vr; | |
| 688 | |
| 689 if (b < -100) | |
| 690 b = -100; | |
| 691 if (b > 100) | |
| 692 b = 100; | |
| 693 | |
| 694 v = xmms_remote_get_main_volume(session); | |
| 695 | |
| 696 if (b < 0) { | |
| 697 vl = v; | |
| 698 vr = (v * (100 - abs(b))) / 100; | |
| 699 } | |
| 700 else if (b > 0) { | |
| 701 vl = (v * (100 - b)) / 100; | |
| 702 vr = v; | |
| 703 } | |
| 704 else | |
| 705 vl = vr = v; | |
| 706 xmms_remote_set_volume(session, vl, vr); | |
| 707 } | |
| 708 | |
| 709 gchar * | |
| 710 xmms_remote_get_skin(gint session) | |
| 711 { | |
| 712 return remote_get_string(session, CMD_GET_SKIN); | |
| 713 } | |
| 714 | |
| 715 void | |
| 716 xmms_remote_set_skin(gint session, gchar * skinfile) | |
| 717 { | |
| 718 remote_send_string(session, CMD_SET_SKIN, skinfile); | |
| 719 } | |
| 720 | |
| 721 gchar * | |
| 722 xmms_remote_get_playlist_file(gint session, gint pos) | |
| 723 { | |
| 724 return remote_get_string_pos(session, CMD_GET_PLAYLIST_FILE, pos); | |
| 725 } | |
| 726 | |
| 727 gchar * | |
| 728 xmms_remote_get_playlist_title(gint session, gint pos) | |
| 729 { | |
| 730 return remote_get_string_pos(session, CMD_GET_PLAYLIST_TITLE, pos); | |
| 731 } | |
| 732 | |
| 733 gint | |
| 734 xmms_remote_get_playlist_time(gint session, gint pos) | |
| 735 { | |
| 736 gpointer data; | |
| 737 gint fd, ret = 0; | |
| 738 guint32 p = pos; | |
| 739 | |
| 740 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 741 return ret; | |
| 742 remote_send_packet(fd, CMD_GET_PLAYLIST_TIME, &p, sizeof(guint32)); | |
|
2002
c97cd4a8c470
[svn] - cleanup the controlsocket code. (nenolod + help from ticpu)
nenolod
parents:
1869
diff
changeset
|
743 data = remote_read_packet(fd); |
| 0 | 744 if (data) { |
| 745 ret = *((gint *) data); | |
| 746 g_free(data); | |
| 747 } | |
| 748 remote_read_ack(fd); | |
| 749 close(fd); | |
| 750 return ret; | |
| 751 } | |
| 752 | |
| 753 void | |
| 754 xmms_remote_get_info(gint session, gint * rate, gint * freq, gint * nch) | |
| 755 { | |
| 756 gint fd; | |
| 757 gpointer data; | |
| 758 | |
| 759 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 760 return; | |
| 761 remote_send_packet(fd, CMD_GET_INFO, NULL, 0); | |
|
2002
c97cd4a8c470
[svn] - cleanup the controlsocket code. (nenolod + help from ticpu)
nenolod
parents:
1869
diff
changeset
|
762 data = remote_read_packet(fd); |
| 0 | 763 if (data) { |
| 764 *rate = ((guint32 *) data)[0]; | |
| 765 *freq = ((guint32 *) data)[1]; | |
| 766 *nch = ((guint32 *) data)[2]; | |
| 767 g_free(data); | |
| 768 } | |
| 769 remote_read_ack(fd); | |
| 770 close(fd); | |
| 771 } | |
| 772 | |
| 773 void | |
| 774 xmms_remote_get_eq_data(gint session) | |
| 775 { | |
| 776 /* Obsolete */ | |
| 777 } | |
| 778 | |
| 779 void | |
| 780 xmms_remote_set_eq_data(gint session) | |
| 781 { | |
| 782 /* Obsolete */ | |
| 783 } | |
| 784 | |
| 785 void | |
| 786 xmms_remote_pl_win_toggle(gint session, gboolean show) | |
| 787 { | |
| 788 remote_send_boolean(session, CMD_PL_WIN_TOGGLE, show); | |
| 789 } | |
| 790 | |
| 791 void | |
| 792 xmms_remote_eq_win_toggle(gint session, gboolean show) | |
| 793 { | |
| 794 remote_send_boolean(session, CMD_EQ_WIN_TOGGLE, show); | |
| 795 } | |
| 796 | |
| 797 void | |
| 798 xmms_remote_main_win_toggle(gint session, gboolean show) | |
| 799 { | |
| 800 remote_send_boolean(session, CMD_MAIN_WIN_TOGGLE, show); | |
| 801 } | |
| 802 | |
| 803 gboolean | |
| 804 xmms_remote_is_main_win(gint session) | |
| 805 { | |
| 806 return remote_get_gboolean(session, CMD_IS_MAIN_WIN); | |
| 807 } | |
| 808 | |
| 809 gboolean | |
| 810 xmms_remote_is_pl_win(gint session) | |
| 811 { | |
| 812 return remote_get_gboolean(session, CMD_IS_PL_WIN); | |
| 813 } | |
| 814 | |
| 815 gboolean | |
| 816 xmms_remote_is_eq_win(gint session) | |
| 817 { | |
| 818 return remote_get_gboolean(session, CMD_IS_EQ_WIN); | |
| 819 } | |
| 820 | |
| 821 void | |
| 822 xmms_remote_show_prefs_box(gint session) | |
| 823 { | |
| 824 remote_cmd(session, CMD_SHOW_PREFS_BOX); | |
| 825 } | |
| 826 | |
| 827 void | |
| 984 | 828 xmms_remote_show_jtf_box(gint session) |
| 829 { | |
| 830 remote_cmd(session, CMD_SHOW_JTF_BOX); | |
| 831 } | |
| 832 | |
| 833 void | |
| 0 | 834 xmms_remote_toggle_aot(gint session, gboolean ontop) |
| 835 { | |
| 836 remote_send_boolean(session, CMD_TOGGLE_AOT, ontop); | |
| 837 } | |
| 838 | |
| 839 void | |
| 840 xmms_remote_show_about_box(gint session) | |
| 841 { | |
| 842 remote_cmd(session, CMD_SHOW_ABOUT_BOX); | |
| 843 } | |
| 844 | |
| 845 void | |
| 846 xmms_remote_eject(gint session) | |
| 847 { | |
| 848 remote_cmd(session, CMD_EJECT); | |
| 849 } | |
| 850 | |
| 851 void | |
| 852 xmms_remote_playlist_prev(gint session) | |
| 853 { | |
| 854 remote_cmd(session, CMD_PLAYLIST_PREV); | |
| 855 } | |
| 856 | |
| 857 void | |
| 858 xmms_remote_playlist_next(gint session) | |
| 859 { | |
| 860 remote_cmd(session, CMD_PLAYLIST_NEXT); | |
| 861 } | |
| 862 | |
| 863 void | |
| 864 xmms_remote_playlist_add_url_string(gint session, gchar * string) | |
| 865 { | |
| 866 g_return_if_fail(string != NULL); | |
| 867 remote_send_string(session, CMD_PLAYLIST_ADD_URL_STRING, string); | |
| 868 } | |
| 869 | |
| 870 void | |
| 871 xmms_remote_playlist_ins_url_string(gint session, gchar * string, gint pos) | |
| 872 { | |
| 873 gint fd, size; | |
| 874 gchar *packet; | |
| 875 | |
| 876 g_return_if_fail(string != NULL); | |
| 877 | |
| 878 size = strlen(string) + 1 + sizeof(gint); | |
| 879 | |
| 880 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 881 return; | |
| 882 | |
| 883 packet = g_malloc0(size); | |
| 884 *((gint *) packet) = pos; | |
| 885 strcpy(packet + sizeof(gint), string); | |
| 886 remote_send_packet(fd, CMD_PLAYLIST_INS_URL_STRING, packet, size); | |
| 887 remote_read_ack(fd); | |
| 888 close(fd); | |
| 889 g_free(packet); | |
| 890 } | |
| 891 | |
| 892 gboolean | |
| 893 xmms_remote_is_running(gint session) | |
| 894 { | |
| 895 return remote_cmd(session, CMD_PING); | |
| 896 } | |
| 897 | |
| 898 void | |
| 899 xmms_remote_toggle_repeat(gint session) | |
| 900 { | |
| 901 remote_cmd(session, CMD_TOGGLE_REPEAT); | |
| 902 } | |
| 903 | |
| 904 void | |
| 905 xmms_remote_toggle_shuffle(gint session) | |
| 906 { | |
| 907 remote_cmd(session, CMD_TOGGLE_SHUFFLE); | |
| 908 } | |
| 909 | |
| 910 void | |
| 911 xmms_remote_toggle_advance(int session) | |
| 912 { | |
| 913 remote_cmd(session, CMD_TOGGLE_ADVANCE); | |
| 914 } | |
| 915 | |
| 916 gboolean | |
| 917 xmms_remote_is_repeat(gint session) | |
| 918 { | |
| 919 return remote_get_gboolean(session, CMD_IS_REPEAT); | |
| 920 } | |
| 921 | |
| 922 gboolean | |
| 923 xmms_remote_is_shuffle(gint session) | |
| 924 { | |
| 925 return remote_get_gboolean(session, CMD_IS_SHUFFLE); | |
| 926 } | |
| 927 | |
| 928 gboolean | |
| 929 xmms_remote_is_advance(gint session) | |
| 930 { | |
| 931 return remote_get_gboolean(session, CMD_IS_ADVANCE); | |
| 932 } | |
| 933 | |
| 934 void | |
| 935 xmms_remote_playqueue_add(gint session, gint pos) | |
| 936 { | |
| 937 remote_send_guint32(session, CMD_PLAYQUEUE_ADD, pos); | |
| 938 } | |
| 939 | |
| 940 void | |
| 941 xmms_remote_playqueue_remove(gint session, gint pos) | |
| 942 { | |
| 943 remote_send_guint32(session, CMD_PLAYQUEUE_REMOVE, pos); | |
| 944 } | |
| 945 | |
| 984 | 946 void |
| 947 xmms_remote_playqueue_clear(gint session) | |
| 948 { | |
| 949 remote_cmd(session, CMD_PLAYQUEUE_CLEAR); | |
| 950 } | |
| 951 | |
| 0 | 952 gint |
| 953 xmms_remote_get_playqueue_length(gint session) | |
| 954 { | |
| 955 return remote_get_gint(session, CMD_GET_PLAYQUEUE_LENGTH); | |
| 956 } | |
| 957 | |
| 984 | 958 gboolean |
| 959 xmms_remote_playqueue_is_queued(gint session, gint pos) | |
| 960 { | |
| 961 gpointer data; | |
| 962 gint fd, ret = 0; | |
| 963 guint32 p = pos; | |
| 964 | |
| 965 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 966 return ret; | |
| 967 remote_send_packet(fd, CMD_PLAYQUEUE_IS_QUEUED, &p, sizeof(guint32)); | |
|
2002
c97cd4a8c470
[svn] - cleanup the controlsocket code. (nenolod + help from ticpu)
nenolod
parents:
1869
diff
changeset
|
968 data = remote_read_packet(fd); |
| 984 | 969 if (data) { |
| 970 ret = *((gint *) data); | |
| 971 g_free(data); | |
| 972 } | |
| 973 remote_read_ack(fd); | |
| 974 close(fd); | |
| 975 return ret; | |
| 976 } | |
| 977 | |
| 978 gint | |
| 979 xmms_remote_get_playqueue_position(gint session, gint pos) | |
| 980 { | |
| 981 gpointer data; | |
| 982 gint fd, ret = 0; | |
| 983 guint32 p = pos; | |
| 984 | |
| 985 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 986 return ret; | |
| 987 remote_send_packet(fd, CMD_PLAYQUEUE_GET_POS, &p, sizeof(guint32)); | |
|
2002
c97cd4a8c470
[svn] - cleanup the controlsocket code. (nenolod + help from ticpu)
nenolod
parents:
1869
diff
changeset
|
988 data = remote_read_packet(fd); |
| 984 | 989 if (data) { |
| 990 ret = *((gint *) data); | |
| 991 g_free(data); | |
| 992 } | |
| 993 remote_read_ack(fd); | |
| 994 close(fd); | |
| 995 return ret; | |
| 996 } | |
| 997 | |
| 998 gint | |
| 999 xmms_remote_get_playqueue_queue_position(gint session, gint pos) | |
| 1000 { | |
| 1001 gpointer data; | |
| 1002 gint fd, ret = 0; | |
| 1003 guint32 p = pos; | |
| 1004 | |
| 1005 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 1006 return ret; | |
| 1007 remote_send_packet(fd, CMD_PLAYQUEUE_GET_QPOS, &p, sizeof(guint32)); | |
|
2002
c97cd4a8c470
[svn] - cleanup the controlsocket code. (nenolod + help from ticpu)
nenolod
parents:
1869
diff
changeset
|
1008 data = remote_read_packet(fd); |
| 984 | 1009 if (data) { |
| 1010 ret = *((gint *) data); | |
| 1011 g_free(data); | |
| 1012 } | |
| 1013 remote_read_ack(fd); | |
| 1014 close(fd); | |
| 1015 return ret; | |
| 1016 } | |
| 1017 | |
| 0 | 1018 void |
| 1019 xmms_remote_get_eq(gint session, gfloat * preamp, gfloat ** bands) | |
| 1020 { | |
| 1021 gint fd; | |
| 1022 gpointer data; | |
| 1023 | |
| 1024 if (preamp) | |
| 1025 *preamp = 0.0; | |
| 1026 | |
| 1027 if (bands) | |
| 1028 *bands = NULL; | |
| 1029 | |
| 1030 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 1031 return; | |
| 1032 remote_send_packet(fd, CMD_GET_EQ, NULL, 0); | |
|
2002
c97cd4a8c470
[svn] - cleanup the controlsocket code. (nenolod + help from ticpu)
nenolod
parents:
1869
diff
changeset
|
1033 data = remote_read_packet(fd); |
| 0 | 1034 if (data) { |
| 1035 if (preamp) | |
| 1036 *preamp = *((gfloat *) data); | |
| 1037 if (bands) | |
| 1038 *bands = | |
| 1039 (gfloat *) g_memdup((gfloat *) data + 1, | |
| 1040 10 * sizeof(gfloat)); | |
| 1041 g_free(data); | |
| 1042 } | |
| 1043 remote_read_ack(fd); | |
| 1044 close(fd); | |
| 1045 } | |
| 1046 | |
| 1047 gfloat | |
| 1048 xmms_remote_get_eq_preamp(gint session) | |
| 1049 { | |
| 1050 return remote_get_gfloat(session, CMD_GET_EQ_PREAMP); | |
| 1051 } | |
| 1052 | |
| 1053 gfloat | |
| 1054 xmms_remote_get_eq_band(gint session, gint band) | |
| 1055 { | |
| 1056 gint fd; | |
| 1057 gpointer data; | |
| 1058 gfloat val = 0.0; | |
| 1059 | |
| 1060 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 1061 return val; | |
| 1062 remote_send_packet(fd, CMD_GET_EQ_BAND, &band, sizeof(band)); | |
|
2002
c97cd4a8c470
[svn] - cleanup the controlsocket code. (nenolod + help from ticpu)
nenolod
parents:
1869
diff
changeset
|
1063 data = remote_read_packet(fd); |
| 0 | 1064 if (data) { |
| 1065 val = *((gfloat *) data); | |
| 1066 g_free(data); | |
| 1067 } | |
| 1068 remote_read_ack(fd); | |
| 1069 close(fd); | |
| 1070 return val; | |
| 1071 } | |
| 1072 | |
| 1073 void | |
| 1074 xmms_remote_set_eq(gint session, gfloat preamp, gfloat * bands) | |
| 1075 { | |
| 1076 gint fd, i; | |
| 1077 gfloat data[11]; | |
| 1078 | |
| 1079 g_return_if_fail(bands != NULL); | |
| 1080 | |
| 1081 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 1082 return; | |
| 1083 data[0] = preamp; | |
| 1084 for (i = 0; i < 10; i++) | |
| 1085 data[i + 1] = bands[i]; | |
| 1086 remote_send_packet(fd, CMD_SET_EQ, data, sizeof(data)); | |
| 1087 remote_read_ack(fd); | |
| 1088 close(fd); | |
| 1089 } | |
| 1090 | |
| 1091 void | |
| 1092 xmms_remote_set_eq_preamp(gint session, gfloat preamp) | |
| 1093 { | |
| 1094 remote_send_gfloat(session, CMD_SET_EQ_PREAMP, preamp); | |
| 1095 } | |
| 1096 | |
| 1097 void | |
| 1098 xmms_remote_set_eq_band(gint session, gint band, gfloat value) | |
| 1099 { | |
| 1100 gint fd; | |
| 1101 gchar data[sizeof(gint) + sizeof(gfloat)]; | |
| 1102 | |
| 1103 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 1104 return; | |
| 1105 *((gint *) data) = band; | |
| 1106 *((gfloat *) (data + sizeof(gint))) = value; | |
| 1107 remote_send_packet(fd, CMD_SET_EQ_BAND, data, sizeof(data)); | |
| 1108 remote_read_ack(fd); | |
| 1109 close(fd); | |
| 1110 } | |
| 1111 | |
| 1112 void | |
| 1113 xmms_remote_quit(gint session) | |
| 1114 { | |
| 1115 gint fd; | |
| 1116 | |
| 1117 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 1118 return; | |
| 1119 remote_send_packet(fd, CMD_QUIT, NULL, 0); | |
| 1120 remote_read_ack(fd); | |
| 1121 close(fd); | |
| 1122 } | |
| 1123 | |
| 1124 void | |
| 1125 xmms_remote_activate(gint session) | |
| 1126 { | |
| 1127 gint fd; | |
| 1128 | |
| 1129 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 1130 return; | |
| 1131 remote_send_packet(fd, CMD_ACTIVATE, NULL, 0); | |
| 1132 remote_read_ack(fd); | |
| 1133 close(fd); | |
| 1134 } |
