Skip to content
Snippets Groups Projects
Commit 6b5b63f1 authored by Alexandre Savard's avatar Alexandre Savard
Browse files

[#3649] Update sipvoiplink with new configuration

parent 01f62b02
Branches
Tags
No related merge requests found
......@@ -36,10 +36,22 @@
#include <pwd.h>
#include <sstream>
// CredentialItem::CredentialItem() {}
// CredentialItem::~CredentialItem() {}
Credentials::Credentials() : credentialCount(0) {}
Credentials::~Credentials() {}
CredentialItem *Credentials::getCredential(int index)
{
if((index >= 0) && (index < credentialCount))
return &(credentialArray[index]);
else
return NULL;
}
void Credentials::serialize(Conf::YamlEmitter *emitter)
{
......@@ -97,7 +109,6 @@ SIPAccount::SIPAccount (const AccountID& accountID)
, _tlsEnabled(false)
, _stunEnabled(false)
// , _routeSet("")
// , _realm("")
, _authenticationUsename("")
// , _tlsListenerPort("5061")
, _srtpEnabled(false)
......@@ -308,6 +319,8 @@ void SIPAccount::unserialize(Conf::MappingNode *map)
credMap = (Conf::MappingNode *)(map->getValue(credKey));
credentials.unserialize(credMap);
_credentialCount = credentials.getCredentialCount();
val = (Conf::ScalarNode *)(map->getValue(displayNameKey));
if(val) { _displayName = val->getValue(); val = NULL; }
......@@ -482,10 +495,6 @@ void SIPAccount::setAccountDetails(const std::map<std::string, std::string>& det
find_in_map(AUTHENTICATION_USERNAME, authenticationName)
find_in_map(USERAGENT, ua_name)
// setConfig(accountID, REALM, realm);
// setConfig(accountID, USERAGENT, ua_name);
// setConfig(accountID, AUTHENTICATION_USERNAME, authenticationName);
setUseragent(ua_name);
// srtp settings
......@@ -558,7 +567,6 @@ void SIPAccount::setAccountDetails(const std::map<std::string, std::string>& det
hash = Manager::instance().computeMd5HashFromCredential(authenticationName, password, realm);
}
// setConfig(accountID, PASSWORD, hash);
setPassword(hash);
}
}
......@@ -613,9 +621,9 @@ std::map<std::string, std::string> SIPAccount::getAccountDetails()
a.insert(std::pair<std::string, std::string>(ROUTESET, getRouteSet()));
a.insert(std::pair<std::string, std::string>(CONFIG_ACCOUNT_RESOLVE_ONCE, isResolveOnce() ? "true" : "false"));
// a.insert(std::pair<std::string, std::string>(REALM, account->
a.insert(std::pair<std::string, std::string>(REALM, _realm));
a.insert(std::pair<std::string, std::string>(USERAGENT, getUseragent()));
// a.insert(std::pair<std::string, std::string>(AUTHENTICATION_USERNAME, getConfigString(accountID, AUTHENTICATION_USERNAME)));
a.insert(std::pair<std::string, std::string>(CONFIG_ACCOUNT_REGISTRATION_EXPIRE, getRegistrationExpire()));
a.insert(std::pair<std::string, std::string>(LOCAL_INTERFACE, getLocalInterface()));
a.insert(std::pair<std::string, std::string>(PUBLISHED_SAMEAS_LOCAL, getPublishedSameasLocal() ? "true" : "false"));
......@@ -697,8 +705,10 @@ int SIPAccount::initCredential (void)
// Use authentication username if provided
if (!_authenticationUsername.empty()) {
_debug("Use credential authentication name -------------------------------------");
cred_info[0].username = pj_str (strdup (_authenticationUsername.c_str()));
} else {
_debug("Use credential uername name -------------------------------------");
cred_info[0].username = pj_str (strdup (_username.c_str()));
}
......@@ -727,6 +737,7 @@ int SIPAccount::initCredential (void)
int i;
for (i = 1; i < credentialCount; i++) {
_debug("--------------------------------------- Not supposed to have any credential");
std::string credentialIndex;
std::stringstream streamOut;
streamOut << i - 1;
......@@ -783,7 +794,7 @@ int SIPAccount::registerVoIPLink()
initCredential();
// Init TLS settings if the user wants to use TLS
bool tlsEnabled = false;// Manager::instance().getConfigBool (_accountID, TLS_ENABLE);
bool tlsEnabled = false;
if (tlsEnabled) {
_transportType = PJSIP_TRANSPORT_TLS;
......@@ -791,7 +802,7 @@ int SIPAccount::registerVoIPLink()
}
// Init STUN settings for this account if the user selected it
bool stunEnabled = _stunEnabled; // Manager::instance().getConfigBool (_accountID, STUN_ENABLE);
bool stunEnabled = _stunEnabled;
if (stunEnabled) {
_transportType = PJSIP_TRANSPORT_START_OTHER;
......@@ -864,7 +875,7 @@ void SIPAccount::initTlsConfiguration (void)
}
// TLS listener is unique and should be only modified through IP2IP_PROFILE
// std::string tlsPortStr = Manager::instance().getConfigString(_accountID, TLS_LISTENER_PORT);
// setTlsListenerPort(atoi(tlsPortStr.c_str()));
setTlsListenerPort(atoi(_tlsPortStr.c_str()));
......@@ -896,8 +907,7 @@ void SIPAccount::initStunConfiguration (void)
size_t pos;
std::string stunServer, serverName, serverPort;
stunServer = _stunServer; // Manager::instance().getConfigString (_accountID, STUN_SERVER);
stunServer = _stunServer;
// Init STUN socket
pos = stunServer.find (':');
......@@ -1116,8 +1126,6 @@ std::string SIPAccount::getContactHeader (const std::string& address, const std:
transport = "";
}
// _displayName = Manager::instance().getConfigString (_accountID, DISPLAY_NAME);
_debug ("Display Name: %s", _displayName.c_str());
int len = pj_ansi_snprintf (contact, PJSIP_MAX_URL_SIZE,
......
......@@ -123,13 +123,20 @@ class SipAccountException : public std::exception
};
class CredentialItem
{
public:
std::string username;
std::string password;
std::string realm;
};
class Credentials : public Serializable
{
public:
typedef std::map<std::string, std::string> CredentialMap;
Credentials();
~Credentials();
......@@ -141,11 +148,14 @@ class Credentials : public Serializable
int getCredentialCount(void) { return credentialCount; }
void setCredentialCount(int count) { credentialCount = count; }
void setNewCredential(std::string username, std::string password, std::string realm);
CredentialItem *getCredential(int index);
private:
int credentialCount;
CredentialMap credentialMap;
CredentialItem credentialArray[10];
};
......@@ -463,6 +473,9 @@ class SIPAccount : public Account
void setZrtpHelloHash(bool hellohash) { _zrtpHelloHash = hellohash; }
// void setSrtpKeyExchange
std::string getRealm(void) { return _realm; }
void setRealm(std::string r) { _realm = r; }
std::string getTlsEnable(void) {return _tlsEnable; }
void setTlsEnable(std::string enabl) { _tlsEnable = enabl; }
......
......@@ -451,7 +451,6 @@ std::string SIPVoIPLink::get_useragent_name (const AccountID& id)
std::ostringstream useragent;
// useragent << Manager::instance ().getConfigString (id, USERAGENT);
useragent << account->getUseragent();
if (useragent.str() == "sflphone" || useragent.str() == "")
useragent << "/" << SFLPHONED_VERSION;
......@@ -1346,7 +1345,6 @@ SIPVoIPLink::dtmfSipInfo(SIPCall *call, char code)
duration = Manager::instance().voipPreferences.getPulseLength();
// Manager::instance().getConfigInt (SIGNALISATION, PULSE_LENGTH);
dtmf_body = new char[body_len];
......@@ -2570,9 +2568,13 @@ std::string SIPVoIPLink::findLocalAddressFromUri (const std::string& uri, pjsip_
}
std::string localaddr(localAddress.ptr, localAddress.slen);
if(localaddr == "0.0.0.0")
loadSIPLocalIP (&localaddr);
_debug ("SIP: Local address discovered from attached transport: %s", localaddr.c_str());
return std::string (localAddress.ptr, localAddress.slen);
return localaddr;
}
......@@ -3297,7 +3299,7 @@ void call_on_media_update (pjsip_inv_session *inv, pj_status_t status)
// if RTPFALLBACK, change RTP session
AccountID accountID = Manager::instance().getAccountFromCall (call->getCallId());
SIPAccount *account = (SIPAccount *)Manager::instance().getAccount(accountID);
//if(Manager::instance().getConfigString (accountID, SRTP_RTP_FALLBACK) == "true")
if(account->getSrtpFallback())
call->getAudioRtp()->initAudioRtpSession(call);
}
......@@ -3440,7 +3442,6 @@ void regc_cb (struct pjsip_regc_cbparam *param)
out << (expire_value * 2);
std::string s = out.str();
// Manager::instance().setConfig(account->getAccountID(), CONFIG_ACCOUNT_REGISTRATION_EXPIRE, s);
account->setRegistrationExpire(s);
account->registerVoIPLink();
}
......@@ -3649,7 +3650,6 @@ mod_on_rx_request (pjsip_rx_data *rdata)
/******************************************* URL HOOK *********************************************/
// if (Manager::instance().getConfigString (HOOKS, URLHOOK_SIP_ENABLED) == "1") {
if (Manager::instance().hookPreference.getSipEnabled()) {
_debug("UserAgent: Set sip url hooks");
......@@ -3658,13 +3658,11 @@ mod_on_rx_request (pjsip_rx_data *rdata)
header_value = fetch_header_value (rdata->msg_info.msg,
Manager::instance().hookPreference.getUrlSipField());
// Manager::instance().getConfigString (HOOKS, URLHOOK_SIP_FIELD));
if (header_value.size () < header_value.max_size()) {
if (header_value!="") {
urlhook->addAction (header_value,
Manager::instance().hookPreference.getUrlCommand());
//Manager::instance().getConfigString (HOOKS, URLHOOK_COMMAND));
}
} else
throw length_error ("UserAgent: Url exceeds std::string max_size");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment