17 #include "clientbase.h"
25 Search::Query::Query( DataForm* form )
26 : StanzaExtension(
ExtSearch ), m_form( form ), m_fields( 0 )
30 Search::Query::Query(
int fields,
const SearchFieldStruct& values )
31 : StanzaExtension(
ExtSearch ), m_form( 0 ), m_fields( fields ), m_values( values )
35 Search::Query::Query(
const Tag* tag )
36 : StanzaExtension(
ExtSearch ), m_form( 0 ), m_fields( 0 )
38 if( !tag || tag->name() !=
"query" || tag->xmlns() != XMLNS_SEARCH )
41 const TagList& l = tag->children();
42 TagList::const_iterator it = l.begin();
43 for( ; it != l.end(); ++it )
45 if( (*it)->name() ==
"instructions" )
47 m_instructions = (*it)->cdata();
49 else if( (*it)->name() ==
"item" )
51 m_srl.push_back(
new SearchFieldStruct( (*it) ) );
53 else if( (*it)->name() ==
"first" )
55 else if( (*it)->name() ==
"last" )
57 else if( (*it)->name() ==
"email" )
59 else if( (*it)->name() ==
"nick" )
61 else if( !m_form && (*it)->name() ==
"x" && (*it)->xmlns() == XMLNS_X_DATA )
62 m_form =
new DataForm( (*it) );
66 Search::Query::~Query()
69 SearchResultList::iterator it = m_srl.begin();
70 for( ; it != m_srl.end(); ++it )
74 const std::string& Search::Query::filterString()
const
76 static const std::string filter =
"/iq/query[@xmlns='" +
XMLNS_SEARCH +
"']";
80 Tag* Search::Query::tag()
const
82 Tag* t =
new Tag(
"query" );
83 t->setXmlns( XMLNS_SEARCH );
85 t->addChild( m_form->tag() );
88 if( !m_instructions.empty() )
89 new Tag( t,
"instructions", m_instructions );
90 if( m_fields & SearchFieldFirst )
91 new Tag( t,
"first", m_values.first() );
92 if( m_fields & SearchFieldLast )
93 new Tag( t,
"last", m_values.last() );
94 if( m_fields & SearchFieldNick )
95 new Tag( t,
"nick", m_values.nick() );
96 if( m_fields & SearchFieldEmail )
97 new Tag( t,
"email", m_values.email() );
99 else if( !m_srl.empty() )
101 SearchResultList::const_iterator it = m_srl.begin();
102 for( ; it != m_srl.end(); ++it )
104 t->addChild( (*it)->tag() );
130 if( !m_parent || !directory || !sh )
133 const std::string&
id = m_parent->
getID();
137 m_parent->
send( iq,
this, FetchSearchFields );
142 if( !m_parent || !directory || !sh )
145 const std::string&
id = m_parent->
getID();
150 m_parent->
send( iq,
this, DoSearch );
155 if( !m_parent || !directory || !sh )
158 const std::string&
id = m_parent->
getID();
164 m_parent->
send( iq,
this, DoSearch );
169 TrackMap::iterator it = m_track.find( iq.
id() );
170 if( it != m_track.end() )
182 case FetchSearchFields:
186 (*it).second->handleSearchFields( iq.
from(), q->form() );
190 (*it).second->handleSearchFields( iq.
from(), q->fields(), q->instructions() );
198 (*it).second->handleSearchResult( iq.
from(), q->form() );
202 (*it).second->handleSearchResult( iq.
from(), q->result() );
210 (*it).second->handleSearchError( iq.
from(), iq.
error() );
This is the common base class for a Jabber/XMPP Client and a Jabber Component.
const std::string getID()
void removeIDHandler(IqHandler *ih)
bool removeStanzaExtension(int ext)
void registerStanzaExtension(StanzaExtension *ext)
An abstraction of an IQ stanza.
A virtual interface that enables objects to receive Jabber Search (XEP-0055) results.
void fetchSearchFields(const JID &directory, SearchHandler *sh)
virtual void handleIqID(const IQ &iq, int context)
void search(const JID &directory, DataForm *form, SearchHandler *sh)
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 XMLNS_SEARCH