2012-07-23 7 views
0

내가 C++ gloox 라이브러리를 사용하기 위해 노력하고있어 먼저 내가 다른 주어진 예제를 시도 여기에 다음
https://github.com/knatten/blog.knatten.org/blob/master/gloox/bot.cpp왜 gloox가 작동하지 않습니까?

에서 예제를 실행하려고했으나 나는 심지어 내 클라이언트가 온라인 상태인지 볼 수 없습니다 ... 어떻게 적어도 현재 상태 정보를 보내고 온라인 상태가 될 수 있습니까? 컴퓨터에 문제가 있습니까? 우분투를 사용하고 있습니다. "콘솔에서

#include <gloox/client.h> 
#include <gloox/messagehandler.h> 
#include <gloox/message.h> 
#include <gloox/presencehandler.h> 
#include <gloox/connectionlistener.h> 
#include <iostream> 
#include <string> 
using namespace std; 
using namespace gloox; 
//my one 
const string LOGIN = "gmail.com"; 
ostream& operator<<(ostream& os, Message::MessageType type) { 
    switch (type) { 
     case Message::Chat: 
      os << "Chat"; 
      break; 
     case Message::Error: 
      os << "Error"; 
      break; 
     case Message::Groupchat: 
      os << "Groupchat"; 
      break; 
     case Message::Headline: 
      os << "Headline"; 
      break; 
     case Message::Normal: 
      os << "Normal"; 
      break; 
     case Message::Invalid: 
      os << "Invalid"; 
      break; 
     default: 
      os << "unknown type"; 
      break; 
    } 
return os; 
} 

ostream& operator<<(ostream& os, const Message& stanza) { 
    os << "type:'" << stanza.subtype() << "' from:'" << stanza.from().full() << "' body:'" << stanza.body() << "'"; 
    return os; 
} 

class Bot : public MessageHandler, 
      /*public PresenceHandler,*/ 
      public ConnectionListener 
      /*,public RosterListener*/{ 
public: 
    Bot(){ 
     JID jid("[email protected]/home"); 
     client = new Client(jid, "mmaaria123"); 
     client->registerConnectionListener(this); 
     client->registerMessageHandler(this); 
     client->connect(true); 
    } 

    virtual void onConnect() { 
     cout << "It is connected good:)" << endl; 
     sleep(5); 
     client->disconnect(); 
    } 

    virtual void onDisconnect(ConnectionError e) { 
     cout << "ConnListener::onDisconnect() " << endl; 
    } 

    virtual bool onTLSConnect(const CertInfo& Info) { 

     time_t tm = Info.date_from; 
     time_t tm_to = Info.date_to; 
     cout << "\t Certificate information to " << LOGIN << endl; 
     cout << "\t========================================" << endl; 
     // number code << "\tServer status: " << Info.status; 
     if (Info.status !=0) 
      { 
      cout << "\t !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl; 
      cout << "\t !!! The certificate has a problem !!!" << endl; 
      cout << "\t !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl; 
      // parsing binary Status Cert 
      if ((CertInvalid) & Info.status) 
       { 
        cout << "\t- The certificate is not trusted " << endl; 
       } 
      if ((CertSignerUnknown) & Info.status) 
       { 
        cout << "\t- The certificate hasn't got a kown issuer" << endl; 
       } 
      if ((CertRevoked) & Info.status) 
       { 
        cout << "\t- The certificate has been revoked " << endl; 
       } 
      if ((CertExpired) & Info.status) 
       { 
        cout << "\t- The certificate has expired " << endl; 
       } 
      if ((CertNotActive) & Info.status) 
       { 
        cout << "\t- The certificate is not yet active " << endl; 
       } 
      if ((CertWrongPeer) & Info.status) 
       { 
        cout << "\t- The certificate has not issued for the peer we're connected to " << endl; 
       } 
      if ((CertSignerNotCa) & Info.status) 
       { 
        cout << "\t- The signer is not CA " << endl; 
       } 
      cout << endl; 
      } 
      // end parsing 
     else 
      // if Info.status=0 sertificate is valide 
      cout << " *** Cert is OK!" << endl; 

     cout << "\tChain: " << Info.chain << endl; 
     cout << "\tIssuer: " << Info.issuer << endl; 
     cout << "\tServer: " << Info.server << endl; 
     cout << "\tCert date from: " << ctime(&tm); 
     cout << "\tCert date to: " << ctime(&tm_to); 
     cout << "\tProtocol: " << Info.protocol << endl; 
     cout << "\tCipher: " << Info.cipher << endl; 
     cout << "\tMAC: " << Info.mac << endl; 
     cout << "\tCompression: " << Info.compression << endl; 
     cout << "\t========================================" << endl; 
    return true; 

    } 

    virtual void handleMessage(const Message& stanza, 
           MessageSession* session = 0){ 
    Message msg(Message::Chat, stanza.from(), "hello world"); 
    client->send(msg); 
    } 

private: 
    Client* client; 
}; 

int main(int argc, char* argv[]){ 
    cout << "1" << endl; 
    Bot b; 
} 

은 인증서가 인증서가 kown 발행 이 없어하지만 onTLSConnect는 항상 true를 돌려 를 신뢰할 수없는 인쇄, 그래서 적어도 ... 알이 laest가 인쇄해야합니다 온라인해야한다 연결된 좋은 :) "

+0

코드의 모양은 어떻습니까? – RedX

+2

우분투 12.04 시스템에서 https://github.com/knatten/blog.knatten.org/blob/master/gloox/bot.cpp에서 컴파일 된 코드를 실행할 때 동일한 결과가 표시됩니다. 나는 우분투 10.04 시스템에서 같은 바이너리를 실행, 그냥 작동합니다. @Maria는 결국이 문제를 해결 했습니까? – Pelle

+0

12.04 32 비트를 사용하고 있습니까? 나는 12.04 이후로 비슷한 문제를 가지고 있지만, 64 비트에서는 모든 것이 잘 동작한다. – cronos

답변

0

코드를 확인하십시오. onTLSConnectreturn 문 하나만 가지고 있으며, 그 말은 return true;입니다. 어디서나 false을 반환하지 않습니다.

+0

예, 사실입니다. 하지만 이유가 될 수는 없습니다. 왜이 코드가 작동하지 않습니다 ... 이유는 우분투 또는 인터넷 연결입니다.하지만 정확한 것을 찾을 수는 없습니다 ... – Maria

+0

@Maria 그래서 문제가 있습니다. 그런데'onTLSConnect'는 실패해도 항상 true를 리턴합니까? –

+0

그는 컴퓨터에서 온라인 상태이지만 데비안의 다른 컴퓨터에서 실행되어 제대로 작동한다는 것을 알지 못합니다. – Maria