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 )
50 const std::string& t = (*it_l)->findAttribute(
TYPE );
53 else if( t ==
"group" )
55 else if( t ==
"subscription" )
60 const std::string& a = (*it_l)->findAttribute(
"action" );
63 else if( a ==
"deny" )
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" )
76 else if( (*it_c)->name() ==
"presence-out" )
78 else if( (*it_c)->name() ==
"presence-in" )
80 else if( (*it_c)->name() ==
"message" )
84 PrivacyItem item( type, action, packetType, value );
85 m_items.push_back( item );
91 PrivacyManager::Query::Query( IdType context,
const std::string& name,
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" );
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() )
148 i->addAttribute(
TYPE,
"jid" );
151 i->addAttribute(
TYPE,
"group" );
154 i->addAttribute(
TYPE,
"subscription" );
160 switch( (*it).action() )
163 i->addAttribute(
"action",
"allow" );
166 i->addAttribute(
"action",
"deny" );
170 int pType = (*it).packetType();
174 new Tag( i,
"message" );
176 new Tag( i,
"presence-in" );
178 new Tag( i,
"presence-out" );
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 )