Commit 0483da3d authored by Julien Bonjean's avatar Julien Bonjean

Merge branch 'master' into contact_list

parents b40f86ec 597c9197
......@@ -9,6 +9,6 @@ unittest:
ACLOCAL_AMFLAGS = -I m4
SUBDIRS = libs src ringtones po man
SUBDIRS = libs src ringtones po man test
EXTRA_DIST = m4/*.m4 tools/*.sh platform/* images/* README.gentoo
......@@ -271,3 +271,15 @@ int account_list_get_iax_account_number( void ){
return n;
}
gchar * account_list_get_ordered_list (void) {
gchar *order="";
guint i;
for( i=0; i<account_list_get_size(); i++ )
{
order = g_strconcat (account_list_get_nth (i)->accountID, "/", NULL);
}
return order;
}
......@@ -182,6 +182,7 @@ int account_list_get_sip_account_number( void );
*/
int account_list_get_iax_account_number( void );
gchar * account_list_get_ordered_list (void);
#endif
......@@ -96,7 +96,22 @@ void create_new_call (gchar *to, gchar *from, call_state_t state, gchar *account
*new_call = call;
}
void
void create_new_call_from_details (const gchar *call_id, GHashTable *details, call_t **call)
{
gchar *from, *to, *accountID;
call_t *new_call;
GHashTable *call_details;
accountID = g_hash_table_lookup (details, "ACCOUNTID");
to = g_hash_table_lookup (details, "PEER_NUMBER");
from = g_markup_printf_escaped("\"\" <%s>", to);
create_new_call (from, from, CALL_STATE_DIALING, accountID, &new_call);
*call = new_call;
}
void
free_call_t (call_t *c)
{
g_free (c->callID);
......
......@@ -143,6 +143,9 @@ call_get_recipient( const call_t *);
void
create_new_call (gchar *, gchar *, call_state_t, gchar *, call_t **);
void
create_new_call_from_details (const gchar *, GHashTable *, call_t **);
void
attach_thumbnail (call_t *, GdkPixbuf *);
......
......@@ -300,6 +300,10 @@ account_move(gboolean moveUp, gpointer data)
account_list_move_up(indice);
else
account_list_move_down(indice);
// Set the order in the configuration file
dbus_set_accounts_order (account_list_get_ordered_list ());
}
/**
......
......@@ -125,6 +125,43 @@ static
inline
#endif
gboolean
org_sflphone_SFLphone_ConfigurationManager_set_accounts_order (DBusGProxy *proxy, const char * IN_order, GError **error)
{
return dbus_g_proxy_call (proxy, "setAccountsOrder", error, G_TYPE_STRING, IN_order, G_TYPE_INVALID, G_TYPE_INVALID);
}
typedef void (*org_sflphone_SFLphone_ConfigurationManager_set_accounts_order_reply) (DBusGProxy *proxy, GError *error, gpointer userdata);
static void
org_sflphone_SFLphone_ConfigurationManager_set_accounts_order_async_callback (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data)
{
DBusGAsyncData *data = (DBusGAsyncData*) user_data;
GError *error = NULL;
dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID);
(*(org_sflphone_SFLphone_ConfigurationManager_set_accounts_order_reply)data->cb) (proxy, error, data->userdata);
return;
}
static
#ifdef G_HAVE_INLINE
inline
#endif
DBusGProxyCall*
org_sflphone_SFLphone_ConfigurationManager_set_accounts_order_async (DBusGProxy *proxy, const char * IN_order, org_sflphone_SFLphone_ConfigurationManager_set_accounts_order_reply callback, gpointer userdata)
{
DBusGAsyncData *stuff;
stuff = g_new (DBusGAsyncData, 1);
stuff->cb = G_CALLBACK (callback);
stuff->userdata = userdata;
return dbus_g_proxy_begin_call (proxy, "setAccountsOrder", org_sflphone_SFLphone_ConfigurationManager_set_accounts_order_async_callback, stuff, g_free, G_TYPE_STRING, IN_order, G_TYPE_INVALID);
}
static
#ifdef G_HAVE_INLINE
inline
#endif
gboolean
org_sflphone_SFLphone_ConfigurationManager_remove_account (DBusGProxy *proxy, const char * IN_accoundID, GError **error)
{
......
......@@ -153,16 +153,25 @@ call_state_cb (DBusGProxy *proxy UNUSED,
}
}
else
{ //The callID is unknow, threat it like a new call
{
// The callID is unknow, threat it like a new call
// If it were an incoming call, we won't be here
// It means that a new call has been initiated with an other client (cli for instance)
if ( strcmp(state, "RINGING") == 0 )
{
g_print ("New ringing call! %s\n",callID);
call_t * c = g_new0 (call_t, 1);
c->accountID = g_strdup("1");
c->callID = g_strdup(callID);
c->from = g_strdup("\"\" <>");
c->state = CALL_STATE_RINGING;
sflphone_incoming_call (c);
call_t *new_call;
GHashTable *call_details;
g_print ("New ringing call! accountID: %s\n", callID);
// We fetch the details associated to the specified call
call_details = dbus_get_call_details (callID);
create_new_call_from_details (callID, call_details, &new_call);
// Restore the callID to be synchronous with the daemon
new_call->callID = g_strdup(callID);
sflphone_incoming_call (new_call);
}
}
}
......@@ -1549,4 +1558,28 @@ void dbus_set_hook_settings (GHashTable * settings){
}
}
GHashTable* dbus_get_call_details (const gchar *callID)
{
GError *error = NULL;
GHashTable *details = NULL;
org_sflphone_SFLphone_CallManager_get_call_details (callManagerProxy, callID, &details, &error);
if (error){
g_print ("Error calling org_sflphone_SFLphone_CallManager_get_call_details\n");
g_error_free (error);
}
return details;
}
void dbus_set_accounts_order (const gchar* order) {
GError *error = NULL;
org_sflphone_SFLphone_ConfigurationManager_set_accounts_order (configurationManagerProxy, order, &error);
if (error){
g_print ("Error calling org_sflphone_SFLphone_ConfigurationManager_set_accounts_order\n");
g_error_free (error);
}
}
......@@ -477,4 +477,8 @@ void dbus_set_hook_settings (GHashTable *);
gboolean dbus_get_is_recording(const call_t *);
GHashTable* dbus_get_call_details (const gchar* callID);
void dbus_set_accounts_order (const gchar* order);
#endif
......@@ -140,11 +140,10 @@ CallManager::getCurrentCodecName(const std::string& callID)
std::map< std::string, std::string >
CallManager::getCallDetails( const std::string& callID UNUSED )
CallManager::getCallDetails( const std::string& callID )
{
_debug("CallManager::getCallDetails received\n");
std::map<std::string, std::string> a;
return a;
return Manager::instance().getCallDetails (callID);
}
std::string
......
......@@ -23,6 +23,7 @@ public:
register_method(ConfigurationManager_adaptor, getAccountDetails, _getAccountDetails_stub);
register_method(ConfigurationManager_adaptor, setAccountDetails, _setAccountDetails_stub);
register_method(ConfigurationManager_adaptor, addAccount, _addAccount_stub);
register_method(ConfigurationManager_adaptor, setAccountsOrder, _setAccountsOrder_stub);
register_method(ConfigurationManager_adaptor, removeAccount, _removeAccount_stub);
register_method(ConfigurationManager_adaptor, getAccountList, _getAccountList_stub);
register_method(ConfigurationManager_adaptor, sendRegister, _sendRegister_stub);
......@@ -106,6 +107,11 @@ public:
{ "details", "a{ss}", true },
{ 0, 0, 0 }
};
static ::DBus::IntrospectedArgument setAccountsOrder_args[] =
{
{ "order", "s", true },
{ 0, 0, 0 }
};
static ::DBus::IntrospectedArgument removeAccount_args[] =
{
{ "accoundID", "s", true },
......@@ -428,6 +434,7 @@ public:
{ "getAccountDetails", getAccountDetails_args },
{ "setAccountDetails", setAccountDetails_args },
{ "addAccount", addAccount_args },
{ "setAccountsOrder", setAccountsOrder_args },
{ "removeAccount", removeAccount_args },
{ "getAccountList", getAccountList_args },
{ "sendRegister", sendRegister_args },
......@@ -527,6 +534,7 @@ public:
virtual std::map< std::string, std::string > getAccountDetails(const std::string& accountID) = 0;
virtual void setAccountDetails(const std::string& accountID, const std::map< std::string, std::string >& details) = 0;
virtual void addAccount(const std::map< std::string, std::string >& details) = 0;
virtual void setAccountsOrder(const std::string& order) = 0;
virtual void removeAccount(const std::string& accoundID) = 0;
virtual std::vector< std::string > getAccountList() = 0;
virtual void sendRegister(const std::string& accountID, const int32_t& expire) = 0;
......@@ -648,6 +656,15 @@ private:
::DBus::ReturnMessage reply(call);
return reply;
}
::DBus::Message _setAccountsOrder_stub(const ::DBus::CallMessage &call)
{
::DBus::MessageIter ri = call.reader();
std::string argin1; ri >> argin1;
setAccountsOrder(argin1);
::DBus::ReturnMessage reply(call);
return reply;
}
::DBus::Message _removeAccount_stub(const ::DBus::CallMessage &call)
{
::DBus::MessageIter ri = call.reader();
......
......@@ -17,6 +17,10 @@
<arg type="a{ss}" name="details" direction="in"/>
</method>
<method name="setAccountsOrder">
<arg type="s" name="order" direction="in"/>
</method>
<method name="removeAccount">
<arg type="s" name="accoundID" direction="in"/>
</method>
......
......@@ -109,14 +109,12 @@ ConfigurationManager::getRingtoneList( )
std::vector< std::string >
ConfigurationManager::getCodecList( )
{
_debug("ConfigurationManager::getCodecList received\n");
return Manager::instance().getCodecList();
}
std::vector< std::string >
ConfigurationManager::getCodecDetails( const int32_t& payload )
{
_debug("ConfigurationManager::getCodecList received\n");
return Manager::instance().getCodecDetails( payload );
}
......@@ -450,3 +448,8 @@ std::map<std::string,std::string> ConfigurationManager::getHookSettings (void) {
void ConfigurationManager::setHookSettings (const std::map<std::string, std::string>& settings) {
Manager::instance().setHookSettings (settings);
}
void ConfigurationManager::setAccountsOrder (const std::string& order) {
Manager::instance().setAccountsOrder (order);
}
......@@ -109,6 +109,8 @@ public:
std::vector< std::string > getAddressbookList ( void );
void setAddressbookList( const std::vector< std::string >& list );
void setAccountsOrder (const std::string& order);
std::map<std::string, std::string> getHookSettings (void);
void setHookSettings (const std::map<std::string, std::string>& settings);
......
......@@ -708,7 +708,7 @@ ManagerImpl::incomingCall(Call* call, const AccountID& accountId)
stopTone(true);
_debug("Incoming call %s\n", call->getCallId().data());
_debug("Incoming call %s for account %s\n", call->getCallId().data(), accountId.c_str());
associateCallToAccount(call->getCallId(), accountId);
......@@ -1204,6 +1204,7 @@ ManagerImpl::initConfigFile ( bool load_user_value )
fill_config_int(CONFIG_AUDIO , DFT_AUDIO_MANAGER);
fill_config_int(CONFIG_PA_VOLUME_CTRL , YES_STR);
fill_config_int(CONFIG_SIP_PORT, DFT_SIP_PORT);
fill_config_str(CONFIG_ACCOUNTS_ORDER, "");
section = ADDRESSBOOK;
fill_config_int (ADDRESSBOOK_MAX_RESULTS, "25");
......@@ -2126,22 +2127,53 @@ ManagerImpl::setConfig(const std::string& section, const std::string& name, int
return _config.setConfigTreeItem(section, name, valueStream.str());
}
void ManagerImpl::setAccountsOrder (const std::string& order)
{
// Set the new config
setConfig (PREFERENCES, CONFIG_ACCOUNTS_ORDER, order);
}
std::vector< std::string >
ManagerImpl::getAccountList()
{
std::vector< std::string > v;
std::vector< std::string > v;
std::vector< std::string > account_order;
int i;
AccountMap::iterator iter = _accountMap.begin();
while ( iter != _accountMap.end() ) {
if ( iter->second != 0 ) {
_debug("Account List: %s\n", iter->first.data());
v.push_back(iter->first.data());
account_order = loadAccountOrder ();
AccountMap::iterator iter;
// If no order has been set, load the default one
// ie according to the creation date.
if (account_order.size () == 0) {
iter = _accountMap.begin ();
while ( iter != _accountMap.end() ) {
if ( iter->second != 0 ) {
v.push_back(iter->first.data());
}
iter++;
}
}
iter++;
}
_debug("Size: %d\n", v.size());
return v;
// Otherelse, load the custom one
// ie according to the saved order
else {
for (i=0; i<account_order.size (); i++) {
// This account has not been loaded, so we ignore it
if ( (iter=_accountMap.find (account_order[i])) != _accountMap.end() )
{
// If the account is valid
if (iter->second != 0)
{
v.push_back (iter->first.data ());
}
}
}
}
return v;
}
std::map< std::string, std::string > ManagerImpl::getAccountDetails(const AccountID& accountID)
......@@ -2338,47 +2370,61 @@ ManagerImpl::getNewCallID()
return random_id.str();
}
short
ManagerImpl::loadAccountMap()
std::vector <std::string> ManagerImpl::loadAccountOrder (void)
{
short nbAccount = 0;
TokenList sections = _config.getSections();
std::string accountType;
Account* tmpAccount;
std::string account_list;
std::vector <std::string> account_vect;
account_list = getConfigString (PREFERENCES, CONFIG_ACCOUNTS_ORDER);
return unserialize (account_list);
}
TokenList::iterator iter = sections.begin();
while(iter != sections.end()) {
// Check if it starts with "Account:" (SIP and IAX pour le moment)
if ((int)(iter->find("Account:")) == -1) {
iter++;
continue;
}
accountType = getConfigString(*iter, CONFIG_ACCOUNT_TYPE);
if (accountType == "SIP") {
tmpAccount = AccountCreator::createAccount(AccountCreator::SIP_ACCOUNT, *iter);
}
else if (accountType == "IAX") {
tmpAccount = AccountCreator::createAccount(AccountCreator::IAX_ACCOUNT, *iter);
}
else {
_debug("Unknown %s param in config file (%s)\n", CONFIG_ACCOUNT_TYPE, accountType.c_str());
}
short
ManagerImpl::loadAccountMap()
{
_debug("tmpAccount.getRegistrationState() %i \n ",tmpAccount->getRegistrationState());
if (tmpAccount != NULL) {
short nbAccount = 0;
TokenList sections = _config.getSections();
std::string accountType;
Account* tmpAccount;
std::vector <std::string> account_order;
TokenList::iterator iter = sections.begin();
while(iter != sections.end()) {
// Check if it starts with "Account:" (SIP and IAX pour le moment)
if ((int)(iter->find("Account:")) == -1) {
iter++;
continue;
}
_debug(" %s \n", iter->c_str());
_accountMap[iter->c_str()] = tmpAccount;
nbAccount++;
}
accountType = getConfigString(*iter, CONFIG_ACCOUNT_TYPE);
if (accountType == "SIP") {
tmpAccount = AccountCreator::createAccount(AccountCreator::SIP_ACCOUNT, *iter);
}
else if (accountType == "IAX") {
tmpAccount = AccountCreator::createAccount(AccountCreator::IAX_ACCOUNT, *iter);
}
else {
_debug("Unknown %s param in config file (%s)\n", CONFIG_ACCOUNT_TYPE, accountType.c_str());
}
iter++;
}
_debug("nbAccount loaded %i \n",nbAccount);
return nbAccount;
if (tmpAccount != NULL) {
_debug(" %s \n", iter->c_str());
_accountMap[iter->c_str()] = tmpAccount;
nbAccount++;
}
iter++;
}
_debug("nbAccount loaded %i \n",nbAccount);
return nbAccount;
}
void
......@@ -2675,3 +2721,44 @@ bool ManagerImpl::removeCallConfig(const CallID& callID) {
return false;
}
std::map< std::string, std::string > ManagerImpl::getCallDetails(const CallID& callID) {
std::map<std::string, std::string> call_details;
AccountID accountid;
Account *account;
VoIPLink *link;
Call *call;
// We need here to retrieve the call information attached to the call ID
// To achieve that, we need to get the voip link attached to the call
// But to achieve that, we need to get the account the call was made with
// So first we fetch the account
accountid = getAccountFromCall (callID);
// Then the VoIP link this account is linked with (IAX2 or SIP)
if ( (account=getAccount (accountid)) != 0) {
link = account->getVoIPLink ();
if (link) {
call = link->getCall (callID);
}
}
if (call)
{
call_details.insert (std::pair<std::string, std::string> ("ACCOUNTID", accountid));
call_details.insert (std::pair<std::string, std::string> ("PEER_NUMBER", call->getPeerNumber ()));
call_details.insert (std::pair<std::string, std::string> ("PEER_NAME", call->getPeerName ()));
}
else
{
_debug ("Error: Managerimpl - getCallDetails ()\n");
call_details.insert (std::pair<std::string, std::string> ("ACCOUNTID", AccountNULL));
call_details.insert (std::pair<std::string, std::string> ("PEER_NUMBER", "Unknown"));
call_details.insert (std::pair<std::string, std::string> ("PEER_NAME", "Unknown"));
}
return call_details;
}
......@@ -282,6 +282,11 @@ class ManagerImpl {
*/
std::vector< std::string > getAccountList();
/**
* Set the account order in the config file
*/
void setAccountsOrder (const std::string& order);
/**
* Retrieve details about a given account
* @param accountID The account identifier
......@@ -289,6 +294,13 @@ class ManagerImpl {
*/
std::map< std::string, std::string > getAccountDetails(const AccountID& accountID);
/**
* Retrieve details about a given call
* @param callID The account identifier
* @return std::map< std::string, std::string > The call details
*/
std::map< std::string, std::string > getCallDetails(const CallID& callID);
/**
* Save the details of an existing account, given the account ID
* This will load the configuration map with the given data.
......@@ -1056,6 +1068,13 @@ class ManagerImpl {
*/
short loadAccountMap();
/**
* Load the accounts order set by the user from the sflphonedrc config file
* @return std::vector<std::string> A vector containing the account ID's
*/
std::vector<std::string> loadAccountOrder ();
/**
* Unload the account (delete them)
*/
......
......@@ -40,7 +40,6 @@ SIPAccount::SIPAccount(const AccountID& accountID)
}
SIPAccount::~SIPAccount()
{
/* One SIP account less connected to the sip voiplink */
......
......@@ -28,12 +28,9 @@
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <resolv.h>
//extern struct state _res;
#define CAN_REINVITE 1
/**************** EXTERN VARIABLES AND FUNCTIONS (callbacks) **************************/
/*
......@@ -47,11 +44,11 @@ void get_remote_sdp_from_offer( pjsip_rx_data *rdata, pjmedia_sdp_session** r_sd
int getModId();
/**
* * Set audio (SDP) configuration for a call
* * localport, localip, localexternalport
* * @param call a SIPCall valid pointer
* * @return bool True
* */
* Set audio (SDP) configuration for a call
* localport, localip, localexternalport
* @param call a SIPCall valid pointer
* @return bool True
*/
bool setCallAudioLocal(SIPCall* call, std::string localIP, bool stun, std::string server);
void handle_incoming_options (pjsip_rx_data *rxdata);
......@@ -178,8 +175,6 @@ SIPVoIPLink* SIPVoIPLink::_instance = NULL;