glooxd  0.3-svn
messagemanager.cpp
1 /*
2  Copyright (c) 2009 by Jakob Schroeter <js@camaya.net>
3  This file is part of the glooxd library. http://camaya.net/glooxd
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 "messagemanager.h"
15 #include "taghandler.h"
16 #include "rosterprovider.h"
17 #include "sm.h"
18 
19 #include <gloox/tag.h>
20 
21 #include <cstdio>
22 
23 namespace glooxd
24 {
25 
27  RosterProvider* rp )
28  : Plugin( sm, router ), m_handler( rp )
29  {
30  }
31 
33  {
34  }
35 
36  const std::string& MessageManager::filterString() const
37  {
38  static const std::string filter = "/message";
39  return filter;
40  }
41 
42  void MessageManager::getRoster( const gloox::JID& jid )
43  {
44  if( m_handler )
45  {
46  const Roster& rm = m_handler->getRoster( jid );
47  Roster::const_iterator it = rm.begin();
48  for( ; it != rm.end(); ++it )
49  {
50  switch( (*it).second )
51  {
52  case gloox::S10nBoth:
53  break;
54  case gloox::S10nNone:
55  break;
56  case gloox::S10nFrom:
57  break;
58  case gloox::S10nTo:
59  break;
60  default:
61  break;
62  }
63  }
64  }
65  }
66 
67  bool MessageManager::handleTag( const gloox::Tag* tag )
68  {
69  if( !tag || !m_handler )
70  return false;
71 
72 #ifdef DEBUG
73  printf( "received a message tag!!!!!!!!!! %s\n", tag->xml().c_str() );
74 #endif
75 
76  if( !m_sm.dispatchMessage( tag ) )
77  {
78  gloox::Tag* m = new gloox::Tag( "message" );
79  m->setXmlns( gloox::XMLNS_CLIENT );
80  m->addAttribute( "type", "error" );
81  m->addAttribute( "to", tag->findAttribute( "from" ) );
82  m->addAttribute( "from", tag->findAttribute( "to" ) );
83  m->addAttribute( "id", tag->findAttribute( "id" ) );
84  gloox::Tag* b = new gloox::Tag( m, "body" );
85  gloox::Tag* t = tag->findChild( "body" );
86  b->setCData( "The following message could not be delivered."
87  " The recipient is offline and offline storage is"
88  " not enabled (or not implemented...)."
89  + ( ( t ) ? " Your message:\n" + t->cdata() : gloox::EmptyString ) );
90  m_router.handleIncomingTag( m );
91  }
92 
93  return true;
94  }
95 
96 
97 }