fixed compilation issues, spectrum now support only backends

This commit is contained in:
HanzZ 2011-05-13 10:11:09 +02:00
parent 1105d3f1e3
commit 7ac55eba24
10 changed files with 0 additions and 752 deletions

View file

@ -1,249 +0,0 @@
/**
* XMPP - libpurple transport
*
* Copyright (C) 2009, Jan Kaluza <hanzz@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 "geventloop.h"
#ifdef _WIN32
#include "win32/win32dep.h"
#endif
#ifdef WITH_LIBEVENT
#include "event.h"
#endif
typedef struct _PurpleIOClosure {
PurpleInputFunction function;
guint result;
gpointer data;
#ifdef WITH_LIBEVENT
GSourceFunc function2;
struct timeval timeout;
struct event evfifo;
#endif
} PurpleIOClosure;
static gboolean io_invoke(GIOChannel *source,
GIOCondition condition,
gpointer data)
{
PurpleIOClosure *closure = (PurpleIOClosure* )data;
PurpleInputCondition purple_cond = (PurpleInputCondition)0;
int tmp = 0;
if (condition & READ_COND)
{
tmp |= PURPLE_INPUT_READ;
purple_cond = (PurpleInputCondition)tmp;
}
if (condition & WRITE_COND)
{
tmp |= PURPLE_INPUT_WRITE;
purple_cond = (PurpleInputCondition)tmp;
}
closure->function(closure->data, g_io_channel_unix_get_fd(source), purple_cond);
return TRUE;
}
static void io_destroy(gpointer data)
{
g_free(data);
}
static guint input_add(gint fd,
PurpleInputCondition condition,
PurpleInputFunction function,
gpointer data)
{
PurpleIOClosure *closure = g_new0(PurpleIOClosure, 1);
GIOChannel *channel;
GIOCondition cond = (GIOCondition)0;
closure->function = function;
closure->data = data;
int tmp = 0;
if (condition & PURPLE_INPUT_READ)
{
tmp |= READ_COND;
cond = (GIOCondition)tmp;
}
if (condition & PURPLE_INPUT_WRITE)
{
tmp |= WRITE_COND;
cond = (GIOCondition)tmp;
}
#ifdef WIN32
channel = wpurple_g_io_channel_win32_new_socket(fd);
#else
channel = g_io_channel_unix_new(fd);
#endif
closure->result = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, cond,
io_invoke, closure, io_destroy);
g_io_channel_unref(channel);
return closure->result;
}
static PurpleEventLoopUiOps eventLoopOps =
{
g_timeout_add,
g_source_remove,
input_add,
g_source_remove,
NULL,
#if GLIB_CHECK_VERSION(2,14,0)
g_timeout_add_seconds,
#else
NULL,
#endif
NULL,
NULL,
NULL
};
#ifdef WITH_LIBEVENT
static GHashTable *events = NULL;
static unsigned long id = 0;
static void event_io_destroy(gpointer data)
{
PurpleIOClosure *closure = (PurpleIOClosure* )data;
event_del(&closure->evfifo);
g_free(data);
}
static void event_io_invoke(int fd, short event, void *data)
{
PurpleIOClosure *closure = (PurpleIOClosure* )data;
PurpleInputCondition purple_cond = (PurpleInputCondition)0;
int tmp = 0;
if (event & EV_READ)
{
tmp |= PURPLE_INPUT_READ;
purple_cond = (PurpleInputCondition)tmp;
}
if (event & EV_WRITE)
{
tmp |= PURPLE_INPUT_WRITE;
purple_cond = (PurpleInputCondition)tmp;
}
if (event & EV_TIMEOUT)
{
// tmp |= PURPLE_INPUT_WRITE;
// purple_cond = (PurpleInputCondition)tmp;
if (closure->function2(closure->data))
evtimer_add(&closure->evfifo, &closure->timeout);
// else
// event_io_destroy(data);
return;
}
closure->function(closure->data, fd, purple_cond);
}
static gboolean event_input_remove(guint handle)
{
PurpleIOClosure *closure = (PurpleIOClosure *) g_hash_table_lookup(events, &handle);
if (closure)
event_io_destroy(closure);
return TRUE;
}
static guint event_input_add(gint fd,
PurpleInputCondition condition,
PurpleInputFunction function,
gpointer data)
{
PurpleIOClosure *closure = g_new0(PurpleIOClosure, 1);
GIOChannel *channel;
GIOCondition cond = (GIOCondition)0;
closure->function = function;
closure->data = data;
int tmp = EV_PERSIST;
if (condition & PURPLE_INPUT_READ)
{
tmp |= EV_READ;
}
if (condition & PURPLE_INPUT_WRITE)
{
tmp |= EV_WRITE;
}
event_set(&closure->evfifo, fd, tmp, event_io_invoke, closure);
event_add(&closure->evfifo, NULL);
int *f = (int *) g_malloc(sizeof(int));
*f = id;
id++;
g_hash_table_replace(events, f, closure);
return *f;
}
static guint event_timeout_add (guint interval, GSourceFunc function, gpointer data) {
struct timeval timeout;
PurpleIOClosure *closure = g_new0(PurpleIOClosure, 1);
closure->function2 = function;
closure->data = data;
timeout.tv_sec = interval/1000;
timeout.tv_usec = (interval%1000)*1000;
evtimer_set(&closure->evfifo, event_io_invoke, closure);
evtimer_add(&closure->evfifo, &timeout);
closure->timeout = timeout;
guint *f = (guint *) g_malloc(sizeof(guint));
*f = id;
id++;
g_hash_table_replace(events, f, closure);
return *f;
}
static PurpleEventLoopUiOps libEventLoopOps =
{
event_timeout_add,
event_input_remove,
event_input_add,
event_input_remove,
NULL,
// #if GLIB_CHECK_VERSION(2,14,0)
// g_timeout_add_seconds,
// #else
NULL,
// #endif
NULL,
NULL,
NULL
};
#endif /* WITH_LIBEVENT*/
PurpleEventLoopUiOps * getEventLoopUiOps(void){
return &eventLoopOps;
#ifdef WITH_LIBEVENT
std::cout << "EPOLL\n";
events = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, NULL);
return &libEventLoopOps;
#endif
}

