Exemplo n.º 1
0
int
xslDbgShellCat(xsltTransformContextPtr styleCtxt, xmlShellCtxtPtr ctxt,
               xmlChar * arg)
{
    xmlXPathObjectPtr list;
    int result = 0;
    static const char * QUIET_STR = "-q";
    bool silenceCtxtErrors = false;

    if ((arg == NULL) || (xmlStrLen(arg) == 0))
        arg = (xmlChar *) ".";

    /* Do we quietly ingore style context errors */
    if (strncasecmp((char*)arg, QUIET_STR, strlen(QUIET_STR))== 0){
      silenceCtxtErrors = true;	
      arg = arg + strlen(QUIET_STR);
      while (isspace(*arg)){
	arg++;
      }
    }

    if (!styleCtxt || !ctxt || !ctxt->node) {
	if (!(!xsldbgReachedFirstTemplate && silenceCtxtErrors)) 
        xsldbgGenericErrorFunc(i18n("Warning: Unable to print expression. No stylesheet was properly loaded.\n"));
        return 0;
    }

    if ((arg == NULL) || (xmlStrLen(arg) == 0))
        arg = (xmlChar *) ".";

    ctxt->pctxt->node = ctxt->node;
    if (!styleCtxt) {
        list = xmlXPathEval((xmlChar *) arg, ctxt->pctxt);
    } else {
        xmlNodePtr savenode = styleCtxt->xpathCtxt->node;

        ctxt->pctxt->node = ctxt->node;
        styleCtxt->xpathCtxt->node = ctxt->node;
        if (!xmlXPathNsLookup(styleCtxt->xpathCtxt, (xmlChar *) "xsl"))
            xmlXPathRegisterNs(styleCtxt->xpathCtxt, (xmlChar *) "xsl",
                               XSLT_NAMESPACE);
        list = xmlXPathEval((xmlChar *) arg, styleCtxt->xpathCtxt);
        styleCtxt->xpathCtxt->node = savenode;
    }
    if (list != NULL) {
        result = printXPathObject(list, arg);
        xmlXPathFreeObject(list);
    } else {
        xsldbgGenericErrorFunc(i18n("Error: XPath %1 results in an empty Node Set.\n").arg(xsldbgText(arg)));
    }
    ctxt->pctxt->node = NULL;
    return result;
}
Exemplo n.º 2
0
const char * config_get_value(const char * _xpath) {
    xmlXPathObjectPtr xmlobject = NULL;
    const xmlChar * xpath = BAD_CAST(_xpath);
    const xmlChar * value = NULL;
    
    
    /* Rquete XPath*/
    xmlobject = xmlXPathEval(xpath, config->context);

    if (!xmlobject)
        return NULL;
    
    if (xmlobject->type == XPATH_NODESET) { 
        if (xmlobject->nodesetval) { 
            /* nodeNr = nb nodes in struct nodesetval */ 
            if (xmlobject->nodesetval->nodeNr > 0) {
                xmlNodePtr n;
		
                n = xmlobject->nodesetval->nodeTab[0];
                if ((n->type == XML_TEXT_NODE) || 
                    (n->type == XML_CDATA_SECTION_NODE))
                    value = n->content;
            }
        }
    }
    
    xmlXPathFreeObject(xmlobject);
    
    return (char *)value;
}
Exemplo n.º 3
0
  XPathContext::NodeSet_t XPathContext::find_nodes(const std::string& xpath, const Node* context)
  {
	if (context != NULL)
	{
	   m_cobj->node = *const_cast<Node*>(context);
	}
	else
	{
	   m_cobj->node = NULL;
	}

    boost::shared_ptr<xmlXPathObject> result(
      xmlXPathEval(reinterpret_cast<const xmlChar*>(xpath.c_str()), m_cobj),
      xmlXPathFreeObject);

    if (result->type != XPATH_NODESET || result->nodesetval == NULL)
    {
      return NodeSet_t();
    }

    NodeSet_t result_nodes;
    result_nodes.reserve(result->nodesetval->nodeNr);
    for (int i = 0; i < result->nodesetval->nodeNr; ++i)
    {
      result_nodes.push_back(reinterpret_cast<Node*>(result->nodesetval->nodeTab[i]->_private));
    }

    return result_nodes;
  }
Exemplo n.º 4
0
   /// Return the text result (if any) of the xpath expression
   TIXML_STRING S_xpath_expr (const xmlDoc * Dp_ptr, const char * cp_xpath_expr)
   {
      xmlXPathObjectPtr XPOp_ptr;
      xmlXPathContextPtr XPCp_ptr;
      const xmlChar * Cp_ptr;
      TIXML_STRING S_out;
   
      S_out = "";
      if (Dp_ptr)
      {
         XPCp_ptr = xmlXPathNewContext ((xmlDoc *) Dp_ptr);
         if (XPCp_ptr)
         {
            // Evaluate 
            XPOp_ptr = xmlXPathEval ((const xmlChar *) cp_xpath_expr, XPCp_ptr);
            if (XPOp_ptr)
            {
               Cp_ptr = xmlXPathCastToString (XPOp_ptr);
               if (Cp_ptr)
                  S_out = (const char *) Cp_ptr;
               xmlXPathFreeObject (XPOp_ptr);
            }
         }
         if (XPCp_ptr)
            xmlXPathFreeContext (XPCp_ptr);
      }

      return S_out;
   }
