phpbbs.bm.c

来自「linux/unix环境下的建站系统」· C语言 代码 · 共 946 行 · 第 1/2 页

C
946
字号
    char *board,*userid;    int  board_len,userid_len;    const struct boardheader *brd;       int ac = ZEND_NUM_ARGS();    if (ac != 2 || zend_parse_parameters(2 TSRMLS_CC, "ss", &board, &board_len, &userid ,&userid_len) == FAILURE) {		WRONG_PARAM_COUNT;	}        if (getbid(board, &brd) == 0)        RETURN_LONG(-1);    if (!check_read_perm(getCurrentUser(), brd))        RETURN_LONG(-1);    strcpy(board,brd->filename);    if (!is_BM(brd, getCurrentUser()))        RETURN_LONG(-2);            if (deny_me(userid, board)) {        deldeny(getCurrentUser(), board, userid, 0, getSession());                  RETURN_LONG(0);    }    else        RETURN_LONG(-3);}/** * function bbs_bm_get_manageable_bids(string userid) * @return a string *         "A": can manage all visible boards *         empty string:  not a bm *         .-delimited bid list: all manageable board id list * @author atppp * */PHP_FUNCTION(bbs_bm_get_manageable_bids){#define MAX_MANAGEABLE_BIDS_LENGTH 1024 // note most browser set 4k as maximum bytes per cookie - atppp    char *userid;    int userid_len;    struct userec *user;    char buf[MAX_MANAGEABLE_BIDS_LENGTH];    int ac = ZEND_NUM_ARGS();    if (ac == 0) {        user = getCurrentUser();        if (user == NULL) {            RETURN_EMPTY_STRING();        }    } else {        if (ac != 1 || zend_parse_parameters(1 TSRMLS_CC, "s", &userid ,&userid_len) == FAILURE) {		    WRONG_PARAM_COUNT;    	}        if (!getuser(userid, &user)) {            RETURN_EMPTY_STRING();        }    }    if (HAS_PERM(user, PERM_OBOARDS) || HAS_PERM(user, PERM_SYSOP)) {        RETURN_STRING("A", 1);    }    if (!HAS_PERM(user, PERM_BOARDS)) {        RETURN_EMPTY_STRING();    }    get_manageable_bids(user, buf, MAX_MANAGEABLE_BIDS_LENGTH);    RETURN_STRING(buf, 1);#undef MAX_MANAGEABLE_BIDS_LENGTH}/* club functions below, by pig2532 */static int func_load_club_users(struct userec *user,void *varg){    struct clubarg *clubflag = (struct clubarg *)varg;    if(user->userid[0]&&get_user_club_perm(user,clubflag->brd,clubflag->mode))    {        struct usernode *untmp;        untmp = (struct usernode *)emalloc(sizeof(struct usernode));        if(untmp != NULL)        {            untmp->userid = estrdup(user->userid);            untmp->next = NULL;            if(clubflag->ulheader == NULL)            {                clubflag->ulheader = clubflag->ulcurrent = untmp;            }            else            {                clubflag->ulcurrent->next = untmp;                clubflag->ulcurrent = untmp;            }        }        return COUNT;    }    return 0;}static int CompareNameCase(const void *v1,const void *v2){    return strcasecmp((*((const char**)v1)),(*((const char**)v2)));}static void clubread_FreeAll(struct usernode *ulheader, char **userarray){    struct usernode *ulnext;    while(ulheader)    {        ulnext = ulheader->next;    	if(ulheader->userid)    	    efree(ulheader->userid);        efree(ulheader);        ulheader = ulnext;    }    if(userarray)        efree(userarray);}/* read club member, by pig2532parameters:    bname: board name    clubmode: 0-read_prem_club, 1-write_prem_club    start: read user list from    num: how many user names to read    userlist: array to save the name listreturn:    >=0: [success] record count total    -1: system error    -2: board not found    -3: no BM perm    -4: this is not a club*/PHP_FUNCTION(bbs_club_read){    char *bname;    long clubmode, start, num;    zval *userlist;    const struct boardheader *brd;    int i, bname_len, count;    struct clubarg clubflag;    char **userarray, **t;    struct usernode *ulheader, *ulcurrent;        if (ZEND_NUM_ARGS() != 5 || zend_parse_parameters(5 TSRMLS_CC, "sllla", &bname, &bname_len, &clubmode, &start, &num, &userlist) == FAILURE) {        WRONG_PARAM_COUNT;    }        if(start < 0)        RETURN_LONG(0);    if(array_init(userlist) != SUCCESS)        RETURN_LONG(-1);    if (getbid(bname, &brd) == 0)        RETURN_LONG(-2);    if (!check_read_perm(getCurrentUser(), brd))        RETURN_LONG(-2);    strcpy(bname, brd->filename);    if (!is_BM(brd, getCurrentUser()))        RETURN_LONG(-3);    if(!(brd->flag&(BOARD_CLUB_READ|BOARD_CLUB_WRITE))||!(brd->clubnum>0)||(brd->clubnum>MAXCLUB))        RETURN_LONG(-4);    if( !((brd->flag & BOARD_CLUB_READ) && (brd->flag & BOARD_CLUB_WRITE)) )        clubmode = brd->flag & BOARD_CLUB_WRITE;        userarray = NULL;    ulheader = ulcurrent = NULL;    clubflag.brd = brd;    clubflag.mode = clubmode;    clubflag.ulheader = ulheader;    clubflag.ulcurrent = ulcurrent;    count = apply_users(func_load_club_users, &clubflag);    ulheader = clubflag.ulheader;    ulcurrent = clubflag.ulcurrent;    if (start >= count)    {        clubread_FreeAll(ulheader, userarray);        RETURN_LONG(0);    }            userarray = (char **)emalloc(count * sizeof(char *));    if (userarray == NULL)    {        clubread_FreeAll(ulheader, userarray);        RETURN_LONG(-1);    }    for(ulcurrent=ulheader,t=userarray;ulcurrent;ulcurrent=ulcurrent->next,t++)        (*t)=ulcurrent->userid;    qsort(userarray, count, sizeof(const char*), CompareNameCase);        num = (num>count-start) ? (count-start) : num;    t = userarray + start;    for(i=0; i<num; i++)    {        add_next_index_string(userlist, *t, 1);        t++;    }        clubread_FreeAll(ulheader, userarray);    RETURN_LONG(count);}/* read club flag, by pig2532parameters:    bname: board namereturn:    -1: board not found    0: not a club    1: read perm club    2: write perm club    3: both perm club*/PHP_FUNCTION(bbs_club_flag){    char *bname;    int bname_len;    const struct boardheader *brd;        if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(1 TSRMLS_CC, "s", &bname, &bname_len) != SUCCESS)        WRONG_PARAM_COUNT;            if (getbid(bname, &brd) == 0)        RETURN_LONG(-1);    if (!check_read_perm(getCurrentUser(), brd))        RETURN_LONG(-1);    strcpy(bname, brd->filename);    if(!(brd->flag&(BOARD_CLUB_READ|BOARD_CLUB_WRITE))||!(brd->clubnum>0)||(brd->clubnum>MAXCLUB))        RETURN_LONG(0);    if (brd->flag & BOARD_CLUB_READ)    {        if (brd->flag & BOARD_CLUB_WRITE)        {            RETURN_LONG(3);        }        else        {            RETURN_LONG(1);        }    }    else if (brd->flag & BOARD_CLUB_WRITE)    {        RETURN_LONG(2);    }    else    {        RETURN_LONG(0);    }}/* modify user's club perm, by pig2532parameters:    bname: board name    clubop: club operate string, start with '+' to add, '-' to remove    mode: 0-read_perm, 1-write_perm    info: operation commentreturn:    0: success    -1: board not found    -2: permission denied    -3: this is not a club*/PHP_FUNCTION(bbs_club_write){    char *bname, *clubop, *line, *info;    int bname_len, clubop_len, info_len;    long mode;    struct userec *user;    const struct boardheader *brd;        if (ZEND_NUM_ARGS() != 4 || zend_parse_parameters(4 TSRMLS_CC, "ssls", &bname, &bname_len, &clubop, &clubop_len, &mode, &info, &info_len) != SUCCESS)        WRONG_PARAM_COUNT;            if (getbid(bname, &brd) == 0)        RETURN_LONG(-1);    if (!check_read_perm(getCurrentUser(), brd))        RETURN_LONG(-1);    strcpy(bname, brd->filename);    if (!is_BM(brd, getCurrentUser()))        RETURN_LONG(-2);    if(!(brd->flag&(BOARD_CLUB_READ|BOARD_CLUB_WRITE))||!(brd->clubnum>0)||(brd->clubnum>MAXCLUB))        RETURN_LONG(-3);    if( !((brd->flag & BOARD_CLUB_READ) && (brd->flag & BOARD_CLUB_WRITE)) )        mode = brd->flag & BOARD_CLUB_WRITE;            line = &clubop[1];    switch(clubop[0])    {    case 0:    case 10:    case 13:    case '#':        RETURN_LONG(0);    case '-':        trimstr(line);        if(!getuser(line,&user)||!get_user_club_perm(user,brd,mode))            RETURN_LONG(0);        if(!del_user_club_perm(user,brd,mode)){            club_maintain_send_mail(user->userid,info,1,mode,brd,getSession());        }        break;    case '+':        line++;    default:        line--;        trimstr(line);        if(!getuser(line,&user)||!strcmp(user->userid,"guest")||get_user_club_perm(user,brd,mode))            RETURN_LONG(0);        if(!set_user_club_perm(user,brd,mode)){            club_maintain_send_mail(user->userid,info,0,mode,brd,getSession());        }        break;    }    RETURN_LONG(0);}/* club functions end *//* threads functions, by pig2532parameters:    bid: board id    gid: thread group id    start: start article id    operate:  0 - nothing              1 - delete              2 - mark              3 - unmark              4 - del X records              5 - put to announce              6 - set X flag              7 - unset X flag              8 - no reply              9 - cancel no reply              10 - make total              11 - make total without quote              12 - import              13 - import without head and qmdreturn:    >=0: [success] article numbers    -1: board not found    -2: permission denied    -3: system error    -10: unknown operate*/PHP_FUNCTION(bbs_threads_bmfunc){#define MAX_THREADS_NUM 512    long bid, gid, start, operate;    const struct boardheader *bp;    char dirpath[STRLEN];    int ret, haveprev=0, i, fd, ent, count;    struct fileheader *articles, fh;        if (ZEND_NUM_ARGS() != 4 || zend_parse_parameters(4 TSRMLS_CC, "llll", &bid, &gid, &start, &operate) == FAILURE)    {        WRONG_PARAM_COUNT;    }        if((operate < 1) || (operate > 13))    {    	RETURN_LONG(-10);    }    bp = getboard(bid);    if(bp == NULL)    {        RETURN_LONG(-1);    }    if(!is_BM(bp, getCurrentUser()))    {        RETURN_LONG(-2);    }        articles = NULL;    setbdir(DIR_MODE_NORMAL, dirpath, bp->filename);    if((operate == 1) || (operate == 4) || ((operate >= 10) && (operate <= 13)))    /* delete or make total or import */    {        articles = (struct fileheader *)emalloc(MAX_THREADS_NUM * sizeof(struct fileheader));        ret = get_threads_from_gid(dirpath, gid, articles, MAX_THREADS_NUM, start, &haveprev, operate, getCurrentUser());    }    else    {        if(operate == 5)    /* initialize announce clipboard first */            ann_article_import(bp->filename, NULL, NULL, getCurrentUser()->userid);        ret = get_threads_from_gid(dirpath, gid, NULL, MAX_THREADS_NUM, start, &haveprev, operate, getCurrentUser());    }        if(operate == 1)    /* del threads */    {        fd = open(dirpath, O_RDWR, 0644);        if (fd < 0)        {            efree(articles);            RETURN_LONG(-3);        }        count = 0;        for(i=0; i<ret; i++)        {            if( !(articles[i].accessed[0] & (FILE_MARKED | FILE_PERCENT)) )                if(get_records_from_id(fd, articles[i].id, &fh, 1, &ent))                {                    if(del_post(ent, &fh, bp) == 0)                        count++;                }        }        close(fd);        ret = count;    }    else if(operate == 4)    /* del X articles in threads */    {        fd = open(dirpath, O_RDWR, 0644);        if (fd < 0)        {            efree(articles);            RETURN_LONG(-3);        }        count = 0;        for(i=0; i<ret; i++)        {           if( (articles[i].accessed[1] & FILE_DEL) && ( !(articles[i].accessed[0] & (FILE_MARKED | FILE_PERCENT)) ) )                if(get_records_from_id(fd, articles[i].id, &fh, 1, &ent))                {                    if(del_post(ent, &fh, bp) == 0)                        count++;                }        }        close(fd);        ret = count;    }    else if((operate == 10) || (operate == 11))     /* make total */    {        char title[STRLEN], *ptr, tmpf[PATHLEN];        for(i=0; i<ret; i++)        {            a_SeSave(NULL, bp->filename, &articles[i], i>0, NULL, 0, operate==11, getCurrentUser()->userid);        }        if(ret > 0)        {            strcpy(title, "[合集] ");            if(strncmp(articles[0].title, "Re: ", 4) == 0)                ptr = articles[0].title + 4;            else                ptr = articles[0].title;            strncpy(title + 7, ptr, STRLEN - 7);            title[STRLEN - 1] = '\0';            sprintf(tmpf, "tmp/bm.%s", getCurrentUser()->userid);            if(post_file(getCurrentUser(), "", tmpf, bp->filename, title, 0, 2, getSession()) < 0)            {                unlink(tmpf);                sprintf(tmpf, "tmp/se.%s", getCurrentUser()->userid);                unlink(tmpf);                efree(articles);                RETURN_LONG(-3);            }        }    }    else if((operate == 12) || (operate == 13))     /* import */    {        for(i=0; i<ret; i++)        {            a_SeSave(NULL, bp->filename, &articles[i], true, NULL, 0, operate==13, getCurrentUser()->userid);        }    }        if(articles)        efree(articles);    if(ret >= 0)    {        RETURN_LONG(ret);    }    else    {        RETURN_LONG(-3);    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?