View file

@ -1,33 +0,0 @@
/**
* XMPP - libpurple transport
*
* Copyright (C) 2009, Jan Kaluza <hanzz@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_EVENTLOOP_H
#define _HI_EVENTLOOP_H
#include <glib.h>
#include "purple.h"
#include "eventloop.h"
#define READ_COND (G_IO_IN | G_IO_HUP | G_IO_ERR)
#define WRITE_COND (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL)
PurpleEventLoopUiOps * getEventLoopUiOps(void);
#endif

View file

@ -1,15 +0,0 @@
#include "spectrum.h"
#include "transport/config.h"
#include "transport/transport.h"
#include "transport/usermanager.h"
#include "transport/logger.h"
#include "transport/sqlite3backend.h"
#include "transport/userregistration.h"
Spectrum::Spectrum(const std::string &config) {
}
Spectrum::~Spectrum() {
}

View file

@ -1,33 +0,0 @@
/**
* XMPP - libpurple transport
*
* Copyright (C) 2011, Jan Kaluza <hanzz@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
*/
#pragma once
#include "transport/transport.h"
using namespace Transport;
class Spectrum {
public:
Spectrum(const std::string &config);
~Spectrum();
private:
Component *m_component;
};

View file

@ -1,138 +0,0 @@
/**
* XMPP - libpurple transport
*
* Copyright (C) 2009, Jan Kaluza <hanzz@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 "spectrumbuddy.h"
#include "transport/user.h"
#define Log(X, STRING) std::cout << "[SPECTRUM] " << X << " " << STRING << "\n";
SpectrumBuddy::SpectrumBuddy(RosterManager *rosterManager, long id, PurpleBuddy *buddy) : Buddy(rosterManager, id), m_buddy(buddy) {
}
SpectrumBuddy::~SpectrumBuddy() {
}
std::string SpectrumBuddy::getAlias() {
std::string alias;
if (purple_buddy_get_server_alias(m_buddy))
alias = (std::string) purple_buddy_get_server_alias(m_buddy);
else
alias = (std::string) purple_buddy_get_alias(m_buddy);
return alias;
}
std::string SpectrumBuddy::getName() {
std::string name(purple_buddy_get_name(m_buddy));
if (name.empty()) {
Log("SpectrumBuddy::getName", "Name is EMPTY!");
}
return name;
}
bool SpectrumBuddy::getStatus(Swift::StatusShow &status, std::string &statusMessage) {
PurplePresence *pres = purple_buddy_get_presence(m_buddy);
if (pres == NULL)
return false;
PurpleStatus *stat = purple_presence_get_active_status(pres);
if (stat == NULL)
return false;
int st = purple_status_type_get_primitive(purple_status_get_type(stat));
switch(st) {
case PURPLE_STATUS_AVAILABLE: {
break;
}
case PURPLE_STATUS_AWAY: {
status = Swift::StatusShow::Away;
break;
}
case PURPLE_STATUS_UNAVAILABLE: {
status = Swift::StatusShow::DND;
break;
}
case PURPLE_STATUS_EXTENDED_AWAY: {
status = Swift::StatusShow::XA;
break;
}
case PURPLE_STATUS_OFFLINE: {
status = Swift::StatusShow::None;
break;
}
default:
break;
}
const char *message = purple_status_get_attr_string(stat, "message");
if (message != NULL) {
char *stripped = purple_markup_strip_html(message);
statusMessage = std::string(stripped);
g_free(stripped);
}
else
statusMessage = "";
return true;
}
std::string SpectrumBuddy::getIconHash() {
char *avatarHash = NULL;
PurpleBuddyIcon *icon = purple_buddy_icons_find(purple_buddy_get_account(m_buddy), purple_buddy_get_name(m_buddy));
if (icon) {
avatarHash = purple_buddy_icon_get_full_path(icon);
Log(getName(), "avatarHash");
}
if (avatarHash) {
Log(getName(), "Got avatar hash");
// Check if it's patched libpurple which saves icons to directories
char *hash = strrchr(avatarHash,'/');
std::string h;
if (hash) {
char *dot;
hash++;
dot = strchr(hash, '.');
if (dot)
*dot = '\0';
std::string ret(hash);
g_free(avatarHash);
return ret;
}
else {
std::string ret(avatarHash);
g_free(avatarHash);
return ret;
}
}
return "";
}
std::vector<std::string> SpectrumBuddy::getGroups() {
std::vector<std::string> groups;
groups.push_back(purple_group_get_name(purple_buddy_get_group(m_buddy)) ? std::string(purple_group_get_name(purple_buddy_get_group(m_buddy))) : std::string("Buddies"));
return groups;
}
void SpectrumBuddy::getVCard(const std::string &id, const Swift::JID &to) {
}

View file

@ -1,58 +0,0 @@
/**
* XMPP - libpurple transport
*
* Copyright (C) 2009, Jan Kaluza <hanzz@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 SPECTRUM_BUDDY_H
#define SPECTRUM_BUDDY_H
#include <string>
#include "purple.h"
#include "account.h"
#include "glib.h"
#include <algorithm>
#include "transport/buddy.h"
#include "transport/rostermanager.h"
using namespace Transport;
// Wrapper for PurpleBuddy
class SpectrumBuddy : public Buddy {
public:
SpectrumBuddy(RosterManager *rosterManager, long id, PurpleBuddy *buddy);
virtual ~SpectrumBuddy();
std::string getAlias();
std::string getName();
bool getStatus(Swift::StatusShow &status, std::string &statusMessage);
std::string getIconHash();
std::vector<std::string> getGroups();
void addBuddy(PurpleBuddy *buddy) { m_buddies.push_back(buddy); }
void removeBuddy(PurpleBuddy *buddy) { m_buddies.remove(buddy); }
int getBuddiesCount() { return m_buddies.size(); }
void getVCard(const std::string &id, const Swift::JID &to);
PurpleBuddy *getBuddy() { return m_buddy; }
private:
PurpleBuddy *m_buddy;
std::list<PurpleBuddy *> m_buddies;
};
#endif

View file

@ -1,41 +0,0 @@
/**
* XMPP - libpurple transport
*
* Copyright (C) 2009, Jan Kaluza <hanzz@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 "spectrumconversation.h"
#include "transport/user.h"
#define Log(X, STRING) std::cout << "[SPECTRUM] " << X << " " << STRING << "\n";
SpectrumConversation::SpectrumConversation(ConversationManager *conversationManager, const std::string &legacyName, PurpleConversation *conv) : Conversation(conversationManager, legacyName), m_conv(conv) {
}
SpectrumConversation::~SpectrumConversation() {
}
void SpectrumConversation::sendMessage(boost::shared_ptr<Swift::Message> &message) {
// escape and send
gchar *_markup = purple_markup_escape_text(message->getBody().c_str(), -1);
if (purple_conversation_get_type(m_conv) == PURPLE_CONV_TYPE_IM) {
purple_conv_im_send(PURPLE_CONV_IM(m_conv), _markup);
}
g_free(_markup);
}

View file

@ -1,47 +0,0 @@
/**
* XMPP - libpurple transport
*
* Copyright (C) 2009, Jan Kaluza <hanzz@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
*/
#pragma once
#include <string>
#include "purple.h"
#include "account.h"
#include "glib.h"
#include <algorithm>
#include "transport/conversation.h"
#include "transport/conversationmanager.h"
#include "transport/user.h"
using namespace Transport;
// Wrapper for PurpleBuddy
class SpectrumConversation : public Conversation {
public:
SpectrumConversation(ConversationManager *conversationManager, const std::string &legacyName, PurpleConversation *conv);
virtual ~SpectrumConversation();
PurpleConversation *getConversation() { return m_conv; }
void sendMessage(boost::shared_ptr<Swift::Message> &message);
private:
PurpleConversation *m_conv;
};

