soc.2009.transport: bedb9555: Added template for AdhoAdmin class
hanzz at soc.pidgin.im
hanzz at soc.pidgin.im
Tue Jul 28 08:36:27 EDT 2009
-----------------------------------------------------------------
Revision: bedb95550a26b45ec07881404154ca658ecbc6ff
Ancestor: 7d8f5ee27e6dbda8d07b972da6944fa25b313db2
Author: hanzz at soc.pidgin.im
Date: 2009-07-28T12:30:48
Branch: im.pidgin.soc.2009.transport
URL: http://d.pidgin.im/viewmtn/revision/info/bedb95550a26b45ec07881404154ca658ecbc6ff
Added files:
adhocadmin.cpp adhocadmin.h
Modified files:
CMakeLists.txt adhochandler.cpp main.cpp
ChangeLog:
Added template for AdhoAdmin class
-------------- next part --------------
============================================================
--- adhocadmin.cpp 5ce5e18f35a97ba4293c1b2b847954c4dd5034c8
+++ adhocadmin.cpp 5ce5e18f35a97ba4293c1b2b847954c4dd5034c8
@@ -0,0 +1,170 @@
+/**
+ * XMPP - libpurple transport
+ *
+ * Copyright (C) 2009, Jan Kaluza <hanzz at soc.pidgin.im>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ */
+
+#include "adhocadmin.h"
+#include "gloox/stanza.h"
+#include "log.h"
+
+AdhocAdmin::AdhocAdmin(GlooxMessageHandler *m, User *user, const std::string &from, const std::string &id) {
+ main = m;
+ m_user = user;
+ PurpleValue *value;
+ Tag *field;
+ m_from = std::string(from);
+ setRequestType(CALLER_ADHOC);
+
+ IQ _response(IQ::Result, from, 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","transport_settings");
+ 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","Transport settings"));
+ xdata->addChild(new Tag("instructions","Change your transport settings here."));
+
+ field = new Tag("field");
+ field->addAttribute("type","boolean");
+ field->addAttribute("label","Enable transport");
+ field->addAttribute("var","enable_transport");
+ value = m_user->getSetting("enable_transport");
+ if (purple_value_get_boolean(value))
+ field->addChild(new Tag("value","1"));
+ else
+ field->addChild(new Tag("value","0"));
+ xdata->addChild(field);
+
+ field = new Tag("field");
+ field->addAttribute("type","boolean");
+ field->addAttribute("label","Enable network notification");
+ field->addAttribute("var","enable_notify_email");
+ value = m_user->getSetting("enable_notify_email");
+ if (purple_value_get_boolean(value))
+ field->addChild(new Tag("value","1"));
+ else
+ field->addChild(new Tag("value","0"));
+ xdata->addChild(field);
+
+ field = new Tag("field");
+ field->addAttribute("type","boolean");
+ field->addAttribute("label","Enable avatars");
+ field->addAttribute("var","enable_avatars");
+ value = m_user->getSetting("enable_avatars");
+ if (purple_value_get_boolean(value))
+ field->addChild(new Tag("value","1"));
+ else
+ field->addChild(new Tag("value","0"));
+ xdata->addChild(field);
+
+ field = new Tag("field");
+ field->addAttribute("type","boolean");
+ field->addAttribute("label","Enable chatstates");
+ field->addAttribute("var","enable_chatstate");
+ value = m_user->getSetting("enable_chatstate");
+ if (purple_value_get_boolean(value))
+ field->addChild(new Tag("value","1"));
+ else
+ field->addChild(new Tag("value","0"));
+ xdata->addChild(field);
+
+ c->addChild(xdata);
+ response->addChild(c);
+ main->j->send(response);
+
+}
+
+AdhocAdmin::~AdhocAdmin() {}
+
+bool AdhocAdmin::handleIq(const IQ &stanza) {
+ Tag *stanzaTag = stanza.tag();
+ Tag *tag = stanzaTag->findChild( "command" );
+ if (tag->hasAttribute("action","cancel")){
+ IQ _response(IQ::Result, stanza.from().full(), stanza.id());
+ _response.setFrom(main->jid());
+ Tag *response = _response.tag();
+
+ 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");
+ response->addChild(c);
+ main->j->send(response);
+
+// g_timeout_add(0,&removeHandler,this);
+ delete stanzaTag;
+ return true;
+ }
+
+ Tag *x = tag->findChildWithAttrib("xmlns","jabber:x:data");
+ if (x) {
+ std::string result("");
+ for(std::list<Tag*>::const_iterator it = x->children().begin(); it != x->children().end(); ++it) {
+ std::string key = (*it)->findAttribute("var");
+ if (key.empty()) continue;
+
+ PurpleValue * savedValue = m_user->getSetting(key.c_str());
+ if (!savedValue) continue;
+
+ Tag *v =(*it)->findChild("value");
+ if (!v) continue;
+
+ PurpleValue *value;
+ if (purple_value_get_type(savedValue) == PURPLE_TYPE_BOOLEAN) {
+ value = purple_value_new(PURPLE_TYPE_BOOLEAN);
+ purple_value_set_boolean(value, atoi(v->cdata().c_str()));
+ if (purple_value_get_boolean(savedValue) == purple_value_get_boolean(value)) {
+ purple_value_destroy(value);
+ continue;
+ }
+ m_user->updateSetting(key, value);
+ }
+ }
+
+ IQ _s(IQ::Result, stanza.from().full(), stanza.id());
+ _s.setFrom(main->jid());
+ Tag *s = _s.tag();
+
+ 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","completed");
+ s->addChild(c);
+ main->j->send(s);
+
+// g_timeout_add(0,&removeRepeater,this);
+ }
+
+ delete stanzaTag;
+ return true;
+}
+
============================================================
--- adhocadmin.h a329430bae484ba5daaf06fc0891f3cc5f35ba75
+++ adhocadmin.h a329430bae484ba5daaf06fc0891f3cc5f35ba75
@@ -0,0 +1,52 @@
+/**
+ * XMPP - libpurple transport
+ *
+ * Copyright (C) 2009, Jan Kaluza <hanzz at soc.pidgin.im>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ */
+
+#ifndef _HI_ADHOC_ADMIN_H
+#define _HI_ADHOC_ADMIN_H
+
+#include <string>
+#include "account.h"
+#include "user.h"
+#include "glib.h"
+#include "request.h"
+#include "adhoccommandhandler.h"
+
+class GlooxMessageHandler;
+class User;
+
+/*
+ * AdhocCommandHandler for Administration node
+ */
+class AdhocAdmin : public AdhocCommandHandler
+{
+ public:
+ AdhocAdmin(GlooxMessageHandler *m, User *user, const std::string &from, const std::string &id);
+ ~AdhocAdmin();
+ bool handleIq(const IQ &iq);
+ std::string & from() { return m_from; }
+
+ private:
+ GlooxMessageHandler *main; // client
+ std::string m_from; // full jid
+ User *m_user; // User class
+};
+
+#endif
+
\ No newline at end of file
============================================================
--- CMakeLists.txt f3fed7e6a97c9db7d716745411ebeecfa7da076e
+++ CMakeLists.txt 20099f27d133852b159c0c63d695e6703d304fc1
@@ -72,6 +72,7 @@
localization.cpp
muchandler.cpp
adhocsettings.cpp
+ adhocadmin.cpp
searchhandler.cpp
searchrepeater.cpp
dataforms.cpp
@@ -116,6 +117,7 @@
muchandler.h
adhoccommandhandler.h
adhocsettings.h
+ adhocadmin.h
searchhandler.h
searchrepeater.h
abstractpurplerequest.h
============================================================
--- adhochandler.cpp 66e5364e945316b7efcce4a3bb0d4f8de8c84b16
+++ adhochandler.cpp df31626cdd99518d75e7b5b891e1c9ca70d9d947
@@ -23,6 +23,7 @@
#include "log.h"
#include "adhocrepeater.h"
#include "adhocsettings.h"
+#include "adhocadmin.h"
#include "gloox/disconodehandler.h"
#include "gloox/adhoc.h"
@@ -30,6 +31,11 @@ static AdhocCommandHandler * createSetti
AdhocCommandHandler *handler = new AdhocSettings(m, user, from, id);
return handler;
}
+
+static AdhocCommandHandler * createAdminHandler(GlooxMessageHandler *m, User *user, const std::string &from, const std::string &id) {
+ AdhocCommandHandler *handler = new AdhocAdmin(m, user, from, id);
+ return handler;
+}
GlooxAdhocHandler::GlooxAdhocHandler(GlooxMessageHandler *m) {
main = m;
@@ -41,6 +47,9 @@ GlooxAdhocHandler::GlooxAdhocHandler(Glo
m_handlers["transport_settings"].name = "Transport settings";
m_handlers["transport_settings"].createHandler = createSettingsHandler;
+
+ m_handlers["transport_admin"].name = "Transport administration";
+ m_handlers["transport_admin"].createHandler = createAdminHandler;
}
GlooxAdhocHandler::~GlooxAdhocHandler() { }
============================================================
--- main.cpp 1083673419293789fa06372ea39feeffd4c5cf3f
+++ main.cpp 84f655306ca251b822c4dc375efc5387f0f78850
@@ -789,8 +789,8 @@ void * GlooxMessageHandler::purpleAuthor
if (account==NULL)
return NULL;
User *user = userManager()->getUserByAccount(account);
- if (user!=NULL){
- if (user->isConnected()){
+ if (user!=NULL) {
+ if (user->isConnected()) {
user->purpleAuthorizeReceived(account,remote_user,id,alias,message,on_list,authorize_cb,deny_cb,user_data);
authData *data = new authData;
data->account = account;
@@ -801,7 +801,7 @@ void * GlooxMessageHandler::purpleAuthor
Log().Get(user->jid()) << "purpleAuthorizeReceived called for unconnected user...";
}
}
- else{
+ else {
Log().Get("purple") << "purpleAuthorizeReceived called, but user does not exist!!!";
}
return NULL;
@@ -813,7 +813,7 @@ void * GlooxMessageHandler::purpleAuthor
/*
* Load config file and parses it and save result to m_configuration
*/
-void GlooxMessageHandler::loadConfigFile(const std::string &config){
+void GlooxMessageHandler::loadConfigFile(const std::string &config) {
GKeyFile *keyfile;
int flags;
char **bind;
@@ -848,9 +848,6 @@ void GlooxMessageHandler::loadConfigFile
m_configuration.sqlUser = (std::string)g_key_file_get_string(keyfile, "database","user", NULL);
m_configuration.sqlDb = (std::string)g_key_file_get_string(keyfile, "database","database", NULL);
m_configuration.sqlPrefix = (std::string)g_key_file_get_string(keyfile, "database","prefix", NULL);
-
-// features0 = (int)g_key_file_get_integer(keyfile, "category0","features", NULL);
-// features1 = (int)g_key_file_get_integer(keyfile, "category1","features", NULL);
m_configuration.userDir = (std::string)g_key_file_get_string(keyfile, "purple","userdir", NULL);
@@ -925,7 +922,7 @@ void GlooxMessageHandler::loadConfigFile
g_key_file_free(keyfile);
}
-void GlooxMessageHandler::purpleFileReceiveRequest(PurpleXfer *xfer){
+void GlooxMessageHandler::purpleFileReceiveRequest(PurpleXfer *xfer) {
std::string tempname(purple_xfer_get_filename(xfer));
std::string remote_user(purple_xfer_get_remote_user(xfer));
@@ -958,17 +955,17 @@ void GlooxMessageHandler::purpleFileRece
}
}
-void GlooxMessageHandler::purpleFileReceiveComplete(PurpleXfer *xfer){
+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()){
+ 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)){
+ if(user->hasFeature(GLOOX_FEATURE_FILETRANSFER)) {
+ if (user->hasTransportFeature(TRANSPORT_FEATURE_FILETRANSFER)) {
fileTransferData *data = new fileTransferData;
data->to=user->jid() + "/" + user->resource();
data->from=remote_user+"@"+jid()+"/bot";
@@ -1085,7 +1082,7 @@ void GlooxMessageHandler::purpleChatTopi
PurpleAccount *account = purple_conversation_get_account(conv);
User *user = userManager()->getUserByAccount(account);
if (user) {
- if (user->isConnected()){
+ if (user->isConnected()) {
user->purpleChatTopicChanged(conv, who, topic);
}
}
@@ -1442,7 +1439,7 @@ bool GlooxMessageHandler::initPurple(){
purple_eventloop_set_ui_ops(getEventLoopUiOps());
ret = purple_core_init(HIICQ_UI);
- if (ret){
+ if (ret) {
static int conversation_handle;
static int conn_handle;
static int xfer_handle;
More information about the Commits
mailing list