glooxd  0.3-svn
glooxd.cpp
1 /*
2  Copyright (c) 2008-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 "glooxd.h"
15 
16 #include <gloox/error.h>
17 #include <gloox/iq.h>
18 #include <gloox/message.h>
19 #include <gloox/presence.h>
20 #include <gloox/tag.h>
21 
22 namespace glooxd
23 {
24 
25  const std::string XMLNS_SERVER = "jabber:server";
26  const std::string XMLNS_GLOOXD = "http://camaya.net/glooxd";
27 
28  const std::string XMPP_STREAM_VERSION_MAJOR = "1";
29  const std::string XMPP_STREAM_VERSION_MINOR = "0";
30  const std::string GLOOXD_VERSION = "0.3-svn";
31  const std::string GLOOXD_DOMAIN = "glooxd";
32 
33  gloox::Tag* returnError( const gloox::Tag* tag, gloox::StanzaError se, gloox::StanzaErrorType type )
34  {
35  gloox::Tag* t = 0;
36 
37  if( !tag )
38  return t;
39 
40  const std::string& name = tag->name();
41  const std::string& from = tag->findAttribute( "from" );
42  const std::string& to = tag->hasAttribute( "to" ) ? tag->findAttribute( "to" ) : from;
43  if( name == "message" )
44  {
45  gloox::Message msg( gloox::Message::Error, from );
46  msg.setFrom( to );
47  msg.addExtension( new gloox::Error( type, se ) );
48  t = msg.tag();
49  }
50  else if( name == "iq" )
51  {
52  gloox::IQ iq( gloox::IQ::Error, from,
53  tag->findAttribute( "id" ) );
54  iq.setFrom( to );
55  iq.addExtension( new gloox::Error( type, se ) );
56  t = iq.tag();
57  }
58  else if( name == "presence" )
59  {
60  gloox::Presence p(gloox::Presence::Error, from );
61  p.setFrom( to );
62  p.addExtension( new gloox::Error( type, se ) );
63  t = p.tag();
64  }
65 
66  return t;
67  }
68 
69 }
70 
71 const char* glooxd_version()
72 {
73  return glooxd::GLOOXD_VERSION.c_str();
74 }