OGRErr GMLExpatHandler::startElement(const char *pszName, void* attr ) { if (m_bStopParsing) return CE_Failure; const char* pszColon = strchr(pszName, ':'); if (pszColon) pszName = pszColon + 1; if (GMLHandler::startElement(pszName, attr) == CE_Failure) { CPLError(CE_Failure, CPLE_OutOfMemory, "Out of memory"); m_bStopParsing = TRUE; XML_StopParser(m_oParser, XML_FALSE); return CE_Failure; } return CE_None; }
/* * Handle the expat characterData event. */ static void characterData(IterParser *self, const XML_Char *text, int len) { /* If we've already had an error in a previous call, don't make things worse. */ if (PyErr_Occurred() != NULL) { XML_StopParser(self->parser, 0); return; } if (self->text_size == 0) { self->last_line = (unsigned long)XML_GetCurrentLineNumber( self->parser); self->last_col = (unsigned long)XML_GetCurrentColumnNumber( self->parser); } if (self->keep_text) { (void)text_append(self, text, (Py_ssize_t)len); } }
void OGRJMLLayer::dataHandlerCbk(const char *data, int nLen) { if (bStopParsing) return; nDataHandlerCounter ++; if (nDataHandlerCounter >= BUFSIZ) { CPLError(CE_Failure, CPLE_AppDefined, "File probably corrupted (million laugh pattern)"); XML_StopParser(oParser, XML_FALSE); bStopParsing = true; return; } nWithoutEventCounter = 0; if (bAccumulateElementValue) { AddStringToElementValue(data, nLen); } }
static void XMLCALL end_proc(void *data, const char *el) { Data* p = (Data*)data; SkXMLPullParser::Curr* c = p->fCurr; if (c->fEventType == SkXMLPullParser::START_TAG) { /* if we get here, we were called with a start_tag immediately followed by this end_tag. The caller will only see the end_tag, so we set a flag to notify them of the missed start_tag */ p->fState = Data::MISSED_START_TAG; SkASSERT(c->fName != NULL); SkASSERT(strcmp(c->fName, el) == 0); } else c->fName = dupstr(p->fAlloc, el, strlen(el)); c->fEventType = SkXMLPullParser::END_TAG; XML_StopParser(p->fParser, true); }
/* * End element adaptor */ void XMLCALL rtSaxCEndElementHandler (void *userData, const XML_Char *name) { XMLReaderImpl* reader = (XMLReaderImpl*)userData; OSCTXT* pctxt = reader->reader.pctxt; OSXMLCtxtInfo* ctxtInfo = (OSXMLCtxtInfo*)pctxt->pXMLInfo; OSSAXHandlerBase* pSaxBase; OSBOOL bSkip = FALSE; if (ctxtInfo) { /* check, are we skipping this level or not */ if (ctxtInfo->mSkipLevel != 0 && ctxtInfo->mSaxLevel >= ctxtInfo->mSkipLevel) { bSkip = TRUE; } } /* call to target end element handler */ if (!bSkip && reader->pEndElementProc != 0) { const OSUTF8CHAR* localname = parseQName ((const OSUTF8CHAR*)name); reader->pEndElementProc (reader->userData, (const OSUTF8CHAR*)localname, (const OSUTF8CHAR*)name); } if (ctxtInfo) { /* if we left the skipping level, reset mSkipLevel */ if (ctxtInfo->mSkipLevel > 0 && ctxtInfo->mSaxLevel == ctxtInfo->mSkipLevel) ctxtInfo->mSkipLevel = 0; /* reset skipLevel */ ctxtInfo->mSaxLevel--; ctxtInfo->mbCdataProcessed = FALSE; } /* Set mState to a final state, to indicate parsing is finished */ pSaxBase = (OSSAXHandlerBase*)reader->userData; if (pSaxBase != 0 && pSaxBase->mLevel == 0) { XML_StopParser(reader->parser, TRUE); pSaxBase->mState = OS_SAX_FINAL_STATE; } }
static void XMLCALL start_proc(void *data, const char *el, const char **attr) { Data* p = (Data*)data; SkXMLPullParser::Curr* c = p->fCurr; SkChunkAlloc& alloc = p->fAlloc; c->fName = dupstr(alloc, el, strlen(el)); int n = count_pairs(attr); SkXMLPullParser::AttrInfo* info = (SkXMLPullParser::AttrInfo*)alloc.alloc(n * sizeof(SkXMLPullParser::AttrInfo), SkChunkAlloc::kThrow_AllocFailType); c->fAttrInfoCount = n; c->fAttrInfos = info; for (int i = 0; i < n; i++) { info[i].fName = dupstr(alloc, attr[0], strlen(attr[0])); info[i].fValue = dupstr(alloc, attr[1], strlen(attr[1])); attr += 2; } c->fEventType = SkXMLPullParser::START_TAG; XML_StopParser(p->fParser, true); }
static int lxp_stop (lua_State *L) { lxp_userdata *xpu = checkparser(L, 1); lua_pushboolean(L, XML_StopParser(xpu->parser, XML_FALSE) == XML_STATUS_OK); return 1; }
enum XML_Status _Expat_XML_StopParser(struct ExpatIFace * Self, XML_Parser parser, XML_Bool resumable) { return XML_StopParser(parser, resumable); }
void LLSDXMLParser::Impl::endElementHandler(const XML_Char* name) { #ifdef XML_PARSER_PERFORMANCE_TESTS XML_Timer timer(&endElementTime); #endif // XML_PARSER_PERFORMANCE_TESTS --mDepth; if (mSkipping) { if (mDepth < mSkipThrough) { mSkipping = false; } return; } Element element = readElement(name); switch (element) { case ELEMENT_LLSD: if (mInLLSDElement) { mInLLSDElement = false; mGracefullStop = true; XML_StopParser(mParser, false); } return; case ELEMENT_KEY: mCurrentKey = mCurrentContent; return; default: // all rest are values, fall through ; } if (!mInLLSDElement) { return; } LLSD& value = *mStack.back(); mStack.pop_back(); switch (element) { case ELEMENT_UNDEF: value.clear(); break; case ELEMENT_BOOL: value = (mCurrentContent == "true" || mCurrentContent == "1"); break; case ELEMENT_INTEGER: { S32 i; if (sscanf(mCurrentContent.c_str(), "%d", &i) == 1) { // See if sscanf works - it's faster value = i; } else { value = LLSD(mCurrentContent).asInteger(); } break; } case ELEMENT_REAL: { // sscanf() is sensitive to the locale and will fail decoding // the decimal point for locales where the decimal separator // is a comma... So, better not using sscanf() for this purpose. // See http://jira.secondlife.com/browse/EXP-700 #if 0 F64 r; if (sscanf(mCurrentContent.c_str(), "%lf", &r) == 1) { // See if sscanf works - it's faster value = r; } else { value = LLSD(mCurrentContent).asReal(); } #else value = LLSD(mCurrentContent).asReal(); #endif break; } case ELEMENT_STRING: value = mCurrentContent; break; case ELEMENT_UUID: value = LLSD(mCurrentContent).asUUID(); break; case ELEMENT_DATE: value = LLSD(mCurrentContent).asDate(); break; case ELEMENT_URI: value = LLSD(mCurrentContent).asURI(); break; case ELEMENT_BINARY: { // Regex is expensive, but only fix for whitespace in base64, // created by python and other non-linden systems - DEV-39358 // Fortunately we have very little binary passing now, // so performance impact shold be negligible. + poppy 2009-09-04 boost::regex r; r.assign("\\s"); std::string stripped = boost::regex_replace(mCurrentContent, r, ""); S32 len = apr_base64_decode_len(stripped.c_str()); std::vector<U8> data; data.resize(len); len = apr_base64_decode_binary(&data[0], stripped.c_str()); data.resize(len); value = data; break; } case ELEMENT_UNKNOWN: value.clear(); break; default: // other values, map and array, have already been set break; } mCurrentContent.clear(); }
static void entity_declaration(void *userData, const XML_Char *entityName, int is_parameter_entity, const XML_Char *value, int value_length, const XML_Char *base, const XML_Char *systemId, const XML_Char *publicId, const XML_Char *notationName) { am_xml_parser_ctx_t *ctx = (am_xml_parser_ctx_t *) userData; XML_StopParser(ctx->parser, XML_FALSE); }
void LLSDXMLParser::Impl::endElementHandler(const XML_Char* name) { #ifdef XML_PARSER_PERFORMANCE_TESTS XML_Timer timer( &endElementTime ); #endif // XML_PARSER_PERFORMANCE_TESTS --mDepth; if (mSkipping) { if (mDepth < mSkipThrough) { mSkipping = false; } return; } Element element = readElement(name); switch (element) { case ELEMENT_LLSD: if (mInLLSDElement) { mInLLSDElement = false; mGracefullStop = true; XML_StopParser(mParser, false); } return; case ELEMENT_KEY: mCurrentKey = mCurrentContent; return; default: // all rest are values, fall through ; } if (!mInLLSDElement) { return; } LLSD& value = *mStack.back(); mStack.pop_back(); switch (element) { case ELEMENT_UNDEF: value.clear(); break; case ELEMENT_BOOL: value = (mCurrentContent == "true" || mCurrentContent == "1"); break; case ELEMENT_INTEGER: { S32 i; if ( sscanf(mCurrentContent.c_str(), "%d", &i ) == 1 ) { // See if sscanf works - it's faster value = i; } else { value = LLSD(mCurrentContent).asInteger(); } } break; case ELEMENT_REAL: { F64 r; if ( sscanf(mCurrentContent.c_str(), "%lf", &r ) == 1 ) { // See if sscanf works - it's faster value = r; } else { value = LLSD(mCurrentContent).asReal(); } } break; case ELEMENT_STRING: value = mCurrentContent; break; case ELEMENT_UUID: value = LLSD(mCurrentContent).asUUID(); break; case ELEMENT_DATE: value = LLSD(mCurrentContent).asDate(); break; case ELEMENT_URI: value = LLSD(mCurrentContent).asURI(); break; case ELEMENT_BINARY: { S32 len = apr_base64_decode_len(mCurrentContent.c_str()); std::vector<U8> data; data.resize(len); len = apr_base64_decode_binary(&data[0], mCurrentContent.c_str()); data.resize(len); value = data; break; } case ELEMENT_UNKNOWN: value.clear(); break; default: // other values, map and array, have already been set break; } mCurrentContent.clear(); }
void OMXMLReaderExpat::startElementHandler(const XML_Char* name, const XML_Char** atts) { TRACE("OMXMLReaderExpat::startElementHandler"); wchar_t* workBuffer = getWorkBuffer(xmlStringLen(name) + 1); OMUInt32 strLen = readCharacters(workBuffer, name, NAMESPACE_SEPARATOR); _uri = workBuffer; if (strLen > 0) { strLen = readCharacters(workBuffer, &(name[strLen + 1]), 0); } else { strLen = readCharacters(workBuffer, &(name[strLen]), 0); } _localName = workBuffer; OMListIterator<OMXMLAttribute*> iter(_attributes, OMBefore); while (++iter) { delete iter.value(); } _attributes.clear(); if (*atts != 0) { const XML_Char** attsPtr = atts; while (*attsPtr != 0) { OMWString nmspace; OMWString localName; OMWString value; wchar_t* workBuffer = getWorkBuffer(xmlStringLen(*attsPtr) + 1); OMUInt32 strLen = readCharacters(workBuffer, *attsPtr, NAMESPACE_SEPARATOR); nmspace = workBuffer; if (strLen > 0) { strLen = readCharacters(workBuffer, &((*attsPtr)[strLen + 1]), 0); } else { strLen = readCharacters(workBuffer, &((*attsPtr)[strLen]), 0); } localName = workBuffer; attsPtr++; workBuffer = getWorkBuffer(xmlStringLen(*attsPtr) + 1); strLen = readCharacters(workBuffer, *attsPtr, 0); value = workBuffer; _attributes.append(new OMXMLAttribute(nmspace.c_str(), localName.c_str(), value.c_str())); attsPtr++; } } XML_Status status = XML_StopParser(_parser, true); if (status != XML_STATUS_OK) { XML_Error errorCode = XML_GetErrorCode(_parser); if (errorCode != XML_ERROR_SUSPENDED) { throw OMException(getErrorString()); } } registerEvent(START_ELEMENT); }
//-------------------------------------------------------------------- void ExpatSaxParser::abortParsing() { XML_StopParser(mParser, false); }
/* * Handle the expat endElement event. */ static void endElement(IterParser *self, const XML_Char *name) { PyObject* pyname = NULL; PyObject* tuple = NULL; PyObject* pytext = NULL; const XML_Char* name_start = NULL; XML_Char* end; PyObject* pos = NULL; /* If we've already had an error in a previous call, don't make things worse. */ if (PyErr_Occurred() != NULL) { XML_StopParser(self->parser, 0); return; } /* Don't overflow the queue -- in practice this should *never* happen */ if (self->queue_write_idx < self->queue_size) { tuple = PyTuple_New(4); if (tuple == NULL) { goto fail; } Py_INCREF(Py_False); PyTuple_SET_ITEM(tuple, 0, Py_False); /* This is an egregious but effective optimization. Since by far the most frequently occurring element name in a large VOTABLE file is TD, we explicitly check for it here with integer comparison to avoid the lookup in the interned string table in PyString_InternFromString, and return a singleton string for "TD" */ if ((*(int*)name & TD_AS_INT_MASK) == TD_AS_INT) { Py_INCREF(self->td_singleton); PyTuple_SetItem(tuple, 1, self->td_singleton); } else { name_start = remove_namespace(name); pyname = PyUnicode_FromString(name_start); if (pyname == NULL) { goto fail; } PyTuple_SetItem(tuple, 1, pyname); pyname = NULL; } /* Cut whitespace off the end of the string */ end = self->text + self->text_size - 1; while (end >= self->text && IS_WHITESPACE(*end)) { --end; --self->text_size; } pytext = PyUnicode_FromStringAndSize(self->text, self->text_size); if (pytext == NULL) { goto fail; } PyTuple_SetItem(tuple, 2, pytext); pytext = NULL; pos = make_pos(self); if (pos == NULL) { goto fail; } PyTuple_SetItem(tuple, 3, pos); pos = NULL; self->keep_text = 0; self->queue[self->queue_write_idx++] = tuple; } else { PyErr_SetString( PyExc_RuntimeError, "XML queue overflow in endElement. This most likely indicates an internal bug."); goto fail; } return; fail: Py_XDECREF(tuple); XML_StopParser(self->parser, 0); }
/* * Handle the expat startElement event. */ static void startElement(IterParser *self, const XML_Char *name, const XML_Char **atts) { PyObject* pyname = NULL; PyObject* pyatts = NULL; const XML_Char** att_ptr = atts; const XML_Char* name_start = NULL; PyObject* tuple = NULL; PyObject* key = NULL; PyObject* val = NULL; PyObject* pos = NULL; /* If we've already had an error in a previous call, don't make things worse. */ if (PyErr_Occurred() != NULL) { XML_StopParser(self->parser, 0); return; } /* Don't overflow the queue -- in practice this should *never* happen */ if (self->queue_write_idx < self->queue_size) { tuple = PyTuple_New(4); if (tuple == NULL) { goto fail; } Py_INCREF(Py_True); PyTuple_SET_ITEM(tuple, 0, Py_True); /* This is an egregious but effective optimization. Since by far the most frequently occurring element name in a large VOTABLE file is TD, we explicitly check for it here with integer comparison to avoid the lookup in the interned string table in PyString_InternFromString, and return a singleton string for "TD" */ if ((*(int*)name & TD_AS_INT_MASK) == TD_AS_INT) { Py_INCREF(self->td_singleton); PyTuple_SetItem(tuple, 1, self->td_singleton); } else { name_start = remove_namespace(name); pyname = PyUnicode_FromString(name_start); if (pyname == NULL) { goto fail; } PyTuple_SetItem(tuple, 1, pyname); pyname = NULL; } if (*att_ptr) { pyatts = PyDict_New(); if (pyatts == NULL) { goto fail; } do { if (*(*(att_ptr + 1)) != 0) { key = PyUnicode_FromString(*att_ptr); if (key == NULL) { goto fail; } val = PyUnicode_FromString(*(att_ptr + 1)); if (val == NULL) { Py_DECREF(key); goto fail; } if (PyDict_SetItem(pyatts, key, val)) { Py_DECREF(key); Py_DECREF(val); goto fail; } Py_DECREF(key); Py_DECREF(val); key = val = NULL; } att_ptr += 2; } while (*att_ptr); } else { Py_INCREF(self->dict_singleton); pyatts = self->dict_singleton; } PyTuple_SetItem(tuple, 2, pyatts); pyatts = NULL; self->last_line = (unsigned long)XML_GetCurrentLineNumber( self->parser); self->last_col = (unsigned long)XML_GetCurrentColumnNumber( self->parser); pos = make_pos(self); if (pos == NULL) { goto fail; } PyTuple_SetItem(tuple, 3, pos); pos = NULL; text_clear(self); self->keep_text = 1; self->queue[self->queue_write_idx++] = tuple; } else { PyErr_SetString( PyExc_RuntimeError, "XML queue overflow in startElement. This most likely indicates an internal bug."); goto fail; } return; fail: Py_XDECREF(tuple); Py_XDECREF(pyatts); XML_StopParser(self->parser, 0); }
static void XMLCALL start(void *data, const char *el, const char **attr) { int i; int newstate; int track,side,sector,sectorsize; AppData *ad = (AppData *) data; newstate = getnewstate((char*)el, ad->current_state); if ( newstate >= 0 ) { ad->stack_ptr++; memcpy(&ad->statestack[ad->stack_ptr], &ad->statestack[ad->stack_ptr-1],sizeof(parse_stack)); ad->statestack[ad->stack_ptr].state = newstate; ad->current_state = newstate; if(!ad->xmlcheck) { switch(ad->current_state) { case LAYOUT: ad->fb = hxcfe_initFloppy(ad->floppycontext,80,2); break; case TRACK: i=0; side=0; track=0; while(attr[i] && strcmp("track_number",attr[i]) ) { i++; } if(attr[i+1]) { track = atoi(attr[i+1]); } i=0; while(attr[i] && strcmp("side_number",attr[i]) ) { i++; } if(attr[i+1]) { side = atoi(attr[i+1]); } ad->statestack[ad->stack_ptr].cur_track = (track<<1) | (side&1); ad->ts[(track<<1) | (side&1)].set=1; hxcfe_pushTrackPFS (ad->fb,track,side); break; case SECTOR: i=0; while(attr[i] && strcmp("sector_id",attr[i]) ) { i++; } if(attr[i+1]) { sector = atoi(attr[i+1]); } i=0; while(attr[i] && strcmp("sector_size",attr[i]) ) { i++; } if(attr[i+1]) { sectorsize = atoi(attr[i+1]); } track = ad->statestack[ad->stack_ptr].cur_track; hxcfe_pushSector(ad->fb); hxcfe_setSectorID(ad->fb,(unsigned char)sector); hxcfe_setSectorSize(ad->fb,sectorsize); if(ad->ts[track].base_adress + ad->ts[track].track_size + sectorsize < ad->buffer_size) { hxcfe_setSectorData(ad->fb,&ad->image_data[ad->ts[track].base_adress + ad->ts[track].track_size],sectorsize); } ad->ts[track].track_size += sectorsize; break; } } } else { XML_StopParser(ad->p, 0); } }
static void logFatalTypeError(const char* expected, Elm found) { fprintf(stderr,"Wrong element type, expected %s, found %s\n", expected, elmNames[found]); XML_StopParser(parser, XML_FALSE); }
void XMLCALL XmlShallowValidator::start ( void *data, const XML_Char *el, const XML_Char **attr ) { XmlShallowValidatorData *vd; vd = ( XmlShallowValidatorData * ) data; if ( XML_GetCurrentLineNumber ( vd->p ) > ( unsigned ) ( vd->maxLine + 1 ) ) { XML_StopParser ( vd->p, true ); } vd->push ( el ); ++ ( vd->depth ); //check element ok wxString parent ( vd->getParent().c_str(), wxConvUTF8 ); if ( parent.empty() ) return; if ( vd->elementMap.empty() ) return; wxString element ( vd->getElement().c_str(), wxConvUTF8 ); if ( !vd->elementMap[parent].count ( element ) ) { vd->isValid = false; vd->positionVector.push_back ( make_pair ( XML_GetCurrentLineNumber ( vd->p ), XML_GetCurrentColumnNumber ( vd->p ) ) ); } element = wxString ( el, wxConvUTF8 ); std::map<wxString, std::set<wxString> > attributeMap; size_t requiredAttributeCount = vd->requiredAttributeMap[element].size(); wxString currentAttribute; while ( *attr ) { attributeMap = vd->attributeMap[element]; // check for existence currentAttribute = wxString ( *attr, wxConvUTF8 ); if ( !attributeMap.count ( currentAttribute ) ) { vd->isValid = false; vd->positionVector.push_back ( make_pair ( XML_GetCurrentLineNumber ( vd->p ), XML_GetCurrentColumnNumber ( vd->p ) ) ); } // check for requirement if ( vd->requiredAttributeMap[element].find ( currentAttribute ) != vd->requiredAttributeMap[element].end() ) --requiredAttributeCount; attr += 2; } if ( requiredAttributeCount != 0 ) { vd->isValid = false; vd->positionVector.push_back ( make_pair ( XML_GetCurrentLineNumber ( vd->p ), XML_GetCurrentColumnNumber ( vd->p ) ) ); } }
/* * Handle the expat startElement event. */ static void startElement(IterParser *self, const XML_Char *name, const XML_Char **atts) { PyObject* pyname = NULL; PyObject* pyatts = NULL; const XML_Char** att_ptr = atts; const XML_Char* name_start = NULL; PyObject* tuple = NULL; PyObject* key = NULL; PyObject* val = NULL; /* If we've already had an error in a previous call, don't make things worse. */ if (PyErr_Occurred() != NULL) { XML_StopParser(self->parser, 0); return; } /* Don't overflow the queue -- in practice this should *never* happen */ if (self->queue_write_idx < self->queue_size) { tuple = PyTuple_New(4); if (tuple == NULL) { XML_StopParser(self->parser, 0); return; } Py_INCREF(Py_True); PyTuple_SET_ITEM(tuple, 0, Py_True); /* This is an egregious but effective optimization. Since by far the most frequently occurring element name in a large VOTABLE file is TD, we explicitly check for it here with integer comparison to avoid the lookup in the interned string table in PyString_InternFromString, and return a singleton string for "TD" */ if ((*(int*)name & TD_AS_INT_MASK) == TD_AS_INT) { Py_INCREF(self->td_singleton); PyTuple_SetItem(tuple, 1, self->td_singleton); } else { name_start = remove_namespace(name); pyname = PyUnicode_FromString(name_start); if (pyname == NULL) { Py_DECREF(tuple); XML_StopParser(self->parser, 0); return; } PyTuple_SetItem(tuple, 1, pyname); } if (*att_ptr) { pyatts = PyDict_New(); if (pyatts == NULL) { Py_DECREF(tuple); XML_StopParser(self->parser, 0); return; } do { if (*(*(att_ptr + 1)) != 0) { /* Python < 2.6.5 can't handle unicode keyword arguments. Since those were coming from here (the dictionary of attributes), we use byte strings for the keys instead. Should be fine for VOTable, since it has ascii attribute names, but that's not true of XML in general. */ #if PY_VERSION_HEX < 0x02060500 /* Due to Python issue #4978 */ key = PyBytes_FromString(*att_ptr); #else key = PyUnicode_FromString(*att_ptr); #endif if (key == NULL) { Py_DECREF(tuple); XML_StopParser(self->parser, 0); return; } val = PyUnicode_FromString(*(att_ptr + 1)); if (val == NULL) { Py_DECREF(key); Py_DECREF(tuple); XML_StopParser(self->parser, 0); return; } if (PyDict_SetItem(pyatts, key, val)) { Py_DECREF(pyatts); Py_DECREF(tuple); Py_DECREF(key); Py_DECREF(val); XML_StopParser(self->parser, 0); return; } Py_DECREF(key); Py_DECREF(val); } att_ptr += 2; } while (*att_ptr); } else { Py_INCREF(self->dict_singleton); pyatts = self->dict_singleton; } PyTuple_SetItem(tuple, 2, pyatts); self->last_line = (unsigned long)XML_GetCurrentLineNumber( self->parser); self->last_col = (unsigned long)XML_GetCurrentColumnNumber( self->parser); PyTuple_SetItem(tuple, 3, make_pos(self)); text_clear(self); self->keep_text = 1; self->queue[self->queue_write_idx++] = tuple; } else { PyErr_SetString( PyExc_RuntimeError, "XML queue overflow in startElement. This most likely indicates an internal bug."); } }
/* * Handle the XML declaration so that we can determine its encoding. */ static void xmlDecl(IterParser *self, const XML_Char *version, const XML_Char *encoding, int standalone) { PyObject* tuple = NULL; PyObject* xml_str = NULL; PyObject* attrs = NULL; PyObject* encoding_str = NULL; PyObject* version_str = NULL; PyObject* pos = NULL; if (self->queue_write_idx < self->queue_size) { tuple = PyTuple_New(4); if (tuple == NULL) { goto fail; } Py_INCREF(Py_True); PyTuple_SET_ITEM(tuple, 0, Py_True); xml_str = PyUnicode_FromString("xml"); if (xml_str == NULL) { goto fail; } PyTuple_SET_ITEM(tuple, 1, xml_str); xml_str = NULL; attrs = PyDict_New(); if (attrs == NULL) { goto fail; } if (encoding) { encoding_str = PyUnicode_FromString(encoding); } else { encoding_str = PyUnicode_FromString(""); } if (encoding_str == NULL) { goto fail; } if (PyDict_SetItemString(attrs, "encoding", encoding_str)) { Py_DECREF(encoding_str); goto fail; } Py_DECREF(encoding_str); encoding_str = NULL; if (version) { version_str = PyUnicode_FromString(version); } else { version_str = PyUnicode_FromString(""); } if (version_str == NULL) { goto fail; } if (PyDict_SetItemString(attrs, "version", version_str)) { Py_DECREF(version_str); goto fail; } Py_DECREF(version_str); version_str = NULL; PyTuple_SET_ITEM(tuple, 2, attrs); attrs = NULL; self->last_line = (unsigned long)XML_GetCurrentLineNumber( self->parser); self->last_col = (unsigned long)XML_GetCurrentColumnNumber( self->parser); pos = make_pos(self); if (pos == NULL) { goto fail; } PyTuple_SetItem(tuple, 3, pos); pos = NULL; self->queue[self->queue_write_idx++] = tuple; } else { PyErr_SetString( PyExc_RuntimeError, "XML queue overflow in xmlDecl. This most likely indicates an internal bug."); goto fail; } return; fail: Py_XDECREF(tuple); Py_XDECREF(attrs); XML_StopParser(self->parser, 0); }
void LLSDXMLParser::Impl::endElementHandler(const XML_Char* name) { #ifdef XML_PARSER_PERFORMANCE_TESTS XML_Timer timer( &endElementTime ); #endif // XML_PARSER_PERFORMANCE_TESTS --mDepth; if (mSkipping) { if (mDepth < mSkipThrough) { mSkipping = false; } return; } Element element = readElement(name); switch (element) { case ELEMENT_LLSD: if (mInLLSDElement) { mInLLSDElement = false; mGracefullStop = true; XML_StopParser(mParser, false); } return; case ELEMENT_KEY: mCurrentKey = mCurrentContent; return; default: // all rest are values, fall through ; } if (!mInLLSDElement) { return; } LLSD& value = *mStack.back(); mStack.pop_back(); switch (element) { case ELEMENT_UNDEF: value.clear(); break; case ELEMENT_BOOL: value = (mCurrentContent == "true" || mCurrentContent == "1"); break; case ELEMENT_INTEGER: { S32 i; // sscanf okay here with different locales - ints don't change for different locale settings like floats do. if ( sscanf(mCurrentContent.c_str(), "%d", &i ) == 1 ) { // See if sscanf works - it's faster value = i; } else { value = LLSD(mCurrentContent).asInteger(); } } break; case ELEMENT_REAL: { value = LLSD(mCurrentContent).asReal(); // removed since this breaks when locale has decimal separator that isn't '.' // investigated changing local to something compatible each time but deemed higher // risk that just using LLSD.asReal() each time. //F64 r; //if ( sscanf(mCurrentContent.c_str(), "%lf", &r ) == 1 ) //{ // See if sscanf works - it's faster // value = r; //} //else //{ // value = LLSD(mCurrentContent).asReal(); //} } break; case ELEMENT_STRING: value = mCurrentContent; break; case ELEMENT_UUID: value = LLSD(mCurrentContent).asUUID(); break; case ELEMENT_DATE: value = LLSD(mCurrentContent).asDate(); break; case ELEMENT_URI: value = LLSD(mCurrentContent).asURI(); break; case ELEMENT_BINARY: { // Regex is expensive, but only fix for whitespace in base64, // created by python and other non-linden systems - DEV-39358 // Fortunately we have very little binary passing now, // so performance impact shold be negligible. + poppy 2009-09-04 boost::regex r; r.assign("\\s"); std::string stripped = boost::regex_replace(mCurrentContent, r, ""); size_t len = LLBase64::requiredDecryptionSpace(stripped); std::vector<U8> data; data.resize(len); len = LLBase64::decode(stripped, &data[0], len); data.resize(len); value = data; break; } case ELEMENT_UNKNOWN: value.clear(); break; default: // other values, map and array, have already been set break; } mCurrentContent.clear(); }
void XMLCALL KML::startElement(void* pUserData, const char* pszName, const char** ppszAttr) { int i = 0; KMLNode* poMynew = NULL; Attribute* poAtt = NULL; KML* poKML = (KML*) pUserData; poKML->nWithoutEventCounter = 0; if(poKML->poTrunk_ == NULL || (poKML->poCurrent_->getName()).compare("description") != 0) { if (poKML->nDepth_ == 1024) { CPLError( CE_Failure, CPLE_AppDefined, "Too big depth level (%d) while parsing KML.", poKML->nDepth_ ); XML_StopParser(poKML->oCurrentParser, XML_FALSE); return; } poMynew = new KMLNode(); poMynew->setName(pszName); poMynew->setLevel(poKML->nDepth_); for (i = 0; ppszAttr[i]; i += 2) { poAtt = new Attribute(); poAtt->sName = ppszAttr[i]; poAtt->sValue = ppszAttr[i + 1]; poMynew->addAttribute(poAtt); } if(poKML->poTrunk_ == NULL) poKML->poTrunk_ = poMynew; if(poKML->poCurrent_ != NULL) poMynew->setParent(poKML->poCurrent_); poKML->poCurrent_ = poMynew; poKML->nDepth_++; } else { std::string sNewContent = "<"; sNewContent += pszName; for (i = 0; ppszAttr[i]; i += 2) { sNewContent += " "; sNewContent += ppszAttr[i]; sNewContent += "=\""; sNewContent += ppszAttr[i + 1]; sNewContent += "\""; } sNewContent += ">"; if(poKML->poCurrent_->numContent() == 0) poKML->poCurrent_->addContent(sNewContent); else poKML->poCurrent_->appendContent(sNewContent); } }