Mercurial > audlegacy
annotate libaudacious/beepctrl.c @ 1459:705d4c089fce trunk
[svn] Fix postal code.
| author | chainsaw |
|---|---|
| date | Wed, 02 Aug 2006 16:00:13 -0700 |
| parents | f12d7e208b43 |
| children | 188437eb996b |
| 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 |
|
6fe7ba6e5489
[svn] - Don't poll the config database if not using TCP sockets.
nhjm449
parents:
1450
diff
changeset
|
362 return audacious_session_type; |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
363 } |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
364 |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
365 /* tcp://192.168.100.1:5900/zyzychynxi389xvmfewqaxznvnw */ |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
366 void |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
367 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
|
368 { |
| 1439 | 369 static gchar *workbuf, *keybuf; |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
370 gint iport; |
| 1439 | 371 gchar *tmp = g_strdup(in); |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
372 |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
373 /* split out the host/port and key */ |
| 1439 | 374 workbuf = tmp; |
|
1448
3b1c464cbbb0
[svn] Seems safer to me to free this way, assuming I'm not misreading.
nemo
parents:
1447
diff
changeset
|
375 workbuf += 6; |
| 1439 | 376 |
|
1448
3b1c464cbbb0
[svn] Seems safer to me to free this way, assuming I'm not misreading.
nemo
parents:
1447
diff
changeset
|
377 keybuf = strchr(workbuf, '/'); |
| 1439 | 378 *keybuf++ = '\0'; |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
379 |
|
1441
ed80e946f30b
[svn] - ok, don't eat up all the system ram (I forgot to g_free())
nenolod
parents:
1439
diff
changeset
|
380 *key = g_strdup(keybuf); |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
381 |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
382 if (strchr(workbuf, ':') == NULL) |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
383 { |
|
1441
ed80e946f30b
[svn] - ok, don't eat up all the system ram (I forgot to g_free())
nenolod
parents:
1439
diff
changeset
|
384 *host = g_strdup(workbuf); |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
385 *port = 37370 + session; |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
386 } |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
387 else |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
388 { |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
389 gchar *hostbuf = NULL; |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
390 sscanf(workbuf, "%s:%d", hostbuf, &iport); |
|
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 *port = iport + session; |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
393 } |
|
1441
ed80e946f30b
[svn] - ok, don't eat up all the system ram (I forgot to g_free())
nenolod
parents:
1439
diff
changeset
|
394 |
| 1447 | 395 g_free(tmp); |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
396 } |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
397 |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
398 /* unix://localhost/tmp/audacious_nenolod.0 */ |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
399 void |
| 1439 | 400 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
|
401 { |
| 1439 | 402 static gchar *workbuf, *keybuf; |
| 403 gchar *tmp = g_strdup(in); | |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
404 |
| 1439 | 405 /* split out the host/port and key */ |
| 406 workbuf = tmp; | |
|
1448
3b1c464cbbb0
[svn] Seems safer to me to free this way, assuming I'm not misreading.
nemo
parents:
1447
diff
changeset
|
407 workbuf += 7; |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
408 |
|
1448
3b1c464cbbb0
[svn] Seems safer to me to free this way, assuming I'm not misreading.
nemo
parents:
1447
diff
changeset
|
409 keybuf = strchr(workbuf, '/'); |
| 1439 | 410 *keybuf++ = '\0'; |
| 411 | |
|
1441
ed80e946f30b
[svn] - ok, don't eat up all the system ram (I forgot to g_free())
nenolod
parents:
1439
diff
changeset
|
412 *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
|
413 |
| 1447 | 414 g_free(tmp); |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
415 } |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
416 |
| 0 | 417 gint |
| 418 xmms_connect_to_session(gint session) | |
| 419 { | |
| 420 gint fd; | |
|
1456
6fe7ba6e5489
[svn] - Don't poll the config database if not using TCP sockets.
nhjm449
parents:
1450
diff
changeset
|
421 gint *type = audacious_determine_session_type(session); |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
422 gchar *uri = audacious_get_session_uri(session); |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
423 |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
424 if (type == AUDACIOUS_TYPE_UNIX) |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
425 { |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
426 if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) != -1) |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
427 { |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
428 uid_t stored_uid, euid; |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
429 struct sockaddr_un saddr; |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
430 gchar *path; |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
431 |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
432 saddr.sun_family = AF_UNIX; |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
433 stored_uid = getuid(); |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
434 euid = geteuid(); |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
435 setuid(euid); |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
436 |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
437 audacious_decode_unix_uri(session, uri, &path); |
| 0 | 438 |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
439 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
|
440 g_free(path); |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
441 setreuid(stored_uid, euid); |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
442 if (connect(fd, (struct sockaddr *) &saddr, sizeof(saddr)) != -1) |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
443 return fd; |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
444 } |
| 0 | 445 } |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
446 else |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
447 { |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
448 if ((fd = socket(AF_INET, SOCK_STREAM, 0)) != -1) |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
449 { |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
450 struct hostent *hp; |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
451 struct sockaddr_in saddr; |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
452 gchar *host, *key; |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
453 gint port; |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
454 |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
455 audacious_decode_tcp_uri(session, uri, &host, &port, &key); |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
456 |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
457 /* resolve it */ |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
458 if ((hp = gethostbyname(host)) == NULL) |
|
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 close(fd); |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
461 return -1; |
|
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 |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
464 memset(&saddr, '\0', sizeof(saddr)); |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
465 saddr.sin_family = AF_INET; |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
466 saddr.sin_port = htons(port); |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
467 memcpy(&saddr.sin_addr, hp->h_addr, hp->h_length); |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
468 |
|
1441
ed80e946f30b
[svn] - ok, don't eat up all the system ram (I forgot to g_free())
nenolod
parents:
1439
diff
changeset
|
469 g_free(host); |
|
ed80e946f30b
[svn] - ok, don't eat up all the system ram (I forgot to g_free())
nenolod
parents:
1439
diff
changeset
|
470 g_free(key); |
|
ed80e946f30b
[svn] - ok, don't eat up all the system ram (I forgot to g_free())
nenolod
parents:
1439
diff
changeset
|
471 |
|
1436
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
472 if (connect(fd, (struct sockaddr *) &saddr, sizeof(saddr)) != -1) |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
473 return fd; |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
474 } |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
475 } |
|
c70b68bcf527
[svn] - add framework for later handling tcp:// connections
nenolod
parents:
984
diff
changeset
|
476 |
| 0 | 477 close(fd); |
| 478 return -1; | |
| 479 } | |
| 480 | |
| 481 void | |
| 482 xmms_remote_playlist(gint session, gchar ** list, gint num, gboolean enqueue) | |
| 483 { | |
| 484 gint fd, i; | |
| 485 gchar *data, *ptr; | |
| 486 gint data_length; | |
| 487 guint32 len; | |
| 488 | |
| 489 g_return_if_fail(list != NULL); | |
| 490 g_return_if_fail(num > 0); | |
| 491 | |
| 492 if (!enqueue) | |
| 493 xmms_remote_playlist_clear(session); | |
| 494 | |
| 495 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 496 return; | |
| 497 | |
| 498 for (i = 0, data_length = 0; i < num; i++) | |
| 499 data_length += (((strlen(list[i]) + 1) + 3) / 4) * 4 + 4; | |
| 500 if (data_length) { | |
| 501 data_length += 4; | |
| 502 data = g_malloc(data_length); | |
| 503 for (i = 0, ptr = data; i < num; i++) { | |
| 504 len = strlen(list[i]) + 1; | |
| 505 *((guint32 *) ptr) = len; | |
| 506 ptr += 4; | |
| 507 memcpy(ptr, list[i], len); | |
| 508 ptr += ((len + 3) / 4) * 4; | |
| 509 } | |
| 510 *((guint32 *) ptr) = 0; | |
| 511 remote_send_packet(fd, CMD_PLAYLIST_ADD, data, data_length); | |
| 512 remote_read_ack(fd); | |
| 513 close(fd); | |
| 514 g_free(data); | |
| 515 } | |
| 516 | |
| 517 if (!enqueue) | |
| 518 xmms_remote_play(session); | |
| 519 } | |
| 520 | |
| 521 gint | |
| 522 xmms_remote_get_version(gint session) | |
| 523 { | |
| 524 return remote_get_gint(session, CMD_GET_VERSION); | |
| 525 } | |
| 526 | |
| 527 void | |
| 528 xmms_remote_play_files(gint session, GList * list) | |
| 529 { | |
| 530 g_return_if_fail(list != NULL); | |
| 531 | |
| 532 xmms_remote_playlist_clear(session); | |
| 533 xmms_remote_add_files(session, list); | |
| 534 xmms_remote_play(session); | |
| 535 } | |
| 536 | |
| 537 void | |
| 538 xmms_remote_playlist_add(gint session, GList * list) | |
| 539 { | |
| 540 gchar **str_list; | |
| 541 GList *node; | |
| 542 gint i, num; | |
| 543 | |
| 544 g_return_if_fail(list != NULL); | |
| 545 | |
| 546 num = g_list_length(list); | |
| 547 str_list = g_malloc0(num * sizeof(gchar *)); | |
| 548 for (i = 0, node = list; i < num && node; i++, node = g_list_next(node)) | |
| 549 str_list[i] = node->data; | |
| 550 | |
| 551 xmms_remote_playlist(session, str_list, num, TRUE); | |
| 552 g_free(str_list); | |
| 553 } | |
| 554 | |
| 555 void | |
| 556 xmms_remote_playlist_delete(gint session, gint pos) | |
| 557 { | |
| 558 remote_send_guint32(session, CMD_PLAYLIST_DELETE, pos); | |
| 559 } | |
| 560 | |
| 561 void | |
| 562 xmms_remote_play(gint session) | |
| 563 { | |
| 564 remote_cmd(session, CMD_PLAY); | |
| 565 } | |
| 566 | |
| 567 void | |
| 568 xmms_remote_pause(gint session) | |
| 569 { | |
| 570 remote_cmd(session, CMD_PAUSE); | |
| 571 } | |
| 572 | |
| 573 void | |
| 574 xmms_remote_stop(gint session) | |
| 575 { | |
| 576 remote_cmd(session, CMD_STOP); | |
| 577 } | |
| 578 | |
| 579 void | |
| 580 xmms_remote_play_pause(gint session) | |
| 581 { | |
| 582 remote_cmd(session, CMD_PLAY_PAUSE); | |
| 583 } | |
| 584 | |
| 585 gboolean | |
| 586 xmms_remote_is_playing(gint session) | |
| 587 { | |
| 588 return remote_get_gboolean(session, CMD_IS_PLAYING); | |
| 589 } | |
| 590 | |
| 591 gboolean | |
| 592 xmms_remote_is_paused(gint session) | |
| 593 { | |
| 594 return remote_get_gboolean(session, CMD_IS_PAUSED); | |
| 595 } | |
| 596 | |
| 597 gint | |
| 598 xmms_remote_get_playlist_pos(gint session) | |
| 599 { | |
| 600 return remote_get_gint(session, CMD_GET_PLAYLIST_POS); | |
| 601 } | |
| 602 | |
| 603 void | |
| 604 xmms_remote_set_playlist_pos(gint session, gint pos) | |
| 605 { | |
| 606 remote_send_guint32(session, CMD_SET_PLAYLIST_POS, pos); | |
| 607 } | |
| 608 | |
| 609 gint | |
| 610 xmms_remote_get_playlist_length(gint session) | |
| 611 { | |
| 612 return remote_get_gint(session, CMD_GET_PLAYLIST_LENGTH); | |
| 613 } | |
| 614 | |
| 615 void | |
| 616 xmms_remote_playlist_clear(gint session) | |
| 617 { | |
| 618 remote_cmd(session, CMD_PLAYLIST_CLEAR); | |
| 619 } | |
| 620 | |
| 621 gint | |
| 622 xmms_remote_get_output_time(gint session) | |
| 623 { | |
| 624 return remote_get_gint(session, CMD_GET_OUTPUT_TIME); | |
| 625 } | |
| 626 | |
| 627 void | |
| 628 xmms_remote_jump_to_time(gint session, gint pos) | |
| 629 { | |
| 630 remote_send_guint32(session, CMD_JUMP_TO_TIME, pos); | |
| 631 } | |
| 632 | |
| 633 void | |
| 634 xmms_remote_get_volume(gint session, gint * vl, gint * vr) | |
| 635 { | |
| 636 ServerPktHeader pkt_hdr; | |
| 637 gint fd; | |
| 638 gpointer data; | |
| 639 | |
| 640 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 641 return; | |
| 642 | |
| 643 remote_send_packet(fd, CMD_GET_VOLUME, NULL, 0); | |
| 644 data = remote_read_packet(fd, &pkt_hdr); | |
| 645 if (data) { | |
| 646 *vl = ((guint32 *) data)[0]; | |
| 647 *vr = ((guint32 *) data)[1]; | |
| 648 g_free(data); | |
| 649 } | |
| 650 remote_read_ack(fd); | |
| 651 close(fd); | |
| 652 } | |
| 653 | |
| 654 gint | |
| 655 xmms_remote_get_main_volume(gint session) | |
| 656 { | |
| 657 gint vl, vr; | |
| 658 | |
| 659 xmms_remote_get_volume(session, &vl, &vr); | |
| 660 | |
| 661 return (vl > vr) ? vl : vr; | |
| 662 } | |
| 663 | |
| 664 gint | |
| 665 xmms_remote_get_balance(gint session) | |
| 666 { | |
| 667 return remote_get_gint(session, CMD_GET_BALANCE); | |
| 668 } | |
| 669 | |
| 670 void | |
| 671 xmms_remote_set_volume(gint session, gint vl, gint vr) | |
| 672 { | |
| 673 gint fd; | |
| 674 guint32 v[2]; | |
| 675 | |
| 676 if (vl < 0) | |
| 677 vl = 0; | |
| 678 if (vl > 100) | |
| 679 vl = 100; | |
| 680 if (vr < 0) | |
| 681 vr = 0; | |
| 682 if (vr > 100) | |
| 683 vr = 100; | |
| 684 | |
| 685 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 686 return; | |
| 687 v[0] = vl; | |
| 688 v[1] = vr; | |
| 689 remote_send_packet(fd, CMD_SET_VOLUME, v, 2 * sizeof(guint32)); | |
| 690 remote_read_ack(fd); | |
| 691 close(fd); | |
| 692 } | |
| 693 | |
| 694 void | |
| 695 xmms_remote_set_main_volume(gint session, gint v) | |
| 696 { | |
| 697 gint b, vl, vr; | |
| 698 | |
| 699 b = xmms_remote_get_balance(session); | |
| 700 | |
| 701 if (b < 0) { | |
| 702 vl = v; | |
| 703 vr = (v * (100 - abs(b))) / 100; | |
| 704 } | |
| 705 else if (b > 0) { | |
| 706 vl = (v * (100 - b)) / 100; | |
| 707 vr = v; | |
| 708 } | |
| 709 else | |
| 710 vl = vr = v; | |
| 711 xmms_remote_set_volume(session, vl, vr); | |
| 712 } | |
| 713 | |
| 714 void | |
| 715 xmms_remote_set_balance(gint session, gint b) | |
| 716 { | |
| 717 gint v, vl, vr; | |
| 718 | |
| 719 if (b < -100) | |
| 720 b = -100; | |
| 721 if (b > 100) | |
| 722 b = 100; | |
| 723 | |
| 724 v = xmms_remote_get_main_volume(session); | |
| 725 | |
| 726 if (b < 0) { | |
| 727 vl = v; | |
| 728 vr = (v * (100 - abs(b))) / 100; | |
| 729 } | |
| 730 else if (b > 0) { | |
| 731 vl = (v * (100 - b)) / 100; | |
| 732 vr = v; | |
| 733 } | |
| 734 else | |
| 735 vl = vr = v; | |
| 736 xmms_remote_set_volume(session, vl, vr); | |
| 737 } | |
| 738 | |
| 739 gchar * | |
| 740 xmms_remote_get_skin(gint session) | |
| 741 { | |
| 742 return remote_get_string(session, CMD_GET_SKIN); | |
| 743 } | |
| 744 | |
| 745 void | |
| 746 xmms_remote_set_skin(gint session, gchar * skinfile) | |
| 747 { | |
| 748 remote_send_string(session, CMD_SET_SKIN, skinfile); | |
| 749 } | |
| 750 | |
| 751 gchar * | |
| 752 xmms_remote_get_playlist_file(gint session, gint pos) | |
| 753 { | |
| 754 return remote_get_string_pos(session, CMD_GET_PLAYLIST_FILE, pos); | |
| 755 } | |
| 756 | |
| 757 gchar * | |
| 758 xmms_remote_get_playlist_title(gint session, gint pos) | |
| 759 { | |
| 760 return remote_get_string_pos(session, CMD_GET_PLAYLIST_TITLE, pos); | |
| 761 } | |
| 762 | |
| 763 gint | |
| 764 xmms_remote_get_playlist_time(gint session, gint pos) | |
| 765 { | |
| 766 ServerPktHeader pkt_hdr; | |
| 767 gpointer data; | |
| 768 gint fd, ret = 0; | |
| 769 guint32 p = pos; | |
| 770 | |
| 771 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 772 return ret; | |
| 773 remote_send_packet(fd, CMD_GET_PLAYLIST_TIME, &p, sizeof(guint32)); | |
| 774 data = remote_read_packet(fd, &pkt_hdr); | |
| 775 if (data) { | |
| 776 ret = *((gint *) data); | |
| 777 g_free(data); | |
| 778 } | |
| 779 remote_read_ack(fd); | |
| 780 close(fd); | |
| 781 return ret; | |
| 782 } | |
| 783 | |
| 784 void | |
| 785 xmms_remote_get_info(gint session, gint * rate, gint * freq, gint * nch) | |
| 786 { | |
| 787 ServerPktHeader pkt_hdr; | |
| 788 gint fd; | |
| 789 gpointer data; | |
| 790 | |
| 791 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 792 return; | |
| 793 remote_send_packet(fd, CMD_GET_INFO, NULL, 0); | |
| 794 data = remote_read_packet(fd, &pkt_hdr); | |
| 795 if (data) { | |
| 796 *rate = ((guint32 *) data)[0]; | |
| 797 *freq = ((guint32 *) data)[1]; | |
| 798 *nch = ((guint32 *) data)[2]; | |
| 799 g_free(data); | |
| 800 } | |
| 801 remote_read_ack(fd); | |
| 802 close(fd); | |
| 803 } | |
| 804 | |
| 805 void | |
| 806 xmms_remote_get_eq_data(gint session) | |
| 807 { | |
| 808 /* Obsolete */ | |
| 809 } | |
| 810 | |
| 811 void | |
| 812 xmms_remote_set_eq_data(gint session) | |
| 813 { | |
| 814 /* Obsolete */ | |
| 815 } | |
| 816 | |
| 817 void | |
| 818 xmms_remote_pl_win_toggle(gint session, gboolean show) | |
| 819 { | |
| 820 remote_send_boolean(session, CMD_PL_WIN_TOGGLE, show); | |
| 821 } | |
| 822 | |
| 823 void | |
| 824 xmms_remote_eq_win_toggle(gint session, gboolean show) | |
| 825 { | |
| 826 remote_send_boolean(session, CMD_EQ_WIN_TOGGLE, show); | |
| 827 } | |
| 828 | |
| 829 void | |
| 830 xmms_remote_main_win_toggle(gint session, gboolean show) | |
| 831 { | |
| 832 remote_send_boolean(session, CMD_MAIN_WIN_TOGGLE, show); | |
| 833 } | |
| 834 | |
| 835 gboolean | |
| 836 xmms_remote_is_main_win(gint session) | |
| 837 { | |
| 838 return remote_get_gboolean(session, CMD_IS_MAIN_WIN); | |
| 839 } | |
| 840 | |
| 841 gboolean | |
| 842 xmms_remote_is_pl_win(gint session) | |
| 843 { | |
| 844 return remote_get_gboolean(session, CMD_IS_PL_WIN); | |
| 845 } | |
| 846 | |
| 847 gboolean | |
| 848 xmms_remote_is_eq_win(gint session) | |
| 849 { | |
| 850 return remote_get_gboolean(session, CMD_IS_EQ_WIN); | |
| 851 } | |
| 852 | |
| 853 void | |
| 854 xmms_remote_show_prefs_box(gint session) | |
| 855 { | |
| 856 remote_cmd(session, CMD_SHOW_PREFS_BOX); | |
| 857 } | |
| 858 | |
| 859 void | |
| 984 | 860 xmms_remote_show_jtf_box(gint session) |
| 861 { | |
| 862 remote_cmd(session, CMD_SHOW_JTF_BOX); | |
| 863 } | |
| 864 | |
| 865 void | |
| 0 | 866 xmms_remote_toggle_aot(gint session, gboolean ontop) |
| 867 { | |
| 868 remote_send_boolean(session, CMD_TOGGLE_AOT, ontop); | |
| 869 } | |
| 870 | |
| 871 void | |
| 872 xmms_remote_show_about_box(gint session) | |
| 873 { | |
| 874 remote_cmd(session, CMD_SHOW_ABOUT_BOX); | |
| 875 } | |
| 876 | |
| 877 void | |
| 878 xmms_remote_eject(gint session) | |
| 879 { | |
| 880 remote_cmd(session, CMD_EJECT); | |
| 881 } | |
| 882 | |
| 883 void | |
| 884 xmms_remote_playlist_prev(gint session) | |
| 885 { | |
| 886 remote_cmd(session, CMD_PLAYLIST_PREV); | |
| 887 } | |
| 888 | |
| 889 void | |
| 890 xmms_remote_playlist_next(gint session) | |
| 891 { | |
| 892 remote_cmd(session, CMD_PLAYLIST_NEXT); | |
| 893 } | |
| 894 | |
| 895 void | |
| 896 xmms_remote_playlist_add_url_string(gint session, gchar * string) | |
| 897 { | |
| 898 g_return_if_fail(string != NULL); | |
| 899 remote_send_string(session, CMD_PLAYLIST_ADD_URL_STRING, string); | |
| 900 } | |
| 901 | |
| 902 void | |
| 903 xmms_remote_playlist_ins_url_string(gint session, gchar * string, gint pos) | |
| 904 { | |
| 905 gint fd, size; | |
| 906 gchar *packet; | |
| 907 | |
| 908 g_return_if_fail(string != NULL); | |
| 909 | |
| 910 size = strlen(string) + 1 + sizeof(gint); | |
| 911 | |
| 912 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 913 return; | |
| 914 | |
| 915 packet = g_malloc0(size); | |
| 916 *((gint *) packet) = pos; | |
| 917 strcpy(packet + sizeof(gint), string); | |
| 918 remote_send_packet(fd, CMD_PLAYLIST_INS_URL_STRING, packet, size); | |
| 919 remote_read_ack(fd); | |
| 920 close(fd); | |
| 921 g_free(packet); | |
| 922 } | |
| 923 | |
| 924 gboolean | |
| 925 xmms_remote_is_running(gint session) | |
| 926 { | |
| 927 return remote_cmd(session, CMD_PING); | |
| 928 } | |
| 929 | |
| 930 void | |
| 931 xmms_remote_toggle_repeat(gint session) | |
| 932 { | |
| 933 remote_cmd(session, CMD_TOGGLE_REPEAT); | |
| 934 } | |
| 935 | |
| 936 void | |
| 937 xmms_remote_toggle_shuffle(gint session) | |
| 938 { | |
| 939 remote_cmd(session, CMD_TOGGLE_SHUFFLE); | |
| 940 } | |
| 941 | |
| 942 void | |
| 943 xmms_remote_toggle_advance(int session) | |
| 944 { | |
| 945 remote_cmd(session, CMD_TOGGLE_ADVANCE); | |
| 946 } | |
| 947 | |
| 948 gboolean | |
| 949 xmms_remote_is_repeat(gint session) | |
| 950 { | |
| 951 return remote_get_gboolean(session, CMD_IS_REPEAT); | |
| 952 } | |
| 953 | |
| 954 gboolean | |
| 955 xmms_remote_is_shuffle(gint session) | |
| 956 { | |
| 957 return remote_get_gboolean(session, CMD_IS_SHUFFLE); | |
| 958 } | |
| 959 | |
| 960 gboolean | |
| 961 xmms_remote_is_advance(gint session) | |
| 962 { | |
| 963 return remote_get_gboolean(session, CMD_IS_ADVANCE); | |
| 964 } | |
| 965 | |
| 966 void | |
| 967 xmms_remote_playqueue_add(gint session, gint pos) | |
| 968 { | |
| 969 remote_send_guint32(session, CMD_PLAYQUEUE_ADD, pos); | |
| 970 } | |
| 971 | |
| 972 void | |
| 973 xmms_remote_playqueue_remove(gint session, gint pos) | |
| 974 { | |
| 975 remote_send_guint32(session, CMD_PLAYQUEUE_REMOVE, pos); | |
| 976 } | |
| 977 | |
| 984 | 978 void |
| 979 xmms_remote_playqueue_clear(gint session) | |
| 980 { | |
| 981 remote_cmd(session, CMD_PLAYQUEUE_CLEAR); | |
| 982 } | |
| 983 | |
| 0 | 984 gint |
| 985 xmms_remote_get_playqueue_length(gint session) | |
| 986 { | |
| 987 return remote_get_gint(session, CMD_GET_PLAYQUEUE_LENGTH); | |
| 988 } | |
| 989 | |
| 984 | 990 gboolean |
| 991 xmms_remote_playqueue_is_queued(gint session, gint pos) | |
| 992 { | |
| 993 ServerPktHeader pkt_hdr; | |
| 994 gpointer data; | |
| 995 gint fd, ret = 0; | |
| 996 guint32 p = pos; | |
| 997 | |
| 998 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 999 return ret; | |
| 1000 remote_send_packet(fd, CMD_PLAYQUEUE_IS_QUEUED, &p, sizeof(guint32)); | |
| 1001 data = remote_read_packet(fd, &pkt_hdr); | |
| 1002 if (data) { | |
| 1003 ret = *((gint *) data); | |
| 1004 g_free(data); | |
| 1005 } | |
| 1006 remote_read_ack(fd); | |
| 1007 close(fd); | |
| 1008 return ret; | |
| 1009 } | |
| 1010 | |
| 1011 gint | |
| 1012 xmms_remote_get_playqueue_position(gint session, gint pos) | |
| 1013 { | |
| 1014 ServerPktHeader pkt_hdr; | |
| 1015 gpointer data; | |
| 1016 gint fd, ret = 0; | |
| 1017 guint32 p = pos; | |
| 1018 | |
| 1019 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 1020 return ret; | |
| 1021 remote_send_packet(fd, CMD_PLAYQUEUE_GET_POS, &p, sizeof(guint32)); | |
| 1022 data = remote_read_packet(fd, &pkt_hdr); | |
| 1023 if (data) { | |
| 1024 ret = *((gint *) data); | |
| 1025 g_free(data); | |
| 1026 } | |
| 1027 remote_read_ack(fd); | |
| 1028 close(fd); | |
| 1029 return ret; | |
| 1030 } | |
| 1031 | |
| 1032 gint | |
| 1033 xmms_remote_get_playqueue_queue_position(gint session, gint pos) | |
| 1034 { | |
| 1035 ServerPktHeader pkt_hdr; | |
| 1036 gpointer data; | |
| 1037 gint fd, ret = 0; | |
| 1038 guint32 p = pos; | |
| 1039 | |
| 1040 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 1041 return ret; | |
| 1042 remote_send_packet(fd, CMD_PLAYQUEUE_GET_QPOS, &p, sizeof(guint32)); | |
| 1043 data = remote_read_packet(fd, &pkt_hdr); | |
| 1044 if (data) { | |
| 1045 ret = *((gint *) data); | |
| 1046 g_free(data); | |
| 1047 } | |
| 1048 remote_read_ack(fd); | |
| 1049 close(fd); | |
| 1050 return ret; | |
| 1051 } | |
| 1052 | |
| 0 | 1053 void |
| 1054 xmms_remote_get_eq(gint session, gfloat * preamp, gfloat ** bands) | |
| 1055 { | |
| 1056 ServerPktHeader pkt_hdr; | |
| 1057 gint fd; | |
| 1058 gpointer data; | |
| 1059 | |
| 1060 if (preamp) | |
| 1061 *preamp = 0.0; | |
| 1062 | |
| 1063 if (bands) | |
| 1064 *bands = NULL; | |
| 1065 | |
| 1066 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 1067 return; | |
| 1068 remote_send_packet(fd, CMD_GET_EQ, NULL, 0); | |
| 1069 data = remote_read_packet(fd, &pkt_hdr); | |
| 1070 if (data) { | |
| 1071 if (pkt_hdr.data_length >= 11 * sizeof(gfloat)) { | |
| 1072 if (preamp) | |
| 1073 *preamp = *((gfloat *) data); | |
| 1074 if (bands) | |
| 1075 *bands = | |
| 1076 (gfloat *) g_memdup((gfloat *) data + 1, | |
| 1077 10 * sizeof(gfloat)); | |
| 1078 } | |
| 1079 g_free(data); | |
| 1080 } | |
| 1081 remote_read_ack(fd); | |
| 1082 close(fd); | |
| 1083 } | |
| 1084 | |
| 1085 gfloat | |
| 1086 xmms_remote_get_eq_preamp(gint session) | |
| 1087 { | |
| 1088 return remote_get_gfloat(session, CMD_GET_EQ_PREAMP); | |
| 1089 } | |
| 1090 | |
| 1091 gfloat | |
| 1092 xmms_remote_get_eq_band(gint session, gint band) | |
| 1093 { | |
| 1094 ServerPktHeader pkt_hdr; | |
| 1095 gint fd; | |
| 1096 gpointer data; | |
| 1097 gfloat val = 0.0; | |
| 1098 | |
| 1099 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 1100 return val; | |
| 1101 remote_send_packet(fd, CMD_GET_EQ_BAND, &band, sizeof(band)); | |
| 1102 data = remote_read_packet(fd, &pkt_hdr); | |
| 1103 if (data) { | |
| 1104 val = *((gfloat *) data); | |
| 1105 g_free(data); | |
| 1106 } | |
| 1107 remote_read_ack(fd); | |
| 1108 close(fd); | |
| 1109 return val; | |
| 1110 } | |
| 1111 | |
| 1112 void | |
| 1113 xmms_remote_set_eq(gint session, gfloat preamp, gfloat * bands) | |
| 1114 { | |
| 1115 gint fd, i; | |
| 1116 gfloat data[11]; | |
| 1117 | |
| 1118 g_return_if_fail(bands != NULL); | |
| 1119 | |
| 1120 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 1121 return; | |
| 1122 data[0] = preamp; | |
| 1123 for (i = 0; i < 10; i++) | |
| 1124 data[i + 1] = bands[i]; | |
| 1125 remote_send_packet(fd, CMD_SET_EQ, data, sizeof(data)); | |
| 1126 remote_read_ack(fd); | |
| 1127 close(fd); | |
| 1128 } | |
| 1129 | |
| 1130 void | |
| 1131 xmms_remote_set_eq_preamp(gint session, gfloat preamp) | |
| 1132 { | |
| 1133 remote_send_gfloat(session, CMD_SET_EQ_PREAMP, preamp); | |
| 1134 } | |
| 1135 | |
| 1136 void | |
| 1137 xmms_remote_set_eq_band(gint session, gint band, gfloat value) | |
| 1138 { | |
| 1139 gint fd; | |
| 1140 gchar data[sizeof(gint) + sizeof(gfloat)]; | |
| 1141 | |
| 1142 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 1143 return; | |
| 1144 *((gint *) data) = band; | |
| 1145 *((gfloat *) (data + sizeof(gint))) = value; | |
| 1146 remote_send_packet(fd, CMD_SET_EQ_BAND, data, sizeof(data)); | |
| 1147 remote_read_ack(fd); | |
| 1148 close(fd); | |
| 1149 } | |
| 1150 | |
| 1151 void | |
| 1152 xmms_remote_quit(gint session) | |
| 1153 { | |
| 1154 gint fd; | |
| 1155 | |
| 1156 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 1157 return; | |
| 1158 remote_send_packet(fd, CMD_QUIT, NULL, 0); | |
| 1159 remote_read_ack(fd); | |
| 1160 close(fd); | |
| 1161 } | |
| 1162 | |
| 1163 void | |
| 1164 xmms_remote_activate(gint session) | |
| 1165 { | |
| 1166 gint fd; | |
| 1167 | |
| 1168 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 1169 return; | |
| 1170 remote_send_packet(fd, CMD_ACTIVATE, NULL, 0); | |
| 1171 remote_read_ack(fd); | |
| 1172 close(fd); | |
| 1173 } |