Exemplo n.º 5
0
  Node* XPathContext::find(const std::string& xpath, const Node* context)
  {
    if (context)
    {
      m_cobj->node = *const_cast<Node*>(context);
    }
    else
    {
      m_cobj->node = *(reinterpret_cast<Document*>(m_cobj->doc->_private)->get_root_element());
    }

    boost::shared_ptr<xmlXPathObject> result(
      xmlXPathEval(reinterpret_cast<const xmlChar*>(xpath.c_str()), m_cobj),
      xmlXPathFreeObject);

    if (result->type != XPATH_NODESET)
    {
      return NULL;
    }

    if (result->nodesetval->nodeNr <= 0)
    {
      return NULL;
    }

    return reinterpret_cast<Node*>(result->nodesetval->nodeTab[0]->_private);
  }
Exemplo n.º 6
0
/**
 * virXPathNode:
 * @xpath: the XPath string to evaluate
 * @ctxt: an XPath context
 *
 * Convenience function to evaluate an XPath node set and returning
 * only one node, the first one in the set if any
 *
 * Returns a pointer to the node or NULL if the evaluation failed.
 */
xmlNodePtr
virXPathNode(const char *xpath,
             xmlXPathContextPtr ctxt)
{
    xmlXPathObjectPtr obj;
    xmlNodePtr relnode;
    xmlNodePtr ret;

    if ((ctxt == NULL) || (xpath == NULL)) {
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       "%s", _("Invalid parameter to virXPathNode()"));
        return NULL;
    }
    relnode = ctxt->node;
    obj = xmlXPathEval(BAD_CAST xpath, ctxt);
    ctxt->node = relnode;
    if ((obj == NULL) || (obj->type != XPATH_NODESET) ||
        (obj->nodesetval == NULL) || (obj->nodesetval->nodeNr <= 0) ||
        (obj->nodesetval->nodeTab == NULL)) {
        xmlXPathFreeObject(obj);
        return NULL;
    }

    ret = obj->nodesetval->nodeTab[0];
    xmlXPathFreeObject(obj);
    return ret;
}
Exemplo n.º 7
0
/**
 * virXPathNumber:
 * @xpath: the XPath string to evaluate
 * @ctxt: an XPath context
 * @value: the returned double value
 *
 * Convenience function to evaluate an XPath number
 *
 * Returns 0 in case of success in which case @value is set,
 *         or -1 if the evaluation failed.
 */
