[ekiga] LDAP: Migrated to the new framework.
- From: Damien Sandras <dsandras src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ekiga] LDAP: Migrated to the new framework.
- Date: Thu, 12 Nov 2015 18:31:59 +0000 (UTC)
commit f7e483ffe70b2340c610100d21ecfbca3236d5fa
Author: Damien Sandras <dsandras seconix com>
Date: Mon May 25 17:42:41 2015 +0200
LDAP: Migrated to the new framework.
plugins/ldap/ldap-book.cpp | 46 ++++++++++++-----
plugins/ldap/ldap-book.h | 23 ++++++---
plugins/ldap/ldap-contact.cpp | 12 +++++
plugins/ldap/ldap-contact.h | 14 ++++--
plugins/ldap/ldap-main.cpp | 2 +-
plugins/ldap/ldap-source.cpp | 109 +++++++++++++++++++++++++----------------
plugins/ldap/ldap-source.h | 16 ++++--
7 files changed, 147 insertions(+), 75 deletions(-)
---
diff --git a/plugins/ldap/ldap-book.cpp b/plugins/ldap/ldap-book.cpp
index 5afe227..bffca4e 100644
--- a/plugins/ldap/ldap-book.cpp
+++ b/plugins/ldap/ldap-book.cpp
@@ -113,7 +113,7 @@ OPENLDAP::Book::parse_result (LDAPMessage* message)
if (!username.empty () && !call_addresses.empty()) {
- result = ContactPtr(new Contact (core, fix_to_utf8 (username), call_addresses));
+ result = OPENLDAP::Contact::create (core, fix_to_utf8 (username), call_addresses);
}
return result;
@@ -167,6 +167,21 @@ struct RefreshData
#endif
/* actual implementation */
+boost::shared_ptr<OPENLDAP::Book> OPENLDAP::Book::create (Ekiga::ServiceCore &_core,
+ boost::shared_ptr<xmlDoc> _doc,
+ xmlNodePtr node)
+{
+ boost::shared_ptr<OPENLDAP::Book> book = boost::shared_ptr<OPENLDAP::Book> (new OPENLDAP::Book (_core,
_doc, node));
+ return book;
+}
+
+boost::shared_ptr<OPENLDAP::Book> OPENLDAP::Book::create (Ekiga::ServiceCore &_core,
+ boost::shared_ptr<xmlDoc> _doc,
+ OPENLDAP::BookInfo _bookinfo)
+{
+ boost::shared_ptr<OPENLDAP::Book> book = boost::shared_ptr<OPENLDAP::Book> (new OPENLDAP::Book (_core,
_doc, _bookinfo));
+ return book;
+}
OPENLDAP::Book::Book (Ekiga::ServiceCore &_core,
boost::shared_ptr<xmlDoc> _doc,
@@ -387,6 +402,9 @@ OPENLDAP::Book::Book (Ekiga::ServiceCore &_core,
OPENLDAP::Book::~Book ()
{
+#if DEBUG
+ std::cout << __FUNCTION__ << " invoked in " << __FILE__ << std::endl << std::flush;
+#endif
}
bool
@@ -466,7 +484,7 @@ void
OPENLDAP::Book::refresh ()
{
/* we flush */
- remove_all_objects ();
+ contacts.remove_all_objects ();
if (ldap_context == NULL)
refresh_start ();
@@ -479,7 +497,7 @@ OPENLDAP::Book::remove ()
xmlFreeNode (node);
trigger_saving ();
- removed ();
+ removed (this->shared_from_this ());
}
xmlNodePtr
@@ -688,13 +706,13 @@ OPENLDAP::Book::refresh_start ()
int ldap_version = LDAP_VERSION3;
status = std::string (_("Refreshing"));
- updated ();
+ updated (this->shared_from_this ());
result = ldap_initialize (&ldap_context, bookinfo.uri_host.c_str());
if (result != LDAP_SUCCESS) {
status = std::string (_("Could not initialize server"));
- updated ();
+ updated (this->shared_from_this ());
return;
}
@@ -709,7 +727,7 @@ OPENLDAP::Book::refresh_start ()
if (result != LDAP_SUCCESS) {
status = std::string (_("LDAP Error: ")) +
std::string (ldap_err2string (result));
- updated ();
+ updated (this->shared_from_this ());
ldap_unbind_ext (ldap_context, NULL, NULL);
ldap_context = NULL;
return;
@@ -754,7 +772,7 @@ OPENLDAP::Book::refresh_start ()
status = std::string (_("LDAP Error: ")) +
std::string (ldap_err2string (result));
- updated ();
+ updated (this->shared_from_this ());
ldap_unbind_ext (ldap_context, NULL, NULL);
ldap_context = NULL;
@@ -762,7 +780,7 @@ OPENLDAP::Book::refresh_start ()
}
status = std::string (_("Contacted server"));
- updated ();
+ updated (this->shared_from_this ());
patience = 3;
refresh_bound ();
@@ -801,7 +819,7 @@ OPENLDAP::Book::refresh_bound ()
} else { // patience == 0
status = std::string (_("Could not connect to server"));
- updated ();
+ updated (this->shared_from_this ());
ldap_unbind_ext (ldap_context, NULL, NULL);
ldap_context = NULL;
@@ -849,7 +867,7 @@ OPENLDAP::Book::refresh_bound ()
if (msgid == -1) {
status = std::string (_("Could not search"));
- updated ();
+ updated (this->shared_from_this ());
ldap_unbind_ext (ldap_context, NULL, NULL);
ldap_context = NULL;
@@ -857,7 +875,7 @@ OPENLDAP::Book::refresh_bound ()
} else {
status = std::string (_("Waiting for search results"));
- updated ();
+ updated (this->shared_from_this ());
}
patience = 3;
@@ -898,7 +916,7 @@ OPENLDAP::Book::refresh_result ()
} else { // patience == 0
status = std::string (_("Could not search"));
- updated ();
+ updated (this->shared_from_this ());
ldap_unbind_ext (ldap_context, NULL, NULL);
ldap_context = NULL;
@@ -932,7 +950,7 @@ OPENLDAP::Book::refresh_result ()
status = c_status;
g_free (c_status);
- updated ();
+ updated (this->shared_from_this ());
(void)ldap_msgfree (msg_entry);
@@ -1164,7 +1182,7 @@ OPENLDAP::Book::on_edit_form_submitted (bool submitted,
else
I_am_an_ekiga_net_book = false;
- updated ();
+ updated (this->shared_from_this ());
trigger_saving ();
return true;
diff --git a/plugins/ldap/ldap-book.h b/plugins/ldap/ldap-book.h
index 072a4b7..5ebeea2 100644
--- a/plugins/ldap/ldap-book.h
+++ b/plugins/ldap/ldap-book.h
@@ -48,6 +48,7 @@
#include "book-impl.h"
#include "form.h"
#include "form-request-simple.h"
+#include "dynamic-object.h"
#include "ldap-contact.h"
@@ -89,17 +90,18 @@ namespace OPENLDAP
class Book:
public virtual Ekiga::Filterable,
- public Ekiga::BookImpl<Contact>
+ public Ekiga::BookImpl<Contact>,
+ public Ekiga::DynamicObject<Book>
{
public:
- Book (Ekiga::ServiceCore &_core,
- boost::shared_ptr<xmlDoc> _doc,
- xmlNodePtr node);
+ static boost::shared_ptr<Book> create (Ekiga::ServiceCore &_core,
+ boost::shared_ptr<xmlDoc> _doc,
+ xmlNodePtr node);
- Book (Ekiga::ServiceCore &_core,
- boost::shared_ptr<xmlDoc> _doc,
- OPENLDAP::BookInfo _bookinfo);
+ static boost::shared_ptr<Book> create (Ekiga::ServiceCore &_core,
+ boost::shared_ptr<xmlDoc> _doc,
+ OPENLDAP::BookInfo _bookinfo);
~Book ();
@@ -131,6 +133,13 @@ namespace OPENLDAP
Ekiga::FormBuilder *saslform;
private:
+ Book (Ekiga::ServiceCore &_core,
+ boost::shared_ptr<xmlDoc> _doc,
+ xmlNodePtr node);
+
+ Book (Ekiga::ServiceCore &_core,
+ boost::shared_ptr<xmlDoc> _doc,
+ OPENLDAP::BookInfo _bookinfo);
void refresh_start ();
void refresh_bound ();
diff --git a/plugins/ldap/ldap-contact.cpp b/plugins/ldap/ldap-contact.cpp
index b807c18..8337c1b 100644
--- a/plugins/ldap/ldap-contact.cpp
+++ b/plugins/ldap/ldap-contact.cpp
@@ -48,6 +48,15 @@ struct null_deleter
}
};
+boost::shared_ptr<OPENLDAP::Contact>
+OPENLDAP::Contact::create (Ekiga::ServiceCore &_core,
+ const std::string _name,
+ const std::map<std::string, std::string> _uris)
+{
+ boost::shared_ptr<OPENLDAP::Contact> contact = boost::shared_ptr<OPENLDAP::Contact> (new OPENLDAP::Contact
(_core, _name, _uris));
+
+ return contact;
+}
OPENLDAP::Contact::Contact (Ekiga::ServiceCore &_core,
const std::string _name,
@@ -59,6 +68,9 @@ OPENLDAP::Contact::Contact (Ekiga::ServiceCore &_core,
OPENLDAP::Contact::~Contact ()
{
+#if DEBUG
+ std::cout << __FUNCTION__ << " invoked in " << __FILE__ << std::endl << std::flush;
+#endif
}
const std::string
diff --git a/plugins/ldap/ldap-contact.h b/plugins/ldap/ldap-contact.h
index 8f78a9e..7c833bb 100644
--- a/plugins/ldap/ldap-contact.h
+++ b/plugins/ldap/ldap-contact.h
@@ -39,6 +39,7 @@
#define __LDAP_CONTACT_H__
#include "contact-core.h"
+#include "dynamic-object.h"
namespace OPENLDAP
{
@@ -49,13 +50,15 @@ namespace OPENLDAP
* @{
*/
- class Contact: public Ekiga::Contact
+ class Contact:
+ public Ekiga::Contact,
+ public Ekiga::DynamicObject<Contact>
{
public:
- Contact (Ekiga::ServiceCore &_core,
- const std::string _name,
- const std::map<std::string, std::string> _uris);
+ static boost::shared_ptr<Contact> create (Ekiga::ServiceCore &_core,
+ const std::string _name,
+ const std::map<std::string, std::string> _uris);
~Contact ();
@@ -64,6 +67,9 @@ namespace OPENLDAP
bool has_uri (const std::string uri) const;
private:
+ Contact (Ekiga::ServiceCore &_core,
+ const std::string _name,
+ const std::map<std::string, std::string> _uris);
Ekiga::ServiceCore &core;
diff --git a/plugins/ldap/ldap-main.cpp b/plugins/ldap/ldap-main.cpp
index 44921bd..100fbb3 100644
--- a/plugins/ldap/ldap-main.cpp
+++ b/plugins/ldap/ldap-main.cpp
@@ -55,7 +55,7 @@ struct LDAPSpark: public Ekiga::Spark
if (contact_core) {
- boost::shared_ptr<OPENLDAP::Source> service (new OPENLDAP::Source (core));
+ boost::shared_ptr<OPENLDAP::Source> service (OPENLDAP::Source::create (core));
core.add (service);
contact_core->add_source (service);
sasl_client_init (NULL); // FIXME: shouldn't it be done by the source!?
diff --git a/plugins/ldap/ldap-source.cpp b/plugins/ldap/ldap-source.cpp
index c5de51f..367528e 100644
--- a/plugins/ldap/ldap-source.cpp
+++ b/plugins/ldap/ldap-source.cpp
@@ -44,50 +44,18 @@
#define LDAP_KEY "ldap-servers"
-OPENLDAP::Source::Source (Ekiga::ServiceCore &_core):
- core(_core), doc(), should_add_ekiga_net_book(false)
+boost::shared_ptr<OPENLDAP::Source>
+OPENLDAP::Source::create (Ekiga::ServiceCore &_core)
{
- xmlNodePtr root;
- contacts_settings = boost::shared_ptr<Ekiga::Settings> (new Ekiga::Settings (CONTACTS_SCHEMA));
- std::string raw = contacts_settings->get_string (LDAP_KEY);
-
- if (!raw.empty ()) {
-
- doc = boost::shared_ptr<xmlDoc> (xmlRecoverMemory (raw.c_str (), raw.length ()), xmlFreeDoc);
- if ( !doc)
- doc = boost::shared_ptr<xmlDoc> (xmlNewDoc (BAD_CAST "1.0"), xmlFreeDoc);
-
- root = xmlDocGetRootElement (doc.get ());
-
- if (root == NULL) {
-
- root = xmlNewDocNode (doc.get (), NULL, BAD_CAST "list", NULL);
- xmlDocSetRootElement (doc.get (), root);
- }
-
- migrate_from_3_0_0 ();
-
- for (xmlNodePtr child = root->children ;
- child != NULL ;
- child = child->next)
- if (child->type == XML_ELEMENT_NODE
- && child->name != NULL
- && xmlStrEqual (BAD_CAST "server", child->name))
- add (child);
-
- }
- else {
-
- doc = boost::shared_ptr<xmlDoc> (xmlNewDoc (BAD_CAST "1.0"), xmlFreeDoc);
- root = xmlNewDocNode (doc.get (), NULL, BAD_CAST "list", NULL);
- xmlDocSetRootElement (doc.get (), root);
+ boost::shared_ptr<OPENLDAP::Source> source = boost::shared_ptr<OPENLDAP::Source> (new OPENLDAP::Source
(_core));
+ source->load ();
- should_add_ekiga_net_book = true;
- }
-
- if (should_add_ekiga_net_book)
- new_ekiga_net_book ();
+ return source;
+}
+OPENLDAP::Source::Source (Ekiga::ServiceCore &_core):
+ core(_core), doc(), should_add_ekiga_net_book(false)
+{
add_action (Ekiga::ActionPtr (new Ekiga::Action ("add-ldap-book", _("Add an LDAP Address Book"),
boost::bind (&OPENLDAP::Source::new_book, this))));
if (!has_ekiga_net_book ()) {
@@ -98,12 +66,15 @@ OPENLDAP::Source::Source (Ekiga::ServiceCore &_core):
OPENLDAP::Source::~Source ()
{
+#if DEBUG
+ std::cout << __FUNCTION__ << " invoked in " << __FILE__ << std::endl << std::flush;
+#endif
}
void
OPENLDAP::Source::add (xmlNodePtr node)
{
- common_add (BookPtr(new Book (core, doc, node)));
+ common_add (OPENLDAP::Book::create (core, doc, node));
}
void
@@ -112,7 +83,7 @@ OPENLDAP::Source::add (struct BookInfo bookinfo)
xmlNodePtr root;
root = xmlDocGetRootElement (doc.get ());
- BookPtr book (new Book (core, doc, bookinfo));
+ BookPtr book = OPENLDAP::Book::create (core, doc, bookinfo);
xmlAddChild (root, book->get_node ());
@@ -199,6 +170,58 @@ OPENLDAP::Source::on_new_book_form_submitted (bool submitted,
}
void
+OPENLDAP::Source::load ()
+{
+ xmlNodePtr root;
+ contacts_settings = boost::shared_ptr<Ekiga::Settings> (new Ekiga::Settings (CONTACTS_SCHEMA));
+ std::string raw = contacts_settings->get_string (LDAP_KEY);
+
+ if (!raw.empty ()) {
+
+ doc = boost::shared_ptr<xmlDoc> (xmlRecoverMemory (raw.c_str (), raw.length ()), xmlFreeDoc);
+ if ( !doc)
+ doc = boost::shared_ptr<xmlDoc> (xmlNewDoc (BAD_CAST "1.0"), xmlFreeDoc);
+
+ root = xmlDocGetRootElement (doc.get ());
+
+ if (root == NULL) {
+
+ root = xmlNewDocNode (doc.get (), NULL, BAD_CAST "list", NULL);
+ xmlDocSetRootElement (doc.get (), root);
+ }
+
+ migrate_from_3_0_0 ();
+
+ for (xmlNodePtr child = root->children ;
+ child != NULL ;
+ child = child->next)
+ if (child->type == XML_ELEMENT_NODE
+ && child->name != NULL
+ && xmlStrEqual (BAD_CAST "server", child->name))
+ add (child);
+
+ }
+ else {
+
+ doc = boost::shared_ptr<xmlDoc> (xmlNewDoc (BAD_CAST "1.0"), xmlFreeDoc);
+ root = xmlNewDocNode (doc.get (), NULL, BAD_CAST "list", NULL);
+ xmlDocSetRootElement (doc.get (), root);
+
+ should_add_ekiga_net_book = true;
+ }
+
+ if (should_add_ekiga_net_book)
+ new_ekiga_net_book ();
+
+ add_action (Ekiga::ActionPtr (new Ekiga::Action ("add-ldap-book", _("Add an LDAP Address Book"),
+ boost::bind (&OPENLDAP::Source::new_book, this))));
+ if (!has_ekiga_net_book ()) {
+ add_action (Ekiga::ActionPtr (new Ekiga::Action ("add-ekiga-book", _("Add the Ekiga.net Directory"),
+ boost::bind (&OPENLDAP::Source::new_ekiga_net_book,
this))));
+ }
+}
+
+void
OPENLDAP::Source::save ()
{
xmlChar *buffer = NULL;
diff --git a/plugins/ldap/ldap-source.h b/plugins/ldap/ldap-source.h
index 0562ddb..7ef0ab4 100644
--- a/plugins/ldap/ldap-source.h
+++ b/plugins/ldap/ldap-source.h
@@ -44,6 +44,7 @@
#include "form.h"
#include "contact-core.h"
#include "source-impl.h"
+#include "dynamic-object.h"
#include "ldap-book.h"
@@ -58,11 +59,11 @@ namespace OPENLDAP
class Source:
public Ekiga::SourceImpl<Book>,
+ public Ekiga::DynamicObject<Source>,
public Ekiga::Service
{
public:
-
- Source (Ekiga::ServiceCore &_core);
+ static boost::shared_ptr<Source> create (Ekiga::ServiceCore &_core);
~Source ();
@@ -75,9 +76,7 @@ namespace OPENLDAP
{ return "\tComponent bringing in LDAP addressbooks"; }
private:
-
- Ekiga::ServiceCore &core;
- boost::shared_ptr<xmlDoc> doc;
+ Source (Ekiga::ServiceCore &_core);
void add (xmlNodePtr node);
@@ -85,6 +84,8 @@ namespace OPENLDAP
void common_add (BookPtr book);
+ void load ();
+
void save ();
void new_book ();
@@ -97,9 +98,12 @@ namespace OPENLDAP
bool has_ekiga_net_book () const;
- gboolean should_add_ekiga_net_book;
void migrate_from_3_0_0 ();
+ Ekiga::ServiceCore &core;
+ boost::shared_ptr<xmlDoc> doc;
+ gboolean should_add_ekiga_net_book;
+
boost::shared_ptr<Ekiga::Settings> contacts_settings;
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]