account.h 6.05 KB
Newer Older
1
/*
2 3
 *  Copyright (C) 2006-2009 Savoir-Faire Linux inc.
 *  Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
4 5 6 7
 *  Author: Yan Morin <yan.morin@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
8
 *  the Free Software Foundation; either version 3 of the License, or
9 10 11 12 13 14 15 16 17 18 19
 *  (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.
 */
20

21 22 23 24
#ifndef ACCOUNT_H
#define ACCOUNT_H

#include <string>
25
#include <vector>
26

27
#include "config/config.h"
28
#include "voiplink.h"
29 30

class VoIPLink;
31

32 33 34 35 36 37 38
/**
 * @file account.h
 * @brief Interface to protocol account (SIPAccount, IAXAccount)
 * It can be enable on loading or activate after.
 * It contains account, configuration, VoIP Link and Calls (inside the VoIPLink)
 */

39
typedef std::string AccountID;
40

41
/** Contains all the state an Voip can be in */
42
typedef enum RegistrationState {
43 44 45 46 47 48 49 50 51
        Unregistered, 
        Trying, 
        Registered, 
        Error, 
        ErrorAuth , 
        ErrorNetwork , 
        ErrorHost, 
        ErrorExistStun, 
        ErrorConfStun
52
} RegistrationState;
53

54
#define AccountNULL ""
55 56 57

// Common account parameters
#define CONFIG_ACCOUNT_TYPE   "Account.type"  
yanmorin's avatar
yanmorin committed
58
#define CONFIG_ACCOUNT_ALIAS  "Account.alias"
59
#define CONFIG_ACCOUNT_MAILBOX	"Account.mailbox"
60
#define CONFIG_ACCOUNT_ENABLE	"Account.enable"
61
#define CONFIG_ACCOUNT_RESOLVE_ONCE "Account.resolveOnce"
62
#define CONFIG_ACCOUNT_REGISTRATION_EXPIRE "Account.expire"
63

64 65 66 67 68
#define HOSTNAME        "hostname"
#define USERNAME        "username"
#define PASSWORD        "password"

// SIP specific parameters
69
#define SIP_PROXY             "SIP.proxy"
70 71 72
#define SIP_STUN_SERVER       "STUN.server"
#define SIP_USE_STUN          "STUN.enable"
#define SIP_STUN_PORT         "STUN.port"
73

74
class Account{
75 76 77

    public:

78
        Account(const AccountID& accountID, std::string type);
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101

        /**
         * Virtual destructor
         */
        virtual ~Account();

        /**
         * Load the settings for this account.
         */
        virtual void loadConfig();

        /**
         * Get the account ID
         * @return constant account id
         */
        inline const AccountID& getAccountID() { return _accountID; }

        /**
         * Get the voiplink pointer
         * @return VoIPLink* the pointer or 0
         */
        inline VoIPLink* getVoIPLink() { return _link; }

102 103
        inline void setVoIPLink (VoIPLink *link) { _link = link; }

104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
        /**
         * Register the underlying VoIPLink. Launch the event listener.
         * This should update the getRegistrationState() return value.
         */
        virtual int registerVoIPLink() = 0;

        /**
         * Unregister the underlying VoIPLink. Stop the event listener.
         * This should update the getRegistrationState() return value.
         */
        virtual int unregisterVoIPLink() = 0;

        /**
         * Tell if the account is enable or not. 
         * @return true if enabled
         *	     false otherwise
         */
        bool isEnabled() { return _enabled; }

        /**
         * Get the registration state of the specified link
         * @return RegistrationState	The registration state of underlying VoIPLink
         */
127
        inline RegistrationState getRegistrationState() { return _registrationState; }
128

129
        void setRegistrationState( RegistrationState state );
130

131 132
        /* inline functions */
        /* They should be treated like macro definitions by the C++ compiler */
133 134 135 136 137 138 139 140 141 142 143
        inline std::string getUsername( void ) { return _username; }
        inline void setUsername( std::string username) { _username = username; }

        inline std::string getHostname( void ) { return _hostname; }
        inline void setHostname( std::string hostname) { _hostname = hostname; }

        inline std::string getPassword( void ) { return _password; }
        inline void setPassword( std::string password ) { _password = password; }

        inline std::string getAlias( void ) { return _alias; }
        inline void setAlias( std::string alias ) { _alias = alias; }
144

145 146 147 148
        inline std::string getType( void ) { return _type; }
        inline void setType( std::string type ) { _type = type; }

    private:
149 150 151 152 153 154 155 156 157 158 159 160
        // copy constructor
        Account(const Account& rh);

        // assignment operator
        Account& operator=(const Account& rh);

    protected:
        /**
         * Account ID are assign in constructor and shall not changed
         */
        AccountID _accountID;

161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
        /**
         * Account login information: username
         */
        std::string _username;

        /**
         * Account login information: hostname
         */
        std::string _hostname;

        /**
         * Account login information: password
         */
        std::string _password;

        /**
         * Account login information: Alias
         */
        std::string _alias;

181 182 183 184 185 186 187 188 189 190 191 192
        /**
         * Voice over IP Link contains a listener thread and calls
         */
        VoIPLink* _link;

        /**
         * Tells if the link is enabled, active.
         * This implies the link will be initialized on startup.
         * Modified by the configuration (key: ENABLED)
         */
        bool _enabled;

193 194 195 196 197 198
        /*
         * The account type
         * IAX2 or SIP
         */
        std::string _type;

199 200 201 202 203
        /*
         * The registration state of the account
         */
        RegistrationState _registrationState;

204 205 206
};

#endif