~ubuntu-branches/ubuntu/vivid/gloox/vivid-proposed

« back to all changes in this revision

Viewing changes to src/carbons.cpp

  • Committer: Package Import Robot
  • Author(s): Vincent Cheng
  • Date: 2014-03-16 17:34:43 UTC
  • mfrom: (12.1.2 experimental)
  • mto: This revision was merged to the branch mainline in revision 15.
  • Revision ID: package-import@ubuntu.com-20140316173443-4s177dovzaz5dm8o
Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (c) 2013 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
 
 
14
#include "carbons.h"
 
15
 
 
16
#include "forward.h"
 
17
#include "util.h"
 
18
 
 
19
namespace gloox
 
20
{
 
21
  /* chat state type values */
 
22
  static const char* typeValues [] = {
 
23
    "received",
 
24
    "sent",
 
25
    "enable",
 
26
    "disable",
 
27
    "private"
 
28
  };
 
29
 
 
30
  Carbons::Carbons( Carbons::Type type )
 
31
    : StanzaExtension( ExtCarbons ), m_forward( 0 ), m_type( type )
 
32
  {
 
33
  }
 
34
 
 
35
  Carbons::Carbons( const Tag* tag )
 
36
    : StanzaExtension( ExtCarbons ), m_forward( 0 ), m_type( Invalid )
 
37
  {
 
38
    if( !tag )
 
39
      return;
 
40
 
 
41
    const std::string& name = tag->name();
 
42
    m_type = (Type)util::lookup( name, typeValues );
 
43
 
 
44
    switch( m_type )
 
45
    {
 
46
      case Sent:
 
47
      case Received:
 
48
      {
 
49
        Tag* f = tag->findChild( "forwarded", XMLNS, XMLNS_STANZA_FORWARDING );
 
50
        if( f )
 
51
          m_forward = new Forward( f );
 
52
        break;
 
53
      }
 
54
      default:
 
55
        break;
 
56
    }
 
57
  }
 
58
 
 
59
  Carbons::~Carbons()
 
60
  {
 
61
    delete m_forward;
 
62
  }
 
63
 
 
64
  const std::string& Carbons::filterString() const
 
65
  {
 
66
    static const std::string filter = "/message/*[@xmlns='" + XMLNS_MESSAGE_CARBONS + "']";
 
67
    return filter;
 
68
  }
 
69
 
 
70
  Stanza* Carbons::embeddedStanza() const
 
71
  {
 
72
    if( !m_forward || m_type == Invalid )
 
73
      return 0;
 
74
 
 
75
    return m_forward->embeddedStanza();
 
76
  }
 
77
 
 
78
  Tag* Carbons::embeddedTag() const
 
79
  {
 
80
    if( !m_forward || m_type == Invalid )
 
81
      return 0;
 
82
 
 
83
    return m_forward->embeddedTag();
 
84
  }
 
85
 
 
86
  Tag* Carbons::tag() const
 
87
  {
 
88
    if( m_type == Invalid )
 
89
      return 0;
 
90
 
 
91
    Tag* t = new Tag( util::lookup( m_type, typeValues ), XMLNS, XMLNS_MESSAGE_CARBONS );
 
92
    if( m_forward && ( m_type == Received || m_type == Sent ) )
 
93
      t->addChild( m_forward->tag() );
 
94
 
 
95
    return t;
 
96
  }
 
97
 
 
98
  StanzaExtension* Carbons::clone() const
 
99
  {
 
100
    return 0; // TODO
 
101
  }
 
102
 
 
103
}