gloox  1.0.28
receipt.cpp
1 /*
2  Copyright (c) 2007-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 #include "receipt.h"
14 #include "tag.h"
15 #include "util.h"
16 
17 namespace gloox
18 {
19 
20  /* chat state type values */
21  static const char* receiptValues [] = {
22  "request",
23  "received"
24  };
25 
26  static inline Receipt::ReceiptType receiptType( const std::string& type )
27  {
28  return static_cast<Receipt::ReceiptType>( util::lookup( type, receiptValues ) );
29  }
30 
31  Receipt::Receipt( const Tag* tag )
32  : StanzaExtension( ExtReceipt ), m_rcpt( Invalid )
33  {
34  if( !tag )
35  return;
36 
37  m_rcpt = receiptType( tag->name() );
38  m_id = tag->findAttribute( "id" );
39  }
40 
41  const std::string& Receipt::filterString() const
42  {
43  static const std::string filter =
44  "/message/request[@xmlns='" + XMLNS_RECEIPTS + "']"
45  "|/message/received[@xmlns='" + XMLNS_RECEIPTS + "']";
46  return filter;
47  }
48 
49  Tag* Receipt::tag() const
50  {
51  if( m_rcpt == Invalid )
52  return 0;
53 
54  Tag* tag = new Tag( util::lookup( m_rcpt, receiptValues ), XMLNS, XMLNS_RECEIPTS );
55  if ( !m_id.empty() )
56  tag->addAttribute( "id", m_id );
57  return tag;
58  }
59 
60 }
virtual const std::string & filterString() const
Definition: receipt.cpp:41
Receipt(const Tag *tag)
Definition: receipt.cpp:31
Tag * tag() const
Definition: receipt.cpp:49
This class abstracts a stanza extension, which is usually an XML child element in a specific namespac...
This is an abstraction of an XML element.
Definition: tag.h:47
bool addAttribute(Attribute *attr)
Definition: tag.cpp:354
const std::string & findAttribute(const std::string &name) const
Definition: tag.cpp:589
const std::string & name() const
Definition: tag.h:394
The namespace for the gloox library.
Definition: adhoc.cpp:28
const std::string XMLNS_RECEIPTS
Definition: gloox.cpp:98
const std::string XMLNS
Definition: gloox.cpp:122