gloox  1.0.27
searchhandler.h
1 /*
2  Copyright (c) 2006-2023 by Jakob Schröter <js@camaya.net>
3  This file is part of the gloox library. http://camaya.net/gloox
4 
5  This software is distributed under a license. The full license
6  agreement can be found in the file LICENSE in this distribution.
7  This software may not be copied, modified, sold or distributed
8  other than expressed in the named license agreement.
9 
10  This software is distributed without any warranty.
11 */
12 
13 
14 #ifndef SEARCHHANDLER_H__
15 #define SEARCHHANDLER_H__
16 
17 #include "stanza.h"
18 
19 #include <string>
20 
21 namespace gloox
22 {
23 
24  class DataForm;
25 
34  {
35  public:
40 
44  SearchFieldStruct( const std::string& first, const std::string& last, const std::string& nick,
45  const std::string& email )
46  : m_first( first ), m_last( last ), m_nick( nick ), m_email( email )
47  {}
48 
52  SearchFieldStruct( const Tag* tag )
53  {
54  if( !tag || tag->name() != "item" || !tag->hasAttribute( "jid" ) )
55  return;
56 
57  m_jid.setJID( tag->findAttribute( "jid" ) );
58  const TagList& l = tag->children();
59  TagList::const_iterator it = l.begin();
60  for( ; it != l.end(); ++it )
61  {
62  if( (*it)->name() == "first" )
63  m_first = (*it)->cdata();
64  else if( (*it)->name() == "last" )
65  m_last = (*it)->cdata();
66  else if( (*it)->name() == "email" )
67  m_email = (*it)->cdata();
68  else if( (*it)->name() == "nick" )
69  m_nick = (*it)->cdata();
70  }
71  }
72 
76  ~SearchFieldStruct() {}
77 
81  const std::string first() const { return m_first; }
82 
86  const std::string last() const { return m_last; }
87 
91  const std::string email() const { return m_email; }
92 
96  const std::string nick() const { return m_nick; }
97 
101  Tag* tag() const
102  {
103  Tag* t = new Tag( "item" );
104  t->addAttribute( "jid", m_jid.bare() );
105  new Tag( t, "first", m_first );
106  new Tag( t, "last", m_last );
107  new Tag( t, "nick", m_nick );
108  new Tag( t, "email", m_email );
109  return t;
110  }
111 
112  private:
113  std::string m_first;
114  std::string m_last;
115  std::string m_nick;
116  std::string m_email;
117  JID m_jid;
118  };
119 
124  {
128  SearchFieldEmail = 8
129  };
130 
134  typedef std::list<const SearchFieldStruct*> SearchResultList;
135 
144  class GLOOX_API SearchHandler
145  {
146  public:
150  virtual ~SearchHandler() {}
151 
159  virtual void handleSearchFields( const JID& directory, int fields,
160  const std::string& instructions ) = 0;
161 
168  virtual void handleSearchFields( const JID& directory, const DataForm* form ) = 0;
169 
175  virtual void handleSearchResult( const JID& directory, const SearchResultList& resultList ) = 0;
176 
182  virtual void handleSearchResult( const JID& directory, const DataForm* form ) = 0;
183 
189  virtual void handleSearchError( const JID& directory, const Error* error ) = 0;
190 
191  };
192 
193 }
194 
195 #endif // SEARCHHANDLER_H__
An abstraction of a XEP-0004 Data Form.
Definition: dataform.h:57
A stanza error abstraction implemented as a StanzaExtension.
Definition: error.h:35
An abstraction of a JID.
Definition: jid.h:31
bool setJID(const std::string &jid)
Definition: jid.cpp:21
const std::string & bare() const
Definition: jid.h:67
A virtual interface that enables objects to receive Jabber Search (XEP-0055) results.
virtual void handleSearchFields(const JID &directory, int fields, const std::string &instructions)=0
virtual void handleSearchError(const JID &directory, const Error *error)=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
This is an abstraction of an XML element.
Definition: tag.h:47
bool addAttribute(Attribute *attr)
Definition: tag.cpp:354
bool hasAttribute(const std::string &name, const std::string &value=EmptyString) const
Definition: tag.cpp:602
const std::string & findAttribute(const std::string &name) const
Definition: tag.cpp:589
const std::string & name() const
Definition: tag.h:394
const TagList & children() const
Definition: tag.cpp:510
The namespace for the gloox library.
Definition: adhoc.cpp:28
@ SearchFieldNick
@ SearchFieldEmail
@ SearchFieldLast
@ SearchFieldFirst
std::list< Tag * > TagList
Definition: tag.h:26
std::list< const SearchFieldStruct * > SearchResultList