void MovieClip::setupFrame(const TagList& tags, bool skipAction) { TagList::const_iterator it = tags.begin(); while( it != tags.end() ) { ITag* tag = *it; tag->setup(*this, skipAction); ++it; } }
void CDataIO::WriteTagList(const TagList& tagList) { uint32 uCount = (uint32)tagList.size(); ASSERT( uCount <= 0xFF ); WriteByte((uint8)uCount); for (TagList::const_iterator itTagList = tagList.begin(); itTagList != tagList.end(); ++itTagList) WriteTag(*itTagList); }
void CDataIO::writeTagList(const TagList& tagList) { uint32 count = (uint32)tagList.size(); ASSERT( count <= 0xFF ); writeByte(count); TagList::const_iterator it; for (it = tagList.begin(); it != tagList.end(); it++) writeTag(*it); }
// Get only the tags from the PSF TagList GetTagsFromPSF(PseudoReadFile &file, uint8_t versionByte) { // Check to make sure the file is valid CheckForValidPSF(file, versionByte); TagList tags; // Get the starting offset of the tags char TagHeader[] = "[TAG]"; auto TagHeaderVector = std::vector<uint8_t>(TagHeader, TagHeader + 5); int32_t TagOffset = file.GetNextOffset(0, TagHeaderVector); // Only continue on if we have tags if (TagOffset != -1) { file.pos = TagOffset + 5; std::string name, value; bool onName = true; size_t lengthOfTags = file.data->size() - file.pos; for (size_t x = 0; x < lengthOfTags; ++x) { char curr = file.ReadLE<uint8_t>(); if (curr == 0x0A) { if (!name.empty() && !value.empty()) { name = TrimWhitespace(name); value = TrimWhitespace(value); if (tags.Exists(name)) tags[name] += "\n" + value; else tags[name] = value; } name = value = ""; onName = true; continue; } if (curr == '=') { onName = false; continue; } if (onName) name += curr; else value += curr; } } return tags; }
QByteArray FlatTextarea::serializeTagsList(const TagList &tags) { if (tags.isEmpty()) { return QByteArray(); } QByteArray tagsSerialized; { QBuffer buffer(&tagsSerialized); buffer.open(QIODevice::WriteOnly); QDataStream stream(&buffer); stream.setVersion(QDataStream::Qt_5_1); stream << qint32(tags.size()); for_const (auto &tag, tags) { stream << qint32(tag.offset) << qint32(tag.length) << tag.id; } }
MtlBlinnSW3D::MtlBlinnSW3D(const Registry *reg, const ScriptVal &table, const TagList &tags) : BaseClass(reg, table, tags) { MtlBlinnData3D *mtlData = (MtlBlinnData3D *) tags.GetPtr(MTL_MaterialData, NULL); RenderContextSW3D &rc = *((RenderContextSW3D *) tags.GetPtr(MTL_RenderContext, NULL)); DiffuseMtl = CreateChildMtl(rc, MtlBlinnData3D::CMS_Diffuse); if (rc.DoLighting) { SpecularMtl = CreateChildMtl(rc, MtlBlinnData3D::CMS_Specular); SpecularIntensityMtl = CreateChildMtl(rc, MtlBlinnData3D::CMS_SpecularIntensity); SpecularExponentMtl = CreateChildMtl(rc, MtlBlinnData3D::CMS_SpecularExponent); BumpmapMtl = CreateChildMtl(rc, MtlBlinnData3D::CMS_Bumpmap); SpecularIntensity = mtlData->SpecularIntensity; SpecularExponent = mtlData->SpecularExponent; PreSpecular = mtlData->Specular * mtlData->SpecularIntensity; Specular = mtlData->Specular * mtlData->Opacity/* * mtlData->SpecularIntensity*/; } else { SpecularMtl = NULL; SpecularIntensityMtl = NULL; SpecularExponentMtl = NULL; BumpmapMtl = NULL; } Diffuse = mtlData->Diffuse * mtlData->Opacity; TransmittanceMtl = NULL; PreDiffuse = mtlData->Diffuse; Transmittance = mtlData->Transmittance; Saturation = mtlData->Saturation; AlphaDetail = mtlData->AlphaDetail; ColorDetail = mtlData->ColorDetail; ShadeFunc = (ShadeFunc3D) &MtlBlinnSW3D::ShadeFragment; }
void BooksUtil::collectTagsFromLibrary(TagList &tags) { const TagList &lTags = Library::Instance().tags(); TagSet tagSet; for (TagList::const_iterator it = lTags.begin(); it != lTags.end(); ++it) { shared_ptr<Tag> tag = *it; if (tag.isNull()) { tagSet.insert(tag); tags.push_back(tag); } else { TagList tagStack; do { tagStack.push_back(tag); tag = tag->parent(); } while (!tag.isNull() && tagSet.find(tag) == tagSet.end()); tagSet.insert(tagStack.begin(), tagStack.end()); tags.insert(tags.end(), tagStack.rbegin(), tagStack.rend()); } } }
int main( int /*argc*/, char** /*argv*/ ) { int fail = 0; std::string name; Tag *t = new Tag( "toe" ); t->addAttribute( "foo", "bar" ); Tag *u = new Tag( t, "uni" ); u->addAttribute( "u3", "3u" ); Tag *v = new Tag( t, "vie" ); v->addAttribute( "v3", "3v" ); Tag *v2 = new Tag( t, "vie" ); v->addAttribute( "v32", "3v2" ); Tag *w = new Tag( u, "who" ); w->addAttribute( "w3", "3w" ); Tag *x = new Tag( v, "xep" ); x->addAttribute( "x3", "3x" ); Tag *y = new Tag( u, "yps" ); y->addAttribute( "y3", "3y" ); Tag *z = new Tag( w, "zoo" ); z->addAttribute( "z3", "3z" ); Tag *c = 0; Tag *d = 0; // ------- name = "simple ctor"; if( t->name() != "toe" ) { ++fail; fprintf( stderr, "test '%s' failed\n", name.c_str() ); } // ------- name = "cdata ctor"; c = new Tag( "cod", "foobar" ); if( c->name() != "cod" || c->cdata() != "foobar" ) { ++fail; fprintf( stderr, "test '%s' failed\n", name.c_str() ); } delete c; c = 0; //------- name = "clone test 1"; c = z->clone(); if( *z != *c ) { ++fail; fprintf( stderr, "test '%s' failed\n", name.c_str() ); } delete c; c = 0; //------- name = "clone test 2"; c = t->clone(); if( *t != *c ) { ++fail; fprintf( stderr, "test '%s' failed\n", name.c_str() ); } delete c; c = 0; //------- name = "operator== test 1"; c = new Tag( "name" ); if( *t == *c ) { ++fail; fprintf( stderr, "test '%s' failed\n", name.c_str() ); } delete c; c = 0; //------- name = "operator== test 2"; c = new Tag( "test" ); c->addAttribute( "me", "help" ); c->addChild( new Tag( "yes" ) ); if( *t == *c ) { ++fail; fprintf( stderr, "test '%s' failed\n", name.c_str() ); } delete c; c = 0; //------- name = "operator== test 3"; c = new Tag( "hello" ); c->addAttribute( "test", "bacd" ); c->addChild( new Tag( "hello" ) ); d = new Tag( "hello" ); d->addAttribute( "test", "bacd" ); d->addChild( new Tag( "helloo" ) ); if( *d == *c ) { ++fail; fprintf( stderr, "test '%s' failed\n", name.c_str() ); } delete c; delete d; c = 0; d = 0; //------- name = "operator!= test 1"; c = new Tag( "hello" ); c->addAttribute( "test", "bacd" ); c->addChild( new Tag( "hello" ) ); d = new Tag( "hello" ); d->addAttribute( "test", "bacd" ); d->addChild( new Tag( "hello" ) ); if( *d != *c ) { ++fail; fprintf( stderr, "test '%s' failed\n", name.c_str() ); } delete c; delete d; c = 0; d = 0; //------- name = "findChildren test"; TagList l = t->findChildren( "vie" ); TagList::const_iterator it = l.begin(); if( l.size() != 2 || (*it) != v || *(++it) != v2 ) { ++fail; fprintf( stderr, "test '%s' failed\n", name.c_str() ); } delete c; c = 0; //------- name = "util::escape"; if ( util::escape( "&<>'\"" ) != "&<>'"" ) { ++fail; fprintf( stderr, "test '%s' failed\n", name.c_str() ); } //------- name = "xml() 1"; if( t->xml() != "<toe foo='bar'><uni u3='3u'><who w3='3w'><zoo z3='3z'/></who><yps y3='3y'/>" "</uni><vie v3='3v' v32='3v2'><xep x3='3x'/></vie><vie/></toe>" ) { ++fail; fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() ); } //------- name = "xml() 2"; t->addAttribute( "test", "bacd" ); if( t->xml() != "<toe foo='bar' test='bacd'><uni u3='3u'><who w3='3w'><zoo z3='3z'/></who><yps y3='3y'/>" "</uni><vie v3='3v' v32='3v2'><xep x3='3x'/></vie><vie/></toe>" ) { ++fail; fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() ); } //------- name = "hasChild 1"; if( !t->hasChild( "uni" ) || !t->hasChild( "vie" ) || !u->hasChild( "who" ) || !w->hasChild( "zoo" ) || !u->hasChild( "yps" ) ) { ++fail; fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() ); } //------- name = "hasAttribute 1"; if( !t->hasAttribute( "test" ) || !t->hasAttribute( "test", "bacd" ) || !t->hasAttribute( "foo" ) || !t->hasAttribute( "foo", "bar" ) ) { ++fail; fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() ); } //------- name = "findAttribute 1"; if( t->findAttribute( "test" ) != "bacd" || t->findAttribute( "foo" ) != "bar" ) { ++fail; fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() ); } //------- name = "findChild 1"; c = t->findChild( "uni" ); if( c != u ) { ++fail; fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() ); } //------- name = "findChild 2"; c = t->findChild( "uni", "u3" ); if( c != u ) { ++fail; fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() ); } //------- name = "findChild 3"; c = t->findChild( "uni", "u3", "3u" ); if( c != u ) { ++fail; fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() ); } //------- name = "findChildWithAttrib 1"; c = t->findChildWithAttrib( "u3" ); if( c != u ) { ++fail; fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() ); } //------- name = "findChildWithAttrib 2"; c = t->findChildWithAttrib( "u3", "3u" ); if( c != u ) { ++fail; fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() ); } //------- name = "attribute order"; c = new Tag( "abc" ); c->addAttribute( "abc", "def" ); c->addAttribute( "xyz", "123" ); d = c->clone(); if( *c != *d ) { ++fail; fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), d->xml().c_str() ); } delete c; c = 0; delete d; d = 0; //------- name = "mixed content 1"; c = new Tag( "abc" ); c->addCData( "cdata1" ); new Tag( c, "fgh" ); c->addCData( "cdata2" ); new Tag( c, "xyz" ); c->addCData( "cdata3" ); if( c->xml() != "<abc>cdata1<fgh/>cdata2<xyz/>cdata3</abc>" ) { ++fail; fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), c->xml().c_str() ); } delete c; c = 0; //------- name = "operator bool()"; Tag tag1( "" ); if( tag1 ) { ++fail; fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), tag1.xml().c_str() ); } //------- name = "bool operator!()"; Tag tag2( "abc" ); if( !tag2 ) { ++fail; fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), d->xml().c_str() ); } //------- { name = "simple xmlns"; Tag t( "abc" ); t.setXmlns( "foo" ); if( t.xml() != "<abc xmlns='foo'/>" ) { ++fail; fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t.xml().c_str() ); } } //------- { name = "deep xmlns"; Tag t( "abc" ); Tag* f = new Tag( &t, "def" ); f = new Tag( f, "ghi" ); t.setXmlns( "foo" ); if( t.xml() != "<abc xmlns='foo'><def><ghi/></def></abc>" ) { ++fail; fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t.xml().c_str() ); } } //------- { name = "simple nested xmlns 2"; Tag t( "abc" ); t.setXmlns( "foo" ); Tag* d = new Tag( &t, "def" ); d->setXmlns( "foobar", "xyz" ); d->setPrefix( "xyz" ); if( t.xml() != "<abc xmlns='foo'><xyz:def xmlns:xyz='foobar'/></abc>" ) { ++fail; fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t.xml().c_str() ); } } //------- { name = "attribute with xmlns"; Tag t( "abc" ); t.setXmlns( "foo", "xyz" ); Tag::Attribute* a = new Tag::Attribute( "foo", "bar", "foo" ); a->setPrefix( "xyz" ); t.addAttribute( a ); if( t.xml() != "<abc xmlns:xyz='foo' xyz:foo='bar'/>" ) { ++fail; fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t.xml().c_str() ); } } //------- { name = "escape attribute value"; Tag t( "foo", "abc", "&" ); if( t.xml() != "<foo abc='&amp;'/>" ) { ++fail; fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t.xml().c_str() ); } } //------- { name = "remove child 1"; Tag t( "foo" ); t.addChild( new Tag( "test", "xmlns", "foo" ) ); t.addChild( new Tag( "abc", "xmlns", "foobar" ) ); t.addAttribute( "attr1", "value1" ); t.addAttribute( "attr2", "value2" ); t.removeChild( "test" ); if( t.hasChild( "test" ) ) { ++fail; fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t.xml().c_str() ); } name = "remove child 2"; t.removeChild( "abc", "foobar" ); if( t.hasChild( "abc", "xmlns", "foobar" ) ) { ++fail; fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t.xml().c_str() ); } name = "remove attrib 1"; t.removeAttribute( "attr1" ); if( t.hasAttribute( "attr1", "value1") ) { ++fail; fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t.xml().c_str() ); } name = "remove attrib 2"; t.removeAttribute( "attr2", "value2" ); if( t.hasAttribute( "attr2", "value2") ) { ++fail; fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t.xml().c_str() ); } } //------- { name = "invalid chars 1"; Tag t( "foo" ); bool check = t.addAttribute( "nul", std::string( 1, 0x00 ) ); if( check || t.hasAttribute( "nul" ) ) { ++fail; fprintf( stderr, "test '%s' failed:%s\n", name.c_str(), t.xml().c_str() ); } } //------- { name = "invalid chars 2"; for( int i = 0; i <= 0xff; ++i ) { Tag::Attribute a( "test", std::string( 1, i ) ); if( ( i < 0x09 || i == 0x0b || i == 0x0c || ( i > 0x0d && i < 0x20 ) || i == 0xc0 || i == 0xc1 || i >= 0xf5 ) && a ) { ++fail; fprintf( stderr, "test '%s' (branch 1) failed (i == %02X)\n", name.c_str(), i ); } else if( ( i == 0x09 || i == 0x0a || i == 0x0d || ( i >= 0x20 && i < 0xc0 ) || ( i > 0xc1 && i < 0xf5 ) ) && !a ) { ++fail; fprintf( stderr, "test '%s' (branch 2) failed (i == %02X)\n", name.c_str(), i ); } // printf( "i: 0x%02X, a: %d, value: %s\n", i, (bool)a, std::string( 1, i ).c_str() ); } } delete t; t = 0; if( fail == 0 ) { printf( "Tag: OK\n" ); return 0; } else { fprintf( stderr, "Tag: %d test(s) failed\n", fail ); return 1; } }
int main( int /*argc*/, char** /*argv*/ ) { int fail = 0; std::string name; DataFormField *f; // ------- name = "empty field"; f = new DataFormField(); if( f->type() != DataFormField::TypeTextSingle ) { ++fail; fprintf( stderr, "test '%s' failed\n", name.c_str() ); } delete f; f = 0; // ------- name = "TypeBoolean field"; f = new DataFormField( DataFormField::TypeBoolean ); if( f->type() != DataFormField::TypeBoolean ) { ++fail; fprintf( stderr, "test '%s' failed\n", name.c_str() ); } delete f; f = 0; // ------- name = "2nd ctor"; f = new DataFormField( "fieldName", "fieldValue", "fieldLabel", DataFormField::TypeBoolean ); if( f->type() != DataFormField::TypeBoolean || f->name() != "fieldName" || f->value() != "fieldValue" || f->label() != "fieldLabel" ) { ++fail; fprintf( stderr, "test '%s' failed\n", name.c_str() ); } delete f; f = 0; // ------- name = "parse 0"; f = new DataFormField( 0 ); if( f->type() != DataFormField::TypeInvalid ) { ++fail; fprintf( stderr, "test '%s' failed\n", name.c_str() ); } delete f; f = 0; Tag*t; // ------- name = "set name"; f = new DataFormField(); f->setName( name ); if( f->name() != name ) { ++fail; fprintf( stderr, "test '%s' failed\n", name.c_str() ); } delete f; f = 0; // ------- name = "set required"; f = new DataFormField(); bool req = true; f->setRequired( req ); if( f->required() != req ) { ++fail; fprintf( stderr, "test '%s' failed\n", name.c_str() ); } delete f; f = 0; // ------- name = "set label"; f = new DataFormField(); f->setLabel( name ); if( f->label() != name ) { ++fail; fprintf( stderr, "test '%s' failed\n", name.c_str() ); } delete f; f = 0; // ------- name = "set value"; f = new DataFormField(); f->setValue( name ); if( f->value() != name ) { ++fail; fprintf( stderr, "test '%s' failed\n", name.c_str() ); } delete f; f = 0; // ------- name = "set values"; f = new DataFormField(); StringList val; val.push_back( "val 1" ); val.push_back( "val 2" ); val.push_back( "val 3" ); f->setValues( val ); if( f->values() != val ) { ++fail; fprintf( stderr, "test '%s' failed\n", name.c_str() ); } delete f; f = 0; // ------- name = "set values"; f = new DataFormField(); StringMultiMap opt; opt.insert( std::make_pair( "lock", "1" ) ); opt.insert( std::make_pair( "stock", "1" ) ); opt.insert( std::make_pair( "smoking barrel", "2" ) ); f->setOptions( opt ); if( f->options() != opt ) { ++fail; fprintf( stderr, "test '%s' failed\n", name.c_str() ); } delete f; f = 0; // ------- name = "parse Tag 1"; t = new Tag( "field"); t->addAttribute( "type", "fixed" ); new Tag( t, "value", "abc" ); f = new DataFormField( t ); Tag *ft = f->tag(); if( *ft != *t ) { ++fail; fprintf( stderr, "test '%s' failed\n", name.c_str() ); printf( "f->tag(): %s\n", f->tag()->xml().c_str() ); printf( " t: %s\n", t->xml().c_str() ); } delete f; delete t; delete ft; f = 0; // ------- t = new Tag( "field"); t->addAttribute( "type", "list-multi" ); t->addAttribute( "label", "blabla label" ); t->addAttribute( "var", "features" ); Tag *o = new Tag( t, "option" ); o->addAttribute( "label", "lock" ); new Tag( o, "value", "lock" ); o = new Tag( t, "option" ); o->addAttribute( "label", "stock" ); new Tag( o, "value", "stock" ); o = new Tag( t, "option" ); o->addAttribute( "label", "smoking barrel" ); new Tag( o, "value", "smoking barrel" ); new Tag( t, "value", "lock" ); new Tag( t, "value", "stock" ); f = new DataFormField( t ); Tag *r = f->tag(); name = "parse Tag 2.1"; if( r->name() != "field" || !r->hasAttribute( "type", "list-multi" ) ) { ++fail; fprintf( stderr, "test '%s' failed\n", name.c_str() ); printf( "f->tag(): %s\n", f->tag()->xml().c_str() ); printf( " t: %s\n", t->xml().c_str() ); } name = "parse Tag 2.2"; if( !r->hasAttribute( "label", "blabla label" ) || !r->hasAttribute( "var", "features" ) ) { ++fail; fprintf( stderr, "test '%s' failed\n", name.c_str() ); printf( "f->tag(): %s\n", f->tag()->xml().c_str() ); printf( " t: %s\n", t->xml().c_str() ); } name = "parse Tag 2.3"; if( !r->hasChild( "option" ) || !r->findChild( "option" )->hasAttribute( "label", "lock" ) ) { ++fail; fprintf( stderr, "test '%s' failed\n", name.c_str() ); printf( "f->tag(): %s\n", f->tag()->xml().c_str() ); printf( " t: %s\n", t->xml().c_str() ); } name = "parse Tag 2.4"; if( !r->hasChild( "option", "label", "stock" ) ) { ++fail; fprintf( stderr, "test '%s' failed\n", name.c_str() ); printf( "f->tag(): %s\n", f->tag()->xml().c_str() ); printf( " t: %s\n", t->xml().c_str() ); } name = "parse Tag 2.5"; if( !r->hasChild( "option", "label", "smoking barrel" ) ) { ++fail; fprintf( stderr, "test '%s' failed\n", name.c_str() ); printf( "f->tag(): %s\n", f->tag()->xml().c_str() ); printf( " t: %s\n", t->xml().c_str() ); } name = "parse Tag 2.6"; if( !r->findChild( "option" )->findChild( "value" ) ) { ++fail; fprintf( stderr, "test '%s' failed\n", name.c_str() ); printf( "f->tag(): %s\n", f->tag()->xml().c_str() ); printf( " t: %s\n", t->xml().c_str() ); } name = "parse Tag 2.7"; if( r->findChild( "option" )->findChild( "value" )->cdata() != "lock" ) { ++fail; fprintf( stderr, "test '%s' failed\n", name.c_str() ); printf( "f->tag(): %s\n", f->tag()->xml().c_str() ); printf( " t: %s\n", t->xml().c_str() ); } name = "parse Tag 2.8"; TagList l = r->children(); TagList::const_iterator it = l.begin(); for( ; it != l.end(); ++it ) { if( (*it)->name() == "option" && ( !(*it)->hasChildWithCData( "value", "lock" ) && !(*it)->hasChildWithCData( "value", "stock" ) && !(*it)->hasChildWithCData( "value", "smoking barrel" ) ) ) { ++fail; fprintf( stderr, "test '%s' failed\n", name.c_str() ); printf( "f->tag(): %s\n", f->tag()->xml().c_str() ); printf( " t: %s\n", t->xml().c_str() ); } } name = "parse Tag 2.9"; if( !r->hasChildWithCData( "value", "lock" ) || !r->hasChildWithCData( "value", "stock" ) ) { ++fail; fprintf( stderr, "test '%s' failed\n", name.c_str() ); printf( "f->tag(): %s\n", f->tag()->xml().c_str() ); printf( " t: %s\n", t->xml().c_str() ); } delete f; delete t; delete r; f = 0; // ------- name = "boolean duplicate <value/>"; f = new DataFormField( DataFormField::TypeBoolean ); f->setName( "name" ); f->setValue( "1" ); f->setLabel( "label" ); t = f->tag(); if( t->children().size() != 1 || t->xml() != "<field type='boolean' var='name' " "label='label'><value>1</value></field>" ) { ++fail; fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() ); } delete f; delete t; f = 0; t = 0; if( fail == 0 ) { printf( "DataFormField: OK\n" ); return 0; } else { fprintf( stderr, "DataFormField: %d test(s) failed\n", fail ); return 1; } }
void Tag::collectAncestors(shared_ptr<Tag> tag, TagList &parents) { for (; !tag.isNull(); tag = tag->parent()) { parents.push_back(tag); } std::reverse(parents.begin(), parents.end()); }
void update(const TagList& tags) { m_crc.process_bytes(tags.data(), tags.byte_size()); }
/* * GetADSP() * * Get ADSP status for message rfc5617 */ void Validatory::GetADSP(std::list<DKIM::ADSP>& adsp) throw (DKIM::PermanentError, DKIM::TemporaryError) { /** * Start by collecting all From: <> addresses (this runtime-time free...) */ std::list<std::string> senders; for (DKIM::Message::HeaderList::const_iterator i = m_msg.GetHeaders().begin(); i != m_msg.GetHeaders().end(); ++i) { std::string headerName = (*i)->GetName(); transform(headerName.begin(), headerName.end(), headerName.begin(), tolower); // find from: <...> header(s)... if (headerName == "from") { std::string header = (*i)->GetHeader().substr((*i)->GetValueOffset()); header = DKIM::Conversion::EncodedWord::Decode(header); std::list<std::string> addrlist = DKIM::Tokenizer::ParseAddressList(header); for (std::list<std::string>::const_iterator aIter = addrlist.begin(); aIter != addrlist.end(); ++aIter) { // if no address is claimed to follow a ADSP, try the next one if (aIter->empty()) continue; size_t atSign = aIter->rfind("@"); if (atSign == std::string::npos) throw DKIM::PermanentError("Found invalid sender address: " + *aIter); std::string host = aIter->substr(atSign + 1); transform(host.begin(), host.end(), host.begin(), tolower); senders.push_back(host); } } } std::map<std::string, std::pair<int, std::string> > dkimResult; for (Validatory::SignatureList::const_iterator i = GetSignatures().begin(); i != GetSignatures().end(); ++i) { DKIM::PublicKey pub; DKIM::Signature sig; try { GetSignature(i, sig); GetPublicKey(sig, pub); CheckSignature(i, sig, pub); dkimResult[sig.GetDomain()] = std::make_pair(1, "pass"); } catch (DKIM::TemporaryError& e) { dkimResult[sig.GetDomain()] = std::make_pair(-1, e.what()); } catch (DKIM::PermanentError& e) { if (pub.SoftFail()) dkimResult[sig.GetDomain()] = std::make_pair(1, e.what()); else dkimResult[sig.GetDomain()] = std::make_pair(0, e.what()); } } for (std::list<std::string>::const_iterator i = senders.begin(); i != senders.end(); ++i) { std::string query = "_adsp._domainkey." + *i; std::string adspRecord; ADSP tmp; tmp.SetDomain(*i); std::map<std::string, std::pair<int, std::string> >::const_iterator dIter = dkimResult.find(*i); if (dIter != dkimResult.end() && dIter->second.first == -1) { tmp.SetResult(ADSP::DKIM_ADSP_TEMPERROR, dIter->second.second); } else if (dIter != dkimResult.end() && dIter->second.first == 1) { tmp.SetResult(ADSP::DKIM_ADSP_PASS, dIter->second.second); } else { std::string error; if (dIter != dkimResult.end()) error = dIter->second.second; else error = "no dkim signature found for d=" + *i; if ((CustomDNSResolver? CustomDNSResolver(query, adspRecord, CustomDNSData): DKIM::Util::Resolver().GetTXT(query, adspRecord) )) { // only bad queries goes here.. if (!adspRecord.empty()) { try { TagList tagList; tagList.Parse(adspRecord); TagListEntry v; if (tagList.GetTag("dkim", v)) { if (v.GetValue() == "all") { tmp.SetResult(ADSP::DKIM_ADSP_FAIL, error); } else if (v.GetValue() == "discardable") { tmp.SetResult(ADSP::DKIM_ADSP_DISCARD, error); } else { tmp.SetResult(ADSP::DKIM_ADSP_UNKNOWN, error); } } else { tmp.SetResult(ADSP::DKIM_ADSP_UNKNOWN, error); } } catch (DKIM::TemporaryError& e) { tmp.SetResult(ADSP::DKIM_ADSP_TEMPERROR, e.what()); } catch (DKIM::PermanentError& e) { tmp.SetResult(ADSP::DKIM_ADSP_PERMERROR, e.what()); } } else { tmp.SetResult(ADSP::DKIM_ADSP_NONE, error); } } else { tmp.SetResult(ADSP::DKIM_ADSP_TEMPERROR, DKIM::Util::StringFormat("dns query failed for %s", query.c_str())); } } adsp.push_back(tmp); } }
bool MovieClip::createFrames( Reader& reader, SWF& swf, MovieFrames &data ) { RECT empty = {FLT_MAX,FLT_MAX,-FLT_MAX,-FLT_MAX}; data._rectangle = empty; sbCalculateRectangle = true; // get all tags and build frame lists TagHeader header; ITag* tag = NULL; TagList* frame_tags = new TagList; TagList actionTags; do { header.read( reader ); const uint32_t code = header.code(); SWF::TagFactoryFunc factory = SWF::getTagFactory( code ); if (! factory ) { // no registered factory so skip this tag SWF_TRACE("*** SKIP *** "); header.print(); reader.skip( header.length() ); continue; } tag = factory( header ); SWF_ASSERT(tag); int32_t end_pos = reader.getCurrentPos() + tag->length(); bool keepTag = tag->read( reader, swf, data ); tag->print(); reader.align(); int32_t dif = end_pos - reader.getCurrentPos(); if( dif != 0 ) { SWF_TRACE("WARNING: tag not read correctly. trying to skip.\n"); reader.skip( dif ); } if (keepTag) { // collect action tags if (tag->code() == TAG_DO_ACTION) { actionTags.push_back(tag); } else { frame_tags->push_back( tag ); } } else { delete tag; } // create a new frame if ( TAG_SHOW_FRAME == code ) { SWF_TRACE("[%d] has %d tags\n", data._frames.size(), frame_tags->size()); // put action tags at the end of list in order to avoid callback error TagList::iterator it = actionTags.begin(); while (it != actionTags.end()) { frame_tags->push_back( *it ); ++it; } actionTags.clear(); data._frames.push_back( frame_tags ); frame_tags = new TagList; sbCalculateRectangle = false; } } while( header.code() != TAG_END ); delete frame_tags; return true; }
// Get time on SSEQ, will run the player at least once (without "playing" the // music), if the song is one-shot (and not looping), it will run the player // a second time, "playing" the song to determine when silence has occurred. // After which, it will store the data in the tags for the SSEQ. void GetTime(const std::string &filename, const SDAT *sdat, const SSEQ *sseq, TagList &tags, bool verbose, uint32_t numberOfLoops, uint32_t fadeLoop, uint32_t fadeOneShot) { auto player = std::unique_ptr<TimerPlayer>(new TimerPlayer()); player->Setup(sseq); player->maxSeconds = 6000; auto looponeplayer = std::unique_ptr<TimerPlayer>(new TimerPlayer()); looponeplayer->Setup(sseq); looponeplayer->maxSeconds = 6000; auto looptwoplayer = std::unique_ptr<TimerPlayer>(new TimerPlayer()); looptwoplayer->Setup(sseq); looptwoplayer->maxSeconds = 6000; // Get the time, without "playing" the notes Time length = GetTime(player.get(), 20, numberOfLoops); // Get the loop start and end positions Time lonelength = GetTime(looponeplayer.get(), 20, 1); Time ltwolengths = GetTime(looptwoplayer.get(), 20, 2); double lstart = lonelength.time - (ltwolengths.time - lonelength.time); // If the length was for a one-shot song, get the time again, this time "playing" the notes bool gotLength = false; if (static_cast<int>(length.time) != -1 && length.type == END) { player.reset(new TimerPlayer()); player->Setup(sseq); player->sbnk = sdat->infoSection.BANKrecord.entries[sseq->info.bank].sbnk; for (int i = 0; i < 4; ++i) if (player->sbnk->info.waveArc[i] != 0xFFFF) player->swar[i] = sdat->infoSection.WAVEARCrecord.entries[player->sbnk->info.waveArc[i]].swar; player->maxSeconds = length.time + 30; player->doNotes = true; Time oldLength = length; length = GetTime(player.get(), 40, numberOfLoops); if (static_cast<int>(length.time) != -1) gotLength = true; else length = oldLength; } if (static_cast<int>(length.time) != -1) { if (length.type == LOOP) { tags["fade"] = stringify(fadeLoop); std::string lsString = SecondsToStringMs(lstart); std::string leString = SecondsToStringMs(lonelength.time); tags["loopstart_ms"] = lsString; tags["loopend_ms"] = leString; } else tags["fade"] = stringify(fadeOneShot); if (!static_cast<int>(length.time)) length.time = 1; std::string lengthString = SecondsToString(std::ceil(length.time)); tags["length"] = lengthString; if (verbose) { std::cout << "Time for " << filename << ": " << lengthString << " (" << (length.type == LOOP ? "timed to 2 loops" : "one-shot") << ")\n"; if (length.type == END && !gotLength) std::cout << "(NOTE: Was unable to detect silence at the end of the track, time may be inaccurate.)\n"; } } else if (verbose) { tags.Remove("fade"); tags.Remove("length"); std::cout << "Unable to calculate time for " << filename << "\n"; } }
int main(int argc, char **argv) { const char *s1 = "I have\na lovely\nbunch of\ncoco nuts\n"; printf("on start :\n"); dump(); printf("initing to '%s'\n", s1); tl.readBuf(s1); dump(); printf("val for tag I is '%s'\n", tl.get("I")); printf("val for tag A is '%s'\n", tl.get("A")); printf("val for tag a is '%s'\n", tl.get("a")); printf("val for tag bunch is '%s'\n", tl.get("bunch")); printf("val for tag foo is '%s'\n", tl.get("foo")); printf("int val for tag foo is %d\n", tl.getInt("foo")); printf("int val for tag bunch is %d\n", tl.getInt("bunch")); printf("calling set('i', 'fly')\n"); tl.set("i", "fly"); printf("get('i') returns '%s'\n", tl.get("i")); dump(); printf("calling setInt('i', 777)\n"); tl.set("i", 777); printf("getInt('i') returns %d\n", tl.getInt("i")); dump(); printf("get('coco') returns '%s'\n", tl.get("coco")); printf("calling rem('coco')\n"); tl.rem("coco"); dump(); printf("get('coco') returns '%s'\n", tl.get("coco")); printf("writing to bar.txt returns %d\n", tl.writeFile("bar.txt")); printf("clearing\n"); tl.clear(); dump(); printf("get('i') returns '%s'\n", tl.get("i")); printf("reading back from bar.txt ... returns %d\n", tl.readFile("bar.txt")); dump(); printf("get('i') returns '%s'\n", tl.get("i")); printf("val for tag I is '%s'\n", tl.get("I")); printf("val for tag a is '%s'\n", tl.get("a")); printf("val for tag bunch is '%s'\n", tl.get("bunch")); }