Beispiel #1
0
static void readxml(const char *name)
{
	mode = 'r'; 
	reader = xmlReaderForFile(name, NULL, 0);
	xmlTextReaderRead(reader); // skip root
	while (xmlTextReaderRead(reader) == 1) {
		all_decl();
	}
	xmlFreeTextReader(reader);
}
Beispiel #2
0
/**
 * Read the xml document in from a file
 * @param   xml The xml document
 * @param   filename The source xml input filename
 * @return  @c TRUE if successful, @c FALSE if an error occurs.
 * @ingroup EXML_Read_Group
 */
int exml_file_read(EXML *xml, char *filename)
{
	xmlTextReaderPtr reader;

	CHECK_PARAM_POINTER_RETURN("xml", xml, FALSE);

	reader = xmlReaderForFile( filename, NULL, XML_PARSE_RECOVER );

	return _exml_read(xml, reader);
}
Beispiel #3
0
void xml_loader::XmlLoader4Viper::LoadFromFile( const char* file_name  ){
	m_reader = xmlReaderForFile( file_name, NULL, 0);	
	if(m_reader==NULL)
	{
		printf("fail to open xml file %s. So quit now\n", file_name);
		exit(0);
	}
	else
		cout << BASH_ESC_RED << "XML Open Success:" <<  file_name;
	cout << BASH_ESC_WHITE << endl;
}
Beispiel #4
0
/* {{{ proto boolean XMLReader::open(string URI [, string encoding [, int options]])
Sets the URI that the XMLReader will parse. */
PHP_METHOD(xmlreader, open)
{
	zval *id;
	size_t source_len = 0, encoding_len = 0;
	zend_long options = 0;
	xmlreader_object *intern = NULL;
	char *source, *valid_file = NULL;
	char *encoding = NULL;
	char resolved_path[MAXPATHLEN + 1];
	xmlTextReaderPtr reader = NULL;

	if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|s!l", &source, &source_len, &encoding, &encoding_len, &options) == FAILURE) {
		return;
	}

	id = getThis();
	if (id != NULL) {
		if (! instanceof_function(Z_OBJCE_P(id), xmlreader_class_entry)) {
			id = NULL;
		} else {
			intern = Z_XMLREADER_P(id);
			xmlreader_free_resources(intern);
		}
	}

	if (!source_len) {
		php_error_docref(NULL, E_WARNING, "Empty string supplied as input");
		RETURN_FALSE;
	}

	valid_file = _xmlreader_get_valid_file_path(source, resolved_path, MAXPATHLEN );

	if (valid_file) {
		reader = xmlReaderForFile(valid_file, encoding, options);
	}

	if (reader == NULL) {
		php_error_docref(NULL, E_WARNING, "Unable to open source data");
		RETURN_FALSE;
	}

	if (id == NULL) {
		object_init_ex(return_value, xmlreader_class_entry);
		intern = Z_XMLREADER_P(return_value);
		intern->ptr = reader;
		return;
	}

	intern->ptr = reader;

	RETURN_TRUE;

}
Beispiel #5
0
/*
 * Parse the configuration file and initialize ows struct
 */
static void ows_parse_config_xml(ows * o, const char *filename)
{
    xmlTextReaderPtr r;
    const xmlChar *name;
    int ret;

    assert(o);
    assert(filename);

    r = xmlReaderForFile(filename, "UTF-8", 0);
    if (!r) {
        ows_error(o, OWS_ERROR_CONFIG_FILE, "Unable to open config file !", "parse_config_file");
        return;
    }

    if (!o->layers) o->layers = ows_layer_list_init();

    while ((ret = xmlTextReaderRead(r)) == 1) {
        if (xmlTextReaderNodeType(r) == XML_READER_TYPE_ELEMENT) {
            name = xmlTextReaderConstLocalName(r);

            if (!strcmp((char *) name, "tinyows"))
                ows_parse_config_tinyows(o, r);

            if (!strcmp((char *) name, "metadata"))
                ows_parse_config_metadata(o, r);

            if (!strcmp((char *) name, "abstract"))
                ows_parse_config_abstract(o, r);

            if (!strcmp((char *) name, "contact"))
                ows_parse_config_contact(o, r);

            if (!strcmp((char *) name, "pg"))
                ows_parse_config_pg(o, r);

            if (!strcmp((char *) name, "limits"))
                ows_parse_config_limits(o, r);

            if (!strcmp((char *) name, "layer"))
                ows_parse_config_layer(o, r);
        }
    }

    if (ret != 0) {
        xmlFreeTextReader(r);
        ows_error(o, OWS_ERROR_CONFIG_FILE, "Unable to open config file !", "parse_config_file");
        return;
    }

    xmlFreeTextReader(r);
}
Beispiel #6
0
/**
 * streamFile:
 * @filename: the file name to parse
 *
 * Parse, validate and print information about an XML file.
 */
node	*getNodeTable( const char *filename, int *_count) {
	xmlTextReaderPtr reader;
	int ret;
	node	*nodeTable ;
	nodeTable	=	NULL ;
	/*
	* Pass some special parsing options to activate DTD attribute defaulting,
	* entities substitution and DTD validation
	*/
//	reader = xmlReaderForFile(filename, NULL,
//				XML_PARSE_DTDATTR |  /* default DTD attributes */
//				XML_PARSE_NOENT |    /* substitute entities */
//				XML_PARSE_DTDVALID); /* validate with the DTD */
	reader = xmlReaderForFile(filename, NULL, XML_PARSE_DTDATTR | XML_PARSE_NOENT) ;
	if (reader != NULL) {
		*_count	=	count( reader);
		nodeTable	=	malloc( *_count * ( sizeof( node))) ;
		xmlFreeTextReader(reader) ;
		/**
		 * re-open the xml file and build the table
		 */
		reader	 =	xmlReaderForFile(filename, NULL, XML_PARSE_NOENT) ;
		processNode( reader, nodeTable) ;
		/**
		 * Once the document has been fully parsed check the validation results
		 */
//		if ( xmlTextReaderIsValid( reader) != 1) {
//			fprintf(stderr, "Document %s does not validate\n", filename);
//		}
		xmlFreeTextReader(reader);
		if (ret != 0) {
			fprintf(stderr, "%s : failed to parse\n", filename);
		}
	} else {
		fprintf(stderr, "Unable to open %s\n", filename);
	}
	return nodeTable ;
}
Beispiel #7
0
static xmlTextReaderPtr create_parser(const char *filename) {
	xmlTextReaderPtr reader = NULL;
	if ((reader = xmlReaderForFile(filename, NULL, 0))) {

		xmlTextReaderSetErrorHandler(reader, error_handler, NULL);

		if (xmlTextReaderRead(reader) != 1) {
			xmlFreeTextReader(reader);
			reader = NULL;
		}
	} else {
		tmx_err(E_UNKN, "xml parser: unable to open %s", filename);
	}
	return reader;
}
Beispiel #8
0
int xml_script_reader_init(const char *filename) {

    if (NULL != _p_xml_reader) {
        LOG_ERROR("xml_script_reader_init() failed - xml reader is already initialized.");
        return 1;
    }

    /* Create a new XmlWriter for uri, with no compression. */
    if (NULL == (_p_xml_reader = xmlReaderForFile(filename, NULL, 0))) {
        LOG_ERROR("xml_script_reader_init() failed - cannot create xml read for file '%s'.", filename);
        return 1;
    }

    return 0;
}
Beispiel #9
0
/**
 * glista_storage_get_all_items:
 * @list: Pointer to a GList* to populate with GlistaItem objects
 *
 * Load all items from storage into a linked-list, which will be in turn used
 * to load the data into the GtkListStore of the UI.
 */
