soc.2009.transport: 2c0a738d: Free AdhocRepeater when request is close...
hanzz at soc.pidgin.im
hanzz at soc.pidgin.im
Thu May 28 03:46:18 EDT 2009
-----------------------------------------------------------------
Revision: 2c0a738d59985f221f43a6f4144e7d4105d24521
Ancestor: 8e0db63608a31bdff3b1973f384246d6220d10d1
Author: hanzz at soc.pidgin.im
Date: 2009-05-28T07:32:43
Branch: im.pidgin.soc.2009.transport
URL: http://d.pidgin.im/viewmtn/revision/info/2c0a738d59985f221f43a6f4144e7d4105d24521
Modified files:
adhocrepeater.cpp adhocrepeater.h main.cpp
ChangeLog:
Free AdhocRepeater when request is closed or when user cancels adhoc command.
-------------- next part --------------
============================================================
--- adhocrepeater.cpp 890b825143a38de9d5bd2151dbf7018ecad45bd3
+++ adhocrepeater.cpp b366b997ee2248994b746574c04afc3143e690b5
@@ -20,7 +20,15 @@
#include "adhocrepeater.h"
#include "gloox/stanza.h"
+#include "log.h"
+static gboolean removeRepeater(gpointer data){
+ AdhocRepeater *repeater = (AdhocRepeater*) data;
+ purple_request_close(repeater->type(),repeater);
+ Log().Get("AdhocRepeater") << "repeater closed";
+ return FALSE;
+}
+
AdhocRepeater::AdhocRepeater(GlooxMessageHandler *m, User *user, const std::string &title, const std::string &primaryString, const std::string &secondaryString, const std::string &value, gboolean multiline, gboolean masked, GCallback ok_cb, GCallback cancel_cb, void * user_data) {
main = m;
m_user = user;
@@ -28,6 +36,7 @@ AdhocRepeater::AdhocRepeater(GlooxMessag
m_cancel_cb = cancel_cb;
m_requestData = user_data;
AdhocData data = user->adhocData();
+ m_from = data.from;
Stanza *response = Stanza::createIqStanza(data.from,data.id,StanzaIqResult,"",0);
response->addAttribute("from",main->jid());
@@ -80,6 +89,8 @@ bool AdhocRepeater::handleIq(Stanza *sta
c->addAttribute("status","canceled");
main->j->send(response);
+ g_timeout_add(0,&removeRepeater,this);
+
return true;
}
============================================================
--- adhocrepeater.h 396e5bba27fa05f80524b2e080fa672e677c4354
+++ adhocrepeater.h c0809861364980a88ea37abfba4e35af5b4e3f09
@@ -36,6 +36,9 @@ class AdhocRepeater
AdhocRepeater(GlooxMessageHandler *m, User *user, const std::string &title, const std::string &primaryString, const std::string &secondaryString, const std::string &value, gboolean multiline, gboolean masked, GCallback ok_cb, GCallback cancel_cb, void * user_data);
~AdhocRepeater();
bool handleIq(Stanza *stanza);
+ void setType(PurpleRequestType t) { m_type = t; }
+ PurpleRequestType type() { return m_type; }
+ std::string from() { return m_from; }
private:
GlooxMessageHandler *main;
@@ -43,6 +46,8 @@ class AdhocRepeater
void *m_requestData;
GCallback m_ok_cb;
GCallback m_cancel_cb;
+ PurpleRequestType m_type;
+ std::string m_from;
};
#endif
============================================================
--- main.cpp 68ffcfb0aacba09d1ab2a71284d2af9e14d7db34
+++ main.cpp b5410dac1aba1aa1d40b24110c05eaaf5c04339f
@@ -152,7 +152,8 @@ static void * requestInput(const char *t
if (!user) return NULL;
if (!user->adhocData().id.empty()) {
AdhocRepeater *repeater = new AdhocRepeater(GlooxMessageHandler::instance(), user, title ? std::string(title):std::string(), primaryString, secondary ? std::string(secondary):std::string(), default_value ? std::string(default_value):std::string(), multiline, masked, ok_cb, cancel_cb, user_data);
- GlooxMessageHandler::instance()->adhoc()->registerSession("test at localhost/hanzz-laptop", repeater);
+ repeater->setType(PURPLE_REQUEST_INPUT);
+ GlooxMessageHandler::instance()->adhoc()->registerSession(user->adhocData().from, repeater);
AdhocData data;
data.id="";
user->setAdhocData(data);
@@ -184,6 +185,14 @@ static void * requestAction(const char *
}
}
+static void requestClose(PurpleRequestType type, void *ui_handle) {
+ if (type == PURPLE_REQUEST_INPUT) {
+ AdhocRepeater *repeater = (AdhocRepeater *) ui_handle;
+ std::string from = repeater->from();
+ GlooxMessageHandler::instance()->adhoc()->unregisterSession(from);
+ delete repeater;
+ }
+}
/*
* Called when somebody from legacy network wants to send file to us.
@@ -228,7 +237,7 @@ static void buddyListUpdate(PurpleBuddyL
* Called when somebody from legacy network wants to authorize some jabber user.
* We can return some object which will be connected with this request all the time...
*/
-static void * requestAuth(PurpleAccount *account,const char *remote_user,const char *id,const char *alias,const char *message,gboolean on_list,PurpleAccountRequestAuthorizationCb authorize_cb,PurpleAccountRequestAuthorizationCb deny_cb,void *user_data){
+static void * accountRequestAuth(PurpleAccount *account,const char *remote_user,const char *id,const char *alias,const char *message,gboolean on_list,PurpleAccountRequestAuthorizationCb authorize_cb,PurpleAccountRequestAuthorizationCb deny_cb,void *user_data){
Log().Get("purple") << "new AUTHORIZE REQUEST";
return GlooxMessageHandler::instance()->purpleAuthorizeReceived(account,remote_user,id,alias,message,on_list,authorize_cb,deny_cb,user_data);
}
@@ -236,7 +245,7 @@ static void * requestAuth(PurpleAccount
/*
* Called when account is disconnecting and all requests will be closed and unreachable.
*/
-static void requestClose(void *data){
+static void accountRequestClose(void *data){
Log().Get("purple") << "AUTHORIZE REQUEST CLOSE";
GlooxMessageHandler::instance()->purpleAuthorizeClose(data);
}
@@ -279,8 +288,8 @@ static PurpleAccountUiOps accountUiOps =
NULL,
NULL,
NULL,
- requestAuth,
- requestClose,
+ accountRequestAuth,
+ accountRequestClose,
NULL,
NULL,
NULL,
@@ -312,11 +321,11 @@ static PurpleRequestUiOps requestUiOps =
requestAction,
NULL,
NULL,
+ requestClose,
NULL,
NULL,
NULL,
NULL,
- NULL,
NULL
};
@@ -1032,6 +1041,7 @@ void GlooxMessageHandler::handleMessage(
void GlooxMessageHandler::handleMessage( Stanza* stanza, MessageSession* session = 0 ){
User *user = userManager()->getUserByJID(stanza->from().bare());
+ Log().Get("purple") << stanza->xml();
if (user!=NULL){
if (user->isConnected()){
Tag *chatstates = stanza->findChildWithAttrib("xmlns","http://jabber.org/protocol/chatstates");
More information about the Commits
mailing list