iaxaccount.cpp 3.08 KB
Newer Older
yanmorin's avatar
 
yanmorin committed
1
/*
2
3
 *  Copyright (C) 2006-2007 Savoir-Faire Linux inc.
 *  Author: Alexandre Bourget <alexandre.bourget@savoirfairelinux.com>
yanmorin's avatar
 
yanmorin committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 *  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
 *  the Free Software Foundation; either version 2 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 "iaxaccount.h"
21
#include "account.h"
yanmorin's avatar
 
yanmorin committed
22
23
24
25
26
27
#include "iaxvoiplink.h"
#include "manager.h"

IAXAccount::IAXAccount(const AccountID& accountID)
 : Account(accountID)
{
28
  _link = new IAXVoIPLink(accountID);
yanmorin's avatar
 
yanmorin committed
29
30
31
32
33
34
35
36
37
38
39
}


IAXAccount::~IAXAccount()
{
}

bool
IAXAccount::registerAccount()
{
  if (_link && !_registered) {
yanmorin's avatar
yanmorin committed
40
    init();
41
    //unregisterAccount(); No need to unregister first.
yanmorin's avatar
yanmorin committed
42
43
    IAXVoIPLink* tmplink = dynamic_cast<IAXVoIPLink*> (_link);
    if (tmplink) {
44
      // Stuff needed for IAX registration
yanmorin's avatar
yanmorin committed
45
46
47
48
      tmplink->setHost(Manager::instance().getConfigString(_accountID,IAX_HOST));
      tmplink->setUser(Manager::instance().getConfigString(_accountID,IAX_USER));
      tmplink->setPass(Manager::instance().getConfigString(_accountID,IAX_PASS));
    }
yanmorin's avatar
 
yanmorin committed
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
    _registered = _link->setRegister();
  }
  return _registered;
}

bool
IAXAccount::unregisterAccount()
{
  if (_link && _registered) {
    _registered = _link->setUnregister();
  }
  return !_registered;
}

bool
IAXAccount::init()
{
  if (_link && !_enabled) {
    _link->init();
    _enabled = true;
    return true;
  }
  return false;
}

bool
IAXAccount::terminate()
{
  if (_link && _enabled) {
    _link->terminate();
    _enabled = false;
    return true;
  }
  return false;
}

void 
IAXAccount::initConfig(Conf::ConfigTree& config)
{
  std::string section(_accountID);
  std::string type_str("string");
  std::string type_int("int");
91
92
93
94
95

  // Account generic
  Account::initConfig(config);

  // IAX specific
yanmorin's avatar
yanmorin committed
96
  config.addConfigTreeItem(section, Conf::ConfigTreeItem(CONFIG_ACCOUNT_TYPE, "IAX", type_str));
97
  config.addConfigTreeItem(section, Conf::ConfigTreeItem(IAX_FULL_NAME, "", type_str));
yanmorin's avatar
yanmorin committed
98
99
100
  config.addConfigTreeItem(section, Conf::ConfigTreeItem(IAX_HOST, "", type_str));
  config.addConfigTreeItem(section, Conf::ConfigTreeItem(IAX_USER, "", type_str));
  config.addConfigTreeItem(section, Conf::ConfigTreeItem(IAX_PASS, "", type_str));
yanmorin's avatar
 
yanmorin committed
101
102
103
104
105
}

void
IAXAccount::loadConfig() 
{
106
107
108
109
110
  // Account generic
  Account::loadConfig();

  // IAX specific
  //none
yanmorin's avatar
 
yanmorin committed
111
}