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