summaryrefslogtreecommitdiffstats
path: root/pki/base/tps/src/include/httpClient/httpc/PSBuddyList.h
blob: 49155a8a5e33916770c0b04cb1755697a25f81fb (plain)
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 */
/** BEGIN COPYRIGHT BLOCK
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation;
 * version 2.1 of the License.
 * 
 * This library 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
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301  USA 
 * 
 * Copyright (C) 2007 Red Hat, Inc.
 * All rights reserved.
 * END COPYRIGHT BLOCK **/

#ifndef __PS_BUDDY_LIST_H__
#define __PS_BUDDY_LIST_H__

#ifdef HAVE_CONFIG_H
#ifndef AUTOTOOLS_CONFIG_H
#define AUTOTOOLS_CONFIG_H

/* Eliminate warnings when using Autotools */
#undef PACKAGE_BUGREPORT
#undef PACKAGE_NAME
#undef PACKAGE_STRING
#undef PACKAGE_TARNAME
#undef PACKAGE_VERSION

#include <config.h>
#endif /* AUTOTOOLS_CONFIG_H */
#endif /* HAVE_CONFIG_H */

/**
 * PSBuddyList.h	1.000 05/21/2002
 * 
 * This class maintains users information which are set for 
 * online status tracking. The online status of users are updated 
 * through a PSBuddyListener interface implemented by this class. 
 *
 * @author  Surendra Rajam
 * @version 1.000, 05/21/2002
 */
