search.h
/*
Copyright (c) 2006-2023 by Jakob Schröter <js@camaya.net>
This file is part of the gloox library. http://camaya.net/gloox
This software is distributed under a license. The full license
agreement can be found in the file LICENSE in this distribution.
This software may not be copied, modified, sold or distributed
other than expressed in the named license agreement.
This software is distributed without any warranty.
*/
#ifndef SEARCH_H__
#define SEARCH_H__
#include "gloox.h"
#include "searchhandler.h"
#include "discohandler.h"
#include "iqhandler.h"
#include "stanzaextension.h"
#include "dataform.h"
#include <string>
namespace gloox
{
class ClientBase;
class IQ;
class Disco;
class GLOOX_API Search : public IqHandler
{
public:
Search( ClientBase* parent );
~Search();
void fetchSearchFields( const JID& directory, SearchHandler* sh );
void search( const JID& directory, DataForm* form, SearchHandler* sh );
void search( const JID& directory, int fields, const SearchFieldStruct& values, SearchHandler* sh );
// reimplemented from IqHandler.
virtual bool handleIq( const IQ& iq ) { (void)iq; return false; }
// reimplemented from IqHandler.
virtual void handleIqID( const IQ& iq, int context );
protected:
enum IdType
{
FetchSearchFields,
DoSearch
};
typedef std::map<std::string, SearchHandler*> TrackMap;
TrackMap m_track;
ClientBase* m_parent;
Disco* m_disco;
private:
#ifdef SEARCH_TEST
public:
#endif
class Query : public StanzaExtension
{
public:
Query( DataForm* form );
Query( int fields, const SearchFieldStruct& values );
Query( const Tag* tag = 0 );
virtual ~Query();
const DataForm* form() const { return m_form; }
const std::string& instructions() const { return m_instructions; }
int fields() const { return m_fields; }
const SearchResultList& result() const { return m_srl; }
// reimplemented from StanzaExtension
virtual const std::string& filterString() const;
// reimplemented from StanzaExtension
virtual StanzaExtension* newInstance( const Tag* tag ) const
{
return new Query( tag );
}
// reimplemented from StanzaExtension
virtual Tag* tag() const;
// reimplemented from StanzaExtension
virtual StanzaExtension* clone() const
{
Query* q = new Query();
q->m_form = m_form ? new DataForm( *m_form ) : 0;
q->m_fields = m_fields;
q->m_values = m_values;
q->m_instructions = m_instructions;
SearchResultList::const_iterator it = m_srl.begin();
for( ; it != m_srl.end(); ++it )
q->m_srl.push_back( new SearchFieldStruct( *(*it) ) );
return q;
}
private:
#ifdef SEARCH_TEST
public:
#endif
DataForm* m_form;
int m_fields;
SearchFieldStruct m_values;
std::string m_instructions;
SearchResultList m_srl;
};
};
}
#endif // SEARCH_H__
gloox::ClientBase
This is the common base class for a Jabber/XMPP Client and a Jabber Component.
Definition clientbase.h:79
gloox::DataForm
An abstraction of a XEP-0004 Data Form.
Definition dataform.h:57
gloox::Disco
This class implements XEP-0030 (Service Discovery) and XEP-0092 (Software Version).
Definition disco.h:46
gloox::IQ
An abstraction of an IQ stanza.
Definition iq.h:34
gloox::IqHandler
A virtual interface which can be reimplemented to receive IQ stanzas.
Definition iqhandler.h:32
gloox::JID
An abstraction of a JID.
Definition jid.h:31
gloox::SearchFieldStruct
Definition searchhandler.h:34
gloox::SearchHandler
A virtual interface that enables objects to receive Jabber Search (XEP-0055) results.
Definition searchhandler.h:145
gloox::Search::handleIq
virtual bool handleIq(const IQ &iq)
Definition search.h:93
gloox::Search::fetchSearchFields
void fetchSearchFields(const JID &directory, SearchHandler *sh)
Definition search.cpp:128
gloox::Search::search
void search(const JID &directory, DataForm *form, SearchHandler *sh)
Definition search.cpp:140
gloox::Search::Search
Search(ClientBase *parent)
Definition search.cpp:112
gloox
The namespace for the gloox library.
Definition adhoc.cpp:28
gloox::SearchResultList
std::list< const SearchFieldStruct * > SearchResultList
Definition searchhandler.h:134