示例#1
0
int parseGame(const char *filename) {

   initParser();

   if (!parseGameFile(filename)) {
      g_outputError("failed to parse game file %s\n", filename);
      return 0;
   }

   /* make sure a room named "start" exists */
   if (NULL == g_hash_table_lookup(roomParsedTable, "start")) {
      g_outputError("room 'start' must be defined\n");
      return 0;
   }

   initGlobalEvents();
   initObjects();
   initCreatures();
   initRooms();

   /* make sure we didn't have any issues parsing Lua scripts */
   if (g_scriptError) {
      return 0;
   }

   destroyParser();
   return 1;
}
示例#2
0
//----------------------------------------------------------------------------//
void System::cleanupXMLParser()
{
    // bail out if no parser
    if (!d_xmlParser)
        return;

    // get parser object to do whatever cleanup it needs to
    d_xmlParser->cleanup();

    // exit if we did not create this parser object
    if (!d_ourXmlParser)
        return;

    // if parser module loaded, destroy the parser object & cleanup module
    if (d_parserModule)
    {
        // get pointer to parser deletion function
        void(*deleteFunc)(XMLParser*) = (void(*)(XMLParser*))d_parserModule->
            getSymbolAddress("destroyParser");
        // cleanup the xml parser object
        deleteFunc(d_xmlParser);

        // delete the dynamic module for the xml parser
        delete d_parserModule;
        d_parserModule = 0;
    }
#ifdef CEGUI_STATIC
    else
        //Static Linking Call
        destroyParser(d_xmlParser);
#endif

    d_xmlParser = 0;
}
示例#3
0
文件: compiler.c 项目: 8l/ark-c
void destroyCompiler(Compiler *self) {
	if (self) {
		if (self->lexer) destroyLexer(self->lexer);
		if (self->parser) destroyParser(self->parser);
		if (self->generatorLLVM) destroyLLVMCodeGenerator(self->generatorLLVM);
		if (self->semantic) destroySemanticAnalyzer(self->semantic);
		if (self->sourceFiles) destroyVector(self->sourceFiles);
		free(self);
		verboseModeMessage("Destroyed compiler");
	}
}
示例#4
0
// native INI_DestroyParser(&INIParser:handle);
static cell AMX_NATIVE_CALL INI_DestroyParser(AMX *amx, cell *params)
{
	return destroyParser(get_amxaddr(amx, params[1]));
}
示例#5
0
END_TEST

