本文整理汇总了C++中xmlXPathFreeObject函数的典型用法代码示例。如果您正苦于以下问题:C++ xmlXPathFreeObject函数的具体用法?C++ xmlXPathFreeObject怎么用?C++ xmlXPathFreeObject使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xmlXPathFreeObject函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: xsl_ext_function_php
static void xsl_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs, int type) /* {{{ */
{
xsltTransformContextPtr tctxt;
zval *args;
zval retval;
int result, i;
int error = 0;
zend_fcall_info fci;
zval handler;
xmlXPathObjectPtr obj;
char *str;
xsl_object *intern;
zend_string *callable = NULL;
if (! zend_is_executing()) {
xsltGenericError(xsltGenericErrorContext,
"xsltExtFunctionTest: Function called from outside of PHP\n");
error = 1;
} else {
tctxt = xsltXPathGetTransformContext(ctxt);
if (tctxt == NULL) {
xsltGenericError(xsltGenericErrorContext,
"xsltExtFunctionTest: failed to get the transformation context\n");
error = 1;
} else {
intern = (xsl_object*)tctxt->_private;
if (intern == NULL) {
xsltGenericError(xsltGenericErrorContext,
"xsltExtFunctionTest: failed to get the internal object\n");
error = 1;
}
else if (intern->registerPhpFunctions == 0) {
xsltGenericError(xsltGenericErrorContext,
"xsltExtFunctionTest: PHP Object did not register PHP functions\n");
error = 1;
}
}
}
if (error == 1) {
for (i = nargs - 1; i >= 0; i--) {
obj = valuePop(ctxt);
xmlXPathFreeObject(obj);
}
return;
}
fci.param_count = nargs - 1;
if (fci.param_count > 0) {
args = safe_emalloc(fci.param_count, sizeof(zval), 0);
}
/* Reverse order to pop values off ctxt stack */
for (i = nargs - 2; i >= 0; i--) {
obj = valuePop(ctxt);
switch (obj->type) {
case XPATH_STRING:
ZVAL_STRING(&args[i], (char *)obj->stringval);
break;
case XPATH_BOOLEAN:
ZVAL_BOOL(&args[i], obj->boolval);
break;
case XPATH_NUMBER:
ZVAL_DOUBLE(&args[i], obj->floatval);
break;
case XPATH_NODESET:
if (type == 1) {
str = (char*)xmlXPathCastToString(obj);
ZVAL_STRING(&args[i], str);
xmlFree(str);
} else if (type == 2) {
int j;
dom_object *domintern = (dom_object *)intern->doc;
array_init(&args[i]);
if (obj->nodesetval && obj->nodesetval->nodeNr > 0) {
for (j = 0; j < obj->nodesetval->nodeNr; j++) {
xmlNodePtr node = obj->nodesetval->nodeTab[j];
zval child;
/* not sure, if we need this... it's copied from xpath.c */
if (node->type == XML_NAMESPACE_DECL) {
xmlNsPtr curns;
xmlNodePtr nsparent;
nsparent = node->_private;
curns = xmlNewNs(NULL, node->name, NULL);
if (node->children) {
curns->prefix = xmlStrdup((char *)node->children);
}
if (node->children) {
node = xmlNewDocNode(node->doc, NULL, (char *) node->children, node->name);
} else {
node = xmlNewDocNode(node->doc, NULL, "xmlns", node->name);
}
node->type = XML_NAMESPACE_DECL;
node->parent = nsparent;
node->ns = curns;
} else {
node = xmlDocCopyNodeList(domintern->document->ptr, node);
}
//.........这里部分代码省略.........
示例2: dom_xpath_ext_function_php
static void dom_xpath_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs, int type) /* {{{ */
{
zval **args;
zval *retval;
int result, i, ret;
int error = 0;
zend_fcall_info fci;
zval handler;
xmlXPathObjectPtr obj;
char *str;
char *callable = NULL;
dom_xpath_object *intern;
TSRMLS_FETCH();
if (! zend_is_executing(TSRMLS_C)) {
xmlGenericError(xmlGenericErrorContext,
"xmlExtFunctionTest: Function called from outside of PHP\n");
error = 1;
} else {
intern = (dom_xpath_object *) ctxt->context->userData;
if (intern == NULL) {
xmlGenericError(xmlGenericErrorContext,
"xmlExtFunctionTest: failed to get the internal object\n");
error = 1;
}
else if (intern->registerPhpFunctions == 0) {
xmlGenericError(xmlGenericErrorContext,
"xmlExtFunctionTest: PHP Object did not register PHP functions\n");
error = 1;
}
}
if (error == 1) {
for (i = nargs - 1; i >= 0; i--) {
obj = valuePop(ctxt);
xmlXPathFreeObject(obj);
}
return;
}
fci.param_count = nargs - 1;
if (fci.param_count > 0) {
fci.params = safe_emalloc(fci.param_count, sizeof(zval**), 0);
args = safe_emalloc(fci.param_count, sizeof(zval *), 0);
}
/* Reverse order to pop values off ctxt stack */
for (i = nargs - 2; i >= 0; i--) {
obj = valuePop(ctxt);
MAKE_STD_ZVAL(args[i]);
switch (obj->type) {
case XPATH_STRING:
ZVAL_STRING(args[i], (char *)obj->stringval, 1);
break;
case XPATH_BOOLEAN:
ZVAL_BOOL(args[i], obj->boolval);
break;
case XPATH_NUMBER:
ZVAL_DOUBLE(args[i], obj->floatval);
break;
case XPATH_NODESET:
if (type == 1) {
str = (char *)xmlXPathCastToString(obj);
ZVAL_STRING(args[i], str, 1);
xmlFree(str);
} else if (type == 2) {
int j;
array_init(args[i]);
if (obj->nodesetval && obj->nodesetval->nodeNr > 0) {
for (j = 0; j < obj->nodesetval->nodeNr; j++) {
xmlNodePtr node = obj->nodesetval->nodeTab[j];
zval *child;
MAKE_STD_ZVAL(child);
/* not sure, if we need this... it's copied from xpath.c */
if (node->type == XML_NAMESPACE_DECL) {
xmlNsPtr curns;
xmlNodePtr nsparent;
nsparent = node->_private;
curns = xmlNewNs(NULL, node->name, NULL);
if (node->children) {
curns->prefix = xmlStrdup((xmlChar *) node->children);
}
if (node->children) {
node = xmlNewDocNode(node->doc, NULL, (xmlChar *) node->children, node->name);
} else {
node = xmlNewDocNode(node->doc, NULL, (xmlChar *) "xmlns", node->name);
}
node->type = XML_NAMESPACE_DECL;
node->parent = nsparent;
node->ns = curns;
}
child = php_dom_create_object(node, &ret, NULL, child, (dom_object *)intern TSRMLS_CC);
add_next_index_zval(args[i], child);
}
}
}
break;
default:
ZVAL_STRING(args[i], (char *)xmlXPathCastToString(obj), 1);
//.........这里部分代码省略.........
示例3: cx_handle_instance_xpath
static int cx_handle_instance_xpath(xmlXPathContextPtr xpath_ctx, /* {{{ */
cx_xpath_t *xpath, value_list_t *vl,
_Bool is_table) {
xmlXPathObjectPtr instance_node_obj = NULL;
xmlNodeSetPtr instance_node = NULL;
memset(vl->type_instance, 0, sizeof(vl->type_instance));
/* If the base xpath returns more than one block, the result is assumed to be
* a table. The `Instance' option is not optional in this case. Check for the
* condition and inform the user. */
if (is_table && (xpath->instance == NULL)) {
WARNING("curl_xml plugin: "
"Base-XPath %s is a table (more than one result was returned), "
"but no instance-XPath has been defined.",
xpath->path);
return -1;
}
/* instance has to be an xpath expression */
if (xpath->instance != NULL) {
int tmp_size;
instance_node_obj = cx_evaluate_xpath(xpath_ctx, BAD_CAST xpath->instance);
if (instance_node_obj == NULL)
return -1; /* error is logged already */
instance_node = instance_node_obj->nodesetval;
tmp_size = (instance_node) ? instance_node->nodeNr : 0;
if (tmp_size <= 0) {
WARNING(
"curl_xml plugin: "
"relative xpath expression for 'InstanceFrom' \"%s\" doesn't match "
"any of the nodes. Skipping the node.",
xpath->instance);
xmlXPathFreeObject(instance_node_obj);
return -1;
}
if (tmp_size > 1) {
WARNING("curl_xml plugin: "
"relative xpath expression for 'InstanceFrom' \"%s\" is expected "
"to return only one text node. Skipping the node.",
xpath->instance);
xmlXPathFreeObject(instance_node_obj);
return -1;
}
/* ignoring the element if other than textnode/attribute */
if (cx_if_not_text_node(instance_node->nodeTab[0])) {
WARNING("curl_xml plugin: "
"relative xpath expression \"%s\" is expected to return only "
"text node "
"which is not the case. Skipping the node.",
xpath->instance);
xmlXPathFreeObject(instance_node_obj);
return -1;
}
} /* if (xpath->instance != NULL) */
if (xpath->instance_prefix != NULL) {
if (instance_node != NULL) {
char *node_value = (char *)xmlNodeGetContent(instance_node->nodeTab[0]);
snprintf(vl->type_instance, sizeof(vl->type_instance), "%s%s",
xpath->instance_prefix, node_value);
sfree(node_value);
} else
sstrncpy(vl->type_instance, xpath->instance_prefix,
sizeof(vl->type_instance));
} else {
/* If instance_prefix and instance_node are NULL, then
* don't set the type_instance */
if (instance_node != NULL) {
char *node_value = (char *)xmlNodeGetContent(instance_node->nodeTab[0]);
sstrncpy(vl->type_instance, node_value, sizeof(vl->type_instance));
sfree(node_value);
}
}
/* Free `instance_node_obj' this late, because `instance_node' points to
* somewhere inside this structure. */
xmlXPathFreeObject(instance_node_obj);
return 0;
} /* }}} int cx_handle_instance_xpath */
示例4: parseLibFile
int parseLibFile(const std::wstring& _wstXML, MacroInfoList& info, std::wstring& libname)
{
info.clear();
char* pstFile = wide_string_to_UTF8(_wstXML.data());
if (FileExist(pstFile) == FALSE)
{
FREE(pstFile);
return 1;
}
std::string s(_wstXML.begin(),_wstXML.end());
std::ifstream file(s);
if (file)
{
const std::string XMLDecl("<?xml");
std::string readXMLDecl;
readXMLDecl.resize(XMLDecl.length(),' ');//reserve space
file.read(&*readXMLDecl.begin(),XMLDecl.length());
if (XMLDecl != readXMLDecl)
{
return 4;
}
}
char *encoding = GetXmlFileEncoding(pstFile);
/* Don't care about line return / empty line */
xmlKeepBlanksDefault(0);
/* check if the XML file has been encoded with utf8 (unicode) or not */
if (stricmp("utf-8", encoding))
{
FREE(pstFile);
free(encoding);
return 3;
}
xmlDocPtr doc;
xmlXPathContextPtr xpathCtxt = NULL;
xmlXPathObjectPtr xpathObj = NULL;
wchar_t* pstName = NULL;
wchar_t* pstLibName = NULL;
wchar_t* pstFileName = NULL;
wchar_t* pstMd5 = NULL;
free(encoding);
doc = xmlParseFile(pstFile);
if (doc == NULL)
{
FREE(pstFile);
return 3;
}
FREE(pstFile);
xpathCtxt = xmlXPathNewContext(doc);
xpathObj = xmlXPathEval((const xmlChar*)"//scilablib", xpathCtxt);
if (xpathObj && xpathObj->nodesetval->nodeMax)
{
xmlAttrPtr attrib = xpathObj->nodesetval->nodeTab[0]->properties;
if (xmlStrEqual(attrib->name, (const xmlChar*)"name"))
{
/* we found the tag name */
const char *str = (const char*)attrib->children->content;
pstLibName = to_wide_string(str);
libname = pstLibName;
FREE(pstLibName);
xmlXPathFreeObject(xpathObj);
}
else
{
if (xpathCtxt)
{
xmlXPathFreeContext(xpathCtxt);
}
xmlXPathFreeObject(xpathObj);
return 1;
}
}
xpathObj = xmlXPathEval((const xmlChar*)"//scilablib/macro", xpathCtxt);
if (xpathObj && xpathObj->nodesetval->nodeMax)
{
/* the Xpath has been understood and there are node */
for (int i = 0; i < xpathObj->nodesetval->nodeNr; i++)
{
xmlAttrPtr attrib = xpathObj->nodesetval->nodeTab[i]->properties;
/* Get the properties of <module> */
while (attrib != NULL)
{
/* loop until when have read all the attributes */
if (xmlStrEqual(attrib->name, (const xmlChar*)"name"))
{
/* we found the tag name */
const char *str = (const char*)attrib->children->content;
pstName = to_wide_string(str);
}
else if (xmlStrEqual(attrib->name, (const xmlChar*)"file"))
//.........这里部分代码省略.........
示例5: xmlXIncludeLoadDoc
//.........这里部分代码省略.........
xmlNodeSetPtr set;
if (doc == NULL) {
xptrctxt = xmlXPtrNewContext(ctxt->doc, ctxt->incTab[nr], NULL);
} else {
xptrctxt = xmlXPtrNewContext(doc, NULL, NULL);
}
if (xptrctxt == NULL) {
xmlGenericError(xmlGenericErrorContext,
"XInclude: could create XPointer context\n");
xmlFree(URL);
xmlFree(fragment);
return;
}
xptr = xmlXPtrEval(fragment, xptrctxt);
if (xptr == NULL) {
xmlGenericError(xmlGenericErrorContext,
"XInclude: XPointer evaluation failed: #%s\n",
fragment);
xmlXPathFreeContext(xptrctxt);
xmlFree(URL);
xmlFree(fragment);
return;
}
switch (xptr->type) {
case XPATH_UNDEFINED:
case XPATH_BOOLEAN:
case XPATH_NUMBER:
case XPATH_STRING:
case XPATH_POINT:
case XPATH_USERS:
case XPATH_XSLT_TREE:
xmlGenericError(xmlGenericErrorContext,
"XInclude: XPointer is not a range: #%s\n",
fragment);
xmlXPathFreeContext(xptrctxt);
xmlFree(URL);
xmlFree(fragment);
return;
case XPATH_NODESET:
case XPATH_RANGE:
case XPATH_LOCATIONSET:
break;
}
set = xptr->nodesetval;
if (set != NULL) {
for (i = 0; i < set->nodeNr; i++) {
if (set->nodeTab[i] == NULL)
continue;
switch (set->nodeTab[i]->type) {
case XML_TEXT_NODE:
case XML_CDATA_SECTION_NODE:
case XML_ELEMENT_NODE:
case XML_ENTITY_REF_NODE:
case XML_ENTITY_NODE:
case XML_PI_NODE:
case XML_COMMENT_NODE:
case XML_DOCUMENT_NODE:
case XML_HTML_DOCUMENT_NODE:
#ifdef LIBXML_DOCB_ENABLED
case XML_DOCB_DOCUMENT_NODE:
#endif
continue;
case XML_ATTRIBUTE_NODE:
xmlGenericError(xmlGenericErrorContext,
"XInclude: XPointer selects an attribute: #%s\n",
fragment);
set->nodeTab[i] = NULL;
continue;
case XML_NAMESPACE_DECL:
xmlGenericError(xmlGenericErrorContext,
"XInclude: XPointer selects a namespace: #%s\n",
fragment);
set->nodeTab[i] = NULL;
continue;
case XML_DOCUMENT_TYPE_NODE:
case XML_DOCUMENT_FRAG_NODE:
case XML_NOTATION_NODE:
case XML_DTD_NODE:
case XML_ELEMENT_DECL:
case XML_ATTRIBUTE_DECL:
case XML_ENTITY_DECL:
case XML_XINCLUDE_START:
case XML_XINCLUDE_END:
xmlGenericError(xmlGenericErrorContext,
"XInclude: XPointer selects unexpected nodes: #%s\n",
fragment);
set->nodeTab[i] = NULL;
set->nodeTab[i] = NULL;
continue; /* for */
}
}
}
ctxt->repTab[nr] = xmlXIncludeCopyXPointer(ctxt, ctxt->doc, doc, xptr);
xmlXPathFreeObject(xptr);
xmlXPathFreeContext(xptrctxt);
xmlFree(fragment);
}
xmlFree(URL);
}
示例6: linphone_friend_list_parse_multipart_related_body
static void linphone_friend_list_parse_multipart_related_body(LinphoneFriendList *list, const LinphoneContent *body, const char *first_part_body) {
xmlparsing_context_t *xml_ctx = linphone_xmlparsing_context_new();
xmlSetGenericErrorFunc(xml_ctx, linphone_xmlparsing_genericxml_error);
xml_ctx->doc = xmlReadDoc((const unsigned char*)first_part_body, 0, NULL, 0);
if (xml_ctx->doc != NULL) {
char xpath_str[MAX_XPATH_LENGTH];
LinphoneFriend *lf;
LinphoneContent *presence_part;
xmlXPathObjectPtr resource_object;
const char *version_str = NULL;
const char *full_state_str = NULL;
const char *uri = NULL;
bool_t full_state = FALSE;
int version;
int i;
if (linphone_create_xml_xpath_context(xml_ctx) < 0) goto end;
xmlXPathRegisterNs(xml_ctx->xpath_ctx, (const xmlChar *)"rlmi", (const xmlChar *)"urn:ietf:params:xml:ns:rlmi");
version_str = linphone_get_xml_attribute_text_content(xml_ctx, "/rlmi:list", "version");
if (version_str == NULL) {
ms_warning("rlmi+xml: No version attribute in list");
goto end;
}
version = atoi(version_str);
linphone_free_xml_text_content(version_str);
if (version < list->expected_notification_version) {
ms_warning("rlmi+xml: Discarding received notification with version %d because %d was expected", version, list->expected_notification_version);
linphone_friend_list_update_subscriptions(list, NULL, FALSE); /* Refresh subscription to get new full state notify. */
goto end;
}
full_state_str = linphone_get_xml_attribute_text_content(xml_ctx, "/rlmi:list", "fullState");
if (full_state_str == NULL) {
ms_warning("rlmi+xml: No fullState attribute in list");
goto end;
}
if ((strcmp(full_state_str, "true") == 0) || (strcmp(full_state_str, "1") == 0)) {
bctbx_list_t *l = list->friends;
for (; l != NULL; l = l->next) {
lf = (LinphoneFriend *)l->data;
linphone_friend_set_presence_model(lf, NULL);
}
full_state = TRUE;
}
linphone_free_xml_text_content(full_state_str);
if ((list->expected_notification_version == 0) && (full_state == FALSE)) {
ms_warning("rlmi+xml: Notification with version 0 is not full state, this is not valid");
goto end;
}
list->expected_notification_version = version + 1;
resource_object = linphone_get_xml_xpath_object_for_node_list(xml_ctx, "/rlmi:list/rlmi:resource");
if ((resource_object != NULL) && (resource_object->nodesetval != NULL)) {
for (i = 1; i <= resource_object->nodesetval->nodeNr; i++) {
snprintf(xpath_str, sizeof(xpath_str), "/rlmi:list/rlmi:resource[%i]/@uri", i);
uri = linphone_get_xml_text_content(xml_ctx, xpath_str);
if (uri == NULL) continue;
lf = linphone_friend_list_find_friend_by_uri(list, uri);
if (lf != NULL) {
const char *state = NULL;
snprintf(xpath_str, sizeof(xpath_str),"/rlmi:list/rlmi:resource[%i]/rlmi:instance/@state", i);
state = linphone_get_xml_text_content(xml_ctx, xpath_str);
if ((state != NULL) && (strcmp(state, "active") == 0)) {
const char *cid = NULL;
snprintf(xpath_str, sizeof(xpath_str),"/rlmi:list/rlmi:resource[%i]/rlmi:instance/@cid", i);
cid = linphone_get_xml_text_content(xml_ctx, xpath_str);
if (cid != NULL) {
presence_part = linphone_content_find_part_by_header(body, "Content-Id", cid);
if (presence_part == NULL) {
ms_warning("rlmi+xml: Cannot find part with Content-Id: %s", cid);
} else {
SalPresenceModel *presence = NULL;
linphone_notify_parse_presence(linphone_content_get_type(presence_part), linphone_content_get_subtype(presence_part), linphone_content_get_string_buffer(presence_part), &presence);
if (presence != NULL) {
lf->presence_received = TRUE;
linphone_friend_set_presence_model(lf, (LinphonePresenceModel *)presence);
if (full_state == FALSE) {
linphone_core_notify_notify_presence_received(list->lc, lf);
}
}
linphone_content_unref(presence_part);
}
}
if (cid != NULL) linphone_free_xml_text_content(cid);
}
if (state != NULL) linphone_free_xml_text_content(state);
lf->subscribe_active = TRUE;
}
linphone_free_xml_text_content(uri);
}
}
if (resource_object != NULL) xmlXPathFreeObject(resource_object);
if (full_state == TRUE) {
bctbx_list_t *l = list->friends;
for (; l != NULL; l = l->next) {
lf = (LinphoneFriend *)l->data;
if (linphone_friend_is_presence_received(lf) == TRUE) {
linphone_core_notify_notify_presence_received(list->lc, lf);
//.........这里部分代码省略.........
示例7: refresh_lists
//.........这里部分代码省略.........
goto cont;
}
/* Get a list of devices for this domain. */
xml = virDomainGetXMLDesc (dom, 0);
if (!xml) {
VIRT_ERROR (conn, "virDomainGetXMLDesc");
goto cont;
}
/* Yuck, XML. Parse out the devices. */
xml_doc = xmlReadDoc ((xmlChar *) xml, NULL, NULL, XML_PARSE_NONET);
if (xml_doc == NULL) {
VIRT_ERROR (conn, "xmlReadDoc");
goto cont;
}
xpath_ctx = xmlXPathNewContext (xml_doc);
/* Block devices. */
xpath_obj = xmlXPathEval
((xmlChar *) "/domain/devices/disk/target[@dev]",
xpath_ctx);
if (xpath_obj == NULL || xpath_obj->type != XPATH_NODESET ||
xpath_obj->nodesetval == NULL)
goto cont;
for (j = 0; j < xpath_obj->nodesetval->nodeNr; ++j) {
xmlNodePtr node;
char *path = NULL;
node = xpath_obj->nodesetval->nodeTab[j];
if (!node) continue;
path = (char *) xmlGetProp (node, (xmlChar *) "dev");
if (!path) continue;
if (il_block_devices &&
ignore_device_match (il_block_devices, name, path) != 0)
goto cont2;
add_block_device (dom, path);
cont2:
if (path) xmlFree (path);
}
xmlXPathFreeObject (xpath_obj);
/* Network interfaces. */
xpath_obj = xmlXPathEval
((xmlChar *) "/domain/devices/interface[target[@dev]]",
xpath_ctx);
if (xpath_obj == NULL || xpath_obj->type != XPATH_NODESET ||
xpath_obj->nodesetval == NULL)
goto cont;
xmlNodeSetPtr xml_interfaces = xpath_obj->nodesetval;
for (j = 0; j < xml_interfaces->nodeNr; ++j) {
char *path = NULL;
char *address = NULL;
xmlNodePtr xml_interface;
xml_interface = xml_interfaces->nodeTab[j];
if (!xml_interface) continue;
xmlNodePtr child = NULL;
for (child = xml_interface->children; child; child = child->next) {
if (child->type != XML_ELEMENT_NODE) continue;
if (xmlStrEqual(child->name, (const xmlChar *) "target")) {
path = (char *) xmlGetProp (child, (const xmlChar *) "dev");
if (!path) continue;
} else if (xmlStrEqual(child->name, (const xmlChar *) "mac")) {
address = (char *) xmlGetProp (child, (const xmlChar *) "address");
if (!address) continue;
}
}
if (il_interface_devices &&
(ignore_device_match (il_interface_devices, name, path) != 0 ||
ignore_device_match (il_interface_devices, name, address) != 0))
goto cont3;
add_interface_device (dom, path, address);
cont3:
if (path) xmlFree (path);
if (address) xmlFree (address);
}
cont:
if (xpath_obj) xmlXPathFreeObject (xpath_obj);
if (xpath_ctx) xmlXPathFreeContext (xpath_ctx);
if (xml_doc) xmlFreeDoc (xml_doc);
sfree (xml);
}
sfree (domids);
}
return 0;
}
示例8: xcaps_xpath_get
//.........这里部分代码省略.........
(const xmlChar*)xpaths->s, xpathCtx);
if(xpathObj == NULL)
{
LM_ERR("unable to evaluate xpath expression [%s]\n", xpaths->s);
goto error;
}
nodes = xpathObj->nodesetval;
if(nodes==NULL)
{
outbuf->len = 0;
outbuf->s[outbuf->len] = '\0';
goto done;
}
size = nodes->nodeNr;
p = outbuf->s;
end = outbuf->s + outbuf->len;
for(i = 0; i < size; ++i)
{
if(nodes->nodeTab[i]==NULL)
continue;
if(i!=0)
{
if(p>=end)
{
LM_ERR("output buffer overflow\n");
goto error;
}
*p = ',';
p++;
}
if(nodes->nodeTab[i]->type == XML_ATTRIBUTE_NODE)
{
keyword = xmlNodeListGetString(doc,
nodes->nodeTab[i]->children, 0);
if(keyword != NULL)
{
pos = p + strlen((char*)keyword);
if(pos>=end)
{
LM_ERR("output buffer overflow\n");
goto error;
}
strcpy(p, (char*)keyword);
p = pos;
xmlFree(keyword);
keyword = NULL;
}
} else {
if(nodes->nodeTab[i]->content!=NULL)
{
pos = p + strlen((char*)nodes->nodeTab[i]->content);
if(pos>=end)
{
LM_ERR("output buffer overflow\n");
goto error;
}
strcpy(p, (char*)nodes->nodeTab[i]->content);
p = pos;
} else {
psBuf = xmlBufferCreate();
if(psBuf != NULL && xmlNodeDump(psBuf, doc,
nodes->nodeTab[i], 0, 0)>0)
{
pos = p + strlen((char*)xmlBufferContent(psBuf));
if(pos>=end)
{
LM_ERR("output buffer overflow\n");
goto error;
}
strcpy(p, (char*)xmlBufferContent(psBuf));
p = pos;
}
if(psBuf != NULL) xmlBufferFree(psBuf);
psBuf = NULL;
}
}
}
outbuf->len = p - outbuf->s;
outbuf->s[outbuf->len] = '\0';
done:
if(xpathObj!=NULL) xmlXPathFreeObject(xpathObj);
if(xpathCtx!=NULL) xmlXPathFreeContext(xpathCtx);
if(doc!=NULL) xmlFreeDoc(doc);
xpathObj = NULL;
xpathCtx = NULL;
doc = NULL;
return 0;
error:
if(xpathObj!=NULL) xmlXPathFreeObject(xpathObj);
if(xpathCtx!=NULL) xmlXPathFreeContext(xpathCtx);
if(doc!=NULL) xmlFreeDoc(doc);
xpathObj = NULL;
xpathCtx = NULL;
doc = NULL;
outbuf->len = 0;
outbuf->s[outbuf->len] = '\0';
return -1;
}
示例9: xcaps_xpath_set
//.........这里部分代码省略.........
}
} else {
/* selection for xpath expression */
size = nodes->nodeNr;
if(val!=NULL)
value = (const xmlChar*)val->s;
/*
* NOTE: the nodes are processed in reverse order, i.e. reverse document
* order because xmlNodeSetContent can actually free up descendant
* of the node and such nodes may have been selected too ! Handling
* in reverse order ensure that descendant are accessed first, before
* they get removed. Mixing XPath and modifications on a tree must be
* done carefully !
*/
for(i = size - 1; i >= 0; i--) {
if(nodes->nodeTab[i]==NULL)
continue;
if(nodes->nodeTab[i]->type==XML_ELEMENT_NODE)
{
parent = nodes->nodeTab[i]->parent;
xmlUnlinkNode(nodes->nodeTab[i]);
if(val!=NULL && newnode!=NULL)
xmlAddChild(parent, xmlCopyNode(newnode->children, 1));
} else {
if(val!=NULL)
xmlNodeSetContent(nodes->nodeTab[i], value);
else
xmlNodeSetContent(nodes->nodeTab[i], (const xmlChar*)"");
}
/*
* All the elements returned by an XPath query are pointers to
* elements from the tree *except* namespace nodes where the XPath
* semantic is different from the implementation in libxml2 tree.
* As a result when a returned node set is freed when
* xmlXPathFreeObject() is called, that routine must check the
* element type. But node from the returned set may have been removed
* by xmlNodeSetContent() resulting in access to freed data.
* This can be exercised by running
* valgrind xpath2 test3.xml '//discarded' discarded
* There is 2 ways around it:
* - make a copy of the pointers to the nodes from the result set
* then call xmlXPathFreeObject() and then modify the nodes
* or
* - remove the reference to the modified nodes from the node set
* as they are processed, if they are not namespace nodes.
*/
if (nodes->nodeTab[i]->type != XML_NAMESPACE_DECL)
nodes->nodeTab[i] = NULL;
}
}
xmlDocDumpMemory(doc, &xmem, &size);
if(xmem==NULL)
{
LM_ERR("error printing output\n");
goto error;
}
if(size<=0)
{
LM_ERR("invalid output size\n");
xmlFree(xmem);
goto error;
}
outbuf->s = (char*)pkg_malloc(size+1);
if(outbuf->s==NULL)
{
LM_ERR("no pkg for output\n");
xmlFree(xmem);
goto error;
}
memcpy(outbuf->s, xmem, size);
outbuf->s[size] = '\0';
outbuf->len = size;
xmlFree(xmem);
done:
if(xpathObj!=NULL) xmlXPathFreeObject(xpathObj);
if(xpathCtx!=NULL) xmlXPathFreeContext(xpathCtx);
if(doc!=NULL) xmlFreeDoc(doc);
if(newnode!=NULL) xmlFreeDoc(newnode);
xpathObj = NULL;
xpathCtx = NULL;
doc = NULL;
return 0;
error:
if(xpathObj!=NULL) xmlXPathFreeObject(xpathObj);
if(xpathCtx!=NULL) xmlXPathFreeContext(xpathCtx);
if(doc!=NULL) xmlFreeDoc(doc);
if(newnode!=NULL) xmlFreeDoc(newnode);
xpathObj = NULL;
xpathCtx = NULL;
doc = NULL;
outbuf->s = NULL;
outbuf->len = 0;
return -1;
}
示例10: xmlSecXPathDataExecute
static xmlSecNodeSetPtr
xmlSecXPathDataExecute(xmlSecXPathDataPtr data, xmlDocPtr doc, xmlNodePtr hereNode) {
xmlXPathObjectPtr xpathObj = NULL;
xmlSecNodeSetPtr nodes;
xmlSecAssert2(data != NULL, NULL);
xmlSecAssert2(data->expr != NULL, NULL);
xmlSecAssert2(data->ctx != NULL, NULL);
xmlSecAssert2(doc != NULL, NULL);
xmlSecAssert2(hereNode != NULL, NULL);
/* do not forget to set the doc */
data->ctx->doc = doc;
/* here function works only on the same document */
if(hereNode->doc == doc) {
xmlXPathRegisterFunc(data->ctx, (xmlChar *)"here", xmlSecXPathHereFunction);
data->ctx->here = hereNode;
data->ctx->xptr = 1;
}
/* execute xpath or xpointer expression */
switch(data->type) {
case xmlSecXPathDataTypeXPath:
case xmlSecXPathDataTypeXPath2:
xpathObj = xmlXPathEvalExpression(data->expr, data->ctx);
if(xpathObj == NULL) {
xmlSecError(XMLSEC_ERRORS_HERE,
NULL,
"xmlXPathEvalExpression",
XMLSEC_ERRORS_R_XML_FAILED,
"expr=%s",
xmlSecErrorsSafeString(data->expr));
return(NULL);
}
break;
case xmlSecXPathDataTypeXPointer:
xpathObj = xmlXPtrEval(data->expr, data->ctx);
if(xpathObj == NULL) {
xmlSecError(XMLSEC_ERRORS_HERE,
NULL,
"xmlXPtrEval",
XMLSEC_ERRORS_R_XML_FAILED,
"expr=%s",
xmlSecErrorsSafeString(data->expr));
return(NULL);
}
break;
}
/* sometime LibXML2 returns an empty nodeset or just NULL, we want
to reserve NULL for our own purposes so we simply create an empty
node set here */
if(xpathObj->nodesetval == NULL) {
xpathObj->nodesetval = xmlXPathNodeSetCreate(NULL);
if(xpathObj->nodesetval == NULL) {
xmlXPathFreeObject(xpathObj);
xmlSecError(XMLSEC_ERRORS_HERE,
NULL,
"xmlXPathNodeSetCreate",
XMLSEC_ERRORS_R_XML_FAILED,
"expr=%s",
xmlSecErrorsSafeString(data->expr));
return(NULL);
}
}
nodes = xmlSecNodeSetCreate(doc, xpathObj->nodesetval, data->nodeSetType);
if(nodes == NULL) {
xmlSecError(XMLSEC_ERRORS_HERE,
NULL,
"xmlSecNodeSetCreate",
XMLSEC_ERRORS_R_XMLSEC_FAILED,
"type=%d", data->nodeSetType);
xmlXPathFreeObject(xpathObj);
return(NULL);
}
xpathObj->nodesetval = NULL;
xmlXPathFreeObject(xpathObj);
return(nodes);
}
示例11: xml_value
//.........这里部分代码省略.........
/*
* sanity check on parameters
*/
if( xmlBuf == NULL ) {
*iret = -1;
return;
}
bufSize = strlen( xmlBuf );
if( bufSize <= 0 ) {
*iret = -2;
return;
}
/*
* Init libxml
*/
xmlInitParser();
/*
* Make the xpath expression
*/
xml_makeXpathExpr( elementName, elementNumber, childName,
childNumber, NULL, &xpathExpr, &ier );
if( ier < 0 ) {
*iret = -3;
G_FREE( xpathExpr, xmlChar );
return;
}
else if( ier > 0 ) {
*iret = 1;
}
xml_executeXpathExpr( xmlBuf, bufSize, xpathExpr, &doc, &xpathObj, &ier );
if( ier != 0 ) {
*iret = -15;
}
else {
nodes = xpathObj->nodesetval;
if( nodes ) {
size = nodes->nodeNr;
}
/*
* Size indicates the number of nodes returned from the XPath
* expression. This should be 1 and only 1; both 0 and > 1 are
* errors. 0 means the XPath expression didn't match anything,
* and > 1 means it matched too many things and we can't identify
* a unique value to return.
*/
if( size <= 0 ) {
*iret = -9;
}
if( size > 1 ) {
*iret = -16;
}
}
if( *iret >= 0 ) {
/*
* Return the content of the node. This must be an XML_TEXT_NODE and
* it must have non-NULL content. Any other condition is an error.
*/
curNode = nodes->nodeTab[0];
if( curNode->type == XML_ELEMENT_NODE ) {
curNode= curNode->children;
}
if( ( curNode->type == XML_TEXT_NODE ) && curNode->content ) {
*value = malloc( (strlen( (char *)(curNode->content) ) + 1) *
sizeof( char ));
strcpy( *value, (char *)curNode->content );
}
else {
*iret = -9;
}
}
/*
* Shutdown libxml and clean up
*/
xmlCleanupParser();
G_FREE( xpathExpr, xmlChar );
xmlXPathFreeObject( xpathObj );
xmlFreeDoc( doc );
return;
}
示例12: mDebug
//.........这里部分代码省略.........
xmlFreeDoc(indexDoc);
mError("ппц...");
return -1;
}
else mDebug("indexDoc read successfully");
indexRootNode = xmlDocGetRootElement(indexDoc);
if (indexRootNode == NULL) {
mError(_("Failed to get index"));
xmlFreeDoc(indexDoc);
}
else mDebug("indexRootNode read successfully");
if (xmlStrcmp(indexRootNode->name, (const xmlChar *) "repository") ) {
mError(_("Invalid index file"));
xmlFreeDoc(indexDoc);
}
else mDebug("Found valid repository index");
xmlXPathContextPtr xContext;
xmlXPathObjectPtr xResult;
xContext = xmlXPathNewContext(indexDoc);
if (xContext == NULL) {
mError("ппц");
}
xResult = xmlXPathEvalExpression((const xmlChar *)"/repository/package", xContext);
if (xResult == NULL) {
mError("XPath expression error");
}
if (xmlXPathNodeSetIsEmpty(xResult->nodesetval)) {
xmlXPathFreeObject(xResult);
printf(_("[%s] ... Nothing found\n"), server_url.c_str());
//mError("No packages found");
return 0;
}
xmlNodeSetPtr xNodeSet;
int xi;
actionBus.setActionProgress(ACTIONID_DBUPDATE, 0);
xNodeSet = xResult->nodesetval;
xmlXPathFreeContext(xContext);
actionBus.setActionProgressMaximum(ACTIONID_DBUPDATE, xNodeSet->nodeNr);
if (xNodeSet->nodeNr==0) printf("[%s] ... Nothing found", server_url.c_str());
for (xi = 0; xi < xNodeSet->nodeNr; xi++) {
printf("[%s] ... Importing received data: %d/%d\r",server_url.c_str(), xi+1, xNodeSet->nodeNr);
actionBus.setActionProgress(ACTIONID_DBUPDATE, xi);
mDebug("Processing " + IntToStr(xi) + " node");
if (actionBus._abortActions) {
actionBus._abortComplete = true;
actionBus.setActionState(ACTIONID_DBUPDATE, ITEMSTATE_ABORTED);
return MPKGERROR_ABORTED;
}
actionBus.setActionProgress(ACTIONID_DBUPDATE, xi);
pkg->clear();
mDebug("Calling xml2Package");
if (xml2package(xNodeSet->nodeTab[xi], pkg)<0) {
mError("Failed to parse");
示例13: libxml_xmlXPathObjectPtrWrap
//.........这里部分代码省略.........
PyTuple_SetItem(tuple, 1, indexIntoNode);
ret = tuple;
break;
}
case XPATH_RANGE:
{
unsigned short bCollapsedRange;
bCollapsedRange = ( (obj->user2 == NULL) ||
((obj->user2 == obj->user) && (obj->index == obj->index2)) );
if ( bCollapsedRange ) {
PyObject *node;
PyObject *indexIntoNode;
PyObject *tuple;
PyObject *list;
list = PyList_New(1);
node = libxml_xmlNodePtrWrap(obj->user);
indexIntoNode = PY_IMPORT_INT((long) obj->index);
tuple = PyTuple_New(2);
PyTuple_SetItem(tuple, 0, node);
PyTuple_SetItem(tuple, 1, indexIntoNode);
PyList_SetItem(list, 0, tuple);
ret = list;
} else {
PyObject *node;
PyObject *indexIntoNode;
PyObject *tuple;
PyObject *list;
list = PyList_New(2);
node = libxml_xmlNodePtrWrap(obj->user);
indexIntoNode = PY_IMPORT_INT((long) obj->index);
tuple = PyTuple_New(2);
PyTuple_SetItem(tuple, 0, node);
PyTuple_SetItem(tuple, 1, indexIntoNode);
PyList_SetItem(list, 0, tuple);
node = libxml_xmlNodePtrWrap(obj->user2);
indexIntoNode = PY_IMPORT_INT((long) obj->index2);
tuple = PyTuple_New(2);
PyTuple_SetItem(tuple, 0, node);
PyTuple_SetItem(tuple, 1, indexIntoNode);
PyList_SetItem(list, 1, tuple);
ret = list;
}
break;
}
case XPATH_LOCATIONSET:
{
xmlLocationSetPtr set;
set = obj->user;
if ( set && set->locNr > 0 ) {
int i;
PyObject *list;
list = PyList_New(set->locNr);
for (i=0; i<set->locNr; i++) {
xmlXPathObjectPtr setobj;
PyObject *pyobj;
setobj = set->locTab[i]; /*xmlXPathObjectPtr setobj*/
pyobj = libxml_xmlXPathObjectPtrWrap(setobj);
/* xmlXPathFreeObject(setobj) is called */
set->locTab[i] = NULL;
PyList_SetItem(list, i, pyobj);
}
set->locNr = 0;
ret = list;
} else {
Py_INCREF(Py_None);
ret = Py_None;
}
break;
}
default:
#ifdef DEBUG
printf("Unable to convert XPath object type %d\n", obj->type);
#endif
Py_INCREF(Py_None);
ret = Py_None;
}
xmlXPathFreeObject(obj);
return (ret);
}
示例14: read_scheda
char * read_scheda(char *baseUrl, xmlChar *url, char *epgdb_root)
{
static char buf[2048];
int i;
FILE *fd;
char cachefile[strlen(epgdb_root) + strlen((char*)url) + 2];
htmlDocPtr docScheda = NULL;
xmlXPathContextPtr contextScheda = NULL;
xmlXPathObjectPtr par = NULL;
xmlChar *urlScheda = NULL;
/* build cache filename */
buf[0]='\0';
strcpy(cachefile, epgdb_root);
cachefile[strlen(epgdb_root)] = '/';
for (i=0; i<strlen((char*)url); i++)
if (url[i] == '/' || url[i] == '\\' || url[i] == '?' || url[i] == '&' || url[i] == '=')
cachefile[i+strlen(epgdb_root)+1] = '_';
else
cachefile[i+strlen(epgdb_root)+1] = url[i];
cachefile[i+strlen(epgdb_root)+1] = '\0';
/* try to read from cache */
fd = fopen(cachefile, "r");
if (fd)
{
fread(buf, 2048, 1, fd);
fclose(fd);
return buf;
}
/* ok... no cache... download it! */
urlScheda = xmlBuildURI(url, (xmlChar *)baseUrl);
if (urlScheda != NULL )
{
docScheda = htmlReadFile((char *)urlScheda, NULL, HTML_PARSE_RECOVER|HTML_PARSE_NOERROR|HTML_PARSE_NOWARNING);
if (docScheda != NULL )
{
contextScheda = xmlXPathNewContext(docScheda);
if (contextScheda != NULL)
{
// Prende il primo paragrafo sotto la div con id="box"
par = xmlXPathEvalExpression((const xmlChar *)"//div[@id='box']/p[1]", contextScheda);
if (par != NULL && !xmlXPathNodeSetIsEmpty(par->nodesetval))
{
append_scheda(buf, par->nodesetval->nodeTab[0]->children, 0, 2048);
xmlXPathFreeObject(par);
}
xmlXPathFreeContext(contextScheda);
}
xmlFreeDoc(docScheda);
}
xmlFree(urlScheda);
}
/* save the cache */
if (strlen(buf) > 0)
{
fd = fopen(cachefile, "w");
if (fd)
{
fwrite(buf, strlen(buf)+1, 1, fd);
fclose(fd);
}
}
return buf;
}
示例15: xmlInitParser
bool Board::InitFromXMLFile(const char * fileName)
{
bool toReturn = false;
xmlDocPtr doc;
xmlXPathContextPtr xpathCtx;
xmlXPathObjectPtr xpathObj;
int ret;
// Init libxml
xmlInitParser();
LIBXML_TEST_VERSION
assert(fileName);
assert(XPathExpression);
// Load XML document
doc = xmlParseFile(fileName);
if (doc == NULL)
{
cout << "Error: unable to parse file " << fileName << endl;
return false;
}
// Create xpath evaluation context
xpathCtx = xmlXPathNewContext(doc);
if(xpathCtx == NULL)
{
cout << "Error: unable to create new XPath context" << endl;
xmlFreeDoc(doc);
return false;
}
// Evaluate xpath expression
xpathObj = xmlXPathEvalExpression(BAD_CAST XPathExpression, xpathCtx);
if(xpathObj == NULL)
{
cout << "Error: unable to evaluate xpath expression " << XPathExpression << endl;
xmlXPathFreeContext(xpathCtx);
xmlFreeDoc(doc);
return false;
}
// Process the nodes in the file
toReturn = ProcessNodes(xpathObj->nodesetval, stdout);
// Cleanup
xmlXPathFreeObject(xpathObj);
xmlXPathFreeContext(xpathCtx);
xmlFreeDoc(doc);
// Shutdown libxml
xmlCleanupParser();
// This is to debug memory for regression tests
xmlMemoryDump();
// Build the UI table with the squares we have
BuildTable();
return toReturn;
}