2009-02-19 16:14:09 +00:00
|
|
|
/*
|
|
|
|
* uhub - A tiny ADC p2p connection hub
|
|
|
|
* Copyright (C) 2007-2009, Jan Vidar Krey
|
|
|
|
*
|
|
|
|
* 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 3 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef HAVE_UHUB_USER_MANAGER_H
|
|
|
|
#define HAVE_UHUB_USER_MANAGER_H
|
|
|
|
|
|
|
|
struct user_manager
|
|
|
|
{
|
|
|
|
size_t count; /**<< "Number of all fully connected and logged in users" */
|
|
|
|
size_t count_peak; /**<< "Peak number of users" */
|
|
|
|
sid_t free_sid; /**<< "The next available SID." */
|
|
|
|
uint64_t shared_size; /**<< "The total number of shared bytes among fully connected users." */
|
|
|
|
uint64_t shared_files; /**<< "The total number of shared files among fully connected users." */
|
|
|
|
struct linked_list* list; /**<< "Contains all users" */
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the user manager.
|
|
|
|
* @return 0 on success, or -1 if error (out of memory).
|
|
|
|
*/
|
2009-05-16 01:14:20 +00:00
|
|
|
extern int uman_init(struct hub_info* hub);
|
2009-02-19 16:14:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Shuts down the user manager.
|
|
|
|
* All users will be disconnected and deleted as part of this.
|
2009-05-15 16:45:26 +00:00
|
|
|
*
|
|
|
|
* @return 0 on success, or -1 in an error occured (hub is invalid).
|
2009-02-19 16:14:09 +00:00
|
|
|
*/
|
2009-05-16 01:14:20 +00:00
|
|
|
extern int uman_shutdown(struct hub_info* hub);
|
2009-02-19 16:14:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate statistics for logfiles.
|
|
|
|
*/
|
2009-05-16 01:14:20 +00:00
|
|
|
extern void uman_update_stats(struct hub_info* hub);
|
|
|
|
extern void uman_print_stats(struct hub_info* hub);
|
2009-02-19 16:14:09 +00:00
|
|
|
|
|
|
|
/**
|
2009-05-15 16:45:26 +00:00
|
|
|
* Add a user to the user manager.
|
|
|
|
*
|
|
|
|
* @param hub The hub to add the user to
|
|
|
|
* @param user The user to be added to the hub.
|
2009-02-19 16:14:09 +00:00
|
|
|
*/
|
2009-05-16 01:14:20 +00:00
|
|
|
extern int uman_add(struct hub_info* hub, struct user* user);
|
2009-02-19 16:14:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a user from the user manager.
|
|
|
|
* This user is connected, and will be moved to the leaving queue, pending
|
|
|
|
* all messages in the message queue, and resource cleanup.
|
2009-05-15 16:45:26 +00:00
|
|
|
*
|
|
|
|
* @return 0 if successfully removed, -1 if error.
|
2009-02-19 16:14:09 +00:00
|
|
|
*/
|
2009-05-16 01:14:20 +00:00
|
|
|
extern int uman_remove(struct hub_info* hub, struct user* user);
|
2009-02-19 16:14:09 +00:00
|
|
|
|
|
|
|
/**
|
2009-05-15 16:45:26 +00:00
|
|
|
* Returns and allocates an unused session ID (SID).
|
2009-02-19 16:14:09 +00:00
|
|
|
*/
|
2009-05-16 01:14:20 +00:00
|
|
|
extern sid_t uman_get_free_sid(struct hub_info* hub);
|
2009-02-19 16:14:09 +00:00
|
|
|
|
|
|
|
/**
|
2009-05-15 16:45:26 +00:00
|
|
|
* Lookup a user based on the session ID (SID).
|
|
|
|
*
|
|
|
|
* NOTE: This function will only search connected users, which means
|
|
|
|
* that SIDs assigned to users who are not yet completely logged in,
|
|
|
|
* or are in the process of being disconnected will result in this
|
|
|
|
* function returning NULL even though the sid is not freely available.
|
|
|
|
*
|
|
|
|
* FIXME: Is that really safe / sensible ?
|
|
|
|
* - Makes sense from a message routing point of view.
|
|
|
|
*
|
2009-02-19 16:14:09 +00:00
|
|
|
* @return a user if found, or NULL if not found
|
|
|
|
*/
|
2009-05-16 10:42:30 +00:00
|
|
|
extern struct user* uman_get_user_by_sid(struct hub_info* hub, sid_t sid);
|
2009-02-19 16:14:09 +00:00
|
|
|
|
|
|
|
/**
|
2009-05-15 16:45:26 +00:00
|
|
|
* Lookup a user based on the client ID (CID).
|
2009-02-19 16:14:09 +00:00
|
|
|
* @return a user if found, or NULL if not found
|
|
|
|
*/
|
2009-05-16 10:42:30 +00:00
|
|
|
extern struct user* uman_get_user_by_cid(struct hub_info* hub, const char* cid);
|
2009-02-19 16:14:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Lookup a user based on the nick name.
|
|
|
|
* @return a user if found, or NULL if not found
|
|
|
|
*/
|
2009-05-16 10:42:30 +00:00
|
|
|
extern struct user* uman_get_user_by_nick(struct hub_info* hub, const char* nick);
|
2009-02-19 16:14:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Send the user list of connected clients to 'user'.
|
|
|
|
* Usually part of the login process.
|
|
|
|
*
|
|
|
|
* @return 1 if sending the user list succeeded, 0 otherwise.
|
|
|
|
*/
|
2009-05-18 14:30:17 +00:00
|
|
|
extern int uman_send_user_list(struct hub_info* hub, struct user* user);
|
2009-02-19 16:14:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a quit message to all connected users when 'user' is
|
|
|
|
* leaving the hub (for whatever reason).
|
|
|
|
*/
|
2009-05-18 14:30:17 +00:00
|
|
|
extern void uman_send_quit_message(struct hub_info* hub, struct user* user);
|
2009-02-19 16:14:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
#endif /* HAVE_UHUB_USER_MANAGER_H */
|