void
glista_storage_load_all_items(GList **list)
{
	xmlTextReaderPtr  xml;
	gchar            *storage_file;
	xmlChar          *node_name;
	GlistaItem       *item;
	
	// Build storage file path
	storage_file = g_build_filename(gl_globs->configdir, GL_XML_FILENAME, NULL);
	
	// Open XML file
	if ((xml = xmlReaderForFile(storage_file, GL_XML_ENCODING, 0)) != NULL) {
		
		// Read the XML root node
		if (xmlTextReaderRead(xml) == 1) {
			node_name = xmlTextReaderName(xml);
			
			if (xmlStrEqual(node_name, BAD_CAST GL_XNODE_ROOT)) {
				
				// Read all items 
				while ((item = read_next_item(xml)) != NULL) {
					if (item->text != NULL) {
						*list = g_list_append(*list, item);
					} else {
						glista_item_free(item);
					}
				}
				
			} else {
				g_warning("Invalid XML file: unexpected root element '%s'\n", 
				           node_name);
			}
			
			xmlFree(node_name);
			
		} else {
			g_warning("Invalid XML file: unable to read root element\n");
		}
		
		xmlFreeTextReader(xml);
	}
	
	g_free(storage_file);
}
Beispiel #10
0
/**
 * streamFile:
 * @filename: the file name to parse
 *
 * Parse and print information about an XML file.
 *
 * Returns the resulting doc with just the elements preserved.
 */
static xmlDocPtr
extractFile(const char *filename, const xmlChar *pattern) {
    xmlDocPtr doc;
    xmlTextReaderPtr reader;
    int ret;

    /*
     * build an xmlReader for that file
     */
    reader = xmlReaderForFile(filename, NULL, 0);
    if (reader != NULL) {
        /*
	 * add the pattern to preserve
	 */
        if (xmlTextReaderPreservePattern(reader, pattern, NULL) < 0) {
            fprintf(stderr, "%s : failed add preserve pattern %s\n",
	            filename, (const char *) pattern);
	}
	/*
	 * Parse and traverse the tree, collecting the nodes in the process
	 */
        ret = xmlTextReaderRead(reader);
        while (ret == 1) {
            ret = xmlTextReaderRead(reader);
        }
        if (ret != 0) {
            fprintf(stderr, "%s : failed to parse\n", filename);
	    xmlFreeTextReader(reader);
	    return(NULL);
        }
	/*
	 * get the resulting nodes
	 */
	doc = xmlTextReaderCurrentDoc(reader);
	/*
	 * Free up the reader
	 */
        xmlFreeTextReader(reader);
    } else {
        fprintf(stderr, "Unable to open %s\n", filename);
	return(NULL);
    }
    return(doc);
}
Beispiel #11
0
/**
 * streamFile:
 * @filename: the file name to parse
 *
 * Parse and print information about an XML file.
 */
static void streamFile (const char *filename) {
	xmlTextReaderPtr reader;
	int ret;

	reader = xmlReaderForFile (filename, NULL, 0);
	if (reader != NULL) {
		ret = xmlTextReaderRead (reader);
		while (ret == 1) {
			processNode (reader);
			ret = xmlTextReaderRead (reader);
		}
		xmlFreeTextReader (reader);
		if (ret != 0) {
			fprintf (stderr, "%s : failed to parse\n", filename);
		}
	} else {
		fprintf (stderr, "Unable to open %s\n", filename);
	}
}
Beispiel #12
0
/* xmlreader.from_file(filename [,encoding] [,options]) */
static int xmlreader_from_file(lua_State *L) {
  const char *fn = luaL_checkstring(L, 1);
  const char *enc = luaL_optstring(L, 2, NULL);
  int opt = 0;
  if (lua_gettop(L) > 2) {
    lua_pop(L, lua_gettop(L) - 3);
    luaL_checktype(L, 3, LUA_TTABLE);
    opt = get_parser_option(L);
  }

  xmlreader xr = push_xmlreader(L, xmlReaderForFile(fn, enc, opt));

  if (xr == NULL)
    lua_pushnil(L);
  /*
  else
    xmlTextReaderSetStructuredErrorHandler(xr, xmlreader_error_handler, NULL);
  */
  return 1;
}
int xml_label_from_file(const char *filename, struct ltfs_label *label)
{
	int ret;
	xmlTextReaderPtr reader;

	CHECK_ARG_NULL(filename, -LTFS_NULL_ARG);
	CHECK_ARG_NULL(label, -LTFS_NULL_ARG);

	reader = xmlReaderForFile(filename, NULL, XML_PARSE_NOERROR | XML_PARSE_NOWARNING);
	if (! reader) {
		ltfsmsg(LTFS_ERR, "17007E", filename);
		return -1;
	}

	ret = _xml_parse_label(reader, label);
	if (ret < 0)
		ltfsmsg(LTFS_ERR, "17008E", filename);
	xmlFreeTextReader(reader);

	return ret;
}
Beispiel #14
0
struct xccdf_benchmark *xccdf_benchmark_import(const char *file)
{
	xmlTextReaderPtr reader = xmlReaderForFile(file, NULL, 0);
	if (!reader) {
		oscap_seterr(OSCAP_EFAMILY_GLIBC, "Unable to open file: '%s'", file);
		return NULL;
	}

	xmlTextReaderSetErrorHandler(reader, &libxml_error_handler, NULL);

	while (xmlTextReaderRead(reader) == 1 && xmlTextReaderNodeType(reader) != XML_READER_TYPE_ELEMENT) ;
	struct xccdf_benchmark *benchmark = xccdf_benchmark_new();
	const bool parse_result = xccdf_benchmark_parse(XITEM(benchmark), reader);
	xmlFreeTextReader(reader);

	if (!parse_result) { // parsing fatal error
		oscap_seterr(OSCAP_EFAMILY_XML, "Failed to parse '%s'.", file);
		xccdf_benchmark_free(benchmark);
		return NULL;
	}

	// This is sadly the only place where we can pass origin file information
	// to the CPE1 embedded dictionary (if any). It is necessary to figure out
	// proper paths to OVAL files referenced from CPE1 dictionaries.

	// FIXME: Refactor and move this somewhere else
	struct cpe_dict_model* embedded_dict = xccdf_benchmark_get_cpe_list(benchmark);
	if (embedded_dict != NULL) {
		cpe_dict_model_set_origin_file(embedded_dict, file);
	}

