Commit 79365bd2 authored by Tristan Matthews's avatar Tristan Matthews

Merge branch 'master' into sipregistration

parents d83cb80a 279af0f7
......@@ -228,13 +228,6 @@ class Account : public Serializable {
alias_ = alias;
}
std::string getType() const {
return type_;
}
void setType(const std::string &type) {
type_ = type;
}
/**
* Accessor to data structures
* @return CodecOrder& The list that reflects the user's choice
......
......@@ -80,8 +80,8 @@ void AudioRecord::setRecordingOption(FILE_TYPE type, int sndSmplRate, const std:
std::stringstream s;
std::string filePath;
// use HOME directory if path is empty, nor does not exist
if(path.empty() || !fileutils::check_dir(path.c_str())) {
// use HOME directory if path is empty, or if path does not exist
if (path.empty() || !fileutils::check_dir(path.c_str())) {
s << getenv("HOME");
filePath = s.str();
}
......@@ -124,8 +124,6 @@ bool AudioRecord::openFile()
{
bool result = false;
DEBUG("AudioRecord: Open file()");
if (not fileExists()) {
DEBUG("AudioRecord: Filename does not exist, creating one");
byteCounter_ = 0;
......@@ -170,24 +168,14 @@ bool AudioRecord::isRecording() const
return recordingEnabled_;
}
bool AudioRecord::setRecording()
void AudioRecord::setRecording()
{
if (isOpenFile()) {
if (!recordingEnabled_) {
DEBUG("AudioRecording: Start recording");
recordingEnabled_ = true;
} else {
DEBUG("AudioRecording: Stop recording");
recordingEnabled_ = false;
}
recordingEnabled_ = !recordingEnabled_;
} else {
openFile();
recordingEnabled_ = true; // once opend file, start recording
}
// WARNING: Unused return value
return true;
}
void AudioRecord::stopRecording()
......@@ -198,12 +186,8 @@ void AudioRecord::stopRecording()
void AudioRecord::createFilename()
{
time_t rawtime;
struct tm * timeinfo;
rawtime = time(NULL);
timeinfo = localtime(&rawtime);
time_t rawtime = time(NULL);
struct tm * timeinfo = localtime(&rawtime);
std::stringstream out;
......@@ -408,28 +392,7 @@ void AudioRecord::closeWavFile()
WARN("AudioRecord: Error: can't close file");
}
void AudioRecord::recSpkrData(SFLDataFormat* buffer, int 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)
void AudioRecord::recData(SFLDataFormat* buffer, size_t nSamples)
{
if (recordingEnabled_) {
if (fileHandle_ == 0) {
......@@ -437,34 +400,11 @@ void AudioRecord::recData(SFLDataFormat* buffer, int nSamples)
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! ");
else {
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 {
/**
* Set recording flag
*/
bool setRecording();
void setRecording();
/**
* Stop recording flag
*/
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
* @param buffer The data chunk to be recorded
* @param nSamples Number of samples (number of bytes) to be recorded
*/
void recData(SFLDataFormat* buffer, int 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);
void recData(SFLDataFormat* buffer, size_t nSamples);
protected:
......
......@@ -58,14 +58,13 @@ AudioRecorder::AudioRecorder(AudioRecord *arec, MainBuffer *mb) : ost::Thread()
*/
void AudioRecorder::run()
{
int bufferLength = 10000;
SFLDataFormat buffer[bufferLength];
const size_t BUFFER_LENGTH = 10000;
SFLDataFormat buffer[BUFFER_LENGTH];
while (isRunning()) {
int availBytes = mbuffer_->availForGet(recorderId_);
int toGet = (availBytes < bufferLength) ? availBytes : bufferLength;
size_t availBytes = mbuffer_->availForGet(recorderId_);
mbuffer_->getData(buffer, toGet, recorderId_);
mbuffer_->getData(buffer, std::min(availBytes, BUFFER_LENGTH), recorderId_);
if (availBytes > 0)
arecord_->recData(buffer, availBytes / sizeof(SFLDataFormat));
......
......@@ -56,12 +56,12 @@ std::map<std::string, std::string> ConfigurationManager::getIp2IpDetails()
SIPAccount *sipaccount = Manager::instance().getIP2IPAccount();
if (!sipaccount) {
ERROR("ConfigurationManager: could not find account");
ERROR("ConfigurationManager: could not find IP2IP account");
return ip2ipAccountDetails;
} else
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::inserter(ip2ipAccountDetails, ip2ipAccountDetails.end()));
......@@ -442,23 +442,19 @@ void ConfigurationManager::setShortcuts(
std::vector<std::map<std::string, std::string> > ConfigurationManager::getCredentials(
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;
if (!account or account->getType() != "SIP")
if (!account)
return credentialInformation;
SIPAccount *sipaccount = static_cast<SIPAccount *>(account);
return sipaccount->getCredentials();
else
return account->getCredentials();
}
void ConfigurationManager::setCredentials(const std::string& accountID,
const std::vector<std::map<std::string, std::string> >& details)
{
Account *account = Manager::instance().getAccount(accountID);
if (account and account->getType() == "SIP") {
SIPAccount *sipaccount = static_cast<SIPAccount*>(account);
sipaccount->setCredentials(details);
}
SIPAccount *account = dynamic_cast<SIPAccount*>(Manager::instance().getAccount(accountID));
if (account)
account->setCredentials(details);
}
......@@ -32,13 +32,13 @@
#include "../manager.h"
#include "logger.h"
const std::string NetworkManager::statesString[5] = {"unknown", "asleep",
"connecting", "connected",
"disconnected"};
const std::string NetworkManager::statesString[] = {"unknown", "asleep",
"connecting", "connected",
"disconnected", "unknown",};
std::string NetworkManager::stateAsString(const uint32_t &state)
{
return statesString[state];
return statesString[state < 6 ? state : 5];
}
void NetworkManager::StateChanged(const uint32_t &state)
......
......@@ -56,7 +56,7 @@ class NetworkManager : public org::freedesktop::NetworkManager_proxy,
NM_STATE_DISCONNECTED
};
static const std::string statesString[5];
static const std::string statesString[];
};
#endif
......@@ -45,7 +45,7 @@ bool check_dir(const char *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
perror(path);
return false;
......
......@@ -43,16 +43,9 @@
#include "config/yamlemitter.h"
IAXAccount::IAXAccount(const std::string& accountID)
: Account(accountID, "iax2"), password_(),
link_(new IAXVoIPLink(accountID))
: Account(accountID, "iax2"), password_(), link_(accountID)
{}
IAXAccount::~IAXAccount()
{
delete link_;
}
void IAXAccount::serialize(Conf::YamlEmitter &emitter)
{
Conf::MappingNode accountmap(NULL);
......@@ -142,8 +135,8 @@ std::map<std::string, std::string> IAXAccount::getAccountDetails() const
void IAXAccount::registerVoIPLink()
{
try {
link_->init();
link_->sendRegister(this);
link_.init();
link_.sendRegister(this);
} catch (const VoipLinkException &e) {
ERROR("IAXAccount: %s", e.what());
}
......@@ -153,8 +146,8 @@ void
IAXAccount::unregisterVoIPLink()
{
try {
link_->sendUnregister(this);
link_->terminate();
link_.sendUnregister(this);
link_.terminate();
} catch (const VoipLinkException &e) {
ERROR("IAXAccount: %s", e.what());
}
......@@ -171,5 +164,5 @@ IAXAccount::loadConfig()
VoIPLink* IAXAccount::getVoIPLink()
{
return link_;
return &link_;
}
......@@ -32,9 +32,7 @@
#define IAXACCOUNT_H
#include "account.h"
#include "noncopyable.h"
class IAXVoIPLink;
#include "iaxvoiplink.h"
/**
* @file: iaxaccount.h
......@@ -43,7 +41,6 @@ class IAXVoIPLink;
class IAXAccount : public Account {
public:
IAXAccount(const std::string& accountID);
~IAXAccount();
virtual void serialize(Conf::YamlEmitter &emitter);
virtual void unserialize(const Conf::MappingNode &map);
......@@ -66,10 +63,9 @@ class IAXAccount : public Account {
}
private:
NON_COPYABLE(IAXAccount);
// Account login information: password
std::string password_;
IAXVoIPLink *link_;
IAXVoIPLink link_;
virtual VoIPLink* getVoIPLink();
};
......
......@@ -42,9 +42,8 @@
#include "manager.h"
#include <pwd.h>
#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::SIPINFO_STR = "sipinfo";
......@@ -867,6 +866,7 @@ std::string computeMd5HashFromCredential(const std::string& username,
MD5_APPEND(&pms, realm.data(), realm.length());
MD5_APPEND(&pms, ":", 1);
MD5_APPEND(&pms, password.data(), password.length());
#undef MD5_APPEND
unsigned char digest[16];
pj_md5_final(&pms, digest);
......@@ -882,14 +882,18 @@ std::string computeMd5HashFromCredential(const std::string& username,
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::string;
using std::map;
bool md5HashingEnabled = Manager::instance().preferences.getMd5Hash();
assert(not creds.empty()); // we can not authenticate without credentials
credentials_ = creds;
/* md5 hashing */
......@@ -946,7 +950,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_;
}
......@@ -978,8 +983,7 @@ std::map<std::string, std::string> SIPAccount::getIp2IpDetails() const
portstr << localPort_;
ip2ipAccountDetails[CONFIG_LOCAL_PORT] = portstr.str();
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()));
......@@ -988,8 +992,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> tlsSettings;
assert(isIP2IP());
std::map<std::string, std::string> tlsSettings;
std::stringstream portstr;
portstr << tlsListenerPort_;
......
......@@ -205,7 +205,9 @@ class SIPAccount : public Account {
}
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> > &
getCredentials() const;
/**
* A client sendings a REGISTER request MAY suggest an expiration
......
......@@ -29,8 +29,8 @@
* as that of the covered work.
*/
#ifndef ACCOUNTLIST_H__
#define ACCOUNTLIST_H__
#ifndef ACCOUNTLIST_H_
#define ACCOUNTLIST_H_
#include <gtk/gtk.h>
/** @file accountlist.h
......@@ -91,20 +91,20 @@ typedef struct {
/**
* This function initialize the account list.
*/
void account_list_init ();
void account_list_init();
/**
* This function append an account to list.
* @param a The account you want to add
*/
void account_list_add (account_t * a);
void account_list_add(account_t * a);
/**
* Return the first account that corresponds to the state
* @param state The state
* @return account_t* An account or NULL
*/
account_t * account_list_get_by_state (account_state_t state);
account_t * account_list_get_by_state(account_state_t state);
/**
* @return guint The number of registered accounts in the list
......@@ -115,14 +115,14 @@ guint account_list_get_registered_accounts();
* Return the number of accounts in the list
* @return guint The number of accounts in the list
*/
guint account_list_get_size ();
guint account_list_get_size();
/**
* Return the account at the nth position in the list
* @param n The position of the account you want
* @return An account or NULL
*/
account_t * account_list_get_nth (guint n);
account_t * account_list_get_nth(guint n);
/**
* Return the current account struct
......@@ -134,54 +134,54 @@ account_t * account_list_get_current();
* This function sets an account as the current one
* @param current the account you want to set as current
*/
void account_list_set_current (account_t *current);
void account_list_set_current(account_t *current);
/**
* This function maps account_state_t enums to a description.
* @param s The state
* @return The full text description of the state
*/
const gchar * account_state_name (account_state_t s);
const gchar * account_state_name(account_state_t s);
/**
* This function frees the list
*/
void account_list_free ();
void account_list_free();
/**
* Return the account associated with an ID
* @param accountID The ID of the account
* @return An account or NULL
*/
account_t * account_list_get_by_id (const gchar * const accountID);
account_t * account_list_get_by_id(const gchar * const accountID);
/**
* Move the account from an unit up in the account_list
* @param index The current index in the list
*/
void account_list_move_up (guint index);
void account_list_move_up(guint index);
/**
* Move the account from an unit down in the account_list
* @param index The current index in the list
*/
void account_list_move_down (guint index);
void account_list_move_down(guint index);
/**
* Return the ID of the current default account
* @return gchar* The id
*/
const gchar* account_list_get_current_id (void);
const gchar* account_list_get_current_id(void);
gchar * account_list_get_ordered_list (void);
gchar * account_list_get_ordered_list(void);
gboolean current_account_has_mailbox (void);
gboolean current_account_has_mailbox(void);
guint current_account_get_message_number (void);
guint current_account_get_message_number(void);
void current_account_set_message_number (guint nb);
void current_account_set_message_number(guint nb);
gboolean current_account_has_new_message (void);
gboolean current_account_has_new_message(void);
gboolean account_is_IP2IP(const account_t *account);
gboolean account_is_SIP(const account_t *account);
......@@ -197,4 +197,4 @@ void account_insert(account_t *account, const gchar *key, const gchar *value);
gpointer account_lookup(const account_t *account, gconstpointer key);
void account_list_remove(const gchar *accountID);
#endif
#endif // ACCOUNTLIST_H_
......@@ -596,6 +596,10 @@ static void set_published_addr_manually_cb(GtkWidget * widget, gpointer data UNU
static void use_stun_cb(GtkWidget *widget, gpointer data UNUSED)
{
/* Widgets have not been created yet */
if (!stun_server_label)
return;
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
DEBUG("Config: Showing stun options, hiding Local/Published info");
gtk_widget_show(stun_server_label);
......@@ -621,8 +625,6 @@ static void use_stun_cb(GtkWidget *widget, gpointer data UNUSED)
gtk_widget_show(published_port_spin_box);
}
}
DEBUG("DONE");
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment