当前位置: 首页>>代码示例>>C++>>正文


C++ xmlXPathNodeSetGetLength函数代码示例

本文整理汇总了C++中xmlXPathNodeSetGetLength函数的典型用法代码示例。如果您正苦于以下问题:C++ xmlXPathNodeSetGetLength函数的具体用法?C++ xmlXPathNodeSetGetLength怎么用?C++ xmlXPathNodeSetGetLength使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了xmlXPathNodeSetGetLength函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: xml_config_for_each_obj

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;
}
开发者ID:Qingtao-Cao,项目名称:obix,代码行数:26,代码来源:xml_config.c

示例2: epp_getSubtree

char *
epp_getSubtree(void *pool,
		epp_command_data *cdata,
		const char *xpath_expr,
		int position)
{
	char	*subtree;
	xmlBufferPtr	 buf;
	xmlDocPtr	 doc;
	xmlNodePtr	 node;
	xmlXPathObjectPtr	 xpath_obj;
	xmlXPathContextPtr	 xpath_ctx;

	doc = (xmlDocPtr) cdata->parsed_doc;
	xpath_ctx = (xmlXPathContextPtr) cdata->xpath_ctx;

	xpath_obj = xmlXPathEvalExpression(BAD_CAST xpath_expr, xpath_ctx);
	if (xpath_obj == NULL)
		return NULL;
	/* correct position for non-list elements */
	if (position == 0) position++;
	if (xmlXPathNodeSetGetLength(xpath_obj->nodesetval) < position) {
		xmlXPathFreeObject(xpath_obj);
		/* return empty string if the node is not there */
		return epp_strdup(pool, "");
	}

	/*
	 * Get content of problematic tag. It's not so easy task. We have
	 * to declare namespaces defined higher in the tree which are relevant
	 * to the part of document being dumped. Fortunatelly there is a
	 * function from libxml library doing exactly that (xmlreconsiliatens).
	 */
	buf = xmlBufferCreate();
	if (buf == NULL)
		return NULL;
	node = xmlXPathNodeSetItem(xpath_obj->nodesetval, position - 1);
	if (node->ns != NULL) {
		xmlNsPtr	 nsdef;

		nsdef = xmlSearchNs(doc, node, node->ns->prefix);
		if (nsdef != NULL)
			xmlNewNs(node, nsdef->href, nsdef->prefix);
	}
	if (xmlNodeDump(buf, doc, node, 0, 0) < 0)
	{
		xmlXPathFreeObject(xpath_obj);
		xmlBufferFree(buf);
		return NULL;
	}
	subtree = epp_strdup(pool, (char *) buf->content);
	xmlXPathFreeObject(xpath_obj);
	xmlBufferFree(buf);
	return subtree;
}
开发者ID:LANJr4D,项目名称:FRED,代码行数:55,代码来源:epp_xmlcommon.c

示例3: xmms_xspf_check_valid_xspf

static gboolean
xmms_xspf_check_valid_xspf (xmlDocPtr doc, xmlXPathContextPtr xpath,
                            xmms_error_t *error)
{
	xmlXPathObjectPtr obj;

	obj = xmlXPathEvalExpression (BAD_CAST "/xspf:playlist[@version<=1]",
	                              xpath);

	if (!obj) {
		xmms_error_set (error, XMMS_ERROR_INVAL,
		                "unable to evaluate xpath expression");
		return FALSE;
	}

	if (xmlXPathNodeSetGetLength (obj->nodesetval) != 1) {
		xmms_error_set (error, XMMS_ERROR_INVAL,
		                "xspf document doesn't contain a version 0 or 1 "
		                "playlist");
		xmlXPathFreeObject (obj);
		return FALSE;
	}

	xmlXPathFreeObject (obj);
	obj = xmlXPathEvalExpression (BAD_CAST "/xspf:playlist[@version<=1]/xspf:trackList",
	                              xpath);

	if (!obj) {
		xmms_error_set (error, XMMS_ERROR_INVAL,
		                "unable to evaluate xpath expression");
		return FALSE;
	}

	if (xmlXPathNodeSetGetLength (obj->nodesetval) != 1) {
		xmms_error_set (error, XMMS_ERROR_INVAL,
		                "invalid xspf: document doesn't contain exactly one trackList");
		xmlXPathFreeObject (obj);
		return FALSE;
	}

	return TRUE;
}
开发者ID:eggpi,项目名称:xmms2-guilherme,代码行数:42,代码来源:xspf.c

