]> git.ipfire.org Git - thirdparty/freeswitch.git/blob
1061dc60b98e5e77ee766f95113f7460e346e9cf
[thirdparty/freeswitch.git] /
1 // *************************************************************************
2 // * GSM TA/ME library
3 // *
4 // * File: gsm_sorted_phonebook_base.cc
5 // *
6 // * Purpose: Virtual base class for alphabetically sorted phonebook
7 // * The infrastructure in this module allows custom backends for
8 // * storing phonebook entries to be integrated into gsmlib
9 // * (eg. LDAP- or RDBMS-based phonebook stores).
10 // *
11 // * Author: Peter Hofmann (software@pxh.de)
12 // *
13 // * Created: 5.6.2000
14 // *************************************************************************
15
16 #ifdef HAVE_CONFIG_H
17 #include <gsm_config.h>
18 #endif
19 #include <gsmlib/gsm_sorted_phonebook_base.h>
20 #include <gsmlib/gsm_error.h>
21 #include <gsmlib/gsm_util.h>
22 #include <gsmlib/gsm_nls.h>
23
24 #include <assert.h>
25
26 using namespace std;
27 using namespace gsmlib;
28
29 // PhonebookEntryBase members
30
31 void PhonebookEntryBase::set(string telephone, string text, int index,
32 bool useIndex)
33 throw(GsmException)
34 {
35 checkTextAndTelephone(text, telephone);
36
37 _changed = true;
38 _telephone = telephone;
39 _text = text;
40 _useIndex = useIndex;
41 if (index != -1)
42 _index = index;
43 }
44
45 bool PhonebookEntryBase::operator==(const PhonebookEntryBase &e) const
46 {
47 assert(! ((_useIndex || e._useIndex) &&
48 (_index == -1 || e._index == -1)));
49 return _telephone == e._telephone && _text == e._text &&
50 (! (_useIndex || e._useIndex) || _index == e._index);
51 }
52
53 string PhonebookEntryBase::text() const throw(GsmException)
54 {
55 return _text;
56 }
57
58 string PhonebookEntryBase::telephone() const throw(GsmException)
59 {
60 return _telephone;
61 }
62
63 bool PhonebookEntryBase::empty() const throw(GsmException)
64 {
65 return (text() == "") && (telephone() == "");
66 }
67
68 Ref<PhonebookEntryBase> PhonebookEntryBase::clone()
69 {
70 Ref<PhonebookEntryBase> result = new PhonebookEntryBase(*this);
71 return result;
72 }
73
74 PhonebookEntryBase::PhonebookEntryBase(const PhonebookEntryBase &e)
75 throw(GsmException)
76 {
77 set(e._telephone, e._text, e._index, e._useIndex);
78 }
79
80 PhonebookEntryBase &PhonebookEntryBase::operator=(const PhonebookEntryBase &e)
81 throw(GsmException)
82 {
83 set(e._telephone, e._text, e._index, e._useIndex);
84 return *this;
85 }
86
87 // CustomPhonebookRegistry members
88
89 map<string, CustomPhonebookFactory*>
90 *CustomPhonebookRegistry::_factoryList = NULL;
91
92 void CustomPhonebookRegistry::
93 registerCustomPhonebookFactory(string backendName,
94 CustomPhonebookFactory *factory)
95 throw(GsmException)
96 {
97 if (_factoryList == NULL)
98 _factoryList = new map<string, CustomPhonebookFactory*>;
99 backendName = lowercase(backendName);
100 if (_factoryList->find(backendName) != _factoryList->end())
101 throw GsmException(stringPrintf(_("backend '%s' already registered"),
102 backendName.c_str()), ParameterError);
103 }
104
105 SortedPhonebookRef CustomPhonebookRegistry::
106 createPhonebook(string backendName, string source) throw(GsmException)
107 {
108 if (_factoryList == NULL)
109 _factoryList = new map<string, CustomPhonebookFactory*>;
110 backendName = lowercase(backendName);
111 if (_factoryList->find(backendName) == _factoryList->end())
112 throw GsmException(stringPrintf(_("backend '%s' not registered"),
113 backendName.c_str()), ParameterError);
114 return (*_factoryList)[backendName]->createPhonebook(source);
115 }