soc.2009.transport: 8aea4cab: Fixed filetranfer with the gloox from sv...

hanzz at soc.pidgin.im hanzz at soc.pidgin.im
Sun Jul 19 06:45:51 EDT 2009


-----------------------------------------------------------------
Revision: 8aea4cab92d285662ec2653fe6e5d4c12b4f31d5
Ancestor: 9f8877196ba856e62edc2d1eaf807d7e19cfba27
Author: hanzz at soc.pidgin.im
Date: 2009-07-19T10:41:54
Branch: im.pidgin.soc.2009.transport
URL: http://d.pidgin.im/viewmtn/revision/info/8aea4cab92d285662ec2653fe6e5d4c12b4f31d5

Modified files:
        filetransfermanager.cpp filetransfermanager.h
        receivefile.cpp receivefile.h sendfile.cpp sendfile.h

ChangeLog: 

Fixed filetranfer with the gloox from svn. You will need patched gloox to compile this, but I hope Jakob will commit it :).

-------------- next part --------------
============================================================
--- filetransfermanager.cpp	3ef8debce199cd87fb38294930eb21e2ebc104dc
+++ filetransfermanager.cpp	3a5a120a59944b9f1bcadc34d8f002533649b39e
@@ -25,55 +25,38 @@ void FileTransferManager::setSIProfileFT
 	p = parent;
 	mutex = new MyMutex();
 }
-/*
-void FileTransferManager::handleFTRequest( const gloox::JID &from,const gloox::JID &to, const std::string &id, const std::string &sid,
-                                             const std::string &name, long size, const std::string &hash,
-                                             const std::string &date, const std::string &mimetype,
-                                             const std::string &desc, int stypes, long offset, long length) {
-     std::cout << "Received file transfer request from " << from.full() << ".\n";
-     m_info[sid].filename = name;
-     m_info[sid].size = size;
-     m_sip->acceptFT( from, to, id, gloox::SIProfileFT::FTTypeS5B );
-}
 
-void FileTransferManager::handleFTRequestError(gloox::Stanza *stanza, const std::string &sid) {
-//     Log::i().log(LogStageError, "FileTransferManager::handleFTRequestError", "Received file transfer error from " + stanza->findAttribute("from") + ".");
-//     Log::i().log(LogStageError, "FileTransferManager::handleFTRequestError", stanza->xml());
+void FileTransferManager::handleFTRequest (const JID &from, const JID &to, const std::string &sid, const std::string &name, long size, const std::string &hash, const std::string &date, const std::string &mimetype, const std::string &desc, int stypes, long offset, long length) {
+	std::cout << "Received file transfer request from " << from.full() << ".\n";
+	m_info[sid].filename = name;
+	m_info[sid].size = size;
+	m_sip->acceptFT(from, to, sid);
 }
 
-void FileTransferManager::handleFTSOCKS5Bytestream(gloox::SOCKS5Bytestream *s5b) {
-//     Log::i().log(LogStageDebug, "FileTransferManager::handleFTSOCKS5Bytestream", "Incomming Bytestream.");
 
-
-	if (std::find(m_sendlist.begin(), m_sendlist.end(), s5b->target().full()) == m_sendlist.end()) {
-
-
-		std::string filename = m_info[s5b->sid()].filename;
-		
-// 		std::string filename;
-	
-// 		filename.resize(tempname.size());
-	
+void FileTransferManager::handleFTBytestream (Bytestream *bs) {
+	if (std::find(m_sendlist.begin(), m_sendlist.end(), bs->target().full()) == m_sendlist.end()) {
+		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+"/"+s5b->target().username()+"-"+p->j->getID()+"-"+filename;
+		filename=p->configuration().filetransferCache+"/"+bs->target().username()+"-"+p->j->getID()+"-"+filename;
 		
 		mutex->lock();
-		m_progress[s5b->sid()].filename=filename;
-		m_progress[s5b->sid()].incoming=true;
-		m_progress[s5b->sid()].state=0;
-		m_progress[s5b->sid()].user=s5b->from().bare();
-		m_progress[s5b->sid()].to=s5b->from();
-		m_progress[s5b->sid()].from=s5b->target();
-		m_progress[s5b->sid()].stream=s5b;
-		std::cout << "FROM:" << s5b->initiator().full();
+		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(s5b,filename, m_info[s5b->sid()].size,mutex,this);
+		new ReceiveFile(bs,filename, m_info[bs->sid()].size,mutex,this);
     } else {
 		// zatim to nepotrebujem u odchozich filu
 // 		mutex->lock();
@@ -81,10 +64,10 @@ void FileTransferManager::handleFTSOCKS5
 // 		m_progress[s5b->sid()].incoming=false;
 // 		m_progress[s5b->sid()].state=0;
 // 		mutex->unlock();
-        new SendFile(s5b, m_info[s5b->sid()].filename, m_info[s5b->sid()].size,mutex,this);
-        m_sendlist.erase(std::find(m_sendlist.begin(), m_sendlist.end(), s5b->target().full()));
+        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(s5b->sid());
+    m_info.erase(bs->sid());
 }
 
 void FileTransferManager::sendFile(std::string jid, std::string from, std::string name, std::string file) {
@@ -98,11 +81,11 @@ void FileTransferManager::sendFile(std::
             return;
         }
 		std::cout << "requesting filetransfer " << jid <<" " << file <<" as " << name << " " << info.st_size << "\n";
-        std::string sid = m_sip->requestFT(jid,from,name, file, info.st_size);
+        std::string sid = m_sip->requestFT(jid, from, /*name,*/ file, info.st_size);
         m_info[sid].filename = file;
         m_info[sid].size = info.st_size;
         f.close();
     } else {
         std::cout << "FileTransferManager::sendFile" << " Couldn't open the file " << file << "!\n";
     }
