From 3dc63b115dbc87d9cda697a791e9b1272aa6116a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C3=ABl=20Carr=C3=A9?= <rafael.carre@savoirfairelinux.com> Date: Wed, 28 Sep 2011 16:03:44 -0400 Subject: [PATCH] Cleanup Fix memory leaks in client Change a bit dbus protocol: int -> int instead of int -> string -> string -> int Remove unused and empty yamlengine --- daemon/src/config/Makefile.am | 3 - daemon/src/config/engine.h | 52 ------- daemon/src/config/serializable.h | 3 - daemon/src/config/yamlengine.cpp | 82 ----------- daemon/src/config/yamlengine.h | 72 ---------- .../dbus/configurationmanager-introspec.xml | 2 +- daemon/src/dbus/configurationmanager.cpp | 21 +-- daemon/src/dbus/configurationmanager.h | 2 +- gnome/src/accountlist.c | 14 +- gnome/src/accountlist.h | 4 +- gnome/src/actions.c | 82 +++++------ gnome/src/callable_obj.c | 22 ++- gnome/src/callable_obj.h | 2 - gnome/src/codeclist.c | 134 +++++------------- gnome/src/codeclist.h | 38 +---- gnome/src/conference_obj.c | 30 +--- gnome/src/config/addressbook-config.c | 46 +++--- gnome/src/config/audioconf.c | 11 +- gnome/src/contacts/addrbookfactory.c | 2 +- gnome/src/contacts/calltree.c | 53 +++---- gnome/src/contacts/calltree.h | 3 - gnome/src/contacts/history.c | 19 +-- gnome/src/contacts/searchbar.c | 9 +- .../dbus/configurationmanager-introspec.xml | 2 +- gnome/src/dbus/dbus.c | 4 +- gnome/src/dbus/dbus.h | 4 +- gnome/src/statusicon.c | 30 ++-- gnome/src/uimanager.c | 16 +-- .../dbus/configurationmanager-introspec.xml | 2 +- 29 files changed, 203 insertions(+), 561 deletions(-) delete mode 100644 daemon/src/config/engine.h delete mode 100644 daemon/src/config/yamlengine.cpp delete mode 100644 daemon/src/config/yamlengine.h diff --git a/daemon/src/config/Makefile.am b/daemon/src/config/Makefile.am index ba68009603..f64c876291 100755 --- a/daemon/src/config/Makefile.am +++ b/daemon/src/config/Makefile.am @@ -2,16 +2,13 @@ noinst_LTLIBRARIES = libconfig.la libconfig_la_SOURCES = \ config.cpp \ - yamlengine.cpp \ yamlemitter.cpp \ yamlparser.cpp \ yamlnode.cpp noinst_HEADERS = \ config.h \ - engine.h \ serializable.h \ - yamlengine.h \ yamlemitter.h \ yamlparser.h \ yamlnode.h diff --git a/daemon/src/config/engine.h b/daemon/src/config/engine.h deleted file mode 100644 index b53ea47d47..0000000000 --- a/daemon/src/config/engine.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010, 2011 Savoir-Faire Linux Inc. - * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com> - * - * 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 3 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., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * Additional permission under GNU GPL version 3 section 7: - * - * If you modify this program, or any covered work, by linking or - * combining it with the OpenSSL project's OpenSSL library (or a - * modified version of that library), containing parts covered by the - * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. - * grants you additional permission to convey the resulting work. - * Corresponding Source for a non-source form of such a combination - * shall include the source code for the parts of OpenSSL used as well - * as that of the covered work. - */ - -#ifndef __ENGINE_H__ -#define __ENGINE_H__ - -#include <yaml.h> - -class Engine -{ - - public: - - virtual void open() = 0; - - virtual void close() = 0; - - virtual void write() = 0; - - virtual void read() = 0; - virtual ~Engine(); - -}; - -#endif diff --git a/daemon/src/config/serializable.h b/daemon/src/config/serializable.h index 695ca5ffac..4b87b052ea 100644 --- a/daemon/src/config/serializable.h +++ b/daemon/src/config/serializable.h @@ -36,9 +36,6 @@ #include "yamlemitter.h" #include "yamlnode.h" -class Engine; -// class MappingNode; - class Serializable { diff --git a/daemon/src/config/yamlengine.cpp b/daemon/src/config/yamlengine.cpp deleted file mode 100644 index 968f9ca937..0000000000 --- a/daemon/src/config/yamlengine.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010, 2011 Savoir-Faire Linux Inc. - * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com> - * - * 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 3 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., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * Additional permission under GNU GPL version 3 section 7: - * - * If you modify this program, or any covered work, by linking or - * combining it with the OpenSSL project's OpenSSL library (or a - * modified version of that library), containing parts covered by the - * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. - * grants you additional permission to convey the resulting work. - * Corresponding Source for a non-source form of such a combination - * shall include the source code for the parts of OpenSSL used as well - * as that of the covered work. - */ - -#include "yamlengine.h" -#include "../global.h" - - -namespace Conf -{ - -YamlEngine::YamlEngine() {} - -YamlEngine::~YamlEngine() {} - -void YamlEngine::openConfigFile() -{ - - Conf::YamlParser *parser = NULL; - - try { - parser = new Conf::YamlParser ("sequence.yml"); - } catch (Conf::YamlParserException &e) { - _error ("ConfigTree: %s", e.what()); - } - - try { - parser->serializeEvents(); - } catch (Conf::YamlParserException &e) { - _error ("ConfigTree: %s", e.what()); - } - - try { - document = parser->composeEvents(); - } catch (Conf::YamlParserException &e) { - _error ("ConfigTree: %s", e.what()); - } - - try { - delete parser; - parser = NULL; - } catch (Conf::YamlParserException &e) { - _error ("ConfigTree: %s", e.what()); - } -} - -void YamlEngine::closeConfigFile() -{ - -} - -void YamlEngine::read() {} - -void YamlEngine::write() {} - -} diff --git a/daemon/src/config/yamlengine.h b/daemon/src/config/yamlengine.h deleted file mode 100644 index 9512a8f154..0000000000 --- a/daemon/src/config/yamlengine.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010, 2011 Savoir-Faire Linux Inc. - * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com> - * - * 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 3 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., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * Additional permission under GNU GPL version 3 section 7: - * - * If you modify this program, or any covered work, by linking or - * combining it with the OpenSSL project's OpenSSL library (or a - * modified version of that library), containing parts covered by the - * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. - * grants you additional permission to convey the resulting work. - * Corresponding Source for a non-source form of such a combination - * shall include the source code for the parts of OpenSSL used as well - * as that of the covered work. - */ - -#ifndef __YAMLENGINE_H__ -#define __YAMLENGINE_H__ - -#include "engine.h" -#include "yamlnode.h" -#include "yamlparser.h" -#include "yamlemitter.h" -#include <exception> - -namespace Conf -{ - -class YamlEngine : public Engine -{ - - public: - - YamlEngine(); - - ~YamlEngine(); - - virtual void openConfigFile(); - - virtual void closeConfigFile(); - - virtual void write(); - - virtual void read(); - - private: - - YamlParser *parser; - - YamlEmitter *emitter; - - YamlDocument *document; - -}; - -} - -#endif diff --git a/daemon/src/dbus/configurationmanager-introspec.xml b/daemon/src/dbus/configurationmanager-introspec.xml index b5a31feb55..21493d0a00 100755 --- a/daemon/src/dbus/configurationmanager-introspec.xml +++ b/daemon/src/dbus/configurationmanager-introspec.xml @@ -313,7 +313,7 @@ <tp:docstring> </tp:docstring> </arg> - <arg type="as" name="list" direction="out"> + <arg type="ai" name="list" direction="out"> <tp:docstring> </tp:docstring> </arg> diff --git a/daemon/src/dbus/configurationmanager.cpp b/daemon/src/dbus/configurationmanager.cpp index 0d926bf9ec..73b3880ec6 100644 --- a/daemon/src/dbus/configurationmanager.cpp +++ b/daemon/src/dbus/configurationmanager.cpp @@ -64,8 +64,7 @@ std::map<std::string, std::string> ConfigurationManager::getIp2IpDetails (void) else return sipaccount->getIp2IpDetails(); - std::map<std::string, std::string> tlsSettings; - tlsSettings = getTlsSettings(); + std::map<std::string, std::string> tlsSettings = getTlsSettings(); std::copy (tlsSettings.begin(), tlsSettings.end(), std::inserter ( ip2ipAccountDetails, ip2ipAccountDetails.end())); @@ -188,20 +187,13 @@ std::vector<std::string> ConfigurationManager::getAudioCodecDetails (const int32 return result; } -std::vector<std::string> ConfigurationManager::getActiveAudioCodecList (const std::string& accountID) +std::vector<int32_t> ConfigurationManager::getActiveAudioCodecList (const std::string& accountID) { - std::vector<std::string> v; + std::vector<int32_t> v; Account *acc = Manager::instance().getAccount (accountID); - if (acc) { - CodecOrder active(acc->getActiveCodecs()); - - for (CodecOrder::const_iterator iter = active.begin(); iter != active.end(); ++iter) { - std::stringstream ss; - ss << *iter; - v.push_back(ss.str()); - } - } + if (acc) + return acc->getActiveCodecs(); return v; } @@ -229,8 +221,6 @@ std::vector<std::string> ConfigurationManager::getAudioPluginList() void ConfigurationManager::setAudioPlugin (const std::string& audioPlugin) { - _debug ("ConfigurationManager: Set audio plugin %s", audioPlugin.c_str()); - return Manager::instance().setAudioPlugin (audioPlugin); } @@ -467,4 +457,3 @@ void ConfigurationManager::setCredentials (const std::string& accountID, sipaccount->setCredentials(details); } } - diff --git a/daemon/src/dbus/configurationmanager.h b/daemon/src/dbus/configurationmanager.h index 0bb9536fe2..85556a3af3 100644 --- a/daemon/src/dbus/configurationmanager.h +++ b/daemon/src/dbus/configurationmanager.h @@ -76,7 +76,7 @@ class ConfigurationManager std::vector< int32_t > getAudioCodecList (void); std::vector< std::string > getSupportedTlsMethod (void); std::vector< std::string > getAudioCodecDetails (const int32_t& payload); - std::vector< std::string > getActiveAudioCodecList (const std::string& accountID); + std::vector< int32_t > getActiveAudioCodecList (const std::string& accountID); void setActiveAudioCodecList (const std::vector< std::string >& list, const std::string& accountID); std::vector< std::string > getAudioPluginList(); diff --git a/gnome/src/accountlist.c b/gnome/src/accountlist.c index 23e73098f3..b92c312351 100644 --- a/gnome/src/accountlist.c +++ b/gnome/src/accountlist.c @@ -184,11 +184,17 @@ const gchar * account_state_name (account_state_t s) return state; } -void -account_list_clear () +void account_list_free_elm(gpointer elm, gpointer data UNUSED) { - g_queue_free (accountQueue); - accountQueue = g_queue_new (); + account_t *a = elm; + g_free(a->accountID); + g_free(a); +} + +void account_list_free () +{ + g_queue_foreach(accountQueue, account_list_free_elm, NULL); + g_queue_free(accountQueue); } void diff --git a/gnome/src/accountlist.h b/gnome/src/accountlist.h index f5c85673ca..fefcab66b1 100644 --- a/gnome/src/accountlist.h +++ b/gnome/src/accountlist.h @@ -144,9 +144,9 @@ void account_list_set_current (account_t *current); const gchar * account_state_name (account_state_t s); /** - * This function clear the list + * This function frees the list */ -void account_list_clear (); +void account_list_free (); /** * Return the account associated with an ID diff --git a/gnome/src/actions.c b/gnome/src/actions.c index 84e3bb0a36..9a746782e5 100644 --- a/gnome/src/actions.c +++ b/gnome/src/actions.c @@ -186,9 +186,13 @@ sflphone_quit () dbus_unregister (getpid()); dbus_clean (); + account_list_free(); calllist_clean (current_calls); calllist_clean (contacts); calllist_clean (history); + gtk_tree_store_clear(history->store); + gtk_tree_store_clear(current_calls->store); + gtk_tree_store_clear(contacts->store); gtk_main_quit (); } } @@ -241,7 +245,8 @@ void sflphone_fill_account_list (void) { int count = current_account_get_message_number (); - account_list_clear (); + account_list_free(); + account_list_init(); gchar **array = dbus_account_list(); if (array) { @@ -1026,30 +1031,27 @@ void sflphone_fill_codec_list () void sflphone_fill_codec_list_per_account (account_t *account) { - gchar **order = dbus_get_active_audio_codec_list(account->accountID); + GArray *order = dbus_get_active_audio_codec_list(account->accountID); GQueue *codeclist = account->codecs; // First clean the list codec_list_clear(&codeclist); - if (!(*order)) - ERROR ("SFLphone: No codec list provided"); - else { - for (gchar **pl = order; *pl; pl++) { - codec_t * cpy = NULL; + for (guint i = 0; i < order->len; i++) { + gint payload = g_array_index(order, gint, i); - // Each account will have a copy of the system-wide capabilities - codec_create_new_from_caps (codec_list_get_by_payload ( (gconstpointer) (size_t) atoi (*pl), NULL), &cpy); + // Each account will have a copy of the system-wide capabilities + codec_t *cpy = codec_create_new_from_caps (codec_list_get_by_payload ( (gconstpointer) (uintptr_t) payload, NULL)); - if (cpy) { - cpy->is_active = TRUE; - codec_list_add (cpy, &codeclist); - } else - ERROR ("SFLphone: Couldn't find codec"); - } + if (cpy) { + codec_list_add (cpy, &codeclist); + } else + ERROR ("SFLphone: Couldn't find codec"); } + g_array_unref(order); + guint caps_size = codec_list_get_size (); for (guint i = 0; i < caps_size; i++) { @@ -1066,27 +1068,18 @@ void sflphone_fill_codec_list_per_account (account_t *account) void sflphone_fill_call_list (void) { - gchar** calls = (gchar**) dbus_get_call_list(); - GHashTable *call_details; + gchar **list = dbus_get_call_list(); - DEBUG ("sflphone_fill_call_list"); - - if (!calls) - return; - - for (; *calls; calls++) { - callable_obj_t *c = g_new0 (callable_obj_t, 1); - gchar *callID = (gchar*) (*calls); - call_details = dbus_get_call_details (callID); - c = create_new_call_from_details (callID, call_details); + for (gchar **calls = list; calls && *calls; calls++) { + gchar *callID = *calls; + callable_obj_t *c = create_new_call_from_details (*calls, dbus_get_call_details (*calls)); g_free(callID); c->_zrtp_confirmed = FALSE; - // Add it to the list - DEBUG ("Add call retrieved from server side: %s\n", c->_callID); calllist_add_call (current_calls, c); - // Update the GUI calltree_add_call (current_calls, c, NULL); } + + g_free(list); } @@ -1094,28 +1087,18 @@ void sflphone_fill_conference_list (void) { // TODO Fetch the active conferences at client startup - gchar** conferences; - GHashTable *conference_details; - - DEBUG ("SFLphone: Fill conference list"); + gchar **conferences = dbus_get_conference_list(); + for (gchar **list = conferences; list && *list; list++) { + const gchar * const conf_id = *list; - conferences = dbus_get_conference_list(); + GHashTable *conference_details = dbus_get_conference_details (conf_id); + conference_obj_t *conf = create_new_conference_from_details (conf_id, conference_details); - if (conferences) { - for (; *conferences; conferences++) { - conference_obj_t *conf = g_new0 (conference_obj_t, 1); - const gchar * const conf_id = (gchar*) (*conferences); - - conference_details = (GHashTable*) dbus_get_conference_details (conf_id); - - conf = create_new_conference_from_details (conf_id, conference_details); - - conf->_confID = g_strdup (conf_id); - - conferencelist_add (current_calls, conf); - calltree_add_conference (current_calls, conf); - } + conferencelist_add (current_calls, conf); + calltree_add_conference (current_calls, conf); } + + g_strfreev(conferences); } void sflphone_fill_history (void) @@ -1328,6 +1311,7 @@ sflphone_call_state_changed (callable_obj_t * c, const gchar * description, cons return; } + g_free(c->_state_code_description); c->_state_code_description = g_strdup (description); c->_state_code = code; diff --git a/gnome/src/callable_obj.c b/gnome/src/callable_obj.c index ab6921e2f1..d30c962d3a 100644 --- a/gnome/src/callable_obj.c +++ b/gnome/src/callable_obj.c @@ -157,6 +157,15 @@ callable_obj_t *create_new_call_from_details (const gchar *call_id, GHashTable * return c; } +static history_state_t get_history_state_from_id (gchar *indice) +{ + history_state_t state = atoi(indice); + if (state > LAST) + state = MISSED; + + return state; +} + callable_obj_t *create_history_entry_from_serialized_form (const gchar *entry) { const gchar *peer_name = ""; @@ -227,16 +236,6 @@ gchar* get_peer_info (const gchar* const number, const gchar* const name) return g_strconcat ("\"", name, "\" <", number, ">", NULL); } -history_state_t get_history_state_from_id (gchar *indice) -{ - history_state_t state = atoi(indice); - - if (state > LAST) - state = MISSED; - - return state; -} - gchar* get_call_duration (callable_obj_t *obj) { long duration = difftime (obj->_time_stop, obj->_time_start); @@ -247,10 +246,9 @@ gchar* get_call_duration (callable_obj_t *obj) static const gchar* get_history_id_from_state (history_state_t state) { - static const gchar *tab[LAST] = { "0", "1", "2" }; if (state >= LAST) return ""; - return tab[state]; + return state + "0"; } gchar* serialize_history_call_entry (callable_obj_t *entry) diff --git a/gnome/src/callable_obj.h b/gnome/src/callable_obj.h index 3c83e6cd53..97c1d75d77 100644 --- a/gnome/src/callable_obj.h +++ b/gnome/src/callable_obj.h @@ -205,8 +205,6 @@ free_callable_obj_t (callable_obj_t *c); gchar* get_peer_info (const gchar* const, const gchar* const); -history_state_t get_history_state_from_id (gchar *indice); - gchar* get_call_duration (callable_obj_t *obj); gchar* serialize_history_call_entry(callable_obj_t *entry); diff --git a/gnome/src/codeclist.c b/gnome/src/codeclist.c index d1cea947aa..e5570c8ae2 100644 --- a/gnome/src/codeclist.c +++ b/gnome/src/codeclist.c @@ -41,25 +41,34 @@ static GQueue * codecsCapabilities = NULL; gint is_name_codecstruct (gconstpointer a, gconstpointer b) { - codec_t * c = (codec_t *) a; - - if (g_strcmp0 (c->name, (const gchar *) b) == 0) - return 0; - else - return 1; + const codec_t *c = a; + return !!g_strcmp0(c->name, (const gchar *) b); } -gint +static gint is_payload_codecstruct (gconstpointer a, gconstpointer b) { - codec_t * c = (codec_t *) a; + const codec_t *c = a; + return (c->_payload == GPOINTER_TO_INT(b)) ? 0 : 1; +} + +static codec_t *codec_create_new(gint payload) +{ + gchar **specs = dbus_audio_codec_details (payload); + + codec_t *codec = g_new0 (codec_t, 1); + codec->_payload = payload; + codec->name = strdup(specs[0]); + codec->sample_rate = atoi (specs[1]); + codec->_bitrate = atoi (specs[2]); + codec->is_active = TRUE; + + g_strfreev(specs); - if (c->_payload == GPOINTER_TO_INT (b)) - return 0; - else - return 1; + return codec; } + void codec_capabilities_load (void) { // Create the queue object that will contain the global list of audio codecs @@ -73,11 +82,8 @@ void codec_capabilities_load (void) // Add the codecs in the list for (guint i = 0; i < codecs->len; i++) { - codec_t *c; gint payload = g_array_index(codecs, gint, i); - gchar **specs = dbus_audio_codec_details (payload); - codec_create_new_with_specs (payload, specs, TRUE, &c); - g_strfreev(specs); + codec_t *c = codec_create_new(payload); g_queue_push_tail (codecsCapabilities, (gpointer) c); } @@ -88,67 +94,20 @@ void codec_capabilities_load (void) ERROR ("No audio codecs found"); } -void account_create_codec_list (account_t **acc) +codec_t *codec_create_new_from_caps (codec_t *original) { - GQueue *_codecs; - - _codecs = (*acc)->codecs; - - if (_codecs != NULL) - g_queue_free (_codecs); - - _codecs = g_queue_new (); - - (*acc)->codecs = _codecs; -} - -void codec_create_new (gint payload, gboolean active, codec_t **c) -{ - codec_t *codec; - gchar **specs; - - codec = g_new0 (codec_t, 1); - codec->_payload = payload; - specs = (gchar **) dbus_audio_codec_details (payload); - codec->name = specs[0]; - codec->sample_rate = atoi (specs[1]); - codec->_bitrate = atoi (specs[2]); - codec->is_active = active; - - *c = codec; -} - -void codec_create_new_with_specs (gint payload, gchar **specs, gboolean active, codec_t **c) -{ - codec_t *codec; - - codec = g_new0 (codec_t, 1); - codec->_payload = payload; - codec->name = strdup(specs[0]); - codec->sample_rate = atoi (specs[1]); - codec->_bitrate = atoi (specs[2]); - codec->is_active = active; - - *c = codec; -} - -void codec_create_new_from_caps (codec_t *original, codec_t **copy) -{ - codec_t *codec; - - if (!original) { - *copy = NULL; - return; + codec_t *codec = NULL; + + if (original) { + codec = g_new0 (codec_t, 1); + codec->_payload = original->_payload; + codec->name = original->name; + codec->sample_rate = original->sample_rate; + codec->_bitrate = original->_bitrate; + codec->is_active = TRUE; } - codec = g_new0 (codec_t, 1); - codec->_payload = original->_payload; - codec->name = original->name; - codec->sample_rate = original->sample_rate; - codec->_bitrate = original->_bitrate; - codec->is_active = original->is_active; - - *copy = codec; + return codec; } @@ -165,20 +124,9 @@ void codec_list_add (codec_t * c, GQueue **queue) g_queue_push_tail (*queue, (gpointer) c); } -void codec_set_active (codec_t **c) +void codec_set_active (codec_t *c, gboolean active) { - if (c) { - DEBUG ("%s set active", (*c)->name); - (*c)->is_active = TRUE; - } -} - -void codec_set_inactive (codec_t **c) -{ - if (c) { - DEBUG ("%s set inactive", (*c)->name); - (*c)->is_active = FALSE; - } + c->is_active = active; } guint codec_list_get_size () @@ -195,11 +143,7 @@ codec_t* codec_list_get_by_name (gconstpointer name, GQueue *q) q = codecsCapabilities; GList * c = g_queue_find_custom (q, name, is_name_codecstruct); - - if (c) - return (codec_t *) c->data; - else - return NULL; + return c ? c->data : NULL; } codec_t* codec_list_get_by_payload (gconstpointer payload, GQueue *q) @@ -209,11 +153,7 @@ codec_t* codec_list_get_by_payload (gconstpointer payload, GQueue *q) q = codecsCapabilities; GList * c = g_queue_find_custom (q, payload, is_payload_codecstruct); - - if (c) - return (codec_t *) c->data; - else - return NULL; + return c ? c->data : NULL; } codec_t* codec_list_get_nth (guint index, GQueue *q) diff --git a/gnome/src/codeclist.h b/gnome/src/codeclist.h index 51824f1987..efb3a77415 100644 --- a/gnome/src/codeclist.h +++ b/gnome/src/codeclist.h @@ -81,14 +81,9 @@ void codec_list_add (codec_t * c, GQueue **q); /** * Set a codec active. An active codec will be used for codec negociation * @param name The string description of the codec + * @param active If it is used or not */ -void codec_set_active (codec_t **c); - -/** - * Set a codec inactive. An active codec won't be used for codec negociation - * @param name The string description of the codec - */ -void codec_set_inactive (codec_t **c); +void codec_set_active (codec_t *c, gboolean active); /** * Return the number of codecs in the list @@ -138,35 +133,8 @@ codec_t* codec_list_get_by_payload (gconstpointer payload, GQueue *q); GQueue* get_system_codec_list (void); -/** - * Instanciate a new codecs with the given payload. - * Fetches codec specification through D-Bus - * - * @param payload The unique RTP payload - * @param active Whether or not this codec should active (checked) - * @param c A pointer to receive the new codec instance - */ -void codec_create_new (gint payload, gboolean active, codec_t **c); - -/* - * Instanciate a new codec with the given specification - * - * @param payload The unique RTP payload - * @param specs A list of codec specifications. Ordered: name, sample rate, bit rate - * @param active Whether or not this codec should active (checked) - * @param c A pointer to receive the new codec instance - */ -void codec_create_new_with_specs (gint payload, gchar **specs, gboolean active, codec_t **c); - - -void codec_create_new_from_caps (codec_t *original, codec_t **copy); -/* - * Attach a codec list to a specific account - * - * @param acc A pointer on the account to modify - */ -void account_create_codec_list (account_t **acc); +codec_t *codec_create_new_from_caps (codec_t *original); #endif diff --git a/gnome/src/conference_obj.c b/gnome/src/conference_obj.c index 40d5f7f908..044491a562 100644 --- a/gnome/src/conference_obj.c +++ b/gnome/src/conference_obj.c @@ -74,19 +74,7 @@ conference_obj_t *create_new_conference (conference_state_t state, const gchar* conference_obj_t *create_new_conference_from_details (const gchar *conf_id, GHashTable *details) { - conference_obj_t *new_conf; - gchar** participants; - gchar* state_str; - - DEBUG ("Conference: Create new conference from details"); - - // Allocate memory - new_conf = g_new0 (conference_obj_t, 1); - if (!new_conf) { - ERROR("Conference: Error: Could not allocate data "); - return NULL; - } - + conference_obj_t *new_conf = g_new0 (conference_obj_t, 1); new_conf->_confID = g_strdup (conf_id); new_conf->_conference_secured = FALSE; @@ -94,17 +82,13 @@ conference_obj_t *create_new_conference_from_details (const gchar *conf_id, GHas new_conf->participant_list = NULL; - // get participant list - participants = dbus_get_participant_list (conf_id); - if (participants == NULL) - ERROR("Conference: Error: Could not get participant list"); - - // generate conference participant list - conference_participant_list_update (participants, new_conf); - - g_strfreev(participants); + gchar **participants = dbus_get_participant_list (conf_id); + if (participants) { + conference_participant_list_update (participants, new_conf); + g_strfreev(participants); + } - state_str = g_hash_table_lookup (details, "CONF_STATE"); + gchar *state_str = g_hash_table_lookup (details, "CONF_STATE"); if (g_strcasecmp (state_str, "ACTIVE_ATACHED") == 0) new_conf->_state = CONFERENCE_STATE_ACTIVE_ATACHED; diff --git a/gnome/src/config/addressbook-config.c b/gnome/src/config/addressbook-config.c index fb7b01b0f9..0f3f912529 100644 --- a/gnome/src/config/addressbook-config.c +++ b/gnome/src/config/addressbook-config.c @@ -43,33 +43,31 @@ enum { COLUMN_BOOK_ACTIVE, COLUMN_BOOK_NAME, COLUMN_BOOK_UID }; -AddressBook_Config *addressbook_config_load_parameters () +AddressBook_Config *addressbook_config_load_parameters() { - AddressBook_Config *config = g_new0 (AddressBook_Config, 1); - GHashTable *params = dbus_get_addressbook_settings(); - - if (params == NULL) { - config->enable = 1; - config->max_results = 30; - config->display_contact_photo = 0; - config->search_phone_business = 1; - config->search_phone_home = 1; - config->search_phone_mobile = 1; - } - else { - config->enable = (size_t) (g_hash_table_lookup (params, ADDRESSBOOK_ENABLE)); - config->max_results = (size_t) (g_hash_table_lookup (params, ADDRESSBOOK_MAX_RESULTS)); - config->display_contact_photo = (size_t) (g_hash_table_lookup (params, ADDRESSBOOK_DISPLAY_CONTACT_PHOTO)); - config->search_phone_business = (size_t) (g_hash_table_lookup (params, ADDRESSBOOK_DISPLAY_PHONE_BUSINESS)); - config->search_phone_home = (size_t) (g_hash_table_lookup (params, ADDRESSBOOK_DISPLAY_PHONE_HOME)); - config->search_phone_mobile = (size_t) (g_hash_table_lookup (params, ADDRESSBOOK_DISPLAY_PHONE_MOBILE)); - } + static AddressBook_Config defconfig = { + .enable = 1, + .max_results = 30, + .display_contact_photo = 0, + .search_phone_business = 1, + .search_phone_home = 1, + .search_phone_mobile = 1, + }; - DEBUG ("Addressbook: Settings: enabled %d, max_result %d, photo %d, business %d, home %d, mobile %d", - config->enable, config->max_results, config->display_contact_photo, - config->search_phone_business, config->search_phone_home, config->search_phone_mobile); + static AddressBook_Config config; - return config; + GHashTable *params = dbus_get_addressbook_settings(); + if (params) { + config.enable = (size_t) (g_hash_table_lookup (params, ADDRESSBOOK_ENABLE)); + config.max_results = (size_t) (g_hash_table_lookup (params, ADDRESSBOOK_MAX_RESULTS)); + config.display_contact_photo = (size_t) (g_hash_table_lookup (params, ADDRESSBOOK_DISPLAY_CONTACT_PHOTO)); + config.search_phone_business = (size_t) (g_hash_table_lookup (params, ADDRESSBOOK_DISPLAY_PHONE_BUSINESS)); + config.search_phone_home = (size_t) (g_hash_table_lookup (params, ADDRESSBOOK_DISPLAY_PHONE_HOME)); + config.search_phone_mobile = (size_t) (g_hash_table_lookup (params, ADDRESSBOOK_DISPLAY_PHONE_MOBILE)); + } else + config = defconfig; + + return &config; } void diff --git a/gnome/src/config/audioconf.c b/gnome/src/config/audioconf.c index 2fc5db0f03..2b0a2afa08 100644 --- a/gnome/src/config/audioconf.c +++ b/gnome/src/config/audioconf.c @@ -545,10 +545,8 @@ codec_active_toggled (GtkCellRendererToggle *renderer UNUSED, gchar *path, gpoin gtk_tree_path_free (treePath); // Modify codec queue to represent change - if (active) - codec_set_active (&codec); - else - codec_set_inactive (&codec); + if (codec) + codec_set_active(codec, active); } /** @@ -1055,5 +1053,8 @@ GtkWidget* create_audio_configuration() /** Show/Hide the alsa configuration panel */ gboolean must_show_alsa_conf() { - return g_strcmp0(dbus_get_audio_manager(), ALSA_API_STR) == 0; + gchar *api = dbus_get_audio_manager(); + int ret = g_strcmp0(api, ALSA_API_STR); + g_free(api); + return ret == 0; } diff --git a/gnome/src/contacts/addrbookfactory.c b/gnome/src/contacts/addrbookfactory.c index 91d694aad2..5348f20977 100644 --- a/gnome/src/contacts/addrbookfactory.c +++ b/gnome/src/contacts/addrbookfactory.c @@ -48,7 +48,7 @@ handler_async_search (GList *hits, gpointer user_data) { AddressBook_Config *addressbook_config = user_data; - calltree_reset (contacts); + gtk_tree_store_clear (contacts->store); calllist_reset (contacts); for (GList *i = hits; i != NULL; i = i->next) { diff --git a/gnome/src/contacts/calltree.c b/gnome/src/contacts/calltree.c index 9e5e7562bd..b6ef5fe73e 100644 --- a/gnome/src/contacts/calltree.c +++ b/gnome/src/contacts/calltree.c @@ -446,12 +446,6 @@ calltree_display_call_info (callable_obj_t * c, CallDisplayType display_type, co return msg; } -void -calltree_reset (calltab_t* tab) -{ - gtk_tree_store_clear (tab->store); -} - void calltree_create (calltab_t* tab, gboolean searchbar_type) { @@ -817,7 +811,7 @@ void calltree_add_call (calltab_t* tab, callable_obj_t * c, GtkTreeIter *parent) // New call in the list - const gchar * description = calltree_display_call_info (c, DISPLAY_TYPE_CALL, ""); + gchar *description = calltree_display_call_info (c, DISPLAY_TYPE_CALL, ""); gtk_tree_store_prepend (tab->store, &iter, parent); @@ -865,19 +859,24 @@ void calltree_add_call (calltab_t* tab, callable_obj_t * c, GtkTreeIter *parent) } else if (tab == contacts) { pixbuf = c->_contact_thumbnail; - description = g_strconcat (description , NULL); } else { WARN ("CallTree: This widget doesn't exist - This is a bug in the application."); } //Resize it if (pixbuf) - if (gdk_pixbuf_get_width (pixbuf) > 32 || gdk_pixbuf_get_height (pixbuf) > 32) - pixbuf = gdk_pixbuf_scale_simple (pixbuf, 32, 32, GDK_INTERP_BILINEAR); + if (gdk_pixbuf_get_width (pixbuf) > 32 || gdk_pixbuf_get_height (pixbuf) > 32) { + GdkPixbuf *new = gdk_pixbuf_scale_simple (pixbuf, 32, 32, GDK_INTERP_BILINEAR); + g_object_unref(pixbuf); + pixbuf = new; + } if (pixbuf_security) - if (gdk_pixbuf_get_width (pixbuf_security) > 32 || gdk_pixbuf_get_height (pixbuf_security) > 32) - pixbuf_security = gdk_pixbuf_scale_simple (pixbuf_security, 32, 32, GDK_INTERP_BILINEAR); + if (gdk_pixbuf_get_width (pixbuf_security) > 32 || gdk_pixbuf_get_height (pixbuf_security) > 32) { + GdkPixbuf *new = gdk_pixbuf_scale_simple (pixbuf_security, 32, 32, GDK_INTERP_BILINEAR); + g_object_unref(pixbuf_security); + pixbuf_security = new; + } gtk_tree_store_set (tab->store, &iter, 0, pixbuf, // Icon @@ -886,6 +885,8 @@ void calltree_add_call (calltab_t* tab, callable_obj_t * c, GtkTreeIter *parent) 3, c, // Pointer -1); + g_free(description); + if (pixbuf != NULL) g_object_unref (G_OBJECT (pixbuf)); @@ -905,7 +906,6 @@ void calltree_add_history_entry (callable_obj_t *c, GtkTreeIter *parent) return; GdkPixbuf *pixbuf = NULL; - GdkPixbuf *pixbuf_security = NULL; GtkTreeIter iter; // New call in the list @@ -948,17 +948,16 @@ void calltree_add_history_entry (callable_obj_t *c, GtkTreeIter *parent) //Resize it if (pixbuf) - if (gdk_pixbuf_get_width (pixbuf) > 32 || gdk_pixbuf_get_height (pixbuf) > 32) - pixbuf = gdk_pixbuf_scale_simple (pixbuf, 32, 32, GDK_INTERP_BILINEAR); - - if (pixbuf_security != NULL) - if (gdk_pixbuf_get_width (pixbuf_security) > 32 || gdk_pixbuf_get_height (pixbuf_security) > 32) - pixbuf_security = gdk_pixbuf_scale_simple (pixbuf_security, 32, 32, GDK_INTERP_BILINEAR); + if (gdk_pixbuf_get_width (pixbuf) > 32 || gdk_pixbuf_get_height (pixbuf) > 32) { + GdkPixbuf *new = gdk_pixbuf_scale_simple (pixbuf, 32, 32, GDK_INTERP_BILINEAR); + g_object_unref(pixbuf); + pixbuf = new; + } gtk_tree_store_set (history->store, &iter, 0, pixbuf, // Icon 1, full_description, // Description - 2, pixbuf_security, // Icon + 2, NULL, // Icon 3, c, // Pointer -1); @@ -967,9 +966,6 @@ void calltree_add_history_entry (callable_obj_t *c, GtkTreeIter *parent) if (pixbuf != NULL) g_object_unref (G_OBJECT (pixbuf)); - if (pixbuf_security != NULL) - g_object_unref (G_OBJECT (pixbuf_security)); - gtk_tree_view_set_model (GTK_TREE_VIEW (history->view), GTK_TREE_MODEL (history->store)); history_search(); @@ -1033,7 +1029,9 @@ void calltree_add_conference (calltab_t* tab, conference_obj_t* conf) //Resize it if (pixbuf) { if (gdk_pixbuf_get_width (pixbuf) > 32 || gdk_pixbuf_get_height (pixbuf) > 32) { - pixbuf = gdk_pixbuf_scale_simple (pixbuf, 32, 32, GDK_INTERP_BILINEAR); + GdkPixbuf *new = gdk_pixbuf_scale_simple (pixbuf, 32, 32, GDK_INTERP_BILINEAR); + g_object_unref(pixbuf); + pixbuf = new; } } else DEBUG ("Error no pixbuff for conference from %s", ICONS_DIR); @@ -1226,8 +1224,11 @@ void calltree_add_history_conference(conference_obj_t *conf) pixbuf = gdk_pixbuf_new_from_file(ICONS_DIR "/usersAttached.svg", NULL); if (pixbuf) - if (gdk_pixbuf_get_width(pixbuf) > 32 || gdk_pixbuf_get_height(pixbuf) > 32) - pixbuf = gdk_pixbuf_scale_simple(pixbuf, 32, 32, GDK_INTERP_BILINEAR); + if (gdk_pixbuf_get_width(pixbuf) > 32 || gdk_pixbuf_get_height(pixbuf) > 32) { + GdkPixbuf *new = gdk_pixbuf_scale_simple(pixbuf, 32, 32, GDK_INTERP_BILINEAR); + g_object_unref(pixbuf); + pixbuf = new; + } const gchar * const date = get_formatted_start_timestamp(conf->_time_start); description = g_strconcat(description, date, NULL); diff --git a/gnome/src/contacts/calltree.h b/gnome/src/contacts/calltree.h index b41d3bdff3..770f3da966 100644 --- a/gnome/src/contacts/calltree.h +++ b/gnome/src/contacts/calltree.h @@ -108,9 +108,6 @@ calltree_update_conference (calltab_t* tab, const conference_obj_t* conf); void calltree_remove_conference (calltab_t* tab, const conference_obj_t* conf, GtkTreeIter *parent); -void -calltree_reset (calltab_t* tab); - void calltree_display (calltab_t *tab); diff --git a/gnome/src/contacts/history.c b/gnome/src/contacts/history.c index c7899de90a..7eb9b6629e 100644 --- a/gnome/src/contacts/history.c +++ b/gnome/src/contacts/history.c @@ -38,8 +38,9 @@ static GtkEntry *history_searchbar_widget; static gboolean history_is_visible (GtkTreeModel* model, GtkTreeIter* iter, gpointer data UNUSED) { + gboolean ret = TRUE; callable_obj_t *history_entry = NULL; - gchar* text = NULL; + const gchar *text = NULL; // Fetch the call description GValue val; @@ -62,17 +63,19 @@ static gboolean history_is_visible (GtkTreeModel* model, GtkTreeIter* iter, gpoi // MISSED, INCOMING, OUTGOING, ALL const gchar* search = gtk_entry_get_text (history_searchbar_widget); if (!search || !*search) - return TRUE; + goto end; SearchType search_type = get_current_history_search_type(); - gboolean match = g_regex_match_simple(search, text, G_REGEX_CASELESS, 0); + ret = g_regex_match_simple(search, text, G_REGEX_CASELESS, 0); if (search_type == SEARCH_ALL) - return match; + goto end; else // We need a match on the history_state_t and the current search type - return (history_entry->_history_state + 1) == search_type && match; + ret = ret && (history_entry->_history_state + 1) == search_type; } - return TRUE; +end: + g_value_unset(&val); + return ret; } static GtkTreeModel* history_create_filter (GtkTreeModel* child) @@ -90,8 +93,8 @@ void history_search (void) void history_search_init (void) { - history_filter = history_create_filter (GTK_TREE_MODEL (history->store)); - gtk_tree_view_set_model (GTK_TREE_VIEW (history->view), GTK_TREE_MODEL (history_filter)); + history_filter = history_create_filter(GTK_TREE_MODEL (history->store)); + gtk_tree_view_set_model(GTK_TREE_VIEW (history->view), GTK_TREE_MODEL (history_filter)); } void history_set_searchbar_widget (GtkWidget *searchbar) diff --git a/gnome/src/contacts/searchbar.c b/gnome/src/contacts/searchbar.c index 16c39b384e..1dda95581e 100644 --- a/gnome/src/contacts/searchbar.c +++ b/gnome/src/contacts/searchbar.c @@ -186,11 +186,12 @@ static void search_all (GtkWidget *item UNUSED, GtkEntry *entry) HistorySearchType = SEARCH_ALL; gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_PRIMARY, GTK_STOCK_FIND); - gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY, - g_markup_printf_escaped ("%s\n%s", - _ ("Search all"), - _ ("Click here to change the search type"))); + gchar *markup = g_markup_printf_escaped ("%s\n%s", + _ ("Search all"), + _ ("Click here to change the search type")); + gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY, markup); + g_free(markup); history_search(); } diff --git a/gnome/src/dbus/configurationmanager-introspec.xml b/gnome/src/dbus/configurationmanager-introspec.xml index d1e7faecb4..603f40d038 100755 --- a/gnome/src/dbus/configurationmanager-introspec.xml +++ b/gnome/src/dbus/configurationmanager-introspec.xml @@ -313,7 +313,7 @@ <tp:docstring> </tp:docstring> </arg> - <arg type="as" name="list" direction="out"> + <arg type="ai" name="list" direction="out"> <tp:docstring> </tp:docstring> </arg> diff --git a/gnome/src/dbus/dbus.c b/gnome/src/dbus/dbus.c index 1983a2968c..853614787d 100644 --- a/gnome/src/dbus/dbus.c +++ b/gnome/src/dbus/dbus.c @@ -1168,11 +1168,11 @@ dbus_get_current_audio_codec_name (const callable_obj_t * c) return codecName; } -gchar** +GArray * dbus_get_active_audio_codec_list (gchar *accountID) { - gchar ** array = NULL; + GArray * array = NULL; GError *error = NULL; org_sflphone_SFLphone_ConfigurationManager_get_active_audio_codec_list ( configurationManagerProxy, accountID, &array, &error); diff --git a/gnome/src/dbus/dbus.h b/gnome/src/dbus/dbus.h index 1eaebc4ede..b6e4eaafd9 100644 --- a/gnome/src/dbus/dbus.h +++ b/gnome/src/dbus/dbus.h @@ -211,9 +211,9 @@ gchar** dbus_default_audio_codec_list(); /** * ConfigurationManager - Get the list of the audio codecs used for media negotiation - * @return gchar** The list of audio codecs + * @return The list of audio codecs */ -gchar** dbus_get_active_audio_codec_list (gchar *accountID); +GArray *dbus_get_active_audio_codec_list (gchar *accountID); /** * ConfigurationManager - Set the list of audio codecs used for media negociation diff --git a/gnome/src/statusicon.c b/gnome/src/statusicon.c index 9e922c7969..92e2564de5 100644 --- a/gnome/src/statusicon.c +++ b/gnome/src/statusicon.c @@ -187,39 +187,29 @@ void hide_status_icon (void) void statusicon_set_tooltip() { - int count; - gchar *tip; - if (status) { - // Add a tooltip to the system tray icon - count = account_list_get_registered_accounts(); - tip = g_markup_printf_escaped ("%s - %s", _ ("SFLphone"), - g_markup_printf_escaped (n_ ("%i active account", "%i active accounts", count), count)); - gtk_status_icon_set_tooltip (status, tip); - g_free (tip); - + int count = account_list_get_registered_accounts(); + gchar *accounts = g_markup_printf_escaped(n_("%i active account", "%i active accounts", count), count); + gchar *tip = g_markup_printf_escaped("%s - %s", _("SFLphone"), accounts); + g_free(accounts); + gtk_status_icon_set_tooltip(status, tip); + g_free(tip); } } void status_tray_icon_blink (gboolean active) { - if (status) { - // Set a different icon to notify of an event - active ? gtk_status_icon_set_from_file (status, LOGO_NOTIF) - : gtk_status_icon_set_from_file (status, LOGO); - } + if (status) + gtk_status_icon_set_from_file (status, active ? LOGO_NOTIF : LOGO); } void status_tray_icon_online (gboolean online) { - if (status) { - // Set a different icon to notify of an event - online ? gtk_status_icon_set_from_file (status, LOGO) - : gtk_status_icon_set_from_file (status, LOGO_OFFLINE); - } + if (status) + gtk_status_icon_set_from_file(status, online ? LOGO : LOGO_OFFLINE); } GtkStatusIcon* diff --git a/gnome/src/uimanager.c b/gnome/src/uimanager.c index 76de57fb96..9484f82847 100644 --- a/gnome/src/uimanager.c +++ b/gnome/src/uimanager.c @@ -163,17 +163,13 @@ update_actions() } // If addressbook support has been enabled and all addressbooks are loaded, display the icon - if (addrbook) { - AddressBook_Config *addressbook_config = addressbook_config_load_parameters(); - - if (addressbook_config->enable && addrbook->is_ready()) { - gtk_toolbar_insert(GTK_TOOLBAR(toolbar_), GTK_TOOL_ITEM(contactButton_), -1); + if (addrbook && addrbook->is_ready() && addressbook_config_load_parameters()->enable) { + gtk_toolbar_insert(GTK_TOOLBAR(toolbar_), GTK_TOOL_ITEM(contactButton_), -1); - // Make the icon clickable only if at least one address book is active - if (addrbook->is_active()) { - gtk_widget_set_sensitive(contactButton_, TRUE); - gtk_widget_set_tooltip_text(contactButton_, _("Address book")); - } + // Make the icon clickable only if at least one address book is active + if (addrbook->is_active()) { + gtk_widget_set_sensitive(contactButton_, TRUE); + gtk_widget_set_tooltip_text(contactButton_, _("Address book")); } } diff --git a/kde/src/dbus/configurationmanager-introspec.xml b/kde/src/dbus/configurationmanager-introspec.xml index a126d8e023..5f84e72cf9 100755 --- a/kde/src/dbus/configurationmanager-introspec.xml +++ b/kde/src/dbus/configurationmanager-introspec.xml @@ -313,7 +313,7 @@ <tp:docstring> </tp:docstring> </arg> - <arg type="as" name="list" direction="out"> + <arg type="ai" name="list" direction="out"> <tp:docstring> </tp:docstring> </arg> -- GitLab