int
virXPathNumber(const char *xpath,
               xmlXPathContextPtr ctxt,
               double *value)
{
    xmlXPathObjectPtr obj;
    xmlNodePtr relnode;

    if ((ctxt == NULL) || (xpath == NULL) || (value == NULL)) {
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       "%s", _("Invalid parameter to virXPathNumber()"));
        return -1;
    }
    relnode = ctxt->node;
    obj = xmlXPathEval(BAD_CAST xpath, ctxt);
    ctxt->node = relnode;
    if ((obj == NULL) || (obj->type != XPATH_NUMBER) ||
        (isnan(obj->floatval))) {
        xmlXPathFreeObject(obj);
        return -1;
    }

    *value = obj->floatval;
    xmlXPathFreeObject(obj);
    return 0;
}
Exemplo n.º 8
0
static xmlChar *
makeCloneXML(const char *origxml, const char *newname)
{

    xmlDocPtr doc = NULL;
    xmlXPathContextPtr ctxt = NULL;
    xmlXPathObjectPtr obj = NULL;
    xmlChar *newxml = NULL;
    int size;

    doc = virXMLParseStringCtxt(origxml, _("(volume_definition)"), &ctxt);
    if (!doc)
        goto cleanup;

    obj = xmlXPathEval(BAD_CAST "/volume/name", ctxt);
    if (obj == NULL || obj->nodesetval == NULL ||
        obj->nodesetval->nodeTab == NULL)
        goto cleanup;

    xmlNodeSetContent(obj->nodesetval->nodeTab[0], (const xmlChar *)newname);
    xmlDocDumpMemory(doc, &newxml, &size);

cleanup:
    xmlXPathFreeObject(obj);
    xmlXPathFreeContext(ctxt);
    xmlFreeDoc(doc);
    return newxml;
}
Exemplo n.º 9
0
static void
exsltDynEvaluateFunction(xmlXPathParserContextPtr ctxt, int nargs) {
	xmlChar *str = NULL;
	xmlXPathObjectPtr ret = NULL;

	if (ctxt == NULL)
		return;
	if (nargs != 1) {
		xsltPrintErrorContext(xsltXPathGetTransformContext(ctxt), NULL, NULL);
        xsltGenericError(xsltGenericErrorContext,
			"dyn:evalute() : invalid number of args %d\n", nargs);
		ctxt->error = XPATH_INVALID_ARITY;
		return;
	}
	str = xmlXPathPopString(ctxt);
	
	if (!str||!xmlStrlen(str)) {
		if (str) xmlFree(str);
		valuePush(ctxt,xmlXPathNewNodeSet(NULL));
		return;
	}
	ret = xmlXPathEval(str,ctxt->context);
	if (ret)
		valuePush(ctxt,ret);
 	else {
		xsltGenericError(xsltGenericErrorContext,
			"dyn:evaluate() : unable to evaluate expression '%s'\n",str);
		valuePush(ctxt,xmlXPathNewNodeSet(NULL));
	}	
	xmlFree(str);
	return;
}
Exemplo n.º 10
0
static SeedValue
seed_xml_xpath_eval (SeedContext ctx,
		     SeedObject function,
		     SeedObject this_object,
		     gsize argument_count,
		     const SeedValue arguments[],
		     SeedException * exception)
{
  xmlXPathObjectPtr xpath_obj;
  xmlXPathContextPtr xpath_ctx;
  guchar *xpath;

  if (argument_count != 1)
    {
      seed_make_exception (ctx, exception,
			   "ArgumentError",
			   "xpathEval expected 1 argument, got %zd",
			   argument_count);
      return seed_make_null (ctx);
    }
  xpath_ctx = XML_XPATH_PRIV (this_object);

  xpath = (guchar *)seed_value_to_string (ctx, arguments[0], exception);
  xpath_obj = xmlXPathEval (xpath, xpath_ctx);
  g_free (xpath);

  return seed_make_object (ctx, xml_xpathobj_class, xpath_obj);
}
Exemplo n.º 11
0
/* If the tag ignor_autoconf if set, disable this feature by
 * setting the variables 
 * /proc/sys/net/ipv6/conf/all/autoconf
 * /proc/sys/net/ipv6/conf/all/accept_ra
 * /proc/sys/net/ipv6/conf/all/accept_ra_defrtr
 * /proc/sys/net/ipv6/conf/all/accept_ra_pinfo
 * /proc/sys/net/ipv6/conf/all/accept_redirects
 * to 0 to avoid the monitoring host to be attacked
 */
void autoconf()
{
	char *request ="/config_ndpmon/ignor_autoconf/text()";
	char  *flag;

	xmlXPathObjectPtr xmlobject = xmlXPathEval ((xmlChar*)request, xpctxt);
	
	if( xmlobject != NULL)
	{	
	    flag = (char *)xmlobject->nodesetval->nodeTab[0]->content;
	    ignor_autoconf = atoi(flag);

        /* Not working for BSD */
#ifdef _LINUX_
		/** note: it may be a good option to save values, and restore
		 * them when exiting
		 */
		write_proc("/proc/sys/net/ipv6/conf/all/autoconf",flag);
		write_proc("/proc/sys/net/ipv6/conf/all/accept_ra",flag);
		write_proc("/proc/sys/net/ipv6/conf/all/accept_ra_defrtr",flag);
		write_proc("/proc/sys/net/ipv6/conf/all/accept_ra_pinfo",flag);
		write_proc("/proc/sys/net/ipv6/conf/all/accept_redirects",flag);
	}
#endif
	xmlXPathFreeObject (xmlobject);
	return;
}
Exemplo n.º 12
0
int xml_config_for_each_obj(const xml_config_t *config, const char *pattern,
							xml_config_cb_t cb, void *arg1, void *arg2)
{
	xmlXPathObject *objs;
	xmlNode *node;
	int i, ret = 0;

	if (!(objs = xmlXPathEval(BAD_CAST pattern, config->xpc))) {
		return -1;
	}

	if (xmlXPathNodeSetIsEmpty(objs->nodesetval) == 0) {
		for (i = 0; i < xmlXPathNodeSetGetLength(objs->nodesetval); i++) {
			if (!(node = xmlXPathNodeSetItem(objs->nodesetval, i))) {
				continue;
			}

			if ((ret = cb(node, arg1, arg2)) < 0) {
				break;
			}
		}
	}

	xmlXPathFreeObject(objs);
	return ret;
}
Exemplo n.º 13
0
/**
 * virXPathULongLong:
 * @xpath: the XPath string to evaluate
 * @ctxt: an XPath context
 * @value: the returned long long value
 *
 * Convenience function to evaluate an XPath number
 *
 * Returns 0 in case of success in which case @value is set,
 *         or -1 if the XPath evaluation failed or -2 if the
 *         value doesn't have a long format.
 */
