Mercurial > audlegacy
annotate src/libaudacious/beepctrl.c @ 2517:5fea66ad690c trunk
[svn] - fix a signed vs unsigned comparison
| author | nenolod |
|---|---|
| date | Wed, 14 Feb 2007 10:48:52 -0800 |
| parents | f24ae4f40e29 |
| children | c2b49ba4be45 |
| rev | line source |
|---|---|
| 2313 | 1 /* Audacious |
| 2 * Copyright (C) 2005-2007 Audacious team | |
| 3 * | |
| 4 * XMMS - Cross-platform multimedia player | |
| 5 * Copyright (C) 1998-2003 Peter Alm, Mikael Alm, Olle Hallnas, | |
| 6 * Thomas Nilsson and 4Front Technologies | |
| 7 * Copyright (C) 1999-2003 Haavard Kvaalen | |
| 8 * | |
| 9 * This program is free software; you can redistribute it and/or modify | |
| 10 * it under the terms of the GNU General Public License as published by | |
| 11 * the Free Software Foundation; under version 2 of the License. | |
| 12 * | |
| 13 * This program is distributed in the hope that it will be useful, | |
| 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 * GNU General Public License for more details. | |
| 17 * | |
| 18 * You should have received a copy of the GNU General Public License | |
| 19 * along with this program; if not, write to the Free Software | |
| 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
| 21 */ | |
| 22 | |
| 23 #ifdef HAVE_CONFIG_H | |
| 24 # include "config.h" | |
| 25 #endif | |
| 26 | |
| 27 #include <glib.h> | |
| 28 #include <sys/types.h> | |
| 29 #include <sys/stat.h> | |
| 30 #include <sys/socket.h> | |
| 31 #include <sys/un.h> | |
| 32 #include <arpa/inet.h> | |
| 33 #include <netdb.h> | |
| 34 #include <errno.h> | |
| 35 #include <stdio.h> | |
| 36 #include <stdlib.h> | |
| 37 #include <string.h> | |
| 38 #include "beepctrl.h" | |
| 39 #include "audacious/controlsocket.h" | |
| 40 #include "libaudacious/configdb.h" | |
| 41 | |
| 42 #include <netdb.h> | |
| 43 #include <netinet/in.h> | |
| 44 #include <unistd.h> | |
| 45 #include <grp.h> | |
| 46 #include <sys/time.h> | |
| 47 #include <sys/wait.h> | |
| 48 #include <sys/resource.h> | |
| 49 #include <sys/socket.h> | |
| 50 #include <fcntl.h> | |
| 51 #include <arpa/inet.h> | |
| 52 | |
| 53 /* overrides audacious_get_session_uri(). */ | |
| 54 gchar *audacious_session_uri = NULL; | |
| 55 gint audacious_session_type = 0; | |
| 56 | |
| 57 #ifdef HAVE_UNISTD_H | |
| 58 #include <unistd.h> | |
| 59 #endif | |
| 60 | |
| 61 static gpointer | |
| 62 remote_read_packet(gint fd) | |
| 63 { | |
| 64 gpointer data = NULL; | |
| 65 ServerPktHeader pkt_hdr = { 0, 0 }; | |
| 66 | |
| 67 if (read(fd, &pkt_hdr, sizeof(ServerPktHeader)) == | |
| 68 sizeof(ServerPktHeader)) | |
| 69 { | |
| 70 if (pkt_hdr.version == XMMS_PROTOCOL_VERSION && | |
| 71 pkt_hdr.data_length > 0) | |
| 72 { | |
| 73 size_t data_length = pkt_hdr.data_length; | |
| 74 data = g_malloc0(data_length); | |
| 75 if ((size_t)read(fd, data, data_length) < data_length) | |
| 76 { | |
| 77 g_free(data); | |
| 78 data = NULL; | |
| 79 } | |
| 80 } | |
| 81 } | |
| 82 | |
| 83 return data; | |
| 84 } | |
| 85 | |
| 86 static void | |
| 87 remote_read_ack(gint fd) | |
| 88 { | |
| 89 gpointer data; | |
| 90 | |
| 91 data = remote_read_packet(fd); | |
| 92 if (data) | |
| 93 g_free(data); | |
| 94 | |
| 95 } | |
| 96 | |
| 97 static void | |
| 98 remote_send_packet(gint fd, guint32 command, gpointer data, | |
| 2517 | 99 gsize data_length) |
| 2313 | 100 { |
| 101 ClientPktHeader pkt_hdr; | |
| 102 | |
| 103 memset(&pkt_hdr, '\0', sizeof(ClientPktHeader)); | |
| 104 | |
| 105 pkt_hdr.version = XMMS_PROTOCOL_VERSION; | |
| 106 pkt_hdr.command = command; | |
| 107 pkt_hdr.data_length = data_length; | |
| 108 if ((size_t)write(fd, &pkt_hdr, sizeof(ClientPktHeader)) < sizeof(pkt_hdr)) | |
|
2361
f24ae4f40e29
[svn] - security and warning fixes from ssommer@suse
nenolod
parents:
2313
diff
changeset
|
109 { |
|
f24ae4f40e29
[svn] - security and warning fixes from ssommer@suse
nenolod
parents:
2313
diff
changeset
|
110 g_warning("remote_send_packet: failed to write packet header"); |
| 2313 | 111 return; |
|
2361
f24ae4f40e29
[svn] - security and warning fixes from ssommer@suse
nenolod
parents:
2313
diff
changeset
|
112 } |
| 2313 | 113 if (data_length && data) |
| 2517 | 114 if( data_length != (gsize) write(fd, data, data_length)) |
|
2361
f24ae4f40e29
[svn] - security and warning fixes from ssommer@suse
nenolod
parents:
2313
diff
changeset
|
115 { |
|
f24ae4f40e29
[svn] - security and warning fixes from ssommer@suse
nenolod
parents:
2313
diff
changeset
|
116 g_warning("remote_send_packet: failed to write packet"); |
|
f24ae4f40e29
[svn] - security and warning fixes from ssommer@suse
nenolod
parents:
2313
diff
changeset
|
117 return; |
|
f24ae4f40e29
[svn] - security and warning fixes from ssommer@suse
nenolod
parents:
2313
diff
changeset
|
118 } |
| 2313 | 119 } |
| 120 | |
| 121 static void | |
| 122 remote_send_guint32(gint session, guint32 cmd, guint32 val) | |
| 123 { | |
| 124 gint fd; | |
| 125 | |
| 126 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 127 return; | |
| 128 remote_send_packet(fd, cmd, &val, sizeof(guint32)); | |
| 129 remote_read_ack(fd); | |
| 130 close(fd); | |
| 131 } | |
| 132 | |
| 133 static void | |
| 134 remote_send_boolean(gint session, guint32 cmd, gboolean val) | |
| 135 { | |
| 136 gint fd; | |
| 137 | |
| 138 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 139 return; | |
| 140 remote_send_packet(fd, cmd, &val, sizeof(gboolean)); | |
| 141 remote_read_ack(fd); | |
| 142 close(fd); | |
| 143 } | |
| 144 | |
| 145 static void | |
| 146 remote_send_gfloat(gint session, guint32 cmd, gfloat value) | |
| 147 { | |
| 148 gint fd; | |
| 149 | |
| 150 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 151 return; | |
| 152 remote_send_packet(fd, cmd, &value, sizeof(gfloat)); | |
| 153 remote_read_ack(fd); | |
| 154 close(fd); | |
| 155 } | |
| 156 | |
| 157 static void | |
| 158 remote_send_string(gint session, guint32 cmd, gchar * string) | |
| 159 { | |
| 160 gint fd; | |
| 161 | |
| 162 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 163 return; | |
| 164 remote_send_packet(fd, cmd, string, string ? strlen(string) + 1 : 0); | |
| 165 remote_read_ack(fd); | |
| 166 close(fd); | |
| 167 } | |
| 168 | |
| 169 static gboolean | |
| 170 remote_cmd(gint session, guint32 cmd) | |
| 171 { | |
| 172 gint fd; | |
| 173 | |
| 174 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 175 return FALSE; | |
| 176 remote_send_packet(fd, cmd, NULL, 0); | |
| 177 remote_read_ack(fd); | |
| 178 close(fd); | |
| 179 | |
| 180 return TRUE; | |
| 181 } | |
| 182 | |
| 183 static gboolean | |
| 184 remote_get_gboolean(gint session, gint cmd) | |
| 185 { | |
| 186 gboolean ret = FALSE; | |
| 187 gpointer data; | |
| 188 gint fd; | |
| 189 | |
| 190 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 191 return ret; | |
| 192 remote_send_packet(fd, cmd, NULL, 0); | |
| 193 data = remote_read_packet(fd); | |
| 194 if (data) { | |
| 195 ret = *((gboolean *) data); | |
| 196 g_free(data); | |
| 197 } | |
| 198 remote_read_ack(fd); | |
| 199 close(fd); | |
| 200 | |
| 201 return ret; | |
| 202 } | |
| 203 | |
| 204 static guint32 | |
| 205 remote_get_gint(gint session, gint cmd) | |
| 206 { | |
| 207 gpointer data; | |
| 208 gint fd, ret = 0; | |
| 209 | |
| 210 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 211 return ret; | |
| 212 remote_send_packet(fd, cmd, NULL, 0); | |
| 213 data = remote_read_packet(fd); | |
| 214 if (data) { | |
| 215 ret = *((gint *) data); | |
| 216 g_free(data); | |
| 217 } | |
| 218 remote_read_ack(fd); | |
| 219 close(fd); | |
| 220 return ret; | |
| 221 } | |
| 222 | |
| 223 static gfloat | |
| 224 remote_get_gfloat(gint session, gint cmd) | |
| 225 { | |
| 226 gpointer data; | |
| 227 gint fd; | |
| 228 gfloat ret = 0.0; | |
| 229 | |
| 230 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 231 return ret; | |
| 232 remote_send_packet(fd, cmd, NULL, 0); | |
| 233 data = remote_read_packet(fd); | |
| 234 if (data) { | |
| 235 ret = *((gfloat *) data); | |
| 236 g_free(data); | |
| 237 } | |
| 238 remote_read_ack(fd); | |
| 239 close(fd); | |
| 240 return ret; | |
| 241 } | |
| 242 | |
| 243 gchar * | |
| 244 remote_get_string(gint session, gint cmd) | |
| 245 { | |
| 246 gpointer data; | |
| 247 gint fd; | |
| 248 | |
| 249 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 250 return NULL; | |
| 251 remote_send_packet(fd, cmd, NULL, 0); | |
| 252 data = remote_read_packet(fd); | |
| 253 remote_read_ack(fd); | |
| 254 close(fd); | |
| 255 return data; | |
| 256 } | |
| 257 | |
| 258 gchar * | |
| 259 remote_get_string_pos(gint session, gint cmd, guint32 pos) | |
| 260 { | |
| 261 gpointer data; | |
| 262 gint fd; | |
| 263 | |
| 264 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 265 return NULL; | |
| 266 remote_send_packet(fd, cmd, &pos, sizeof(guint32)); | |
| 267 data = remote_read_packet(fd); | |
| 268 remote_read_ack(fd); | |
| 269 close(fd); | |
| 270 return data; | |
| 271 } | |
| 272 | |
| 273 /** | |
| 274 * audacious_set_session_uri: | |
| 275 * @uri: The session URI to set the client API to. | |
| 276 * | |
| 277 * Sets the Session URI where Audacious can be reached at. | |
| 278 **/ | |
| 279 void | |
| 280 audacious_set_session_uri(gchar *uri) | |
| 281 { | |
| 282 audacious_session_uri = uri; | |
| 283 } | |
| 284 | |
| 285 /** | |
| 286 * audacious_get_session_uri: | |
| 287 * @session: Legacy XMMS session id (usually 0). | |
| 288 * | |
| 289 * Attempts to determine what the Session URI may be. | |
| 290 * | |
| 291 * Return value: A session URI. | |
| 292 **/ | |
| 293 gchar * | |
| 294 audacious_get_session_uri(gint session) | |
| 295 { | |
| 296 ConfigDb *db; | |
| 297 gchar *value = NULL; | |
| 298 | |
| 299 if (audacious_session_uri != NULL) | |
| 300 { | |
| 301 return g_strdup(audacious_session_uri); | |
| 302 } | |
| 303 | |
| 304 if (audacious_session_type != AUDACIOUS_TYPE_UNIX) | |
| 305 { | |
| 306 db = bmp_cfg_db_open(); | |
| 307 | |
| 308 bmp_cfg_db_get_string(db, NULL, "listen_uri_base", &value); | |
| 309 | |
| 310 bmp_cfg_db_close(db); | |
| 311 } | |
| 312 | |
| 313 if (value == NULL) | |
| 314 return g_strdup_printf("unix://localhost/%s/%s_%s.%d", g_get_tmp_dir(), | |
| 315 CTRLSOCKET_NAME, g_get_user_name(), session); | |
| 316 | |
| 317 audacious_session_uri = value; | |
| 318 | |
| 319 return value; | |
| 320 } | |
| 321 | |
| 322 /** | |
| 323 * audacious_set_session_type: | |
| 324 * @type: The type to set the session type to. | |
| 325 * | |
| 326 * Sets the type of session used by the audacious server. | |
| 327 **/ | |
| 328 void | |
| 329 audacious_set_session_type(gint type) | |
| 330 { | |
| 331 audacious_session_type = type; | |
| 332 } | |
| 333 | |
| 334 /** | |
| 335 * audacious_determine_session_type: | |
| 336 * @session: Legacy XMMS session id (usually 0). | |
| 337 * | |
| 338 * Attempts to determine what the session type may be. | |
| 339 **/ | |
| 340 gint | |
| 341 audacious_determine_session_type(gint session) | |
| 342 { | |
| 343 gchar *uri = NULL; | |
| 344 | |
| 345 if (audacious_session_type != 0) | |
| 346 { | |
| 347 return audacious_session_type; | |
| 348 } | |
| 349 | |
| 350 uri = audacious_get_session_uri(session); | |
| 351 | |
| 352 if (!g_strncasecmp(uri, "tcp://", 6)) | |
| 353 audacious_session_type = AUDACIOUS_TYPE_TCP; | |
| 354 else | |
| 355 audacious_session_type = AUDACIOUS_TYPE_UNIX; | |
| 356 | |
| 357 if (audacious_session_type == 0) | |
| 358 audacious_session_type = AUDACIOUS_TYPE_UNIX; | |
| 359 | |
| 360 /* memory leak! */ | |
| 361 g_free(uri); | |
| 362 | |
| 363 return audacious_session_type; | |
| 364 } | |
| 365 | |
| 366 /* tcp://192.168.100.1:5900/zyzychynxi389xvmfewqaxznvnw */ | |
| 367 | |
| 368 /** | |
| 369 * audacious_decode_tcp_uri: | |
| 370 * @session: The legacy XMMS session id (usually 0). | |
| 371 * @in: A TCP:// Session URI to decode. | |
| 372 * @host: Pointer to a host buffer. | |
| 373 * @port: Pointer to the TCP port. | |
| 374 * @key: Pointer to a security key buffer. | |
| 375 * | |
| 376 * Decodes a tcp:// session URI. | |
| 377 **/ | |
| 378 void | |
| 379 audacious_decode_tcp_uri(gint session, gchar *in, gchar **host, gint *port, gchar **key) | |
| 380 { | |
| 381 static gchar *workbuf, *keybuf; | |
| 382 gint iport; | |
| 383 gchar *tmp = g_strdup(in); | |
| 384 | |
| 385 /* split out the host/port and key */ | |
| 386 workbuf = tmp; | |
| 387 workbuf += 6; | |
| 388 | |
| 389 keybuf = strchr(workbuf, '/'); | |
| 390 *keybuf++ = '\0'; | |
| 391 | |
| 392 *key = g_strdup(keybuf); | |
| 393 | |
| 394 if (strchr(workbuf, ':') == NULL) | |
| 395 { | |
| 396 *host = g_strdup(workbuf); | |
| 397 *port = 37370 + session; | |
| 398 } | |
| 399 else | |
| 400 { | |
| 401 gchar *hostbuf = NULL; | |
| 402 sscanf(workbuf, "%s:%d", hostbuf, &iport); | |
| 403 | |
| 404 *port = iport + session; | |
| 405 } | |
| 406 | |
| 407 g_free(tmp); | |
| 408 } | |
| 409 | |
| 410 /* unix://localhost/tmp/audacious_nenolod.0 */ | |
| 411 | |
| 412 /** | |
| 413 * audacious_decode_unix_uri: | |
| 414 * @session: The legacy XMMS session id (usually 0). | |
| 415 * @in: A UNIX:// Session URI to decode. | |
| 416 * @key: Pointer to a UNIX path buffer. | |
| 417 * | |
| 418 * Decodes a unix:// session URI. | |
| 419 **/ | |
| 420 void | |
| 421 audacious_decode_unix_uri(gint session, gchar *in, gchar **key) | |
| 422 { | |
| 423 static gchar *workbuf, *keybuf; | |
| 424 gchar *tmp = g_strdup(in); | |
| 425 | |
| 426 /* split out the host/port and key */ | |
| 427 workbuf = tmp; | |
| 428 workbuf += 7; | |
| 429 | |
| 430 keybuf = strchr(workbuf, '/'); | |
| 431 *keybuf++ = '\0'; | |
| 432 | |
| 433 *key = g_strdup(keybuf); | |
| 434 | |
| 435 g_free(tmp); | |
| 436 } | |
| 437 | |
| 438 /** | |
| 439 * xmms_connect_to_session: | |
| 440 * @session: Legacy XMMS-style session identifier. | |
| 441 * | |
| 442 * Connects to an audacious server. | |
| 443 * | |
| 444 * Return value: an FD on success, otherwise -1. | |
| 445 **/ | |
| 446 gint | |
| 447 xmms_connect_to_session(gint session) | |
| 448 { | |
| 449 gint fd; | |
| 450 gint type = audacious_determine_session_type(session); | |
| 451 gchar *uri = audacious_get_session_uri(session); | |
| 452 | |
| 453 if (type == AUDACIOUS_TYPE_UNIX) | |
| 454 { | |
| 455 if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) != -1) | |
| 456 { | |
| 457 uid_t stored_uid, euid; | |
| 458 struct sockaddr_un saddr; | |
| 459 gchar *path; | |
| 460 | |
| 461 saddr.sun_family = AF_UNIX; | |
| 462 stored_uid = getuid(); | |
| 463 euid = geteuid(); | |
| 464 setuid(euid); | |
| 465 | |
| 466 audacious_decode_unix_uri(session, uri, &path); | |
| 467 | |
| 468 g_strlcpy(saddr.sun_path, path, 108); | |
| 469 g_free(path); | |
| 470 setreuid(stored_uid, euid); | |
| 471 | |
| 472 g_free(uri); | |
| 473 | |
| 474 if (connect(fd, (struct sockaddr *) &saddr, sizeof(saddr)) != -1) | |
| 475 return fd; | |
| 476 } | |
| 477 } | |
| 478 else | |
| 479 { | |
| 480 if ((fd = socket(AF_INET, SOCK_STREAM, 0)) != -1) | |
| 481 { | |
| 482 struct hostent *hp; | |
| 483 struct sockaddr_in saddr; | |
| 484 gchar *host, *key; | |
| 485 gint port; | |
| 486 | |
| 487 audacious_decode_tcp_uri(session, uri, &host, &port, &key); | |
| 488 | |
| 489 /* resolve it */ | |
| 490 if ((hp = gethostbyname(host)) == NULL) | |
| 491 { | |
| 492 close(fd); | |
| 493 return -1; | |
| 494 } | |
| 495 | |
| 496 memset(&saddr, '\0', sizeof(saddr)); | |
| 497 saddr.sin_family = AF_INET; | |
| 498 saddr.sin_port = htons(port); | |
| 499 memcpy(&saddr.sin_addr, hp->h_addr, hp->h_length); | |
| 500 | |
| 501 g_free(host); | |
| 502 g_free(key); | |
| 503 | |
| 504 g_free(uri); | |
| 505 | |
| 506 if (connect(fd, (struct sockaddr *) &saddr, sizeof(saddr)) != -1) | |
| 507 return fd; | |
| 508 } | |
| 509 } | |
| 510 | |
| 511 close(fd); | |
| 512 return -1; | |
| 513 } | |
| 514 | |
| 515 /** | |
| 516 * xmms_remote_playlist: | |
| 517 * @session: Legacy XMMS-style session identifier. | |
| 518 * @list: A list of URIs to play. | |
| 519 * @num: Number of URIs to play. | |
| 520 * @enqueue: Whether or not the new playlist should be added on, or replace the current playlist. | |
| 521 * | |
| 522 * Sends a playlist to audacious. | |
| 523 **/ | |
| 524 void | |
| 525 xmms_remote_playlist(gint session, gchar ** list, gint num, gboolean enqueue) | |
| 526 { | |
| 527 gint fd, i; | |
| 528 gchar *data, *ptr; | |
| 529 gint data_length; | |
| 530 guint32 len; | |
| 531 | |
| 532 g_return_if_fail(list != NULL); | |
| 533 g_return_if_fail(num > 0); | |
| 534 | |
| 535 if (!enqueue) | |
| 536 xmms_remote_playlist_clear(session); | |
| 537 | |
| 538 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 539 return; | |
| 540 | |
| 541 for (i = 0, data_length = 0; i < num; i++) | |
| 542 data_length += (((strlen(list[i]) + 1) + 3) / 4) * 4 + 4; | |
| 543 if (data_length) { | |
| 544 data_length += 4; | |
| 545 data = g_malloc(data_length); | |
| 546 for (i = 0, ptr = data; i < num; i++) { | |
| 547 len = strlen(list[i]) + 1; | |
| 548 *((guint32 *) ptr) = len; | |
| 549 ptr += 4; | |
| 550 memcpy(ptr, list[i], len); | |
| 551 ptr += ((len + 3) / 4) * 4; | |
| 552 } | |
| 553 *((guint32 *) ptr) = 0; | |
| 554 remote_send_packet(fd, CMD_PLAYLIST_ADD, data, data_length); | |
| 555 remote_read_ack(fd); | |
| 556 close(fd); | |
| 557 g_free(data); | |
| 558 } | |
| 559 | |
| 560 if (!enqueue) | |
| 561 xmms_remote_play(session); | |
| 562 } | |
| 563 | |
| 564 /** | |
| 565 * xmms_remote_get_version: | |
| 566 * @session: Legacy XMMS-style session identifier. | |
| 567 * | |
| 568 * Queries audacious for it's protocol version. | |
| 569 * | |
| 570 * Return value: The protocol version used by Audacious. | |
| 571 **/ | |
| 572 gint | |
| 573 xmms_remote_get_version(gint session) | |
| 574 { | |
| 575 return remote_get_gint(session, CMD_GET_VERSION); | |
| 576 } | |
| 577 | |
| 578 /** | |
| 579 * xmms_remote_play_files: | |
| 580 * @session: Legacy XMMS-style session identifier. | |
| 581 * @list: A GList of URIs to play. | |
| 582 * | |
| 583 * Sends a list of URIs to Audacious to play. | |
| 584 **/ | |
| 585 void | |
| 586 xmms_remote_play_files(gint session, GList * list) | |
| 587 { | |
| 588 g_return_if_fail(list != NULL); | |
| 589 | |
| 590 xmms_remote_playlist_clear(session); | |
| 591 xmms_remote_playlist_add(session, list); | |
| 592 xmms_remote_play(session); | |
| 593 } | |
| 594 | |
| 595 /** | |
| 596 * xmms_remote_playlist_add: | |
| 597 * @session: Legacy XMMS-style session identifier. | |
| 598 * @list: A GList of URIs to add to the playlist. | |
| 599 * | |
| 600 * Sends a list of URIs to Audacious to add to the playlist. | |
| 601 **/ | |
| 602 void | |
| 603 xmms_remote_playlist_add(gint session, GList * list) | |
| 604 { | |
| 605 gchar **str_list; | |
| 606 GList *node; | |
| 607 gint i, num; | |
| 608 | |
| 609 g_return_if_fail(list != NULL); | |
| 610 | |
| 611 num = g_list_length(list); | |
| 612 str_list = g_malloc0(num * sizeof(gchar *)); | |
| 613 for (i = 0, node = list; i < num && node; i++, node = g_list_next(node)) | |
| 614 str_list[i] = node->data; | |
| 615 | |
| 616 xmms_remote_playlist(session, str_list, num, TRUE); | |
| 617 g_free(str_list); | |
| 618 } | |
| 619 | |
| 620 /** | |
| 621 * xmms_remote_playlist_delete: | |
| 622 * @session: Legacy XMMS-style session identifier. | |
| 623 * @pos: The playlist position to delete. | |
| 624 * | |
| 625 * Deletes a playlist entry. | |
| 626 **/ | |
| 627 void | |
| 628 xmms_remote_playlist_delete(gint session, gint pos) | |
| 629 { | |
| 630 remote_send_guint32(session, CMD_PLAYLIST_DELETE, pos); | |
| 631 } | |
| 632 | |
| 633 /** | |
| 634 * xmms_remote_play: | |
| 635 * @session: Legacy XMMS-style session identifier. | |
| 636 * | |
| 637 * Tells audacious to begin playback. | |
| 638 **/ | |
| 639 void | |
| 640 xmms_remote_play(gint session) | |
| 641 { | |
| 642 remote_cmd(session, CMD_PLAY); | |
| 643 } | |
| 644 | |
| 645 /** | |
| 646 * xmms_remote_pause: | |
| 647 * @session: Legacy XMMS-style session identifier. | |
| 648 * | |
| 649 * Tells audacious to pause. | |
| 650 **/ | |
| 651 void | |
| 652 xmms_remote_pause(gint session) | |
| 653 { | |
| 654 remote_cmd(session, CMD_PAUSE); | |
| 655 } | |
| 656 | |
| 657 /** | |
| 658 * xmms_remote_stop: | |
| 659 * @session: Legacy XMMS-style session identifier. | |
| 660 * | |
| 661 * Tells audacious to stop. | |
| 662 **/ | |
| 663 void | |
| 664 xmms_remote_stop(gint session) | |
| 665 { | |
| 666 remote_cmd(session, CMD_STOP); | |
| 667 } | |
| 668 | |
| 669 /** | |
| 670 * xmms_remote_play_pause: | |
| 671 * @session: Legacy XMMS-style session identifier. | |
| 672 * | |
| 673 * Tells audacious to either play or pause. | |
| 674 **/ | |
| 675 void | |
| 676 xmms_remote_play_pause(gint session) | |
| 677 { | |
| 678 remote_cmd(session, CMD_PLAY_PAUSE); | |
| 679 } | |
| 680 | |
| 681 /** | |
| 682 * xmms_remote_is_playing: | |
| 683 * @session: Legacy XMMS-style session identifier. | |
| 684 * | |
| 685 * Queries audacious about whether it is playing or not. | |
| 686 * | |
| 687 * Return value: TRUE if playing, FALSE otherwise. | |
| 688 **/ | |
| 689 gboolean | |
| 690 xmms_remote_is_playing(gint session) | |
| 691 { | |
| 692 return remote_get_gboolean(session, CMD_IS_PLAYING); | |
| 693 } | |
| 694 | |
| 695 /** | |
| 696 * xmms_remote_is_paused: | |
| 697 * @session: Legacy XMMS-style session identifier. | |
| 698 * | |
| 699 * Queries audacious about whether it is paused or not. | |
| 700 * | |
| 701 * Return value: TRUE if playing, FALSE otherwise. | |
| 702 **/ | |
| 703 gboolean | |
| 704 xmms_remote_is_paused(gint session) | |
| 705 { | |
| 706 return remote_get_gboolean(session, CMD_IS_PAUSED); | |
| 707 } | |
| 708 | |
| 709 /** | |
| 710 * xmms_remote_get_playlist_pos: | |
| 711 * @session: Legacy XMMS-style session identifier. | |
| 712 * | |
| 713 * Queries audacious about the current playlist position. | |
| 714 * | |
| 715 * Return value: The current playlist position. | |
| 716 **/ | |
| 717 gint | |
| 718 xmms_remote_get_playlist_pos(gint session) | |
| 719 { | |
| 720 return remote_get_gint(session, CMD_GET_PLAYLIST_POS); | |
| 721 } | |
| 722 | |
| 723 /** | |
| 724 * xmms_remote_set_playlist_pos: | |
| 725 * @session: Legacy XMMS-style session identifier. | |
| 726 * @pos: Playlist position to jump to. | |
| 727 * | |
| 728 * Tells audacious to jump to a different playlist position. | |
| 729 **/ | |
| 730 void | |
| 731 xmms_remote_set_playlist_pos(gint session, gint pos) | |
| 732 { | |
| 733 remote_send_guint32(session, CMD_SET_PLAYLIST_POS, pos); | |
| 734 } | |
| 735 | |
| 736 /** | |
| 737 * xmms_remote_get_playlist_length: | |
| 738 * @session: Legacy XMMS-style session identifier. | |
| 739 * | |
| 740 * Queries audacious about the current playlist length. | |
| 741 * | |
| 742 * Return value: The amount of entries in the playlist. | |
| 743 **/ | |
| 744 gint | |
| 745 xmms_remote_get_playlist_length(gint session) | |
| 746 { | |
| 747 return remote_get_gint(session, CMD_GET_PLAYLIST_LENGTH); | |
| 748 } | |
| 749 | |
| 750 /** | |
| 751 * xmms_remote_playlist_clear: | |
| 752 * @session: Legacy XMMS-style session identifier. | |
| 753 * | |
| 754 * Clears the playlist. | |
| 755 **/ | |
| 756 void | |
| 757 xmms_remote_playlist_clear(gint session) | |
| 758 { | |
| 759 remote_cmd(session, CMD_PLAYLIST_CLEAR); | |
| 760 } | |
| 761 | |
| 762 /** | |
| 763 * xmms_remote_get_output_time: | |
| 764 * @session: Legacy XMMS-style session identifier. | |
| 765 * | |
| 766 * Queries audacious about the current output position. | |
| 767 * | |
| 768 * Return value: The current output position. | |
| 769 **/ | |
| 770 gint | |
| 771 xmms_remote_get_output_time(gint session) | |
| 772 { | |
| 773 return remote_get_gint(session, CMD_GET_OUTPUT_TIME); | |
| 774 } | |
| 775 | |
| 776 /** | |
| 777 * xmms_remote_jump_to_time: | |
| 778 * @session: Legacy XMMS-style session identifier. | |
| 779 * @pos: The time (in milliseconds) to jump to. | |
| 780 * | |
| 781 * Tells audacious to seek to a new time position. | |
| 782 **/ | |
| 783 void | |
| 784 xmms_remote_jump_to_time(gint session, gint pos) | |
| 785 { | |
| 786 remote_send_guint32(session, CMD_JUMP_TO_TIME, pos); | |
| 787 } | |
| 788 | |
| 789 /** | |
| 790 * xmms_remote_get_volume: | |
| 791 * @session: Legacy XMMS-style session identifier. | |
| 792 * @vl: Pointer to integer containing the left channel's volume. | |
| 793 * @vr: Pointer to integer containing the right channel's volume. | |
| 794 * | |
| 795 * Queries audacious about the current volume. | |
| 796 **/ | |
| 797 void | |
| 798 xmms_remote_get_volume(gint session, gint * vl, gint * vr) | |
| 799 { | |
| 800 gint fd; | |
| 801 gpointer data; | |
| 802 | |
| 803 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 804 return; | |
| 805 | |
| 806 remote_send_packet(fd, CMD_GET_VOLUME, NULL, 0); | |
| 807 data = remote_read_packet(fd); | |
| 808 if (data) { | |
| 809 *vl = ((guint32 *) data)[0]; | |
| 810 *vr = ((guint32 *) data)[1]; | |
| 811 g_free(data); | |
| 812 } | |
| 813 remote_read_ack(fd); | |
| 814 close(fd); | |
| 815 } | |
| 816 | |
| 817 /** | |
| 818 * xmms_remote_get_main_volume: | |
| 819 * @session: Legacy XMMS-style session identifier. | |
| 820 * | |
| 821 * Queries audacious about the current volume. | |
| 822 * | |
| 823 * Return value: The current volume. | |
| 824 **/ | |
| 825 gint | |
| 826 xmms_remote_get_main_volume(gint session) | |
| 827 { | |
| 828 gint vl, vr; | |
| 829 | |
| 830 xmms_remote_get_volume(session, &vl, &vr); | |
| 831 | |
| 832 return (vl > vr) ? vl : vr; | |
| 833 } | |
| 834 | |
| 835 /** | |
| 836 * xmms_remote_get_balance: | |
| 837 * @session: Legacy XMMS-style session identifier. | |
| 838 * | |
| 839 * Queries audacious about the current balance. | |
| 840 * | |
| 841 * Return value: The current balance. | |
| 842 **/ | |
| 843 gint | |
| 844 xmms_remote_get_balance(gint session) | |
| 845 { | |
| 846 return remote_get_gint(session, CMD_GET_BALANCE); | |
| 847 } | |
| 848 | |
| 849 /** | |
| 850 * xmms_remote_set_volume: | |
| 851 * @session: Legacy XMMS-style session identifier. | |
| 852 * @vl: The volume for the left channel. | |
| 853 * @vr: The volume for the right channel. | |
| 854 * | |
| 855 * Sets the volume for the left and right channels in Audacious. | |
| 856 **/ | |
| 857 void | |
| 858 xmms_remote_set_volume(gint session, gint vl, gint vr) | |
| 859 { | |
| 860 gint fd; | |
| 861 guint32 v[2]; | |
| 862 | |
| 863 if (vl < 0) | |
| 864 vl = 0; | |
| 865 if (vl > 100) | |
| 866 vl = 100; | |
| 867 if (vr < 0) | |
| 868 vr = 0; | |
| 869 if (vr > 100) | |
| 870 vr = 100; | |
| 871 | |
| 872 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 873 return; | |
| 874 v[0] = vl; | |
| 875 v[1] = vr; | |
| 876 remote_send_packet(fd, CMD_SET_VOLUME, v, 2 * sizeof(guint32)); | |
| 877 remote_read_ack(fd); | |
| 878 close(fd); | |
| 879 } | |
| 880 | |
| 881 /** | |
| 882 * xmms_remote_set_main_volume: | |
| 883 * @session: Legacy XMMS-style session identifier. | |
| 884 * @v: The volume to set. | |
| 885 * | |
| 886 * Sets the volume in Audacious. | |
| 887 **/ | |
| 888 void | |
| 889 xmms_remote_set_main_volume(gint session, gint v) | |
| 890 { | |
| 891 gint b, vl, vr; | |
| 892 | |
| 893 b = xmms_remote_get_balance(session); | |
| 894 | |
| 895 if (b < 0) { | |
| 896 vl = v; | |
| 897 vr = (v * (100 - abs(b))) / 100; | |
| 898 } | |
| 899 else if (b > 0) { | |
| 900 vl = (v * (100 - b)) / 100; | |
| 901 vr = v; | |
| 902 } | |
| 903 else | |
| 904 vl = vr = v; | |
| 905 xmms_remote_set_volume(session, vl, vr); | |
| 906 } | |
| 907 | |
| 908 /** | |
| 909 * xmms_remote_set_balance: | |
| 910 * @session: Legacy XMMS-style session identifier. | |
| 911 * @b: The balance to set. | |
| 912 * | |
| 913 * Sets the balance in Audacious. | |
| 914 **/ | |
| 915 void | |
| 916 xmms_remote_set_balance(gint session, gint b) | |
| 917 { | |
| 918 gint v, vl, vr; | |
| 919 | |
| 920 if (b < -100) | |
| 921 b = -100; | |
| 922 if (b > 100) | |
| 923 b = 100; | |
| 924 | |
| 925 v = xmms_remote_get_main_volume(session); | |
| 926 | |
| 927 if (b < 0) { | |
| 928 vl = v; | |
| 929 vr = (v * (100 - abs(b))) / 100; | |
| 930 } | |
| 931 else if (b > 0) { | |
| 932 vl = (v * (100 - b)) / 100; | |
| 933 vr = v; | |
| 934 } | |
| 935 else | |
| 936 vl = vr = v; | |
| 937 xmms_remote_set_volume(session, vl, vr); | |
| 938 } | |
| 939 | |
| 940 /** | |
| 941 * xmms_remote_get_skin: | |
| 942 * @session: Legacy XMMS-style session identifier. | |
| 943 * | |
| 944 * Queries Audacious about it's skin. | |
| 945 * | |
| 946 * Return value: A path to the currently selected skin. | |
| 947 **/ | |
| 948 gchar * | |
| 949 xmms_remote_get_skin(gint session) | |
| 950 { | |
| 951 return remote_get_string(session, CMD_GET_SKIN); | |
| 952 } | |
| 953 | |
| 954 /** | |
| 955 * xmms_remote_set_skin: | |
| 956 * @session: Legacy XMMS-style session identifier. | |
| 957 * @skinfile: Path to a skinfile to use with Audacious. | |
| 958 * | |
| 959 * Tells audacious to start using the skinfile provided. | |
| 960 **/ | |
| 961 void | |
| 962 xmms_remote_set_skin(gint session, gchar * skinfile) | |
| 963 { | |
| 964 remote_send_string(session, CMD_SET_SKIN, skinfile); | |
| 965 } | |
| 966 | |
| 967 /** | |
| 968 * xmms_remote_get_playlist_file: | |
| 969 * @session: Legacy XMMS-style session identifier. | |
| 970 * @pos: The playlist position to query for. | |
| 971 * | |
| 972 * Queries Audacious about a playlist entry's file. | |
| 973 * | |
| 974 * Return value: A path to the file in the playlist at %pos position. | |
| 975 **/ | |
| 976 gchar * | |
| 977 xmms_remote_get_playlist_file(gint session, gint pos) | |
| 978 { | |
| 979 return remote_get_string_pos(session, CMD_GET_PLAYLIST_FILE, pos); | |
| 980 } | |
| 981 | |
| 982 /** | |
| 983 * xmms_remote_get_playlist_title: | |
| 984 * @session: Legacy XMMS-style session identifier. | |
| 985 * @pos: The playlist position to query for. | |
| 986 * | |
| 987 * Queries Audacious about a playlist entry's title. | |
| 988 * | |
| 989 * Return value: The title for the entry in the playlist at %pos position. | |
| 990 **/ | |
| 991 gchar * | |
| 992 xmms_remote_get_playlist_title(gint session, gint pos) | |
| 993 { | |
| 994 return remote_get_string_pos(session, CMD_GET_PLAYLIST_TITLE, pos); | |
| 995 } | |
| 996 | |
| 997 /** | |
| 998 * xmms_remote_get_playlist_time: | |
| 999 * @session: Legacy XMMS-style session identifier. | |
| 1000 * @pos: The playlist position to query for. | |
| 1001 * | |
| 1002 * Queries Audacious about a playlist entry's length. | |
| 1003 * | |
| 1004 * Return value: The length of the entry in the playlist at %pos position. | |
| 1005 **/ | |
| 1006 gint | |
| 1007 xmms_remote_get_playlist_time(gint session, gint pos) | |
| 1008 { | |
| 1009 gpointer data; | |
| 1010 gint fd, ret = 0; | |
| 1011 guint32 p = pos; | |
| 1012 | |
| 1013 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 1014 return ret; | |
| 1015 remote_send_packet(fd, CMD_GET_PLAYLIST_TIME, &p, sizeof(guint32)); | |
| 1016 data = remote_read_packet(fd); | |
| 1017 if (data) { | |
| 1018 ret = *((gint *) data); | |
| 1019 g_free(data); | |
| 1020 } | |
| 1021 remote_read_ack(fd); | |
| 1022 close(fd); | |
| 1023 return ret; | |
| 1024 } | |
| 1025 | |
| 1026 /** | |
| 1027 * xmms_remote_get_info: | |
| 1028 * @session: Legacy XMMS-style session identifier. | |
| 1029 * @rate: Pointer to an integer containing the bitrate. | |
| 1030 * @freq: Pointer to an integer containing the frequency. | |
| 1031 * @nch: Pointer to an integer containing the number of channels. | |
| 1032 * | |
| 1033 * Queries Audacious about the current audio format. | |
| 1034 **/ | |
| 1035 void | |
| 1036 xmms_remote_get_info(gint session, gint * rate, gint * freq, gint * nch) | |
| 1037 { | |
| 1038 gint fd; | |
| 1039 gpointer data; | |
| 1040 | |
| 1041 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 1042 return; | |
| 1043 remote_send_packet(fd, CMD_GET_INFO, NULL, 0); | |
| 1044 data = remote_read_packet(fd); | |
| 1045 if (data) { | |
| 1046 *rate = ((guint32 *) data)[0]; | |
| 1047 *freq = ((guint32 *) data)[1]; | |
| 1048 *nch = ((guint32 *) data)[2]; | |
| 1049 g_free(data); | |
| 1050 } | |
| 1051 remote_read_ack(fd); | |
| 1052 close(fd); | |
| 1053 } | |
| 1054 | |
| 1055 /** | |
| 1056 * xmms_remote_get_eq_data: | |
| 1057 * @session: Legacy XMMS-style session identifier. | |
| 1058 * | |
| 1059 * Not implemented, present for compatibility with libxmms API. | |
| 1060 **/ | |
| 1061 void | |
| 1062 xmms_remote_get_eq_data(gint session) | |
| 1063 { | |
| 1064 /* Obsolete */ | |
| 1065 } | |
| 1066 | |
| 1067 /** | |
| 1068 * xmms_remote_set_eq_data: | |
| 1069 * @session: Legacy XMMS-style session identifier. | |
| 1070 * | |
| 1071 * Not implemented, present for compatibility with libxmms API. | |
| 1072 **/ | |
| 1073 void | |
| 1074 xmms_remote_set_eq_data(gint session) | |
| 1075 { | |
| 1076 /* Obsolete */ | |
| 1077 } | |
| 1078 | |
| 1079 /** | |
| 1080 * xmms_remote_pl_win_toggle: | |
| 1081 * @session: Legacy XMMS-style session identifier. | |
| 1082 * @show: Whether or not to show the playlist window. | |
| 1083 * | |
| 1084 * Toggles the playlist window's visibility. | |
| 1085 **/ | |
| 1086 void | |
| 1087 xmms_remote_pl_win_toggle(gint session, gboolean show) | |
| 1088 { | |
| 1089 remote_send_boolean(session, CMD_PL_WIN_TOGGLE, show); | |
| 1090 } | |
| 1091 | |
| 1092 /** | |
| 1093 * xmms_remote_eq_win_toggle: | |
| 1094 * @session: Legacy XMMS-style session identifier. | |
| 1095 * @show: Whether or not to show the equalizer window. | |
| 1096 * | |
| 1097 * Toggles the equalizer window's visibility. | |
| 1098 **/ | |
| 1099 void | |
| 1100 xmms_remote_eq_win_toggle(gint session, gboolean show) | |
| 1101 { | |
| 1102 remote_send_boolean(session, CMD_EQ_WIN_TOGGLE, show); | |
| 1103 } | |
| 1104 | |
| 1105 /** | |
| 1106 * xmms_remote_main_win_toggle: | |
| 1107 * @session: Legacy XMMS-style session identifier. | |
| 1108 * @show: Whether or not to show the main window. | |
| 1109 * | |
| 1110 * Toggles the main window's visibility. | |
| 1111 **/ | |
| 1112 void | |
| 1113 xmms_remote_main_win_toggle(gint session, gboolean show) | |
| 1114 { | |
| 1115 remote_send_boolean(session, CMD_MAIN_WIN_TOGGLE, show); | |
| 1116 } | |
| 1117 | |
| 1118 /** | |
| 1119 * xmms_remote_is_main_win: | |
| 1120 * @session: Legacy XMMS-style session identifier. | |
| 1121 * | |
| 1122 * Queries Audacious about the main window's visibility. | |
| 1123 * | |
| 1124 * Return value: TRUE if visible, FALSE otherwise. | |
| 1125 **/ | |
| 1126 gboolean | |
| 1127 xmms_remote_is_main_win(gint session) | |
| 1128 { | |
| 1129 return remote_get_gboolean(session, CMD_IS_MAIN_WIN); | |
| 1130 } | |
| 1131 | |
| 1132 /** | |
| 1133 * xmms_remote_is_pl_win: | |
| 1134 * @session: Legacy XMMS-style session identifier. | |
| 1135 * | |
| 1136 * Queries Audacious about the playlist window's visibility. | |
| 1137 * | |
| 1138 * Return value: TRUE if visible, FALSE otherwise. | |
| 1139 **/ | |
| 1140 gboolean | |
| 1141 xmms_remote_is_pl_win(gint session) | |
| 1142 { | |
| 1143 return remote_get_gboolean(session, CMD_IS_PL_WIN); | |
| 1144 } | |
| 1145 | |
| 1146 /** | |
| 1147 * xmms_remote_is_eq_win: | |
| 1148 * @session: Legacy XMMS-style session identifier. | |
| 1149 * | |
| 1150 * Queries Audacious about the equalizer window's visibility. | |
| 1151 * | |
| 1152 * Return value: TRUE if visible, FALSE otherwise. | |
| 1153 **/ | |
| 1154 gboolean | |
| 1155 xmms_remote_is_eq_win(gint session) | |
| 1156 { | |
| 1157 return remote_get_gboolean(session, CMD_IS_EQ_WIN); | |
| 1158 } | |
| 1159 | |
| 1160 /** | |
| 1161 * xmms_remote_show_prefs_box: | |
| 1162 * @session: Legacy XMMS-style session identifier. | |
| 1163 * | |
| 1164 * Tells audacious to show the preferences pane. | |
| 1165 **/ | |
| 1166 void | |
| 1167 xmms_remote_show_prefs_box(gint session) | |
| 1168 { | |
| 1169 remote_cmd(session, CMD_SHOW_PREFS_BOX); | |
| 1170 } | |
| 1171 | |
| 1172 /** | |
| 1173 * xmms_remote_show_jtf_box: | |
| 1174 * @session: Legacy XMMS-style session identifier. | |
| 1175 * | |
| 1176 * Tells audacious to show the Jump-to-File pane. | |
| 1177 **/ | |
| 1178 void | |
| 1179 xmms_remote_show_jtf_box(gint session) | |
| 1180 { | |
| 1181 remote_cmd(session, CMD_SHOW_JTF_BOX); | |
| 1182 } | |
| 1183 | |
| 1184 /** | |
| 1185 * xmms_remote_toggle_aot: | |
| 1186 * @session: Legacy XMMS-style session identifier. | |
| 1187 * @ontop: Whether or not Audacious should be always-on-top. | |
| 1188 * | |
| 1189 * Tells audacious to toggle the always-on-top feature. | |
| 1190 **/ | |
| 1191 void | |
| 1192 xmms_remote_toggle_aot(gint session, gboolean ontop) | |
| 1193 { | |
| 1194 remote_send_boolean(session, CMD_TOGGLE_AOT, ontop); | |
| 1195 } | |
| 1196 | |
| 1197 /** | |
| 1198 * xmms_remote_show_about_box: | |
| 1199 * @session: Legacy XMMS-style session identifier. | |
| 1200 * | |
| 1201 * Tells audacious to show the about pane. | |
| 1202 **/ | |
| 1203 void | |
| 1204 xmms_remote_show_about_box(gint session) | |
| 1205 { | |
| 1206 remote_cmd(session, CMD_SHOW_ABOUT_BOX); | |
| 1207 } | |
| 1208 | |
| 1209 /** | |
| 1210 * xmms_remote_eject: | |
| 1211 * @session: Legacy XMMS-style session identifier. | |
| 1212 * | |
| 1213 * Tells audacious to display the open files pane. | |
| 1214 **/ | |
| 1215 void | |
| 1216 xmms_remote_eject(gint session) | |
| 1217 { | |
| 1218 remote_cmd(session, CMD_EJECT); | |
| 1219 } | |
| 1220 | |
| 1221 /** | |
| 1222 * xmms_remote_playlist_prev: | |
| 1223 * @session: Legacy XMMS-style session identifier. | |
| 1224 * | |
| 1225 * Tells audacious to move backwards in the playlist. | |
| 1226 **/ | |
| 1227 void | |
| 1228 xmms_remote_playlist_prev(gint session) | |
| 1229 { | |
| 1230 remote_cmd(session, CMD_PLAYLIST_PREV); | |
| 1231 } | |
| 1232 | |
| 1233 /** | |
| 1234 * xmms_remote_playlist_next: | |
| 1235 * @session: Legacy XMMS-style session identifier. | |
| 1236 * | |
| 1237 * Tells audacious to move forward in the playlist. | |
| 1238 **/ | |
| 1239 void | |
| 1240 xmms_remote_playlist_next(gint session) | |
| 1241 { | |
| 1242 remote_cmd(session, CMD_PLAYLIST_NEXT); | |
| 1243 } | |
| 1244 | |
| 1245 /** | |
| 1246 * xmms_remote_playlist_add_url_string: | |
| 1247 * @session: Legacy XMMS-style session identifier. | |
| 1248 * @string: The URI to add. | |
| 1249 * | |
| 1250 * Tells audacious to add an URI to the playlist. | |
| 1251 **/ | |
| 1252 void | |
| 1253 xmms_remote_playlist_add_url_string(gint session, gchar * string) | |
| 1254 { | |
| 1255 g_return_if_fail(string != NULL); | |
| 1256 remote_send_string(session, CMD_PLAYLIST_ADD_URL_STRING, string); | |
| 1257 } | |
| 1258 | |
| 1259 /** | |
| 1260 * xmms_remote_playlist_enqueue_to_temp: | |
| 1261 * @session: Legacy XMMS-style session identifier. | |
| 1262 * @string: The URI to enqueue to a temporary playlist. | |
| 1263 * | |
| 1264 * Tells audacious to add an URI to a temporary playlist. | |
| 1265 **/ | |
| 1266 void | |
| 1267 xmms_remote_playlist_enqueue_to_temp(gint session, gchar * string) | |
| 1268 { | |
| 1269 g_return_if_fail(string != NULL); | |
| 1270 remote_send_string(session, CMD_PLAYLIST_ENQUEUE_TO_TEMP, string); | |
| 1271 } | |
| 1272 | |
| 1273 /** | |
| 1274 * xmms_remote_playlist_ins_url_string: | |
| 1275 * @session: Legacy XMMS-style session identifier. | |
| 1276 * @string: The URI to add. | |
| 1277 * @pos: The position to add the URI at. | |
| 1278 * | |
| 1279 * Tells audacious to add an URI to the playlist at a specific position. | |
| 1280 **/ | |
| 1281 void | |
| 1282 xmms_remote_playlist_ins_url_string(gint session, gchar * string, gint pos) | |
| 1283 { | |
| 1284 gint fd, size; | |
| 1285 gchar *packet; | |
| 1286 | |
| 1287 g_return_if_fail(string != NULL); | |
| 1288 | |
| 1289 size = strlen(string) + 1 + sizeof(gint); | |
| 1290 | |
| 1291 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 1292 return; | |
| 1293 | |
| 1294 packet = g_malloc0(size); | |
| 1295 *((gint *) packet) = pos; | |
| 1296 strcpy(packet + sizeof(gint), string); | |
| 1297 remote_send_packet(fd, CMD_PLAYLIST_INS_URL_STRING, packet, size); | |
| 1298 remote_read_ack(fd); | |
| 1299 close(fd); | |
| 1300 g_free(packet); | |
| 1301 } | |
| 1302 | |
| 1303 /** | |
| 1304 * xmms_remote_is_running: | |
| 1305 * @session: Legacy XMMS-style session identifier. | |
| 1306 * | |
| 1307 * Checks to see if an Audacious server is running. | |
| 1308 * | |
| 1309 * Return value: TRUE if yes, otherwise FALSE. | |
| 1310 **/ | |
| 1311 gboolean | |
| 1312 xmms_remote_is_running(gint session) | |
| 1313 { | |
| 1314 return remote_cmd(session, CMD_PING); | |
| 1315 } | |
| 1316 | |
| 1317 /** | |
| 1318 * xmms_remote_toggle_repeat: | |
| 1319 * @session: Legacy XMMS-style session identifier. | |
| 1320 * | |
| 1321 * Tells audacious to toggle the repeat feature. | |
| 1322 **/ | |
| 1323 void | |
| 1324 xmms_remote_toggle_repeat(gint session) | |
| 1325 { | |
| 1326 remote_cmd(session, CMD_TOGGLE_REPEAT); | |
| 1327 } | |
| 1328 | |
| 1329 /** | |
| 1330 * xmms_remote_toggle_shuffle: | |
| 1331 * @session: Legacy XMMS-style session identifier. | |
| 1332 * | |
| 1333 * Tells audacious to toggle the shuffle feature. | |
| 1334 **/ | |
| 1335 void | |
| 1336 xmms_remote_toggle_shuffle(gint session) | |
| 1337 { | |
| 1338 remote_cmd(session, CMD_TOGGLE_SHUFFLE); | |
| 1339 } | |
| 1340 | |
| 1341 /** | |
| 1342 * xmms_remote_toggle_advance: | |
| 1343 * @session: Legacy XMMS-style session identifier. | |
| 1344 * | |
| 1345 * Tells audacious to toggle the no-playlist-advance feature. | |
| 1346 **/ | |
| 1347 void | |
| 1348 xmms_remote_toggle_advance(int session) | |
| 1349 { | |
| 1350 remote_cmd(session, CMD_TOGGLE_ADVANCE); | |
| 1351 } | |
| 1352 | |
| 1353 /** | |
| 1354 * xmms_remote_is_repeat: | |
| 1355 * @session: Legacy XMMS-style session identifier. | |
| 1356 * | |
| 1357 * Queries audacious about whether or not the repeat feature is active. | |
| 1358 * | |
| 1359 * Return value: TRUE if yes, otherwise FALSE. | |
| 1360 **/ | |
| 1361 gboolean | |
| 1362 xmms_remote_is_repeat(gint session) | |
| 1363 { | |
| 1364 return remote_get_gboolean(session, CMD_IS_REPEAT); | |
| 1365 } | |
| 1366 | |
| 1367 /** | |
| 1368 * xmms_remote_is_shuffle: | |
| 1369 * @session: Legacy XMMS-style session identifier. | |
| 1370 * | |
| 1371 * Queries audacious about whether or not the shuffle feature is active. | |
| 1372 * | |
| 1373 * Return value: TRUE if yes, otherwise FALSE. | |
| 1374 **/ | |
| 1375 gboolean | |
| 1376 xmms_remote_is_shuffle(gint session) | |
| 1377 { | |
| 1378 return remote_get_gboolean(session, CMD_IS_SHUFFLE); | |
| 1379 } | |
| 1380 | |
| 1381 /** | |
| 1382 * xmms_remote_is_advance: | |
| 1383 * @session: Legacy XMMS-style session identifier. | |
| 1384 * | |
| 1385 * Queries audacious about whether or not the no-playlist-advance feature is active. | |
| 1386 * | |
| 1387 * Return value: TRUE if yes, otherwise FALSE. | |
| 1388 **/ | |
| 1389 gboolean | |
| 1390 xmms_remote_is_advance(gint session) | |
| 1391 { | |
| 1392 return remote_get_gboolean(session, CMD_IS_ADVANCE); | |
| 1393 } | |
| 1394 | |
| 1395 /** | |
| 1396 * xmms_remote_playqueue_add: | |
| 1397 * @session: Legacy XMMS-style session identifier. | |
| 1398 * @pos: The playlist position to add to the queue. | |
| 1399 * | |
| 1400 * Tells audacious to add a playlist entry to the playqueue. | |
| 1401 **/ | |
| 1402 void | |
| 1403 xmms_remote_playqueue_add(gint session, gint pos) | |
| 1404 { | |
| 1405 remote_send_guint32(session, CMD_PLAYQUEUE_ADD, pos); | |
| 1406 } | |
| 1407 | |
| 1408 /** | |
| 1409 * xmms_remote_playqueue_remove: | |
| 1410 * @session: Legacy XMMS-style session identifier. | |
| 1411 * @pos: The playlist position to remove from the queue. | |
| 1412 * | |
| 1413 * Tells audacious to remove a playlist entry from the playqueue. | |
| 1414 **/ | |
| 1415 void | |
| 1416 xmms_remote_playqueue_remove(gint session, gint pos) | |
| 1417 { | |
| 1418 remote_send_guint32(session, CMD_PLAYQUEUE_REMOVE, pos); | |
| 1419 } | |
| 1420 | |
| 1421 /** | |
| 1422 * xmms_remote_playqueue_clear: | |
| 1423 * @session: Legacy XMMS-style session identifier. | |
| 1424 * | |
| 1425 * Tells audacious to clear the playqueue. | |
| 1426 **/ | |
| 1427 void | |
| 1428 xmms_remote_playqueue_clear(gint session) | |
| 1429 { | |
| 1430 remote_cmd(session, CMD_PLAYQUEUE_CLEAR); | |
| 1431 } | |
| 1432 | |
| 1433 /** | |
| 1434 * xmms_remote_get_playqueue_length: | |
| 1435 * @session: Legacy XMMS-style session identifier. | |
| 1436 * | |
| 1437 * Queries audacious about the playqueue's length. | |
| 1438 * | |
| 1439 * Return value: The number of entries in the playqueue. | |
| 1440 **/ | |
| 1441 gint | |
| 1442 xmms_remote_get_playqueue_length(gint session) | |
| 1443 { | |
| 1444 return remote_get_gint(session, CMD_GET_PLAYQUEUE_LENGTH); | |
| 1445 } | |
| 1446 | |
| 1447 /** | |
| 1448 * xmms_remote_playqueue_is_queued: | |
| 1449 * @session: Legacy XMMS-style session identifier. | |
| 1450 * @pos: Position to check queue for. | |
| 1451 * | |
| 1452 * Queries audacious about whether or not a playlist entry is in the playqueue. | |
| 1453 * | |
| 1454 * Return value: TRUE if yes, FALSE otherwise. | |
| 1455 **/ | |
| 1456 gboolean | |
| 1457 xmms_remote_playqueue_is_queued(gint session, gint pos) | |
| 1458 { | |
| 1459 gpointer data; | |
| 1460 gint fd, ret = 0; | |
| 1461 guint32 p = pos; | |
| 1462 | |
| 1463 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 1464 return ret; | |
| 1465 remote_send_packet(fd, CMD_PLAYQUEUE_IS_QUEUED, &p, sizeof(guint32)); | |
| 1466 data = remote_read_packet(fd); | |
| 1467 if (data) { | |
| 1468 ret = *((gint *) data); | |
| 1469 g_free(data); | |
| 1470 } | |
| 1471 remote_read_ack(fd); | |
| 1472 close(fd); | |
| 1473 return ret; | |
| 1474 } | |
| 1475 | |
| 1476 /** | |
| 1477 * xmms_remote_get_playqueue_position: | |
| 1478 * @session: Legacy XMMS-style session identifier. | |
| 1479 * @pos: Position to check queue for. | |
| 1480 * | |
| 1481 * Queries audacious about what the playqueue position is for a playlist entry. | |
| 1482 * | |
| 1483 * Return value: TRUE if yes, FALSE otherwise. | |
| 1484 **/ | |
| 1485 gint | |
| 1486 xmms_remote_get_playqueue_position(gint session, gint pos) | |
| 1487 { | |
| 1488 gpointer data; | |
| 1489 gint fd, ret = 0; | |
| 1490 guint32 p = pos; | |
| 1491 | |
| 1492 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 1493 return ret; | |
| 1494 remote_send_packet(fd, CMD_PLAYQUEUE_GET_POS, &p, sizeof(guint32)); | |
| 1495 data = remote_read_packet(fd); | |
| 1496 if (data) { | |
| 1497 ret = *((gint *) data); | |
| 1498 g_free(data); | |
| 1499 } | |
| 1500 remote_read_ack(fd); | |
| 1501 close(fd); | |
| 1502 return ret; | |
| 1503 } | |
| 1504 | |
| 1505 /** | |
| 1506 * xmms_remote_get_playqueue_queue_position: | |
| 1507 * @session: Legacy XMMS-style session identifier. | |
| 1508 * @pos: Position to check queue for. | |
| 1509 * | |
| 1510 * Queries audacious about what the playlist position is for a playqueue entry. | |
| 1511 * | |
| 1512 * Return value: TRUE if yes, FALSE otherwise. | |
| 1513 **/ | |
| 1514 gint | |
| 1515 xmms_remote_get_playqueue_queue_position(gint session, gint pos) | |
| 1516 { | |
| 1517 gpointer data; | |
| 1518 gint fd, ret = 0; | |
| 1519 guint32 p = pos; | |
| 1520 | |
| 1521 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 1522 return ret; | |
| 1523 remote_send_packet(fd, CMD_PLAYQUEUE_GET_QPOS, &p, sizeof(guint32)); | |
| 1524 data = remote_read_packet(fd); | |
| 1525 if (data) { | |
| 1526 ret = *((gint *) data); | |
| 1527 g_free(data); | |
| 1528 } | |
| 1529 remote_read_ack(fd); | |
| 1530 close(fd); | |
| 1531 return ret; | |
| 1532 } | |
| 1533 | |
| 1534 /** | |
| 1535 * xmms_remote_get_eq: | |
| 1536 * @session: Legacy XMMS-style session identifier. | |
| 1537 * @preamp: Pointer to value for preamp setting. | |
| 1538 * @bands: Pointer to array of band settings. | |
| 1539 * | |
| 1540 * Queries audacious about the equalizer settings. | |
| 1541 **/ | |
| 1542 void | |
| 1543 xmms_remote_get_eq(gint session, gfloat * preamp, gfloat ** bands) | |
| 1544 { | |
| 1545 gint fd; | |
| 1546 gpointer data; | |
| 1547 | |
| 1548 if (preamp) | |
| 1549 *preamp = 0.0; | |
| 1550 | |
| 1551 if (bands) | |
| 1552 *bands = NULL; | |
| 1553 | |
| 1554 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 1555 return; | |
| 1556 remote_send_packet(fd, CMD_GET_EQ, NULL, 0); | |
| 1557 data = remote_read_packet(fd); | |
| 1558 if (data) { | |
| 1559 if (preamp) | |
| 1560 *preamp = *((gfloat *) data); | |
| 1561 if (bands) | |
| 1562 *bands = | |
| 1563 (gfloat *) g_memdup((gfloat *) data + 1, | |
| 1564 10 * sizeof(gfloat)); | |
| 1565 g_free(data); | |
| 1566 } | |
| 1567 remote_read_ack(fd); | |
| 1568 close(fd); | |
| 1569 } | |
| 1570 | |
| 1571 /** | |
| 1572 * xmms_remote_get_eq_preamp: | |
| 1573 * @session: Legacy XMMS-style session identifier. | |
| 1574 * | |
| 1575 * Queries audacious about the equalizer preamp's setting. | |
| 1576 * | |
| 1577 * Return value: The equalizer preamp's setting. | |
| 1578 **/ | |
| 1579 gfloat | |
| 1580 xmms_remote_get_eq_preamp(gint session) | |
| 1581 { | |
| 1582 return remote_get_gfloat(session, CMD_GET_EQ_PREAMP); | |
| 1583 } | |
| 1584 | |
| 1585 /** | |
| 1586 * xmms_remote_get_eq_band: | |
| 1587 * @session: Legacy XMMS-style session identifier. | |
| 1588 * @band: Which band to lookup the value for. | |
| 1589 * | |
| 1590 * Queries audacious about an equalizer band's value. | |
| 1591 * | |
| 1592 * Return value: The equalizer band's value. | |
| 1593 **/ | |
| 1594 gfloat | |
| 1595 xmms_remote_get_eq_band(gint session, gint band) | |
| 1596 { | |
| 1597 gint fd; | |
| 1598 gpointer data; | |
| 1599 gfloat val = 0.0; | |
| 1600 | |
| 1601 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 1602 return val; | |
| 1603 remote_send_packet(fd, CMD_GET_EQ_BAND, &band, sizeof(band)); | |
| 1604 data = remote_read_packet(fd); | |
| 1605 if (data) { | |
| 1606 val = *((gfloat *) data); | |
| 1607 g_free(data); | |
| 1608 } | |
| 1609 remote_read_ack(fd); | |
| 1610 close(fd); | |
| 1611 return val; | |
| 1612 } | |
| 1613 | |
| 1614 /** | |
| 1615 * xmms_remote_set_eq: | |
| 1616 * @session: Legacy XMMS-style session identifier. | |
| 1617 * @preamp: Value for preamp setting. | |
| 1618 * @bands: Array of band settings. | |
| 1619 * | |
| 1620 * Tells audacious to set the equalizer up using the provided values. | |
| 1621 **/ | |
| 1622 void | |
| 1623 xmms_remote_set_eq(gint session, gfloat preamp, gfloat * bands) | |
| 1624 { | |
| 1625 gint fd, i; | |
| 1626 gfloat data[11]; | |
| 1627 | |
| 1628 g_return_if_fail(bands != NULL); | |
| 1629 | |
| 1630 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 1631 return; | |
| 1632 data[0] = preamp; | |
| 1633 for (i = 0; i < 10; i++) | |
| 1634 data[i + 1] = bands[i]; | |
| 1635 remote_send_packet(fd, CMD_SET_EQ, data, sizeof(data)); | |
| 1636 remote_read_ack(fd); | |
| 1637 close(fd); | |
| 1638 } | |
| 1639 | |
| 1640 /** | |
| 1641 * xmms_remote_set_eq_preamp: | |
| 1642 * @session: Legacy XMMS-style session identifier. | |
| 1643 * @preamp: Value for preamp setting. | |
| 1644 * | |
| 1645 * Tells audacious to set the equalizer's preamp setting. | |
| 1646 **/ | |
| 1647 void | |
| 1648 xmms_remote_set_eq_preamp(gint session, gfloat preamp) | |
| 1649 { | |
| 1650 remote_send_gfloat(session, CMD_SET_EQ_PREAMP, preamp); | |
| 1651 } | |
| 1652 | |
| 1653 /** | |
| 1654 * xmms_remote_set_eq_band: | |
| 1655 * @session: Legacy XMMS-style session identifier. | |
| 1656 * @band: The band to set the value for. | |
| 1657 * @value: The value to set that band to. | |
| 1658 * | |
| 1659 * Tells audacious to set an equalizer band's setting. | |
| 1660 **/ | |
| 1661 void | |
| 1662 xmms_remote_set_eq_band(gint session, gint band, gfloat value) | |
| 1663 { | |
| 1664 gint fd; | |
| 1665 gchar data[sizeof(gint) + sizeof(gfloat)]; | |
| 1666 | |
| 1667 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 1668 return; | |
| 1669 *((gint *) data) = band; | |
| 1670 *((gfloat *) (data + sizeof(gint))) = value; | |
| 1671 remote_send_packet(fd, CMD_SET_EQ_BAND, data, sizeof(data)); | |
| 1672 remote_read_ack(fd); | |
| 1673 close(fd); | |
| 1674 } | |
| 1675 | |
| 1676 /** | |
| 1677 * xmms_remote_quit: | |
| 1678 * @session: Legacy XMMS-style session identifier. | |
| 1679 * | |
| 1680 * Tells audacious to quit. | |
| 1681 **/ | |
| 1682 void | |
| 1683 xmms_remote_quit(gint session) | |
| 1684 { | |
| 1685 gint fd; | |
| 1686 | |
| 1687 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 1688 return; | |
| 1689 remote_send_packet(fd, CMD_QUIT, NULL, 0); | |
| 1690 remote_read_ack(fd); | |
| 1691 close(fd); | |
| 1692 } | |
| 1693 | |
| 1694 /** | |
| 1695 * xmms_remote_activate: | |
| 1696 * @session: Legacy XMMS-style session identifier. | |
| 1697 * | |
| 1698 * Tells audacious to display the main window and become the selected window. | |
| 1699 **/ | |
| 1700 void | |
| 1701 xmms_remote_activate(gint session) | |
| 1702 { | |
| 1703 gint fd; | |
| 1704 | |
| 1705 if ((fd = xmms_connect_to_session(session)) == -1) | |
| 1706 return; | |
| 1707 remote_send_packet(fd, CMD_ACTIVATE, NULL, 0); | |
| 1708 remote_read_ack(fd); | |
| 1709 close(fd); | |
| 1710 } |
