Fixes many problems in sample code.
In particular, undoes 25c908c558c8e60eb386c155a6b93add447ffec0: SF Patch Tracker [ 2836704 ] Search for nested serviceList (not stopping at the first lis Submitted By: zephyrus ( zephyrus00jp ) The original zephyrus' code is still #ifdef'd in the file, if someone wishes to fix it, check for "#ifdef OLD_FIND_SERVICE_CODE". (cherry picked from commit 7e8d1787c9fee5125167e0a352f4617c4b135b42)
This commit is contained in:
parent
d4ef92e1bd
commit
7ec5511a8d
@ -38,21 +38,16 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#define SAMPLE_UTIL_C
|
#define SAMPLE_UTIL_C
|
||||||
|
|
||||||
#include "sample_util.h"
|
#include "sample_util.h"
|
||||||
|
|
||||||
#include "tv_ctrlpt.h"
|
|
||||||
#include "tv_device.h"
|
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
#if !UPNP_HAVE_TOOLS
|
#if !UPNP_HAVE_TOOLS
|
||||||
# error "Need upnptools.h to compile samples ; try ./configure --enable-tools"
|
# error "Need upnptools.h to compile samples ; try ./configure --enable-tools"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
static int initialize_init = 1;
|
static int initialize_init = 1;
|
||||||
static int initialize_register = 1;
|
static int initialize_register = 1;
|
||||||
|
|
||||||
@ -73,12 +68,11 @@ int SampleUtil_Initialize(print_string print_function)
|
|||||||
ithread_mutexattr_setkind_np(&attr, ITHREAD_MUTEX_RECURSIVE_NP);
|
ithread_mutexattr_setkind_np(&attr, ITHREAD_MUTEX_RECURSIVE_NP);
|
||||||
ithread_mutex_init(&display_mutex, &attr);
|
ithread_mutex_init(&display_mutex, &attr);
|
||||||
ithread_mutexattr_destroy(&attr);
|
ithread_mutexattr_destroy(&attr);
|
||||||
|
|
||||||
/* To shut up valgrind mutex warning. */
|
/* To shut up valgrind mutex warning. */
|
||||||
ithread_mutex_lock(&display_mutex);
|
ithread_mutex_lock(&display_mutex);
|
||||||
gPrintFun = print_function;
|
gPrintFun = print_function;
|
||||||
ithread_mutex_unlock(&display_mutex);
|
ithread_mutex_unlock(&display_mutex);
|
||||||
|
/* Finished initializing. */
|
||||||
initialize_init = 0;
|
initialize_init = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,6 +133,9 @@ IXML_NodeList *SampleUtil_GetFirstServiceList(IXML_Document *doc)
|
|||||||
return ServiceList;
|
return ServiceList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define OLD_FIND_SERVICE_CODE
|
||||||
|
#ifdef OLD_FIND_SERVICE_CODE
|
||||||
|
#else
|
||||||
/*
|
/*
|
||||||
* Obtain the service list
|
* Obtain the service list
|
||||||
* n == 0 the first
|
* n == 0 the first
|
||||||
@ -177,18 +174,20 @@ static IXML_NodeList *SampleUtil_GetNthServiceList(
|
|||||||
* return (Node*) A pointer to a Node or NULL if there was an
|
* return (Node*) A pointer to a Node or NULL if there was an
|
||||||
* error. */
|
* error. */
|
||||||
servlistnode = ixmlNodeList_item(servlistnodelist, n);
|
servlistnode = ixmlNodeList_item(servlistnodelist, n);
|
||||||
|
if (!servlistnode) {
|
||||||
assert(servlistnode != 0);
|
|
||||||
|
|
||||||
/* create as list of DOM nodes */
|
/* create as list of DOM nodes */
|
||||||
ServiceList = ixmlElement_getElementsByTagName(
|
ServiceList = ixmlElement_getElementsByTagName(
|
||||||
(IXML_Element *)servlistnode, "service");
|
(IXML_Element *)servlistnode, "service");
|
||||||
|
} else
|
||||||
|
SampleUtil_Print("%s(%d): ixmlNodeList_item(nodeList, n) returned NULL\n",
|
||||||
|
__FILE__, __LINE__);
|
||||||
}
|
}
|
||||||
if (servlistnodelist)
|
if (servlistnodelist)
|
||||||
ixmlNodeList_free(servlistnodelist);
|
ixmlNodeList_free(servlistnodelist);
|
||||||
|
|
||||||
return ServiceList;
|
return ServiceList;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
char *SampleUtil_GetFirstDocumentItem(IXML_Document *doc, const char *item)
|
char *SampleUtil_GetFirstDocumentItem(IXML_Document *doc, const char *item)
|
||||||
{
|
{
|
||||||
@ -208,14 +207,14 @@ char *SampleUtil_GetFirstDocumentItem(IXML_Document *doc, const char *item)
|
|||||||
ret = strdup("");
|
ret = strdup("");
|
||||||
goto epilogue;
|
goto epilogue;
|
||||||
}
|
}
|
||||||
ret = ixmlNode_getNodeValue(textNode);
|
ret = strdup(ixmlNode_getNodeValue(textNode));
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
SampleUtil_Print("%s(%d): ixmlNode_getNodeValue returned NULL\n",
|
SampleUtil_Print("%s(%d): ixmlNode_getNodeValue returned NULL\n",
|
||||||
__FILE__, __LINE__);
|
__FILE__, __LINE__);
|
||||||
ret = strdup("");
|
ret = strdup("");
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
SampleUtil_Print("%s(%d): ixmlNode_getFirstChild(tmpNode) returned NULL\n",
|
SampleUtil_Print("%s(%d): ixmlNodeList_item(nodeList, 0) returned NULL\n",
|
||||||
__FILE__, __LINE__);
|
__FILE__, __LINE__);
|
||||||
} else
|
} else
|
||||||
SampleUtil_Print("%s(%d): Error finding %s in XML Node\n",
|
SampleUtil_Print("%s(%d): Error finding %s in XML Node\n",
|
||||||
@ -242,7 +241,7 @@ char *SampleUtil_GetFirstElementItem(IXML_Element *element, const char *item)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
tmpNode = ixmlNodeList_item(nodeList, 0);
|
tmpNode = ixmlNodeList_item(nodeList, 0);
|
||||||
if (tmpNode) {
|
if (!tmpNode) {
|
||||||
SampleUtil_Print("%s(%d): Error finding %s value in XML Node\n",
|
SampleUtil_Print("%s(%d): Error finding %s value in XML Node\n",
|
||||||
__FILE__, __LINE__, item);
|
__FILE__, __LINE__, item);
|
||||||
ixmlNodeList_free(nodeList);
|
ixmlNodeList_free(nodeList);
|
||||||
@ -555,7 +554,10 @@ int SampleUtil_FindAndParseService(IXML_Document *DescDoc, const char *location,
|
|||||||
unsigned long length;
|
unsigned long length;
|
||||||
int found = 0;
|
int found = 0;
|
||||||
int ret;
|
int ret;
|
||||||
|
#ifdef OLD_FIND_SERVICE_CODE
|
||||||
|
#else /* OLD_FIND_SERVICE_CODE */
|
||||||
unsigned int sindex = 0;
|
unsigned int sindex = 0;
|
||||||
|
#endif /* OLD_FIND_SERVICE_CODE */
|
||||||
char *tempServiceType = NULL;
|
char *tempServiceType = NULL;
|
||||||
char *baseURL = NULL;
|
char *baseURL = NULL;
|
||||||
const char *base = NULL;
|
const char *base = NULL;
|
||||||
@ -569,8 +571,9 @@ int SampleUtil_FindAndParseService(IXML_Document *DescDoc, const char *location,
|
|||||||
base = baseURL;
|
base = baseURL;
|
||||||
else
|
else
|
||||||
base = location;
|
base = location;
|
||||||
|
#ifdef OLD_FIND_SERVICE_CODE
|
||||||
/* Top level */
|
serviceList = SampleUtil_GetFirstServiceList(DescDoc);
|
||||||
|
#else /* OLD_FIND_SERVICE_CODE */
|
||||||
for (sindex = 0;
|
for (sindex = 0;
|
||||||
(serviceList = SampleUtil_GetNthServiceList(DescDoc , sindex)) != NULL;
|
(serviceList = SampleUtil_GetNthServiceList(DescDoc , sindex)) != NULL;
|
||||||
sindex++) {
|
sindex++) {
|
||||||
@ -578,8 +581,7 @@ int SampleUtil_FindAndParseService(IXML_Document *DescDoc, const char *location,
|
|||||||
relcontrolURL = NULL;
|
relcontrolURL = NULL;
|
||||||
releventURL = NULL;
|
releventURL = NULL;
|
||||||
service = NULL;
|
service = NULL;
|
||||||
|
#endif /* OLD_FIND_SERVICE_CODE */
|
||||||
/* serviceList = SampleUtil_GetFirstServiceList( DescDoc ); */
|
|
||||||
length = ixmlNodeList_length(serviceList);
|
length = ixmlNodeList_length(serviceList);
|
||||||
for (i = 0; i < length; i++) {
|
for (i = 0; i < length; i++) {
|
||||||
service = (IXML_Element *)ixmlNodeList_item(serviceList, i);
|
service = (IXML_Element *)ixmlNodeList_item(serviceList, i);
|
||||||
@ -620,7 +622,10 @@ int SampleUtil_FindAndParseService(IXML_Document *DescDoc, const char *location,
|
|||||||
if (serviceList)
|
if (serviceList)
|
||||||
ixmlNodeList_free(serviceList);
|
ixmlNodeList_free(serviceList);
|
||||||
serviceList = NULL;
|
serviceList = NULL;
|
||||||
|
#ifdef OLD_FIND_SERVICE_CODE
|
||||||
|
#else /* OLD_FIND_SERVICE_CODE */
|
||||||
}
|
}
|
||||||
|
#endif /* OLD_FIND_SERVICE_CODE */
|
||||||
free(baseURL);
|
free(baseURL);
|
||||||
|
|
||||||
return found;
|
return found;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user