82 } |
82 } |
83 // if we have an elm, the hash is correct |
83 // if we have an elm, the hash is correct |
84 if(elm) { |
84 if(elm) { |
85 // compare the key data to be sure it is the correct user |
85 // compare the key data to be sure it is the correct user |
86 int n = (mapkey.len > elm->key.len) ? elm->key.len : mapkey.len; |
86 int n = (mapkey.len > elm->key.len) ? elm->key.len : mapkey.len; |
87 if (!memcmp(elm->key.data.cbytes, mapkey.data.cbytes, n)) { |
87 if (!memcmp(elm->key.data, mapkey.data, n)) { |
88 // elm is now the correct UserCacheElm |
88 // elm is now the correct UserCacheElm |
89 // TODO: use configuration for expire time |
89 // TODO: use configuration for expire time |
90 if(now - elm->created > 120) { |
90 if(now - elm->created > 120) { |
91 // cached user expired |
91 // cached user expired |
92 // remove all users from the list from the first to this one |
92 // remove all users from the list from the first to this one |
168 memcpy(key, authdb, authdblen); |
168 memcpy(key, authdb, authdblen); |
169 key[authdblen] = 0; |
169 key[authdblen] = 0; |
170 memcpy(key + authdblen + 1, user->name, userlen); |
170 memcpy(key + authdblen + 1, user->name, userlen); |
171 CxHashKey mapkey = cx_hash_key_bytes(key, keylen); |
171 CxHashKey mapkey = cx_hash_key_bytes(key, keylen); |
172 |
172 |
173 elm->key.data.bytes = key; |
173 elm->key.data = key; |
174 elm->key.len = mapkey.len; |
174 elm->key.len = mapkey.len; |
175 elm->key.hash = mapkey.hash; |
175 elm->key.hash = mapkey.hash; |
176 elm->slot = mapkey.hash%cache.size; |
176 elm->slot = mapkey.hash%cache.size; |
177 |
177 |
178 // add user to list and map |
178 // add user to list and map |