added for plugins own dir

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1850 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
defnax 2009-11-28 14:21:11 +00:00
parent 97d8640f3a
commit 87344de7d4
809 changed files with 790 additions and 722 deletions

View file

@ -0,0 +1,338 @@
/***************************************************************************
* Copyright (C) 2008 by normal *
* normal@Desktop2 *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "ConnectionI2P.h"
cConnectionI2P::cConnectionI2P(
QString SamHost,
QString SamPort,
SESSION_Types::SESSION_STYLE SessionStyle,
QString SessionDestination,
SESSION_Types::SESSION_DIRECTION SessionDirection,
QString SessionOptions,
QObject *parent)
:SamHost(SamHost),SamPort(SamPort),SessionStyle(SessionStyle),SessionDestination(SessionDestination),
SessionDirection(SessionDirection),SessionOptions(SessionOptions)//, QObject(parent)
{
IncomingPackets= new QByteArray();
tcpSocket= new QTcpSocket(parent);
tcpSocket->moveToThread(this->thread());
Analyser= new I2PSamMessageAnalyser();
this->HandShakeWasSuccesfullDone=false;
this->SessionWasSuccesfullCreated=false;
this->nextFreeID=1;
connect(tcpSocket,SIGNAL(connected() ),this,SLOT(connected() ),Qt::DirectConnection );
connect(tcpSocket,SIGNAL(readyRead() ),this, SLOT(readFromSocket()),Qt::DirectConnection);
}
cConnectionI2P::~cConnectionI2P()
{
doDisconnect();
delete tcpSocket;
delete Analyser;
}
void cConnectionI2P::doConnect()
{
if(tcpSocket->state()==QAbstractSocket::UnconnectedState)
{
tcpSocket->connectToHost(SamHost,SamPort.toInt( ));
}
if(!tcpSocket->waitForConnected(1000))
doDisconnect();
}
void cConnectionI2P::doDisconnect()
{
if(tcpSocket->state()!=0)
{
tcpSocket->disconnectFromHost();
emit debugMessages("<-- I2P Socket Disconnected -->\n");
}
else if(tcpSocket->state()==QAbstractSocket::UnconnectedState)
emit debugMessages("<-- I2P Socket Disconnected -->\n");
this->nextFreeID=1;
}
void cConnectionI2P::connected()
{
emit debugMessages("<-- I2P Socket Connected -->\n");
//emit debugMessages("<-- SAM Connection Handshake send -->\n");
emit debugMessages(SAM_HANDSHAKE);
if(tcpSocket->state()==QAbstractSocket::ConnectedState)
{
tcpSocket->write(SAM_HANDSHAKE);
tcpSocket->flush();
}
}
void cConnectionI2P::readFromSocket()
{
using namespace SAM_Message_Types;
QByteArray newData =tcpSocket->readAll();
QByteArray CurrentPacket;
IncomingPackets->append(newData);
while(IncomingPackets->contains("\n")==true){
CurrentPacket=IncomingPackets->left(IncomingPackets->indexOf("\n",0)+1);
//else return;//Not the complead Packet recived ??? maybe possible ???
QString t(CurrentPacket.data());
SAM_MESSAGE sam=Analyser->Analyse(t);
switch(sam.type)
{ //emit the signals
case HELLO_REPLAY:{
emit debugMessages(t);
emit HelloReplayRecived(sam.result);
if(sam.result==OK){
this->HandShakeWasSuccesfullDone=true;
doSessionCreate();
}
break;
}
case SESSION_STATUS:{
emit debugMessages(t);
if(sam.result==OK)this->SessionWasSuccesfullCreated=true;
emit SessionStatusRecived(sam.result,sam.Destination,sam.Message);
break;
}
case STREAM_STATUS:{
emit debugMessages(t);
if(sam.result==OK)
this->doSendStreamSessionLimit(sam.ID,0);
emit StreamStatusRecived(sam.result,sam.ID,sam.Message);
break;
}
case STREAM_CONNECTED:{
emit debugMessages(t);
this->doSendStreamSessionLimit(sam.ID,0);
emit StreamConnectedRecived(sam.Destination,sam.ID);
break;
}
case STREAM_CLOSED:{
emit debugMessages(t);
emit StreamClosedRecived(sam.result,sam.ID,sam.Message);
break;
}
case STREAM_SEND:{
emit debugMessages(t);
emit StreamSendRecived(sam.ID,sam.result,sam.state);
break;
}
case STREAM_READY_TO_SEND:{
emit debugMessages(t);
emit StreamReadyToSendRecived(sam.ID);
break;
}
case NAMING_REPLY:{
emit debugMessages(t);
emit NamingReplyRecived(sam.result,sam.Name,sam.Value,sam.Message);
break;
}
case STREAM_RECEIVED:{
if( sam.Size.toLong() > (IncomingPackets->length() - CurrentPacket.length()) )
return;//Not the complead Packet recived ??? maybe possible ???
QByteArray Data=IncomingPackets->mid(CurrentPacket.length(),sam.Size.toLong());
emit debugMessages(t+Data);
emit StreamDataRecived(sam.ID,sam.Size,Data);
IncomingPackets->remove(CurrentPacket.length(),sam.Size.toLong());
break;
}
case ERROR_IN_ANALYSE:{
emit debugMessages("<ERROR_IN_ANALYSE>\n"+t);
break;
}
default:
{
emit debugMessages("<Unknown Packet>\n"+t);
break;
}
}
IncomingPackets->remove(0,IncomingPackets->indexOf("\n",0)+1);
}//while
}
void cConnectionI2P::doSessionCreate(){
using namespace SESSION_Types;
ConnectionReadyCheck();
QByteArray Message="SESSION CREATE STYLE=";
switch(this->SessionStyle)
{
case STREAM:
{
Message+="STREAM";
break;
}
case DATAGRAMM:
{
Message+="DATAGRAMM";
break;
}
case RAW:
{
Message+="RAW";
break;
}
}
Message+=" DESTINATION="+this->SessionDestination+" DIRECTION=";
switch(this->SessionDirection)
{
case BOTH:
{
Message+="BOTH";
break;
}
case RECEIVE:
{
Message+="RECEIVE";
break;
}
case CREATE:
{
Message+="CREATE";
break;
}
}
if(this->SessionOptions.isEmpty()==false)
Message+=" "+SessionOptions;
Message+="\n";
//emit debugMessages("<-Send Create Session Message->\n");
emit debugMessages(Message);
tcpSocket->write(Message);
tcpSocket->flush();
}
qint32 cConnectionI2P::get_NextFreeId()
{
return nextFreeID++;
}
qint32 cConnectionI2P::doStreamConnect(QString Destination)
{
ConnectionReadyCheck();
qint32 ID=get_NextFreeId();
QByteArray Message="STREAM CONNECT ID=";
Message+=QString::number(ID,10);
Message+=" DESTINATION="+Destination+"\n";
emit debugMessages(Message);
tcpSocket->write(Message);
tcpSocket->flush();
return ID;
}
void cConnectionI2P::doStreamClose(qint32 ID)
{
ConnectionReadyCheck();
QByteArray Message="STREAM CLOSE ID=";
Message+=QString::number(ID,10)+"\n";
emit debugMessages(Message);
tcpSocket->write(Message);
tcpSocket->flush();
}
void cConnectionI2P::doSendStreamSessionLimit(qint32 ID,quint64 value)
{
ConnectionReadyCheck();
QByteArray Message="STREAM RECEIVE ID=";
Message+=QString::number(ID,10)+" LIMIT=";
if(value==0)
Message+="NONE\n";
else
{
QString Svalue;
Svalue.setNum(value,10);
Message+=Svalue+"\n";
}
emit debugMessages(Message);
tcpSocket->write(Message);
tcpSocket->flush();
}
void cConnectionI2P::doStreamSend(qint32 ID,QString Data)
{
QByteArray t="";
t.insert(0,Data);
doStreamSend(ID,t);
}
void cConnectionI2P::doStreamSend(qint32 ID,QByteArray Data)
{
ConnectionReadyCheck();
QString Size;
Size.setNum(Data.length());
QByteArray Message="STREAM SEND ID=";
Message+=QString::number(ID,10)+" SIZE="+Size+"\n";
Message.append(Data+="\n");
emit debugMessages(Message);
tcpSocket->write(Message);
tcpSocket->flush();
}
void cConnectionI2P::doNamingLookUP(QString Name)
{
ConnectionReadyCheck();
QByteArray Message="NAMING LOOKUP NAME=";
Message+=Name+"\n";
emit debugMessages(Message);
tcpSocket->write(Message);
tcpSocket->flush();
}

View file

@ -0,0 +1,123 @@
/***************************************************************************
* Copyright (C) 2008 by normal *
* normal@Desktop2 *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef CONENCTIONI2P_H
#define CONENCTIONI2P_H
#include <QtGui>
#include <QTcpSocket>
#include <Qt>
#include <QSocketNotifier>
#include "I2PSamMessageAnalyser.h"
#define SAM_HANDSHAKE "HELLO VERSION MIN=2.0 MAX=2.0\n"
namespace SESSION_Types
{
enum SESSION_STYLE
{
STREAM,
DATAGRAMM,
RAW
};
enum SESSION_DIRECTION
{
BOTH,
RECEIVE,
CREATE
};
};
//class cConnectionI2P
//
//Handshake with SAM an Session Creation are done atomatically
//all STREAMs will be init with no limit | limit is possible with the function doSendStreamSessionLimit
//
class cConnectionI2P :public QObject
{
Q_OBJECT
public:
cConnectionI2P( QString SamHost,
QString SamPort,
SESSION_Types::SESSION_STYLE SessionStyle,
QString SessionDestination,
SESSION_Types::SESSION_DIRECTION SessionDirection,
QString SessionOptions="",
QObject *parent = 0
);
~cConnectionI2P();
public slots:
void doConnect();
void doDisconnect();
qint32 doStreamConnect(QString Destination);//base64key || return the new id for the stream
void doStreamSend(qint32 ID,QByteArray Data);
void doStreamSend(qint32 ID,QString Data);
void doStreamClose(qint32 ID);
void doSendStreamSessionLimit(qint32 ID,quint64 value=0);
void doNamingLookUP(QString Name);
private slots:
void connected();
void readFromSocket();
signals:
void debugMessages(const QString Message);
void HelloReplayRecived(const SAM_Message_Types::RESULT result);
void SessionStatusRecived(const SAM_Message_Types::RESULT result,const QString Destination,const QString Message);
void StreamStatusRecived(const SAM_Message_Types::RESULT result,const qint32 ID,QString Message);
void StreamConnectedRecived(const QString Destinaton,const qint32 ID);
void StreamSendRecived(const qint32 ID,const SAM_Message_Types::RESULT result,SAM_Message_Types::STATE state);
void StreamClosedRecived(const SAM_Message_Types::RESULT result,qint32 ID,QString Message);
void StreamReadyToSendRecived(const qint32 ID);
void StreamDataRecived(const qint32 ID,const QString Size,const QByteArray Data);
void NamingReplyRecived(const SAM_Message_Types::RESULT result,QString Name,QString Value="",QString Message="");
private:
const QString SamHost;
const QString SamPort;
qint32 nextFreeID;
QByteArray* IncomingPackets;
QTcpSocket* tcpSocket;
I2PSamMessageAnalyser* Analyser;
bool HandShakeWasSuccesfullDone;
bool SessionWasSuccesfullCreated;
const SESSION_Types::SESSION_STYLE SessionStyle;
const QString SessionDestination;
const SESSION_Types::SESSION_DIRECTION SessionDirection;
const QString SessionOptions;
void doSessionCreate();
qint32 get_NextFreeId();
inline void ConnectionReadyCheck()
{
if( HandShakeWasSuccesfullDone==false ||
SessionWasSuccesfullCreated==false||
tcpSocket->state()!=QAbstractSocket::ConnectedState)
return;
}
};
#endif

View file

@ -0,0 +1,962 @@
/***************************************************************************
* Copyright (C) 2008 by normal *
* normal@Desktop2 *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "Core.h"
cCore::cCore(){
init();
}
cCore::~cCore(){
this->UserConnectThread->stop();
this->saveUserList();
this->closeAllActiveConnections();
for(int i=0;i<this->users.count();i++)
delete users.at(i);
QList<cPacketManager*>::Iterator it;
for(it=DataPacketsManagers.begin(); it<DataPacketsManagers.end() ;++it){
DataPacketsManagers.erase(it);
}
delete this->DebugMessageHandler;
delete this->Protocol;
delete this->I2P;
delete this->SoundManager;
}
cDebugMessageManager* cCore::get_DebugMessageHandler(){
return this->DebugMessageHandler;
}
bool cCore::addNewUser(QString Name,QString I2PDestination,qint32 I2PStream_ID){
//TODO I2PDestination verify check
//check if user already exist
if(I2PDestination.length()!=516){
//Destination must be 516 length
return false;
}
if(!I2PDestination.right(4).contains("AAAA",Qt::CaseInsensitive)){
//the last 4 char must be "AAAA"
return false;
}
if(I2PDestination.length()>0)
if(this->doesUserAllReadyExitsByI2PDestination(I2PDestination)==true)
return false;
//add newuser
cUser* newuser=new cUser(Protocol,Name,I2PDestination,I2PStream_ID);
connect(newuser,SIGNAL(newIncomingMessageRecived()),SoundManager,
SLOT(event_NewChatMessage()));
connect(newuser,SIGNAL(connectionOnline()),SoundManager,
SLOT(event_User_go_Online()));
connect(newuser,SIGNAL(connectionOffline()),SoundManager,
SLOT(event_User_go_Offline()));
this->users.append(newuser);
saveUserList();
emit eventUserChanged();
return true;
}
bool cCore::deleteUserByI2PDestination(QString I2PDestination){
for(int i=0;i<users.count();i++){
if(users.at(i)->get_I2PDestination()==I2PDestination){
if(users.at(i)->get_ConnectionStatus()==ONLINE ||users.at(i)->get_ConnectionStatus()==TRYTOCONNECT)
{
this->StreamClose(users.at(i)->get_I2PStreamID());
deletePacketManagerByID(users.at(i)->get_I2PStreamID());
}
users.removeAt(i);
saveUserList();
emit eventUserChanged();
return true;
}
}
return false;
}
bool cCore::doesUserAllReadyExitsByI2PDestination(const QString I2PDestination){
if(I2PDestination==MyDestination) return true;
for(int i=0;i<users.count();i++){
if(users.at(i)->get_I2PDestination()==I2PDestination){
return true;
}
}
return false;
}
void cCore::doNamingLookUP(QString Name){
I2P->doNamingLookUP(Name);
}
void cCore::init(){
using namespace SESSION_Types;
this->MyDestination="";
this->currentOnlineStatus=User::USERTRYTOCONNECT;
QSettings* settings= new QSettings(QApplication::applicationDirPath()+"/application.ini",QSettings::IniFormat);
settings->beginGroup("Network");
this->I2P= new cConnectionI2P( settings->value("SamHost","127.0.0.1").toString(),
settings->value("SamPort","7656").toString(),
STREAM,
settings->value("Destination","test").toString(),
BOTH,
settings->value("SessionOptionString","").toString()
,this);
this->I2P=I2P;
//signals from I2PConnection Core
connect (I2P,SIGNAL(StreamClosedRecived(const SAM_Message_Types::RESULT, qint32, QString)),this,
SLOT(StreamClosedRecived(const SAM_Message_Types::RESULT, qint32, QString)),Qt::DirectConnection);
connect (I2P,SIGNAL(StreamStatusRecived(const SAM_Message_Types::RESULT, const qint32, const QString)),this,
SLOT(StreamStatusRecived(const SAM_Message_Types::RESULT, const qint32, QString)),Qt::DirectConnection);
connect (I2P,SIGNAL(SessionStatusRecived(const SAM_Message_Types::RESULT, const QString, const QString)),this,
SLOT(SessionStatusRecived(const SAM_Message_Types::RESULT, const QString, QString)),Qt::DirectConnection);
connect (I2P,SIGNAL(StreamConnectedRecived(const QString, const qint32)),this,
SLOT(StreamConnectedRecived(const QString, const qint32)),Qt::DirectConnection);
connect (I2P,SIGNAL(StreamReadyToSendRecived(const qint32)),this,
SLOT(StreamReadyToSendRecived(const qint32)),Qt::DirectConnection);
connect (I2P,SIGNAL(StreamSendRecived(const qint32, const SAM_Message_Types::RESULT, SAM_Message_Types::STATE)),this,
SLOT(StreamSendRecived(const qint32, const SAM_Message_Types::RESULT, SAM_Message_Types::STATE)),Qt::DirectConnection);
connect (I2P,SIGNAL(StreamDataRecived(const qint32, const QString, const QByteArray)),this,
SLOT(StreamDataRecived(const qint32, const QString, const QByteArray)),Qt::DirectConnection);
connect (I2P,SIGNAL(NamingReplyRecived(const SAM_Message_Types::RESULT, QString, QString, QString)),this,
SLOT(NamingReplyRecived(const SAM_Message_Types::RESULT, QString, QString, QString)),Qt::DirectConnection);
this->SoundManager=new cSoundManager();
this->DebugMessageHandler= new cDebugMessageManager(I2P);
this->Protocol= new cProtocol(this);
this->loadUserList();
this->I2P->doConnect();
this->UserConnectThread= new cUserConnectThread(this,settings->value("Waittime_between_rechecking_offline_users","30000").toInt());
delete settings;
}
void cCore::saveUserList(){
QFile file(QApplication::applicationDirPath()+"/users.config");
file.open(QIODevice::WriteOnly | QIODevice::Text);
QTextStream out(&file);
for(int i=0;i<this->users.count();i++){
out<<"Nick:\t"<<(users.at(i)->get_Name())<<endl
<<"I2PDest:\t"<<(users.at(i)->get_I2PDestination())<<endl;
}
out.flush();
file.close();
}
void cCore::loadUserList(){
QFile file(QApplication::applicationDirPath()+"/users.config");
if (!file.open(QIODevice::ReadOnly|QIODevice::Text))
return;
QTextStream in(&file);
in.skipWhiteSpace();
QString NickName;QString I2PDest;
while (!in.atEnd()) {
QString line = in.readLine();
QStringList temp=line.split("\t");
if(temp[0]=="Nick:")NickName=temp[1];
if(temp[0]=="I2PDest:"){
I2PDest=temp[1];
this->addNewUser(NickName,I2PDest);
NickName.clear();
I2PDest.clear();
}
else if(temp[0]=="TorDest:"){
//ignore it
}
file.close();
}
}
void cCore::StreamClosedRecived(const SAM_Message_Types::RESULT result,qint32 ID,QString Message){
if(isThisID_a_FileSendID(ID)){
//FileSend
for(int i=0;i<FileSends.size();i++){
if(FileSends.at(i)->get_StreamID()==ID){
FileSends.at(i)->StreamClosed(result,ID,Message);
FileSends.removeAt(i);
return;
}
}
}
else if(isThisID_a_FileReciveID(ID)){
//Filerecive
for(int i=0;i<FileRecives.size();i++){
if(FileRecives.at(i)->get_StreamID()==ID){
FileRecives.at(i)->StreamClosed(result,ID,Message);
FileRecives.removeAt(i);
return;
}
}
}
else if(this->isThisIDunknown(ID)==true){
//if ID=UnKnown then remove the ID
this->removeUnknownID(ID);
}
//known ID
for(int i=0;i<users.count();i++){
if(users.at(i)->get_I2PStreamID()==ID){
if( result==SAM_Message_Types::OK ||
result==SAM_Message_Types::CANT_REACH_PEER ||
result==SAM_Message_Types::TIMEOUT
){
users.at(i)->set_ConnectionStatus(OFFLINE);
break;
}
else {
//on I2P_ERROR or PEER_NOT_FOUND
users.at(i)->set_ConnectionStatus(ERROR);
break;
}
}
}
deletePacketManagerByID(ID);
emit eventUserChanged();
}
void cCore::StreamStatusRecived(const SAM_Message_Types::RESULT result,const qint32 ID,QString Message){
if(isThisID_a_FileSendID(ID)){
//FileSend
for(int i=0;i<FileSends.size();i++){
if(FileSends.at(i)->get_StreamID()==ID){
FileSends.at(i)->StreamStatus(result,ID,Message);
if(result!=SAM_Message_Types::OK){
I2P->doStreamClose(ID);
FileSends.removeAt(i);
}
return;
}
}
}
else if(isThisID_a_FileReciveID(ID)){
//Filerecive
for(int i=0;i<FileRecives.size();i++){
if(FileRecives.at(i)->get_StreamID()==ID){
FileRecives.at(i)->StreamStatus(result,ID,Message);
if(result!=SAM_Message_Types::OK){
I2P->doStreamClose(ID);
FileRecives.removeAt(i);
}
return;
}
}
}
else if(this->isThisIDunknown(ID)){
if(result==SAM_Message_Types::OK){
Protocol->newConnectionChat(ID);
return;
}
else{
//I2P->doStreamClose(ID);
removeUnknownID(ID);
}
}
for(int i=0;i<users.count();i++){
if(users.at(i)->get_I2PStreamID()==ID){
if(result==SAM_Message_Types::OK){
users.at(i)->set_I2PStreamID(ID);
users.at(i)->set_ConnectionStatus(ONLINE);
//this->Protocol->newConnectionChat(ID);
}
else if( result==SAM_Message_Types::CANT_REACH_PEER ||
result==SAM_Message_Types::TIMEOUT
){
if(users.at(i)->get_OnlineState()!=USEROFFLINE && users.at(i)->get_OnlineState()!=USERTRYTOCONNECT)
{
users.at(i)->IncomingMessageFromSystem("The Connection is broken: "+Message+"\nConnection closed");
I2P->doStreamClose(ID);
}
deletePacketManagerByID(ID);
users.at(i)->set_ConnectionStatus(OFFLINE);
}
else if( result==SAM_Message_Types::INVALID_KEY){
users.at(i)->IncomingMessageFromSystem("Invalid User - Destination: please delete the user\n");
if(users.at(i)->get_ConnectionStatus()==ONLINE)
I2P->doStreamClose(ID);
deletePacketManagerByID(ID);
users.at(i)->set_ConnectionStatus(ERROR);
}
else if(result==SAM_Message_Types::I2P_ERROR){
users.at(i)->IncomingMessageFromSystem("I2P_Error: "+Message);
if(users.at(i)->get_ConnectionStatus()==ONLINE)
I2P->doStreamClose(ID);
deletePacketManagerByID(ID);
users.at(i)->set_ConnectionStatus(ERROR);
}
emit eventUserChanged();
break;
}
}
}
void cCore::SessionStatusRecived(const SAM_Message_Types::RESULT result,const QString Destination,const QString Message)
{
if(result==(SAM_Message_Types::OK)){
currentOnlineStatus=User::USERONLINE;
emit eventOnlineStatusChanged();
I2P->doNamingLookUP("ME");//get the current Destination from this client
this->UserConnectThread->start();
}
}
void cCore::StreamConnectedRecived(const QString Destinaton,const qint32 ID){
//Someone connected you
//this->Protocol->newConnection(ID);
cConnection t(ID,Destinaton);
this->unknownConnections.push_back(t);
}
bool cCore::removeUnknownID(qint32 ID)
{
for(int i=0;i<this->unknownConnections.size();i++){
if(unknownConnections.at(i).ID==ID){
unknownConnections.removeAt(i);
return true;
}
}
return false;
}
QString cCore::get_UserProtocolVersionByStreamID(qint32 ID){
for(int i=0;i< users.size();i++)
if(users.at(i)->get_I2PStreamID()==ID){
return users.at(i)->get_ProtocolVersion();
}
return "";
}
void cCore::set_UserProtocolVersionByStreamID(qint32 ID,QString Version){
for(int i=0;i< users.size();i++)
if(users.at(i)->get_I2PStreamID()==ID){
users.at(i)->set_ProtocolVersion(Version);
return;
}
}
void cCore::removeUnknownIDCreateUserIfNeeded(const qint32 ID,const QString ProtocolVersion){
//TODO add some security thinks for adding !!! at the moment all user are allowed to connect
QString Destinaton;
for(int i=0;i<unknownConnections.size();i++)
if(unknownConnections.at(i).ID==ID){
Destinaton=unknownConnections.at(i).Destination;
removeUnknownID(ID);
break;
}
if(doesUserAllReadyExitsByI2PDestination(Destinaton)==false){
addNewUser("Unknown",Destinaton,ID);
}
for(int i=0;i<users.count();i++){
if(users.at(i)->get_I2PDestination()==Destinaton){
if(users.at(i)->get_ConnectionStatus()==OFFLINE){
users.at(i)->set_ProtocolVersion(ProtocolVersion);
users.at(i)->set_I2PStreamID(ID);
users.at(i)->set_ConnectionStatus(ONLINE);
cPacketManager* newPacket=new cPacketManager(ID);
connect(newPacket,SIGNAL(aPacketIsComplead(const qint32, const QByteArray)),Protocol,
SLOT(inputKnown(const qint32,const QByteArray)));
DataPacketsManagers.push_back(newPacket);
}
else if(users.at(i)->get_ConnectionStatus()==ONLINE){
/*
//close both Streams
if(ID!=users.at(i)->get_I2PStreamID())
{
I2P->doStreamClose(ID);
I2P->doStreamClose(users.at(i)->get_I2PStreamID());
}
*/
//close new connection and use the old
if(ID!=users.at(i)->get_I2PStreamID())
I2P->doStreamClose(ID);
}
else if(users.at(i)->get_ConnectionStatus()==TRYTOCONNECT){
/*
//Stop the TRYTOCONNECT
if(ID!=users.at(i)->get_I2PStreamID())
I2P->doStreamClose(users.at(i)->get_I2PStreamID());
users.at(i)->set_ProtocolVersion(ProtocolVersion);
users.at(i)->set_I2PStreamID(ID);
users.at(i)->set_ConnectionStatus(ONLINE);
*/
//close the tryconnection use the new one
if(ID!=users.at(i)->get_I2PStreamID())
I2P->doStreamClose(users.at(i)->get_I2PStreamID());
users.at(i)->set_ProtocolVersion(ProtocolVersion);
users.at(i)->set_I2PStreamID(ID);
users.at(i)->set_ConnectionStatus(ONLINE);
cPacketManager* newPacket=new cPacketManager(ID);
connect(newPacket,SIGNAL(aPacketIsComplead(const qint32, const QByteArray)),Protocol,
SLOT(inputKnown(const qint32,const QByteArray)));
DataPacketsManagers.push_back(newPacket);
}
break;
}
}
emit eventUserChanged();
}
void cCore::StreamReadyToSendRecived(const qint32 ID){
//FileSendsConnections
for(int i=0;i<FileSends.size();i++){
if(FileSends.at(i)->get_StreamID()==ID){
FileSends.at(i)->StreamReadyToSend(true);
return;
}
}
//the Rest (Chatconnections)
for(int i=0;i<users.count();i++){
if(users.at(i)->get_I2PStreamID()==ID){
users.at(i)->set_ReadyToSend(true);
return;
}
}
}
void cCore::StreamSendRecived(const qint32 ID,const SAM_Message_Types::RESULT result,SAM_Message_Types::STATE state){
//FIXME what do when result = FAILED ?, impl. a stack ?
//FileSendsConnections
for(int i=0;i<FileSends.size();i++){
if(FileSends.at(i)->get_StreamID()==ID){
if(state==SAM_Message_Types::READY){
FileSends.at(i)->StreamReadyToSend(true);
return;
}
else{
FileSends.at(i)->StreamReadyToSend(false);
return;
}
}
}
//the Rest (Chatconnections)
for(int i=0;i<users.count();i++){
if(users.at(i)->get_I2PStreamID()==ID){
if(state==SAM_Message_Types::BUFFER_FULL)users.at(i)->set_ReadyToSend(false);
if(state==SAM_Message_Types::READY)users.at(i)->set_ReadyToSend(true);
}
}
}
const QList<cUser*> cCore::get_userList(){
return users;
}
qint32 cCore::StreamConnect(QString Destination){
qint32 ID;
ID=I2P->doStreamConnect(Destination);
cConnection t(ID,Destination);
this->unknownConnections.push_back(t);
return (ID);
}
void cCore::StreamDataRecived(const qint32 ID,const QString Size,const QByteArray Data){
if(Data.isEmpty()==true)return;
//FileRecive
for(int i=0;i<FileRecives.size();i++){
if(FileRecives.at(i)->get_StreamID()==ID){
FileRecives.at(i)->operator <<(Data);
return;
}
}
//FileSend
for(int i=0;i<FileSends.size();i++){
if(FileSends.at(i)->get_StreamID()==ID){
FileSends.at(i)->operator <<(Data);
return;
}
}
//unknown connection
if(this->isThisIDunknown(ID)){
QByteArray Data2=Protocol->inputUnknown(ID,Data);
if(Data2.isEmpty()==true)
return;
else{
QList<cPacketManager*>::Iterator it;
for(it=DataPacketsManagers.begin(); it!=DataPacketsManagers.end() ;++it){
if((*(it))->getID()==ID){
//(*(it))->operator <<(Data);
(*(*it))<<Data2;
return;
}
}
/*
QString StringSize=QString::number(Data2.length());
StreamDataRecived(ID,StringSize,Data2);
return;
*/
}
}
//normal connection
QList<cPacketManager*>::Iterator it;
for(it=DataPacketsManagers.begin(); it!=DataPacketsManagers.end() ;++it){
if((*(it))->getID()==ID){
//(*(it))->operator <<(Data);
(*(*it))<<Data;
return;
}
}
//Ignore Data
//if you close a stream i can happen that the QSocket already have recive same data of that Stream (and send it to the Socket)
//if it happen forget the Data
}
void cCore::closeAllActiveConnections(){
//close all known Online||TrytoConnect Connections
for(int i=0;i<users.size();i++)
if(users.at(i)->get_ConnectionStatus()==ONLINE ||
users.at(i)->get_ConnectionStatus()==TRYTOCONNECT)
{
deletePacketManagerByID(users.at(i)->get_I2PStreamID());
I2P->doStreamClose(users.at(i)->get_I2PStreamID());
//removeUnknownID(users.at(i)->get_I2PStreamID());
users.at(i)->set_ConnectionStatus(User::OFFLINE);
users.at(i)->set_OnlineState(USEROFFLINE);
}
//close all unknownConnections
for(int i=0;i<unknownConnections.size();i++)
{
I2P->doStreamClose(unknownConnections.at(i).ID);
removeUnknownID( unknownConnections.at(i).ID);
}
//DataPacketsManagers.clear();
emit eventUserChanged();
}
bool cCore::isThisIDunknown(qint32 ID){
for(int i=0;i<this->unknownConnections.size();i++)
if(unknownConnections.at(i).ID==ID){
return true;
}
return false;
}
cUser* cCore::getUserByI2P_ID(qint32 ID){
for(int i=0;i<users.size();i++){
if(users.at(i)->get_I2PStreamID()==ID){
return users.at(i);
}
}
return NULL;
}
cUser* cCore::getUserByI2P_Destination(QString Destination){
for(int i=0;i<users.size();i++){
if(users.at(i)->get_I2PDestination()==Destination){
return users.at(i);
}
}
return NULL;
}
void cCore::NamingReplyRecived(const SAM_Message_Types::RESULT result,QString Name,QString Value,QString Message){
if(result==SAM_Message_Types::OK && Name=="ME")
this->MyDestination=Value;
}
const QString cCore::getMyDestination()const{
return this->MyDestination;
}
bool cCore::isThisDestinationInunknownConnections(QString Destination){
for(int i=0;i<unknownConnections.size();i++){
if(unknownConnections.at(i).Destination==Destination)return true;
}
return false;
}
void cCore::deletePacketManagerByID(qint32 ID){
if(this->isThisIDunknown(ID)==true)
return;
else
{
QList<cPacketManager*>::Iterator it;
for(it=DataPacketsManagers.begin(); it!=DataPacketsManagers.end() ;++it){
if((*(it))->getID()==ID){
//delete (*(it));
DataPacketsManagers.erase(it);
break;
}
}
}
}
QString cCore::get_connectionDump(){
QString Message;
Message+="< Current open Unknown IDs: >\n";
for(int i=0;i<unknownConnections.size();i++)
Message+=QString::number(unknownConnections.at(i).ID,10)+"\n";
Message+="\n\n< Current open Known IDs(packetManager): >\n";
QList<cPacketManager*>::Iterator it;
for(it=DataPacketsManagers.begin(); it!=DataPacketsManagers.end();++it)
Message+= (QString::number((*(it))->getID(),10)+"\n");
Message+="\n\n< Active FileTransfer: >\n";
for(int i=0;i<FileSends.count();i++){
Message+="FileName:\t\t:"+FileSends.at(i)->get_FileName()+"\n";
Message+="StreamID:\t\t"+QString::number(FileSends.at(i)->get_StreamID(),10)+"\n";
}
Message+="\n\n< Active Filerecive: >\n";
for(int i=0;i<FileRecives.count();i++){
Message+="FileName:\t\t"+FileRecives.at(i)->get_FileName()+"\n";
Message+="StreamID:\t\t"+QString::number(FileRecives.at(i)->get_StreamID(),10)+"\n";
}
Message+="\n\n< USER-Infos: >\n";
for(int i=0;i< users.count();i++){
Message+="Name:\t\t"+users.at(i)->get_Name()+"\n";
Message+="ClientName:\t\t"+users.at(i)->get_ClientName()+"\n";
Message+="ClientVersion:\t\t"+users.at(i)->get_ClientVersion()+"\n";
Message+="ProtocolVersion:\t" +users.at(i)->get_ProtocolVersion()+"\n";
Message+="I2PStreamID:\t\t" +QString::number(users.at(i)->get_I2PStreamID(),10)+"\n";
switch(users.at(i)->get_ConnectionStatus())
{
case User::ONLINE:
{
Message+="ConnectionStatus:\tOnline\n\n";
break;
}
case User::OFFLINE:
{
Message+="ConnectionStatus:\tOffline/Invisible\n\n";
break;
}
case User::TRYTOCONNECT:
{
Message+="ConnectionStatus:\tTryToConnect\n\n";
break;
}
case User::ERROR:
{
Message+="ConnectionStatus: (Stream)\tError\n\n";
break;
}
};
}
return Message;
}
bool cCore::renameuserByI2PDestination(const QString Destination, const QString newNickname){
for(int i=0;i<users.size();i++){
if(users.at(i)->get_I2PDestination()==Destination){
users.at(i)->set_Name(newNickname);
emit eventUserChanged();
return true;
}
}
return false;
}
ONLINESTATE cCore::getOnlineStatus() const
{
return this->currentOnlineStatus;
}
void cCore::setOnlineStatus(const ONLINESTATE newStatus)
{
if(currentOnlineStatus==newStatus) return;
if(newStatus==User::USEROFFLINE)
{
stopCore();
this->currentOnlineStatus=newStatus;
}
else if(newStatus==User::USERTRYTOCONNECT)
{
if(currentOnlineStatus==User::USEROFFLINE)
{
restartCore();
this->currentOnlineStatus=newStatus;
}
}
else
{
//send new Status to every connected User
this->currentOnlineStatus=newStatus;
for(int i=0;i<users.size();i++){
if(users.at(i)->get_ConnectionStatus()==ONLINE)
{
switch(this->currentOnlineStatus)
{
case USERONLINE:
{
Protocol->send(USER_ONLINESTATUS_ONLINE,users.at(i)->get_I2PStreamID(),"");
break;
}
case USEROFFLINE:
case USERINVISIBLE:
{
Protocol->send(USER_ONLINESTATUS_OFFLINE,users.at(i)->get_I2PStreamID(),"");
break;
}
case USERAWAY:
{
Protocol->send(USER_ONLINESTATUS_AWAY,users.at(i)->get_I2PStreamID(),"");
break;
}
case USERWANTTOCHAT:
{
Protocol->send(USER_ONLINESTATUS_WANTTOCHAT,users.at(i)->get_I2PStreamID(),"");
break;
}
case USERDONT_DISTURB:
{
Protocol->send(USER_ONLINESTATUS_DONT_DISTURB,users.at(i)->get_I2PStreamID(),"");
break;
}
default:
{
QMessageBox* msgBox= new QMessageBox(NULL);
msgBox->setIcon(QMessageBox::Warning);
msgBox->setText("cCore(setOnlineStatus)");
msgBox->setInformativeText("Unknown USERSTATE");
msgBox->setStandardButtons(QMessageBox::Ok);
msgBox->setDefaultButton(QMessageBox::Ok);
msgBox->setWindowModality(Qt::NonModal);
msgBox->show();
}
}
}//if
}//for
}
emit eventOnlineStatusChanged();
}
void cCore::stopCore()
{
UserConnectThread->stop();
closeAllActiveConnections();
I2P->doDisconnect();
}
void cCore::restartCore()
{
I2P->doConnect();
UserConnectThread->start();
}
void cCore::addNewFileTransfer(QString FilePath, QString Destination)
{
cFileTransferSend * t= new cFileTransferSend(this,FilePath,Destination);
connect (t,SIGNAL(event_FileTransferFinishedOK()),SoundManager,
SLOT(event_FileSend_Finished()));
FileSends.append(t);
}
bool cCore::isThisID_a_FileSendID(qint32 ID)
{
for(int i=0;i<FileSends.size();i++){
if(FileSends.at(i)->get_StreamID()==ID){
return true;
}
}
return false;
}
bool cCore::isThisID_a_FileReciveID(qint32 ID)
{
for(int i=0;i<FileRecives.size();i++){
if(FileRecives.at(i)->get_StreamID()==ID){
return true;
}
}
return false;
}
void cCore::addNewFileRecive(qint32 ID, QString FileName, QString FileSize)
{
if(isThisIDunknown(ID)) removeUnknownID(ID);
quint64 Size;
bool OK;
Size=FileSize.toULongLong(&OK,10);
if(OK==false)
{
QMessageBox* msgBox= new QMessageBox(NULL);
msgBox->setIcon(QMessageBox::Critical);
msgBox->setText("cCore(addNewFileRecive)");
msgBox->setInformativeText("Error convert QString to Quint64\nValue: "+FileSize +"\nFilerecive aborted");
msgBox->setStandardButtons(QMessageBox::Ok);
msgBox->setDefaultButton(QMessageBox::Ok);
msgBox->setWindowModality(Qt::NonModal);
msgBox->exec();
//abort the Filerecive
this->StreamSendData(ID,QString("1"));//false
this->StreamClose(ID);
return;
}
SoundManager->event_FileRecive_Incoming();
cFileTransferRecive* t= new cFileTransferRecive(this,ID,FileName,Size);
connect(t,SIGNAL(event_FileRecivedFinishedOK()),SoundManager,
SLOT(event_FileRecive_Finished()));
FileRecives.append(t);
t->start();
}
void cCore::StreamSendData(qint32 ID, QByteArray Data)
{
I2P->doStreamSend(ID,Data);
}
void cCore::StreamSendData(qint32 ID, QString Data)
{
I2P->doStreamSend(ID,Data);
}
void cCore::StreamClose(qint32 ID)
{
if(FileSends.count()>0){
for(int i=0;i<FileSends.count();i++){
if(FileSends.at(i)->get_StreamID()==ID){
FileSends.removeAt(i);
break;
}
}
}
if(FileRecives.count()>0){
for(int i=0;i<FileRecives.count();i++){
if(FileRecives.at(i)->get_StreamID()==ID){
FileRecives.removeAt(i);
break;
}
}
}
I2P->doStreamClose(ID);
}
bool cCore::checkIfAFileTransferOrReciveisActive()
{
if(FileSends.count()>0) return true;
if(FileRecives.count()>0) return true;
return false;
}
void cCore::MuteSound(bool t)
{
SoundManager->doMute(t);
}

