mDNSlocal mDNSBool ParseElement(xmlDocPtr tadoc, xmlNode * a_node, TrustAnchor *ta) { xmlNode *cur_node = NULL; for (cur_node = a_node; cur_node; cur_node = cur_node->next) { if (cur_node->type == XML_ELEMENT_NODE) { // There could be multiple KeyDigests per TrustAnchor. We keep parsing till we // reach the last one or we encounter an error in parsing the document. if (!xmlStrcmp(cur_node->name, (const xmlChar *)"KeyDigest")) { if (ta->rds.digest) mDNSPlatformMemFree(ta->rds.digest); ta->rds.digestType = 0; ta->digestLen = 0; } if (!ParseElementChildren(tadoc, cur_node->children, ta)) return mDNSfalse; if (!ParseElement(tadoc, cur_node->children, ta)) return mDNSfalse; } } return mDNStrue; }
bool ClassDecodeGenerator::ProcessObjectInline( const TiXmlElement* field ) { char iname[16]; snprintf( iname, sizeof( iname ), "obj_%u", mItemNumber++ ); //make sure its an object const char* v = top(); fprintf( mOutputFile, " if( !%s->IsObject() )\n" " {\n" " _log( NET__PACKET_ERROR, \"Decode %s failed: %s is the wrong type: %%s\", %s->TypeString() );\n" "\n" " return false;\n" " }\n" " PyObject* %s = %s->AsObject();\n" "\n", v, mName, iname, v, iname, v ); char aname[32]; snprintf( aname, sizeof( aname ), "%s->arguments()", iname ); push( aname ); char tname[32]; snprintf( tname, sizeof( tname ), "%s->type()", iname ); push( tname ); if( !ParseElementChildren( field, 2 ) ) return false; pop(); return true; }
bool ClassCloneGenerator::ProcessElementDef( const TiXmlElement* field ) { const char* name = field->Attribute( "name" ); if( name == NULL ) { _log( COMMON__ERROR, "<element> at line %d is missing the name attribute, skipping.", field->Row() ); return false; } fprintf( mOutputFile, "%s& %s::operator=( const %s& oth )\n" "{\n", name, name, name ); if( !ParseElementChildren( field ) ) return false; fprintf( mOutputFile, " return *this;\n" "}\n" "\n" ); return true; }
bool ClassDecodeGenerator::ProcessSubStructInline( const TiXmlElement* field ) { char iname[16]; snprintf( iname, sizeof( iname ), "ss_%u", mItemNumber++ ); //make sure its a substruct const char* v = top(); fprintf( mOutputFile, " if( !%s->IsSubStruct() )\n" " {\n" " _log( NET__PACKET_ERROR, \"Decode %s failed: %s is not a substruct: %%s\", %s->TypeString() );\n" "\n" " return false;\n" " }\n" " PySubStruct* %s = %s->AsSubStruct();\n" "\n", v, mName, iname, v, iname, v ); char ssname[32]; snprintf( ssname, sizeof( ssname ), "%s->sub()", iname ); push( ssname ); //Decode the sub-element if( !ParseElementChildren( field, 1 ) ) return false; pop(); return true; }
bool ClassDumpGenerator::ProcessElementDef( const TiXmlElement* field ) { const char* name = field->Attribute( "name" ); if( name == NULL ) { _log( COMMON__ERROR, "<element> at line %d is missing the name attribute, skipping.", field->Row() ); return false; } fprintf( mOutputFile, "void %s::Dump( LogType l_type, const char* pfx ) const\n" "{\n" " _log( l_type, \"%%s%s\", pfx );\n" "\n", name, name ); if( !ParseElementChildren( field ) ) return false; fprintf( mOutputFile, "}\n" "\n" ); return true; }
bool ClassDumpGenerator::ProcessObjectInline( const TiXmlElement* field ) { fprintf( mOutputFile, " _log( l_type, \"%%sObject:\", pfx );\n" "\n" ); return ParseElementChildren( field, 2 ); }
bool EVEServerConfig::ProcessCharacter( const TiXmlElement* ele ) { AddValueParser( "startBalance", character.startBalance ); const bool result = ParseElementChildren( ele ); RemoveParser( "startBalance" ); return result; }
bool ClassDecodeGenerator::ProcessTupleInline( const TiXmlElement* field ) { //first, we need to know how many elements this tuple has: const TiXmlNode* i = NULL; uint32 count = 0; while( ( i = field->IterateChildren( i ) ) ) { if( i->Type() == TiXmlNode::ELEMENT ) count++; } char iname[16]; snprintf( iname, sizeof( iname ), "tuple%u", mItemNumber++ ); const char* v = top(); //now we can generate the tuple decl fprintf( mOutputFile, " if( !%s->IsTuple() )\n" " {\n" " _log( NET__PACKET_ERROR, \"Decode %s failed: %s is the wrong type: %%s\", %s->TypeString() );\n" "\n" " return false;\n" " }\n" " PyTuple* %s = %s->AsTuple();\n" "\n" " if( %s->size() != %u )\n" " {\n" " _log( NET__PACKET_ERROR, \"Decode %s failed: %s is the wrong size: expected %d, but got %%lu\", %s->size() );\n" "\n" " return false;\n" " }\n" "\n", v, mName, iname, v, iname, v, iname, count, mName, iname, count, iname ); //now we need to queue up all the storage locations for the fields //need to be backward char varname[64]; while( count-- > 0 ) { snprintf( varname, sizeof( varname ), "%s->GetItem( %u )", iname, count ); push( varname ); } if( !ParseElementChildren( field ) ) return false; pop(); return true; }
bool EVEServerConfig::ProcessNet( const TiXmlElement* ele ) { AddValueParser( "port", net.port ); AddValueParser( "imageServer", net.imageServer); const bool result = ParseElementChildren( ele ); RemoveParser( "port" ); RemoveParser( "imageServer" ); return result; }
bool ClassDumpGenerator::ProcessDictInlineEntry( const TiXmlElement* field ) { //we dont really even care about this... const char* key = field->Attribute( "key" ); if( key == NULL ) { _log( COMMON__ERROR, "<dictInlineEntry> at line %d is missing the key attribute, skipping.", field->Row() ); return false; } return ParseElementChildren( field, 1 ); }
bool EVEServerConfig::ProcessAccount( const TiXmlElement* ele ) { AddValueParser( "autoAccountRole", account.autoAccountRole ); AddValueParser( "loginMessage", account.loginMessage ); const bool result = ParseElementChildren( ele ); RemoveParser( "autoAccountRole" ); RemoveParser( "loginMessage" ); return result; }
bool EVEServerConfig::ProcessRates( const TiXmlElement* ele ) { AddValueParser( "skillRate", rates.skillRate ); AddValueParser( "secRate", rates.secRate ); AddValueParser( "npcBountyMultiply", rates.npcBountyMultiply ); const bool result = ParseElementChildren( ele ); RemoveParser( "skillRate" ); RemoveParser( "secRate" ); RemoveParser( "npcBountyMultiply" ); return result; }
bool EVEServerConfig::ProcessFiles( const TiXmlElement* ele ) { AddValueParser( "logDir", files.logDir ); AddValueParser( "logSettings", files.logSettings ); AddValueParser( "cacheDir", files.cacheDir ); AddValueParser( "imageDir", files.imageDir ); const bool result = ParseElementChildren( ele ); RemoveParser( "logDir" ); RemoveParser( "logSettings" ); RemoveParser( "cacheDir" ); RemoveParser( "imageDir" ); return result; }
bool XMLPacketGen::ParseElements( const TiXmlElement* field ) { if( !OpenFiles() ) { sLog.Error( "XMLPacketGen", "Unable to open output files: %s.", strerror( errno ) ); return false; } const std::string def = FNameToDef( mHeaderFileName.c_str() ); //headers: fprintf( mHeaderFile, "%s\n" "\n" "#ifndef %s\n" "#define %s\n" "\n" "#include \"python/PyVisitor.h\"\n" "#include \"python/PyRep.h\"\n" "\n", smGenFileComment, def.c_str(), def.c_str() ); fprintf( mSourceFile, "%s\n" "\n" "#include \"EVECommonPCH.h\"\n" "\n" "#include \"%s\"\n" "\n", smGenFileComment, mHeaderFileName.c_str() ); //content bool res = ParseElementChildren( field ); //footers: fprintf( mHeaderFile, "#endif /* !%s */\n" "\n", def.c_str() ); return res; }
bool EVEServerConfig::ProcessCharacter( const TiXmlElement* ele ) { AddValueParser( "startBalance", character.startBalance ); AddValueParser( "startStation", character.startStation ); AddValueParser( "startSecRating", character.startSecRating ); AddValueParser( "startCorporation", character.startCorporation ); AddValueParser( "terminationDelay", character.terminationDelay ); const bool result = ParseElementChildren( ele ); RemoveParser( "startBalance" ); RemoveParser( "startStation" ); RemoveParser( "startSecRating" ); RemoveParser( "startCorporation" ); RemoveParser( "terminationDelay" ); return result; }
bool EVEServerConfig::ProcessDatabase( const TiXmlElement* ele ) { AddValueParser( "host", database.host ); AddValueParser( "port", database.port ); AddValueParser( "username", database.username ); AddValueParser( "password", database.password ); AddValueParser( "db", database.db ); const bool result = ParseElementChildren( ele ); RemoveParser( "host" ); RemoveParser( "port" ); RemoveParser( "username" ); RemoveParser( "password" ); RemoveParser( "db" ); return result; }
bool EVEServerConfig::ProcessEveServer( const TiXmlElement* ele ) { // entering element, extend allowed syntax AddMemberParser( "account", &EVEServerConfig::ProcessAccount ); AddMemberParser( "character", &EVEServerConfig::ProcessCharacter ); AddMemberParser( "database", &EVEServerConfig::ProcessDatabase ); AddMemberParser( "files", &EVEServerConfig::ProcessFiles ); AddMemberParser( "net", &EVEServerConfig::ProcessNet ); // parse the element const bool result = ParseElementChildren( ele ); // leaving element, reduce allowed syntax RemoveParser( "account" ); RemoveParser( "character" ); RemoveParser( "database" ); RemoveParser( "files" ); RemoveParser( "net" ); // return status of parsing return result; }
bool ClassDumpGenerator::ProcessSubStreamInline( const TiXmlElement* field ) { //do we want to display the substream in the dump? return ParseElementChildren( field, 1 ); }
bool ClassDumpGenerator::ProcessSubStructInline( const TiXmlElement* field ) { return ParseElementChildren( field, 1 ); }
bool ClassDumpGenerator::ProcessDictInline( const TiXmlElement* field ) { //do we want to display the dict in the dump? return ParseElementChildren( field ); }
bool ClassHeaderGenerator::ProcessTupleInline( const TiXmlElement* field ) { return ParseElementChildren( field ); }
/* * this function could be improved quite a bit by not parsing and checking the * dictInlineEntry elements over and over again */ bool ClassDecodeGenerator::ProcessDictInline( const TiXmlElement* field ) { char iname[16]; snprintf( iname, sizeof( iname ), "dict%u", mItemNumber++ ); bool soft = false; const char* soft_str = field->Attribute( "soft" ); if( soft_str != NULL ) soft = str2<bool>( soft_str ); const char* v = top(); //make sure its a dict fprintf( mOutputFile, " if( !%s->IsDict() )\n" " {\n" " _log( NET__PACKET_ERROR, \"Decode %s failed: %s is the wrong type: %%s\", %s->TypeString() );\n" "\n" " return false;\n" " }\n" " PyDict* %s = %s->AsDict();\n" "\n", v, mName, iname, v, iname, v ); //now generate the "found" flags for each expected element. const TiXmlNode* i = NULL; bool empty = true; uint32 count = 0; while( ( i = field->IterateChildren( i ) ) ) { if( i->Type() == TiXmlNode::ELEMENT ) { const TiXmlElement* ele = i->ToElement(); //we only handle dictInlineEntry elements if( strcmp( ele->Value(), "dictInlineEntry" ) != 0 ) { _log(COMMON__ERROR, "non-dictInlineEntry in <dictInline> at line %d, ignoring.", ele->Row()); continue; } fprintf( mOutputFile, " bool %s_%u = false;\n", iname, count ); ++count; empty = false; } } fprintf( mOutputFile, "\n" ); if( empty ) fprintf( mOutputFile, " // %s is empty from our perspective, not enforcing though.\n", iname ); else { //setup the loop... fprintf( mOutputFile, " PyDict::const_iterator %s_cur, %s_end;\n" " %s_cur = %s->begin();\n" " %s_end = %s->end();\n" " for(; %s_cur != %s_end; %s_cur++)\n" " {\n" " if( !%s_cur->first->IsString() )\n" " {\n" " _log( NET__PACKET_ERROR, \"Decode %s failed: a key in %s is the wrong type: %%s\", %s_cur->first->TypeString() );\n" "\n" " return false;\n" " }\n" " const PyString* key_string__ = %s_cur->first->AsString();\n" "\n", iname, iname, iname, iname, iname, iname, iname, iname, iname, iname, mName, iname, iname, iname ); count = 0; while( ( i = field->IterateChildren( i ) ) ) { if( i->Type() == TiXmlNode::ELEMENT ) { const TiXmlElement* ele = i->ToElement(); //we only handle dictInlineEntry elements if( strcmp( ele->Value(), "dictInlineEntry" ) != 0 ) { _log( COMMON__ERROR, "non-dictInlineEntry in <dictInline> at line %d, ignoring.", ele->Row() ); continue; } const char* key = ele->Attribute( "key" ); if( key == NULL ) { _log( COMMON__ERROR, "<dictInlineEntry> at line %d lacks a key attribute", ele->Row() ); return false; } //conditional prefix... fprintf( mOutputFile, " if( key_string__->content() == \"%s\" )\n" " {\n" " %s_%u = true;\n" "\n", key, iname, count ); ++count; //now process the data part, putting the value into `varname` //TODO: figure out a reasonable way to fix the indention here... char vname[64]; snprintf( vname, sizeof( vname ), "%s_cur->second", iname ); push( vname ); if( !ParseElementChildren( ele, 1 ) ) return false; //fixed suffix... fprintf( mOutputFile, " }\n" " else\n" ); } } if( soft ) fprintf( mOutputFile, " {\n" " /* do nothing, soft dict */\n" " }\n" " }\n" "\n" ); else fprintf( mOutputFile, " {\n" " _log( NET__PACKET_ERROR, \"Decode %s failed: Unknown key string '%%s' in %s\", key_string__->content().c_str() );\n" "\n" " return false;\n" " }\n" " }\n" "\n", mName, iname ); //finally, check the "found" flags for each expected element. count = 0; while( ( i = field->IterateChildren( i ) ) ) { if(i->Type() == TiXmlNode::ELEMENT) { const TiXmlElement* ele = i->ToElement(); //we only handle dictInlineEntry elements if( strcmp( ele->Value(), "dictInlineEntry" ) != 0 ) { _log( COMMON__ERROR, "non-dictInlineEntry in <dictInline> at line %d, ignoring.", ele->Row() ); continue; } const char* key = ele->Attribute( "key" ); if( key == NULL ) { _log( COMMON__ERROR, "<dictInlineEntry> at line %d lacks a key attribute", ele->Row() ); return false; } fprintf( mOutputFile, " if( !%s_%u )\n" " {\n" " _log( NET__PACKET_ERROR, \"Decode %s failed: Missing dict entry '%s' in %s\" );\n" "\n" " return false;\n" " }\n" "\n", iname, count, mName, key, iname ); ++count; } } } pop(); return true; }
bool ClassConstructGenerator::ProcessListInline( const TiXmlElement* field ) { return ParseElementChildren( field ); }
bool ClassCloneGenerator::ProcessDictInline( const TiXmlElement* field ) { return ParseElementChildren( field ); }
bool ClassCloneGenerator::ProcessSubStreamInline( const TiXmlElement* field ) { return ParseElementChildren( field, 1 ); }
bool ClassDestructGenerator::ProcessObjectInline( const TiXmlElement* field ) { return ParseElementChildren( field, 2 ); }