XMLSize_t IconvGNUTranscoder::transcodeTo ( const XMLCh* const srcData , const XMLSize_t srcCount , XMLByte* const toFill , const XMLSize_t maxBytes , XMLSize_t& charsEaten , const UnRepOpts /*options*/ ) { // Transcode FROM XMLCh char tmpWBuff[gTempBuffArraySize]; char *startSrc = tmpWBuff; char *wBufPtr = 0; ArrayJanitor<char> janBuf(wBufPtr, getMemoryManager()); size_t len = srcCount * uChSize(); if (uChSize() != sizeof(XMLCh) || UBO() != BYTE_ORDER) { if (len > gTempBuffArraySize) { wBufPtr = (char*) getMemoryManager()->allocate(len * sizeof(char));//new char[len]; janBuf.reset(wBufPtr, getMemoryManager()); startSrc = wBufPtr; } else startSrc = tmpWBuff; xmlToMbs (srcData, startSrc, srcCount); } else startSrc = (char *) srcData; char* startTarget = (char *) toFill; size_t srcLen = len; size_t rc; { XMLMutexLock lockConverter(&fMutex); rc = iconvTo (startSrc, &srcLen, &startTarget, maxBytes); } if (rc == (size_t)-1 && errno != E2BIG) { ThrowXMLwithMemMgr(TranscodingException, XMLExcepts::Trans_BadSrcSeq, getMemoryManager()); } charsEaten = srcCount - srcLen / uChSize(); return startTarget - (char *)toFill; }
unsigned int IconvGNUTranscoder::transcodeTo ( const XMLCh* const srcData , const unsigned int srcCount , XMLByte* const toFill , const unsigned int maxBytes , unsigned int& charsEaten , const UnRepOpts options ) { // Transcode FROM XMLCh char tmpWBuff[gTempBuffArraySize]; char *startSrc = tmpWBuff; char *wBufPtr = 0; size_t len = srcCount * uChSize(); if (uChSize() != sizeof(XMLCh) || UBO() != BYTE_ORDER) { if (len > gTempBuffArraySize) { wBufPtr = (char*) getMemoryManager()->allocate ( len * sizeof(char) );//new char[len]; if (wBufPtr == NULL) return 0; startSrc = wBufPtr; } else startSrc = tmpWBuff; xmlToMbs (srcData, srcCount, startSrc, srcCount); } else startSrc = (char *) srcData; char* startTarget = (char *) toFill; size_t srcLen = len; size_t rc = iconvTo (startSrc, &srcLen, &startTarget, maxBytes); if (rc == (size_t)-1 && errno != E2BIG) { if (wBufPtr) getMemoryManager()->deallocate(wBufPtr);//delete [] wBufPtr; ThrowXMLwithMemMgr(TranscodingException, XMLExcepts::Trans_BadSrcSeq, getMemoryManager()); } charsEaten = srcCount - srcLen / uChSize(); if (wBufPtr) getMemoryManager()->deallocate(wBufPtr);//delete [] wBufPtr; return startTarget - (char *)toFill; }
// // This method is called in the case of errors to clean up the stack when // entities have been incorrectly left on the stack due to syntax errors. // It just cleans back the stack, and sends no entity events. // void ReaderMgr::cleanStackBackTo(const unsigned int readerNum) { // // Just start popping readers until we find the one with the indicated // reader number. // while (true) { if (fCurReader->getReaderNum() == readerNum) break; if (fReaderStack->empty()) ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::RdrMgr_ReaderIdNotFound, fMemoryManager); delete fCurReader; fCurReader = fReaderStack->pop(); fCurEntity = fEntityStack->pop(); } }
template <class TVal> const RefHash3KeysTableBucketElem<TVal>* RefHash3KeysIdPool<TVal>:: findBucketElem(const void* const key1, const int key2, const int key3, unsigned int& hashVal) const { // Hash the key hashVal = fHash->getHashVal(key1, fHashModulus); if (hashVal > fHashModulus) ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::HshTbl_BadHashFromKey, fMemoryManager); // Search that bucket for the key const RefHash3KeysTableBucketElem<TVal>* curElem = fBucketList[hashVal]; while (curElem) { if (fHash->equals(key1, curElem->fKey1) && (key2==curElem->fKey2) && (key3==curElem->fKey3)) return curElem; curElem = curElem->fNext; } return 0; }
// --------------------------------------------------------------------------- // ValueHashTableOf: Private methods // --------------------------------------------------------------------------- template <class TVal> ValueHashTableBucketElem<TVal>* ValueHashTableOf<TVal>:: findBucketElem(const void* const key, unsigned int& hashVal) { // Hash the key hashVal = fHash->getHashVal(key, fHashModulus, fMemoryManager); if (hashVal > fHashModulus) ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::HshTbl_BadHashFromKey, fMemoryManager); // Search that bucket for the key ValueHashTableBucketElem<TVal>* curElem = fBucketList[hashVal]; while (curElem) { if (fHash->equals(key, curElem->fKey)) return curElem; curElem = curElem->fNext; } return 0; }
// --------------------------------------------------------------------------- // RefHashTableOfEnumerator: Constructors and Destructor // --------------------------------------------------------------------------- template <class TVal, class THasher> RefHashTableOfEnumerator<TVal, THasher>:: RefHashTableOfEnumerator(RefHashTableOf<TVal, THasher>* const toEnum , const bool adopt , MemoryManager* const manager) : fAdopted(adopt), fCurElem(0), fCurHash((XMLSize_t)-1), fToEnum(toEnum) , fMemoryManager(manager) { if (!toEnum) ThrowXMLwithMemMgr(NullPointerException, XMLExcepts::CPtr_PointerIsZero, fMemoryManager); // // Find the next available bucket element in the hash table. If it // comes back zero, that just means the table is empty. // // Note that the -1 in the current hash tells it to start // from the beginning. // findNext(); }
// // Grow the table to the next larger size. // It has gotten too full for efficient operation. // (We never fill it all the way) // void NodeIDMap::growTable() { AttrImpl **oldTable = fTable; unsigned int oldSize = fSize; // // Figure the new table size. // #if defined(XERCES_DEBUG) fprintf(stderr, "growing...\n"); #endif fSizeIndex++; fSize = gPrimes[fSizeIndex]; if (fSize == 0) { // We need to grow bigger than the largest available size. // Big trouble. fSizeIndex--; ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::NodeIDMap_GrowErr, fMemoryManager); } // // Allocate the new table. // fTable = (AttrImpl**) fMemoryManager->allocate(fSize * sizeof(AttrImpl*));//new AttrImpl *[fSize]; unsigned int i; for (i=0; i<fSize; i++) fTable[i] = 0; fMaxEntries = (unsigned long)(float(fSize) * gMaxFill); // // Move entries over from the old table to the new one. // for (i=0; i<oldSize; i++) { if ((oldTable[i] != 0) && (oldTable[i] != (AttrImpl *)-1)) add(oldTable[i]); } fMemoryManager->deallocate(oldTable);//delete [] oldTable; };
template <class TElem> void ValueVectorOf<TElem>:: removeElementAt(const unsigned int removeAt) { if (removeAt >= fCurCount) ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Vector_BadIndex, fMemoryManager); if (removeAt == fCurCount-1) { fCurCount--; return; } // Copy down every element above remove point for (unsigned int index = removeAt; index < fCurCount-1; index++) fElemList[index] = fElemList[index+1]; // And bump down count fCurCount--; }
template <class TVal> void RefHash3KeysIdPoolEnumerator<TVal>::nextElementKey(void*& retKey1, int& retKey2, int& retKey3) { // Make sure we have an element to return if (!hasMoreKeys()) ThrowXMLwithMemMgr(NoSuchElementException, XMLExcepts::Enum_NoMoreElements, fMemoryManager); // // Save the current element, then move up to the next one for the // next time around. // RefHash3KeysTableBucketElem<TVal>* saveElem = fCurElem; findNext(); retKey1 = saveElem->fKey1; retKey2 = saveElem->fKey2; retKey3 = saveElem->fKey3; return; }
XMLInt32 ParserForXMLSchema::decodeEscaped() { // XML Schema doesn't support an escaped "$" if (getState() != REGX_T_BACKSOLIDUS) ThrowXMLwithMemMgr(ParseException,XMLExcepts::Parser_Next1, getMemoryManager()); XMLInt32 ch = getCharData(); switch (ch) { case chLatin_n: ch = chLF; break; case chLatin_r: ch = chCR; break; case chLatin_t: ch = chHTab; break; case chBackSlash: case chPipe: case chPeriod: case chCaret: case chDash: case chQuestion: case chAsterisk: case chPlus: case chOpenCurly: case chCloseCurly: case chOpenParen: case chCloseParen: case chOpenSquare: case chCloseSquare: break; default: { XMLCh chString[] = {chBackSlash, (XMLCh)ch, chNull}; ThrowXMLwithMemMgr1(ParseException,XMLExcepts::Parser_Process2, chString, getMemoryManager()); } } return ch; }
XMLInt32 RegxParser::decodeEscaped() { if (fState != REGX_T_BACKSOLIDUS) ThrowXMLwithMemMgr(ParseException,XMLExcepts::Parser_Next1, getMemoryManager()); XMLInt32 ch = fCharData; switch (ch) { case chLatin_n: ch = chLF; break; case chLatin_r: ch = chCR; break; case chLatin_t: ch = chHTab; break; case chBackSlash: case chPipe: case chPeriod: case chCaret: case chDash: case chQuestion: case chAsterisk: case chPlus: case chOpenCurly: case chCloseCurly: case chOpenParen: case chCloseParen: case chOpenSquare: case chCloseSquare: case chDollarSign: break; default: { XMLCh chString[] = {chBackSlash, ch, chNull}; ThrowXMLwithMemMgr1(ParseException,XMLExcepts::Parser_Process2, chString, getMemoryManager()); } } return ch; }
UnionDatatypeValidator::UnionDatatypeValidator( RefVectorOf<DatatypeValidator>* const memberTypeValidators , const int finalSet , MemoryManager* const manager) :DatatypeValidator(0, 0, finalSet, DatatypeValidator::Union, manager) ,fEnumerationInherited(false) ,fMemberTypesInherited(false) ,fEnumeration(0) ,fMemberTypeValidators(0) ,fValidatedDatatype(0) { if ( !memberTypeValidators ) { ThrowXMLwithMemMgr(InvalidDatatypeFacetException , XMLExcepts::FACET_Union_Null_memberTypeValidators, manager); } // no pattern, no enumeration fMemberTypeValidators = memberTypeValidators; }
// --------------------------------------------------------------------------- // XMLPlatformUtils: NEL Character Handling // --------------------------------------------------------------------------- void XMLPlatformUtils::recognizeNEL(bool state, MemoryManager* const manager) { //Make sure initialize has been called if (gInitFlag == 0) { return; } if (state) { if (!XMLChar1_0::isNELRecognized()) { XMLChar1_0::enableNELWS(); } } else { if (XMLChar1_0::isNELRecognized()) { ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::NEL_RepeatedCalls, manager); } } }
XERCES_CPP_NAMESPACE_BEGIN // --------------------------------------------------------------------------- // CMBinaryOp: Constructors // --------------------------------------------------------------------------- CMBinaryOp::CMBinaryOp( const ContentSpecNode::NodeTypes type , CMNode* const leftToAdopt , CMNode* const rightToAdopt , MemoryManager* const manager) : CMNode(type, manager) , fLeftChild(leftToAdopt) , fRightChild(rightToAdopt) { // Insure that its one of the types we require if (((type & 0x0f) != ContentSpecNode::Choice) && ((type & 0x0f) != ContentSpecNode::Sequence)) { ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::CM_BinOpHadUnaryType, manager); } }
// --------------------------------------------------------------------------- // XMLPlatformUtils: File system methods // --------------------------------------------------------------------------- XMLCh* XMLPlatformUtils::getFullPath(const XMLCh* const srcPath, MemoryManager* const manager) { // // NOTE: The path provided has always already been opened successfully, // so we know that its not some pathological freaky path. It comes in // in native format, and goes out as Unicode always // char* newSrc = XMLString::transcode(srcPath, manager); ArrayJanitor<char> janText(newSrc, manager); // Use a local buffer that is big enough for the largest legal path char posix_name[PATH_MAX + 1]; // get the absolute path if (0 != cygwin_conv_to_full_posix_path(newSrc, posix_name)) { ThrowXMLwithMemMgr(XMLPlatformUtilsException, XMLExcepts::File_CouldNotGetBasePathName, manager); } return XMLString::transcode(posix_name, manager); }
// --------------------------------------------------------------------------- // XMLPlatformUtils: File system methods // --------------------------------------------------------------------------- XMLCh* XMLPlatformUtils::getFullPath(const XMLCh* const srcPath, MemoryManager* const manager) { // // NOTE: THe path provided has always already been opened successfully, // so we know that its not some pathological freaky path. It comes in // in native format, and goes out as Unicode always // char* newSrc = XMLString::transcode(srcPath, manager); ArrayJanitor<char> janText(newSrc, manager); char absPath[PATH_MAX + 1]; char* retPath = realpath(newSrc, &absPath[0]); if (!retPath) { ThrowXMLwithMemMgr(XMLPlatformUtilsException, XMLExcepts::File_CouldNotGetBasePathName, manager); } return XMLString::transcode(absPath, manager); }
void SAXParser::parse(const char* const systemId) { // Avoid multiple entrance if (fParseInProgress) ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager); ResetInProgressType resetInProgress(this, &SAXParser::resetInProgress); try { fParseInProgress = true; fScanner->scanDocument(systemId); } catch(const OutOfMemoryException&) { resetInProgress.release(); throw; } }
const NameIdPoolBucketElem<TElem>* NameIdPool<TElem>:: findBucketElem(const XMLCh* const key, unsigned int& hashVal) const { // Hash the key hashVal = XMLString::hash(key, fHashModulus, fMemoryManager); if (hashVal > fHashModulus) ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Pool_BadHashFromKey, fMemoryManager); // Search that bucket for the key const NameIdPoolBucketElem<TElem>* curElem = fBucketList[hashVal]; while (curElem) { if (XMLString::equals(key, curElem->fData->getKey())) return curElem; curElem = curElem->fNext; } return 0; }
void XMLPlatformUtils::closeMutex(void* const mtxHandle) { if (mtxHandle != NULL) { MutexHolderType* const holder = MutexHolderType::castTo(mtxHandle); if (pthread_mutex_destroy(&holder->fInstance)) { delete holder; ThrowXMLwithMemMgr( XMLPlatformUtilsException, XMLExcepts::Mutex_CouldNotDestroy, fgMemoryManager); } delete holder; } }
// --------------------------------------------------------------------------- // TranscodeToStr: Private helper methods // --------------------------------------------------------------------------- void TranscodeToStr::transcode(const XMLCh *in, XMLSize_t len, XMLTranscoder* trans) { if(!in) return; XMLSize_t allocSize = len * sizeof(XMLCh); fString = (XMLByte*)fMemoryManager->allocate(allocSize); XMLSize_t charsRead = 0; XMLSize_t charsDone = 0; while(true) { fBytesWritten += trans->transcodeTo(in + charsDone, len - charsDone, fString + fBytesWritten, allocSize - fBytesWritten, charsRead, XMLTranscoder::UnRep_Throw); if(charsRead == 0) ThrowXMLwithMemMgr(TranscodingException, XMLExcepts::Trans_BadSrcSeq, fMemoryManager); charsDone += charsRead; if(charsDone == len) break; allocSize *= 2; XMLByte *newBuf = (XMLByte*)fMemoryManager->allocate(allocSize); memcpy(newBuf, fString, fBytesWritten); fMemoryManager->deallocate(fString); fString = newBuf; } // null terminate if((fBytesWritten + 4) > allocSize) { allocSize = fBytesWritten + 4; XMLByte *newBuf = (XMLByte*)fMemoryManager->allocate(allocSize); memcpy(newBuf, fString, fBytesWritten); fMemoryManager->deallocate(fString); fString = newBuf; } fString[fBytesWritten + 0] = 0; fString[fBytesWritten + 1] = 0; fString[fBytesWritten + 2] = 0; fString[fBytesWritten + 3] = 0; }
template <class TElem> void ValueVectorOf<TElem>:: insertElementAt(const TElem& toInsert, const unsigned int insertAt) { if (insertAt == fCurCount) { addElement(toInsert); return; } if (insertAt > fCurCount) ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Vector_BadIndex, fMemoryManager); // Make room for the newbie ensureExtraCapacity(1); for (unsigned int index = fCurCount; index > insertAt; index--) fElemList[index] = fElemList[index-1]; // And stick it in and bump the count fElemList[insertAt] = toInsert; fCurCount++; }
CMStateSet& operator=(const CMStateSet& srcSet) { if (this == &srcSet) return *this; // They have to be the same size if (fBitCount != srcSet.fBitCount) ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Bitset_NotEqualSize, fMemoryManager); if (fBitCount < 65) { fBits1 = srcSet.fBits1; fBits2 = srcSet.fBits2; } else { for (unsigned int index = 0; index < fByteCount; index++) fByteArray[index] = srcSet.fByteArray[index]; } return *this; }
ListDatatypeValidator::ListDatatypeValidator( DatatypeValidator* const baseValidator , RefHashTableOf<KVStringPair>* const facets , RefArrayVectorOf<XMLCh>* const enums , const int finalSet , MemoryManager* const manager) :AbstractStringValidator(baseValidator, facets, finalSet, DatatypeValidator::List, manager) ,fContent(0) { // // baseValidator shall either // an atomic DTV which servers as itemType, or // another ListDTV from which, this ListDTV is derived by restriction. // // In either case, it shall be not null // if (!baseValidator) ThrowXMLwithMemMgr(InvalidDatatypeFacetException, XMLExcepts::FACET_List_Null_baseValidator, manager); init(enums, manager); }
bool getBit(const unsigned int bitToGet) const { if (bitToGet >= fBitCount) ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Bitset_BadIndex, fMemoryManager); if (fBitCount < 65) { unsigned int mask = (0x1UL << (bitToGet % 32)); if (bitToGet < 32) return ((fBits1 & mask) != 0); else return ((fBits2 & mask) != 0); } // Create the mask and byte values const XMLByte mask1 = XMLByte(0x1 << (bitToGet % 8)); const unsigned int byteOfs = bitToGet >> 3; // And access the right bit and byte return ((fByteArray[byteOfs] & mask1) != 0); }
BinInputStream* SocketNetAccessor::makeNew(const XMLURL& urlSource, const XMLNetHTTPInfo* httpInfo/*=0*/) { XMLURL::Protocols protocol = urlSource.getProtocol(); switch(protocol) { case XMLURL::HTTP: { UnixHTTPURLInputStream* retStrm = new (urlSource.getMemoryManager()) UnixHTTPURLInputStream(urlSource, httpInfo); return retStrm; } // // These are the only protocols we support now. So throw and // unsupported protocol exception for the others. // default : ThrowXMLwithMemMgr(MalformedURLException, XMLExcepts::URL_UnsupportedProto, urlSource.getMemoryManager()); break; } return 0; }
void SAXParser::parse(const char* const systemId) { // Avoid multiple entrance if (fParseInProgress) ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager); try { fParseInProgress = true; fScanner->scanDocument(systemId); fParseInProgress = false; } catch(const OutOfMemoryException&) { throw; } catch (...) { fParseInProgress = false; throw; } }
// --------------------------------------------------------------------------- // NamespaceScope: Prefix map methods // --------------------------------------------------------------------------- void NamespaceScope::addPrefix(const XMLCh* const prefixToAdd, const unsigned int uriId) { if (!fStackTop) ThrowXMLwithMemMgr(EmptyStackException, XMLExcepts::ElemStack_EmptyStack, fMemoryManager); // Get a convenience pointer to the stack top row StackElem* curRow = fStack[fStackTop - 1]; // Map the prefix to its unique id const unsigned int prefId = fPrefixPool.addOrFind(prefixToAdd); // Search the map at this level for the passed prefix for (unsigned int mapIndex = 0; mapIndex < curRow->fMapCount; mapIndex++) { if (curRow->fMap[mapIndex].fPrefId == prefId) { curRow->fMap[mapIndex].fURIId = uriId; return; } } // // Add a new element to the prefix map for this element. If its full, // then expand it out. // if (curRow->fMapCount == curRow->fMapCapacity) expandMap(curRow); // // And now add a new element for this prefix. // curRow->fMap[curRow->fMapCount].fPrefId = prefId; curRow->fMap[curRow->fMapCount].fURIId = uriId; // Bump the map count now curRow->fMapCount++; }
// --------------------------------------------------------------------------- // XPathScannerForSchema: Helper methods // --------------------------------------------------------------------------- void XPathScannerForSchema::addToken(ValueVectorOf<int>* const tokens, const int aToken) { if (aToken == XercesXPath::EXPRTOKEN_ATSIGN || aToken == XercesXPath::EXPRTOKEN_AXISNAME_ATTRIBUTE || aToken == XercesXPath::EXPRTOKEN_AXISNAME_CHILD || //token == XercesXPath::EXPRTOKEN_AXISNAME_SELF || aToken == XercesXPath::EXPRTOKEN_DOUBLE_COLON || aToken == XercesXPath::EXPRTOKEN_NAMETEST_QNAME || //token == XercesXPath::EXPRTOKEN_NODETYPE_NODE || aToken == XercesXPath::EXPRTOKEN_OPERATOR_SLASH || aToken == XercesXPath::EXPRTOKEN_PERIOD || aToken == XercesXPath::EXPRTOKEN_NAMETEST_ANY || aToken == XercesXPath::EXPRTOKEN_NAMETEST_NAMESPACE || aToken == XercesXPath::EXPRTOKEN_OPERATOR_DOUBLE_SLASH || aToken == XercesXPath::EXPRTOKEN_OPERATOR_UNION) { tokens->addElement(aToken); return; } ThrowXMLwithMemMgr(XPathException, XMLExcepts::XPath_TokenNotSupported, tokens->getMemoryManager()); }
void XMLAbstractDoubleFloat::init(const XMLCh* const strValue) { if ((!strValue) || (!*strValue)) ThrowXMLwithMemMgr(NumberFormatException, XMLExcepts::XMLNUM_emptyString, fMemoryManager); fRawData = XMLString::replicate(strValue, fMemoryManager); // preserve the raw data form XMLCh* tmpStrValue = XMLString::replicate(strValue, fMemoryManager); ArrayJanitor<XMLCh> janTmpName(tmpStrValue, fMemoryManager); XMLString::trim(tmpStrValue); normalizeZero(tmpStrValue); if (XMLString::equals(tmpStrValue, XMLUni::fgNegINFString) ) { fType = NegINF; fSign = -1; } else if (XMLString::equals(tmpStrValue, XMLUni::fgPosINFString) ) { fType = PosINF; fSign = 1; } else if (XMLString::equals(tmpStrValue, XMLUni::fgNaNString) ) { fType = NaN; fSign = 1; } else // // Normal case // { checkBoundary(tmpStrValue); } }
XERCES_CPP_NAMESPACE_BEGIN // --------------------------------------------------------------------------- // CMUnaryOp: Constructors and Destructor // --------------------------------------------------------------------------- CMUnaryOp::CMUnaryOp( ContentSpecNode::NodeTypes type , CMNode* const nodeToAdopt , unsigned int maxStates , MemoryManager* const manager) : CMNode(type, maxStates, manager) , fChild(nodeToAdopt) { // Insure that its one of the types we require if ((type != ContentSpecNode::ZeroOrOne) && (type != ContentSpecNode::ZeroOrMore) && (type != ContentSpecNode::OneOrMore)) { ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::CM_UnaryOpHadBinType, manager); } if (type == ContentSpecNode::OneOrMore) fIsNullable=fChild->isNullable(); else fIsNullable=true; }