static void hub_event_dispatcher(void* callback_data, struct event_data* message) { struct hub_info* hub = (struct hub_info*) callback_data; struct hub_user* user = (struct hub_user*) message->ptr; assert(hub != NULL); switch (message->id) { case UHUB_EVENT_USER_JOIN: { if (user_is_disconnecting(user)) break; if (message->flags) { hub_send_password_challenge(hub, user); } else { on_login_success(hub, user); } break; } case UHUB_EVENT_USER_QUIT: { uman_remove(hub, user); uman_send_quit_message(hub, user); on_logout_user(hub, user); hub_schedule_destroy_user(hub, user); break; } case UHUB_EVENT_USER_DESTROY: { user_destroy(user); break; } case UHUB_EVENT_HUB_SHUTDOWN: { struct hub_user* u = (struct hub_user*) list_get_first(hub->users->list); while (u) { uman_remove(hub, u); user_destroy(u); u = (struct hub_user*) list_get_first(hub->users->list); } break; } default: /* FIXME: ignored */ break; } }
int hub_handle_password(struct hub_info* hub, struct hub_user* u, struct adc_message* cmd) { char* password = adc_msg_get_argument(cmd, 0); int ret = 0; if (u->state == state_verify) { if (acl_password_verify(hub, u, password)) { on_login_success(hub, u); } else { on_login_failure(hub, u, status_msg_auth_invalid_password); ret = -1; } } hub_free(password); return ret; }
static void hub_event_dispatcher(void* callback_data, struct event_data* message) { int status; struct hub_info* hub = (struct hub_info*) callback_data; struct hub_user* user = (struct hub_user*) message->ptr; uhub_assert(hub != NULL); switch (message->id) { case UHUB_EVENT_USER_JOIN: { if (user_is_disconnecting(user)) break; if (message->flags) { hub_send_password_challenge(hub, user); } else { /* Race condition, we could have two messages for two logins queued up. So make sure we don't let the second client in. */ status = check_duplicate_logins_ok(hub, user); if (!status) { on_login_success(hub, user); } else { on_login_failure(hub, user, (enum status_message) status); } } break; } case UHUB_EVENT_USER_QUIT: { uman_remove(hub->users, user); uman_send_quit_message(hub, hub->users, user); on_logout_user(hub, user); hub_schedule_destroy_user(hub, user); break; } case UHUB_EVENT_USER_DESTROY: { user_destroy(user); break; } case UHUB_EVENT_HUB_SHUTDOWN: { struct hub_user* u = (struct hub_user*) list_get_first(hub->users->list); while (u) { uman_remove(hub->users, u); user_destroy(u); u = (struct hub_user*) list_get_first(hub->users->list); } break; } default: /* FIXME: ignored */ break; } }