searchhandler.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 SEARCHHANDLER_H__
#define SEARCHHANDLER_H__
#include "stanza.h"
#include <string>
namespace gloox
{
class DataForm;
class SearchFieldStruct
{
public:
SearchFieldStruct() {}
SearchFieldStruct( const std::string& first, const std::string& last, const std::string& nick,
const std::string& email )
: m_first( first ), m_last( last ), m_nick( nick ), m_email( email )
{}
SearchFieldStruct( const Tag* tag )
{
if( !tag || tag->name() != "item" || !tag->hasAttribute( "jid" ) )
return;
m_jid.setJID( tag->findAttribute( "jid" ) );
const TagList& l = tag->children();
TagList::const_iterator it = l.begin();
for( ; it != l.end(); ++it )
{
if( (*it)->name() == "first" )
m_first = (*it)->cdata();
else if( (*it)->name() == "last" )
m_last = (*it)->cdata();
else if( (*it)->name() == "email" )
m_email = (*it)->cdata();
else if( (*it)->name() == "nick" )
m_nick = (*it)->cdata();
}
}
~SearchFieldStruct() {}
const std::string first() const { return m_first; }
const std::string last() const { return m_last; }
const std::string email() const { return m_email; }
const std::string nick() const { return m_nick; }
Tag* tag() const
{
Tag* t = new Tag( "item" );
t->addAttribute( "jid", m_jid.bare() );
new Tag( t, "first", m_first );
new Tag( t, "last", m_last );
new Tag( t, "nick", m_nick );
new Tag( t, "email", m_email );
return t;
}
private:
std::string m_first;
std::string m_last;
std::string m_nick;
std::string m_email;
JID m_jid;
};
enum SearchFieldEnum
{
SearchFieldFirst = 1,
SearchFieldLast = 2,
SearchFieldNick = 4,
SearchFieldEmail = 8
};
typedef std::list<const SearchFieldStruct*> SearchResultList;
class GLOOX_API SearchHandler
{
public:
virtual ~SearchHandler() {}
virtual void handleSearchFields( const JID& directory, int fields,
const std::string& instructions ) = 0;
virtual void handleSearchFields( const JID& directory, const DataForm* form ) = 0;
virtual void handleSearchResult( const JID& directory, const SearchResultList& resultList ) = 0;
virtual void handleSearchResult( const JID& directory, const DataForm* form ) = 0;
virtual void handleSearchError( const JID& directory, const Error* error ) = 0;
};
}
#endif // SEARCHHANDLER_H__
gloox::DataForm
An abstraction of a XEP-0004 Data Form.
Definition dataform.h:57
gloox::Error
A stanza error abstraction implemented as a StanzaExtension.
Definition error.h:35
gloox::JID
An abstraction of a JID.
Definition jid.h:31
gloox::SearchHandler
A virtual interface that enables objects to receive Jabber Search (XEP-0055) results.
Definition searchhandler.h:145
gloox::SearchHandler::handleSearchFields
virtual void handleSearchFields(const JID &directory, int fields, const std::string &instructions)=0
gloox::SearchHandler::~SearchHandler
virtual ~SearchHandler()
Definition searchhandler.h:150
gloox::SearchHandler::handleSearchError
virtual void handleSearchError(const JID &directory, const Error *error)=0
gloox::SearchHandler::handleSearchFields
virtual void handleSearchFields(const JID &directory, const DataForm *form)=0
gloox::SearchHandler::handleSearchResult
virtual void handleSearchResult(const JID &directory, const SearchResultList &resultList)=0
gloox::SearchHandler::handleSearchResult
virtual void handleSearchResult(const JID &directory, const DataForm *form)=0
gloox::Tag
This is an abstraction of an XML element.
Definition tag.h:47
gloox::Tag::addAttribute
bool addAttribute(Attribute *attr)
Definition tag.cpp:354
gloox
The namespace for the gloox library.
Definition adhoc.cpp:28
gloox::SearchFieldEnum
SearchFieldEnum
Definition searchhandler.h:124
gloox::SearchFieldNick
@ SearchFieldNick
Definition searchhandler.h:127
gloox::SearchFieldEmail
@ SearchFieldEmail
Definition searchhandler.h:128
gloox::SearchFieldLast
@ SearchFieldLast
Definition searchhandler.h:126
gloox::SearchFieldFirst
@ SearchFieldFirst
Definition searchhandler.h:125
gloox::TagList
std::list< Tag * > TagList
Definition tag.h:31
gloox::SearchResultList
std::list< const SearchFieldStruct * > SearchResultList
Definition searchhandler.h:134