コード例 #1
0
/*
 * Internal function to open an XML file
 *
 * Returns the XML doc pointer, or NULL on failure.  It will validate the
 * document, as well as removing any comments from the document structure.
 */
static xmlDocPtr
open_xml_file(const char *file)
{
	xmlDocPtr doc;
	xmlValidCtxtPtr cvp;
	int valid;

	if (!libbrand_initialize())
		return (NULL);

	/*
	 * Parse the file
	 */
	if ((doc = xmlParseFile(file)) == NULL)
		return (NULL);

	/*
	 * Validate the file
	 */
	if ((cvp = xmlNewValidCtxt()) == NULL) {
		xmlFreeDoc(doc);
		return (NULL);
	}
	cvp->error = brand_error_func;
	cvp->warning = brand_error_func;
	valid = xmlValidateDocument(cvp, doc);
	xmlFreeValidCtxt(cvp);
	if (valid == 0) {
		xmlFreeDoc(doc);
		return (NULL);
	}

	return (doc);
}
コード例 #2
0
pipeline_t * pipeline_cargar(const char *ruta, funcion_error_t funcion_error, const void *dato) 
{
    xmlDocPtr doc;
    xmlNodePtr cur;
    xmlValidCtxt cvp;
    pipeline_t *p;

    if(!g_module_supported()) {
      return 0;
    }
    
    doc = xmlParseFile(ruta);
    if (doc == NULL) {
	return 0;
    }
    
    cvp.userData = (void *) stderr;
    cvp.error    = (xmlValidityErrorFunc) fprintf;
    cvp.warning  = (xmlValidityWarningFunc) fprintf;
    if (!xmlValidateDocument(&cvp, doc)) {
      return 0;
    }
    cur = xmlDocGetRootElement(doc);
    if (cur == NULL) {
	xmlFreeDoc(doc);
	return 0;
    }
    if (xmlStrcmp(cur->name, (const xmlChar *) "pipeline")) {
	xmlFreeDoc(doc);
	return 0;
    }

    chdir(g_path_get_dirname(ruta));
    p = (pipeline_t*)malloc(sizeof(pipeline_t));
    p->m_modulos = g_hash_table_new_full(g_str_hash, g_str_equal, /*pipeline_borrar_cadena*/0, pipeline_borrar_elemento);
    p->m_funcion_error = funcion_error;
    p->m_dato_funcion_error = (gpointer)dato;
    p->m_nombres = 0;
    cur = cur->xmlChildrenNode;
    cur = cur->next;
    while (cur != NULL) {
	if ((!xmlStrcmp(cur->name, (const xmlChar *) "modulo"))) {
	  p = pipeline_leer_xml(p, doc, cur/*, dir*/);
	    if(p == 0) {
	      xmlFreeDoc(doc);
	      pipeline_borrar(p);
	      return 0;
	    }
	}
	cur = cur->next;
    }
    xmlFreeDoc(doc);
    p->m_nombres = (char **)realloc(p->m_nombres, sizeof(char **) * (g_hash_table_size(p->m_modulos) + 1));
    p->m_nombres[g_hash_table_size(p->m_modulos)] = 0;
    return p;
}
コード例 #3
0
ファイル: xmldoc.cpp プロジェクト: alilloyd/livecode
Bool CXMLDocument::Validate()
{
if (!isinited()) return False;
		xmlValidCtxt ctxt;
		ctxt.doc = doc;
		ctxt.userData = NULL;
		//point to dtd error handling function
		ctxt.error = errorCallback; 
		ctxt.warning = warningCallback;
		if ((doc->intSubset == NULL) && (doc->extSubset == NULL))
			return True;
		return xmlValidateDocument(&ctxt, doc) == 1;
}
コード例 #4
0
ファイル: xml_tree.cpp プロジェクト: JonathanFu/OpenAM-1
XMLTree::XMLTree(bool validate, const char *docBuffer, std::size_t bufferLen)
: docPtr(NULL) {
    if (static_cast<const char *> (NULL) == docBuffer) {
        throw std::invalid_argument("XMLTree(docBuffer) is NULL");
    }

    if (0 == bufferLen) {
        bufferLen = std::strlen(docBuffer);
        if (0 == bufferLen) {
            throw std::invalid_argument("XMLTree(docBuffer) is empty");
        }
    }

    if (INT_MAX < bufferLen) {
        throw std::invalid_argument("XMLTree(docBuffer) too long");
    }

    docPtr = xmlReadMemory(docBuffer, static_cast<int> (bufferLen), NULL, NULL, XML_PARSE_NONET);
    if (static_cast<xmlDocPtr> (NULL) == docPtr) {
        throw ParseException("XMLTree() unable to parse docBuffer");
    }

    if (validate) {
        //
        // Now, try to validate the document.
        //
        XMLErrorData errorData("XMLTree() ");
        xmlValidCtxt cvp;

        cvp.userData = &errorData;
        cvp.error = reinterpret_cast<xmlValidityErrorFunc> (XMLErrorHandler);
        cvp.warning = reinterpret_cast<xmlValidityErrorFunc> (XMLErrorHandler);

        if (!xmlValidateDocument(&cvp, docPtr)) {
            xmlFreeDoc(docPtr);
            if (errorData.errorDetected) {
                throw ParseException(errorData.message);
            } else {
                throw ParseException("XMLTree() docBuffer does not validate");
            }
        }
    }

    if (static_cast<xmlNodePtr> (NULL) == xmlDocGetRootElement(docPtr)) {
        xmlFreeDoc(docPtr);
        throw ParseException("XMLTree() empty document");
    }
}
コード例 #5
0
pipeline_t * pipeline_cargar(const char *ruta, const char *dir, funcion_error_t funcion_error) 
{
    xmlDocPtr doc;
    xmlNodePtr cur;
    doc = xmlParseFile(ruta);
    if (doc == NULL) {
	return 0;
    }

    xmlValidCtxt cvp;
    
    cvp.userData = (void *) stderr;
    cvp.error    = (xmlValidityErrorFunc) fprintf;
    cvp.warning  = (xmlValidityWarningFunc) fprintf;
    if (!xmlValidateDocument(&cvp, doc)) {
      return 0;
    }
    cur = xmlDocGetRootElement(doc);
    if (cur == NULL) {
	xmlFreeDoc(doc);
	return 0;
    }
    if (xmlStrcmp(cur->name, (const xmlChar *) "pipeline")) {
	xmlFreeDoc(doc);
	return 0;
    }
    pipeline_t *p = (pipeline_t*)malloc(sizeof(pipeline_t));
    p->m_modulos = g_hash_table_new_full(g_str_hash, g_str_equal, pipeline_borrar_cadena, pipeline_borrar_elemento);
    p->m_funcion_error = funcion_error;

    cur = cur->xmlChildrenNode;
    cur = cur->next;
    while (cur != NULL) {
	if ((!xmlStrcmp(cur->name, (const xmlChar *) "modulo"))) {
	    p = pipeline_leer_xml(p, doc, cur, dir);
	}
	cur = cur->next;
    }
    xmlFreeDoc(doc);
    return p;
}
コード例 #6
0
static void get_tone_set(const char *tone_file, const char *set_id)
{
    xmlDocPtr doc;
    xmlNsPtr ns;
    xmlNodePtr cur;
#if 0
    xmlValidCtxt valid;
#endif
    xmlChar *x;

    ns = NULL;    
    xmlKeepBlanksDefault(0);
    xmlCleanupParser();
    doc = xmlParseFile(tone_file);
    if (doc == NULL)
    {
        fprintf(stderr, "No document\n");
        exit(2);
    }
    /*endif*/
    xmlXIncludeProcess(doc);
#if 0
    if (!xmlValidateDocument(&valid, doc))
    {
        fprintf(stderr, "Invalid document\n");
        exit(2);
    }
    /*endif*/
#endif
    /* Check the document is of the right kind */
    if ((cur = xmlDocGetRootElement(doc)) == NULL)
    {
        fprintf(stderr, "Empty document\n");
        xmlFreeDoc(doc);
        exit(2);
    }
    /*endif*/
    if (xmlStrcmp(cur->name, (const xmlChar *) "global-tones"))
    {
        fprintf(stderr, "Document of the wrong type, root node != global-tones");
        xmlFreeDoc(doc);
        exit(2);
    }
    /*endif*/
    cur = cur->xmlChildrenNode;
    while (cur  &&  xmlIsBlankNode(cur))
        cur = cur->next;
    /*endwhile*/
    if (cur == NULL)
        exit(2);
    /*endif*/
    while (cur)
    {
        if (xmlStrcmp(cur->name, (const xmlChar *) "tone-set") == 0)
        {
            if ((x = xmlGetProp(cur, (const xmlChar *) "uncode")))
            {
                if (strcmp((char *) x, set_id) == 0)
                    parse_tone_set(doc, ns, cur);
                /*endif*/
                xmlFree(x);
            }
            /*endif*/
        }
        /*endif*/
        cur = cur->next;
    }
    /*endwhile*/
    xmlFreeDoc(doc);
}
コード例 #7
0
ファイル: keyfiles.c プロジェクト: twouters/apt-dater
gboolean loadConfig(const gchar *filename, CfgFile *lcfg) {
    /* Parse hosts.xml document. */
    xmlDocPtr xcfg = xmlParseFile(filename);
    if(xcfg == NULL)
      return(FALSE);

    /* Handle Xincludes. */
    xmlSetGenericErrorFunc(NULL, xmlErrIgnoreHandler);
    xmlXIncludeProcess(xcfg);
    handleXMLError( xmlGetLastError() );
    xmlSetGenericErrorFunc(NULL, NULL);

    /* Validate against DTD. */
    xmlValidCtxtPtr xval = xmlNewValidCtxt();
    if(xmlValidateDocument(xval, xcfg) == 0) {
      xmlFreeValidCtxt(xval);
      return(FALSE);
    }
    xmlFreeValidCtxt(xval);

    /* Allocate XPath context. */
    xmlXPathContextPtr xctx = xmlXPathNewContext(xcfg);
    if(!xctx) {
      g_error("%s: xmlXPathNewContext failed!\n", filename);
      return(FALSE);
    }

    xmlNodePtr s_ssh[2] = {getXNode(xctx, "/apt-dater/ssh"), NULL};
    xmlNodePtr s_path[2] = {getXNode(xctx, "/apt-dater/paths"), NULL};
#ifdef FEAT_TMUX
    xmlNodePtr s_tmux[2] = {getXNode(xctx, "/apt-dater/tmux"), NULL};
#else
    xmlNodePtr s_screen[2] = {getXNode(xctx, "/apt-dater/screen"), NULL};
#endif
    xmlNodePtr s_appearance[2] = {getXNode(xctx, "/apt-dater/appearance"), NULL};
    xmlNodePtr s_notify[2] = {getXNode(xctx, "/apt-dater/notify"), NULL};
    xmlNodePtr s_hooks[2] = {getXNode(xctx, "/apt-dater/hooks"), NULL};
#ifdef FEAT_AUTOREF
    xmlNodePtr s_autoref[2] = {getXNode(xctx, "/apt-dater/auto-ref"), NULL};
#endif
#ifdef FEAT_HISTORY
    xmlNodePtr s_history[2] = {getXNode(xctx, "/apt-dater/history"), NULL};
#endif
#ifdef FEAT_TCLFILTER
    xmlNodePtr s_tclfilter[2] = {getXNode(xctx, "/apt-dater/tcl-filter"), NULL};
#endif

    lcfg->ssh_optflags = getXPropStr(s_ssh, "opt-cmd-flags", "-t");
    lcfg->ssh_cmd = getXPropStr(s_ssh, "cmd", "/usr/bin/ssh");
    lcfg->sftp_cmd = getXPropStr(s_ssh, "sftp-cmd", "/usr/bin/sftp");

    lcfg->umask = getXPropInt(s_path, "umask", S_IRWXG | S_IRWXO);
    umask(lcfg->umask);

    lcfg->hostsfile = getXPropStr(s_path, "hosts-file", g_strdup_printf("%s/%s/%s", g_get_user_config_dir(), PROG_NAME, "hosts.xml"));
    lcfg->statsdir = getXPropStr(s_path, "stats-dir", g_strdup_printf("%s/%s/%s", g_get_user_cache_dir(), PROG_NAME, "stats"));
    if(g_mkdir_with_parents(lcfg->statsdir, S_IRWXU | S_IRWXG) == -1) {
      g_warning("Failed to create %s: %s", lcfg->statsdir, g_strerror(errno));
      exit(1);
    }

#ifdef FEAT_TMUX
    lcfg->tmuxconffile = getXPropStr(s_tmux, "conf-file", g_strdup_printf("%s/%s/%s", g_get_user_config_dir(), PROG_NAME, "tmux.conf"));
    lcfg->tmuxsockpath = getXPropStr(s_tmux, "socket-path", g_strdup_printf("%s/%s/%s", g_get_user_cache_dir(), PROG_NAME, "tmux"));
    if(g_mkdir_with_parents(lcfg->tmuxsockpath, S_IRWXU | S_IRWXG) == -1) {
      g_warning("Failed to create %s: %s", lcfg->tmuxsockpath, g_strerror(errno));
      exit(1);
    }
#else
    lcfg->screenrcfile = getXPropStr(s_screen, "rc-file", g_strdup_printf("%s/%s/%s", g_get_user_config_dir(), PROG_NAME, "screenrc"));
    lcfg->screentitle = getXPropStr(s_screen, "title", g_strdup("%m # %U%H"));
#endif

    lcfg->ssh_agent = getXPropBool(s_ssh, "spawn-agent", FALSE);

    xmlNodeSetPtr s_addkeys = getXNodes(xctx, "/apt-dater/ssh/add-key");
    if(!xmlXPathNodeSetIsEmpty(s_addkeys)) {
      lcfg->ssh_add = g_new0(char*, s_addkeys->nodeNr + 1);
      int i;
      for(i = 0; i < s_addkeys->nodeNr; i++) {
	lcfg->ssh_add[i] = g_strdup((gchar *)xmlGetProp(s_addkeys->nodeTab[i], BAD_CAST("name")));
	xmlChar *c = xmlGetProp(s_addkeys->nodeTab[i], BAD_CAST("fn"));
	if(!c) {
	    g_printerr(_("Empty SSH key filename (%s/@fn) in configuration."), xmlGetNodePath(s_addkeys->nodeTab[i]));
	    exit(1);
	}
	lcfg->ssh_add[i] = g_strdup((gchar *)c);
      }
      lcfg->ssh_numadd = s_addkeys->nodeNr;
    }