START_TEST (test_strict_option)
{
	EXIPSchema schema;
	Parser testParser;
	char buf[OUTPUT_BUFFER_SIZE];
	errorCode tmp_err_code = UNEXPECTED_ERROR;
	BinaryBuffer buffer;
	char exipath[MAX_PATH_LEN + strlen(EMPTY_TYPE_DEFAULT)];
	size_t pathlen;
	FILE *infile;
	struct appData parsingData;

	buffer.buf = buf;
	buffer.bufContent = 0;
	buffer.bufLen = OUTPUT_BUFFER_SIZE;
	buffer.ioStrm.readWriteToStream = NULL;
	buffer.ioStrm.stream = NULL;

	// Parsing steps:

	// I.A: First, read in the schema
	parseSchema(EMPTY_TYPE_SCHEMA, &schema);

	// I.B: Define an external stream for the input to the parser if any
	pathlen = strlen(dataDir);
	memcpy(exipath, dataDir, pathlen);
	exipath[pathlen] = '/';
	memcpy(&exipath[pathlen+1], EMPTY_TYPE_STRICT, strlen(EMPTY_TYPE_STRICT)+1);

	infile = fopen(exipath, "rb" );
	if(!infile)
		fail("Unable to open file %s", exipath);

	buffer.ioStrm.readWriteToStream = readFileInputStream;
	buffer.ioStrm.stream = infile;

	// II: Second, initialize the parser object
	tmp_err_code = initParser(&testParser, buffer, &schema, &parsingData);
	fail_unless (tmp_err_code == ERR_OK, "initParser returns an error code %d", tmp_err_code);

	// III: Initialize the parsing data and hook the callback handlers to the parser object
	parsingData.eventCount = 0;
	parsingData.expectAttributeData = 0;

	testParser.handler.fatalError    = sample_fatalError;
	testParser.handler.error         = sample_fatalError;
	testParser.handler.startElement  = sample_startElement;
	testParser.handler.attribute     = sample_attribute;
	testParser.handler.stringData    = sample_stringData;
	testParser.handler.intData       = sample_intData;

	// IV: Parse the header of the stream

	tmp_err_code = parseHeader(&testParser);
	fail_unless (tmp_err_code == ERR_OK, "parsing the header returns an error code %d", tmp_err_code);

	// V: Parse the body of the EXI stream

	while(tmp_err_code == ERR_OK)
	{
		tmp_err_code = parseNext(&testParser);
	}

	// VI: Free the memory allocated by the parser object

	destroyParser(&testParser);
	fail_unless (tmp_err_code == PARSING_COMPLETE, "Error during parsing of the EXI body %d", tmp_err_code);
}
示例#6
0
errorCode decodeHeader(EXIStream* strm, boolean outOfBandOpts)
{
	errorCode tmp_err_code = UNEXPECTED_ERROR;
	unsigned int bits_val = 0;
	boolean boolVal = FALSE;

	DEBUG_MSG(INFO, DEBUG_CONTENT_IO, (">Start EXI header decoding\n"));
	TRY(readBits(strm, 2, &bits_val));
	if(bits_val == 2)  // The header Distinguishing Bits i.e. no EXI Cookie
	{
		strm->header.has_cookie = 0;
		DEBUG_MSG(INFO, DEBUG_CONTENT_IO, (">No EXI cookie detected\n"));
	}
	else if(bits_val == 0)// ASCII code for $ = 00100100  (36)
	{
		TRY(readBits(strm, 6, &bits_val));
		if(bits_val != 36)
			return INVALID_EXI_HEADER;
		TRY(readBits(strm, 8, &bits_val));
		if(bits_val != 69)   // ASCII code for E = 01000101  (69)
			return INVALID_EXI_HEADER;
		TRY(readBits(strm, 8, &bits_val));
		if(bits_val != 88)   // ASCII code for X = 01011000  (88)
			return INVALID_EXI_HEADER;
		TRY(readBits(strm, 8, &bits_val));
		if(bits_val != 73)   // ASCII code for I = 01001001  (73)
			return INVALID_EXI_HEADER;

		strm->header.has_cookie = 1;
		DEBUG_MSG(INFO, DEBUG_CONTENT_IO, (">EXI cookie detected\n"));
		TRY(readBits(strm, 2, &bits_val));
		if(bits_val != 2)  // The header Distinguishing Bits are required
			return INVALID_EXI_HEADER;
	}
	else
	{
		return INVALID_EXI_HEADER;
	}

	// Read the Presence Bit for EXI Options
	TRY(readNextBit(strm, &boolVal));

	if(boolVal == TRUE) // There are EXI options
	{
		strm->header.has_options = TRUE;
		// validation checks. If the options are included then
		// they cannot be set by an out-of-band mechanism.
		// If out-of-band options are set -
		// rise a warning and overwrite them.
		// Only the options from the header will be used
		if(outOfBandOpts == TRUE)
		{
			DEBUG_MSG(WARNING, DEBUG_CONTENT_IO, (">Ignored out-of-band set EXI options\n"));
			makeDefaultOpts(&strm->header.opts);
		}
	}
	else // Out-of-band set EXI options
	{
		DEBUG_MSG(INFO, DEBUG_CONTENT_IO, (">No EXI options field in the header\n"));
		strm->header.has_options = FALSE;
		if(outOfBandOpts == FALSE)
		{
			DEBUG_MSG(ERROR, DEBUG_CONTENT_IO, (">No EXI options in the header and no out-of-band options specified. \n"));
			return HEADER_OPTIONS_MISMATCH;
		}
	}

	// Read the Version type
	TRY(readNextBit(strm, &boolVal));

	strm->header.is_preview_version = boolVal;
	strm->header.version_number = 1;

	do
	{
		TRY(readBits(strm, 4, &bits_val));
		strm->header.version_number += bits_val;
		if(bits_val < 15)
			break;
	} while(1);

	DEBUG_MSG(INFO, DEBUG_CONTENT_IO, (">EXI version: %d\n", strm->header.version_number));

	if(strm->header.has_options == 1)
	{
		Parser optionsParser;
		struct ops_AppData appD;

		TRY(initParser(&optionsParser, strm->buffer, &appD));

		optionsParser.strm.context.bitPointer = strm->context.bitPointer;
		optionsParser.strm.context.bufferIndx = strm->context.bufferIndx;
		optionsParser.strm.gStack = NULL;

		makeDefaultOpts(&optionsParser.strm.header.opts);
		SET_STRICT(optionsParser.strm.header.opts.enumOpt);

		optionsParser.handler.fatalError = ops_fatalError;
		optionsParser.handler.error = ops_fatalError;
		optionsParser.handler.startDocument = ops_startDocument;
		optionsParser.handler.endDocument = ops_endDocument;
		optionsParser.handler.startElement = ops_startElement;
		optionsParser.handler.attribute = ops_attribute;
		optionsParser.handler.stringData = ops_stringData;
		optionsParser.handler.endElement = ops_endElement;
		optionsParser.handler.intData = ops_intData;
		optionsParser.handler.booleanData = ops_boolData;

		appD.o_strm = &optionsParser.strm;
		appD.parsed_ops = &strm->header.opts;
		appD.prevElementLnID = 0;
		appD.prevElementUriID = 0;
		appD.permanentAllocList = &strm->memList;

		TRY_CATCH(setSchema(&optionsParser, (EXIPSchema*) &ops_schema), destroyParser(&optionsParser));
		TRY_CATCH(createValueTable(&optionsParser.strm.valueTable), destroyParser(&optionsParser));

		while(tmp_err_code == ERR_OK)
		{
			tmp_err_code = parseNext(&optionsParser);
		}

		destroyParser(&optionsParser);

		if(tmp_err_code != PARSING_COMPLETE)
			return tmp_err_code;

		strm->buffer.bufContent = optionsParser.strm.buffer.bufContent;
		strm->context.bitPointer = optionsParser.strm.context.bitPointer;
		strm->context.bufferIndx = optionsParser.strm.context.bufferIndx;

		if(WITH_COMPRESSION(strm->header.opts.enumOpt) ||
			GET_ALIGNMENT(strm->header.opts.enumOpt) != BIT_PACKED)
		{
			// Padding bits
			if(strm->context.bitPointer != 0)
			{
				strm->context.bitPointer = 0;
				strm->context.bufferIndx += 1;
			}
		}
	}

	return checkOptionValues(&strm->header.opts);
}
示例#7
0
errorCode decode(EXIPSchema* schemaPtr, unsigned char outFlag, FILE *infile, size_t (*inputStream)(void* buf, size_t size, void* stream))
{
	Parser testParser;
	char buf[INPUT_BUFFER_SIZE];
	BinaryBuffer buffer;
	errorCode tmp_err_code = UNEXPECTED_ERROR;
	struct appData parsingData;

	buffer.buf = buf;
	buffer.bufLen = INPUT_BUFFER_SIZE;
	buffer.bufContent = 0;
	// Parsing steps:

	// I: First, define an external stream for the input to the parser if any, otherwise set to NULL
	buffer.ioStrm.readWriteToStream = inputStream;
	buffer.ioStrm.stream = infile;

	// II: Second, initialize the parser object
	TRY(initParser(&testParser, buffer, &parsingData));

	// III: Initialize the parsing data and hook the callback handlers to the parser object.
	//      If out-of-band options are defined use testParser.strm.header.opts to set them
	parsingData.expectAttributeData = 0;
	parsingData.stack = NULL;
	parsingData.unclosedElement = 0;
	parsingData.prefixesCount = 0;
	parsingData.outputFormat = outFlag;

	testParser.handler.fatalError = sample_fatalError;
	testParser.handler.error = sample_fatalError;
	testParser.handler.startDocument = sample_startDocument;
	testParser.handler.endDocument = sample_endDocument;
	testParser.handler.startElement = sample_startElement;
	testParser.handler.attribute = sample_attribute;
	testParser.handler.stringData = sample_stringData;
	testParser.handler.endElement = sample_endElement;
	testParser.handler.decimalData = sample_decimalData;
	testParser.handler.intData = sample_intData;
	testParser.handler.floatData = sample_floatData;
	testParser.handler.booleanData = sample_booleanData;
	testParser.handler.dateTimeData = sample_dateTimeData;
	testParser.handler.binaryData = sample_binaryData;

	// IV: Parse the header of the stream

	TRY(parseHeader(&testParser, FALSE));

	// IV.1: Set the schema to be used for parsing.
	// The schemaID mode and schemaID field can be read at
	// parser.strm.header.opts.schemaIDMode and
	// parser.strm.header.opts.schemaID respectively
	// If schemaless mode, use setSchema(&parser, NULL);

	TRY(setSchema(&testParser, schemaPtr));

	// V: Parse the body of the EXI stream

	while(tmp_err_code == ERR_OK)
	{
		tmp_err_code = parseNext(&testParser);
	}

	// VI: Free the memory allocated by the parser

	destroyParser(&testParser);

	if(tmp_err_code == PARSING_COMPLETE)
		return ERR_OK;
	else
		return tmp_err_code;
}
示例#8
0
文件: apiexiread.c 项目: actility/ong
static void *XoReadExiCommon(struct ioStream *ioStr, char *roottype,int flags,int *err) {
	Parser testParser;
	struct appData parsingData;
	char buf[INPUT_BUFFER_SIZE];
	BinaryBuffer buffer;
	errorCode tmp_err_code = UNEXPECTED_ERROR;

	memset	(&parsingData,0,sizeof(parsingData));
	parsingData.ctxt.roottype	= roottype;
	parsingData.ctxt.flags	= flags;
	parsingData.ctxt.ns.flags	= flags;
	parsingData.parser	= &testParser;
	_XoAllocCtxt(&parsingData.ctxt);

	buffer.buf = buf;
	buffer.bufLen = INPUT_BUFFER_SIZE;
	buffer.bufContent = 0;
	// Parsing steps:

	// I: First, define an external stream for the input to the parser if any
	buffer.ioStrm	= *ioStr;

	// II: Second, initialize the parser object
#if EXIP_VERSION==276
	tmp_err_code = initParser(&testParser, buffer, g_schemaPtr, &parsingData);
#endif
#if EXIP_VERSION>=289
	tmp_err_code = initParser(&testParser, buffer, &parsingData);
#endif
	if(tmp_err_code != ERR_OK) {
		_XoFreeCtxt(&parsingData.ctxt);
		return NULL;
	}

	// III: Initialize the parsing data and hook the callback handlers to the parser object

	parsingData.expectAttributeData = 0;
	parsingData.stack = NULL;
	parsingData.unclosedElement = 0;
	parsingData.prefixesCount = 0;

	testParser.handler.fatalError = sample_fatalError;
	testParser.handler.error = sample_fatalError;
	testParser.handler.startDocument = sample_startDocument;
	testParser.handler.endDocument = sample_endDocument;
	testParser.handler.startElement = sample_startElement;
	testParser.handler.attribute = sample_attribute;
	testParser.handler.stringData = sample_stringData;
	testParser.handler.endElement = sample_endElement;
	testParser.handler.decimalData = sample_decimalData;
	testParser.handler.intData = sample_intData;
	testParser.handler.floatData = sample_floatData;
	testParser.handler.booleanData = sample_booleanData;
	testParser.handler.dateTimeData = sample_dateTimeData;
	testParser.handler.binaryData = sample_binaryData;
	testParser.handler.qnameData = sample_qnameData;
#if EXIP_VERSION==276
	testParser.handler.retrieveSchema = sample_retrieveSchema;
#endif

	// IV: Parse the header of the stream

	tmp_err_code = parseHeader(&testParser, FALSE);
#if EXIP_VERSION>=289
	// IV.1: Set the schema to be used for parsing.
	// The schemaID mode and schemaID field can be read at
	// parser.strm.header.opts.schemaIDMode and
	// parser.strm.header.opts.schemaID respectively
	// If schemaless mode, use setSchema(&parser, NULL);

	EXIPSchema *schemaPtr = sample_retrieveSchema(&parsingData);
	setSchema(&testParser, schemaPtr);
#endif

	//_lookupSchema();

	// V: Parse the body of the EXI stream

	while(tmp_err_code == ERR_OK)
	{
		tmp_err_code = parseNext(&testParser);
		PRINT ("parseNext ret=%d\n", tmp_err_code);
	}

	// PCA
	parsingData.xo_obj	= parsingData.ctxt.obj[0];

	// VI: Free the memory allocated by the parser and schema object

	destroyParser(&testParser);

	_XoFreeCtxt(&parsingData.ctxt);
	PRINT ("End parsing xo_obj=%p\n", parsingData.xo_obj);
	return	parsingData.xo_obj;
}
示例#9
0
END_TEST

