Commit 50b84cf7 authored by Guillaume BIENKOWSKI's avatar Guillaume BIENKOWSKI

Working version of the LDAP configuration panel in GTK.

parent f8134446
......@@ -96,7 +96,7 @@ void linphone_dictionary_clear(LinphoneDictionary* obj)
belle_sip_dict_clear(obj);
}
int linphone_dictionary_haskey(LinphoneDictionary* obj, const char* key)
int linphone_dictionary_haskey(const LinphoneDictionary* obj, const char* key)
{
return belle_sip_dict_haskey(obj, key);
}
......
......@@ -53,16 +53,17 @@ struct _LinphoneLDAPContactProvider
// config
int use_tls;
LDAPAuthMethod auth_method;
char* username;
char* password;
char* server;
const char* username;
const char* password;
const char* server;
char* base_object;
char** attributes;
char* sip_attr;
char* name_attr;
const char* base_object;
const char* sip_attr;
const char* name_attr;
const char* filter;
char** attributes;
char* filter;
int timeout;
int deref_aliases;
int max_results;
......@@ -150,6 +151,7 @@ BELLE_SIP_INSTANCIATE_VPTR(LinphoneLDAPContactSearch,LinphoneContactSearch,
static inline LinphoneLDAPContactSearch* linphone_ldap_request_entry_search( LinphoneLDAPContactProvider* obj, int msgid );
static unsigned int linphone_ldap_contact_provider_cancel_search(LinphoneContactProvider* obj, LinphoneContactSearch *req);
static void linphone_ldap_contact_provider_conf_destroy(LinphoneLDAPContactProvider* obj );
static bool_t linphone_ldap_contact_provider_iterate(void *data);
/* Authentication methods */
struct AuthMethodDescription{
......@@ -182,6 +184,9 @@ static void linphone_ldap_contact_provider_destroy_request_cb(void *req)
static void linphone_ldap_contact_provider_destroy( LinphoneLDAPContactProvider* obj )
{
ms_message("linphone_ldap_contact_provider_destroy");
linphone_core_remove_iterate_hook(LINPHONE_CONTACT_PROVIDER(obj)->lc, linphone_ldap_contact_provider_iterate,obj);
// clean pending requests
ms_list_for_each(obj->requests, linphone_ldap_contact_provider_destroy_request_cb);
......@@ -399,7 +404,7 @@ static char* required_config_keys[] = {
NULL
};
static bool_t linphone_ldap_contact_provider_valid_config(LinphoneDictionary* dict)
static bool_t linphone_ldap_contact_provider_valid_config(const LinphoneDictionary* dict)
{
char** config_name = required_config_keys;
......@@ -410,6 +415,7 @@ static bool_t linphone_ldap_contact_provider_valid_config(LinphoneDictionary* di
has_key = linphone_dictionary_haskey(dict, *config_name);
if( !has_key ) ms_error("Missing LDAP config value for '%s'", *config_name);
valid &= has_key;
config_name++;
}
return valid;
}
......@@ -426,9 +432,7 @@ static void linphone_ldap_contact_provider_loadconfig(LinphoneLDAPContactProvide
if( obj->config ) linphone_dictionary_unref(obj->config);
// clone new config into the dictionary
obj->config = linphone_dictionary_clone(dict);
linphone_dictionary_ref(obj->config);
obj->config = linphone_dictionary_ref(linphone_dictionary_clone(dict));
obj->use_tls = linphone_dictionary_get_int(obj->config, "use_tls", 0);
obj->timeout = linphone_dictionary_get_int(obj->config, "timeout", 10);
......@@ -480,8 +484,7 @@ static void linphone_ldap_contact_provider_loadconfig(LinphoneLDAPContactProvide
static int linphone_ldap_contact_provider_bind( LinphoneLDAPContactProvider* obj )
{
const char* password_str = linphone_dictionary_get_string(obj, "password", "");
struct berval password = { strlen( password_str ), password_str };
struct berval password = { strlen( obj->password ), ms_strdup(obj->password) };
int ret;
int bind_msgid = 0;
......@@ -505,6 +508,8 @@ static int linphone_ldap_contact_provider_bind( LinphoneLDAPContactProvider* obj
break;
}
}
if(password.bv_val) ms_free(password.bv_val);
return 0;
}
......
......@@ -200,7 +200,7 @@ LINPHONE_PUBLIC void linphone_dictionary_set_int64(LinphoneDictionary* obj, cons
LINPHONE_PUBLIC int64_t linphone_dictionary_get_int64(LinphoneDictionary* obj, const char* key, int64_t default_value);
LINPHONE_PUBLIC int linphone_dictionary_remove(LinphoneDictionary* obj, const char* key);
LINPHONE_PUBLIC void linphone_dictionary_clear(LinphoneDictionary* obj);
LINPHONE_PUBLIC int linphone_dictionary_haskey(LinphoneDictionary* obj, const char* key);
LINPHONE_PUBLIC int linphone_dictionary_haskey(const LinphoneDictionary* obj, const char* key);
LINPHONE_PUBLIC void linphone_dictionary_foreach( const LinphoneDictionary* obj, void (*apply_func)(const char*key, void* value, void* userdata), void* userdata);
/**
* Converts a config section into a dictionary.
......
......@@ -74,6 +74,7 @@ void linphone_gtk_close_assistant(void);
LinphoneCore *linphone_gtk_get_core(void);
LinphoneLDAPContactProvider* linphone_gtk_get_ldap(void);
void linphone_gtk_set_ldap(LinphoneLDAPContactProvider* ldap);
GtkWidget *linphone_gtk_get_main_window();
void linphone_gtk_display_something(GtkMessageType type,const gchar *message);
void linphone_gtk_start_call(GtkWidget *button);
......
......@@ -232,6 +232,22 @@ static const char *linphone_gtk_get_factory_config_file(){
return _factory_config_file;
}
LinphoneLDAPContactProvider* linphone_gtk_get_ldap(void){
#ifdef BUILD_LDAP
return ldap_provider;
#else
return NULL;
#endif
}
void linphone_gtk_set_ldap(LinphoneLDAPContactProvider* ldap)
{
if( ldap_provider )
belle_sip_object_unref(ldap_provider);
ldap_provider = LINPHONE_LDAP_CONTACT_PROVIDER(belle_sip_object_ref( ldap ));
}
static void linphone_gtk_init_liblinphone(const char *config_file,
const char *factory_config_file, const char *db_file) {
LinphoneCoreVTable vtable={0};
......@@ -263,8 +279,7 @@ static void linphone_gtk_init_liblinphone(const char *config_file,
if( lp_config_has_section(linphone_core_get_config(the_core),"ldap") ){
LpConfig* cfg = linphone_core_get_config(the_core);
LinphoneDictionary* ldap_cfg = lp_config_section_to_dict(cfg, "ldap");
ldap_provider = linphone_ldap_contact_provider_create(the_core, ldap_cfg);
belle_sip_object_ref( ldap_provider );
linphone_gtk_set_ldap( linphone_ldap_contact_provider_create(the_core, ldap_cfg) );
}
#endif
......@@ -285,14 +300,6 @@ LinphoneCore *linphone_gtk_get_core(void){
return the_core;
}
LinphoneLDAPContactProvider* linphone_gtk_get_ldap(void){
#ifdef BUILD_LDAP
return ldap_provider;
#else
return NULL;
#endif
}
GtkWidget *linphone_gtk_get_main_window(){
return the_ui;
}
......
......@@ -2520,7 +2520,7 @@
</packing>
</child>
<child>
<object class="GtkCheckButton" id="use_tls">
<object class="GtkCheckButton" id="ldap_use_tls">
<property name="label" translatable="yes">Use TLS Connection</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
......@@ -2536,7 +2536,7 @@
</packing>
</child>
<child>
<object class="GtkEntry" id="ldap_address">
<object class="GtkEntry" id="ldap_server">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char"></property>
......@@ -2585,9 +2585,6 @@
<property name="bottom_attach">4</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<object class="GtkComboBox" id="ldap_auth_method">
<property name="visible">True</property>
......@@ -2851,7 +2848,7 @@
</packing>
</child>
<child>
<object class="GtkSpinButton" id="ldap_maxresult">
<object class="GtkSpinButton" id="ldap_max_results">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="max_length">3</property>
......@@ -2871,7 +2868,7 @@
</packing>
</child>
<child>
<object class="GtkCheckButton" id="ldap_followaliases">
<object class="GtkCheckButton" id="ldap_deref_aliases">
<property name="label" translatable="yes">Follow Aliases</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
......@@ -2908,6 +2905,51 @@
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="hbox20">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">2</property>
<child>
<placeholder/>
</child>
<child>
<object class="GtkButton" id="ldap_reset">
<property name="label" translatable="yes">Reset</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<signal name="clicked" handler="linphone_gtk_ldap_reset" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="ldap_save">
<property name="label" translatable="yes">Save</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<signal name="clicked" handler="linphone_gtk_ldap_save" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="position">5</property>
......
......@@ -19,6 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "linphone.h"
#include "linphone_tunnel.h"
#include "lpconfig.h"
typedef enum {
CAP_IGNORE,
......@@ -59,6 +60,131 @@ static void linphone_gtk_fill_combo_box(GtkWidget *combo, const char **devices,
gtk_combo_box_set_active(GTK_COMBO_BOX(combo),active);
}
static void linphone_gtk_ldap_load_settings(GtkWidget* param)
{
GtkWidget *mw = linphone_gtk_get_main_window();
GtkWidget *pb = (GtkWidget *) g_object_get_data(G_OBJECT(mw), "parameters");
LpConfig* config = linphone_core_get_config(linphone_gtk_get_core());
LinphoneDictionary* ldap_conf = lp_config_section_to_dict(config,"ldap");
GtkEntry* entry;
GtkToggleButton* toggle;
GtkSpinButton* spin;
toggle = GTK_TOGGLE_BUTTON(linphone_gtk_get_widget(pb,"ldap_use_tls"));
gtk_toggle_button_set_active(toggle, linphone_dictionary_get_int(ldap_conf,"use_tls", 0) );
entry = GTK_ENTRY(linphone_gtk_get_widget(pb,"ldap_server"));
gtk_entry_set_text(entry, linphone_dictionary_get_string(ldap_conf,"server", "ldap://example.com") );
entry = GTK_ENTRY(linphone_gtk_get_widget(pb,"ldap_username"));
gtk_entry_set_text(entry, linphone_dictionary_get_string(ldap_conf,"username", "") );
entry = GTK_ENTRY(linphone_gtk_get_widget(pb,"ldap_password"));
gtk_entry_set_text(entry, linphone_dictionary_get_string(ldap_conf,"password", "") );
// TODO
// GtkComboBox* cbox = GTK_COMBO_BOX(linphone_gtk_get_widget(pb,"ldap_auth_method"));
// gtk_combo_box_set_active(entry, linphone_dictionary_get_string(ldap_conf,"auth_method", "anonymous") );
entry = GTK_ENTRY(linphone_gtk_get_widget(pb,"ldap_base_object"));
gtk_entry_set_text(entry, linphone_dictionary_get_string(ldap_conf,"base_object", "dc=example,dc=com") );
entry = GTK_ENTRY(linphone_gtk_get_widget(pb,"ldap_filter"));
gtk_entry_set_text(entry, linphone_dictionary_get_string(ldap_conf,"filter", "uid=*%s*") );
entry = GTK_ENTRY(linphone_gtk_get_widget(pb,"ldap_name_attribute"));
gtk_entry_set_text(entry, linphone_dictionary_get_string(ldap_conf,"name_attribute", "cn") );
entry = GTK_ENTRY(linphone_gtk_get_widget(pb,"ldap_sip_attribute"));
gtk_entry_set_text(entry, linphone_dictionary_get_string(ldap_conf,"sip_attribute", "mobile") );
entry = GTK_ENTRY(linphone_gtk_get_widget(pb,"ldap_attributes"));
gtk_entry_set_text(entry, linphone_dictionary_get_string(ldap_conf,"attributes", "cn,givenName,sn,mobile,homePhone") );
toggle = GTK_TOGGLE_BUTTON(linphone_gtk_get_widget(pb,"ldap_deref_aliases"));
gtk_toggle_button_set_active(toggle, linphone_dictionary_get_int(ldap_conf,"deref_aliases", 0) );
spin = GTK_SPIN_BUTTON(linphone_gtk_get_widget(pb,"ldap_max_results"));
gtk_spin_button_set_value(spin, linphone_dictionary_get_int(ldap_conf,"max_results", 50) );
spin = GTK_SPIN_BUTTON(linphone_gtk_get_widget(pb,"ldap_timeout"));
gtk_spin_button_set_value(spin, linphone_dictionary_get_int(ldap_conf,"timeout", 10) );
}
void linphone_gtk_ldap_reset(GtkWidget *tabmgr)
{
GtkWidget *mw = linphone_gtk_get_main_window();
GtkWidget *pb = (GtkWidget *) g_object_get_data(G_OBJECT(mw), "parameters");
ms_message("RESET LDAP");
linphone_gtk_ldap_load_settings(pb);
}
void linphone_gtk_ldap_save(GtkWidget *tabmgr)
{
LinphoneCore *lc = linphone_gtk_get_core();
LpConfig* conf = linphone_core_get_config(lc);
LinphoneDictionary* dict = linphone_dictionary_new();
GtkWidget *mw = linphone_gtk_get_main_window();
GtkWidget *pb = (GtkWidget *) g_object_get_data(G_OBJECT(mw), "parameters");
GtkEntry* entry;
GtkToggleButton* toggle;
GtkSpinButton* spin;
ms_message("SAVE LDAP");
toggle = GTK_TOGGLE_BUTTON(linphone_gtk_get_widget(pb,"ldap_use_tls"));
linphone_dictionary_set_int(dict, "use_tls", gtk_toggle_button_get_active(toggle));
entry = GTK_ENTRY(linphone_gtk_get_widget(pb,"ldap_server"));
linphone_dictionary_set_string(dict, "server", gtk_entry_get_text(entry));
entry = GTK_ENTRY(linphone_gtk_get_widget(pb,"ldap_username"));
linphone_dictionary_set_string(dict, "username", gtk_entry_get_text(entry));
entry = GTK_ENTRY(linphone_gtk_get_widget(pb,"ldap_password"));
linphone_dictionary_set_string(dict, "password", gtk_entry_get_text(entry));
GtkComboBox* cbox = GTK_COMBO_BOX(linphone_gtk_get_widget(pb,"ldap_auth_method"));
linphone_dictionary_set_string(dict, "auth_method", gtk_combo_box_get_active_text(cbox));
entry = GTK_ENTRY(linphone_gtk_get_widget(pb,"ldap_base_object"));
linphone_dictionary_set_string(dict, "base_object", gtk_entry_get_text(entry));
entry = GTK_ENTRY(linphone_gtk_get_widget(pb,"ldap_filter"));
linphone_dictionary_set_string(dict, "filter", gtk_entry_get_text(entry));
entry = GTK_ENTRY(linphone_gtk_get_widget(pb,"ldap_name_attribute"));
linphone_dictionary_set_string(dict, "name_attribute", gtk_entry_get_text(entry));
entry = GTK_ENTRY(linphone_gtk_get_widget(pb,"ldap_sip_attribute"));
linphone_dictionary_set_string(dict, "sip_attribute", gtk_entry_get_text(entry));
entry = GTK_ENTRY(linphone_gtk_get_widget(pb,"ldap_attributes"));
linphone_dictionary_set_string(dict, "attributes", gtk_entry_get_text(entry));
toggle = GTK_TOGGLE_BUTTON(linphone_gtk_get_widget(pb,"ldap_deref_aliases"));
linphone_dictionary_set_int(dict, "deref_aliases", gtk_toggle_button_get_active(toggle));
spin = GTK_SPIN_BUTTON(linphone_gtk_get_widget(pb,"ldap_max_results"));
linphone_dictionary_set_int(dict, "max_results", gtk_spin_button_get_value(spin) );
spin = GTK_SPIN_BUTTON(linphone_gtk_get_widget(pb,"ldap_timeout"));
linphone_dictionary_set_int(dict, "timeout", gtk_spin_button_get_value(spin) );
ms_message("Create LDAP from config");
// create new LDAP according to the validated config
linphone_gtk_set_ldap( linphone_ldap_contact_provider_create(lc, dict) );
// save the config to linphonerc:
lp_config_load_dict_to_section(conf, "ldap", dict);
}
void linphone_gtk_fill_video_sizes(GtkWidget *combo){
const MSVideoSizeDef *def=linphone_core_get_supported_video_sizes(linphone_gtk_get_core());;
int i,active=0;
......@@ -1301,6 +1427,15 @@ void linphone_gtk_show_parameters(void){
gtk_widget_set_visible(GTK_WIDGET(linphone_gtk_get_widget(pb,"tunnel_label")), TRUE);
}
/* LDAP CONFIG */
#ifdef BUILD_LDAP
linphone_gtk_ldap_load_settings(pb);
#else
// hide the LDAP tab
GtkNotebook* notebook = GTK_NOTEBOOK(linphone_gtk_get_widget(pb, "notebook1"));
gtk_notebook_remove_page(notebook,5);
#endif
gtk_widget_show(pb);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment