1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
/*
Copyright (C) 2005-2009 Michel de Boer <michel@twinklephone.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, see <https://www.gnu.org/licenses/>.
*/
/**
* @file
* Local address book.
*/
#ifndef _ADDRESS_BOOK_H
#define _ADDRESS_BOOK_H
#include <string>
#include <list>
#include "user.h"
#include "sockets/url.h"
#include "threads/mutex.h"
#include "utils/record_file.h"
using namespace std;
/** A single address card. */
class t_address_card : public utils::t_record {
public:
string name_last; /**< Last name. */
string name_first; /**< First name. */
string name_infix; /**< Infix name. */
string sip_address; /**< SIP address. */
string remark; /**< Remark. */
/**
* Get the display name derived from first, last and infix name.
* @return The display name.
*/
string get_display_name(void) const;
virtual bool create_file_record(vector<string> &v) const;
virtual bool populate_from_file_record(const vector<string> &v);
/** Equality check. */
bool operator==(const t_address_card other) const;
};
/**
* A book containing address cards. The user can
* create different address books.
*/
class t_address_book : public utils::t_record_file<t_address_card> {
private:
/** @name Cache for last searched name/url mapping */
//@{
mutable t_url last_url; /**< Last URL. */
mutable string last_name; /**< Lat name. */
//@}
/**
* Find a matching address for a url and cache the display name.
* @param user_config [in] The user profile.
* @param u [in] The url to find.
* @post If a matching address is found, then the URL and name are
* put in the cache. Otherwise the cache is cleared.
*/
void find_address(t_user *user_config, const t_url &u) const;
public:
/** Constructor. */
t_address_book();
/**
* Add an address.
* @param address [in] The address to be added.
*/
void add_address(const t_address_card &address);
/**
* Delete an address.
* @return true, if the address was successfully deleted.
* @return false, if the address does not exist.
*/
bool del_address(const t_address_card &address);
/**
* Update an address.
* @param old_address [in] The address to be updated.
* @param new_address [in] The updated address information.
* @return true, if the update was successful.
* @return false, if the old address does not exist.
*/
bool update_address(const t_address_card &old_address,
const t_address_card &new_address);
/**
* Find the display name for a SIP URL.
* @param user_config [in] The user profile.
* @param u [in] The SIP URL.
* @return The display name if a match was found.
* @return Empty string if no match can be found.
*/
string find_name(t_user *user_config, const t_url &u) const;
/**
* Get the list of addresses.
* @return The list of addresses.
*/
const list<t_address_card> &get_address_list(void) const;
};
extern t_address_book *ab_local;
#endif
|