void FileTransfer::parseFileList( const TagList& files ) { TagList::const_iterator it = files.begin(); for( ; it != files.end(); ++it ) { File f; Tag *t = (*it)->findChild( "name" ); f.name = t ? t->cdata() : EmptyString; t = (*it)->findChild( "desc" ); f.desc = t ? t->cdata() : EmptyString; t = (*it)->findChild( "date" ); f.date = t ? t->cdata() : EmptyString; t = (*it)->findChild( "size" ); f.size = t ? atoi( t->cdata().c_str() ) : -1; t = (*it)->findChild( "range" ); if( t ) { f.range = true; f.offset = t->hasAttribute( "offset" ) ? atoi( t->findAttribute( "offset" ).c_str() ) : -1; } t = (*it)->findChild( "hash", XMLNS, XMLNS_HASHES ); if( t ) { f.hash_algo = t->findAttribute( "algo" ); f.hash = t->cdata(); } m_files.push_back( f ); } }
bool InBandBytestreamManager::handleIq( Stanza *stanza ) { Tag *o = 0; if( ( stanza->subtype() == StanzaIqSet ) && ( ( o = stanza->findChild( "open", "xmlns", XMLNS_IBB ) ) != 0 ) ) { InBandBytestream *ibb = new InBandBytestream( 0, m_parent ); const std::string sid = o->findAttribute( "sid" ); ibb->setSid( sid ); if( !m_inbandBytestreamHandler ) rejectInBandBytestream( ibb, stanza->from(), stanza->id() ); if( !m_syncInbandBytestreams ) { AsyncIBBItem item; item.ibb = ibb; item.from = stanza->from(); item.id = stanza->id(); m_asyncTrackMap[sid] = item; } bool t = m_inbandBytestreamHandler->handleIncomingInBandBytestream( stanza->from(), ibb ); if( m_syncInbandBytestreams && t ) { acceptInBandBytestream( ibb, stanza->from(), stanza->id() ); } else if( m_syncInbandBytestreams && !t ) { rejectInBandBytestream( ibb, stanza->from(), stanza->id() ); } } else if( ( stanza->subtype() == StanzaIqSet ) && ( ( o = stanza->findChild( "close", "xmlns", XMLNS_IBB ) ) != 0 ) && o->hasAttribute( "sid" ) ) { IBBMap::iterator it = m_ibbMap.find( o->findAttribute( "sid" ) ); if( it != m_ibbMap.end() ) { (*it).second->closed(); Tag *iq = new Tag( "iq" ); iq->addAttribute( "type", "result" ); iq->addAttribute( "to", stanza->from().full() ); iq->addAttribute( "id", stanza->id() ); m_parent->send( iq ); } } else { return false; } return true; }
jFileTransfer::StreamHostQuery::StreamHostQuery(const Tag *tag) : StanzaExtension(SExtFileTransfer) { if(!tag) return; Tag *streamhost = tag->findChild("streamhost"); if(!streamhost) return; m_jid = JID(streamhost->findAttribute("jid")); m_host = streamhost->findAttribute("host"); m_port = atoi(streamhost->findAttribute("port").c_str()); m_zeroconf = streamhost->findAttribute("zeroconf"); }
bool SOCKS5BytestreamManager::handleIq( Stanza *stanza ) { Tag* q = stanza->findChild( "query", "xmlns", XMLNS_BYTESTREAMS ); if( !q || !m_socks5BytestreamHandler ) return false; if( m_trackMap.find( stanza->id() ) != m_trackMap.end() ) return false; switch( stanza->subtype() ) { case StanzaIqSet: { const std::string& sid = q->findAttribute( "sid" ); const std::string& mode = q->findAttribute( "mode" ); if( haveStream( stanza->from() ) || sid.empty() || mode == "udp" ) { rejectSOCKS5Bytestream( stanza->from(), stanza->id(), StanzaErrorNotAcceptable ); return true; } AsyncS5BItem asi; Tag::TagList& l = q->children(); Tag::TagList::const_iterator it = l.begin(); for( ; it != l.end(); ++it ) { if( (*it)->name() == "streamhost" && (*it)->hasAttribute( "jid" ) && (*it)->hasAttribute( "host" ) && (*it)->hasAttribute( "port" ) ) { StreamHost sh; sh.jid = (*it)->findAttribute( "jid" ); sh.host = (*it)->findAttribute( "host" ); sh.port = atoi( (*it)->findAttribute( "port" ).c_str() ); asi.sHosts.push_back( sh ); } } asi.id = stanza->id(); asi.from = stanza->from(); asi.incoming = true; m_asyncTrackMap[sid] = asi; m_socks5BytestreamHandler->handleIncomingSOCKS5BytestreamRequest( sid, stanza->from() ); break; } case StanzaIqError: m_socks5BytestreamHandler->handleSOCKS5BytestreamError( stanza, std::string() ); break; default: break; } return true; }
void InBandBytestream::filter( Stanza *stanza ) { if( !m_inbandBytestreamDataHandler || !m_open ) return; if( stanza->subtype() == StanzaMessageError ) { m_inbandBytestreamDataHandler->handleInBandError( m_sid, stanza->from(), stanza->error() ); m_open = false; } Tag *data = 0; if( ( data = stanza->findChild( "data", "xmlns", XMLNS_IBB ) ) == 0 ) return; const std::string& sid = data->findAttribute( "sid" ); if( sid.empty() || sid != m_sid ) return; const std::string& seq = data->findAttribute( "seq" ); if( seq.empty() ) { m_open = false; return; } std::stringstream str; int sequence = 0; str << seq; str >> sequence; if( m_lastChunkReceived + 1 != sequence ) { m_open = false; return; } m_lastChunkReceived = sequence; if( !data->cdata().length() ) { m_open = false; return; } m_inbandBytestreamDataHandler->handleInBandData( Base64::decode64( data->cdata() ), sid ); }
void ClientBase::send( IQ& iq, IqHandler*, int ) { Tag* tag = iq.tag(); switch( m_test ) { case 1: { Tag* si = tag->findChild( "si", "xmlns", XMLNS_SI ); if( tag->findAttribute( "to" ) == to.full() && si && *(si->findChild( "file" )) == *t1 && *(si->findChild( "feature" )) == *t2 && si->findAttribute( "mime-type" ) == "binary/octet-stream" && si->findAttribute( "profile" ) == g_profile ) m_ok = true; break; } } delete tag; }
void XmppGSAuth_base::untagAuth_base( const Tag* tag ) { Tag *tAuth = tag->findChild("authority"); if( tAuth ) { if(tAuth->hasAttribute("method")) { m_srcmethod = tAuth->findAttribute("method"); std::string method = m_srcmethod; g_toLowerCase( method ); if( method == "add" ) { m_method = defCfgOprt_AddModify; } else if( method == "edit" ) { m_method = defCfgOprt_Modify; } else if( method == "delete" ) { m_method = defCfgOprt_Delete; } else if( method == "getself" ) { m_method = defCfgOprt_GetSelf; } else if( method == "getsimple" ) { m_method = defCfgOprt_GetSimple; } } const TagList& l = tAuth->children(); TagList::const_iterator it = l.begin(); for( ; it != l.end(); ++it ) { if((*it)->name() == "user") { GSIOTUser *pUser = new GSIOTUser(*it); std::string jid = pUser->GetKeyJid(); if( GSIOTUserMgr::usermapFind( m_mapUser, jid ) == m_mapUser.end() ) { GSIOTUserMgr::usermapInsert( m_mapUser, pUser ); } else { delete pUser; } } } } }
void ResourceManager::setResource(const Presence &stanza) { std::string resource = stanza.from().resource(); if (resource.empty()) return; Tag *stanzaTag = stanza.tag(); Tag *c = stanzaTag->findChildWithAttrib("xmlns", "http://jabber.org/protocol/caps"); int caps = -1; // presence has caps if (c != NULL) { caps = Transport::instance()->getCapabilities(c->findAttribute("ver")); } setResource(resource, stanza.priority(), caps, (int) stanza.presence(), stanza.status()); delete stanzaTag; }
bool Adhoc::handleIq( Stanza *stanza ) { if( stanza->subtype() != StanzaIqSet ) return false; if( stanza->hasChild( "command" ) ) { Tag *c = stanza->findChild( "command" ); const std::string& node = c->findAttribute( "node" ); AdhocCommandProviderMap::const_iterator it = m_adhocCommandProviders.find( node ); if( !node.empty() && ( it != m_adhocCommandProviders.end() ) ) { (*it).second->handleAdhocCommand( node, c, stanza->from(), stanza->id() ); return true; } } return false; }
Adhoc::Command::Command( const Tag* tag ) : StanzaExtension( ExtAdhocCommand ), m_plugin( 0 ), m_actions( 0 ) { if( !tag || tag->name() != "command" || tag->xmlns() != XMLNS_ADHOC_COMMANDS ) return; m_node = tag->findAttribute( "node" ); m_sessionid = tag->findAttribute( "sessionid" ); m_status = static_cast<Status>( util::lookup( tag->findAttribute( "status" ), cmdStatusStringValues ) ); Tag* a = tag->findChild( "actions" ); if( a ) { // Multi-stage response m_action = static_cast<Action>( util::deflookup2( a->findAttribute( "action" ), cmdActionStringValues, Complete ) ); if( a->hasChild( "prev" ) ) m_actions |= Previous; if( a->hasChild( "next" ) ) m_actions |= Next; if( a->hasChild( "complete" ) ) m_actions |= Complete; } else { m_action = static_cast<Action>( util::deflookup2( tag->findAttribute( "action" ), cmdActionStringValues, Execute ) ); } const ConstTagList& l = tag->findTagList( "/command/note" ); ConstTagList::const_iterator it = l.begin(); for( ; it != l.end(); ++it ) m_notes.push_back( new Note( (*it) ) ); Tag* x = tag->findChild( "x", "xmlns", XMLNS_X_DATA ); if( x ) m_plugin = new DataForm( x ); else { Tag* x = tag->findChild( "iodata", "xmlns", XMLNS_IODATA ); if( x ) m_plugin = new IOData( x ); } }
XmppGSManager::XmppGSManager( const Tag* tag ) :StanzaExtension(ExtIotManager), m_method(defCfgOprt_Unknown) { if( !tag || tag->name() != "gsiot" || tag->xmlns() != XMLNS_GSIOT_MANAGER ) return; Tag *tmgr = tag->findChild("manager"); if( tmgr ) { if(tmgr->hasAttribute("method")) { m_srcmethod = tmgr->findAttribute("method"); std::string method = m_srcmethod; g_toLowerCase( method ); if( method == "add" ) { m_method = defCfgOprt_Add; } else if( method == "edit" ) { m_method = defCfgOprt_Modify; } else if( method == "delete" ) { m_method = defCfgOprt_Delete; } } const TagList& l = tmgr->children(); TagList::const_iterator it = l.begin(); for( ; it != l.end(); ++it ) { if((*it)->name() == "device") { m_devices.push_back( new GSIOTDevice(*it) ); } } } }
XmppGSEvent::XmppGSEvent( const Tag* tag ) :StanzaExtension(ExtIotEvent), m_method(defCfgOprt_Unknown), m_pDevice(NULL), m_runstate(1) { if( !tag || tag->name() != "gsiot" || tag->xmlns() != XMLNS_GSIOT_EVENT ) return; //GSIOTClient::XmppPrint( tag, "recv", stanza, false ); //jyc20170227 debug //XmppGSEvent::PrintTag( tag , ExtIotEvent); Tag *tmgr = tag->findChild("event"); if( tmgr ) { Tag *tDevice = tmgr->findChild("device"); if( tDevice ) { m_pDevice = new GSIOTDevice(tDevice); } else { LOGMSG( "not found device tag" ); return; } this->UntagEditAttr( tmgr ); if(tmgr->hasAttribute("method")) { m_srcmethod = tmgr->findAttribute("method"); std::string method = m_srcmethod; g_toLowerCase( method ); if( method == "add" ) { m_method = defCfgOprt_Add; } else if( method == "edit" ) { m_method = defCfgOprt_Modify; } else if( method == "delete" ) { m_method = defCfgOprt_Delete; } } Tag *tdo = tmgr->findChild("do"); //jyc20170223 trans "edit trigger" if( tdo ) { const TagList& l = tdo->children(); TagList::const_iterator it = l.begin(); for( ; it != l.end(); ++it ) { ControlEvent *pNew = NULL; if((*it)->name() == "smsthing") { pNew = new AutoSendSMSEvent(*it); } else if((*it)->name() == "mailthing") { //... } else if((*it)->name() == "messagething") { pNew = new AutoNoticeEvent(*it); } else if((*it)->name() == "devicething") { pNew = new AutoControlEvent(*it); } else if((*it)->name() == "callthing") { //... } else if((*it)->name() == "eventthing") { pNew = new AutoEventthing(*it); } if( pNew ) { if( m_pDevice ) { pNew->SetDeviceType( m_pDevice->getType() ); pNew->SetDeviceID( m_pDevice->getId() ); } m_Events.push_back( pNew ); } } } Tag *tState = tmgr->findChild("state"); if( tState ) { m_runstate = atoi( tState->cdata().c_str() ); } } }
XmppGSPlayback::XmppGSPlayback( const Tag* tag ) :StanzaExtension(ExtIotPlayback), m_camera_id(0), m_startdt(0), m_enddt(0), m_state(defPBState_Unknown), m_sound(-1) { if( !tag || tag->name() != "gsiot" || tag->xmlns() != XMLNS_GSIOT_PLAYBACK ) return; Tag *tmgr = tag->findChild("playback"); if( tmgr ) { Tag *tcamera = tmgr->findChild("device"); if( tcamera ) { if( tcamera->hasAttribute("id") ) { m_camera_id = atoi( tcamera->findAttribute("id").c_str() ); } } if( tmgr->findChild("startdate") ) { m_startdt = atoi( tmgr->findChild("startdate")->cdata().c_str() ); } if( tmgr->findChild("enddate") ) { m_enddt = atoi( tmgr->findChild("enddate")->cdata().c_str() ); } if( tmgr->findChild("url") ) { m_url = tmgr->findChild("url")->cdata(); } //#ifdef _DEBUG #if 0 std::string useUrl_lastback; if( IsRUNCODEEnable( defCodeIndex_TEST_Debug_TempCode ) ) { if( !g_IsRTMFP_url( m_url ) ) useUrl_lastback = m_url; //m_url = "rtmfp://192.168.0.76:1985/p2p"; m_url = "rtmfp://p2p.gsss.cn:1985/p2p"; //m_url = "rtmfp://unknownp2p.gsss.cn:1985/p2p"; GUID guid; ::CoCreateGuid( &guid ); m_url += "/"; m_url += g_BufferToString( (unsigned char*)&guid, sizeof( guid ), false, false ); } #endif if( IsRUNCODEEnable( defCodeIndex_RTMFP_DelFromUrlStreamID ) && g_IsRTMFP_url( m_url ) ) { std::vector<std::string> useUrl_unit_vec; split( m_url, useUrl_unit_vec, "/" ); const int unitsize = useUrl_unit_vec.size(); // 偶数个表示最后一个为streamid,去掉 if( 0 == (unitsize%2) ) { g_replace_all_distinct( m_url, std::string( "/" )+useUrl_unit_vec[unitsize-1], "" ); } } Tag *tchildlist_url_backup = tmgr->findChild("url_backup"); if( tchildlist_url_backup ) { const TagList& l = tchildlist_url_backup->children(); TagList::const_iterator it = l.begin(); for( ; it != l.end(); ++it ) { Tag *tChild = (*it); if( tChild->name() == "url" ) { m_url_backup.push_back( tChild->cdata() ); } } } //if( !useUrl_lastback.empty() ) m_url_backup.push_back( useUrl_lastback ); if( tmgr->findChild("key") ) { m_key = tmgr->findChild("key")->cdata(); } if( tmgr->findChild("state") ) { std::string strState = tmgr->findChild("state")->cdata(); g_toLowerCase( strState ); if( strState == "start" ) { m_state = defPBState_Start; } else if( strState == "stop" ) { m_state = defPBState_Stop; } else if( strState == "set" ) { m_state = defPBState_Set; } else if( strState == "get" ) { m_state = defPBState_Get; } else if( strState == "pause" ) { m_state = defPBState_Pause; } else if( strState == "resume" ) { m_state = defPBState_Resume; } else if( strState == "normalplay" ) { m_state = defPBState_NormalPlay; } else if( strState == "fastplay" ) { m_state = defPBState_FastPlay; } else if( strState == "fastplaythrow" ) { m_state = defPBState_FastPlayThrow; } else if( strState == "fastplay1" ) { m_state = defPBState_FastPlay1; } else if( strState == "fastplay2" ) { m_state = defPBState_FastPlay2; } else if( strState == "slowplay" ) { m_state = defPBState_SlowPlay; } else if( strState == "slowplay1" ) { m_state = defPBState_SlowPlay1; } else if( strState == "slowplay2" ) { m_state = defPBState_SlowPlay2; } else if( strState == "stopall" ) { m_state = defPBState_StopAll; } } if( tmgr->findChild("sound") ) { m_sound = atoi( tmgr->findChild("sound")->cdata().c_str() ); } else { m_sound = -1; // 无效值 } } }
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; } }
XmppGSTalk::XmppGSTalk( const Tag* tag ) :StanzaExtension(ExtIotTalk), m_cmd(defTalkCmd_Unknown), m_result(true) { if( !tag || tag->name() != "gstalk" || tag->xmlns() != XMLNS_GSIOT_TALK ) return; Tag *tmgr = tag->findChild("gstalk"); if( tmgr ) { if( tmgr->findChild("command") ) { m_strSrcCmd = tmgr->findChild("command")->cdata(); std::string strcmd = m_strSrcCmd; g_toLowerCase( strcmd ); if( strcmd == "request" ) { m_cmd = defTalkCmd_request; } else if( strcmd == "accept" ) { m_cmd = defTalkCmd_accept; } else if( strcmd == "reject" ) { m_cmd = defTalkCmd_reject; } else if( strcmd == "session" ) { m_cmd = defTalkCmd_session; } else if( strcmd == "adddev" ) { m_cmd = defTalkCmd_adddev; } else if( strcmd == "removedev" ) { m_cmd = defTalkCmd_removedev; } else if( strcmd == "keepalive" ) { m_cmd = defTalkCmd_keepalive; } else if( strcmd == "quit" ) { m_cmd = defTalkCmd_quit; } else if( strcmd == "forcequit" ) { m_cmd = defTalkCmd_forcequit; } else { m_cmd = defTalkCmd_Unknown; } } if( tmgr->findChild("url") ) { m_url = tmgr->findChild("url")->cdata(); } Tag *tdevicelist = tmgr->findChild("devicelist"); if( tdevicelist ) { const TagList& l = tdevicelist->children(); TagList::const_iterator it = l.begin(); for( ; it != l.end(); ++it ) { Tag *tDev = (*it); if( tDev->name() == "device" ) { if( tDev->hasAttribute("type") && tDev->hasAttribute("id") ) { IOTDeviceType dev_type = (IOTDeviceType)atoi( tDev->findAttribute("type").c_str() ); int dev_id = atoi( tDev->findAttribute("id").c_str() ); m_vecdev.push_back( GSIOTDeviceKey(dev_type,dev_id) ); } } } } } }
bool Adhoc::handleIqID( Stanza * stanza, int context ) { if( context != ExecuteAdhocCommand || stanza->subtype() != StanzaIqResult ) return false; AdhocTrackMap::iterator it = m_adhocTrackMap.begin(); for( ; it != m_adhocTrackMap.end(); ++it ) { if( (*it).second.context == context && (*it).second.remote == stanza->from() ) { Tag *c = stanza->findChild( "command", "xmlns", XMLNS_ADHOC_COMMANDS ); if( c ) { const std::string& command = c->findAttribute( "node" ); const std::string& id = c->findAttribute( "sessionid" ); Tag *a = c->findChild( "actions" ); int actions = ActionCancel; Adhoc::AdhocExecuteActions def = ActionCancel; if( a ) { if( a->hasChild( "prev" ) ) actions |= ActionPrevious; if( a->hasChild( "next" ) ) actions |= ActionNext; if( a->hasChild( "complete" ) ) actions |= ActionComplete; const std::string& d = a->findAttribute( "execute" ); if( d == "next" ) def = ActionNext; else if( d == "prev" ) def = ActionPrevious; else if( d == "complete" ) def = ActionComplete; } Tag *n = c->findChild( "note" ); std::string note; AdhocNoteType type = AdhocNoteInfo; if( n ) { note = n->cdata(); if( n->hasAttribute( "type", "warn" ) ) type = AdhocNoteWarn; else if( n->hasAttribute( "type", "error" ) ) type = AdhocNoteError; } const std::string& s = c->findAttribute( "status" ); AdhocCommandStatus status = AdhocCommandStatusUnknown; if( s == "executing" ) status = AdhocCommandExecuting; else if( s == "completed" ) status = AdhocCommandCompleted; else if( s == "canceled" ) status = AdhocCommandCanceled; DataForm form; Tag *x = c->findChild( "x", "xmlns", XMLNS_X_DATA ); if( x ) form.parse( x ); (*it).second.ah->handleAdhocExecutionResult( stanza->from(), command, status, id, form, actions, def, note, type ); } m_adhocTrackMap.erase( it ); return true; } } return false; }
bool SOCKS5BytestreamManager::handleIqID( Stanza *stanza, int context ) { StringMap::iterator it = m_trackMap.find( stanza->id() ); if( it == m_trackMap.end() ) return false; switch( context ) { case S5BOpenStream: { switch( stanza->subtype() ) { case StanzaIqResult: { Tag* q = stanza->findChild( "query", "xmlns", XMLNS_BYTESTREAMS ); if( !q || !m_socks5BytestreamHandler ) return false; Tag* s = q->findChild( "streamhost-used" ); if( !s || !s->hasAttribute( "jid" ) ) return false; const std::string & proxy = s->findAttribute( "jid" ); const StreamHost* sh = findProxy( stanza->from(), proxy, (*it).second ); if( sh ) { SOCKS5Bytestream* s5b = 0; bool selfProxy = ( proxy == m_parent->jid().full() && m_server ); if( selfProxy ) { SHA sha; sha.feed( (*it).second ); sha.feed( m_parent->jid().full() ); sha.feed( stanza->from().full() ); s5b = new SOCKS5Bytestream( this, m_server->getConnection( sha.hex() ), m_parent->logInstance(), m_parent->jid(), stanza->from(), (*it).second ); } else { s5b = new SOCKS5Bytestream( this, m_parent->connectionImpl()->newInstance(), m_parent->logInstance(), m_parent->jid(), stanza->from(), (*it).second ); StreamHostList shl; shl.push_back( *sh ); s5b->setStreamHosts( shl ); } m_s5bMap[(*it).second] = s5b; m_socks5BytestreamHandler->handleOutgoingSOCKS5Bytestream( s5b ); if( selfProxy ) s5b->activate(); } break; } case StanzaIqError: m_socks5BytestreamHandler->handleSOCKS5BytestreamError( stanza, (*it).second ); break; default: break; } break; } case S5BActivateStream: { switch( stanza->subtype() ) { case StanzaIqResult: { S5BMap::const_iterator it5 = m_s5bMap.find( (*it).second ); if( it5 != m_s5bMap.end() ) (*it5).second->activate(); break; } case StanzaIqError: m_socks5BytestreamHandler->handleSOCKS5BytestreamError( stanza, (*it).second ); break; default: break; } break; } default: break; } m_trackMap.erase( it ); return false; }