soc.2009.transport: 582b197f: Working filetransfer from legacy network...
hanzz at soc.pidgin.im
hanzz at soc.pidgin.im
Wed Aug 5 02:51:24 EDT 2009
-----------------------------------------------------------------
Revision: 582b197f4de7264036f24907746b48d21f0b2ff2
Ancestor: b4ad8c30223af81351bf0aa387499e4f9d3fb6a7
Author: hanzz at soc.pidgin.im
Date: 2009-08-05T06:48:33
Branch: im.pidgin.soc.2009.transport
URL: http://d.pidgin.im/viewmtn/revision/info/582b197f4de7264036f24907746b48d21f0b2ff2
Modified files:
filetransfermanager.cpp filetransferrepeater.cpp main.cpp
ChangeLog:
Working filetransfer from legacy network to XMPP
-------------- next part --------------
============================================================
--- filetransfermanager.cpp 50bc4d72655a658044c8619d96b05f599d6c8d11
+++ filetransfermanager.cpp 822d9e4ca42efe26a819f9fc5307afe5fb4c4e1b
@@ -32,7 +32,8 @@ void FileTransferManager::handleFTReques
std::cout << "Received file transfer request from " << from.full() << " " << to.full() << " " << sid << ".\n";
m_info[sid].filename = name;
m_info[sid].size = size;
-
+ std::string uname = to.username();
+ std::for_each( uname.begin(), uname.end(), replaceBadJidCharacters() );
User *user = p->userManager()->getUserByJID(from.bare());
if (user) {
Log().Get(user->jid()) << "has user";
@@ -41,7 +42,7 @@ void FileTransferManager::handleFTReques
if (user->isConnected()){
Log().Get(user->jid()) << "sending file";
user->addFiletransfer(from, sid, SIProfileFT::FTTypeS5B, to, size);
- serv_send_file(purple_account_get_connection(user->account()),to.username().c_str(), name.c_str());
+ serv_send_file(purple_account_get_connection(user->account()), uname.c_str(), name.c_str());
}
}
}
@@ -75,10 +76,19 @@ void FileTransferManager::handleFTBytest
User *user = p->userManager()->getUserByJID(bs->initiator().bare());
Log().Get("a") << "wants user" << bs->initiator().bare();
- if (!user) return;
- Log().Get("a") << "wants repeater" << bs->target().username();
- FiletransferRepeater *repeater = user->removeFiletransfer(bs->target().username());
- if (!repeater) return;
+ FiletransferRepeater *repeater = NULL;
+ if (user) {
+ Log().Get("a") << "wants repeater" << bs->target().username();
+ repeater = user->removeFiletransfer(bs->target().username());
+ if (!repeater) return;
+ }
+ else {
+ User *user = p->userManager()->getUserByJID(bs->target().bare());
+ if (!user)
+ return;
+ repeater = user->removeFiletransfer(bs->initiator().username());
+ if (!repeater) return;
+ }
if (repeater->isSending())
repeater->handleFTSendBytestream(bs);
============================================================
--- filetransferrepeater.cpp 42eba03d82799e227c393159aa0338bb0fced276
+++ filetransferrepeater.cpp f66ae76f9f0726e84be2cf720d3b54c55b810b63
@@ -43,7 +43,7 @@ void SendFileStraight::exec() {
bool empty;
while (true) {
if (m_stream->isOpen()){
- std::cout << "sending...\n";
+// std::cout << "sending...\n";
std::string data;
// if (getBuffer().size() > size) {
// data = repeater->getBuffer().substr(0, size);
@@ -60,7 +60,8 @@ void SendFileStraight::exec() {
empty = true;
else {
empty = false;
- t = std::string(m_parent->getBuffer(), m_parent->getBuffer().size());
+ t = std::string(m_parent->getBuffer());
+ m_parent->getBuffer().erase();
}
getMutex()->unlock();
if (!empty) {
@@ -168,6 +169,7 @@ static size_t ui_write_fnc(const guchar
repeater->gotData(d);
if (repeater->getResender())
repeater->getResender()->getMutex()->unlock();
+ return size;
}
static size_t ui_read_fnc(guchar **buffer, size_t size, PurpleXfer *xfer) {
@@ -263,6 +265,7 @@ void FiletransferRepeater::handleFTSendB
void FiletransferRepeater::handleFTSendBytestream(Bytestream *bs) {
Log().Get("SendFileStraight") << "new!";
+ purple_xfer_request_accepted(m_xfer, NULL);
m_resender = new SendFileStraight(bs, 0, this);
}
============================================================
--- main.cpp b0de4124b2a791749ee3cd1d776e544c7450a1c9
+++ main.cpp 983acba02d1fc482ad595e62b1a4eaf2ab240659
@@ -282,15 +282,17 @@ static void * requestAction(const char *
((PurpleRequestActionCb) va_arg(actions, GCallback))(user_data,2);
}
}
- if (primary) {
- std::string primaryString(primary);
- if (primaryString.find("Accept file transfer") == 0) {
- FiletransferRepeater *repeater = user->getFiletransfer((std::string) who);
- repeater->requestFT();
-
-// std::string sid = m_sip->requestFT(jid, name, info.st_size, EmptyString, EmptyString, EmptyString, EmptyString, SIProfileFT::FTTypeAll, from);
- }
- }
+// Log().Get("purple") << "blablabla " << (std::string) who;
+// if (primary) {
+// std::string primaryString(primary);
+// Log().Get("purple") << primaryString;
+// if (primaryString.find("wants to send you") != std::string::npos) {
+// FiletransferRepeater *repeater = user->getFiletransfer((std::string) who);
+// repeater->requestFT();
+//
+// // std::string sid = m_sip->requestFT(jid, name, info.st_size, EmptyString, EmptyString, EmptyString, EmptyString, SIProfileFT::FTTypeAll, from);
+// }
+// }
return NULL;
}
@@ -406,7 +408,14 @@ static void XferCreated(PurpleXfer *xfer
repeater->registerXfer(xfer);
}
else {
- user->addFiletransfer(std::string(xfer->who) + "@" + GlooxMessageHandler::instance()->jid() + "/bot");
+ std::string name(xfer->who);
+ std::for_each( name.begin(), name.end(), replaceBadJidCharacters() );
+ size_t pos = name.find("/");
+ if (pos != std::string::npos)
+ name.erase((int) pos, name.length() - (int) pos);
+ user->addFiletransfer(name + "@" + GlooxMessageHandler::instance()->jid() + "/bot");
+ FiletransferRepeater *repeater = user->getFiletransfer(name);
+ repeater->registerXfer(xfer);
}
}
@@ -988,6 +997,8 @@ void GlooxMessageHandler::purpleFileRece
// purple_xfer_request_accepted(xfer, std::string(configuration().filetransferCache+"/"+remote_user+"-"+j->getID()+"-"+filename).c_str());
User *user = userManager()->getUserByAccount(purple_xfer_get_account(xfer));
if (user!=NULL){
+ FiletransferRepeater *repeater = (FiletransferRepeater *) xfer->ui_data;
+ repeater->requestFT();
// 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)){
@@ -1006,48 +1017,50 @@ void GlooxMessageHandler::purpleFileRece
void GlooxMessageHandler::purpleFileReceiveComplete(PurpleXfer *xfer) {
std::string filename(purple_xfer_get_filename(xfer));
std::string remote_user(purple_xfer_get_remote_user(xfer));
- std::string localname(purple_xfer_get_local_filename(xfer));
- std::string basename(g_path_get_basename(purple_xfer_get_local_filename(xfer)));
- 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");
+ if (purple_xfer_get_local_filename(xfer)) {
+ std::string localname(purple_xfer_get_local_filename(xfer));
+ std::string basename(g_path_get_basename(purple_xfer_get_local_filename(xfer)));
+ 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);
}
- else {
- sql()->addDownload(basename,"0");
+ 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);
}
- 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{
- 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);
+ Log().Get(user->jid()) << "purpleFileReceiveComplete called for unconnected user...";
}
}
- else{
- Log().Get(user->jid()) << "purpleFileReceiveComplete called for unconnected user...";
- }
+ else
+ Log().Get("purple") << "purpleFileReceiveComplete called, but user does not exist!!!";
}
- else
- Log().Get("purple") << "purpleFileReceiveComplete called, but user does not exist!!!";
}
More information about the Commits
mailing list