View file

@ -0,0 +1,154 @@
/***************************************************************************
* Copyright (C) 2008 by normal *
* normal@Desktop2 *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef CORE_H
#define CORE_H
#include <QtGui>
#include <QSettings>
#include <QtXml>
#include <QTextStream>
#include <QList>
#include "User.h"
#include "ConnectionI2P.h"
#include "DebugMessageManager.h"
#include "I2PSamMessageAnalyser.h"
#include "UserConnectThread.h"
#include "Protocol.h"
#include "PacketManager.h"
#include "FileTransferSend.h"
#include "FileTransferRecive.h"
#include "SoundManager.h"
#define CLIENTVERSION "0.2.9 Beta"
#define CLIENTNAME "I2P-Messenger (QT)"
struct cConnection
{
cConnection ( qint32 ID,QString Destination )
{
this->ID=ID;
this->Destination=Destination;
}
void operator= ( const cConnection& t )
{
this->ID=t.ID;
this->Destination=t.Destination;
}
qint32 ID;
QString Destination;
};
using namespace SAM_Message_Types;
using namespace User;
class cUserConnectThread;
class cCore :public QObject
{
Q_OBJECT
public:
cCore();
~cCore();
cDebugMessageManager* get_DebugMessageHandler();
const QList<cUser*> get_userList();
bool isThisIDunknown ( qint32 ID );
bool removeUnknownID ( qint32 ID );
bool isThisDestinationInunknownConnections ( QString Destination );
void removeUnknownIDCreateUserIfNeeded( const qint32 ID,const QString ProtocolVersion );
QString get_UserProtocolVersionByStreamID ( qint32 ID );
void set_UserProtocolVersionByStreamID ( qint32 ID,QString Version );
cUser* getUserByI2P_ID ( qint32 ID );
cUser* getUserByI2P_Destination ( QString Destination );
const QString getMyDestination() const;
ONLINESTATE getOnlineStatus()const;
QString get_ClientName() {return CLIENTNAME;};
QString get_ClientVersion(){return CLIENTVERSION;};
QString get_ProtocolVersion(){return Protocol->get_ProtocolVersion();};
void setOnlineStatus(const ONLINESTATE newStatus);
void addNewFileTransfer(QString FilePath,QString Destination);
void addNewFileRecive(qint32 ID,QString FileName,QString FileSize);
void StreamSendData(qint32 ID,QByteArray Data);
void StreamSendData(qint32 ID,QString Data);
void StreamClose(qint32 ID);
qint32 StreamConnect (QString Destination );
bool checkIfAFileTransferOrReciveisActive();
public slots:
bool addNewUser (QString Name,QString I2PDestination,qint32 I2PStream_ID=0);
bool deleteUserByI2PDestination (const QString I2PDestination );
bool renameuserByI2PDestination (const QString Destination, const QString newNickname);
void doNamingLookUP ( QString Name );
void MuteSound(bool t);
QString get_connectionDump();
private slots:
// <SIGNALS FROM cConnectionI2P>
void StreamClosedRecived ( const SAM_Message_Types::RESULT result,qint32 ID,QString Message );
void StreamStatusRecived ( const SAM_Message_Types::RESULT result,const qint32 ID,QString Message );
void StreamConnectedRecived ( const QString Destinaton,const qint32 ID );
void StreamReadyToSendRecived ( const qint32 ID );
void StreamSendRecived ( const qint32 ID,const SAM_Message_Types::RESULT result,SAM_Message_Types::STATE state );
void SessionStatusRecived ( const SAM_Message_Types::RESULT result,const QString Destination,const QString Message );
void StreamDataRecived ( const qint32 ID,const QString Size,const QByteArray Data );
void NamingReplyRecived ( const SAM_Message_Types::RESULT result,QString Name,QString Value="",QString Message="" );
signals:
void eventUserChanged();
void eventOnlineStatusChanged();
private:
cConnectionI2P* I2P;
cDebugMessageManager* DebugMessageHandler;
cProtocol* Protocol;
QList<cUser*> users;
QList<cConnection> unknownConnections;
cUserConnectThread* UserConnectThread;
QString MyDestination;
QList<cPacketManager*> DataPacketsManagers;
ONLINESTATE currentOnlineStatus;
QList<cFileTransferSend*> FileSends;
QList<cFileTransferRecive*> FileRecives;
cSoundManager* SoundManager;
bool doesUserAllReadyExitsByI2PDestination ( QString I2PDestination );
void init();
void saveUserList();
void loadUserList();
void stopCore();
void restartCore();
void closeAllActiveConnections();
void deletePacketManagerByID ( qint32 ID );
bool isThisID_a_FileSendID(qint32 ID);
bool isThisID_a_FileReciveID(qint32 ID);
};
#endif

View file

@ -0,0 +1,57 @@
/***************************************************************************
* Copyright (C) 2008 by normal *
* normal@Desktop2 *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "DebugMessageManager.h"
cDebugMessageManager::cDebugMessageManager(cConnectionI2P* I2P)
{
this->I2P=I2P;
this->settings= new QSettings("./application.ini",QSettings::IniFormat);
settings->beginGroup("General");
this->MaxMessageCount=settings->value("Debug_Max_Message_count","20").toInt();
settings->endGroup();
connect(I2P,SIGNAL(debugMessages(QString) ),this,SLOT(NewIncomingDebugMessage(const QString)) );
}
cDebugMessageManager::~cDebugMessageManager()
{
disconnect(I2P,SIGNAL(debugMessages(QString)),this,SLOT(NewIncomingDebugMessage(const QString)));
}
void cDebugMessageManager::clearAllMessages()
{
Messages.clear();
}
const QStringList cDebugMessageManager::getAllMessages()
{
return Messages;
}
void cDebugMessageManager::NewIncomingDebugMessage(const QString Message){
while(Messages.count()>= (signed int)MaxMessageCount){
Messages.removeLast();
}
Messages.prepend(Message);
emit newDebugMessage(Message);
}

View file

@ -0,0 +1,53 @@
/***************************************************************************
* Copyright (C) 2008 by normal *
* normal@Desktop2 *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef DEBUGMESSAGEMANAGER_H
#define DEBUGMESSAGEMANAGER_H
#include <QtGui>
#include <QSettings>
#include "ConnectionI2P.h"
class cDebugMessageManager:public QObject
{
Q_OBJECT
public:
cDebugMessageManager(cConnectionI2P* I2P);
~cDebugMessageManager();
public slots:
void clearAllMessages();
const QStringList getAllMessages();
private slots:
void NewIncomingDebugMessage(const QString Message);
signals:
void newDebugMessage(QString Message);
private:
cConnectionI2P* I2P;
quint32 MaxMessageCount;
QSettings* settings;
QStringList Messages;
};
#endif

View file

@ -0,0 +1,150 @@
/***************************************************************************
* Copyright (C) 2008 by normal *
* normal@Desktop2 *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "Core.h"
#include "FileTransferRecive.h"
cFileTransferRecive::cFileTransferRecive(cCore * Core, qint32 StreamID, QString FileName, quint64 FileSize)
:StreamID(StreamID),FileName(FileName),FileSize(FileSize)
{
this->Core=Core;
allreadyRecivedSize=0;
}
cFileTransferRecive::~ cFileTransferRecive()
{
delete Dialog;
delete FileForRecive;
}
void cFileTransferRecive::StreamStatus(const SAM_Message_Types::RESULT result, const qint32 ID, QString Message)
{
if(result==SAM_Message_Types::OK)
{
}
else
{
FileForRecive->close();
FileForRecive->remove();
emit event_FileReciveError();
}
}
void cFileTransferRecive::StreamClosed(const SAM_Message_Types::RESULT result, qint32 ID, QString Message)
{
if(allreadyRecivedSize==FileSize){
FileForRecive->close();
emit event_FileRecivedFinishedOK();
}
else{
FileForRecive->close();
FileForRecive->remove();
emit event_FileReciveAbort();
}
}
void cFileTransferRecive::operator <<(QByteArray t)
{
allreadyRecivedSize+=t.length();
FileForRecive->write(t);
FileForRecive->flush();
emit event_allreadyRecivedSizeChanged(allreadyRecivedSize);
if(allreadyRecivedSize==FileSize)
{
Core->StreamClose(StreamID);
FileForRecive->close();
emit event_FileRecivedFinishedOK();
}
}
void cFileTransferRecive::abbortFileRecive()
{
Core->StreamClose(StreamID);
FileForRecive->close();
FileForRecive->remove();
}
void cFileTransferRecive::start()
{
QString SFileSize;
SFileSize.setNum(FileSize);
QMessageBox* msgBox= new QMessageBox(NULL);
msgBox->setText("Incoming FileTransfer");
msgBox->setInformativeText("Do you want to accept it ?\nFileName: "+FileName+"\nFileSize: " +SFileSize+" Bit");
msgBox->setStandardButtons(QMessageBox::Yes | QMessageBox::No);
msgBox->setDefaultButton(QMessageBox::Yes);
msgBox->setWindowModality(Qt::WindowModal);
int ret = msgBox->exec();
if(ret==QMessageBox::Yes){
QString FilePath=QFileDialog::getSaveFileName(NULL,"File Save","./"+FileName);
if(!FilePath.isEmpty()){
FileForRecive= new QFile(FilePath);
FileForRecive->open(QIODevice::WriteOnly);
Core->StreamSendData(StreamID,QString("0"));//true
Dialog= new form_fileRecive(this);
Dialog->show();
}
else{
Core->StreamSendData(StreamID,QString("1"));//false
Core->StreamClose(StreamID);
}
}
else{
Core->StreamSendData(StreamID,QString("1"));//false
Core->StreamClose(StreamID);
}
}
void cFileTransferRecive::start_withAutoAccept(QString Path)
{
QString SFileSize;
SFileSize.setNum(FileSize);
QString FilePath=Path+="/"+FileName;
if(!FilePath.isEmpty()){
FileForRecive= new QFile(FilePath);
FileForRecive->open(QIODevice::WriteOnly);
Core->StreamSendData(StreamID,QString("0"));//true
Dialog= new form_fileRecive(this);
Dialog->show();
}
}

View file

@ -0,0 +1,61 @@
/***************************************************************************
* Copyright (C) 2008 by normal *
* normal@Desktop2 *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef FILETRANSFER_H
#define FILETRANSFER_H
#include "gui/form_fileRecive.h"
#include "ConnectionI2P.h"
class cCore;
class cFileTransferRecive:public QObject
{
Q_OBJECT
public:
cFileTransferRecive(cCore* Core,qint32 StreamID,QString FileName,quint64 FileSize);
~cFileTransferRecive();
void start();
void start_withAutoAccept(QString Path);
void StreamStatus(const SAM_Message_Types::RESULT result,const qint32 ID,QString Message);
void StreamClosed(const SAM_Message_Types::RESULT result,qint32 ID,QString Message);
void operator << ( QByteArray t );
quint64 get_FileSize(){return FileSize;};
QString get_FileName(){return FileName;};
qint32 get_StreamID(){return StreamID;};
public slots:
void abbortFileRecive();
signals:
void event_allreadyRecivedSizeChanged(quint64 Size);
void event_FileReciveError();
void event_FileRecivedFinishedOK();
void event_FileReciveAbort();
private:
cCore* Core;
form_fileRecive* Dialog;
const quint64 FileSize;
quint64 allreadyRecivedSize;
const QString FileName;
const qint32 StreamID;
QFile* FileForRecive;
};
#endif

View file

@ -0,0 +1,144 @@
/***************************************************************************
* Copyright (C) 2008 by normal *
* normal@Desktop2 *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "FileTransferSend.h"
#include "gui/form_fileSend.h"
#include "Core.h"
cFileTransferSend::cFileTransferSend(cCore * Core, QString FilePath,QString Destination)
:FilePath(FilePath),Destination(Destination)
{
this->Core=Core;
StreamID=Core->StreamConnect(Destination);
Core->removeUnknownID(StreamID);
sendFirstPaket=true;
FileName=FilePath.mid(FilePath.lastIndexOf("/")+1);
FileTransferAccepted=false;
FileForSend = new QFile(FilePath);
FileSize=FileForSend->size();
Dialog=new form_fileSend(this);
Dialog->show();
}
void cFileTransferSend::abbortFileSend()
{
FileForSend->close();
Core->StreamClose(StreamID);
}
void cFileTransferSend::StreamStatus(const SAM_Message_Types::RESULT result, const qint32 ID, QString Message)
{
using namespace FileTransferProtocol;
if(result==SAM_Message_Types::OK)
{
if(sendFirstPaket==true)
{
QString StringFileSize;
StringFileSize.setNum(FileSize);
Core->StreamSendData(StreamID,FIRSTPAKET+StringFileSize+"\n"+FileName);
sendFirstPaket=false;
}
}
else
{
FileForSend->close();
emit event_FileTransferError();
}
}
void cFileTransferSend::StreamClosed(const SAM_Message_Types::RESULT result, qint32 ID, QString Message)
{
if(result==SAM_Message_Types::OK){
if(allreadySendedSize==FileSize){
emit event_FileTransferFinishedOK();
}
else
emit event_FileTransferAborted();
}
else{
emit event_FileTransferAborted();
}
FileForSend->close();
}
cFileTransferSend::~ cFileTransferSend()
{
delete FileForSend;
delete Dialog;
}
void cFileTransferSend::StreamReadyToSend(bool t)
{
if(t==false)return;
if(FileTransferAccepted==false)return;
if(allreadySendedSize==FileSize)
{
emit event_FileTransferFinishedOK();
Core->StreamClose(StreamID);
return;
}
QByteArray Buffer;
Buffer=FileForSend->read(MAXPAKETSIZE);
allreadySendedSize+=Buffer.length();
Core->StreamSendData(StreamID,Buffer);
emit event_allreadySendedSizeChanged(allreadySendedSize);
}
void cFileTransferSend::operator <<(QByteArray t)
{
if(t.length()==1){
if(t.contains("0")){//true
emit event_FileTransferAccepted(true);
FileTransferAccepted=true;
StartFileTransfer();
}
else{
emit event_FileTransferAccepted(false);
Core->StreamClose(StreamID);
}
}
else{
emit event_FileTransferAccepted(false);
Core->StreamClose(StreamID);
}
}
void cFileTransferSend::StartFileTransfer()
{
allreadySendedSize=0;
FileForSend->open(QIODevice::ReadOnly);
StreamReadyToSend(true);
}

View file

@ -0,0 +1,79 @@
/***************************************************************************
* Copyright (C) 2008 by normal *
* normal@Desktop2 *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef FILETRANSFERSEND_H
#define FILETRANSFERSEND_H
#include "ConnectionI2P.h"
namespace FileTransferProtocol
{
const QString PROTOCOLVERSION= "0.1";
const QString FIRSTPAKET ="CHATSYSTEMFILETRANSFER\t"+PROTOCOLVERSION+"\n";
//+sizeinbit\nFileName
};
//limited to 30Kb
//#define MAXPAKETSIZE 30720
#define MAXPAKETSIZE 1024
class cCore;
class form_fileSend;
class cFileTransferSend:public QObject
{
Q_OBJECT
public:
cFileTransferSend(cCore* Core,QString FilePath,QString Destination);
~cFileTransferSend();
void StreamStatus(const SAM_Message_Types::RESULT result,const qint32 ID,QString Message);
void StreamClosed(const SAM_Message_Types::RESULT result,qint32 ID,QString Message);
void StreamReadyToSend(bool t);
void operator << ( QByteArray t );
quint64 get_FileSize(){return FileSize;};
qint32 get_StreamID(){return StreamID;};
QString get_FileName(){return FileName;};
public slots:
void abbortFileSend();
signals:
void event_allreadySendedSizeChanged(quint64 Size);
void event_FileTransferAccepted(bool t);
void event_FileTransferFinishedOK();
void event_FileTransferError();
void event_FileTransferAborted();//the otherSide abort it
private:
void StartFileTransfer();
cCore* Core;
const QString FilePath;
qint64 FileSize;
qint64 allreadySendedSize;
const QString Destination;
qint32 StreamID;
QFile* FileForSend;
bool sendFirstPaket;
bool FileTransferAccepted;
QString FileName;
form_fileSend* Dialog;
};
#endif

View file

@ -0,0 +1,251 @@
/***************************************************************************
* Copyright (C) 2008 by normal *
* normal@Desktop2 *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "I2PSamMessageAnalyser.h"
I2PSamMessageAnalyser::I2PSamMessageAnalyser()
{
//Constructor
}
const SAM_MESSAGE I2PSamMessageAnalyser::Analyse(QString Message)
{
using namespace SAM_Message_Types;
SAM_MESSAGE t;
QStringList list =Message.split(" ",QString::SkipEmptyParts);
if((list[0]=="STREAM") && (list[1]=="RECEIVED")){
t.type=STREAM_RECEIVED;
//get ID
QStringList temp=list[2].split("=");
QString sID=temp[1];
t.ID=QStringToQint32(sID);
//get Size
temp= list[3].split("=");
t.Size=temp[1].remove("\n");
}
else if((list[0].contains("STREAM")==true) && (list[1].contains("READY_TO_SEND")==true)){
t.type=STREAM_READY_TO_SEND;
//GET ID
QStringList temp=list[2].split("=");
QString sID=temp[1].remove("\n");
t.ID=QStringToQint32(sID);
}
else if((list[0]=="HELLO") && (list[1]=="REPLY")){
t.type=HELLO_REPLAY;
if(list[2].contains("RESULT=OK")==true) t.result=OK;
else if(list[2].contains("RESULT=NOVERSION")==true)t.result=NOVERSION;
}
else if((list[0].contains("SESSION")==true) && (list[1].contains("STATUS")==true)){
t.type=SESSION_STATUS;
//Get Result
if(list[2].contains("RESULT=OK",Qt::CaseInsensitive))t.result=OK;
else if(list[2].contains("RESULT=DUPLICATED_DEST",Qt::CaseInsensitive))t.result=DUPLICATED_DEST;
else if(list[2].contains("RESULT=I2P_ERROR",Qt::CaseInsensitive))t.result=I2P_ERROR;
else if(list[2].contains("RESULT=INVALID_KEY",Qt::CaseInsensitive))t.result=INVALID_KEY;
else
t.type=ERROR_IN_ANALYSE;
//----------------
//Get Destination
QStringList temp=list[3].split("=");
t.Destination=temp[1].remove("\n");
//----------------
//Get Message
if(Message.contains("MESSAGE=",Qt::CaseInsensitive)){
t.Message=Message.mid(Message.indexOf("MESSAGE=")+8);
t.Message.remove("\n");
}
//----------------
}
else if((list[0].contains("STREAM")==true) && (list[1].contains("STATUS")==true)){
t.type=STREAM_STATUS;
//Get Result
if(list[2].contains("RESULT=OK",Qt::CaseInsensitive))t.result=OK;
else if(list[2].contains("RESULT=CANT_REACH_PEER",Qt::CaseInsensitive))t.result=CANT_REACH_PEER;
else if(list[2].contains("RESULT=I2P_ERROR",Qt::CaseInsensitive))t.result=I2P_ERROR;
else if(list[2].contains("RESULT=INVALID_KEY",Qt::CaseInsensitive))t.result=INVALID_KEY;
else if(list[2].contains("RESULT=TIMEOUT",Qt::CaseInsensitive))t.result=TIMEOUT;
else
{
t.type=ERROR_IN_ANALYSE;
return t;
}
//----------------
//Get ID
QStringList temp=list[3].split("=");
QString sID=temp[1].remove("\n");
t.ID=QStringToQint32(sID);
//----------------
//Get Message
if(Message.contains("MESSAGE=",Qt::CaseInsensitive)){
t.Message=Message.mid(Message.indexOf("MESSAGE=")+8);
t.Message.remove("\n");
}
//----------------
}
else if((list[0].contains("STREAM")==true) && (list[1].contains("CONNECTED")==true)){
t.type=STREAM_CONNECTED;
QStringList temp=list[2].split("=");
QString sID;
t.Destination=temp[1];
temp=list[3].split("=");
sID=temp[1].remove("\n");
t.ID=QStringToQint32(sID);
}
else if((list[0].contains("STREAM")==true) && (list[1].contains("SEND")==true)){
t.type=STREAM_SEND;
//get ID
QStringList temp=list[2].split("=");
QString sID=temp[1];
t.ID=QStringToQint32(sID);
//Get Result
if(list[3].contains("RESULT=OK",Qt::CaseInsensitive))t.result=OK;
else if(list[2].contains("RESULT=FAILED",Qt::CaseInsensitive))t.result=FAILED;
//get STATE
if(list[4].contains("STATE=BUFFER_FULL",Qt::CaseInsensitive))t.state=BUFFER_FULL;
else if(list[4].contains("STATE=READY",Qt::CaseInsensitive))t.state=READY;
}
else if((list[0].contains("STREAM")==true) && (list[1].contains("CLOSED")==true)){
t.type=STREAM_CLOSED;
//Get RESULT
if(list[2].contains("RESULT",Qt::CaseInsensitive))
{
if(list[2].contains("RESULT=OK",Qt::CaseInsensitive))t.result=OK;
else if(list[2].contains("RESULT=CANT_REACH_PEER",Qt::CaseInsensitive))t.result=CANT_REACH_PEER;
else if(list[2].contains("RESULT=I2P_ERROR",Qt::CaseInsensitive))t.result=I2P_ERROR;
else if(list[2].contains("RESULT=PEER_NOT_FOUND",Qt::CaseInsensitive))t.result=PEER_NOT_FOUND;
else if(list[2].contains("RESULT=TIMEOUT",Qt::CaseInsensitive))t.result=TIMEOUT;
else{
t.type=ERROR_IN_ANALYSE;
return t;
}
//Get ID
QStringList temp=list[3].split("=");
QString sID=temp[1];
t.ID=QStringToQint32(sID);
}
else
{
if(list[3].contains("RESULT=OK",Qt::CaseInsensitive))t.result=OK;
else if(list[3].contains("RESULT=CANT_REACH_PEER",Qt::CaseInsensitive))t.result=CANT_REACH_PEER;
else if(list[3].contains("RESULT=I2P_ERROR",Qt::CaseInsensitive))t.result=I2P_ERROR;
else if(list[3].contains("RESULT=PEER_NOT_FOUND",Qt::CaseInsensitive))t.result=PEER_NOT_FOUND;
else if(list[3].contains("RESULT=TIMEOUT",Qt::CaseInsensitive))t.result=TIMEOUT;
else{
t.type=ERROR_IN_ANALYSE;
return t;
}
//Get ID
QStringList temp=list[2].split("=");
QString sID=temp[1];
t.ID=QStringToQint32(sID);
}
//----------------
//Get Message
if(Message.contains("MESSAGE=",Qt::CaseInsensitive)){
t.Message=Message.mid(Message.indexOf("MESSAGE=")+8);
t.Message.remove("\n");
}
//----------------
}
else if((list[0].contains("NAMING")==true) && (list[1].contains("REPLY")==true)){
t.type=NAMING_REPLY;
//get Result
if(list[2].contains("RESULT=OK",Qt::CaseInsensitive))t.result=OK;
else if(list[2].contains("RESULT=INVALID_KEY",Qt::CaseInsensitive))t.result=INVALID_KEY;
else if(list[2].contains("RESULT=KEY_NOT_FOUND",Qt::CaseInsensitive))t.result=KEY_NOT_FOUND;
else{
t.type=ERROR_IN_ANALYSE;
return t;
}
//get Name
QStringList temp=list[3].split("=");
t.Name=temp[1].remove("\n");
//get Value
if(list.count()-1>=4){
QStringList temp=list[4].split("=");
t.Value=temp[1].remove("\n");
}
//Get Message
if(Message.contains("MESSAGE=",Qt::CaseInsensitive)){
t.Message=Message.mid(Message.indexOf("MESSAGE=")+8);
t.Message.remove("\n");
}
}
else{
t.type=ERROR_IN_ANALYSE;
}
return t;
}
qint32 I2PSamMessageAnalyser::QStringToQint32(QString value)
{
bool OK=false;
qint32 iValue =value.toInt ( &OK,10 );
if(OK==false)
{
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Warning);
msgBox.setText("I2PSamMessageAnalyser");
msgBox.setInformativeText("cant parse value: "+value );
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.exec();
}
return iValue;
}

View file

@ -0,0 +1,96 @@
/***************************************************************************
* Copyright (C) 2008 by normal *
* normal@Desktop2 *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef I2PSAMMESSAGEANALYSER_H
#define I2PSAMMESSAGEANALYSER_H
#include <QtGui>
namespace SAM_Message_Types
{
enum TYPE
{
HELLO_REPLAY,
SESSION_STATUS,
STREAM_STATUS,
STREAM_CONNECTED,
STREAM_SEND,
STREAM_READY_TO_SEND,
STREAM_CLOSED,
STREAM_RECEIVED,
NAMING_REPLY,
ERROR_IN_ANALYSE
};
enum RESULT
{
OK,
DUPLICATED_DEST,
I2P_ERROR,
INVALID_KEY,
CANT_REACH_PEER,
TIMEOUT,
FAILED,
NOVERSION,
KEY_NOT_FOUND,
PEER_NOT_FOUND
};
enum STATE
{
BUFFER_FULL,
READY
};
}
struct SAM_MESSAGE
{
public:
QString Message;
qint32 ID;
QString Destination;
QString Size;
QString Name;
QString Value;
SAM_Message_Types::TYPE type;
SAM_Message_Types::RESULT result;
SAM_Message_Types::STATE state;
/*
SAM_MESSAGE(TYPE t,RESULT r,QString Message,QString Id,QString Destination,QString Size)
:type(t),result(r),Message(Message),Id(Id),Destination(Destination),Size(Size)
{
}
*/
};
class I2PSamMessageAnalyser: public QObject
{
Q_OBJECT
public:
I2PSamMessageAnalyser();
const SAM_MESSAGE Analyse(QString Message);
private:
qint32 QStringToQint32(QString value);
};
#endif