	// same situation with embedded CPE2 lang model
	// FIXME: Refactor and move this somewhere else
	struct cpe_lang_model* embedded_lang_model = xccdf_benchmark_get_cpe_lang_model(benchmark);
	if (embedded_lang_model != NULL) {
		cpe_lang_model_set_origin_file(embedded_lang_model, file);
	}

	return benchmark;
}
Beispiel #15
0
Language_XML *languages_load()
{
    Language_XML *xml;
    char filename[PATH_MAX];
    xmlTextReaderPtr reader;
    Eina_Bool result;

    xml = calloc(sizeof(Language_XML), 1);
    if (!xml)
    {
        DBG("One of values is NULL, returning with error.");
        return NULL;
    }

    snprintf(filename, sizeof(filename), "%s.xml", default_xkb_rules_file);
    reader = xmlReaderForFile( filename, NULL, XML_PARSE_RECOVER );

    result = _lng_read(xml, reader);
    if (!result) return NULL;

    return xml;
}
/**
 * Parse an extent list from a file and populate provided dentry with the extents read during
 * the scanning.
 *
 * @param filename File name from where to read the extent list from.
 * @param d Dentry where the extents are to be appended to.
 * @return 0 on success or a negative value on error.
 */
static int xml_extentlist_from_file(const char *filename, struct dentry *d)
{
	declare_extent_parser_vars("extentinfo");
	xmlTextReaderPtr reader;
	xmlDocPtr doc;
	int ret = 0;

	CHECK_ARG_NULL(filename, -LTFS_NULL_ARG);
	CHECK_ARG_NULL(d, -LTFS_NULL_ARG);

	reader = xmlReaderForFile(filename, NULL, XML_PARSE_NOERROR | XML_PARSE_NOWARNING);
	if (! reader) {
		ltfsmsg(LTFS_ERR, "17011E", filename);
		return -1;
	}

	/* Workaround for old libxml2 version on OS X 10.5: the method used to preserve
	 * unknown tags modifies the behavior of xmlFreeTextReader so that an additional
	 * xmlDocFree call is required to free all memory. */
	doc = xmlTextReaderCurrentDoc(reader);

	while (true) { /* BEAM: loop doesn't iterate - Because get_next_tag() macro uses "break", at most once loop is needed here. */
		get_next_tag();
		if (! strcmp(name, "extentinfo")) {
			ret = _xml_parse_extents(reader, IDX_VERSION_SPARSE, d);
			if (ret < 0) {
				/* XML parser: failed to read extent list from file (%d) */
				ltfsmsg(LTFS_ERR, "17084E", ret);
			}
		}
		break;
	}

	if (doc)
		xmlFreeDoc(doc);
	xmlFreeTextReader(reader);

	return ret;
}
Beispiel #17
0
struct xccdf_tailoring *xccdf_tailoring_import(const char *file, struct xccdf_benchmark *benchmark)
{
	xmlTextReaderPtr reader = xmlReaderForFile(file, NULL, 0);
	if (!reader) {
		oscap_seterr(OSCAP_EFAMILY_GLIBC, "Unable to open file: '%s'", file);
		return NULL;
	}

	xmlTextReaderSetErrorHandler(reader, &libxml_error_handler, NULL);

	while (xmlTextReaderRead(reader) == 1 && xmlTextReaderNodeType(reader) != XML_READER_TYPE_ELEMENT) ;
	struct xccdf_tailoring *tailoring = xccdf_tailoring_parse(reader, XITEM(benchmark));
	xmlFreeTextReader(reader);

	if (!tailoring) { // parsing fatal error
		oscap_seterr(OSCAP_EFAMILY_XML, "Failed to parse '%s'.", file);
		xccdf_tailoring_free(tailoring);
		return NULL;
	}

	return tailoring;
}
Beispiel #18
0
int xmlconfig_load( const char *filename )
{
	int rc = -1;
	int ret;
	xmlTextReaderPtr reader;
	const xmlChar *name;
        
	reader = xmlReaderForFile( filename, NULL, 0 );
	if ( reader != NULL ) {
		ret = xmlTextReaderRead( reader );
		while (ret == 1) {
			name = xmlTextReaderConstName( reader );
			if ( name &&
                            (XML_READER_TYPE_ELEMENT == xmlTextReaderNodeType( reader )) &&
                            ( 0 == xmlStrncmp( name, (const xmlChar *)"NodeConfig", 10 ) ) )
			{
				xmlconfig_load_node( reader );
			}
			else if ( name &&
                            (XML_READER_TYPE_ELEMENT == xmlTextReaderNodeType( reader )) &&
                            ( 0 == xmlStrncmp( name, (const xmlChar *)"TimerConfig", 10 ) ) )
			{
				xmlconfig_load_timer( reader );
			}
			ret = xmlTextReaderRead( reader );
		}
		xmlFreeTextReader( reader );
		if (ret != 0) {
			fprintf( stderr, "%s : failed to parse\n", filename );
			goto out;
		}
		rc = 0;
	} else {
		fprintf( stderr, "Unable to open %s\n", filename );
	}
out:
	return rc;
}
Beispiel #19
0
/**
 * streamFile:
 * @filename: the file name to parse
 *
 * Parse, validate and print information about an XML file.
 */
