16 #include "clientbase.h"
20 #include "mucmessagesession.h"
27 : m_parent( parent ), m_nick( nick ), m_joined( false ), m_roomHandler( mrh ),
29 m_historyType( HistoryUnknown ), m_historyValue( 0 ), m_flags( 0 ),
30 m_creationInProgress( false ), m_configChanged( false ),
31 m_publishNick( false ), m_publish( false ), m_unique( false )
53 if( m_joined || !m_parent )
62 Tag *x =
new Tag( s,
"x" );
64 if( !m_password.empty() )
65 new Tag( x,
"password", m_password );
68 switch( m_historyType )
72 Tag *h =
new Tag( x,
"history" );
78 Tag *h =
new Tag( x,
"history" );
84 Tag *h =
new Tag( x,
"history" );
90 Tag *h =
new Tag( x,
"history" );
111 Tag *x =
new Tag( s,
"x" );
131 Tag *d =
new Tag(
"destroy" );
135 if( !reason.empty() )
136 new Tag( d,
"reason", reason );
138 if( !password.empty() )
139 new Tag( d,
"password", password );
141 const std::string&
id = m_parent->
getID();
147 m_parent->
send( iq );
152 if( m_session && m_joined )
153 m_session->
send( message );
158 if( m_session && m_joined )
164 if( m_parent && m_joined )
168 Tag *p =
new Tag(
"presence" );
205 if( !m_parent || !m_joined )
208 Tag *m =
new Tag(
"message" );
210 Tag *x =
new Tag( m,
"x" );
212 Tag *i =
new Tag( x,
"invite" );
214 if( !reason.empty() )
215 new Tag( i,
"reason", reason );
217 new Tag( i,
"continue" );
226 Tag *x =
new Tag( m,
"x" );
228 Tag *d =
new Tag( x,
"decline" );
230 if( !reason.empty() )
231 new Tag( d,
"reason", reason );
239 m_publishNick = publishNick;
252 if( !m_joined || !m_parent )
255 Tag *m =
new Tag(
"message" );
258 new Tag( m,
"body", message );
259 Tag *x =
new Tag( m,
"x" );
269 m_historyType = type;
271 m_historyValue = value;
277 m_historySince = since;
292 if( !m_parent || !m_joined )
302 field->
setLabel(
"Requested role" );
306 Tag *m =
new Tag(
"messsage" );
328 void MUCRoom::ban(
const std::string& nick,
const std::string& reason )
335 modifyOccupant( nick, role,
"role", reason );
339 const std::string& reason )
341 modifyOccupant( nick, affiliation,
"affiliation", reason );
344 void MUCRoom::modifyOccupant(
const std::string& nick,
int state,
const std::string roa,
345 const std::string& reason )
347 if( !m_parent || !m_joined || nick.empty() || roa.empty() )
365 newRoA =
"participant";
369 newRoA =
"moderator";
400 Tag *i =
new Tag(
"item" );
401 i->addAttribute(
"nick", nick );
402 i->addAttribute( roa, newRoA );
403 if( !reason.empty() )
404 new Tag( i,
"reason", reason );
406 const std::string&
id = m_parent->
getID();
407 JID j( m_nick.
bare() );
410 m_parent->
trackID(
this,
id, action );
416 if( !m_parent || !m_joined || !m_roomConfigHandler )
419 Tag *i =
new Tag(
"item" );
447 const std::string&
id = m_parent->
getID();
451 m_parent->
trackID(
this,
id, operation );
452 m_parent->
send( iq );
457 if( !m_parent || !m_joined )
466 value =
"participant";
493 const std::string&
id = m_parent->
getID();
494 Tag *iq =
new Tag(
"iq" );
498 Tag *q =
new Tag( iq,
"query" );
501 MUCListItemList::const_iterator it = items.begin();
502 for( ; it != items.end(); ++it )
504 if( (*it).nick.empty() )
507 Tag *i =
new Tag( q,
"item" );
510 if( !(*it).reason.empty() )
511 new Tag( i,
"reason", (*it).reason );
514 m_parent->
trackID(
this,
id, operation );
515 m_parent->
send( iq );
518 void MUCRoom::handlePresence(
Stanza *stanza )
520 if( ( stanza->
from().
bare() != m_nick.
bare() ) || !m_roomHandler )
525 if( m_newNick.empty() )
541 MUCRoomParticipant party;
543 party.nick =
new JID( stanza->
from() );
548 Tag::TagList::const_iterator it = l.begin();
549 for( ; it != l.end(); ++it )
551 if( (*it)->name() ==
"item" )
553 const std::string&
affiliation = (*it)->findAttribute(
"affiliation" );
554 if( affiliation ==
"owner" )
556 else if( affiliation ==
"admin" )
558 else if( affiliation ==
"member" )
560 else if( affiliation ==
"outcast" )
565 const std::string&
role = (*it)->findAttribute(
"role" );
566 if( role ==
"moderator" )
568 else if( role ==
"participant" )
570 else if( role ==
"visitor" )
575 const std::string& jid = (*it)->findAttribute(
"jid" );
577 party.jid =
new JID( jid );
579 if( (*it)->hasChild(
"actor" ) )
581 const std::string& actor = (*it)->findChild(
"actor" )->findAttribute(
"jid" );
583 party.actor =
new JID( actor );
585 if( (*it)->hasChild(
"reason" ) )
587 party.reason = (*it)->findChild(
"reason" )->cdata();
589 party.newNick = (*it)->findAttribute(
"nick" );
591 else if( (*it)->name() ==
"status" )
593 const std::string& code = (*it)->findAttribute(
"code" );
596 else if( code ==
"101" )
600 else if( code ==
"110" )
604 m_affiliation = party.affiliation;
606 else if( code ==
"201" )
608 m_creationInProgress =
true;
612 else if( code ==
"210" )
614 else if( code ==
"301" )
616 else if( code ==
"303" )
618 else if( code ==
"307" )
620 else if( code ==
"321" )
623 else if( (*it)->name() ==
"destroy" )
625 if( (*it)->hasAttribute(
"jid" ) )
626 party.alternate =
new JID( (*it)->findAttribute(
"jid" ) );
628 if( (*it)->hasChild(
"reason" ) )
629 party.reason = (*it)->findChild(
"reason" )->cdata();
637 && party.newNick == m_newNick )
643 party.status = stanza->
status();
649 delete party.alternate;
656 if( !m_creationInProgress || !m_parent || !m_joined )
664 const std::string&
id = m_parent->
getID();
668 m_parent->
send( iq );
670 m_creationInProgress =
false;
675 if( !m_creationInProgress || !m_parent || !m_joined )
683 const std::string&
id = m_parent->
getID();
687 m_parent->
send( iq );
689 m_creationInProgress =
false;
694 if( !m_parent || !m_joined )
698 const std::string&
id = m_parent->
getID();
702 m_parent->
send( iq );
704 if( m_creationInProgress )
705 m_creationInProgress =
false;
710 if( !m_parent || !m_joined )
714 const std::string&
id = m_parent->
getID();
719 m_parent->
send( iq );
721 if( m_creationInProgress )
722 m_creationInProgress =
false;
725 void MUCRoom::setNonAnonymous()
732 void MUCRoom::setSemiAnonymous()
739 void MUCRoom::setFullyAnonymous()
746 void MUCRoom::handleMessage( Stanza *stanza, MessageSession * )
758 if( ( x = stanza->findChild(
"x",
"xmlns",
XMLNS_MUC_USER ) ) != 0 )
761 Tag::TagList::const_iterator it = l.begin();
762 for( ; it != l.end(); ++it )
764 if( (*it)->name() ==
"status" )
766 const std::string& code = (*it)->findAttribute(
"code" );
771 else if( code ==
"104" )
773 else if( code ==
"170" )
775 else if( code ==
"171" )
777 else if( code ==
"172" )
781 else if( code ==
"173" )
785 else if( code ==
"174" )
790 else if( (*it)->name() ==
"decline" )
793 JID invitee( (*it)->findAttribute(
"from" ) );
794 if( (*it)->hasChild(
"reason" ) )
795 reason = (*it)->findChild(
"reason" )->cdata();
802 else if( m_roomConfigHandler && ( x = stanza->findChild(
"x",
"xmlns",
XMLNS_X_DATA ) ) != 0 )
809 if( !stanza->subject().empty() )
811 m_roomHandler->
handleMUCSubject(
this, stanza->from().resource(), stanza->subject() );
813 else if( !stanza->body().empty() )
817 bool privMsg =
false;
818 bool history =
false;
819 if( ( x = stanza->findChild(
"x",
"xmlns",
XMLNS_X_DELAY ) ) != 0 )
821 from.setJID( x->findAttribute(
"from" ) );
822 when = x->findAttribute(
"stamp" );
829 m_roomHandler->
handleMUCMessage(
this, stanza->from().resource(), stanza->body(),
830 history, when, privMsg );
835 bool MUCRoom::handleIqID( Stanza *stanza,
int context )
837 if( !m_roomConfigHandler )
840 switch( stanza->subtype() )
843 return handleIqResult( stanza, context );
846 return handleIqError( stanza, context );
855 bool MUCRoom::handleIqResult( Stanza *stanza,
int context )
906 Tag::TagList::const_iterator it = items.begin();
907 for( ; it != items.end(); ++it )
911 item.role = getEnumRole( (*it)->findAttribute(
"role" ) );
912 item.affiliation = getEnumAffiliation( (*it)->findAttribute(
"affiliation" ) );
913 if( (*it)->hasAttribute(
"jid" ) )
914 item.jid =
new JID( (*it)->findAttribute(
"jid" ) );
915 item.nick = (*it)->findAttribute(
"nick" );
916 itemList.push_back( item );
920 MUCListItemList::iterator itl = itemList.begin();
921 for( ; itl != itemList.end(); ++itl )
933 bool MUCRoom::handleIqError( Stanza * ,
int context )
968 void MUCRoom::handleDiscoInfoResult( Stanza *stanza,
int context )
974 int oldflags = m_flags;
981 Tag *q = stanza->findChild(
"query" );
985 Tag::TagList::const_iterator it = l.begin();
986 for( ; it != l.end(); ++it )
988 if( (*it)->name() ==
"feature" )
990 if( (*it)->findAttribute(
"var" ) ==
"muc_hidden" )
992 else if( (*it)->findAttribute(
"var" ) ==
"muc_membersonly" )
994 else if( (*it)->findAttribute(
"var" ) ==
"muc_moderated" )
996 else if( (*it)->findAttribute(
"var" ) ==
"muc_nonanonymous" )
998 else if( (*it)->findAttribute(
"var" ) ==
"muc_open" )
1000 else if( (*it)->findAttribute(
"var" ) ==
"muc_passwordprotected" )
1002 else if( (*it)->findAttribute(
"var" ) ==
"muc_persistent" )
1004 else if( (*it)->findAttribute(
"var" ) ==
"muc_public" )
1006 else if( (*it)->findAttribute(
"var" ) ==
"muc_semianonymous" )
1008 else if( (*it)->findAttribute(
"var" ) ==
"muc_temporary" )
1010 else if( (*it)->findAttribute(
"var" ) ==
"muc_fullyanonymous" )
1011 setFullyAnonymous();
1012 else if( (*it)->findAttribute(
"var" ) ==
"muc_unmoderated" )
1014 else if( (*it)->findAttribute(
"var" ) ==
"muc_unsecured" )
1017 else if( (*it)->name() ==
"identity" )
1019 name = (*it)->findAttribute(
"name" );
1021 else if( (*it)->name() ==
"x" && (*it)->hasAttribute(
"xmlns",
XMLNS_X_DATA ) )
1023 df =
new DataForm( (*it) );
1036 void MUCRoom::handleDiscoItemsResult( Stanza *stanza,
int context )
1038 if( !m_roomHandler )
1045 Tag *q = stanza->findChild(
"query" );
1050 Tag::TagList::const_iterator it = l.begin();
1051 for( ; it != l.end(); ++it )
1053 if( (*it)->name() ==
"item" && (*it)->hasAttribute(
"jid" ) )
1055 items[(*it)->findAttribute(
"name" )] = (*it)->findAttribute(
"jid" );
1067 void MUCRoom::handleDiscoError( Stanza * ,
int context )
1069 if( !m_roomHandler )
1088 StringList MUCRoom::handleDiscoNodeFeatures(
const std::string& )
1093 StringMap MUCRoom::handleDiscoNodeIdentities(
const std::string& , std::string& )
1108 item.jid = m_nick.
bare();
1111 l.push_back( item );
1116 MUCRoomRole MUCRoom::getEnumRole(
const std::string& role )
1118 if( role ==
"moderator" )
1120 if( role ==
"participant" )
1122 if( role ==
"visitor" )
1129 if( affiliation ==
"owner" )
1131 if( affiliation ==
"admin" )
1133 if( affiliation ==
"member" )
1135 if( affiliation ==
"outcast" )