summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJaromil <jaromil@dyne.org>2012-01-22 11:40:20 (GMT)
committer Jaromil <jaromil@dyne.org>2012-01-22 11:40:20 (GMT)
commitbf97fba2e1819cea9b0bfc9bf6bcddad9e7afc45 (patch)
treebc37f793446feea7fcf757631091c630749fe709
parent52912325e53b7018d4f2f9643b9a231ad3f15518 (diff)
avoid segfault on error returned
also noted down a list of error codes for parsing
-rw-r--r--src/parsers.c41
1 files changed, 28 insertions, 13 deletions
diff --git a/src/parsers.c b/src/parsers.c
index 0063c6f..74b46c7 100644
--- a/src/parsers.c
+++ b/src/parsers.c
@@ -31,8 +31,26 @@ char *extract_xml(char *dest, char *haystack, const char *needle) {
p = strstr(haystack, needle);
if (!p) {
- fprintf(stderr, "parser cannot find \"%s\" in:\n%s\n",needle, haystack);
+ fprintf(stderr, "Bad reply to \"%s\":\n%s\n",needle, haystack);
return NULL;
+ /* TODO parse XML correctly and handle standard errors:
+ *
+ * errorCode errorDescription Description
+ * -------- ---------------- -----------
+ * 401 Invalid Action No action by that name at this service.
+ * 402 Invalid Args Could be any of the following: not enough in args,
+ * too many in args, no in arg by that name,
+ * one or more in args are of the wrong data type.
+ * 403 Out of Sync Out of synchronization.
+ * 501 Action Failed May be returned in current state of service
+ * prevents invoking that action.
+ * 600-699 TBD Common action errors. Defined by UPnP Forum
+ * Technical Committee.
+ * 700-799 TBD Action-specific errors for standard actions.
+ * Defined by UPnP Forum working committee.
+ * 800-899 TBD Action-specific errors for non-standard actions.
+ * Defined by UPnP vendor.
+ */
}
// 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++;
@@ -46,9 +64,10 @@ char *extract_xml(char *dest, char *haystack, const char *needle) {
void GetCurrentTransportActions(char *res) {
char actions[MAX];
- fprintf(stderr,"#\tactions\n");
- extract_xml(actions, res, "Actions");
- fprintf(stderr,"Act: %s\n");
+ if( ! extract_xml(actions, res, "Actions") ) return;
+
+ fprintf(stderr,"#\tActions\n");
+ fprintf(stderr,"Act: %s\n", actions);
}
void GetDeviceCapabilities(char *res) {
@@ -57,11 +76,11 @@ void GetDeviceCapabilities(char *res) {
char qual[MAX];
char *p;
- fprintf(stderr,"#\tPlay\tRec\tQuality\n");
- p = extract_xml(play, res, "PlayMedia");
+ p = extract_xml(play, res, "PlayMedia"); if(!p) return;
p = extract_xml(rec, p, "RecMedia");
p = extract_xml(qual, p, "RecQualityModes");
-
+
+ fprintf(stderr,"#\tPlay\tRec\tQuality\n");
fprintf(stderr,"Caps:\t%s\t%s\t%s\n",play,rec,qual);
}
@@ -71,14 +90,10 @@ void GetTransportInfo(char *res) {
char speed[MAX];
char *p;
- fprintf(stderr,"#\tstate\tstatus\tspeed\n");
-
- p = extract_xml(state, res, "CurrentTransportState");
-
+ p = extract_xml(state, res, "CurrentTransportState"); if(!p) return;
p = extract_xml(status, p, "CurrentTransportStatus");
-
p = extract_xml(speed, p, "CurrentSpeed");
+ fprintf(stderr,"#\tstate\tstatus\tspeed\n");
fprintf(stderr,"TInfo:\t%s\t%s\t%s\n", state, status, speed);
}
-