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