View file

@ -1,89 +0,0 @@
/**
* XMPP - libpurple transport
*
* Copyright (C) 2009, Jan Kaluza <hanzz@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 "spectrumeventloop.h"
#include "purple.h"
#include <iostream>
#ifdef WITH_LIBEVENT
#include <event.h>
#endif
using namespace Swift;
// Fires the event's callback and frees the event
static gboolean processEvent(void *data) {
Event *ev = (Event *) data;
ev->callback();
delete ev;
return FALSE;
}
SpectrumEventLoop::SpectrumEventLoop() : m_isRunning(false) {
m_loop = NULL;
if (true) {
m_loop = g_main_loop_new(NULL, FALSE);
}
#ifdef WITH_LIBEVENT
else {
/*struct event_base *base = (struct event_base *)*/
event_init();
}
#endif
}
SpectrumEventLoop::~SpectrumEventLoop() {
stop();
}
void SpectrumEventLoop::run() {
m_isRunning = true;
if (m_loop) {
g_main_loop_run(m_loop);
}
#ifdef WITH_LIBEVENT
else {
event_loop(0);
}
#endif
}
void SpectrumEventLoop::stop() {
if (!m_isRunning)
return;
if (m_loop) {
g_main_loop_quit(m_loop);
g_main_loop_unref(m_loop);
m_loop = NULL;
}
#ifdef WITH_LIBEVENT
else {
event_loopexit(NULL);
}
#endif
}
void SpectrumEventLoop::post(const Event& event) {
// pass copy of event to main thread
Event *ev = new Event(event.owner, event.callback);
purple_timeout_add(0, processEvent, ev);
}

View file

@ -1,49 +0,0 @@
/**
* XMPP - libpurple transport
*
* Copyright (C) 2009, Jan Kaluza <hanzz@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 SPECTRUM_EVENT_LOOP_H
#define SPECTRUM_EVENT_LOOP_H
#include <vector>
#include "Swiften/EventLoop/EventLoop.h"
#include "glib.h"
// Event loop implementation for Spectrum
class SpectrumEventLoop : public Swift::EventLoop {
public:
// Creates event loop according to CONFIG().eventloop settings.
SpectrumEventLoop();
~SpectrumEventLoop();
// Executes the eventloop.
void run();
// Stops tht eventloop.
void stop();
// Posts new Swift::Event to main thread.
virtual void post(const Swift::Event& event);
private:
bool m_isRunning;
GMainLoop *m_loop;
};
#endif