示例4: cache_from_doc_ns

/* This one adds all namespaces defined in document to a cache, without anything
   associated with uri obviously.
   Unfortunately namespace:: axis implementation in libxml2 differs from what we need,
   it uses additional node type to describe namespace definition attribute while
   in msxml it's expected to be a normal attribute - as a workaround document is
   queried at libxml2 level here. */
HRESULT cache_from_doc_ns(IXMLDOMSchemaCollection2 *iface, xmlnode *node)
{
    schema_cache* This = impl_from_IXMLDOMSchemaCollection2(iface);
    static const xmlChar query[] = "//*/namespace::*";
    xmlXPathObjectPtr nodeset;
    xmlXPathContextPtr ctxt;

    This->read_only = 1;

    ctxt = xmlXPathNewContext(node->node->doc);

    nodeset = xmlXPathEvalExpression(query, ctxt);
    xmlXPathFreeContext(ctxt);

    if (nodeset)
    {
        int pos = 0, len = xmlXPathNodeSetGetLength(nodeset->nodesetval);

        if (len == 0) return S_OK;

        while (pos < len)
        {
            xmlNodePtr node = xmlXPathNodeSetItem(nodeset->nodesetval, pos);
            if (node->type == XML_NAMESPACE_DECL)
            {
                static const xmlChar defns[] = "http://www.w3.org/XML/1998/namespace";
                xmlNsPtr ns = (xmlNsPtr)node;
                cache_entry *entry;

                /* filter out default uri */
                if (xmlStrEqual(ns->href, defns))
                {
                    pos++;
                    continue;
                }

                entry = heap_alloc(sizeof(cache_entry));
                entry->type = CacheEntryType_NS;
                entry->ref = 1;
                entry->schema = NULL;
                entry->doc = NULL;

                cache_add_entry(This, ns->href, entry);
            }
            pos++;
        }

        xmlXPathFreeObject(nodeset);
    }

    return S_OK;
}
开发者ID:ZoloZiak,项目名称:reactos,代码行数:58,代码来源:schema.c

示例5: queryresult_get_length

static HRESULT WINAPI queryresult_get_length(
        IXMLDOMNodeList* iface,
        LONG* listLength)
{
    queryresult *This = impl_from_IXMLDOMNodeList( iface );

    TRACE("(%p)->(%p)\n", This, listLength);

    if(!listLength)
        return E_INVALIDARG;

    *listLength = xmlXPathNodeSetGetLength(This->result->nodesetval);
    return S_OK;
}
开发者ID:mikekap,项目名称:wine,代码行数:14,代码来源:queryresult.c

示例6: domselection_get_length

static HRESULT WINAPI domselection_get_length(
        IXMLDOMSelection* iface,
        LONG* listLength)
{
    domselection *This = impl_from_IXMLDOMSelection( iface );

    TRACE("(%p)->(%p)\n", This, listLength);

    if(!listLength)
        return E_INVALIDARG;

    *listLength = xmlXPathNodeSetGetLength(This->result->nodesetval);
    return S_OK;
}
开发者ID:Sunmonds,项目名称:wine,代码行数:14,代码来源:selection.c

示例7: queryresult_get_dispid

static HRESULT queryresult_get_dispid(IUnknown *iface, BSTR name, DWORD flags, DISPID *dispid)
{
    queryresult *This = impl_from_IXMLDOMNodeList( (IXMLDOMNodeList*)iface );
    WCHAR *ptr;
    int idx = 0;

    for(ptr = name; *ptr && isdigitW(*ptr); ptr++)
        idx = idx*10 + (*ptr-'0');
    if(*ptr)
        return DISP_E_UNKNOWNNAME;

    if(idx >= xmlXPathNodeSetGetLength(This->result->nodesetval))
        return DISP_E_UNKNOWNNAME;

    *dispid = MSXML_DISPID_CUSTOM_MIN + idx;
    TRACE("ret %x\n", *dispid);
    return S_OK;
}
开发者ID:mikekap,项目名称:wine,代码行数:18,代码来源:queryresult.c

