added idb_lock functions
This commit is contained in:
@@ -34,15 +34,15 @@ declare_RequestHandler(Login)
|
||||
}
|
||||
|
||||
// lock users cache
|
||||
try_stderrcode(pthread_mutex_lock(&conn->server->users_cache_mutex));
|
||||
idb_lockTable(conn->server->users.table);
|
||||
bool unlocked_users_cache_mutex = false;
|
||||
Defer(
|
||||
if(!unlocked_users_cache_mutex)
|
||||
pthread_mutex_unlock(&conn->server->users_cache_mutex)
|
||||
idb_unlockTable(conn->server->users.table)
|
||||
);
|
||||
|
||||
// try get id from name cache
|
||||
u64* id_ptr = HashMap_tryGetPtr(&conn->server->users_name_id_map, username_str);
|
||||
u64* id_ptr = HashMap_tryGetPtr(&conn->server->users.username_id_map, username_str);
|
||||
if(id_ptr == NULL){
|
||||
try_void(sendErrorMessage_f(log_ctx, conn, res_head,
|
||||
LogSeverity_Warn,
|
||||
@@ -54,8 +54,8 @@ declare_RequestHandler(Login)
|
||||
u64 user_id = *id_ptr;
|
||||
|
||||
// get user by id
|
||||
try_assert(user_id < List_len(conn->server->users_cache_list, UserInfo));
|
||||
UserInfo* u = &List_index(conn->server->users_cache_list, UserInfo, user_id);
|
||||
try_assert(user_id < List_len(conn->server->users.cache_list, UserInfo));
|
||||
UserInfo* u = &List_index(conn->server->users.cache_list, UserInfo, user_id);
|
||||
|
||||
// validate token hash
|
||||
if(memcmp(req.token, u->token, sizeof(req.token)) != 0){
|
||||
@@ -67,7 +67,7 @@ declare_RequestHandler(Login)
|
||||
}
|
||||
|
||||
// manually unlock mutex
|
||||
pthread_mutex_unlock(&conn->server->users_cache_mutex);
|
||||
idb_unlockTable(conn->server->users.table);
|
||||
unlocked_users_cache_mutex = true;
|
||||
|
||||
// authorize
|
||||
|
||||
Reference in New Issue
Block a user