int ListDatatypeValidator::compare(const XMLCh* const lValue , const XMLCh* const rValue , MemoryManager* const manager) { DatatypeValidator* theItemTypeDTV = getItemTypeDTV(); BaseRefVectorOf<XMLCh>* lVector = XMLString::tokenizeString(lValue, manager); Janitor<BaseRefVectorOf<XMLCh> > janl(lVector); BaseRefVectorOf<XMLCh>* rVector = XMLString::tokenizeString(rValue, manager); Janitor<BaseRefVectorOf<XMLCh> > janr(rVector); int lNumberOfTokens = lVector->size(); int rNumberOfTokens = rVector->size(); if (lNumberOfTokens < rNumberOfTokens) return -1; else if (lNumberOfTokens > rNumberOfTokens) return 1; else { //compare each token for ( int i = 0; i < lNumberOfTokens; i++) { int returnValue = theItemTypeDTV->compare(lVector->elementAt(i), rVector->elementAt(i), manager); if (returnValue != 0) return returnValue; //REVISIT: does it make sense to return -1 or +1..? } return 0; } }
bool gss_eap_saml_attr_provider::getAttribute(const gss_buffer_t attr, int *authenticated, int *complete, const saml2::Attribute **pAttribute) const { saml2::Assertion *assertion; if (authenticated != NULL) *authenticated = false; if (complete != NULL) *complete = true; *pAttribute = NULL; if (!getAssertion(authenticated, &assertion) || assertion->getAttributeStatements().size() == 0) return false; /* Check the attribute name consists of name format | whsp | name */ BaseRefVectorOf<XMLCh> *components = decomposeAttributeName(attr); if (components == NULL) return false; /* For each attribute statement, look for an attribute match */ const vector <saml2::AttributeStatement *> &statements = const_cast<const saml2::Assertion *>(assertion)->getAttributeStatements(); const saml2::Attribute *ret = NULL; for (vector<saml2::AttributeStatement *>::const_iterator s = statements.begin(); s != statements.end(); ++s) { const vector<saml2::Attribute *> &attrs = const_cast<const saml2::AttributeStatement*>(*s)->getAttributes(); for (vector<saml2::Attribute *>::const_iterator a = attrs.begin(); a != attrs.end(); ++a) { const XMLCh *attributeName, *attributeNameFormat; attributeName = (*a)->getName(); attributeNameFormat = (*a)->getNameFormat(); if (attributeNameFormat == NULL || attributeNameFormat[0] == '\0') attributeNameFormat = saml2::Attribute::UNSPECIFIED; if (XMLString::equals(attributeNameFormat, components->elementAt(0)) && XMLString::equals(attributeName, components->elementAt(1))) { ret = *a; break; } } if (ret != NULL) break; } delete components; *pAttribute = ret; return (ret != NULL); }
void XMLStringUtil::Space2Hex(XMLCh* const str) { XMLCh hexVal[4] = {chPercent,chDigit_2,chDigit_0,chNull}; XMLCh tempBuf[512]; XMLString::copyString(tempBuf,str); BaseRefVectorOf<XMLCh>* parts = XMLString::tokenizeString(tempBuf); Janitor<BaseRefVectorOf<XMLCh> > jan(parts); if (parts->size()) { XMLString::copyString(str,parts->elementAt(0)); for(size_t i=1,is=parts->size();i<is;++i) { XMLString::catString(str,hexVal); XMLString::catString(str,parts->elementAt(i)); } } }
bool gss_eap_saml_attr_provider::deleteAttribute(const gss_buffer_t attr) { saml2::Assertion *assertion; bool ret = false; if (!getAssertion(NULL, &assertion) || assertion->getAttributeStatements().size() == 0) return false; /* Check the attribute name consists of name format | whsp | name */ BaseRefVectorOf<XMLCh> *components = decomposeAttributeName(attr); if (components == NULL) return false; /* For each attribute statement, look for an attribute match */ const vector<saml2::AttributeStatement *> &statements = const_cast<const saml2::Assertion *>(assertion)->getAttributeStatements(); for (vector<saml2::AttributeStatement *>::const_iterator s = statements.begin(); s != statements.end(); ++s) { const vector<saml2::Attribute *> &attrs = const_cast<const saml2::AttributeStatement *>(*s)->getAttributes(); ssize_t index = -1, i = 0; /* There's got to be an easier way to do this */ for (vector<saml2::Attribute *>::const_iterator a = attrs.begin(); a != attrs.end(); ++a) { if (XMLString::equals((*a)->getNameFormat(), components->elementAt(0)) && XMLString::equals((*a)->getName(), components->elementAt(1))) { index = i; break; } ++i; } if (index != -1) { (*s)->getAttributes().erase((*s)->getAttributes().begin() + index); ret = true; } } delete components; return ret; }
void ListDatatypeValidator::inspectFacetBase(MemoryManager* const manager) { // // we are pretty sure baseValidator is not null // if (getBaseValidator()->getType() == DatatypeValidator::List) { AbstractStringValidator::inspectFacetBase(manager); } else { // the first level ListDTV // check 4.3.5.c0 must: enumeration values from the value space of base if ( ((getFacetsDefined() & DatatypeValidator::FACET_ENUMERATION) != 0) && (getEnumeration() !=0) ) { int i; int enumLength = getEnumeration()->size(); try { for ( i = 0; i < enumLength; i++) { // ask the itemType for a complete check BaseRefVectorOf<XMLCh>* tempList = XMLString::tokenizeString(getEnumeration()->elementAt(i), manager); Janitor<BaseRefVectorOf<XMLCh> > jan(tempList); int tokenNumber = tempList->size(); try { for ( int j = 0; j < tokenNumber; j++) getBaseValidator()->validate(tempList->elementAt(j), (ValidationContext*)0, manager); } catch(const OutOfMemoryException&) { jan.release(); throw; } // enum shall pass this->checkContent() as well. checkContent(getEnumeration()->elementAt(i), (ValidationContext*)0, false, manager); } } catch ( XMLException& ) { ThrowXMLwithMemMgr1(InvalidDatatypeFacetException , XMLExcepts::FACET_enum_base , getEnumeration()->elementAt(i) , manager); } } } }// End of inspectFacetBase()
std::vector<XMLCh*> XMLStringUtil::Tokenise(const XMLCh* const str) { BaseRefVectorOf<XMLCh>* parts = XMLString::tokenizeString(str); std::vector<XMLCh*> partsVec(parts->size()); for(size_t i=0,is=parts->size();i<is;++i) { partsVec[i] = parts->elementAt(i); } return partsVec; }
bool gss_eap_saml_attr_provider::setAttribute(int complete GSSEAP_UNUSED, const gss_buffer_t attr, const gss_buffer_t value) { saml2::Assertion *assertion; saml2::Attribute *attribute; saml2::AttributeValue *attributeValue; saml2::AttributeStatement *attributeStatement; if (!getAssertion(NULL, &assertion, true)) return false; if (assertion->getAttributeStatements().size() != 0) { attributeStatement = assertion->getAttributeStatements().front(); } else { attributeStatement = saml2::AttributeStatementBuilder::buildAttributeStatement(); assertion->getAttributeStatements().push_back(attributeStatement); } /* Check the attribute name consists of name format | whsp | name */ BaseRefVectorOf<XMLCh> *components = decomposeAttributeName(attr); if (components == NULL) return false; attribute = saml2::AttributeBuilder::buildAttribute(); attribute->setNameFormat(components->elementAt(0)); attribute->setName(components->elementAt(1)); attributeValue = saml2::AttributeValueBuilder::buildAttributeValue(); auto_ptr_XMLCh unistr((char *)value->value, value->length); attributeValue->setTextContent(unistr.get()); attribute->getAttributeValues().push_back(attributeValue); GSSEAP_ASSERT(attributeStatement != NULL); attributeStatement->getAttributes().push_back(attribute); delete components; return true; }
void ParamElement::ReadValue(const DOMNode* node) { _ASSERTE(node != NULL); DOMNode* value = node->getFirstChild(); if( value == NULL ) { return; } BaseRefVectorOf<XMLCh>* vecValue = XMLString::tokenizeString( value->getNodeValue() ); unsigned int sizeValue = vecValue->size(); if( sizeValue == 0 ) { return; } if( IsFloatType() ) { valFloat.reserve( sizeValue ); for( unsigned int i = 0; i < sizeValue; i++ ) { valFloat.push_back( XMLChToFloat( vecValue->elementAt( i ) ) ); } } else if( IsBoolType() ) { valBool.reserve( sizeValue ); for( unsigned int i = 0; i < sizeValue; i++ ) { valBool.push_back( XMLChToBool( vecValue->elementAt( i ) ) ); } } else if( IsBlendType() ) { // 未実装 } else if( IsFunctionType() ) { // 未実装 } else { _ASSERTE(!"UnknownType"); } SAFE_DELETE(vecValue); }
bool ListDatatypeValidator::valueSpaceCheck(BaseRefVectorOf<XMLCh>* tokenVector , const XMLCh* const enumStr , MemoryManager* const manager) const { DatatypeValidator* theItemTypeDTV = getItemTypeDTV(); BaseRefVectorOf<XMLCh>* enumVector = XMLString::tokenizeString(enumStr, manager); Janitor<BaseRefVectorOf<XMLCh> > janName(enumVector); if (tokenVector->size() != enumVector->size()) return false; for ( unsigned int j = 0; j < tokenVector->size(); j++ ) { if (theItemTypeDTV->compare(tokenVector->elementAt(j), enumVector->elementAt(j), manager) != 0) return false; } return true; }
void BaseValue::ReadValue(const DOMNode* node) { _ASSERTE(node != NULL); DOMNode* value = node->getFirstChild(); if( value == NULL ) { return; } BaseRefVectorOf<XMLCh>* vecValue = XMLString::tokenizeString( value->getNodeValue() ); unsigned int sizeValue = vecValue->size(); if( sizeValue == 0 ) { return; } valParam.reserve( sizeValue ); for( unsigned int i = 0; i < sizeValue; i++ ) { valParam.push_back( XMLChToFloat( vecValue->elementAt( i ) ) ); } SAFE_DELETE(vecValue); }
/*** * 2.5.1.2 List datatypes * * The canonical-lexical-representation for the ·list· datatype is defined as * the lexical form in which each item in the ·list· has the canonical * lexical representation of its ·itemType·. ***/ const XMLCh* ListDatatypeValidator::getCanonicalRepresentation(const XMLCh* const rawData , MemoryManager* const memMgr , bool toValidate) const { MemoryManager* toUse = memMgr? memMgr : getMemoryManager(); ListDatatypeValidator* temp = (ListDatatypeValidator*) this; temp->setContent(rawData); BaseRefVectorOf<XMLCh>* tokenVector = XMLString::tokenizeString(rawData, toUse); Janitor<BaseRefVectorOf<XMLCh> > janName(tokenVector); if (toValidate) { try { temp->checkContent(tokenVector, rawData, 0, false, toUse); } catch (...) { return 0; } } unsigned int retBufSize = 2 * XMLString::stringLen(rawData); XMLCh* retBuf = (XMLCh*) toUse->allocate(retBufSize * sizeof(XMLCh)); retBuf[0] = 0; XMLCh* retBufPtr = retBuf; DatatypeValidator* itemDv = this->getItemTypeDTV(); try { for (unsigned int i = 0; i < tokenVector->size(); i++) { XMLCh* itemCanRep = (XMLCh*) itemDv->getCanonicalRepresentation(tokenVector->elementAt(i), toUse, false); unsigned int itemLen = XMLString::stringLen(itemCanRep); if(retBufPtr+itemLen+2 >= retBuf+retBufSize) { // need to resize XMLCh * oldBuf = retBuf; retBuf = (XMLCh*) toUse->allocate(retBufSize * sizeof(XMLCh) * 4); memcpy(retBuf, oldBuf, retBufSize * sizeof(XMLCh )); retBufPtr = (retBufPtr - oldBuf) + retBuf; toUse->deallocate(oldBuf); retBufSize <<= 2; } XMLString::catString(retBufPtr, itemCanRep); retBufPtr = retBufPtr + itemLen + 1; *(retBufPtr++) = chSpace; *(retBufPtr) = chNull; toUse->deallocate(itemCanRep); } return retBuf; } catch (...) { return 0; } }