START_TEST (test_noLearning02)
{
	EXIStream testStrm;
	Parser testParser;
	String uri;
	String ln;
	QName qname= {&uri, &ln};
	String chVal;
	char buf[OUTPUT_BUFFER_SIZE];
	errorCode tmp_err_code = EXIP_UNEXPECTED_ERROR;
	BinaryBuffer buffer;
	EXITypeClass valueType;

	buffer.buf = buf;
	buffer.bufContent = 0;
	buffer.bufLen = OUTPUT_BUFFER_SIZE;
	buffer.ioStrm.readWriteToStream = NULL;
	buffer.ioStrm.stream = NULL;

	// Serialization steps:

	// I: First initialize the header of the stream
	serialize.initHeader(&testStrm);

	// II: Set any options in the header, if different from the defaults
	testStrm.header.has_options = TRUE;
	testStrm.header.opts.schemaIDMode = SCHEMA_ID_EMPTY;

	// III: Define an external stream for the output if any

	// IV: Initialize the stream
	tmp_err_code = serialize.initStream(&testStrm, buffer, NULL);
	fail_unless (tmp_err_code == EXIP_OK, "initStream returns an error code %d", tmp_err_code);

	// V: Start building the stream step by step: header, document, element etc...
	tmp_err_code = serialize.exiHeader(&testStrm);
	fail_unless (tmp_err_code == EXIP_OK, "serialize.exiHeader returns an error code %d", tmp_err_code);

	tmp_err_code = serialize.startDocument(&testStrm);
	fail_unless (tmp_err_code == EXIP_OK, "serialize.startDocument returns an error code %d", tmp_err_code);

	getEmptyString(&uri);
	tmp_err_code += asciiToString("root", &ln, &testStrm.memList, FALSE);
	tmp_err_code += serialize.startElement(&testStrm, qname, &valueType);
	fail_unless (tmp_err_code == EXIP_OK, "serialize.startElement returns an error code %d", tmp_err_code);

	tmp_err_code += asciiToString("a", &ln, &testStrm.memList, FALSE);
	tmp_err_code += serialize.startElement(&testStrm, qname, &valueType);
	fail_unless (tmp_err_code == EXIP_OK, "serialize.startElement returns an error code %d", tmp_err_code);

	tmp_err_code += asciiToString("bla", &chVal, &testStrm.memList, FALSE);
	tmp_err_code += serialize.stringData(&testStrm, chVal);
	fail_unless (tmp_err_code == EXIP_OK, "serialize.stringData returns an error code %d", tmp_err_code);

	tmp_err_code += serialize.endElement(&testStrm);

	tmp_err_code += asciiToString("b", &ln, &testStrm.memList, FALSE);
	tmp_err_code += serialize.startElement(&testStrm, qname, &valueType);
	fail_unless (tmp_err_code == EXIP_OK, "serialize.startElement returns an error code %d", tmp_err_code);

	tmp_err_code += asciiToString("23", &chVal, &testStrm.memList, FALSE);
	tmp_err_code += serialize.stringData(&testStrm, chVal);
	fail_unless (tmp_err_code == EXIP_OK, "serialize.stringData returns an error code %d", tmp_err_code);

	tmp_err_code += serialize.endElement(&testStrm);

	tmp_err_code += asciiToString("a", &ln, &testStrm.memList, FALSE);
	tmp_err_code += serialize.startElement(&testStrm, qname, &valueType);
	fail_unless (tmp_err_code == EXIP_OK, "serialize.startElement returns an error code %d", tmp_err_code);

	tmp_err_code += asciiToString("bla", &chVal, &testStrm.memList, FALSE);
	tmp_err_code += serialize.stringData(&testStrm, chVal);
	fail_unless (tmp_err_code == EXIP_OK, "serialize.stringData returns an error code %d", tmp_err_code);

	tmp_err_code += serialize.endElement(&testStrm);

	tmp_err_code += asciiToString("c", &ln, &testStrm.memList, FALSE);
	tmp_err_code += serialize.startElement(&testStrm, qname, &valueType);
	fail_unless (tmp_err_code == EXIP_OK, "serialize.startElement returns an error code %d", tmp_err_code);

	tmp_err_code += asciiToString("b", &ln, &testStrm.memList, FALSE);
	tmp_err_code += serialize.startElement(&testStrm, qname, &valueType);
	fail_unless (tmp_err_code == EXIP_OK, "serialize.startElement returns an error code %d", tmp_err_code);

	tmp_err_code += asciiToString("http://www.w3.org/2001/XMLSchema-instance", &uri, &testStrm.memList, FALSE);
	tmp_err_code += asciiToString("type", &ln, &testStrm.memList, FALSE);
	tmp_err_code += serialize.attribute(&testStrm, qname, TRUE, &valueType);
	fail_unless (tmp_err_code == EXIP_OK, "serialize.attribute returns an error code %d", tmp_err_code);

	tmp_err_code += asciiToString("http://www.w3.org/2001/XMLSchema", &uri, &testStrm.memList, FALSE);
	tmp_err_code += asciiToString("integer", &ln, &testStrm.memList, FALSE);
	tmp_err_code += serialize.qnameData(&testStrm, qname);
	fail_unless (tmp_err_code == EXIP_OK, "serialize.qnameData returns an error code %d", tmp_err_code);

	tmp_err_code += serialize.intData(&testStrm, 66);
	fail_unless (tmp_err_code == EXIP_OK, "serialize.stringData returns an error code %d", tmp_err_code);

	tmp_err_code += serialize.endElement(&testStrm);

	tmp_err_code += serialize.endElement(&testStrm);

	tmp_err_code += serialize.endElement(&testStrm);
	tmp_err_code += serialize.endDocument(&testStrm);

	if(tmp_err_code != EXIP_OK)
		fail_unless (tmp_err_code == EXIP_OK, "serialization ended with error code %d", tmp_err_code);

	// V: Free the memory allocated by the EXI stream object
	tmp_err_code = serialize.closeEXIStream(&testStrm);
	fail_unless (tmp_err_code == EXIP_OK, "serialize.closeEXIStream ended with error code %d", tmp_err_code);


	buffer.bufContent = OUTPUT_BUFFER_SIZE;
	// Parsing steps:

	// I: First, define an external stream for the input to the parser if any

	// II: Second, initialize the parser object
	tmp_err_code = initParser(&testParser, buffer, NULL);
	fail_unless (tmp_err_code == EXIP_OK, "initParser returns an error code %d", tmp_err_code);

	// III: Initialize the parsing data and hook the callback handlers to the parser object

	// IV: Parse the header of the stream

	tmp_err_code = parseHeader(&testParser, TRUE);
	fail_unless (tmp_err_code == EXIP_OK, "parsing the header returns an error code %d", tmp_err_code);

	tmp_err_code = setSchema(&testParser, NULL);
	fail_unless (tmp_err_code == EXIP_OK, "setSchema() returns an error code %d", tmp_err_code);

	// V: Parse the body of the EXI stream

	while(tmp_err_code == EXIP_OK)
	{
		tmp_err_code = parseNext(&testParser);
	}

	// VI: Free the memory allocated by the parser object

	destroyParser(&testParser);
	fail_unless (tmp_err_code == EXIP_PARSING_COMPLETE, "Error during parsing of the EXI body %d", tmp_err_code);
}
示例#10
0
END_TEST

