Archive for资料存档(旧)

doc/userid

//hash 命中liu 是1.6 ,不知道是个什么意思..好好学学.

用户hash设计

——————————————————————————–

firebird BBS系统查询用户一直使用的是从头到尾遍历整个用户链表的模式
来查找用户,这个在大用户量的情况下是极大的开销。为了解决这个问题,
我设想使用hash表保存用户id索引,加快查找速度。相关的程序在libBBS/ucache.c
和libBBS/utmp.c中实现。
这个函数由我和ttiny@SMTH共同设计,由ttiny@SMTH完成。
我采用的是线性探测再散列的hash表。之所以不用二次探测再散列,是考虑到
当我们的hash_size>2-3倍的max_user的时候,如果选择恰当的hash函数,hash
的命中率可以 0 —
1 1 |
2 ———> 2 |
4

Comments (1)

local_utl目录的Makefile.am

CC=”@LIBTOOL@”
CCLD=”@CC@”
bin_PROGRAMS = poststat static usage Xclean Xhtml Bhtml refriend listonline
showBM idx0Ann lazybm fixdir autoundeny login statBM gen_title
resetMailTotal cnv_brdflag find_rm_lost
cnv_bh statguy cnv_bh2 autoclear ch_brdflag statkiller showipdeny
convpass356 scanIP scanMODE listMODE cnv_register calc_effsize usage smth_usage change_tmpl
mailall settoptitle genhot bonlinelog uonlinelog dayuserlog alluserlog
cnv_passwd strip_fh gennewboard recalc_signum find_lost_user outdaybm
cnv_brddir

EXTRA_DIST = urlencode.c
EXTRA_PROGRAMS =
LDADD=-lBBS -lsystem -L../libBBS -L../libsystem
AM_CFLAGS=-DINVISIBLE -D_DETAIL_UINFO_ -DSHOW_IDLE_TIME -I$(top_builddir)/src
CLEANFILES=@EXTRA_CLEAN@

Comments (1)

Xclean.c

/* Leeward 98.04.22 Cleaning “dead” files */
/* Leeward 99.04.22 Fixing a bug:
Error erasing files in a directory without .DIR */

//删除 /boards/bname/ 下的某个文件,此文件不能在 .DIR 和 .DIGEST 中.

//对目录中的每个文件循环调用此命令,可以删除 .JUNK .DELETE 里的文件.

#include
#include

#include “bbs.h”

int main(int argc, char **argv)
{
char fn[256], dn[256];
char *p;
FILE *fp;
struct fileheader fh;
int in;

if (argc

Comments (1)

mailall.c

//呵呵,水木把招清发群件的程序了放这里来,遵守 GPL 到家了

//俺也放这里权混文章数吧

#include “bbs.h”

//arg 为 NULL
int mailuser(struct userec *user, char *arg)
{ //发信人 正文文件名 收信人 标题
mail_file(“Arbitrator”, “tekan/JuryMail01”, user->userid, “[公告]BBS 水木清华站仲裁委员会集中招新”, BBSPOST_LINK, NULL); //BBSPOST_LINK 只链接,不复制.
return 0;
};

main()
{
chdir(BBSHOME);
resolve_ucache();
resolve_boards();
resolve_utmp();
//对每个用户适用 mailuser 函数
apply_users(mailuser, NULL);
}

评论

outdaybm.c

//根据 /etc/bmat 显示各版主的上任时间和任职版面
// “用户代号”, “任职版面”, “上任时间”, “距今天数”

#include
#include
#include

#if !defined __LINUX__ && !defined FREEBSD
#include
#include
#endif
#include “bbs.h”

#define MAXCHECK MAXBOARD*3

typedef int cmpfunc(const void *, const void *);

typedef struct {
char uname[IDLEN + 2];
char board[STRLEN];
time_t inday;
} BMInfo;

static BMInfo *pBMInfo;
static nBMCount = 0;

//比较版主登录时间先后
int cmpBMLogin(BMInfo * fst, BMInfo * snd)
{
return (fst->inday – snd->inday);
}

//判断是否是普通版
int isNormalBoard(struct boardheader *brd)
{
if (brd->level & PERM_NOZAP)
return 1;
else if (brd->level & PERM_LOGINOK)
return 1;
return (brd->level == 0);
}

void checkBMs(void)
{
char lbuf[256], tbuf[80], mdate[80];

char *fmt = ” 33[%2d;%2dm%-14.14s%-32.32s%-24.24s%8.8s33[m”;
char *timefmt = “%Y年%m月%d日 %T”;
char *nulstr = “”;
int i, j, uid, brd, dftime, warningBM = 0;
int fgc = 37, bgc = 44;
time_t now;
BMInfo *pBM;

now = time(NULL); /* current time stamp */
sprintf(lbuf, fmt, fgc, bgc, “用户代号”, “任职版面”, “上任时间”, “距今天数”);
fprintf(stdout, “33[m
%s
“, lbuf);
for (i = 0; i inday) / 86400;
strftime(mdate, 30, timefmt, localtime(&(pBM->inday)));

sprintf(tbuf, “%d”, dftime);
sprintf(lbuf, fmt, fgc, bgc, pBM->uname, pBM->board, mdate, uid ? tbuf : nulstr);
fprintf(stdout, “%s
“, lbuf);
}
strftime(mdate, 30, timefmt, localtime(&now));
fprintf(stdout, ”

统计时间∶%s
“, mdate);
}

int main(int argc, char **argv)
{
BMInfo bmusr[MAXCHECK];
int i;
char buf[256];
FILE *fp;
char uname[IDLEN + 2];
char board[STRLEN];
time_t inday;
char renming[STRLEN];
struct boardheader *bp;

pBMInfo = bmusr;

chdir(BBSHOME);
resolve_boards(); //get shm

//open etc/bmat for read
if ((fp = fopen(“etc/bmat”, “r”)) == NULL) {
fprintf(stdout, “cannot read bmat file
“);
exit(0);
}

while (fgets(buf, 256, fp)) {
if (sscanf(buf, “%s %s %d %s”, uname, board, &inday, renming) != 4)
continue;
if (!strcasecmp(uname, “SYSOP”) || !isascii(*uname))
continue;
bp = getbcache(board);
if (bp == NULL)
continue;
if (!isNormalBoard(bp))
continue;
if (nBMCount >= MAXCHECK)
continue;
strcpy(pBMInfo[nBMCount].uname, uname);
strcpy(pBMInfo[nBMCount].board, board);
pBMInfo[nBMCount].inday = inday;
nBMCount++;
}
fclose(fp);

//排序? 以上任时间对 pBMInfo 数组排序
qsort(pBMInfo, nBMCount, sizeof(BMInfo), (cmpfunc *) cmpBMLogin);
checkBMs();

pBMInfo = NULL;

return 0;
}

Comments (1)

« Previous entries