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