int
virXPathLongLong(const char *xpath,
                 xmlXPathContextPtr ctxt,
                 long long *value)
{
    xmlXPathObjectPtr obj;
    xmlNodePtr relnode;
    int ret = 0;

    if ((ctxt == NULL) || (xpath == NULL) || (value == NULL)) {
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       "%s", _("Invalid parameter to virXPathLongLong()"));
        return -1;
    }
    relnode = ctxt->node;
    obj = xmlXPathEval(BAD_CAST xpath, ctxt);
    ctxt->node = relnode;
    if ((obj != NULL) && (obj->type == XPATH_STRING) &&
        (obj->stringval != NULL) && (obj->stringval[0] != 0)) {
        if (virStrToLong_ll((char *) obj->stringval, NULL, 10, value) < 0)
            ret = -2;
    } else if ((obj != NULL) && (obj->type == XPATH_NUMBER) &&
               (!(isnan(obj->floatval)))) {
        *value = (long long) obj->floatval;
        if (*value != obj->floatval) {
            ret = -2;
        }
    } else {
        ret = -1;
    }

    xmlXPathFreeObject(obj);
    return ret;
}
Exemplo n.º 14
0
/**
 * virXPathString:
 * @xpath: the XPath string to evaluate
 * @ctxt: an XPath context
 *
 * Convenience function to evaluate an XPath string
 *
 * Returns a new string which must be deallocated by the caller or NULL
 *         if the evaluation failed.
 */
char *
virXPathString(const char *xpath,
               xmlXPathContextPtr ctxt)
{
    xmlXPathObjectPtr obj;
    xmlNodePtr relnode;
    char *ret;

    if ((ctxt == NULL) || (xpath == NULL)) {
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       "%s", _("Invalid parameter to virXPathString()"));
        return NULL;
    }
    relnode = ctxt->node;
    obj = xmlXPathEval(BAD_CAST xpath, ctxt);
    ctxt->node = relnode;
    if ((obj == NULL) || (obj->type != XPATH_STRING) ||
        (obj->stringval == NULL) || (obj->stringval[0] == 0)) {
        xmlXPathFreeObject(obj);
        return NULL;
    }
    ignore_value(VIR_STRDUP(ret, (char *) obj->stringval));
    xmlXPathFreeObject(obj);
    return ret;
}
Exemplo n.º 15
0
/* Get sha1file */
static void get_sha1(const char *ident)
{
	char *path = NULL;
	char xpath[SIZE];
	xmlXPathContextPtr xml_context = NULL;
	xmlXPathObjectPtr xmlobject;

	(void)crv_strncpy(xpath, "/database/file[@id='", sizeof(xpath));
	(void)crv_strncat(xpath, ident, sizeof(xpath));
	(void)crv_strncat(xpath, "']" , sizeof(xpath));
	path = crv_strdup(xpath);

	xmlXPathInit();
	xml_context = xmlXPathNewContext (xmldoc);
	xmlobject = xmlXPathEval (path, xml_context);
	crv_free(path);

	if ((xmlobject->type == XPATH_NODESET) )
  {
		int j;
		xmlNodePtr node;
		for (j = 0; j < xmlobject->nodesetval->nodeNr; j++)
		{
			node = xmlobject->nodesetval->nodeTab[j];
			xmlChar *Sha1 = xmlGetProp(node, "sha1");
			sha1 = crv_strdup(Sha1);
			xmlFree (Sha1);
		}
	}
	xmlXPathFreeObject (xmlobject);
  xmlXPathFreeContext (xml_context);	
}
Exemplo n.º 16
0
/**
 * virXPathBoolean:
 * @xpath: the XPath string to evaluate
 * @ctxt: an XPath context
 *
 * Convenience function to evaluate an XPath boolean
 *
 * Returns 0 if false, 1 if true, or -1 if the evaluation failed.
 */
int
virXPathBoolean(const char *xpath,
                xmlXPathContextPtr ctxt)
{
    xmlXPathObjectPtr obj;
    xmlNodePtr relnode;
    int ret;

    if ((ctxt == NULL) || (xpath == NULL)) {
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       "%s", _("Invalid parameter to virXPathBoolean()"));
        return -1;
    }
    relnode = ctxt->node;
    obj = xmlXPathEval(BAD_CAST xpath, ctxt);
    ctxt->node = relnode;
    if ((obj == NULL) || (obj->type != XPATH_BOOLEAN) ||
        (obj->boolval < 0) || (obj->boolval > 1)) {
        xmlXPathFreeObject(obj);
        return -1;
    }
    ret = obj->boolval;

    xmlXPathFreeObject(obj);
    return ret;
}
Exemplo n.º 17
0
/*
 * call-seq:
 *    context.find("xpath") -> true|false|number|string|XML::XPath::Object
 *
 * Executes the provided xpath function.  The result depends on the execution
 * of the xpath statement.  It may be true, false, a number, a string or 
 * a node set.
 */
