Decouple hub and user manager more cleanly.
This commit is contained in:
@@ -28,36 +28,38 @@ struct hub_user_manager
|
||||
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 logged in users" */
|
||||
#ifdef STATS_SUPPORT
|
||||
struct timeout_evt* timeout; /**<< "Timeout handler for statistics" */
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
* Initializes the user manager.
|
||||
* @return 0 on success, or -1 if error (out of memory).
|
||||
*/
|
||||
extern int uman_init(struct hub_info* hub);
|
||||
extern struct hub_user_manager* uman_init();
|
||||
|
||||
/**
|
||||
* Shuts down the user manager.
|
||||
* All users will be disconnected and deleted as part of this.
|
||||
*
|
||||
* @return 0 on success, or -1 in an error occured (hub is invalid).
|
||||
* @return 0 on success, or -1 in an error occured (invalid pointer).
|
||||
*/
|
||||
extern int uman_shutdown(struct hub_info* hub);
|
||||
extern int uman_shutdown(struct hub_user_manager* users);
|
||||
|
||||
/**
|
||||
* Generate statistics for logfiles.
|
||||
*/
|
||||
extern void uman_update_stats(struct hub_info* hub);
|
||||
extern void uman_print_stats(struct hub_info* hub);
|
||||
extern void uman_update_stats(struct hub_user_manager* users);
|
||||
extern void uman_print_stats(struct hub_user_manager* users);
|
||||
|
||||
/**
|
||||
* Add a user to the user manager.
|
||||
*
|
||||
* @param hub The hub to add the user to
|
||||
* @param users The usermanager to add the user to
|
||||
* @param user The user to be added to the hub.
|
||||
*/
|
||||
extern int uman_add(struct hub_info* hub, struct hub_user* user);
|
||||
extern int uman_add(struct hub_user_manager* users, struct hub_user* user);
|
||||
|
||||
/**
|
||||
* Remove a user from the user manager.
|
||||
@@ -66,12 +68,12 @@ extern int uman_add(struct hub_info* hub, struct hub_user* user);
|
||||
*
|
||||
* @return 0 if successfully removed, -1 if error.
|
||||
*/
|
||||
extern int uman_remove(struct hub_info* hub, struct hub_user* user);
|
||||
extern int uman_remove(struct hub_user_manager* users, struct hub_user* user);
|
||||
|
||||
/**
|
||||
* Returns and allocates an unused session ID (SID).
|
||||
*/
|
||||
extern sid_t uman_get_free_sid(struct hub_info* hub, struct hub_user* user);
|
||||
extern sid_t uman_get_free_sid(struct hub_user_manager* users, struct hub_user* user);
|
||||
|
||||
/**
|
||||
* Lookup a user based on the session ID (SID).
|
||||
@@ -86,26 +88,28 @@ extern sid_t uman_get_free_sid(struct hub_info* hub, struct hub_user* user);
|
||||
*
|
||||
* @return a user if found, or NULL if not found
|
||||
*/
|
||||
extern struct hub_user* uman_get_user_by_sid(struct hub_info* hub, sid_t sid);
|
||||
extern struct hub_user* uman_get_user_by_sid(struct hub_user_manager* users, sid_t sid);
|
||||
|
||||
/**
|
||||
* Lookup a user based on the client ID (CID).
|
||||
* @return a user if found, or NULL if not found
|
||||
*/
|
||||
extern struct hub_user* uman_get_user_by_cid(struct hub_info* hub, const char* cid);
|
||||
extern struct hub_user* uman_get_user_by_cid(struct hub_user_manager* users, const char* cid);
|
||||
|
||||
/**
|
||||
* Lookup a user based on the nick name.
|
||||
* @return a user if found, or NULL if not found
|
||||
*/
|
||||
extern struct hub_user* uman_get_user_by_nick(struct hub_info* hub, const char* nick);
|
||||
extern struct hub_user* uman_get_user_by_nick(struct hub_user_manager* users, const char* nick);
|
||||
|
||||
/**
|
||||
* Lookup users based on an ip address range.
|
||||
*
|
||||
* @param[out] target the list of users matching the address
|
||||
* @param range the IP range of users to match
|
||||
* @return The number of users matching the addressess, or -1 on error (mask is wrong).
|
||||
*/
|
||||
extern size_t uman_get_user_by_addr(struct hub_info* hub, struct linked_list* users, struct ip_range* range);
|
||||
extern size_t uman_get_user_by_addr(struct hub_user_manager* users, struct linked_list* target, struct ip_range* range);
|
||||
|
||||
/**
|
||||
* Send the user list of connected clients to 'user'.
|
||||
@@ -113,13 +117,13 @@ extern size_t uman_get_user_by_addr(struct hub_info* hub, struct linked_list* us
|
||||
*
|
||||
* @return 1 if sending the user list succeeded, 0 otherwise.
|
||||
*/
|
||||
extern int uman_send_user_list(struct hub_info* hub, struct hub_user* user);
|
||||
extern int uman_send_user_list(struct hub_info* hub, struct hub_user_manager* users, struct hub_user* user);
|
||||
|
||||
/**
|
||||
* Send a quit message to all connected users when 'user' is
|
||||
* leaving the hub (for whatever reason).
|
||||
*/
|
||||
extern void uman_send_quit_message(struct hub_info* hub, struct hub_user* user);
|
||||
extern void uman_send_quit_message(struct hub_info* hub, struct hub_user_manager* users, struct hub_user* user);
|
||||
|
||||
|
||||
#endif /* HAVE_UHUB_USER_MANAGER_H */
|
||||
|
||||
Reference in New Issue
Block a user