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