示例8: noit_conf_mkcheck_under

static int
noit_conf_mkcheck_under(const char *ppath, int argc, char **argv, uuid_t out) {
  int rv = -1;
  const char *path;
  char xpath[1024];
  xmlXPathContextPtr xpath_ctxt = NULL;
  xmlXPathObjectPtr pobj = NULL;
  xmlNodePtr node = NULL, newnode;

  /* attr val [or] no attr (sets of two) */
  if(argc % 2) goto out;

  mtev_conf_xml_xpath(NULL, &xpath_ctxt);
  path = strcmp(ppath, "/") ? ppath : "";
  snprintf(xpath, sizeof(xpath), "/noit%s", path);
  pobj = xmlXPathEval((xmlChar *)xpath, xpath_ctxt);
  if(!pobj || pobj->type != XPATH_NODESET ||
     xmlXPathNodeSetGetLength(pobj->nodesetval) != 1) {
    goto out;
  }
  node = (mtev_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, 0);
  if((newnode = xmlNewChild(node, NULL, (xmlChar *)"check", NULL)) != NULL) {
    char outstr[37];
    uuid_generate(out);
    uuid_unparse_lower(out, outstr);
    xmlSetProp(newnode, (xmlChar *)"uuid", (xmlChar *)outstr);
    xmlSetProp(newnode, (xmlChar *)"disable", (xmlChar *)"true");

    /* No risk of running off the end (we checked this above) */
    if(noit_config_check_update_attrs(newnode, argc, argv)) {
      /* Something went wrong, remove the node */
      xmlUnlinkNode(newnode);
    }
    else {
      CONF_DIRTY(newnode);
      mtev_conf_mark_changed();
      rv = 0;
    }
  }
 out:
  if(pobj) xmlXPathFreeObject(pobj);
  return rv;
}
开发者ID:JonasKunze,项目名称:reconnoiter,代码行数:43,代码来源:noit_conf_checks.c

示例9: domselection_nextNode

static HRESULT WINAPI domselection_nextNode(
        IXMLDOMSelection* iface,
        IXMLDOMNode** nextItem)
{
    domselection *This = impl_from_IXMLDOMSelection( iface );

    TRACE("(%p)->(%p)\n", This, nextItem );

    if(!nextItem)
        return E_INVALIDARG;

    *nextItem = NULL;

    if (This->resultPos >= xmlXPathNodeSetGetLength(This->result->nodesetval))
        return S_FALSE;

    *nextItem = create_node(xmlXPathNodeSetItem(This->result->nodesetval, This->resultPos));
    This->resultPos++;
    return S_OK;
}
开发者ID:Sunmonds,项目名称:wine,代码行数:20,代码来源:selection.c

示例10: domselection_get_item

static HRESULT WINAPI domselection_get_item(
        IXMLDOMSelection* iface,
        LONG index,
        IXMLDOMNode** listItem)
{
    domselection *This = impl_from_IXMLDOMSelection( iface );

    TRACE("(%p)->(%d %p)\n", This, index, listItem);

    if(!listItem)
        return E_INVALIDARG;

    *listItem = NULL;

    if (index < 0 || index >= xmlXPathNodeSetGetLength(This->result->nodesetval))
        return S_FALSE;

    *listItem = create_node(xmlXPathNodeSetItem(This->result->nodesetval, index));
    This->resultPos = index + 1;

    return S_OK;
}
开发者ID:Sunmonds,项目名称:wine,代码行数:22,代码来源:selection.c

示例11: create_selection

