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