static void
streamFile(const char *filename) {
    xmlTextReaderPtr reader;
    int ret;


    /*
     * Pass some special parsing options to activate DTD attribute defaulting,
     * entities substitution and DTD validation
     */
    reader = xmlReaderForFile(filename, NULL,
                 XML_PARSE_DTDATTR |  /* default DTD attributes */
         XML_PARSE_NOENT |            /* substitute entities */
         XML_PARSE_DTDVALID); /* validate with the DTD */
    if (reader != NULL) {
        ret = xmlTextReaderRead(reader);
        while (ret == 1) {
            // processNode(reader);
            ret = xmlTextReaderRead(reader);
        }

        /*
         * Once the document has been fully parsed check the validation results
         */
        if (xmlTextReaderIsValid(reader) != 1) {
            fprintf(stderr, "Document %s does not validate\n", filename);
        } else {
            printf("Look nice.\n");
        }

        xmlFreeTextReader(reader);
        if (ret != 0) {
            fprintf(stderr, "%s : failed to parse\n", filename);
        }
    } else {
        fprintf(stderr, "Unable to open %s\n", filename);
    }
}
Beispiel #20
0
bool ddDatabaseDesign::readXmlModel(wxString file, ctlAuiNotebook *notebook)
{
	emptyModel();

	mappingIdToName.clear();
	//Initial Parse Model
	xmlTextReaderPtr reader = xmlReaderForFile(file.mb_str(wxConvUTF8), NULL, 0);
	ddXmlStorage::setModel(this);
	ddXmlStorage::setModel(this);
	ddXmlStorage::initialModelParse(reader);

	//Parse Model
	xmlReaderNewFile(reader, file.mb_str(wxConvUTF8), NULL, 0);
	ddXmlStorage::setModel(this);
	ddXmlStorage::setNotebook(notebook);

	if(!ddXmlStorage::Read(reader))
	{
		return false;
	}
	xmlFreeTextReader(reader);
	return true;
}
Beispiel #21
0
int
main(int argc, char **argv)
{
    xmlTextReaderPtr reader;
    if (argc != 2)
        return(1);

    LIBXML_TEST_VERSION

    reader = xmlReaderForFile(argv[1], NULL, 0);
    if (reader == NULL) {
        fprintf(stderr, "Unable to open %s\n", argv[1]);
        return (1);
    }

    if (fx_parse_xml(reader, &testSchema))
    	printf("Error parsing document\n");

    xmlCleanupParser();
    xmlMemoryDump();

    return(0);
}
Beispiel #22
0
// ref: http://xmlsoft.org/examples/index.html#reader1.c
void xml::xmlreader(const  char *filename) {
	LIBXML_TEST_VERSION
	xmlTextReaderPtr reader;
	if((reader = xmlReaderForFile(filename, NULL, 0)) != NULL) {
		while(xmlTextReaderRead(reader) == 1) {
			const xmlChar *name;
			const xmlChar *value;
			if((name = xmlTextReaderConstName(reader)) != NULL) {
				value = xmlTextReaderConstValue(reader);
				cout << xmlTextReaderDepth(reader)
					<< " " << xmlTextReaderNodeType(reader)
					<< " " << name
					<< " " << xmlTextReaderIsEmptyElement(reader)
					<< " " << xmlTextReaderHasValue(reader);
				if(value != NULL)
					cout << endl;
				cout.flush();
			}

		}
		xmlFreeTextReader(reader);
	}
	xmlCleanupParser();
}
Beispiel #23
0
// This function needs to be re-entrant, it can be called recursively from inside of resolveAll
// to load files that the first file depends on.
daeInt daeLIBXMLPlugin::read(daeURI& uri, daeString docBuffer)
{
    // Make sure topMeta has been set before proceeding
	
	if (topMeta == NULL) 
	{
		return DAE_ERR_BACKEND_IO;
	}

	// Generate a version of the URI with the fragment removed

	daeURI fileURI(uri.getURI(),true);

	// Create the right type of xmlTextReader on the stack so this function can be re-entrant

	xmlTextReaderPtr reader;

	if(docBuffer)
	{
		// Load from memory (experimental)
#if 0 //debug stuff
		printf("Reading %s from memory buffer\n", fileURI.getURI());
#endif
		reader = xmlReaderForDoc((xmlChar*)docBuffer, fileURI.getURI(), NULL,0);
	}
	else
	{
		// Load from URI
#if 0 //debug stuff
		printf("Opening %s\n", fileURI.getURI());
#endif
		reader = xmlReaderForFile(fileURI.getURI(), NULL,0);
	}

	if(!reader)
	{
		printf( "no libxml2 reader\n");
		return DAE_ERR_BACKEND_IO;
	}

	// Start parsing the file

	daeElementRef domObject = startParse(topMeta, reader);

	// Parsing done, free the xmlReader and error check to make sure we got a valid DOM back
	
	xmlFreeTextReader(reader);

	if (!domObject)
	{
#if defined(_DEBUG) && defined(WIN32)
		fprintf(stderr,"daeLIBXMLPlugin::read(%s) failed - XML Parse Failed\n",
				fileURI.getFile());
		fflush(stdout);
#endif		
		printf("not able to load\n");
		return DAE_ERR_BACKEND_IO;
	}

	// Insert the document into the database, the Database will keep a ref on the main dom, so it won't gets deleted
	// until we clear the database

	daeDocument *document = NULL;

	int res = database->insertDocument(fileURI.getURI(),domObject,&document);
	if (res!= DAE_OK)
		return res;

	// Make a vector to store a list of the integration items that need to be processed later
	// postProcessDom will fill this in for us (this should probably not be done in the IOPlugin)
	
	std::vector<INTEGRATION_ITEM> intItems;
	
	//insert the elements into the database, for this DB the elements are the Collada object which have
	//an ID. 
	//this function will fill the _integrationItems array as well
	postProcessDom(document, domObject, intItems);
	database->validate();
	daeElement::resolveAll();

	//create the integration objects
	int size = (int)intItems.size();
	int i;
	for (i=0;i<size;i++)
		intItems[i].intObject->createFromChecked(intItems[i].element);
	
	for (i=0;i<size;i++)
		intItems[i].intObject->fromCOLLADAChecked();

	for (i=0;i<size;i++)
		intItems[i].intObject->fromCOLLADAPostProcessChecked();

	//clear the temporary integration items array
	intItems.clear();

	return DAE_OK;
}
Beispiel #24
0
/* Parse the configuration file. */
int sechk_lib_parse_xml_file(const char *filename, sechk_lib_t * lib)
{
	xmlTextReaderPtr reader = NULL;
	xmlDtdPtr dtd = NULL;
	xmlDocPtr xml = NULL;
	xmlValidCtxtPtr ctxt = NULL;
	int tmp, ret = 0;
	char *dtd_path = NULL;

	/* this initializes the XML library and checks potential ABI mismatches
	 * between the version it was compiled for and the actual shared
	 * library used. */
	LIBXML_TEST_VERSION;
	reader = xmlReaderForFile(filename, NULL, 0);
	if (!reader) {
		ret = errno;
		if (ret != ENOENT)
			fprintf(stderr, "Error: Could not create xmlReader.\n");
		goto exit_err;
	}

	dtd_path = build_dtd_path();
	if (!dtd_path) {
		fprintf(stderr, "Error: getting DTD path\n");
		goto exit_err;
	}
	dtd = xmlParseDTD(NULL, (const xmlChar *)dtd_path);
	free(dtd_path);

	if (!dtd) {
		fprintf(stderr, "Error: parsing DTD\n");
		goto exit_err;
	}

	xml = xmlParseFile(filename);
	if (!xml) {
		fprintf(stderr, "Error: parsing sechecker profile\n");
		goto exit_err;
	}

	ctxt = xmlNewValidCtxt();
	if (!ctxt) {
		fprintf(stderr, "Error: out of memory\n");
		goto exit_err;
	}
	/* validate profile against the DTD */
	if (xmlValidateDtd(ctxt, xml, dtd) == 0) {
		fprintf(stderr, "Error: SEChecker profile contains invalid XML. Aborting.\n");
		goto exit_err;
	}
	xmlFreeValidCtxt(ctxt);
	xmlFreeDoc(xml);
	xmlFreeDtd(dtd);

	while (1) {
		ret = xmlTextReaderRead(reader);
		if (ret == -1) {
			ret = errno;
			fprintf(stderr, "Error: Error reading xml.\n");
			goto exit_err;
		}
		if (ret == 0)	       /* no more nodes to read */
			break;

		tmp = sechk_lib_process_xml_node(reader, lib);
		if (tmp == -1)
			goto exit_err;
		if (tmp == 1) {
			ret = xmlTextReaderNext(reader);
			if (ret == 0)
				break;
			if (ret == -1) {
				ret = errno;
				fprintf(stderr, "Error in xmlTextReaderNext()\n");
				goto exit_err;
			}
		}
	}

	/* cleanup function for the XML library */
	xmlCleanupParser();
	xmlFreeTextReader(reader);
	return 0;

      exit_err:
	xmlCleanupParser();
	if (reader)
		xmlFreeTextReader(reader);
	if (ret)
		errno = ret;
	return -1;
}
Beispiel #25
0
XmlTextReader::XmlTextReader(RCString uri) {
	Init(xmlReaderForFile(uri.c_str(), 0, XML_PARSE_NOBLANKS));
}
Beispiel #26
0
int main ( int argc, char *argv[] ) {
  xmlTextReaderPtr reader;
  xmlTextWriterPtr writer;
  int status;
  struct api_shapes_circle *circle;
  struct api_shapes_triangle *triangle;
  struct api_shapes_rectangle *rectangle;
  struct api_animals_cat *cat;
  struct api_draw_canvas *canvas;
  struct api_structures_house *house;
  struct api_vehicles_bus *bus;
  if (argc != 4) {
    printf("Usage: %s [cat|canvas|house|bus|circle|triangle|rectangle] [infile] [outfile]", argv[0]);
    return 1;
  }

  reader = xmlReaderForFile(argv[2], NULL, 0);
  writer = xmlNewTextWriterFilename(argv[3], 0);
  if (strcmp("circle", argv[1]) == 0) {
    circle = xml_read_api_shapes_circle(reader);
    status = xml_write_api_shapes_circle(writer, circle);
    if (status < 0) {
      //panic
      printf("Problem writing circle.");
      return 1;
    }
#if DEBUG_ENUNCIATE
    else {
      printf("Successfully wrote the circle with status: %i\n", status);
    }
#endif

    free_api_shapes_circle(circle); //free the circle.
#if DEBUG_ENUNCIATE
    printf("Successfully freed the circle from memory.\n");
#endif
    xmlFreeTextWriter(writer); //free the writer
#if DEBUG_ENUNCIATE
    printf("Successfully freed the writer.\n");
#endif
    xmlFreeTextReader(reader); //free the reader
#if DEBUG_ENUNCIATE
    printf("Successfully freed the reader.\n");
#endif
  }
  else if (strcmp("triangle", argv[1]) == 0) {
    triangle = xml_read_api_shapes_triangle(reader);
    status = xml_write_api_shapes_triangle(writer, triangle);
    if (status < 0) {
      //panic
      printf("Problem writing triangle.");
      return 1;
    }
#if DEBUG_ENUNCIATE
    else {
      printf("Successfully wrote the triangle with status: %i\n", status);
    }
#endif

    free_api_shapes_triangle(triangle); //free the triangle.
#if DEBUG_ENUNCIATE
    printf("Successfully freed the triangle from memory.\n");
#endif
    xmlFreeTextWriter(writer); //free the writer
#if DEBUG_ENUNCIATE
    printf("Successfully freed the writer.\n");
#endif
    xmlFreeTextReader(reader); //free the reader
#if DEBUG_ENUNCIATE
    printf("Successfully freed the reader.\n");
#endif
  }
  else if (strcmp("rectangle", argv[1]) == 0) {
    rectangle = xml_read_api_shapes_rectangle(reader);
    status = xml_write_api_shapes_rectangle(writer, rectangle);
    if (status < 0) {
      //panic
      printf("Problem writing rectangle.");
      return 1;
    }
#if DEBUG_ENUNCIATE
    else {
      printf("Successfully wrote the rectangle with status: %i\n", status);
    }
#endif

    free_api_shapes_rectangle(rectangle); //free the rectangle.
#if DEBUG_ENUNCIATE
    printf("Successfully freed the rectangle from memory.\n");
#endif
    xmlFreeTextWriter(writer); //free the writer
#if DEBUG_ENUNCIATE
    printf("Successfully freed the writer.\n");
#endif
    xmlFreeTextReader(reader); //free the reader
#if DEBUG_ENUNCIATE
    printf("Successfully freed the reader.\n");
#endif
  }
  else if (strcmp("cat", argv[1]) == 0) {
    cat = xml_read_api_animals_cat(reader);
    status = xml_write_api_animals_cat(writer, cat);
    if (status < 0) {
      //panic
      printf("Problem writing cat.");
      return 1;
    }
#if DEBUG_ENUNCIATE
    else {
      printf("Successfully wrote the cat with status: %i\n", status);
    }
#endif

    free_api_animals_cat(cat); //free the cat.
#if DEBUG_ENUNCIATE
    printf("Successfully freed the cat from memory.\n");
#endif
    xmlFreeTextWriter(writer); //free the writer
#if DEBUG_ENUNCIATE
    printf("Successfully freed the writer.\n");
#endif
    xmlFreeTextReader(reader); //free the reader
#if DEBUG_ENUNCIATE
    printf("Successfully freed the reader.\n");
#endif
  }
  else if (strcmp("canvas", argv[1]) == 0) {
    canvas = xml_read_api_draw_canvas(reader);
    status = xml_write_api_draw_canvas(writer, canvas);
    if (status < 0) {
      //panic
      printf("Problem writing canvas.");
      return 1;
    }
#if DEBUG_ENUNCIATE
    else {
      printf("Successfully wrote the canvas with status: %i\n", status);
    }
#endif

    free_api_draw_canvas(canvas); //free the canvas.
#if DEBUG_ENUNCIATE
    printf("Successfully freed the canvas from memory.\n");
#endif
    xmlFreeTextWriter(writer); //free the writer
#if DEBUG_ENUNCIATE
    printf("Successfully freed the writer.\n");
#endif
    xmlFreeTextReader(reader); //free the reader
#if DEBUG_ENUNCIATE
    printf("Successfully freed the reader.\n");
#endif
  }
  else if (strcmp("house", argv[1]) == 0) {
    house = xml_read_api_structures_house(reader);
    house->style = xml_convert_known_api_structures_houseStyle(xml_get_known_api_structures_houseStyle(house->style));
    house->type = xml_convert_known_api_structures_houseType(xml_get_known_api_structures_houseType(house->type));
    status = xml_write_api_structures_house(writer, house);
    if (status < 0) {
      //panic
      printf("Problem writing house.");
      return 1;
    }
#if DEBUG_ENUNCIATE
    else {
      printf("Successfully wrote the house with status: %i\n", status);
    }
#endif

    free_api_structures_house(house); //free the house.
#if DEBUG_ENUNCIATE
    printf("Successfully freed the house from memory.\n");
#endif
    xmlFreeTextWriter(writer); //free the writer
#if DEBUG_ENUNCIATE
    printf("Successfully freed the writer.\n");
#endif
    xmlFreeTextReader(reader); //free the reader
#if DEBUG_ENUNCIATE
    printf("Successfully freed the reader.\n");
#endif
  }
  else if (strcmp("bus", argv[1]) == 0) {
    bus = xml_read_api_vehicles_bus(reader);
    status = xml_write_api_vehicles_bus(writer, bus);
    if (status < 0) {
      //panic
      printf("Problem writing bus.");
      return 1;
    }
#if DEBUG_ENUNCIATE
    else {
      printf("Successfully wrote the bus with status: %i\n", status);
    }
#endif

    free_api_vehicles_bus(bus); //free the bus.
#if DEBUG_ENUNCIATE
    printf("Successfully freed the bus from memory.\n");
#endif
    xmlFreeTextWriter(writer); //free the writer
#if DEBUG_ENUNCIATE
    printf("Successfully freed the writer.\n");
#endif
    xmlFreeTextReader(reader); //free the reader
#if DEBUG_ENUNCIATE
    printf("Successfully freed the reader.\n");
#endif
  }
  else {
    printf("Unrecognized xml type: %s\nUsage: %s [cat|canvas|house|bus||circle|triangle|rectangle] [infile] [outfile]", argv[1], argv[0]);
    return 1;
  }

  return 0;
}
Beispiel #27
0
const char *getURL(const char *rssfile, const char *logfile) {
    xmlTextReaderPtr reader;
    FILE* log;
    const char *url;
    const char *name, *value;
    const char *msg;
    xmlChar* xmlURL;
    int ret = 0, LOGGING = TRUE;

    log = fopen(logfile, "a");
    if( log == NULL ) {
        // no logfile, disable logging
        LOGGING = FALSE;
    }

    if( LOGGING ) {
        msg = "[INFO]\tAttempting to extract URL from RSS file...";
        myLog(log, msg);
    }

    if( rssfile == NULL ) {
        if( LOGGING ) {
            msg = "[ERROR]\tGiven NULL value for RSS file.";
            myLog(log, msg); 
        }

        return NULL;
    }

    reader = xmlReaderForFile(rssfile, NULL, 0);

    if( reader == NULL ) {
        if( LOGGING ) {
            msg = "[ERROR]\tXML Reader could not open RSS file";
            myLog(log, msg); 
        }

        return NULL;
    }

    ret = xmlTextReaderRead(reader);
    while( ret == 1 ) {
        name = xmlTextReaderConstName(reader);

        if(xmlStrEqual(name, (const xmlChar *) "url") == 1) {
            ret = xmlTextReaderRead(reader);
            if( ret != 1 ) {
                if( LOGGING ) {
                    msg = "[ERROR]\tFailed to read URL.";
                    myLog(log, msg);
                }
                return NULL;
            }

            xmlURL = xmlTextReaderValue(reader);
            url = (const char *) xmlStrdup(xmlURL);

            if( LOGGING ) {
                msg = "[INFO]\t...Succeeded!";
                myLog(log, msg); 
            }

            xmlFree(xmlURL);
            xmlFreeTextReader(reader);
            fclose(log);

            return (const char *) url;
        }

        ret = xmlTextReaderRead(reader);
    }

    goto cleanup;
    return NULL;
cleanup:
    xmlFreeTextReader(reader);
    fclose(log);
}
Beispiel #28
0
int XMIResource::load(const char* uri)
{
    int ret;

    LibXML2State state;

    /*
     * Allocate the reader object, this API is used as it is simpler to use than SAX2 :
     *  * we have direct access to a node object
     *  * Strings are interned by libxml2
     *  * partial SAX2 callbacks are not supported by libxml2
     */
    xmlTextReaderPtr reader;
    /* resolve xinclude and intern strings */
    reader = xmlReaderForFile(uri, NULL, XML_PARSE_XINCLUDE | XML_PARSE_COMPACT);

    /*
     * Intern strings to speedup comparaison, this table can be generated using XPath on xcos.ecore .
     */
    constXcosNames[e_Annotation] = xmlTextReaderConstString(reader, BAD_CAST ("Annotation"));
    constXcosNames[e_BaseObject] = xmlTextReaderConstString(reader, BAD_CAST ("BaseObject"));
    constXcosNames[e_Block] = xmlTextReaderConstString(reader, BAD_CAST ("Block"));
    constXcosNames[e_CompiledRepresentation] = xmlTextReaderConstString(reader, BAD_CAST ("CompiledRepresentation"));
    constXcosNames[e_Diagram] = xmlTextReaderConstString(reader, BAD_CAST ("Diagram"));
    constXcosNames[e_Geometry] = xmlTextReaderConstString(reader, BAD_CAST ("Geometry"));
    constXcosNames[e_Layer] = xmlTextReaderConstString(reader, BAD_CAST ("Layer"));
    constXcosNames[e_Link] = xmlTextReaderConstString(reader, BAD_CAST ("Link"));
    constXcosNames[e_Point] = xmlTextReaderConstString(reader, BAD_CAST ("Point"));
    constXcosNames[e_Port] = xmlTextReaderConstString(reader, BAD_CAST ("Port"));
    constXcosNames[e_PortKind] = xmlTextReaderConstString(reader, BAD_CAST ("PortKind"));
    constXcosNames[e_SimulationConfig] = xmlTextReaderConstString(reader, BAD_CAST ("SimulationConfig"));
    constXcosNames[e_absoluteTolerance] = xmlTextReaderConstString(reader, BAD_CAST ("absoluteTolerance"));
    constXcosNames[e_base64] = xmlTextReaderConstString(reader, BAD_CAST ("base64"));
    constXcosNames[e_blocktype] = xmlTextReaderConstString(reader, BAD_CAST ("blocktype"));
    constXcosNames[e_child] = xmlTextReaderConstString(reader, BAD_CAST ("child"));
    constXcosNames[e_color] = xmlTextReaderConstString(reader, BAD_CAST ("color"));
    constXcosNames[e_connectedSignal] = xmlTextReaderConstString(reader, BAD_CAST ("connectedSignal"));
    constXcosNames[e_context] = xmlTextReaderConstString(reader, BAD_CAST ("context"));
    constXcosNames[e_controlPoint] = xmlTextReaderConstString(reader, BAD_CAST ("controlPoint"));
    constXcosNames[e_datatype] = xmlTextReaderConstString(reader, BAD_CAST ("datatype"));
    constXcosNames[e_debugLevel] = xmlTextReaderConstString(reader, BAD_CAST ("debugLevel"));
    constXcosNames[e_deltaH] = xmlTextReaderConstString(reader, BAD_CAST ("deltaH"));
    constXcosNames[e_deltaT] = xmlTextReaderConstString(reader, BAD_CAST ("deltaT"));
    constXcosNames[e_dependsOnT] = xmlTextReaderConstString(reader, BAD_CAST ("dependsOnT"));
    constXcosNames[e_dependsOnU] = xmlTextReaderConstString(reader, BAD_CAST ("dependsOnU"));
    constXcosNames[e_description] = xmlTextReaderConstString(reader, BAD_CAST ("description"));
    constXcosNames[e_destinationPort] = xmlTextReaderConstString(reader, BAD_CAST ("destinationPort"));
    constXcosNames[e_dstate] = xmlTextReaderConstString(reader, BAD_CAST ("dstate"));
    constXcosNames[e_ein] = xmlTextReaderConstString(reader, BAD_CAST ("ein"));
    constXcosNames[e_eout] = xmlTextReaderConstString(reader, BAD_CAST ("eout"));
    constXcosNames[e_equations] = xmlTextReaderConstString(reader, BAD_CAST ("equations"));
    constXcosNames[e_expression] = xmlTextReaderConstString(reader, BAD_CAST ("expression"));
    constXcosNames[e_exprs] = xmlTextReaderConstString(reader, BAD_CAST ("exprs"));
    constXcosNames[e_finalTime] = xmlTextReaderConstString(reader, BAD_CAST ("finalTime"));
    constXcosNames[e_firing] = xmlTextReaderConstString(reader, BAD_CAST ("firing"));
    constXcosNames[e_font] = xmlTextReaderConstString(reader, BAD_CAST ("font"));
    constXcosNames[e_fontSize] = xmlTextReaderConstString(reader, BAD_CAST ("fontSize"));
    constXcosNames[e_functionAPI] = xmlTextReaderConstString(reader, BAD_CAST ("functionAPI"));
    constXcosNames[e_functionName] = xmlTextReaderConstString(reader, BAD_CAST ("functionName"));
    constXcosNames[e_geometry] = xmlTextReaderConstString(reader, BAD_CAST ("geometry"));
    constXcosNames[e_height] = xmlTextReaderConstString(reader, BAD_CAST ("height"));
    constXcosNames[e_implicit] = xmlTextReaderConstString(reader, BAD_CAST ("implicit"));
    constXcosNames[e_in] = xmlTextReaderConstString(reader, BAD_CAST ("in"));
    constXcosNames[e_interfaceFunction] = xmlTextReaderConstString(reader, BAD_CAST ("interfaceFunction"));
    constXcosNames[e_ipar] = xmlTextReaderConstString(reader, BAD_CAST ("ipar"));
    constXcosNames[e_kind] = xmlTextReaderConstString(reader, BAD_CAST ("kind"));
    constXcosNames[e_label] = xmlTextReaderConstString(reader, BAD_CAST ("label"));
    constXcosNames[e_lineHeight] = xmlTextReaderConstString(reader, BAD_CAST ("lineHeight"));
    constXcosNames[e_lineWidth] = xmlTextReaderConstString(reader, BAD_CAST ("lineWidth"));
    constXcosNames[e_nmode] = xmlTextReaderConstString(reader, BAD_CAST ("nmode"));
    constXcosNames[e_nzcross] = xmlTextReaderConstString(reader, BAD_CAST ("nzcross"));
    constXcosNames[e_odstate] = xmlTextReaderConstString(reader, BAD_CAST ("odstate"));
    constXcosNames[e_opar] = xmlTextReaderConstString(reader, BAD_CAST ("opar"));
    constXcosNames[e_out] = xmlTextReaderConstString(reader, BAD_CAST ("out"));
    constXcosNames[e_parent] = xmlTextReaderConstString(reader, BAD_CAST ("parent"));
    constXcosNames[e_parentDiagram] = xmlTextReaderConstString(reader, BAD_CAST ("parentDiagram"));
    constXcosNames[e_path] = xmlTextReaderConstString(reader, BAD_CAST ("path"));
    constXcosNames[e_properties] = xmlTextReaderConstString(reader, BAD_CAST ("properties"));
    constXcosNames[e_realtimeScale] = xmlTextReaderConstString(reader, BAD_CAST ("realtimeScale"));
    constXcosNames[e_relativeTolerance] = xmlTextReaderConstString(reader, BAD_CAST ("relativeTolerance"));
    constXcosNames[e_rpar] = xmlTextReaderConstString(reader, BAD_CAST ("rpar"));
    constXcosNames[e_solver] = xmlTextReaderConstString(reader, BAD_CAST ("solver"));
    constXcosNames[e_sourceBlock] = xmlTextReaderConstString(reader, BAD_CAST ("sourceBlock"));
    constXcosNames[e_sourcePort] = xmlTextReaderConstString(reader, BAD_CAST ("sourcePort"));
    constXcosNames[e_state] = xmlTextReaderConstString(reader, BAD_CAST ("state"));
    constXcosNames[e_style] = xmlTextReaderConstString(reader, BAD_CAST ("style"));
    constXcosNames[e_timeTolerance] = xmlTextReaderConstString(reader, BAD_CAST ("timeTolerance"));
    constXcosNames[e_title] = xmlTextReaderConstString(reader, BAD_CAST ("title"));
    constXcosNames[e_type] = xmlTextReaderConstString(reader, BAD_CAST ("type"));
    constXcosNames[e_uid] = xmlTextReaderConstString(reader, BAD_CAST ("uid"));
    constXcosNames[e_version] = xmlTextReaderConstString(reader, BAD_CAST ("version"));
    constXcosNames[e_width] = xmlTextReaderConstString(reader, BAD_CAST ("width"));
    constXcosNames[e_x] = xmlTextReaderConstString(reader, BAD_CAST ("x"));
    constXcosNames[e_xcos] = xmlTextReaderConstString(reader, BAD_CAST ("xcos"));
    constXcosNames[e_y] = xmlTextReaderConstString(reader, BAD_CAST ("y"));

    xcosNamespaceUri = xmlTextReaderConstString(reader, BAD_CAST ("org.scilab.modules.xcos"));
    xsiNamespaceUri = xmlTextReaderConstString(reader, BAD_CAST ("http://www.w3.org/2001/XMLSchema-instance"));

    unresolved.clear();

    /*
     * Process the document
     */
    if (reader != NULL)
    {
        ret = xmlTextReaderRead(reader);
        while (ret == 1)
        {
            ret = processNode(reader);
            if (ret == 1)
            {
                ret = xmlTextReaderRead(reader);
            }
        }
        /*
         * Once the document has been fully parsed check the validation results
         */
        if (xmlTextReaderIsValid(reader) < 0)
        {
            sciprint("Document %s does not validate\n", uri);
        }
        xmlFreeTextReader(reader);
        if (ret < 0)
        {
            sciprint("%s : failed to parse\n", uri);
            return ret;
        }
    }
    else
    {
        sciprint("Unable to open %s\n", uri);
        return -1;
    }

    /*
     * After loading the XML file, resolve all references
     */
    for (const unresolvedReference& ref : unresolved)
    {
        auto it = references.find(ref.m_uid);
        if (it != references.end())
        {
            controller.setObjectProperty(ref.m_id, ref.m_kind, ref.m_prop, it->second);
        }
        else
        {
            sciprint("Unable to resolve %s\n", ref.m_uid.c_str());
            return -1;
        }
    }

    return ret;
}
Beispiel #29
0
int main(int argc, char** argv)
{
    struct { char* settingsFile; } settings;
    fuse_opt shellOptions[] =
    {
        { "settings=%s", 0, NULL },
        { NULL }
    };
    fuse_args arguments = FUSE_ARGS_INIT(argc, argv);
    if (fuse_opt_parse(&arguments, &settings, shellOptions, NULL) == -1)
    {
        return (EXIT_FAILURE);
    }

    LIBXML_TEST_VERSION
    convertfs_context.cache = 0;
    Dispatcher* dispatcher = new Dispatcher;
    xmlTextReaderPtr reader = xmlReaderForFile(settings.settingsFile, NULL, 0);
    while (xmlTextReaderRead(reader) == 1)
    {
        const xmlChar* name = xmlTextReaderConstName(reader);
        if (!strcmp((const char*)name, "rule"))
        {
            Classificator* classificator = 0;
            Filter* filter = 0;
            const xmlChar* classificatorType = xmlTextReaderGetAttribute(reader, (const xmlChar*)"classificator-type");
            const xmlChar* classificatorData = xmlTextReaderGetAttribute(reader, (const xmlChar*)"classificator-data");
            const xmlChar* filterType = xmlTextReaderGetAttribute(reader, (const xmlChar*)"filter-type");
            const xmlChar* filterData = xmlTextReaderGetAttribute(reader, (const xmlChar*)"filter-data");
            if (!strcmp((const char*)classificatorType, "any"))
            {
                classificator = new AnyClassificator;
            }
            else if (!strcmp((const char*)classificatorType, "ext"))
            {
                classificator = new ExtensionClassificator((const char*)classificatorData);
            }

            if (!strcmp((const char*)filterType, "ignore"))
            {
                filter = new IgnoreFilter;
            }
            else if (!strcmp((const char*)filterType, "windows-names"))
            {
                filter = new WindowsNamesFilter("_");
            }
            else if (!strcmp((const char*)filterType, "command"))
            {
                std::vector<std::string> v;
                std::string s((const char*)filterData);
                boost::algorithm::split(v, s, boost::is_any_of(","));
                filter = new ConvertFilter(v[1], v[0]);
            }

            if (filter && classificator)
            {
                dispatcher->addRule(classificator, filter);
            }
        }
        else if (!strcmp((const char*)name, "source"))
        {
            const xmlChar* directory = xmlTextReaderGetAttribute(reader, (const xmlChar*)"directory");
            convertfs_context.tree = new Tree((const char*)directory, dispatcher);
        }
        else if (!strcmp((const char*)name, "cache"))
        {
            const xmlChar* directory = xmlTextReaderGetAttribute(reader, (const xmlChar*)"directory");
            const xmlChar* enabled = xmlTextReaderGetAttribute(reader, (const xmlChar*)"enabled");
            if (!strcmp((const char*)enabled, "1"))
            {
                convertfs_context.cache = new Cache((const char *)directory);
            }
        }
    }

    fuse_operations operations;
    memset(&operations, 0, sizeof(fuse_operations));
    operations.getattr = convertfs_getattr;
    operations.readdir = convertfs_readdir;
    operations.open    = convertfs_open;
    operations.read    = convertfs_read;
    operations.release = convertfs_release;

    return fuse_main(arguments.argc, arguments.argv, &operations, NULL);
}
Beispiel #30
0
/**
 * filters, transforms, and indexes file using ngrams to the index
 * 
 * file name - name of file to process
 * wikiindex - the judy arrays to store the index of the wiki in
 */