HRESULT create_selection(xmlNodePtr node, xmlChar* query, IXMLDOMNodeList **out)
{
    domselection *This = heap_alloc(sizeof(domselection));
    xmlXPathContextPtr ctxt = xmlXPathNewContext(node->doc);
    HRESULT hr;

    TRACE("(%p, %s, %p)\n", node, wine_dbgstr_a((char const*)query), out);

    *out = NULL;
    if (!This || !ctxt || !query)
    {
        xmlXPathFreeContext(ctxt);
        heap_free(This);
        return E_OUTOFMEMORY;
    }

    This->IXMLDOMSelection_iface.lpVtbl = &domselection_vtbl;
    This->ref = 1;
    This->resultPos = 0;
    This->node = node;
    This->enumvariant = NULL;
    init_dispex(&This->dispex, (IUnknown*)&This->IXMLDOMSelection_iface, &domselection_dispex);
    xmldoc_add_ref(This->node->doc);

    ctxt->error = query_serror;
    ctxt->node = node;
    registerNamespaces(ctxt);

    if (is_xpathmode(This->node->doc))
    {
        xmlXPathRegisterAllFunctions(ctxt);
        This->result = xmlXPathEvalExpression(query, ctxt);
    }
    else
    {
        xmlChar* pattern_query = XSLPattern_to_XPath(ctxt, query);

        xmlXPathRegisterFunc(ctxt, (xmlChar const*)"not", xmlXPathNotFunction);
        xmlXPathRegisterFunc(ctxt, (xmlChar const*)"boolean", xmlXPathBooleanFunction);

        xmlXPathRegisterFunc(ctxt, (xmlChar const*)"index", XSLPattern_index);
        xmlXPathRegisterFunc(ctxt, (xmlChar const*)"end", XSLPattern_end);
        xmlXPathRegisterFunc(ctxt, (xmlChar const*)"nodeType", XSLPattern_nodeType);

        xmlXPathRegisterFunc(ctxt, (xmlChar const*)"OP_IEq", XSLPattern_OP_IEq);
        xmlXPathRegisterFunc(ctxt, (xmlChar const*)"OP_INEq", XSLPattern_OP_INEq);
        xmlXPathRegisterFunc(ctxt, (xmlChar const*)"OP_ILt", XSLPattern_OP_ILt);
        xmlXPathRegisterFunc(ctxt, (xmlChar const*)"OP_ILEq", XSLPattern_OP_ILEq);
        xmlXPathRegisterFunc(ctxt, (xmlChar const*)"OP_IGt", XSLPattern_OP_IGt);
        xmlXPathRegisterFunc(ctxt, (xmlChar const*)"OP_IGEq", XSLPattern_OP_IGEq);

        This->result = xmlXPathEvalExpression(pattern_query, ctxt);
        xmlFree(pattern_query);
    }

    if (!This->result || This->result->type != XPATH_NODESET)
    {
        hr = E_FAIL;
        goto cleanup;
    }

    *out = (IXMLDOMNodeList*)&This->IXMLDOMSelection_iface;
    hr = S_OK;
    TRACE("found %d matches\n", xmlXPathNodeSetGetLength(This->result->nodesetval));

cleanup:
    if (This && FAILED(hr))
        IXMLDOMSelection_Release( &This->IXMLDOMSelection_iface );
    xmlXPathFreeContext(ctxt);
    return hr;
}
开发者ID:Sunmonds,项目名称:wine,代码行数:71,代码来源:selection.c

示例12: rest_show_check

