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