/* Verifies a single global element also used as a reference. */
START_TEST (test_acceptance_for_A_01_exip1)
{
	EXIPSchema schema;
	FILE *infile;
	Parser testParser;
	char buf[INPUT_BUFFER_SIZE];
	const char *schemafname = "testStates/acceptance-xsd.exi";
	const char *exifname = "testStates/acceptance_a_01a.exi";
	char exipath[MAX_PATH_LEN + strlen(exifname)];
	struct appData parsingData;
	errorCode tmp_err_code = EXIP_UNEXPECTED_ERROR;
	BinaryBuffer buffer;

	buffer.buf = buf;
	buffer.bufContent = 0;
	buffer.bufLen = INPUT_BUFFER_SIZE;

	// Parsing steps:

	// I.A: First, read in the schema
	parseSchema(schemafname, &schema);

	// I.B: Define an external stream for the input to the parser if any
	size_t pathlen = strlen(dataDir);
	memcpy(exipath, dataDir, pathlen);
	exipath[pathlen] = '/';
	memcpy(&exipath[pathlen+1], exifname, strlen(exifname)+1);
	
	infile = fopen(exipath, "rb" );
	if(!infile)
		fail("Unable to open file %s", exipath);
	
	buffer.ioStrm.readWriteToStream = readFileInputStream;
	buffer.ioStrm.stream = infile;

	// II: Second, initialize the parser object
	tmp_err_code = initParser(&testParser, buffer, &parsingData);
	fail_unless (tmp_err_code == EXIP_OK, "initParser returns an error code %d", tmp_err_code);

	// III: Initialize the parsing data and hook the callback handlers to the parser object
	parsingData.eventCount = 0;
	parsingData.expectAttributeData = 0;
	if (EXIP_OK != initAllocList(&parsingData.allocList))
		fail("Memory allocation error!");

	testParser.handler.fatalError    = sample_fatalError;
	testParser.handler.error         = sample_fatalError;
	testParser.handler.startDocument = sample_startDocument;
	testParser.handler.endDocument   = sample_endDocument;
	testParser.handler.startElement  = sample_startElement;
	testParser.handler.attribute     = sample_attribute;
	testParser.handler.stringData    = sample_stringData;
	testParser.handler.endElement    = sample_endElement;
	testParser.handler.decimalData   = sample_decimalData;
	testParser.handler.intData       = sample_intData;
	testParser.handler.floatData     = sample_floatData;
	
	// IV: Parse the header of the stream
	tmp_err_code = parseHeader(&testParser, FALSE);
	fail_unless (tmp_err_code == EXIP_OK, "parsing the header returns an error code %d", tmp_err_code);

	tmp_err_code = setSchema(&testParser, &schema);
	fail_unless (tmp_err_code == EXIP_OK, "setSchema() returns an error code %d", tmp_err_code);

	// V: Parse the body of the EXI stream
	while(tmp_err_code == EXIP_OK)
	{
		switch (parsingData.eventCount)
		{
			case 0:
				fail_unless(stringEqualToAscii(parsingData.eventCode, "SD"));
				break;
			case 1:
				fail_unless(stringEqualToAscii(parsingData.eventCode, "SE"));
				fail_unless(stringEqualToAscii(parsingData.uri, "urn:foo"));
				fail_unless(stringEqualToAscii(parsingData.localName, "AB"));
				break;
			case 2:
				fail_unless(stringEqualToAscii(parsingData.eventCode, "CH"));
				break;
			case 3:
				fail_unless(stringEqualToAscii(parsingData.eventCode, "EE"));
				break;
			case 4:
				fail_unless(stringEqualToAscii(parsingData.eventCode, "ED"));
				break;
			default:
				// Unexpected event count caught below.
				break;
		}

		tmp_err_code = parseNext(&testParser);
		parsingData.eventCount++;
	}
	
	fail_unless(stringEqualToAscii(parsingData.eventCode, "ED"));

	fail_unless(parsingData.eventCount == 4,
	            "Unexpected event count: %u", parsingData.eventCount);

	// VI: Free the memory allocated by the parser object
	freeAllocList(&parsingData.allocList);
	destroyParser(&testParser);
	fclose(infile);
	fail_unless (tmp_err_code == EXIP_PARSING_COMPLETE, "Error during parsing of the EXI body %d", tmp_err_code);
}
示例#11
0
static error_code parseDevDescMsg(char* buf, unsigned int buf_size, DevDescribtion* devDesc)
{
	Parser lkabParser;
	BinaryBuffer buffer;
	errorCode tmp_err_code = EXIP_UNEXPECTED_ERROR;
	struct appDataLKAB parsingData;
	EXIPSchema lkab_schema;
	const char *schemafname = "SchemaStrict/lkab-devices-xsd.exi";

	buffer.buf = buf;
	buffer.bufLen = buf_size;
	buffer.bufContent = buf_size;

	// Parsing steps:

	// I.A: First, read in the schema
	parseSchema(schemafname, &lkab_schema);

	// I: First, define an external stream for the input to the parser if any
	buffer.ioStrm.stream = NULL;

	// II: Second, initialize the parser object
	tmp_err_code = initParser(&lkabParser, buffer, &parsingData);
	if(tmp_err_code != EXIP_OK)
		return tmp_err_code;

	// III: Initialize the parsing data and hook the callback handlers to the parser object

	parsingData.currElementNumber = 0;
	parsingData.devDesc.id[0] = '\0';
	parsingData.devDesc.location[0] = '\0';
	parsingData.devDesc.name[0] = '\0';
	parsingData.devDesc.type[0] = '\0';
	parsingData.devDesc.processValue.description[0] = '\0';
	parsingData.devDesc.processValue.name[0] = '\0';
	parsingData.devDesc.processValue.isReadOnly = 0;
	parsingData.devDesc.processValue.type = Bool;

	lkabParser.handler.fatalError = lkab_fatalError;
	lkabParser.handler.error = lkab_fatalError;
	lkabParser.handler.startElement = lkab_startElement_desc;
	lkabParser.handler.stringData = lkab_stringData_desc;
	lkabParser.handler.endElement = lkab_endElement;
	lkabParser.handler.booleanData = lkab_booleanData_desc;

	// IV: Parse the header of the stream

	tmp_err_code = parseHeader(&lkabParser, FALSE);

	tmp_err_code = setSchema(&lkabParser, &lkab_schema);
	// V: Parse the body of the EXI stream

	while(tmp_err_code == EXIP_OK)
	{
		tmp_err_code = parseNext(&lkabParser);
	}

	// VI: Free the memory allocated by the parser object

	destroyParser(&lkabParser);

	strcpy(devDesc->id, parsingData.devDesc.id);
	strcpy(devDesc->location, parsingData.devDesc.location);
	strcpy(devDesc->name, parsingData.devDesc.name);
	strcpy(devDesc->type, parsingData.devDesc.type);
	strcpy(devDesc->processValue.description, parsingData.devDesc.processValue.description);
	strcpy(devDesc->processValue.name, parsingData.devDesc.processValue.name);
	devDesc->processValue.isReadOnly = parsingData.devDesc.processValue.isReadOnly;
	devDesc->processValue.type = parsingData.devDesc.processValue.type;

	if(tmp_err_code == EXIP_PARSING_COMPLETE)
		return EXIP_OK;
	else
		return tmp_err_code;
}
示例#12
0
static error_code parseIOMsg(char* buf, unsigned int buf_size, BoolValue *val)
{
	Parser lkabParser;
	BinaryBuffer buffer;
	errorCode tmp_err_code = EXIP_UNEXPECTED_ERROR;
	struct appDataLKAB parsingData;
	EXIPSchema lkab_schema;
	const char *schemafname = "SchemaStrict/lkab-devices-xsd.exi";

	buffer.buf = buf;
	buffer.bufLen = buf_size;
	buffer.bufContent = buf_size;
	// Parsing steps:

	// I.A: First, read in the schema
	parseSchema(schemafname, &lkab_schema);

	// I: First, define an external stream for the input to the parser if any
	buffer.ioStrm.stream = NULL;

	// II: Second, initialize the parser object
	tmp_err_code = initParser(&lkabParser, buffer, &parsingData);
	if(tmp_err_code != EXIP_OK)
		return tmp_err_code;

	// III: Initialize the parsing data and hook the callback handlers to the parser object

	parsingData.currElementNumber = 0;
	parsingData.val.quality = Good;
	parsingData.val.val = 0;
	parsingData.val.ts.year = 0;
	parsingData.val.ts.month = 0;
	parsingData.val.ts.mday = 0;
	parsingData.val.ts.hour = 0;
	parsingData.val.ts.min = 0;
	parsingData.val.ts.sec = 0;
	parsingData.val.ts.msec = 0;

	lkabParser.handler.fatalError = lkab_fatalError;
	lkabParser.handler.error = lkab_fatalError;
	lkabParser.handler.startElement = lkab_startElement_io;
	lkabParser.handler.stringData = lkab_stringData_io;
	lkabParser.handler.endElement = lkab_endElement;
	lkabParser.handler.booleanData = lkab_booleanData_io;
	lkabParser.handler.dateTimeData = lkab_dateTimeData;

	// IV: Parse the header of the stream

	tmp_err_code = parseHeader(&lkabParser, FALSE);

	tmp_err_code = setSchema(&lkabParser, &lkab_schema);
	// V: Parse the body of the EXI stream

	while(tmp_err_code == EXIP_OK)
	{
		tmp_err_code = parseNext(&lkabParser);
	}

	// VI: Free the memory allocated by the parser object

	destroyParser(&lkabParser);

	val->ts = parsingData.val.ts;
	val->val = parsingData.val.val;
	val->quality = parsingData.val.quality;

	if(tmp_err_code == EXIP_PARSING_COMPLETE)
		return EXIP_OK;
	else
		return tmp_err_code;
}