static int
rest_show_check(mtev_http_rest_closure_t *restc,
                int npats, char **pats) {
  mtev_http_session_ctx *ctx = restc->http_ctx;
  xmlXPathObjectPtr pobj = NULL;
  xmlXPathContextPtr xpath_ctxt = NULL;
  xmlDocPtr doc = NULL;
  xmlNodePtr node, root, attr, config, state, tmp, anode;
  uuid_t checkid;
  noit_check_t *check;
  char xpath[1024], *uuid_conf, *module = NULL, *value = NULL;
  int rv, mod, mod_cnt, cnt, error_code = 500;
  mtev_hash_iter iter = MTEV_HASH_ITER_ZERO;
  const char *k;
  int klen;
  void *data;
  mtev_hash_table *configh;

  if(npats != 2 && npats != 3) goto error;

  rv = noit_check_xpath(xpath, sizeof(xpath), pats[0], pats[1]);
  if(rv == 0) goto not_found;
  if(rv < 0) goto error;

  mtev_conf_xml_xpath(NULL, &xpath_ctxt);
  pobj = xmlXPathEval((xmlChar *)xpath, xpath_ctxt);
  if(!pobj || pobj->type != XPATH_NODESET ||
     xmlXPathNodeSetIsEmpty(pobj->nodesetval)) goto not_found;
  cnt = xmlXPathNodeSetGetLength(pobj->nodesetval);
  if(cnt != 1) goto error;

  node = (mtev_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, 0);
  uuid_conf = (char *)xmlGetProp(node, (xmlChar *)"uuid");
  if(!uuid_conf || uuid_parse(uuid_conf, checkid)) goto error;

  if(npats == 3 && !strcmp(pats[2], ".json")) {
    return rest_show_check_json(restc, checkid);
  }

  doc = xmlNewDoc((xmlChar *)"1.0");
  root = xmlNewDocNode(doc, NULL, (xmlChar *)"check", NULL);
  xmlDocSetRootElement(doc, root);

#define MYATTR(node,a,n,b) _mtev_conf_get_string(node, &(n), "@" #a, &(b))
#define INHERIT(node,a,n,b) \
  _mtev_conf_get_string(node, &(n), "ancestor-or-self::node()/@" #a, &(b))
#define SHOW_ATTR(parent, node, a) do { \
  char *_value = NULL; \
  INHERIT(node, a, anode, _value); \
  if(_value != NULL) { \
    int clen, plen;\
    char *_cpath, *_apath; \
    xmlNodePtr child; \
    _cpath = node ? (char *)xmlGetNodePath(node) : strdup(""); \
    _apath = anode ? (char *)xmlGetNodePath(anode) : strdup(""); \
    clen = strlen(_cpath); \
    plen = strlen("/noit/checks"); \
    child = xmlNewNode(NULL, (xmlChar *)#a); \
    xmlNodeAddContent(child, (xmlChar *)_value); \
    if(!strncmp(_cpath, _apath, clen) && _apath[clen] == '/') { \
    } \
    else { \
      xmlSetProp(child, (xmlChar *)"inherited", (xmlChar *)_apath+plen); \
    } \
    xmlAddChild(parent, child); \
    free(_cpath); \
    free(_apath); \
    free(_value); \
  } \
} while(0)

  attr = xmlNewNode(NULL, (xmlChar *)"attributes");
  xmlAddChild(root, attr);

  SHOW_ATTR(attr,node,uuid);
  SHOW_ATTR(attr,node,seq);

  /* Name is odd, it falls back transparently to module */
  if(!INHERIT(node, module, tmp, module)) module = NULL;
  xmlAddChild(attr, (tmp = xmlNewNode(NULL, (xmlChar *)"name")));
  if(MYATTR(node, name, anode, value))
    xmlNodeAddContent(tmp, (xmlChar *)value);
  else if(module)
    xmlNodeAddContent(tmp, (xmlChar *)module);
  if(value) free(value);
  if(module) free(module);

  SHOW_ATTR(attr,node,module);
  SHOW_ATTR(attr,node,target);
  SHOW_ATTR(attr,node,resolve_rtype);
  SHOW_ATTR(attr,node,seq);
  SHOW_ATTR(attr,node,period);
  SHOW_ATTR(attr,node,timeout);
  SHOW_ATTR(attr,node,oncheck);
  SHOW_ATTR(attr,node,filterset);
  SHOW_ATTR(attr,node,disable);

  /* Add the config */
  config = xmlNewNode(NULL, (xmlChar *)"config");
  configh = mtev_conf_get_hash(node, "config");
//.........这里部分代码省略.........
开发者ID:damajor,项目名称:reconnoiter,代码行数:101,代码来源:noit_check_rest.c

示例13: rn_xml_topology

/* 
 * This function creates and setups the g_rn_machines global data structure of nodes
 */
void
rn_xml_topology()
{
	xmlXPathObjectPtr	obj;

	xmlNodePtr		node;

	unsigned int		i;
	//unsigned int		j;
	unsigned int		id;
	unsigned int		size;

	rn_as			*as;
	rn_area			*ar;
	rn_subnet		*sn;
	rn_machine		*m;

	size = 0;

	/* Environment */
	obj = xpath("//environment", ctxt);
	if(obj->nodesetval->nodeTab)
		g_rn_environment = *obj->nodesetval->nodeTab;
	xmlXPathFreeObject(obj);

	/* ASes */
	obj = xpath("/rossnet/as", ctxt);
	g_rn_nas = xmlXPathNodeSetGetLength(obj->nodesetval);	

	if(g_rn_nas > 0)
	{
		g_rn_as = (rn_as *) tw_calloc(TW_LOC, "", sizeof(rn_as), g_rn_nas);
		size += sizeof(rn_as) * g_rn_nas;
	}

	node = obj->nodesetval->nodeTab[0];
	for(i = 0; i < obj->nodesetval->nodeNr; )
	{
		g_rn_as[i].low = -1;
		g_rn_as[i].id = atoi(xml_getprop(node, "id"));	
		//g_rn_as[i].frequency = atoi(xml_getprop(node, "frequency"));	

#if WASTE_MEM
		if(0 == strcmp(xml_getprop(node, "name"), "name"))
			g_rn_as[i].name = (char *) xmlStrdup((xmlChar *) xml_getprop(node, "name"));
#endif

		node = obj->nodesetval->nodeTab[++i];
	}

	xmlXPathFreeObject(obj);

	/* Areas */
	obj = xpath("/rossnet/as/area", ctxt);
	g_rn_nareas = xmlXPathNodeSetGetLength(obj->nodesetval);	

	if(g_rn_nareas > 0)
	{
		g_rn_areas = (rn_area *) tw_calloc(TW_LOC, "", sizeof(rn_area), g_rn_nareas);
		size += sizeof(rn_area) * g_rn_nareas;
	}

	node = obj->nodesetval->nodeTab[0];
	for(i = 0; i < obj->nodesetval->nodeNr; )
	{
		//g_rn_areas[i].root = INT_MAX;
		//g_rn_areas[i].root_lvl = 0xff;
		g_rn_areas[i].low = INT_MAX;
		g_rn_areas[i].id = atoi(xml_getprop(node, "id"));	
		g_rn_areas[i].as = &g_rn_as[atoi(xml_getprop(node->parent, "id"))];

		if(g_rn_areas[i].as->areas == NULL)
			g_rn_areas[i].as->areas = &g_rn_areas[i];

		if(i > 0 && g_rn_areas[i-1].as->id == g_rn_areas[i].as->id)
			g_rn_areas[i-1].next = &g_rn_areas[i];

		g_rn_areas[i].as->nareas++;

		node = obj->nodesetval->nodeTab[++i];
	}

	xmlXPathFreeObject(obj);

	/* Subnets */
	obj = xpath("/rossnet/as/area/subnet", ctxt);
	g_rn_nsubnets = xmlXPathNodeSetGetLength(obj->nodesetval);	

	if(g_rn_nsubnets > 0)
	{
		g_rn_subnets = (rn_subnet *) tw_calloc(TW_LOC, "", sizeof(rn_subnet), g_rn_nsubnets);
		size += sizeof(rn_subnet) * g_rn_nsubnets;
	}

	node = *obj->nodesetval->nodeTab;
	for(i = 0; i < obj->nodesetval->nodeNr; )
	{
//.........这里部分代码省略.........
开发者ID:chleemobile,项目名称:rossnet,代码行数:101,代码来源:xml-libxml.c

示例14: noit_console_watch_check

static int
noit_console_watch_check(noit_console_closure_t ncct,
                         int argc, char **argv,
                         noit_console_state_t *state, void *closure) {
  int i, cnt;
  int adding = (int)(vpsized_int)closure;
  int period = 0;
  char xpath[1024];
  xmlXPathObjectPtr pobj = NULL;
  xmlXPathContextPtr xpath_ctxt = NULL;

  noit_conf_xml_xpath(NULL, &xpath_ctxt);
  if(argc < 1 || argc > 2) {
    nc_printf(ncct, "requires one or two arguments\n");
    return -1;
  }
  /* An alternate period */
  if(argc == 2) period = atoi(argv[1]);

  if(noit_console_mkcheck_xpath(xpath, sizeof(xpath), NULL,
                                argc ? argv[0] : NULL)) {
    nc_printf(ncct, "ERROR: could not find check '%s'\n", argv[0]);
    return -1;
  }

  pobj = xmlXPathEval((xmlChar *)xpath, xpath_ctxt);
  if(!pobj || pobj->type != XPATH_NODESET ||
     xmlXPathNodeSetIsEmpty(pobj->nodesetval)) {
    nc_printf(ncct, "no checks found\n");
    goto out;
  }
  cnt = xmlXPathNodeSetGetLength(pobj->nodesetval);
  for(i=0; i<cnt; i++) {
    uuid_t checkid;
    noit_check_t *check;
    xmlNodePtr node;
    char *uuid_conf;

    node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, i);
    uuid_conf = (char *)xmlGetProp(node, (xmlChar *)"uuid");
    if(!uuid_conf || uuid_parse(uuid_conf, checkid)) {
      nc_printf(ncct, "%s has invalid or missing UUID!\n",
                (char *)xmlGetNodePath(node) + strlen("/noit"));
      continue;
    }
    if(period == 0) {
      check = noit_poller_lookup(checkid);
      if(!check) continue;
      if(adding) noit_check_transient_add_feed(check, ncct->feed_path);
      else noit_check_transient_remove_feed(check, ncct->feed_path);
    }
    else {
      if(adding) {
        check = noit_check_watch(checkid, period);
        /* This check must be watched from the console */
        noit_check_transient_add_feed(check, ncct->feed_path);
        /* Note the check */
        noit_check_log_check(check);
        /* kick it off, if it isn't running already */
        if(!NOIT_CHECK_LIVE(check)) noit_check_activate(check);
      }
      else {
        check = noit_check_get_watch(checkid, period);
        if(check) noit_check_transient_remove_feed(check, ncct->feed_path);
      }
    }
  }
 out:
  if(pobj) xmlXPathFreeObject(pobj);
  return 0;
}
开发者ID:easel,项目名称:reconnoiter,代码行数:71,代码来源:noit_conf_checks.c

示例15: main


//.........这里部分代码省略.........
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, NULL);
    curl_easy_setopt(curl, CURLOPT_HEADERDATA, NULL);
    curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, NULL);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, NULL);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);

    // get video query, and get filename
    sprintf(query, "http://www.nicovideo.jp/api/getthumbinfo?v=%s", id);
    mf = memfopen();
    curl_easy_setopt(curl, CURLOPT_URL, query);
    curl_easy_setopt(curl, CURLOPT_POST, 0);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, mf);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, memfwrite);
    res = curl_easy_perform(curl);
    if (res != CURLE_OK) {
        fputs(error, stderr);
        memfclose(mf);
        goto leave;
    }

