7 - struct user_access_info* info = 0;
8 + struct uhub_user_access_info* info = 0;
10 if (!strncmp(line, cmd, strlen(cmd)))
16 - info = hub_malloc_zero(sizeof(struct user_access_info));
17 + info = hub_malloc_zero(sizeof(struct uhub_user_access_info));
23 static void acl_free_access_info(void* ptr)
25 - struct user_access_info* info = (struct user_access_info*) ptr;
26 + struct uhub_user_access_info* info = (struct uhub_user_access_info*) ptr;
29 hub_free(info->username);
34 -struct user_access_info* acl_get_access_info(struct acl_handle* handle, const char* name)
35 +struct uhub_user_access_info* acl_get_access_info(struct acl_handle* handle, const char* name)
37 - struct user_access_info* info = (struct user_access_info*) list_get_first(handle->users);
38 + struct uhub_user_access_info* info = (struct uhub_user_access_info*) list_get_first(handle->users);
41 if (strcasecmp(info->username, name) == 0)
45 - info = (struct user_access_info*) list_get_next(handle->users);
46 + info = (struct uhub_user_access_info*) list_get_next(handle->users);
51 * seconds since the unix epoch (modulus 1 million)
52 * and the SID of the user (0-1 million).
54 -const char* password_generate_challenge(struct user* user)
55 +const char* password_generate_challenge(struct uhub_user* user)
58 uint64_t tiger_res[3];
63 -int password_verify(struct user* user, const char* password)
64 +int password_verify(struct uhub_user* user, const char* password)
67 - struct user_access_info* access;
68 + struct uhub_user_access_info* access;
69 const char* challenge;
70 char raw_challenge[64];
71 char password_calc[64];
75 #define HAVE_UHUB_ACL_H
85 const char* get_user_credential_string(enum user_credentials cred);
87 -struct user_access_info
88 +struct uhub_user_access_info
90 char* username; /* name of user, cid or IP range */
91 char* password; /* password */
93 extern int acl_initialize(struct hub_config* config, struct acl_handle* handle);
94 extern int acl_shutdown(struct acl_handle* handle);
96 -extern struct user_access_info* acl_get_access_info(struct acl_handle* handle, const char* name);
97 +extern struct uhub_user_access_info* acl_get_access_info(struct acl_handle* handle, const char* name);
98 extern int acl_is_cid_banned(struct acl_handle* handle, const char* cid);
99 extern int acl_is_ip_banned(struct acl_handle* handle, const char* ip_address);
100 extern int acl_is_ip_nat_override(struct acl_handle* handle, const char* ip_address);
103 extern int acl_check_ip_range(struct ip_addr_encap* addr, struct ip_ban_record* info);
105 -extern const char* password_generate_challenge(struct user* user);
106 -extern int password_verify(struct user* user, const char* password);
107 +extern const char* password_generate_challenge(struct uhub_user* user);
108 +extern int password_verify(struct uhub_user* user, const char* password);
110 #endif /* HAVE_UHUB_ACL_H */
117 -typedef int (*command_handler)(struct user* user, const char* message);
118 +typedef int (*command_handler)(struct uhub_user* user, const char* message);
120 struct commands_handler
124 static struct commands_handler command_handlers[];
126 -static void send_message(struct user* user, const char* message)
127 +static void send_message(struct uhub_user* user, const char* message)
129 char* buffer = adc_msg_escape(message);
130 struct adc_message* command = adc_msg_construct(ADC_CMD_IMSG, strlen(buffer) + 6);
135 -static int command_access_denied(struct user* user, const char* command)
136 +static int command_access_denied(struct uhub_user* user, const char* command)
139 snprintf(temp, 64, "*** Access denied: \"%s\"", command);
144 -static int command_stats(struct user* user, const char* message)
145 +static int command_stats(struct uhub_user* user, const char* message)
148 snprintf(temp, 128, "*** Stats: %zu users, peak: %zu. Network (up/down): %d/%d KB/s, peak: %d/%d KB/s",
153 -static int command_help(struct user* user, const char* message)
154 +static int command_help(struct uhub_user* user, const char* message)
156 #define MAX_HELP_MSG 1024
162 -static int command_uptime(struct user* user, const char* message)
163 +static int command_uptime(struct uhub_user* user, const char* message)
167 @@ -124,20 +124,20 @@
171 -static int command_kick(struct user* user, const char* message)
172 +static int command_kick(struct uhub_user* user, const char* message)
174 send_message(user, "*** Kick not implemented!");
178 -static int command_reload(struct user* user, const char* message)
179 +static int command_reload(struct uhub_user* user, const char* message)
181 send_message(user, "*** Reloading configuration");
182 user->hub->status = hub_status_restart;
186 -static int command_shutdown(struct user* user, const char* message)
187 +static int command_shutdown(struct uhub_user* user, const char* message)
189 send_message(user, "*** Hub shuting down...");
190 user->hub->status = hub_status_shutdown;
191 @@ -145,13 +145,13 @@
195 -static int command_version(struct user* user, const char* message)
196 +static int command_version(struct uhub_user* user, const char* message)
198 send_message(user, "*** Powered by " PRODUCT "/" VERSION);
202 -static int command_myip(struct user* user, const char* message)
203 +static int command_myip(struct uhub_user* user, const char* message)
206 snprintf(tmp, 128, "*** Your IP: %s", ip_convert_to_string(&user->ipaddr));
211 -int command_dipatcher(struct user* user, const char* message)
212 +int command_dipatcher(struct uhub_user* user, const char* message)
215 for (n = 0; command_handlers[n].prefix; n++)
219 #define CHAT_MSG_IGNORED 0
220 #define CHAT_MSG_INVALID -1
222 -typedef int (*plugin_event_chat_message)(struct hub_info*, struct user*, struct adc_message*);
223 +typedef int (*plugin_event_chat_message)(struct hub_info*, struct uhub_user*, struct adc_message*);
228 plugin_event_chat_message function;
231 -int command_dipatcher(struct user* user, const char* message);
232 +int command_dipatcher(struct uhub_user* user, const char* message);
239 -int hub_handle_message(struct user* u, const char* line, size_t length)
240 +int hub_handle_message(struct uhub_user* u, const char* line, size_t length)
243 struct adc_message* cmd = 0;
248 -int hub_handle_support(struct user* u, struct adc_message* cmd)
249 +int hub_handle_support(struct uhub_user* u, struct adc_message* cmd)
257 -int hub_handle_password(struct user* u, struct adc_message* cmd)
258 +int hub_handle_password(struct uhub_user* u, struct adc_message* cmd)
260 char* password = adc_msg_get_argument(cmd, 0);
266 -int hub_handle_chat_message(struct user* u, struct adc_message* cmd)
267 +int hub_handle_chat_message(struct uhub_user* u, struct adc_message* cmd)
269 char* message = adc_msg_get_argument(cmd, 0);
271 @@ -206,14 +206,14 @@
275 -int on_kick(struct user* u, struct adc_message* cmd)
276 +int on_kick(struct uhub_user* u, struct adc_message* cmd)
278 hub_log(log_error, "on_kick() not implemented");
282 #ifdef ADC_UDP_OPERATION
283 -int hub_handle_autocheck(struct user* u, struct adc_message* cmd)
284 +int hub_handle_autocheck(struct uhub_user* u, struct adc_message* cmd)
286 char* port_str = adc_msg_get_argument(cmd, 0);
287 char* token = adc_msg_get_argument(cmd, 1);
288 @@ -245,13 +245,13 @@
292 -void hub_send_autocheck(struct user* u, uint16_t port, const char* token)
293 +void hub_send_autocheck(struct uhub_user* u, uint16_t port, const char* token)
299 -void hub_send_support(struct user* u)
300 +void hub_send_support(struct uhub_user* u)
302 if (user_is_connecting(u) || user_is_logged_in(u))
308 -void hub_send_sid(struct user* u)
309 +void hub_send_sid(struct uhub_user* u)
311 struct adc_message* command;
312 if (user_is_connecting(u))
317 -void hub_send_ping(struct user* user)
318 +void hub_send_ping(struct uhub_user* user)
320 /* This will just send a newline, despite appearing to do more below. */
321 struct adc_message* ping = adc_msg_construct(0, 0);
326 -void hub_send_hubinfo(struct user* u)
327 +void hub_send_hubinfo(struct uhub_user* u)
329 struct adc_message* info = adc_msg_copy(u->hub->command_info);
335 -void hub_send_handshake(struct user* u)
336 +void hub_send_handshake(struct uhub_user* u)
344 -void hub_send_motd(struct user* u)
345 +void hub_send_motd(struct uhub_user* u)
347 if (u->hub->command_motd)
353 -void hub_send_password_challenge(struct user* u)
354 +void hub_send_password_challenge(struct uhub_user* u)
356 struct adc_message* igpa;
357 igpa = adc_msg_construct(ADC_CMD_IGPA, 38);
358 @@ -399,33 +399,33 @@
360 case UHUB_EVENT_USER_JOIN:
362 - if (user_is_disconnecting((struct user*) message->ptr))
363 + if (user_is_disconnecting((struct uhub_user*) message->ptr))
368 - hub_send_password_challenge((struct user*) message->ptr);
369 + hub_send_password_challenge((struct uhub_user*) message->ptr);
373 - on_login_success((struct user*) message->ptr);
374 + on_login_success((struct uhub_user*) message->ptr);
379 case UHUB_EVENT_USER_QUIT:
381 - user_manager_remove((struct user*) message->ptr);
382 - send_quit_message((struct user*) message->ptr);
383 - on_logout_user((struct user*) message->ptr);
384 - user_schedule_destroy((struct user*) message->ptr);
385 + user_manager_remove((struct uhub_user*) message->ptr);
386 + send_quit_message((struct uhub_user*) message->ptr);
387 + on_logout_user((struct uhub_user*) message->ptr);
388 + user_schedule_destroy((struct uhub_user*) message->ptr);
392 case UHUB_EVENT_USER_DESTROY:
394 hub_log(log_trace, "hub_event_dispatcher: UHUB_EVENT_USER_DESTROY (ptr=%p)", message->ptr);
395 - user_destroy((struct user*) message->ptr);
396 + user_destroy((struct uhub_user*) message->ptr);
402 static inline int is_nick_in_use(struct hub_info* hub, const char* nick)
404 - struct user* lookup = get_user_by_nick(hub, nick);
405 + struct uhub_user* lookup = get_user_by_nick(hub, nick);
411 static inline int is_cid_in_use(struct hub_info* hub, const char* cid)
413 - struct user* lookup = get_user_by_cid(hub, cid);
414 + struct uhub_user* lookup = get_user_by_cid(hub, cid);
419 * @param msg See enum status_message
420 * @param level See enum status_level
422 -void hub_send_status(struct user* user, enum status_message msg, enum msg_status_level level)
423 +void hub_send_status(struct uhub_user* user, enum status_message msg, enum msg_status_level level)
425 struct hub_config* cfg = user->hub->config;
426 struct adc_message* cmd = adc_msg_construct(ADC_CMD_ISTA, 6);
433 -static void log_user_login(struct user* u)
434 +static void log_user_login(struct uhub_user* u)
436 const char* cred = get_user_credential_string(u->credentials);
437 const char* addr = ip_convert_to_string(&u->ipaddr);
438 hub_log(log_user, "LoginOK %s/%s %s \"%s\" (%s) \"%s\"", sid_to_string(u->id.sid), u->id.cid, addr, u->id.nick, cred, u->user_agent);
441 -static void log_user_login_error(struct user* u, enum status_message msg)
442 +static void log_user_login_error(struct uhub_user* u, enum status_message msg)
444 const char* addr = ip_convert_to_string(&u->ipaddr);
445 const char* message = hub_get_status_message_log(u->hub, msg);
446 hub_log(log_user, "LoginError %s/%s %s \"%s\" (%s) \"%s\"", sid_to_string(u->id.sid), u->id.cid, addr, u->id.nick, message, u->user_agent);
449 -static void log_user_logout(struct user* u, const char* message)
450 +static void log_user_logout(struct uhub_user* u, const char* message)
452 const char* addr = ip_convert_to_string(&u->ipaddr);
453 hub_log(log_user, "Logout %s/%s %s \"%s\" (%s)", sid_to_string(u->id.sid), u->id.cid, addr, u->id.nick, message);
456 -static void log_user_nick_change(struct user* u, const char* nick)
457 +static void log_user_nick_change(struct uhub_user* u, const char* nick)
459 const char* addr = ip_convert_to_string(&u->ipaddr);
460 hub_log(log_user, "NickChange %s/%s %s \"%s\" -> \"%s\"", sid_to_string(u->id.sid), u->id.cid, addr, u->id.nick, nick);
464 /* Send MOTD, do logging etc */
465 -void on_login_success(struct user* u)
466 +void on_login_success(struct uhub_user* u)
468 struct timeval timeout = { TIMEOUT_IDLE, 0 };
471 event_add(u->ev_read, &timeout);
474 -void on_login_failure(struct user* u, enum status_message msg)
475 +void on_login_failure(struct uhub_user* u, enum status_message msg)
477 log_user_login_error(u, msg);
478 hub_send_status(u, msg, status_level_fatal);
479 user_disconnect(u, quit_logon_error);
482 -void on_nick_change(struct user* u, const char* nick)
483 +void on_nick_change(struct uhub_user* u, const char* nick)
485 if (user_is_logged_in(u))
491 -void on_logout_user(struct user* user)
492 +void on_logout_user(struct uhub_user* user)
494 const char* reason = "";
500 * This event is triggered whenever a user successfully logs in to the hub.
502 -extern void on_login_success(struct user* u);
503 +extern void on_login_success(struct uhub_user* u);
506 * This event is triggered whenever a user failed to log in to the hub.
508 -extern void on_login_failure(struct user* u, enum status_message msg);
509 +extern void on_login_failure(struct uhub_user* u, enum status_message msg);
512 * This event is triggered whenever a previously logged in user leaves the hub.
514 -extern void on_logout_user(struct user* u);
515 +extern void on_logout_user(struct uhub_user* u);
518 * This event is triggered whenever a user changes his/her nickname.
520 -extern void on_nick_change(struct user* u, const char* nick);
521 +extern void on_nick_change(struct uhub_user* u, const char* nick);
524 #endif /* HAVE_UHUB_HUB_EVENT_H */
528 struct event_queue* queue;
529 struct event_base* evbase;
530 struct hub_config* config;
531 - struct user_manager* users;
532 + struct uhub_user_manager* users;
533 struct acl_handle* acl;
534 struct adc_message* command_info; /* The hub's INF command */
535 struct adc_message* command_support; /* The hub's SUP command */
536 @@ -116,103 +116,103 @@
538 * @return 0 on success, -1 on error
540 -extern int hub_handle_message(struct user* u, const char* message, size_t length);
541 +extern int hub_handle_message(struct uhub_user* u, const char* message, size_t length);
544 * Handle protocol support/subscription messages received clients.
546 * @return 0 on success, -1 on error
548 -extern int hub_handle_support(struct user* u, struct adc_message* cmd);
549 +extern int hub_handle_support(struct uhub_user* u, struct adc_message* cmd);
552 * Handle password messages received from clients.
554 * @return 0 on success, -1 on error
556 -extern int hub_handle_password(struct user* u, struct adc_message* cmd);
557 +extern int hub_handle_password(struct uhub_user* u, struct adc_message* cmd);
560 * Handle chat messages received from clients.
561 * @return 0 on success, -1 on error.
563 -extern int hub_handle_chat_message(struct user* u, struct adc_message* cmd);
564 +extern int hub_handle_chat_message(struct uhub_user* u, struct adc_message* cmd);
567 * Used internally by hub_handle_info
568 * @return 1 if nickname is OK, or 0 if nickname is not accepted.
570 -extern int hub_handle_info_check_nick(struct user* u, struct adc_message* cmd);
571 +extern int hub_handle_info_check_nick(struct uhub_user* u, struct adc_message* cmd);
574 * Used internally by hub_handle_info
575 * @return 1 if CID/PID is OK, or 0 if not valid.
577 -extern int hub_handle_info_check_cid(struct user* u, struct adc_message* cmd);
578 +extern int hub_handle_info_check_cid(struct uhub_user* u, struct adc_message* cmd);
581 * Can only be used by administrators or operators.
583 * @return 0 on success, -1 on error
585 -extern int hub_handle_kick(struct user* u, struct adc_message* cmd);
586 +extern int hub_handle_kick(struct uhub_user* u, struct adc_message* cmd);
588 #ifdef ADC_UDP_OPERATION
590 * Handle incoming autocheck message.
592 -extern int hub_handle_autocheck(struct user* u, struct adc_message* cmd);
593 +extern int hub_handle_autocheck(struct uhub_user* u, struct adc_message* cmd);
597 * Send the support line for the hub to a particular user.
598 * Only used during the initial handshake.
600 -extern void hub_send_support(struct user* u);
601 +extern void hub_send_support(struct uhub_user* u);
604 * Send a message assigning a SID for a user.
605 * This is only sent after hub_send_support() during initial handshake.
607 -extern void hub_send_sid(struct user* u);
608 +extern void hub_send_sid(struct uhub_user* u);
611 * Send a 'ping' message to user.
613 -extern void hub_send_ping(struct user* user);
614 +extern void hub_send_ping(struct uhub_user* user);
617 * Send a message containing hub information to a particular user.
618 * This is sent during user connection, but can safely be sent at any
621 -extern void hub_send_hubinfo(struct user* u);
622 +extern void hub_send_hubinfo(struct uhub_user* u);
625 * Send handshake. This basically calls
626 * hub_send_support() and hub_send_sid()
628 -extern void hub_send_handshake(struct user* u);
629 +extern void hub_send_handshake(struct uhub_user* u);
632 * Send a welcome message containing the message of the day to
633 * one particular user. This can be sent in any point in time.
635 -extern void hub_send_motd(struct user* u);
636 +extern void hub_send_motd(struct uhub_user* u);
639 * Send a password challenge to a user.
640 * This is only used if the user tries to access the hub using a
641 * password protected nick name.
643 -extern void hub_send_password_challenge(struct user* u);
644 +extern void hub_send_password_challenge(struct uhub_user* u);
647 * Send an autocheck message to a user.
648 * This is basically a UDP message. The user's client can then determine
649 * if UDP communication works by either hole punching or configuring UPnP.
651 -extern void hub_send_autocheck(struct user* u, uint16_t port, const char* token);
652 +extern void hub_send_autocheck(struct uhub_user* u, uint16_t port, const char* token);
655 * This starts the hub.
658 * Sends a status_message to a user.
660 -extern void hub_send_status(struct user* user, enum status_message msg, enum msg_status_level level);
661 +extern void hub_send_status(struct uhub_user* user, enum status_message msg, enum msg_status_level level);
664 * Returns the number of logged in users on the hub.
668 adc_msg_remove_named_argument(cmd, ADC_INF_FLAG_REFERER);
671 -static int user_is_protected(struct user* user);
672 +static int user_is_protected(struct uhub_user* user);
674 -static int set_feature_cast_supports(struct user* u, struct adc_message* cmd)
675 +static int set_feature_cast_supports(struct uhub_user* u, struct adc_message* cmd)
681 * FIXME: Only works for tiger hash. If a client doesnt support tiger we cannot let it in!
683 -static int check_cid(struct user* user, struct adc_message* cmd)
684 +static int check_cid(struct uhub_user* user, struct adc_message* cmd)
687 char* cid = adc_msg_get_named_argument(cmd, ADC_INF_FLAG_CLIENT_ID);
692 -static int check_required_login_flags(struct user* user, struct adc_message* cmd)
693 +static int check_required_login_flags(struct uhub_user* user, struct adc_message* cmd)
698 * remove any wrong address, and replace it with the correct one
699 * as seen by the hub.
701 -int check_network(struct user* user, struct adc_message* cmd)
702 +int check_network(struct uhub_user* user, struct adc_message* cmd)
704 const char* address = ip_convert_to_string(&user->ipaddr);
710 -static int check_nick(struct user* user, struct adc_message* cmd)
711 +static int check_nick(struct uhub_user* user, struct adc_message* cmd)
715 @@ -317,10 +317,10 @@
719 -static int check_logged_in(struct user* user, struct adc_message* cmd)
720 +static int check_logged_in(struct uhub_user* user, struct adc_message* cmd)
722 - struct user* lookup1 = get_user_by_nick(user->hub, user->id.nick);
723 - struct user* lookup2 = get_user_by_cid(user->hub, user->id.cid);
724 + struct uhub_user* lookup1 = get_user_by_nick(user->hub, user->id.nick);
725 + struct uhub_user* lookup2 = get_user_by_cid(user->hub, user->id.cid);
730 * But this is not something we want to do, and is deprecated in the ADC specification.
731 * One should rather look at capabilities/features.
733 -static int check_user_agent(struct user* user, struct adc_message* cmd)
734 +static int check_user_agent(struct uhub_user* user, struct adc_message* cmd)
736 char* ua_encoded = 0;
742 -static int check_acl(struct user* user, struct adc_message* cmd)
743 +static int check_acl(struct uhub_user* user, struct adc_message* cmd)
745 if (acl_is_cid_banned(user->hub->acl, user->id.cid))
751 -static int check_limits(struct user* user, struct adc_message* cmd)
752 +static int check_limits(struct uhub_user* user, struct adc_message* cmd)
754 char* arg = adc_msg_get_named_argument(cmd, ADC_INF_FLAG_SHARED_SIZE);
756 @@ -525,10 +525,10 @@
757 * If the hub is configured to allow only registered users and the user
758 * is not recognized this will return 1.
760 -static int set_credentials(struct user* user, struct adc_message* cmd)
761 +static int set_credentials(struct uhub_user* user, struct adc_message* cmd)
764 - struct user_access_info* info = acl_get_access_info(user->hub->acl, user->id.nick);
765 + struct uhub_user_access_info* info = acl_get_access_info(user->hub->acl, user->id.nick);
771 * Determines if a user is to be let into the hub even if the hub is "full".
773 -static int user_is_protected(struct user* user)
774 +static int user_is_protected(struct uhub_user* user)
776 switch (user->credentials)
779 * Only registered users will be let in if the hub is configured for registered
782 -static int user_is_registered(struct user* user)
783 +static int user_is_registered(struct uhub_user* user)
785 switch (user->credentials)
791 -void update_user_info(struct user* u, struct adc_message* cmd)
792 +void update_user_info(struct uhub_user* u, struct adc_message* cmd)
800 -static int check_is_hub_full(struct user* user)
801 +static int check_is_hub_full(struct uhub_user* user)
804 * If hub is full, don't let users in, but we still want to allow
809 -static int check_registered_users_only(struct user* user)
810 +static int check_registered_users_only(struct uhub_user* user)
812 if (user->hub->config->registered_users_only && !user_is_registered(user))
818 -static int hub_handle_info_common(struct user* user, struct adc_message* cmd)
819 +static int hub_handle_info_common(struct uhub_user* user, struct adc_message* cmd)
821 /* Remove server restricted flags */
822 remove_server_restricted_flags(cmd);
827 -static int hub_handle_info_low_bandwidth(struct user* user, struct adc_message* cmd)
828 +static int hub_handle_info_low_bandwidth(struct uhub_user* user, struct adc_message* cmd)
830 if (user->hub->config->low_bandwidth_mode)
836 -int hub_handle_info_login(struct user* user, struct adc_message* cmd)
837 +int hub_handle_info_login(struct uhub_user* user, struct adc_message* cmd)
842 * - CID/PID (valid, not taken, etc).
843 * - IP addresses (IPv4 and IPv6)
845 -int hub_handle_info(struct user* user, const struct adc_message* cmd_unmodified)
846 +int hub_handle_info(struct uhub_user* user, const struct adc_message* cmd_unmodified)
848 struct adc_message* cmd = adc_msg_copy(cmd_unmodified);
849 if (!cmd) return -1; /* OOM */
854 * @return 0 on success, -1 on error
856 -extern int hub_handle_info(struct user* u, const struct adc_message* cmd);
857 +extern int hub_handle_info(struct uhub_user* u, const struct adc_message* cmd);
860 #endif /* HAVE_UHUB_INF_PARSER_H */
867 -struct adc_message* adc_msg_parse_verify(struct user* u, const char* line, size_t length)
868 +struct adc_message* adc_msg_parse_verify(struct uhub_user* u, const char* line, size_t length)
870 struct adc_message* command = adc_msg_parse(line, length);
875 #ifndef HAVE_UHUB_COMMAND_H
876 #define HAVE_UHUB_COMMAND_H
884 * The message is only considered valid if the user who sent it
885 * is the rightful origin of the message.
887 -extern struct adc_message* adc_msg_parse_verify(struct user* u, const char* string, size_t length);
888 +extern struct adc_message* adc_msg_parse_verify(struct uhub_user* u, const char* string, size_t length);
891 * This will parse 'string' and return it as a adc_message struct, or
895 void net_on_read(int fd, short ev, void *arg)
897 static char buf[MAX_RECV_BUF];
898 - struct user* user = (struct user*) arg;
899 + struct uhub_user* user = (struct uhub_user*) arg;
905 void net_on_write(int fd, short ev, void *arg)
907 - struct user* user = (struct user*) arg;
908 + struct uhub_user* user = (struct uhub_user*) arg;
909 struct adc_message* msg;
913 void net_on_accept(int server_fd, short ev, void *arg)
915 struct hub_info* hub = (struct hub_info*) arg;
916 - struct user* user = 0;
917 + struct uhub_user* user = 0;
918 struct ip_addr_encap ipaddr;
920 struct timeval timeout = { TIMEOUT_CONNECTED, 0 };
923 static char buffer[1024] = {0,};
924 // struct hub_info* hub = (struct hub_info*) arg;
925 - // struct user* user = 0;
926 + // struct uhub_user* user = 0;
928 struct sockaddr_storage from;
934 typedef void (*plugin_event_startup)(struct hub*);
935 typedef void (*plugin_event_shutdown)(struct hub*);
936 -typedef void (*plugin_event_user_login)(struct hub*, struct user*);
937 -typedef void (*plugin_event_user_logout)(struct hub*, struct user*);
938 +typedef void (*plugin_event_user_login)(struct hub*, struct uhub_user*);
939 +typedef void (*plugin_event_user_logout)(struct hub*, struct uhub_user*);
940 typedef int (*plugin_event_connect)(struct hub*, struct ip_addr_encap);
941 -typedef void (*plugin_event_disconnect)(struct hub*, struct user*);
942 -typedef int (*plugin_event_message)(struct hub*, struct user*, struct adc_message*);
943 -typedef void (*plugin_event_support)(struct hub*, struct user*, int);
944 +typedef void (*plugin_event_disconnect)(struct hub*, struct uhub_user*);
945 +typedef int (*plugin_event_message)(struct hub*, struct uhub_user*, struct adc_message*);
946 +typedef void (*plugin_event_support)(struct hub*, struct uhub_user*, int);
956 -int route_message(struct user* u, struct adc_message* msg)
957 +int route_message(struct uhub_user* u, struct adc_message* msg)
959 - struct user* target = NULL;
960 + struct uhub_user* target = NULL;
962 switch (msg->cache[0])
968 -static void queue_command(struct user* user, struct adc_message* msg__, int offset)
969 +static void queue_command(struct uhub_user* user, struct adc_message* msg__, int offset)
971 struct adc_message* msg = adc_msg_incref(msg__);
972 list_append(user->send_queue, msg);
974 * -1 if send queue is overflowed
975 * 0 if soft send queue is overflowed (not implemented at the moment)
977 -static int check_send_queue(struct user* user, struct adc_message* msg)
978 +static int check_send_queue(struct uhub_user* user, struct adc_message* msg)
980 if (user_flag_get(user, flag_user_list))
986 -int route_to_user(struct user* user, struct adc_message* msg)
987 +int route_to_user(struct uhub_user* user, struct adc_message* msg)
991 @@ -174,11 +174,11 @@
993 int route_to_all(struct hub_info* hub, struct adc_message* command) /* iterate users */
995 - struct user* user = (struct user*) list_get_first(hub->users->list);
996 + struct uhub_user* user = (struct uhub_user*) list_get_first(hub->users->list);
999 route_to_user(user, command);
1000 - user = (struct user*) list_get_next(hub->users->list);
1001 + user = (struct uhub_user*) list_get_next(hub->users->list);
1009 - struct user* user = (struct user*) list_get_first(hub->users->list);
1010 + struct uhub_user* user = (struct uhub_user*) list_get_first(hub->users->list);
1013 if (user->feature_cast)
1018 - user = (struct user*) list_get_next(hub->users->list);
1019 + user = (struct uhub_user*) list_get_next(hub->users->list);
1023 @@ -229,13 +229,13 @@
1024 route_to_user(user, command);
1027 - user = (struct user*) list_get_next(hub->users->list);
1028 + user = (struct uhub_user*) list_get_next(hub->users->list);
1034 -int route_info_message(struct user* u)
1035 +int route_info_message(struct uhub_user* u)
1037 if (!user_is_nat_override(u))
1039 @@ -245,12 +245,12 @@
1041 struct adc_message* cmd = adc_msg_copy(u->info);
1042 const char* address = ip_convert_to_string(&u->ipaddr);
1043 - struct user* user = 0;
1044 + struct uhub_user* user = 0;
1046 adc_msg_remove_named_argument(cmd, ADC_INF_FLAG_IPV4_ADDR);
1047 adc_msg_add_named_argument(cmd, ADC_INF_FLAG_IPV4_ADDR, address);
1049 - user = (struct user*) list_get_first(u->hub->users->list);
1050 + user = (struct uhub_user*) list_get_first(u->hub->users->list);
1053 if (user_is_nat_override(user))
1056 route_to_user(user, u->info);
1058 - user = (struct user*) list_get_next(u->hub->users->list);
1059 + user = (struct uhub_user*) list_get_next(u->hub->users->list);
1067 * Route a message by sending it to it's final destination.
1069 -extern int route_message(struct user* u, struct adc_message* msg);
1070 +extern int route_message(struct uhub_user* u, struct adc_message* msg);
1073 * Transmit message directly to one user.
1075 -extern int route_to_user(struct user*, struct adc_message* command);
1076 +extern int route_to_user(struct uhub_user*, struct adc_message* command);
1079 * Broadcast message to all users.
1081 * This will ensure the correct IP is seen by other users
1082 * in case nat override is in use.
1084 -extern int route_info_message(struct user* user);
1085 +extern int route_info_message(struct uhub_user* user);
1088 #endif /* HAVE_UHUB_ROUTE_H */
1096 + struct uhub_user* ptr;
1097 struct sid_map* next;
1103 extern void sid_initialize(struct sid_pool*);
1104 -extern sid_t sid_alloc(struct sid_pool*, struct user*);
1105 +extern sid_t sid_alloc(struct sid_pool*, struct uhub_user*);
1106 extern void sid_free(struct sid_pool*, sid_t);
1115 -struct user* user_create(struct hub_info* hub, int sd)
1116 +struct uhub_user* user_create(struct hub_info* hub, int sd)
1118 - struct user* user = NULL;
1119 + struct uhub_user* user = NULL;
1121 hub_log(log_trace, "user_create(), hub=%p, sd=%d", hub, sd);
1123 - user = (struct user*) hub_malloc_zero(sizeof(struct user));
1124 + user = (struct uhub_user*) hub_malloc_zero(sizeof(struct uhub_user));
1127 return NULL; /* OOM */
1129 adc_msg_free((struct adc_message*) ptr);
1132 -void user_destroy(struct user* user)
1133 +void user_destroy(struct uhub_user* user)
1135 hub_log(log_trace, "user_destroy(), user=%p", user);
1141 -void user_set_state(struct user* user, enum user_state state)
1142 +void user_set_state(struct uhub_user* user, enum user_state state)
1144 if ((user->state == state_cleanup && state != state_disconnected) || (user->state == state_disconnected))
1147 user->state = state;
1150 -void user_set_info(struct user* user, struct adc_message* cmd)
1151 +void user_set_info(struct uhub_user* user, struct adc_message* cmd)
1153 adc_msg_free(user->info);
1154 user->info = adc_msg_incref(cmd);
1155 @@ -156,44 +156,44 @@
1159 -void user_support_add(struct user* user, int fourcc)
1160 +void user_support_add(struct uhub_user* user, int fourcc)
1162 int feature_mask = convert_support_fourcc(fourcc);
1163 user->flags |= feature_mask;
1166 -int user_flag_get(struct user* user, enum user_flags flag)
1167 +int user_flag_get(struct uhub_user* user, enum user_flags flag)
1169 return user->flags & flag;
1172 -void user_flag_set(struct user* user, enum user_flags flag)
1173 +void user_flag_set(struct uhub_user* user, enum user_flags flag)
1175 user->flags |= flag;
1178 -void user_flag_unset(struct user* user, enum user_flags flag)
1179 +void user_flag_unset(struct uhub_user* user, enum user_flags flag)
1181 user->flags &= ~flag;
1184 -void user_set_nat_override(struct user* user)
1185 +void user_set_nat_override(struct uhub_user* user)
1187 user_flag_set(user, flag_nat);
1190 -int user_is_nat_override(struct user* user)
1191 +int user_is_nat_override(struct uhub_user* user)
1193 return user_flag_get(user, flag_nat);
1196 -void user_support_remove(struct user* user, int fourcc)
1197 +void user_support_remove(struct uhub_user* user, int fourcc)
1199 int feature_mask = convert_support_fourcc(fourcc);
1200 user->flags &= ~feature_mask;
1203 -void user_schedule_destroy(struct user* user)
1204 +void user_schedule_destroy(struct uhub_user* user)
1206 struct event_data post;
1207 memset(&post, 0, sizeof(post));
1209 event_queue_post(user->hub->queue, &post);
1212 -void user_disconnect(struct user* user, int reason)
1213 +void user_disconnect(struct uhub_user* user, int reason)
1215 struct event_data post;
1216 int need_notify = 0;
1221 -int user_have_feature_cast_support(struct user* user, char feature[4])
1222 +int user_have_feature_cast_support(struct uhub_user* user, char feature[4])
1224 char* tmp = list_get_first(user->feature_cast);
1230 -int user_set_feature_cast_support(struct user* u, char feature[4])
1231 +int user_set_feature_cast_support(struct uhub_user* u, char feature[4])
1233 if (!u->feature_cast)
1239 -void user_clear_feature_cast_support(struct user* u)
1240 +void user_clear_feature_cast_support(struct uhub_user* u)
1242 if (u->feature_cast)
1244 @@ -282,21 +282,21 @@
1248 -int user_is_logged_in(struct user* user)
1249 +int user_is_logged_in(struct uhub_user* user)
1251 if (user->state == state_normal)
1256 -int user_is_connecting(struct user* user)
1257 +int user_is_connecting(struct uhub_user* user)
1259 if (user->state == state_protocol || user->state == state_identify || user->state == state_verify)
1264 -int user_is_disconnecting(struct user* user)
1265 +int user_is_disconnecting(struct uhub_user* user)
1267 if (user->state == state_cleanup || user->state == state_disconnected)
1276 +struct uhub_user_info
1278 sid_t sid; /** session ID */
1279 char cid[MAX_CID_LEN+1]; /** global client ID */
1281 * as the number of bytes and files shared, and the number of hubs the
1282 * user is connected to, etc.
1285 +struct uhub_user_counts
1287 uint64_t shared_size; /** Shared size in bytes */
1288 size_t shared_files; /** The number of shared files */
1290 size_t hub_count_total; /** The number of hubs connected to in total */
1296 int sd; /** socket descriptor */
1297 struct event* ev_read; /** libevent struct for read events */
1298 struct event* ev_write; /** libevent struct for write events */
1299 enum user_state state; /** see enum user_state */
1300 enum user_credentials credentials; /** see enum user_credentials */
1301 - struct user_info id; /** Contains nick name and CID */
1302 + struct uhub_user_info id; /** Contains nick name and CID */
1303 int flags; /** see enum user_features */
1304 char user_agent[MAX_UA_LEN+1];/** User agent string */
1305 time_t tm_connected; /** time when user connected */
1307 struct hub_info* hub; /** The hub instance this user belong to */
1308 int quit_reason; /** Quit reason (see user_quit_reason) */
1309 struct ip_addr_encap ipaddr; /** IP address of connected user */
1310 - struct user_counts limits; /** Data used for limitation */
1311 + struct uhub_user_counts limits; /** Data used for limitation */
1313 SSL* ssl; /** SSL handle */
1314 #endif /* SSL_SUPPORT */
1315 @@ -137,19 +137,19 @@
1316 * @param sd socket descriptor associated with the user
1317 * @return User object or NULL if not enough memory is available.
1319 -extern struct user* user_create(struct hub_info* hub, int sd);
1320 +extern struct uhub_user* user_create(struct hub_info* hub, int sd);
1325 * !WRONG! If the user is logged in a quit message is issued.
1327 -extern void user_destroy(struct user* user);
1328 +extern void user_destroy(struct uhub_user* user);
1331 * Will post a message that will delete the user later.
1333 -extern void user_schedule_destroy(struct user* user);
1334 +extern void user_schedule_destroy(struct uhub_user* user);
1337 * Disconnect a user.
1338 @@ -165,36 +165,36 @@
1339 * @param user User to disconnect
1340 * @param reason See enum user_quit_reason
1342 -extern void user_disconnect(struct user* user, int reason);
1343 +extern void user_disconnect(struct uhub_user* user, int reason);
1346 * This associates a INF message to the user.
1347 * If the user already has a INF message associated, then this is
1348 * released before setting the new one.
1350 -extern void user_set_info(struct user* user, struct adc_message* info);
1351 +extern void user_set_info(struct uhub_user* user, struct adc_message* info);
1354 * Specify a user's state.
1355 * NOTE: DON'T, unless you know what you are doing.
1357 -extern void user_set_state(struct user* user, enum user_state);
1358 +extern void user_set_state(struct uhub_user* user, enum user_state);
1361 * Returns 1 if the user is in state state_normal, or 0 otherwise.
1363 -extern int user_is_logged_in(struct user* user);
1364 +extern int user_is_logged_in(struct uhub_user* user);
1367 * Returns 1 if the user is in state_protocol, state_identify or state_verify.
1368 * Returns 0 otherwise.
1370 -extern int user_is_connecting(struct user* user);
1371 +extern int user_is_connecting(struct uhub_user* user);
1374 * Returns 1 only if the user is in state_cleanup or state_disconnected.
1376 -extern int user_is_disconnecting(struct user* user);
1377 +extern int user_is_disconnecting(struct uhub_user* user);
1380 * User supports the protocol extension as given in fourcc.
1383 * @see enum user_flags
1385 -extern void user_support_add(struct user* user, int fourcc);
1386 +extern void user_support_add(struct uhub_user* user, int fourcc);
1389 * User no longer supports the protocol extension as given in fourcc.
1390 @@ -212,26 +212,26 @@
1392 * @see enum user_flags
1394 -extern void user_support_remove(struct user* user, int fourcc);
1395 +extern void user_support_remove(struct uhub_user* user, int fourcc);
1398 * Sets the nat override flag for a user, this allows users on the same
1399 * subnet as a natted hub to spoof their IP in order to use active mode
1402 -extern void user_set_nat_override(struct user* user);
1403 -extern int user_is_nat_override(struct user* user);
1404 +extern void user_set_nat_override(struct uhub_user* user);
1405 +extern int user_is_nat_override(struct uhub_user* user);
1408 * Set a flag. @see enum user_flags
1410 -extern void user_flag_set(struct user* user, enum user_flags flag);
1411 -extern void user_flag_unset(struct user* user, enum user_flags flag);
1412 +extern void user_flag_set(struct uhub_user* user, enum user_flags flag);
1413 +extern void user_flag_unset(struct uhub_user* user, enum user_flags flag);
1416 * Get a flag. @see enum user_flags
1418 -extern int user_flag_get(struct user* user, enum user_flags flag);
1419 +extern int user_flag_get(struct uhub_user* user, enum user_flags flag);
1422 * Check if a user supports 'feature' for feature casting (basis for 'Fxxx' messages)
1424 * @param feature a feature to lookup (example: 'TCP4' or 'UDP4')
1425 * @return 1 if 'feature' supported, or 0 otherwise
1427 -extern int user_have_feature_cast_support(struct user* user, char feature[4]);
1428 +extern int user_have_feature_cast_support(struct uhub_user* user, char feature[4]);
1431 * Set feature cast support for feature.
1432 @@ -249,12 +249,12 @@
1433 * @param feature a feature to lookup (example: 'TCP4' or 'UDP4')
1434 * @return 1 if 'feature' supported, or 0 otherwise
1436 -extern int user_set_feature_cast_support(struct user* u, char feature[4]);
1437 +extern int user_set_feature_cast_support(struct uhub_user* u, char feature[4]);
1440 * Remove all feature cast support features.
1442 -extern void user_clear_feature_cast_support(struct user* u);
1443 +extern void user_clear_feature_cast_support(struct uhub_user* u);
1447 --- a/src/usermanager.c
1448 +++ b/src/usermanager.c
1453 - struct user* u = (struct user*) ptr;
1454 + struct uhub_user* u = (struct uhub_user*) ptr;
1456 /* Mark the user as already being disconnected.
1457 * This prevents the hub from trying to send
1460 int user_manager_init(struct hub_info* hub)
1462 - struct user_manager* users = NULL;
1463 + struct uhub_user_manager* users = NULL;
1464 struct timeval timeout = { TIMEOUT_STATS, 0 };
1466 - users = (struct user_manager*) hub_malloc_zero(sizeof(struct user_manager));
1467 + users = (struct uhub_user_manager*) hub_malloc_zero(sizeof(struct uhub_user_manager));
1469 users->list = list_create();
1470 users->free_sid = 1;
1473 void user_manager_shutdown(struct hub_info* hub)
1475 - struct user_manager* users = hub->users;
1476 + struct uhub_user_manager* users = hub->users;
1477 event_del(&hub->ev_timer);
1479 list_clear(users->list, &clear_user_list_callback);
1484 -void user_manager_add(struct user* user)
1485 +void user_manager_add(struct uhub_user* user)
1487 list_append(user->hub->users->list, user);
1488 user->hub->users->count++;
1490 user->hub->users->shared_files += user->limits.shared_files;
1493 -void user_manager_remove(struct user* user)
1494 +void user_manager_remove(struct uhub_user* user)
1496 list_remove(user->hub->users->list, user);
1497 user->hub->users->count--;
1498 @@ -135,50 +135,50 @@
1502 -struct user* get_user_by_sid(struct hub_info* hub, sid_t sid)
1503 +struct uhub_user* get_user_by_sid(struct hub_info* hub, sid_t sid)
1505 - struct user* user = (struct user*) list_get_first(hub->users->list); /* iterate users */
1506 + struct uhub_user* user = (struct uhub_user*) list_get_first(hub->users->list); /* iterate users */
1509 if (user->id.sid == sid)
1511 - user = (struct user*) list_get_next(hub->users->list);
1512 + user = (struct uhub_user*) list_get_next(hub->users->list);
1518 -struct user* get_user_by_cid(struct hub_info* hub, const char* cid)
1519 +struct uhub_user* get_user_by_cid(struct hub_info* hub, const char* cid)
1521 - struct user* user = (struct user*) list_get_first(hub->users->list); /* iterate users - only on incoming INF msg */
1522 + struct uhub_user* user = (struct uhub_user*) list_get_first(hub->users->list); /* iterate users - only on incoming INF msg */
1525 if (strcmp(user->id.cid, cid) == 0)
1527 - user = (struct user*) list_get_next(hub->users->list);
1528 + user = (struct uhub_user*) list_get_next(hub->users->list);
1534 -struct user* get_user_by_nick(struct hub_info* hub, const char* nick)
1535 +struct uhub_user* get_user_by_nick(struct hub_info* hub, const char* nick)
1537 - struct user* user = (struct user*) list_get_first(hub->users->list); /* iterate users - only on incoming INF msg */
1538 + struct uhub_user* user = (struct uhub_user*) list_get_first(hub->users->list); /* iterate users - only on incoming INF msg */
1541 if (strcmp(user->id.nick, nick) == 0)
1543 - user = (struct user*) list_get_next(hub->users->list);
1544 + user = (struct uhub_user*) list_get_next(hub->users->list);
1550 -int send_user_list(struct user* target)
1551 +int send_user_list(struct uhub_user* target)
1554 user_flag_set(target, flag_user_list);
1555 - struct user* user = (struct user*) list_get_first(target->hub->users->list); /* iterate users - only on INF or PAS msg */
1556 + struct uhub_user* user = (struct uhub_user*) list_get_first(target->hub->users->list); /* iterate users - only on INF or PAS msg */
1559 if (user_is_logged_in(user))
1564 - user = (struct user*) list_get_next(user->hub->users->list);
1565 + user = (struct uhub_user*) list_get_next(user->hub->users->list);
1568 if (!target->send_queue_size)
1573 -void send_quit_message(struct user* leaving)
1574 +void send_quit_message(struct uhub_user* leaving)
1576 struct adc_message* command = adc_msg_construct(ADC_CMD_IQUI, 6);
1577 adc_msg_add_argument(command, (const char*) sid_to_string(leaving->id.sid));
1579 sid_t user_manager_get_free_sid(struct hub_info* hub)
1582 - struct user* user;
1583 - user = (struct user*) list_get_first(hub->users->list); /* iterate normal users */
1584 + struct uhub_user* user;
1585 + user = (struct uhub_user*) list_get_first(hub->users->list); /* iterate normal users */
1588 if (user->sid == hub->users->free_sid)
1590 if (hub->users->free_sid >= SID_MAX) hub->users->free_sid = 1;
1593 - user = (struct user*) list_get_next(hub->users->list);
1594 + user = (struct uhub_user*) list_get_next(hub->users->list);
1597 return hub->users->free_sid++;
1598 --- a/src/usermanager.h
1599 +++ b/src/usermanager.h
1601 #ifndef HAVE_UHUB_USER_MANAGER_H
1602 #define HAVE_UHUB_USER_MANAGER_H
1604 -struct user_manager
1605 +struct uhub_user_manager
1607 size_t count; /**<< "Number of all fully connected and logged in users" */
1608 size_t count_peak; /**<< "Peak number of users" */
1611 * Add a new user to the user manager.
1613 -extern void user_manager_add(struct user* user);
1614 +extern void user_manager_add(struct uhub_user* user);
1617 * Remove a user from the user manager.
1618 * This user is connected, and will be moved to the leaving queue, pending
1619 * all messages in the message queue, and resource cleanup.
1621 -extern void user_manager_remove(struct user* user);
1622 +extern void user_manager_remove(struct uhub_user* user);
1625 * Returns a free sid for a new user.
1627 * NOTE: This will only search connected users.
1628 * @return a user if found, or NULL if not found
1630 -extern struct user* get_user_by_sid(struct hub_info* hub, sid_t sid);
1631 +extern struct uhub_user* get_user_by_sid(struct hub_info* hub, sid_t sid);
1634 * Lookup a user based on the client ID (cid).
1635 * @return a user if found, or NULL if not found
1637 -extern struct user* get_user_by_cid(struct hub_info* hub, const char* cid);
1638 +extern struct uhub_user* get_user_by_cid(struct hub_info* hub, const char* cid);
1641 * Lookup a user based on the nick name.
1642 * @return a user if found, or NULL if not found
1644 -extern struct user* get_user_by_nick(struct hub_info* hub, const char* nick);
1645 +extern struct uhub_user* get_user_by_nick(struct hub_info* hub, const char* nick);
1648 * Send the user list of connected clients to 'user'.
1651 * @return 1 if sending the user list succeeded, 0 otherwise.
1653 -extern int send_user_list(struct user* user);
1654 +extern int send_user_list(struct uhub_user* user);
1657 * Send a quit message to all connected users when 'user' is
1658 * leaving the hub (for whatever reason).
1660 -extern void send_quit_message(struct user* user);
1661 +extern void send_quit_message(struct uhub_user* user);
1664 #endif /* HAVE_UHUB_USER_MANAGER_H */