static VALUE rxml_xpath_context_find(VALUE self, VALUE xpath_expr)
{
  xmlXPathContextPtr xctxt;
  xmlXPathObjectPtr xobject;
  xmlXPathCompExprPtr xcompexpr;

  Data_Get_Struct(self, xmlXPathContext, xctxt);

  if (TYPE(xpath_expr) == T_STRING)
  {
    VALUE expression = rb_check_string_type(xpath_expr);
    xobject = xmlXPathEval((xmlChar*) StringValueCStr(expression), xctxt);
  }
  else if (rb_obj_is_kind_of(xpath_expr, cXMLXPathExpression))
  {
    Data_Get_Struct(xpath_expr, xmlXPathCompExpr, xcompexpr);
    xobject = xmlXPathCompiledEval(xcompexpr, xctxt);
  }
  else
  {
    rb_raise(rb_eTypeError,
        "Argument should be an intance of a String or XPath::Expression");
  }

  return rxml_xpath_to_value(xctxt, xobject);
}
Exemplo n.º 18
0
/*
 * query from root
 * Note: need to be cautious that  the result from xmlXPathEval call is not freed within  this API
 * it is up to user to call xmlXPathFreeObject to free it
 */
xmlXPathObjectPtr wsNode::xpath(string xpath)
{
	xmlXPathContextPtr ctxt=xmlXPathNewContext(thisNode->doc);
	xmlXPathObjectPtr res=xmlXPathEval((xmlChar *)xpath.c_str(),ctxt);
	xmlXPathFreeContext(ctxt);
	check_xmlXPathObjectPtr(res, xpath);
	return res;
}
Exemplo n.º 19
0
static void
parse_forecast_xml (GWeatherInfo    *master_info,
                    SoupMessageBody *body)
{
    GWeatherInfoPrivate *priv;
    xmlDocPtr doc;
    xmlXPathContextPtr xpath_ctx;
    xmlXPathObjectPtr xpath_result;
    int i;

    priv = master_info->priv;

    doc = xmlParseMemory (body->data, body->length);
    if (!doc)
	return;

    xpath_ctx = xmlXPathNewContext (doc);
    xpath_result = xmlXPathEval (XC("/weatherdata/forecast/time"), xpath_ctx);

    if (!xpath_result || xpath_result->type != XPATH_NODESET)
	goto out;

    for (i = 0; i < xpath_result->nodesetval->nodeNr; i++) {
	xmlNodePtr node;
	GWeatherInfo *info;

	node = xpath_result->nodesetval->nodeTab[i];
	info = make_info_from_node (master_info, node);

	priv->forecast_list = g_slist_append (priv->forecast_list, info);
    }

    xmlXPathFreeObject (xpath_result);

    xpath_result = xmlXPathEval (XC("/weatherdata/credit/link"), xpath_ctx);
    if (!xpath_result || xpath_result->type != XPATH_NODESET)
	goto out;

    priv->forecast_attribution = g_strdup(_("Weather data from the <a href=\"http://openweathermap.org\">Open Weather Map project</a>"));

 out:
    if (xpath_result)
	xmlXPathFreeObject (xpath_result);
    xmlXPathFreeContext (xpath_ctx);
    xmlFreeDoc (doc);
}
Exemplo n.º 20
0
/** Parse counter measures configuration. */
void parse_countermeasures() {
    char
        *config_kill_illegitimate_router=NULL,
        *config_kill_wrong_prefix=NULL,
        *config_propagate_router_params=NULL,
        *config_indicate_ndpmon_presence=NULL,
        *request;
    xmlXPathObjectPtr xmlobject;

    request ="/config_ndpmon/countermeasures/kill_illegitimate_router/text()";
    xmlobject = xmlXPathEval ((xmlChar*)request, xpctxt);
    if (xmlobject->nodesetval!=NULL) {
        config_kill_illegitimate_router = (char*)xmlobject->nodesetval->nodeTab[0]->content;
    }
    xmlXPathFreeObject (xmlobject);

    request ="/config_ndpmon/countermeasures/kill_wrong_prefix/text()";
    xmlobject = xmlXPathEval ((xmlChar*)request, xpctxt);
    if (xmlobject->nodesetval!=NULL) {
        config_kill_wrong_prefix = (char*)xmlobject->nodesetval->nodeTab[0]->content;
    }
    xmlXPathFreeObject (xmlobject);

    request ="/config_ndpmon/countermeasures/propagate_router_params/text()";
    xmlobject = xmlXPathEval ((xmlChar*)request, xpctxt);
    if (xmlobject->nodesetval!=NULL) {
        config_propagate_router_params = (char*)xmlobject->nodesetval->nodeTab[0]->content;
    }
    xmlXPathFreeObject (xmlobject);

    request ="/config_ndpmon/countermeasures/indicate_ndpmon_presence/text()";
    xmlobject = xmlXPathEval ((xmlChar*)request, xpctxt);
    if (xmlobject->nodesetval!=NULL) {
        config_indicate_ndpmon_presence = (char*)xmlobject->nodesetval->nodeTab[0]->content;
    }
    xmlXPathFreeObject (xmlobject);

    cm_guard_init_all(
        config_kill_illegitimate_router,
        config_kill_wrong_prefix,
        config_propagate_router_params,
        config_indicate_ndpmon_presence
    );

}
Exemplo n.º 21
0
/*
 * call-seq:
 *    context.find("xpath") -> true|false|number|string|XML::XPath::Object
 *
 * Executes the provided xpath function.  The result depends on the execution
 * of the xpath statement.  It may be true, false, a number, a string or 
 * a node set.
 */