#ifdef USE_LIBXML
    // parse title node
    {
        xmlDocPtr doc = NULL;
        xmlXPathContextPtr xpathctx;
        xmlXPathObjectPtr xpathobj;

        doc = xmlParseMemory(mf->data, mf->size);
        xpathctx = doc ? xmlXPathNewContext(doc) : NULL;
        xpathobj = xpathctx ? xmlXPathEvalExpression((xmlChar*) "//title", xpathctx) : NULL;
        if (xpathobj) {
            int n;
            xmlNodeSetPtr nodes = xpathobj->nodesetval;
            for(n = 0; nodes && n < xmlXPathNodeSetGetLength(nodes); n++) {
                xmlNodePtr node = nodes->nodeTab[n];
                if(node->type != XML_ATTRIBUTE_NODE && node->type != XML_ELEMENT_NODE && node->type != XML_CDATA_SECTION_NODE) continue;
                if (node->type == XML_CDATA_SECTION_NODE)
                    sprintf(fname, "%s.flv", (char*) node->content);
                else
                    if (node->children)
                        sprintf(fname, "%s.flv", (char*) node->children->content);
                break;
            }
        }
        if (xpathobj ) xmlXPathFreeObject(xpathobj);
        if (xpathctx) xmlXPathFreeContext(xpathctx);
        if (doc) xmlFreeDoc(doc);
    }
#else
    buf = memfstrdup(mf);
    ptr = buf ? strstr(buf, "<title>") : NULL;
    if (ptr) {
        ptr += 7;
        tmp = strstr(ptr, "</title>");
        if (*tmp) {
            *tmp = 0;
            sprintf(fname, "%s.flv", ptr);
        }
    }
    if (buf) free(buf);
#endif

    memfclose(mf);

#ifdef _WIN32
    {
开发者ID:mattn,项目名称:nicodown,代码行数:67,代码来源:nicodown.c


注:本文中的xmlXPathNodeSetGetLength函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。