Exemple #1
0
int fillbcache(struct boardheader *fptr,int idx,void* arg)
{
	int bnum;
    struct BoardStatus * bs;
	char sql[500];

    if (check_see_perm(NULL, fptr)==0 || strlen(fptr->filename) == 0)
        return 0;

    bnum = getbid(fptr->filename,NULL);
    bs = getbstatus(bnum);

	sprintf(sql, "INSERT INTO bonline VALUES ( NULL, '%s', '%d', '%d', \"%d-%d-%d\", '%d', '%d' );",
				fptr->filename, bs->currentusers, bs->nowid, 
				t.tm_year+1900, t.tm_mon+1, t.tm_mday, t.tm_hour, t.tm_min/6);
    if( mysql_real_query( &s, sql, strlen(sql) ))
        printf("%s\n",mysql_error(&s));
    return 0;
}
Exemple #2
0
int generate_board_title(struct boardheader *bh,void* arg)
{
    int fd2, total, i;
    char olddirect[PATHLEN];
    char *ptr;
    struct fileheader * ptr1;
    struct BoardStatus* bs;
    struct stat buf;
	unsigned int iid;

    setbdir(DIR_MODE_NORMAL, olddirect, bh->filename);
    
    if ((fd2 = open(olddirect, O_RDWR, 0664)) == -1) {
		perror(olddirect);
        return 0;
    }

        if (safe_mmapfile_handle(fd2, PROT_READ | PROT_WRITE, MAP_SHARED, &ptr, &buf.st_size) == 0) {
            close(fd2);
            return 0;
        }
        total = buf.st_size / (sizeof(struct fileheader));
        ptr1 = (struct fileheader *) ptr;

		iid = ptr1[total-1].id;

		if(iid <=0) iid = 1;

    end_mmapfile((void *) ptr, buf.st_size, -1);
    close(fd2);

    bs=getbstatus(getbid(bh->filename,NULL));
	if(bs)
    	bs->nowid= iid + 1;

    return 0;
}
Exemple #3
0
/*主函数*/
int main(int argc,char **argv)
{
    FILE *fp;
    struct stat st;
    struct fileheader *dir1,*dir2,*dir;
    struct boardheader bh;
    struct BoardStatus *bs;
    char path1[512],path2[512],path[512],buf[512],*p1,*p2,*p;
    int ret;
    unsigned int size1,size2,pos1,pos2,pos,*offset1,*offset2;
    //初始化及错误检测
    if (argc!=4) {
        printf("[%s] 错误的参数结构...\nUSAGE: %s <srcboard1> <srcboard2> <dstdir>\n",argv[0],argv[0]);
        return 0x11;
    }
    if (chdir(BBSHOME)) {
        printf("[%s] 切换到 BBS 主目录 %s 错误...\n",argv[0],BBSHOME);
        return 0x12;
    }
    /*初始化源版面数据*/
    if ((ret=initdir(argv[0],path1,argv[1],&offset1,&size1,&dir1,&p1))!=0)
        return ret;
    if ((ret=initdir(argv[0],path2,argv[2],&offset2,&size2,&dir2,&p2))!=0)
        return ret;
    /*检测顺序并进行可能必要的顺序化*/
    if (!checkseq(dir1,size1)&&!seqdir(dir1,size1)) {
        printf("[%s] 版面 %s .DIR 结构错误, 修复失败...\n",argv[0],argv[1]);
        return 0x51;
    }
    if (!checkseq(dir2,size2)&&!seqdir(dir2,size2)) {
        printf("[%s] 版面 %s .DIR 结构错误, 修复失败...\n",argv[0],argv[2]);
        return 0x51;
    }
    /*创建目标目录,用pid进行标识区分*/
    sprintf(path,"boards/%s",argv[3]);
    sprintf(buf,"boards/%s_%d",argv[3], (int)getpid());
    if (!stat(path,&st)&&S_ISDIR(st.st_mode))
        rename(path,buf);
    else
        unlink(path);
    if (mkdir(path,(S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH))) {
        printf("[%s] 创建版面目录 %s 错误...\n",argv[0],path);
        return 0x31;
    }
    build_board_structure(argv[3]);
    p=path+strlen(path);*p++='/';
    sprintf(p,".DIR");
    /*准备目标.DIR文件的写操作*/
    if (!(fp=fopen(path,"wb"))) {
        printf("[%s] 创建 %s 错误...\n",argv[0],path);
        return 0x32;
    }
    /*申请目标.DIR结构需要的内存空间*/
    if (!(dir=(struct fileheader*)malloc((size1+size2)*sizeof(struct fileheader)))) {
        printf("[%s] 申请内存空间失败...\n",argv[0]);
        return 0x33;
    }
    //主处理
    pos1=0;pos2=0;pos=0;
    while (true) {
        /*比较时间戳*/
        if (pos1<size1&&pos2<size2) {
            //ret=strcmp(&dir1[pos1].filename[2],&dir2[pos2].filename[2]);
            ret = get_posttime(&dir1[pos1]) - get_posttime(&dir2[pos2]);
        } else if (pos1<size1)/*源版面2已经处理完成*/
            ret=-1;
        else if (pos2<size2)/*源版面1已经处理完成*/
            ret=1;
        else/*done*/
            break;
        /*处理当前fileheader*/
        if (!(ret>0)) {/*源版面1*/
            process(argv[0],dir,dir1,offset1,pos,pos1,path,p,path1,p1);
            pos1++;pos++;
        } else {/*源版面2*/
            process(argv[0],dir,dir2,offset2,pos,pos2,path,p,path2,p2);
            pos2++;pos++;
        }
    }
    /*写回目的.DIR*/
    if (fwrite(dir,sizeof(struct fileheader),(size1+size2),fp)!=(size1+size2)) {
        printf("[%s] 写入文件错误...\n",argv[0]);
        return 0x41;
    }
    /*设定未读标记*/
    resolve_boards();
    ret=getboardnum(argv[3],&bh);
    if (ret) {
        bh.idseq=size1+size2;
        set_board(ret,&bh,NULL);
        bs=getbstatus(ret);
        bs->total=size1+size2;
        bs->lastpost=size1+size2;
        bs->updatemark=true;
        bs->updatetitle=true;
        bs->updateorigin=true;
        bs->nowid=size1+size2;
        bs->toptitle=0;
    }
    /*清理*/
    fclose(fp);
    munmap(dir1,size1*sizeof(struct fileheader));
    if (size1)
        free(offset1);
    munmap(dir2,size2*sizeof(struct fileheader));
    if (size2)
        free(offset2);
    free(dir);
    return 0;
}
Exemple #4
0
int generate_board_title(struct boardheader *bh,void* arg)
{
    int fd2, size = sizeof(fileheader), total, i;
    struct boardheader btmp;
    char olddirect[PATHLEN];
    char *ptr, *t, *t2;
#ifdef GEN_ORIGIN
    FILE *fp=NULL;
    char opath[512];
#endif
    struct fileheader * ptr1;
    struct search_temp {
        bool has_pre;
        int digest;
        int thread_id;
        int id;
        int next;
    } *index=NULL;
    struct stat buf;
    int gen_threadid;
    struct BoardStatus* bs;

#ifdef GEN_ORIGIN
    setbdir(DIR_MODE_ORIGIN, opath, bh->filename);
#endif
    setbdir(DIR_MODE_NORMAL, olddirect, bh->filename);

    gen_threadid=1;
    if ((fd2 = open(olddirect, O_RDWR, 0664)) == -1) {
        perror(olddirect);
        return 0;
    }

    BBS_TRY {
        if (!safe_mmapfile_handle(fd2,PROT_READ|PROT_WRITE,MAP_SHARED,&ptr,&buf.st_size)) {
            close(fd2);
            return 0;
        }
#ifdef GEN_ORIGIN
        fp = fopen(opath, "wb");
#endif
        total = buf.st_size / size;
        index = (struct search_temp *) malloc(sizeof(*index) * total);
        ptr1 = (struct fileheader *) ptr;
        for (i = 0; i < total; i++, ptr1++) {
            int j;

            t2 = ptr1->title;
            if (!strncmp(t2, "Re:", 3)) {
                index[i].has_pre = true;
                t2 += 4;
            } else
                index[i].has_pre = false;
            index[i].thread_id = 0;
            index[i].digest = simple_digest(t2, ARTICLE_TITLE_LEN);
            for (j = i - 1; j >= 0; j--) {
                struct fileheader *tmppost;

                if (index[j].digest != index[i].digest)
                    continue;
                tmppost = ((struct fileheader *)(ptr + j * size));
                t = tmppost->title;
                if (index[j].has_pre)
                    t += 4;
                if (!strcmp(t, t2)) {
                    index[j].next = i;
                    index[i].thread_id = index[j].thread_id;
                    index[i].next = 0;
                    break;
                }
            }
            if (index[i].thread_id == 0) {
                index[i].thread_id = gen_threadid;
                index[i].id = gen_threadid;
                index[i].next = 0;
                gen_threadid++;
            } else {
                index[i].id = gen_threadid;
                gen_threadid++;
            }
        }
        ptr1 = (struct fileheader *) ptr;
        for (i = 0; i < total; i++, ptr1++) {
            ptr1->id = index[i].id;
            ptr1->groupid = index[i].thread_id;
            ptr1->reid = index[i].thread_id;
#ifdef GEN_ORIGIN
            if (index[i].has_pre == false)
                fwrite(ptr1, 1, sizeof(struct fileheader), fp);
#endif
        }
    }
    BBS_CATCH {
    }
    BBS_END;
    free(index);
    end_mmapfile((void *) ptr, buf.st_size, -1);
    close(fd2);
#ifdef GEN_ORIGIN
    fclose(fp);
#endif
    memcpy(&btmp,getbcache(bh->filename),sizeof(btmp));
    bs=getbstatus(getbid(bh->filename,NULL));
    bs->nowid=gen_threadid + 1;
    set_board(getbid(bh->filename,NULL), &btmp,NULL);
    setboardmark(bh->filename, 1);
    setboardtitle(bh->filename, 1);
    setboardorigin(bh->filename, 1);
    return 0;
}