void indexWiki(char* inFileName, Pvoid_t *wikiIndex, int* articleCount) {
	
	//-------------------- initialization --------------------//
	bool articleIndex[lastNgram] = {0}; // boolean array of what trigrams are in an article
	struct stemmer * currentStemmer = create_stemmer();
	
	// file for writing the titles to
	FILE* titleFile = NULL;
	if (writeFiles) {
		titleFile = fopen("title_file", "w");
		if (NULL == titleFile) {
			fprintf(stderr, "Error open title file: %m\n");
			exit(1);
		}
	}
	
	// initializes the libxml library
	LIBXML_TEST_VERSION
	xmlTextReaderPtr wikiReader; //the reader for the document
	wikiReader = xmlReaderForFile(inFileName, NULL, XML_PARSE_RECOVER+XML_PARSE_NOWARNING+XML_PARSE_NOERROR+XML_PARSE_HUGE);
	if (NULL == wikiReader) {
		//fprintf(stderr, "%s %s\n", "Failed to open ", wikiFileName);
		fprintf(stderr, "Error opening XML wiki: %m\n");
		exit(1);
	}

	// for progress bar
	int percent = 0;
	long fileSize = getFileSize(inFileName);
	
	// initialization for currentArticle and its componens 
	article currentArticle;	
	currentArticle.title = g_string_sized_new(256);
	currentArticle.body  = g_string_sized_new(786432); //768*1024

	//-------------------- index the wiki --------------------//
	optionalPrint ("%s", "Adding collection to index.\n");
	optionalPrint ("%d", (int)(fileSize / 1048576));
	optionalPrint (" MB in file\n");
	displayProgressBar (xmlTextReaderByteConsumed(wikiReader), fileSize, &percent);
	 
	//prime the loop
	currentArticle.title->len = 0;
	currentArticle.body->len  = 0;
	xmlTextReaderRead(wikiReader);// at a <page> tag, drop in
	xmlTextReaderRead(wikiReader);// at a <page> tag, drop in
	 
	// reads from xml file until file is finished, adds articles to index, and writes tittles to file
	// processes one article per iteration
	while (getArticle (wikiReader, &currentArticle)) {
		currentArticle.articleNumber = *articleCount;
		*articleCount = *articleCount + 1;
		// filter / transform text
		removeMarkup(currentArticle.body);
		stemText(currentArticle.body, currentStemmer); //ngramming.h
		// index the text
		indexText(currentArticle.body, articleIndex); //ngramming.h
		addToIndex(articleIndex, wikiIndex, currentArticle.articleNumber);
		//adds titles to title file
		if (writeFiles) {fprintf(titleFile, "%s\n", currentArticle.title->str);}
		//re-prime the loop
		currentArticle.title->len = 0;
		currentArticle.body->len  = 0;
		displayProgressBar (xmlTextReaderByteConsumed(wikiReader), fileSize, &percent);
	}
	optionalPrint ("\n%s", "Finished indexing. \n");
	optionalPrint ("%lu", (long)(xmlTextReaderByteConsumed(wikiReader)/1048576));
	optionalPrint ("MB consumed\n");
	
	
	optionalPrint ("%d %s %d %s", *articleCount, "articles found", (int) currentArticle.body->allocated_len, "length allocated for article body\n");
	// clean up of structures needed to process wiki
	if (writeFiles) {fclose (titleFile);}
	free_stemmer(currentStemmer);
	xmlFreeTextReader(wikiReader);
	xmlCleanupParser();
	//g_string_free(currentArticle.title, TRUE);
	//g_string_free(currentArticle.body, TRUE); //malloc fail if this is uncommented ?!
}