View file

@ -0,0 +1,37 @@
/***************************************************************************
* Copyright (C) 2008 by normal *
* normal@Desktop2 *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <QtGui>
#include <QApplication>
#include "gui/form_Main.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
form_MainWindow* mainForm= new form_MainWindow();
mainForm->show();
return app.exec();
app.closeAllWindows();
return 0;
}

View file

@ -0,0 +1,72 @@
/***************************************************************************
* Copyright (C) 2008 by normal *
* normal@Desktop2 *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "PacketManager.h"
cPacketManager::cPacketManager ( qint32 ID )
:ID ( ID )
{
Data.clear();
}
cPacketManager::~cPacketManager()
{
}
void cPacketManager::operator << ( QByteArray t )
{
Data.append ( t );
checkifOnePacketIsComplead();
}
qint32 cPacketManager::getID()
{
return ID;
}
void cPacketManager::checkifOnePacketIsComplead()
{
if ( Data.length() >=8 )
{
QString sPacketLength=Data.mid ( 0,4 );
bool OK=false;
int iPacketLength =sPacketLength.toInt ( &OK,16 );
if(OK==false)
{
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Warning);
msgBox.setText("cPacketManager ("+QString(ID)+")");
msgBox.setInformativeText("cant parse PacketLength\nHexValue: "+sPacketLength );
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.exec();
}
if ( Data.length() >=iPacketLength+4 )
{
QByteArray CurrentPacket ( Data.mid ( 4 ),iPacketLength );
Data.remove ( 0,iPacketLength+4 );
emit aPacketIsComplead ( ID,CurrentPacket );
checkifOnePacketIsComplead();
}
}
return;
}

View file

@ -0,0 +1,45 @@
/***************************************************************************
* Copyright (C) 2008 by normal *
* normal@Desktop2 *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef PACKETMANAGER_H
#define PACKETMANAGER_H
#include <Qt>
#include <QtGui>
class cPacketManager :public QObject
{
Q_OBJECT
public:
//cPacketManager() {}
cPacketManager ( qint32 ID );
~cPacketManager();
void operator << ( QByteArray t );
qint32 getID();
void checkifOnePacketIsComplead();
signals:
void aPacketIsComplead ( const qint32 ID,const QByteArray CurrentPacket );
private:
const qint32 ID;
QByteArray Data;
};
#endif

View file

@ -0,0 +1,333 @@
/***************************************************************************
* Copyright (C) 2008 by normal *
* normal@Desktop2 *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "Protocol.h"
#include "Core.h"
#include "User.h"
cProtocol::cProtocol(cCore * Core){
this->Core=Core;
connect (this,SIGNAL(eventUserChanged()),Core,SIGNAL(eventUserChanged()));
}
void cProtocol::newConnectionChat(const qint32 ID){
using namespace Protocol_Info;
//send the ChatSystem\tProtocolVersion
Core->StreamSendData(ID,FIRSTPAKETCHAT);
}
void cProtocol::inputKnown(const qint32 ID, const QByteArray Data){
using namespace Protocol_Info;
if(Data.length()<4)
return;
QString ProtocolInfoTag(Data.left(4));
//COMMANDS
if(ProtocolInfoTag=="1000"){//PING:
send(ECHO_OF_PING,ID,"");
}
else if(ProtocolInfoTag=="1001"){//GET_CLIENTVERSION:
send(ANSWER_OF_GET_CLIENTVERSION,ID,Core->get_ClientVersion());
}
else if(ProtocolInfoTag=="1002"){//GET_CLIENTNAME:
send(ANSWER_OF_GET_CLIENTNAME,ID,Core->get_ClientName());
}
else if(ProtocolInfoTag=="1003"){//GET_USER_ONLINESTATUS:
//TODO sendOnlineStatus
switch(Core->getOnlineStatus())
{
case USERONLINE:
{
send(USER_ONLINESTATUS_ONLINE,ID,"");
break;
}
case USEROFFLINE:
case USERINVISIBLE:
{
send(USER_ONLINESTATUS_OFFLINE,ID,"");
break;
}
case USERAWAY:
{
send(USER_ONLINESTATUS_AWAY,ID,"");
break;
}
case USERWANTTOCHAT:
{
send(USER_ONLINESTATUS_WANTTOCHAT,ID,"");
break;
}
case USERDONT_DISTURB:
{
send(USER_ONLINESTATUS_DONT_DISTURB,ID,"");
break;
}
default:
{
QMessageBox* msgBox= new QMessageBox(NULL);
msgBox->setIcon(QMessageBox::Warning);
msgBox->setText("cProtocol(inputKnown)");
msgBox->setInformativeText("Unknown USERSTATE");
msgBox->setStandardButtons(QMessageBox::Ok);
msgBox->setDefaultButton(QMessageBox::Ok);
msgBox->setWindowModality(Qt::NonModal);
msgBox->show();
}
}
}
//end of commands
//Messages
else if(ProtocolInfoTag=="0001"){//ANSWER_OF_GET_CLIENTVERSION
cUser* thisUser=Core->getUserByI2P_ID(ID);
if(thisUser!=NULL){
QString ClientVersion=Data.mid(4);
thisUser->set_ClientVersion(ClientVersion);
}
}
else if(ProtocolInfoTag=="0002"){//ANSWER_OF_GET_CLIENTNAME
cUser* thisUser=Core->getUserByI2P_ID(ID);
if(thisUser!=NULL){
QString Clientname=Data.mid(4);
thisUser->set_ClientName(Clientname);
}
}
else if(ProtocolInfoTag=="0003"){//chatmessage
cUser* thisUser=Core->getUserByI2P_ID(ID);
if(thisUser!=NULL){
QByteArray temp=Data.mid(4);
thisUser->IncomingNewChatMessage(temp);
emit eventUserChanged();
}
}
else if(ProtocolInfoTag=="0004"){//USER_ONLINESTATUS_ONLINE
cUser* thisUser=Core->getUserByI2P_ID(ID);
if(thisUser!=NULL){
QByteArray temp=Data.mid(4);
thisUser->set_OnlineState(USERONLINE);
emit eventUserChanged();
}
}
else if(ProtocolInfoTag=="0005"){//USER_ONLINESTATUS_OFFLINE || USER_ONLINESTATUS_INVISIBLE
cUser* thisUser=Core->getUserByI2P_ID(ID);
if(thisUser!=NULL){
QByteArray temp=Data.mid(4);
thisUser->set_OnlineState(USEROFFLINE);
emit eventUserChanged();
}
}
else if(ProtocolInfoTag=="0006"){//USER_ONLINESTATUS_WANTTOCHAT
cUser* thisUser=Core->getUserByI2P_ID(ID);
if(thisUser!=NULL){
QByteArray temp=Data.mid(4);
thisUser->set_OnlineState(USERWANTTOCHAT);
emit eventUserChanged();
}
}
else if(ProtocolInfoTag=="0007"){//USER_ONLINESTATUS_AWAY
cUser* thisUser=Core->getUserByI2P_ID(ID);
if(thisUser!=NULL){
QByteArray temp=Data.mid(4);
thisUser->set_OnlineState(USERAWAY);
emit eventUserChanged();
}
}
else if(ProtocolInfoTag=="0008"){//USER_ONLINESTATUS_DONT_DISTURB
cUser* thisUser=Core->getUserByI2P_ID(ID);
if(thisUser!=NULL){
QByteArray temp=Data.mid(4);
thisUser->set_OnlineState(USERDONT_DISTURB);
emit eventUserChanged();
}
}
//end Messages
}
QByteArray cProtocol::inputUnknown(const qint32 ID, const QByteArray Data){
using namespace Protocol_Info;
if(Core->isThisIDunknown(ID)==true){
//check if First Paket = from a other CHATSYSTEM
if(Data.contains("CHATSYSTEM\t")==true){
QByteArray temp=Data.mid(Data.indexOf("\t")+1,Data.indexOf("\n")-Data.indexOf("\t")-1);
QString version(temp);
//dont send the firstpacket if you have connected someone
//(the firstpacket is sended from core::StreamStatusRecived)
if(ID < 0)
newConnectionChat(ID);//someone connect you
Core->removeUnknownIDCreateUserIfNeeded(ID,version);
//remove Firstpacket
QByteArray Data2=Data;
Data2=Data2.remove(0,Data.indexOf("\n")+1);
return Data2;
}
else if(Data.contains("CHATSYSTEMFILETRANSFER\t")==true)
{
//FIRSTPAKET ="CHATSYSTEMFILETRANSFER\t"+PROTOCOLVERSION+"\nSizeinBit\nFileName";
QByteArray Data2=Data;
QString ProtovolVersion=Data2.mid(Data.indexOf("\t")+1,Data2.indexOf("\n")-Data2.indexOf("\t")-1);
Data2.remove(0,Data2.indexOf("\n")+1);//CHATSYSTEMFILETRANSFER\tPROTOCOLVERSION
QString FileSize=Data2.mid(0,Data2.indexOf("\n"));
Data2.remove(0,Data2.indexOf("\n")+1);
QString FileName=Data2;
Core->removeUnknownID(ID);
Core->addNewFileRecive(ID,FileName,FileSize);
Data2.clear();
return Data2;
}
else{
// not from a other CHATSYSTEM
Core->StreamSendData(ID,HTTPPAGE);
Core->StreamClose(ID);
Core->removeUnknownID(ID);
QByteArray Data2;
Data2.clear();
return Data2;
}
}
//not possible
return Data;
}
void cProtocol::send(const COMMANDS_TAGS TAG,const qint32 ID){
using namespace Protocol_Info;
QString ProtocolInfoTag;
QString Data="";
switch(TAG){
case PING:
{
ProtocolInfoTag="1000";
break;
}
case GET_CLIENTVERSION:
{
ProtocolInfoTag="1001";
break;
}
case GET_CLIENTNAME:
{
ProtocolInfoTag="1002";
break;
}
case GET_USER_ONLINESTATUS:
{
ProtocolInfoTag="1003";
break;
}
default:
{
break;
}
}
Data.insert(0,ProtocolInfoTag);
Data.insert(0,"0004");//No PaketData
Core->StreamSendData(ID,Data);
}
void cProtocol::send(const MESSAGES_TAGS TAG,const qint32 ID,QString Data){
QString ProtocolInfoTag;
switch(TAG)
{
case ECHO_OF_PING:
{
ProtocolInfoTag="0000";
break;
}
case ANSWER_OF_GET_CLIENTVERSION:
{
ProtocolInfoTag="0001";
break;
}
case ANSWER_OF_GET_CLIENTNAME:
{
ProtocolInfoTag="0002";
break;
}
case CHATMESSAGE:
{
ProtocolInfoTag="0003";
break;
}
case USER_ONLINESTATUS_ONLINE:
{
ProtocolInfoTag="0004";
break;
}
case USER_ONLINESTATUS_OFFLINE:
case USER_ONLINESTATUS_INVISIBLE:
{
ProtocolInfoTag="0005";
break;
}
case USER_ONLINESTATUS_WANTTOCHAT:
{
ProtocolInfoTag="0006";
break;
}
case USER_ONLINESTATUS_AWAY:
{
ProtocolInfoTag="0007";
break;
}
case USER_ONLINESTATUS_DONT_DISTURB:
{
ProtocolInfoTag="0008";
break;
}
default:
{
break;
}
}
QString temp;
temp.setNum(Data.length()+4,16);//hex
QString Paketlength=QString("%1").arg(temp,4,'0');
Data.insert(0,ProtocolInfoTag);
Data.insert(0,Paketlength);
Core->StreamSendData(ID,Data);
}

View file

@ -0,0 +1,95 @@
/***************************************************************************
* Copyright (C) 2008 by normal *
* normal@Desktop2 *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef PROTOCOL
#define PROTOCOL
#include <QtGui>
#include <QThread>
/*
First packet on connection must be:
CHATSYSTEM\tProtocolVersion\n
CHATSYSTEMFILETRANSFER\tProtocolVersion\nSizeinBit\nFileName
else
send <the html info-page > //maybe with information about the user ???
//maybe good for usersearch ?
Every packet must be >= 8 Byte
1-4 Byte = Paketlength in Byte (HEX) without the 4 Byte Paketlength
5-8 Byte = PaketInfo
>8 Byte = PaketData
*/
namespace Protocol_Info{
const QString PROTOCOLVERSION="0.2";
const QString FIRSTPAKETCHAT="CHATSYSTEM\t"+PROTOCOLVERSION+"\n";
const QString HTTPPAGE="<html><header></header><body>This is not a eepsite,this is a I2PMessenger Destination<br><br></body></html>\n\n\n";
};
namespace PROTOCOL_TAGS{
enum COMMANDS_TAGS{
PING,
GET_PROTOCOLVERSION,
GET_CLIENTVERSION,
GET_CLIENTNAME,
GET_USER_ONLINESTATUS
};
enum MESSAGES_TAGS{
CHATMESSAGE,
ECHO_OF_PING,
ANSWER_OF_GET_CLIENTVERSION,
ANSWER_OF_GET_CLIENTNAME,
USER_ONLINESTATUS_ONLINE,
USER_ONLINESTATUS_OFFLINE,
USER_ONLINESTATUS_INVISIBLE,
USER_ONLINESTATUS_WANTTOCHAT,
USER_ONLINESTATUS_AWAY,
USER_ONLINESTATUS_DONT_DISTURB
};
};
using namespace Protocol_Info;
using namespace PROTOCOL_TAGS;
class cCore;
class cUser;
class cProtocol:public QObject{
Q_OBJECT
public:
cProtocol(cCore* Core);
QString get_ProtocolVersion(){return PROTOCOLVERSION;};
public slots:
QByteArray inputUnknown(const qint32 ID,const QByteArray Data);
void inputKnown(const qint32 ID, const QByteArray Data);
void send(const MESSAGES_TAGS TAG,const qint32 ID,QString Data);
void send(const COMMANDS_TAGS TAG,const qint32 ID);
void newConnectionChat(const qint32 ID);
signals:
void eventUserChanged();//also used for newchatMessage
private:
cCore* Core;
};
#endif

