Skip to content
Snippets Groups Projects
Commit 8a73d38d authored by pierre-luc's avatar pierre-luc
Browse files

[#2027] Fix segmentation fault when showMessage callback is called after

an error occured with libzrtpcpp. Also, exceptions in AudioRtpFactory are
now derived from some more specialized types.
parent 41c7a67e
No related branches found
No related tags found
No related merge requests found
...@@ -754,6 +754,7 @@ show_account_window (account_t * a) ...@@ -754,6 +754,7 @@ show_account_window (account_t * a)
gchar* keyExchange = (gchar *)gtk_combo_box_get_active_text(GTK_COMBO_BOX(keyExchangeCombo)); gchar* keyExchange = (gchar *)gtk_combo_box_get_active_text(GTK_COMBO_BOX(keyExchangeCombo));
if (g_strcasecmp(keyExchange, "ZRTP") == 0) { if (g_strcasecmp(keyExchange, "ZRTP") == 0) {
g_hash_table_replace(currentAccount->properties, g_strdup(ACCOUNT_SRTP_ENABLED), g_strdup("TRUE")); g_hash_table_replace(currentAccount->properties, g_strdup(ACCOUNT_SRTP_ENABLED), g_strdup("TRUE"));
g_hash_table_replace(currentAccount->properties, g_strdup(ACCOUNT_KEY_EXCHANGE), g_strdup("1"));
} else { } else {
g_hash_table_replace(currentAccount->properties, g_strdup(ACCOUNT_SRTP_ENABLED), g_strdup("FALSE")); g_hash_table_replace(currentAccount->properties, g_strdup(ACCOUNT_SRTP_ENABLED), g_strdup("FALSE"));
} }
......
...@@ -58,8 +58,8 @@ namespace sfl { ...@@ -58,8 +58,8 @@ namespace sfl {
assert(ca); assert(ca);
if (_rtpSession != NULL) { if (_rtpSession != NULL) {
_debugException("An audio rtp thread was already created but not \ _debugException("An audio rtp thread was already created but not" \
destroyed. Forcing it before continuing.\n"); "destroyed. Forcing it before continuing.\n");
stop(); stop();
} }
...@@ -113,27 +113,23 @@ namespace sfl { ...@@ -113,27 +113,23 @@ namespace sfl {
void AudioRtpFactory::start(void) void AudioRtpFactory::start(void)
{ {
if (_rtpSession == NULL) { if (_rtpSession == NULL) {
throw AudioRtpFactoryException(); throw AudioRtpFactoryException("_rtpSession was null when trying to start audio thread");
} }
try {
switch(_rtpSessionType) { switch(_rtpSessionType) {
case Sdes: case Sdes:
case Symmetric: case Symmetric:
_debug("Starting symmetric rtp thread\n"); _debug("Starting symmetric rtp thread\n");
if(static_cast<AudioSymmetricRtpSession *>(_rtpSession)->startRtpThread() != 0) { if(static_cast<AudioSymmetricRtpSession *>(_rtpSession)->startRtpThread() != 0) {
throw AudioRtpFactoryException(); throw AudioRtpFactoryException("Failed to start AudioSymmetricRtpSession thread");
} }
break; break;
case Zrtp: case Zrtp:
if(static_cast<AudioZrtpSession *>(_rtpSession)->startRtpThread() != 0) { if(static_cast<AudioZrtpSession *>(_rtpSession)->startRtpThread() != 0) {
throw AudioRtpFactoryException(); throw AudioRtpFactoryException("Failed to start AudioZrtpSession thread");
} }
break; break;
} }
} catch (...) {
throw AudioRtpFactoryException();
}
} }
void AudioRtpFactory::stop(void) void AudioRtpFactory::stop(void)
...@@ -141,8 +137,7 @@ namespace sfl { ...@@ -141,8 +137,7 @@ namespace sfl {
ost::MutexLock mutex(_audioRtpThreadMutex); ost::MutexLock mutex(_audioRtpThreadMutex);
_debug("Stopping audio rtp session\n"); _debug("Stopping audio rtp session\n");
if (_rtpSession == NULL) { if (_rtpSession == NULL) {
_debugException("_rtpSession is null\n"); throw AudioRtpFactoryException("_rtpSession is null when trying to stop");
throw AudioRtpFactoryException();
} }
try { try {
switch(_rtpSessionType) { switch(_rtpSessionType) {
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#ifndef __SFL_AUDIO_RTP_FACTORY_H__ #ifndef __SFL_AUDIO_RTP_FACTORY_H__
#define __SFL_AUDIO_RTP_FACTORY_H__ #define __SFL_AUDIO_RTP_FACTORY_H__
#include <exception> #include <stdexcept>
#include <cc++/thread.h> #include <cc++/thread.h>
class SIPCall; class SIPCall;
...@@ -38,20 +38,15 @@ namespace sfl { ...@@ -38,20 +38,15 @@ namespace sfl {
Sdes Sdes
} RtpMethod; } RtpMethod;
class UnsupportedRtpSessionType: public std::exception
{ class UnsupportedRtpSessionType : public std::logic_error {
virtual const char* what() const throw() public:
{ UnsupportedRtpSessionType(const std::string& msg = "") : std::logic_error(msg) {}
return "Could not create RTP session of the given type";
}
}; };
class AudioRtpFactoryException: public std::exception class AudioRtpFactoryException : public std::logic_error {
{ public:
virtual const char* what() const throw() AudioRtpFactoryException(const std::string& msg = "") : std::logic_error(msg) {}
{
return "An AudioRtpFactoryException occured";
}
}; };
class AudioRtpFactory { class AudioRtpFactory {
......
...@@ -143,29 +143,30 @@ namespace sfl { ...@@ -143,29 +143,30 @@ namespace sfl {
if (sev == Info) { if (sev == Info) {
msg = _infoMap[subCode]; msg = _infoMap[subCode];
if (msg != NULL) { if (msg != NULL) {
_debug("ZRTP Debug: %s\n", msg->c_str()); _debug("ZRTP Debug:\n", msg->c_str());
} }
} }
if (sev == Warning) { if (sev == Warning) {
msg = _warningMap[subCode]; msg = _warningMap[subCode];
if (msg != NULL) { if (msg != NULL) {
_debug("ZRTP Debug: %s\n", msg->c_str()); _debug("ZRTP Debug:\n", msg->c_str());
} }
} }
if (sev == Severe) { if (sev == Severe) {
msg = _severeMap[subCode]; msg = _severeMap[subCode];
if (msg != NULL) { if (msg != NULL) {
_debug("ZRTP Debug: %s\n", msg->c_str()); _debug("ZRTP Debug:\n", msg->c_str());
} }
} }
if (sev == ZrtpError) { if (sev == ZrtpError) {
if (subCode < 0) { // received an error packet from peer if (subCode < 0) { // received an error packet from peer
subCode *= -1; subCode *= -1;
_debug("Received an error packet from peer: %s\n", msg->c_str()); _debug("Received an error packet from peer:\n");
} }
else { else {
_debug("Sent error packet to peer: %s\n", msg->c_str()); _debug("Sent error packet to peer:\n");
} }
msg = _zrtpMap[subCode]; msg = _zrtpMap[subCode];
if (msg != NULL) { if (msg != NULL) {
_debug("ZRTP Debug: %s\n", msg->c_str()); _debug("ZRTP Debug: %s\n", msg->c_str());
...@@ -180,10 +181,10 @@ namespace sfl { ...@@ -180,10 +181,10 @@ namespace sfl {
if (severity == ZrtpError) { if (severity == ZrtpError) {
if (subCode < 0) { // received an error packet from peer if (subCode < 0) { // received an error packet from peer
subCode *= -1; subCode *= -1;
_debug("Received error packet: "); _debug("Received error packet: \n");
} }
else { else {
_debug("Sent error packet: "); _debug("Sent error packet: \n");
} }
msg = _zrtpMap[subCode]; msg = _zrtpMap[subCode];
if (msg != NULL) { if (msg != NULL) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment