Hi everybody,
I'm with a problem to connect a client gloox to the simpleserver provided
by glooxd (file /src/examples/simpleserver.cpp). I think that something in
the simpleserver may be wrong or missing.
The following line describes the error log:
*log: level: 0, area: 262144, <stream:error><not-authorized
xmlns='urn:ietf:params:xml:ns:xmpp-streams'/></stream:error>*
Do you happen to know what's going wrong?
The gloox client and the glooxd server are attached in this mail.
To compile simpleclient.cpp: g++ simpleclient.cpp -o simpleclient -lgloox
To run the server: ./simpleserver
To run the client: ./simpleclient user1@my_server localhost
--
Ivo Augusto Andrade Rocha Calado
MSc. Candidate
Embedded Systems and Pervasive Computing Lab - http://embedded.ufcg.edu.br
Systems and Computing Department - http://www.dsc.ufcg.edu.br
Electrical Engineering and Informatics Center - http://www.ceei.ufcg.edu.br
Federal University of Campina Grande - http://www.ufcg.edu.br
PGP: 0x03422935
Quidquid latine dictum sit, altum viditur.
#include <gloox/client.h>
#include <gloox/messagehandler.h>
#include <gloox/message.h>
#include <gloox/disco.h>
#include <iostream>
#include <stdio.h>
using namespace gloox;
using namespace std;
class Bot : public MessageHandler, TagHandler
{
public:
Bot(std::string user, std::string server_host)
{
JID jid( user + "/client" );
j = new Client(jid,"1");
j->setPort(5222);
j->setServer(server_host);
j->registerTagHandler(this, "stream", "http://etherx.jabber.org/streams");
j->registerMessageHandler( this );
j->disco()->setVersion( "messageTest", GLOOX_VERSION, "Linux" );
j->disco()->setIdentity( "client", "bot" );
j->disco()->addFeature( XMLNS_CHAT_STATES );
j->connect(false);
cout << "Press ENTER... to send msg." << endl;
getchar();
Tag *msg = new Tag( "message" );
msg->addAttribute( "from", user );
msg->addAttribute( "to", user );
msg->addAttribute( "id", "id1" );
msg->addAttribute( "body", "CODEC:MPG-4" );
j->send(msg);
cout << "Press Enter... to finish" << endl;
getchar();
}
virtual void handleTag(Tag *tag)
{
}
virtual void handleMessage( const Message& msg, MessageSession * /*session*/
)
{
printf( "type: %d, subject: %s, message: %s, thread id: %s\n",
msg.subtype(),
msg.subject().c_str(), msg.body().c_str(),
msg.thread().c_str() );
}
private:
Client* j;
};
int main( int argc, char* argv[] )
{
if (argc < 3)
std::cout << "Use: ./teste username server_host" << std::endl;
else
Bot b(argv[1], argv[2]);
}
/*
Copyright (c) 2008 by Jakob Schroeter <js@xxxxxxxxxx>
This file is part of the glooxd library. http://camaya.net/glooxd
This software is distributed under a license. The full license
agreement can be found in the file LICENSE in this distribution.
This software may not be copied, modified, sold or distributed
other than expressed in the named license agreement.
This software is distributed without any warranty.
*/
#ifndef SIMPLESERVER_H__
#define SIMPLESERVER_H__
#include "../authenticationhandler.h"
#include "../c2s.h"
#include "../certificateprovider.h"
#include "../rosterprovider.h"
#include <gloox/loghandler.h>
#include <gloox/jid.h>
#include <gloox/logsink.h>
#include <string>
/**
* @brief Implements a simple server using glooxd's components.
*
* @author Jakob Schroeter <js@xxxxxxxxxx>
*/
class GLOOXD_API SimpleServer : gloox::LogHandler,
glooxd::AuthenticationHandler, glooxd::RosterProvider,
glooxd::CertificateProvider
{
public:
/**
* Constructor.
*/
SimpleServer();
/**
* Destructor.
*/
~SimpleServer();
// reimplemented from AuthenticationHandler
virtual bool handleUserRequest( const gloox::JID& bare );
// reimplemented from AuthenticationHandler
virtual bool handleSASLPlain( const std::string& authzid,
const std::string& authcid,
const std::string& password );
// reimplemented from gloox::LogHandler
virtual void handleLog( gloox::LogLevel level, gloox::LogArea area, const
std::string& message );
// reimplemented from RosterProvider
virtual const glooxd::Roster getRoster( const gloox::JID& jid );
// reimplemented from CertificateProvider
virtual const std::string handleCertificateRequest( const std::string&
domain );
virtual const std::string handleKeyRequest( const std::string& domain );
private:
gloox::LogSink m_log;
};
#endif // SIMPLESERVER_H__
/*
Copyright (c) 2008-2009 by Jakob Schroeter <js@xxxxxxxxxx>
This file is part of the glooxd library. http://camaya.net/glooxd
This software is distributed under a license. The full license
agreement can be found in the file LICENSE in this distribution.
This software may not be copied, modified, sold or distributed
other than expressed in the named license agreement.
This software is distributed without any warranty.
*/
#include "simpleserver.h"
#include "../c2s.h"
#include "../certificategenerator.h"
#include "../discomanager.h"
#include "../configmanager.h"
#include "../featurestarttls.h"
#include "../featuresasl.h"
#include "../featurecompression.h"
#include "../featureresourcebind.h"
#include "../featuresession.h"
#include "../messagemanager.h"
#include "../presencemanager.h"
#include "../rostermanager.h"
#include "../router.h"
#include "../sm.h"
#include "../vcardmanager.h"
#include <gloox/gloox.h>
using namespace glooxd;
SimpleServer::SimpleServer()
{
m_log.registerLogHandler( gloox::LogLevelDebug,
gloox::LogAreaAll
| static_cast<gloox::LogArea>( LogAreaC2S )
| static_cast<gloox::LogArea>( LogAreaClient )
| static_cast<gloox::LogArea>( LogAreaSM )
| static_cast<gloox::LogArea>( LogAreaDM )
| static_cast<gloox::LogArea>( LogAreaRouter ),
this );
ConfigManager cm( m_log );
// Do not add domains just yet. They are pushed to components
// only once, so add them when all components are in place.
Router r( cm, m_log );
SM sm( r, cm, m_log, this );
sm.addPlugin( new RosterManager( sm, r, this ) );
sm.addPlugin( new PresenceManager( sm, r, this ) );
sm.addPlugin( new MessageManager( sm, r, this ) );
sm.addPlugin( new VCardManager( sm, r ) );
sm.addPlugin( new DiscoManager( sm, r ) );
// sm.addPlugin( new OfflineMessage( sm, r, this ) );
// sm.addPlugin( new PrivateXML( sm, r, this ) );
// sm.addPlugin( new Privacy( sm, r, this ) );
// etc
C2S c2s( r, cm, m_log, sm );
// c2s.registerStreamFeature( new FeatureSTARTTLS( true, this ) );
// c2s.registerStreamFeature( new FeatureSASL( this ) );
c2s.registerStreamFeature( new FeatureCompression() );
c2s.registerStreamFeature( new FeatureResourceBind( sm ) );
c2s.registerStreamFeature( new FeatureSession() );
// c2s.registerClientHandler( this );
// It's ok to add domains and interfaces now.
cm.addC2SInterface();
cm.bindDomain( "my_server", gloox::EmptyString);
//cm.bindDomain( "glooxd.im", gloox::EmptyString, 6222 );
//cm.bindDomain( "camaya.im", gloox::EmptyString, 6222 );
while( true )
{
r.run();
sm.run();
c2s.run();
}
}
SimpleServer::~SimpleServer()
{
}
bool SimpleServer::handleUserRequest( const gloox::JID& bare )
{
printf( "user account checked: %s\n", bare.full().c_str() );
return true;
}
bool SimpleServer::handleSASLPlain( const std::string& authzid,
const std::string& authcid,
const std::string& password )
{
printf( "SASL PLAIN requested:\n authzid: %s,\n authcid: %s,\n
password: %s\n", authzid.c_str(), authcid.c_str(), password.c_str() );
// Check credentials here. Return true if ok, false otherwise.
return true;
}
const Roster SimpleServer::getRoster( const gloox::JID& /*jid*/ )
{
glooxd::Roster rm;
rm.insert( std::make_pair( "user1@my_server", gloox::S10nBoth ) );
rm.insert( std::make_pair( "user2@my_server", gloox::S10nBoth ) );
//rm.insert( std::make_pair( "js@xxxxxxxxx", gloox::S10nBoth ) );
//rm.insert( std::make_pair( "hurkhurk@xxxxxxxxx", gloox::S10nBoth ) );
return rm;
}
const std::string SimpleServer::handleKeyRequest( const std::string& domain )
{
printf( "private key requested for %s\n", domain.c_str() );
return "/tmp/server.key";
}
const std::string SimpleServer::handleCertificateRequest( const std::string&
domain )
{
printf( "cert requested for %s\n", domain.c_str() );
// certificates should be cached, and possibly created upfront anyway
const std::string cert = "/tmp/" + domain + ".crt";
if( !util::generateCertificate( domain, "/tmp/server.key",
cert, 1024, 365, 1 ) )
{
printf( "generating cert for %s failed\n", domain.c_str() );
return gloox::EmptyString;
}
return cert;
}
void SimpleServer::handleLog( gloox::LogLevel level, gloox::LogArea area, const
std::string& message )
{
printf("log: level: %d, area: %d, %s\n", level, area, message.c_str() );
}
int main( int, char** )
{
SimpleServer s;
return 0;
}