Debian Codegraph @

rplayd/command.c

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 /* $Id: command.c,v 1.6 1999/03/10 07:58:02 boyns Exp $ */
2
3 /*
4 * Copyright (C) 1993-99 Mark R. Boyns <[email protected]>
5 *
6 * This file is part of rplay.
7 *
8 * rplay is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * rplay is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with rplay; see the file COPYING. If not, write to the
20 * Free Software Foundation, Inc.,
21 * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22 */
23
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27 #include <sys/types.h>
28 #include <sys/stat.h>
29 #include <stdlib.h>
30 #ifdef HAVE_STRING_H
31 #include <string.h>
32 #endif
33 #include "rplayd.h"
34 #include "command.h"
35 #include "connection.h"
36 #include "server.h"
37 #include "host.h"
38 #include "spool.h"
39 #include "cache.h"
40 #include "sound.h"
41 #include "misc.h"
42 #include "strdup.h"
43 #include "getopt.h"
44 #ifdef HAVE_HELPERS
45 #include "helper.h"
46 #endif /* HAVE_HELPERS */
47
48 #undef is_true
49 #define is_true(string) \
50 (strcmp (string, "true") == 0 \
51 || strcmp (string, "t") == 0 \
52 || strcmp (string, "1") == 0 \
53 || strcmp (string, "yes") == 0 \
54 || strcmp (string, "y") == 0 \
55 || strcmp (string, "on") == 0) \
56
57 typedef struct
58 {
59 char *name;
60 int min_args;
61 int max_args;
62 char *usage;
63 #ifdef __STDC__
64 int (*func) (CONNECTION *c, int argc, char **argv);
65 #else
66 int (*func) ( /* CONNECTION *c, int argc, char **argv */ );
67 #endif
68 }
69 COMMAND;
70
71 #ifdef __STDC__
72 static int do_command(CONNECTION *c, int argc, char **argv);
73 static int command_quit(CONNECTION *c, int argc, char **argv);
74 static int command_unknown(CONNECTION *c, int argc, char **argv);
75 static int command_help(CONNECTION *c, int argc, char **argv);
76 static int command_get(CONNECTION *c, int argc, char **argv);
77 static int command_put(CONNECTION *c, int argc, char **argv);
78 static int command_list(CONNECTION *c, int argc, char **argv);
79 static int command_find(CONNECTION *c, int argc, char **argv);
80 static int command_execute(CONNECTION *c, int argc, char **argv);
81 static int command_access(CONNECTION *c, int argc, char **argv);
82 static int command_volume(CONNECTION *c, int argc, char **argv);
83 static int command_info(CONNECTION *c, int argc, char **argv);
84 static int command_version(CONNECTION *c, int argc, char **argv);
85 static int command_wait(CONNECTION *c, int argc, char **argv);
86 static int do_execute(CONNECTION *c, int argc, char **argv);
87 static int command_status(CONNECTION *c, int argc, char **argv);
88 static int command_application(CONNECTION *c, int argc, char **argv);
89 static int command_reset(CONNECTION *c, int argc, char **argv);
90 static int command_skip(CONNECTION *c, int argc, char **argv);
91 static int command_set(CONNECTION *c, int argc, char **argv);
92 static int command_modify(CONNECTION *c, int argc, char **argv);
93 static int command_monitor(CONNECTION *c, int argc, char **argv);
94 #else
95 static int do_command( /* CONNECTION *c, int argc, char **argv */ );
96 static int command_quit( /* CONNECTION *c, int argc, char **argv */ );
97 static int command_unknown( /* CONNECTION *c, int argc, char **argv */ );
98 static int command_help( /* CONNECTION *c, int argc, char **argv */ );
99 static int command_get( /* CONNECTION *c, int argc, char **argv */ );
100 static int command_put( /* CONNECTION *c, int argc, char **argv */ );
101 static int command_list( /* CONNECTION *c, int argc, char **argv */ );
102 static int command_find( /* CONNECTION *c, int argc, char **argv */ );
103 static int command_execute( /* CONNECTION *c, int argc, char **argv */ );
104 static int command_access( /* CONNECTION *c, int argc, char **argv */ );
105 static int command_volume( /* CONNECTION *c, int argc, char **argv */ );
106 static int command_info( /* CONNECTION *c, int argc, char **argv */ );
107 static int command_version( /* CONNECTION *c, int argc, char **argv */ );
108 static int command_wait( /* CONNECTION *c, int argc, char **argv */ );
109 static int do_execute( /* CONNECTION *c, int argc, char **argv */ );
110 static int command_status( /* CONNECTION *c, int argc, char **argv */ );
111 static int command_application( /* CONNECTION *c, int argc, char **argv */ );
112 static int command_reset( /* CONNECTION *c, int argc, char **argv */ );
113 static int command_skip( /* CONNECTION *c, int argc, char **argv */ );
114 static int command_set( /* CONNECTION *c, int argc, char **argv */ );
115 static int command_modify( /* CONNECTION *c, int argc, char **argv */ );
116 static int command_monitor( /* CONNECTION *c, int argc, char **argv */ );
117 #endif
118
119 #ifdef DEBUG
120 extern int command_die( /* CONNECTION *c, int argc, char **argv */ );
121 #endif
122
123 static COMMAND commands[] =
124 {
125 /*
126 * command min max usage function
127 */
128 {"access", -1, -1, "", command_access},
129 {"application", 1, -1, "name", command_application},
130 {"continue", 1, -1, "id|sound ...", command_execute},
131 #ifdef DEBUG
132 {"die", -1, -1, "", command_die},
133 #endif
134 {"done", 1, -1, "id|sound ...", command_execute},
135 {"find", 1, 1, "sound", command_find},
136 {"get", 1, 1, "sound", command_get},
137 {"help", -1, -1, "", command_help},
138 {"info", 1, 1, "sound", command_info},
139 #ifdef AUTH
140 {"list", 0, 1, "[connections|hosts|servers|spool|sounds]", command_list},
141 #else
142 {"list", 0, 1, "[connections|servers|sounds}", command_list},
143 #endif /* AUTH */
144 {"modify", 2, -1, "id [count|list-count|priority|sample-rate|volume] ...", command_modify},
145 {"monitor", -1, -1, "", command_monitor},
146 {"pause", 1, -1, "id|sound ...", command_execute},
147 {"play", 1, -1, "sound ...", command_execute},
148 {"put", 2, -1, "id|sound size", command_put},
149 {"quit", 0, 0, "", command_quit},
150 {"reset", 0, 0, "", command_reset},
151 {"set", 1, -1, "name[=value] ...", command_set},
152 {"skip", 1, -1, "id count", command_skip},
153 {"status", 0, 0, "", command_status},
154 {"stop", 1, -1, "id|sound ...", command_execute},
155 {"version", 0, 0, "", command_version},
156 {"volume", 0, 1, "[[+|-]volume]", command_volume},
157 {"wait", -1, -1, "id|event|RPTP command", command_wait},
158 };
159 #define NCOMMANDS (sizeof(commands)/sizeof(COMMAND))
160
161 /* Copy of the current RPTP command. */
162 static char command_buffer[RPTP_MAX_LINE];
163
164 static char *default_client_data = "";
165
166 #ifdef __STDC__
167 int
168 command(CONNECTION *c, char *buf)
169 #else
170 int
171 command(c, buf)
172 CONNECTION *c;
173 char *buf;
174 #endif
175 {
176 char *argv[RPTP_MAX_ARGS], *p;
177 int argc = 0, first = 1;
178
179 report(REPORT_INFO, "%s command=\"%s\"\n", inet_ntoa(c->sin.sin_addr), buf);
180 strncpy(command_buffer, buf, sizeof(command_buffer));
181
182 while ((p = strtok(first ? buf : NULL, " \t")))
183 {
184 argv[argc++] = p;
185 first = 0;
186 if (argc == RPTP_MAX_ARGS - 1)
187 {
188 break;
189 }
190 }
191 argv[argc] = NULL;
192
193 if (argc == 0)
194 {
195 return 0;
196 }
197 else
198 {
199 return do_command(c, argc, argv);
200 }
201 }
202
203 #ifdef __STDC__
204 static int
205 do_command(CONNECTION *c, int argc, char **argv)
206 #else
207 static int
208 do_command(c, argc, argv)
209 CONNECTION *c;
210 int argc;
211 char **argv;
212 #endif
213 {
214 int i;
215
216 for (i = 0; i < NCOMMANDS; i++)
217 {
218 if (strcmp(commands[i].name, argv[0]) == 0)
219 {
220 if ((commands[i].min_args >= 0 && argc - 1 < commands[i].min_args)
221 || (commands[i].max_args >= 0 && argc - 1 > commands[i].max_args))
222 {
223 connection_reply(c, "%cerror=\"usage: %s %s\"",
224 RPTP_ERROR, commands[i].name, commands[i].usage);
225 return 0;
226 }
227 else
228 {
229 return (*commands[i].func) (c, argc, argv);
230 }
231 }
232 }
233
234 return command_unknown(c, argc, argv);
235 }
236
237 #ifdef __STDC__
238 static int
239 command_quit(CONNECTION *c, int argc, char **argv)
240 #else
241 static int
242 command_quit(c, argc, argv)
243 CONNECTION *c;
244 int argc;
245 char **argv;
246 #endif
247 {
248 /* connection_close (c); */
249 return -1;
250 }
251
252 #ifdef __STDC__
253 static int
254 command_unknown(CONNECTION *c, int argc, char **argv)
255 #else
256 static int
257 command_unknown(c, argc, argv)
258 CONNECTION *c;
259 int argc;
260 char **argv;
261 #endif
262 {
263 char *client_data;
264
265 client_data = rptp_parse(command_buffer, "client-data");
266 if (!client_data)
267 {
268 client_data = default_client_data;
269 }
270
271 connection_reply(c, "%cerror=\"unknown command `%s'\" command=\"%s\" client-data=\"%s\"",
272 RPTP_ERROR, argv[0], argv[0], client_data);
273
274 return 0;
275 }
276
277 #ifdef __STDC__
278 static int
279 command_help(CONNECTION *c, int argc, char **argv)
280 #else
281 static int
282 command_help(c, argc, argv)
283 CONNECTION *c;
284 int argc;
285 char **argv;
286 #endif
287 {
288 int i;
289 char fmt[1024];
290 EVENT *e;
291 static BUFFER *b;
292
293 if (b == NULL)
294 {
295 b = buffer_create();
296 b->status = BUFFER_KEEP;
297 SNPRINTF(SIZE(b->buf, BUFFER_SIZE), "%cmessage=\"command summary\" command=help\r\n", RPTP_OK);
298 b->nbytes += strlen(b->buf);
299 for (i = 0; i < NCOMMANDS; i++)
300 {
301 SNPRINTF(SIZE(fmt, sizeof(fmt)), "%-8s %s\r\n", commands[i].name, commands[i].usage);
302 SNPRINTF(SIZE(b->buf + b->nbytes, BUFFER_SIZE - b->nbytes), fmt);
303 b->nbytes += strlen(fmt);
304 }
305 SNPRINTF(SIZE(b->buf + b->nbytes, BUFFER_SIZE - b->nbytes), ".\r\n");
306 b->nbytes += 3;
307 }
308
309 e = event_create(EVENT_WRITE, b);
310 event_insert(c, e);
311
312 return 0;
313 }
314
315 #ifdef __STDC__
316 static int
317 command_get(CONNECTION *c, int argc, char **argv)
318 #else
319 static int
320 command_get(c, argc, argv)
321 CONNECTION *c;
322 int argc;
323 char **argv;
324 #endif
325 {
326 SOUND *s;
327 EVENT *e;
328 char *sound_name = NULL;
329 int old_style = 0;
330 char *client_data = default_client_data;
331
332 if (strchr(command_buffer, '='))
333 {
334 sound_name = rptp_parse(command_buffer, "sound");
335 client_data = rptp_parse(0, "client-data");
336 if (!client_data)
337 {
338 client_data = default_client_data;
339 }
340 }
341 if (!sound_name)
342 {
343 sound_name = argv[1];
344 old_style++;
345 }
346
347 #ifdef AUTH
348 if (!host_access(c->sin, HOST_READ))
349 {
350 report(REPORT_NOTICE, "%s get %s - read access denied\n",
351 inet_ntoa(c->sin.sin_addr),
352 argv[1]);
353 connection_reply(c, "%cerror=\"access denied\" command=get client-data=\"%s\"",
354 RPTP_ERROR, client_data);
355 return 0;
356 }
357 #endif /* AUTH */
358
359 s = sound_lookup(sound_name, SOUND_DONT_FIND, NULL);
360 if (s == NULL || s->status != SOUND_READY)
361 {
362 report(REPORT_NOTICE, "%s get %s - not found\n",
363 inet_ntoa(c->sin.sin_addr), sound_name);
364 connection_reply(c, "%cerror=\"%s not found\" command=get client-data=\"%s\"",
365 RPTP_ERROR, sound_name, client_data);
366 }
367 else if (s->type != SOUND_FILE)
368 {
369 connection_reply(c, "%cerror=\"%s not a file\" command=get client-data=\"%s\"",
370 RPTP_ERROR, s->name, client_data);
371 }
372 else
373 {
374 e = event_create(EVENT_WRITE_SOUND, s);
375 if (e == NULL)
376 {
377 report(REPORT_NOTICE, "%s get %s - cannot open\n",
378 inet_ntoa(c->sin.sin_addr), s->name);
379 connection_reply(c, "%cerror=\"cannot open %s\" command=get client-data=\"%s\"",
380 RPTP_ERROR, s->name, client_data);
381 }
382 else
383 {
384 report(REPORT_NOTICE, "%s get %s %d\n",
385 inet_ntoa(c->sin.sin_addr), s->name, s->size);
386 if (old_style)
387 {
388 connection_reply(c, "%c%s %d", RPTP_OK, s->name, s->size);
389 }
390 else
391 {
392 connection_reply(c, "%csound=\"%s\" size=%d command=get client-data=\"%s\"",
393 RPTP_OK, s->name, s->size, client_data);
394 }
395 event_insert(c, e);
396 }
397 }
398
399 return 0;
400 }
401
402 #ifdef __STDC__
403 static int
404 command_put(CONNECTION *c, int argc, char **argv)
405 #else
406 static int
407 command_put(c, argc, argv)
408 CONNECTION *c;
409 int argc;
410 char **argv;
411 #endif
412 {
413 EVENT *e;
414 int sound_size;
415 char *name, *sound_name = NULL, *p;
416 SOUND *s;
417 int fd;
418 int old_style = 0;
419 int spool_id = 0;
420 char *client_data = default_client_data;
421
422 if (strchr(command_buffer, '='))
423 {
424 client_data = rptp_parse(command_buffer, "client-data");
425 if (!client_data)
426 {
427 client_data = default_client_data;
428 }
429 }
430 else
431 {
432 old_style++;
433 }
434
435 #ifdef AUTH
436 if (!host_access(c->sin, HOST_WRITE))
437 {
438 report(REPORT_NOTICE, "%s put %s - write access denied\n",
439 inet_ntoa(c->sin.sin_addr),
440 argv[1]);
441 connection_reply(c, "%cerror=\"access denied\" command=put client-data=\"%s\"",
442 RPTP_ERROR, client_data);
443 return 0;
444 }
445 #endif /* AUTH */
446
447 if (!old_style)
448 {
449 char *p;
450
451 sound_name = rptp_parse(0, "sound");
452
453 p = rptp_parse(0, "size");
454 if (!p)
455 {
456 connection_reply(c, "%cerror=\"missing `size=<value>'\" command=put client-data=\"%s\"",
457 RPTP_ERROR, client_data);
458 return 0;
459 }
460 sound_size = atoi(p);
461
462 p = rptp_parse(0, "id");
463 if (p && *p && p[0] == '#')
464 {
465 spool_id = atoi(p + 1);
466 }
467 }
468 else
469 /* old-style */
470 {
471 sound_name = argv[1];
472 sound_size = atoi(argv[2]);
473 old_style++;
474 }
475
476 if (spool_id)
477 {
478 SPOOL *sp;
479 #ifdef HAVE_HELPERS
480 HELPER *hp;
481 #endif
482
483 sp = spool_find(spool_id);
484 if (!sp)
485 {
486 connection_reply(c, "%cerror=\"`%d' no such spool id\" command=put client-data=\"%s\"",
487 RPTP_ERROR, spool_id, client_data);
488 return 0;
489 }
490 else if (sp->sound[sp->curr_sound]->type != SOUND_FLOW)
491 {
492 connection_reply(c, "%cerror=\"`%d' spool id is not a flow\" command=put client-data=\"%s\"",
493 RPTP_ERROR, spool_id, client_data);
494 return 0;
495 }
496
497 connection_reply(c, "%cid=#%d size=%d command=put client-data=\"%s\"",
498 RPTP_OK, spool_id, sound_size, client_data);
499
500 #ifdef HAVE_HELPERS
501 /* XXX - it isn't known yet whether or not this sound
502 will need a helper. Check here too. */
503 hp = helper_lookup(sp->sound[sp->curr_sound]->path);
504 if (hp)
505 {
506 SOUND *s = sp->sound[sp->curr_sound];
507 e = event_create(EVENT_PIPE_FLOW, spool_id, s);
508 event_insert(c, e);
509
510 s->status = SOUND_READY;
511 sound_map(s);
512 spool_ready(s);
513 }
514 else
515 #endif /* HAVE_HELPERS */
516 {
517 e = event_create(EVENT_READ_FLOW, spool_id, sound_size);
518 event_insert(c, e);
519 }
520
521 return 0;
522 }
523 else
524 {
525 /* strip pathnames -- files can only be put in the cache directory */
526 p = strrchr(sound_name, '/');
527 if (p)
528 {
529 sound_name = p + 1;
530 }
531 name = cache_name(sound_name);
532
533 s = sound_lookup(name, SOUND_DONT_FIND, NULL);
534 if (s != NULL)
535 {
536 connection_reply(c, "%cerror=\"%s already is in the cache\" command=put client-data=\"%s\"",
537 RPTP_ERROR, sound_name, client_data);
538 return 0;
539 }
540
541 if (cache_free(sound_size) < 0)
542 {
543 connection_reply(c, "%cerror=\"the cache is full\" command=put client-data=\"%s\"",
544 RPTP_ERROR, client_data);
545 }
546 else
547 {
548 fd = cache_create(name, sound_size);
549 if (fd < 0)
550 {
551 connection_reply(c, "%cerror=\"cache error\" command=put client-data=\"%s\"",
552 RPTP_ERROR, client_data);
553 }
554 else
555 {
556 report(REPORT_NOTICE, "%s put %s %d\n",
557 inet_ntoa(c->sin.sin_addr), sound_name, sound_size);
558 s = sound_insert(name, SOUND_NOT_READY, SOUND_FILE);
559 if (old_style)
560 {
561 connection_reply(c, "%c%s %d", RPTP_OK, sound_name, sound_size);
562 }
563 else
564 {
565 connection_reply(c, "%csound=\"%s\" size=%d command=put client-data=\"%s\"",
566 RPTP_OK, sound_name, sound_size, client_data);
567 }
568 e = event_create(EVENT_READ_SOUND, fd, buffer_create(), sound_size, s);
569 event_insert(c, e);
570 }
571 }
572
573 return 0;
574 }
575 }
576
577 #ifdef __STDC__
578 static int
579 command_list(CONNECTION *c, int argc, char **argv)
580 #else
581 static int
582 command_list(c, argc, argv)
583 CONNECTION *c;
584 int argc;
585 char **argv;
586 #endif
587 {
588 EVENT *e;
589 char *client_data = default_client_data;
590 BUFFER *b;
591
592 if (strchr(command_buffer, '='))
593 {
594 client_data = rptp_parse(command_buffer, "client-data");
595 if (!client_data)
596 {
597 client_data = default_client_data;
598 }
599 }
600
601 if (argv[1] == NULL || strcmp(argv[1], "sounds") == 0)
602 {
603 b = sound_list_create();
604 if (b)
605 {
606 e = event_create(EVENT_WRITE, b);
607 event_insert(c, e);
608 }
609 else
610 {
611 connection_reply(c, "%cerror=\"no sounds available\" command=list client-data=\"%s\"",
612 RPTP_ERROR, client_data);
613 }
614 }
615 else if (strcmp(argv[1], "connections") == 0)
616 {
617 b = connection_list_create();
618 if (b)
619 {
620 e = event_create(EVENT_WRITE, b);
621 event_insert(c, e);
622 }
623 else
624 {
625 connection_reply(c, "%cerror=\"no connections available\" command=list client-data=\"%s\"",
626 RPTP_ERROR, client_data);
627 }
628 }
629 else if (strcmp(argv[1], "servers") == 0)
630 {
631 if (server_list)
632 {
633 e = event_create(EVENT_WRITE, server_list);
634 event_insert(c, e);
635 }
636 else
637 {
638 connection_reply(c, "%cerror=\"no servers available\" command=list client-data=\"%s\"",
639 RPTP_ERROR, client_data);
640 }
641 }
642 else if (strcmp(argv[1], "spool") == 0)
643 {
644 b = spool_list_create();
645 if (b)
646 {
647 e = event_create(EVENT_WRITE, b);
648 event_insert(c, e);
649 }
650 else
651 {
652 connection_reply(c, "%cerror=\"no spool available\" command=list client-data=\"%s\"",
653 RPTP_ERROR, client_data);
654 }
655 }
656 #ifdef AUTH
657 else if (strcmp(argv[1], "hosts") == 0)
658 {
659 b = host_list;
660 if (b)
661 {
662 e = event_create(EVENT_WRITE, b);
663 event_insert(c, e);
664 }
665 else
666 {
667 connection_reply(c, "%cerror=\"no hosts available\" command=list client-data=\"%s\"",
668 RPTP_ERROR, client_data);
669 }
670 }
671 #endif /* AUTH */
672 else
673 {
674 connection_reply(c, "%cerror=\"cannot list `%s'\" command=list client-data=\"%s\"",
675 RPTP_ERROR, argv[1], client_data);
676 }
677
678 return 0;
679 }
680
681 #ifdef __STDC__
682 static int
683 command_find(CONNECTION *c, int argc, char **argv)
684 #else
685 static int
686 command_find(c, argc, argv)
687 CONNECTION *c;
688 int argc;
689 char **argv;
690 #endif
691 {
692 SOUND *s;
693 char *sound_name = NULL;
694 int old_style = 0;
695 char *client_data = default_client_data;
696
697 if (strchr(command_buffer, '='))
698 {
699 sound_name = rptp_parse(command_buffer, "sound");
700 client_data = rptp_parse(0, "client-data");
701 if (!client_data)
702 {
703 client_data = default_client_data;
704 }
705 }
706 if (!sound_name)
707 {
708 sound_name = argv[1];
709 old_style++;
710 }
711
712 s = sound_lookup(sound_name, SOUND_DONT_FIND, NULL);
713 if (s == NULL || s->status != SOUND_READY)
714 {
715 report(REPORT_NOTICE, "%s find %s - not found\n",
716 inet_ntoa(c->sin.sin_addr), sound_name);
717 connection_reply(c, "%cerror=\"%s not found\" command=find client-data=\"%s\"",
718 RPTP_ERROR, sound_name, client_data);
719 }
720 else
721 {
722 report(REPORT_NOTICE, "%s find %s %d\n",
723 inet_ntoa(c->sin.sin_addr), sound_name, s->size);
724 if (old_style)
725 {
726 connection_reply(c, "%c%s %d", RPTP_OK, s->name, s->size);
727 }
728 else
729 {
730 connection_reply(c, "%csound=\"%s\" size=%d command=find client-data=\"%s\"",
731 RPTP_OK, s->name, s->size, client_data);
732 }
733 }
734
735 return 0;
736 }
737
738 #ifdef __STDC__
739 static int
740 command_access(CONNECTION *c, int argc, char **argv)
741 #else
742 static int
743 command_access(c, argc, argv)
744 CONNECTION *c;
745 int argc;
746 char **argv;
747 #endif
748 {
749 char buf[4];
750 char *client_data = default_client_data;
751
752 if (strchr(command_buffer, '='))
753 {
754 client_data = rptp_parse(command_buffer, "client-data");
755 if (!client_data)
756 {
757 client_data = default_client_data;
758 }
759 }
760
761 buf[0] = '\0';
762 #ifdef AUTH
763 if (host_access(c->sin, HOST_READ))
764 {
765 strcat(buf, "r");
766 }
767 if (host_access(c->sin, HOST_WRITE))
768 {
769 strcat(buf, "w");
770 }
771 if (host_access(c->sin, HOST_EXECUTE))
772 {
773 strcat(buf, "x");
774 }
775 #else /* AUTH */
776 strcat(buf, "rwx");
777 #endif /* AUTH */
778
779 connection_reply(c, "%caccess=%s command=access client-data=\"%s\"",
780 RPTP_OK, buf, client_data);
781
782 return 0;
783 }
784
785 #ifdef __STDC__
786 static int
787 command_execute(CONNECTION *c, int argc, char **argv)
788 #else
789 static int
790 command_execute(c, argc, argv)
791 CONNECTION *c;
792 int argc;
793 char **argv;
794 #endif
795 {
796 SPOOL *sp;
797 int id = do_execute(c, argc, argv);
798
799 if (id > 0)
800 {
801 sp = spool_find(id);
802 connection_reply(c, "%cid=#%d sound=\"%s\" command=%s client-data=\"%s\" list-name=\"%s\"",
803 RPTP_OK, id,
804 sp->curr_attrs->sound,
805 argv[0],
806 sp->curr_attrs->client_data,
807 sp->rp->list_name);
808 }
809
810 return 0;
811 }
812
813 /*
814 * Return -1 for errors, 0 for stop, pause, continue, and return
815 * a spool id for play.
816 */
817 #ifdef __STDC__
818 static int
819 do_execute(CONNECTION *c, int argc, char **argv)
820 #else
821 static int
822 do_execute(c, argc, argv)
823 CONNECTION *c;
824 int argc;
825 char **argv;
826 #endif
827 {
828 int old_style = 0;
829 int i, n, command = RPLAY_PLAY, val = 0;
830 RPLAY *rp;
831 int volume, list_count, count, priority, sample_rate;
832 int do_random = 0;
833 int do_search = 1; /* search by default */
834 int input = SOUND_FILE;
835 int input_offset = 0;
836 int input_format = 0;
837 int input_byte_order = 0;
838 int input_sample_rate = 0;
839 float input_precision = 0;
840 int input_channels = 0;
841 int input_storage = SOUND_STORAGE_NONE; /* Don't store flows by default. */
842 char *client_data = default_client_data;
843 char *list_name = NULL;
844
845 if (strcmp(argv[0], "play") == 0)
846 {
847 command = RPLAY_PLAY;
848 }
849 else if (strcmp(argv[0], "stop") == 0)
850 {
851 command = RPLAY_STOP;
852 }
853 else if (strcmp(argv[0], "pause") == 0)
854 {
855 command = RPLAY_PAUSE;
856 }
857 else if (strcmp(argv[0], "continue") == 0)
858 {
859 command = RPLAY_CONTINUE;
860 }
861 else if (strcmp(argv[0], "done") == 0)
862 {
863 command = RPLAY_DONE;
864 }
865
866 if (strchr(command_buffer, '='))
867 {
868 client_data = rptp_parse(command_buffer, "client-data");
869 if (!client_data)
870 {
871 client_data = default_client_data;
872 }
873 }
874 else
875 {
876 old_style++;
877 }
878
879 #ifdef AUTH
880 if (!host_access(c->sin, HOST_EXECUTE))
881 {
882 report(REPORT_NOTICE, "%s %s access denied\n", argv[0],
883 inet_ntoa(c->sin.sin_addr));
884 connection_reply(c, "%cerror=\"access denied\" command=%s client-data=\"%s\"",
885 RPTP_ERROR, argv[0], client_data);
886 return -1;
887 }
888 #endif /* AUTH */
889
890 rp = rplay_create(command);
891 if (rp == NULL)
892 {
893 connection_reply(c, "%cerror=\"%s failed\" command=%s client_data=\"%s\"",
894 RPTP_ERROR, argv[0], argv[0], client_data);
895 return -1;
896 }
897
898 volume = RPLAY_DEFAULT_VOLUME;
899 count = RPLAY_DEFAULT_COUNT;
900 list_count = RPLAY_DEFAULT_LIST_COUNT;
901 priority = RPLAY_DEFAULT_PRIORITY;
902 sample_rate = RPLAY_DEFAULT_SAMPLE_RATE;
903
904 if (!old_style)
905 {
906 char *name, *value;
907
908 rptp_parse(command_buffer, 0);
909 while (name = rptp_parse(0, 0))
910 {
911 value = rptp_parse(0, name);
912
913 if (!value || !*value)
914 {
915 continue;
916 }
917 else if (strcmp(name, "sound") == 0
918 || (command != RPLAY_PLAY && strcmp(name, "id") == 0))
919 {
920 val = rplay_set(rp, RPLAY_APPEND,
921 RPLAY_SOUND, value,
922 RPLAY_VOLUME, volume,
923 RPLAY_COUNT, count,
924 RPLAY_SAMPLE_RATE, sample_rate,
925 RPLAY_RPTP_SEARCH, do_search,
926 RPLAY_CLIENT_DATA, client_data,
927 NULL);
928 if (val < 0)
929 {
930 connection_reply(c, "%cerror=\"%s failed\" command=%s client-data=\"%s\"",
931 RPTP_ERROR, argv[0], argv[0], client_data);
932 return -1;
933 }
934 }
935 else if (strcmp(name, "client-data") == 0)
936 {
937 client_data = value;
938 }
939 else if (strcmp(name, "volume") == 0)
940 {
941 volume = atoi(value);
942 }
943 else if (strcmp(name, "count") == 0)
944 {
945 count = atoi(value);
946 }
947 else if (strcmp(name, "list-count") == 0)
948 {
949 list_count = atoi(value);
950 }
951 else if (strcmp(name, "priority") == 0)
952 {
953 priority = atoi(value);
954 }
955 else if (strcmp(name, "sample-rate") == 0)
956 {
957 sample_rate = atoi(value);
958 }
959 else if (strcmp(name, "search") == 0
960 || strcmp(name, "rptp-search") == 0)
961 {
962 do_search = is_true(value);
963 }
964 else if (strcmp(name, "random") == 0)
965 {
966 do_random = is_true(value);
967 }
968 else if (strcmp(name, "list-name") == 0)
969 {
970 list_name = value;
971 }
972 else if (strcmp(name, "input") == 0)
973 {
974 input = string_to_input(value);
975 }
976 else if (strcmp(name, "input-offset") == 0)
977 {
978 input_offset = atoi(value);
979 }
980 else if (strcmp(name, "input-format") == 0)
981 {
982 input_format = string_to_audio_format(value);
983 }
984 else if (strcmp(name, "input-byte-order") == 0)
985 {
986 input_byte_order = string_to_byte_order(value);
987 }
988 else if (strcmp(name, "input-sample-rate") == 0)
989 {
990 input_sample_rate = atoi(value);
991 }
992 else if (strcmp(name, "input-bits") == 0)
993 {
994 input_precision = atof(value);
995 }
996 else if (strcmp(name, "input-channels") == 0)
997 {
998 input_channels = atoi(value);
999 }
1000 else if (strcmp(name, "input-storage") == 0)
1001 {
1002 input_storage = string_to_storage(value);
1003 }
1004 else if (strcmp(name, "input-info") == 0)
1005 {
1006 char *p = strtok(value, ",");
1007 if (p) input_format = string_to_audio_format(p);
1008
1009 p = strtok(NULL, ",");
1010 if (p) input_sample_rate = atoi(p);
1011
1012 p = strtok(NULL, ",");
1013 if (p) input_precision = atoi(p);
1014
1015 p = strtok(NULL, ",");
1016 if (p) input_channels = atoi(p);
1017
1018 p = strtok(NULL, ",");
1019 if (p) input_byte_order = string_to_byte_order(p);
1020
1021 p = strtok(NULL, ",");
1022 if (p) input_offset = atoi(p);
1023 }
1024 }
1025 }
1026 else
1027 /* old-style */
1028 {
1029 extern char *optarg;
1030 extern int optind;
1031
1032 optind = 0;
1033 while ((n = getopt(argc, argv, "+P:R:N:n:v:")) != -1)
1034 {
1035 switch (n)
1036 {
1037 case 'v':
1038 volume = atoi(optarg);
1039 break;
1040
1041 case 'n':
1042 count = atoi(optarg);
1043 break;
1044
1045 case 'N':
1046 list_count = atoi(optarg);
1047 break;
1048
1049 case 'P':
1050 priority = atoi(optarg);
1051 break;
1052
1053 case 'R':
1054 sample_rate = atoi(optarg);
1055 break;
1056
1057 default:
1058 argc = optind;
1059 break;
1060 }
1061 }
1062
1063 if (argc == optind)
1064 {
1065 for (i = 0; i < NCOMMANDS; i++)
1066 {
1067 if (strcmp(commands[i].name, argv[0]) == 0)
1068 {
1069 connection_reply(c, "%cerror=\"usage: %s %s\" command=%s",
1070 RPTP_ERROR, commands[i].name, commands[i].usage,
1071 argv[0]);
1072 return -1;
1073 }
1074 }
1075 }
1076
1077 while (argv[optind] != NULL)
1078 {
1079 val = rplay_set(rp, RPLAY_APPEND,
1080 RPLAY_SOUND, argv[optind++],
1081 RPLAY_VOLUME, volume,
1082 RPLAY_COUNT, count,
1083 RPLAY_SAMPLE_RATE, sample_rate,
1084 RPLAY_RPTP_SEARCH, do_search,
1085 NULL);
1086 if (val < 0)
1087 {
1088 connection_reply(c, "%cerror=\"%s failed\" command=%s",
1089 RPTP_ERROR, argv[0], argv[0]);
1090 return -1;
1091 }
1092 }
1093 }
1094
1095 if (rplay_set(rp, RPLAY_LIST_COUNT, list_count, NULL) < 0)
1096 {
1097 connection_reply(c, "%cerror=\"%s failed\" command=%s client-data=\"%s\"",
1098 RPTP_ERROR, argv[0], argv[0], client_data);
1099 return -1;
1100 }
1101
1102 if (rplay_set(rp, RPLAY_PRIORITY, priority, NULL) < 0)
1103 {
1104 connection_reply(c, "%cerror=\"%s failed\" command=%s client-data=\"%s\"",
1105 RPTP_ERROR, argv[0], argv[0], client_data);
1106 return -1;
1107 }
1108
1109 if (do_random && rplay_set(rp, RPLAY_RANDOM_SOUND, NULL) < 0)
1110 {
1111 connection_reply(c, "%cerror=\"%s failed\" command=%s client-data=\"%s\"",
1112 RPTP_ERROR, argv[0], argv[0], client_data);
1113 return -1;
1114 }
1115
1116 if (list_name && rplay_set(rp, RPLAY_LIST_NAME, list_name, NULL) < 0)
1117 {
1118 connection_reply(c, "%cerror=\"%s failed\" command=%s client-data=\"%s\"",
1119 RPTP_ERROR, argv[0], argv[0], client_data);
1120 return -1;
1121 }
1122
1123 /* Flows */
1124 if (input == SOUND_FLOW && command == RPLAY_PLAY)
1125 {
1126 int spool_id, i;
1127 SOUND *s;
1128 char buf[RPTP_MAX_LINE], *sound_name, *p;
1129
1130 #ifdef AUTH
1131 /* Flows require `write' access along with the previously
1132 checked `execute' access. */
1133 if (!host_access(c->sin, HOST_WRITE))
1134 {
1135 report(REPORT_NOTICE, "%s %s access denied\n", argv[0],
1136 inet_ntoa(c->sin.sin_addr));
1137 connection_reply(c, "%cerror=\"access denied\" command=%s client-data=\"%s\"",
1138 RPTP_ERROR, argv[0], client_data);
1139 return -1;
1140 }
1141 #endif /* AUTH */
1142
1143 /* Generate a unique sound name. */
1144 sound_name = (char *) rplay_get(rp, RPLAY_SOUND, 0);
1145 if (!sound_name)
1146 {
1147 connection_reply(c, "%cerror=\"missing required `sound' attribute\" command=%s client-data=\"%s\"",
1148 RPTP_ERROR, argv[0], client_data);
1149 return -1;
1150 }
1151 p = strrchr(sound_name, '/');
1152 if (p)
1153 {
1154 sound_name = p + 1;
1155 }
1156 i = 0;
1157 do
1158 {
1159 if (i)
1160 {
1161 SNPRINTF(SIZE(buf, sizeof(buf)), "rplay%d-%s", i, sound_name);
1162 }
1163 else
1164 {
1165 SNPRINTF(SIZE(buf, sizeof(buf)), sound_name);
1166 }
1167 i++;
1168 }
1169 while (sound_lookup(buf, SOUND_DONT_FIND, NULL));
1170
1171 sound_name = cache_name(buf);
1172 rplay_set(rp, RPLAY_CHANGE, 0,
1173 RPLAY_SOUND, sound_name,
1174 RPLAY_RPTP_SEARCH, FALSE, /* never search */
1175 NULL);
1176 s = sound_insert(sound_name, SOUND_NOT_READY, SOUND_FLOW);
1177 if (!s)
1178 {
1179 connection_reply(c, "%cerror=\"%s failed\" command=%s client-data=\"%s\"",
1180 RPTP_ERROR, argv[0], argv[0], client_data);
1181 return -1;
1182 }
1183
1184 s->offset = input_offset;
1185 s->format = input_format;
1186 s->byte_order = input_byte_order;
1187 s->sample_rate = input_sample_rate;
1188 s->input_precision = input_precision;
1189 s->output_precision = input_precision;
1190 s->channels = input_channels;
1191 s->storage = input_storage;
1192
1193 /* Grab a spool entry. */
1194 spool_id = rplayd_play(rp, c->sin);
1195 if (spool_id < 0)
1196 {
1197 connection_reply(c, "%cerror=\"spool full\" command=%s client-data=\"%s\"",
1198 RPTP_ERROR, argv[0], client_data);
1199 sound_delete(s, 0);
1200 return -1;
1201 }
1202
1203 connection_reply(c, "%cid=#%d sound=\"%s\" command=%s client-data=\"%s\"",
1204 RPTP_OK, spool_id, buf, argv[0], client_data);
1205
1206 return 0;
1207 }
1208 else
1209 {
1210 switch (command)
1211 {
1212 case RPLAY_PLAY:
1213 val = rplayd_play(rp, c->sin);
1214 break;
1215
1216 case RPLAY_STOP:
1217 val = rplayd_stop(rp, c->sin);
1218 break;
1219
1220 case RPLAY_PAUSE:
1221 val = rplayd_pause(rp, c->sin);
1222 break;
1223
1224 case RPLAY_CONTINUE:
1225 val = rplayd_continue(rp, c->sin);
1226 break;
1227
1228 case RPLAY_DONE:
1229 val = rplayd_done(rp, c->sin);
1230 break;
1231 }
1232
1233 if (val == 0)
1234 {
1235 connection_reply(c, "%cmessage=\"%s successful\" command=%s client-data=\"%s\"",
1236 RPTP_OK, argv[0], argv[0], client_data);
1237 }
1238 else if (val < 0)
1239 {
1240 connection_reply(c, "%cerror=\"%s failed\" command=%s client-data=\"%s\"",
1241 RPTP_ERROR, argv[0], argv[0], client_data);
1242 }
1243
1244 return val;
1245 }
1246 }
1247
1248 /* OBSOLETE */
1249 #ifdef __STDC__
1250 static int
1251 command_volume(CONNECTION *c, int argc, char **argv)
1252 #else
1253 static int
1254 command_volume(c, argc, argv)
1255 CONNECTION *c;
1256 int argc;
1257 char **argv;
1258 #endif
1259 {
1260 int volume;
1261 int n;
1262
1263 #ifdef AUTH
1264 if (!host_access(c->sin, HOST_EXECUTE))
1265 {
1266 report(REPORT_NOTICE, "%s volume access denied\n",
1267 inet_ntoa(c->sin.sin_addr));
1268 connection_reply(c, "%cerror=\"access denied\" command=volume", RPTP_ERROR);
1269 return 0;
1270 }
1271 #endif /* AUTH */
1272
1273 if (argv[1] == NULL)
1274 {
1275 volume = rplay_audio_get_volume();
1276 if (volume >= 0)
1277 {
1278 connection_reply(c, "%c%d", RPTP_OK, volume);
1279 }
1280 else
1281 {
1282 connection_reply(c, "%cerror=\"volume failed\" command=volume", RPTP_ERROR);
1283 }
1284 }
1285 else if (*argv[1] == '+')
1286 {
1287 volume = rplay_audio_get_volume();
1288 if (volume < 0)
1289 {
1290 connection_reply(c, "%cerror=\"volume failed\" command=volume", RPTP_ERROR);
1291 }
1292
1293 volume += atoi(argv[1] + 1);
1294 n = rplay_audio_set_volume(volume);
1295 if (n >= 0)
1296 {
1297 connection_reply(c, "%c%d", RPTP_OK, n);
1298 connection_notify(0, NOTIFY_VOLUME, n);
1299 }
1300 else
1301 {
1302 connection_reply(c, "%cerror=\"volume failed\" command=volume", RPTP_ERROR);
1303 }
1304 }
1305 else if (*argv[1] == '-')
1306 {
1307 volume = rplay_audio_get_volume();
1308 if (volume < 0)
1309 {
1310 connection_reply(c, "%cerror=\"volume failed\" command=volume", RPTP_ERROR);
1311 }
1312
1313 volume -= atoi(argv[1] + 1);
1314 n = rplay_audio_set_volume(volume);
1315 if (n >= 0)
1316 {
1317 connection_reply(c, "%c%d", RPTP_OK, n);
1318 connection_notify(0, NOTIFY_VOLUME, n);
1319 }
1320 else
1321 {
1322 connection_reply(c, "%cerror=\"volume failed\" command=volume", RPTP_ERROR);
1323 }
1324 }
1325 else
1326 {
1327 volume = atoi(argv[1]);
1328 n = rplay_audio_set_volume(volume);
1329 if (n >= 0)
1330 {
1331 connection_reply(c, "%c%d", RPTP_OK, n);
1332 connection_notify(0, NOTIFY_VOLUME, n);
1333 }
1334 else
1335 {
1336 connection_reply(c, "%cerror=\"volume failed\" command=volume", RPTP_ERROR);
1337 }
1338 }
1339
1340 return 0;
1341 }
1342
1343 #ifdef __STDC__
1344 static int
1345 command_info(CONNECTION *c, int argc, char **argv)
1346 #else
1347 static int
1348 command_info(c, argc, argv)
1349 CONNECTION *c;
1350 int argc;
1351 char **argv;
1352 #endif
1353 {
1354 SOUND *s;
1355 char *sound_name = NULL;
1356 char *client_data = default_client_data;
1357
1358 #ifdef AUTH
1359 if (!host_access(c->sin, HOST_READ))
1360 {
1361 report(REPORT_NOTICE, "%s info %s - read access denied\n",
1362 inet_ntoa(c->sin.sin_addr), argv[1]);
1363 connection_reply(c, "%cerror=\"access denied\" command=info client-data=\"%s\"",
1364 RPTP_ERROR, client_data);
1365 return 0;
1366 }
1367 #endif /* AUTH */
1368
1369 if (strchr(command_buffer, '='))
1370 {
1371 sound_name = rptp_parse(command_buffer, "sound");
1372 client_data = rptp_parse(0, "client-data");
1373 if (!client_data)
1374 {
1375 client_data = default_client_data;
1376 }
1377 }
1378 if (!sound_name)
1379 {
1380 sound_name = argv[1];
1381 }
1382
1383 /* s = sound_lookup (sound_name, SOUND_CREATE, NULL); */
1384 s = sound_lookup(sound_name, SOUND_LOAD, NULL);
1385 if (s == NULL || s->status != SOUND_READY)
1386 {
1387 report(REPORT_NOTICE, "%s info %s - not found\n",
1388 inet_ntoa(c->sin.sin_addr), sound_name);
1389 connection_reply(c, "%cerror=\"%s not found\" command=info client-data=\"%s\"",
1390 RPTP_ERROR, sound_name, client_data);
1391 }
1392 else
1393 {
1394 connection_reply(c, "\
1395 %csound=\"%s\" size=%d bits=%g sample-rate=%d channels=%d format=%s byte-order=%s input=%s seconds=%.2f command=info client-data=\"%s\"",
1396 RPTP_OK,
1397 s->name,
1398 s->size,
1399 s->input_precision,
1400 s->sample_rate,
1401 s->channels,
1402 audio_format_to_string(s->format),
1403 byte_order_to_string(s->byte_order),
1404 input_to_string(s->type),
1405 s->sample_rate && s->samples ? (double) s->samples / s->sample_rate : 0,
1406 client_data);
1407 }
1408
1409 return 0;
1410 }
1411
1412 #ifdef __STDC__
1413 static int
1414 command_version(CONNECTION *c, int argc, char **argv)
1415 #else
1416 static int
1417 command_version(c, argc, argv)
1418 CONNECTION *c;
1419 int argc;
1420 char **argv;
1421 #endif
1422 {
1423 char *client_data;
1424
1425 client_data = rptp_parse(command_buffer, "client-data");
1426 if (!client_data)
1427 {
1428 client_data = default_client_data;
1429 }
1430
1431 connection_reply(c, "%cversion=%s command=version client-data=\"%s\"",
1432 RPTP_OK, RPLAY_VERSION, client_data);
1433
1434 return 0;
1435 }
1436
1437 #ifdef __STDC__
1438 static void
1439 do_events(char *event_string, int *mask, int *spool_id)
1440 #else
1441 static void
1442 do_events(event_string, mask, spool_id)
1443 char *event_string;
1444 int *mask;
1445 int *spool_id;
1446 #endif
1447 {
1448 char buf[RPTP_MAX_LINE];
1449 int first = 1;
1450 char *p;
1451 int operator, bit;
1452
1453 *spool_id = 0;
1454
1455 strncpy(buf, event_string, sizeof(buf));
1456
1457 while (p = strtok(first ? buf : NULL, ",| "))
1458 {
1459 first = 0;
1460 bit = 0;
1461 operator = 0;
1462
1463 if (*p == '+')
1464 {
1465 operator = 0;
1466 p++;
1467 }
1468 else if (*p == '-')
1469 {
1470 operator = 1;
1471 p++;
1472 }
1473
1474 if (strcmp(p, "all") == 0 || strcmp(p, "any") == 0)
1475 {
1476 bit = NOTIFY_ANY;
1477 }
1478 else if (strcmp(p, "none") == 0)
1479 {
1480 *mask = 0;
1481 }
1482 else if (strcmp(p, "play") == 0)
1483 {
1484 bit = NOTIFY_PLAY;
1485 }
1486 else if (strcmp(p, "stop") == 0)
1487 {
1488 bit = NOTIFY_STOP;
1489 }
1490 else if (strcmp(p, "pause") == 0)
1491 {
1492 bit = NOTIFY_PAUSE;
1493 }
1494 else if (strcmp(p, "continue") == 0)
1495 {
1496 bit = NOTIFY_CONTINUE;
1497 }
1498 else if (strcmp(p, "volume") == 0)
1499 {
1500 bit = NOTIFY_VOLUME;
1501 }
1502 else if (strcmp(p, "done") == 0)
1503 {
1504 bit = NOTIFY_DONE;
1505 }
1506 else if (strcmp(p, "skip") == 0)
1507 {
1508 bit = NOTIFY_SKIP;
1509 }
1510 else if (strcmp(p, "state") == 0)
1511 {
1512 bit = NOTIFY_STATE;
1513 }
1514 else if (strcmp(p, "flow") == 0)
1515 {
1516 bit = NOTIFY_FLOW;
1517 }
1518 else if (p[0] == '#')
1519 {
1520 *spool_id = atoi(p + 1);
1521 }
1522 else if (strcmp(p, "modify") == 0)
1523 {
1524 bit = NOTIFY_MODIFY;
1525 }
1526 else if (strcmp(p, "level") == 0)
1527 {
1528 bit = NOTIFY_LEVEL;
1529 }
1530 else if (strcmp(p, "position") == 0)
1531 {
1532 bit = NOTIFY_POSITION;
1533 }
1534
1535 if (operator == 0)
1536 {
1537 SET_BIT(*mask, bit);
1538 }
1539 else
1540 {
1541 CLR_BIT(*mask, bit);
1542 }
1543 }
1544
1545 /* If a spool id is set and there's no mask, assign a default
1546 mask which will notify everything than can happen to the
1547 spool entry. */
1548 if (*spool_id && !*mask)
1549 {
1550 SET_BIT(*mask, NOTIFY_SPOOL);
1551 }
1552 }
1553
1554 #ifdef __STDC__
1555 static int
1556 command_wait(CONNECTION *c, int argc, char **argv)
1557 #else
1558 static int
1559 command_wait(c, argc, argv)
1560 CONNECTION *c;
1561 int argc;
1562 char **argv;
1563 #endif
1564 {
1565 EVENT *e;
1566 char *client_data;
1567
1568 client_data = rptp_parse(command_buffer, "client-data");
1569 if (!client_data)
1570 {
1571 client_data = default_client_data;
1572 }
1573
1574 /* `wait' - wait for anything */
1575 if (argc == 1)
1576 {
1577 e = event_create(EVENT_NOTIFY);
1578 SET_BIT(e->wait_mask, NOTIFY_ANY);
1579 event_insert(c, e);
1580 return 0;
1581 }
1582 /* `wait id=#spool-id' or `wait event=event,event,event' */
1583 else if (argc == 2 && strchr(argv[1], '='))
1584 {
1585 char *value;
1586
1587 value = rptp_parse(argv[1], "id");
1588 if (value && *value)
1589 {
1590 e = event_create(EVENT_NOTIFY);
1591 SET_BIT(e->wait_mask, NOTIFY_DONE);
1592 e->id = atoi(value + 1);
1593 event_insert(c, e);
1594 return 0;
1595 }
1596
1597 value = rptp_parse(argv[1], "event");
1598 if (value && *value)
1599 {
1600 e = event_create(EVENT_NOTIFY);
1601 do_events(value, &e->wait_mask, &e->id);
1602 event_insert(c, e);
1603 return 0;
1604 }
1605
1606 connection_reply(c, "%cerror=\"unknown wait attribute `%s'\" command=wait client-data=\"%s\"",
1607 RPTP_ERROR, argv[1], client_data);
1608 return 0;
1609 }
1610 /* `wait play ...' */
1611 else if (strcmp(argv[1], "play") == 0)
1612 {
1613 int id;
1614
1615 id = do_execute(c, argc - 1, argv + 1);
1616 if (id > 0)
1617 {
1618 e = event_create(EVENT_NOTIFY);
1619 SET_BIT(e->wait_mask, NOTIFY_DONE);
1620 e->id = id;
1621 event_insert(c, e);
1622 }
1623
1624 return 0;
1625 }
1626 else
1627 {
1628 /* XXX: Need to fix command_buffer */
1629 int i, n;
1630 command_buffer[0] = '\0';
1631 n = 0;
1632 for (i = 1; i < argc; i++)
1633 {
1634 SNPRINTF(SIZE(command_buffer + n, sizeof(command_buffer) - n), argv[i]);
1635 n += strlen(argv[i]);
1636 if (i + 1 != argc)
1637 {
1638 SNPRINTF(SIZE(command_buffer + n, sizeof(command_buffer) - n), " ");
1639 n++;
1640 }
1641 }
1642
1643 return do_command(c, argc - 1, argv + 1);
1644 }
1645 }
1646
1647 #ifdef __STDC__
1648 static int
1649 command_status(CONNECTION *c, int argc, char **argv)
1650 #else
1651 static int
1652 command_status(c, argc, argv)
1653 CONNECTION *c;
1654 int argc;
1655 char **argv;
1656 #endif
1657 {
1658 EVENT *e;
1659
1660 e = event_create(EVENT_WRITE, rplayd_status());
1661 event_insert(c, e);
1662
1663 return 0;
1664 }
1665
1666 /* OBSOLETE */
1667 #ifdef __STDC__
1668 static int
1669 command_application(CONNECTION *c, int argc, char **argv)
1670 #else
1671 static int
1672 command_application(c, argc, argv)
1673 CONNECTION *c;
1674 int argc;
1675 char **argv;
1676 #endif
1677 {
1678 int i, n;
1679 char buf[RPTP_MAX_LINE];
1680
1681 buf[0] = '\0';
1682 n = 0;
1683 for (i = 1; i < argc; i++)
1684 {
1685 SNPRINTF(SIZE(buf + n, sizeof(buf) - n), argv[i]);
1686 n += strlen(argv[i]);
1687 if (i + 1 != argc)
1688 {
1689 SNPRINTF(SIZE(buf + n, sizeof(buf) - n), " ");
1690 n++;
1691 }
1692 }
1693
1694 if (c->application)
1695 {
1696 free(c->application);
1697 }
1698
1699 c->application = strdup(buf);
1700
1701 connection_reply(c, "%c%s", RPTP_OK, c->application);
1702
1703 return 0;
1704 }
1705
1706 #ifdef DEBUG
1707 #ifdef __STDC__
1708 static int
1709 command_die(CONNECTION *c, int argc, char **argv)
1710 #else
1711 static int
1712 command_die(c, argc, argv)
1713 CONNECTION *c;
1714 int argc;
1715 char **argv;
1716 #endif
1717 {
1718 report(REPORT_DEBUG, "time to die...\n");
1719 connection_close(c);
1720 done(0);
1721 return -1; /* not reached */
1722 }
1723 #endif /* DEBUG */
1724
1725 #ifdef __STDC__
1726 static int
1727 command_reset(CONNECTION *c, int argc, char **argv)
1728 #else
1729 static int
1730 command_reset(c, argc, argv)
1731 CONNECTION *c;
1732 int argc;
1733 char **argv;
1734 #endif
1735 {
1736 char *client_data;
1737
1738 client_data = rptp_parse(command_buffer, "client-data");
1739 if (!client_data)
1740 {
1741 client_data = default_client_data;
1742 }
1743
1744 #ifdef AUTH
1745 if (!host_access(c->sin, HOST_EXECUTE))
1746 {
1747 report(REPORT_NOTICE, "%s reset access denied\n", inet_ntoa(c->sin.sin_addr));
1748 connection_reply(c, "%cerror=\"access denied\" command=reset client-data=\"%s\"",
1749 RPTP_ERROR, client_data);
1750 return 0;
1751 }
1752 #endif /* AUTH */
1753
1754 need_reset();
1755
1756 connection_reply(c, "%cmessage=\"reset successful\" command=reset client-data=\"%s\"",
1757 RPTP_OK, client_data);
1758
1759 return 0;
1760 }
1761
1762 #ifdef __STDC__
1763 static int
1764 command_skip(CONNECTION *c, int argc, char **argv)
1765 #else
1766 static int
1767 command_skip(c, argc, argv)
1768 CONNECTION *c;
1769 int argc;
1770 char **argv;
1771 #endif
1772 {
1773 SPOOL *sp;
1774 int id = 0, count = 1; /* default */
1775 int nskipped = 0;
1776 char *p;
1777 char *client_data;
1778
1779 client_data = rptp_parse(command_buffer, "client-data");
1780 if (!client_data)
1781 {
1782 client_data = default_client_data;
1783 }
1784
1785 #ifdef AUTH
1786 if (!host_access(c->sin, HOST_EXECUTE))
1787 {
1788 report(REPORT_NOTICE, "%s skip access denied\n", inet_ntoa(c->sin.sin_addr));
1789 connection_reply(c, "%cerror=\"access denied\" command=skip client-data=\"%s\"",
1790 RPTP_ERROR, client_data);
1791 return 0;
1792 }
1793 #endif /* AUTH */
1794
1795 p = rptp_parse(0, "id");
1796 if (p)
1797 {
1798 id = atoi(p + 1);
1799 }
1800 p = rptp_parse(0, "count");
1801 if (p)
1802 {
1803 count = atoi(p);
1804 }
1805
1806 for (sp = spool; sp; sp = sp->next)
1807 {
1808 if (!id || sp->id == id)
1809 {
1810 spool_skip(sp, count);
1811 nskipped++;
1812 }
1813 }
1814
1815 if (nskipped)
1816 {
1817 connection_reply(c, "%cmessage=\"skipped\" command=skip client-data=\"%s\"",
1818 RPTP_OK, client_data);
1819 }
1820 else
1821 {
1822 connection_reply(c, "%cerror=\"skip failed\" command=skip client-data=\"%s\"",
1823 RPTP_ERROR, client_data);
1824 }
1825
1826 return 0;
1827 }
1828
1829 #ifdef __STDC__
1830 static int
1831 command_set(CONNECTION *c, int argc, char **argv)
1832 #else
1833 static int
1834 command_set(c, argc, argv)
1835 CONNECTION *c;
1836 int argc;
1837 char **argv;
1838 #endif
1839 {
1840 char *name, *value;
1841 BUFFER *b;
1842 EVENT *e;
1843 int volume_changed = 0;
1844 int priority_threshold_changed = 0;
1845 int audio_port_changed = 0;
1846 int notify_enabled = 0;
1847 SPOOL *sp;
1848 int notify_mask = 0;
1849 int notify_id = 0;
1850 char *client_data;
1851 char buf[RPTP_MAX_LINE];
1852
1853 client_data = rptp_parse(command_buffer, "client-data");
1854 if (!client_data)
1855 {
1856 client_data = default_client_data;
1857 }
1858
1859 #ifdef AUTH
1860 if (!host_access(c->sin, HOST_EXECUTE))
1861 {
1862 report(REPORT_NOTICE, "%s set access denied\n", inet_ntoa(c->sin.sin_addr));
1863 connection_reply(c, "%cerror=\"access denied\" command=set client-data=\"%s\"",
1864 RPTP_ERROR, client_data);
1865 return 0;
1866 }
1867 #endif /* AUTH */
1868
1869 b = buffer_create();
1870 b->buf[0] = RPTP_OK;
1871 b->buf[1] = '\0';
1872 b->nbytes = 1;
1873
1874 rptp_parse(command_buffer, 0);
1875 while (name = rptp_parse(0, 0))
1876 {
1877 value = rptp_parse(0, name);
1878
1879 if (strcmp(name, "application") == 0) /* `application=value' */
1880 {
1881 if (value && *value)
1882 {
1883 if (c->application)
1884 {
1885 free(c->application);
1886 }
1887 c->application = strdup(value);
1888 }
1889 SNPRINTF(SIZE(buf, sizeof(buf)), "application=\"%s\"",
1890 c->application ? c->application : "-1");
1891 strncat(b->buf + b->nbytes, buf, BUFFER_SIZE - b->nbytes);
1892 b->nbytes += strlen(buf);
1893 }
1894 else if (strcmp(name, "notify") == 0) /* `notify=[event,...]' */
1895 {
1896 if (value)
1897 {
1898 do_events(value, &c->notify_mask, &c->notify_id);
1899 }
1900
1901 if (!c->notify_mask)
1902 {
1903 SNPRINTF(SIZE(buf, sizeof(buf)), "notify=none");
1904 strncat(b->buf + b->nbytes, buf, BUFFER_SIZE - b->nbytes);
1905 b->nbytes += strlen(buf);
1906 }
1907 else
1908 {
1909 SNPRINTF(SIZE(buf, sizeof(buf)), "notify=\"%s\"", value);
1910 strncat(b->buf + b->nbytes, buf, BUFFER_SIZE - b->nbytes);
1911 b->nbytes += strlen(buf);
1912 notify_enabled++;
1913 }
1914 }
1915 else if (strcmp(name, "volume") == 0) /* `volume=[+|-]value' */
1916 {
1917 int volume = rplay_audio_get_volume();
1918
1919 if (value && *value)
1920 {
1921 switch (value[0])
1922 {
1923 case '+':
1924 volume += atoi(value + 1);
1925 break;
1926
1927 case '-':
1928 volume -= atoi(value + 1);
1929 break;
1930
1931 case '*':
1932 volume *= atoi(value + 1);
1933 break;
1934
1935 case '/':
1936 volume /= atoi(value + 1);
1937 break;
1938
1939 default:
1940 volume = atoi(value);
1941 }
1942
1943 volume = rplay_audio_set_volume(volume);
1944 }
1945
1946 if (volume >= 0)
1947 {
1948 SNPRINTF(SIZE(buf, sizeof(buf)), "volume=%d", volume);
1949 strncat(b->buf + b->nbytes, buf, BUFFER_SIZE - b->nbytes);
1950 b->nbytes += strlen(buf);
1951 volume_changed++;
1952 }
1953 else
1954 {
1955 SNPRINTF(SIZE(buf, sizeof(buf)), "volume=-1");
1956 strncat(b->buf + b->nbytes, buf, BUFFER_SIZE - b->nbytes);
1957 b->nbytes += strlen(buf);
1958 }
1959 }
1960 else if (strcmp(name, "priority-threshold") == 0) /* `priority-threshold=value' */
1961 {
1962 if (value && *value)
1963 {
1964 rplay_priority_threshold = atoi(value);
1965 if (rplay_priority_threshold < RPLAY_MIN_PRIORITY)
1966 {
1967 rplay_priority_threshold = RPLAY_MIN_PRIORITY;
1968 }
1969 else if (rplay_priority_threshold > RPLAY_MAX_PRIORITY)
1970 {
1971 rplay_priority_threshold = RPLAY_MAX_PRIORITY;
1972 }
1973
1974 priority_threshold_changed++;
1975 }
1976 SNPRINTF(SIZE(buf, sizeof(buf)), "priority-threshold=%d",
1977 rplay_priority_threshold);
1978 strncat(b->buf + b->nbytes, buf, BUFFER_SIZE - b->nbytes);
1979 b->nbytes += strlen(buf);
1980 }
1981 else if (strcmp(name, "notify-rate") == 0) /* `notify-rate=value' */
1982 {
1983 if (value && *value)
1984 {
1985 int i;
1986 double rate;
1987
1988 rate = atof(value);
1989
1990 for (i = 0; i < NOTIFY_RATE_MAX; i++)
1991 {
1992 c->notify_rate[i].rate = rate;
1993 c->notify_rate[i].next = 0.0;
1994 }
1995 }
1996
1997 SNPRINTF(SIZE(buf, sizeof(buf)), "level-notify-rate=%.2f position-notify-rate=%.2f",
1998 c->notify_rate[NOTIFY_RATE_LEVEL].rate,
1999 c->notify_rate[NOTIFY_RATE_POSITION].rate);
2000 strncat(b->buf + b->nbytes, buf, BUFFER_SIZE - b->nbytes);
2001 b->nbytes += strlen(buf);
2002 }
2003 else if (strcmp(name, "level-notify-rate") == 0)
2004 {
2005 if (value && *value)
2006 {
2007 c->notify_rate[NOTIFY_RATE_LEVEL].rate = atof(value);
2008 c->notify_rate[NOTIFY_RATE_LEVEL].next = 0.0;
2009 }
2010
2011 SNPRINTF(SIZE(buf, sizeof(buf)), "level-notify-rate=%.2f",
2012 c->notify_rate[NOTIFY_RATE_LEVEL].rate);
2013 strncat(b->buf + b->nbytes, buf, BUFFER_SIZE - b->nbytes);
2014 b->nbytes += strlen(buf);
2015 }
2016 else if (strcmp(name, "position-notify-rate") == 0)
2017 {
2018 if (value && *value)
2019 {
2020 c->notify_rate[NOTIFY_RATE_POSITION].rate = atof(value);
2021 c->notify_rate[NOTIFY_RATE_POSITION].next = 0.0;
2022 }
2023
2024 SNPRINTF(SIZE(buf, sizeof(buf)), "position-notify-rate=%.2f",
2025 c->notify_rate[NOTIFY_RATE_POSITION].rate);
2026 strncat(b->buf + b->nbytes, buf, BUFFER_SIZE - b->nbytes);
2027 b->nbytes += strlen(buf);
2028 }
2029 else if (strcmp(name, "audio-port") == 0)
2030 {
2031 int n;
2032
2033 optional_port = rplay_audio_port;
2034
2035 if (strstr(value, "none"))
2036 {
2037 optional_port = 0;
2038 }
2039 if (strstr(value, "speaker"))
2040 {
2041 SET_BIT(optional_port, RPLAY_AUDIO_PORT_SPEAKER);
2042 }
2043 if (strstr(value, "headphone"))
2044 {
2045 SET_BIT(optional_port, RPLAY_AUDIO_PORT_HEADPHONE);
2046 }
2047 if (strstr(value, "lineout"))
2048 {
2049 SET_BIT(optional_port, RPLAY_AUDIO_PORT_LINEOUT);
2050 }
2051
2052 if (optional_port != rplay_audio_port)
2053 {
2054 n = rplay_audio_init();
2055 if (n >= 0)
2056 {
2057 audio_port_changed++;
2058 }
2059 }
2060 else
2061 {
2062 n = 0;
2063 }
2064
2065 if (n < 0)
2066 {
2067 SNPRINTF(SIZE(buf, sizeof(buf)), "audio-port=-1");
2068 strncat(b->buf + b->nbytes, buf, BUFFER_SIZE - b->nbytes);
2069 b->nbytes += strlen(buf);
2070 }
2071 else
2072 {
2073 SNPRINTF(SIZE(buf, sizeof(buf)), "audio-port=%s", value);
2074 strncat(b->buf + b->nbytes, buf, BUFFER_SIZE - b->nbytes);
2075 b->nbytes += strlen(buf);
2076 }
2077 }
2078 else if (strcmp(name, "audio-info") == 0)
2079 {
2080 char info[1024], *p;
2081 SPOOL *sp, *sp_next;
2082 int bufsize, rate;
2083
2084 /* Stop all sounds. */
2085 for (sp = spool; sp; sp = sp_next)
2086 {
2087 sp_next = sp->next;
2088 spool_stop(sp);
2089 }
2090
2091 /* Example: ulaw,8000,8,1 */
2092 strncpy(info, value, sizeof(info));
2093 p = strtok(info, ", ");
2094 if (p)
2095 optional_format = string_to_audio_format(p);
2096 p = strtok(NULL, ",");
2097 if (p)
2098 optional_sample_rate = atoi(p);
2099 p = strtok(NULL, ",");
2100 if (p)
2101 optional_precision = atoi(p);
2102 p = strtok(NULL, ",");
2103 if (p)
2104 optional_channels = atoi(p);
2105
2106 #ifndef HAVE_OSS
2107 bufsize = rplay_audio_bufsize; /* XXX: force recalculation */
2108 rplay_audio_bufsize = 0;
2109 #endif /* !HAVE_OSS */
2110
2111 rate = rplay_audio_rate;
2112 rplay_audio_rate = 0;
2113
2114 if (rplayd_audio_init() < 0)
2115 {
2116 SNPRINTF(SIZE(buf, sizeof(buf)), "audio-info=-1");
2117 strncat(b->buf + b->nbytes, buf, BUFFER_SIZE - b->nbytes);
2118 b->nbytes += strlen(buf);
2119 #ifndef HAVE_OSS
2120 rplay_audio_bufsize = bufsize;
2121 #endif /* !HAVE_OSS */
2122 rplay_audio_rate = rate;
2123 }
2124 else
2125 {
2126 SNPRINTF(SIZE(buf, sizeof(buf)), "audio-info=%s", value);
2127 strncat(b->buf + b->nbytes, buf, BUFFER_SIZE - b->nbytes);
2128 b->nbytes += strlen(buf);
2129 }
2130 }
2131 else if (strcmp(name, "audio-close") == 0)
2132 {
2133 if (value && *value)
2134 {
2135 extern int rplay_audio_timeout;
2136 rplay_audio_timeout = atoi(value);
2137 SNPRINTF(SIZE(buf, sizeof(buf)), "audio-close=%d", rplay_audio_timeout);
2138 strncat(b->buf + b->nbytes, buf, BUFFER_SIZE - b->nbytes);
2139 b->nbytes += strlen(buf);
2140 }
2141 }
2142 else
2143 {
2144 SNPRINTF(SIZE(buf, sizeof(buf)), "%s=-1", name);
2145 strncat(b->buf + b->nbytes, buf, BUFFER_SIZE - b->nbytes);
2146 b->nbytes += strlen(buf);
2147 }
2148
2149 SNPRINTF(SIZE(buf, sizeof(buf)), " ");
2150 strncat(b->buf + b->nbytes, buf, BUFFER_SIZE - b->nbytes);
2151 b->nbytes += strlen(buf);
2152 }
2153
2154 SNPRINTF(SIZE(buf, sizeof(buf)), "command=set client-data=\"%s\"\r\n",
2155 client_data);
2156 strncat(b->buf + b->nbytes, buf, BUFFER_SIZE - b->nbytes);
2157 b->nbytes += strlen(buf);
2158
2159 e = event_create(EVENT_WRITE, b);
2160 event_insert(c, e);
2161
2162 if (notify_enabled)
2163 {
2164 /* Notify the current status. */
2165 for (sp = spool; sp; sp = sp->next)
2166 {
2167 switch (sp->state)
2168 {
2169 case SPOOL_PLAY:
2170 connection_notify(c, NOTIFY_PLAY, sp);
2171 break;
2172
2173 case SPOOL_PAUSE:
2174 connection_notify(c, NOTIFY_PAUSE, sp);
2175 break;
2176 }
2177 }
2178 connection_notify(c, NOTIFY_VOLUME, rplay_audio_volume);
2179
2180 e = event_create(EVENT_NOTIFY);
2181 event_insert(c, e);
2182 }
2183
2184 if (volume_changed)
2185 {
2186 connection_notify(0, NOTIFY_VOLUME, rplay_audio_volume);
2187 }
2188
2189 if (priority_threshold_changed || audio_port_changed)
2190 {
2191 connection_notify(0, NOTIFY_STATE);
2192 }
2193
2194 connection_want_level_notify = 0;
2195 for (c = connections; c; c = c->next)
2196 {
2197 if (BIT(c->notify_mask, NOTIFY_LEVEL)
2198 || (c->event && BIT(c->event->wait_mask, NOTIFY_LEVEL)))
2199 {
2200 connection_want_level_notify++;
2201 }
2202 }
2203
2204 return 0;
2205 }
2206
2207 #ifdef __STDC__
2208 static int
2209 command_modify(CONNECTION *c, int argc, char **argv)
2210 #else
2211 static int
2212 command_modify(c, argc, argv)
2213 CONNECTION *c;
2214 int argc;
2215 char **argv;
2216 #endif
2217 {
2218 SPOOL *sp;
2219 int id = 0;
2220 char *p;
2221 int new_sample_rate = -1;
2222 int new_volume = -1;
2223 int new_count = -1;
2224 int new_priority = -1;
2225 int new_list_count = -1;
2226 char *new_client_data = NULL;
2227 int modified, total_modified = 0;
2228
2229 #ifdef AUTH
2230 if (!host_access(c->sin, HOST_EXECUTE))
2231 {
2232 report(REPORT_NOTICE, "%s modify access denied\n", inet_ntoa(c->sin.sin_addr));
2233 connection_reply(c, "%cerror=\"access denied\" command=modify", RPTP_ERROR);
2234 return 0;
2235 }
2236 #endif /* AUTH */
2237
2238 p = rptp_parse(command_buffer, "id");
2239 if (!p || !*p)
2240 {
2241 connection_reply(c, "%cerror=\"missing `id'\" command=modify", RPTP_ERROR);
2242 return 0;
2243 }
2244 id = atoi(p + 1);
2245
2246 p = rptp_parse(0, "count");
2247 if (p)
2248 {
2249 new_count = atoi(p);
2250 }
2251
2252 p = rptp_parse(0, "list-count");
2253 if (p)
2254 {
2255 new_list_count = atoi(p);
2256 }
2257
2258 p = rptp_parse(0, "priority");
2259 if (p)
2260 {
2261 new_priority = atoi(p);
2262 }
2263
2264 p = rptp_parse(0, "sample-rate");
2265 if (p)
2266 {
2267 new_sample_rate = atoi(p);
2268 }
2269
2270 p = rptp_parse(0, "volume");
2271 if (p)
2272 {
2273 new_volume = atoi(p);
2274 }
2275
2276 p = rptp_parse(0, "client-data");
2277 if (p)
2278 {
2279 new_client_data = p;
2280 }
2281
2282 for (sp = spool; sp; sp = sp->next)
2283 {
2284 if (!id || sp->id == id)
2285 {
2286 modified = 0;
2287 if (new_count != -1)
2288 {
2289 spool_set_count(sp, new_count);
2290 modified++;
2291 }
2292 if (new_list_count != -1)
2293 {
2294 spool_set_list_count(sp, new_list_count);
2295 modified++;
2296 }
2297 if (new_priority != -1)
2298 {
2299 spool_set_priority(sp, new_priority);
2300 modified++;
2301 }
2302 if (new_sample_rate != -1)
2303 {
2304 spool_set_sample_rate(sp, new_sample_rate);
2305 modified++;
2306 }
2307 if (new_volume != -1)
2308 {
2309 spool_set_volume(sp, new_volume);
2310 modified++;
2311 }
2312 if (new_client_data)
2313 {
2314 spool_set_client_data(sp, new_client_data);
2315 modified++;
2316 }
2317
2318 if (modified)
2319 {
2320 connection_notify(c, NOTIFY_MODIFY, sp);
2321 total_modified++;
2322 }
2323 }
2324 }
2325
2326 if (total_modified)
2327 {
2328 connection_reply(c, "%cmessage=\"modified\" command=modify", RPTP_OK);
2329 }
2330 else
2331 {
2332 connection_reply(c, "%cerror=\"nothing modified\" command=modify", RPTP_ERROR);
2333 }
2334
2335 return 0;
2336 }
2337
2338 #ifdef __STDC__
2339 static int
2340 command_monitor(CONNECTION *c, int argc, char **argv)
2341 #else
2342 static int
2343 command_monitor(c, argc, argv)
2344 CONNECTION *c;
2345 int argc;
2346 char **argv;
2347 #endif
2348 {
2349 EVENT *e;
2350
2351 #ifdef AUTH
2352 if (!host_access(c->sin, HOST_MONITOR))
2353 {
2354 report(REPORT_NOTICE, "%s monitor - monitor access denied\n",
2355 inet_ntoa(c->sin.sin_addr));
2356 connection_reply(c, "%cerror=\"access denied\" command=monitor",
2357 RPTP_ERROR);
2358 return 0;
2359 }
2360 #endif /* AUTH */
2361
2362 if (monitor_count == 0)
2363 {
2364 monitor_alloc();
2365 }
2366 monitor_count++;
2367
2368 connection_reply(c, "%caudio-info=\"%s,%d,%d,%d,%s\"", RPTP_OK,
2369 audio_format_to_string(rplay_audio_format),
2370 rplay_audio_sample_rate,
2371 rplay_audio_precision,
2372 rplay_audio_channels,
2373 byte_order_to_string(RPLAY_AUDIO_BYTE_ORDER));
2374 e = event_create(EVENT_WAIT_MONITOR);
2375 event_insert(c, e);
2376
2377 c->monitor = 1;
2378
2379 return 0;
2380 }