-}*/
+}
============================================================
--- filetransfermanager.h	2642a6f8e59527e873627d9b37a39327adcb136f
+++ filetransfermanager.h	6c9550305dbc66316b10b1c68ebf61ca888b50ee
@@ -43,7 +43,7 @@ struct progress {
 	gloox::JID from;
 	gloox::JID to;
 	std::string user;
-	gloox::SOCKS5Bytestream *stream;
+	gloox::Bytestream *stream;
 	
 };
 
@@ -73,11 +73,11 @@ class FileTransferManager : public gloox
 // 		void handleFTRequestError(gloox::Stanza *stanza, const std::string &sid);
 
 // 		void handleFTSOCKS5Bytestream(gloox::SOCKS5Bytestream *s5b);
-		void handleFTRequest (const JID &from, const std::string &sid, const std::string &name, long size, const std::string &hash, const std::string &date, const std::string &mimetype, const std::string &desc, int stypes, long offset, long length) {}
+		void handleFTRequest (const JID &from, const JID &to, const std::string &sid, const std::string &name, long size, const std::string &hash, const std::string &date, const std::string &mimetype, const std::string &desc, int stypes, long offset, long length);
 		void handleFTRequestError (const IQ &iq, const std::string &sid) {}
-		void handleFTBytestream (Bytestream *bs) {}
-		const std::string handleOOBRequestResult (const JID &from, const std::string &sid) { return ""; }
+		void handleFTBytestream (Bytestream *bs);
+		const std::string handleOOBRequestResult (const JID &from, const JID &to, const std::string &sid) { return ""; }
 
-		void sendFile(std::string jid,std::string from,std::string name, std::string file) {}
+		void sendFile(std::string jid,std::string from,std::string name, std::string file);
 	};
 #endif
============================================================
--- receivefile.cpp	0a4c37f5e23e9531b2e3b55eef5bab39748f6c8d
+++ receivefile.cpp	76fb7d232b8d996296541d415a7475551a29e470
@@ -67,7 +67,7 @@ static gboolean transferFinished(gpointe
 	return FALSE;
 }
 
