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; }
/* 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; }
METHOD XPath_find(Ctx *ctx, knh_sfp_t *sfp) { xmlXPathContextPtr xctx = (xmlXPathContextPtr) p_cptr(sfp[0]); xmlChar *xpath = (xmlChar *) p_char(sfp[1]); xmlNodePtr node = NULL; xmlXPathObjectPtr xpobj; if (!(xpobj = xmlXPathEvalExpression( xpath, xctx))) { fprintf(stderr,"xpath:%s",(char*)xpath); KNH_THROWs(ctx, "XPATH: cant execute xmlXPathEvalExpression"); } if (!xmlXPathNodeSetIsEmpty(xpobj->nodesetval)) { node = xmlXPathNodeSetItem(xpobj->nodesetval, 0); } xmlXPathFreeObject(xpobj); KNH_RETURN(ctx,sfp,new_Glue(ctx,(char*)"libxml2.XmlNode",node,NULL)); }
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; }
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; }
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; }
xmlNode *xml_config_get_node(const xml_config_t *config, const char *pattern) { xmlXPathObject *objs; xmlNode *node = NULL; if (!(objs = xmlXPathEval(BAD_CAST pattern, config->xpc))) { log_error("Failed to apply XPath Predicate %s", pattern); return NULL; } /* * Return the pointer of the first matching node */ if (xmlXPathNodeSetIsEmpty(objs->nodesetval) == 0) { node = xmlXPathNodeSetItem(objs->nodesetval, 0); } /* * Release the table of xmlNode pointers won't impact * the nodes pointed to in relevant document at all */ xmlXPathFreeObject(objs); return node; }
static int replace_config(noit_console_closure_t ncct, noit_conf_t_userdata_t *info, const char *name, const char *value) { int i, cnt, rv = -1, active = 0; xmlXPathObjectPtr pobj = NULL; xmlXPathContextPtr xpath_ctxt = NULL; xmlNodePtr node, confignode; char xpath[1024], *path; path = info->path; if(!strcmp(path, "/")) path = ""; noit_conf_xml_xpath(NULL, &xpath_ctxt); /* Only if checks will fixate this attribute shall we check for * child <check> nodes. * NOTE: this return nothing and "seems" okay if we are _in_ * a <check> node. That case is handled below. */ snprintf(xpath, sizeof(xpath), "/noit/%s//check[@uuid]", path); pobj = xmlXPathEval((xmlChar *)xpath, xpath_ctxt); if(!pobj || pobj->type != XPATH_NODESET) goto out; cnt = xmlXPathNodeSetGetLength(pobj->nodesetval); for(i=0; i<cnt; i++) { uuid_t checkid; node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, i); if(noit_conf_get_uuid(node, "@uuid", checkid)) { noit_check_t *check; check = noit_poller_lookup(checkid); if(check && NOIT_CHECK_LIVE(check)) active++; } } if(pobj) xmlXPathFreeObject(pobj); #ifdef UNSAFE_RECONFIG snprintf(xpath, sizeof(xpath), "/noit/%s", path); pobj = xmlXPathEval((xmlChar *)xpath, xpath_ctxt); if(!pobj || pobj->type != XPATH_NODESET) goto out; cnt = xmlXPathNodeSetGetLength(pobj->nodesetval); if(cnt != 1) { nc_printf(ncct, "Internal error: context node disappeared\n"); goto out; } node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, 0); if(strcmp((const char *)node->name, "check")) { uuid_t checkid; /* Detect if we are actually a <check> node and attempting to * change something we shouldn't. * This is the counterpart noted above. */ if(noit_conf_get_uuid(node, "@uuid", checkid)) { noit_check_t *check; check = noit_poller_lookup(checkid); if(NOIT_CHECK_LIVE(check)) active++; } } if(active) { nc_printf(ncct, "Cannot set '%s', it would effect %d live check(s)\n", name, active); goto out; } if(pobj) xmlXPathFreeObject(pobj); #endif /* Here we want to remove /noit/path/config/name */ snprintf(xpath, sizeof(xpath), "/noit/%s/config/%s", path, name); pobj = xmlXPathEval((xmlChar *)xpath, xpath_ctxt); if(!pobj || pobj->type != XPATH_NODESET) goto out; if(xmlXPathNodeSetGetLength(pobj->nodesetval) > 0) { xmlNodePtr toremove; toremove = xmlXPathNodeSetItem(pobj->nodesetval, 0); xmlUnlinkNode(toremove); } /* TODO: if there are no more children of config, remove config? */ if(value) { if(pobj) xmlXPathFreeObject(pobj); /* He we create config if needed and place a child node under it */ snprintf(xpath, sizeof(xpath), "/noit/%s/config", path); pobj = xmlXPathEval((xmlChar *)xpath, xpath_ctxt); if(!pobj || pobj->type != XPATH_NODESET) goto out; if(xmlXPathNodeSetGetLength(pobj->nodesetval) == 0) { if(pobj) xmlXPathFreeObject(pobj); snprintf(xpath, sizeof(xpath), "/noit/%s", path); pobj = xmlXPathEval((xmlChar *)xpath, xpath_ctxt); if(!pobj || pobj->type != XPATH_NODESET) goto out; if(xmlXPathNodeSetGetLength(pobj->nodesetval) != 1) { nc_printf(ncct, "Node disappeared from under you!\n"); goto out; } confignode = xmlNewChild(xmlXPathNodeSetItem(pobj->nodesetval, 0), NULL, (xmlChar *)"config", NULL); if(confignode == NULL) { nc_printf(ncct, "Error creating config child node.\n"); goto out; } } else confignode = xmlXPathNodeSetItem(pobj->nodesetval, 0); assert(confignode); /* Now we create a child */ xmlNewChild(confignode, NULL, (xmlChar *)name, (xmlChar *)value); } noit_conf_mark_changed(); rv = 0; out: if(pobj) xmlXPathFreeObject(pobj); return rv; }
static int noit_console_config_show(noit_console_closure_t ncct, int argc, char **argv, noit_console_state_t *state, void *closure) { noit_hash_iter iter = NOIT_HASH_ITER_ZERO; const char *k; int klen; void *data; int i, cnt, titled = 0, cliplen = 0; const char *path = "", *basepath = NULL; char xpath[1024]; noit_conf_t_userdata_t *info = NULL; noit_hash_table *config; xmlXPathObjectPtr pobj = NULL; xmlXPathContextPtr xpath_ctxt = NULL, current_ctxt; xmlDocPtr master_config = NULL; xmlNodePtr node = NULL; noit_conf_xml_xpath(&master_config, &xpath_ctxt); if(argc > 1) { nc_printf(ncct, "too many arguments\n"); return -1; } info = noit_console_userdata_get(ncct, NOIT_CONF_T_USERDATA); if(info && info->path) path = basepath = info->path; if(!info && argc == 0) { nc_printf(ncct, "argument required when not in configuration mode\n"); return -1; } if(argc == 1) path = argv[0]; if(!basepath) basepath = path; /* { / } is a special case */ if(!strcmp(basepath, "/")) basepath = ""; if(!strcmp(path, "/")) path = ""; if(!master_config) { nc_printf(ncct, "no config\n"); return -1; } /* { / } is the only path that will end with a / * in XPath { / / * } means something _entirely different than { / * } * Ever notice how it is hard to describe xpath in C comments? */ /* We don't want to show the root node */ cliplen = strlen("/noit/"); /* If we are in configuration mode * and we are without an argument or the argument is absolute, * clip the current path off */ if(info && (argc == 0 || path[0] != '/')) cliplen += strlen(basepath); if(!path[0] || path[0] == '/') /* base only, or absolute path requested */ snprintf(xpath, sizeof(xpath), "/noit%s/@*", path); else snprintf(xpath, sizeof(xpath), "/noit%s/%s/@*", basepath, path); current_ctxt = xpath_ctxt; pobj = xmlXPathEval((xmlChar *)xpath, current_ctxt); if(!pobj || pobj->type != XPATH_NODESET) { nc_printf(ncct, "no such object\n"); goto bad; } cnt = xmlXPathNodeSetGetLength(pobj->nodesetval); titled = 0; for(i=0; i<cnt; i++) { node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, i); if(!strcmp((char *)node->name, "check")) continue; if(node->children && node->children == xmlGetLastChild(node) && xmlNodeIsText(node->children)) { if(!titled++) nc_printf(ncct, "== Section Settings ==\n"); nc_printf(ncct, "%s: %s\n", xmlGetNodePath(node) + cliplen, xmlXPathCastNodeToString(node->children)); } } xmlXPathFreeObject(pobj); /* Print out all the config settings */ if(!path[0] || path[0] == '/') /* base only, or absolute path requested */ snprintf(xpath, sizeof(xpath), "/noit%s", path); else snprintf(xpath, sizeof(xpath), "/noit%s/%s", basepath, path); pobj = xmlXPathEval((xmlChar *)xpath, current_ctxt); if(!pobj || pobj->type != XPATH_NODESET) { nc_printf(ncct, "no such object\n"); goto bad; } cnt = xmlXPathNodeSetGetLength(pobj->nodesetval); if(cnt > 0) { node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, 0); titled = 0; config = noit_conf_get_hash(node, "config"); while(noit_hash_next(config, &iter, &k, &klen, &data)) { if(!titled++) nc_printf(ncct, "== Section [Aggregated] Config ==\n"); nc_printf(ncct, "config::%s: %s\n", k, (const char *)data); } noit_hash_destroy(config, free, free); free(config); } xmlXPathFreeObject(pobj); /* _shorten string_ turning last { / @ * } to { / * } */ if(!path[0] || path[0] == '/') /* base only, or absolute path requested */ snprintf(xpath, sizeof(xpath), "/noit%s/*", path); else snprintf(xpath, sizeof(xpath), "/noit%s/%s/*", basepath, path); pobj = xmlXPathEval((xmlChar *)xpath, current_ctxt); if(!pobj || pobj->type != XPATH_NODESET) { nc_printf(ncct, "no such object\n"); goto bad; } cnt = xmlXPathNodeSetGetLength(pobj->nodesetval); titled = 0; for(i=0; i<cnt; i++) { node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, i); if(!strcmp((char *)node->name, "check")) continue; if(!strcmp((char *)node->name, "filterset")) continue; if(!strcmp((char *)xmlGetNodePath(node) + cliplen, "config")) continue; if(!(node->children && node->children == xmlGetLastChild(node) && xmlNodeIsText(node->children))) { if(!titled++) nc_printf(ncct, "== Subsections ==\n"); nc_printf(ncct, "%s\n", xmlGetNodePath(node) + cliplen); } } titled = 0; for(i=0; i<cnt; i++) { node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, i); if(!strcmp((char *)node->name, "filterset")) { xmlAttr *attr; char *filter_name = NULL; for(attr=node->properties; attr; attr = attr->next) { if(!strcmp((char *)attr->name, "name")) filter_name = (char *)xmlXPathCastNodeToString(attr->children); } if(filter_name) { nc_printf(ncct, "filterset[@name=\"%s\"]\n", filter_name); xmlFree(filter_name); } else nc_printf(ncct, "fitlerset\n"); } else if(!strcmp((char *)node->name, "check")) { int busted = 1; xmlAttr *attr; char *uuid_str = "undefined"; if(!titled++) nc_printf(ncct, "== Checks ==\n"); for(attr=node->properties; attr; attr = attr->next) { if(!strcmp((char *)attr->name, "uuid")) uuid_str = (char *)xmlXPathCastNodeToString(attr->children); } if(uuid_str) { uuid_t checkid; nc_printf(ncct, "check[@uuid=\"%s\"] ", uuid_str); if(uuid_parse(uuid_str, checkid) == 0) { noit_check_t *check; check = noit_poller_lookup(checkid); if(check) { busted = 0; nc_printf(ncct, "%s`%s`%s", check->target, check->module, check->name); } } } else nc_printf(ncct, "%s ", xmlGetNodePath(node) + cliplen); if(busted) nc_printf(ncct, "[check not in running system]"); nc_write(ncct, "\n", 1); } } xmlXPathFreeObject(pobj); return 0; bad: if(pobj) xmlXPathFreeObject(pobj); return -1; }
static int noit_console_config_nocheck(noit_console_closure_t ncct, int argc, char **argv, noit_console_state_t *state, void *closure) { int i, cnt; const char *err = "internal error"; noit_conf_t_userdata_t *info; xmlXPathObjectPtr pobj = NULL; xmlXPathContextPtr xpath_ctxt = NULL; char xpath[1024]; uuid_t checkid; noit_conf_xml_xpath(NULL, &xpath_ctxt); if(argc < 1) { nc_printf(ncct, "requires one argument\n"); return -1; } info = noit_console_userdata_get(ncct, NOIT_CONF_T_USERDATA); if(noit_console_mkcheck_xpath(xpath, sizeof(xpath), info, argv[0])) { nc_printf(ncct, "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)) { err = "no checks found"; goto bad; } cnt = xmlXPathNodeSetGetLength(pobj->nodesetval); for(i=0; i<cnt; i++) { 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")); } else { if(argc > 1) { int j; for(j=1;j<argc;j++) xmlUnsetProp(node, (xmlChar *)argv[j]); } else { nc_printf(ncct, "descheduling %s\n", uuid_conf); noit_poller_deschedule(checkid); xmlUnlinkNode(node); } noit_conf_mark_changed(); } } if(argc > 1) { noit_poller_process_checks(xpath); noit_poller_reload(xpath); } nc_printf(ncct, "rebuilding causal map...\n"); noit_poller_make_causal_map(); if(pobj) xmlXPathFreeObject(pobj); return 0; bad: if(pobj) xmlXPathFreeObject(pobj); nc_printf(ncct, "%s\n", err); return -1; }
static int noit_console_show_check(noit_console_closure_t ncct, int argc, char **argv, noit_console_state_t *state, void *closure) { int i, cnt; noit_conf_t_userdata_t *info; char xpath[1024]; xmlXPathObjectPtr pobj = NULL; xmlXPathContextPtr xpath_ctxt = NULL; noit_conf_xml_xpath(NULL, &xpath_ctxt); if(argc > 1) { nc_printf(ncct, "requires zero or one arguments\n"); return -1; } info = noit_console_userdata_get(ncct, NOIT_CONF_T_USERDATA); /* We many not be in conf-t mode -- that's fine */ if(noit_console_mkcheck_xpath(xpath, sizeof(xpath), info, argc ? argv[0] : NULL)) { nc_printf(ncct, "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); if(info && cnt != 1) { nc_printf(ncct, "Ambiguous check specified\n"); goto out; } for(i=0; i<cnt; i++) { noit_hash_iter iter = NOIT_HASH_ITER_ZERO; const char *k; int klen; void *data; uuid_t checkid; noit_check_t *check; noit_hash_table *config; xmlNodePtr node, anode, mnode = NULL; char *uuid_conf; char *module, *value; 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; } nc_printf(ncct, "==== %s ====\n", uuid_conf); #define MYATTR(a,n,b) _noit_conf_get_string(node, &(n), "@" #a, &(b)) #define INHERIT(a,n,b) \ _noit_conf_get_string(node, &(n), "ancestor-or-self::node()/@" #a, &(b)) #define SHOW_ATTR(a) do { \ anode = NULL; \ value = NULL; \ INHERIT(a, anode, value); \ nc_attr_show(ncct, #a, node, anode, value); \ } while(0) if(!INHERIT(module, mnode, module)) module = NULL; if(MYATTR(name, anode, value)) nc_printf(ncct, " name: %s\n", value); else nc_printf(ncct, " name: %s [from module]\n", module ? module : "[undef]"); nc_attr_show(ncct, "module", node, mnode, module); SHOW_ATTR(target); SHOW_ATTR(period); SHOW_ATTR(timeout); SHOW_ATTR(oncheck); SHOW_ATTR(filterset); SHOW_ATTR(disable); /* Print out all the config settings */ config = noit_conf_get_hash(node, "config"); while(noit_hash_next(config, &iter, &k, &klen, &data)) { nc_printf(ncct, " config::%s: %s\n", k, (const char *)data); } noit_hash_destroy(config, free, free); free(config); check = noit_poller_lookup(checkid); if(!check) { nc_printf(ncct, " ERROR: not in running system\n"); } else { int idx = 0; nc_printf(ncct, " currently: "); if(NOIT_CHECK_RUNNING(check)) nc_printf(ncct, "%srunning", idx++?",":""); if(NOIT_CHECK_KILLED(check)) nc_printf(ncct, "%skilled", idx++?",":""); if(!NOIT_CHECK_CONFIGURED(check)) nc_printf(ncct, "%sunconfig", idx++?",":""); if(NOIT_CHECK_DISABLED(check)) nc_printf(ncct, "%sdisabled", idx++?",":""); if(!idx) nc_printf(ncct, "idle"); nc_write(ncct, "\n", 1); if(check->stats.current.whence.tv_sec == 0) { nc_printf(ncct, " last run: never\n"); } else { stats_t *c = &check->stats.current; struct timeval now, diff; gettimeofday(&now, NULL); sub_timeval(now, c->whence, &diff); nc_printf(ncct, " last run: %0.3f seconds ago\n", diff.tv_sec + (diff.tv_usec / 1000000.0)); nc_printf(ncct, " availability/state: %s/%s\n", noit_check_available_string(c->available), noit_check_state_string(c->state)); nc_printf(ncct, " status: %s\n", c->status ? c->status : "[[null]]"); nc_printf(ncct, " metrics:\n"); memset(&iter, 0, sizeof(iter)); while(noit_hash_next(&c->metrics, &iter, &k, &klen, &data)) { char buff[256]; noit_boolean filtered; noit_stats_snprint_metric(buff, sizeof(buff), (metric_t *)data); filtered = !noit_apply_filterset(check->filterset, check, (metric_t *)data); nc_printf(ncct, " %c%s\n", filtered ? '*' : ' ', buff); } } } } out: if(pobj) xmlXPathFreeObject(pobj); return 0; }
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; }
//! Returns a node by index (NULL if index is invalid). //----------------------------------------------------------------------- static node_type item(nodeset_type const ns, index_type index) { return xmlXPathNodeSetItem(ns, index); }
/** * xmlSecNodeSetDebugDump: * @nset: the pointer to node set. * @output: the pointer to output FILE. * * Prints information about @nset to the @output. */ EXPORT_C void xmlSecNodeSetDebugDump(xmlSecNodeSetPtr nset, FILE *output) { int i, l; xmlNodePtr cur; xmlSecAssert(nset != NULL); xmlSecAssert(output != NULL); fprintf(output, "== Nodes set "); switch(nset->type) { case xmlSecNodeSetNormal: fprintf(output, "(xmlSecNodeSetNormal)\n"); break; case xmlSecNodeSetInvert: fprintf(output, "(xmlSecNodeSetInvert)\n"); break; case xmlSecNodeSetTree: fprintf(output, "(xmlSecNodeSetTree)\n"); break; case xmlSecNodeSetTreeWithoutComments: fprintf(output, "(xmlSecNodeSetTreeWithoutComments)\n"); break; case xmlSecNodeSetTreeInvert: fprintf(output, "(xmlSecNodeSetTreeInvert)\n"); break; case xmlSecNodeSetTreeWithoutCommentsInvert: fprintf(output, "(xmlSecNodeSetTreeWithoutCommentsInvert)\n"); break; case xmlSecNodeSetList: fprintf(output, "(xmlSecNodeSetList)\n"); fprintf(output, ">>>\n"); xmlSecNodeSetDebugDump(nset->children, output); fprintf(output, "<<<\n"); return; default: fprintf(output, "(unknown=%d)\n", nset->type); xmlSecError(XMLSEC_ERRORS_HERE, NULL, NULL, XMLSEC_ERRORS_R_INVALID_TYPE, "type=%d", nset->type); } l = xmlXPathNodeSetGetLength(nset->nodes); for(i = 0; i < l; ++i) { cur = xmlXPathNodeSetItem(nset->nodes, i); if(cur->type != XML_NAMESPACE_DECL) { fprintf(output, "%d: %s\n", cur->type, (cur->name) ? cur->name : BAD_CAST "null"); } else { xmlNsPtr ns = (xmlNsPtr)cur; fprintf(output, "%d: %s=%s (%s:%s)\n", cur->type, (ns->prefix) ? ns->prefix : BAD_CAST "null", (ns->href) ? ns->href : BAD_CAST "null", (((xmlNodePtr)ns->next)->ns && ((xmlNodePtr)ns->next)->ns->prefix) ? ((xmlNodePtr)ns->next)->ns->prefix : BAD_CAST "null", ((xmlNodePtr)ns->next)->name); } } }
static gboolean _lt_ext_ldml_u_lookup_type(lt_ext_ldml_u_data_t *data, const gchar *subtag, GError **error) { lt_xml_t *xml = NULL; xmlDocPtr doc; xmlXPathContextPtr xctxt = NULL; xmlXPathObjectPtr xobj = NULL; gint i, n; gchar key[4], *xpath_string = NULL; GList *l; GString *s; gboolean retval = FALSE; g_return_val_if_fail (data->current_type > 0, FALSE); l = g_list_last(data->tags); if (l == NULL) { g_set_error(error, LT_ERROR, LT_ERR_FAIL_ON_SCANNER, "Invalid internal state. failed to find a key container."); goto bail; } s = l->data; strncpy(key, s->str, 2); key[2] = 0; xml = lt_xml_new(); doc = lt_xml_get_cldr(xml, data->current_type); xctxt = xmlXPathNewContext(doc); if (!xctxt) { g_set_error(error, LT_ERROR, LT_ERR_OOM, "Unable to create an instance of xmlXPathContextPtr."); goto bail; } xpath_string = g_strdup_printf("/ldmlBCP47/keyword/key[@name = '%s']", key); xobj = xmlXPathEvalExpression((const xmlChar *)xpath_string, xctxt); if (!xobj) { g_set_error(error, LT_ERROR, LT_ERR_FAIL_ON_XML, "No valid elements for %s: %s", doc->name, xpath_string); goto bail; } n = xmlXPathNodeSetGetLength(xobj->nodesetval); for (i = 0; i < n; i++) { xmlNodePtr ent = xmlXPathNodeSetItem(xobj->nodesetval, i); xmlNodePtr cnode; xmlChar *name; if (!ent) { g_set_error(error, LT_ERROR, LT_ERR_FAIL_ON_XML, "Unable to obtain the xml node via XPath."); goto bail; } cnode = ent->children; while (cnode != NULL) { if (xmlStrcmp(cnode->name, (const xmlChar *)"type") == 0) { name = xmlGetProp(cnode, (const xmlChar *)"name"); if (name && g_ascii_strcasecmp((const gchar *)name, subtag) == 0) { retval = TRUE; xmlFree(name); goto bail; } else if (g_strcmp0((const gchar *)name, "CODEPOINTS") == 0) { gsize len = strlen(subtag), j; static const gchar *hexdigit = "0123456789abcdefABCDEF"; gchar *p; guint64 x; /* an exception to deal with the unicode code point. */ if (len >= 4 && len <= 6) { for (j = 0; j < len; j++) { if (!strchr(hexdigit, subtag[j])) goto bail2; } x = g_ascii_strtoull(subtag, &p, 16); if (p && p[0] == 0 && x <= 0x10ffff) { retval = TRUE; xmlFree(name); goto bail; } } bail2:; } xmlFree(name); } else if (xmlStrcmp(cnode->name, (const xmlChar *)"text") == 0) { /* ignore */ } else { g_warning("Unknown node under /ldmlBCP47/keyword/key: %s", cnode->name); } cnode = cnode->next; } } bail: g_free(xpath_string); if (xobj) xmlXPathFreeObject(xobj); if (xctxt) xmlXPathFreeContext(xctxt); if (xml) lt_xml_unref(xml); return retval; }
static int noit_console_show_check(mtev_console_closure_t ncct, int argc, char **argv, mtev_console_state_t *state, void *closure) { int i, cnt; mtev_conf_t_userdata_t *info; char xpath[1024]; xmlXPathObjectPtr pobj = NULL; xmlXPathContextPtr xpath_ctxt = NULL; mtev_conf_xml_xpath(NULL, &xpath_ctxt); if(argc > 1) { nc_printf(ncct, "requires zero or one arguments\n"); return -1; } info = mtev_console_userdata_get(ncct, MTEV_CONF_T_USERDATA); /* We many not be in conf-t mode -- that's fine */ if(noit_console_mkcheck_xpath(xpath, sizeof(xpath), info, argc ? argv[0] : NULL)) { nc_printf(ncct, "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); if(info && cnt != 1) { nc_printf(ncct, "Ambiguous check specified\n"); goto out; } for(i=0; i<cnt; i++) { mtev_hash_iter iter = MTEV_HASH_ITER_ZERO; const char *k; int klen; void *data; uuid_t checkid; noit_check_t *check; mtev_hash_table *config; xmlNodePtr node, anode, mnode = NULL; char *uuid_conf; char *module, *value; node = (mtev_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; } nc_printf(ncct, "==== %s ====\n", uuid_conf); xmlFree(uuid_conf); #define MYATTR(a,n,b) _mtev_conf_get_string(node, &(n), "@" #a, &(b)) #define INHERIT(a,n,b) \ _mtev_conf_get_string(node, &(n), "ancestor-or-self::node()/@" #a, &(b)) #define SHOW_ATTR(a) do { \ anode = NULL; \ value = NULL; \ INHERIT(a, anode, value); \ nc_attr_show(ncct, #a, node, anode, value); \ if(value != NULL) free(value); \ } while(0) if(!INHERIT(module, mnode, module)) module = NULL; if(MYATTR(name, anode, value)) { nc_printf(ncct, " name: %s\n", value); free(value); } else nc_printf(ncct, " name: %s [from module]\n", module ? module : "[undef]"); nc_attr_show(ncct, "module", node, mnode, module); if(module) free(module); SHOW_ATTR(target); SHOW_ATTR(seq); SHOW_ATTR(resolve_rtype); SHOW_ATTR(period); SHOW_ATTR(timeout); SHOW_ATTR(oncheck); SHOW_ATTR(filterset); SHOW_ATTR(disable); /* Print out all the config settings */ config = mtev_conf_get_hash(node, "config"); while(mtev_hash_next(config, &iter, &k, &klen, &data)) { nc_printf(ncct, " config::%s: %s\n", k, (const char *)data); } mtev_hash_destroy(config, free, free); free(config); check = noit_poller_lookup(checkid); if(!check) { nc_printf(ncct, " ERROR: not in running system\n"); } else { int idx = 0; stats_t *c; struct timeval *whence; mtev_hash_table *metrics; nc_printf(ncct, " target_ip: %s\n", check->target_ip); nc_printf(ncct, " currently: %08x ", check->flags); if(NOIT_CHECK_RUNNING(check)) { nc_printf(ncct, "running"); idx++; } if(NOIT_CHECK_KILLED(check)) nc_printf(ncct, "%skilled", idx++?",":""); if(!NOIT_CHECK_CONFIGURED(check)) nc_printf(ncct, "%sunconfig", idx++?",":""); if(NOIT_CHECK_DISABLED(check)) nc_printf(ncct, "%sdisabled", idx++?",":""); if(!idx) nc_printf(ncct, "idle"); nc_write(ncct, "\n", 1); if (check->fire_event != NULL) { struct timeval now, diff; mtev_gettimeofday(&now, NULL); sub_timeval(check->fire_event->whence, now, &diff); nc_printf(ncct, " next run: %0.3f seconds\n", diff.tv_sec + (diff.tv_usec / 1000000.0)); } else { nc_printf(ncct, " next run: unscheduled\n"); } c = noit_check_get_stats_current(check); whence = noit_check_stats_whence(c, NULL); if(whence->tv_sec == 0) { nc_printf(ncct, " last run: never\n"); } else { const char *status; struct timeval now, *then, diff; mtev_gettimeofday(&now, NULL); then = noit_check_stats_whence(c, NULL); sub_timeval(now, *then, &diff); nc_printf(ncct, " last run: %0.3f seconds ago\n", diff.tv_sec + (diff.tv_usec / 1000000.0)); nc_printf(ncct, " availability/state: %s/%s\n", noit_check_available_string(noit_check_stats_available(c, NULL)), noit_check_state_string(noit_check_stats_state(c, NULL))); status = noit_check_stats_status(c, NULL); nc_printf(ncct, " status: %s\n", status); nc_printf(ncct, " feeds: %d\n", check->feeds ? check->feeds->size : 0); } c = noit_check_get_stats_inprogress(check); metrics = noit_check_stats_metrics(c); if(mtev_hash_size(metrics) > 0) { nc_printf(ncct, " metrics (inprogress):\n"); nc_print_stat_metrics(ncct, check, c); } c = noit_check_get_stats_current(check); metrics = noit_check_stats_metrics(c); if(mtev_hash_size(metrics)) { nc_printf(ncct, " metrics (current):\n"); nc_print_stat_metrics(ncct, check, c); } c = noit_check_get_stats_previous(check); metrics = noit_check_stats_metrics(c); if(mtev_hash_size(metrics) > 0) { nc_printf(ncct, " metrics (previous):\n"); nc_print_stat_metrics(ncct, check, c); } } } out: if(pobj) xmlXPathFreeObject(pobj); return 0; }
static gboolean rygel_mediathek_rss_container_parse_response (RygelMediathekRssContainer* self, const char* data, gsize length) { #line 178 "rygel-mediathek-rss-container.c" gboolean result = FALSE; GError * _inner_error_; gboolean ret; xmlDoc* doc; #line 52 "rygel-mediathek-rss-container.vala" g_return_val_if_fail (self != NULL, FALSE); #line 52 "rygel-mediathek-rss-container.vala" g_return_val_if_fail (data != NULL, FALSE); #line 187 "rygel-mediathek-rss-container.c" _inner_error_ = NULL; #line 53 "rygel-mediathek-rss-container.vala" ret = FALSE; #line 54 "rygel-mediathek-rss-container.vala" doc = xmlParseMemory (data, (gint) length); #line 55 "rygel-mediathek-rss-container.vala" if (doc != NULL) { #line 195 "rygel-mediathek-rss-container.c" xmlXPathContext* ctx; xmlXPathObject* xpo; gboolean _tmp0_ = FALSE; #line 56 "rygel-mediathek-rss-container.vala" gee_abstract_collection_clear ((GeeAbstractCollection*) ((RygelSimpleContainer*) self)->children); #line 57 "rygel-mediathek-rss-container.vala" ((RygelMediaContainer*) self)->child_count = 0; #line 59 "rygel-mediathek-rss-container.vala" ctx = xmlXPathNewContext (doc); #line 60 "rygel-mediathek-rss-container.vala" xpo = xmlXPathEval ("/rss/channel/title", ctx); #line 61 "rygel-mediathek-rss-container.vala" if (xpo->type == XPATH_NODESET) { #line 62 "rygel-mediathek-rss-container.vala" _tmp0_ = xmlXPathNodeSetGetLength (xpo->nodesetval) > 0; #line 211 "rygel-mediathek-rss-container.c" } else { #line 61 "rygel-mediathek-rss-container.vala" _tmp0_ = FALSE; #line 215 "rygel-mediathek-rss-container.c" } #line 61 "rygel-mediathek-rss-container.vala" if (_tmp0_) { #line 219 "rygel-mediathek-rss-container.c" char* _tmp1_; #line 64 "rygel-mediathek-rss-container.vala" rygel_media_object_set_title ((RygelMediaObject*) self, _tmp1_ = xmlNodeGetContent (xmlXPathNodeSetItem (xpo->nodesetval, 0))); #line 223 "rygel-mediathek-rss-container.c" _g_free0 (_tmp1_); } #line 67 "rygel-mediathek-rss-container.vala" xpo = xmlXPathEval ("/rss/channel/item", ctx); #line 68 "rygel-mediathek-rss-container.vala" if (xpo->type == XPATH_NODESET) { #line 230 "rygel-mediathek-rss-container.c" { gint i; #line 69 "rygel-mediathek-rss-container.vala" i = 0; #line 235 "rygel-mediathek-rss-container.c" { gboolean _tmp2_; #line 69 "rygel-mediathek-rss-container.vala" _tmp2_ = TRUE; #line 69 "rygel-mediathek-rss-container.vala" while (TRUE) { #line 242 "rygel-mediathek-rss-container.c" xmlNode* node; #line 69 "rygel-mediathek-rss-container.vala" if (!_tmp2_) { #line 69 "rygel-mediathek-rss-container.vala" i++; #line 248 "rygel-mediathek-rss-container.c" } #line 69 "rygel-mediathek-rss-container.vala" _tmp2_ = FALSE; #line 69 "rygel-mediathek-rss-container.vala" if (!(i < xmlXPathNodeSetGetLength (xpo->nodesetval))) { #line 69 "rygel-mediathek-rss-container.vala" break; #line 256 "rygel-mediathek-rss-container.c" } #line 70 "rygel-mediathek-rss-container.vala" node = xmlXPathNodeSetItem (xpo->nodesetval, i); #line 260 "rygel-mediathek-rss-container.c" { RygelMediathekVideoItem* item; #line 73 "rygel-mediathek-rss-container.vala" item = rygel_mediathek_video_item_create_from_xml ((RygelMediaContainer*) self, node, &_inner_error_); #line 265 "rygel-mediathek-rss-container.c" if (_inner_error_ != NULL) { if (_inner_error_->domain == RYGEL_MEDIATHEK_VIDEO_ITEM_ERROR) { goto __catch3_rygel_mediathek_video_item_error; } _xmlXPathFreeContext0 (ctx); g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code); g_clear_error (&_inner_error_); return FALSE; } #line 75 "rygel-mediathek-rss-container.vala" rygel_simple_container_add_child ((RygelSimpleContainer*) self, (RygelMediaObject*) item); #line 76 "rygel-mediathek-rss-container.vala" ret = TRUE; #line 279 "rygel-mediathek-rss-container.c" _g_object_unref0 (item); } goto __finally3; __catch3_rygel_mediathek_video_item_error: { GError * _error_; _error_ = _inner_error_; _inner_error_ = NULL; { #line 79 "rygel-mediathek-rss-container.vala" g_warning (_ ("Error creating video item: %s"), _error_->message); #line 291 "rygel-mediathek-rss-container.c" _g_error_free0 (_error_); } } __finally3: if (_inner_error_ != NULL) { _xmlXPathFreeContext0 (ctx); g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code); g_clear_error (&_inner_error_); return FALSE; } } } } } else { #line 85 "rygel-mediathek-rss-container.vala" g_warning ("rygel-mediathek-rss-container.vala:85: %s", _ ("XPath query failed")); #line 308 "rygel-mediathek-rss-container.c" } #line 88 "rygel-mediathek-rss-container.vala" xmlFreeDoc (doc); #line 89 "rygel-mediathek-rss-container.vala" rygel_media_container_updated ((RygelMediaContainer*) self); #line 314 "rygel-mediathek-rss-container.c" _xmlXPathFreeContext0 (ctx); } else { #line 92 "rygel-mediathek-rss-container.vala" g_warning ("rygel-mediathek-rss-container.vala:92: %s", _ ("Failed to parse doc")); #line 319 "rygel-mediathek-rss-container.c" } result = ret; #line 95 "rygel-mediathek-rss-container.vala" return result; #line 324 "rygel-mediathek-rss-container.c" }
static int rest_show_check(noit_http_rest_closure_t *restc, int npats, char **pats) { noit_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, *value; int rv, cnt, error_code = 500; noit_hash_iter iter = NOIT_HASH_ITER_ZERO; const char *k; int klen; void *data; noit_hash_table *configh; if(npats != 2) goto error; rv = noit_check_xpath(xpath, sizeof(xpath), pats[0], pats[1]); if(rv == 0) goto not_found; if(rv < 0) goto error; noit_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 = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, 0); uuid_conf = (char *)xmlGetProp(node, (xmlChar *)"uuid"); if(!uuid_conf || uuid_parse(uuid_conf, checkid)) goto error; doc = xmlNewDoc((xmlChar *)"1.0"); root = xmlNewDocNode(doc, NULL, (xmlChar *)"check", NULL); xmlDocSetRootElement(doc, root); #define MYATTR(node,a,n,b) _noit_conf_get_string(node, &(n), "@" #a, &(b)) #define INHERIT(node,a,n,b) \ _noit_conf_get_string(node, &(n), "ancestor-or-self::node()/@" #a, &(b)) #define SHOW_ATTR(parent, node, a) do { \ xmlNodePtr anode = NULL; \ char *value = NULL; \ INHERIT(node, a, anode, value); \ if(value != NULL) { \ int clen, plen;\ const char *cpath, *apath; \ xmlNodePtr child; \ cpath = node ? (char *)xmlGetNodePath(node) : ""; \ apath = anode ? (char *)xmlGetNodePath(anode) : ""; \ 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); \ } \ } while(0) attr = xmlNewNode(NULL, (xmlChar *)"attributes"); xmlAddChild(root, attr); SHOW_ATTR(attr,node,uuid); /* 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); SHOW_ATTR(attr,node,module); SHOW_ATTR(attr,node,target); 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 = noit_conf_get_hash(node, "config"); while(noit_hash_next(configh, &iter, &k, &klen, &data)) NODE_CONTENT(config, k, data); noit_hash_destroy(configh, free, free); free(configh); xmlAddChild(root, config); /* Add the state */ check = noit_poller_lookup(checkid); if(!check) { state = xmlNewNode(NULL, (xmlChar *)"state"); xmlSetProp(state, (xmlChar *)"error", (xmlChar *)"true"); } else state = noit_check_state_as_xml(check); xmlAddChild(root, state); noit_http_response_ok(ctx, "text/xml"); noit_http_response_xml(ctx, doc); noit_http_response_end(ctx); goto cleanup; not_found: noit_http_response_not_found(ctx, "text/html"); noit_http_response_end(ctx); goto cleanup; error: noit_http_response_standard(ctx, error_code, "ERROR", "text/html"); noit_http_response_end(ctx); goto cleanup; cleanup: if(pobj) xmlXPathFreeObject(pobj); if(doc) xmlFreeDoc(doc); return 0; }
static int replace_attr(noit_console_closure_t ncct, noit_conf_t_userdata_t *info, struct _valid_attr_t *attrinfo, const char *value) { int i, cnt, rv = -1, active = 0; xmlXPathObjectPtr pobj = NULL; xmlXPathContextPtr xpath_ctxt = NULL; xmlNodePtr node; char xpath[1024], *path; path = info->path; if(!strcmp(path, "/")) path = ""; noit_conf_xml_xpath(NULL, &xpath_ctxt); if(attrinfo->checks_fixate) { /* Only if checks will fixate this attribute shall we check for * child <check> nodes. * NOTE: this return nothing and "seems" okay if we are _in_ * a <check> node. That case is handled below. */ snprintf(xpath, sizeof(xpath), "/noit/%s//check[@uuid]", path); pobj = xmlXPathEval((xmlChar *)xpath, xpath_ctxt); if(!pobj || pobj->type != XPATH_NODESET) goto out; cnt = xmlXPathNodeSetGetLength(pobj->nodesetval); for(i=0; i<cnt; i++) { uuid_t checkid; node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, i); if(noit_conf_get_uuid(node, "@uuid", checkid)) { noit_check_t *check; check = noit_poller_lookup(checkid); if(check && NOIT_CHECK_LIVE(check)) active++; } } if(pobj) xmlXPathFreeObject(pobj); } snprintf(xpath, sizeof(xpath), "/noit/%s", path); pobj = xmlXPathEval((xmlChar *)xpath, xpath_ctxt); if(!pobj || pobj->type != XPATH_NODESET) goto out; cnt = xmlXPathNodeSetGetLength(pobj->nodesetval); if(cnt != 1) { nc_printf(ncct, "Internal error: context node disappeared\n"); goto out; } node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, 0); if(attrinfo->checks_fixate && !strcmp((const char *)node->name, "check")) { uuid_t checkid; /* Detect if we are actually a <check> node and attempting to * change something we shouldn't. * This is the counterpart noted above. */ if(noit_conf_get_uuid(node, "@uuid", checkid)) { noit_check_t *check; check = noit_poller_lookup(checkid); if(check && NOIT_CHECK_LIVE(check)) active++; } } if(active) { nc_printf(ncct, "Cannot set '%s', it would effect %d live check(s)\n", attrinfo->name, active); goto out; } xmlUnsetProp(node, (xmlChar *)attrinfo->name); if(value) xmlSetProp(node, (xmlChar *)attrinfo->name, (xmlChar *)value); noit_conf_mark_changed(); rv = 0; out: if(pobj) xmlXPathFreeObject(pobj); return rv; }
/*< private >*/ static gboolean lt_region_db_parse(lt_region_db_t *regiondb, GError **error) { gboolean retval = TRUE; xmlDocPtr doc = NULL; xmlXPathContextPtr xctxt = NULL; xmlXPathObjectPtr xobj = NULL; GError *err = NULL; int i, n; g_return_val_if_fail (regiondb != NULL, FALSE); doc = lt_xml_get_subtag_registry(regiondb->xml); xctxt = xmlXPathNewContext(doc); if (!xctxt) { g_set_error(&err, LT_ERROR, LT_ERR_OOM, "Unable to create an instance of xmlXPathContextPtr."); goto bail; } xobj = xmlXPathEvalExpression((const xmlChar *)"/registry/region", xctxt); if (!xobj) { g_set_error(&err, LT_ERROR, LT_ERR_FAIL_ON_XML, "No valid elements for %s", doc->name); goto bail; } n = xmlXPathNodeSetGetLength(xobj->nodesetval); for (i = 0; i < n; i++) { xmlNodePtr ent = xmlXPathNodeSetItem(xobj->nodesetval, i); xmlNodePtr cnode; xmlChar *subtag = NULL, *desc = NULL, *preferred = NULL; lt_region_t *le = NULL; gchar *s; if (!ent) { g_set_error(&err, LT_ERROR, LT_ERR_FAIL_ON_XML, "Unable to obtain the xml node via XPath."); goto bail; } cnode = ent->children; while (cnode != NULL) { if (xmlStrcmp(cnode->name, (const xmlChar *)"subtag") == 0) { if (subtag) { g_warning("Duplicate subtag element in region: previous value was '%s'", subtag); } else { subtag = xmlNodeGetContent(cnode); } } else if (xmlStrcmp(cnode->name, (const xmlChar *)"added") == 0 || xmlStrcmp(cnode->name, (const xmlChar *)"text") == 0 || xmlStrcmp(cnode->name, (const xmlChar *)"deprecated") == 0 || xmlStrcmp(cnode->name, (const xmlChar *)"comments") == 0) { /* ignore it */ } else if (xmlStrcmp(cnode->name, (const xmlChar *)"description") == 0) { /* wonder if many descriptions helps something. or is it a bug? */ if (!desc) desc = xmlNodeGetContent(cnode); } else if (xmlStrcmp(cnode->name, (const xmlChar *)"preferred-value") == 0) { if (preferred) { g_warning("Duplicate preferred-value element in region: previous value was '%s'", preferred); } else { preferred = xmlNodeGetContent(cnode); } } else { g_warning("Unknown node under /registry/region: %s", cnode->name); } cnode = cnode->next; } if (!subtag) { g_warning("No subtag node: description = '%s', preferred-value = '%s'", desc, preferred); goto bail1; } if (!desc) { g_warning("No description node: subtag = '%s', preferred-value = '%s'", subtag, preferred); goto bail1; } le = lt_region_create(); if (!le) { g_set_error(&err, LT_ERROR, LT_ERR_OOM, "Unable to create an instance of lt_region_t."); goto bail1; } lt_region_set_tag(le, (const gchar *)subtag); lt_region_set_name(le, (const gchar *)desc); if (preferred) lt_region_set_preferred_tag(le, (const gchar *)preferred); s = g_strdup(lt_region_get_tag(le)); g_hash_table_replace(regiondb->region_entries, lt_strlower(s), lt_region_ref(le)); bail1: if (subtag) xmlFree(subtag); if (desc) xmlFree(desc); if (preferred) xmlFree(preferred); lt_region_unref(le); } bail: if (err) { if (error) *error = g_error_copy(err); else g_warning(err->message); g_error_free(err); retval = FALSE; } if (xobj) xmlXPathFreeObject(xobj); if (xctxt) xmlXPathFreeContext(xctxt); return retval; }
/** This extension function is designed to be used in a sanity test with an * XPath expression like this: * "//entry[ fd:unbalanced-braces(.//orth | .//tr | .//note | .//def | .//q) ]" * Before its use, a namespace prefix like "fd" has to be bound to * FREEDICT_EDITOR_NAMESPACE. */ static void freedict_xpath_extension_unbalanced_braces( xmlXPathParserContextPtr ctxt, const int nargs) { if(nargs != 1) { xmlXPathSetArityError(ctxt); return; } xmlNodeSetPtr ns = xmlXPathPopNodeSet(ctxt); if(xmlXPathCheckError(ctxt) || !ns) { xmlXPathFreeNodeSet(ns); return; } // function that does the actual parsing // returns TRUE if a brace of the string in c does not have // a corresponding brace gboolean contains_unbalanced_braces(xmlChar *c) { if(!c) return FALSE; char stack[100]; int stackend = sizeof(stack); // returns FALSE on stack full gboolean cub_push(const char b) { if(!stackend) { g_printerr(G_STRLOC ": Too many open braces"); return FALSE; } stack[--stackend] = b; return TRUE; } gchar cub_pop() { // stack is empty if(stackend>=sizeof(stack)) return 'E'; return stack[stackend++]; } do { switch(*c) { case '(': if(!cub_push('(')) return TRUE; break; case '[': if(!cub_push('[')) return TRUE; break; case '{': if(!cub_push('{')) return TRUE; break; case ')': if(cub_pop()!='(') return TRUE;break; case ']': if(cub_pop()!='[') return TRUE;break; case '}': if(cub_pop()!='{') return TRUE;break; // all other characters are skipped } c++; } while(*c); // braces left open? if(cub_pop()!='E') return TRUE; // this string is well formed in regard of braces return FALSE; } int result = FALSE; int i; for(i=0; i < xmlXPathNodeSetGetLength(ns); i++) { xmlNodePtr n = xmlXPathNodeSetItem(ns, i); xmlChar* c = xmlNodeGetContent(n); if(!c) continue; result = contains_unbalanced_braces(c); xmlFree(c); if(result) break; } if(ns) xmlXPathFreeNodeSet(ns); xmlXPathReturnBoolean(ctxt, result); }
static gboolean _lt_ext_ldml_u_lookup_key(lt_ext_ldml_u_data_t *data, const gchar *subtag, GError **error) { gint i, j, n; lt_xml_t *xml = lt_xml_new(); gboolean retval = FALSE; for (i = LT_XML_CLDR_BCP47_BEGIN; i <= LT_XML_CLDR_BCP47_END; i++) { xmlDocPtr doc = lt_xml_get_cldr(xml, i); xmlXPathContextPtr xctxt = NULL; xmlXPathObjectPtr xobj = NULL; xctxt = xmlXPathNewContext(doc); if (!xctxt) { g_set_error(error, LT_ERROR, LT_ERR_OOM, "Unable to create an instance of xmlXPathContextPtr."); goto bail1; } xobj = xmlXPathEvalExpression((const xmlChar *)"/ldmlBCP47/keyword/key", xctxt); if (!xobj) { g_set_error(error, LT_ERROR, LT_ERR_FAIL_ON_XML, "No valid elements for %s", doc->name); goto bail1; } n = xmlXPathNodeSetGetLength(xobj->nodesetval); for (j = 0; j < n; j++) { xmlNodePtr ent = xmlXPathNodeSetItem(xobj->nodesetval, j); xmlChar *name; if (!ent) { g_set_error(error, LT_ERROR, LT_ERR_FAIL_ON_XML, "Unable to obtain the xml node via XPath."); goto bail1; } name = xmlGetProp(ent, (const xmlChar *)"name"); if (g_ascii_strcasecmp((const gchar *)name, subtag) == 0) { data->current_type = i; data->state = STATE_TYPE; xmlFree(name); retval = TRUE; goto bail1; } xmlFree(name); } bail1: if (xobj) xmlXPathFreeObject(xobj); if (xctxt) xmlXPathFreeContext(xctxt); if (*error || retval) goto bail; } g_set_error(error, LT_ERROR, LT_ERR_FAIL_ON_SCANNER, "Invalid key for -u- extension: %s", subtag); bail: lt_xml_unref(xml); return *error == NULL; }
static gboolean xmms_xspf_browse_add_entries (xmms_xform_t *xform, xmlDocPtr doc, xmms_error_t *error) { int i; xmlXPathContextPtr xpath; xmlXPathObjectPtr obj; const xmlChar *playlist_image = NULL; xpath = xmlXPathNewContext (doc); xmlXPathRegisterNs (xpath, BAD_CAST "xspf", BAD_CAST "http://xspf.org/ns/0/"); if (!xmms_xspf_check_valid_xspf (doc, xpath, error)) { xmlXPathFreeContext (xpath); return FALSE; } obj = xmlXPathEvalExpression (BAD_CAST "/xspf:playlist[@version<=1]/xspf:image/text()/..", xpath); if (!obj) { xmms_error_set (error, XMMS_ERROR_INVAL, "unable to evaluate xpath expression"); xmlXPathFreeContext (xpath); return FALSE; } if (xmlXPathNodeSetGetLength (obj->nodesetval) == 1) { playlist_image = xmlXPathNodeSetItem (obj->nodesetval, 0)->children->content; } xmlXPathFreeObject (obj); obj = xmlXPathEvalExpression (BAD_CAST "/xspf:playlist[@version<=1]/xspf:trackList/xspf:track/xspf:location/text()/../..", xpath); if (!obj) { xmms_error_set (error, XMMS_ERROR_INVAL, "unable to evaluate xpath expression"); xmlXPathFreeContext (xpath); return FALSE; } for (i = 0; i < xmlXPathNodeSetGetLength (obj->nodesetval); i++) { xmms_xspf_track_t *track; GList *attr; track = xmms_xspf_parse_track_node (xform, xmlXPathNodeSetItem (obj->nodesetval, i), error); if (!track) { continue; } xmms_xform_browse_add_symlink (xform, NULL, track->location); if (playlist_image) { xmms_xform_browse_add_entry_property_str (xform, "image", (char *)playlist_image); } for (attr = track->attrs; attr; attr = g_list_next (attr)) { xmms_xform_browse_add_entry_property (xform, ((xmms_xspf_track_attr_t *)attr->data)->key, ((xmms_xspf_track_attr_t *)attr->data)->value); } g_list_free (track->attrs); g_free (track); } xmlXPathFreeObject (obj); xmlXPathFreeContext (xpath); return TRUE; }
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"); while(mtev_hash_next(configh, &iter, &k, &klen, &data)) NODE_CONTENT(config, k, data); mtev_hash_destroy(configh, free, free); free(configh); mod_cnt = noit_check_registered_module_cnt(); for(mod=0; mod<mod_cnt; mod++) { xmlNsPtr ns; const char *nsname; char buff[256]; nsname = noit_check_registered_module(mod); snprintf(buff, sizeof(buff), "noit://module/%s", nsname); ns = xmlSearchNs(root->doc, root, (xmlChar *)nsname); if(!ns) ns = xmlNewNs(root, (xmlChar *)buff, (xmlChar *)nsname); if(ns) { configh = mtev_conf_get_namespaced_hash(node, "config", nsname); if(configh) { memset(&iter, 0, sizeof(iter)); while(mtev_hash_next(configh, &iter, &k, &klen, &data)) { NS_NODE_CONTENT(config, ns, "value", data, xmlSetProp(tmp, (xmlChar *)"name", (xmlChar *)k); ); } mtev_hash_destroy(configh, free, free); free(configh); } } }
static int noit_console_check(noit_console_closure_t ncct, int argc, char **argv, noit_console_state_t *state, void *closure) { int cnt; noit_conf_t_userdata_t *info; char xpath[1024], newuuid_str[37]; char *uuid_conf, *wanted; uuid_t checkid; xmlXPathContextPtr xpath_ctxt = NULL; xmlXPathObjectPtr pobj = NULL; xmlNodePtr node = NULL; noit_boolean creating_new = noit_false; if(closure) { char *fake_argv[1] = { ".." }; noit_console_state_pop(ncct, 0, argv, NULL, NULL); noit_console_config_cd(ncct, 1, fake_argv, NULL, NULL); } noit_conf_xml_xpath(NULL, &xpath_ctxt); if(argc < 1) { nc_printf(ncct, "requires at least one argument\n"); return -1; } if(argc % 2 == 0) { nc_printf(ncct, "wrong number of arguments\n"); return -1; } info = noit_console_userdata_get(ncct, NOIT_CONF_T_USERDATA); wanted = strcmp(argv[0], "new") ? argv[0] : NULL; if(info && !wanted) { /* We are creating a new node */ uuid_t out; creating_new = noit_true; if(strncmp(info->path, "/checks/", strlen("/checks/")) && strcmp(info->path, "/checks")) { nc_printf(ncct, "New checks must be under /checks/\n"); return -1; } if(noit_conf_mkcheck_under(info->path, argc - 1, argv + 1, out)) { nc_printf(ncct, "Error creating new check\n"); return -1; } newuuid_str[0] = '\0'; uuid_unparse_lower(out, newuuid_str); wanted = newuuid_str; } /* We many not be in conf-t mode -- that's fine */ if(noit_console_mkcheck_xpath(xpath, sizeof(xpath), info, wanted)) { nc_printf(ncct, "could not find check '%s'\n", wanted); return -1; } pobj = xmlXPathEval((xmlChar *)xpath, xpath_ctxt); if(!pobj || pobj->type != XPATH_NODESET || xmlXPathNodeSetIsEmpty(pobj->nodesetval)) { nc_printf(ncct, "no checks found for '%s'\n", wanted); goto out; } cnt = xmlXPathNodeSetGetLength(pobj->nodesetval); if(info && cnt != 1) { nc_printf(ncct, "Ambiguous check specified\n"); goto out; } node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, 0); 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")); goto out; } if(argc > 1 && !creating_new) if(noit_config_check_update_attrs(node, argc - 1, argv + 1)) nc_printf(ncct, "Partially successful, error setting some attributes\n"); if(info) { if(info->path) free(info->path); info->path = strdup((char *)xmlGetNodePath(node) + strlen("/noit")); uuid_copy(info->current_check, checkid); if(argc > 1) refresh_subchecks(ncct, info); if(state) { noit_console_state_push_state(ncct, state); noit_console_state_init(ncct); } goto out; } out: if(pobj) xmlXPathFreeObject(pobj); return 0; }
xmlNodePtr __xmlXPathNodeSetItem(const xmlNodeSet * ns, int index) { return xmlXPathNodeSetItem(ns, index); }
/*< private >*/ static lt_bool_t lt_script_db_parse(lt_script_db_t *scriptdb, lt_error_t **error) { lt_bool_t retval = TRUE; xmlDocPtr doc = NULL; xmlXPathContextPtr xctxt = NULL; xmlXPathObjectPtr xobj = NULL; lt_error_t *err = NULL; int i, n; lt_return_val_if_fail (scriptdb != NULL, FALSE); doc = lt_xml_get_subtag_registry(scriptdb->xml); xctxt = xmlXPathNewContext(doc); if (!xctxt) { lt_error_set(&err, LT_ERR_OOM, "Unable to create an instance of xmlXPathContextPtr."); goto bail; } xobj = xmlXPathEvalExpression((const xmlChar *)"/registry/script", xctxt); if (!xobj) { lt_error_set(&err, LT_ERR_FAIL_ON_XML, "No valid elements for %s", doc->name); goto bail; } n = xmlXPathNodeSetGetLength(xobj->nodesetval); for (i = 0; i < n; i++) { xmlNodePtr ent = xmlXPathNodeSetItem(xobj->nodesetval, i); xmlNodePtr cnode; xmlChar *subtag = NULL, *desc = NULL; lt_script_t *le = NULL; char *s; if (!ent) { lt_error_set(&err, LT_ERR_FAIL_ON_XML, "Unable to obtain the xml node via XPath."); goto bail; } cnode = ent->children; while (cnode != NULL) { if (xmlStrcmp(cnode->name, (const xmlChar *)"subtag") == 0) { if (subtag) { lt_warning("Duplicate subtag element in script: previous value was '%s'", subtag); } else { subtag = xmlNodeGetContent(cnode); } } else if (xmlStrcmp(cnode->name, (const xmlChar *)"added") == 0 || xmlStrcmp(cnode->name, (const xmlChar *)"text") == 0 || xmlStrcmp(cnode->name, (const xmlChar *)"comments") == 0) { /* ignore it */ } else if (xmlStrcmp(cnode->name, (const xmlChar *)"description") == 0) { /* wonder if many descriptions helps something. or is it a bug? */ if (!desc) desc = xmlNodeGetContent(cnode); } else { lt_warning("Unknown node under /registry/script: %s", cnode->name); } cnode = cnode->next; } if (!subtag) { lt_warning("No subtag node: description = '%s'", desc); goto bail1; } if (!desc) { lt_warning("No description node: subtag = '%s'", subtag); goto bail1; } le = lt_script_create(); if (!le) { lt_error_set(&err, LT_ERR_OOM, "Unable to create an instance of lt_script_t."); goto bail1; } lt_script_set_tag(le, (const char *)subtag); lt_script_set_name(le, (const char *)desc); s = strdup(lt_script_get_tag(le)); lt_trie_replace(scriptdb->script_entries, lt_strlower(s), lt_script_ref(le), (lt_destroy_func_t)lt_script_unref); free(s); bail1: if (subtag) xmlFree(subtag); if (desc) xmlFree(desc); lt_script_unref(le); } bail: if (lt_error_is_set(err, LT_ERR_ANY)) { if (error) *error = lt_error_ref(err); else lt_error_print(err, LT_ERR_ANY); lt_error_unref(err); retval = FALSE; } if (xobj) xmlXPathFreeObject(xobj); if (xctxt) xmlXPathFreeContext(xctxt); return retval; }