soc.2009.transport: 40f43daf: Added support for PURPLE_REQUEST_ACTION ...

hanzz at soc.pidgin.im hanzz at soc.pidgin.im
Mon Jun 8 04:10:37 EDT 2009


-----------------------------------------------------------------
Revision: 40f43daf53f689512cd627db26a6be31def2b41f
Ancestor: c648ca32b70c9b858f8e0b35da5d8b656f0e156e
Author: hanzz at soc.pidgin.im
Date: 2009-06-08T08:02:43
Branch: im.pidgin.soc.2009.transport
URL: http://d.pidgin.im/viewmtn/revision/info/40f43daf53f689512cd627db26a6be31def2b41f

Modified files:
        adhocrepeater.cpp adhocrepeater.h main.cpp

ChangeLog: 

Added support for PURPLE_REQUEST_ACTION actions. They are now sent to end user by AdHoc commands.

-------------- next part --------------
============================================================
--- adhocrepeater.cpp	06652f8d04ea00d73de3ca0670c15b3f92e490fb
+++ adhocrepeater.cpp	18d0caedc4d934b31225fd9e18007f3a4aa3b0e6
@@ -38,6 +38,8 @@ AdhocRepeater::AdhocRepeater(GlooxMessag
 	AdhocData data = user->adhocData();
 	m_from = data.from;
 	
+	setType(PURPLE_REQUEST_INPUT);
+	
 	IQ _response(IQ::Result, data.from, data.id);
 	Tag *response = _response.tag();
 	response->addAttribute("from",main->jid());
@@ -75,6 +77,71 @@ AdhocRepeater::AdhocRepeater(GlooxMessag
 
 }
 
+AdhocRepeater::AdhocRepeater(GlooxMessageHandler *m, User *user, const std::string &title, const std::string &primaryString, const std::string &secondaryString, int default_action, void * user_data, size_t action_count, va_list acts) {
+	setType(PURPLE_REQUEST_ACTION);
+	main = m;
+	m_user = user;
+	m_requestData = user_data;
+	AdhocData data = user->adhocData();
+	m_from = data.from;
+//       <field type='list-single'
+//              label='Maximum number of subscribers'
+//              var='maxsubs'>
+//         <value>20</value>
+//         <option label='10'><value>10</value></option>
+//         <option label='20'><value>20</value></option>
+//         <option label='30'><value>30</value></option>
+//         <option label='50'><value>50</value></option>
+//         <option label='100'><value>100</value></option>
+//         <option label='None'><value>none</value></option>
+//       </field>
+
+	IQ _response(IQ::Result, data.from, data.id);
+	Tag *response = _response.tag();
+	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");
+	field->addAttribute("type","list-single");
+	field->addAttribute("label","Actions");
+	for (unsigned int i = 0; i < action_count; i++) {
+		Tag *option;
+		std::ostringstream os;
+		os << i;
+		std::string name(va_arg(acts, char *));
+		if (i == 0)
+			field->addChild(new Tag("value",os.str()));
+		m_actions[i] = va_arg(acts, GCallback);
+		option = new Tag("option");
+		option->addAttribute("label",name);
+		option->addChild( new Tag("value",os.str()) );
+		field->addChild(option);
+	}
+	field->addAttribute("var","result");
+	xdata->addChild(field);
+
+	c->addChild(xdata);
+	response->addChild(c);
+	main->j->send(response);
+
+}
+
 AdhocRepeater::~AdhocRepeater() {}
 
 bool AdhocRepeater::handleIq(const IQ &stanza) {
@@ -106,7 +173,17 @@ bool AdhocRepeater::handleIq(const IQ &s
 			}
 		}
 
-		((PurpleRequestInputCb) m_ok_cb)(m_requestData, result.c_str());
+		if (m_type == PURPLE_REQUEST_INPUT) {
+			((PurpleRequestInputCb) m_ok_cb)(m_requestData, result.c_str());
+		}
+		else if (m_type == PURPLE_REQUEST_ACTION) {
+			std::istringstream i(result);
+			int index;
+			i >> index;
+			if (m_actions.find(index) != m_actions.end()) {
+				((PurpleRequestActionCb) m_actions[index])(m_requestData,index);
+			}
+		}
 
 		IQ _s(IQ::Result, stanza.from().full(), stanza.id());
 		_s.setFrom(main->jid());
============================================================
--- adhocrepeater.h	457931567b69af928520c11067afc19b44f71744
+++ adhocrepeater.h	75ace4d4215e0a0f5fecebfa5df8db233e0df515
@@ -34,6 +34,7 @@ class AdhocRepeater
 {
 	public:
 		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(GlooxMessageHandler *m, User *user, const std::string &title, const std::string &primaryString, const std::string &secondaryString, int default_action, void * user_data, size_t action_count, va_list actions);
 		~AdhocRepeater();
 		bool handleIq(const IQ &iq);
 		void setType(PurpleRequestType t) { m_type = t; }
@@ -48,6 +49,7 @@ class AdhocRepeater
 		GCallback m_cancel_cb;
 		PurpleRequestType m_type;
 		std::string m_from;
+		std::map<int, GCallback> m_actions;
 };
 
 #endif
============================================================
--- main.cpp	c214ccdf531210b1f87052454c90154e716153f2
+++ main.cpp	56a639c2cae637cf9ab60d395dbe516e76312131
@@ -155,7 +155,6 @@ 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);
-			repeater->setType(PURPLE_REQUEST_INPUT);
 			GlooxMessageHandler::instance()->adhoc()->registerSession(user->adhocData().from, repeater);
 			AdhocData data;
 			data.id="";
@@ -179,7 +178,16 @@ static void * requestAction(const char *
 }
 
 static void * requestAction(const char *title, const char *primary,const char *secondary, int default_action,PurpleAccount *account, const char *who,PurpleConversation *conv, void *user_data,size_t action_count, va_list actions){
-	if (title){
+	User *user = GlooxMessageHandler::instance()->userManager()->getUserByAccount(account);
+	if (user && !user->adhocData().id.empty()) {
+		AdhocRepeater *repeater = new AdhocRepeater(GlooxMessageHandler::instance(), user, title ? std::string(title):std::string(), primary ? std::string(primary):std::string(), secondary ? std::string(secondary):std::string(), default_action, user_data, action_count, actions);
+		GlooxMessageHandler::instance()->adhoc()->registerSession(user->adhocData().from, repeater);
+		AdhocData data;
+		data.id="";
+		user->setAdhocData(data);
+		return repeater;
+	}
+	else if (title){
 		std::string headerString(title);
 		Log().Get("purple") << "header string: " << headerString;
 		if (headerString=="SSL Certificate Verification"){


More information about the Commits mailing list