-ReceiveFile::ReceiveFile(gloox::SOCKS5Bytestream *stream, std::string filename, int size, MyMutex *mutex, FileTransferManager *manager) {
+ReceiveFile::ReceiveFile(gloox::Bytestream *stream, std::string filename, int size, MyMutex *mutex, FileTransferManager *manager) {
     m_stream = stream;
     m_size = size;
     m_filename = filename;
@@ -107,20 +107,20 @@ void ReceiveFile::exec() {
 //     m_finished = true;
 }
 
-void ReceiveFile::handleSOCKS5Data(gloox::SOCKS5Bytestream *s5b, const std::string &data) {
+void ReceiveFile::handleBytestreamData(gloox::Bytestream *s5b, const std::string &data) {
     m_file.write(data.c_str(), data.size());
 }
 
-void ReceiveFile::handleSOCKS5Error(gloox::SOCKS5Bytestream *s5b, gloox::Stanza *stanza) {
+void ReceiveFile::handleBytestreamError(gloox::Bytestream *s5b, const gloox::IQ &iq) {
 	Log().Get(m_filename) << "STREAM ERROR!";
 // 	Log().Get(m_filename) << stanza->xml();
 }
 
-void ReceiveFile::handleSOCKS5Open(gloox::SOCKS5Bytestream *s5b) {
+void ReceiveFile::handleBytestreamOpen(gloox::Bytestream *s5b) {
     Log().Get(m_filename) << "stream opened...";
 }
 
-void ReceiveFile::handleSOCKS5Close(gloox::SOCKS5Bytestream *s5b) {
+void ReceiveFile::handleBytestreamClose(gloox::Bytestream *s5b) {
     if (m_finished){
 		Log().Get(m_filename) << "Transfer finished and we're already finished => deleting receiveFile thread";
 // 		delete this;
============================================================
--- receivefile.h	4098cb1698b5b72b9e543cc2980e9e85c872a6c2
+++ receivefile.h	7bea2daa7c8ece5bc840fe8fd1462b82c443ccc7
@@ -22,8 +22,8 @@
 #define RECEIVEFILE_H
 #include "thread.h"
 
-#include <gloox/socks5bytestreamdatahandler.h>
-#include <gloox/socks5bytestream.h>
+#include <gloox/bytestreamdatahandler.h>
+#include <gloox/bytestream.h>
 class FileTransferManager;
 class GlooxMessageHandler;
 #include <iostream>
@@ -33,9 +33,10 @@ struct progress;
 
 struct progress;
 
-class ReceiveFile : public gloox::SOCKS5BytestreamDataHandler,
+class ReceiveFile : public gloox::BytestreamDataHandler,
                     public Thread {
-    gloox::SOCKS5Bytestream *m_stream;
+public:
+	gloox::Bytestream *m_stream;
     std::string m_filename;
     int m_size;
     bool m_finished;
@@ -44,20 +45,20 @@ class ReceiveFile : public gloox::SOCKS5
 	FileTransferManager *m_parent;
 
     std::ofstream m_file;
-public:
-    ReceiveFile(gloox::SOCKS5Bytestream *stream, std::string filename, int size, MyMutex *mutex, FileTransferManager *manager);
 
+    ReceiveFile(gloox::Bytestream *stream, std::string filename, int size, MyMutex *mutex, FileTransferManager *manager);
+
     ~ReceiveFile();
 
     void exec();
 
-    void handleSOCKS5Data(gloox::SOCKS5Bytestream *s5b, const std::string &data);
+    void handleBytestreamData(gloox::Bytestream *s5b, const std::string &data);
 
-    void handleSOCKS5Error(gloox::SOCKS5Bytestream *s5b, gloox::Stanza *stanza);
+    void handleBytestreamError(gloox::Bytestream *s5b, const gloox::IQ &iq);
 
-    void handleSOCKS5Open(gloox::SOCKS5Bytestream *s5b);
+    void handleBytestreamOpen(gloox::Bytestream *s5b);
 
-    void handleSOCKS5Close(gloox::SOCKS5Bytestream *s5b);
+    void handleBytestreamClose(gloox::Bytestream *s5b);
 };
 
 #endif
============================================================
--- sendfile.cpp	a8df3e38ada722ba777e6e155db8998bf90ac747
+++ sendfile.cpp	490c044bdc6f0924af407f028ccd87d69f702284
@@ -20,12 +20,12 @@
 
 #include "sendfile.h"
 
-SendFile::SendFile(gloox::SOCKS5Bytestream *stream, std::string filename, int size, MyMutex *mutex, FileTransferManager *manager) {
+SendFile::SendFile(gloox::Bytestream *stream, std::string filename, int size, MyMutex *mutex, FileTransferManager *manager) {
     std::cout << "SendFile::SendFile" << " Constructor.\n";
     m_stream = stream;
     m_filename = filename;
     m_size = size;
-//     m_stream->registerSOCKS5BytestreamDataHandler(this);
+//     m_stream->registerBytestreamBytestreamDataHandler(this);
 	m_mutex = mutex;
 	m_parent = manager;
 	if (m_stream->connect())
@@ -65,18 +65,18 @@ void SendFile::exec() {
     delete this;
 }
 
-void SendFile::handleSOCKS5Data(gloox::SOCKS5Bytestream *s5b, const std::string &data) {
+void SendFile::handleBytestreamData(gloox::Bytestream *s5b, const std::string &data) {
 	std::cout << "socks stream data\n";
 }
 
-void SendFile::handleSOCKS5Error(gloox::SOCKS5Bytestream *s5b, gloox::Stanza *stanza) {
+void SendFile::handleBytestreamError(gloox::Bytestream *s5b, const gloox::IQ &iq) {
 
 }
 
-void SendFile::handleSOCKS5Open(gloox::SOCKS5Bytestream *s5b) {
+void SendFile::handleBytestreamOpen(gloox::Bytestream *s5b) {
 	std::cout << "socks stream open\n";
 }
 
-void SendFile::handleSOCKS5Close(gloox::SOCKS5Bytestream *s5b) {
+void SendFile::handleBytestreamClose(gloox::Bytestream *s5b) {
 	std::cout << "socks stream error\n";
 }
============================================================
--- sendfile.h	6114f827483edc266e50af969d39662dd125f171
+++ sendfile.h	ec09f54d7fc7acf9b876820191a08ece12fc973d
@@ -27,38 +27,36 @@ class FileTransferManager;
 #include <fstream>
 
 #include <gloox/simanager.h>
-// #include <gloox/siprofileft.h>
-// #include <gloox/siprofilefthandler.h>
-#include <gloox/socks5bytestreammanager.h>
-#include <gloox/socks5bytestreamdatahandler.h>
+#include <gloox/bytestreamdatahandler.h>
+#include <gloox/bytestream.h>
 
 class GlooxMessageHandler;
 #include "main.h"
 
 
 
-class SendFile : public gloox::SOCKS5BytestreamDataHandler, public Thread {
+class SendFile : public gloox::BytestreamDataHandler, public Thread {
     std::string m_filename;
     int m_size;
-    gloox::SOCKS5Bytestream *m_stream;
+    gloox::Bytestream *m_stream;
 	MyMutex *m_mutex;
 	FileTransferManager *m_parent;
 
 
     std::ifstream m_file;
 public:
-    SendFile(gloox::SOCKS5Bytestream *stream, std::string filename, int size, MyMutex *mutex, FileTransferManager *manager);
+    SendFile(gloox::Bytestream *stream, std::string filename, int size, MyMutex *mutex, FileTransferManager *manager);
 
     ~SendFile();
 
     void exec();
 
-    void handleSOCKS5Data(gloox::SOCKS5Bytestream *s5b, const std::string &data);
+    void handleBytestreamData(gloox::Bytestream *s5b, const std::string &data);
 
-    void handleSOCKS5Error(gloox::SOCKS5Bytestream *s5b, gloox::Stanza *stanza);
+    void handleBytestreamError(gloox::Bytestream *s5b, const gloox::IQ &iq);
 
-    void handleSOCKS5Open(gloox::SOCKS5Bytestream *s5b);
+    void handleBytestreamOpen(gloox::Bytestream *s5b);
 
-    void handleSOCKS5Close(gloox::SOCKS5Bytestream *s5b);
+    void handleBytestreamClose(gloox::Bytestream *s5b);
 };
 #endif


More information about the Commits mailing list