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