static VALUE rxml_xpath_context_find(VALUE self, VALUE xpath_expr)
{
  xmlXPathContextPtr xctxt;
  xmlXPathObjectPtr xobject;
  xmlXPathCompExprPtr xcompexpr;
  VALUE result;

  Data_Get_Struct(self, xmlXPathContext, xctxt);

  if (TYPE(xpath_expr) == T_STRING)
  {
    VALUE expression = rb_check_string_type(xpath_expr);
    xobject = xmlXPathEval((xmlChar*) StringValueCStr(expression), xctxt);
  }
  else if (rb_obj_is_kind_of(xpath_expr, cXMLXPathExpression))
  {
    Data_Get_Struct(xpath_expr, xmlXPathCompExpr, xcompexpr);
    xobject = xmlXPathCompiledEval(xcompexpr, xctxt);
  }
  else
  {
    rb_raise(rb_eTypeError,
        "Argument should be an intance of a String or XPath::Expression");
  }

  if (xobject == NULL)
  {
    /* xmlLastError is different than xctxt->lastError.  Use
     xmlLastError since it has the message set while xctxt->lastError
     does not. */
    xmlErrorPtr xerror = xmlGetLastError();
    rxml_raise(xerror);
  }

  switch (xobject->type)
  {
  case XPATH_NODESET:
    result = rxml_xpath_object_wrap(xctxt->doc, xobject);
    break;
  case XPATH_BOOLEAN:
    result = (xobject->boolval != 0) ? Qtrue : Qfalse;
    xmlXPathFreeObject(xobject);
    break;
  case XPATH_NUMBER:
    result = rb_float_new(xobject->floatval);
    xmlXPathFreeObject(xobject);
    break;
  case XPATH_STRING:
    result = rb_str_new2((const char*)xobject->stringval);
    xmlXPathFreeObject(xobject);
    break;
  default:
    result = Qnil;
    xmlXPathFreeObject(xobject);
  }
  return result;
}
Exemplo n.º 22
0
/**
 * xslDbgShellPrintList: 
 * @ctxt: The current shell context
 * @arg: What xpath to display and in UTF-8
 * @dir: If 1 print in dir mode?, 
 *        otherwise ls mode
 *
 * Print list of nodes in either ls or dir format
 *
 * Returns 1 on success,
 *         0 otherwise
 */
