Ejemplo n.º 1
0
static int lxp_setencoding (lua_State *L) {
  lxp_userdata *xpu = checkparser(L, 1);
  const char *encoding = luaL_checkstring(L, 2);
  luaL_argcheck(L, xpu->state == XPSpre, 1, "invalid parser state");
  XML_SetEncoding(xpu->parser, encoding);
  return 0;
}
Ejemplo n.º 2
0
bool parseSvnStatus(char*filename,svninfo*svni,mstring*err){
	int read;
	XMLUDATA udata;
	XML_Parser p = XML_ParserCreate(NULL);
	udata.status=STPARSE_DEF;
	udata.svni=svni;
	err->set(NULL);
	XML_SetElementHandler(p, startElement, endElement);
	XML_SetCharacterDataHandler(p, dataHandler);
	XML_SetEncoding(p,"UTF-8");

	XML_SetUserData(p, &udata);
	FILE*f=fopen(filename, "r");
	if(f){
		do{
			void *buf = XML_GetBuffer(p, BUF_SIZE);
			read=fread(buf,1,BUF_SIZE,f);
			if (! XML_ParseBuffer(p, read, /*isFinal*/(read == 0) )){
				//handle error here
				err->sprintf("%s at line %i\n", XML_ErrorString(XML_GetErrorCode(p)), XML_GetCurrentLineNumber(p));
			}
		}while(read>0 && err->len()==0);
		fclose(f);
	}else{
		err->sprintf("can't open file \"%s\"",filename);
	}
	XML_ParserFree(p);
	return (err->len()==0);
}
Ejemplo n.º 3
0
END_TEST

