gloox  1.0
receipt.cpp
1 /*
2  Copyright (c) 2007-2009 by Jakob Schroeter <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 (Receipt::ReceiptType)util::lookup( type, receiptValues );
29  }
30 
31  Receipt::Receipt( const Tag* tag )
33  m_rcpt( receiptType( tag->name() ) )
34  {
35  }
36 
37  const std::string& Receipt::filterString() const
38  {
39  static const std::string filter =
40  "/message/request[@xmlns='" + XMLNS_RECEIPTS + "']"
41  "|/message/received[@xmlns='" + XMLNS_RECEIPTS + "']";
42  return filter;
43  }
44 
45  Tag* Receipt::tag() const
46  {
47  if( m_rcpt == Invalid )
48  return 0;
49 
50  return new Tag( util::lookup( m_rcpt, receiptValues ), XMLNS, XMLNS_RECEIPTS );
51  }
52 
53 }