soc.2009.transport: 72ae3d6a: Another milestone in Adhoc support. It c...
hanzz at soc.pidgin.im
hanzz at soc.pidgin.im
Wed May 27 09:15:49 EDT 2009
-----------------------------------------------------------------
Revision: 72ae3d6a91ce12a547122d36aa211f06182f967d
Ancestor: cc4367c49f9c7103ea481322e97bdc3f8575ceaa
Author: hanzz at soc.pidgin.im
Date: 2009-05-27T11:45:17
Branch: im.pidgin.soc.2009.transport
URL: http://d.pidgin.im/viewmtn/revision/info/72ae3d6a91ce12a547122d36aa211f06182f967d
Modified files:
adhochandler.cpp adhochandler.h adhocrepeater.cpp
adhocrepeater.h main.cpp main.h user.h
ChangeLog:
Another milestone in Adhoc support. It can currently resend actions which use request_input.
-------------- next part --------------
============================================================
--- adhochandler.cpp ad626ad80b6666a32d8e445646257ff72f90ad38
+++ adhochandler.cpp 9ccfb821ed37956b57e196e88d18b93fcb5e956e
@@ -20,6 +20,8 @@
#include "adhochandler.h"
#include "usermanager.h"
+ #include "log.h"
+ #include "adhocrepeater.h"
AdhocHandler::AdhocHandler(GlooxMessageHandler *m) {
main = m;
@@ -91,9 +93,75 @@ bool AdhocHandler::handleIq( Stanza *sta
}
bool AdhocHandler::handleIq( Stanza *stanza ) {
+ Log().Get("AdhocHandler") << "handleIq";
+ std::string to = stanza->to().bare();
+ std::string from = stanza->from().bare();
+ Tag *tag = stanza->findChild( "command" );
+ const std::string& node = tag->findAttribute( "node" );
+ if (node.empty()) return false;
+
+ if (to == main->jid()) {
+// if (tag->hasAttribute("action","cancel")){
+// Stanza *response = Stanza::createIqStanza(from, stanza()->id, StanzaIqResult, "", 0);
+// response->addAttribute("from",p->jid);
+//
+// Tag *c = new Tag("command");
+// c->addAttribute("xmlns","http://jabber.org/protocol/commands");
+// c->addAttribute("sessionid",tag->findAttribute("sessionid"));
+// c->addAttribute("node","configuration");
+// c->addAttribute("status","canceled");
+// p->j->send(response);
+//
+// return;
+// }
+
+ User *user = main->userManager()->getUserByJID(from);
+ if (user) {
+ if (user->isConnected() && purple_account_get_connection(user->account())) {
+ if (hasSession(stanza->from().full())) {
+ m_sessions[stanza->from().full()]->handleIq(stanza);
+ }
+ else {
+ PurpleConnection *gc = purple_account_get_connection(user->account());
+ PurplePlugin *plugin = gc && PURPLE_CONNECTION_IS_CONNECTED(gc) ? gc->prpl : NULL;
+ if (plugin && PURPLE_PLUGIN_HAS_ACTIONS(plugin)) {
+ PurplePluginAction *action = NULL;
+ GList *actions, *l;
+
+ actions = PURPLE_PLUGIN_ACTIONS(plugin, gc);
+
+ for (l = actions; l != NULL; l = l->next) {
+ if (l->data) {
+ action = (PurplePluginAction *) l->data;
+ if (node == (std::string) action->label) {
+ AdhocData data;
+ data.id = stanza->id();
+ data.from = stanza->from().full();
+ data.node = node;
+ user->setAdhocData(data);
+ action->plugin = plugin;
+ action->context = gc;
+ action->callback(action);
+ }
+ purple_plugin_action_free(action);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
return true;
}
+bool AdhocHandler::hasSession(const std::string &jid) {
+ std::map<std::string,AdhocRepeater *> ::iterator iter = m_sessions.begin();
+ iter = m_sessions.find(jid);
+ if(iter != m_sessions.end())
+ return true;
+ return false;
+}
+
bool AdhocHandler::handleIqID( Stanza *stanza, int context ) {
return true;
}
============================================================
--- adhochandler.h f4b96fd3044807fa1af0f44ffb1a63247340fc53
+++ adhochandler.h 8d353c41e537cd38021048c96bbef2462f80f078
@@ -27,6 +27,7 @@ class GlooxMessageHandler;
#include "glib.h"
class GlooxMessageHandler;
+class AdhocRepeater;
class AdhocHandler : public DiscoNodeHandler, public DiscoHandler, public IqHandler
{
@@ -41,10 +42,14 @@ class AdhocHandler : public DiscoNodeHan
virtual void handleDiscoInfoResult( Stanza *stanza, int context );
virtual void handleDiscoItemsResult( Stanza *stanza, int context );
virtual void handleDiscoError( Stanza *stanza, int context );
+ void registerSession(const std::string &jid, AdhocRepeater *repeater) {std::cout << jid << "\n"; m_sessions[jid] = repeater; }
+ void unregisterSession(std::string &jid) { m_sessions.erase(jid); }
+ bool hasSession(const std::string &jid);
private:
GlooxMessageHandler *main;
-
+ std::map<std::string, AdhocRepeater *> m_sessions;
+
};
#endif
============================================================
--- adhocrepeater.cpp 59b6e3e792c3fab3f7ab0e61083bf4325f02c31b
+++ adhocrepeater.cpp 85f9d1fc75268d509c331d0d186c5f9588388d9f
@@ -18,13 +18,56 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
*/
- #include "adhocrepeater.h"
+#include "adhocrepeater.h"
+#include "gloox/stanza.h"
-AdhocRepeater::AdhocRepeater(GlooxMessageHandler *m){
+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;
+ m_ok_cb = ok_cb;
+ m_cancel_cb = cancel_cb;
+ m_requestData = user_data;
+ AdhocData data = user->adhocData();
+
+ Stanza *response = Stanza::createIqStanza(data.from,data.id,StanzaIqResult,"",0);
+ response->addAttribute("from",main->jid());
+
+ Tag *c = new Tag("command");
+ c->addAttribute("xmlns","http://jabber.org/protocol/commands");
+ c->addAttribute("sessionid",main->j->getID());
+ c->addAttribute("node",data.node);
+ c->addAttribute("status","executing");
+
+ Tag *actions = new Tag("actions");
+ actions->addAttribute("execute","complete");
+ actions->addChild(new Tag("complete"));
+ c->addChild(actions);
+
+ Tag *xdata = new Tag("x");
+ xdata->addAttribute("xmlns","jabber:x:data");
+ xdata->addAttribute("type","form");
+ xdata->addChild(new Tag("title",title));
+ xdata->addChild(new Tag("instructions",primaryString));
+
+ Tag *field = new Tag("field");
+ if (multiline)
+ field->addAttribute("type","text-multi");
+ else
+ field->addAttribute("type","text-single");
+ field->addAttribute("label","Field:");
+ field->addAttribute("var","result");
+ field->addChild(new Tag("value",value));
+ xdata->addChild(field);
+
+ c->addChild(xdata);
+ response->addChild(c);
+ main->j->send(response);
+
}
-AdhocRepeater::~AdhocRepeater(){
+AdhocRepeater::~AdhocRepeater() {}
+bool AdhocRepeater::handleIq(Stanza *stanza) {
+ return true;
}
============================================================
--- adhocrepeater.h 0aefa435fa4eaaaaed0fca9aaf68f24e35f3a304
+++ adhocrepeater.h 396e5bba27fa05f80524b2e080fa672e677c4354
@@ -25,18 +25,24 @@
#include "account.h"
#include "user.h"
#include "glib.h"
+#include "request.h"
class GlooxMessageHandler;
+class User;
class AdhocRepeater
{
public:
- AdhocRepeater(GlooxMessageHandler *m);
+ 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);
private:
GlooxMessageHandler *main;
-
+ User *m_user;
+ void *m_requestData;
+ GCallback m_ok_cb;
+ GCallback m_cancel_cb;
};
#endif
============================================================
--- main.cpp 30569edd31ad6ea72359c459a7916c0d7844aff0
+++ main.cpp 68ffcfb0aacba09d1ab2a71284d2af9e14d7db34
@@ -148,16 +148,27 @@ static void * requestInput(const char *t
if (primary){
std::string primaryString(primary);
Log().Get("purple") << "primary string: " << primaryString;
- if (primaryString=="Authorization Request Message:") {
- Log().Get("purple") << "accepting this authorization request";
- ((PurpleRequestInputCb) ok_cb)(user_data,"Please authorize me.");
+ User *user = GlooxMessageHandler::instance()->userManager()->getUserByAccount(account);
+ 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);
+ AdhocData data;
+ data.id="";
+ user->setAdhocData(data);
+ return repeater;
}
- else if ( primaryString == "Set your Facebook status" ) {
- Log().Get("purple") << "set facebook status";
- User *user = GlooxMessageHandler::instance()->userManager()->getUserByAccount(account);
- if (user!=NULL){
- ((PurpleRequestInputCb) ok_cb)(user_data,user->actionData.c_str());
+ else {
+ if (primaryString=="Authorization Request Message:") {
+ Log().Get("purple") << "accepting this authorization request";
+ ((PurpleRequestInputCb) ok_cb)(user_data,"Please authorize me.");
}
+ else if ( primaryString == "Set your Facebook status" ) {
+ Log().Get("purple") << "set facebook status";
+ if (user!=NULL){
+ ((PurpleRequestInputCb) ok_cb)(user_data,user->actionData.c_str());
+ }
+ }
}
}
}
============================================================
--- main.h 745c6c9e006fe45c5c41ecac7b5cd789ee148b9b
+++ main.h ebf615bab1c9769a70100d45479c61f0ccbcc5aa
@@ -176,7 +176,7 @@ public:
SQLClass *sql() { return m_sql; }
GlooxVCardHandler *vcard() { return m_vcard; }
AbstractProtocol *protocol() { return m_protocol; }
- AdhocRepeater *adhocRepeater() { return m_adhocRepeater; }
+ AdhocHandler *adhoc() { m_adhoc; }
FileTransferManager* ftManager;
SIProfileFT* ft;
@@ -209,7 +209,6 @@ private:
GlooxStatsHandler *m_stats;
GlooxVCardHandler *m_vcard;
// std::list <GlooxAdhocHandler *> m_adhoc_handlers;
- AdhocRepeater *m_adhocRepeater;
AdhocHandler *m_adhoc;
GIOChannel *connectIO;
============================================================
--- user.h 6dfedcc9a6d51a07e10976f6a58bf4905082980c
+++ user.h 06709b8aea12ee3b8dbe6f6ed60a7f1b9eab8091
@@ -35,6 +35,12 @@ using namespace gloox;
using namespace gloox;
+struct AdhocData {
+ std::string id;
+ std::string from;
+ std::string node;
+};
+
struct authData{
PurpleAccount *account;
std::string who;
@@ -119,6 +125,8 @@ class User {
std::string username() { return m_username; }
std::string jid() { return m_jid; }
std::string resource() { return m_resource; }
+ AdhocData adhocData() { return m_adhocData; }
+ void setAdhocData(AdhocData data) { m_adhocData = data; }
std::map<std::string,RosterRow> roster() { return m_roster; }
GlooxMessageHandler *p;
@@ -132,6 +140,7 @@ class User {
bool m_rosterXCalled; // true if we are counting buddies for roster X
bool m_connected; // true if this user is connected to legacy account
bool m_reconnectCount; // number of passed reconnect tries
+ AdhocData m_adhocData; // name of node for AdhocHandler
std::string m_bindIP; // IP address to which libpurple will be binded
std::string m_password; // password used to connect to legacy network
std::string m_username; // legacy network user name
More information about the Commits
mailing list