/* Regression test for SF bug #620106. */
static int XMLCALL
external_entity_loader_set_encoding(XML_Parser parser,
                                    const XML_Char *context,
                                    const XML_Char *base,
                                    const XML_Char *systemId,
                                    const XML_Char *publicId)
{
    /* This text says it's an unsupported encoding, but it's really
       UTF-8, which we tell Expat using XML_SetEncoding().
    */
    char *text =
        "<?xml encoding='iso-8859-3'?>"
        "\xC3\xA9";
    XML_Parser extparser;

    extparser = XML_ExternalEntityParserCreate(parser, context, NULL);
    if (extparser == NULL)
        fail("Could not create external entity parser.");
    if (!XML_SetEncoding(extparser, "utf-8"))
        fail("XML_SetEncoding() ignored for external entity");
    if (  XML_Parse(extparser, text, strlen(text), XML_TRUE)
          == XML_STATUS_ERROR) {
        xml_failure(parser);
        return 0;
    }
    return 1;
}
Ejemplo n.º 4
0
XML_Status bmx_expat_XML_SetEncoding(XML_Parser parser, BBString * encoding) {

	char * c = bbStringToUTF8String(encoding);

	XML_Status res = XML_SetEncoding(parser, c);
	
	bbMemFree(c);
	return res;
}
Ejemplo n.º 5
0
void ZLXMLReaderInternal::init(const char *encoding) {
	if (myInitialized) {
		XML_ParserReset(myParser, encoding);
	}

	myInitialized = true;
	XML_UseForeignDTD(myParser, XML_TRUE);

	setupEntities();

	XML_SetUserData(myParser, &myReader);
	if (encoding != 0) {
		XML_SetEncoding(myParser, encoding);
	}
	XML_SetStartElementHandler(myParser, fStartElementHandler);
	XML_SetEndElementHandler(myParser, fEndElementHandler);
	XML_SetCharacterDataHandler(myParser, fCharacterDataHandler);
	XML_SetUnknownEncodingHandler(myParser, fUnknownEncodingHandler, 0);
}
Ejemplo n.º 6
0
void ZLXMLReaderInternal::init(const char *encoding) {
	if (myInitialized) {
		XML_ParserReset(myParser, encoding);
	}

	myInitialized = true;
	XML_UseForeignDTD(myParser, XML_TRUE);

	const std::vector<std::string> &dtds = myReader.externalDTDs();
	for (std::vector<std::string>::const_iterator it = dtds.begin(); it != dtds.end(); ++it) {
		myDTDStreamLocks.insert(ZLFile(*it).inputStream());
		parseDTD(myParser, *it);
	}

	XML_SetUserData(myParser, &myReader);
	if (encoding != 0) {
		XML_SetEncoding(myParser, encoding);
	}
	XML_SetStartElementHandler(myParser, fStartElementHandler);
	XML_SetEndElementHandler(myParser, fEndElementHandler);
	XML_SetCharacterDataHandler(myParser, fCharacterDataHandler);
	XML_SetUnknownEncodingHandler(myParser, fUnknownEncodingHandler, 0);
}
Ejemplo n.º 7
0
int __wiz_load_xml ( lua_State *_l, const char *_filepath ) {
    XML_Parser parser;
    ex_file_t *file;
    char buffer[BUF_SIZE];
    int done;
    size_t len;
    __user_data_t userData;

    //
    file = ex_os_fopen( _filepath, "rb" );
    if ( file == NULL ) {
        ex_log ( "[wiz] Can't find the file %s", _filepath );
        return 1;
    }

    // init userData
    userData.l = _l;
    lua_getglobal( _l, "wiz" );
    lua_getfield( _l, -1, "xmlparser" );

    lua_getfield( _l, -1, "onStartElement" );
    userData.refID_on_start_element = luaL_ref( _l, LUA_REGISTRYINDEX );

    lua_getfield( _l, -1, "onEndElement" );
    userData.refID_on_end_element = luaL_ref( _l, LUA_REGISTRYINDEX );

    lua_getfield( _l, -1, "onAddText" );
    userData.refID_on_add_text = luaL_ref( _l, LUA_REGISTRYINDEX );

    lua_getfield( _l, -1, "onFinish" );
    userData.refID_on_finish = luaL_ref( _l, LUA_REGISTRYINDEX );

        // create xml parser 
        parser = XML_ParserCreate(NULL);
        XML_SetEncoding(parser, "utf-8");
        XML_SetUserData(parser, &userData);
        XML_SetElementHandler ( parser, __start_element, __end_element );
        XML_SetCharacterDataHandler ( parser, __process_character_data );

        // begin parse strimming xml 
        do {
            len = ex_os_fread (file, buffer, BUF_SIZE);
            done = len < sizeof(buffer);
            if ( XML_Parse(parser, buffer, len, done) == XML_STATUS_ERROR ) {
                ex_log( "[wiz] %s at line %d", 
                        XML_ErrorString(XML_GetErrorCode(parser)),
                        XML_GetCurrentLineNumber(parser) );
                return 1;
            }
        } while (!done);

        XML_ParserFree(parser);
        ex_os_fclose(file);

        // invoke wiz.parser.onFinish()
        lua_rawgeti( _l, LUA_REGISTRYINDEX, userData.refID_on_finish );
        if ( lua_pcall( _l, 0, 0, 0 ) ) {
            ex_lua_alert(_l);
        }

    // deinit userData
    luaL_unref( _l, LUA_REGISTRYINDEX, userData.refID_on_start_element );
    luaL_unref( _l, LUA_REGISTRYINDEX, userData.refID_on_end_element );
    luaL_unref( _l, LUA_REGISTRYINDEX, userData.refID_on_add_text );
    luaL_unref( _l, LUA_REGISTRYINDEX, userData.refID_on_finish );
    lua_pop(_l,2); // pop wiz.parser

    return 0;
}
Ejemplo n.º 8
0
enum XML_Status _Expat_XML_SetEncoding(struct ExpatIFace * Self, XML_Parser parser, const XML_Char *encoding)
{
	return XML_SetEncoding(parser, encoding);
}