void sethomefile(char *buf, const char *userid, const char *fname) { assert(is_validuserid(userid)); assert(fname[0]); snprintf(buf, PATHLEN, str_home_file, userid[0], userid, fname); }
void setuserhashedfile(char *buf, const char *filename) { #ifdef USERHASHSTORE_ROOTPATH // hash designed by kcwu unsigned hash = StringHash(cuser.userid) & 0xffff; assert(is_validuserid(cuser.userid)); snprintf(buf, PATHLEN, USERHASHSTORE_ROOTPATH "/%02x/%02x/%s.%s.%x", (hash >> 8) & 0xff, hash & 0xff, filename, cuser.userid, cuser.firstlogin); #else (void)buf; (void)filename; assert(!"you must define and initialize USERHASHSTORE_ROOTPATH"); #endif }
void userec_add_to_uhash(int n, userec_t *user, int onfly) { int *p, h, l=0; // uhash use userid="" to denote free slot for new register // However, such entries will have the same hash key. // So we skip most of invalid userid to prevent lots of hash collision. if (!is_validuserid(user->userid)) { // dirty hack, preserve few slot for new register static int count = 0; count++; if (count > 1000) return; } h = StringHash(user->userid)%(1<<HASH_BITS); p = &(SHM->hash_head[h]); if(!onfly || SHM->userid[n][0] != user->userid[0] || strncmp(SHM->userid[n], user->userid, IDLEN-1)) { strcpy(SHM->userid[n], user->userid); SHM->money[n] = user->money; #ifdef USE_COOLDOWN SHM->cooldowntime[n] = 0; #endif if(onfly) printf("add %s\n", user->userid); } while (*p != -1) { if(onfly && *p==n ) // already in hash return; l++; p = &(SHM->next_in_hash[*p]); } if(onfly) printf("add %d %d %d [%s] in hash\n", l, h, n, user->userid); SHM->next_in_hash[*p = n] = -1; }
void sethomeman(char *buf, const char *userid) { assert(is_validuserid(userid)); snprintf(buf, PATHLEN, str_home_file, userid[0], userid, "man"); }
void sethomedir(char *buf, const char *userid) { assert(is_validuserid(userid)); snprintf(buf, PATHLEN, str_home_file, userid[0], userid, str_dotdir); }
/* XXX set*() all assume buffer size = PATHLEN */ void sethomepath(char *buf, const char *userid) { assert(is_validuserid(userid)); snprintf(buf, PATHLEN, "home/%c/%s", userid[0], userid); }