Commit 3dc63b11 authored by Rafaël Carré's avatar Rafaël Carré

Cleanup

Fix memory leaks in client
Change a bit dbus protocol: int -> int instead of int -> string -> string -> int
Remove unused and empty yamlengine
parent 7dd5689c
......@@ -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
......
/*
* 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
......@@ -36,9 +36,6 @@
#include "yamlemitter.h"
#include "yamlnode.h"
class Engine;
// class MappingNode;
class Serializable
{
......
/*
* 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() {}
}
/*
* 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
......@@ -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>
......
......@@ -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);
}
}
......@@ -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();
......
......@@ -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
......
......@@ -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
......
......@@ -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;
......
......@@ -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)
......
......@@ -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);
......
......@@ -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)
......
......@@ -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);