PKI_CONFIG * PKI_CONFIG_load(char *urlPath) { FILE *file = NULL; PKI_CONFIG *doc = NULL; URL *url = NULL; xmlParserCtxt *parserCtxt = NULL; LIBXML_TEST_VERSION if (urlPath) url = URL_new( urlPath ); else return ( NULL ); // Let's check the URL was parsed correctly if( !url || !url->addr ) return(PKI_ERR); if ((file = fopen(url->addr, "r")) == NULL) { URL_free(url); return PKI_ERR; } fclose(file); if ((parserCtxt = xmlNewParserCtxt()) == NULL ) { URL_free( url ); return(PKI_ERR); } #if LIBXML_VERSION > LIBXML_MIN_VERSION xmlSetStructuredErrorFunc( parserCtxt, logXmlMessages ); #endif /* Do not Keep Blank Nodes */ xmlKeepBlanksDefault(0); /*parse the file and get the DOM */ #if LIBXML_VERSION > LIBXML_MIN_VERSION doc = (PKI_CONFIG *) xmlCtxtReadFile(parserCtxt, url->addr, NULL, XML_PARSE_RECOVER | XML_PARSE_NOERROR | XML_PARSE_NOWARNING | XML_PARSE_NOENT ); #else doc = (PKI_CONFIG *) xmlCtxtReadFile(parserCtxt, url->addr, NULL, 0); #endif // xmlClearParserCtxt ( parserCtxt ); xmlFreeParserCtxt ( parserCtxt ); URL_free(url); return( doc ); }
//! Parse a file. //----------------------------------------------------------------------- static bool parse_file(const parser_type &p, const path_type &path, const options_type &opt = options_type()) { p->myDoc = xmlCtxtReadFile(p, path, "UTF-8", opt); return (p->myDoc != 0); }
xmlDoc *XMLDocument::readDocument(const char *filename, const char * encoding, bool validate, std::string * error) { xmlParserCtxt *ctxt = initContext(error, validate); xmlDoc *doc = 0; int options = XML_PARSE_NSCLEAN | XML_PARSE_NOBLANKS; if (validate) { options |= XML_PARSE_DTDVALID; } if (!ctxt) { xmlSetGenericErrorFunc(0, errorFunctionWithoutOutput); return 0; } doc = xmlCtxtReadFile(ctxt, filename, encoding, options); if (!doc || !ctxt->valid) { *error = errorBuffer; } xmlSetGenericErrorFunc(0, errorFunctionWithoutOutput); xmlFreeParserCtxt(ctxt); return doc; }
void Vpz::validateFile(const std::string& filename) { xmlParserCtxtPtr ctxt; xmlDocPtr doc; ctxt = xmlNewParserCtxt(); if (ctxt == NULL) { throw utils::SaxParserError(_("Failed to allocate parser context\n")); } doc = xmlCtxtReadFile(ctxt, filename.c_str(), NULL, XML_PARSE_DTDVALID); if (not doc) { std::string msg((fmt(_("Failed to parse '%1%': %2%")) % filename % (ctxt->lastError.message ? ctxt->lastError.message : "")).str()); xmlFreeParserCtxt(ctxt); throw utils::SaxParserError(msg); } if (ctxt->valid == 0) { std::string msg((fmt(_("Failed to validate '%1%': %2%")) % filename % (ctxt->lastError.message ? ctxt->lastError.message : "")).str()); xmlFreeDoc(doc); xmlFreeParserCtxt(ctxt); throw utils::SaxParserError(msg); } xmlFreeParserCtxt(ctxt); }
void load(std::string const& filename, xml_node &node) { boost::filesystem::path path(filename); if (!boost::filesystem::exists(path)) { throw config_error(string("Could not load map file: File does not exist"), 0, filename); } xmlDocPtr doc = xmlCtxtReadFile(ctx_, filename.c_str(), encoding_, options_); if (!doc) { xmlError * error = xmlCtxtGetLastError(ctx_); if (error) { std::string msg("XML document not well formed:\n"); msg += error->message; // remove CR msg = msg.substr(0, msg.size() - 1); throw config_error(msg, error->line, error->file); } } /* if ( ! ctx->valid ) { MAPNIK_LOG_WARN(libxml2_loader) << "libxml2_loader: Failed to validate DTD."; } */ load(doc, node); }
bool CSpmXml::Load(const QString& strFileName, bool bDTDValidation) { xmlParserCtxtPtr pXMLParser = xmlNewParserCtxt(); if (0 == pXMLParser) return false; int nOptions = XML_PARSE_NOBLANKS; if (bDTDValidation) nOptions |= XML_PARSE_DTDVALID; m_pXMLDoc = xmlCtxtReadFile(pXMLParser, strFileName.toLocal8Bit().data(), NULL, nOptions); if (0 == m_pXMLDoc) { xmlFreeParserCtxt(pXMLParser); return false; } // Проверка корректности структуры if (bDTDValidation && (false == pXMLParser->valid)) { xmlFreeParserCtxt(pXMLParser); return false; } m_pCurNode = xmlDocGetRootElement(m_pXMLDoc); if (0 == m_pCurNode) return false; SetModified(false); xmlFreeParserCtxt(pXMLParser); return true; }
bool MainWindow::OpenXMLDocument(const QString &file_name) { FreeXMLDocument(); xmlParserCtxtPtr parser = xmlNewParserCtxt(); if (0 == parser) return false; xml_doc_ptr_ = xmlCtxtReadFile(parser, file_name.toLocal8Bit().data(), NULL, XML_PARSE_NOBLANKS);// | XML_PARSE_DTDVALID); if (false == parser->valid) { QMessageBox::critical(this, tr("Открытие XML документа"), tr("Структура файла %1 не соответствует " "DTD-диаграмме").arg(file_name), QMessageBox::Ok); SetCurrentFileName("", false); xmlFreeParserCtxt(parser); FreeXMLDocument(); return false; } AddItem(xmlDocGetRootElement(xml_doc_ptr_)); xmlFreeParserCtxt(parser); UpdateButtons(); return true; }
/* * The hierarchical place tree for a shared memory system is specified as an XML * file containing the hierarchy of memory spaces it contains. In general, this * hierarchy is multi-layered and may include a separate layer for system * memory, L3 caches, L2 caches, L1 caches, etc. * * Each layer is described by two properties: a type and a count/num. For * example, the type may be "mem" whose contents are explicitly managed by the * programmer, or a "cache" whose contents are automatically managed. The count * refers to the fan-out at a given level. For example, a machine with main * memory feeding to two sockets each with their own L3 cache would have a count * of 2 for the L3 layer. * * An example HPT specification is below. This specification describes a machine * with a single system memory, two L3 caches, each of which fans out to 6 L1/L2 * caches. * * <HPT version="0.1" info="2 hex core2 Intel Westmere processors"> * <place num="1" type="mem"> * <place num="2" type="cache"> <!-- 2 sockets with common L3 in each --> * <place num="6" type="cache"> <!-- 6 L2/L1 cache per socket --> * <worker num="1"/> * </place> * </place> * </place> * </HPT> * * While homogeneous systems will usually have this singly-nested structure, a * machine with multiple types of memory sitting below system memory may have * multiple elements at the same nesting level, e.g. both L3 and GPU device * memory at the same level in the hierarchy. * * read_hpt parses one of these XML files and produces the equivalent place * hierarchy, returning the root of that hierarchy. The schema of the HPT XML * file is stored in $HCLIB_HOME/hpt/hpt.dtd. */ place_t *read_hpt(place_t *** all_places, int *num_pl, int *nproc, hclib_worker_state *** all_workers, int *num_wk) { const char *filename = getenv("HCLIB_HPT_FILE"); place_t *hpt; if (filename == NULL) { const char *workers_str = getenv("HCLIB_WORKERS"); uint32_t num_workers; if (workers_str) { num_workers = atoi(workers_str); } else { num_workers = sysconf(_SC_NPROCESSORS_ONLN); fprintf(stderr, "WARNING: HCLIB_WORKERS not provided, running with " "default of %u\n", num_workers); } hpt = generate_fake_hpt(num_workers, all_places, num_pl, nproc, all_workers, num_wk); } else { /* create a parser context */ xmlParserCtxt *ctxt = xmlNewParserCtxt(); if (ctxt == NULL) { fprintf(stderr, "Failed to allocate parser context\n"); return NULL; } /* parse the file, activating the DTD validation option */ xmlDoc *doc = xmlCtxtReadFile(ctxt, filename, NULL, XML_PARSE_DTDVALID); /* check if parsing succeeded */ if (doc == NULL) { fprintf(stderr, "Failed to parse %s\n", filename); return NULL; } /* check if validation suceeded */ if (ctxt->valid == 0) { fprintf(stderr, "Failed to validate %s\n", filename); return NULL; } xmlNode *root_element = xmlDocGetRootElement(doc); hpt = parseHPTDoc(root_element); /*free the document */ xmlFreeDoc(doc); /* free up the parser context */ xmlFreeParserCtxt(ctxt); } /* * This takes places which have num > 1 and workers that have num > 1 and * fully expand them in the place tree so that every node in the tree * corresponds to a single place/worker. */ unrollHPT(hpt, all_places, num_pl, nproc, all_workers, num_wk); return hpt; }
/*< private >*/ static gboolean lt_xml_read_subtag_registry(lt_xml_t *xml, GError **error) { gchar *regfile = NULL; xmlParserCtxtPtr xmlparser; xmlDocPtr doc = NULL; GError *err = NULL; g_return_val_if_fail (xml != NULL, FALSE); #ifdef GNOME_ENABLE_DEBUG regfile = g_build_filename(BUILDDIR, "data", "language-subtag-registry.xml", NULL); if (!g_file_test(regfile, G_FILE_TEST_EXISTS)) { g_free(regfile); #endif regfile = g_build_filename(lt_db_get_datadir(), "language-subtag-registry.xml", NULL); #ifdef GNOME_ENABLE_DEBUG } #endif xmlparser = xmlNewParserCtxt(); if (!xmlparser) { g_set_error(&err, LT_ERROR, LT_ERR_OOM, "Unable to create an instance of xmlParserCtxt."); goto bail; } doc = xmlCtxtReadFile(xmlparser, regfile, "UTF-8", 0); if (!doc) { g_set_error(&err, LT_ERROR, LT_ERR_FAIL_ON_XML, "Unable to read the xml file: %s", regfile); goto bail; } xml->subtag_registry = doc; lt_mem_add_ref(&xml->parent, xml->subtag_registry, (lt_destroy_func_t)xmlFreeDoc); bail: g_free(regfile); if (xmlparser) xmlFreeParserCtxt(xmlparser); xmlCleanupParser(); if (err) { if (error) *error = g_error_copy(err); else g_warning(err->message); g_error_free(err); return FALSE; } return TRUE; }
void parse_config() { FILE *f = NULL; fprintf(stderr,"Reading configuration file: \"%s\" ...\n",config_path); if( (f=fopen (config_path, "r")) == NULL ) { perror("fopen"); exit(1); } LIBXML_TEST_VERSION; /* create a parser context */ ctxt = xmlNewParserCtxt(); if (ctxt == NULL) { fprintf(stderr, "Failed to allocate parser context\n"); fclose(f); return; } /* parse the file, activating the DTD validation option */ doc = xmlCtxtReadFile(ctxt, config_path, NULL, XML_PARSE_DTDVALID); /* check if parsing suceeded */ if (doc == NULL) { fprintf(stderr, "Failed to parse %s\n", config_path); } else { /* check if validation suceeded */ if (ctxt->valid == 0) fprintf(stderr, "Failed to validate %s\n", config_path); /* free up the resulting document */ else { xmlXPathInit(); xpctxt= xmlXPathNewContext(doc); } } autoconf(); get_mail(); init_syslog(); parse_routers(); parse_actions(); #ifdef _COUNTERMEASURES_ parse_countermeasures(); #endif free_xml(); fclose(f); fprintf(stderr," Done.\n"); }
bool XMLReader::loadFile(const std::string& file, int parserOptions) { ILOG_TRACE_F(ILX_XMLREADER); release(); ILOG_DEBUG(ILX_XMLREADER, " -> file: %s\n", file.c_str()); _ctxt = xmlNewParserCtxt(); if (_ctxt == NULL) { ILOG_ERROR(ILX_XMLREADER, "Failed to allocate parser context!\n"); return false; } #ifdef ANDROID_NDK _doc = xmlCtxtReadFile(_ctxt, file.c_str(), NULL, XML_PARSE_RECOVER | XML_PARSE_NOENT | XML_PARSE_NOBLANKS); #else _doc = xmlCtxtReadFile(_ctxt, file.c_str(), NULL, XML_PARSE_DTDATTR | XML_PARSE_NOENT | XML_PARSE_DTDVALID | XML_PARSE_NOBLANKS); #endif if (_doc == NULL) { xmlFreeParserCtxt(_ctxt); _ctxt = NULL; ILOG_ERROR(ILX_XMLREADER, "Failed to parse %s!\n", file.c_str()); return false; } if ((parserOptions & XML_PARSE_DTDVALID) && (_ctxt->valid == 0)) { xmlFreeDoc(_doc); xmlFreeParserCtxt(_ctxt); _doc = NULL; _ctxt = NULL; ILOG_ERROR(ILX_XMLREADER, "Failed to validate %s!\n", file.c_str()); return false; } _currentNode = root()->xmlChildrenNode; ILOG_DEBUG(ILX_XMLREADER, " -> done.\n"); return true; }
static gboolean chatroom_manager_file_parse (EmpathyChatroomManager *manager, const gchar *filename) { EmpathyChatroomManagerPriv *priv; xmlParserCtxtPtr ctxt; xmlDocPtr doc; xmlNodePtr chatrooms; xmlNodePtr node; priv = GET_PRIV (manager); DEBUG ("Attempting to parse file:'%s'...", filename); ctxt = xmlNewParserCtxt (); /* Parse and validate the file. */ doc = xmlCtxtReadFile (ctxt, filename, NULL, 0); if (doc == NULL) { g_warning ("Failed to parse file:'%s'", filename); xmlFreeParserCtxt (ctxt); return FALSE; } if (!empathy_xml_validate (doc, CHATROOMS_DTD_FILENAME)) { g_warning ("Failed to validate file:'%s'", filename); xmlFreeDoc (doc); xmlFreeParserCtxt (ctxt); return FALSE; } /* The root node, chatrooms. */ chatrooms = xmlDocGetRootElement (doc); for (node = chatrooms->children; node; node = node->next) { if (strcmp ((gchar *) node->name, "chatroom") == 0) chatroom_manager_parse_chatroom (manager, node); } DEBUG ("Parsed %d chatrooms", g_list_length (priv->chatrooms)); xmlFreeDoc (doc); xmlFreeParserCtxt (ctxt); return TRUE; }
static gboolean irc_network_manager_file_parse (EmpathyIrcNetworkManager *self, const gchar *filename, gboolean user_defined) { EmpathyIrcNetworkManagerPriv *priv; xmlParserCtxtPtr ctxt; xmlDocPtr doc; xmlNodePtr networks; xmlNodePtr node; priv = GET_PRIV (self); DEBUG ("Attempting to parse file:'%s'...", filename); ctxt = xmlNewParserCtxt (); /* Parse and validate the file. */ doc = xmlCtxtReadFile (ctxt, filename, NULL, 0); if (!doc) { g_warning ("Failed to parse file:'%s'", filename); xmlFreeParserCtxt (ctxt); return FALSE; } if (!empathy_xml_validate (doc, IRC_NETWORKS_DTD_FILENAME)) { g_warning ("Failed to validate file:'%s'", filename); xmlFreeDoc (doc); xmlFreeParserCtxt (ctxt); return FALSE; } /* The root node, networks. */ networks = xmlDocGetRootElement (doc); for (node = networks->children; node; node = node->next) { irc_network_manager_parse_irc_network (self, node, user_defined); } xmlFreeDoc(doc); xmlFreeParserCtxt (ctxt); return TRUE; }
static gboolean bt_song_io_native_xml_load (gconstpointer const _self, const BtSong * const song, GError ** err) { const BtSongIONativeXML *const self = BT_SONG_IO_NATIVE_XML (_self); xmlDocPtr song_doc; gchar *const file_name; guint len; gpointer data; gboolean result = FALSE; xmlParserCtxtPtr const ctxt = xmlNewParserCtxt (); if (!ctxt) { GST_WARNING ("failed to create parser context"); g_set_error (err, G_IO_ERROR, G_IO_ERROR_FAILED, "Failed to create parser context."); return FALSE; } g_object_get ((gpointer) self, "file-name", &file_name, "data", &data, "data-len", &len, NULL); GST_INFO ("native io xml will now load song from \"%s\"", file_name ? file_name : "data"); if (data && len) { // parse the file from the memory block song_doc = xmlCtxtReadMemory (ctxt, data, len, NULL, NULL, 0L); } else { // open the file from the file_name argument song_doc = xmlCtxtReadFile (ctxt, file_name, NULL, 0L); } if (song_doc) { result = bt_song_io_native_load (song_doc, song, err); xmlFreeDoc (song_doc); } else { bt_song_io_native_load_set_error (ctxt, file_name, err); } g_free (file_name); xmlFreeParserCtxt (ctxt); return result; }
int initxmlcfg(void** lpCtxt,void** lpxmlDoc) { xmlParserCtxtPtr ctxt; xmlDocPtr doc; char *file = "npconf.xml"; ctxt = xmlNewParserCtxt(); doc = xmlCtxtReadFile(ctxt, file, "GBK", XML_PARSE_DTDATTR|XML_PARSE_NOERROR); if (doc == NULL) { printf("Can't parse the content: %s\n", file); return 0; } *lpCtxt = ctxt; *lpxmlDoc = doc; return 1; }
int DPM_parse_tree::Initialize(const char *XMLFileName) { int rc; xmlParserCtxtPtr parser_context; valid = 0; if (! XMLFileName) { std::cerr << "ERROR: XML file name is NULL." << std::endl; std::cerr.flush(); rc = -1; } else { LIBXML_TEST_VERSION // Create a parser context. if ((parser_context = xmlNewParserCtxt()) == NULL) { std::cerr << "ERROR: Out of Memory" << std::endl; std::cerr.flush(); exit(0); } doc = xmlCtxtReadFile( parser_context, XMLFileName, NULL, XML_PARSE_DTDVALID ); if (doc == NULL) { std::cerr << "ERROR: Parse of XML file \"" << XMLFileName << "\"" << " failed." << std::endl; std::cerr.flush(); rc = -1; } else if (parser_context->valid == 0) { std::cerr << "WARNING: Validation of XML file \"" << XMLFileName << "\"" << " failed." << std::endl; std::cerr.flush(); rc = 0; } else { valid = 1; rc = 0; } xmlFreeParserCtxt(parser_context); } return rc; }
int main(int argc, const char *argv[]) { int status = 0; xmlParserCtxtPtr parser_context = 0; xmlDocPtr doc = 0; xmlDtdPtr dtd = 0; xmlValidCtxtPtr valid_context = 0; do { if (argc < 3) { status = 2; fprintf(stderr, "Too few arguments.\n"); break; } parser_context = xmlNewParserCtxt(); doc = xmlCtxtReadFile(parser_context, argv[1], NULL, 0); if (!doc) { status = 3; fprintf(stderr, "Can't read xml.\n"); break; } dtd = xmlParseDTD(NULL, (const xmlChar *)argv[2]); if (!dtd) { status = 4; fprintf(stderr, "Can't read dtd.\n"); break; } valid_context = xmlNewValidCtxt(); status = xmlValidateDtd(valid_context, doc, dtd) ? 0 : 1; } while (0); if (parser_context) xmlFreeParserCtxt(parser_context); if (doc) xmlFreeDoc(doc); if (dtd) xmlFreeDtd(dtd); if (valid_context) xmlFreeValidCtxt(valid_context); return status; }
static unsigned get_xml_shaders(const char *path, struct shader_program *prog, size_t size) { LIBXML_TEST_VERSION; xmlParserCtxtPtr ctx = xmlNewParserCtxt(); if (!ctx) { RARCH_ERR("Failed to load libxml2 context.\n"); return false; } RARCH_LOG("Loading XML shader: %s\n", path); xmlDocPtr doc = xmlCtxtReadFile(ctx, path, NULL, 0); xmlNodePtr head = NULL; xmlNodePtr cur = NULL; unsigned num = 0; if (!doc) { RARCH_ERR("Failed to parse XML file: %s\n", path); goto error; } #ifdef HAVE_LIBXML2 if (ctx->valid == 0) { RARCH_ERR("Cannot validate XML shader: %s\n", path); goto error; } #endif head = xmlDocGetRootElement(doc); for (cur = head; cur; cur = cur->next) { if (cur->type != XML_ELEMENT_NODE) continue; if (strcmp((const char*)cur->name, "shader") != 0) continue; char attr[64]; xml_get_prop(attr, sizeof(attr), cur, "language"); if (strcmp(attr, "GLSL") != 0) continue; xml_get_prop(attr, sizeof(attr), cur, "style"); glsl_modern = strcmp(attr, "GLES2") == 0; if (glsl_modern) RARCH_LOG("[GL]: Shader reports a GLES2 style shader.\n"); break; } if (!cur) // We couldn't find any GLSL shader :( goto error; memset(prog, 0, sizeof(struct shader_program) * size); // Iterate to check if we find fragment and/or vertex shaders. for (cur = cur->children; cur && num < size; cur = cur->next) { if (cur->type != XML_ELEMENT_NODE) continue; char *content = xml_get_content(cur); if (!content) continue; if (strcmp((const char*)cur->name, "vertex") == 0) { if (prog[num].vertex) { RARCH_ERR("Cannot have more than one vertex shader in a program.\n"); free(content); goto error; } content = xml_replace_if_file(content, path, cur, "src"); if (!content) { RARCH_ERR("Shader source file was provided, but failed to read.\n"); goto error; } prog[num].vertex = content; } else if (strcmp((const char*)cur->name, "fragment") == 0) { if (glsl_modern && !prog[num].vertex) { RARCH_ERR("Modern GLSL was chosen and vertex shader was not provided. This is an error.\n"); free(content); goto error; } content = xml_replace_if_file(content, path, cur, "src"); if (!content) { RARCH_ERR("Shader source file was provided, but failed to read.\n"); goto error; } prog[num].fragment = content; if (!get_xml_attrs(&prog[num], cur)) { RARCH_ERR("XML shader attributes do not comply with specifications.\n"); goto error; } num++; } else if (strcmp((const char*)cur->name, "texture") == 0) { free(content); if (!get_texture_image(path, cur)) { RARCH_ERR("Texture image failed to load.\n"); goto error; } } else if (strcmp((const char*)cur->name, "import") == 0) { free(content); if (!get_import_value(cur)) { RARCH_ERR("Import value is invalid.\n"); goto error; } } #ifdef HAVE_PYTHON else if (strcmp((const char*)cur->name, "script") == 0) { free(content); if (!get_script(path, cur)) { RARCH_ERR("Script is invalid.\n"); goto error; } } #endif } if (num == 0) { RARCH_ERR("Couldn't find vertex shader nor fragment shader in XML file.\n"); goto error; } xmlFreeDoc(doc); xmlFreeParserCtxt(ctx); return num; error: RARCH_ERR("Failed to load XML shader ...\n"); if (doc) xmlFreeDoc(doc); xmlFreeParserCtxt(ctx); return 0; }
static unsigned get_xml_shaders(const char *path, struct shader_program *prog, size_t size) { LIBXML_TEST_VERSION; xmlParserCtxtPtr ctx = xmlNewParserCtxt(); if (!ctx) { RARCH_ERR("Failed to load libxml2 context.\n"); return false; } RARCH_LOG("Loading XML shader: %s\n", path); xmlDocPtr doc = xmlCtxtReadFile(ctx, path, NULL, 0); xmlNodePtr head = NULL; xmlNodePtr cur = NULL; unsigned num = 0; if (!doc) { RARCH_ERR("Failed to parse XML file: %s\n", path); goto error; } if (ctx->valid == 0) { RARCH_ERR("Cannot validate XML shader: %s\n", path); goto error; } head = xmlDocGetRootElement(doc); for (cur = head; cur; cur = cur->next) { if (cur->type == XML_ELEMENT_NODE && strcmp((const char*)cur->name, "shader") == 0) { xmlChar *attr; attr = xmlGetProp(cur, (const xmlChar*)"language"); if (attr && strcmp((const char*)attr, "GLSL") == 0) { xmlFree(attr); break; } if (attr) xmlFree(attr); } } if (!cur) // We couldn't find any GLSL shader :( goto error; memset(prog, 0, sizeof(struct shader_program) * size); // Iterate to check if we find fragment and/or vertex shaders. for (cur = cur->children; cur && num < size; cur = cur->next) { if (cur->type != XML_ELEMENT_NODE) continue; xmlChar *content = xmlNodeGetContent(cur); if (!content) continue; if (strcmp((const char*)cur->name, "vertex") == 0) { if (prog[num].vertex) { RARCH_ERR("Cannot have more than one vertex shader in a program.\n"); xmlFree(content); goto error; } prog[num].vertex = (char*)content; } else if (strcmp((const char*)cur->name, "fragment") == 0) { prog[num].fragment = (char*)content; if (!get_xml_attrs(&prog[num], cur)) { RARCH_ERR("XML shader attributes do not comply with specifications.\n"); goto error; } num++; } else if (strcmp((const char*)cur->name, "texture") == 0) { if (!get_texture_image(path, cur)) { RARCH_ERR("Texture image failed to load.\n"); goto error; } } else if (strcmp((const char*)cur->name, "import") == 0) { if (!get_import_value(cur)) { RARCH_ERR("Import value is invalid.\n"); goto error; } } #ifdef HAVE_PYTHON else if (strcmp((const char*)cur->name, "script") == 0) { if (!get_script(path, cur)) { RARCH_ERR("Script is invalid.\n"); goto error; } } #endif } if (num == 0) { RARCH_ERR("Couldn't find vertex shader nor fragment shader in XML file.\n"); goto error; } xmlFreeDoc(doc); xmlFreeParserCtxt(ctx); return num; error: RARCH_ERR("Failed to load XML shader ...\n"); if (doc) xmlFreeDoc(doc); xmlFreeParserCtxt(ctx); return 0; }
/** * Program entry point. * * @param argc: Number of arguments passed to the program. * @param argv: Array of string arguments. * * @returns: EXIT_SUCCESS or EXIT_FAILURE depending upon success or failure * of the conversion to XML. */ int main(int argc, char **argv) { char *infilename, *outfilename; FILE *outfile; int successFlag; xmlParserCtxtPtr ctxt; xmlDocPtr doc; /* parse command line arguments */ if (argc != 3) { usage(argv[0]); return (EXIT_FAILURE); } else { infilename = argv[1]; outfilename = argv[2]; } /* attempt to parse the XML file */ LIBXML_TEST_VERSION ctxt = xmlNewParserCtxt(); if (ctxt == NULL) { printf("Failed to allocate XML parser context!\n"); return (EXIT_FAILURE); } doc = xmlCtxtReadFile(ctxt, infilename, NULL, XML_PARSE_DTDVALID); if (doc == NULL) { printf("Could not parse XML file \"%s\"!\n", infilename); xmlFreeParserCtxt(ctxt); return (EXIT_FAILURE); } /* attempt to open the output binary file */ //#ifdef WIN32 // outfile = _wfopen(utf8_decode(outfilename).c_str(), L"wb"); //#else outfile = fopen(outfilename, "wb"); //#endif if (outfile == NULL) { printf("Could not open file \"%s\" for writing!\n", outfilename); xmlFreeDoc(doc); xmlFreeParserCtxt(ctxt); xmlCleanupParser(); return (EXIT_FAILURE); } /* perform the conversion: XML -> binary */ successFlag = xml2g3d(doc, outfile); /* close the files */ xmlFreeDoc(doc); xmlFreeParserCtxt(ctxt); xmlCleanupParser(); fclose(outfile); /* return a success or failure flag */ if (successFlag) return (EXIT_SUCCESS); else return (EXIT_FAILURE); }
int main(int argc, char **argv) { int opt, r = 0; char *alt_config = NULL, *pub = NULL, *ver = NULL, *winfile = NULL; char prefix[2048]; enum { REBUILD, WINZONES, NONE } op = NONE; if ((geteuid()) == 0 && (become_cyrus(/*ismaster*/0) != 0)) { fatal("must run as the Cyrus user", EC_USAGE); } while ((opt = getopt(argc, argv, "C:r:vw:")) != EOF) { switch (opt) { case 'C': /* alt config file */ alt_config = optarg; break; case 'r': if (op == NONE) { op = REBUILD; pub = optarg; ver = strchr(optarg, ':'); if (ver) *ver++ = '\0'; else usage(); } else usage(); break; case 'v': verbose = 1; break; case 'w': if (op == NONE) { op = WINZONES; winfile = optarg; } else usage(); break; default: usage(); } } cyrus_init(alt_config, "ctl_zoneinfo", 0, 0); signals_set_shutdown(&shut_down); signals_add_handlers(0); snprintf(prefix, sizeof(prefix), "%s%s", config_dir, FNAME_ZONEINFODIR); switch (op) { case REBUILD: { struct hash_table tzentries; struct zoneinfo *info; struct txn *tid = NULL; char buf[1024]; FILE *fp; construct_hash_table(&tzentries, 500, 1); /* Add INFO record (overall lastmod and TZ DB source version) */ info = xzmalloc(sizeof(struct zoneinfo)); info->type = ZI_INFO; appendstrlist(&info->data, pub); appendstrlist(&info->data, ver); hash_insert(INFO_TZID, info, &tzentries); /* Add LEAP record (last updated and hash) */ snprintf(buf, sizeof(buf), "%s%s", prefix, FNAME_LEAPSECFILE); if (verbose) printf("Processing leap seconds file %s\n", buf); if (!(fp = fopen(buf, "r"))) { fprintf(stderr, "Could not open leap seconds file %s\n", buf); } else { struct zoneinfo *leap = xzmalloc(sizeof(struct zoneinfo)); leap->type = ZI_INFO; while(fgets(buf, sizeof(buf), fp)) { if (buf[0] == '#') { /* comment line */ if (buf[1] == '$') { /* last updated */ unsigned long last; sscanf(buf+2, "\t%lu", &last); leap->dtstamp = last - NIST_EPOCH_OFFSET; } else if (buf[1] == 'h') { /* hash */ char *p, *hash = buf+3 /* skip "#h\t" */; /* trim trailing whitespace */ for (p = hash + strlen(hash); isspace(*--p); *p = '\0'); appendstrlist(&leap->data, hash); } } } fclose(fp); hash_insert(LEAP_TZID, leap, &tzentries); info->dtstamp = leap->dtstamp; } /* Add ZONE/LINK records */ do_zonedir(prefix, &tzentries, info); zoneinfo_open(NULL); /* Store records */ hash_enumerate(&tzentries, &store_zoneinfo, &tid); zoneinfo_close(tid); free_hash_table(&tzentries, &free_zoneinfo); break; } case WINZONES: { xmlParserCtxtPtr ctxt; xmlDocPtr doc; xmlNodePtr node; struct buf tzidbuf = BUF_INITIALIZER; struct buf aliasbuf = BUF_INITIALIZER; if (verbose) printf("Processing Windows Zone file %s\n", winfile); /* Parse the XML file */ ctxt = xmlNewParserCtxt(); if (!ctxt) { fprintf(stderr, "Failed to create XML parser context\n"); break; } doc = xmlCtxtReadFile(ctxt, winfile, NULL, 0); xmlFreeParserCtxt(ctxt); if (!doc) { fprintf(stderr, "Failed to parse XML document\n"); break; } node = xmlDocGetRootElement(doc); if (!node || xmlStrcmp(node->name, BAD_CAST "supplementalData")) { fprintf(stderr, "Incorrect root node\n"); goto done; } for (node = xmlFirstElementChild(node); node && xmlStrcmp(node->name, BAD_CAST "windowsZones"); node = xmlNextElementSibling(node)); if (!node) { fprintf(stderr, "Missing windowsZones node\n"); goto done; } node = xmlFirstElementChild(node); if (!node || xmlStrcmp(node->name, BAD_CAST "mapTimezones")) { fprintf(stderr, "Missing mapTimezones node\n"); goto done; } if (chdir(prefix)) { fprintf(stderr, "chdir(%s) failed\n", prefix); goto done; } for (node = xmlFirstElementChild(node); node; node = xmlNextElementSibling(node)) { if (!xmlStrcmp(node->name, BAD_CAST "mapZone") && !xmlStrcmp(xmlGetProp(node, BAD_CAST "territory"), BAD_CAST "001")) { const char *tzid, *alias; buf_setcstr(&tzidbuf, (const char *) xmlGetProp(node, BAD_CAST "type")); buf_appendcstr(&tzidbuf, ".ics"); tzid = buf_cstring(&tzidbuf); buf_setcstr(&aliasbuf, (const char *) xmlGetProp(node, BAD_CAST "other")); buf_appendcstr(&aliasbuf, ".ics"); alias = buf_cstring(&aliasbuf); if (verbose) printf("\tLINK: %s -> %s\n", alias, tzid); if (symlink(tzid, alias)) { if (errno == EEXIST) { struct stat sbuf; if (stat(alias, &sbuf)) { fprintf(stderr, "stat(%s) failed: %s\n", alias, strerror(errno)); errno = EEXIST; } else if (sbuf.st_mode & S_IFLNK) { char link[MAX_MAILBOX_PATH+1]; int n = readlink(alias, link, MAX_MAILBOX_PATH); if (n == -1) { fprintf(stderr, "readlink(%s) failed: %s\n", alias, strerror(errno)); errno = EEXIST; } else if (n == (int) strlen(tzid) && !strncmp(tzid, link, n)) { errno = 0; } } } if (errno) { fprintf(stderr, "symlink(%s, %s) failed: %s\n", tzid, alias, strerror(errno)); } } } } done: buf_free(&aliasbuf); buf_free(&tzidbuf); xmlFreeDoc(doc); break; } case NONE: r = 2; usage(); break; } cyrus_done(); return r; }
static GList * log_store_empathy_get_messages_for_file (EmpathyLogStore *self, TpAccount *account, const gchar *filename) { GList *messages = NULL; xmlParserCtxtPtr ctxt; xmlDocPtr doc; xmlNodePtr log_node; xmlNodePtr node; g_return_val_if_fail (EMPATHY_IS_LOG_STORE (self), NULL); g_return_val_if_fail (filename != NULL, NULL); DEBUG ("Attempting to parse filename:'%s'...", filename); if (!g_file_test (filename, G_FILE_TEST_EXISTS)) { DEBUG ("Filename:'%s' does not exist", filename); return NULL; } /* Create parser. */ ctxt = xmlNewParserCtxt (); /* Parse and validate the file. */ doc = xmlCtxtReadFile (ctxt, filename, NULL, 0); if (!doc) { g_warning ("Failed to parse file:'%s'", filename); xmlFreeParserCtxt (ctxt); return NULL; } /* The root node, presets. */ log_node = xmlDocGetRootElement (doc); if (!log_node) { xmlFreeDoc (doc); xmlFreeParserCtxt (ctxt); return NULL; } /* Now get the messages. */ for (node = log_node->children; node; node = node->next) { EmpathyMessage *message; EmpathyContact *sender; gchar *time_; time_t t; gchar *sender_id; gchar *sender_name; gchar *sender_avatar_token; gchar *body; gchar *is_user_str; gboolean is_user = FALSE; gchar *msg_type_str; gchar *cm_id_str; guint cm_id; TpChannelTextMessageType msg_type = TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL; if (strcmp ((const gchar *) node->name, "message") != 0) continue; body = (gchar *) xmlNodeGetContent (node); time_ = (gchar *) xmlGetProp (node, (const xmlChar *) "time"); sender_id = (gchar *) xmlGetProp (node, (const xmlChar *) "id"); sender_name = (gchar *) xmlGetProp (node, (const xmlChar *) "name"); sender_avatar_token = (gchar *) xmlGetProp (node, (const xmlChar *) "token"); is_user_str = (gchar *) xmlGetProp (node, (const xmlChar *) "isuser"); msg_type_str = (gchar *) xmlGetProp (node, (const xmlChar *) "type"); cm_id_str = (gchar *) xmlGetProp (node, (const xmlChar *) "cm_id"); if (is_user_str) is_user = strcmp (is_user_str, "true") == 0; if (msg_type_str) msg_type = empathy_message_type_from_str (msg_type_str); if (cm_id_str) cm_id = atoi (cm_id_str); t = empathy_time_parse (time_); sender = empathy_contact_new_for_log (account, sender_id, sender_name, is_user); if (!EMP_STR_EMPTY (sender_avatar_token)) empathy_contact_load_avatar_cache (sender, sender_avatar_token); message = empathy_message_new (body); empathy_message_set_sender (message, sender); empathy_message_set_timestamp (message, t); empathy_message_set_tptype (message, msg_type); empathy_message_set_is_backlog (message, TRUE); if (cm_id_str) empathy_message_set_id (message, cm_id); messages = g_list_append (messages, message); g_object_unref (sender); xmlFree (time_); xmlFree (sender_id); xmlFree (sender_name); xmlFree (body); xmlFree (is_user_str); xmlFree (msg_type_str); xmlFree (cm_id_str); xmlFree (sender_avatar_token); } DEBUG ("Parsed %d messages", g_list_length (messages)); xmlFreeDoc (doc); xmlFreeParserCtxt (ctxt); return messages; }
cheat_manager_t *cheat_manager_new(const char *path) { LIBXML_TEST_VERSION; pretro_cheat_reset(); xmlParserCtxtPtr ctx = NULL; xmlDocPtr doc = NULL; cheat_manager_t *handle = (cheat_manager_t*)calloc(1, sizeof(struct cheat_manager)); if (!handle) return NULL; xmlNodePtr head = NULL; xmlNodePtr cur = NULL; handle->buf_size = 1; handle->cheats = (struct cheat*)calloc(handle->buf_size, sizeof(struct cheat)); if (!handle->cheats) { handle->buf_size = 0; goto error; } ctx = xmlNewParserCtxt(); if (!ctx) goto error; doc = xmlCtxtReadFile(ctx, path, NULL, 0); if (!doc) { RARCH_ERR("Failed to parse XML file: %s\n", path); goto error; } #ifdef HAVE_LIBXML2 if (ctx->valid == 0) { RARCH_ERR("Cannot validate XML file: %s\n", path); goto error; } #endif head = xmlDocGetRootElement(doc); for (cur = head; cur; cur = cur->next) { if (cur->type == XML_ELEMENT_NODE && strcmp((const char*)cur->name, "database") == 0) break; } if (!cur) goto error; for (cur = cur->children; cur; cur = cur->next) { if (cur->type != XML_ELEMENT_NODE) continue; if (strcmp((const char*)cur->name, "cartridge") == 0) { xmlChar *sha256 = xmlGetProp(cur, (const xmlChar*)"sha256"); if (!sha256) continue; if (*g_extern.sha256 && strcmp((const char*)sha256, g_extern.sha256) == 0) { xmlFree(sha256); break; } xmlFree(sha256); } } if (!cur) goto error; if (!xml_grab_cheats(handle, cur->children)) { RARCH_ERR("Failed to grab cheats. This should not happen.\n"); goto error; } if (handle->size == 0) { RARCH_ERR("Did not find any cheats in XML file: %s\n", path); goto error; } cheat_manager_load_config(handle, g_settings.cheat_settings_path, g_extern.sha256); xmlFreeDoc(doc); xmlFreeParserCtxt(ctx); return handle; error: cheat_manager_free(handle); if (doc) xmlFreeDoc(doc); if (ctx) xmlFreeParserCtxt(ctx); return NULL; }
gint main (gint argc, gchar **argv) { GOptionContext *context; xmlParserCtxtPtr parser; xmlDocPtr doc; YelpTransform *transform; gchar **params; const gchar *stylesheet; gchar *file; context = g_option_context_new ("[STYLESHEET] FILE"); g_option_context_add_main_entries (context, options, NULL); g_option_context_parse (context, &argc, &argv, NULL); if (files == NULL || files[0] == NULL) { g_printerr ("Usage: test-transform [OPTION...] [STYLESHEET] FILE\n"); return 1; } if (files[1] == NULL) { stylesheet = DATADIR"/yelp/xslt/db2html.xsl"; file = files[0]; } else { stylesheet = files[0]; file = files[1]; } params = g_new0 (gchar *, 7); params[0] = g_strdup ("db.chunk.extension"); params[1] = g_strdup ("\"\""); params[2] = g_strdup ("db.chunk.info_basename"); params[3] = g_strdup ("\"x-yelp-titlepage\""); params[4] = g_strdup ("db.chunk.max_depth"); params[5] = g_strdup ("2"); params[6] = NULL; transform = yelp_transform_new (stylesheet); g_object_weak_ref ((GObject *) transform, transform_destroyed, NULL); g_signal_connect (transform, "chunk-ready", (GCallback) transform_chunk, NULL); g_signal_connect (transform, "finished", (GCallback) transform_finished, NULL); g_signal_connect (transform, "error", (GCallback) transform_error, NULL); parser = xmlNewParserCtxt (); doc = xmlCtxtReadFile (parser, file, NULL, XML_PARSE_DTDLOAD | XML_PARSE_NOCDATA | XML_PARSE_NOENT | XML_PARSE_NONET ); xmlFreeParserCtxt (parser); xmlXIncludeProcessFlags (doc, XML_PARSE_DTDLOAD | XML_PARSE_NOCDATA | XML_PARSE_NOENT | XML_PARSE_NONET ); if (!yelp_transform_start (transform, doc, (xmlDocPtr)params, NULL)) return 1; if (random_timeout) { GRand *rand = g_rand_new (); timeout = g_rand_int_range (rand, 80, 280); g_rand_free (rand); } if (timeout >= 0) g_timeout_add (timeout, (GSourceFunc) transform_release, transform); loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (loop); return 0; }
GList * empathy_log_manager_get_messages_for_file (EmpathyLogManager *manager, const gchar *filename) { GList *messages = NULL; xmlParserCtxtPtr ctxt; xmlDocPtr doc; xmlNodePtr log_node; xmlNodePtr node; EmpathyLogSearchHit *hit; McAccount *account; g_return_val_if_fail (EMPATHY_IS_LOG_MANAGER (manager), NULL); g_return_val_if_fail (filename != NULL, NULL); DEBUG ("Attempting to parse filename:'%s'...", filename); if (!g_file_test (filename, G_FILE_TEST_EXISTS)) { DEBUG ("Filename:'%s' does not exist", filename); return NULL; } /* Get the account from the filename */ hit = log_manager_search_hit_new (manager, filename); account = g_object_ref (hit->account); log_manager_search_hit_free (hit); /* Create parser. */ ctxt = xmlNewParserCtxt (); /* Parse and validate the file. */ doc = xmlCtxtReadFile (ctxt, filename, NULL, 0); if (!doc) { g_warning ("Failed to parse file:'%s'", filename); xmlFreeParserCtxt (ctxt); return NULL; } /* The root node, presets. */ log_node = xmlDocGetRootElement (doc); if (!log_node) { xmlFreeDoc (doc); xmlFreeParserCtxt (ctxt); return NULL; } /* Now get the messages. */ for (node = log_node->children; node; node = node->next) { EmpathyMessage *message; EmpathyContact *sender; gchar *time; time_t t; gchar *sender_id; gchar *sender_name; gchar *sender_avatar_token; gchar *body; gchar *is_user_str; gboolean is_user = FALSE; gchar *msg_type_str; TpChannelTextMessageType msg_type = TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL; if (strcmp (node->name, "message") != 0) { continue; } body = xmlNodeGetContent (node); time = xmlGetProp (node, "time"); sender_id = xmlGetProp (node, "id"); sender_name = xmlGetProp (node, "name"); sender_avatar_token = xmlGetProp (node, "token"); is_user_str = xmlGetProp (node, "isuser"); msg_type_str = xmlGetProp (node, "type"); if (is_user_str) { is_user = strcmp (is_user_str, "true") == 0; } if (msg_type_str) { msg_type = empathy_message_type_from_str (msg_type_str); } t = empathy_time_parse (time); sender = empathy_contact_new_full (account, sender_id, sender_name); empathy_contact_set_is_user (sender, is_user); if (!EMP_STR_EMPTY (sender_avatar_token)) { empathy_contact_load_avatar_cache (sender, sender_avatar_token); } message = empathy_message_new (body); empathy_message_set_sender (message, sender); empathy_message_set_timestamp (message, t); empathy_message_set_tptype (message, msg_type); messages = g_list_append (messages, message); g_object_unref (sender); xmlFree (time); xmlFree (sender_id); xmlFree (sender_name); xmlFree (body); xmlFree (is_user_str); xmlFree (msg_type_str); } DEBUG ("Parsed %d messages", g_list_length (messages)); xmlFreeDoc (doc); xmlFreeParserCtxt (ctxt); return messages; }
AppConfig::AppConfig(std::string& xmlfile) : analyticsEnabled(true), updateMonitorEnabled(true) { systemProperties = new PropertiesBinding(); xmlParserCtxtPtr context = xmlNewParserCtxt(); xmlDocPtr document = xmlCtxtReadFile(context, xmlfile.c_str(), NULL, 0); if (!document) { std::ostringstream error; if (context->lastError.code != XML_IO_LOAD_ERROR) { error << context->lastError.file << "[Line "; error << context->lastError.line << "] "; } error << context->lastError.message; GetLogger()->Error(error.str()); xmlFreeParserCtxt(context); xmlCleanupParser(); return; } xmlNodePtr root = xmlDocGetRootElement(document); xmlNodePtr node = root->children; while (node) { if (node->type != XML_ELEMENT_NODE) { node = node->next; continue; } // This should always be a UTF-8, so we can just cast // the node name here to a char* std::string nodeName(reinterpret_cast<char*>( const_cast<xmlChar*>(node->name))); if (nodeName == "name") { appName = ConfigUtils::GetNodeValue(node); } else if (nodeName == "id") { appID = ConfigUtils::GetNodeValue(node); } else if (nodeName == "description") { description = ConfigUtils::GetNodeValue(node); } else if (nodeName == "copyright") { copyright = ConfigUtils::GetNodeValue(node); } else if (nodeName == "url") { url = ConfigUtils::GetNodeValue(node); } else if (nodeName == "version") { version = ConfigUtils::GetNodeValue(node); } else if (nodeName == "publisher") { publisher = ConfigUtils::GetNodeValue(node); } else if (nodeName == "window") { this->windows.push_back(WindowConfig::FromXMLNode(node)); } else if (nodeName == "analytics") { std::string nodeValue(ConfigUtils::GetNodeValue(node)); analyticsEnabled = ConfigUtils::StringToBool(nodeValue); } else if (nodeName == "update-monitor") { std::string nodeValue(ConfigUtils::GetNodeValue(node)); updateMonitorEnabled = ConfigUtils::StringToBool(nodeValue); } else if (nodeName == "icon") { icon = ConfigUtils::GetNodeValue(node); } else if (nodeName == "property") { ParsePropertyNode(node, systemProperties->GetConfig()); } else if (nodeName == "title") { appTitle = ConfigUtils::GetNodeValue(node); } node = node->next; } xmlFreeDoc(document); xmlFreeParserCtxt(context); xmlCleanupParser(); }
/* ************************************************** */ int do_configuration(void) { xmlSchemaValidCtxtPtr sv_ctxt = NULL; xmlSchemaParserCtxtPtr sp_ctxt = NULL; xmlSchemaPtr schema = NULL; xmlParserCtxtPtr p_ctxt = NULL; xmlDocPtr doc = NULL; xmlXPathContextPtr xp_ctx = NULL; xmlXPathObjectPtr simul_xobj = NULL; xmlXPathObjectPtr entity_xobj = NULL; xmlXPathObjectPtr environment_xobj = NULL; xmlXPathObjectPtr bundle_xobj = NULL; xmlXPathObjectPtr node_xobj = NULL; xmlNodeSetPtr nodeset; xmlpathobj_t xpathobj[] = {{&simul_xobj, (xmlChar *) XML_X_SIMULATION}, {&entity_xobj, (xmlChar *) XML_X_ENTITY}, {&environment_xobj, (xmlChar *) XML_X_ENVIRONMENT}, {&bundle_xobj, (xmlChar *) XML_X_BUNDLE}, {&node_xobj, (xmlChar *) XML_X_NODE}}; int ok = 0, i; /* Check XML version */ LIBXML_TEST_VERSION; /* Initialise and parse schema */ sp_ctxt = xmlSchemaNewParserCtxt(schemafile); if (sp_ctxt == NULL) { fprintf(stderr, "config: XML schema parser initialisation failure (do_configuration())\n"); ok = -1; goto cleanup; } xmlSchemaSetParserErrors(sp_ctxt, (xmlSchemaValidityErrorFunc) xml_error, (xmlSchemaValidityWarningFunc) xml_warning, NULL); schema = xmlSchemaParse(sp_ctxt); if (schema == NULL) { fprintf(stderr, "config: error in schema %s (do_configuration())\n", schemafile); ok = -1; goto cleanup; } xmlSchemaSetValidErrors(sv_ctxt, (xmlSchemaValidityErrorFunc) xml_error, (xmlSchemaValidityWarningFunc) xml_warning, NULL); sv_ctxt = xmlSchemaNewValidCtxt(schema); if (sv_ctxt == NULL) { fprintf(stderr, "config: XML schema validator initialisation failure (do_configuration())\n"); ok = -1; goto cleanup; } /* Initialise and parse document */ p_ctxt = xmlNewParserCtxt(); if (p_ctxt == NULL) { fprintf(stderr, "config: XML parser initialisation failure (do_configuration())\n"); ok = -1; goto cleanup; } doc = xmlCtxtReadFile(p_ctxt, configfile, NULL, XML_PARSE_NONET | XML_PARSE_NOBLANKS | XML_PARSE_NSCLEAN); if (doc == NULL) { fprintf(stderr, "config: failed to parse %s (do_configuration())\n", configfile); ok = -1; goto cleanup; } /* Validate document */ if (xmlSchemaValidateDoc(sv_ctxt, doc)) { fprintf(stderr, "config: error in configuration file %s (do_configuration())\n", configfile); ok = -1; goto cleanup; } /* Create xpath context */ xp_ctx = xmlXPathNewContext(doc); if (xp_ctx == NULL) { fprintf(stderr, "config: XPath initialisation failure (do_configuration())\n"); ok = -1; goto cleanup; } xmlXPathRegisterNs(xp_ctx, (xmlChar *) XML_NS_ID, (xmlChar *) XML_NS_URL); /* Get xpath obj */ for (i = 0 ; i < (int) (sizeof(xpathobj) / sizeof(xpathobj[0])); i++) { *xpathobj[i].ptr = xmlXPathEvalExpression(xpathobj[i].expr, xp_ctx); if (*xpathobj[i].ptr == NULL) { fprintf(stderr, "config: unable to evaluate xpath \"%s\" (do_configuration())\n", xpathobj[i].expr); ok = -1; goto cleanup; } } /***************/ /* Counting... */ /***************/ nodeset = entity_xobj->nodesetval; if ((entities.size = (nodeset) ? nodeset->nodeNr : 0) == 0) { fprintf(stderr, "config: no entity defined (do_configuration())\n"); ok = -1; goto cleanup; } fprintf(stderr, "\nFound %d entities...\n", entities.size); nodeset = environment_xobj->nodesetval; if (((nodeset) ? nodeset->nodeNr : 0) == 0) { fprintf(stderr, "config: no environment defined (do_configuration())\n"); ok = -1; goto cleanup; } fprintf(stderr, "Found 1 environment...\n"); nodeset = bundle_xobj->nodesetval; if ((bundles.size = (nodeset) ? nodeset->nodeNr : 0) == 0) { fprintf(stderr, "config: no bundle defined (do_configuration())\n"); ok = -1; goto cleanup; } fprintf(stderr, "Found %d bundles...\n", bundles.size); if ((dflt_params = das_create()) == NULL) { ok = -1; goto cleanup; } /**************/ /* Simulation */ /**************/ if (parse_simulation(simul_xobj->nodesetval)) { ok = -1; goto cleanup; } /**********/ /* Entity */ /**********/ /* initialize library paths */ config_set_usr_modulesdir(); user_path_list = g_strsplit(user_modulesdir, ":", 0); /* TOCLEAN */ sys_path_list = g_strsplit(sys_modulesdir, ":", 0); /* TOCLEAN */ /* parse */ if (parse_entities(entity_xobj->nodesetval)) { ok = -1; goto cleanup; } /**************/ /* Measure */ /**************/ if (parse_measure()) { ok = -1; goto cleanup; } /***************/ /* Environment */ /***************/ if (parse_environment(environment_xobj->nodesetval)) { ok = -1; goto cleanup; } /***************/ /* Bundle */ /***************/ if (parse_bundles(bundle_xobj->nodesetval)) { ok = -1; goto cleanup; } /***************/ /* Nodes */ /***************/ if (parse_nodes(node_xobj->nodesetval)) { ok = -1; goto cleanup; } /* edit by Quentin Lampin <*****@*****.**> */ gchar **path = NULL; for (path = user_path_list ; *path ; path++) { g_free(*path); } path = NULL; for (path = sys_path_list ; *path ; path++) { g_free(*path); } /* end of edition */ cleanup: clean_params(); for (i = 0 ; i < (int) (sizeof(xpathobj) / sizeof(xpathobj[0])); i++) { xmlXPathFreeObject(*xpathobj[i].ptr); } if (xp_ctx) { xmlXPathFreeContext(xp_ctx); } if (sp_ctxt) { xmlSchemaFreeParserCtxt(sp_ctxt); } if (schema) { xmlSchemaFree(schema); } if (sv_ctxt) { xmlSchemaFreeValidCtxt(sv_ctxt); } if (doc) { xmlFreeDoc(doc); } if (p_ctxt) { xmlFreeParserCtxt(p_ctxt); } xmlCleanupParser(); return ok; }
int xmi_xmso_to_htm_xslt(char *xmsofile, char *xmsifile, unsigned convoluted) { xsltStylesheetPtr cur = NULL; xmlDocPtr doc, res; xmlParserCtxtPtr ctx; const char *params[3]; char catalog[] = XMI_CATALOG; xmlXPathContextPtr xpathCtx; xmlXPathObjectPtr xpathObj; char parm_name[] = "type1"; char s_convoluted[] = "'convoluted'"; char s_unconvoluted[] = "'unconvoluted'"; #ifdef G_OS_WIN32 xmlChar *xsltfile; if (xmi_registry_win_query(XMI_REGISTRY_WIN_XMSO2HTM,(char **) &xsltfile) == 0) return 0; #elif defined(MAC_INTEGRATION) xmlChar *xsltfile; if (xmi_resources_mac_query(XMI_RESOURCES_MAC_XMSO2HTM,(char **) &xsltfile) == 0) return 0; #else const xmlChar xsltfile[] = XMI_XMSO2HTM_XSLT; #endif xsltInit(); params[0] = parm_name; if ( convoluted ) params[1] = s_convoluted; else params[1] = s_unconvoluted; params[2] = NULL; //fprintf(stdout, "parm 0 = %s \n", params[0] ); //fprintf(stdout, "parm 1 = %s \n", params[1] ); //fprintf(stdout, "parm 2 = %s \n", params[2] ); cur = xsltParseStylesheetFile(xsltfile); if (cur == NULL) return 0; #if defined(G_OS_WIN32) || defined (MAC_INTEGRATION) free(xsltfile); #endif if ((ctx=xmlNewParserCtxt()) == NULL) { fprintf(stderr,"xmlNewParserCtxt error\n"); return 0; } if ((doc = xmlCtxtReadFile(ctx,xmsofile,NULL,XML_PARSE_DTDVALID | XML_PARSE_NOBLANKS | XML_PARSE_DTDATTR)) == NULL) { fprintf(stderr,"xmlCtxtReadFile error for %s\n",xmsofile); xmlFreeParserCtxt(ctx); return 0; } if (ctx->valid == 0) { fprintf(stderr,"Error validating %s\n",xmsofile); xmlFreeDoc(doc); return 0; } xmlFreeParserCtxt(ctx); res = xsltApplyStylesheet(cur, doc, params); if (res == NULL) return 0; xsltSaveResultToFilename(xmsifile, res, cur, 0); xsltFreeStylesheet(cur); xmlFreeDoc(res); xmlFreeDoc(doc); xsltCleanupGlobals(); return 1; }
int xmi_xmso_to_xmsi_xslt(char *xmsofile, char *xmsifile , char *outputfile ) { xsltStylesheetPtr cur = NULL; xmlDocPtr doc, res; xmlParserCtxtPtr ctx; const char *params[1] = {NULL}; xmlXPathContextPtr xpathCtx; xmlXPathObjectPtr xpathObj; #ifdef G_OS_WIN32 xmlChar *xsltfile; if (xmi_registry_win_query(XMI_REGISTRY_WIN_XMSO2XMSI,(char **) &xsltfile) == 0) return 0; #elif defined(MAC_INTEGRATION) xmlChar *xsltfile; if (xmi_resources_mac_query(XMI_RESOURCES_MAC_XMSO2XMSI,(char **) &xsltfile) == 0) return 0; #else const xmlChar xsltfile[] = XMI_XMSO2XMSI_XSLT; #endif xsltInit(); cur = xsltParseStylesheetFile(xsltfile); if (cur == NULL) return 0; #if defined(G_OS_WIN32) || defined (MAC_INTEGRATION) free(xsltfile); #endif if ((ctx=xmlNewParserCtxt()) == NULL) { fprintf(stderr,"xmlNewParserCtxt error\n"); return 0; } if ((doc = xmlCtxtReadFile(ctx,xmsofile,NULL,XML_PARSE_DTDVALID | XML_PARSE_NOBLANKS | XML_PARSE_DTDATTR)) == NULL) { fprintf(stderr,"xmlCtxtReadFile error for %s\n",xmsofile); xmlFreeParserCtxt(ctx); return 0; } if (ctx->valid == 0) { fprintf(stderr,"Error validating %s\n",xmsofile); xmlFreeDoc(doc); return 0; } xmlFreeParserCtxt(ctx); res = xsltApplyStylesheet(cur, doc, params); if (res == NULL) return 0; if (outputfile != NULL) { xpathCtx = xmlXPathNewContext(res); if(xpathCtx == NULL) { fprintf(stderr,"Error: unable to create new XPath context\n"); return 0; } xpathObj = xmlXPathEvalExpression((const xmlChar *) "/xmimsim/general/outputfile", xpathCtx); if(xpathObj == NULL) { fprintf(stderr,"Error: unable to evaluate xpath expression \"%s\"\n","xmimsim/general/outputfile" ); xmlXPathFreeContext(xpathCtx); return 0; } update_xpath_nodes(xpathObj->nodesetval, (const xmlChar *) outputfile); xmlXPathFreeObject(xpathObj); xmlXPathFreeContext(xpathCtx); } xsltSaveResultToFilename(xmsifile, res, cur, 0); xsltFreeStylesheet(cur); xmlFreeDoc(res); xmlFreeDoc(doc); xsltCleanupGlobals(); return 1; }
static void status_presets_file_parse (const gchar *filename) { xmlParserCtxtPtr ctxt; xmlDocPtr doc; xmlNodePtr presets_node; xmlNodePtr node; DEBUG ("Attempting to parse file:'%s'...", filename); ctxt = xmlNewParserCtxt (); /* Parse and validate the file. */ doc = xmlCtxtReadFile (ctxt, filename, NULL, 0); if (!doc) { g_warning ("Failed to parse file:'%s'", filename); xmlFreeParserCtxt (ctxt); return; } if (!tpaw_xml_validate_from_resource (doc, STATUS_PRESETS_DTD_RESOURCENAME)) { g_warning ("Failed to validate file:'%s'", filename); xmlFreeDoc (doc); xmlFreeParserCtxt (ctxt); return; } /* The root node, presets. */ presets_node = xmlDocGetRootElement (doc); node = presets_node->children; while (node) { if (strcmp ((gchar *) node->name, "status") == 0 || strcmp ((gchar *) node->name, "default") == 0) { TpConnectionPresenceType state; gchar *status; gchar *state_str; StatusPreset *preset; gboolean is_default = FALSE; if (strcmp ((gchar *) node->name, "default") == 0) { is_default = TRUE; } status = (gchar *) xmlNodeGetContent (node); state_str = (gchar *) xmlGetProp (node, (const xmlChar *) "presence"); if (state_str) { state = empathy_presence_from_str (state_str); if (empathy_status_presets_is_valid (state)) { if (is_default) { DEBUG ("Default status preset state is:" " '%s', status:'%s'", state_str, status); status_presets_set_default (state, status); } else { preset = status_preset_new (state, status); presets = g_list_append (presets, preset); } } } xmlFree (status); xmlFree (state_str); } node = node->next; } /* Use the default if not set */ if (!default_preset) { status_presets_set_default (TP_CONNECTION_PRESENCE_TYPE_OFFLINE, NULL); } DEBUG ("Parsed %d status presets", g_list_length (presets)); xmlFreeDoc (doc); xmlFreeParserCtxt (ctxt); }