AmendHub

Download:

jcs

/

subtext

/

amendments

/

109

user: Rename user_map to username_cache to reflect what it actually is


jcs made amendment 109 over 2 years ago
--- user.c Mon May 23 13:19:02 2022 +++ user.c Mon May 23 13:58:48 2022 @@ -47,19 +47,20 @@ void user_cache_usernames(void) { struct user user; - struct user_map *muser; + struct username_cache *muser; struct bile_object *o; size_t nuser, len; - if (db->user_map != NULL) - free(db->user_map); + if (db->username_cache != NULL) + free(db->username_cache); db->nusers = bile_count_by_type(db->bile, DB_USER_RTYPE); - db->user_map = xmalloczero(sizeof(struct user_map) * db->nusers); + db->username_cache = xmalloczero(sizeof(struct username_cache) * + db->nusers); nuser = 0; while ((o = bile_get_nth_of_type(db->bile, nuser, DB_USER_RTYPE))) { - muser = &db->user_map[nuser]; + muser = &db->username_cache[nuser]; muser->id = o->id; len = bile_read(db->bile, DB_USER_RTYPE, o->id, (char *)&user, @@ -116,7 +117,7 @@ struct user * user_find_by_username(const char *username) { struct user suser; - struct user_map *muser; + struct username_cache *muser; short n; size_t len; @@ -125,7 +126,7 @@ user_find_by_username(const char *username) return NULL; for (n = 0; n < db->nusers; n++) { - muser = &db->user_map[n]; + muser = &db->username_cache[n]; if (strcasecmp(muser->username, username) == 0) return user_find(muser->id); @@ -134,14 +135,14 @@ user_find_by_username(const char *username) return NULL; } -struct user_map * +struct username_cache * user_find_username(unsigned long id) { - struct user_map *muser; + struct username_cache *muser; size_t n; for (n = 0; n < db->nusers; n++) { - muser = &db->user_map[n]; + muser = &db->username_cache[n]; if (muser->id == id) return muser; } --- user.h Mon May 23 12:59:50 2022 +++ user.h Mon May 23 13:57:39 2022 @@ -34,7 +34,7 @@ struct user { short is_sysop; }; -struct user_map { +struct username_cache { unsigned long id; char username[DB_USERNAME_LENGTH + 1]; }; @@ -43,7 +43,7 @@ void user_cache_usernames(void); void user_save(struct user *user); struct user * user_find(unsigned long id); struct user * user_find_by_username(const char *username); -struct user_map * user_find_username(unsigned long id); +struct username_cache * user_find_username(unsigned long id); short user_authenticate(struct user *user, const char *password); void user_set_password(struct user *user, const char *password); short user_valid_username(char *username, char **error);