I forgot to add some parts of the code from the constructor and the
methods. Maybe you find a mistake there.
Regards, Christoph tremmel
Am 18.09.2013 11:29, schrieb Tremmel:
Hey,
I am trying to use the chunk parsing together with the schema
validation. The parser works when I switch off the validation. The
validation works when I use a normal parser.
When i use both together I get an access violation at xmlParseChunk.
Am I missing something or is this a bug?
Regards, Christoph Tremmel
ActorParserCore::ActorParserCore ()
(...)
{
//SAX Handler
xmlSAXHandler sax;
memset(&sax,0,sizeof(xmlSAXHandler));
sax.initialized = XML_SAX2_MAGIC;
sax.startElementNs = ActorParserCore::startElementNsSAX2Func;
sax.endElementNs = ActorParserCore::endElementNsSAX2Func;
sax.characters = ActorParserCore::charactersSAXFunc;
sax.ignorableWhitespace = ActorParserCore::ignorableWhitespaceSAXFunc;
//junkparser
junkparser = xmlCreatePushParserCtxt(&sax, user_data,NULL,0,NULL);
if ( junkparser == NULL ) {
return;
}
(...)
}
bool ActorParserCore::setSchema(const char *schemafilepath) {
if ( attachedschema != NULL) {
xmlSchemaSAXUnplug(attachedschema);
attachedschema = NULL;
}
if ( ctxt2 != NULL) {
xmlSchemaFreeValidCtxt(ctxt2);
ctxt2 = NULL;
}
if ( resource != NULL ) {
xmlSchemaFree(resource);
resource = NULL;
}
if ( schema != NULL ) {
xmlSchemaFreeParserCtxt(schema);
schema = NULL;
}
schema = xmlSchemaNewParserCtxt (schemafilepath);
if ( schema == NULL ) {
return false;
}
failed = false;
xmlSchemaSetParserStructuredErrors(schema,ActorParserCore::handleParserErrors,this);
xmlSchemaSetParserErrors(schema,ActorParserCore::validationError,ActorParserCore::validationWarning,this);
resource = xmlSchemaParse (schema);
if ( resource == NULL ) {
xmlSchemaFreeParserCtxt(schema);
schema = NULL;
return false;
}
if ( failed ) {
xmlSchemaFree(resource);
xmlSchemaFreeParserCtxt(schema);
resource = NULL;
schema = NULL;
return false;
}
#if 0
FILE * check = fopen("..\Parser\XSD\Test.xsd","w");
if ( check != NULL ) {
xmlSchemaDump(check,resource);
fclose(check);
}
#endif
ctxt2 = xmlSchemaNewValidCtxt(resource);
if ( ctxt2 == NULL) {
xmlSchemaFree(resource);
xmlSchemaFreeParserCtxt(schema);
resource = NULL;
schema = NULL;
return false;
}
attachedschema = xmlSchemaSAXPlug (ctxt2, &(junkparser->sax), ((void
**)&user_data));
if ( attachedschema == NULL) {
xmlSchemaFreeValidCtxt(ctxt2);
xmlSchemaFree(resource);
xmlSchemaFreeParserCtxt(schema);
ctxt2 = NULL;
resource = NULL;
schema = NULL;
return false;
}
xmlSchemaSetValidStructuredErrors(ctxt2,ActorParserCore::handleParserErrors,this);
xmlSchemaSetValidErrors(ctxt2,ActorParserCore::validationError,ActorParserCore::validationWarning,this);
return true;
}
ssize_t ActorParserCore::parse (char *message, size_t messagelength, size_t
count,std::string filename) {
(...)
if ( remainingjunks == 0 ) {
if ( current_message != NULL ) {
current_message->unref();
current_message = NULL;
newmessage.pop();
}
if ( count == 0 ) {
return 1;
}
failed = false;
success = 0;
current_message = new ActorParserImpl::Message(*this);
if ( current_message == NULL ) {
return 0;
}
newmessage.push(current_message);
if ( newmessage.empty() ) {
current_message->unref();
current_message = NULL;
return 0;
}
remainingjunks = count;
xmlError * lasterr = xmlCtxtGetLastError(junkparser);
if ( lasterr != NULL ) {
xmlCtxtResetLastError(junkparser);
xmlCtxtResetLastError(this);
}
lasterr = xmlCtxtGetLastError(this);
if ( lasterr != NULL ) {
xmlResetLastError();
}
if ( parsererror != NULL ) {
parsererror->unref();
parsererror = NULL;
}
xmlCtxtResetPush(junkparser, NULL, 0, filename.c_str(),NULL );
}
if ( -- remainingjunks == 0 ) {
if ( ( xmlParseChunk(junkparser, message,(int) messagelength, 1 ) !=
XML_ERR_OK )
|| failed ) {
if ( current_message != NULL ) {
current_message->unref();
current_message = NULL;
newmessage.pop();
}
reportError();
return 0;
}
if ( success == 0 ) { // seems as if no acknowledge or request message
was processed assume AppList
current_message->id = "";
current_message->replyto = "";
current_message->content = "";
current_message->maskname = "";
ActorParserImpl::MessageType & msgtyp =
(ActorParserImpl::MessageType)(current_message->type);
msgtyp = ActorParserImpl::COMMANDLIST;
success = 1;
master.reportMessage(current_message);
}
if ( current_message != NULL ) {
current_message->unref();
current_message = NULL;
newmessage.pop();
}
return (ssize_t)success;
}
if ( ( xmlParseChunk(junkparser, message, (int)messagelength, 0 ) !=
XML_ERR_OK )
|| failed ) {
if ( current_message != NULL ) {
current_message->unref();
current_message = NULL;
newmessage.pop();
}
remainingjunks = 0;
reportError();
return 0;
}
return -1;
}
_______________________________________________
xml mailing list, project page http://xmlsoft.org/
xml@gnome.org
https://mail.gnome.org/mailman/listinfo/xml