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