[ekiga] Get the roster and basic updates : looks neat :-)
- From: Julien Puydt <jpuydt src gnome org>
- To: svn-commits-list gnome org
- Subject: [ekiga] Get the roster and basic updates : looks neat :-)
- Date: Thu, 11 Jun 2009 11:41:49 -0400 (EDT)
commit 41a384de9a8f2fbed2e9d443f57a32927a086f20
Author: Julien Puydt <jpuydt noether localdomain>
Date: Sat Nov 29 22:48:43 2008 +0100
Get the roster and basic updates : looks neat :-)
lib/engine/components/loudmouth/Makefile.am | 4 +-
.../components/loudmouth/loudmouth-account.cpp | 2 -
lib/engine/components/loudmouth/loudmouth-heap.cpp | 80 ++++++++++++-
lib/engine/components/loudmouth/loudmouth-heap.h | 13 ++-
.../components/loudmouth/loudmouth-presentity.cpp | 129 ++++++++++++++++++++
.../components/loudmouth/loudmouth-presentity.h | 76 ++++++++++++
6 files changed, 297 insertions(+), 7 deletions(-)
---
diff --git a/lib/engine/components/loudmouth/Makefile.am b/lib/engine/components/loudmouth/Makefile.am
index cc55ca6..235967d 100644
--- a/lib/engine/components/loudmouth/Makefile.am
+++ b/lib/engine/components/loudmouth/Makefile.am
@@ -19,6 +19,8 @@ libgmloudmouth_la_SOURCES = \
$(loudmouth_dir)/loudmouth-cluster.h \
$(loudmouth_dir)/loudmouth-cluster.cpp \
$(loudmouth_dir)/loudmouth-heap.h \
- $(loudmouth_dir)/loudmouth-heap.cpp
+ $(loudmouth_dir)/loudmouth-heap.cpp \
+ $(loudmouth_dir)/loudmouth-presentity.h \
+ $(loudmouth_dir)/loudmouth-presentity.cpp
libgmloudmouth_la_LDFLAGS = -export-dynamic -no-undefined $(SIGC_LIBS) $(LOUDMOUTH_LIBS)
\ No newline at end of file
diff --git a/lib/engine/components/loudmouth/loudmouth-account.cpp b/lib/engine/components/loudmouth/loudmouth-account.cpp
index 3e85b9d..24f8cb5 100644
--- a/lib/engine/components/loudmouth/loudmouth-account.cpp
+++ b/lib/engine/components/loudmouth/loudmouth-account.cpp
@@ -122,7 +122,6 @@ LM::Account::on_connection_opened (bool result)
{
if (result) {
- std::cout << "Opened loudmouth connection" << std::endl;
lm_connection_authenticate (connection, user.c_str (), password.c_str (), resource.c_str (),
(LmResultFunction)on_authenticate_c, this, NULL, NULL);
} else {
@@ -148,7 +147,6 @@ LM::Account::on_authenticate (bool result)
heap = gmref_ptr<Heap> (new Heap (connection));
cluster->add_heap (heap);
- std::cout << "Loudmouth authentication succeeded" << std::endl;
} else {
lm_connection_close (connection, NULL);
diff --git a/lib/engine/components/loudmouth/loudmouth-heap.cpp b/lib/engine/components/loudmouth/loudmouth-heap.cpp
index b399e14..96b99bb 100644
--- a/lib/engine/components/loudmouth/loudmouth-heap.cpp
+++ b/lib/engine/components/loudmouth/loudmouth-heap.cpp
@@ -34,15 +34,45 @@
*/
#include <iostream>
+#include <string.h>
#include "loudmouth-heap.h"
+LmHandlerResult
+iq_handler_c (LmMessageHandler* /*handler*/,
+ LmConnection* /*connection*/,
+ LmMessage* message,
+ LM::Heap* heap)
+{
+ return heap->iq_handler (message);
+}
+
LM::Heap::Heap (LmConnection* connection_): connection(connection_)
{
+ lm_connection_ref (connection);
+
+ iq_lm_handler = lm_message_handler_new ((LmHandleMessageFunction)iq_handler_c, this, NULL);
+ lm_connection_register_message_handler (connection, iq_lm_handler, LM_MESSAGE_TYPE_IQ, LM_HANDLER_PRIORITY_NORMAL);
+
+ { // populate the roster
+ LmMessage* roster_request = lm_message_new_with_sub_type (NULL, LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_GET);
+ LmMessageNode* node = lm_message_node_add_child (lm_message_get_node (roster_request), "query", NULL);
+ lm_message_node_set_attributes (node, "xmlns", "jabber:iq:roster", NULL);
+ lm_connection_send (connection, roster_request, NULL);
+ lm_message_unref (roster_request);
+ }
}
LM::Heap::~Heap ()
{
+ lm_connection_unregister_message_handler (connection, iq_lm_handler, LM_MESSAGE_TYPE_IQ);
+
+ lm_message_handler_unref (iq_lm_handler);
+ iq_lm_handler = 0;
+
+ lm_connection_unref (connection);
+ connection = 0;
+
std::cout << __PRETTY_FUNCTION__ << std::endl;
}
@@ -69,5 +99,53 @@ LM::Heap::populate_menu_for_group (const std::string /*group*/,
void
LM::Heap::disconnected ()
{
- // FIXME: do something
+ removed.emit ();
+}
+
+LmHandlerResult
+LM::Heap::iq_handler (LmMessage* message)
+{
+ if (lm_message_get_sub_type (message) == LM_MESSAGE_SUB_TYPE_SET
+ || lm_message_get_sub_type (message) == LM_MESSAGE_SUB_TYPE_RESULT) {
+
+ LmMessageNode* node = lm_message_node_get_child (lm_message_get_node (message), "query");
+ if (node != NULL) {
+
+ const gchar* xmlns = lm_message_node_get_attribute (node, "xmlns");
+ if (xmlns != NULL && strcmp (xmlns, "jabber:iq:roster") == 0) {
+
+ parse_roster (node);
+ }
+ }
+ }
+
+ return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
+}
+
+void
+LM::Heap::parse_roster (LmMessageNode* query)
+{
+ for (LmMessageNode* node = query->children; node != NULL; node = node->next) {
+
+ if (strcmp (node->name, "item") != 0) {
+
+ continue;
+ }
+
+ const gchar* jid = lm_message_node_get_attribute (node, "jid");
+ bool found = false;
+ for (iterator iter = begin (); !found && iter != end (); ++iter) {
+
+ if ((*iter)->get_jid () == jid) {
+
+ (*iter)->update (node);
+ found = true;
+ }
+ }
+ if ( !found) {
+
+ gmref_ptr<Presentity> presentity(new Presentity (connection, node));
+ add_presentity (presentity);
+ }
+ }
}
diff --git a/lib/engine/components/loudmouth/loudmouth-heap.h b/lib/engine/components/loudmouth/loudmouth-heap.h
index d524747..35b08ee 100644
--- a/lib/engine/components/loudmouth/loudmouth-heap.h
+++ b/lib/engine/components/loudmouth/loudmouth-heap.h
@@ -36,14 +36,13 @@
#ifndef __LOUDMOUTH_HEAP_H__
#define __LOUDMOUTH_HEAP_H__
-#include <loudmouth/loudmouth.h>
-
#include "heap-impl.h"
+#include "loudmouth-presentity.h"
namespace LM
{
class Heap:
- public Ekiga::HeapImpl<Ekiga::Presentity>
+ public Ekiga::HeapImpl<Presentity>
{
public:
@@ -60,9 +59,17 @@ namespace LM
void disconnected ();
+ /* public to be accessed by C callbacks */
+
+ LmHandlerResult iq_handler (LmMessage* message);
+
private:
LmConnection* connection;
+
+ LmMessageHandler* iq_lm_handler;
+
+ void parse_roster (LmMessageNode* query);
};
};
diff --git a/lib/engine/components/loudmouth/loudmouth-presentity.cpp b/lib/engine/components/loudmouth/loudmouth-presentity.cpp
new file mode 100644
index 0000000..709f47d
--- /dev/null
+++ b/lib/engine/components/loudmouth/loudmouth-presentity.cpp
@@ -0,0 +1,129 @@
+
+/*
+ * Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2008 Damien Sandras
+
+ * 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 St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Ekiga is licensed under the GPL license and as a special exception, you
+ * have permission to link or otherwise combine this program with the
+ * programs OPAL, OpenH323 and PWLIB, and distribute the combination, without
+ * applying the requirements of the GNU GPL to the OPAL, OpenH323 and PWLIB
+ * programs, as long as you do follow the requirements of the GNU GPL for all
+ * the rest of the software thus combined.
+ */
+
+
+/*
+ * loudmouth-presentity.cpp - description
+ * ------------------------------------------
+ * begin : written in 2008 by Julien Puydt
+ * copyright : (c) 2008 by Julien Puydt
+ * description : implementation of a loudmouth presentity
+ *
+ */
+
+#include <iostream>
+#include <string.h>
+
+#include "loudmouth-presentity.h"
+
+LM::Presentity::Presentity (LmConnection* connection_,
+ LmMessageNode* item_):
+ connection(connection_), item(item_)
+{
+ lm_connection_ref (connection);
+ lm_message_node_ref (item);
+}
+
+LM::Presentity::~Presentity ()
+{
+ std::cout << __PRETTY_FUNCTION__ << std::endl;
+
+ lm_message_node_unref (item);
+ item = 0;
+
+ lm_connection_unref (connection);
+ connection = 0;
+}
+
+void
+LM::Presentity::update (LmMessageNode* item_)
+{
+ lm_message_node_unref (item);
+ item = item_;
+ lm_message_node_ref (item);
+ updated.emit ();
+}
+
+const std::string
+LM::Presentity::get_jid () const
+{
+ return lm_message_node_get_attribute (item, "jid");
+}
+
+const std::string
+LM::Presentity::get_name () const
+{
+ const gchar* result = lm_message_node_get_attribute (item, "name");
+
+ if (result == NULL) {
+
+ result = lm_message_node_get_attribute (item, "jid");
+ }
+
+ return result;
+}
+
+const std::string
+LM::Presentity::get_presence () const
+{
+ return "FIXME";
+}
+
+const std::string
+LM::Presentity::get_status () const
+{
+ return "FIXME";
+}
+
+const std::string
+LM::Presentity::get_avatar () const
+{
+ return "FIXME";
+}
+
+const std::set<std::string>
+LM::Presentity::get_groups () const
+{
+ std::set<std::string> result;
+
+ for (LmMessageNode* node = item->children; node != NULL; node = node->next) {
+
+ if (strcmp (node->name, "group") == 0) {
+
+ if (node->value) {
+
+ result.insert (node->value);
+ }
+ }
+ }
+
+ return result;
+}
+
+bool
+LM::Presentity::populate_menu (Ekiga::MenuBuilder& /*builder*/)
+{
+ return false; // FIXME
+}
diff --git a/lib/engine/components/loudmouth/loudmouth-presentity.h b/lib/engine/components/loudmouth/loudmouth-presentity.h
new file mode 100644
index 0000000..7e9e46b
--- /dev/null
+++ b/lib/engine/components/loudmouth/loudmouth-presentity.h
@@ -0,0 +1,76 @@
+
+/*
+ * Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2008 Damien Sandras
+
+ * 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 St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Ekiga is licensed under the GPL license and as a special exception, you
+ * have permission to link or otherwise combine this program with the
+ * programs OPAL, OpenH323 and PWLIB, and distribute the combination, without
+ * applying the requirements of the GNU GPL to the OPAL, OpenH323 and PWLIB
+ * programs, as long as you do follow the requirements of the GNU GPL for all
+ * the rest of the software thus combined.
+ */
+
+
+/*
+ * loudmouth-presentity.h - description
+ * ------------------------------------------
+ * begin : written in 2008 by Julien Puydt
+ * copyright : (c) 2008 by Julien Puydt
+ * description : declaration of a loudmouth presentity
+ *
+ */
+
+#ifndef __LOUDMOUTH_PRESENTITY_H__
+#define __LOUDMOUTH_PRESENTITY_H__
+
+#include <loudmouth/loudmouth.h>
+
+#include "presentity.h"
+
+namespace LM
+{
+ class Presentity:
+ public Ekiga::Presentity
+ {
+ public:
+ Presentity (LmConnection* connection_,
+ LmMessageNode* item_);
+
+ ~Presentity ();
+
+ void update (LmMessageNode* item_);
+
+ const std::string get_jid () const;
+
+ const std::string get_name () const;
+
+ const std::string get_presence () const;
+
+ const std::string get_status () const;
+
+ const std::string get_avatar () const;
+
+ const std::set<std::string> get_groups () const;
+
+ bool populate_menu (Ekiga::MenuBuilder& builder);
+
+ private:
+ LmConnection* connection;
+ LmMessageNode* item;
+ };
+};
+
+#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]