15 #include "privacymanager.h"
16 #include "clientbase.h"
23 PrivacyManager::Query::Query(
const Tag* tag )
29 const TagList& l = tag->children();
30 TagList::const_iterator it = l.begin();
31 for( ; it != l.end(); ++it )
33 const std::string& name = (*it)->findAttribute(
"name" );
34 if( (*it)->name() ==
"default" )
36 else if( (*it)->name() ==
"active" )
38 else if( (*it)->name() ==
"list" )
40 m_names.push_back( name );
42 const TagList& l = (*it)->children();
43 TagList::const_iterator it_l = l.begin();
44 for( ; it_l != l.end(); ++it_l )
46 PrivacyItem::ItemType type;
47 PrivacyItem::ItemAction action;
50 const std::string& t = (*it_l)->findAttribute( TYPE );
52 type = PrivacyItem::TypeJid;
53 else if( t ==
"group" )
54 type = PrivacyItem::TypeGroup;
55 else if( t ==
"subscription" )
56 type = PrivacyItem::TypeSubscription;
58 type = PrivacyItem::TypeUndefined;
60 const std::string& a = (*it_l)->findAttribute(
"action" );
62 action = PrivacyItem::ActionAllow;
63 else if( a ==
"deny" )
64 action = PrivacyItem::ActionDeny;
66 action = PrivacyItem::ActionAllow;
68 const std::string& value = (*it_l)->findAttribute(
"value" );
70 const TagList& c = (*it_l)->children();
71 TagList::const_iterator it_c = c.begin();
72 for( ; it_c != c.end(); ++it_c )
74 if( (*it_c)->name() ==
"iq" )
75 packetType |= PrivacyItem::PacketIq;
76 else if( (*it_c)->name() ==
"presence-out" )
77 packetType |= PrivacyItem::PacketPresenceOut;
78 else if( (*it_c)->name() ==
"presence-in" )
79 packetType |= PrivacyItem::PacketPresenceIn;
80 else if( (*it_c)->name() ==
"message" )
81 packetType |= PrivacyItem::PacketMessage;
84 PrivacyItem item( type, action, packetType, value );
85 m_items.push_back( item );
91 PrivacyManager::Query::Query( IdType context,
const std::string& name,
92 const PrivacyListHandler::PrivacyList& list )
93 : StanzaExtension(
ExtPrivacy ), m_context( context ), m_items( list )
95 m_names.push_back( name );
98 PrivacyManager::Query::~Query()
102 const std::string& PrivacyManager::Query::filterString()
const
104 static const std::string filter =
"/iq/query[@xmlns='" +
XMLNS_PRIVACY +
"']";
108 Tag* PrivacyManager::Query::tag()
const
110 Tag* t =
new Tag(
"query" );
111 t->setXmlns( XMLNS_PRIVACY );
126 case PLUnsetActivate:
134 Tag* c =
new Tag( t, child );
136 if( !m_names.empty() )
137 c->addAttribute(
"name", (*m_names.begin()) );
140 PrivacyListHandler::PrivacyList::const_iterator it = m_items.begin();
141 for( ; it != m_items.end(); ++it )
143 Tag* i =
new Tag( c,
"item" );
145 switch( (*it).type() )
147 case PrivacyItem::TypeJid:
148 i->addAttribute( TYPE,
"jid" );
150 case PrivacyItem::TypeGroup:
151 i->addAttribute( TYPE,
"group" );
153 case PrivacyItem::TypeSubscription:
154 i->addAttribute( TYPE,
"subscription" );
160 switch( (*it).action() )
162 case PrivacyItem::ActionAllow:
163 i->addAttribute(
"action",
"allow" );
165 case PrivacyItem::ActionDeny:
166 i->addAttribute(
"action",
"deny" );
170 int pType = (*it).packetType();
173 if( pType & PrivacyItem::PacketMessage )
174 new Tag( i,
"message" );
175 if( pType & PrivacyItem::PacketPresenceIn )
176 new Tag( i,
"presence-in" );
177 if( pType & PrivacyItem::PacketPresenceOut )
178 new Tag( i,
"presence-out" );
179 if( pType & PrivacyItem::PacketIq )
183 i->addAttribute(
"value", (*it).value() );
184 i->addAttribute(
"order", ++count );
193 : m_parent( parent ), m_privacyListHandler( 0 )
211 std::string PrivacyManager::operation( IdType context,
const std::string& name )
213 const std::string&
id = m_parent->
getID();
215 if( context == PLRequestNames || context == PLRequestList )
217 IQ iq( iqType,
JID(),
id );
218 iq.addExtension(
new Query( context, name ) );
219 m_parent->
send( iq,
this, context );
228 const std::string&
id = m_parent->
getID();
232 m_parent->
send( iq,
this, PLStore );
240 || !q || q->name().empty() )
245 m_parent->
send( re );
251 if( !m_privacyListHandler )
This is the common base class for a Jabber/XMPP Client and a Jabber Component.
const std::string getID()
void removeIqHandler(IqHandler *ih, int exttype)
void removeIDHandler(IqHandler *ih)
void registerIqHandler(IqHandler *ih, int exttype)
void registerStanzaExtension(StanzaExtension *ext)
StanzaError error() const
An abstraction of an IQ stanza.
virtual void handlePrivacyList(const std::string &name, const PrivacyList &items)=0
std::list< PrivacyItem > PrivacyList
virtual void handlePrivacyListNames(const std::string &active, const std::string &def, const StringList &lists)=0
virtual void handlePrivacyListChanged(const std::string &name)=0
virtual void handlePrivacyListResult(const std::string &id, PrivacyListResult plResult)=0
virtual ~PrivacyManager()
virtual void handleIqID(const IQ &iq, int context)
virtual bool handleIq(const IQ &iq)
std::string store(const std::string &name, const PrivacyListHandler::PrivacyList &list)
void addExtension(const StanzaExtension *se)
const Error * error() const
const std::string & id() const
const StanzaExtension * findExtension(int type) const
The namespace for the gloox library.
std::list< Tag * > TagList
const std::string EmptyString
@ StanzaErrorItemNotFound
const std::string XMLNS_PRIVACY