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