class PSBuddyList : 
    public PSBuddyListener
{
private:

	/**
	 * Constructor
	 */
	PSBuddyList();

	/**
	 * Destructor
	 */
	virtual ~PSBuddyList();

public:

	/**
	 * Gets an instance of the class
	 */
	static PSBuddyList* GetBuddyList();

	public:

	/**
	 * Save the users maintain by an instance of presence server 
	 * to a local file in the BLT format
	 *
	 * @return 0 on succcess, negative error code otherwise
	 */
	int SaveBuddyList();

	/**
	 * Loads the users into an instance of presence server 
	 * from a local file
	 *
	 * @return 0 on succcess, negative error code otherwise
	 */
	int LoadBuddyList();

	/**
	 * Sets a service provider. We currently support only one service
	 * provider in a presence server instance.
	 *
	 * @return 0 on succcess, negative error code otherwise
	 */
	int RegisterService(PSBuddyService* service);

	/** 
	 * Gets the online status of a user along with the 
	 * requested additional attributes
	 * 
	 * @param     group       group name to which the user belongs 
	 * @param     name        the screen name of the user to query status for 
	 * @param     nAttributes number of attributes 
	 * @param     attributes  the names of the attributes of the user to return 
	 * @param     user        upon return, filled with user attributes 
	 * @return                0 on success, a negative error code on failure 
	 */ 
	int GetUserStatus( const char* group, 
					   const char* name, 
					   int nAttributes, 
					   char** attributes, 
					   PSUser** user );

	/** 
	 * Gets the online status of multiple users along with the requested
	 * additional attributes
	 * 
	 * @param     group       group name to which the user belongs 
	 * @param     nUsers      the number of screen names to status query for
	 * @param     names       the screen names of the users to query status for 
	 * @param     nAttributes number of attributes 
	 * @param     attributes  the names of the attributes of the user to return 
	 * @param     user        upon return, filled with user attributes 
	 * @return                0 on success, a negative error code on failure 
	 */ 
	int GetMultipleUserStatus( const char* group,
							   int nUsers,
							   char** names,
							   int nAttributes,
							   char** attributes,
							   PSUser*** users );

	/** 
	 * Gets the screen names and attributes of users that match 
	 * certain search criteria
	 * 
	 * @param     group       group name to query from 
	 * @param     filter      an LDAP-like search expression on 
	 *						  presence status attributes 
	 * @param     nAttrbiutes number of attributes 
	 * @param     attributes  the names of the attributes of the user to return 
	 * @param     user        upon return, an array of users with 
	 *						  requested attributes 
	 * @return                number of users returned, or a negative error code 
	 */ 
	int GetUsersByFilter( const char* group, 
						  const char* filter, 
						  int nAttributes, 
						  char** attributes, 
						  PSUser*** users );

	/** 
	 * Gets the screen names and attributes of users that match certain search
	 * criteria and sorts the results (currently only by entryId)
	 * 
	 * @param     group       group name to query from 
	 * @param     filter      an LDAP-like search expression on presence status
	 *                        attributes 
	 * @param     sortKey     name of attribute to sort on
	 * @param     sortKeyType 1 for numeric, 2 for string
	 * @param     nAttributes number of attributes 
	 * @param     attributes  the names of the attributes of the user to return 
	 * @param     user        upon return, an array of users with requested
	 *                        attributes 
	 * @return                number of users returned, or a negative error code 
	 */ 
	int GetSortedUsersByFilter(	const char* group, 
								const char* filter, 
								const char *sortKey, 
								int sortKeyType, 
								int nAttributes, 
								char** attributes, 
								PSUser*** users	);

	/** 
	 * Gets the number of users who are online or offline in a group
	 * 
	 * @param group Name of group to query; NULL or empty for all groups
	 * @param bOnline true to return the count of online users, false for offline
	 * @return Number of users, or a negative error code on failure 
	 *
	 * Error Code(s):
	 * PS_UNKOWN_GROUP 
	 */ 
	int GetBuddyCount( const char* group, int bOnline );

	/** 
	 * Add a new group 
	 * 
	 * @param     group       name of the new group 
	 * @param     nAttributes number of attributes 
	 * @param     attributes  attributes the group will support 
	 * @return                0 on success, a negative error code on failure 
	 */ 
	int AddGroup( const char* group, int nAttributes, char** attributes	); 

	/** 
	 * Adds a user to be tracked. 
	 * 
	 * @param     group       name of the group to add the user in 
	 * @param     name        screen name of the user to track 
	 * @param     nAttributes number of attributes 
	 * @param     attributes  the attributes of the users to be stored 
	 * @return                on success, 0 or an error code 
	 */
	int AddUser( const char* group, 
				 const char* name, 
				 int nAttributes, 
				 PSAttribute** attributes );

	/** 
	 * Adds a number of users to track. 
	 * 
	 * @param     group       name of the group to which the users belong 
	 * @param     nUsers      number of users 
	 * @param     users       names and attributes of users to track 
	 * @return                number of users added on success, 
							  or a negative error code on failure 
	 */ 
	int AddUsers( const char* group, 
				  int nUsers, 
				  PSUser** users );

	/** 
	 * Removes a user to be tracked. 
	 * 
	 * @param     group       name of the group to which the user belongs 
	 * @param     name        screen name of the user to be removed 
	 * @return                0 on success, or a negative error code on failure 
	 */ 
	int RemoveUser(	const char* group, const char* name	);

	/** 
	 * Removes a number of users to be tracked. 
	 * 
	 * @param     group       name of the group to which the users belong 
	 * @param     nUsers      number of users 
	 * @param     names       screen name of the users to be removed 
	 * @return                number of users removed on success, 
	 *						or a negative error code on failure 
	 */ 
	int RemoveUsers( const char* group, int nUsers, char** names );

	/** 
	 * Removes a group. 
	 * 
	 * @param     group       name of the group to be removed 
	 * @return                number of users removed on success, 
	 *						or a negative error code on failure 
	 * 
	 * Error Code(s):
	 * PS_UNKNOWN_GROUP 
	 */ 
	int RemoveGroup(const char* group); 

	/** 
	 * Gets the list of groups. 
	 * 
	 * @param     groups      upon return, array containing group names 
	 * @return                number of groups or 0 if no group present 
	 * 
	 * Error Code(s):
	 * PS_NO_GROUPS
	 */ 
	int GetAllGroups(char*** groups);

	/** 
	 * Gets the users in a group(s). 
	 * 
	 * @param     group       name of the group to query 
	 * @param     users       upon return, array of User objects 
	 * @return                number of users returned, 
	 *						 or a negative error code on failure 
	 */ 
	int GetAllUsers( const char* group, PSUser*** users	); 

	/** 
	 * Gets the attributes supported by a group(s)
	 * 
	 * @param     group			name of the group
	 * @param	  attributes	upon return, array of attributes
	 * @return					number of users removed on success, 
	 *							or a negative error code on failure 
	 */ 
	int GetSearchableAttributes( const char* group, char*** attributes );

	// PSBuddyListener interface
	/**
	 * Callback to notify buddy changes
	 *
	 * @param	service	the reporting buddy service
	 * @param	buddy	buddy object containing online status attributes
	 * @return			0 on success
	 */
	int OnBuddyChanged(PSBuddyService* service, PSBuddy* buddy);

	/**
	 * Callback to refresh the list of screen names to the buddy queue 
	 *
	 * @param	the reporting buddy service
	 * @return 0 on success
	 */
	int OnRefreshList(PSBuddyService* service);

	/** 
	 * Removes a user from a group based on its entry Id
	 * 
	 * @param	group		name of the group
	 * @param	entryId		user's entry id
	 * @return	0
	 */ 
	int RemoveUserByEntryId(const char* group, char* entryId);

protected:

	/** 
	 * Gets the max number of search results to return
	 * 
	 * @return The max number of search results to return
	 */ 
	int GetMaxSearchResults();

private:

	/**
	 * Parses the LDAP like filter and create a map object containing
	 * filter in the form of name-value pair
	 *
	 * @param	filter	LDAP like filter
	 * @param	map		array containing break up of filter into name-value pair
	 * @return 0 on success
	 */
	int ParseFilter(const char* filter, PSAttribute*** map);

	/**
	 * Checks whether a given string is NULL or ""
	 *
	 * @param	value	a string to be tested for NULL or ""
	 * @return  true if NULL, false otherwise
	 */
	bool IsNull(const char* value);

	/**
	 * Prints buddy information
	 *
	 * @param	buddy	a buddy object containing online status attributes
	 * @return 0 on success
	 */
	int DumpBuddy(PSBuddy* buddy);

	/**
	 * Sorts a list of users based on a "entryId"
	 *
	 * @param	users	array of users to be sorted
	 * @param	nUsers	number of users in the array
	 * @return 0 on success
	 */
	int SortUsersByEntryId(PSUser** users, int nUsers);

private:    
	PSBuddyCache*	m_buddies;
	PSGroupCache*	m_groups;
	PSBuddyService*	m_service;

	/* flag indicating if buddy list is loaded from the disk */
	bool m_loadedList;	
};

#endif // __PS_BUDDY_LIST_H__