diff --git a/daemon/src/account.h b/daemon/src/account.h index c536c63ac9df63bc8c2a82b6a13fd9f57a8df7f5..6ebb7bd517e90aa91012de05a4aa5a75f4b5712e 100644 --- a/daemon/src/account.h +++ b/daemon/src/account.h @@ -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 diff --git a/daemon/src/audio/audiorecord.cpp b/daemon/src/audio/audiorecord.cpp index af1f94ef161628194cdf32758e934acf33df402f..8acdfa853fce8a11d8c025cd4619992e19284643 100644 --- a/daemon/src/audio/audiorecord.cpp +++ b/daemon/src/audio/audiorecord.cpp @@ -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)); - } -} - diff --git a/daemon/src/audio/audiorecord.h b/daemon/src/audio/audiorecord.h index 83143255b49a5c108f8f798b1f5f962a2c0b497b..47bfa28ac303771cc0d47eb73a8d2458e65d1c2e 100644 --- a/daemon/src/audio/audiorecord.h +++ b/daemon/src/audio/audiorecord.h @@ -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: diff --git a/daemon/src/audio/audiorecorder.cpp b/daemon/src/audio/audiorecorder.cpp index 669e2ed27d93c59f5d852eea58551381d3904a6e..63cac9e7e56e64a704f8a893b721703b995b665b 100644 --- a/daemon/src/audio/audiorecorder.cpp +++ b/daemon/src/audio/audiorecorder.cpp @@ -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)); diff --git a/daemon/src/dbus/configurationmanager.cpp b/daemon/src/dbus/configurationmanager.cpp index f067e5ec9317fbad9a6dad1d920fb49517522f6d..2a739e9d8ab79d2d7572fe06bc906de04c7a2589 100644 --- a/daemon/src/dbus/configurationmanager.cpp +++ b/daemon/src/dbus/configurationmanager.cpp @@ -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); } diff --git a/daemon/src/dbus/networkmanager.cpp b/daemon/src/dbus/networkmanager.cpp index 52680d4acb8b02e6b4372458d7e9e9cacc3e17ea..ed9d6f45f950588fb2c61720d5e5331ccf395712 100644 --- a/daemon/src/dbus/networkmanager.cpp +++ b/daemon/src/dbus/networkmanager.cpp @@ -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) diff --git a/daemon/src/dbus/networkmanager.h b/daemon/src/dbus/networkmanager.h index 0f005d9ef469fb2fdbd96ad3998fd86ca5781c16..69a83a104f0f1692f876b732fd510e44370a9427 100644 --- a/daemon/src/dbus/networkmanager.h +++ b/daemon/src/dbus/networkmanager.h @@ -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 diff --git a/daemon/src/fileutils.cpp b/daemon/src/fileutils.cpp index 29376115950b5a2634ca44cd285c1a8af71b40c4..7a7240abd2c8cce14e1fd14a95f15d872f11762f 100644 --- a/daemon/src/fileutils.cpp +++ b/daemon/src/fileutils.cpp @@ -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; diff --git a/daemon/src/iax/iaxaccount.cpp b/daemon/src/iax/iaxaccount.cpp index ae4affb02915b5b4ecd3b3022893e23734fd085d..5fbc1dc913942a1094af99d054b06ed2ca0a4989 100644 --- a/daemon/src/iax/iaxaccount.cpp +++ b/daemon/src/iax/iaxaccount.cpp @@ -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_; } diff --git a/daemon/src/iax/iaxaccount.h b/daemon/src/iax/iaxaccount.h index 8d2e4fd770ed31590a0fee7eca5c2ed734cdecef..35871972bb7051b5f26ebc04a99d7b99f55dce26 100644 --- a/daemon/src/iax/iaxaccount.h +++ b/daemon/src/iax/iaxaccount.h @@ -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(); }; diff --git a/daemon/src/sip/sipaccount.cpp b/daemon/src/sip/sipaccount.cpp index 33a6a6301bdd7d7fef05973ee19ffe062fd6313c..8ed341cce56429ea1f3a5a32e6cc171ee2e25249 100644 --- a/daemon/src/sip/sipaccount.cpp +++ b/daemon/src/sip/sipaccount.cpp @@ -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_; diff --git a/daemon/src/sip/sipaccount.h b/daemon/src/sip/sipaccount.h index 2e406363ae8119b08202fbc00709c226348f56f0..960b47f74fa0de0b544d370a316c055a04561521 100644 --- a/daemon/src/sip/sipaccount.h +++ b/daemon/src/sip/sipaccount.h @@ -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 diff --git a/gnome/src/accountlist.h b/gnome/src/accountlist.h index bb0aac284fd6cc0e6d09618d7531e314f611a369..59b0fb32eb780edf75cbca7e97158c8385b6674c 100644 --- a/gnome/src/accountlist.h +++ b/gnome/src/accountlist.h @@ -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_ diff --git a/gnome/src/config/accountconfigdialog.c b/gnome/src/config/accountconfigdialog.c index 437e21c1f448e5805decc7f81e6a3f0f3e285070..a23725fd35c88f4cbdf61e29d1c844f0917e5d61 100644 --- a/gnome/src/config/accountconfigdialog.c +++ b/gnome/src/config/accountconfigdialog.c @@ -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"); }