int
xslDbgShellPrintList(xmlShellCtxtPtr ctxt, xmlChar * arg, int dir)
{
    xmlXPathObjectPtr list;
    int result = 0;

    if (!ctxt || !arg) {
#ifdef WITH_XSLDBG_DEBUG_PROCESS
        xsltGenericError(xsltGenericErrorContext,
                         "Error: NULL arguments provided\n");
#endif
        return result;
    }

    if (arg[0] == 0) {
        if (dir)
            xmlShellDir(ctxt, NULL, ctxt->node, NULL);
        else
            xmlShellList(ctxt, NULL, ctxt->node, NULL);
        result = 1;             /*assume that this worked */
    } else {
        ctxt->pctxt->node = ctxt->node;
        ctxt->pctxt->node = ctxt->node;
        if (!xmlXPathNsLookup(ctxt->pctxt, (xmlChar *) "xsl"))
            xmlXPathRegisterNs(ctxt->pctxt, (xmlChar *) "xsl",
                               XSLT_NAMESPACE);
        list = xmlXPathEval(arg, ctxt->pctxt);
        if (list != NULL) {
            switch (list->type) {
                case XPATH_NODESET:{
                        int indx;

                        for (indx = 0;
                             indx < list->nodesetval->nodeNr; indx++) {
                            if (dir)
                                xmlShellList(ctxt, NULL,
                                             list->nodesetval->
                                             nodeTab[indx], NULL);
                            else
                                xmlShellList(ctxt, NULL,
                                             list->nodesetval->
                                             nodeTab[indx], NULL);
                        }
                        result = 1;
                        break;
                    }
                default:
                    xmlShellPrintXPathError(list->type, (char *) arg);
            }
            xmlXPathFreeObject(list);
        } else {
            xsldbgGenericErrorFunc(i18n("Error: XPath %1 results in an empty Node Set.\n").arg(xsldbgText(arg)));
        }
        ctxt->pctxt->node = NULL;
    }
    return result;
}
Exemplo n.º 23
0
/*Admin mail from the config file to send warnings
*/
void get_mail()
{
	char* request ="/config_ndpmon/admin_mail/text()";

	xmlXPathObjectPtr xmlobject = xmlXPathEval ((xmlChar*)request, xpctxt);
	strncpy(admin_mail,(char*)xmlobject->nodesetval->nodeTab[0]->content, ADMIN_MAIL_SIZE);

	xmlXPathFreeObject (xmlobject);
	return;
}
Exemplo n.º 24
0
/* Should we do reverse DNS lookups on an action that is logged? */
void get_use_reverse_hostlookups()
{
	char* request ="/config_ndpmon/use_reverse_hostlookups/text()";

	xmlXPathObjectPtr xmlobject = xmlXPathEval ((xmlChar*)request, xpctxt);
	if ((xmlobject->nodesetval==NULL) || (strcmp("1", (char*)xmlobject->nodesetval->nodeTab[0]->content)!=0)) use_reverse_hostlookups=0;
	else use_reverse_hostlookups=1;

	xmlXPathFreeObject (xmlobject);
	return;
}
Exemplo n.º 25
0
static bool image_add(GHashTable *images, xmlDocPtr args,
        xmlNodePtr image_args, GError **err)
{
    struct vmnetfs_image *img;
    xmlXPathContextPtr ctx;
    xmlXPathObjectPtr obj;
    xmlChar *content;
    int i;

    ctx = make_xpath_context(args);
    ctx->node = image_args;

    img = g_slice_new0(struct vmnetfs_image);
    img->url = xpath_get_str(ctx, "v:origin/v:url/text()");
    img->username = xpath_get_str(ctx,
            "v:origin/v:credentials/v:username/text()");
    img->password = xpath_get_str(ctx,
            "v:origin/v:credentials/v:password/text()");
    img->read_base = xpath_get_str(ctx, "v:cache/v:path/text()");
    img->fetch_offset = xpath_get_uint(ctx, "v:origin/v:offset/text()");
    img->initial_size = xpath_get_uint(ctx, "v:size/text()");
    img->chunk_size = xpath_get_uint(ctx, "v:cache/v:chunk-size/text()");
    img->etag = xpath_get_str(ctx, "v:origin/v:validators/v:etag/text()");
    img->last_modified = xpath_get_uint(ctx,
            "v:origin/v:validators/v:last-modified/text()");

    obj = xmlXPathEval(BAD_CAST "v:origin/v:cookies/v:cookie/text()", ctx);
    for (i = 0; obj && obj->nodesetval && i < obj->nodesetval->nodeNr; i++) {
        content = xmlNodeGetContent(obj->nodesetval->nodeTab[i]);
        img->cookies = g_list_prepend(img->cookies,
                g_strdup((const char *) content));
        xmlFree(content);
    }
    xmlXPathFreeObject(obj);

    img->io_stream = _vmnetfs_stream_group_new(NULL, NULL);
    img->bytes_read = _vmnetfs_stat_new();
    img->bytes_written = _vmnetfs_stat_new();
    img->chunk_fetches = _vmnetfs_stat_new();
    img->chunk_dirties = _vmnetfs_stat_new();
    img->io_errors = _vmnetfs_stat_new();

    if (!_vmnetfs_io_init(img, err)) {
        _image_free(img);
        xmlXPathFreeContext(ctx);
        return false;
    }

    g_hash_table_insert(images, xpath_get_str(ctx, "v:name/text()"), img);
    xmlXPathFreeContext(ctx);
    return true;
}
Exemplo n.º 26
0
static void xpath_censor(xmlXPathContextPtr ctx, const char *xpath)
{
    xmlXPathObjectPtr result;
    int i;

    result = xmlXPathEval(BAD_CAST xpath, ctx);
    if (result && result->nodesetval) {
        for (i = 0; i < result->nodesetval->nodeNr; i++) {
            xmlNodeSetContent(result->nodesetval->nodeTab[i],
                    (const xmlChar *) "XXXXX");
        }
    }
    xmlXPathFreeObject(result);
}
Exemplo n.º 27
0
Arquivo: xml.c Projeto: emaste/libvirt
/**
 * virXPathNodeSet:
 * @xpath: the XPath string to evaluate
 * @ctxt: an XPath context
 * @list: the returned list of nodes (or NULL if only count matters)
 *
 * Convenience function to evaluate an XPath node set
 *
 * Returns the number of nodes found in which case @list is set (and
 *         must be freed) or -1 if the evaluation failed.
 */
int
virXPathNodeSet(const char *xpath,
                xmlXPathContextPtr ctxt,
                xmlNodePtr **list)
{
    xmlXPathObjectPtr obj;
    xmlNodePtr relnode;
    int ret;

    if ((ctxt == NULL) || (xpath == NULL)) {
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       "%s", _("Invalid parameter to virXPathNodeSet()"));
        return -1;
    }

    if (list != NULL)
        *list = NULL;

    relnode = ctxt->node;
    obj = xmlXPathEval(BAD_CAST xpath, ctxt);
    ctxt->node = relnode;
    if (obj == NULL)
        return 0;

    if (obj->type != XPATH_NODESET) {
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("Incorrect xpath '%s'"), xpath);
        xmlXPathFreeObject(obj);
        return -1;
    }

    if ((obj->nodesetval == NULL)  || (obj->nodesetval->nodeNr < 0)) {
        xmlXPathFreeObject(obj);
        return 0;
    }

    ret = obj->nodesetval->nodeNr;
    if (list != NULL && ret) {
        if (VIR_ALLOC_N(*list, ret) < 0) {
            virReportOOMError();
            ret = -1;
        } else {
            memcpy(*list, obj->nodesetval->nodeTab,
                   ret * sizeof(xmlNodePtr));
        }
    }
    xmlXPathFreeObject(obj);
    return ret;
}
Exemplo n.º 28
0
/* Get Info server */
static void get_server_info(const char *ident)
{
	char *path = NULL;
	char xpath[SIZE];
	xmlXPathContextPtr xml_context = NULL;
	xmlXPathObjectPtr xmlobject;
	long lval;
	char *ep;

	(void)crv_strncpy(xpath, "/database/file[@id='", sizeof(xpath));
	(void)crv_strncat(xpath, ident, sizeof(xpath));
	(void)crv_strncat(xpath, "']/server" , sizeof(xpath));
	path = crv_strdup(xpath);

	xmlXPathInit();
	xml_context = xmlXPathNewContext (xmldoc);
	xmlobject = xmlXPathEval (path, xml_context);
	crv_free(path);

	if ((xmlobject->type == XPATH_NODESET) )
  {
		int j;
		xmlNodePtr node;
		for (j = 0; j < xmlobject->nodesetval->nodeNr; j++)
		{
			node = xmlobject->nodesetval->nodeTab[j];
			xmlChar *Host = xmlGetProp(node, "host");
			if (Host != NULL) {
				server = crv_strdup(Host);
			}

			xmlChar *Port = xmlGetProp(node, "port");
			if (Port != NULL) {
				lval = strtol(Port, &ep, 10);
				if (Port[0] == '\0' || *ep != '\0') {
					fprintf(stderr, "%s%s", Port, " is not a number");
					return;
				}
				port = lval;
			}
			xmlFree (Host);
			xmlFree (Port);
		}
	}
	xmlXPathFreeObject (xmlobject);
  xmlXPathFreeContext (xml_context);
}
Exemplo n.º 29
0
/**
 * Evaluates an XPath expression on the passed-in context.
 *
 * @param pContext Pointer to the context.
 * @param pczExpression The XPath expression to evaluate
 *
 * @return xmlNodeSetPtr pointing to the resulting node set, must be
 *         freed by the caller.
 */
static xmlNodeSetPtr
evaluateXPathExpression(xmlXPathContextPtr pContext, const char * pczExpression)
{
  xmlXPathObjectPtr pObject = xmlXPathEval(CONSTXMLCHAR_P(pczExpression), 
                                           pContext);

  if (!pObject || !pObject->nodesetval)
    {
      return NULL;
    }

  xmlNodeSetPtr pNodeSet = pObject->nodesetval;

  xmlXPathFreeNodeSetList(pObject);

  return pNodeSet;
}
Exemplo n.º 30
0
/**
 * This is identical to xpath_foreach_match, except that it takes the context
 * as parameter.
 */
static void
inoreader_source_xpath_foreach_match (const gchar* expr, xmlXPathContextPtr xpathCtxt, xpathMatchFunc func, gpointer user_data) 
{
	xmlXPathObjectPtr xpathObj = NULL;
	xpathObj = xmlXPathEval ((xmlChar*)expr, xpathCtxt);
	
	if (xpathObj && xpathObj->nodesetval && xpathObj->nodesetval->nodeMax) {
		int	i;
		for (i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
			(*func) (xpathObj->nodesetval->nodeTab[i], user_data);
			xpathObj->nodesetval->nodeTab[i] = NULL ;
		}
	}
	
	if (xpathObj)
		xmlXPathFreeObject (xpathObj);
}