summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJaromil <jaromil@dyne.org>2011-04-19 14:02:26 (GMT)
committer Jaromil <jaromil@dyne.org>2011-04-19 14:02:26 (GMT)
commitabdbc9b5c8ea7bdb1660a5d990f13f7cacfc6323 (patch)
treef851bfd38ea068ca82c514cb5fa3eaabb06a5306
parent11de3001a20ccac18ba1ec8fbc9b1f89244ea2db (diff)
parsers reorganized
-rw-r--r--src/Makefile.am2
-rw-r--r--src/cmdline.c71
-rw-r--r--src/discover.c19
-rw-r--r--src/discover.h19
-rw-r--r--src/parsers.c83
-rw-r--r--src/parsers.h31
6 files changed, 168 insertions, 57 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 4451631..fcb288d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,6 +1,6 @@
bin_PROGRAMS = avremote
-avremote_SOURCES = avremote.c avremote.h discover.h cmdline.c discover.c
+avremote_SOURCES = avremote.c avremote.h cmdline.c discover.c discover.h parsers.c parsers.h
avremove_CFLAGS = $(UPNP_CFLAGS)
avremote_LDADD = $(UPNP_LIBS)
diff --git a/src/cmdline.c b/src/cmdline.c
index fea75d2..73c40ef 100644
--- a/src/cmdline.c
+++ b/src/cmdline.c
@@ -33,6 +33,7 @@
#include <avremote.h>
#include <discover.h>
+#include <parsers.h>
// our exit codes are shell style: 1 is error, 0 is success
#define ERR 1
@@ -47,6 +48,8 @@ int port = 0;
int dry_run = 0;
int discover = 0;
+parser_f *parser = NULL;
+
// we use only getopt, no _long
static const char *short_options = "-hvs:p:t";
@@ -71,13 +74,14 @@ void cmdline(int argc, char **argv) {
"\n"
"Commands:\n"
"\n"
+#ifdef USE_UPNP
+ " discover search for upnp devices on the network\n"
+#endif
" load load a file and prepare it for playback\n"
" play start playing the selected file\n"
" pause pause currently running playback\n"
" stop stop playback and return to menu\n"
-#ifdef USE_UPNP
- " discover search for upnp devices on the network\n"
-#endif
+ " get get the current status of the device\n"
"\n"
"Options:\n"
"\n"
@@ -154,11 +158,6 @@ void cmdline(int argc, char **argv) {
}
}
-// function pointers to various parsers
-typedef void (parser_f)(char *res);
-static parser_f *parser = NULL;
-// parsers implemented
-void gettransportinfo(char *res);
int main(int argc, char **argv) {
upnp_t *upnp;
@@ -225,15 +224,18 @@ int main(int argc, char **argv) {
render_upnp(upnp,"Stop","");
break;
- case 'g':
+ case 'g': // dump a parsable full state of the device
render_upnp(upnp,"GetTransportInfo","");
- parser = gettransportinfo;
+ parser = GetTransportInfo;
+
break;
default:
- fprintf(stderr,"error: command not understood.\n");
- free_upnp(upnp);
- exit(1);
+ fprintf(stderr,"warning: command not recognized, sending anyway.\n");
+ render_upnp(upnp,command,"");
+
+ // free_upnp(upnp);
+ // exit(1);
}
if (dry_run)
@@ -252,46 +254,3 @@ int main(int argc, char **argv) {
exit(0);
}
-
-void gettransportinfo(char *res) {
- char *p, *pp;
- char state[64];
- char status[64];
- char speed[32];
-
- // as you can see, i had a lot of fun with pointers when i was a kid
-
- p = strstr(res, "CurrentTransportState");
- if (!p) {
- fprintf(stderr, "error parsing response:\n%s\n",res);
- return;
- }
- pp = p; do pp+=1; while (*pp != '>'); pp++;
- p = pp; do p+=1; while (*p != '<'); *p = 0;
- snprintf(state,63,"%s",pp);
-
- p++;
-
- p = strstr(p, "CurrentTransportStatus");
- if (!p) {
- fprintf(stderr, "error parsing response:\n%s\n",res);
- return;
- }
- pp = p; do pp+=2; while (*pp != '>'); pp++;
- p = pp; do p+=1; while (*p != '<'); *p = 0;
- snprintf(status,63,"%s",pp);
-
- p++;
-
- p = strstr(p, "CurrentSpeed");
- if (!p) {
- fprintf(stderr, "error parsing response:\n%s\n",res);
- return;
- }
- pp = p; do pp+=2; while (*pp != '>'); pp++;
- p = pp; do p+=1; while (*p != '<'); *p = 0;
- snprintf(speed,31,"%s",pp);
-
- fprintf(stderr,"%s\t%s\t%s\n", state, status, speed);
-}
-
diff --git a/src/discover.c b/src/discover.c
index 86639a0..2da2ffa 100644
--- a/src/discover.c
+++ b/src/discover.c
@@ -1,3 +1,22 @@
+/* AVRemote
+
+ (c) 2011 Nederlands Instituut voor Mediakunst (NIMk)
+ 2011 Denis Roio <jaromil@nimk.nl>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>
+
+*/
#include <config.h>
diff --git a/src/discover.h b/src/discover.h
index 52fd25d..40bd95d 100644
--- a/src/discover.h
+++ b/src/discover.h
@@ -1,3 +1,22 @@
+/* AVRemote
+
+ (c) 2011 Nederlands Instituut voor Mediakunst (NIMk)
+ 2011 Denis Roio <jaromil@nimk.nl>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>
+
+*/
#ifdef USE_UPNP
diff --git a/src/parsers.c b/src/parsers.c
new file mode 100644
index 0000000..f37f0b0
--- /dev/null
+++ b/src/parsers.c
@@ -0,0 +1,83 @@
+/* AVRemote
+
+ (c) 2011 Nederlands Instituut voor Mediakunst (NIMk)
+ 2011 Denis Roio <jaromil@nimk.nl>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>
+
+*/
+
+#include <stdio.h>
+#include <string.h>
+
+
+#define MAX 256 // max XML string size
+
+// returns a pointer to the current position in haystack
+// for subsequent calls
+char *extract_xml(char *dest, char *haystack, const char *needle) {
+ char *p, *pp;
+
+ p = strstr(haystack, needle);
+ if (!p) {
+ fprintf(stderr, "parser cannot find \"%s\" in:\n%s\n",needle, haystack);
+ return NULL;
+ }
+ // as you can see, i had a lot of fun with pointers when i was a kid
+ pp = p; do pp+=1; while (*pp != '>'); pp++;
+ p = pp; do p+=1; while (*p != '<'); *p = 0;
+
+ snprintf(dest,MAX-1,"%s",pp);
+
+ return(p+1);
+
+}
+
+void GetCurrentTransportActions(char *res) {
+ char actions[MAX];
+ fprintf(stderr,"#\tactions\n");
+ extract_xml(actions, res, "Actions");
+ fprintf(stderr,"Act: %s\n");
+}
+
+void GetDeviceCapabilities(char *res) {
+ char play[MAX];
+ char rec[MAX];
+ char qual[MAX];
+ char *p;
+
+ fprintf(stderr,"#\tPlay\tRec\tQuality\n");
+ p = extract_xml(play, res, "PlayMedia");
+ p = extract_xml(rec, p, "RecMedia");
+ p = extract_xml(qual, p, "RecQualityModes");
+
+ fprintf(stderr,"Caps:\t%s\t%s\t%s\n",play,rec,qual);
+}
+
+void GetTransportInfo(char *res) {
+ char state[MAX];
+ char status[MAX];
+ char speed[MAX];
+ char *p;
+ fprintf(stderr,"#\tstate\tstatus\tspeed\n");
+
+ p = extract_xml(state, res, "CurrentTransportState");
+
+ p = extract_xml(status, p, "CurrentTransportStatus");
+
+ p = extract_xml(speed, p, "CurrentSpeed");
+
+ fprintf(stderr,"TInfo:\t%s\t%s\t%s\n", state, status, speed);
+}
+
diff --git a/src/parsers.h b/src/parsers.h
new file mode 100644
index 0000000..4983c59
--- /dev/null
+++ b/src/parsers.h
@@ -0,0 +1,31 @@
+/* AVRemote
+
+ (c) 2011 Nederlands Instituut voor Mediakunst (NIMk)
+ 2011 Denis Roio <jaromil@nimk.nl>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>
+
+*/
+
+#ifndef __PARSERS_H__
+#define __PARSERS_H__
+
+// function pointers to various parsers
+typedef void (parser_f)(char *res);
+
+// parsers implemented
+void GetTransportInfo(char *res);
+
+#endif
+