Commit c39f2734 authored by Emmanuel Milou's avatar Emmanuel Milou

Error handling for accounts registration

Adding error state
Global variables on the client side moved in sflphone_const.h
parent 48e795d3
......@@ -2,8 +2,9 @@ bin_PROGRAMS = sflphone-gtk
sflphone_gtk_SOURCES = \
main.c \
errors.c \
dbus.c \
SFLnotify.c \
sflnotify.c \
mainwindow.c \
calllist.c \
dialpad.c \
......@@ -21,8 +22,8 @@ sflphone_gtk_SOURCES = \
glwidget.c \
MemManager.c
noinst_HEADERS = actions.h dbus.h SFLnotify.h mainwindow.h calllist.h dialpad.h codeclist.h\
callmanager-glue.h configurationmanager-glue.h instance-glue.h menus.h calltree.h screen.h configwindow.h \
noinst_HEADERS = actions.h dbus.h sflnotify.h mainwindow.h calllist.h dialpad.h codeclist.h\
callmanager-glue.h errors.h sflphone_const.h configurationmanager-glue.h instance-glue.h menus.h calltree.h screen.h configwindow.h \
accountlist.h accountwindow.h marshaller.h sliders.h statusicon.h
EXTRA_DIST = marshaller.list
sflphone_gtk_LDADD = $(DEPS_LIBS) -lnotify
......
......@@ -164,6 +164,9 @@ const gchar * account_state_name(account_state_t s)
case ACCOUNT_STATE_ERROR:
state = _("Error");
break;
case ACCOUNT_STATE_ERROR_AUTH:
state = _("Bad authentification");
break;
default:
state = _("Invalid");
break;
......
......@@ -26,25 +26,6 @@
* @brief A list to hold accounts.
*/
#define ACCOUNT_TYPE "Account.type"
#define ACCOUNT_ALIAS "Account.alias"
#define ACCOUNT_ENABLED "Account.enable"
//#define ACCOUNT_REGISTER "Account.autoregister"
#define ACCOUNT_SIP_FULL_NAME "SIP.fullName"
#define ACCOUNT_SIP_HOST_PART "SIP.hostPart"
#define ACCOUNT_SIP_USER_PART "SIP.userPart"
#define ACCOUNT_SIP_AUTH_NAME "SIP.username"
#define ACCOUNT_SIP_PASSWORD "SIP.password"
#define ACCOUNT_SIP_PROXY "SIP.proxy"
#define ACCOUNT_SIP_STUN_SERVER "STUN.server"
#define ACCOUNT_SIP_STUN_ENABLED "STUN.enable"
#define ACCOUNT_IAX_FULL_NAME "IAX.fullName"
#define ACCOUNT_IAX_HOST "IAX.host"
#define ACCOUNT_IAX_USER "IAX.user"
#define ACCOUNT_IAX_PASS "IAX.pass"
/** @enum account_state_t
* This enum have all the states an account can take.
*/
......@@ -54,7 +35,8 @@ typedef enum
ACCOUNT_STATE_REGISTERED,
ACCOUNT_STATE_UNREGISTERED,
ACCOUNT_STATE_TRYING,
ACCOUNT_STATE_ERROR
ACCOUNT_STATE_ERROR,
ACCOUNT_STATE_ERROR_AUTH
} account_state_t;
/** @struct account_t
......
......@@ -33,12 +33,6 @@
#include <sys/types.h>
#include <unistd.h>
#define ALSA_ERROR_CAPTURE_DEVICE 0
#define ALSA_ERROR_PLAYBACK_DEVICE 1
#define TONE_WITHOUT_MESSAGE 0
#define TONE_WITH_MESSAGE 1
guint voice_mails;
void
......@@ -53,7 +47,7 @@ sflphone_notify_voice_mail ( const gchar* accountID , guint count )
g_sprintf(message, _("%d voice mails"), count);
else
g_sprintf(message, _("%d voice mail"), count);
status_bar_message_add(message, __MSG_VOICE_MAILS);
statusbar_push_message(message, __MSG_VOICE_MAILS);
g_free(message);
}
// TODO: add ifdef
......@@ -75,7 +69,7 @@ status_bar_display_account( call_t* c)
msg = g_markup_printf_escaped("%s account- %s" ,
(gchar*)g_hash_table_lookup( acc->properties , ACCOUNT_TYPE),
(gchar*)g_hash_table_lookup( acc->properties , ACCOUNT_ALIAS));
status_bar_message_add( msg , __MSG_ACCOUNT_DEFAULT);
statusbar_push_message( msg , __MSG_ACCOUNT_DEFAULT);
g_free(msg);
}
}
......@@ -169,6 +163,10 @@ sflphone_fill_account_list()
{
a->state = ACCOUNT_STATE_ERROR;
}
else if(strcmp( status , "ERROR_AUTH") == 0 )
{
a->state = ACCOUNT_STATE_ERROR_AUTH;
}
else
{
a->state = ACCOUNT_STATE_INVALID;
......@@ -624,22 +622,6 @@ sflphone_set_current_account()
account_list_set_current_pos( 0 );
}
void
sflphone_throw_exception( int errCode )
{
gchar* markup = malloc(1000);
switch( errCode ){
case ALSA_ERROR_PLAYBACK_DEVICE:
sprintf( markup , _("<b>ALSA notification</b>\n\nError while opening playback device"));
break;
case ALSA_ERROR_CAPTURE_DEVICE:
sprintf( markup , _("<b>ALSA notification</b>\n\nError while opening capture device"));
break;
}
main_window_error_message( markup );
free( markup );
}
/* Internal to action - get the codec list */
void
......
......@@ -21,20 +21,14 @@
#ifndef __ACTIONS_H__
#define __ACTIONS_H__
#define _(STRING) gettext( STRING )
#include <libintl.h>
#include <locale.h>
#include <calllist.h>
#include <accountlist.h>
#include <codeclist.h>
#define __MSG_INCOMING_CALL 0
#define __MSG_CALLING 1
#define __MSG_VOICE_MAILS 2
#define __MSG_ACCOUNT_DEFAULT 3
#include <sflphone_const.h>
#include <errors.h>
/** @file actions.h
* @brief General functions that change the state of the application.
......@@ -117,6 +111,5 @@ void sflphone_place_call ( call_t * c );
void sflphone_fill_account_list();
void sflphone_set_current_account();
void sflphone_throw_exception( int errCode );
void sflphone_fill_codec_list();
#endif
......@@ -60,6 +60,8 @@ GtkWidget *pluginComboBox;
GtkWidget *codecMoveUpButton;
GtkWidget *codecMoveDownButton;
GtkWidget* status;
account_t *selectedAccount;
// Account properties
......@@ -1362,7 +1364,8 @@ show_accounts_window( void )
gtk_box_pack_start( GTK_BOX( dialog->vbox ), accountFrame , TRUE, TRUE, 0);
gtk_container_set_border_width(GTK_CONTAINER(accountFrame), 10);
gtk_widget_show(accountFrame);
// Accounts tab
// Accounts tab
tab = create_accounts_tab();
gtk_container_add(GTK_CONTAINER(accountFrame) , tab);
......@@ -1371,3 +1374,4 @@ show_accounts_window( void )
dialogOpen=FALSE;
gtk_widget_destroy(GTK_WIDGET(dialog));
}
......@@ -367,8 +367,6 @@ dbus_accept (const call_t * c)
void
dbus_refuse (const call_t * c)
{
// Remove the account message from the status bar stack
status_bar_message_remove( __MSG_ACCOUNT_DEFAULT );
status_tray_icon_blink( FALSE );
GError *error = NULL;
org_sflphone_SFLphone_CallManager_refuse ( callManagerProxy, c->callID, &error);
......
......@@ -25,7 +25,7 @@
#include <accountlist.h>
#include <calllist.h>
#include <SFLnotify.h>
#include <sflnotify.h>
/** @file dbus.h
* @brief General DBus functions wrappers.
......
/*
* Copyright (C) 2008 Savoir-Faire Linux inc.
* Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <errors.h>
void
sflphone_throw_exception( int err )
{
gchar* markup;
switch( err ){
case ALSA_PLAYBACK_DEVICE:
markup = g_markup_printf_escaped(_("<b>ALSA notification</b>\n\nError while opening playback device"));
break;
case ALSA_CAPTURE_DEVICE:
markup = g_markup_printf_escaped(_("<b>ALSA notification</b>\n\nError while opening capture device"));
break;
case REGISTRATION_FORBIDDEN:
markup = g_markup_printf_escaped(_("<b>Account Registration</b>\n\nBad authentification"));
break;
case REGISTRATION_UNAUTHORIZED:
markup = g_markup_printf_escaped(_("<b>Account Registration</b>\n\nBad authentification"));
break;
}
main_window_error_message( markup );
free( markup );
}
/*
* Copyright (C) 2008 Savoir-Faire Linux inc.
* Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __ERRORS_H
#define __ERRORS_H
#include <sflphone_const.h>
void sflphone_throw_exception( int err );
#endif
......@@ -246,13 +246,13 @@ main_window_dialpad(gboolean show){
}
void
status_bar_message_add(const gchar * message, guint id)
statusbar_push_message(const gchar * message, guint id)
{
gtk_statusbar_push(GTK_STATUSBAR(statusBar), id, message);
}
void
status_bar_message_remove(guint id)
statusbar_pop_message(guint id)
{
gtk_statusbar_pop(GTK_STATUSBAR(statusBar), id);
}
......
......@@ -43,7 +43,7 @@ void main_window_warning_message(gchar * markup);
void main_window_info_message(gchar * markup);
void status_bar_message_add(const gchar * message , guint id);
void status_bar_message_remove(guint id);
void statusbar_push_message( const gchar* message , guint id );
void statusbar_pop_message( guint id );
#endif
/*
* Copyright (C) 2008 Savoir-Faire Linux inc.
* Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __SFLPHONE_CONST_H
#define __SFLPHONE_CONST_H
#include <libintl.h>
#include "dbus.h"
// Locale
#define _(STRING) gettext( STRING )
// Generic parameters for accounts registration
#define ACCOUNT_TYPE "Account.type"
#define ACCOUNT_ALIAS "Account.alias"
#define ACCOUNT_ENABLED "Account.enable"
// SIP specific parameters
#define ACCOUNT_SIP_FULL_NAME "SIP.fullName"
#define ACCOUNT_SIP_HOST_PART "SIP.hostPart"
#define ACCOUNT_SIP_USER_PART "SIP.userPart"
#define ACCOUNT_SIP_AUTH_NAME "SIP.username"
#define ACCOUNT_SIP_PASSWORD "SIP.password"
#define ACCOUNT_SIP_PROXY "SIP.proxy"
#define ACCOUNT_SIP_STUN_SERVER "STUN.server"
#define ACCOUNT_SIP_STUN_ENABLED "STUN.enable"
// IAX2 specific parameters
#define ACCOUNT_IAX_FULL_NAME "IAX.fullName"
#define ACCOUNT_IAX_HOST "IAX.host"
#define ACCOUNT_IAX_USER "IAX.user"
#define ACCOUNT_IAX_PASS "IAX.pass"
// Error codes for error handling
#define ALSA_CAPTURE_DEVICE 0x0001
#define ALSA_PLAYBACK_DEVICE 0x0010
#define REGISTRATION_FORBIDDEN 0x0011
#define REGISTRATION_UNAUTHORIZED 0x0100
#define REGISTRATION_UNREACHABLE 0x0101
#define NETWORK_UNREACHABLE 0x0110
// Customizing-related parameters
#define TONE_WITHOUT_MESSAGE 0
#define TONE_WITH_MESSAGE 1
#define MINIMIZED TRUE
#define __POPUP_WINDOW ( dbus_popup_mode() )
// Messages ID for status bar
#define __MSG_INCOMING_CALL 0
#define __MSG_CALLING 1
#define __MSG_VOICE_MAILS 2
#define __MSG_ACCOUNT_DEFAULT 3
// Desktop notifications
#define __TIMEOUT_MODE "default"
#define __TIMEOUT_TIME 30000 // 30 secondes
#endif
......@@ -20,9 +20,9 @@
#ifndef __STATUSICON_H__
#define __STATUSICON_H__
#define MINIMIZED TRUE
#include <gtk/gtk.h>
#include <sflphone_const.h>
/** @file statusicon.h
* @brief The status icon.
*/
......
......@@ -313,7 +313,7 @@ AudioLayer::open_device(std::string pcm_p, std::string pcm_c, int flag)
_debugAlsa("Opening capture device %s\n", pcm_c.c_str());
if(err = snd_pcm_open(&_CaptureHandle, pcm_c.c_str(), SND_PCM_STREAM_CAPTURE, 0) < 0){
_debugAlsa("Error while opening capture device %s\n", pcm_c.c_str());
setErrorMessage( ERROR_ALSA_CAPTURE_DEVICE );
setErrorMessage( ALSA_CAPTURE_DEVICE );
return false;
}
......@@ -343,7 +343,7 @@ AudioLayer::open_device(std::string pcm_p, std::string pcm_c, int flag)
_debugAlsa(" Opening playback device %s\n", pcm_p.c_str());
if(err = snd_pcm_open(&_PlaybackHandle, pcm_p.c_str(), SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK ) < 0){
_debugAlsa("Error while opening playback device %s\n", pcm_c.c_str());
setErrorMessage( ERROR_ALSA_PLAYBACK_DEVICE );
setErrorMessage( ALSA_PLAYBACK_DEVICE );
return false;
}
if( err = snd_pcm_hw_params_malloc( &hwParams ) < 0 ) {
......
......@@ -113,10 +113,13 @@ typedef short int16;
#define START_HIDDEN 1
#define WINDOW_POPUP 1
#define ERROR_ALSA_CAPTURE_DEVICE 0
#define ERROR_ALSA_PLAYBACK_DEVICE 1
//#define ERROR_ALSA_OPENING_CAPTURE_DEVICE 0
//#define ERROR_ALSA_OPENING_CAPTURE_DEVICE 0
//#define ERROR_ALSA_OPENING_CAPTURE_DEVICE 0
// Error codes for error handling
#define NO_ERROR 0x0000
#define ALSA_CAPTURE_DEVICE 0x0001
#define ALSA_PLAYBACK_DEVICE 0x0010
#define REGISTRATION_FORBIDDEN 0x0011
#define REGISTRATION_UNAUTHORIZED 0x0100
#define REGISTRATION_UNREACHABLE 0x0101
#define NETWORK_UNREACHABLE 0x0110
#endif // __GLOBAL_H__
......@@ -833,7 +833,7 @@ IAXVoIPLink::iaxHandleRegReply(iax_event* event)
_mutexIAX.leaveMutex();
_regSession = NULL;
setRegistrationState(Error, "Registration failed");
setRegistrationState(Error, REGISTRATION_FORBIDDEN);
//Manager::instance().registrationFailed(getAccountID());
}
......
......@@ -1966,9 +1966,10 @@ ManagerImpl::getAccountDetails(const AccountID& accountID)
std::pair<std::string, std::string>(
"Status",
(state == VoIPLink::Registered ? "REGISTERED":
(state == VoIPLink::Unregistered ? "UNREGISTERED":
(state == VoIPLink::Trying ? "TRYING":
(state == VoIPLink::Error ? "ERROR": "ERROR"))))
(state == VoIPLink::Unregistered ? "UNREGISTERED":
(state == VoIPLink::Trying ? "TRYING":
(state == VoIPLink::ErrorAuth ? "ERROR_AUTH":
(state == VoIPLink::Error ? "ERROR": "ERROR")))))
)
);
a.insert(
......
......@@ -213,7 +213,7 @@ SIPVoIPLink::loadSIPLocalIP()
void
SIPVoIPLink::parseRequestUri( osip_uri_t* req )
{
_debug("%d\n",req->url_header);
// _debug("%d\n",req->url_header);
}
void
......@@ -229,10 +229,7 @@ SIPVoIPLink::getEvent()
return;
}
parseRequestUri( event->request->req_uri);
//if(event->request->line != 0)
_debug("%s\n\n" , event->request->req_uri);
_debug("> SIP Event: [cdt=%4d:%4d:%4d] type=#%03d %s \n", event->cid, event->did, event->tid, event->type, event->textinfo);
switch (event->type) {
/* REGISTER related events */
case EXOSIP_REGISTRATION_NEW: /** 00 < announce new registration. */
......@@ -251,14 +248,15 @@ SIPVoIPLink::getEvent()
}
break;
case EXOSIP_REGISTRATION_FAILURE: /** 02 < user is not registred. */
setRegistrationState(Error, "SIP registration failure.");
SIPRegistrationFailure( event );
_debugMid(" !EXOSIP_REGISTRATION_FAILURE\n");
break;
case EXOSIP_REGISTRATION_REFRESHED: /** 03 < registration has been refreshed. */
_debugMid(" !EXOSIP_REGISTRATION_REFRESHED event is not implemented\n");
break;
case EXOSIP_REGISTRATION_TERMINATED: /** 04 < UA is not registred any more. */
setRegistrationState(Unregistered, "Registration terminated by remote host");
//setRegistrationState(Unregistered, "Registration terminated by remote host");
setRegistrationState(Unregistered);
_debugMid(" !EXOSIP_REGISTRATION_TERMINATED event is not implemented\n");
break;
......@@ -1459,6 +1457,24 @@ SIPVoIPLink::SIPCallServerFailure(eXosip_event_t *event)
}
}
void
SIPVoIPLink::SIPRegistrationFailure( eXosip_event_t* event )
{
if(!event->response) {return ;}
switch( event->response->status_code ) {
case SIP_FORBIDDEN:
_debug("SIP forbidden\n");
setRegistrationState(ErrorAuth, REGISTRATION_FORBIDDEN);
break;
case SIP_UNAUTHORIZED:
_debug("SIP unauthorized\n");
setRegistrationState(Error);
break;
default:
_debug("Unknown error: %s\n" , event->response->status_code);
}
}
void
SIPVoIPLink::SIPCallAck(eXosip_event_t *event)
{
......
......@@ -189,6 +189,7 @@ private:
*/
void SIPCallServerFailure(eXosip_event_t *event);
void SIPRegistrationFailure( eXosip_event_t *event );
/**
* Handling ack (restart audio if reinvite)
* @param event eXosip Event
......
......@@ -25,7 +25,7 @@
#include "voiplink.h"
#include "manager.h"
VoIPLink::VoIPLink(const AccountID& accountID) : _accountID(accountID), _localIPAddress("127.0.0.1"), _localPort(0), _registrationError(""), _initDone(false)
VoIPLink::VoIPLink(const AccountID& accountID) : _accountID(accountID), _localIPAddress("127.0.0.1"), _localPort(0), _registrationError(NO_ERROR), _initDone(false)
{
}
......@@ -82,13 +82,12 @@ VoIPLink::clearCallMap()
}
void
VoIPLink::setRegistrationState(const enum RegistrationState state, const std::string& errorMessage)
VoIPLink::setRegistrationState(const enum RegistrationState state, const int& errorCode)
{
_registrationState = state;
_registrationError = errorMessage;
_registrationError = errorCode;
std::string acc_ID = getAccountID();
_debug("Set registration state for account %s\n" , acc_ID.c_str());
/** Push to the GUI when state changes */
switch (state) {
......@@ -99,6 +98,12 @@ VoIPLink::setRegistrationState(const enum RegistrationState state, const std::st
Manager::instance().registrationTrying( acc_ID);
break;
case Error:
Manager::instance().registrationFailed(acc_ID);
// Notify the error to the client
if( _registrationError != NO_ERROR )
Manager::instance().notifyErrClient( errorCode );
break;
case ErrorAuth:
Manager::instance().registrationFailed(acc_ID);
break;
case Unregistered:
......@@ -110,7 +115,7 @@ VoIPLink::setRegistrationState(const enum RegistrationState state, const std::st
void
VoIPLink::setRegistrationState(const enum RegistrationState state)
{
setRegistrationState(state, "");
setRegistrationState(state, NO_ERROR);
}
// NOW
......
......@@ -44,7 +44,7 @@ public:
VoIPLink(const AccountID& accountID);
virtual ~VoIPLink (void);
enum RegistrationState {Unregistered, Trying, Registered, Error};
enum RegistrationState {Unregistered, Trying, Registered, Error, ErrorAuth};
// Pure virtual functions
virtual void getEvent (void) = 0;
......@@ -141,7 +141,7 @@ public:
/**
* Get registration error message, if set.
*/
std::string getRegistrationError() { return _registrationError; }
int getRegistrationError() { return _registrationError; }
/**
* Set new registration state
......@@ -150,7 +150,7 @@ public:
* GUI when the state changes.
*/
void setRegistrationState(const enum RegistrationState state,
const std::string& errorMessage);
const int& errorCode);
/**
* Same, but with default error value to ""
......@@ -179,9 +179,9 @@ private:
enum RegistrationState _registrationState;
/**
* Registration error message
* Registration error code -> refers to global.h
*/
std::string _registrationError;
int _registrationError;
protected:
/** Add a call to the call map (protected by mutex)
......
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