Commit 90cc0a5e authored by Alexandre Savard's avatar Alexandre Savard
Browse files

Merge branch 'sipregistration' of...

Merge branch 'sipregistration' of git+ssh://git.sflphone.org/var/repos/sflphone/git/sflphone into sipregistration
parents dd05d035 497f205c
...@@ -228,13 +228,6 @@ class Account : public Serializable { ...@@ -228,13 +228,6 @@ class Account : public Serializable {
alias_ = alias; alias_ = alias;
} }
std::string getType() const {
return type_;
}
void setType(const std::string &type) {
type_ = type;
}
/** /**
* Accessor to data structures * Accessor to data structures
* @return CodecOrder& The list that reflects the user's choice * @return CodecOrder& The list that reflects the user's choice
......
...@@ -80,8 +80,8 @@ void AudioRecord::setRecordingOption(FILE_TYPE type, int sndSmplRate, const std: ...@@ -80,8 +80,8 @@ void AudioRecord::setRecordingOption(FILE_TYPE type, int sndSmplRate, const std:
std::stringstream s; std::stringstream s;
std::string filePath; std::string filePath;
// use HOME directory if path is empty, nor does not exist // use HOME directory if path is empty, or if path does not exist
if(path.empty() || !fileutils::check_dir(path.c_str())) { if (path.empty() || !fileutils::check_dir(path.c_str())) {
s << getenv("HOME"); s << getenv("HOME");
filePath = s.str(); filePath = s.str();
} }
...@@ -124,8 +124,6 @@ bool AudioRecord::openFile() ...@@ -124,8 +124,6 @@ bool AudioRecord::openFile()
{ {
bool result = false; bool result = false;
DEBUG("AudioRecord: Open file()");
if (not fileExists()) { if (not fileExists()) {
DEBUG("AudioRecord: Filename does not exist, creating one"); DEBUG("AudioRecord: Filename does not exist, creating one");
byteCounter_ = 0; byteCounter_ = 0;
...@@ -170,24 +168,14 @@ bool AudioRecord::isRecording() const ...@@ -170,24 +168,14 @@ bool AudioRecord::isRecording() const
return recordingEnabled_; return recordingEnabled_;
} }
bool AudioRecord::setRecording() void AudioRecord::setRecording()
{ {
if (isOpenFile()) { if (isOpenFile()) {
if (!recordingEnabled_) { recordingEnabled_ = !recordingEnabled_;
DEBUG("AudioRecording: Start recording");
recordingEnabled_ = true;
} else {
DEBUG("AudioRecording: Stop recording");
recordingEnabled_ = false;
}
} else { } else {
openFile(); openFile();
recordingEnabled_ = true; // once opend file, start recording recordingEnabled_ = true; // once opend file, start recording
} }
// WARNING: Unused return value
return true;
} }
void AudioRecord::stopRecording() void AudioRecord::stopRecording()
...@@ -198,12 +186,8 @@ void AudioRecord::stopRecording() ...@@ -198,12 +186,8 @@ void AudioRecord::stopRecording()
void AudioRecord::createFilename() void AudioRecord::createFilename()
{ {
time_t rawtime; time_t rawtime = time(NULL);
struct tm * timeinfo = localtime(&rawtime);
struct tm * timeinfo;
rawtime = time(NULL);
timeinfo = localtime(&rawtime);
std::stringstream out; std::stringstream out;
...@@ -408,28 +392,7 @@ void AudioRecord::closeWavFile() ...@@ -408,28 +392,7 @@ void AudioRecord::closeWavFile()
WARN("AudioRecord: Error: can't close file"); WARN("AudioRecord: Error: can't close file");
} }
void AudioRecord::recSpkrData(SFLDataFormat* buffer, int nSamples) void AudioRecord::recData(SFLDataFormat* buffer, size_t nSamples)
{
if (recordingEnabled_) {
nbSamplesMic_ = nSamples;
for (int i = 0; i < nbSamplesMic_; i++)
micBuffer_[i] = buffer[i];
}
}
void AudioRecord::recMicData(SFLDataFormat* buffer, int nSamples)
{
if (recordingEnabled_) {
nbSamplesSpk_ = nSamples;
for (int i = 0; i < nbSamplesSpk_; i++)
spkBuffer_[i] = buffer[i];
}
}
void AudioRecord::recData(SFLDataFormat* buffer, int nSamples)
{ {
if (recordingEnabled_) { if (recordingEnabled_) {
if (fileHandle_ == 0) { if (fileHandle_ == 0) {
...@@ -437,34 +400,11 @@ void AudioRecord::recData(SFLDataFormat* buffer, int nSamples) ...@@ -437,34 +400,11 @@ void AudioRecord::recData(SFLDataFormat* buffer, int nSamples)
return; return;
} }
if (fwrite(buffer, sizeof(SFLDataFormat), nSamples, fileHandle_) != (unsigned int) nSamples) if (fwrite(buffer, sizeof(SFLDataFormat), nSamples, fileHandle_) != nSamples)
WARN("AudioRecord: Could not record data! "); WARN("AudioRecord: Could not record data! ");
else { else {
fflush(fileHandle_); fflush(fileHandle_);
byteCounter_ += (unsigned long)(nSamples*sizeof(SFLDataFormat)); byteCounter_ += nSamples * sizeof(SFLDataFormat);
} }
} }
} }
void AudioRecord::recData(SFLDataFormat* buffer_1, SFLDataFormat* buffer_2,
int nSamples_1, int /*nSamples_2*/)
{
if (recordingEnabled_) {
if (fileHandle_ == 0) {
DEBUG("AudioRecord: Can't record data, a file has not yet been opened!");
return;
}
for (int k = 0; k < nSamples_1; k++) {
mixBuffer_[k] = (buffer_1[k]+buffer_2[k]);
if (fwrite(&mixBuffer_[k], 2, 1, fileHandle_) != 1)
WARN("AudioRecord: Could not record data!");
else
fflush(fileHandle_);
}
byteCounter_ += (unsigned long)(nSamples_1 * sizeof(SFLDataFormat));
}
}
...@@ -90,44 +90,19 @@ class AudioRecord { ...@@ -90,44 +90,19 @@ class AudioRecord {
/** /**
* Set recording flag * Set recording flag
*/ */
bool setRecording(); void setRecording();
/** /**
* Stop recording flag * Stop recording flag
*/ */
void stopRecording(); void stopRecording();
/**
* Record a chunk of data in an internal buffer
* @param buffer The data chunk to be recorded
* @param nSamples Number of samples (number of bytes) to be recorded
*/
void recSpkrData(SFLDataFormat* buffer, int nSamples);
/**
* Record a chunk of data in an internal buffer
* @param buffer The data chunk to be recorded
* @param nSamples Number of samples (number of bytes) to be recorded
*/
void recMicData(SFLDataFormat* buffer, int nSamples);
/** /**
* Record a chunk of data in an openend file * Record a chunk of data in an openend file
* @param buffer The data chunk to be recorded * @param buffer The data chunk to be recorded
* @param nSamples Number of samples (number of bytes) to be recorded * @param nSamples Number of samples (number of bytes) to be recorded
*/ */
void recData(SFLDataFormat* buffer, int nSamples); void recData(SFLDataFormat* buffer, size_t nSamples);
/**
* Record a chunk of data in an openend file, Mix two differnet buffer
* @param buffer_1 The first data chunk to be recorded
* @param buffer_2 The second data chunk to be recorded
* @param nSamples_1 Number of samples (number of bytes) of buffer_1
* @param nSamples_2 Number of samples (number of bytes) of buffer_2
*/
void recData(SFLDataFormat* buffer_1, SFLDataFormat* buffer_2, int nSamples_1, int nSamples_2);
protected: protected:
......
...@@ -58,14 +58,13 @@ AudioRecorder::AudioRecorder(AudioRecord *arec, MainBuffer *mb) : ost::Thread() ...@@ -58,14 +58,13 @@ AudioRecorder::AudioRecorder(AudioRecord *arec, MainBuffer *mb) : ost::Thread()
*/ */
void AudioRecorder::run() void AudioRecorder::run()
{ {
int bufferLength = 10000; const size_t BUFFER_LENGTH = 10000;
SFLDataFormat buffer[bufferLength]; SFLDataFormat buffer[BUFFER_LENGTH];
while (isRunning()) { while (isRunning()) {
int availBytes = mbuffer_->availForGet(recorderId_); size_t availBytes = mbuffer_->availForGet(recorderId_);
int toGet = (availBytes < bufferLength) ? availBytes : bufferLength;
mbuffer_->getData(buffer, toGet, recorderId_); mbuffer_->getData(buffer, std::min(availBytes, BUFFER_LENGTH), recorderId_);
if (availBytes > 0) if (availBytes > 0)
arecord_->recData(buffer, availBytes / sizeof(SFLDataFormat)); arecord_->recData(buffer, availBytes / sizeof(SFLDataFormat));
......
...@@ -56,12 +56,12 @@ std::map<std::string, std::string> ConfigurationManager::getIp2IpDetails() ...@@ -56,12 +56,12 @@ std::map<std::string, std::string> ConfigurationManager::getIp2IpDetails()
SIPAccount *sipaccount = Manager::instance().getIP2IPAccount(); SIPAccount *sipaccount = Manager::instance().getIP2IPAccount();
if (!sipaccount) { if (!sipaccount) {
ERROR("ConfigurationManager: could not find account"); ERROR("ConfigurationManager: could not find IP2IP account");
return ip2ipAccountDetails; return ip2ipAccountDetails;
} else } else
return sipaccount->getIp2IpDetails(); return sipaccount->getIp2IpDetails();
std::map<std::string, std::string> tlsSettings = getTlsSettings(); std::map<std::string, std::string> tlsSettings(getTlsSettings());
std::copy(tlsSettings.begin(), tlsSettings.end(), std::copy(tlsSettings.begin(), tlsSettings.end(),
std::inserter(ip2ipAccountDetails, ip2ipAccountDetails.end())); std::inserter(ip2ipAccountDetails, ip2ipAccountDetails.end()));
...@@ -442,23 +442,19 @@ void ConfigurationManager::setShortcuts( ...@@ -442,23 +442,19 @@ void ConfigurationManager::setShortcuts(
std::vector<std::map<std::string, std::string> > ConfigurationManager::getCredentials( std::vector<std::map<std::string, std::string> > ConfigurationManager::getCredentials(
const std::string& accountID) const std::string& accountID)
{ {
Account *account = Manager::instance().getAccount(accountID); SIPAccount *account = dynamic_cast<SIPAccount*>(Manager::instance().getAccount(accountID));
std::vector<std::map<std::string, std::string> > credentialInformation; std::vector<std::map<std::string, std::string> > credentialInformation;
if (!account or account->getType() != "SIP") if (!account)
return credentialInformation; return credentialInformation;
else
SIPAccount *sipaccount = static_cast<SIPAccount *>(account); return account->getCredentials();
return sipaccount->getCredentials();
} }
void ConfigurationManager::setCredentials(const std::string& accountID, void ConfigurationManager::setCredentials(const std::string& accountID,
const std::vector<std::map<std::string, std::string> >& details) const std::vector<std::map<std::string, std::string> >& details)
{ {
Account *account = Manager::instance().getAccount(accountID); SIPAccount *account = dynamic_cast<SIPAccount*>(Manager::instance().getAccount(accountID));
if (account)
if (account and account->getType() == "SIP") { account->setCredentials(details);
SIPAccount *sipaccount = static_cast<SIPAccount*>(account);
sipaccount->setCredentials(details);
}
} }
...@@ -32,13 +32,13 @@ ...@@ -32,13 +32,13 @@
#include "../manager.h" #include "../manager.h"
#include "logger.h" #include "logger.h"
const std::string NetworkManager::statesString[5] = {"unknown", "asleep", const std::string NetworkManager::statesString[] = {"unknown", "asleep",
"connecting", "connected", "connecting", "connected",
"disconnected"}; "disconnected", "unknown",};
std::string NetworkManager::stateAsString(const uint32_t &state) std::string NetworkManager::stateAsString(const uint32_t &state)
{ {
return statesString[state]; return statesString[state < 6 ? state : 5];
} }
void NetworkManager::StateChanged(const uint32_t &state) void NetworkManager::StateChanged(const uint32_t &state)
......
...@@ -56,7 +56,7 @@ class NetworkManager : public org::freedesktop::NetworkManager_proxy, ...@@ -56,7 +56,7 @@ class NetworkManager : public org::freedesktop::NetworkManager_proxy,
NM_STATE_DISCONNECTED NM_STATE_DISCONNECTED
}; };
static const std::string statesString[5]; static const std::string statesString[];
}; };
#endif #endif
...@@ -45,7 +45,7 @@ bool check_dir(const char *path) ...@@ -45,7 +45,7 @@ bool check_dir(const char *path)
{ {
DIR *dir = opendir(path); DIR *dir = opendir(path);
if (!dir) { // doesn't exist if (!dir) { // doesn't exist
if (mkdir(path, 0755) != 0) { // couldn't create the dir if (mkdir(path, 0755) != 0) { // couldn't create the dir
perror(path); perror(path);
return false; return false;
......
...@@ -43,16 +43,9 @@ ...@@ -43,16 +43,9 @@
#include "config/yamlemitter.h" #include "config/yamlemitter.h"
IAXAccount::IAXAccount(const std::string& accountID) IAXAccount::IAXAccount(const std::string& accountID)
: Account(accountID, "iax2"), password_(), : Account(accountID, "iax2"), password_(), link_(accountID)
link_(new IAXVoIPLink(accountID))
{} {}
IAXAccount::~IAXAccount()
{
delete link_;
}
void IAXAccount::serialize(Conf::YamlEmitter &emitter) void IAXAccount::serialize(Conf::YamlEmitter &emitter)
{ {
Conf::MappingNode accountmap(NULL); Conf::MappingNode accountmap(NULL);
...@@ -142,8 +135,8 @@ std::map<std::string, std::string> IAXAccount::getAccountDetails() const ...@@ -142,8 +135,8 @@ std::map<std::string, std::string> IAXAccount::getAccountDetails() const
void IAXAccount::registerVoIPLink() void IAXAccount::registerVoIPLink()
{ {
try { try {
link_->init(); link_.init();
link_->sendRegister(this); link_.sendRegister(this);
} catch (const VoipLinkException &e) { } catch (const VoipLinkException &e) {
ERROR("IAXAccount: %s", e.what()); ERROR("IAXAccount: %s", e.what());
} }
...@@ -153,8 +146,8 @@ void ...@@ -153,8 +146,8 @@ void
IAXAccount::unregisterVoIPLink() IAXAccount::unregisterVoIPLink()
{ {
try { try {
link_->sendUnregister(this); link_.sendUnregister(this);
link_->terminate(); link_.terminate();
} catch (const VoipLinkException &e) { } catch (const VoipLinkException &e) {
ERROR("IAXAccount: %s", e.what()); ERROR("IAXAccount: %s", e.what());
} }
...@@ -171,5 +164,5 @@ IAXAccount::loadConfig() ...@@ -171,5 +164,5 @@ IAXAccount::loadConfig()
VoIPLink* IAXAccount::getVoIPLink() VoIPLink* IAXAccount::getVoIPLink()
{ {
return link_; return &link_;
} }
...@@ -32,9 +32,7 @@ ...@@ -32,9 +32,7 @@
#define IAXACCOUNT_H #define IAXACCOUNT_H
#include "account.h" #include "account.h"
#include "noncopyable.h" #include "iaxvoiplink.h"
class IAXVoIPLink;
/** /**
* @file: iaxaccount.h * @file: iaxaccount.h
...@@ -43,7 +41,6 @@ class IAXVoIPLink; ...@@ -43,7 +41,6 @@ class IAXVoIPLink;
class IAXAccount : public Account { class IAXAccount : public Account {
public: public:
IAXAccount(const std::string& accountID); IAXAccount(const std::string& accountID);
~IAXAccount();
virtual void serialize(Conf::YamlEmitter &emitter); virtual void serialize(Conf::YamlEmitter &emitter);
virtual void unserialize(const Conf::MappingNode &map); virtual void unserialize(const Conf::MappingNode &map);
...@@ -66,10 +63,9 @@ class IAXAccount : public Account { ...@@ -66,10 +63,9 @@ class IAXAccount : public Account {
} }
private: private:
NON_COPYABLE(IAXAccount);
// Account login information: password // Account login information: password
std::string password_; std::string password_;
IAXVoIPLink *link_; IAXVoIPLink link_;
virtual VoIPLink* getVoIPLink(); virtual VoIPLink* getVoIPLink();
}; };
......
...@@ -42,9 +42,8 @@ ...@@ -42,9 +42,8 @@
#include "manager.h" #include "manager.h"
#include <pwd.h> #include <pwd.h>
#include <sstream> #include <sstream>
#include <cassert>
const char * const SIPAccount::IP2IP_PROFILE = "IP2IP"; const char * const SIPAccount::IP2IP_PROFILE = "IP2IP";
const char * const SIPAccount::OVERRTP_STR = "overrtp"; const char * const SIPAccount::OVERRTP_STR = "overrtp";
const char * const SIPAccount::SIPINFO_STR = "sipinfo"; const char * const SIPAccount::SIPINFO_STR = "sipinfo";
...@@ -868,6 +867,7 @@ std::string computeMd5HashFromCredential(const std::string& username, ...@@ -868,6 +867,7 @@ std::string computeMd5HashFromCredential(const std::string& username,
MD5_APPEND(&pms, realm.data(), realm.length()); MD5_APPEND(&pms, realm.data(), realm.length());
MD5_APPEND(&pms, ":", 1); MD5_APPEND(&pms, ":", 1);
MD5_APPEND(&pms, password.data(), password.length()); MD5_APPEND(&pms, password.data(), password.length());
#undef MD5_APPEND
unsigned char digest[16]; unsigned char digest[16];
pj_md5_final(&pms, digest); pj_md5_final(&pms, digest);
...@@ -883,14 +883,18 @@ std::string computeMd5HashFromCredential(const std::string& username, ...@@ -883,14 +883,18 @@ std::string computeMd5HashFromCredential(const std::string& username,
void SIPAccount::setCredentials(const std::vector<std::map<std::string, std::string> >& creds) void SIPAccount::setCredentials(const std::vector<std::map<std::string, std::string> >& creds)
{ {
// we can not authenticate without credentials
if (creds.empty()) {
ERROR("SIPAccount: Cannot authenticate with empty credentials list");
return;
}
using std::vector; using std::vector;
using std::string; using std::string;
using std::map; using std::map;
bool md5HashingEnabled = Manager::instance().preferences.getMd5Hash(); bool md5HashingEnabled = Manager::instance().preferences.getMd5Hash();
assert(not creds.empty()); // we can not authenticate without credentials
credentials_ = creds; credentials_ = creds;
/* md5 hashing */ /* md5 hashing */
...@@ -947,7 +951,8 @@ void SIPAccount::setCredentials(const std::vector<std::map<std::string, std::str ...@@ -947,7 +951,8 @@ void SIPAccount::setCredentials(const std::vector<std::map<std::string, std::str
} }
} }
const std::vector<std::map<std::string, std::string> > &SIPAccount::getCredentials() const std::vector<std::map<std::string, std::string> > &
SIPAccount::getCredentials() const
{ {
return credentials_; return credentials_;
} }
...@@ -979,8 +984,7 @@ std::map<std::string, std::string> SIPAccount::getIp2IpDetails() const ...@@ -979,8 +984,7 @@ std::map<std::string, std::string> SIPAccount::getIp2IpDetails() const
portstr << localPort_; portstr << localPort_;
ip2ipAccountDetails[CONFIG_LOCAL_PORT] = portstr.str(); ip2ipAccountDetails[CONFIG_LOCAL_PORT] = portstr.str();
std::map<std::string, std::string> tlsSettings; std::map<std::string, std::string> tlsSettings(getTlsSettings());
tlsSettings = getTlsSettings();
std::copy(tlsSettings.begin(), tlsSettings.end(), std::inserter( std::copy(tlsSettings.begin(), tlsSettings.end(), std::inserter(
ip2ipAccountDetails, ip2ipAccountDetails.end())); ip2ipAccountDetails, ip2ipAccountDetails.end()));
...@@ -989,8 +993,8 @@ std::map<std::string, std::string> SIPAccount::getIp2IpDetails() const ...@@ -989,8 +993,8 @@ std::map<std::string, std::string> SIPAccount::getIp2IpDetails() const
std::map<std::string, std::string> SIPAccount::getTlsSettings() const std::map<std::string, std::string> SIPAccount::getTlsSettings() const
{ {
std::map<std::string, std::string> tlsSettings;
assert(isIP2IP()); assert(isIP2IP());
std::map<std::string, std::string> tlsSettings;
std::stringstream portstr; std::stringstream portstr;
portstr << tlsListenerPort_; portstr << tlsListenerPort_;
......
...@@ -205,7 +205,9 @@ class SIPAccount : public Account { ...@@ -205,7 +205,9 @@ class SIPAccount : public Account {
} }
void setCredentials(const std::vector<std::map<std::string, std::string> >& details); void setCredentials(const std::vector<std::map<std::string, std::string> >& details);
const std::vector<std::map<std::string, std::string> > &getCredentials();
const std::vector<std::map<std::string, std::string> > &