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