summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJaromil <jaromil@dyne.org>2011-05-31 14:33:27 (GMT)
committer Jaromil <jaromil@dyne.org>2011-05-31 14:33:27 (GMT)
commitec036c8ec18b884a3edeebbb8b714ac65452f8c4 (patch)
treefd7b8c7d830a2c117f9d28fd8006a00c10e6e2a1
parenta5a478f909d416a19ead6ba7e6699f2c9d0475c7 (diff)
accepts piping raw xml commands from stdin
-rw-r--r--src/avremote.c6
-rw-r--r--src/cmdline.c32
2 files changed, 29 insertions, 9 deletions
diff --git a/src/avremote.c b/src/avremote.c
index c21285a..ab00c29 100644
--- a/src/avremote.c
+++ b/src/avremote.c
@@ -214,7 +214,9 @@ int recv_upnp(upnp_t *upnp, int timeout) {
}
int print_upnp(upnp_t *upnp) {
- fprintf(stderr,"header (%u bytes):\n\n%s\n\n",upnp->hdrlen, upnp->hdr);
- fprintf(stderr,"message (%u bytes):\n\n%s\n\n",upnp->msglen, upnp->msg);
+ fprintf(stderr,"header (%u bytes):\n",upnp->hdrlen);
+ fprintf(stdout,"%s\n\n", upnp->hdr);
+ fprintf(stderr,"message (%u bytes):\n",upnp->msglen);
+ fprintf(stdout,"%s\n\n", upnp->msg);
}
diff --git a/src/cmdline.c b/src/cmdline.c
index 0c57f9f..da46ad4 100644
--- a/src/cmdline.c
+++ b/src/cmdline.c
@@ -46,6 +46,7 @@ char server[512];
int port = 0;
int dry_run = 0;
int discover = 0;
+int pipe_stdin = 0;
parser_f *parser = NULL;
@@ -98,7 +99,7 @@ void cmdline(int argc, char **argv) {
case 'v':
fprintf(stderr,"%s - simple commandline tool to send AVTransport commands over UPNP\n"
- "version %s (Apr/2011) by Jaromil - Netherlands Media Art Institute\n"
+ "version %s by Jaromil - Netherlands Media Art Institute\n"
"Copyright (C) 2011 NIMk Artlab, License GNU AGPL v3+\n"
"This is free software: you are free to change and redistribute it\n",
PACKAGE, VERSION);
@@ -138,10 +139,8 @@ void cmdline(int argc, char **argv) {
discover = 1;
} else if(!dry_run) {
// check requires args
- if(!command[0]) {
- fprintf(stderr,"command not specified, see %s -h for help\n",argv[0]);
- exit(1);
- }
+ if( !command[0] || command[0]=='-' && !command[1]) pipe_stdin++;
+
}
}
@@ -158,7 +157,7 @@ int main(int argc, char **argv) {
// no server specified, force discovery
if(!server[0] || !port) discover = 1;
- if (discover)
+ if (discover && !dry_run)
{
fprintf(stderr,"Performing upnp discovery...\n");
found = upnp_discover(upnp);
@@ -195,7 +194,26 @@ int main(int argc, char **argv) {
upnp->port = 0;
}
-
+
+ // pipe raw xml commands from stdin
+ if(pipe_stdin) {
+ int res;
+ int in = 0;
+ char raw[8192];
+
+ while( !feof(stdin) )
+ {
+ in = fread(raw,1,8191,stdin);
+ res = write(upnp->sockfd,raw,in);
+ if(res != in)
+ fprintf(stderr,"upnp pipe wrote only %u of %u bytes",res, in);
+ recv_upnp(upnp, 1000);
+ fprintf(stderr,"%s\n",upnp->res);
+ }
+ free_upnp(upnp);
+ exit(0);
+ }
+
// command parsing is a cascade switch on single letters
// this is supposedly faster than strcmp
switch(command[0]) {