View file

@ -0,0 +1,101 @@
/***************************************************************************
* Copyright (C) 2008 by normal *
* normal@Desktop2 *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "SoundManager.h"
cSoundManager::cSoundManager()
{
isMute=false;
reInit();
}
void cSoundManager::doMute(bool t)
{
isMute=t;
}
void cSoundManager::event_User_go_Online()
{
if(isMute==true) return;
if(enable_eventUser_go_Online)
QSound::play(SoundFileUser_go_Online);
}
void cSoundManager::event_User_go_Offline()
{
if(isMute==true) return;
if(enable_eventUser_go_Offline)
QSound::play(SoundFileUser_go_Offline);
}
void cSoundManager::event_FileSend_Finished()
{
if(isMute==true) return;
if(enable_eventFileSend_Finished)
QSound::play(SoundFileFileSend_Finished);
}
void cSoundManager::event_FileRecive_Incoming()
{
if(isMute==true) return;
if(enable_eventFileRecive_Incoming)
QSound::play(SoundFileFileRecive_Incoming);
}
void cSoundManager::event_FileRecive_Finished()
{
if(isMute==true) return;
if(enable_eventFileRecive_Finished)
QSound::play(SoundFileFileRecive_Finished);
}
void cSoundManager::event_NewChatMessage()
{
if(isMute==true) return;
if(enable_eventNewChatMessage)
{
QSound::play(SoundFileNewChatMessage);
}
}
void cSoundManager::reInit()
{
QSettings* settings= new QSettings(QApplication::applicationDirPath()+"/application.ini",QSettings::IniFormat);
settings->beginGroup("Sound");
settings->beginGroup("Enable");
enable_eventUser_go_Online=settings->value("User_go_Online",false).toBool();
enable_eventUser_go_Offline=settings->value("User_go_Offline",false).toBool();
enable_eventFileSend_Finished=settings->value("FileSend_Finished",false).toBool();
enable_eventFileRecive_Incoming=settings->value("FileRecive_Incoming",false).toBool();
enable_eventFileRecive_Finished=settings->value("FileRecive_Finished",false).toBool();
enable_eventNewChatMessage=settings->value("NewChatMessage",false).toBool();
settings->endGroup();
settings->beginGroup("SoundFilePath");
SoundFileUser_go_Online=settings->value("User_go_Online","").toString();
SoundFileUser_go_Offline=settings->value("User_go_Offline","").toString();
SoundFileFileSend_Finished=settings->value("FileSend_Finished","").toString();
SoundFileFileRecive_Incoming=settings->value("FileRecive_Incoming","").toString();
SoundFileFileRecive_Finished=settings->value("FileRecive_Finished","").toString();
SoundFileNewChatMessage=settings->value("NewChatMessage","").toString();
settings->endGroup();
settings->endGroup();
delete settings;
}

View file

@ -0,0 +1,61 @@
/***************************************************************************
* Copyright (C) 2008 by normal *
* normal@Desktop2 *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef SOUND_MANAGER_H
#define SOUND_MANAGER_H
#include <QSound>
#include <QSettings>
#include <QtGui>
class cSoundManager :public QObject
{
Q_OBJECT
public:
cSoundManager();
public slots:
void doMute(bool t);
void event_User_go_Online();
void event_User_go_Offline();
void event_FileSend_Finished();
void event_FileRecive_Incoming();
void event_FileRecive_Finished();
void event_NewChatMessage();
void reInit();
private:
bool isMute;
QString SoundFileUser_go_Online;
QString SoundFileUser_go_Offline;
QString SoundFileFileSend_Finished;
QString SoundFileFileRecive_Incoming;
QString SoundFileFileRecive_Finished;
QString SoundFileNewChatMessage;
bool enable_eventUser_go_Online;
bool enable_eventUser_go_Offline;
bool enable_eventFileSend_Finished;
bool enable_eventFileRecive_Incoming;
bool enable_eventFileRecive_Finished;
bool enable_eventNewChatMessage;
};
#endif

View file

@ -0,0 +1,224 @@
/***************************************************************************
* Copyright (C) 2008 by normal *
* normal@Desktop2 *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "User.h"
#include "Protocol.h"
cUser::cUser( cProtocol* Protocol,
QString Name,
QString I2PDestination,
qint32 I2PStream_ID
):I2PDestination(I2PDestination)
{
this->Protocol=Protocol;
this->Name=Name;
this->ReadyToSend=true;
this->I2PStream_ID=I2PStream_ID;
this->ConnectionStatus=OFFLINE;
this->HaveAllreadyOneChatWindow=false;
this->newUnreadMessages=false;
this->ClientName="";
this->ClientVersion="";
this->CurrentOnlineState=USEROFFLINE;
this->textColor=Qt::black;
this->textFont=QFont("Comic Sans MS", 10);
}
const QString cUser::get_Name()const{
return this->Name;
}
const QString cUser::get_I2PDestination()const{
return this->I2PDestination;
}
qint32 cUser::get_I2PStreamID()const{
return this->I2PStream_ID;
}
CONNECTIONTOUSER cUser::get_ConnectionStatus()const{
return this->ConnectionStatus;
}
void cUser::set_Name(QString newName){
this->Name=newName;
}
void cUser::set_ConnectionStatus(CONNECTIONTOUSER Status){
this->ConnectionStatus=Status;
if(Status==ONLINE){
this->ConnectionStatus=Status;
//get some Infos from the CHATSYSTEM - client
Protocol->send(GET_CLIENTNAME,I2PStream_ID);
Protocol->send(GET_CLIENTVERSION,I2PStream_ID);
Protocol->send(GET_USER_ONLINESTATUS,I2PStream_ID);
//emit connectionOnline();
}
if(Status==OFFLINE ||Status==ERROR)
{
I2PStream_ID=0;
this->CurrentOnlineState=USEROFFLINE;
this->ConnectionStatus=Status;
}
}
void cUser::set_I2PStreamID(qint32 ID){
this->I2PStream_ID=ID;
}
void cUser::set_ReadyToSend(bool b){
ReadyToSend=b;
}
void cUser::set_ProtocolVersion(QString Version){
this->ProtocolVersion=Version;
}
const QString cUser::get_ProtocolVersion()const{
return this->ProtocolVersion;
}
void cUser::IncomingNewChatMessage(QString newMessage){
this->Messages.push_back(Name+"("+ QTime::currentTime().toString("hh:mm:ss") +"): "+newMessage+"<br>");
this->newUnreadMessages=true;
emit newMessageRecived();
emit newIncomingMessageRecived();
}
void cUser::sendChatMessage(QString Message){
using namespace PROTOCOL_TAGS;
if(this->ReadyToSend==false)return;
if(ConnectionStatus==ONLINE &&
CurrentOnlineState != USEROFFLINE &&
CurrentOnlineState != USERINVISIBLE
){
Protocol->send(CHATMESSAGE,I2PStream_ID,Message);
this->Messages.push_back("Me("+QTime::currentTime().toString("hh:mm:ss") +"): "+Message+"<br>");
//this->Messages.push_back(Message);
emit newMessageRecived();
}
else{
this->Messages.push_back("[SYSTEM]("+QTime::currentTime().toString("hh:mm:ss") +"): Sending the Message when the user come online<br>When you close the client the Message is lost<br>");
unsendedMessages.push_back(Message);
emit newMessageRecived();
}
}
void cUser::set_HaveAllreadyOneChatWindow(bool t){
HaveAllreadyOneChatWindow=t;
}
bool cUser::getHaveAllreadyOneChatWindow() const{
return HaveAllreadyOneChatWindow;
}
const QStringList& cUser::get_ChatMessages(){
newUnreadMessages=false;
return Messages;
}
void cUser::sendAllunsendedMessages(){
using namespace PROTOCOL_TAGS;
if(unsendedMessages.empty())return;
for(int i=0;i<unsendedMessages.count();i++)
Protocol->send(CHATMESSAGE,I2PStream_ID,unsendedMessages.at(i));
this->Messages.push_back("[SYSTEM]("+QTime::currentTime().toString("hh:mm:ss")+"): All unsended Messages were sended<br><br>");
unsendedMessages.clear();
this->newUnreadMessages=true;
emit newMessageRecived();
}
bool cUser::getHaveNewUnreadMessages(){
return newUnreadMessages;
}
const QString cUser::get_ClientName() const
{
return ClientName;
}
void cUser::set_ClientName(QString Name)
{
ClientName=Name;
}
const QString cUser::get_ClientVersion() const
{
return ClientVersion;
}
void cUser::set_ClientVersion(QString Version)
{
this->ClientVersion=Version;
}
ONLINESTATE cUser::get_OnlineState() const
{
return CurrentOnlineState;
}
void cUser::set_OnlineState(const ONLINESTATE newState)
{
if(newState!=USEROFFLINE &&
newState!=USERINVISIBLE){
if(CurrentOnlineState==USEROFFLINE || CurrentOnlineState==USERINVISIBLE)
emit connectionOnline();
this->sendAllunsendedMessages();
}
else if(newState==USEROFFLINE || newState==USERINVISIBLE){
if(newState!=CurrentOnlineState)
emit connectionOffline();
}
this->CurrentOnlineState=newState;
emit OnlineStateChanged();
}
QColor cUser::get_textColor()
{
return textColor;
}
void cUser::set_textColor(QColor textColor)
{
this->textColor=textColor;
}
void cUser::set_textFont(QFont textFont)
{
this->textFont=textFont;
}
QFont cUser::get_textFont()
{
return textFont;
}
void cUser::IncomingMessageFromSystem(QString newMessage)
{
this->Messages.push_back("[System]("+ QTime::currentTime().toString("hh:mm:ss") +"): "+newMessage+"<br>");
this->newUnreadMessages=true;
emit newMessageRecived();
emit newIncomingMessageRecived();
}

View file

@ -0,0 +1,127 @@
/***************************************************************************
* Copyright (C) 2008 by normal *
* normal@Desktop2 *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef USER_H
#define USER_H
#include <QtGui>
#include <QStringList>
#include <QTime>
namespace User
{
enum CONNECTIONTOUSER{
OFFLINE,
ONLINE,
TRYTOCONNECT,
ERROR
};
enum ONLINESTATE{
USERONLINE,
USEROFFLINE,
USERINVISIBLE,
USERWANTTOCHAT,
USERAWAY,
USERDONT_DISTURB,
USERTRYTOCONNECT
};
}//namespace user
using namespace User;
class cProtocol;
class cUser: public QObject
{
Q_OBJECT
public:
cUser( cProtocol* Protocol,
QString Name,
QString I2PDestination,
qint32 I2PStream_ID
);
const QString get_Name()const;
const QString get_I2PDestination()const;
qint32 get_I2PStreamID()const;
const QString get_ProtocolVersion()const;
const QString get_ClientName()const;
const QString get_ClientVersion()const;
QColor get_textColor();
QFont get_textFont();
CONNECTIONTOUSER get_ConnectionStatus()const;
ONLINESTATE get_OnlineState()const;
const QStringList &get_ChatMessages();
bool getHaveAllreadyOneChatWindow()const;
bool getHaveNewUnreadMessages();
void set_ConnectionStatus(CONNECTIONTOUSER Status);
void set_OnlineState(const ONLINESTATE newState);
void set_Name(QString newName);
void set_I2PStreamID(qint32 ID);
void set_ReadyToSend(bool b);
void set_ProtocolVersion(QString Version);
void set_HaveAllreadyOneChatWindow(bool t);
void set_ClientName(QString Name);
void set_ClientVersion(QString Version);
void IncomingNewChatMessage(QString newMessage);
void IncomingMessageFromSystem(QString newMessage);
void set_textColor(QColor textColor);
void set_textFont(QFont textFont);
public slots:
void sendChatMessage(QString Message);
signals:
void OnlineStateChanged();
void newMessageRecived();
void newIncomingMessageRecived();
void connectionOnline();
void connectionOffline();
private:
bool HaveAllreadyOneChatWindow;
bool newUnreadMessages;
void sendAllunsendedMessages();
const QString I2PDestination;
QString Name;
qint32 I2PStream_ID;
bool ReadyToSend;
CONNECTIONTOUSER ConnectionStatus;
ONLINESTATE CurrentOnlineState;
QString ProtocolVersion;
QString ClientName;
QString ClientVersion;
QStringList Messages;
QStringList unsendedMessages;
cProtocol* Protocol;
//Settings for the chatwindow
QColor textColor;
QFont textFont;
};
#endif

View file

@ -0,0 +1,58 @@
/***************************************************************************
* Copyright (C) 2008 by normal *
* normal@Desktop2 *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "UserConnectThread.h"
cUserConnectThread::cUserConnectThread(cCore* core,quint32 timeToWait=30000)
{ this->core=core;
this->timeToWait=timeToWait;
this->timer= new QTimer();
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
}
cUserConnectThread::~cUserConnectThread()
{
stop();
disconnect(timer, SIGNAL(timeout()), this, SLOT(update()));
}
void cUserConnectThread::update()
{
QList<cUser*> users=core->get_userList();
for(int i=0;i<users.count();i++){
if(users.at(i)->get_ConnectionStatus()==OFFLINE){
if(core->isThisDestinationInunknownConnections(users.at(i)->get_I2PDestination())==false){
users.at(i)->set_ConnectionStatus(TRYTOCONNECT);
users.at(i)->set_I2PStreamID(core->StreamConnect(users.at(i)->get_I2PDestination()));
//users.at(i)->set_I2PStreamID(emit doStreamConnect(users.at(i)->get_I2PDestination()));
}
}
}
}
void cUserConnectThread::start()
{
timer->start(timeToWait);
}
void cUserConnectThread::stop()
{
timer->stop();
}

View file

@ -0,0 +1,52 @@
/***************************************************************************
* Copyright (C) 2008 by normal *
* normal@Desktop2 *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef USERCONNECTTHREAD_H
#define USERCONNECTTHREAD_H
#include <QList>
#include <QTimer>
#include "User.h"
#include "Core.h"
class cCore;
class cUserConnectThread :public QObject
{
Q_OBJECT
public:
cUserConnectThread(cCore* core,quint32 timeToWait);
~cUserConnectThread();
//void run();
void stop();
void start();
signals:
QString doStreamConnect ( QString Destination );
private:
cCore* core;
QTimer* timer;
quint32 timeToWait;
private slots:
void update();
};
#endif