soc.2009.transport: c538790d: Added fallback SendFile class if XMPP us...
hanzz at soc.pidgin.im
hanzz at soc.pidgin.im
Sat Aug 8 07:45:58 EDT 2009
-----------------------------------------------------------------
Revision: c538790d6e74c74ddbbadb613e4cd0c96c8c23e4
Ancestor: 267a0ac84edd3b91e76f132a6129daed1bd6ca27
Author: hanzz at soc.pidgin.im
Date: 2009-08-08T11:39:29
Branch: im.pidgin.soc.2009.transport
URL: http://d.pidgin.im/viewmtn/revision/info/c538790d6e74c74ddbbadb613e4cd0c96c8c23e4
Modified files:
CMakeLists.txt filetransfermanager.cpp filetransfermanager.h
filetransferrepeater.cpp filetransferrepeater.h main.cpp
main.h
ChangeLog:
Added fallback SendFile class if XMPP user can't receive file from legacy network
-------------- next part --------------
============================================================
--- CMakeLists.txt 01df60a83a21339a3f65cb27a0ff632a665d16ad
+++ CMakeLists.txt 7f4b942ff45fda5a04b0bb1cd4a7b7de372b60f2
@@ -61,7 +61,6 @@
discoinfohandler.cpp
filetransfermanager.cpp
filetransferrepeater.cpp
- sendfile.cpp
thread.cpp
gatewayhandler.cpp
geventloop.cpp
@@ -104,7 +103,6 @@
discoinfohandler.h
filetransfermanager.h
filetransferrepeater.h
- sendfile.h
thread.h
gatewayhandler.h
log.h
============================================================
--- filetransfermanager.cpp 406f38d2b235b85ef50768ae337ded8b34d36130
+++ filetransfermanager.cpp 004dd5fedef5cc62dc0e28665f1a87f7409a98af
@@ -72,30 +72,6 @@ void FileTransferManager::handleFTBytest
void FileTransferManager::handleFTBytestream (Bytestream *bs) {
Log().Get("a") << "handleFTBytestream";
if (std::find(m_sendlist.begin(), m_sendlist.end(), bs->target().full()) == m_sendlist.end()) {
-// if (m_info[bs->sid()].straight == false){
-// std::string filename = m_info[bs->sid()].filename;
-// // replace invalid characters
-// for (std::string::iterator it = filename.begin(); it != filename.end(); ++it) {
-// if (*it == '\\' || *it == '&' || *it == '/' || *it == '?' || *it == '*' || *it == ':') {
-// *it = '_';
-// }
-// }
-// filename=p->configuration().filetransferCache+"/"+bs->target().username()+"-"+p->j->getID()+"-"+filename;
-//
-// mutex->lock();
-// m_progress[bs->sid()].filename=filename;
-// m_progress[bs->sid()].incoming=true;
-// m_progress[bs->sid()].state=0;
-// m_progress[bs->sid()].user=bs->initiator().bare();
-// m_progress[bs->sid()].to=bs->initiator();
-// m_progress[bs->sid()].from=bs->target();
-// m_progress[bs->sid()].stream=bs;
-// std::cout << "FROM:" << bs->initiator().full() << " TO:" << bs->target().full();
-//
-// mutex->unlock();
-// new ReceiveFile(bs,filename, m_info[bs->sid()].size,mutex,this);
-// }
-// else {
std::string filename = "";
if (m_info[bs->sid()].straight == false) {
filename = m_info[bs->sid()].filename;
@@ -135,7 +111,7 @@ void FileTransferManager::handleFTBytest
// m_progress[s5b->sid()].incoming=false;
// m_progress[s5b->sid()].state=0;
// mutex->unlock();
- new SendFile(bs, m_info[bs->sid()].filename, m_info[bs->sid()].size,mutex,this);
+// new SendFile(bs, m_info[bs->sid()].filename, m_info[bs->sid()].size,mutex,this);
m_sendlist.erase(std::find(m_sendlist.begin(), m_sendlist.end(), bs->target().full()));
}
m_info.erase(bs->sid());
============================================================
--- filetransfermanager.h 63d3890cc2bf99a7cac9b875dfaf79dd5f817f24
+++ filetransfermanager.h ab7f45040f1a4d357128d3d397f7f0b9fe8c9327
@@ -21,7 +21,7 @@
#ifndef FILETRANSFERMANAGER_H
#define FILETRANSFERMANAGER_H
-#include "sendfile.h"
+// #include "sendfile.h"
#include "thread.h"
#include <sys/stat.h>
@@ -47,19 +47,17 @@ class FileTransferManager : public gloox
};
class FileTransferManager : public gloox::SIProfileFTHandler {
- struct Info {
- std::string filename;
- int size;
- bool straight;
- };
+ public:
+ struct Info {
+ std::string filename;
+ int size;
+ bool straight;
+ };
- std::map<std::string, Info> m_info;
-
- std::list<std::string> m_sendlist;
-
-
-
- public:
+ std::map<std::string, Info> m_info;
+
+ std::list<std::string> m_sendlist;
+
GlooxMessageHandler *p;
gloox::SIProfileFT *m_sip;
MyMutex *mutex;
============================================================
--- filetransferrepeater.cpp 45a085d175312677d51779caade13fe07c11d731
+++ filetransferrepeater.cpp 903090e5dc11b09473a34cdac108f0e52db2d4fd
@@ -22,6 +22,92 @@
#include "main.h"
#include "usermanager.h"
+
+SendFile::SendFile(Bytestream *stream, int size, const std::string &filename, User *user, FiletransferRepeater *manager) {
+ std::cout << "SendFile::SendFile" << " Constructor.\n";
+ m_stream = stream;
+ m_size = size;
+ m_filename = filename;
+ m_user = user;
+ m_stream->registerBytestreamDataHandler (this);
+ m_parent = manager;
+ if (m_stream->connect())
+ std::cout << "stream connected\n";
+ run();
+}
+
+SendFile::~SendFile() {
+
+}
+
+void SendFile::exec() {
+ std::cout << "SendFile::exec Starting transfer.\n";
+ char input[200024];
+ int ret;
+ bool empty;
+ m_file.open(m_filename.c_str(), std::ios_base::out | std::ios_base::binary );
+ if (!m_file) {
+ Log().Get(m_filename) << "can't create this file!";
+ return;
+ }
+ while (true) {
+ if (m_stream->isOpen()){
+// std::cout << "sending...\n";
+ std::string data;
+// if (getBuffer().size() > size) {
+// data = repeater->getBuffer().substr(0, size);
+// repeater->getBuffer().erase(0, size);
+// }
+// else {
+// getBuffer();
+// getBuffer().erase();
+// }
+// m_file.read(input, 200024);
+ getMutex()->lock();
+ std::string t;
+ if (m_parent->getBuffer().empty())
+ empty = true;
+ else {
+ empty = false;
+ t = std::string(m_parent->getBuffer());
+ m_parent->getBuffer().erase();
+ }
+ getMutex()->unlock();
+ if (!empty) {
+ m_file.write(t.c_str(), t.size());
+ if(ret<1){
+ std::cout << "error in sending or sending probably finished\n";
+ break;
+ };
+ }
+ }
+ m_stream->recv(200);
+ }
+ m_file.close();
+ dispose();
+ delete this;
+}
+
+void SendFile::dispose() {
+ m_parent->parent()->ft->dispose(m_stream);
+}
+
+void SendFile::handleBytestreamData(gloox::Bytestream *s5b, const std::string &data) {
+ std::cout << "socks stream data\n";
+}
+
+void SendFile::handleBytestreamError(gloox::Bytestream *s5b, const gloox::IQ &iq) {
+
+}
+
+void SendFile::handleBytestreamOpen(gloox::Bytestream *s5b) {
+ std::cout << "socks stream open\n";
+}
+
+void SendFile::handleBytestreamClose(gloox::Bytestream *s5b) {
+ std::cout << "socks stream error\n";
+}
+
SendFileStraight::SendFileStraight(Bytestream *stream, int size, FiletransferRepeater *manager) {
std::cout << "SendFileStraight::SendFileStraight" << " Constructor.\n";
m_stream = stream;
@@ -289,10 +375,14 @@ void FiletransferRepeater::fileRecvStart
Log().Get("SendFileStraight") << "fileRecvStart!" << m_from.full() << " " << m_to.full();
}
-void FiletransferRepeater::requestFT() {
+std::string FiletransferRepeater::requestFT() {
// purple_xfer_request_accepted(xfer, std::string(filename).c_str());
std::string filename(purple_xfer_get_filename(m_xfer));
m_sid = m_main->ft->requestFT(m_to, filename, purple_xfer_get_size(m_xfer), EmptyString, EmptyString, EmptyString, EmptyString, SIProfileFT::FTTypeAll, m_from);
+ m_main->ftManager->m_info[m_sid].filename = filename;
+ m_main->ftManager->m_info[m_sid].size = purple_xfer_get_size(m_xfer);
+ m_main->ftManager->m_info[m_sid].straight = true;
+ return m_sid;
}
void FiletransferRepeater::handleFTReceiveBytestream(Bytestream *bs, const std::string &filename) {
@@ -308,7 +398,12 @@ void FiletransferRepeater::handleFTSendB
void FiletransferRepeater::handleFTSendBytestream(Bytestream *bs, const std::string &filename) {
Log().Get("SendFileStraight") << "new!";
purple_xfer_request_accepted(m_xfer, NULL);
- m_resender = new SendFileStraight(bs, 0, this);
+ if (filename.empty())
+ m_resender = new SendFileStraight(bs, 0, this);
+ else {
+ User *user = m_main->userManager()->getUserByJID(bs->initiator().bare());
+ m_resender = new SendFile(bs, 0, filename, user, this);
+ }
}
void FiletransferRepeater::gotData(const std::string &data) {
============================================================
--- filetransferrepeater.h 44ba8829587203fcb471681931ec4047b443c993
+++ filetransferrepeater.h 57fb2bdcaa75fa510bdf88b874e506777a78f775
@@ -101,6 +101,30 @@ class ReceiveFileStraight : public Abstr
std::ofstream m_file;
};
+class SendFile : public AbstractResendClass, public BytestreamDataHandler, public Thread {
+ public:
+ SendFile(Bytestream *stream, int size, const std::string &filename, User *user, FiletransferRepeater *manager);
+ ~SendFile();
+
+ void exec();
+ void handleBytestreamData(Bytestream *s5b, const std::string &data);
+ void handleBytestreamError(Bytestream *s5b, const IQ &iq);
+ void handleBytestreamOpen(Bytestream *s5b);
+ void handleBytestreamClose(Bytestream *s5b);
+
+ std::string &filename() { return m_filename; }
+ User *user() { return m_user; }
+ void dispose();
+
+ private:
+ Bytestream *m_stream;
+ std::string m_filename;
+ User *m_user;
+ int m_size;
+ FiletransferRepeater *m_parent;
+ std::ofstream m_file;
+};
+
class SendFileStraight : public AbstractResendClass, public BytestreamDataHandler, public Thread {
public:
SendFileStraight(Bytestream *stream, int size, FiletransferRepeater *manager);
@@ -132,7 +156,7 @@ class FiletransferRepeater {
void handleFTReceiveBytestream(Bytestream *bs, const std::string &filename = "");
void handleFTSendBytestream(Bytestream *bs, const std::string &filename = "");
void gotData(const std::string &data);
- void requestFT();
+ std::string requestFT();
bool isSending() { return m_send; }
============================================================
--- main.cpp 19bc5edc5490708cbbce2eb55ad1be70fe6cd18c
+++ main.cpp 30f0d73f1b9ed3bc5268437e82e560f9a8a0c7b2
@@ -1048,7 +1048,13 @@ void GlooxMessageHandler::purpleFileRece
User *user = userManager()->getUserByAccount(purple_xfer_get_account(xfer));
if (user!=NULL){
FiletransferRepeater *repeater = (FiletransferRepeater *) xfer->ui_data;
- repeater->requestFT();
+ if(user->hasFeature(GLOOX_FEATURE_FILETRANSFER)){
+ repeater->requestFT();
+ }
+ else {
+ purple_xfer_request_accepted(xfer, std::string(configuration().filetransferCache+"/"+remote_user+"-"+j->getID()+"-"+filename).c_str());
+ }
+
// std::string sid = GlooxMessageHandler::instance()->ft->requestFT(jid, name, info.st_size, EmptyString, EmptyString, EmptyString, EmptyString, SIProfileFT::FTTypeAll, from);
// purple_xfer_request_accepted(xfer, std::string(filename).c_str());
// if(user->hasFeature(GLOOX_FEATURE_FILETRANSFER)){
@@ -1073,36 +1079,15 @@ void GlooxMessageHandler::purpleFileRece
User *user = userManager()->getUserByAccount(purple_xfer_get_account(xfer));
if (user!=NULL) {
if (user->isConnected()) {
- Log().Get(user->jid()) << "Trying to send file " << filename;
- if(user->hasFeature(GLOOX_FEATURE_FILETRANSFER)) {
- if (user->hasTransportFeature(TRANSPORT_FEATURE_FILETRANSFER)) {
- Log().Get(user->jid()) << "Trying to send file got feature";
- fileTransferData *data = new fileTransferData;
- data->to=user->jid() + "/" + user->resource();
- data->from=remote_user+"@"+jid()+"/bot";
- data->filename=localname;
- data->name=filename;
- g_timeout_add_seconds(1,&sendFileToJabber,data);
- sql()->addDownload(basename,"1");
- }
- else {
- sql()->addDownload(basename,"0");
- }
- Message s(Message::Chat, user->jid(), tr(user->getLang(),_("File '"))+filename+tr(user->getLang(),_("' was received. You can download it here: ")) + "http://soumar.jabbim.cz/icq/" + basename +" .");
- s.setFrom(remote_user+"@"+jid()+"/bot");
- j->send(s);
+ if (user->isVIP()){
+ sql()->addDownload(basename,"1");
}
- else{
- if (user->isVIP()){
- sql()->addDownload(basename,"1");
- }
- else {
- sql()->addDownload(basename,"0");
- }
- Message s(Message::Chat, user->jid(), tr(user->getLang(),_("File '"))+filename+tr(user->getLang(),_("' was received. You can download it here: ")) + "http://soumar.jabbim.cz/icq/" + basename +" .");
- s.setFrom(remote_user+"@"+jid()+"/bot");
- j->send(s);
+ else {
+ sql()->addDownload(basename,"0");
}
+ Message s(Message::Chat, user->jid(), tr(user->getLang(),_("File '"))+filename+tr(user->getLang(),_("' was received. You can download it here: ")) + "http://soumar.jabbim.cz/icq/" + basename +" .");
+ s.setFrom(remote_user+"@"+jid()+"/bot");
+ j->send(s);
}
else{
Log().Get(user->jid()) << "purpleFileReceiveComplete called for unconnected user...";
============================================================
--- main.h 29b16ab6ffb8faccf29b98a53300df46355bf69d
+++ main.h 2026e71234b79638a034638c0e2e4b775bf5fb1f
@@ -73,6 +73,7 @@
#include "caps.h"
#include "sql.h"
#include "user.h"
+class FileTransferManager;
#include "filetransfermanager.h"
#include <sys/stat.h>
#include <sys/types.h>
More information about the Commits
mailing list